PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 106 lines | 73 code | 11 blank | 22 comment | 2 complexity | f9765450accfa3463821fc2d99aa4f7d 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 3883 2001-11-09 20:27:55Z jgellene $
  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.add(makeCustomButton("quicknotepad.choose-file",
  42. new ActionListener() {
  43. public void actionPerformed(ActionEvent evt) {
  44. QuickNotepadToolPanel.this.pad.chooseFile();
  45. }
  46. }));
  47. toolBar.add(makeCustomButton("quicknotepad.save-file",
  48. new ActionListener() {
  49. public void actionPerformed(ActionEvent evt) {
  50. QuickNotepadToolPanel.this.pad.saveFile();
  51. }
  52. }));
  53. toolBar.add(makeCustomButton("quicknotepad.copy-to-buffer",
  54. new ActionListener() {
  55. public void actionPerformed(ActionEvent evt) {
  56. QuickNotepadToolPanel.this.pad.copyToBuffer();
  57. }
  58. }));
  59. label = new JLabel(pad.getFilename(), SwingConstants.RIGHT);
  60. label.setForeground(Color.black);
  61. label.setVisible(jEdit.getProperty(
  62. QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
  63. this.setLayout(new BorderLayout(10, 0));
  64. this.add(BorderLayout.WEST, toolBar);
  65. this.add(BorderLayout.CENTER, label);
  66. this.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 10));
  67. }
  68. void propertiesChanged()
  69. {
  70. label.setText(pad.getFilename());
  71. label.setVisible(jEdit.getProperty(
  72. QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
  73. }
  74. private AbstractButton makeCustomButton(String name, ActionListener listener)
  75. {
  76. String icon = jEdit.getProperty(name + ".icon");
  77. java.net.URL u = getClass().getResource(icon);
  78. String toolTip = jEdit.getProperty(name.concat(".label"));
  79. AbstractButton b = new JButton(new ImageIcon(u));
  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. }