PageRenderTime 42ms CodeModel.GetById 31ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/jars/QuickNotepad/QuickNotepadOptionPane.java

#
Java | 127 lines | 85 code | 17 blank | 25 comment | 2 complexity | 7f9f89673d9e2037399fa11431a9d7af MD5 | raw file
  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
 24import java.awt.BorderLayout;
 25import java.awt.Font;
 26import java.awt.event.ActionEvent;
 27import java.awt.event.ActionListener;
 28
 29import javax.swing.JButton;
 30import javax.swing.JCheckBox;
 31import javax.swing.JFileChooser;
 32import javax.swing.JPanel;
 33import javax.swing.JTextField;
 34
 35import org.gjt.sp.jedit.AbstractOptionPane;
 36import org.gjt.sp.jedit.GUIUtilities;
 37import org.gjt.sp.jedit.jEdit;
 38import org.gjt.sp.jedit.gui.FontSelector;
 39
 40public class QuickNotepadOptionPane extends AbstractOptionPane implements
 41		ActionListener {
 42	private JCheckBox showPath;
 43
 44	private JTextField pathName;
 45
 46	private FontSelector font;
 47
 48	public QuickNotepadOptionPane() {
 49		super(QuickNotepadPlugin.NAME);
 50	}
 51
 52	public void _init() {
 53		showPath = new JCheckBox(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(jEdit
 61				.getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath"));
 62		JButton pickPath = new JButton(jEdit
 63				.getProperty(QuickNotepadPlugin.OPTION_PREFIX + "choose-file"));
 64		pickPath.addActionListener(this);
 65
 66		JPanel pathPanel = new JPanel(new BorderLayout(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 _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 evt) {
 96		String[] 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 makeFont() {
105		int style, size;
106		String 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 nf) {
114			size = 14;
115		}
116		try {
117			style = Integer
118					.parseInt(jEdit
119							.getProperty(QuickNotepadPlugin.OPTION_PREFIX
120									+ "fontstyle"));
121		} catch (NumberFormatException nf) {
122			style = Font.PLAIN;
123		}
124		return new Font(family, style, size);
125	}
126
127}