2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.Component;
25 import java.awt.HeadlessException;
27 import javax.swing.Icon;
28 import javax.swing.JOptionPane;
30 public class JvOptionPane extends JOptionPane
35 private static final long serialVersionUID = -3019167117756785229L;
37 private static Object mockResponse = JvOptionPane.CANCEL_OPTION;
39 private static boolean interactiveMode = true;
41 public static int showConfirmDialog(Component parentComponent,
42 Object message) throws HeadlessException
44 return isInteractiveMode()
45 ? JOptionPane.showConfirmDialog(parentComponent, message)
46 : (int) getMockResponse();
49 public static int showConfirmDialog(Component parentComponent,
50 Object message, String title, int optionType)
51 throws HeadlessException
53 return isInteractiveMode()
54 ? JOptionPane.showConfirmDialog(parentComponent, message, title,
56 : (int) getMockResponse();
59 public static int showConfirmDialog(Component parentComponent,
60 Object message, String title, int optionType, int messageType)
61 throws HeadlessException
63 return isInteractiveMode()
64 ? JOptionPane.showConfirmDialog(parentComponent, message, title,
65 optionType, messageType)
66 : (int) getMockResponse();
69 public static int showConfirmDialog(Component parentComponent,
70 Object message, String title, int optionType, int messageType,
71 Icon icon) throws HeadlessException
73 return isInteractiveMode()
74 ? JOptionPane.showConfirmDialog(parentComponent, message, title,
75 optionType, messageType, icon)
76 : (int) getMockResponse();
79 public static int showInternalConfirmDialog(Component parentComponent,
82 return isInteractiveMode()
83 ? JOptionPane.showInternalConfirmDialog(parentComponent,
85 : (int) getMockResponse();
88 public static int showInternalConfirmDialog(Component parentComponent,
89 Object message, String title, int optionType)
91 return isInteractiveMode()
92 ? JOptionPane.showConfirmDialog(parentComponent, message, title,
94 : (int) getMockResponse();
97 public static int showInternalConfirmDialog(Component parentComponent,
98 Object message, String title, int optionType, int messageType)
100 return isInteractiveMode()
101 ? JOptionPane.showConfirmDialog(parentComponent, message, title,
102 optionType, messageType)
103 : (int) getMockResponse();
106 public static int showInternalConfirmDialog(Component parentComponent,
107 Object message, String title, int optionType, int messageType,
110 return isInteractiveMode()
111 ? JOptionPane.showInternalConfirmDialog(parentComponent,
112 message, title, optionType, messageType, icon)
113 : (int) getMockResponse();
116 public static int showOptionDialog(Component parentComponent,
117 Object message, String title, int optionType, int messageType,
118 Icon icon, Object[] options, Object initialValue)
119 throws HeadlessException
121 return isInteractiveMode()
122 ? JOptionPane.showOptionDialog(parentComponent, message, title,
123 optionType, messageType, icon, options, initialValue)
124 : (int) getMockResponse();
127 public static void showMessageDialog(Component parentComponent,
128 Object message) throws HeadlessException
130 if (isInteractiveMode())
132 JOptionPane.showMessageDialog(parentComponent, message);
136 outputMessage(message);
140 public static void showMessageDialog(Component parentComponent,
141 Object message, String title, int messageType)
142 throws HeadlessException
144 if (isInteractiveMode())
146 JOptionPane.showMessageDialog(parentComponent, message, title,
151 outputMessage(message);
155 public static void showMessageDialog(Component parentComponent,
156 Object message, String title, int messageType, Icon icon)
157 throws HeadlessException
159 if (isInteractiveMode())
161 JOptionPane.showMessageDialog(parentComponent, message, title,
166 outputMessage(message);
170 public static void showInternalMessageDialog(Component parentComponent,
173 if (isInteractiveMode())
175 JOptionPane.showMessageDialog(parentComponent, message);
179 outputMessage(message);
183 public static void showInternalMessageDialog(Component parentComponent,
184 Object message, String title, int messageType)
186 if (isInteractiveMode())
188 JOptionPane.showMessageDialog(parentComponent, message, title,
193 outputMessage(message);
197 public static void showInternalMessageDialog(Component parentComponent,
198 Object message, String title, int messageType, Icon icon)
200 if (isInteractiveMode())
202 JOptionPane.showMessageDialog(parentComponent, message, title,
207 outputMessage(message);
211 public static String showInputDialog(Object message)
212 throws HeadlessException
214 return isInteractiveMode() ? JOptionPane.showInputDialog(message)
215 : getMockResponse().toString();
218 public static String showInputDialog(Object message,
219 Object initialSelectionValue)
221 return isInteractiveMode()
222 ? JOptionPane.showInputDialog(message, initialSelectionValue)
223 : getMockResponse().toString();
226 public static String showInputDialog(Component parentComponent,
227 Object message) throws HeadlessException
229 return isInteractiveMode()
230 ? JOptionPane.showInputDialog(parentComponent, message)
231 : getMockResponse().toString();
234 public static String showInputDialog(Component parentComponent,
235 Object message, Object initialSelectionValue)
237 return isInteractiveMode()
238 ? JOptionPane.showInputDialog(parentComponent, message,
239 initialSelectionValue)
240 : getMockResponse().toString();
243 public static String showInputDialog(Component parentComponent,
244 Object message, String title, int messageType)
245 throws HeadlessException
247 return isInteractiveMode()
248 ? JOptionPane.showInputDialog(parentComponent, message, title,
250 : getMockResponse().toString();
253 public static Object showInputDialog(Component parentComponent,
254 Object message, String title, int messageType, Icon icon,
255 Object[] selectionValues, Object initialSelectionValue)
256 throws HeadlessException
258 return isInteractiveMode()
259 ? JOptionPane.showInputDialog(parentComponent, message, title,
260 messageType, icon, selectionValues,
261 initialSelectionValue)
262 : getMockResponse().toString();
265 public static String showInternalInputDialog(Component parentComponent,
268 return isInteractiveMode()
269 ? JOptionPane.showInternalInputDialog(parentComponent, message)
270 : getMockResponse().toString();
273 public static String showInternalInputDialog(Component parentComponent,
274 Object message, String title, int messageType)
276 return isInteractiveMode()
277 ? JOptionPane.showInternalInputDialog(parentComponent, message,
279 : getMockResponse().toString();
282 public static Object showInternalInputDialog(Component parentComponent,
283 Object message, String title, int messageType, Icon icon,
284 Object[] selectionValues, Object initialSelectionValue)
286 return isInteractiveMode()
287 ? JOptionPane.showInternalInputDialog(parentComponent, message,
288 title, messageType, icon, selectionValues,
289 initialSelectionValue)
290 : getMockResponse().toString();
293 private static void outputMessage(Object message)
295 System.out.println(">>> JOption Message : " + message.toString());
298 public static Object getMockResponse()
303 public static void setMockResponse(Object mockOption)
305 JvOptionPane.mockResponse = mockOption;
308 public static void resetMock()
310 setMockResponse(JvOptionPane.CANCEL_OPTION);
311 setInteractiveMode(true);
314 public static boolean isInteractiveMode()
316 return interactiveMode;
319 public static void setInteractiveMode(boolean interactiveMode)
321 JvOptionPane.interactiveMode = interactiveMode;