/[svn]/jsampler/trunk/src/org/jsampler/HF.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/HF.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 787 - (show annotations) (download)
Mon Oct 10 16:03:12 2005 UTC (18 years, 6 months ago) by iliev
File size: 3721 byte(s)
* The first alpha-release of JSampler

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005 Grigor Kirilov Iliev
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler;
24
25 import java.awt.Component;
26 import java.awt.Dialog;
27 import java.awt.Font;
28 import java.awt.Frame;
29
30 import java.util.logging.Level;
31
32 import javax.swing.JOptionPane;
33 import javax.swing.UIManager;
34 import javax.swing.plaf.FontUIResource;
35
36 import org.linuxsampler.lscp.LSException;
37 import org.linuxsampler.lscp.LscpException;
38
39 import static org.jsampler.JSI18n.i18n;
40
41
42 /**
43 *
44 * @author Grigor Iliev
45 */
46 public class HF {
47 // GUI HELPER FUNCIONS
48 public static String
49 getErrorMessage(Exception e) {
50 String msg = e.getMessage();
51
52 if(e instanceof LSException) {
53 LSException x = (LSException)e;
54 } else if(e instanceof LscpException) {
55
56 } else { msg = (msg != null ? msg : i18n.getError("unknownError")); }
57
58 return msg;
59 }
60
61 public static void
62 showErrorMessage(String msg) { showErrorMessage(msg, CC.getMainFrame()); }
63
64 public static void
65 showErrorMessage(String msg, Frame frame) {
66 JOptionPane.showMessageDialog (
67 frame, msg,
68 i18n.getError("error"),
69 JOptionPane.ERROR_MESSAGE
70 );
71 }
72
73 public static void
74 showErrorMessage(String msg, Dialog dlg) {
75 JOptionPane.showMessageDialog (
76 dlg, msg,
77 i18n.getError("error"),
78 JOptionPane.ERROR_MESSAGE
79 );
80 }
81
82 public static void
83 showErrorMessage(Exception e) { showErrorMessage(e, CC.getMainFrame()); }
84
85 public static void
86 showErrorMessage(Exception e, Frame frame) {
87 String msg = getErrorMessage(e);
88
89 CC.getLogger().log(Level.INFO, msg, e);
90
91 JOptionPane.showMessageDialog (
92 frame, msg,
93 i18n.getError("error"),
94 JOptionPane.ERROR_MESSAGE
95 );
96 }
97
98 public static void
99 showErrorMessage(Exception e, Dialog dlg) {
100 String msg = getErrorMessage(e);
101
102 CC.getLogger().log(Level.INFO, msg, e);
103
104 JOptionPane.showMessageDialog (
105 dlg, msg,
106 i18n.getError("error"),
107 JOptionPane.ERROR_MESSAGE
108 );
109 }
110
111 /**
112 * Brings up a question dialog with Yes, No options, empty title and the specified message.
113 *
114 */
115 public static boolean
116 showYesNoDialog(Component parent, String message) {
117 return showYesNoDialog(parent, message, "");
118 }
119
120 public static boolean
121 showYesNoDialog(Component parent, String message, String title) {
122 Object[] options = { i18n.getButtonLabel("yes"), i18n.getButtonLabel("no") };
123 int n = JOptionPane.showOptionDialog (
124 parent,
125 message, title,
126 JOptionPane.YES_NO_OPTION,
127 JOptionPane.QUESTION_MESSAGE,
128 null,
129 options, options[0]
130 );
131
132 return n == 0;
133 }
134
135 public static void
136 setUIDefaultFont(String fontName) {
137 if(fontName == null) return;
138
139 java.util.Enumeration keys = UIManager.getDefaults().keys();
140 while(keys.hasMoreElements()) {
141 Object key = keys.nextElement();
142 Object value = UIManager.get(key);
143 if(value instanceof FontUIResource) {
144 Font f = (FontUIResource)value;
145 FontUIResource fr =
146 new FontUIResource(fontName, f.getStyle(), f.getSize());
147 UIManager.put(key, fr);
148 }
149 }
150 }
151 ///////
152 }

  ViewVC Help
Powered by ViewVC