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() ? JOptionPane.showConfirmDialog(
45 parentComponent, message) : (int) getMockResponse();
48 public static int showConfirmDialog(Component parentComponent,
49 Object message, String title, int optionType)
50 throws HeadlessException
52 return isInteractiveMode() ? JOptionPane.showConfirmDialog(
53 parentComponent, message, title, optionType)
54 : (int) getMockResponse();
57 public static int showConfirmDialog(Component parentComponent,
58 Object message, String title, int optionType, int messageType)
59 throws HeadlessException
61 return isInteractiveMode() ? JOptionPane.showConfirmDialog(
62 parentComponent, message, title, optionType, messageType)
63 : (int) getMockResponse();
66 public static int showConfirmDialog(Component parentComponent,
67 Object message, String title, int optionType, int messageType,
68 Icon icon) throws HeadlessException
70 return isInteractiveMode() ? JOptionPane.showConfirmDialog(
71 parentComponent, message, title, optionType, messageType, icon)
72 : (int) getMockResponse();
75 public static int showInternalConfirmDialog(Component parentComponent,
78 return isInteractiveMode() ? JOptionPane.showInternalConfirmDialog(
79 parentComponent, message) : (int) getMockResponse();
82 public static int showInternalConfirmDialog(Component parentComponent,
83 Object message, String title, int optionType)
85 return isInteractiveMode() ? JOptionPane.showConfirmDialog(
86 parentComponent, message, title, optionType)
87 : (int) getMockResponse();
90 public static int showInternalConfirmDialog(Component parentComponent,
91 Object message, String title, int optionType, int messageType)
93 return isInteractiveMode() ? JOptionPane.showConfirmDialog(
94 parentComponent, message, title, optionType, messageType)
95 : (int) getMockResponse();
98 public static int showInternalConfirmDialog(Component parentComponent,
99 Object message, String title, int optionType, int messageType,
102 return isInteractiveMode() ? JOptionPane.showInternalConfirmDialog(
103 parentComponent, message, title, optionType, messageType, icon)
104 : (int) getMockResponse();
107 public static int showOptionDialog(Component parentComponent,
108 Object message, String title, int optionType, int messageType,
109 Icon icon, Object[] options, Object initialValue)
110 throws HeadlessException
112 return isInteractiveMode() ? JOptionPane.showOptionDialog(
113 parentComponent, message, title, optionType, messageType, icon,
114 options, initialValue) : (int) getMockResponse();
117 public static void showMessageDialog(Component parentComponent,
118 Object message) throws HeadlessException
120 if (isInteractiveMode())
122 JOptionPane.showMessageDialog(parentComponent, message);
126 outputMessage(message);
130 public static void showMessageDialog(Component parentComponent,
131 Object message, String title, int messageType)
132 throws HeadlessException
134 if (isInteractiveMode())
136 JOptionPane.showMessageDialog(parentComponent, message, title,
141 outputMessage(message);
145 public static void showMessageDialog(Component parentComponent,
146 Object message, String title, int messageType, Icon icon)
147 throws HeadlessException
149 if (isInteractiveMode())
151 JOptionPane.showMessageDialog(parentComponent, message, title,
156 outputMessage(message);
160 public static void showInternalMessageDialog(Component parentComponent,
163 if (isInteractiveMode())
165 JOptionPane.showMessageDialog(parentComponent, message);
169 outputMessage(message);
173 public static void showInternalMessageDialog(Component parentComponent,
174 Object message, String title, int messageType)
176 if (isInteractiveMode())
178 JOptionPane.showMessageDialog(parentComponent, message, title,
183 outputMessage(message);
187 public static void showInternalMessageDialog(Component parentComponent,
188 Object message, String title, int messageType, Icon icon)
190 if (isInteractiveMode())
192 JOptionPane.showMessageDialog(parentComponent, message, title,
197 outputMessage(message);
201 public static String showInputDialog(Object message)
202 throws HeadlessException
204 return isInteractiveMode() ? JOptionPane.showInputDialog(message)
205 : getMockResponse().toString();
208 public static String showInputDialog(Object message,
209 Object initialSelectionValue)
211 return isInteractiveMode() ? JOptionPane.showInputDialog(message,
212 initialSelectionValue) : getMockResponse().toString();
215 public static String showInputDialog(Component parentComponent,
216 Object message) throws HeadlessException
218 return isInteractiveMode() ? JOptionPane.showInputDialog(
219 parentComponent, message) : getMockResponse().toString();
222 public static String showInputDialog(Component parentComponent,
223 Object message, Object initialSelectionValue)
225 return isInteractiveMode() ? JOptionPane.showInputDialog(
226 parentComponent, message, initialSelectionValue)
227 : getMockResponse().toString();
230 public static String showInputDialog(Component parentComponent,
231 Object message, String title, int messageType)
232 throws HeadlessException
234 return isInteractiveMode() ? JOptionPane.showInputDialog(
235 parentComponent, message, title, messageType)
236 : getMockResponse().toString();
239 public static Object showInputDialog(Component parentComponent,
240 Object message, String title, int messageType, Icon icon,
241 Object[] selectionValues, Object initialSelectionValue)
242 throws HeadlessException
244 return isInteractiveMode() ? JOptionPane.showInputDialog(
245 parentComponent, message, title, messageType, icon,
246 selectionValues, initialSelectionValue) : getMockResponse()
250 public static String showInternalInputDialog(Component parentComponent,
253 return isInteractiveMode() ? JOptionPane.showInternalInputDialog(
254 parentComponent, message) : getMockResponse().toString();
257 public static String showInternalInputDialog(Component parentComponent,
258 Object message, String title, int messageType)
260 return isInteractiveMode() ? JOptionPane.showInternalInputDialog(
261 parentComponent, message, title, messageType)
262 : getMockResponse().toString();
265 public static Object showInternalInputDialog(Component parentComponent,
266 Object message, String title, int messageType, Icon icon,
267 Object[] selectionValues, Object initialSelectionValue)
269 return isInteractiveMode() ? JOptionPane.showInternalInputDialog(
270 parentComponent, message, title, messageType, icon,
271 selectionValues, initialSelectionValue) : getMockResponse()
275 private static void outputMessage(Object message)
277 System.out.println(">>> JOption Message : " + message.toString());
280 public static Object getMockResponse()
285 public static void setMockResponse(Object mockOption)
287 JvOptionPane.mockResponse = mockOption;
290 public static void resetMock()
292 setMockResponse(JvOptionPane.CANCEL_OPTION);
293 setInteractiveMode(true);
296 public static boolean isInteractiveMode()
298 return interactiveMode;
301 public static void setInteractiveMode(boolean interactiveMode)
303 JvOptionPane.interactiveMode = interactiveMode;