View Javadoc

1   /*
2   
3       dsh-curate  Interfaces for curating collections quickly.
4       Copyright (c) 2007-2013 held jointly by the individual authors.
5   
6       This library is free software; you can redistribute it and/or modify it
7       under the terms of the GNU Lesser General Public License as published
8       by the Free Software Foundation; either version 3 of the License, or (at
9       your option) any later version.
10  
11      This library is distributed in the hope that it will be useful, but WITHOUT
12      ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
13      FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14      License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public License
17      along with this library;  if not, write to the Free Software Foundation,
18      Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
19  
20      > http://www.fsf.org/licensing/licenses/lgpl.html
21      > http://www.opensource.org/licenses/lgpl-license.php
22  
23  */
24  package org.dishevelled.curate.impl;
25  
26  import java.awt.event.ActionEvent;
27  
28  import javax.swing.AbstractAction;
29  import javax.swing.Action;
30  import javax.swing.JButton;
31  import javax.swing.JDialog;
32  import javax.swing.JPanel;
33  
34  import org.dishevelled.iconbundle.tango.TangoProject;
35  
36  import org.dishevelled.identify.IdButton;
37  import org.dishevelled.identify.IdentifiableAction;
38  
39  import org.dishevelled.layout.ButtonPanel;
40  
41  /**
42   * Abstract curate dialog.
43   *
44   * @author  Michael Heuer
45   * @version $Revision$ $Date$
46   */
47  public abstract class AbstractCurateDialog
48      extends JDialog
49  {
50      /** Cancel action. */
51      private final Action cancel;
52  
53      /** Help action. */
54      private final IdentifiableAction help;
55  
56      /** OK action. */
57      private final Action ok;
58  
59  
60      /**
61       * Create a new abstract curate dialog.
62       */
63      protected AbstractCurateDialog()
64      {
65          super();
66  
67          //cancel = new IdentifiableAction("Cancel", TangoProject.DIALOG_CANCEL)
68          cancel = new AbstractAction("Cancel")
69              {
70                  /** {@inheritDoc} */
71                  public void actionPerformed(final ActionEvent event)
72                  {
73                      cancel();
74                  }
75              };
76  
77          help = new IdentifiableAction("Help", TangoProject.HELP_BROWSER)
78              {
79                  /** {@inheritDoc} */
80                  public void actionPerformed(final ActionEvent event)
81                  {
82                      help();
83                  }
84              };
85          help.setEnabled(false);
86  
87          //ok = new IdentifiableAction("OK", TangoProject.DIALOG_OK)
88          ok = new AbstractAction("OK")
89              {
90                  /** {@inheritDoc} */
91                  public void actionPerformed(final ActionEvent event)
92                  {
93                      ok();
94                  }
95              };
96      }
97  
98      /**
99       * Create and return the button panel.
100      *
101      * @return the button panel
102      */
103     protected final JPanel createButtonPanel()
104     {
105         ButtonPanel buttonPanel = new ButtonPanel();
106         JButton okButton = buttonPanel.add(ok);
107         JButton cancelButton = buttonPanel.add(cancel);
108         buttonPanel.add(new IdButton(help));
109 
110         // don't let ok button get too small
111         okButton.setPreferredSize(cancelButton.getPreferredSize());
112         getRootPane().setDefaultButton(okButton);
113 
114         return buttonPanel;
115     }
116 
117     /**
118      * Return the cancel action.  The cancel action calls the
119      * abstract <code>cancel()</code> method of this class.
120      *
121      * @see #cancel
122      * @return the cancel action
123      */
124     protected final Action getCancelAction()
125     {
126         return cancel;
127     }
128 
129     /**
130      * Return the help action.  The help action calls the
131      * abstract <code>help()</code> method of this class.
132      *
133      * @see #help
134      * @return the help action
135      */
136     protected final Action getHelpAction()
137     {
138         return help;
139     }
140 
141     /**
142      * Return the OK action.  The OK action calls the
143      * abstract <code>ok()</code> method of this class.
144      *
145      * @see #ok
146      * @return the OK action
147      */
148     protected final Action getOKAction()
149     {
150         return ok;
151     }
152 
153     /**
154      * Abstract method called by the cancel action.
155      *
156      * @see #getCancelAction
157      */
158     protected abstract void cancel();
159 
160     /**
161      * Abstract method called by the help action.
162      *
163      * @see #getHelpAction
164      */
165     protected abstract void help();
166 
167     /**
168      * Abstract method called by the OK action.
169      *
170      * @see #getOKAction
171      */
172     protected abstract void ok();
173 }