/jEdit/tags/jedit-4-0-pre3/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
- /*
- * QuickNotepadOptionPane.java
- * part of the QuickNotepad plugin for the jEdit text editor
- * Copyright (C) 2001 John Gellene
- * jgellene@nyc.rr.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id: QuickNotepadOptionPane.java 3892 2001-11-11 12:26:20Z jgellene $
- */
- import java.io.File;
- import java.io.IOException;
- import java.awt.Font;
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.JFileChooser;
- import org.gjt.sp.jedit.jEdit;
- import org.gjt.sp.jedit.GUIUtilities;
- import org.gjt.sp.jedit.AbstractOptionPane;
- import org.gjt.sp.jedit.gui.FontSelector;
- public class QuickNotepadOptionPane extends AbstractOptionPane
- implements ActionListener
- {
- private JCheckBox showPath;
- private JTextField pathName;
- private FontSelector font;
- public QuickNotepadOptionPane()
- {
- super(QuickNotepadPlugin.NAME);
- }
- public void _init()
- {
- showPath = new JCheckBox(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "show-filepath.title"),
- jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX +
- "show-filepath").equals("true"));
- addComponent(showPath);
- pathName = new JTextField(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "filepath"));
- JButton pickPath = new JButton(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "choose-file"));
- pickPath.addActionListener(this);
- JPanel pathPanel = new JPanel(new BorderLayout(0, 0));
- pathPanel.add(pathName, BorderLayout.CENTER);
- pathPanel.add(pickPath, BorderLayout.EAST);
- addComponent(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "file"),
- pathPanel);
- font = new FontSelector(makeFont());
- addComponent(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "choose-font"),
- font);
- }
- public void _save()
- {
- jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath",
- pathName.getText());
- Font _font = font.getFont();
- jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "font",
- _font.getFamily());
- jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontsize",
- String.valueOf(_font.getSize()));
- jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontstyle",
- String.valueOf(_font.getStyle()));
- jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "show-filepath",
- String.valueOf(showPath.isSelected()));
- }
- // end AbstractOptionPane implementation
- // begin ActionListener implementation
- public void actionPerformed(ActionEvent evt)
- {
- String[] paths = GUIUtilities.showVFSFileDialog(null,
- null,JFileChooser.OPEN_DIALOG,false);
- if(paths != null)
- {
- pathName.setText(paths[0]);
- }
- }
- // helper method to get Font from plugin properties
- static public Font makeFont()
- {
- int style, size;
- String family = jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "font");
- try
- {
- size = Integer.parseInt(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "fontsize"));
- }
- catch(NumberFormatException nf)
- {
- size = 14;
- }
- try
- {
- style = Integer.parseInt(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "fontstyle"));
- }
- catch(NumberFormatException nf)
- {
- style = Font.PLAIN;
- }
- return new Font(family, style, size);
- }
- }