1   /**
2    * QJ-Pro
3    * Copyright (c) 2004, http://qjpro.sourceforge.net
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but WITHOUT
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13   * details.
14   *
15   * You should have received a copy of the GNU General Public License along with
16   * this program; if not, write to the Free Software Foundation, Inc.,
17   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  package com.qasystems.qstudio.java.gui.dialog;
20  
21  import com.qasystems.international.MessageResource;
22  import com.qasystems.qstudio.java.browser.BrowserHelpContext;
23  import com.qasystems.swing.ButtonDialog;
24  
25  import java.awt.Dialog;
26  import java.awt.Frame;
27  
28  import javax.swing.JButton;
29  
30  /**
31   * This class creates a standard button dialog which always
32   * contains a help button, the help button is always added.
33   */
34  public class HelpButtonDialog extends ButtonDialog {
35    private JButton helpButton =
36      new JButton(MessageResource.getClientInstance().getString("BUTTON_031"));
37  
38    /**
39     * Default constructor
40     */
41    public HelpButtonDialog() {
42      super();
43    }
44  
45    /**
46     * Creates a new HelpButtonDialog object.
47     *
48     * @param parent DOCUMENT ME!
49     */
50    public HelpButtonDialog(Dialog parent) {
51      super(parent);
52    }
53  
54    /**
55     * Creates a new HelpButtonDialog object.
56     *
57     * @param parent DOCUMENT ME!
58     */
59    public HelpButtonDialog(Frame parent) {
60      super(parent);
61    }
62  
63    /**
64     * Override method to add the help button
65     *
66     * @param buttons
67     */
68    public void setButtons(Object[] buttons) {
69      super.setButtons(addHelpButton(buttons));
70    }
71  
72    /**
73     * Connect a context help action with the help button.
74     *
75     * @param the context
76     */
77    public void setHelpContext(BrowserHelpContext ctx) {
78      helpButton.setAction(ctx.getContextAction());
79    }
80  
81    /**
82     * Add a standard help button for the dialog
83     *
84     * @param ops the other buttons
85     * @return the new button set with the help button included
86     */
87    private Object[] addHelpButton(Object[] ops) {
88      Object[] result = null;
89  
90      if (ops != null) {
91        final MessageResource resources = MessageResource.getClientInstance();
92        result = new Object[ops.length + 1];
93  
94        for (int i = 0; i < ops.length; i++) {
95          result[i] = ops[i];
96        }
97  
98        result[ops.length] = helpButton;
99      }
100 
101     return (result);
102   }
103 }
104