|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DialogShell.java | 50% | 73.5% | 70% | 70% |
|
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 |
import java.awt.event.ActionListener;
|
|
21 |
import java.awt.AWTEvent;
|
|
22 |
import java.awt.event.WindowEvent;
|
|
23 |
import java.awt.event.ActionEvent;
|
|
24 |
import javax.swing.JDialog;
|
|
25 |
import javax.swing.JButton;
|
|
26 |
import javax.swing.JPanel;
|
|
27 |
import java.awt.Frame;
|
|
28 |
import java.awt.BorderLayout;
|
|
29 |
import java.awt.FlowLayout;
|
|
30 |
import java.awt.Container;
|
|
31 |
import javax.swing.text.AttributeSet;
|
|
32 |
import java.awt.Dialog;
|
|
33 |
//import javax.help.*;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Base class for other dialogs of application SimplyHTML.
|
|
37 |
*
|
|
38 |
* @author Ulrich Hilger
|
|
39 |
* @author Light Development
|
|
40 |
* @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
|
|
41 |
* @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
|
|
42 |
* @author published under the terms and conditions of the
|
|
43 |
* GNU General Public License,
|
|
44 |
* for details see file gpl.txt in the distribution
|
|
45 |
* package of this software
|
|
46 |
*
|
|
47 |
* @version stage 11, April 27, 2003
|
|
48 |
*/
|
|
49 |
|
|
50 |
public class DialogShell extends JDialog implements ActionListener { |
|
51 |
|
|
52 |
/** panel containing dialog buttons */
|
|
53 |
protected JPanel buttonPanel;
|
|
54 |
|
|
55 |
/** button to confirm the operation */
|
|
56 |
protected JButton okButton;
|
|
57 |
|
|
58 |
/** button to cancel the operation */
|
|
59 |
protected JButton cancelButton;
|
|
60 |
|
|
61 |
/** button to display context sensitive help */
|
|
62 |
protected JButton helpButton;
|
|
63 |
|
|
64 |
/**
|
|
65 |
* the result of the operation, one of RESULT_CANCEL and RESULT_OK
|
|
66 |
*/
|
|
67 |
private int result; |
|
68 |
|
|
69 |
/** result value for a cancelled operation */
|
|
70 |
public static int RESULT_CANCEL = 1; |
|
71 |
|
|
72 |
/** result value for a confirmed operation */
|
|
73 |
public static int RESULT_OK = 0; |
|
74 |
|
|
75 |
/** id of associated help topic (if any) */
|
|
76 |
protected String helpTopicId = null; |
|
77 |
|
|
78 |
//private HelpBroker myHelpBroker;
|
|
79 |
|
|
80 |
/**
|
|
81 |
* constructor
|
|
82 |
*
|
|
83 |
* @param parent the parent dialog
|
|
84 |
* @param title the title for this dialog
|
|
85 |
*/
|
|
86 | 0 |
public DialogShell(Dialog parent, String title) {
|
87 | 0 |
super(parent, title);
|
88 | 0 |
buildDialog(); |
89 |
} |
|
90 |
|
|
91 |
/**
|
|
92 |
* constructor
|
|
93 |
*
|
|
94 |
* @param parent the parent frame
|
|
95 |
* @param title the title for this dialog
|
|
96 |
*/
|
|
97 | 5 |
public DialogShell(Frame parent, String title) {
|
98 | 5 |
super(parent, title);
|
99 | 5 |
buildDialog(); |
100 |
} |
|
101 |
|
|
102 |
/**
|
|
103 |
* constructor
|
|
104 |
*
|
|
105 |
* @param parent the parent frame
|
|
106 |
* @param title the title for this dialog
|
|
107 |
* @param helpTopicId the id of the help topic to display for this dialog
|
|
108 |
*/
|
|
109 | 3 |
public DialogShell(Frame parent, String title, String helpTopicId) {
|
110 | 3 |
super(parent, title);
|
111 | 3 |
this.helpTopicId = helpTopicId;
|
112 | 3 |
buildDialog(); |
113 |
} |
|
114 |
|
|
115 |
/**
|
|
116 |
* constructor
|
|
117 |
*
|
|
118 |
* @param parent the parent dialog
|
|
119 |
* @param title the title for this dialog
|
|
120 |
* @param helpTopicId the id of the help topic to display for this dialog
|
|
121 |
*/
|
|
122 | 0 |
public DialogShell(Dialog parent, String title, String helpTopicId) {
|
123 | 0 |
super(parent, title);
|
124 | 0 |
this.helpTopicId = helpTopicId;
|
125 | 0 |
buildDialog(); |
126 |
} |
|
127 |
|
|
128 |
/**
|
|
129 |
* constructor
|
|
130 |
*
|
|
131 |
* @param parent the parent dialog
|
|
132 |
* @param title the title for this dialog
|
|
133 |
* @param helpTopicId the id of the help topic to display for this dialog
|
|
134 |
* @param helpBroker the helpBroker to use for context sensitive help
|
|
135 |
*/
|
|
136 |
/* public DialogShell(Dialog parent, String title, String helpTopicId, HelpBroker broker) {
|
|
137 |
super(parent, title);
|
|
138 |
this.helpTopicId = helpTopicId;
|
|
139 |
//this.myHelpBroker = broker;
|
|
140 |
buildDialog();
|
|
141 |
}*/
|
|
142 |
|
|
143 |
/**
|
|
144 |
* constructor
|
|
145 |
*
|
|
146 |
* @param parent the parent dialog
|
|
147 |
* @param title the title for this dialog
|
|
148 |
* @param helpTopicId the id of the help topic to display for this dialog
|
|
149 |
* @param helpBroker the helpBroker to use for context sensitive help
|
|
150 |
*/
|
|
151 |
/*public DialogShell(Frame parent, String title, String helpTopicId, HelpBroker broker) {
|
|
152 |
super(parent, title);
|
|
153 |
this.helpTopicId = helpTopicId;
|
|
154 |
this.myHelpBroker = broker;
|
|
155 |
buildDialog();
|
|
156 |
}*/
|
|
157 |
|
|
158 |
/**
|
|
159 |
* create dialog components
|
|
160 |
*/
|
|
161 | 8 |
private void buildDialog() { |
162 |
|
|
163 | 8 |
enableEvents(AWTEvent.WINDOW_EVENT_MASK); |
164 |
|
|
165 |
// construct dialog buttons
|
|
166 | 8 |
okButton = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "okBtnName")); |
167 | 8 |
cancelButton = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "cancelBtnName")); |
168 | 8 |
cancelButton.addActionListener(this);
|
169 | 8 |
okButton.addActionListener(this);
|
170 |
|
|
171 |
// construct button panel
|
|
172 | 8 |
buttonPanel = new JPanel(new FlowLayout()); |
173 | 8 |
buttonPanel.add(okButton); |
174 | 8 |
buttonPanel.add(cancelButton); |
175 |
|
|
176 |
// construct help button
|
|
177 |
/* if(helpTopicId != null) {
|
|
178 |
helpButton = new JButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "helpLabel"));
|
|
179 |
CSH.setHelpIDString(helpButton, helpTopicId);
|
|
180 |
if(myHelpBroker == null) {
|
|
181 |
helpButton.addActionListener(
|
|
182 |
new CSH.DisplayHelpFromSource(FrmMain.getHelpBroker()));
|
|
183 |
}
|
|
184 |
else {
|
|
185 |
helpButton.addActionListener(
|
|
186 |
new CSH.DisplayHelpFromSource(myHelpBroker));
|
|
187 |
}
|
|
188 |
buttonPanel.add(helpButton);
|
|
189 |
}*/
|
|
190 |
|
|
191 |
// add all to content pane of dialog
|
|
192 | 8 |
Container contentPane = getContentPane(); |
193 | 8 |
contentPane.setLayout(new BorderLayout(5,5));
|
194 | 8 |
contentPane.add(buttonPanel, BorderLayout.SOUTH); |
195 |
} |
|
196 |
|
|
197 |
/**
|
|
198 |
* dispose the dialog properly in case of window close events
|
|
199 |
*/
|
|
200 | 34 |
protected void processWindowEvent(WindowEvent e) { |
201 | 34 |
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
|
202 | 0 |
cancel(); |
203 |
} |
|
204 | 34 |
super.processWindowEvent(e);
|
205 |
} |
|
206 |
|
|
207 |
/**
|
|
208 |
* cancel the operation
|
|
209 |
*/
|
|
210 | 0 |
protected void cancel() { |
211 | 0 |
result = RESULT_CANCEL; |
212 | 0 |
dispose(); |
213 |
} |
|
214 |
|
|
215 |
/**
|
|
216 |
* confirm the operation
|
|
217 |
*/
|
|
218 | 8 |
protected void confirm() { |
219 | 8 |
result = RESULT_OK; |
220 | 8 |
dispose(); |
221 |
} |
|
222 |
|
|
223 |
/**
|
|
224 |
* get the result of the operation performed in this dialog
|
|
225 |
*
|
|
226 |
* @return the result, one of RESULT_OK and RESULT_CANCEL
|
|
227 |
*/
|
|
228 | 6 |
public int getResult() { |
229 | 6 |
return result;
|
230 |
} |
|
231 |
|
|
232 |
/**
|
|
233 |
* implements the ActionListener interface to be notified of
|
|
234 |
* clicks onto the ok and cancel button.
|
|
235 |
*/
|
|
236 | 8 |
public void actionPerformed(ActionEvent e) { |
237 | 8 |
Object src = e.getSource(); |
238 | 8 |
if(src == cancelButton) {
|
239 | 0 |
cancel(); |
240 |
} |
|
241 | 8 |
else if(src == okButton) { |
242 | 8 |
confirm(); |
243 |
} |
|
244 |
} |
|
245 |
} |
|