001
002 /*****************************************************************************
003 *
004 * jBudget.
005 * Copyright (C) 2006 Dmitri Petrov
006 *
007 * This program is free software: you can redistribute it and/or modify
008 * it under the terms of the GNU General Public License as published by
009 * the Free Software Foundation, either version 3 of the License, or
010 * (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program. If not, see <http://www.gnu.org/licenses/>.
019 *
020 *****************************************************************************/
021
022
023 /*
024 * PreferencesEditorPanel.java
025 *
026 * Created on August 30, 2007, 11:00 PM
027 */
028
029 package org.jbudget.gui;
030
031 import java.awt.BorderLayout;
032 import java.awt.Color;
033 import java.awt.Component;
034 import java.awt.Dimension;
035 import java.awt.event.ActionEvent;
036 import java.awt.event.ActionListener;
037 import java.awt.event.ItemEvent;
038 import java.awt.event.ItemListener;
039 import java.beans.PropertyChangeEvent;
040 import java.beans.PropertyChangeListener;
041 import java.text.NumberFormat;
042 import java.text.ParseException;
043 import java.util.ArrayList;
044 import java.util.Currency;
045 import java.util.List;
046 import java.util.Locale;
047 import javax.swing.DefaultComboBoxModel;
048 import javax.swing.JCheckBox;
049 import javax.swing.JComboBox;
050 import javax.swing.JLabel;
051 import javax.swing.JList;
052 import javax.swing.JOptionPane;
053 import javax.swing.JPanel;
054 import javax.swing.JTabbedPane;
055 import javax.swing.JTextField;
056 import javax.swing.ListCellRenderer;
057 import javax.swing.SpringLayout;
058 import javax.swing.UIManager;
059 import javax.swing.border.LineBorder;
060 import org.jbudget.Core.SharedPreferences;
061 import org.jbudget.Core.User;
062 import org.jbudget.gui.components.ColorSelectionButton;
063 import org.jbudget.gui.components.FontSelector;
064 import org.jbudget.io.DataManager;
065 import org.jdesktop.swingx.JXTaskPane;
066 import org.jdesktop.swingx.JXTaskPaneContainer;
067
068 /**
069 * @author petrov
070 */
071 public class PreferencesEditorPanel extends JPanel
072 {
073 //==========================================================================
074 //
075 // Data Memebers
076 //
077 //==========================================================================
078
079
080 /** Tabbed Pane. */
081 private final JTabbedPane tabbedPane = new JTabbedPane();
082
083 //======================= LOOK AND FEEL ===============================//
084
085 /** Look and Feel Tab. */
086 private final JPanel lfTab = new JPanel();
087
088 /** Task Pane container for the Look and Feel tab. */
089 private final JXTaskPaneContainer lfContainer = new JXTaskPaneContainer();
090
091 /** Task Pane for the Look and feel selections. */
092 private final JXTaskPane lfTaskPane = new JXTaskPane();
093
094 /** Combo box for Look and Feel selections. */
095 private final JComboBox lfComboBox = new JComboBox();
096
097 /** Text field for L&F Selections. */
098 private final JTextField lfTextField = new JTextField();
099
100 public final static String osDefaultLFKey = "Operating System Default";
101 public final static String sysDefaultLFKey = "Java Default";
102 public final static String customLFKey = "Custom";
103
104 /** Task Pane for selecting the locale. */
105 private final JXTaskPane localeTaskPane = new JXTaskPane();
106
107 private JComboBox localeChoice = new JComboBox();
108 private final JCheckBox salesTaxCheckBox = new JCheckBox("Enable Sales Tax");
109 private final JTextField salesTaxText = new JTextField(4);
110
111
112 //========================== COLORS ===============================//
113
114 /** Colors Tab. */
115 private final JPanel colorsTab = new JPanel();
116
117 /** Task Pane container for the Colors tab. */
118 private final JXTaskPaneContainer colorsContainer = new JXTaskPaneContainer();
119
120 /** Task Pane for the general UI color selections. */
121 private final JXTaskPane uiColorsTaskPane = new JXTaskPane();
122
123 /** Task Pane for the table color selections. */
124 private final JXTaskPane tableColorsTaskPane = new JXTaskPane();
125
126 private final JCheckBox defaultLFColorsCheckBox =
127 new JCheckBox("Default Look and Feel Colors");
128
129 // Color selection labels.
130
131 private final JLabel foregroundColorLabel =
132 new JLabel("Foreground Color:");
133
134 private final JLabel backgroundColorLabel =
135 new JLabel("Background Color:");
136
137 private final JLabel highlightColorLabel =
138 new JLabel("Highlighted Component Color:");
139
140 private final JLabel selectedColorLabel =
141 new JLabel("Selected Component Color:");
142
143 private final JLabel textBackgroundLabel =
144 new JLabel("Text Component Background:");
145
146 private final JLabel toolTipBackgroundLabel =
147 new JLabel("Tool Tip Background Color:");
148
149
150 private final JLabel controlBackgroundColorLabel =
151 new JLabel("Control Component Background:");
152
153 private final JLabel tableForegroundColorLabel =
154 new JLabel("Foreground Color:");
155
156 private final JLabel tableBackgroundColorLabel =
157 new JLabel("Background Color:");
158
159 private final JLabel tableAltBackgroundColorLabel =
160 new JLabel("Alt. Background Color:");
161
162 private final JLabel tableSelectedHighlightColorLabel =
163 new JLabel("Selected Highlight Color:");
164
165 private final JLabel tableIncomeHighlightColorLabel =
166 new JLabel("Income Highlight Color:");
167
168 private final JLabel tableExpenseHighlightColorLabel =
169 new JLabel("Expense Highlight Color:");
170
171
172 // Color selection buttons.
173
174 private ColorSelectionButton fgBtn;
175 private ColorSelectionButton bgBtn;
176 private ColorSelectionButton controlBgBtn;
177 private ColorSelectionButton textBgBtn;
178 private ColorSelectionButton toolTipBgBtn;
179 private ColorSelectionButton highlightedColorBtn;
180 private ColorSelectionButton selectedColorBtn;
181
182 private ColorSelectionButton tableFgBtn;
183 private ColorSelectionButton tableBgBtn;
184 private ColorSelectionButton tableAltBgBtn;
185 private ColorSelectionButton tableSelectedHltBtn;
186 private ColorSelectionButton tableIncomeHltBtn;
187 private ColorSelectionButton tableExpenseHltBtn;
188
189
190 //========================== FONTS ===============================//
191
192 /** Fonts Tab. */
193 private final JPanel fontTab = new JPanel();
194
195 /** Task Pane container for the Fonts tab. */
196 private final JXTaskPaneContainer fontContainer = new JXTaskPaneContainer();
197
198 /** Task Pane for the UI Font selections. */
199 private final JXTaskPane uiFontTaskPane = new JXTaskPane();
200
201 /** Combo box for the default UI Font selections. */
202 private final JCheckBox uiDefaultFontCheckBox =
203 new JCheckBox("Default Look and Feel Font");
204
205 /** Task Pane for the tool tip font selections. */
206 private final JXTaskPane ttFontTaskPane = new JXTaskPane();
207
208 /** Combo box for the default tool tip font selections. */
209 private final JCheckBox ttDefaultFontCheckBox =
210 new JCheckBox("Default Look and Feel Font");
211
212 /** Task Pane for the table font selections. */
213 private final JXTaskPane tableFontTaskPane = new JXTaskPane();
214
215 /** Combo box for the default table font selections. */
216 private final JCheckBox tableDefaultFontCheckBox =
217 new JCheckBox("Default Look and Feel Font");
218
219 /** Font selector panel for selecting the general UI font.
220 * This changes the fonts used in buttons, menues, and other GUI components.*/
221 private final FontSelector generalFontSelector;
222
223 /** Font selector panel for selecting the table font. This font
224 * is used in the month info table and the transaction/allocation lists. */
225 private final FontSelector tableFontSelector;
226
227 /** Font selector panel for selecting the tool tip font. */
228 private final FontSelector toolTipFontSelector;
229
230
231 /** Array of objects describing the available Look and Feel selections. */
232 private String[] lfKeys;
233
234 //============================================================================
235 //
236 // Initialization Routines
237 //
238 //============================================================================
239
240 /** Creates a new instance of PreferencesEditorPanel */
241 public PreferencesEditorPanel()
242 {
243 generalFontSelector = new FontSelector(GuiPreferences.getFont(
244 GuiPreferences.generalUIFontKey, GuiPreferences.generalUIFontDef));
245
246 tableFontSelector = new FontSelector(GuiPreferences.getFont(
247 GuiPreferences.tableFontKey, GuiPreferences.tableFontDef));
248
249 toolTipFontSelector = new FontSelector(GuiPreferences.getFont(
250 GuiPreferences.toolTipFontKey, GuiPreferences.toolTipFontDef));
251
252 initializeGUI();
253 // Finish ME
254 }
255
256 /** Initialize the GUI. */
257 private void initializeGUI()
258 {
259 // Look and Feel
260 initializeLFPane();
261 syncLFPane();
262 initializeLFActions();
263
264 // Colors
265 initializeColorPane();
266 initializeColorPaneActions();
267
268 // Fonts.
269 initializeFontPane();
270 syncFontPane();
271 initializeFontActions();
272
273 tabbedPane.addTab("Look and Feel", lfTab);
274 tabbedPane.addTab("Colors", colorsTab);
275 tabbedPane.addTab("Fonts", fontTab);
276
277 setLayout(new BorderLayout());
278 add(tabbedPane, BorderLayout.CENTER);
279 }
280
281 //----------------------------------------------------------------------------
282 //
283 // Look and Feel Handling.
284 //
285 //----------------------------------------------------------------------------
286
287 /** Initializes the L&F pane. */
288 private void initializeLFPane()
289 {
290 lfTaskPane.setTitle("Look and Feel");
291
292 UIManager.LookAndFeelInfo[] installed =
293 UIManager.getInstalledLookAndFeels();
294
295 lfKeys = new String[installed.length + 3];
296
297 // Add system and default L&F labels
298 lfKeys[0] = osDefaultLFKey;
299 lfKeys[1] = sysDefaultLFKey;
300
301 // Add installed L&F's
302 for (int i = 0; i < installed.length; i ++)
303 lfKeys[i+2] = installed[i].getName();
304
305 // Add 'Custom'
306 lfKeys[installed.length+2] = customLFKey;
307
308 // set the list model
309 lfComboBox.setModel(new DefaultComboBoxModel(lfKeys));
310
311 JPanel panel = new JPanel();
312 SpringLayout layout = new SpringLayout();
313 panel.setLayout(layout);
314 panel.add(lfComboBox);
315 panel.add(lfTextField);
316
317 layout.putConstraint(SpringLayout.WEST, lfComboBox,
318 0,
319 SpringLayout.WEST, panel);
320
321 layout.putConstraint(SpringLayout.EAST, lfComboBox,
322 -5,
323 SpringLayout.EAST, panel);
324
325 layout.putConstraint(SpringLayout.NORTH, lfComboBox,
326 5,
327 SpringLayout.NORTH, panel);
328
329 layout.putConstraint(SpringLayout.WEST, lfTextField,
330 10,
331 SpringLayout.WEST, panel);
332
333 layout.putConstraint(SpringLayout.EAST, lfTextField,
334 -5,
335 SpringLayout.EAST, panel);
336
337 layout.putConstraint(SpringLayout.NORTH, lfTextField,
338 5,
339 SpringLayout.SOUTH, lfComboBox);
340
341 lfComboBox.setPreferredSize(new Dimension(100, 21));
342 lfTextField.setPreferredSize(new Dimension(100, 21));
343 panel.setPreferredSize(new Dimension(100, 55));
344
345 lfTaskPane.add(panel);
346 lfContainer.add(lfTaskPane);
347
348 //-------------------------------------------------------------------//
349
350 localeTaskPane.setTitle("Locale");
351
352 panel = new JPanel();
353 layout = new SpringLayout();
354 panel.setLayout(layout);
355
356 List<Locale> locales = new ArrayList<Locale>();
357 Locale[] allLocales = Locale.getAvailableLocales();
358 for (Locale locale : allLocales)
359 {
360 String country = locale.getCountry();
361 if (country != null && country.length() != 0)
362 locales.add(locale);
363 }
364
365 localeChoice.setModel(new DefaultComboBoxModel(locales.toArray()));
366 localeChoice.setPreferredSize(new Dimension(150, 21));
367 localeChoice.setRenderer(new LocaleRenderer());
368
369 JLabel localeLabel = new JLabel("Locale: ");
370 localeLabel.setPreferredSize(new Dimension(55, 21));
371
372 salesTaxCheckBox.setPreferredSize(new Dimension(150, 21));
373 salesTaxText.setPreferredSize(new Dimension(50, 21));
374
375 JPanel messagePanel = new JPanel();
376 messagePanel.setLayout(new BorderLayout());
377
378 JLabel messageLabel = new JLabel();
379 messageLabel.setHorizontalAlignment(JLabel.CENTER);
380 messageLabel.setVerticalAlignment(JLabel.CENTER);
381
382 messagePanel.add(messageLabel, BorderLayout.CENTER);
383 messagePanel.setBorder(new LineBorder(Color.LIGHT_GRAY));
384
385 panel.add(localeLabel);
386 panel.add(localeChoice);
387 panel.add(salesTaxCheckBox);
388 panel.add(salesTaxText);
389 panel.add(messagePanel);
390
391 layout.putConstraint(SpringLayout.NORTH, localeLabel,
392 0,
393 SpringLayout.NORTH, panel);
394
395 layout.putConstraint(SpringLayout.NORTH, localeChoice,
396 0,
397 SpringLayout.NORTH, panel);
398
399 layout.putConstraint(SpringLayout.WEST, localeLabel,
400 0,
401 SpringLayout.WEST, panel);
402
403 layout.putConstraint(SpringLayout.WEST, localeChoice,
404 0,
405 SpringLayout.EAST, localeLabel);
406
407 layout.putConstraint(SpringLayout.WEST, salesTaxCheckBox,
408 0,
409 SpringLayout.WEST, panel);
410
411 layout.putConstraint(SpringLayout.NORTH, salesTaxCheckBox,
412 15,
413 SpringLayout.SOUTH, localeLabel);
414
415 layout.putConstraint(SpringLayout.WEST, salesTaxText,
416 10,
417 SpringLayout.EAST, salesTaxCheckBox);
418
419 layout.putConstraint(SpringLayout.NORTH, salesTaxText,
420 15,
421 SpringLayout.SOUTH, localeLabel);
422
423 layout.putConstraint(SpringLayout.NORTH, messagePanel,
424 5,
425 SpringLayout.SOUTH, salesTaxText);
426
427 layout.putConstraint(SpringLayout.SOUTH, messagePanel,
428 0,
429 SpringLayout.SOUTH, panel);
430
431 layout.putConstraint(SpringLayout.EAST, messagePanel,
432 0,
433 SpringLayout.EAST, panel);
434
435 layout.putConstraint(SpringLayout.WEST, messagePanel,
436 0,
437 SpringLayout.WEST, panel);
438
439 if (DataManager.getInstance().getCurrentUser() != User.SYSTEM)
440 {
441 messageLabel.setText(
442 "These settings can only be changed by the 'System' user");
443
444 localeLabel.setEnabled(false);
445 localeChoice.setEnabled(false);
446 salesTaxCheckBox.setEnabled(false);
447 salesTaxText.setEnabled(false);
448 }
449 else
450 messageLabel.setText(
451 "Changes to these settings require restarting the program.");
452
453 panel.setPreferredSize(new Dimension(100, 100));
454 localeTaskPane.add(panel);
455
456 lfContainer.add(localeTaskPane);
457
458 lfTab.setLayout(new BorderLayout());
459 lfTab.add(lfContainer, BorderLayout.CENTER);
460 }
461
462 /** synchronizes the LF panel with the currently selected value.
463 * Reads the currently selected L&F from the UIManager and
464 * selects the corresponding element in the list of L&F objects in
465 * the GUI. */
466 private void syncLFPane()
467 {
468 SharedPreferences pref = DataManager.getInstance().getSharedPreferences();
469
470 localeChoice.setSelectedItem(pref.getLocale());
471 salesTaxCheckBox.setSelected(pref.getUseSalesTax());
472 salesTaxText.setEnabled(pref.getUseSalesTax() &&
473 DataManager.getInstance().getCurrentUser() == User.SYSTEM);
474
475 NumberFormat format = NumberFormat.getPercentInstance(pref.getLocale());
476 format.setMaximumFractionDigits(2);
477 salesTaxText.setText(format.format(pref.getSalesTax()*0.0001));
478
479 String selectedLF = GuiPreferences.get(GuiPreferences.uiLFKey,
480 osDefaultLFKey);
481
482 for (int i = 0; i < lfKeys.length; i++)
483 {
484 if (lfKeys[i].equals(selectedLF))
485 {
486 lfComboBox.setSelectedItem(lfKeys[i]);
487 return;
488 }
489 }
490
491 lfComboBox.setSelectedItem(customLFKey);
492 lfTextField.setText(selectedLF);
493 lfTextField.setEnabled(true);
494 }
495
496 /** Sets the LF key in the GuiPreferenses to correspond to the
497 * Look and Feel chosen in the GUI. */
498 private void commitLF()
499 {
500 DataManager manager = DataManager.getInstance();
501
502 if (manager.getCurrentUser() == User.SYSTEM)
503 {
504 SharedPreferences pref = DataManager.getInstance().getSharedPreferences();
505
506 pref.setLocale((Locale) localeChoice.getSelectedItem());
507 pref.setUseSalesTax(salesTaxCheckBox.isSelected());
508
509 try
510 {
511 NumberFormat format = NumberFormat.getPercentInstance(pref.getLocale());
512 Number tax = format.parse(salesTaxText.getText());
513 pref.setSalesTax((long)(tax.doubleValue()*10000));
514 }
515 catch (ParseException ex)
516 {
517 try
518 {
519 NumberFormat format = NumberFormat.getNumberInstance();
520 Number tax = format.parse(salesTaxText.getText());
521 pref.setSalesTax((long) (tax.doubleValue()*100));
522 }
523 catch (ParseException ex1)
524 {
525 }
526 }
527 }
528
529 String selectedLF = GuiPreferences.get(GuiPreferences.uiLFKey,
530 osDefaultLFKey);
531
532 Object selected = lfComboBox.getSelectedItem();
533 if (selected instanceof UIManager.LookAndFeelInfo)
534 {
535 GuiPreferences.put(GuiPreferences.uiLFKey,
536 ((UIManager.LookAndFeelInfo)selected).getName());
537 return;
538 }
539
540 if (selected != customLFKey)
541 {
542 GuiPreferences.put(GuiPreferences.uiLFKey, (String)selected);
543 return;
544 }
545
546 // Custom L&F objectString
547 String lfClassName = lfTextField.getText();
548 if (checkLF(lfClassName))
549 {
550 GuiPreferences.put(GuiPreferences.uiLFKey, lfClassName);
551 }
552 else
553 {
554 JOptionPane.showMessageDialog(PreferencesEditorPanel.this,
555 new JLabel(
556 "<html><center>Cannot load Look and Feel class <br> <u>" +
557 lfClassName +
558 "</u>. <br>"+
559 "This means that the Look and Feel you have selected is <br>" +
560 "not installed or has not been added to the CLASSPATH" +
561 "</center></html>"),
562 "Warning", JOptionPane.WARNING_MESSAGE);
563 GuiPreferences.put(GuiPreferences.uiLFKey, osDefaultLFKey);
564 }
565 }
566
567 /** Initializes actions associated with the LF selection panel. */
568 private void initializeLFActions()
569 {
570 lfComboBox.addItemListener(new ItemListener()
571 {
572 public void itemStateChanged(ItemEvent e)
573 {
574 lfTextField.setEnabled(
575 lfComboBox.getSelectedItem() == customLFKey);
576 }
577 });
578
579 lfTextField.addActionListener(new ActionListener()
580 {
581 public void actionPerformed(ActionEvent ev)
582 {
583 String lfClassName = lfTextField.getText();
584 if (!checkLF(lfClassName))
585 {
586 JOptionPane.showMessageDialog(PreferencesEditorPanel.this,
587 new JLabel(
588 "<html><center>Cannot load Look and Feel class <br> <u>" +
589 lfClassName +
590 "</u>. <br>"+
591 "This means that the Look and Feel you have selected is <br>" +
592 "not installed or has not been added to the CLASSPATH" +
593 "</center></html>"),
594 "Warning", JOptionPane.WARNING_MESSAGE);
595 }
596 }
597 });
598
599 salesTaxCheckBox.addActionListener(new ActionListener()
600 {
601 public void actionPerformed(ActionEvent e)
602 {
603 salesTaxText.setEnabled(salesTaxCheckBox.isSelected());
604 }
605 });
606
607 }
608
609 /** Checks if a look and feel class exists and can be loaded. */
610 private boolean checkLF(String lfClassName)
611 {
612 // Check if GTK L&F is available
613 boolean lfAvailable = false;
614
615 try
616 {
617 this.getClass().getClassLoader().loadClass(lfClassName);
618 lfAvailable = true;
619 }
620 catch (Exception ex)
621 {}
622
623 return lfAvailable;
624 }
625
626 //--------------------------------------------------------------------------
627 //
628 // Font Handling.
629 //
630 //--------------------------------------------------------------------------
631
632 /** Initializes GUI components assoicated with the Fonts tab in the
633 * Preferences Editor. */
634 private void initializeFontPane()
635 {
636 fontTab.setLayout(new BorderLayout());
637 fontTab.add(fontContainer, BorderLayout.CENTER);
638
639 uiFontTaskPane.setTitle("General UI Font");
640 ttFontTaskPane.setTitle("Tool Tip Font");
641 tableFontTaskPane.setTitle("Table Font");
642
643 fontContainer.add(uiFontTaskPane);
644 fontContainer.add(ttFontTaskPane);
645 fontContainer.add(tableFontTaskPane);
646
647 JPanel panel = new JPanel();
648 SpringLayout layout = new SpringLayout();
649 panel.setLayout(layout);
650 panel.add(uiDefaultFontCheckBox);
651 panel.add(generalFontSelector);
652
653 layout.putConstraint(SpringLayout.WEST, uiDefaultFontCheckBox,
654 0,
655 SpringLayout.WEST, panel);
656
657 layout.putConstraint(SpringLayout.EAST, uiDefaultFontCheckBox,
658 -5,
659 SpringLayout.EAST, panel);
660
661 layout.putConstraint(SpringLayout.NORTH, uiDefaultFontCheckBox,
662 5,
663 SpringLayout.NORTH, panel);
664
665 layout.putConstraint(SpringLayout.WEST, generalFontSelector,
666 10,
667 SpringLayout.WEST, panel);
668
669 layout.putConstraint(SpringLayout.EAST, generalFontSelector,
670 -5,
671 SpringLayout.EAST, panel);
672
673 layout.putConstraint(SpringLayout.NORTH, generalFontSelector,
674 5,
675 SpringLayout.SOUTH, uiDefaultFontCheckBox);
676
677 layout.putConstraint(SpringLayout.SOUTH, generalFontSelector,
678 -5,
679 SpringLayout.SOUTH, panel);
680
681 panel.setPreferredSize(new Dimension(400, 200));
682 uiFontTaskPane.add(panel);
683
684 layout = new SpringLayout();
685 panel = new JPanel();
686 panel.setLayout(layout);
687 panel.add(tableDefaultFontCheckBox);
688 panel.add(tableFontSelector);
689
690 layout.putConstraint(SpringLayout.WEST, tableDefaultFontCheckBox,
691 0,
692 SpringLayout.WEST, panel);
693
694 layout.putConstraint(SpringLayout.EAST, tableDefaultFontCheckBox,
695 -5,
696 SpringLayout.EAST, panel);
697
698 layout.putConstraint(SpringLayout.NORTH, tableDefaultFontCheckBox,
699 5,
700 SpringLayout.NORTH, panel);
701
702 layout.putConstraint(SpringLayout.WEST, tableFontSelector,
703 10,
704 SpringLayout.WEST, panel);
705
706 layout.putConstraint(SpringLayout.EAST, tableFontSelector,
707 -5,
708 SpringLayout.EAST, panel);
709
710 layout.putConstraint(SpringLayout.NORTH, tableFontSelector,
711 5,
712 SpringLayout.SOUTH, tableDefaultFontCheckBox);
713
714 layout.putConstraint(SpringLayout.SOUTH, tableFontSelector,
715 -5,
716 SpringLayout.SOUTH, panel);
717
718 panel.setPreferredSize(new Dimension(400, 200));
719 tableFontTaskPane.add(panel);
720
721 layout = new SpringLayout();
722 panel = new JPanel();
723 panel.setLayout(layout);
724 panel.add(ttDefaultFontCheckBox);
725 panel.add(toolTipFontSelector);
726
727 layout.putConstraint(SpringLayout.WEST, ttDefaultFontCheckBox,
728 5,
729 SpringLayout.WEST, panel);
730
731 layout.putConstraint(SpringLayout.EAST, ttDefaultFontCheckBox,
732 -5,
733 SpringLayout.EAST, panel);
734
735 layout.putConstraint(SpringLayout.NORTH, ttDefaultFontCheckBox,
736 5,
737 SpringLayout.NORTH, panel);
738
739 layout.putConstraint(SpringLayout.WEST, toolTipFontSelector,
740 10,
741 SpringLayout.WEST, panel);
742
743 layout.putConstraint(SpringLayout.EAST, toolTipFontSelector,
744 -5,
745 SpringLayout.EAST, panel);
746
747 layout.putConstraint(SpringLayout.NORTH, toolTipFontSelector,
748 5,
749 SpringLayout.SOUTH, ttDefaultFontCheckBox);
750
751 layout.putConstraint(SpringLayout.SOUTH, toolTipFontSelector,
752 -5,
753 SpringLayout.SOUTH, panel);
754
755 panel.setPreferredSize(new Dimension(400, 200));
756 ttFontTaskPane.add(panel);
757
758 ttFontTaskPane.setCollapsed(true);
759 uiFontTaskPane.setCollapsed(true);
760 tableFontTaskPane.setCollapsed(false);
761 }
762
763 /** Initializes actions associated with the font pane. */
764 private void initializeFontActions()
765 {
766 uiDefaultFontCheckBox.addItemListener(new ItemListener()
767 {
768 public void itemStateChanged(ItemEvent e)
769 {
770 generalFontSelector.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
771 }
772 });
773
774 ttDefaultFontCheckBox.addItemListener(new ItemListener()
775 {
776 public void itemStateChanged(ItemEvent e)
777 {
778 toolTipFontSelector.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
779 }
780 });
781
782 tableDefaultFontCheckBox.addItemListener(new ItemListener()
783 {
784 public void itemStateChanged(ItemEvent e)
785 {
786 tableFontSelector.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
787 }
788 });
789
790 // Allow only one expanded panel.
791 PropertyChangeListener expansionListener = new PropertyChangeListener()
792 {
793 JXTaskPane[] panes = {uiFontTaskPane,
794 ttFontTaskPane,
795 tableFontTaskPane};
796
797 public void propertyChange(PropertyChangeEvent event)
798 {
799 if (!event.getPropertyName().equals("collapsed"))
800 {
801 return;
802 }
803 if (((Boolean) event.getNewValue()).booleanValue())
804 {
805 return;
806 }
807
808 for (JXTaskPane panel : panes)
809 if (event.getSource() != panel)
810 panel.setCollapsed(true);
811 }
812 };
813
814 uiFontTaskPane.addPropertyChangeListener(expansionListener);
815 ttFontTaskPane.addPropertyChangeListener(expansionListener);
816 tableFontTaskPane.addPropertyChangeListener(expansionListener);
817 }
818
819 /** synchronizes the font panel with the state of the GuiPreferences object.*/
820 private void syncFontPane()
821 {
822 boolean flag = GuiPreferences.getBoolean(
823 GuiPreferences.generalUIFontSelectKey,
824 GuiPreferences.generalUIFontSelectDef);
825
826 uiDefaultFontCheckBox.setSelected(!flag);
827 generalFontSelector.setEnabled(flag);
828
829 flag = GuiPreferences.getBoolean(
830 GuiPreferences.toolTipFontSelectKey,
831 GuiPreferences.toolTipFontSelectDef);
832
833 ttDefaultFontCheckBox.setSelected(!flag);
834 toolTipFontSelector.setEnabled(flag);
835
836 flag = GuiPreferences.getBoolean(
837 GuiPreferences.tableFontSelectKey,
838 GuiPreferences.tableFontSelectDef);
839
840 tableDefaultFontCheckBox.setSelected(!flag);
841 tableFontSelector.setEnabled(flag);
842
843 generalFontSelector.setSelectedFont(GuiPreferences.getFont(
844 GuiPreferences.generalUIFontKey, GuiPreferences.generalUIFontDef));
845
846 tableFontSelector.setSelectedFont(GuiPreferences.getFont(
847 GuiPreferences.tableFontKey, GuiPreferences.tableFontDef));
848
849 toolTipFontSelector.setSelectedFont(GuiPreferences.getFont(
850 GuiPreferences.toolTipFontKey, GuiPreferences.toolTipFontDef));
851 }
852
853 /** Sets the Font information in the GuiPreferences object to the settings
854 * currently selected in the font pane. */
855 private void commitFonts()
856 {
857 // General UI Font.
858
859 boolean flag = !uiDefaultFontCheckBox.isSelected();
860
861 GuiPreferences.setBoolean(GuiPreferences.generalUIFontSelectKey, flag);
862
863 if (flag)
864 {
865 GuiPreferences.setFont(GuiPreferences.generalUIFontKey,
866 generalFontSelector.getSelectedFont());
867 }
868
869 // Tool Tip Font.
870
871 flag = !ttDefaultFontCheckBox.isSelected();
872
873 GuiPreferences.setBoolean(GuiPreferences.toolTipFontSelectKey, flag);
874
875 if (flag)
876 {
877 GuiPreferences.setFont(GuiPreferences.toolTipFontKey,
878 toolTipFontSelector.getSelectedFont());
879 }
880
881 // Table Font.
882
883 flag = !tableDefaultFontCheckBox.isSelected();
884
885 GuiPreferences.setBoolean(GuiPreferences.tableFontSelectKey, flag);
886
887 if (flag)
888 {
889 GuiPreferences.setFont(GuiPreferences.tableFontKey,
890 tableFontSelector.getSelectedFont());
891 }
892 }
893
894 //--------------------------------------------------------------------------
895 //
896 // Color Handling.
897 //
898 //--------------------------------------------------------------------------
899
900 /** Initializes GUI components associated with the Color Tab in the
901 * Preferences Editor Panel. */
902 private void initializeColorPane()
903 {
904 colorsTab.setLayout(new BorderLayout());
905 colorsTab.add(colorsContainer, BorderLayout.CENTER);
906
907 uiColorsTaskPane.setTitle("General UI Colors");
908 tableColorsTaskPane.setTitle("Table Colors");
909
910 SpringLayout layout = new SpringLayout();
911 JPanel panel = new JPanel();
912 panel.setLayout(layout);
913
914 panel.add(defaultLFColorsCheckBox);
915
916 layout.putConstraint(SpringLayout.WEST, defaultLFColorsCheckBox,
917 0,
918 SpringLayout.WEST, panel);
919
920 layout.putConstraint(SpringLayout.EAST, defaultLFColorsCheckBox,
921 -5,
922 SpringLayout.EAST, panel);
923
924 layout.putConstraint(SpringLayout.NORTH, defaultLFColorsCheckBox,
925 5,
926 SpringLayout.NORTH, panel);
927
928 fgBtn = new ColorSelectionButton(
929 GuiPreferences.getColor(GuiPreferences.generalUIFgKey,
930 GuiPreferences.generalUIFg));
931
932 int labelWidth = 300;
933
934 fgBtn.setPreferredSize(new Dimension(0,21));
935 foregroundColorLabel.setPreferredSize(new Dimension(300,21));
936
937 panel.add(foregroundColorLabel);
938 panel.add(fgBtn);
939
940 layout.putConstraint(SpringLayout.WEST, foregroundColorLabel,
941 10,
942 SpringLayout.WEST, panel);
943
944 layout.putConstraint(SpringLayout.EAST, foregroundColorLabel,
945 labelWidth,
946 SpringLayout.WEST, panel);
947
948 layout.putConstraint(SpringLayout.NORTH, foregroundColorLabel,
949 5,
950 SpringLayout.SOUTH, defaultLFColorsCheckBox);
951
952 layout.putConstraint(SpringLayout.WEST, fgBtn,
953 1,
954 SpringLayout.EAST, foregroundColorLabel);
955
956 layout.putConstraint(SpringLayout.EAST, fgBtn,
957 -5,
958 SpringLayout.EAST, panel);
959
960 layout.putConstraint(SpringLayout.NORTH, fgBtn,
961 5,
962 SpringLayout.SOUTH, defaultLFColorsCheckBox);
963
964 bgBtn = new ColorSelectionButton(
965 GuiPreferences.getColor(GuiPreferences.generalUIBgKey,
966 GuiPreferences.generalUIBg));
967
968 panel.add(backgroundColorLabel);
969 panel.add(bgBtn);
970
971 bgBtn.setPreferredSize(new Dimension(0,21));
972 backgroundColorLabel.setPreferredSize(new Dimension(300,21));
973
974 layout.putConstraint(SpringLayout.WEST, backgroundColorLabel,
975 10,
976 SpringLayout.WEST, panel);
977
978 layout.putConstraint(SpringLayout.EAST, backgroundColorLabel,
979 labelWidth,
980 SpringLayout.WEST, panel);
981
982 layout.putConstraint(SpringLayout.NORTH, backgroundColorLabel,
983 1,
984 SpringLayout.SOUTH, foregroundColorLabel);
985
986 layout.putConstraint(SpringLayout.WEST, bgBtn,
987 1,
988 SpringLayout.EAST, backgroundColorLabel);
989
990 layout.putConstraint(SpringLayout.EAST, bgBtn,
991 -5,
992 SpringLayout.EAST, panel);
993
994 layout.putConstraint(SpringLayout.NORTH, bgBtn,
995 1,
996 SpringLayout.SOUTH, foregroundColorLabel);
997
998 controlBgBtn = new ColorSelectionButton(
999 GuiPreferences.getColor(GuiPreferences.generalUIControlBgKey,
1000 GuiPreferences.generalUIControlBgDef));
1001
1002 panel.add(controlBackgroundColorLabel);
1003 panel.add(controlBgBtn);
1004
1005 controlBgBtn.setPreferredSize(new Dimension(0,21));
1006 controlBackgroundColorLabel.setPreferredSize(new Dimension(300,21));
1007
1008 layout.putConstraint(SpringLayout.WEST, controlBackgroundColorLabel,
1009 10,
1010 SpringLayout.WEST, panel);
1011
1012 layout.putConstraint(SpringLayout.EAST, controlBackgroundColorLabel,
1013 labelWidth,
1014 SpringLayout.WEST, panel);
1015
1016 layout.putConstraint(SpringLayout.NORTH, controlBackgroundColorLabel,
1017 1,
1018 SpringLayout.SOUTH, backgroundColorLabel);
1019
1020 layout.putConstraint(SpringLayout.WEST, controlBgBtn,
1021 1,
1022 SpringLayout.EAST, controlBackgroundColorLabel);
1023
1024 layout.putConstraint(SpringLayout.EAST, controlBgBtn,
1025 -5,
1026 SpringLayout.EAST, panel);
1027
1028 layout.putConstraint(SpringLayout.NORTH, controlBgBtn,
1029 1,
1030 SpringLayout.SOUTH, backgroundColorLabel);
1031
1032 textBgBtn = new ColorSelectionButton(
1033 GuiPreferences.getColor(GuiPreferences.generalUITextBgKey,
1034 GuiPreferences.generalTextUIBg));
1035
1036 panel.add(textBackgroundLabel);
1037 panel.add(textBgBtn);
1038
1039 textBgBtn.setPreferredSize(new Dimension(0,21));
1040 textBackgroundLabel.setPreferredSize(new Dimension(300,21));
1041
1042 layout.putConstraint(SpringLayout.WEST, textBackgroundLabel,
1043 10,
1044 SpringLayout.WEST, panel);
1045
1046 layout.putConstraint(SpringLayout.EAST, textBackgroundLabel,
1047 labelWidth,
1048 SpringLayout.WEST, panel);
1049
1050 layout.putConstraint(SpringLayout.NORTH, textBackgroundLabel,
1051 1,
1052 SpringLayout.SOUTH, controlBackgroundColorLabel);
1053
1054 layout.putConstraint(SpringLayout.WEST, textBgBtn,
1055 1,
1056 SpringLayout.EAST, textBackgroundLabel);
1057
1058 layout.putConstraint(SpringLayout.EAST, textBgBtn,
1059 -5,
1060 SpringLayout.EAST, panel);
1061
1062 layout.putConstraint(SpringLayout.NORTH, textBgBtn,
1063 1,
1064 SpringLayout.SOUTH, controlBackgroundColorLabel);
1065
1066 toolTipBgBtn = new ColorSelectionButton(
1067 GuiPreferences.getColor(GuiPreferences.generalUIToolTipBgKey,
1068 GuiPreferences.generalUIToolTipBg));
1069
1070 panel.add(toolTipBackgroundLabel);
1071 panel.add(toolTipBgBtn);
1072
1073 toolTipBgBtn.setPreferredSize(new Dimension(0,21));
1074 toolTipBackgroundLabel.setPreferredSize(new Dimension(300,21));
1075
1076 layout.putConstraint(SpringLayout.WEST, toolTipBackgroundLabel,
1077 10,
1078 SpringLayout.WEST, panel);
1079
1080 layout.putConstraint(SpringLayout.EAST, toolTipBackgroundLabel,
1081 labelWidth,
1082 SpringLayout.WEST, panel);
1083
1084 layout.putConstraint(SpringLayout.NORTH, toolTipBackgroundLabel,
1085 1,
1086 SpringLayout.SOUTH, textBackgroundLabel);
1087
1088 layout.putConstraint(SpringLayout.WEST, toolTipBgBtn,
1089 1,
1090 SpringLayout.EAST, toolTipBackgroundLabel);
1091
1092 layout.putConstraint(SpringLayout.EAST, toolTipBgBtn,
1093 -5,
1094 SpringLayout.EAST, panel);
1095
1096 layout.putConstraint(SpringLayout.NORTH, toolTipBgBtn,
1097 1,
1098 SpringLayout.SOUTH, textBackgroundLabel);
1099
1100 highlightedColorBtn = new ColorSelectionButton(
1101 GuiPreferences.getColor(GuiPreferences.generalUIHgKey,
1102 GuiPreferences.generalUIHg));
1103
1104 panel.add(highlightColorLabel);
1105 panel.add(highlightedColorBtn);
1106
1107 highlightedColorBtn.setPreferredSize(new Dimension(0,21));
1108 highlightColorLabel.setPreferredSize(new Dimension(300,21));
1109
1110 layout.putConstraint(SpringLayout.WEST, highlightColorLabel,
1111 10,
1112 SpringLayout.WEST, panel);
1113
1114 layout.putConstraint(SpringLayout.EAST, highlightColorLabel,
1115 labelWidth,
1116 SpringLayout.WEST, panel);
1117
1118 layout.putConstraint(SpringLayout.NORTH, highlightColorLabel,
1119 1,
1120 SpringLayout.SOUTH, toolTipBackgroundLabel);
1121
1122 layout.putConstraint(SpringLayout.WEST, highlightedColorBtn,
1123 1,
1124 SpringLayout.EAST, highlightColorLabel);
1125
1126 layout.putConstraint(SpringLayout.EAST, highlightedColorBtn,
1127 -5,
1128 SpringLayout.EAST, panel);
1129
1130 layout.putConstraint(SpringLayout.NORTH, highlightedColorBtn,
1131 1,
1132 SpringLayout.SOUTH, toolTipBackgroundLabel);
1133
1134 selectedColorBtn = new ColorSelectionButton(
1135 GuiPreferences.getColor(GuiPreferences.generalUISelectionBgKey,
1136 GuiPreferences.generalUISelectionBg));
1137
1138 panel.add(selectedColorLabel);
1139 panel.add(selectedColorBtn);
1140
1141 selectedColorBtn.setPreferredSize(new Dimension(0,21));
1142 selectedColorLabel.setPreferredSize(new Dimension(300,21));
1143
1144 layout.putConstraint(SpringLayout.WEST, selectedColorLabel,
1145 10,
1146 SpringLayout.WEST, panel);
1147
1148 layout.putConstraint(SpringLayout.EAST, selectedColorLabel,
1149 labelWidth,
1150 SpringLayout.WEST, panel);
1151
1152 layout.putConstraint(SpringLayout.NORTH, selectedColorLabel,
1153 1,
1154 SpringLayout.SOUTH, highlightColorLabel);
1155
1156 layout.putConstraint(SpringLayout.WEST, selectedColorBtn,
1157 1,
1158 SpringLayout.EAST, selectedColorLabel);
1159
1160 layout.putConstraint(SpringLayout.EAST, selectedColorBtn,
1161 -5,
1162 SpringLayout.EAST, panel);
1163
1164 layout.putConstraint(SpringLayout.NORTH, selectedColorBtn,
1165 1,
1166 SpringLayout.SOUTH, highlightColorLabel);
1167
1168 panel.setPreferredSize(new Dimension(400, 200));
1169 uiColorsTaskPane.add(panel);
1170 colorsContainer.add(uiColorsTaskPane);
1171
1172 //=====================================================================
1173 //
1174 // TABLE COLORS
1175 //
1176 //=====================================================================
1177
1178 layout = new SpringLayout();
1179 panel = new JPanel();
1180 panel.setLayout(layout);
1181
1182 tableFgBtn = new ColorSelectionButton(
1183 GuiPreferences.getColor(GuiPreferences.tableFgKey,
1184 GuiPreferences.tableFgDef));
1185
1186 tableFgBtn.setPreferredSize(new Dimension(0,21));
1187 tableForegroundColorLabel.setPreferredSize(new Dimension(300,21));
1188
1189 panel.add(tableForegroundColorLabel);
1190 panel.add(tableFgBtn);
1191
1192 layout.putConstraint(SpringLayout.WEST, tableForegroundColorLabel,
1193 10,
1194 SpringLayout.WEST, panel);
1195
1196 layout.putConstraint(SpringLayout.EAST, tableForegroundColorLabel,
1197 labelWidth,
1198 SpringLayout.WEST, panel);
1199
1200 layout.putConstraint(SpringLayout.NORTH, tableForegroundColorLabel,
1201 5,
1202 SpringLayout.NORTH, panel);
1203
1204 layout.putConstraint(SpringLayout.WEST, tableFgBtn,
1205 1,
1206 SpringLayout.EAST, tableForegroundColorLabel);
1207
1208 layout.putConstraint(SpringLayout.EAST, tableFgBtn,
1209 -5,
1210 SpringLayout.EAST, panel);
1211
1212 layout.putConstraint(SpringLayout.NORTH, tableFgBtn,
1213 5,
1214 SpringLayout.NORTH, panel);
1215
1216 tableBgBtn = new ColorSelectionButton(
1217 GuiPreferences.getColor(GuiPreferences.tableBgKey,
1218 GuiPreferences.tableBgDef));
1219
1220 tableBgBtn.setPreferredSize(new Dimension(0,21));
1221 tableBackgroundColorLabel.setPreferredSize(new Dimension(300,21));
1222
1223 panel.add(tableBackgroundColorLabel);
1224 panel.add(tableBgBtn);
1225
1226 layout.putConstraint(SpringLayout.WEST, tableBackgroundColorLabel,
1227 10,
1228 SpringLayout.WEST, panel);
1229
1230 layout.putConstraint(SpringLayout.EAST, tableBackgroundColorLabel,
1231 labelWidth,
1232 SpringLayout.WEST, panel);
1233
1234 layout.putConstraint(SpringLayout.NORTH, tableBackgroundColorLabel,
1235 1,
1236 SpringLayout.SOUTH, tableForegroundColorLabel);
1237
1238 layout.putConstraint(SpringLayout.WEST, tableBgBtn,
1239 1,
1240 SpringLayout.EAST, tableBackgroundColorLabel);
1241
1242 layout.putConstraint(SpringLayout.EAST, tableBgBtn,
1243 -5,
1244 SpringLayout.EAST, panel);
1245
1246 layout.putConstraint(SpringLayout.NORTH, tableBgBtn,
1247 1,
1248 SpringLayout.SOUTH, tableFgBtn);
1249
1250 tableAltBgBtn = new ColorSelectionButton(
1251 GuiPreferences.getColor(GuiPreferences.tableAltBgKey,
1252 GuiPreferences.tableAltBgDef));
1253
1254 tableAltBgBtn.setPreferredSize(new Dimension(0,21));
1255 tableAltBackgroundColorLabel.setPreferredSize(new Dimension(300,21));
1256
1257 panel.add(tableAltBackgroundColorLabel);
1258 panel.add(tableAltBgBtn);
1259
1260 layout.putConstraint(SpringLayout.WEST, tableAltBackgroundColorLabel,
1261 10,
1262 SpringLayout.WEST, panel);
1263
1264 layout.putConstraint(SpringLayout.EAST, tableAltBackgroundColorLabel,
1265 labelWidth,
1266 SpringLayout.WEST, panel);
1267
1268 layout.putConstraint(SpringLayout.NORTH, tableAltBackgroundColorLabel,
1269 1,
1270 SpringLayout.SOUTH, tableBackgroundColorLabel);
1271
1272 layout.putConstraint(SpringLayout.WEST, tableAltBgBtn,
1273 1,
1274 SpringLayout.EAST, tableAltBackgroundColorLabel);
1275
1276 layout.putConstraint(SpringLayout.EAST, tableAltBgBtn,
1277 -5,
1278 SpringLayout.EAST, panel);
1279
1280 layout.putConstraint(SpringLayout.NORTH, tableAltBgBtn,
1281 1,
1282 SpringLayout.SOUTH, tableBgBtn);
1283
1284 tableSelectedHltBtn = new ColorSelectionButton(
1285 GuiPreferences.getColor(GuiPreferences.tableSelectionBgKey,
1286 GuiPreferences.tableSelectionBgDef));
1287
1288 tableSelectedHltBtn.setPreferredSize(new Dimension(0,21));
1289 tableSelectedHighlightColorLabel.setPreferredSize(new Dimension(300,21));
1290
1291 panel.add(tableSelectedHighlightColorLabel);
1292 panel.add(tableSelectedHltBtn);
1293
1294 layout.putConstraint(SpringLayout.WEST, tableSelectedHighlightColorLabel,
1295 10,
1296 SpringLayout.WEST, panel);
1297
1298 layout.putConstraint(SpringLayout.EAST, tableSelectedHighlightColorLabel,
1299 labelWidth,
1300 SpringLayout.WEST, panel);
1301
1302 layout.putConstraint(SpringLayout.NORTH, tableSelectedHighlightColorLabel,
1303 1,
1304 SpringLayout.SOUTH, tableAltBackgroundColorLabel);
1305
1306 layout.putConstraint(SpringLayout.WEST, tableSelectedHltBtn,
1307 1,
1308 SpringLayout.EAST, tableSelectedHighlightColorLabel);
1309
1310 layout.putConstraint(SpringLayout.EAST, tableSelectedHltBtn,
1311 -5,
1312 SpringLayout.EAST, panel);
1313
1314 layout.putConstraint(SpringLayout.NORTH, tableSelectedHltBtn,
1315 1,
1316 SpringLayout.SOUTH, tableAltBgBtn);
1317
1318 tableIncomeHltBtn = new ColorSelectionButton(
1319 GuiPreferences.getColor(GuiPreferences.tableAllocHgKey,
1320 GuiPreferences.tableAllocHgDef));
1321
1322 tableIncomeHltBtn.setPreferredSize(new Dimension(0,21));
1323 tableIncomeHighlightColorLabel.setPreferredSize(new Dimension(300,21));
1324
1325 panel.add(tableIncomeHighlightColorLabel);
1326 panel.add(tableIncomeHltBtn);
1327
1328 layout.putConstraint(SpringLayout.WEST, tableIncomeHighlightColorLabel,
1329 10,
1330 SpringLayout.WEST, panel);
1331
1332 layout.putConstraint(SpringLayout.EAST, tableIncomeHighlightColorLabel,
1333 labelWidth,
1334 SpringLayout.WEST, panel);
1335
1336 layout.putConstraint(SpringLayout.NORTH, tableIncomeHighlightColorLabel,
1337 1,
1338 SpringLayout.SOUTH, tableSelectedHighlightColorLabel);
1339
1340 layout.putConstraint(SpringLayout.WEST, tableIncomeHltBtn,
1341 1,
1342 SpringLayout.EAST, tableIncomeHighlightColorLabel);
1343
1344 layout.putConstraint(SpringLayout.EAST, tableIncomeHltBtn,
1345 -5,
1346 SpringLayout.EAST, panel);
1347
1348 layout.putConstraint(SpringLayout.NORTH, tableIncomeHltBtn,
1349 1,
1350 SpringLayout.SOUTH, tableSelectedHltBtn);
1351
1352 tableExpenseHltBtn = new ColorSelectionButton(
1353 GuiPreferences.getColor(GuiPreferences.tableExpenseHgKey,
1354 GuiPreferences.tableExpenseHgDef));
1355
1356 tableExpenseHltBtn.setPreferredSize(new Dimension(0,21));
1357 tableExpenseHighlightColorLabel.setPreferredSize(new Dimension(300,21));
1358
1359 panel.add(tableExpenseHighlightColorLabel);
1360 panel.add(tableExpenseHltBtn);
1361
1362 layout.putConstraint(SpringLayout.WEST, tableExpenseHighlightColorLabel,
1363 10,
1364 SpringLayout.WEST, panel);
1365
1366 layout.putConstraint(SpringLayout.EAST, tableExpenseHighlightColorLabel,
1367 labelWidth,
1368 SpringLayout.WEST, panel);
1369
1370 layout.putConstraint(SpringLayout.NORTH, tableExpenseHighlightColorLabel,
1371 1,
1372 SpringLayout.SOUTH, tableIncomeHighlightColorLabel);
1373
1374 layout.putConstraint(SpringLayout.WEST, tableExpenseHltBtn,
1375 1,
1376 SpringLayout.EAST, tableExpenseHighlightColorLabel);
1377
1378 layout.putConstraint(SpringLayout.EAST, tableExpenseHltBtn,
1379 -5,
1380 SpringLayout.EAST, panel);
1381
1382 layout.putConstraint(SpringLayout.NORTH, tableExpenseHltBtn,
1383 1,
1384 SpringLayout.SOUTH, tableIncomeHltBtn);
1385
1386 defaultLFColorsCheckBox.setSelected(
1387 !GuiPreferences.getBoolean(GuiPreferences.generalUIColorsSelectKey,
1388 GuiPreferences.generalUIColorsSelectDef));
1389
1390 panel.setPreferredSize(new Dimension(400, 155));
1391 tableColorsTaskPane.add(panel);
1392 colorsContainer.add(tableColorsTaskPane);
1393
1394 uiColorsTaskPane.setCollapsed(true);
1395 tableColorsTaskPane.setCollapsed(false);
1396 }
1397
1398 /** Initializes GUI actions associated with the Color Pane. */
1399 private void initializeColorPaneActions()
1400 {
1401 // Allow only one expanded panel.
1402 PropertyChangeListener expansionListener = new PropertyChangeListener()
1403 {
1404 JXTaskPane[] panes = {uiColorsTaskPane, tableColorsTaskPane};
1405
1406 public void propertyChange(PropertyChangeEvent event)
1407 {
1408 if (!event.getPropertyName().equals("collapsed"))
1409 {
1410 return;
1411 }
1412 if (((Boolean) event.getNewValue()).booleanValue())
1413 {
1414 return;
1415 }
1416
1417 for (JXTaskPane panel : panes)
1418 if (event.getSource() != panel)
1419 panel.setCollapsed(true);
1420 }
1421 };
1422
1423 uiColorsTaskPane.addPropertyChangeListener(expansionListener);
1424 tableColorsTaskPane.addPropertyChangeListener(expansionListener);
1425 }
1426
1427 /** Save the colors from the Preferences Editor Panel to the GuiPreferences. */
1428 private void commitColors()
1429 {
1430
1431 // General Colors
1432
1433 GuiPreferences.setColor(GuiPreferences.generalUIFgKey,
1434 fgBtn.getSelectedColor());
1435
1436 GuiPreferences.setColor(GuiPreferences.generalUIBgKey,
1437 bgBtn.getSelectedColor());
1438
1439 GuiPreferences.setColor(GuiPreferences.generalUIControlBgKey,
1440 controlBgBtn.getSelectedColor());
1441
1442 GuiPreferences.setColor(GuiPreferences.generalUITextBgKey,
1443 textBgBtn.getSelectedColor());
1444
1445 GuiPreferences.setColor(GuiPreferences.generalUIToolTipBgKey,
1446 toolTipBgBtn.getSelectedColor());
1447
1448 GuiPreferences.setColor(GuiPreferences.generalUIHgKey,
1449 highlightedColorBtn.getSelectedColor());
1450
1451 GuiPreferences.setColor(GuiPreferences.generalUISelectionBgKey,
1452 selectedColorBtn.getSelectedColor());
1453
1454 // Table colors
1455
1456 GuiPreferences.setColor(GuiPreferences.tableFgKey,
1457 tableFgBtn.getSelectedColor());
1458
1459 GuiPreferences.setColor(GuiPreferences.tableBgKey,
1460 tableBgBtn.getSelectedColor());
1461
1462 GuiPreferences.setColor(GuiPreferences.tableAltBgKey,
1463 tableAltBgBtn.getSelectedColor());
1464
1465 GuiPreferences.setColor(GuiPreferences.tableSelectionBgKey,
1466 tableSelectedHltBtn.getSelectedColor());
1467
1468 GuiPreferences.setColor(GuiPreferences.tableAllocHgKey,
1469 tableIncomeHltBtn.getSelectedColor());
1470
1471 GuiPreferences.setColor(GuiPreferences.tableExpenseHgKey,
1472 tableExpenseHltBtn.getSelectedColor());
1473
1474 GuiPreferences.setBoolean(GuiPreferences.generalUIColorsSelectKey,
1475 !defaultLFColorsCheckBox.isSelected());
1476 }
1477
1478 //==========================================================================
1479 //
1480 // Methods
1481 //
1482 //==========================================================================
1483
1484 public void applySelections()
1485 {
1486 commitLF();
1487 GuiPreferences.installLF();
1488 commitFonts();
1489 commitColors();
1490 GuiPreferences.updateUIDefaults();
1491 }
1492
1493 //==========================================================================
1494 //
1495 // Inner Classes
1496 //
1497 //==========================================================================
1498
1499 private static class LocaleRenderer extends JLabel implements ListCellRenderer
1500 {
1501 public Component getListCellRendererComponent(JList list,
1502 Object value,
1503 int index,
1504 boolean isSelected,
1505 boolean cellHasFocus)
1506 {
1507 if (!(value instanceof Locale))
1508 {
1509 setText(value.toString());
1510 return this;
1511 }
1512
1513 Locale locale = (Locale) value;
1514
1515 StringBuffer buffer = new StringBuffer();
1516
1517 buffer.append(locale.getLanguage());
1518 String country = locale.getCountry();
1519 if (country != null && country.length() != 0)
1520 {
1521 buffer.append(", ");
1522 buffer.append(country);
1523 buffer.append("; ");
1524 buffer.append(Currency.getInstance(locale).getSymbol());
1525 }
1526
1527 setText(buffer.toString());
1528 return this;
1529 }
1530 }
1531
1532 }