1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
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.view.std; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dialog; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
29 |
import java.awt.Rectangle; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.Box; |
36 |
import javax.swing.BoxLayout; |
37 |
import javax.swing.Icon; |
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JComponent; |
40 |
import javax.swing.JToggleButton; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JTextArea; |
44 |
import javax.swing.JScrollPane; |
45 |
import javax.swing.JSeparator; |
46 |
import javax.swing.SwingUtilities; |
47 |
|
48 |
import org.linuxsampler.lscp.LSException; |
49 |
|
50 |
import net.sf.juife.EnhancedDialog; |
51 |
import net.sf.juife.JuifeUtils; |
52 |
|
53 |
import static org.jsampler.view.std.StdI18n.i18n; |
54 |
|
55 |
|
56 |
/** |
57 |
* |
58 |
* @author Grigor Iliev |
59 |
*/ |
60 |
public class JSDetailedErrorDlg extends EnhancedDialog { |
61 |
private final JLabel lError = new JLabel(); |
62 |
private final JTextArea taDetails = new JTextArea(); |
63 |
|
64 |
private final JButton btnDetails = |
65 |
new JButton(i18n.getButtonLabel("JSDetailedErrorDlg.showDetails")); |
66 |
|
67 |
private JComponent mainPane; |
68 |
private JComponent detailsPane; |
69 |
|
70 |
int hideHeight; |
71 |
int showHeight; |
72 |
boolean show = false; |
73 |
|
74 |
/** |
75 |
* Creates a new instance of <code>JSDetailedErrorDlg</code> |
76 |
*/ |
77 |
public JSDetailedErrorDlg(Frame owner, Icon iconWarning, String title, String err, String details) { |
78 |
super(owner, title); |
79 |
initDetailedErrorDlg(err, details, iconWarning); |
80 |
} |
81 |
|
82 |
/** |
83 |
* Creates a new instance of <code>JSDetailedErrorDlg</code> |
84 |
*/ |
85 |
public JSDetailedErrorDlg(Dialog owner, Icon iconWarning, String title, String err, String details) { |
86 |
super(owner, title); |
87 |
initDetailedErrorDlg(err, details, iconWarning); |
88 |
} |
89 |
|
90 |
private void |
91 |
initDetailedErrorDlg(String err, String details, Icon iconWarning) { |
92 |
lError.setText(err); |
93 |
lError.setIcon(iconWarning); |
94 |
lError.setAlignmentX(LEFT_ALIGNMENT); |
95 |
lError.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); |
96 |
taDetails.setText(details); |
97 |
taDetails.setEditable(false); |
98 |
|
99 |
mainPane = new JPanel(); |
100 |
mainPane.setLayout(new BorderLayout()); |
101 |
|
102 |
JPanel p = new JPanel(); |
103 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
104 |
p.add(lError); |
105 |
|
106 |
JPanel btnPane = new JPanel(); |
107 |
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
108 |
btnPane.add(Box.createGlue()); |
109 |
btnPane.add(btnDetails); |
110 |
btnPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0)); |
111 |
btnPane.setAlignmentX(LEFT_ALIGNMENT); |
112 |
p.add(btnPane); |
113 |
|
114 |
mainPane.add(p, BorderLayout.NORTH); |
115 |
|
116 |
detailsPane = new JPanel(); |
117 |
detailsPane.setLayout(new BoxLayout(detailsPane, BoxLayout.Y_AXIS)); |
118 |
detailsPane.add(Box.createRigidArea(new Dimension(0, 5))); |
119 |
detailsPane.add(new JSeparator()); |
120 |
detailsPane.add(Box.createRigidArea(new Dimension(0, 12))); |
121 |
detailsPane.add(new JScrollPane(taDetails)); |
122 |
detailsPane.setAlignmentX(LEFT_ALIGNMENT); |
123 |
|
124 |
mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
125 |
add(mainPane); |
126 |
|
127 |
Dimension d = mainPane.getPreferredSize(); |
128 |
d = new Dimension(d.width > 300 ? d.width : 300, d.height); |
129 |
hideHeight = getPreferredSize().height; |
130 |
showHeight = hideHeight + 200; |
131 |
|
132 |
mainPane.setPreferredSize(d); |
133 |
mainPane.setMinimumSize(d); |
134 |
|
135 |
//d = new Dimension(300, 200); |
136 |
//detailsPane.setPreferredSize(d); |
137 |
//detailsPane.setMinimumSize(d); |
138 |
pack(); |
139 |
setMinimumSize(getPreferredSize()); |
140 |
|
141 |
setLocation(JuifeUtils.centerLocation(this, getOwner())); |
142 |
|
143 |
btnDetails.addActionListener(new ActionListener() { |
144 |
public void |
145 |
actionPerformed(ActionEvent e) { showDetails(show = !show); } |
146 |
}); |
147 |
} |
148 |
|
149 |
public void |
150 |
showDetails(final boolean b) { |
151 |
if(b) btnDetails.setText(i18n.getButtonLabel("JSDetailedErrorDlg.hideDetails")); |
152 |
else btnDetails.setText(i18n.getButtonLabel("JSDetailedErrorDlg.showDetails")); |
153 |
|
154 |
if(b) { |
155 |
mainPane.add(detailsPane); |
156 |
} else { |
157 |
showHeight = getSize().height; |
158 |
mainPane.remove(detailsPane); |
159 |
} |
160 |
|
161 |
SwingUtilities.invokeLater(new Runnable() { |
162 |
public void |
163 |
run() { |
164 |
int w = getSize().width; |
165 |
if(b) { |
166 |
Rectangle r = getBounds(); |
167 |
setBounds(r.x, r.y, w, showHeight); |
168 |
} else { |
169 |
Rectangle r = getBounds(); |
170 |
setBounds(r.x, r.y, w, hideHeight); |
171 |
} |
172 |
} |
173 |
}); |
174 |
|
175 |
setResizable(b); |
176 |
} |
177 |
|
178 |
protected void |
179 |
onOk() { } |
180 |
|
181 |
protected void |
182 |
onCancel() { setVisible(false); } |
183 |
} |