/[svn]/jsampler/trunk/src/org/jsampler/view/classic/DetailedErrorDlg.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/classic/DetailedErrorDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1205 - (hide annotations) (download)
Thu May 24 21:55:41 2007 UTC (16 years, 11 months ago) by iliev
File size: 5040 byte(s)
* upgrading to version 0.5a

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

  ViewVC Help
Powered by ViewVC