1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.services.gui.swing.exceptions;
18
19 import java.awt.BorderLayout;
20 import java.awt.Rectangle;
21 import java.net.URL;
22
23 import javax.swing.JButton;
24 import javax.swing.JDialog;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 import javax.swing.JScrollPane;
28 import javax.swing.JTextArea;
29 import javax.swing.SwingUtilities;
30 import javax.swing.UIManager;
31
32 import org.jdesktop.application.Action;
33 import org.jdesktop.application.ResourceMap;
34
35 import ch.elca.el4j.services.gui.swing.GUIApplication;
36
37 import cookxml.cookswing.CookSwing;
38
39
40
41
42
43
44
45
46 @SuppressWarnings("serial")
47 public class ExceptionDialog extends JDialog {
48
49
50
51 protected JLabel m_message;
52
53
54
55
56 protected JButton m_detailsButton;
57
58
59
60
61 protected JScrollPane m_detailsScrollPane;
62
63
64
65
66 protected JTextArea m_details;
67
68
69
70
71 protected JLabel m_errorImage;
72
73
74
75
76 protected ResourceMap m_resourceMap;
77
78
79
80
81 public ExceptionDialog(String details) {
82 super(GUIApplication.getInstance().getMainFrame());
83
84 m_resourceMap = GUIApplication.getInstance().getContext().getResourceMap(ExceptionDialog.class);
85
86 CookSwing cookSwing = new CookSwing(this);
87 URL url = m_resourceMap.getClassLoader().getResource(m_resourceMap.getResourcesDir() + "exceptionDialog.xml");
88 setLayout(new BorderLayout());
89 add((JPanel) cookSwing.render(url.getFile()));
90
91 setModal(true);
92 setTitle(getRes("exceptionDialogTitle"));
93 m_message.setText(getRes("exceptionDialogMessage"));
94 m_details.setText(details);
95
96
97 m_details.setFont(m_details.getFont().deriveFont(12.0f));
98
99 m_errorImage.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
100
101 pack();
102
103
104 toggleDetails();
105
106
107 setLocationRelativeTo(null);
108 }
109
110
111
112
113 @Action
114 public void close() {
115 dispose();
116 }
117
118
119
120
121 @Action
122 public void toggleDetails() {
123 Rectangle bounds = getBounds();
124 if (m_detailsScrollPane.isVisible()) {
125 m_detailsButton.setText(getRes("moreDetails"));
126 bounds.height -= m_detailsScrollPane.getBounds().height;
127 setBounds(bounds);
128 m_detailsScrollPane.setVisible(false);
129 } else {
130 m_detailsButton.setText(getRes("lessDetails"));
131 bounds.height += m_detailsScrollPane.getBounds().height;
132 setBounds(bounds);
133 m_detailsScrollPane.setVisible(true);
134 }
135 SwingUtilities.updateComponentTreeUI(this);
136 }
137
138
139
140
141
142 protected String getRes(String id) {
143 return m_resourceMap.getString(id);
144 }
145
146 }