[3952] | 1 | /* |
---|
| 2 | * SimplyHTML, a word processor based on Java, HTML and CSS |
---|
| 3 | * Copyright (C) 2002 Ulrich Hilger |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or |
---|
| 6 | * modify it under the terms of the GNU General Public License |
---|
| 7 | * as published by the Free Software Foundation; either version 2 |
---|
| 8 | * of the License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU General Public License |
---|
| 16 | * along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | package nu.fw.jeti.plugins.xhtml.fontchooser; |
---|
| 21 | |
---|
| 22 | import java.awt.event.ActionListener; |
---|
| 23 | import java.awt.AWTEvent; |
---|
| 24 | import java.awt.event.WindowEvent; |
---|
| 25 | import java.awt.event.ActionEvent; |
---|
| 26 | import javax.swing.JDialog; |
---|
| 27 | import javax.swing.JButton; |
---|
| 28 | import javax.swing.JPanel; |
---|
| 29 | |
---|
| 30 | import nu.fw.jeti.util.I18N; |
---|
| 31 | |
---|
| 32 | import java.awt.Frame; |
---|
| 33 | import java.awt.BorderLayout; |
---|
| 34 | import java.awt.FlowLayout; |
---|
| 35 | import java.awt.Container; |
---|
| 36 | import java.awt.Dialog; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Base class for other dialogs of application SimplyHTML. |
---|
| 41 | * |
---|
| 42 | * @author Ulrich Hilger |
---|
| 43 | * @author Light Development |
---|
| 44 | * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a> |
---|
| 45 | * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a> |
---|
| 46 | * @author published under the terms and conditions of the |
---|
| 47 | * GNU General Public License, |
---|
| 48 | * for details see file gpl.txt in the distribution |
---|
| 49 | * package of this software |
---|
| 50 | * |
---|
| 51 | * @version stage 9, release 4, January 12, 2003 |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | public class DialogShell extends JDialog implements ActionListener { |
---|
| 55 | |
---|
| 56 | /** panel containing dialog buttons */ |
---|
| 57 | protected JPanel buttonPanel; |
---|
| 58 | |
---|
| 59 | /** button to confirm the operation */ |
---|
| 60 | protected JButton okButton; |
---|
| 61 | |
---|
| 62 | /** button to cancel the operation */ |
---|
| 63 | protected JButton cancelButton; |
---|
| 64 | |
---|
| 65 | /** button to display context sensitive help */ |
---|
| 66 | protected JButton helpButton; |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * the result of the operation, one of RESULT_CANCEL and RESULT_OK |
---|
| 70 | */ |
---|
| 71 | private int result; |
---|
| 72 | |
---|
| 73 | /** result value for a cancelled operation */ |
---|
| 74 | public static final int RESULT_CANCEL = 1; |
---|
| 75 | |
---|
| 76 | /** result value for a confirmed operation */ |
---|
| 77 | public static final int RESULT_OK = 0; |
---|
| 78 | |
---|
| 79 | /** id of associated help topic (if any) */ |
---|
| 80 | protected String helpTopicId = null; |
---|
| 81 | |
---|
| 82 | //private HelpBroker myHelpBroker; |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * constructor |
---|
| 86 | * |
---|
| 87 | * @param parent the parent dialog |
---|
| 88 | * @param title the title for this dialog |
---|
| 89 | */ |
---|
| 90 | public DialogShell(Dialog parent, String title) { |
---|
| 91 | super(parent, title); |
---|
| 92 | buildDialog(); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * constructor |
---|
| 97 | * |
---|
| 98 | * @param parent the parent frame |
---|
| 99 | * @param title the title for this dialog |
---|
| 100 | */ |
---|
| 101 | public DialogShell(Frame parent, String title) { |
---|
| 102 | super(parent, title); |
---|
| 103 | buildDialog(); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * constructor |
---|
| 108 | * |
---|
| 109 | * @param parent the parent frame |
---|
| 110 | * @param title the title for this dialog |
---|
| 111 | * @param helpTopicId the id of the help topic to display for this dialog |
---|
| 112 | */ |
---|
| 113 | public DialogShell(Frame parent, String title, String helpTopicId) { |
---|
| 114 | super(parent, title); |
---|
| 115 | this.helpTopicId = helpTopicId; |
---|
| 116 | buildDialog(); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
| 120 | * constructor |
---|
| 121 | * |
---|
| 122 | * @param parent the parent dialog |
---|
| 123 | * @param title the title for this dialog |
---|
| 124 | * @param helpTopicId the id of the help topic to display for this dialog |
---|
| 125 | */ |
---|
| 126 | public DialogShell(Dialog parent, String title, String helpTopicId) { |
---|
| 127 | super(parent, title); |
---|
| 128 | this.helpTopicId = helpTopicId; |
---|
| 129 | buildDialog(); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /** |
---|
| 133 | * constructor |
---|
| 134 | * |
---|
| 135 | * @param parent the parent dialog |
---|
| 136 | * @param title the title for this dialog |
---|
| 137 | * @param helpTopicId the id of the help topic to display for this dialog |
---|
| 138 | * @param helpBroker the helpBroker to use for context sensitive help |
---|
| 139 | */ |
---|
| 140 | // public DialogShell(Dialog parent, String title, String helpTopicId, HelpBroker broker) { |
---|
| 141 | // super(parent, title); |
---|
| 142 | // this.helpTopicId = helpTopicId; |
---|
| 143 | // this.myHelpBroker = broker; |
---|
| 144 | // buildDialog(); |
---|
| 145 | // } |
---|
| 146 | |
---|
| 147 | /** |
---|
| 148 | * constructor |
---|
| 149 | * |
---|
| 150 | * @param parent the parent dialog |
---|
| 151 | * @param title the title for this dialog |
---|
| 152 | * @param helpTopicId the id of the help topic to display for this dialog |
---|
| 153 | * @param helpBroker the helpBroker to use for context sensitive help |
---|
| 154 | */ |
---|
| 155 | // public DialogShell(Frame parent, String title, String helpTopicId, HelpBroker broker) { |
---|
| 156 | // super(parent, title); |
---|
| 157 | // this.helpTopicId = helpTopicId; |
---|
| 158 | // this.myHelpBroker = broker; |
---|
| 159 | // buildDialog(); |
---|
| 160 | // } |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | * create dialog components |
---|
| 164 | */ |
---|
| 165 | private void buildDialog() { |
---|
| 166 | |
---|
| 167 | enableEvents(AWTEvent.WINDOW_EVENT_MASK); |
---|
| 168 | |
---|
| 169 | // construct dialog buttons |
---|
| 170 | // okButton = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "okBtnName")); |
---|
| 171 | okButton = new JButton(I18N.gettext("OK")); |
---|
| 172 | //cancelButton = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "cancelBtnName")); |
---|
| 173 | cancelButton = new JButton(I18N.gettext("Cancel")); |
---|
| 174 | cancelButton.addActionListener(this); |
---|
| 175 | okButton.addActionListener(this); |
---|
| 176 | |
---|
| 177 | // construct button panel |
---|
| 178 | buttonPanel = new JPanel(new FlowLayout()); |
---|
| 179 | buttonPanel.add(okButton); |
---|
| 180 | buttonPanel.add(cancelButton); |
---|
| 181 | |
---|
| 182 | // construct help button |
---|
| 183 | // if(helpTopicId != null) { |
---|
| 184 | // helpButton = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "helpLabel")); |
---|
| 185 | // CSH.setHelpIDString(helpButton, helpTopicId); |
---|
| 186 | // if(myHelpBroker == null) { |
---|
| 187 | // helpButton.addActionListener( |
---|
| 188 | // new CSH.DisplayHelpFromSource(FrmMain.getHelpBroker())); |
---|
| 189 | // } |
---|
| 190 | // else { |
---|
| 191 | // helpButton.addActionListener( |
---|
| 192 | // new CSH.DisplayHelpFromSource(myHelpBroker)); |
---|
| 193 | // } |
---|
| 194 | // buttonPanel.add(helpButton); |
---|
| 195 | //} |
---|
| 196 | |
---|
| 197 | // add all to content pane of dialog |
---|
| 198 | Container contentPane = getContentPane(); |
---|
| 199 | contentPane.setLayout(new BorderLayout(5,5)); |
---|
| 200 | contentPane.add(buttonPanel, BorderLayout.SOUTH); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | /** |
---|
| 204 | * dispose the dialog properly in case of window close events |
---|
| 205 | */ |
---|
| 206 | protected void processWindowEvent(WindowEvent e) { |
---|
| 207 | if (e.getID() == WindowEvent.WINDOW_CLOSING) { |
---|
| 208 | cancel(); |
---|
| 209 | } |
---|
| 210 | super.processWindowEvent(e); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | /** |
---|
| 214 | * cancel the operation |
---|
| 215 | */ |
---|
| 216 | protected void cancel() { |
---|
| 217 | result = RESULT_CANCEL; |
---|
| 218 | dispose(); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | /** |
---|
| 222 | * confirm the operation |
---|
| 223 | */ |
---|
| 224 | protected void confirm() { |
---|
| 225 | result = RESULT_OK; |
---|
| 226 | dispose(); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | /** |
---|
| 230 | * get the result of the operation performed in this dialog |
---|
| 231 | * |
---|
| 232 | * @return the result, one of RESULT_OK and RESULT_CANCEL |
---|
| 233 | */ |
---|
| 234 | public int getResult() { |
---|
| 235 | return result; |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | /** |
---|
| 239 | * implements the ActionListener interface to be notified of |
---|
| 240 | * clicks onto the ok and cancel button. |
---|
| 241 | */ |
---|
| 242 | public void actionPerformed(ActionEvent e) { |
---|
| 243 | Object src = e.getSource(); |
---|
| 244 | if(src == cancelButton) { |
---|
| 245 | cancel(); |
---|
| 246 | } |
---|
| 247 | else if(src == okButton) { |
---|
| 248 | confirm(); |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | /* |
---|
| 253 | * Overrides for emacs |
---|
| 254 | * Local variables: |
---|
| 255 | * tab-width: 4 |
---|
| 256 | * End: |
---|
| 257 | */ |
---|