1 23 24 import java.awt.BorderLayout ; 25 import java.awt.Font ; 26 import java.awt.event.ActionEvent ; 27 import java.awt.event.ActionListener ; 28 29 import javax.swing.JButton ; 30 import javax.swing.JCheckBox ; 31 import javax.swing.JFileChooser ; 32 import javax.swing.JPanel ; 33 import javax.swing.JTextField ; 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 { 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 94 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 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 } 128 | Popular Tags |