001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.colorchooser;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Color;
023:
024: import javax.swing.JColorChooser;
025: import javax.swing.JPanel;
026: import javax.swing.LookAndFeel;
027: import javax.swing.UIManager;
028:
029: import com.jeta.open.gui.framework.JETADialog;
030: import com.jeta.open.gui.framework.JETAPanel;
031: import com.jeta.open.gui.utils.JETAToolbox;
032: import com.jeta.open.i18n.I18N;
033:
034: public class JETAColorChooser extends JETAPanel {
035: /**
036: * The current look and feel
037: */
038: private static LookAndFeel m_look_and_feel;
039:
040: private JColorChooser m_cc;
041: private RecentSwatchPanel m_recent_panel;
042:
043: public JETAColorChooser() {
044: m_look_and_feel = UIManager.getLookAndFeel();
045:
046: setLayout(new BorderLayout());
047: m_cc = new JColorChooser();
048: m_recent_panel = new RecentSwatchPanel();
049: m_recent_panel.setController(new RecentSwatchController(
050: m_recent_panel, this ));
051: add(m_cc, BorderLayout.CENTER);
052:
053: JPanel swatch_panel = new JPanel();
054: swatch_panel.add(m_recent_panel);
055: swatch_panel.setBorder(javax.swing.BorderFactory
056: .createTitledBorder(I18N
057: .getLocalizedMessage("Recent Selections")));
058: add(swatch_panel, BorderLayout.SOUTH);
059: }
060:
061: public Color getColor() {
062: return m_cc.getColor();
063: }
064:
065: /**
066: * Invokes a ColorChooser dialog.
067: */
068: public static Color invokeColorChooser(
069: java.awt.Component parentComp, Color selectedColor) {
070: JETAColorChooser color_chooser = new JETAColorChooser();
071:
072: if (selectedColor != null) {
073: color_chooser.setColor(selectedColor);
074: }
075:
076: JETADialog dlg = (JETADialog) JETAToolbox.createDialog(
077: JETADialog.class, parentComp, true);
078: dlg.setPrimaryPanel(color_chooser);
079: dlg.setTitle(I18N.getLocalizedMessage("Color Chooser"));
080: dlg.setSize(dlg.getPreferredSize());
081: dlg.showCenter();
082: if (dlg.isOk()) {
083: Color c = color_chooser.getColor();
084: color_chooser.m_recent_panel.setMostRecentColor(c);
085: color_chooser.m_recent_panel.saveSettings();
086: return c;
087: } else
088: return null;
089: }
090:
091: private static boolean isLookAndFeelChanged() {
092: LookAndFeel lf = UIManager.getLookAndFeel();
093: if (m_look_and_feel != lf) {
094: m_look_and_feel = lf;
095: return true;
096: }
097: return false;
098: }
099:
100: public void setColor(Color c) {
101: m_cc.setColor(c);
102: }
103:
104: }
|