PageRenderTime 13ms CodeModel.GetById 6ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/CommonControls/common/gui/OkCancelButtons.java

#
Java | 106 lines | 56 code | 16 blank | 34 comment | 6 complexity | 0bad56222507565adf07477c66e41f0e MD5 | raw file
  1/*
  2 * OkCancelButtons.java - a button pane for EnhancedDialog instances.
  3 * Copyright (c) 2005 Marcelo Vanzin
  4 *
  5 * :tabSize=4:indentSize=4:noTabs=false:
  6 * :folding=explicit:collapseFolds=1:
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22package common.gui;
 23
 24//{{{ Imports
 25import java.awt.Dimension;
 26import java.awt.FlowLayout;
 27import java.awt.event.ActionEvent;
 28import java.awt.event.ActionListener;
 29
 30import java.io.File;
 31
 32import javax.swing.JButton;
 33import javax.swing.JPanel;
 34
 35import org.gjt.sp.jedit.gui.EnhancedDialog;
 36import org.gjt.sp.jedit.jEdit;
 37//}}}
 38
 39/**
 40 *	A pair of buttons (OK/Cancel) to be added to instances of
 41 *	EnhancedDialog. Calls <code>ok()</code> when OK is pressed, and
 42 *	<code>cancel()</code> when Cancel is pressed.
 43 *
 44 *	<p>Copied from the same class that belonged to the ProjectViewer plugin.</p>
 45 *
 46 *  @author		Marcelo Vanzin
 47 *	@version	$Id: OkCancelButtons.java 1350 2005-12-12 04:26:01Z vanza $
 48 *	@since		CC 0.9.0
 49 */
 50public class OkCancelButtons extends JPanel
 51							 implements ActionListener
 52{
 53
 54	private EnhancedDialog	target;
 55	private JButton 		cancel;
 56	private JButton 		ok;
 57
 58	public OkCancelButtons(EnhancedDialog target)
 59	{
 60		super(new FlowLayout());
 61		this.target = target;
 62
 63		cancel	= new JButton(jEdit.getProperty("common.cancel"));
 64		ok 		= new JButton(jEdit.getProperty("common.ok"));
 65
 66		ok.setPreferredSize(cancel.getPreferredSize());
 67		ok.addActionListener(this);
 68		cancel.addActionListener(this);
 69
 70		add(ok);
 71		add(cancel);
 72		resizeButtons();
 73	}
 74
 75	public void setOkText(String text)
 76	{
 77		ok.setText(text);
 78		resizeButtons();
 79	}
 80
 81	public void setCancelText(String text)
 82	{
 83		cancel.setText(text);
 84		resizeButtons();
 85	}
 86
 87	public void actionPerformed(ActionEvent ae)
 88	{
 89		if (ae.getSource() == cancel)
 90			target.cancel();
 91		else if (ae.getSource() == ok)
 92			target.ok();
 93	}
 94
 95	private void resizeButtons()
 96	{
 97		Dimension d1 = ok.getPreferredSize();
 98		Dimension d2 = cancel.getPreferredSize();
 99		if (d1.getWidth() > d2.getWidth())
100			cancel.setPreferredSize(d1);
101		else
102			ok.setPreferredSize(d2);
103	}
104
105}
106