001: package net.sourceforge.squirrel_sql.plugins.syntax.prefspanel;
002:
003: /*
004: * Copyright (C) 2003 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or 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, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021: import java.awt.Color;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024:
025: import javax.swing.JButton;
026: import javax.swing.JColorChooser;
027: import javax.swing.JToggleButton;
028: import javax.swing.JToolBar;
029:
030: import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxPluginResources;
031: import net.sourceforge.squirrel_sql.plugins.syntax.SyntaxStyle;
032: import net.sourceforge.squirrel_sql.fw.util.StringManager;
033: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
034:
035: /**
036: * This panel allows maintenance of the selected Syntax Style.
037: *
038: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
039: */
040: public class StyleMaintenancePanel extends JToolBar {
041:
042: private static final StringManager s_stringMgr = StringManagerFactory
043: .getStringManager(StyleMaintenancePanel.class);
044:
045: private final StylesList _list;
046: private final JToggleButton _boldChk;
047: private final JToggleButton _italicChk;
048: private final JButton _fontColorBtn;
049: private final JButton _backgroundColorBtn;
050: private FontColorButtonListener _fontColorBtnLis;
051: private BackgroundColorButtonListener _backgroundColorBtnLis;
052: private ActionListener _toggleLis;
053:
054: private SyntaxStyle _style;
055:
056: public StyleMaintenancePanel(StylesList list,
057: SyntaxPluginResources rsrc) {
058: super ();
059: _list = list;
060:
061: this .setFloatable(false);
062:
063: _boldChk = new JToggleButton(rsrc
064: .getIcon(SyntaxPluginResources.IKeys.BOLD_IMAGE));
065: //i18n[syntax.bold=Bold]
066: _boldChk.setToolTipText(s_stringMgr.getString("syntax.bold"));
067: _italicChk = new JToggleButton(rsrc
068: .getIcon(SyntaxPluginResources.IKeys.ITALIC_IMAGE));
069: //i18n[syntax.italic=Italic]
070: _italicChk.setToolTipText(s_stringMgr
071: .getString("syntax.italic"));
072:
073: _fontColorBtn = new JButton(rsrc
074: .getIcon(SyntaxPluginResources.IKeys.FOREGROUND_IMAGE));
075: //i18n[syntax.font=Select font color]
076: _fontColorBtn.setToolTipText(s_stringMgr
077: .getString("syntax.font"));
078: _backgroundColorBtn = new JButton(rsrc
079: .getIcon(SyntaxPluginResources.IKeys.BACKGROUND_IMAGE));
080: //i18n[syntax.background=Select background color]
081: _backgroundColorBtn.setToolTipText(s_stringMgr
082: .getString("syntax.background"));
083:
084: add(_boldChk);
085: add(_italicChk);
086: add(_fontColorBtn);
087: add(_backgroundColorBtn);
088: }
089:
090: /**
091: * Component has been added to its parent so setup listeners etc.
092: */
093: public void addNotify() {
094: super .addNotify();
095:
096: if (_fontColorBtnLis == null) {
097: _fontColorBtnLis = new FontColorButtonListener(_list);
098: _fontColorBtn.addActionListener(_fontColorBtnLis);
099: _backgroundColorBtnLis = new BackgroundColorButtonListener(
100: _list);
101: _backgroundColorBtn
102: .addActionListener(_backgroundColorBtnLis);
103: }
104:
105: if (_toggleLis == null) {
106: _toggleLis = new ToggleButtonListener();
107: _boldChk.addActionListener(_toggleLis);
108: _italicChk.addActionListener(_toggleLis);
109: }
110: }
111:
112: /**
113: * Component has been removed from its parent so remove listeners etc.
114: */
115: public void removeNotify() {
116: if (_fontColorBtnLis != null) {
117: _fontColorBtn.removeActionListener(_fontColorBtnLis);
118: _backgroundColorBtn
119: .removeActionListener(_backgroundColorBtnLis);
120: _fontColorBtnLis = null;
121: _backgroundColorBtnLis = null;
122: }
123: if (_toggleLis != null) {
124: _boldChk.removeActionListener(_toggleLis);
125: _italicChk.removeActionListener(_toggleLis);
126: _toggleLis = null;
127: }
128:
129: super .removeNotify();
130: }
131:
132: public void setEnabled(boolean enable) {
133: _boldChk.setEnabled(enable);
134: _italicChk.setEnabled(enable);
135: _fontColorBtn.setEnabled(enable);
136: _backgroundColorBtn.setEnabled(enable);
137: }
138:
139: public void setStyle(SyntaxStyle style) {
140: _boldChk.setSelected(style.isBold());
141: _italicChk.setSelected(style.isItalic());
142: _style = style;
143: }
144:
145: private final class ToggleButtonListener implements ActionListener {
146: public void actionPerformed(ActionEvent evt) {
147: _style.setBold(_boldChk.isSelected());
148: _style.setItalic(_italicChk.isSelected());
149: _list.repaint();
150: }
151: }
152:
153: /**
154: * Listener for the Font Color selection button. Show a Color selection
155: * dialog and if the user selects a color update the current style with
156: * that color.
157: */
158: private static class FontColorButtonListener implements
159: ActionListener {
160: private final StylesList _list;
161:
162: FontColorButtonListener(StylesList list) {
163: super ();
164: _list = list;
165: }
166:
167: public void actionPerformed(ActionEvent evt) {
168: final SyntaxStyle style = _list.getSelectedSyntaxStyle();
169: final int origRGB = style.getTextRGB();
170: final Color color = JColorChooser.showDialog(null,
171: //i18n[syntax.selColor=Select Color]
172: s_stringMgr.getString("syntax.selColor"),
173: new Color(origRGB));
174: if (color != null) {
175: style.setTextRGB(color.getRGB());
176: }
177: }
178: }
179:
180: /**
181: * Listener for the Background Color selection button. Show a Color
182: * selection dialog and if the user selects a color update the current
183: * style with that color.
184: */
185: private static class BackgroundColorButtonListener implements
186: ActionListener {
187: private final StylesList _list;
188:
189: BackgroundColorButtonListener(StylesList list) {
190: super ();
191: _list = list;
192: }
193:
194: public void actionPerformed(ActionEvent evt) {
195: final SyntaxStyle style = _list.getSelectedSyntaxStyle();
196: final int origRGB = style.getBackgroundRGB();
197: final Color color = JColorChooser.showDialog(null,
198: //i18n[syntax.selColor2=Select Color]
199: s_stringMgr.getString("syntax.selColor2"),
200: new Color(origRGB));
201: if (color != null) {
202: style.setBackgroundRGB(color.getRGB());
203: }
204:
205: }
206: }
207: }
|