40 |
|
|
41 |
|
|
42 |
/** |
/** |
43 |
* |
* This class contains some helper function. |
44 |
* @author Grigor Iliev |
* @author Grigor Iliev |
45 |
*/ |
*/ |
46 |
public class HF { |
public class HF { |
47 |
// GUI HELPER FUNCIONS |
// GUI HELPER FUNCIONS |
48 |
|
|
49 |
|
/** |
50 |
|
* Returns more meaningful, non-<code>null</code> message. |
51 |
|
* @return More meaningful, non-<code>null</code> message. |
52 |
|
*/ |
53 |
public static String |
public static String |
54 |
getErrorMessage(Exception e) { |
getErrorMessage(Exception e) { |
55 |
String msg = e.getMessage(); |
String msg = e.getMessage(); |
63 |
return msg; |
return msg; |
64 |
} |
} |
65 |
|
|
66 |
|
/** |
67 |
|
* Shows a dialog with the specified error message. |
68 |
|
* @param msg The error message to be shown. |
69 |
|
*/ |
70 |
public static void |
public static void |
71 |
showErrorMessage(String msg) { showErrorMessage(msg, CC.getMainFrame()); } |
showErrorMessage(String msg) { showErrorMessage(msg, CC.getMainFrame()); } |
72 |
|
|
73 |
|
/** |
74 |
|
* Shows a dialog with the specified error message. |
75 |
|
* @param frame The parent <code>Frame</code> for the dialog. |
76 |
|
* @param msg The error message to be shown. |
77 |
|
*/ |
78 |
public static void |
public static void |
79 |
showErrorMessage(String msg, Frame frame) { |
showErrorMessage(String msg, Frame frame) { |
80 |
JOptionPane.showMessageDialog ( |
JOptionPane.showMessageDialog ( |
84 |
); |
); |
85 |
} |
} |
86 |
|
|
87 |
|
/** |
88 |
|
* Shows a dialog with the specified error message. |
89 |
|
* @param dlg The parent <code>Dialog</code> from which the dialog is displayed. |
90 |
|
* @param msg The error message to be shown. |
91 |
|
*/ |
92 |
public static void |
public static void |
93 |
showErrorMessage(String msg, Dialog dlg) { |
showErrorMessage(String msg, Dialog dlg) { |
94 |
JOptionPane.showMessageDialog ( |
JOptionPane.showMessageDialog ( |
98 |
); |
); |
99 |
} |
} |
100 |
|
|
101 |
|
/** |
102 |
|
* Shows a dialog with error message obtained by {@link #getErrorMessage} method. |
103 |
|
* @param e The <code>Exception</code> from which the error message is obtained. |
104 |
|
*/ |
105 |
public static void |
public static void |
106 |
showErrorMessage(Exception e) { showErrorMessage(e, CC.getMainFrame()); } |
showErrorMessage(Exception e) { showErrorMessage(e, CC.getMainFrame()); } |
107 |
|
|
108 |
|
/** |
109 |
|
* Shows a dialog with error message obtained by {@link #getErrorMessage} method. |
110 |
|
* @param e The <code>Exception</code> from which the error message is obtained. |
111 |
|
* @param prefix The prefix to be added to the error message. |
112 |
|
*/ |
113 |
|
public static void |
114 |
|
showErrorMessage(Exception e, String prefix) { |
115 |
|
showErrorMessage(e, CC.getMainFrame(), prefix); |
116 |
|
} |
117 |
|
|
118 |
|
/** |
119 |
|
* Shows a dialog with error message obtained by {@link #getErrorMessage} method. |
120 |
|
* @param e The <code>Exception</code> from which the error message is obtained. |
121 |
|
* @param frame The parent <code>Frame</code> for the dialog. |
122 |
|
*/ |
123 |
public static void |
public static void |
124 |
showErrorMessage(Exception e, Frame frame) { |
showErrorMessage(Exception e, Frame frame) { |
125 |
String msg = getErrorMessage(e); |
showErrorMessage(e, frame, ""); |
126 |
|
} |
127 |
|
|
128 |
|
/** |
129 |
|
* Shows a dialog with error message obtained by {@link #getErrorMessage} method. |
130 |
|
* @param e The <code>Exception</code> from which the error message is obtained. |
131 |
|
* @param frame The parent <code>Frame</code> for the dialog. |
132 |
|
* @param prefix The prefix to be added to the error message. |
133 |
|
*/ |
134 |
|
public static void |
135 |
|
showErrorMessage(Exception e, Frame frame, String prefix) { |
136 |
|
String msg = prefix + getErrorMessage(e); |
137 |
|
|
138 |
CC.getLogger().log(Level.INFO, msg, e); |
CC.getLogger().log(Level.INFO, msg, e); |
139 |
|
|
144 |
); |
); |
145 |
} |
} |
146 |
|
|
147 |
|
/** |
148 |
|
* Shows a dialog with error message obtained by {@link #getErrorMessage} method. |
149 |
|
* @param e The <code>Exception</code> from which the error message is obtained. |
150 |
|
* @param dlg The parent <code>Dialog</code> from which the dialog is displayed. |
151 |
|
*/ |
152 |
public static void |
public static void |
153 |
showErrorMessage(Exception e, Dialog dlg) { |
showErrorMessage(Exception e, Dialog dlg) { |
154 |
String msg = getErrorMessage(e); |
String msg = getErrorMessage(e); |
164 |
|
|
165 |
/** |
/** |
166 |
* Brings up a question dialog with Yes, No options, empty title and the specified message. |
* Brings up a question dialog with Yes, No options, empty title and the specified message. |
167 |
* |
* @param parent The parent <code>Component</code> for the dialog. |
168 |
|
* @param message The message to display. |
169 |
*/ |
*/ |
170 |
public static boolean |
public static boolean |
171 |
showYesNoDialog(Component parent, String message) { |
showYesNoDialog(Component parent, String message) { |
172 |
return showYesNoDialog(parent, message, ""); |
return showYesNoDialog(parent, message, ""); |
173 |
} |
} |
174 |
|
|
175 |
|
/** |
176 |
|
* Brings up a question dialog with Yes, No options, empty title and the specified message. |
177 |
|
* @param parent The parent <code>Component</code> for the dialog. |
178 |
|
* @param message The message to display. |
179 |
|
* @param title The dialog's title. |
180 |
|
*/ |
181 |
public static boolean |
public static boolean |
182 |
showYesNoDialog(Component parent, String message, String title) { |
showYesNoDialog(Component parent, String message, String title) { |
183 |
Object[] options = { i18n.getButtonLabel("yes"), i18n.getButtonLabel("no") }; |
Object[] options = { i18n.getButtonLabel("yes"), i18n.getButtonLabel("no") }; |
193 |
return n == 0; |
return n == 0; |
194 |
} |
} |
195 |
|
|
196 |
|
/** |
197 |
|
* Sets the default font to be used in the GUI. |
198 |
|
* @param fontName The name of the font to be used as default. |
199 |
|
*/ |
200 |
public static void |
public static void |
201 |
setUIDefaultFont(String fontName) { |
setUIDefaultFont(String fontName) { |
202 |
if(fontName == null) return; |
if(fontName == null) return; |