001: /*
002: * StyleEditor.java - Style editor dialog
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 1999, 2000, 2001 Slava Pestov
007: * Portions copyright (C) 1999 mike dillon
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: */
023: package org.gjt.sp.jedit.gui;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Color;
027: import java.awt.Component;
028: import java.awt.Font;
029: import java.awt.GridLayout;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: import javax.swing.Box;
034: import javax.swing.BoxLayout;
035: import javax.swing.JButton;
036: import javax.swing.JCheckBox;
037: import javax.swing.JDialog;
038: import javax.swing.JFrame;
039: import javax.swing.JLabel;
040: import javax.swing.JPanel;
041: import javax.swing.border.EmptyBorder;
042:
043: import org.gjt.sp.jedit.GUIUtilities;
044: import org.gjt.sp.jedit.jEdit;
045: import org.gjt.sp.jedit.syntax.SyntaxStyle;
046:
047: //{{{ StyleEditor class
048: public class StyleEditor extends EnhancedDialog implements
049: ActionListener {
050: //{{{ StyleEditor constructor
051: public StyleEditor(JDialog parent, SyntaxStyle style,
052: String styleName) {
053: super (parent, jEdit.getProperty("style-editor.title"), true);
054: initialize(parent, style, styleName);
055: }
056:
057: public StyleEditor(JFrame parent, SyntaxStyle style,
058: String styleName) {
059: super (parent, jEdit.getProperty("style-editor.title"), true);
060: initialize(parent, style, styleName);
061: }
062:
063: private void initialize(Component comp, SyntaxStyle style,
064: String styleName) {
065: JPanel content = new JPanel(new BorderLayout(12, 12));
066: content.setBorder(new EmptyBorder(12, 12, 12, 12));
067: setContentPane(content);
068:
069: JPanel panel = new JPanel(new GridLayout(5, 2, 12, 12));
070:
071: panel.add(new JLabel(jEdit
072: .getProperty("style-editor.tokenType")));
073: panel.add(new JLabel(styleName));
074:
075: italics = new JCheckBox(jEdit
076: .getProperty("style-editor.italics"));
077: italics.setSelected(style.getFont().isItalic());
078: panel.add(italics);
079: panel.add(new JLabel());
080:
081: bold = new JCheckBox(jEdit.getProperty("style-editor.bold"));
082: bold.setSelected(style.getFont().isBold());
083: panel.add(bold);
084: panel.add(new JLabel());
085:
086: Color fg = style.getForegroundColor();
087:
088: fgColorCheckBox = new JCheckBox(jEdit
089: .getProperty("style-editor.fgColor"));
090: fgColorCheckBox.setSelected(fg != null);
091: fgColorCheckBox.addActionListener(this );
092: panel.add(fgColorCheckBox);
093:
094: fgColor = new ColorWellButton(fg);
095: fgColor.setEnabled(fg != null);
096: panel.add(fgColor);
097:
098: Color bg = style.getBackgroundColor();
099: bgColorCheckBox = new JCheckBox(jEdit
100: .getProperty("style-editor.bgColor"));
101: bgColorCheckBox.setSelected(bg != null);
102: bgColorCheckBox.addActionListener(this );
103: panel.add(bgColorCheckBox);
104:
105: bgColor = new ColorWellButton(bg);
106: bgColor.setEnabled(bg != null);
107: panel.add(bgColor);
108:
109: content.add(BorderLayout.CENTER, panel);
110:
111: Box box = new Box(BoxLayout.X_AXIS);
112: box.add(Box.createGlue());
113: box.add(ok = new JButton(jEdit.getProperty("common.ok")));
114: getRootPane().setDefaultButton(ok);
115: ok.addActionListener(this );
116: box.add(Box.createHorizontalStrut(6));
117: box
118: .add(cancel = new JButton(jEdit
119: .getProperty("common.cancel")));
120: cancel.addActionListener(this );
121: box.add(Box.createGlue());
122:
123: content.add(BorderLayout.SOUTH, box);
124:
125: pack();
126: setLocationRelativeTo(comp);
127:
128: setResizable(false);
129: setVisible(true);
130: } //}}}
131:
132: //{{{ actionPerformed() method
133: public void actionPerformed(ActionEvent evt) {
134: Object source = evt.getSource();
135: if (source == ok)
136: ok();
137: else if (source == cancel)
138: cancel();
139: else if (source == fgColorCheckBox)
140: fgColor.setEnabled(fgColorCheckBox.isSelected());
141: else if (source == bgColorCheckBox)
142: bgColor.setEnabled(bgColorCheckBox.isSelected());
143: } //}}}
144:
145: //{{{ ok() method
146: public void ok() {
147: okClicked = true;
148: dispose();
149: } //}}}
150:
151: //{{{ cancel() method
152: public void cancel() {
153: dispose();
154: } //}}}
155:
156: //{{{ getStyle() method
157: public SyntaxStyle getStyle() {
158: if (!okClicked)
159: return null;
160:
161: Color foreground = (fgColorCheckBox.isSelected() ? fgColor
162: .getSelectedColor() : null);
163:
164: Color background = (bgColorCheckBox.isSelected() ? bgColor
165: .getSelectedColor() : null);
166:
167: return new SyntaxStyle(foreground, background, new Font(
168: "Dialog", (italics.isSelected() ? Font.ITALIC : 0)
169: | (bold.isSelected() ? Font.BOLD : 0), 12));
170: } //}}}
171:
172: //{{{ Private members
173: private JCheckBox italics;
174: private JCheckBox bold;
175: private JCheckBox fgColorCheckBox;
176: private ColorWellButton fgColor;
177: private JCheckBox bgColorCheckBox;
178: private ColorWellButton bgColor;
179: private JButton ok;
180: private JButton cancel;
181: private boolean okClicked;
182: //}}}
183: } //}}}
|