KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > QuickNotepadOptionPane


1 /*
2  * QuickNotepadOptionPane.java
3  * part of the QuickNotepad plugin for the jEdit text editor
4  * Copyright (C) 2001 John Gellene
5  * jgellene@nyc.rr.com
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * $Id: QuickNotepadOptionPane.java 5275 2005-09-10 19:40:17Z ezust $
22  */

23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import java.awt.event.ActionListener JavaDoc;
28
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.JCheckBox JavaDoc;
31 import javax.swing.JFileChooser JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JTextField JavaDoc;
34
35 import org.gjt.sp.jedit.AbstractOptionPane;
36 import org.gjt.sp.jedit.GUIUtilities;
37 import org.gjt.sp.jedit.jEdit;
38 import org.gjt.sp.jedit.gui.FontSelector;
39
40 public class QuickNotepadOptionPane extends AbstractOptionPane implements
41         ActionListener JavaDoc {
42     private JCheckBox JavaDoc showPath;
43
44     private JTextField JavaDoc pathName;
45
46     private FontSelector font;
47
48     public QuickNotepadOptionPane() {
49         super(QuickNotepadPlugin.NAME);
50     }
51
52     public void _init() {
53         showPath = new JCheckBox JavaDoc(jEdit
54                 .getProperty(QuickNotepadPlugin.OPTION_PREFIX
55                         + "show-filepath.title"), jEdit.getProperty(
56                 QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals(
57                 "true"));
58         addComponent(showPath);
59
60         pathName = new JTextField JavaDoc(jEdit
61                 .getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath"));
62         JButton JavaDoc pickPath = new JButton JavaDoc(jEdit
63                 .getProperty(QuickNotepadPlugin.OPTION_PREFIX + "choose-file"));
64         pickPath.addActionListener(this);
65
66         JPanel JavaDoc pathPanel = new JPanel JavaDoc(new BorderLayout JavaDoc(0, 0));
67         pathPanel.add(pathName, BorderLayout.CENTER);
68         pathPanel.add(pickPath, BorderLayout.EAST);
69
70         addComponent(jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
71                 + "file"), pathPanel);
72
73         font = new FontSelector(makeFont());
74         addComponent(jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
75                 + "choose-font"), font);
76     }
77
78     public void _save() {
79         jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath",
80                 pathName.getText());
81         Font JavaDoc _font = font.getFont();
82         jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "font", _font
83                 .getFamily());
84         jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontsize", String
85                 .valueOf(_font.getSize()));
86         jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontstyle",
87                 String.valueOf(_font.getStyle()));
88         jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "show-filepath",
89                 String.valueOf(showPath.isSelected()));
90     }
91
92     // end AbstractOptionPane implementation
93

94     // begin ActionListener implementation
95
public void actionPerformed(ActionEvent JavaDoc evt) {
96         String JavaDoc[] paths = GUIUtilities.showVFSFileDialog(null, null,
97                 JFileChooser.OPEN_DIALOG, false);
98         if (paths != null) {
99             pathName.setText(paths[0]);
100         }
101     }
102
103     // helper method to get Font from plugin properties
104
static public Font JavaDoc makeFont() {
105         int style, size;
106         String JavaDoc family = jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
107                 + "font");
108         try {
109             size = Integer
110                     .parseInt(jEdit
111                             .getProperty(QuickNotepadPlugin.OPTION_PREFIX
112                                     + "fontsize"));
113         } catch (NumberFormatException JavaDoc nf) {
114             size = 14;
115         }
116         try {
117             style = Integer
118                     .parseInt(jEdit
119                             .getProperty(QuickNotepadPlugin.OPTION_PREFIX
120                                     + "fontstyle"));
121         } catch (NumberFormatException JavaDoc nf) {
122             style = Font.PLAIN;
123         }
124         return new Font JavaDoc(family, style, size);
125     }
126
127 }
128
Popular Tags