PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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