1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: ButtonPane.java 2104 2011-03-07 18:54:34Z dmsmith $
21   */
22  package org.crosswire.common.config.swing;
23  
24  import java.awt.BorderLayout;
25  import java.awt.GridLayout;
26  import java.awt.event.ActionEvent;
27  
28  import javax.swing.BorderFactory;
29  import javax.swing.JButton;
30  import javax.swing.JPanel;
31  import javax.swing.SwingConstants;
32  
33  import org.crosswire.common.swing.ActionFactory;
34  import org.crosswire.common.swing.EdgeBorder;
35  import org.crosswire.common.swing.CWMsg;
36  
37  /**
38   * A pane that contains ok, cancel and apply buttons.
39   * 
40   * @see gnu.lgpl.License for license details.<br>
41   *      The copyright to this program is held by it's authors.
42   * @author Joe Walker [joe at eireneh dot com]
43   */
44  public class ButtonPane extends JPanel {
45  
46      /**
47       * Simple ctor
48       */
49      public ButtonPane(ButtonPaneListener li) {
50          this.li = li;
51          init();
52      }
53  
54      /**
55       * GUI init.
56       */
57      private void init() {
58          actions = new ActionFactory(this);
59  
60          // PENDING: find some way to do default buttons
61          // dialog.getRootPane().setDefaultButton(ok);
62  
63          // A panel so we can right justify
64          JPanel buttons = new JPanel();
65  
66          buttons.setLayout(new GridLayout(1, 2, 10, 10));
67          buttons.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
68          // TRANSLATOR: This is the text on an "OK" button
69          buttons.add(new JButton(actions.addAction("OK", CWMsg.gettext("OK"))));
70          // TRANSLATOR: This is the text on a "Cancel" button
71          buttons.add(new JButton(actions.addAction("Cancel", CWMsg.gettext("Cancel"))));
72          // TRANSLATOR: This is the text on an "Apply" button
73          buttons.add(new JButton(actions.addAction("Apply", CWMsg.gettext("Apply"))));
74  
75          this.setBorder(new EdgeBorder(SwingConstants.NORTH));
76          this.setLayout(new BorderLayout(10, 10));
77          this.add(buttons, BorderLayout.LINE_END);
78      }
79  
80      /**
81       * Do the OK action
82       * 
83       * @param ev
84       */
85      public void doOK(ActionEvent ev) {
86          li.okPressed(ev);
87      }
88  
89      /**
90       * Do the Cancel action
91       * 
92       * @param ev
93       */
94      public void doCancel(ActionEvent ev) {
95          li.cancelPressed(ev);
96      }
97  
98      /**
99       * Do the Apply action
100      * 
101      * @param ev
102      */
103     public void doApply(ActionEvent ev) {
104         li.applyPressed(ev);
105     }
106 
107     /**
108      * The action factory for the buttons
109      */
110     private transient ActionFactory actions;
111 
112     /**
113      * PENDING: turn this into a [add|remove]ButtonPaneListener thing
114      */
115     protected ButtonPaneListener li;
116 
117     /**
118      * Serialization ID
119      */
120     private static final long serialVersionUID = 3257847701248031033L;
121 }
122