/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
- /*
- * QuickNotepadToolPanel.java
- * part of the QuickNotepad plugin for the jEdit text editor
- * Copyright (C) 2001 John Gellene
- * jgellene@nyc.rr.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id: QuickNotepadToolPanel.java 4219 2002-06-01 02:46:39Z spestov $
- */
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- import org.gjt.sp.jedit.*;
- import org.gjt.sp.jedit.gui.*;
- import org.gjt.sp.jedit.io.*;
- import org.gjt.sp.jedit.textarea.*;
- import org.gjt.sp.jedit.msg.PropertiesChanged;
- import org.gjt.sp.util.Log;
- public class QuickNotepadToolPanel extends JPanel
- {
- private QuickNotepad pad;
- private JLabel label;
- public QuickNotepadToolPanel(QuickNotepad qnpad)
- {
- pad = qnpad;
- JToolBar toolBar = new JToolBar();
- toolBar.setFloatable(false);
- toolBar.putClientProperty("JToolBar.isRollover",Boolean.TRUE);
- toolBar.add(makeCustomButton("quicknotepad.choose-file",
- new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- QuickNotepadToolPanel.this.pad.chooseFile();
- }
- }));
- toolBar.add(makeCustomButton("quicknotepad.save-file",
- new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- QuickNotepadToolPanel.this.pad.saveFile();
- }
- }));
- toolBar.add(makeCustomButton("quicknotepad.copy-to-buffer",
- new ActionListener() {
- public void actionPerformed(ActionEvent evt) {
- QuickNotepadToolPanel.this.pad.copyToBuffer();
- }
- }));
- label = new JLabel(pad.getFilename(), SwingConstants.RIGHT);
- label.setForeground(Color.black);
- label.setVisible(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
- this.setLayout(new BorderLayout(10, 0));
- this.add(BorderLayout.WEST, toolBar);
- this.add(BorderLayout.CENTER, label);
- this.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 10));
- }
- void propertiesChanged()
- {
- label.setText(pad.getFilename());
- label.setVisible(jEdit.getProperty(
- QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
- }
- private AbstractButton makeCustomButton(String name, ActionListener listener)
- {
- String toolTip = jEdit.getProperty(name.concat(".label"));
- AbstractButton b = new JButton(GUIUtilities.loadIcon(
- jEdit.getProperty(name + ".icon")));
- if(listener != null)
- {
- b.addActionListener(listener);
- b.setEnabled(true);
- }
- else
- {
- b.setEnabled(false);
- }
- b.setToolTipText(toolTip);
- b.setMargin(new Insets(0,0,0,0));
- b.setAlignmentY(0.0f);
- b.setRequestFocusEnabled(false);
- return b;
- }
- }