-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplaySettings.java
More file actions
179 lines (164 loc) · 7.36 KB
/
DisplaySettings.java
File metadata and controls
179 lines (164 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DisplaySettings extends JFrame implements ActionListener {
private JComboBox<String> modeBox;
private JButton applyButton, cancelButton;
private JPanel previewPanel;
public DisplaySettings() {
// Use Nimbus Look and Feel if available
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception ex) { }
setTitle("Display Settings");
setSize(400, 300);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
initUI();
setVisible(true);
}
private void initUI() {
JPanel mainPanel = new JPanel(new BorderLayout(20, 20));
mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JLabel titleLabel = new JLabel("Display Settings", SwingConstants.CENTER);
titleLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
mainPanel.add(titleLabel, BorderLayout.NORTH);
// Center panel for mode selection and preview
JPanel centerPanel = new JPanel(new BorderLayout(10, 10));
JPanel selectionPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
JLabel modeLabel = new JLabel("Select Mode:");
modeLabel.setFont(new Font("SansSerif", Font.PLAIN, 16));
String[] modes = {"Mono Magic", "Vibrant Vibes", "Rainbow Surprise"};
modeBox = new JComboBox<>(modes);
modeBox.setFont(new Font("SansSerif", Font.PLAIN, 16));
modeBox.addActionListener(e -> updatePreview());
selectionPanel.add(modeLabel);
selectionPanel.add(modeBox);
centerPanel.add(selectionPanel, BorderLayout.NORTH);
previewPanel = new JPanel();
previewPanel.setPreferredSize(new Dimension(300, 150));
previewPanel.setBorder(BorderFactory.createTitledBorder("Preview"));
updatePreview();
centerPanel.add(previewPanel, BorderLayout.CENTER);
mainPanel.add(centerPanel, BorderLayout.CENTER);
// Button panel at the bottom
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 10));
applyButton = new JButton("Apply");
applyButton.setFont(new Font("SansSerif", Font.BOLD, 16));
applyButton.addActionListener(this);
cancelButton = new JButton("Cancel");
cancelButton.setFont(new Font("SansSerif", Font.BOLD, 16));
cancelButton.addActionListener(this);
buttonPanel.add(applyButton);
buttonPanel.add(cancelButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
add(mainPanel);
}
private void updatePreview() {
String selectedMode = (String) modeBox.getSelectedItem();
previewPanel.removeAll();
previewPanel.setLayout(new GridBagLayout());
JLabel previewLabel = new JLabel();
previewLabel.setFont(new Font("SansSerif", Font.BOLD, 18));
if ("Mono Magic".equals(selectedMode)) {
Color sample = new Color(30, 144, 255);
Color transformed = ColorBlindnessFilter.applyMonochromacy(sample);
previewPanel.setBackground(transformed);
previewLabel.setText("Mono Magic Preview");
} else if ("Vibrant Vibes".equals(selectedMode)) {
Color sample = new Color(220, 20, 60);
Color transformed = ColorBlindnessFilter.applyDichromacy(sample);
previewPanel.setBackground(transformed);
previewLabel.setText("Vibrant Vibes Preview");
} else if ("Rainbow Surprise".equals(selectedMode)) {
Color sample = new Color(50, 205, 50);
Color transformed = ColorBlindnessFilter.applyAnomalousTrichromacy(sample);
previewPanel.setBackground(transformed);
previewLabel.setText("Rainbow Surprise Preview");
}
previewLabel.setForeground(Color.BLACK);
previewPanel.add(previewLabel, new GridBagConstraints());
previewPanel.revalidate();
previewPanel.repaint();
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == applyButton) {
String selectedMode = (String) modeBox.getSelectedItem();
if ("Mono Magic".equals(selectedMode)) {
ColorBlindnessFilter.setMode(ColorBlindnessFilter.Mode.MONOCHROMACY);
} else if ("Vibrant Vibes".equals(selectedMode)) {
ColorBlindnessFilter.setMode(ColorBlindnessFilter.Mode.DICHROMACY);
} else if ("Rainbow Surprise".equals(selectedMode)) {
ColorBlindnessFilter.setMode(ColorBlindnessFilter.Mode.ANOMALOUS_TRICHROMACY);
}
JOptionPane.showMessageDialog(this, "Display settings applied: " + selectedMode,
"Settings Applied", JOptionPane.INFORMATION_MESSAGE);
dispose();
} else if (e.getSource() == cancelButton) {
dispose();
}
}
// Inner static class for simulating color blindness effects
public static class ColorBlindnessFilter {
public enum Mode {
NORMAL,
MONOCHROMACY,
DICHROMACY,
ANOMALOUS_TRICHROMACY
}
private static Mode currentMode = Mode.NORMAL;
public static void setMode(Mode mode) {
currentMode = mode;
}
public static Mode getMode() {
return currentMode;
}
// Mono Magic: Convert to grayscale
public static Color applyMonochromacy(Color color) {
int gray = (int)(color.getRed() * 0.299 + color.getGreen() * 0.587 + color.getBlue() * 0.114);
return new Color(gray, gray, gray);
}
// Vibrant Vibes: Simple dichromacy simulation
public static Color applyDichromacy(Color color) {
int r = color.getRed();
int g = color.getGreen();
int b = color.getBlue();
int r2 = clamp((int)(0.625 * r + 0.375 * g));
int g2 = clamp((int)(0.7 * r + 0.3 * g));
int b2 = b;
return new Color(r2, g2, b2);
}
// Rainbow Surprise: Blend normal with dichromacy simulation
public static Color applyAnomalousTrichromacy(Color color) {
Color dichro = applyDichromacy(color);
int r = (int)(0.5 * color.getRed() + 0.5 * dichro.getRed());
int g = (int)(0.5 * color.getGreen() + 0.5 * dichro.getGreen());
int b = (int)(0.5 * color.getBlue() + 0.5 * dichro.getBlue());
return new Color(clamp(r), clamp(g), clamp(b));
}
public static Color transformColor(Color color) {
switch(currentMode) {
case MONOCHROMACY:
return applyMonochromacy(color);
case DICHROMACY:
return applyDichromacy(color);
case ANOMALOUS_TRICHROMACY:
return applyAnomalousTrichromacy(color);
default:
return color;
}
}
private static int clamp(int value) {
return Math.max(0, Math.min(255, value));
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new DisplaySettings());
}
}