/jEdit/tags/jedit-4-2-pre4/jars/QuickNotepad/QuickNotepadOptionPane.java
Java | 138 lines | 97 code | 16 blank | 25 comment | 2 complexity | acb2cdc60b6d9ffb040aaa7cae53f9d9 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
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 3892 2001-11-11 12:26:20Z jgellene $
22 */
23
24import java.io.File;
25import java.io.IOException;
26import java.awt.Font;
27import java.awt.BorderLayout;
28import java.awt.event.ActionEvent;
29import java.awt.event.ActionListener;
30
31import javax.swing.JButton;
32import javax.swing.JCheckBox;
33import javax.swing.JPanel;
34import javax.swing.JTextField;
35import javax.swing.JFileChooser;
36
37import org.gjt.sp.jedit.jEdit;
38import org.gjt.sp.jedit.GUIUtilities;
39import org.gjt.sp.jedit.AbstractOptionPane;
40import org.gjt.sp.jedit.gui.FontSelector;
41
42
43public class QuickNotepadOptionPane extends AbstractOptionPane
44 implements ActionListener
45{
46 private JCheckBox showPath;
47 private JTextField pathName;
48 private FontSelector font;
49
50 public QuickNotepadOptionPane()
51 {
52 super(QuickNotepadPlugin.NAME);
53 }
54
55 public void _init()
56 {
57 showPath = new JCheckBox(jEdit.getProperty(
58 QuickNotepadPlugin.OPTION_PREFIX + "show-filepath.title"),
59 jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX +
60 "show-filepath").equals("true"));
61 addComponent(showPath);
62
63 pathName = new JTextField(jEdit.getProperty(
64 QuickNotepadPlugin.OPTION_PREFIX + "filepath"));
65 JButton pickPath = new JButton(jEdit.getProperty(
66 QuickNotepadPlugin.OPTION_PREFIX + "choose-file"));
67 pickPath.addActionListener(this);
68
69 JPanel pathPanel = new JPanel(new BorderLayout(0, 0));
70 pathPanel.add(pathName, BorderLayout.CENTER);
71 pathPanel.add(pickPath, BorderLayout.EAST);
72
73 addComponent(jEdit.getProperty(
74 QuickNotepadPlugin.OPTION_PREFIX + "file"),
75 pathPanel);
76
77 font = new FontSelector(makeFont());
78 addComponent(jEdit.getProperty(
79 QuickNotepadPlugin.OPTION_PREFIX + "choose-font"),
80 font);
81 }
82
83 public void _save()
84 {
85 jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath",
86 pathName.getText());
87 Font _font = font.getFont();
88 jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "font",
89 _font.getFamily());
90 jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontsize",
91 String.valueOf(_font.getSize()));
92 jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontstyle",
93 String.valueOf(_font.getStyle()));
94 jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "show-filepath",
95 String.valueOf(showPath.isSelected()));
96 }
97 // end AbstractOptionPane implementation
98
99 // begin ActionListener implementation
100 public void actionPerformed(ActionEvent evt)
101 {
102 String[] paths = GUIUtilities.showVFSFileDialog(null,
103 null,JFileChooser.OPEN_DIALOG,false);
104 if(paths != null)
105 {
106 pathName.setText(paths[0]);
107 }
108 }
109
110 // helper method to get Font from plugin properties
111 static public Font makeFont()
112 {
113 int style, size;
114 String family = jEdit.getProperty(
115 QuickNotepadPlugin.OPTION_PREFIX + "font");
116 try
117 {
118 size = Integer.parseInt(jEdit.getProperty(
119 QuickNotepadPlugin.OPTION_PREFIX + "fontsize"));
120 }
121 catch(NumberFormatException nf)
122 {
123 size = 14;
124 }
125 try
126 {
127 style = Integer.parseInt(jEdit.getProperty(
128 QuickNotepadPlugin.OPTION_PREFIX + "fontstyle"));
129 }
130 catch(NumberFormatException nf)
131 {
132 style = Font.PLAIN;
133 }
134 return new Font(family, style, size);
135 }
136
137}
138