001: /*
002: * Created on 11.04.2005 for PIROL
003: *
004: * SVN header information:
005: * $Author: javamap $
006: * $Rev: 856 $
007: * $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
008: * $Id: OkCancelButtonPanel.java 856 2007-06-19 04:15:27Z javamap $
009: */
010: package de.fho.jump.pirol.ui.panels;
011:
012: import java.awt.Dimension;
013: import java.awt.event.ActionListener;
014:
015: import javax.swing.Box;
016: import javax.swing.BoxLayout;
017: import javax.swing.JButton;
018: import javax.swing.JPanel;
019:
020: import com.vividsolutions.jump.I18N;
021:
022: //import de.fho.jump.pirol.utilities.i18n.PirolPlugInMessages;
023:
024: /**
025: * This class is a JPanel with a "Cancel" and a "OK" button.
026: * @author Carsten Schulze
027: * @author FH Osnabrück - University of Applied Sciences Osnabrück,
028: * Project: PIROL (2005),
029: * Subproject: Daten- und Wissensmanagement
030: */
031: public class OkCancelButtonPanel extends JPanel {
032:
033: private static final long serialVersionUID = -4703181650847522122L;
034:
035: /**The constant ActionCommand String for the ok-button*/
036: public static final String OK_BUTTON_ACTION_COMMAND = new String(
037: "OK_BUTTON_ACTION_COMMAND");
038: /**The constant ActionCommand String for the cancel-button*/
039: public static final String CANCEL_BUTTON_ACTION_COMMAND = new String(
040: "CANCEL_BUTTON_ACTION_COMMAND");
041: private JButton cancelButton;
042: private JButton okButton;
043:
044: /**
045: * This is the default constructor
046: */
047: public OkCancelButtonPanel() {
048: super ();
049: initialize();
050: }
051:
052: /**
053: * Adds the given ActionListener to both buttons.
054: * @param listener the listener
055: */
056: public void addActionListener(ActionListener listener) {
057: getOkButton().addActionListener(listener);
058: getCancelButton().addActionListener(listener);
059: }
060:
061: /**
062: * This method initializes cancelButton
063: *
064: * @return javax.swing.JButton
065: */
066: public JButton getCancelButton() {
067: if (cancelButton == null) {
068: cancelButton = new JButton();
069: cancelButton.setText(I18N.get("ui.OKCancelPanel.cancel"));
070: cancelButton.setActionCommand(CANCEL_BUTTON_ACTION_COMMAND);
071: cancelButton.setFocusPainted(false);
072: }
073: return cancelButton;
074: }
075:
076: /**
077: * This method initializes okButton
078: *
079: * @return javax.swing.JButton
080: */
081: public JButton getOkButton() {
082: if (okButton == null) {
083: okButton = new JButton();
084: okButton.setText(I18N.get("ui.OKCancelPanel.ok"));
085: okButton.setActionCommand(OK_BUTTON_ACTION_COMMAND);
086: okButton.setFocusPainted(false);
087: }
088: return okButton;
089: }
090:
091: /**
092: * Enables/Disables the ok button. May be useful, if the user had to put in values
093: * that may not be correct. You can disable the ok button in this case.
094: * @param enable enables the ok button if true, else disables it
095: */
096: public void setOkButtonEnabled(boolean enable) {
097: this .getOkButton().setEnabled(enable);
098: }
099:
100: /**
101: * This method initializes this
102: */
103: private void initialize() {
104: this .setSize(300, 40);
105: this .setLayout(new BoxLayout(this , BoxLayout.LINE_AXIS));
106: this .add(Box.createHorizontalGlue(), null);
107: this .add(getCancelButton(), null);
108: this .add(Box.createRigidArea(new Dimension(10, 0)));
109: this .add(getOkButton(), null);
110:
111: this .requestFocus();
112: }
113:
114: public void requestFocus() {
115: okButton.setFocusable(true);
116: okButton.requestFocus();
117: }
118:
119: }
|