~raginggoblin/infolog/trunk

« back to all changes in this revision

Viewing changes to InfologClient/src/main/java/raging/goblin/infolog/client/gui/GuiConfigDialog.java

  • Committer: Raging Goblin
  • Date: 2013-11-22 16:57:07 UTC
  • Revision ID: raging_goblin-20131122165707-v2i0efo3jt5fjxd3
Updated copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2012, RagingGoblin <http://raginggoblin.wordpress.com>
 
2
 * Copyright 2013, RagingGoblin <http://raginggoblin.wordpress.com>
3
3
 * 
4
4
 * This file is part of Infolog.
5
5
 *
48
48
 */
49
49
public class GuiConfigDialog extends JDialog {
50
50
 
51
 
    private static final String TITLE = "Configure look and feel";
52
 
    private static final String WIDTH_TOOLTIP = "Width of a sticky note in px.";
53
 
    private static final String HEIGHT_TOOLTIP = "Height of a sticky note in px.";
54
 
    private static final String SYSTRAY_TOOLTIP = "Path to icon used in system tray (requires restart).";
55
 
    private static final String SPACING_TOOLTIP = "Offset in px. between sticky notes when layed out on the screen.";
56
 
    private static final String NOTE_BOTTOM_TOOLTIP = "Bottom color used for sticky notes of type 'note'.";
57
 
    private static final String NOTE_TOP_TOOLTIP = "Top color used for sticky notes of type 'note'.";
58
 
    private static final String PHONE_BOTTOM_TOOLTIP = "Bottom color used for sticky notes of type 'phone call'.";
59
 
    private static final String PHONE_TOP_TOOLTIP = "Top color used for sticky notes of type 'phone call'.";
60
 
    private static final String TASK_BOTTOM_TOOLTIP = "Bottom color used for sticky notes of type 'task'.";
61
 
    private static final String TASK_TOP_TOOLTIP = "Top color used for sticky notes of type 'task'.";
62
 
    private static final String DRAG_DELAY_TOOLTIP = "Threshold value to tweak the drag behaviour, higher values will delay the repaint events making it easier for slow graphic cards to keep up.";
63
 
    private static final String DOUBLE_CLICK_DELAY_TOOLTIP = "Delay in ms between two clicks to register as a double click.";
64
 
 
65
 
    private JSpinner widthSpinner;
66
 
    private JSpinner spacingSpinner;
67
 
    private JSpinner heightSpinner;
68
 
    private ColorButton btnTopColorNotes;
69
 
    private ColorButton btnTopColorTasks;
70
 
    private ColorButton btnTopColorPhoneCalls;
71
 
    private ColorButton btnBottomColorNotes;
72
 
    private ColorButton btnBottomColorTasks;
73
 
    private ColorButton btnBottomColorPhoneCalls;
74
 
    private JSpinner dragDelaySpinner;
75
 
    private JSpinner doubleClickDelaySpinner;
76
 
    private JTextField trayIconField;
77
 
 
78
 
    public GuiConfigDialog(JFrame parent) {
79
 
        super(parent, TITLE, true);
80
 
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
81
 
        setSize(850, 550);
82
 
 
83
 
        JPanel actionPanel = new JPanel();
84
 
        getContentPane().add(actionPanel, BorderLayout.SOUTH);
85
 
        actionPanel.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"),
86
 
            FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
87
 
            FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(40dlu;default)"),
88
 
            FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
89
 
            ColumnSpec.decode("max(40dlu;default)"), FormFactory.RELATED_GAP_COLSPEC,
90
 
            ColumnSpec.decode("max(5dlu;default)"), }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC,
91
 
            FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("max(5dlu;default)"), }));
92
 
 
93
 
        JButton btnCancel = new JButton("Cancel");
94
 
        btnCancel.addActionListener(new ActionListener() {
95
 
            @Override
96
 
            public void actionPerformed(ActionEvent e) {
97
 
                setVisible(false);
98
 
            }
99
 
        });
100
 
        actionPanel.add(btnCancel, "7, 1, 2, 1");
101
 
 
102
 
        JButton btnDefaults = new JButton("Load defaults");
103
 
        btnDefaults.addActionListener(new ActionListener() {
104
 
            @Override
105
 
            public void actionPerformed(ActionEvent e) {
106
 
                setDefaults();
107
 
            }
108
 
        });
109
 
        actionPanel.add(btnDefaults, "3, 1");
110
 
 
111
 
        JButton btnOk = new JButton("OK");
112
 
        btnOk.addActionListener(new ActionListener() {
113
 
            @Override
114
 
            public void actionPerformed(ActionEvent e) {
115
 
                setVisible(false);
116
 
                saveConfiguration();
117
 
            }
118
 
        });
119
 
        actionPanel.add(btnOk, "11, 1, 2, 1");
120
 
 
121
 
        JPanel configPanel = new JPanel();
122
 
        getContentPane().add(configPanel, BorderLayout.CENTER);
123
 
        configPanel.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("max(61dlu;min):grow"),
124
 
            ColumnSpec.decode("max(40dlu;default):grow"), FormFactory.RELATED_GAP_COLSPEC,
125
 
            ColumnSpec.decode("99px:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(30dlu;default)"),
126
 
            FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
127
 
            ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
128
 
            FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC,
129
 
            ColumnSpec.decode("max(30dlu;default)"), FormFactory.RELATED_GAP_COLSPEC,
130
 
            ColumnSpec.decode("max(30dlu;default)"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
131
 
            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
132
 
            FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
133
 
            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
134
 
            FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
135
 
            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
136
 
            FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
137
 
            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));
138
 
 
139
 
        StringSeparator dimensionsSeparator = new StringSeparator("Dimensions");
140
 
        configPanel.add(dimensionsSeparator, "1, 2, 18, 1");
141
 
 
142
 
        JLabel lblWidth = new JLabel("Width");
143
 
        configPanel.add(lblWidth, "4, 4, right, center");
144
 
 
145
 
        widthSpinner = new JSpinner();
146
 
        widthSpinner.setToolTipText(WIDTH_TOOLTIP);
147
 
        configPanel.add(widthSpinner, "6, 4");
148
 
 
149
 
        JLabel lblPx_1 = new JLabel("px");
150
 
        configPanel.add(lblPx_1, "8, 4");
151
 
 
152
 
        JLabel lblHeight = new JLabel("Height");
153
 
        configPanel.add(lblHeight, "12, 4, 3, 1, right, center");
154
 
 
155
 
        heightSpinner = new JSpinner();
156
 
        heightSpinner.setToolTipText(HEIGHT_TOOLTIP);
157
 
        configPanel.add(heightSpinner, "16, 4");
158
 
 
159
 
        JLabel lblPx = new JLabel("px");
160
 
        configPanel.add(lblPx, "18, 4");
161
 
 
162
 
        JLabel lblSpacing = new JLabel("Spacing:");
163
 
        configPanel.add(lblSpacing, "4, 5, right, center");
164
 
 
165
 
        spacingSpinner = new JSpinner();
166
 
        spacingSpinner.setToolTipText(SPACING_TOOLTIP);
167
 
        configPanel.add(spacingSpinner, "6, 5");
168
 
 
169
 
        JLabel lblPx_2 = new JLabel("px");
170
 
        configPanel.add(lblPx_2, "8, 5");
171
 
 
172
 
        StringSeparator colorsSeparator = new StringSeparator("Colors");
173
 
        configPanel.add(colorsSeparator, "1, 6, 18, 1");
174
 
 
175
 
        JLabel lblNotes = new JLabel("Notes");
176
 
        configPanel.add(lblNotes, "2, 8, right, default");
177
 
 
178
 
        JLabel lblTop = new JLabel("Top:");
179
 
        configPanel.add(lblTop, "4, 8, right, center");
180
 
 
181
 
        btnTopColorNotes = new ColorButton(InfologClientProperties.noteTopColor);
182
 
        btnTopColorNotes.setToolTipText(NOTE_TOP_TOOLTIP);
183
 
        configPanel.add(btnTopColorNotes, "6, 8, fill, fill");
184
 
 
185
 
        JLabel lblBottom = new JLabel("Bottom:");
186
 
        configPanel.add(lblBottom, "12, 8, 3, 1, right, center");
187
 
 
188
 
        btnBottomColorNotes = new ColorButton(InfologClientProperties.noteBottomColor);
189
 
        btnBottomColorNotes.setToolTipText(NOTE_BOTTOM_TOOLTIP);
190
 
        configPanel.add(btnBottomColorNotes, "16, 8, fill, fill");
191
 
 
192
 
        JLabel lblTasks = new JLabel("Tasks");
193
 
        configPanel.add(lblTasks, "2, 10, right, default");
194
 
 
195
 
        JLabel lblTop_1 = new JLabel("Top:");
196
 
        configPanel.add(lblTop_1, "4, 10, right, center");
197
 
 
198
 
        btnTopColorTasks = new ColorButton(InfologClientProperties.taskTopColor);
199
 
        btnTopColorTasks.setToolTipText(TASK_TOP_TOOLTIP);
200
 
        configPanel.add(btnTopColorTasks, "6, 10, fill, fill");
201
 
 
202
 
        JLabel lblBottom_1 = new JLabel("Bottom:");
203
 
        configPanel.add(lblBottom_1, "12, 10, 3, 1, right, center");
204
 
 
205
 
        btnBottomColorTasks = new ColorButton(InfologClientProperties.taskBottomColor);
206
 
        btnBottomColorTasks.setToolTipText(TASK_BOTTOM_TOOLTIP);
207
 
        configPanel.add(btnBottomColorTasks, "16, 10, fill, fill");
208
 
 
209
 
        JLabel lblPhoneCalls = new JLabel("Phone Calls");
210
 
        configPanel.add(lblPhoneCalls, "2, 12, right, default");
211
 
 
212
 
        JLabel lblTop_2 = new JLabel("Top:");
213
 
        configPanel.add(lblTop_2, "4, 12, right, center");
214
 
 
215
 
        btnTopColorPhoneCalls = new ColorButton(InfologClientProperties.phoneTopColor);
216
 
        btnTopColorPhoneCalls.setToolTipText(PHONE_TOP_TOOLTIP);
217
 
        configPanel.add(btnTopColorPhoneCalls, "6, 12, fill, fill");
218
 
 
219
 
        JLabel lblBottom_2 = new JLabel("Bottom:");
220
 
        configPanel.add(lblBottom_2, "12, 12, 3, 1, right, center");
221
 
 
222
 
        btnBottomColorPhoneCalls = new ColorButton(InfologClientProperties.phoneBottomColor);
223
 
        btnBottomColorPhoneCalls.setToolTipText(PHONE_BOTTOM_TOOLTIP);
224
 
        configPanel.add(btnBottomColorPhoneCalls, "16, 12, fill, fill");
225
 
 
226
 
        StringSeparator behaviourSeparator = new StringSeparator("Mouse behaviour");
227
 
        configPanel.add(behaviourSeparator, "1, 14, 18, 1, fill, default");
228
 
 
229
 
        JLabel lblDragDelay = new JLabel("Drag delay: ");
230
 
        configPanel.add(lblDragDelay, "4, 16, right, center");
231
 
 
232
 
        dragDelaySpinner = new JSpinner();
233
 
        dragDelaySpinner.setToolTipText(DRAG_DELAY_TOOLTIP);
234
 
        configPanel.add(dragDelaySpinner, "6, 16");
235
 
 
236
 
        JLabel lblDoubleClickDelay = new JLabel("Double click delay:");
237
 
        configPanel.add(lblDoubleClickDelay, "10, 16, 5, 1, right, center");
238
 
 
239
 
        doubleClickDelaySpinner = new JSpinner();
240
 
        doubleClickDelaySpinner.setToolTipText(DOUBLE_CLICK_DELAY_TOOLTIP);
241
 
        configPanel.add(doubleClickDelaySpinner, "16, 16");
242
 
 
243
 
        StringSeparator iconSeparator = new StringSeparator("System tray icon");
244
 
        configPanel.add(iconSeparator, "1, 18, 18, 1");
245
 
 
246
 
        trayIconField = new JTextField();
247
 
        trayIconField.setToolTipText(SYSTRAY_TOOLTIP);
248
 
        configPanel.add(trayIconField, "2, 20, 11, 1, fill, default");
249
 
 
250
 
        JButton btnChooseIcon = new JButton("Choose file");
251
 
        btnChooseIcon.addActionListener(new ActionListener() {
252
 
            @Override
253
 
            public void actionPerformed(ActionEvent e) {
254
 
                JFileChooser fileChooser = new JFileChooser();
255
 
                int returnVal = fileChooser.showOpenDialog(GuiConfigDialog.this);
256
 
                if (returnVal == JFileChooser.APPROVE_OPTION) {
257
 
                    File file = fileChooser.getSelectedFile();
258
 
                    trayIconField.setText(file.getPath());
259
 
                }
260
 
            }
261
 
        });
262
 
        configPanel.add(btnChooseIcon, "14, 20, 3, 1, right, default");
263
 
 
264
 
        loadConfiguration();
265
 
        setFocus(btnCancel);
266
 
        setVisible(true);
267
 
    }
268
 
 
269
 
    private void loadConfiguration() {
270
 
        widthSpinner.setValue(InfologClientProperties.width);
271
 
        heightSpinner.setValue(InfologClientProperties.height);
272
 
        spacingSpinner.setValue(InfologClientProperties.spacing);
273
 
        dragDelaySpinner.setValue(InfologClientProperties.dragDelay);
274
 
        doubleClickDelaySpinner.setValue(InfologClientProperties.doubleClickDelay);
275
 
        trayIconField.setText(InfologClientProperties.trayIcon);
276
 
    }
277
 
 
278
 
    private void saveConfiguration() {
279
 
        new Thread() {
280
 
            @Override
281
 
            public void run() {
282
 
                Properties properties = Properties.getInstance();
283
 
                properties.setProperty("width", widthSpinner.getValue().toString());
284
 
                properties.setProperty("spacing", spacingSpinner.getValue().toString());
285
 
                properties.setProperty("height", heightSpinner.getValue().toString());
286
 
 
287
 
                properties.setProperty("notetopcolor", btnTopColorNotes.getPropertiesValue());
288
 
                properties.setProperty("notebottomcolor", btnBottomColorNotes.getPropertiesValue());
289
 
 
290
 
                properties.setProperty("tasktopcolor", btnTopColorTasks.getPropertiesValue());
291
 
                properties.setProperty("taskbottomcolor", btnBottomColorTasks.getPropertiesValue());
292
 
 
293
 
                properties.setProperty("phonetopcolor", btnTopColorPhoneCalls.getPropertiesValue());
294
 
                properties.setProperty("phonebottomcolor", btnBottomColorPhoneCalls.getPropertiesValue());
295
 
 
296
 
                properties.setProperty("dragdelay", dragDelaySpinner.getValue().toString());
297
 
                properties.setProperty("doubleclickdelay", doubleClickDelaySpinner.getValue().toString());
298
 
 
299
 
                properties.setProperty("systrayicon", trayIconField.getText());
300
 
 
301
 
                properties.save();
302
 
                applyConfiguration();
303
 
            }
304
 
 
305
 
        }.start();
306
 
    }
307
 
 
308
 
    private void applyConfiguration() {
309
 
        InfologClientProperties.width = (Integer) widthSpinner.getValue();
310
 
        InfologClientProperties.spacing = (Integer) spacingSpinner.getValue();
311
 
        InfologClientProperties.height = (Integer) heightSpinner.getValue();
312
 
 
313
 
        InfologClientProperties.noteTopColor = btnTopColorNotes.getColorValue();
314
 
        InfologClientProperties.noteBottomColor = btnBottomColorNotes.getColorValue();
315
 
 
316
 
        InfologClientProperties.taskTopColor = btnTopColorTasks.getColorValue();
317
 
        InfologClientProperties.taskBottomColor = btnBottomColorTasks.getColorValue();
318
 
 
319
 
        InfologClientProperties.phoneTopColor = btnTopColorPhoneCalls.getColorValue();
320
 
        InfologClientProperties.phoneBottomColor = btnBottomColorPhoneCalls.getColorValue();
321
 
 
322
 
        InfologClientProperties.dragDelay = (Integer) dragDelaySpinner.getValue();
323
 
        InfologClientProperties.doubleClickDelay = (Integer) doubleClickDelaySpinner.getValue();
324
 
 
325
 
        InfologClientProperties.trayIcon = trayIconField.getText();
326
 
 
327
 
        StickyNoteIcon.colorsRefreshed();
328
 
    }
329
 
 
330
 
    private void setDefaults() {
331
 
        widthSpinner.setValue(InfologClientProperties.DEFAULT_WIDTH);
332
 
        spacingSpinner.setValue(InfologClientProperties.DEFAULT_SPACING);
333
 
        heightSpinner.setValue(InfologClientProperties.DEFAULT_HEIGHT);
334
 
        btnTopColorNotes.setColor(InfologClientProperties.DEFAULT_NOTE_TOP_COLOR);
335
 
        btnBottomColorNotes.setColor(InfologClientProperties.DEFAULT_NOTE_BOTTOM_COLOR);
336
 
        btnTopColorTasks.setColor(InfologClientProperties.DEFAULT_TASK_TOP_COLOR);
337
 
        btnBottomColorTasks.setColor(InfologClientProperties.DEFAULT_TASK_BOTTOM_COLOR);
338
 
        btnTopColorPhoneCalls.setColor(InfologClientProperties.DEFAULT_PHONE_TOP_COLOR);
339
 
        btnBottomColorPhoneCalls.setColor(InfologClientProperties.DEFAULT_PHONE_BOTTOM_COLOR);
340
 
        dragDelaySpinner.setValue(InfologClientProperties.DEFAULT_DRAG_DELAY);
341
 
        doubleClickDelaySpinner.setValue(InfologClientProperties.DEFAULT_DOUBLE_CLICK_DELAY);
342
 
        trayIconField.setText(InfologClientProperties.DEFAULT_TRAY_ICON);
343
 
    }
344
 
 
345
 
    private void setFocus(final JComponent component) {
346
 
        SwingUtilities.invokeLater(new Runnable() {
347
 
            @Override
348
 
            public void run() {
349
 
                component.requestFocusInWindow();
350
 
            }
351
 
        });
352
 
    }
 
51
        private static final String TITLE = "Configure look and feel";
 
52
        private static final String WIDTH_TOOLTIP = "Width of a sticky note in px.";
 
53
        private static final String HEIGHT_TOOLTIP = "Height of a sticky note in px.";
 
54
        private static final String SYSTRAY_TOOLTIP = "Path to icon used in system tray (requires restart).";
 
55
        private static final String SPACING_TOOLTIP = "Offset in px. between sticky notes when layed out on the screen.";
 
56
        private static final String NOTE_BOTTOM_TOOLTIP = "Bottom color used for sticky notes of type 'note'.";
 
57
        private static final String NOTE_TOP_TOOLTIP = "Top color used for sticky notes of type 'note'.";
 
58
        private static final String PHONE_BOTTOM_TOOLTIP = "Bottom color used for sticky notes of type 'phone call'.";
 
59
        private static final String PHONE_TOP_TOOLTIP = "Top color used for sticky notes of type 'phone call'.";
 
60
        private static final String TASK_BOTTOM_TOOLTIP = "Bottom color used for sticky notes of type 'task'.";
 
61
        private static final String TASK_TOP_TOOLTIP = "Top color used for sticky notes of type 'task'.";
 
62
        private static final String DRAG_DELAY_TOOLTIP = "Threshold value to tweak the drag behaviour, higher values will delay the repaint events making it easier for slow graphic cards to keep up.";
 
63
        private static final String DOUBLE_CLICK_DELAY_TOOLTIP = "Delay in ms between two clicks to register as a double click.";
 
64
 
 
65
        private JSpinner widthSpinner;
 
66
        private JSpinner spacingSpinner;
 
67
        private JSpinner heightSpinner;
 
68
        private ColorButton btnTopColorNotes;
 
69
        private ColorButton btnTopColorTasks;
 
70
        private ColorButton btnTopColorPhoneCalls;
 
71
        private ColorButton btnBottomColorNotes;
 
72
        private ColorButton btnBottomColorTasks;
 
73
        private ColorButton btnBottomColorPhoneCalls;
 
74
        private JSpinner dragDelaySpinner;
 
75
        private JSpinner doubleClickDelaySpinner;
 
76
        private JTextField trayIconField;
 
77
 
 
78
        public GuiConfigDialog(JFrame parent) {
 
79
                super(parent, TITLE, true);
 
80
                setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
 
81
                setSize(850, 550);
 
82
 
 
83
                JPanel actionPanel = new JPanel();
 
84
                getContentPane().add(actionPanel, BorderLayout.SOUTH);
 
85
                actionPanel.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"),
 
86
                   FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
 
87
                   FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(40dlu;default)"),
 
88
                   FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
 
89
                   ColumnSpec.decode("max(40dlu;default)"), FormFactory.RELATED_GAP_COLSPEC,
 
90
                   ColumnSpec.decode("max(5dlu;default)"), }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC,
 
91
                   FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("max(5dlu;default)"), }));
 
92
 
 
93
                JButton btnCancel = new JButton("Cancel");
 
94
                btnCancel.addActionListener(new ActionListener() {
 
95
                        @Override
 
96
                        public void actionPerformed(ActionEvent e) {
 
97
                                setVisible(false);
 
98
                        }
 
99
                });
 
100
                actionPanel.add(btnCancel, "7, 1, 2, 1");
 
101
 
 
102
                JButton btnDefaults = new JButton("Load defaults");
 
103
                btnDefaults.addActionListener(new ActionListener() {
 
104
                        @Override
 
105
                        public void actionPerformed(ActionEvent e) {
 
106
                                setDefaults();
 
107
                        }
 
108
                });
 
109
                actionPanel.add(btnDefaults, "3, 1");
 
110
 
 
111
                JButton btnOk = new JButton("OK");
 
112
                btnOk.addActionListener(new ActionListener() {
 
113
                        @Override
 
114
                        public void actionPerformed(ActionEvent e) {
 
115
                                setVisible(false);
 
116
                                saveConfiguration();
 
117
                        }
 
118
                });
 
119
                actionPanel.add(btnOk, "11, 1, 2, 1");
 
120
 
 
121
                JPanel configPanel = new JPanel();
 
122
                getContentPane().add(configPanel, BorderLayout.CENTER);
 
123
                configPanel.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("max(61dlu;min):grow"),
 
124
                   ColumnSpec.decode("max(40dlu;default):grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("99px:grow"),
 
125
                   FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(30dlu;default)"), FormFactory.RELATED_GAP_COLSPEC,
 
126
                   FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
 
127
                   FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
 
128
                   ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(30dlu;default)"),
 
129
                   FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(30dlu;default)"), }, new RowSpec[] {
 
130
                   FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
 
131
                   FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
 
132
                   FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
 
133
                   FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
 
134
                   FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
 
135
                   FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
 
136
                   FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
 
137
                   FormFactory.DEFAULT_ROWSPEC, }));
 
138
 
 
139
                StringSeparator dimensionsSeparator = new StringSeparator("Dimensions");
 
140
                configPanel.add(dimensionsSeparator, "1, 2, 18, 1");
 
141
 
 
142
                JLabel lblWidth = new JLabel("Width");
 
143
                configPanel.add(lblWidth, "4, 4, right, center");
 
144
 
 
145
                widthSpinner = new JSpinner();
 
146
                widthSpinner.setToolTipText(WIDTH_TOOLTIP);
 
147
                configPanel.add(widthSpinner, "6, 4");
 
148
 
 
149
                JLabel lblPx_1 = new JLabel("px");
 
150
                configPanel.add(lblPx_1, "8, 4");
 
151
 
 
152
                JLabel lblHeight = new JLabel("Height");
 
153
                configPanel.add(lblHeight, "12, 4, 3, 1, right, center");
 
154
 
 
155
                heightSpinner = new JSpinner();
 
156
                heightSpinner.setToolTipText(HEIGHT_TOOLTIP);
 
157
                configPanel.add(heightSpinner, "16, 4");
 
158
 
 
159
                JLabel lblPx = new JLabel("px");
 
160
                configPanel.add(lblPx, "18, 4");
 
161
 
 
162
                JLabel lblSpacing = new JLabel("Spacing:");
 
163
                configPanel.add(lblSpacing, "4, 5, right, center");
 
164
 
 
165
                spacingSpinner = new JSpinner();
 
166
                spacingSpinner.setToolTipText(SPACING_TOOLTIP);
 
167
                configPanel.add(spacingSpinner, "6, 5");
 
168
 
 
169
                JLabel lblPx_2 = new JLabel("px");
 
170
                configPanel.add(lblPx_2, "8, 5");
 
171
 
 
172
                StringSeparator colorsSeparator = new StringSeparator("Colors");
 
173
                configPanel.add(colorsSeparator, "1, 6, 18, 1");
 
174
 
 
175
                JLabel lblNotes = new JLabel("Notes");
 
176
                configPanel.add(lblNotes, "2, 8, right, default");
 
177
 
 
178
                JLabel lblTop = new JLabel("Top:");
 
179
                configPanel.add(lblTop, "4, 8, right, center");
 
180
 
 
181
                btnTopColorNotes = new ColorButton(InfologClientProperties.noteTopColor);
 
182
                btnTopColorNotes.setToolTipText(NOTE_TOP_TOOLTIP);
 
183
                configPanel.add(btnTopColorNotes, "6, 8, fill, fill");
 
184
 
 
185
                JLabel lblBottom = new JLabel("Bottom:");
 
186
                configPanel.add(lblBottom, "12, 8, 3, 1, right, center");
 
187
 
 
188
                btnBottomColorNotes = new ColorButton(InfologClientProperties.noteBottomColor);
 
189
                btnBottomColorNotes.setToolTipText(NOTE_BOTTOM_TOOLTIP);
 
190
                configPanel.add(btnBottomColorNotes, "16, 8, fill, fill");
 
191
 
 
192
                JLabel lblTasks = new JLabel("Tasks");
 
193
                configPanel.add(lblTasks, "2, 10, right, default");
 
194
 
 
195
                JLabel lblTop_1 = new JLabel("Top:");
 
196
                configPanel.add(lblTop_1, "4, 10, right, center");
 
197
 
 
198
                btnTopColorTasks = new ColorButton(InfologClientProperties.taskTopColor);
 
199
                btnTopColorTasks.setToolTipText(TASK_TOP_TOOLTIP);
 
200
                configPanel.add(btnTopColorTasks, "6, 10, fill, fill");
 
201
 
 
202
                JLabel lblBottom_1 = new JLabel("Bottom:");
 
203
                configPanel.add(lblBottom_1, "12, 10, 3, 1, right, center");
 
204
 
 
205
                btnBottomColorTasks = new ColorButton(InfologClientProperties.taskBottomColor);
 
206
                btnBottomColorTasks.setToolTipText(TASK_BOTTOM_TOOLTIP);
 
207
                configPanel.add(btnBottomColorTasks, "16, 10, fill, fill");
 
208
 
 
209
                JLabel lblPhoneCalls = new JLabel("Phone Calls");
 
210
                configPanel.add(lblPhoneCalls, "2, 12, right, default");
 
211
 
 
212
                JLabel lblTop_2 = new JLabel("Top:");
 
213
                configPanel.add(lblTop_2, "4, 12, right, center");
 
214
 
 
215
                btnTopColorPhoneCalls = new ColorButton(InfologClientProperties.phoneTopColor);
 
216
                btnTopColorPhoneCalls.setToolTipText(PHONE_TOP_TOOLTIP);
 
217
                configPanel.add(btnTopColorPhoneCalls, "6, 12, fill, fill");
 
218
 
 
219
                JLabel lblBottom_2 = new JLabel("Bottom:");
 
220
                configPanel.add(lblBottom_2, "12, 12, 3, 1, right, center");
 
221
 
 
222
                btnBottomColorPhoneCalls = new ColorButton(InfologClientProperties.phoneBottomColor);
 
223
                btnBottomColorPhoneCalls.setToolTipText(PHONE_BOTTOM_TOOLTIP);
 
224
                configPanel.add(btnBottomColorPhoneCalls, "16, 12, fill, fill");
 
225
 
 
226
                StringSeparator behaviourSeparator = new StringSeparator("Mouse behaviour");
 
227
                configPanel.add(behaviourSeparator, "1, 14, 18, 1, fill, default");
 
228
 
 
229
                JLabel lblDragDelay = new JLabel("Drag delay: ");
 
230
                configPanel.add(lblDragDelay, "4, 16, right, center");
 
231
 
 
232
                dragDelaySpinner = new JSpinner();
 
233
                dragDelaySpinner.setToolTipText(DRAG_DELAY_TOOLTIP);
 
234
                configPanel.add(dragDelaySpinner, "6, 16");
 
235
 
 
236
                JLabel lblDoubleClickDelay = new JLabel("Double click delay:");
 
237
                configPanel.add(lblDoubleClickDelay, "10, 16, 5, 1, right, center");
 
238
 
 
239
                doubleClickDelaySpinner = new JSpinner();
 
240
                doubleClickDelaySpinner.setToolTipText(DOUBLE_CLICK_DELAY_TOOLTIP);
 
241
                configPanel.add(doubleClickDelaySpinner, "16, 16");
 
242
 
 
243
                StringSeparator iconSeparator = new StringSeparator("System tray icon");
 
244
                configPanel.add(iconSeparator, "1, 18, 18, 1");
 
245
 
 
246
                trayIconField = new JTextField();
 
247
                trayIconField.setToolTipText(SYSTRAY_TOOLTIP);
 
248
                configPanel.add(trayIconField, "2, 20, 11, 1, fill, default");
 
249
 
 
250
                JButton btnChooseIcon = new JButton("Choose file");
 
251
                btnChooseIcon.addActionListener(new ActionListener() {
 
252
                        @Override
 
253
                        public void actionPerformed(ActionEvent e) {
 
254
                                JFileChooser fileChooser = new JFileChooser();
 
255
                                int returnVal = fileChooser.showOpenDialog(GuiConfigDialog.this);
 
256
                                if (returnVal == JFileChooser.APPROVE_OPTION) {
 
257
                                        File file = fileChooser.getSelectedFile();
 
258
                                        trayIconField.setText(file.getPath());
 
259
                                }
 
260
                        }
 
261
                });
 
262
                configPanel.add(btnChooseIcon, "14, 20, 3, 1, right, default");
 
263
 
 
264
                loadConfiguration();
 
265
                setFocus(btnCancel);
 
266
                setVisible(true);
 
267
        }
 
268
 
 
269
        private void loadConfiguration() {
 
270
                widthSpinner.setValue(InfologClientProperties.width);
 
271
                heightSpinner.setValue(InfologClientProperties.height);
 
272
                spacingSpinner.setValue(InfologClientProperties.spacing);
 
273
                dragDelaySpinner.setValue(InfologClientProperties.dragDelay);
 
274
                doubleClickDelaySpinner.setValue(InfologClientProperties.doubleClickDelay);
 
275
                trayIconField.setText(InfologClientProperties.trayIcon);
 
276
        }
 
277
 
 
278
        private void saveConfiguration() {
 
279
                new Thread() {
 
280
                        @Override
 
281
                        public void run() {
 
282
                                Properties properties = Properties.getInstance();
 
283
                                properties.setProperty("width", widthSpinner.getValue().toString());
 
284
                                properties.setProperty("spacing", spacingSpinner.getValue().toString());
 
285
                                properties.setProperty("height", heightSpinner.getValue().toString());
 
286
 
 
287
                                properties.setProperty("notetopcolor", btnTopColorNotes.getPropertiesValue());
 
288
                                properties.setProperty("notebottomcolor", btnBottomColorNotes.getPropertiesValue());
 
289
 
 
290
                                properties.setProperty("tasktopcolor", btnTopColorTasks.getPropertiesValue());
 
291
                                properties.setProperty("taskbottomcolor", btnBottomColorTasks.getPropertiesValue());
 
292
 
 
293
                                properties.setProperty("phonetopcolor", btnTopColorPhoneCalls.getPropertiesValue());
 
294
                                properties.setProperty("phonebottomcolor", btnBottomColorPhoneCalls.getPropertiesValue());
 
295
 
 
296
                                properties.setProperty("dragdelay", dragDelaySpinner.getValue().toString());
 
297
                                properties.setProperty("doubleclickdelay", doubleClickDelaySpinner.getValue().toString());
 
298
 
 
299
                                properties.setProperty("systrayicon", trayIconField.getText());
 
300
 
 
301
                                properties.save();
 
302
                                applyConfiguration();
 
303
                        }
 
304
 
 
305
                }.start();
 
306
        }
 
307
 
 
308
        private void applyConfiguration() {
 
309
                InfologClientProperties.width = (Integer) widthSpinner.getValue();
 
310
                InfologClientProperties.spacing = (Integer) spacingSpinner.getValue();
 
311
                InfologClientProperties.height = (Integer) heightSpinner.getValue();
 
312
 
 
313
                InfologClientProperties.noteTopColor = btnTopColorNotes.getColorValue();
 
314
                InfologClientProperties.noteBottomColor = btnBottomColorNotes.getColorValue();
 
315
 
 
316
                InfologClientProperties.taskTopColor = btnTopColorTasks.getColorValue();
 
317
                InfologClientProperties.taskBottomColor = btnBottomColorTasks.getColorValue();
 
318
 
 
319
                InfologClientProperties.phoneTopColor = btnTopColorPhoneCalls.getColorValue();
 
320
                InfologClientProperties.phoneBottomColor = btnBottomColorPhoneCalls.getColorValue();
 
321
 
 
322
                InfologClientProperties.dragDelay = (Integer) dragDelaySpinner.getValue();
 
323
                InfologClientProperties.doubleClickDelay = (Integer) doubleClickDelaySpinner.getValue();
 
324
 
 
325
                InfologClientProperties.trayIcon = trayIconField.getText();
 
326
 
 
327
                StickyNoteIcon.colorsRefreshed();
 
328
        }
 
329
 
 
330
        private void setDefaults() {
 
331
                widthSpinner.setValue(InfologClientProperties.DEFAULT_WIDTH);
 
332
                spacingSpinner.setValue(InfologClientProperties.DEFAULT_SPACING);
 
333
                heightSpinner.setValue(InfologClientProperties.DEFAULT_HEIGHT);
 
334
                btnTopColorNotes.setColor(InfologClientProperties.DEFAULT_NOTE_TOP_COLOR);
 
335
                btnBottomColorNotes.setColor(InfologClientProperties.DEFAULT_NOTE_BOTTOM_COLOR);
 
336
                btnTopColorTasks.setColor(InfologClientProperties.DEFAULT_TASK_TOP_COLOR);
 
337
                btnBottomColorTasks.setColor(InfologClientProperties.DEFAULT_TASK_BOTTOM_COLOR);
 
338
                btnTopColorPhoneCalls.setColor(InfologClientProperties.DEFAULT_PHONE_TOP_COLOR);
 
339
                btnBottomColorPhoneCalls.setColor(InfologClientProperties.DEFAULT_PHONE_BOTTOM_COLOR);
 
340
                dragDelaySpinner.setValue(InfologClientProperties.DEFAULT_DRAG_DELAY);
 
341
                doubleClickDelaySpinner.setValue(InfologClientProperties.DEFAULT_DOUBLE_CLICK_DELAY);
 
342
                trayIconField.setText(InfologClientProperties.DEFAULT_TRAY_ICON);
 
343
        }
 
344
 
 
345
        private void setFocus(final JComponent component) {
 
346
                SwingUtilities.invokeLater(new Runnable() {
 
347
                        @Override
 
348
                        public void run() {
 
349
                                component.requestFocusInWindow();
 
350
                        }
 
351
                });
 
352
        }
353
353
}