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