PageRenderTime 34ms CodeModel.GetById 10ms RepoModel.GetById 0ms 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
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 5275 2005-09-10 19:40:17Z ezust $
  22. */
  23. import java.awt.BorderLayout;
  24. import java.awt.Font;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.event.ActionListener;
  27. import javax.swing.JButton;
  28. import javax.swing.JCheckBox;
  29. import javax.swing.JFileChooser;
  30. import javax.swing.JPanel;
  31. import javax.swing.JTextField;
  32. import org.gjt.sp.jedit.AbstractOptionPane;
  33. import org.gjt.sp.jedit.GUIUtilities;
  34. import org.gjt.sp.jedit.jEdit;
  35. import org.gjt.sp.jedit.gui.FontSelector;
  36. public class QuickNotepadOptionPane extends AbstractOptionPane implements
  37. ActionListener {
  38. private JCheckBox showPath;
  39. private JTextField pathName;
  40. private FontSelector font;
  41. public QuickNotepadOptionPane() {
  42. super(QuickNotepadPlugin.NAME);
  43. }
  44. public void _init() {
  45. showPath = new JCheckBox(jEdit
  46. .getProperty(QuickNotepadPlugin.OPTION_PREFIX
  47. + "show-filepath.title"), jEdit.getProperty(
  48. QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals(
  49. "true"));
  50. addComponent(showPath);
  51. pathName = new JTextField(jEdit
  52. .getProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath"));
  53. JButton pickPath = new JButton(jEdit
  54. .getProperty(QuickNotepadPlugin.OPTION_PREFIX + "choose-file"));
  55. pickPath.addActionListener(this);
  56. JPanel pathPanel = new JPanel(new BorderLayout(0, 0));
  57. pathPanel.add(pathName, BorderLayout.CENTER);
  58. pathPanel.add(pickPath, BorderLayout.EAST);
  59. addComponent(jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
  60. + "file"), pathPanel);
  61. font = new FontSelector(makeFont());
  62. addComponent(jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
  63. + "choose-font"), font);
  64. }
  65. public void _save() {
  66. jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "filepath",
  67. pathName.getText());
  68. Font _font = font.getFont();
  69. jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "font", _font
  70. .getFamily());
  71. jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontsize", String
  72. .valueOf(_font.getSize()));
  73. jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "fontstyle",
  74. String.valueOf(_font.getStyle()));
  75. jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX + "show-filepath",
  76. String.valueOf(showPath.isSelected()));
  77. }
  78. // end AbstractOptionPane implementation
  79. // begin ActionListener implementation
  80. public void actionPerformed(ActionEvent evt) {
  81. String[] paths = GUIUtilities.showVFSFileDialog(null, null,
  82. JFileChooser.OPEN_DIALOG, false);
  83. if (paths != null) {
  84. pathName.setText(paths[0]);
  85. }
  86. }
  87. // helper method to get Font from plugin properties
  88. static public Font makeFont() {
  89. int style, size;
  90. String family = jEdit.getProperty(QuickNotepadPlugin.OPTION_PREFIX
  91. + "font");
  92. try {
  93. size = Integer
  94. .parseInt(jEdit
  95. .getProperty(QuickNotepadPlugin.OPTION_PREFIX
  96. + "fontsize"));
  97. } catch (NumberFormatException nf) {
  98. size = 14;
  99. }
  100. try {
  101. style = Integer
  102. .parseInt(jEdit
  103. .getProperty(QuickNotepadPlugin.OPTION_PREFIX
  104. + "fontstyle"));
  105. } catch (NumberFormatException nf) {
  106. style = Font.PLAIN;
  107. }
  108. return new Font(family, style, size);
  109. }
  110. }