-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSettings.java
186 lines (157 loc) · 4.99 KB
/
Settings.java
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
180
181
182
183
184
185
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.HashMap;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
public final class Settings {
private static class StringColor {
public String title;
public Color color;
}
private static HashMap<Integer, StringColor> annoColors = new HashMap<Integer, StringColor>();
private static int currAnnoType = 0;
private static boolean badLeadInterp = false;
private static String defaultDir;
private Settings() {} //no initialization
public static void makeDefaultSettings() {
String[] desc = {"P-wave", "QRS-complex", "R-wave", "T-wave"};
Color[] colors = {Color.BLACK, Color.ORANGE, Color.GREEN, Color.BLUE};
for(int i = 0; i < desc.length; i++) {
StringColor s = new StringColor();
s.title = desc[i];
s.color = colors[i];
annoColors.put(i, s);
}
badLeadInterp=false;
defaultDir = "~";
}
public static void load() {
makeDefaultSettings();
try {
BufferedReader reader = new BufferedReader(new FileReader("settings.conf"));
String line = "";
String[] tokens;
while((line = reader.readLine())!=null) {
tokens = line.split(":");
if("DefaultDir".equals(tokens[0])) {
defaultDir = tokens[1];
continue;
}
}
} catch (IOException e) {}
}
public static void save() {
try {
PrintWriter writer = new PrintWriter("settings.conf");
writer.println("DefaultDir:"+defaultDir);
writer.close();
} catch(IOException e) {}
}
public static int numAnnoTypes() {
return annoColors.size();
}
public static int getSelectedAnnotationType() {
return currAnnoType;
}
public static void setSelectedAnnotationType(int type) {
currAnnoType = type;
}
public static Color getAnnotationColor(int type) {
return annoColors.get(type).color;
}
public static Color getSelectedAnnotationColor() {
return annoColors.get(currAnnoType).color;
}
public static String getAnnotationTitle(int type) {
return annoColors.get(type).title;
}
public static String getSelectedAnnotationTitle() {
return annoColors.get(currAnnoType).title;
}
public static boolean isBadInterp() {
return badLeadInterp;
}
public static void setInterp(boolean interp) {
badLeadInterp = interp;
}
public static String getDefaultDirectory() {
return defaultDir;
}
public static void edit() {
final JDialog frame = new JDialog((Frame)null, "Settings", true);
frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
JPanel annotation = new JPanel();
for(final StringColor sc : annoColors.values()) {
JPanel p = new JPanel();
JLabel label = new JLabel(sc.title);
JButton color = new JButton();
color.setBackground(sc.color);
color.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Color c = JColorChooser.showDialog((JButton) e.getSource(), "Choose Color", sc.color);
if(c != null) {
sc.color = c;
}
}
});
p.add(label);
p.add(color);
p.revalidate();
annotation.add(p);
annotation.revalidate();
}
annotation.setBorder(BorderFactory.createTitledBorder("Annotations"));
frame.add(annotation);
JCheckBox interp = new JCheckBox("Interpolate bad leads?", badLeadInterp);
interp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
badLeadInterp = !badLeadInterp;
}
});
frame.add(interp);
JPanel directory = new JPanel();
JLabel dirlabel = new JLabel("Default Open/Save directory:");
directory.add(dirlabel);
final JLabel dir = new JLabel(defaultDir);
directory.add(dir);
String imgLoc = "imgs/toolbarButtonGraphics/general/Open16.gif";
URL imageURL = MainFrame.class.getResource(imgLoc);
JButton dirbutton = new JButton();
dirbutton.setIcon(new ImageIcon(imageURL));
dirbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Default Directory...");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
if(chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
defaultDir = chooser.getSelectedFile().getAbsolutePath();
dir.setText(defaultDir);
}
}
});
directory.add(dirbutton);
frame.add(directory);
frame.pack();
frame.setVisible(true);
}
public static final Color normalLead = UIManager.getColor("Panel.background");
public static final Color badLead = new Color(233, 174, 174);
public static final Color selected = UIManager.getColor("ComboBox.selectionBackground");
}