KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > QuickNotepadToolPanel


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 5275 2005-09-10 19:40:17Z ezust $
22  */

23
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26
27 import javax.swing.AbstractButton JavaDoc;
28 import javax.swing.Box JavaDoc;
29 import javax.swing.BoxLayout JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32
33 import org.gjt.sp.jedit.GUIUtilities;
34 import org.gjt.sp.jedit.jEdit;
35 import org.gjt.sp.jedit.gui.RolloverButton;
36
37 public class QuickNotepadToolPanel extends JPanel JavaDoc {
38     private QuickNotepad pad;
39
40     private JLabel JavaDoc label;
41
42     public QuickNotepadToolPanel(QuickNotepad qnpad) {
43         setLayout(new BoxLayout JavaDoc(this, BoxLayout.X_AXIS));
44         pad = qnpad;
45
46         Box JavaDoc labelBox = new Box JavaDoc(BoxLayout.Y_AXIS);
47         labelBox.add(Box.createGlue());
48
49         label = new JLabel JavaDoc(pad.getFilename());
50         label.setVisible(jEdit.getProperty(
51                 QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals(
52                 "true"));
53
54         labelBox.add(label);
55         labelBox.add(Box.createGlue());
56
57         add(labelBox);
58
59         add(Box.createGlue());
60
61         add(makeCustomButton("quicknotepad.choose-file", new ActionListener JavaDoc() {
62             public void actionPerformed(ActionEvent JavaDoc evt) {
63                 QuickNotepadToolPanel.this.pad.chooseFile();
64             }
65         }));
66         add(makeCustomButton("quicknotepad.save-file", new ActionListener JavaDoc() {
67             public void actionPerformed(ActionEvent JavaDoc evt) {
68                 QuickNotepadToolPanel.this.pad.saveFile();
69             }
70         }));
71         add(makeCustomButton("quicknotepad.copy-to-buffer",
72                 new ActionListener JavaDoc() {
73                     public void actionPerformed(ActionEvent JavaDoc evt) {
74                         QuickNotepadToolPanel.this.pad.copyToBuffer();
75                     }
76                 }));
77     }
78
79     void propertiesChanged() {
80         label.setText(pad.getFilename());
81         label.setVisible(jEdit.getProperty(
82                 QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals(
83                 "true"));
84     }
85
86     private AbstractButton JavaDoc makeCustomButton(String JavaDoc name, ActionListener JavaDoc listener) {
87         String JavaDoc toolTip = jEdit.getProperty(name.concat(".label"));
88         AbstractButton JavaDoc b = new RolloverButton(GUIUtilities.loadIcon(jEdit
89                 .getProperty(name + ".icon")));
90         if (listener != null) {
91             b.addActionListener(listener);
92             b.setEnabled(true);
93         } else {
94             b.setEnabled(false);
95         }
96         b.setToolTipText(toolTip);
97         return b;
98     }
99
100 }
101
Popular Tags