001: /*
002: * QuickNotepadOptionPane.java
003: * part of the QuickNotepad plugin for the jEdit text editor
004: * Copyright (C) 2001 John Gellene
005: * jgellene@nyc.rr.com
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: * $Id: QuickNotepadOptionPane.java 5275 2005-09-10 19:40:17Z ezust $
022: */
023:
024: import java.awt.BorderLayout;
025: import java.awt.Font;
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028:
029: import javax.swing.JButton;
030: import javax.swing.JCheckBox;
031: import javax.swing.JFileChooser;
032: import javax.swing.JPanel;
033: import javax.swing.JTextField;
034:
035: import org.gjt.sp.jedit.AbstractOptionPane;
036: import org.gjt.sp.jedit.GUIUtilities;
037: import org.gjt.sp.jedit.jEdit;
038: import org.gjt.sp.jedit.gui.FontSelector;
039:
040: public class QuickNotepadOptionPane extends AbstractOptionPane
041: implements ActionListener {
042: private JCheckBox showPath;
043:
044: private JTextField pathName;
045:
046: private FontSelector font;
047:
048: public QuickNotepadOptionPane() {
049: super (QuickNotepadPlugin.NAME);
050: }
051:
052: public void _init() {
053: showPath = new JCheckBox(jEdit
054: .getProperty(QuickNotepadPlugin.OPTION_PREFIX
055: + "show-filepath.title"), jEdit.getProperty(
056: QuickNotepadPlugin.OPTION_PREFIX + "show-filepath")
057: .equals("true"));
058: addComponent(showPath);
059:
060: pathName = new JTextField(jEdit
061: .getProperty(QuickNotepadPlugin.OPTION_PREFIX
062: + "filepath"));
063: JButton pickPath = new JButton(jEdit
064: .getProperty(QuickNotepadPlugin.OPTION_PREFIX
065: + "choose-file"));
066: pickPath.addActionListener(this );
067:
068: JPanel pathPanel = new JPanel(new BorderLayout(0, 0));
069: pathPanel.add(pathName, BorderLayout.CENTER);
070: pathPanel.add(pickPath, BorderLayout.EAST);
071:
072: addComponent(jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
073: + "file"), pathPanel);
074:
075: font = new FontSelector(makeFont());
076: addComponent(jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
077: + "choose-font"), font);
078: }
079:
080: public void _save() {
081: jEdit.setProperty(
082: QuickNotepadPlugin.OPTION_PREFIX + "filepath", pathName
083: .getText());
084: Font _font = font.getFont();
085: jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "font",
086: _font.getFamily());
087: jEdit.setProperty(
088: QuickNotepadPlugin.OPTION_PREFIX + "fontsize", String
089: .valueOf(_font.getSize()));
090: jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX
091: + "fontstyle", String.valueOf(_font.getStyle()));
092: jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX
093: + "show-filepath", String
094: .valueOf(showPath.isSelected()));
095: }
096:
097: // end AbstractOptionPane implementation
098:
099: // begin ActionListener implementation
100: public void actionPerformed(ActionEvent evt) {
101: String[] paths = GUIUtilities.showVFSFileDialog(null, null,
102: JFileChooser.OPEN_DIALOG, false);
103: if (paths != null) {
104: pathName.setText(paths[0]);
105: }
106: }
107:
108: // helper method to get Font from plugin properties
109: static public Font makeFont() {
110: int style, size;
111: String family = jEdit
112: .getProperty(QuickNotepadPlugin.OPTION_PREFIX + "font");
113: try {
114: size = Integer.parseInt(jEdit
115: .getProperty(QuickNotepadPlugin.OPTION_PREFIX
116: + "fontsize"));
117: } catch (NumberFormatException nf) {
118: size = 14;
119: }
120: try {
121: style = Integer.parseInt(jEdit
122: .getProperty(QuickNotepadPlugin.OPTION_PREFIX
123: + "fontstyle"));
124: } catch (NumberFormatException nf) {
125: style = Font.PLAIN;
126: }
127: return new Font(family, style, size);
128: }
129:
130: }
|