PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/jars/QuickNotepad/QuickNotepadToolPanel.java

#
Java | 107 lines | 73 code | 12 blank | 22 comment | 2 complexity | 4d3a5f9205aa94a8ecb35da6c715aeb4 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. * QuickNotepadToolPanel.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: QuickNotepadToolPanel.java 4219 2002-06-01 02:46:39Z spestov $
  22. */
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import javax.swing.*;
  26. import org.gjt.sp.jedit.*;
  27. import org.gjt.sp.jedit.gui.*;
  28. import org.gjt.sp.jedit.io.*;
  29. import org.gjt.sp.jedit.textarea.*;
  30. import org.gjt.sp.jedit.msg.PropertiesChanged;
  31. import org.gjt.sp.util.Log;
  32. public class QuickNotepadToolPanel extends JPanel
  33. {
  34. private QuickNotepad pad;
  35. private JLabel label;
  36. public QuickNotepadToolPanel(QuickNotepad qnpad)
  37. {
  38. pad = qnpad;
  39. JToolBar toolBar = new JToolBar();
  40. toolBar.setFloatable(false);
  41. toolBar.putClientProperty("JToolBar.isRollover",Boolean.TRUE);
  42. toolBar.add(makeCustomButton("quicknotepad.choose-file",
  43. new ActionListener() {
  44. public void actionPerformed(ActionEvent evt) {
  45. QuickNotepadToolPanel.this.pad.chooseFile();
  46. }
  47. }));
  48. toolBar.add(makeCustomButton("quicknotepad.save-file",
  49. new ActionListener() {
  50. public void actionPerformed(ActionEvent evt) {
  51. QuickNotepadToolPanel.this.pad.saveFile();
  52. }
  53. }));
  54. toolBar.add(makeCustomButton("quicknotepad.copy-to-buffer",
  55. new ActionListener() {
  56. public void actionPerformed(ActionEvent evt) {
  57. QuickNotepadToolPanel.this.pad.copyToBuffer();
  58. }
  59. }));
  60. label = new JLabel(pad.getFilename(), SwingConstants.RIGHT);
  61. label.setForeground(Color.black);
  62. label.setVisible(jEdit.getProperty(
  63. QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
  64. this.setLayout(new BorderLayout(10, 0));
  65. this.add(BorderLayout.WEST, toolBar);
  66. this.add(BorderLayout.CENTER, label);
  67. this.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 10));
  68. }
  69. void propertiesChanged()
  70. {
  71. label.setText(pad.getFilename());
  72. label.setVisible(jEdit.getProperty(
  73. QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
  74. }
  75. private AbstractButton makeCustomButton(String name, ActionListener listener)
  76. {
  77. String toolTip = jEdit.getProperty(name.concat(".label"));
  78. AbstractButton b = new JButton(GUIUtilities.loadIcon(
  79. jEdit.getProperty(name + ".icon")));
  80. if(listener != null)
  81. {
  82. b.addActionListener(listener);
  83. b.setEnabled(true);
  84. }
  85. else
  86. {
  87. b.setEnabled(false);
  88. }
  89. b.setToolTipText(toolTip);
  90. b.setMargin(new Insets(0,0,0,0));
  91. b.setAlignmentY(0.0f);
  92. b.setRequestFocusEnabled(false);
  93. return b;
  94. }
  95. }