PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms 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
  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
 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.add(makeCustomButton("quicknotepad.choose-file",
 48			new ActionListener() {
 49				public void actionPerformed(ActionEvent evt) {
 50					QuickNotepadToolPanel.this.pad.chooseFile();
 51				}
 52			}));
 53        toolBar.add(makeCustomButton("quicknotepad.save-file",
 54			new ActionListener() {
 55				public void actionPerformed(ActionEvent evt) {
 56					QuickNotepadToolPanel.this.pad.saveFile();
 57				}
 58			}));
 59        toolBar.add(makeCustomButton("quicknotepad.copy-to-buffer",
 60			new ActionListener() {
 61				public void actionPerformed(ActionEvent evt) {
 62					QuickNotepadToolPanel.this.pad.copyToBuffer();
 63				}
 64			}));
 65		label = new JLabel(pad.getFilename(), SwingConstants.RIGHT);
 66		label.setForeground(Color.black);
 67		label.setVisible(jEdit.getProperty(
 68			QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
 69        this.setLayout(new BorderLayout(10, 0));
 70        this.add(BorderLayout.WEST, toolBar);
 71		this.add(BorderLayout.CENTER, label);
 72        this.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 10));
 73    }
 74
 75
 76	void propertiesChanged()
 77	{
 78		label.setText(pad.getFilename());
 79		label.setVisible(jEdit.getProperty(
 80			QuickNotepadPlugin.OPTION_PREFIX + "show-filepath").equals("true"));
 81	}
 82
 83    private AbstractButton makeCustomButton(String name, ActionListener listener)
 84	{
 85        String icon = jEdit.getProperty(name + ".icon");
 86        java.net.URL u = getClass().getResource(icon);
 87        String toolTip = jEdit.getProperty(name.concat(".label"));
 88        AbstractButton b = new JButton(new ImageIcon(u));
 89		if(listener != null)
 90		{
 91			b.addActionListener(listener);
 92			b.setEnabled(true);
 93		}
 94		else
 95		{
 96			b.setEnabled(false);
 97		}
 98        b.setToolTipText(toolTip);
 99        b.setMargin(new Insets(0,0,0,0));
100		b.setAlignmentY(0.0f);
101        b.setRequestFocusEnabled(false);
102        return b;
103    }
104
105}
106