001: /*
002: * QuickNotepadToolPanel.java
003: * part of the QuickNotepad plugin for the jEdit text editor
004: * Copyright (C) 2001 John Gellene
005: * jgellene@nyc.rr.com
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * $Id: QuickNotepadToolPanel.java 5275 2005-09-10 19:40:17Z ezust $
022: */
023:
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026:
027: import javax.swing.AbstractButton;
028: import javax.swing.Box;
029: import javax.swing.BoxLayout;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032:
033: import org.gjt.sp.jedit.GUIUtilities;
034: import org.gjt.sp.jedit.jEdit;
035: import org.gjt.sp.jedit.gui.RolloverButton;
036:
037: public class QuickNotepadToolPanel extends JPanel {
038: private QuickNotepad pad;
039:
040: private JLabel label;
041:
042: public QuickNotepadToolPanel(QuickNotepad qnpad) {
043: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
044: pad = qnpad;
045:
046: Box labelBox = new Box(BoxLayout.Y_AXIS);
047: labelBox.add(Box.createGlue());
048:
049: label = new JLabel(pad.getFilename());
050: label.setVisible(jEdit.getProperty(
051: QuickNotepadPlugin.OPTION_PREFIX + "show-filepath")
052: .equals("true"));
053:
054: labelBox.add(label);
055: labelBox.add(Box.createGlue());
056:
057: add(labelBox);
058:
059: add(Box.createGlue());
060:
061: add(makeCustomButton("quicknotepad.choose-file",
062: new ActionListener() {
063: public void actionPerformed(ActionEvent evt) {
064: QuickNotepadToolPanel.this .pad.chooseFile();
065: }
066: }));
067: add(makeCustomButton("quicknotepad.save-file",
068: new ActionListener() {
069: public void actionPerformed(ActionEvent evt) {
070: QuickNotepadToolPanel.this .pad.saveFile();
071: }
072: }));
073: add(makeCustomButton("quicknotepad.copy-to-buffer",
074: new ActionListener() {
075: public void actionPerformed(ActionEvent evt) {
076: QuickNotepadToolPanel.this .pad.copyToBuffer();
077: }
078: }));
079: }
080:
081: void propertiesChanged() {
082: label.setText(pad.getFilename());
083: label.setVisible(jEdit.getProperty(
084: QuickNotepadPlugin.OPTION_PREFIX + "show-filepath")
085: .equals("true"));
086: }
087:
088: private AbstractButton makeCustomButton(String name,
089: ActionListener listener) {
090: String toolTip = jEdit.getProperty(name.concat(".label"));
091: AbstractButton b = new RolloverButton(GUIUtilities
092: .loadIcon(jEdit.getProperty(name + ".icon")));
093: if (listener != null) {
094: b.addActionListener(listener);
095: b.setEnabled(true);
096: } else {
097: b.setEnabled(false);
098: }
099: b.setToolTipText(toolTip);
100: return b;
101: }
102:
103: }
|