1 /* Copyright (c) 2002-2013 The University of the West Indies
2  *
3  * Contact: robert.lancashire@uwimona.edu.jm
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2.1 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package jspecview.application;
21 
22 import java.awt.BorderLayout;
23 
24 
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.Frame;
28 import java.awt.GraphicsEnvironment;
29 import java.awt.GridBagConstraints;
30 import java.awt.GridBagLayout;
31 import java.awt.GridLayout;
32 import java.awt.Insets;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.util.Map;
36 import java.util.Properties;
37 import java.util.TreeMap;
38 
39 
40 import javajs.util.CU;
41 
42 import javax.swing.BorderFactory;
43 import javax.swing.ButtonGroup;
44 import javax.swing.DefaultListModel;
45 import javax.swing.JButton;
46 import javax.swing.JCheckBox;
47 import javax.swing.JColorChooser;
48 import javax.swing.JComboBox;
49 import javax.swing.JDialog;
50 import javax.swing.JLabel;
51 import javax.swing.JList;
52 import javax.swing.JOptionPane;
53 import javax.swing.JPanel;
54 import javax.swing.JRadioButton;
55 import javax.swing.JScrollPane;
56 import javax.swing.JTabbedPane;
57 import javax.swing.JTextField;
58 import javax.swing.ListSelectionModel;
59 import javax.swing.border.TitledBorder;
60 import javax.swing.event.ListSelectionEvent;
61 import javax.swing.event.ListSelectionListener;
62 
63 import jspecview.common.ColorParameters;
64 import jspecview.common.JSViewer;
65 import jspecview.common.ScriptToken;
66 import jspecview.exception.JSVException;
67 import jspecview.java.AwtColor;
68 import jspecview.java.AwtPanel;
69 import jspecview.java.AwtParameters;
70 import jspecview.source.JDXReader;
71 import jspecview.source.JDXSource;
72 import java.awt.Font;
73 import javax.swing.UIManager;
74 import javax.swing.JSeparator;
75 
76 /**
77  * Dialog to change the preferences for the application.
78  * @author Debbie-Ann Facey
79  * @author Khari A. Bryan
80  * @author Prof Robert J. Lancashire
81  */
82 
83 public class PreferencesDialog extends JDialog implements ActionListener {
84   /**
85    *
86    */
87   private static final long serialVersionUID = 1L;
88   JPanel contentpanel = new JPanel();
89   BorderLayout contentBorderLayout = new BorderLayout();
90   JTabbedPane preferencesTabbedPane = new JTabbedPane();
91   JPanel generalPanel = new JPanel();
92   JPanel displayPanel = new JPanel();
93   TitledBorder fontTitledBorder;
94   TitledBorder contentTitledBorder;
95   JCheckBox confirmExitCheckBox = new JCheckBox();
96   JCheckBox statusBarCheckBox = new JCheckBox();
97   JCheckBox toolbarCheckBox = new JCheckBox();
98   JCheckBox sidePanelCheckBox = new JCheckBox();
99   JCheckBox exportDirCheckBox = new JCheckBox();
100   JCheckBox openedDirCheckBox = new JCheckBox();
101   JCheckBox legendCheckBox = new JCheckBox();
102   JCheckBox overlayCheckBox = new JCheckBox();
103   JButton clearRecentButton = new JButton();
104   JButton cancelButton = new JButton();
105   JPanel buttonPanel = new JPanel();
106   JButton okButton = new JButton();
107   private BorderLayout borderLayout6 = new BorderLayout();
108   private DefaultListModel<String> elModel = new DefaultListModel<String>();
109   private JPanel topPanel = new JPanel();
110   private JPanel displayFontPanel = new JPanel();
111   private JPanel colorSchemePanel = new JPanel();
112   private JPanel elementPanel = new JPanel();
113   private JLabel elementLabel = new JLabel();
114   private GridBagLayout gridBagLayout1 = new GridBagLayout();
115   private JCheckBox defaultFontCheckBox = new JCheckBox();
116   private JComboBox<String> fontComboBox = new JComboBox<String>();
117   private GridBagLayout gridBagLayout2 = new GridBagLayout();
118   private JPanel colorPanel = new JPanel();
119   private JComboBox<String> schemeComboBox = new JComboBox<String>();
120   private GridLayout gridLayout1 = new GridLayout();
121   private JCheckBox defaultColorCheckBox = new JCheckBox();
122   private JButton customButton = new JButton();
123   private GridBagLayout gridBagLayout3 = new GridBagLayout();
124   private JScrollPane listScrollPane = new JScrollPane();
125   JList<String> elementList = new JList<String>();
126   private JButton colorButton8 = new JButton();
127   private JButton colorButton7 = new JButton();
128   private JButton colorButton6 = new JButton();
129   private JButton colorButton5 = new JButton();
130   private JButton colorButton4 = new JButton();
131   private JButton colorButton3 = new JButton();
132   private JButton colorButton2 = new JButton();
133   private JButton colorButton1 = new JButton();
134   JButton currentColorButton = new JButton();
135   private JPanel processingPanel = new JPanel();
136   private GridBagLayout gridBagLayout4 = new GridBagLayout();
137   private JButton saveButton = new JButton();
138   private GridBagLayout gridBagLayout5 = new GridBagLayout();
139   private JPanel integrationPanel = new JPanel();
140   private JPanel absTransPanel = new JPanel();
141   private GridBagLayout gridBagLayout6 = new GridBagLayout();
142   private TitledBorder integratinTitledBorder;
143   private JLabel jLabel1 = new JLabel();
144   private JTextField minYTextField = new JTextField();
145   private JLabel jLabel2 = new JLabel();
146   private JTextField integFactorTextField = new JTextField();
147   private JLabel jLabel3 = new JLabel();
148   private JLabel jLabel4 = new JLabel();
149   private JButton processingCustomButton = new JButton();
150   private JCheckBox autoIntegrateCheckBox = new JCheckBox();
151   private JTextField integOffsetTextField = new JTextField();
152   private TitledBorder absTransTitledBorder;
153   private JCheckBox separateWindowCheckBox = new JCheckBox();
154   //private ButtonGroup fontButtonGroup = new ButtonGroup();
155   private JLabel jLabel5 = new JLabel();
156   private JLabel jLabel6 = new JLabel();
157   private JLabel jLabel7 = new JLabel();
158   private GridBagLayout gridBagLayout7 = new GridBagLayout();
159   private JRadioButton TtoARadioButton = new JRadioButton();
160   private JRadioButton AtoTRadioButton = new JRadioButton();
161   private ButtonGroup conversionButtonGroup = new ButtonGroup();
162 
163   ColorParameters currentDS = (ColorParameters) new AwtParameters().setName("Current");
164   private DisplaySchemesProcessor dsp;
165   private AwtPanel previewPanel = null;
166   private String defaultDSName = "";
167   private JLabel jLabel8 = new JLabel();
168   private JLabel jLabel9 = new JLabel();
169   //private JColorChooser cc = new JColorChooser();
170   private JCheckBox AutoConvertCheckBox = new JCheckBox();
171   //private boolean clearRecentFiles = false;
172   JButton plotColorButton = new JButton();
173   private JPanel colorPanel1 = new JPanel();
174   private JButton procColorButton8 = new JButton();
175   private JButton procColorButton7 = new JButton();
176   private JButton procColorButton6 = new JButton();
177   private JButton procColorButton5 = new JButton();
178   private JButton procColorButton4 = new JButton();
179   private JButton procColorButton3 = new JButton();
180   private JButton procColorButton2 = new JButton();
181   private GridLayout gridLayout2 = new GridLayout();
182   private JButton procColorButton1 = new JButton();
183 
184   private JCheckBox gridCheckBox = new JCheckBox();
185   private JCheckBox coordinatesCheckBox = new JCheckBox();
186   private JCheckBox scaleXCheckBox = new JCheckBox();
187   private JCheckBox svgForInkscapeCheckBox = new JCheckBox();
188   private JPanel applicationPanel;
189   private JPanel uiPanel;
190   private final JPanel spectrumPanel = new JPanel();
191   private final JCheckBox spectrumDisplayApplyNowCheckBox = new JCheckBox("Apply to currently opened spectra");
192 
193 
194   private Properties preferences;
195   private boolean isSpectrumDisplayApplyNowEnabled = false;
196   private final JCheckBox scaleYCheckBox = new JCheckBox();
197   private final JPanel panel = new JPanel();
198   private final JButton deleteButton = new JButton("Delete Scheme");
199 
200   /**
201    * Initialises the <code>PreferencesDialog</code>
202    * @param frame the the parent frame
203    * @param viewer
204    * @param title the title
205    * @param modal the modality
206    * @param dsp an instance of <code>DisplaySchemesProcessor</code>
207    */
PreferencesDialog(Frame frame, JSViewer viewer, String title, boolean modal, DisplaySchemesProcessor dsp)208   public PreferencesDialog(Frame frame, JSViewer viewer, String title, boolean modal,
209                            DisplaySchemesProcessor dsp) {
210     super(frame, title, modal);
211     setSize(new Dimension(480, 571));
212 
213     setLocationRelativeTo(frame);
214 
215     preferences = viewer.properties;
216     this.dsp = dsp;
217 
218     elModel.addElement("Title");
219     elModel.addElement("Plot");
220     elModel.addElement("Scale");
221     elModel.addElement("Units");
222     elModel.addElement("Coordinates");
223     elModel.addElement("PlotArea");
224     elModel.addElement("Background");
225     elModel.addElement("Grid");
226 
227 
228 
229     try {
230       jbInit();
231       if(dsp != null){
232         initDisplayTab(viewer);
233       }
234     }
235     catch(Exception ex) {
236       ex.printStackTrace();
237     }
238 
239     initProcessingTab();
240     initGeneralTab();
241 
242     elementList.addListSelectionListener(new ElementListSelectionListener());
243     elementList.getSelectionModel().setSelectionInterval(0, 0);
244 
245     setVisible(true);
246   }
247 
248   /**
249    * Initialises GUI components
250    * @throws Exception
251    */
jbInit()252   void jbInit() throws Exception {
253     fontTitledBorder = new TitledBorder("");
254     contentTitledBorder = new TitledBorder("");
255     integratinTitledBorder = new TitledBorder("");
256     absTransTitledBorder = new TitledBorder("");
257     contentpanel.setLayout(contentBorderLayout);
258     fontTitledBorder.setTitle("Font");
259     fontTitledBorder.setTitleJustification(2);
260     contentTitledBorder.setTitle("Content");
261     contentTitledBorder.setTitleJustification(2);
262     gridCheckBox.setToolTipText("");
263     gridCheckBox.setText("Show grid");
264     coordinatesCheckBox.setText("Show coordinates");
265     scaleXCheckBox.setText("Show X scale");
266     svgForInkscapeCheckBox.setText("SVG export for Inkscape");
267     generalPanel.setBorder(BorderFactory.createEtchedBorder());
268     statusBarCheckBox.setText("Show status bar");
269     toolbarCheckBox.setText("Show toolbar");
270     exportDirCheckBox.setText("Remember directory of last exported file");
271     openedDirCheckBox.setText("Remember directory of last opened file");
272     legendCheckBox.setText("Automatically show legend when spectra are overlaid");
273     confirmExitCheckBox.setText("Confirm before exiting");
274     sidePanelCheckBox.setText("Show side panel");
275 
276     applicationPanel = new JPanel();
277     applicationPanel.setLayout(null);
278     applicationPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Application", TitledBorder.CENTER, TitledBorder.TOP, null, Color.BLACK));
279     applicationPanel.setBounds(12, 5, 437, 157);
280     generalPanel.add(applicationPanel);
281 
282     uiPanel = new JPanel();
283     uiPanel.setLayout(null);
284     uiPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "User Interface", TitledBorder.CENTER, TitledBorder.TOP, null, Color.BLACK));
285     uiPanel.setBounds(12, 164, 437, 101);
286     generalPanel.add(uiPanel);
287 
288     confirmExitCheckBox.setBounds(6, 19, 133, 23);
289     applicationPanel.add(confirmExitCheckBox);
290     openedDirCheckBox.setBounds(6, 45, 211, 23);
291     applicationPanel.add(openedDirCheckBox);
292     exportDirCheckBox.setBounds(6, 71, 219, 23);
293     applicationPanel.add(exportDirCheckBox);
294     svgForInkscapeCheckBox.setBounds(6, 97, 143, 23);
295     applicationPanel.add(svgForInkscapeCheckBox);
296     clearRecentButton.setBounds(6, 127, 119, 23);
297     applicationPanel.add(clearRecentButton);
298     clearRecentButton.setText("Clear Recent Files");
299     overlayCheckBox.setBounds(6, 150, 241, 23);
300     spectrumPanel.add(overlayCheckBox);
301     legendCheckBox.setBounds(6, 126, 291, 23);
302     spectrumPanel.add(legendCheckBox);
303     gridCheckBox.setBounds(6, 22, 73, 23);
304     spectrumPanel.add(gridCheckBox);
305     scaleXCheckBox.setBounds(6, 48, 97, 23);
306     spectrumPanel.add(scaleXCheckBox);
307     coordinatesCheckBox.setBounds(142, 22, 111, 23);
308     spectrumPanel.add(coordinatesCheckBox);
309 
310 
311     clearRecentButton.addActionListener(new java.awt.event.ActionListener() {
312       @Override
313 			public void actionPerformed(ActionEvent e) {
314         clearRecentButton_actionPerformed(e);
315       }
316     });
317 
318     sidePanelCheckBox.setBounds(6, 21, 103, 23);
319     uiPanel.add(sidePanelCheckBox);
320     toolbarCheckBox.setBounds(6, 47, 89, 23);
321     uiPanel.add(toolbarCheckBox);
322     statusBarCheckBox.setBounds(6, 73, 114, 23);
323     uiPanel.add(statusBarCheckBox);
324     cancelButton.setText("Cancel");
325     cancelButton.addActionListener(new java.awt.event.ActionListener() {
326       @Override
327 			public void actionPerformed(ActionEvent e) {
328         cancelButton_actionPerformed(e);
329       }
330     });
331     okButton.setText("OK");
332     okButton.addActionListener(new java.awt.event.ActionListener() {
333       @Override
334 			public void actionPerformed(ActionEvent e) {
335         okButton_actionPerformed(e);
336       }
337     });
338     displayPanel.setLayout(borderLayout6);
339     gridBagLayout4.rowWeights = new double[]{0.0, 1.0};
340     gridBagLayout4.columnWeights = new double[]{0.0, 0.0, 1.0};
341     topPanel.setLayout(gridBagLayout4);
342     elementPanel.setBorder(BorderFactory.createEtchedBorder());
343     elementPanel.setLayout(gridBagLayout1);
344     colorSchemePanel.setBorder(BorderFactory.createEtchedBorder());
345     colorSchemePanel.setLayout(gridBagLayout3);
346     displayFontPanel.setBorder(BorderFactory.createEtchedBorder());
347     displayFontPanel.setLayout(gridBagLayout2);
348     elementLabel.setText("Element:");
349     defaultFontCheckBox.setText("Use Default");
350     defaultFontCheckBox.addActionListener(new java.awt.event.ActionListener() {
351       @Override
352 			public void actionPerformed(ActionEvent e) {
353         defaultFontCheckBox_actionPerformed(e);
354       }
355     });
356     colorPanel.setLayout(gridLayout1);
357     schemeComboBox.setMaximumSize(new Dimension(200, 21));
358     schemeComboBox.addActionListener(new java.awt.event.ActionListener() {
359       @Override
360 			public void actionPerformed(ActionEvent e) {
361         schemeComboBox_actionPerformed(e);
362       }
363     });
364     gridLayout1.setHgap(2);
365     gridLayout1.setRows(2);
366     gridLayout1.setVgap(2);
367     defaultColorCheckBox.setText("Use Default");
368     defaultColorCheckBox.addActionListener(new java.awt.event.ActionListener() {
369       @Override
370 			public void actionPerformed(ActionEvent e) {
371         defaultColorCheckBox_actionPerformed(e);
372       }
373     });
374     customButton.setText("Custom...");
375     customButton.addActionListener(new java.awt.event.ActionListener() {
376       @Override
377 			public void actionPerformed(ActionEvent e) {
378         customButton_actionPerformed(e);
379       }
380     });
381     elementList.setToolTipText("");
382     elementList.setModel(elModel);
383     elementList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
384     elementList.setVisibleRowCount(4);
385     listScrollPane.setMinimumSize(new Dimension(125, 110));
386     listScrollPane.setPreferredSize(new Dimension(125, 110));
387     addColorButton(colorButton1, Color.black);
388     addColorButton(colorButton2, Color.white);
389     addColorButton(colorButton3, Color.gray);
390     addColorButton(colorButton4, Color.blue);
391     addColorButton(colorButton5, Color.red);
392     addColorButton(colorButton6, new Color(0, 0, 64));
393     addColorButton(colorButton7, new Color(0, 92, 0));
394     addColorButton(colorButton8, Color.magenta);
395     colorButton3.setText(" ");
396         currentColorButton.setBorder(BorderFactory.createLoweredBevelBorder());
397     currentColorButton.setMaximumSize(new Dimension(50, 11));
398     currentColorButton.setMinimumSize(new Dimension(50, 11));
399     currentColorButton.setPreferredSize(new Dimension(50, 11));
400     currentColorButton.setMnemonic('0');
401     processingPanel.setLayout(gridBagLayout5);
402     integrationPanel.setLayout(gridBagLayout6);
403     integrationPanel.setBorder(integratinTitledBorder);
404     integratinTitledBorder.setTitle("Integration");
405     integratinTitledBorder.setTitleJustification(2);
406     jLabel1.setText("Integral Factor");
407     jLabel2.setText("Minimum Y");
408     jLabel3.setText("Integral Offset");
409     jLabel4.setText("Plot Color");
410     processingCustomButton.setPreferredSize(new Dimension(87, 21));
411     processingCustomButton.setText("Custom...");
412     processingCustomButton.addActionListener(new java.awt.event.ActionListener() {
413       @Override
414 			public void actionPerformed(ActionEvent e) {
415         processingCustomButton_actionPerformed(e);
416       }
417     });
418     autoIntegrateCheckBox.setText("Automatically Integrate HNMR Spectra");
419     minYTextField.setMinimumSize(new Dimension(40, 21));
420     minYTextField.setPreferredSize(new Dimension(40, 21));
421     integFactorTextField.setMinimumSize(new Dimension(40, 21));
422     integFactorTextField.setPreferredSize(new Dimension(40, 21));
423     integOffsetTextField.setMinimumSize(new Dimension(40, 21));
424     integOffsetTextField.setPreferredSize(new Dimension(40, 21));
425     absTransPanel.setBorder(absTransTitledBorder);
426     absTransPanel.setLayout(gridBagLayout7);
427     absTransTitledBorder.setTitle("Absorbance/Transmittance");
428     absTransTitledBorder.setTitleJustification(2);
429     separateWindowCheckBox.setEnabled(false);
430     separateWindowCheckBox.setText("Show converted Spectrum in a separate window");
431     jLabel5.setText("%");
432     jLabel6.setText("%");
433     jLabel7.setText("%");
434     TtoARadioButton.setSelected(true);
435     TtoARadioButton.setText("Transmittance to Absorbance");
436     AtoTRadioButton.setText("Absorbance to Transmittance");
437     colorPanel.setBorder(BorderFactory.createRaisedBevelBorder());
438     jLabel8.setText("Color Scheme:");
439     jLabel9.setText("Font:");
440     fontComboBox.addActionListener(new java.awt.event.ActionListener() {
441       @Override
442 			public void actionPerformed(ActionEvent e) {
443         fontComboBox_actionPerformed(e);
444       }
445     });
446     AutoConvertCheckBox.setToolTipText("");
447     AutoConvertCheckBox.setText("Automatically Convert");
448     plotColorButton.setBackground(Color.green);
449     plotColorButton.setBorder(null);
450     plotColorButton.setPreferredSize(new Dimension(30, 21));
451     colorPanel1.setBorder(BorderFactory.createRaisedBevelBorder());
452     colorPanel1.setLayout(gridLayout2);
453 
454     addProcColorButton(procColorButton1, Color.black);
455     addProcColorButton(procColorButton2, Color.white);
456     addProcColorButton(procColorButton3, Color.gray);
457     addProcColorButton(procColorButton4, Color.blue);
458     addProcColorButton(procColorButton5, Color.red);
459     addProcColorButton(procColorButton6, new Color(0, 0, 64));
460     addProcColorButton(procColorButton7, new Color(0, 92, 0));
461     addProcColorButton(procColorButton8, Color.magenta);
462 
463     gridLayout2.setHgap(2);
464     gridLayout2.setRows(2);
465     gridLayout2.setVgap(2);
466 
467     displayFontPanel.add(fontComboBox,                    new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
468             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
469     displayFontPanel.add(defaultFontCheckBox,                  new GridBagConstraints(0, 2, 1, 1, 0.0, 1.0
470             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 5, 0, 0), 0, 0));
471     displayFontPanel.add(jLabel9,      new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
472             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 5));
473     getContentPane().add(contentpanel);
474     contentpanel.add(preferencesTabbedPane, BorderLayout.CENTER);
475     preferencesTabbedPane.add(generalPanel,   "General");
476     preferencesTabbedPane.add(displayPanel,     "Display Scheme");
477     displayPanel.add(topPanel,  BorderLayout.NORTH);
478     topPanel.add(elementPanel,    new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
479             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 13, 0));
480     elementPanel.add(listScrollPane,          new GridBagConstraints(0, 1, 1, 1, 0.0, 1.0
481             ,GridBagConstraints.NORTH, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
482     listScrollPane.setViewportView(elementList);
483     elementPanel.add(elementLabel,           new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
484             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 5, 0), 0, 0));
485     colorSchemePanel.add(schemeComboBox,          new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
486             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
487     colorSchemePanel.add(defaultColorCheckBox,  new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
488             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
489     colorSchemePanel.add(customButton,         new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
490             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
491     colorSchemePanel.add(colorPanel,         new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0
492             ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 5), 0, 0));
493     colorSchemePanel.add(currentColorButton,        new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
494             ,GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), -16, 0));
495     colorSchemePanel.add(jLabel8,    new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
496             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 5));
497     topPanel.add(colorSchemePanel,    new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0
498             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 10, 5, 5), 8, 17));
499     topPanel.add(displayFontPanel,    new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0
500             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 10, 5, 1), 8, 36));
501     preferencesTabbedPane.add(processingPanel,  "Processing");
502     processingPanel.add(integrationPanel,            new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
503             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 10, 0), 0, 30));
504     contentpanel.add(buttonPanel,  BorderLayout.SOUTH);
505     buttonPanel.add(okButton, null);
506     buttonPanel.add(cancelButton, null);
507     generalPanel.setLayout(null);
508     spectrumPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Default Spectrum Display Settings", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 0, 0)));
509     spectrumPanel.setBounds(12, 266, 437, 184);
510 
511     generalPanel.add(spectrumPanel);
512     spectrumPanel.setLayout(null);
513     overlayCheckBox.setText("Show compound files as overlaid if possible");
514 
515     JLabel lblTheFollowingProperties = new JLabel("The spectrum display properties above will apply for new spectra");
516     lblTheFollowingProperties.setFont(new Font("Tahoma", Font.ITALIC, 11));
517     lblTheFollowingProperties.setForeground(Color.DARK_GRAY);
518     lblTheFollowingProperties.setBounds(6, 74, 389, 14);
519     spectrumPanel.add(lblTheFollowingProperties);
520     spectrumDisplayApplyNowCheckBox.setFont(new Font("Tahoma", Font.ITALIC, 11));
521     spectrumDisplayApplyNowCheckBox.setForeground(Color.DARK_GRAY);
522     spectrumDisplayApplyNowCheckBox.setBounds(6, 87, 220, 23);
523 
524     spectrumPanel.add(spectrumDisplayApplyNowCheckBox);
525     scaleYCheckBox.setText("Show Y scale");
526     scaleYCheckBox.setSelected(false);
527     scaleYCheckBox.setBounds(142, 48, 105, 23);
528 
529     spectrumPanel.add(scaleYCheckBox);
530 
531     JSeparator separator = new JSeparator();
532     separator.setBounds(6, 117, 421, 2);
533     spectrumPanel.add(separator);
534 
535     GridBagConstraints gbc_panel = new GridBagConstraints();
536     gbc_panel.gridwidth = 5;
537     gbc_panel.fill = GridBagConstraints.BOTH;
538     gbc_panel.gridx = 0;
539     gbc_panel.gridy = 1;
540     topPanel.add(panel, gbc_panel);
541     panel.add(saveButton);
542     saveButton.setText("Save Scheme");
543     deleteButton.addActionListener(new ActionListener() {
544     	@Override
545 			public void actionPerformed(ActionEvent arg0) {
546     		deleteButton_actionPerformed(arg0);
547     	}
548     });
549 
550     panel.add(deleteButton);
551     saveButton.addActionListener(new java.awt.event.ActionListener() {
552       @Override
553 			public void actionPerformed(ActionEvent e) {
554         saveButton_actionPerformed(e);
555       }
556     });
557     processingPanel.add(absTransPanel,      new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
558             ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
559     integrationPanel.add(jLabel2,                              new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
560             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 10, 0), 0, 0));
561     integrationPanel.add(jLabel1,                  new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
562             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 10, 0), 0, 0));
563     integrationPanel.add(autoIntegrateCheckBox,                   new GridBagConstraints(0, 5, 4, 1, 0.0, 1.0
564             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(10, 5, 0, 0), 0, 0));
565     integrationPanel.add(minYTextField,                     new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
566             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 0), 0, 0));
567     integrationPanel.add(integFactorTextField,              new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
568             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 0), 0, 0));
569     integrationPanel.add(jLabel3,           new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
570             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
571     integrationPanel.add(integOffsetTextField,            new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
572             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 50, 0, 0), 0, 0));
573     integrationPanel.add(jLabel5,         new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0
574             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
575     integrationPanel.add(jLabel6,        new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
576             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
577     integrationPanel.add(jLabel7,        new GridBagConstraints(2, 2, 1, 2, 0.0, 0.0
578             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
579     integrationPanel.add(colorPanel1,            new GridBagConstraints(2, 3, 1, 1, 1.0, 0.0
580             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
581     integrationPanel.add(jLabel4,    new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
582             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0));
583     integrationPanel.add(processingCustomButton,        new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
584             ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
585     integrationPanel.add(plotColorButton,                new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
586             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 50, 0, 0), 0, 0));
587     absTransPanel.add(separateWindowCheckBox,        new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0
588             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 147, 0));
589     absTransPanel.add(TtoARadioButton,     new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
590             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0));
591     absTransPanel.add(AtoTRadioButton,      new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
592             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 20, 0, 0), 0, 0));
593     absTransPanel.add(AutoConvertCheckBox,   new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
594             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 0), 0, 0));
595     conversionButtonGroup.add(TtoARadioButton);
596     conversionButtonGroup.add(AtoTRadioButton);
597   }
598 
addProcColorButton(JButton btn, Color c)599   private void addProcColorButton(JButton btn, Color c) {
600     colorPanel1.add(btn, null);
601     btn.setBackground(c);
602     btn.setBorder(BorderFactory.createLoweredBevelBorder());
603     btn.setName("pcb");
604     btn.addActionListener(this);
605     btn.setText(" ");
606     btn.setMaximumSize(new Dimension(20, 20));
607     btn.setMinimumSize(new Dimension(20, 20));
608     btn.setPreferredSize(new Dimension(20, 20));
609 	}
610 
addColorButton(JButton btn, Color c)611 	private void addColorButton(JButton btn, Color c) {
612     colorPanel.add(btn, null);
613     btn.setBackground(c);
614     btn.setBorder(BorderFactory.createLoweredBevelBorder());
615     btn.setName("cb");
616     btn.addActionListener(this);
617 	}
618 
619 
620 	/**
621    * Initialise the Display Tab, where display schemes are created or set
622    * @param viewer
623    */
initDisplayTab(JSViewer viewer)624   private void initDisplayTab(JSViewer viewer) {
625     TreeMap<String, ColorParameters> displaySchemes = dsp.getDisplaySchemes();
626 
627     defaultDSName = preferences.getProperty("defaultDisplaySchemeName");
628 
629     // load names of schemes in schemeComboBox
630     for (String key : displaySchemes.keySet())
631       schemeComboBox.addItem(key);
632 
633     // load names of fonts in fontComboBox
634     GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
635     String[] allFontNames = ge.getAvailableFontFamilyNames();
636     for (int i = 0; i < allFontNames.length; i++)
637       fontComboBox.addItem(allFontNames[i]);
638 
639     schemeComboBox.setSelectedItem(defaultDSName);
640 
641     // init preview panel
642     try {
643       JDXSource source = JDXReader.createJDXSourceFromStream(getClass()
644           .getResourceAsStream("resources/sample.jdx"), false, false, Float.NaN);
645 
646       previewPanel = AwtPanel.getPanelOne(viewer, source.getSpectra().get(0));
647       previewPanel.getPanelData().setBoolean(ScriptToken.ENABLEZOOM, false);
648       previewPanel.getPanelData().setBoolean(ScriptToken.GRIDON, true);
649       previewPanel.getPanelData().setBoolean(ScriptToken.TITLEON, true);
650       previewPanel.getPanelData().setBoolean(ScriptToken.COORDINATESON, true);
651     } catch (JSVException ex) {
652       ex.printStackTrace();
653     } catch (Exception ioe) {
654       ioe.printStackTrace();
655       return;
656     }
657 
658     if (previewPanel != null)
659       displayPanel.add(previewPanel, BorderLayout.CENTER);
660     else {
661       displayPanel.add(new JButton("Error Loading Sample File!"),
662           BorderLayout.CENTER);
663     }
664 
665     schemeComboBox.setSelectedItem(currentDS.name);
666     fontComboBox.setSelectedItem(currentDS.displayFontName);
667 
668     repaint();
669   }
670 
671   /**
672    * Initalises the precesing tab, where integration properties and
673    * transmittance/Adsorbance properties are set
674    */
initProcessingTab()675   private void initProcessingTab(){
676 
677     minYTextField.setText(preferences.getProperty("integralMinY"));
678     integFactorTextField.setText(preferences.getProperty("integralFactor"));
679     integOffsetTextField.setText(preferences.getProperty("integralOffset"));
680     plotColorButton.setBackground(
681         new Color(CU.getArgbFromString(preferences.getProperty("integralPlotColor"))));
682     autoIntegrateCheckBox.setSelected(
683        Boolean.parseBoolean(preferences.getProperty("automaticallyIntegrate")));
684     String autoConvert =
685         preferences.getProperty("automaticTAConversion");
686     if(autoConvert.equals("TtoA")){
687       TtoARadioButton.setSelected(true);
688       autoIntegrateCheckBox.setSelected(true);
689     }else if(autoConvert.equals("AtoT")){
690       AtoTRadioButton.setSelected(true);
691       autoIntegrateCheckBox.setSelected(true);
692     }else{
693       autoIntegrateCheckBox.setSelected(false);
694     }
695 
696     separateWindowCheckBox.setSelected(
697         Boolean.parseBoolean(preferences.getProperty("AtoTSeparateWindow")));
698 
699   }
700 
701   /**
702    * Intialises the general tab, where general properties of the application
703    * are set
704    */
initGeneralTab()705   private void initGeneralTab(){
706 
707     confirmExitCheckBox.setSelected(
708         Boolean.parseBoolean(preferences.getProperty("confirmBeforeExit")));
709     openedDirCheckBox.setSelected(
710         Boolean.parseBoolean(preferences.getProperty("useDirectoryLastOpenedFile")));
711     exportDirCheckBox.setSelected(
712         Boolean.parseBoolean(preferences.getProperty("useDirectoryLastExportedFile")));
713     svgForInkscapeCheckBox.setSelected(
714         Boolean.parseBoolean(preferences.getProperty("svgForInkscape")));
715     overlayCheckBox.setSelected(
716         Boolean.parseBoolean(preferences.getProperty("automaticallyOverlay")));
717     legendCheckBox.setSelected(
718         Boolean.parseBoolean(preferences.getProperty("automaticallyShowLegend")));
719     gridCheckBox.setSelected(
720         Boolean.parseBoolean(preferences.getProperty("showGrid")));
721     coordinatesCheckBox.setSelected(
722         Boolean.parseBoolean(preferences.getProperty("showCoordinates")));
723     scaleXCheckBox.setSelected(
724         Boolean.parseBoolean(preferences.getProperty("showXScale")));
725     scaleYCheckBox.setSelected(
726             Boolean.parseBoolean(preferences.getProperty("showYScale")));
727     sidePanelCheckBox.setSelected(
728         Boolean.parseBoolean(preferences.getProperty("showSidePanel")));
729     toolbarCheckBox.setSelected(
730         Boolean.parseBoolean(preferences.getProperty("showToolBar")));
731     statusBarCheckBox.setSelected(
732     		Boolean.parseBoolean(preferences.getProperty("showStatusBar")));
733 
734 
735 
736   }
737 
738   /**
739    * Listener for the element list
740    */
741   class ElementListSelectionListener implements ListSelectionListener{
742 
743     /**
744      * Sets the color of the currentColorButton to the color of the selected
745      * element in the list
746      *
747      * @param lse
748      *        the ListSelectionEvent
749      */
750     @Override
751 		@SuppressWarnings("unchecked")
valueChanged(ListSelectionEvent lse)752 		public void valueChanged(ListSelectionEvent lse) {
753       currentColorButton.setBackground((Color) currentDS
754           .getElementColor(ScriptToken.getScriptToken(
755           		((JList<String>)lse.getSource()).getSelectedValue())));
756     }
757   }
758 
759 	/**
760 	 * Sets the color of the selected element on the current color button
761 	 *
762 	 * @param ae
763 	 *          the ActionEvent
764 	 */
765 	@Override
actionPerformed(ActionEvent ae)766 	public void actionPerformed(ActionEvent ae) {
767 		JButton button = (JButton) ae.getSource();
768 		Color color = button.getBackground();
769 		if (button.getName().equals("cb")) {
770 			currentColorButton.setBackground(color);
771 			String element = elementList.getSelectedValue();
772 			setCurrentColor(element, color);
773 			currentDS.name = "Current";
774 			updatePreviewPanel();
775 		} else {
776 			plotColorButton.setBackground(color);
777 		}
778 	}
779   /**
780    * disposes the dialog when the cancel button is pressed
781    * @param e the ActionEvent
782    */
cancelButton_actionPerformed(ActionEvent e)783   void cancelButton_actionPerformed(ActionEvent e) {
784     dispose();
785   }
786 
setCurrentColor(String element, Color color)787   public void setCurrentColor(String element, Color color) {
788     currentDS.setColor(ScriptToken.getScriptToken(element + "COLOR"), new AwtColor(color.getRGB()));
789 	}
790 
791 	/**
792    * Updates the preferences that were set to the <code>Properties</code> passed
793    * in the constructor
794    * @param e the ActionEvent
795    */
okButton_actionPerformed(ActionEvent e)796   void okButton_actionPerformed(ActionEvent e) {
797     //preferences = new Properties();
798 
799     // rewrite and call setProperty method instead of the put method
800 
801     // General tab
802     preferences.setProperty(
803         "confirmBeforeExit", Boolean.toString(confirmExitCheckBox.isSelected()));
804     preferences.setProperty(
805         "automaticallyOverlay", Boolean.toString(overlayCheckBox.isSelected()));
806     preferences.setProperty(
807         "automaticallyShowLegend", Boolean.toString(legendCheckBox.isSelected()));
808     preferences.setProperty(
809         "useDirectoryLastOpenedFile", Boolean.toString(openedDirCheckBox.isSelected()));
810     preferences.setProperty(
811         "useDirectoryLastExportedFile", Boolean.toString(exportDirCheckBox.isSelected()));
812     preferences.setProperty(
813         "showSidePanel", Boolean.toString(sidePanelCheckBox.isSelected()));
814     preferences.setProperty(
815         "showToolBar", Boolean.toString(toolbarCheckBox.isSelected()));
816     preferences.setProperty(
817         "showStatusBar", Boolean.toString(statusBarCheckBox.isSelected()));
818     preferences.setProperty(
819         "showGrid", Boolean.toString(gridCheckBox.isSelected()));
820     preferences.setProperty(
821         "showCoordinates", Boolean.toString(coordinatesCheckBox.isSelected()));
822     preferences.setProperty(
823     	"showXScale", Boolean.toString(scaleXCheckBox.isSelected()));
824     preferences.setProperty(
825     	"showYScale", Boolean.toString(scaleYCheckBox.isSelected()));
826     preferences.setProperty(
827         "svgForInkscape", Boolean.toString(svgForInkscapeCheckBox.isSelected()));
828 
829     isSpectrumDisplayApplyNowEnabled = spectrumDisplayApplyNowCheckBox.isSelected();
830 
831     // Processing tab
832     preferences.setProperty("automaticallyIntegrate", Boolean.toString(autoIntegrateCheckBox.isSelected()));
833 
834     boolean autoTACovert = AutoConvertCheckBox.isSelected();
835     if(autoTACovert){
836       if(TtoARadioButton.isSelected())
837         preferences.setProperty("automaticTAConversion", "TtoA");
838       else
839         preferences.setProperty("automaticTAConversion", "AtoT");
840     }else{
841       preferences.setProperty("automaticTAConversion", "false");
842     }
843 
844     preferences.setProperty(
845         "AtoTSeparateWindow", Boolean.toString(separateWindowCheckBox.isSelected()));
846     preferences.setProperty("integralMinY", minYTextField.getText());
847     preferences.setProperty("integralFactor", integFactorTextField.getText());
848     preferences.setProperty("integralOffset", integOffsetTextField.getText());
849     preferences.setProperty("integralPlotColor",
850     		CU.toRGBHexString(new AwtColor(plotColorButton.getBackground().getRGB())));
851 
852     // Display Schemes Tab
853     preferences.setProperty("defaultDisplaySchemeName", currentDS.name);
854 //    System.out.println(currentDS.name);
855 
856     //TreeMap<String,DisplayScheme> dispSchemes;
857     if(currentDS.name.equals("Current")){
858       //@SuppressWarnings("unchecked")
859       TreeMap<String, ColorParameters> dispSchemes = dsp.getDisplaySchemes();
860       dispSchemes.put("Current", currentDS);
861     }
862 
863     dispose();
864   }
865 
866   /**
867    * Returns the preferences (<code>Properties</code> Object)
868    * @return the preferences (<code>Properties</code> Object)
869    */
getPreferences()870   public Properties getPreferences(){
871     return preferences;
872   }
873 
874   /**
875    * Shows a Color Dialog and updates the currentColorButton and the preview
876    * panel accordingly
877    * @param e the ActionEvent
878    */
customButton_actionPerformed(ActionEvent e)879   void customButton_actionPerformed(ActionEvent e) {
880     Color color = JColorChooser.showDialog(this, "Choose Color", Color.BLACK);
881     if(color != null){
882       currentColorButton.setBackground(color);
883       setCurrentColor(elementList.getSelectedValue(), color);
884       currentDS.name = "Current";
885       updatePreviewPanel();
886     }
887   }
888 
889   /**
890    * Delete a DisplayScheme to file
891    * @param e the ActionEvent
892    */
deleteButton_actionPerformed(ActionEvent e)893   void deleteButton_actionPerformed(ActionEvent e) {
894 
895 	 int option = JOptionPane.showConfirmDialog(this, "Do you really want to delete '" + currentDS.name + "'? This cannot be undone.",
896 			  "Delete Scheme", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
897 	 if(option == JOptionPane.YES_OPTION){
898 		 TreeMap<String, ColorParameters> dispSchemes = dsp.getDisplaySchemes();
899 
900 		 dispSchemes.remove(currentDS.name);
901 
902 		 int selectedIndex = schemeComboBox.getSelectedIndex();
903 		 schemeComboBox.removeItemAt(selectedIndex);
904 
905 		 try{
906 		 	dsp.store();
907 		 }
908 		 catch (Exception ex) {
909 		     JOptionPane.showMessageDialog(this, "There was an error deleting the Display Scheme",
910 		                                    "Error Deleting Scheme", JOptionPane.ERROR_MESSAGE);
911 		 }
912 
913 	 }
914   }
915 
916   /**
917    * Saves a new DisplayScheme to file
918    * @param e the ActionEvent
919    */
saveButton_actionPerformed(ActionEvent e)920   void saveButton_actionPerformed(ActionEvent e) {
921     // Prompt for Scheme Name
922     String input = "";
923     while(input != null && input.equals(""))
924       input = JOptionPane.showInputDialog(this, "Enter the Name of the Display Scheme",
925                                 "Display Scheme Name", JOptionPane.PLAIN_MESSAGE);
926     if(input == null)
927       return;
928 
929     currentDS.name = input;
930     boolean isdefault = defaultFontCheckBox.isSelected();
931     if(!isdefault){
932       String fontName = (String)fontComboBox.getSelectedItem();
933       currentDS.displayFontName = fontName;
934     }
935 
936     TreeMap<String, ColorParameters> dispSchemes = dsp.getDisplaySchemes();
937 
938     dispSchemes.put(input, currentDS);
939 
940     try {
941       dsp.store();
942       boolean found = false;
943       // add if not already in combobox
944       for (int i=0; i < schemeComboBox.getItemCount(); i++) {
945         String item = schemeComboBox.getItemAt(i);
946         if(item.equals(input)){
947           found = true;
948           break;
949         }
950       }
951 
952       if(!found)
953         schemeComboBox.addItem(input);
954       schemeComboBox.setSelectedItem(input);
955     }
956     catch (Exception ex) {
957       JOptionPane.showMessageDialog(this, "There was an error saving the Display Scheme",
958                                     "Error Saving Scheme", JOptionPane.ERROR_MESSAGE);
959     }
960   }
961 
962   /**
963    * Updates the preview panel and the font panel with the DisplayScheme
964    * chosen
965    * @param e the ActionEvent
966    */
967   @SuppressWarnings("unchecked")
schemeComboBox_actionPerformed(ActionEvent e)968 	void schemeComboBox_actionPerformed(ActionEvent e) {
969     JComboBox<String> schemeCB = (JComboBox<String>)e.getSource();
970     String schemeName = (String)schemeCB.getSelectedItem();
971     ColorParameters ds = null;
972 
973     TreeMap<String, ColorParameters> schemes = dsp.getDisplaySchemes();
974     for (Map.Entry<String, ColorParameters> entry: schemes.entrySet()) {
975       ds = entry.getValue();
976       if(ds.name.equals(schemeName)){
977         currentDS = ds.copy();
978         break;
979       }
980     }
981     elementList.getSelectionModel().setSelectionInterval(0, 0);
982 
983     // Update Selected Font
984     String fontName = currentDS.displayFontName;
985     fontComboBox.setSelectedItem(fontName);
986     currentDS.name = ds.name;
987     updatePreviewPanel();
988   }
989 
990   /**
991    * Updates the preview panel with the values chosen in the dialog
992    */
updatePreviewPanel()993   void updatePreviewPanel(){
994     if(previewPanel != null){
995       previewPanel.setColorOrFont(currentDS, null);
996       repaint();
997     }
998   }
999 
1000   /**
1001    * Changes the font of the current DisplayScheme
1002    * @param e the ActionEvent
1003    */
1004   @SuppressWarnings("unchecked")
fontComboBox_actionPerformed(ActionEvent e)1005 	void fontComboBox_actionPerformed(ActionEvent e) {
1006     String fontName = (String)((JComboBox<String>)e.getSource()).getSelectedItem();
1007     currentDS.displayFontName = fontName;
1008     currentDS.name = "Current";
1009     updatePreviewPanel();
1010   }
1011 
1012   /**
1013    * Sets the font of the current DisplayScheme to the the system default
1014    * @param e ActionEvent
1015    */
defaultFontCheckBox_actionPerformed(ActionEvent e)1016   void defaultFontCheckBox_actionPerformed(ActionEvent e) {
1017     JCheckBox cb = (JCheckBox)e.getSource();
1018     if(cb.isSelected()){
1019       fontComboBox.setSelectedItem("Default");
1020       fontComboBox.setEnabled(false);
1021       currentDS.displayFontName = "Default";
1022       currentDS.name = "Current";
1023       updatePreviewPanel();
1024     }else{
1025       fontComboBox.setEnabled(true);
1026     }
1027   }
1028 
1029   /**
1030    * Sets the current DisplayScheme to the default
1031    * @param e the ActionEvent
1032    */
defaultColorCheckBox_actionPerformed(ActionEvent e)1033   void defaultColorCheckBox_actionPerformed(ActionEvent e) {
1034     JCheckBox cb = (JCheckBox)e.getSource();
1035     if(cb.isSelected()){
1036       schemeComboBox.setSelectedItem("Default");
1037       schemeComboBox.setEnabled(false);
1038       customButton.setEnabled(false);
1039       saveButton.setEnabled(false);
1040 
1041       colorButton1.setEnabled(false);
1042       colorButton2.setEnabled(false);
1043       colorButton3.setEnabled(false);
1044       colorButton4.setEnabled(false);
1045       colorButton5.setEnabled(false);
1046       colorButton6.setEnabled(false);
1047       colorButton7.setEnabled(false);
1048       colorButton8.setEnabled(false);
1049 
1050       updatePreviewPanel();
1051     }else{
1052       schemeComboBox.setEnabled(true);
1053       colorPanel.setEnabled(true);
1054       customButton.setEnabled(true);
1055       saveButton.setEnabled(true);
1056 
1057       colorButton1.setEnabled(true);
1058       colorButton2.setEnabled(true);
1059       colorButton3.setEnabled(true);
1060       colorButton4.setEnabled(true);
1061       colorButton5.setEnabled(true);
1062       colorButton6.setEnabled(true);
1063       colorButton7.setEnabled(true);
1064       colorButton8.setEnabled(true);
1065     }
1066   }
1067 
1068 
1069   /* ---------------------------------------------------------------------*/
1070 
1071   /**
1072    * Retruns the current Display Scheme
1073    * @return the current Display Scheme
1074    */
getSelectedDisplayScheme()1075   public ColorParameters getSelectedDisplayScheme(){
1076     return currentDS;
1077   }
1078 
1079   /**
1080    * Clears the list of recently opened files
1081    * @param e the ActionEvent
1082    */
clearRecentButton_actionPerformed(ActionEvent e)1083   void clearRecentButton_actionPerformed(ActionEvent e) {
1084     int option = JOptionPane.showConfirmDialog(this, "Recent File Paths will be cleared!",
1085                                   "Warning", JOptionPane.OK_CANCEL_OPTION,
1086                                   JOptionPane.WARNING_MESSAGE);
1087     if(option == JOptionPane.OK_OPTION)
1088       preferences.setProperty("recentFilePaths", "");
1089   }
1090 
1091   /**
1092    * Shows Color dialog to set the color of the integral plot
1093    * @param e ActionEvent
1094    */
processingCustomButton_actionPerformed(ActionEvent e)1095   void processingCustomButton_actionPerformed(ActionEvent e) {
1096     Color color = JColorChooser.showDialog(this, "Choose Color", Color.BLACK);
1097     if(color != null)
1098       plotColorButton.setBackground(color);
1099   }
1100 
shouldApplySpectrumDisplaySettingsNow()1101 	public boolean shouldApplySpectrumDisplaySettingsNow() {
1102 		return isSpectrumDisplayApplyNowEnabled;
1103 	}
1104 
1105 }
1106