Browser.java

biz/hammurapi/swing/Browser.java

Violations

Inspector Message Severity Location
Java Inspector 002 Empty catch block. 1 219:43
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 043 Call 'wait ()' only inside a "while" loop 2 218:61
Java Inspector 089 Type is not documented 2 47:1
Java Inspector 089 Undocumented method 2 110:33
Java Inspector 089 Constructor is not properly documented 2 152:9
Java Inspector 089 Undocumented parameter title 2 152:9
Java Inspector 089 Parameter root is not documented 2 152:9
Java Inspector 089 Parameter o is not documented 2 195:9
Java Inspector 089 Parameter title is not documented 2 195:9
Java Inspector 089 Undocumented method 2 203:41
Java Inspector 089 Parameter o is not documented 2 232:9
Java Inspector 089 Parameter title is not documented 2 232:9
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 70:55
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 165:30
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 165:35
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 167:31
Java Inspector 046 Empty statements 3 219:75

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.swing;
24
25import java.awt.GridBagConstraints;
26import java.awt.GridBagLayout;
27import java.awt.event.WindowEvent;
28
29import javax.swing.JFrame;
30import javax.swing.JScrollPane;
31import javax.swing.JSplitPane;
32import javax.swing.JTable;
33import javax.swing.JTree;
34import javax.swing.WindowConstants;
35import javax.swing.table.TableModel;
36import javax.swing.tree.DefaultMutableTreeNode;
37import javax.swing.tree.TreeNode;
38import javax.swing.tree.DefaultTreeModel;
39import javax.swing.tree.TreePath;
40
41import biz.hammurapi.convert.ConvertingService;
42/**
43 * @author Pavel Vlasov
44 *
45 * @version $Revision: 1.2 $
46 */
47public class Browser extends JFrame {
48
49 private javax.swing.JPanel jContentPane = null;
50
51 private JSplitPane jSplitPane = null;
52
53 private JScrollPane jScrollPane = null;
54
55 private JScrollPane jDetailsPane = null;
56
57 private JTree jTree = null;
58
59 private JTable jTable = null;
60 /**
61 * This method initializes jSplitPane
62 *
63 * @return javax.swing.JSplitPane
64 */
65 private JSplitPane getJSplitPane() {
66 if (jSplitPane == null) {
67 jSplitPane = new JSplitPane();
68 jSplitPane.setLeftComponent(getJScrollPane());
69 jSplitPane.setRightComponent(getJScrollPane1());
70 jSplitPane.setDividerLocation(400);
71 }
72 return jSplitPane;
73 }
74
75 /**
76 * This method initializes jScrollPane
77 *
78 * @return javax.swing.JScrollPane
79 */
80 private JScrollPane getJScrollPane() {
81 if (jScrollPane == null) {
82 jScrollPane = new JScrollPane();
83 jScrollPane.setViewportView(getJTree());
84 }
85 return jScrollPane;
86 }
87
88 /**
89 * This method initializes jScrollPane1
90 *
91 * @return javax.swing.JScrollPane
92 */
93 private JScrollPane getJScrollPane1() {
94 if (jDetailsPane == null) {
95 jDetailsPane = new JScrollPane();
96 jDetailsPane.setViewportView(getJTable());
97 }
98 return jDetailsPane;
99 }
100
101 /**
102 * This method initializes jTree
103 *
104 * @return javax.swing.JTree
105 */
106 private JTree getJTree() {
107 if (jTree == null) {
108 jTree = new JTree();
109 jTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
110 public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
111 TreePath newLeadSelectionPath = e.getNewLeadSelectionPath();
112 if (newLeadSelectionPath==null) {
113 jTable.setVisible(false);
114 } else {
115 Object lastPathComponent = newLeadSelectionPath.getLastPathComponent();
116 if (lastPathComponent instanceof DefaultMutableTreeNode) { // For compatibility with old visualizables
117 lastPathComponent = ((DefaultMutableTreeNode) lastPathComponent).getUserObject();
118 }
119 if (lastPathComponent instanceof TableVisualizable) {
120 TableModel toTable = ((TableVisualizable) lastPathComponent).toTable();
121 if (toTable!=null) {
122 jTable.setModel(toTable);
123 }
124 jTable.setVisible(toTable!=null);
125 } else {
126 jTable.setVisible(false);
127 }
128 //jTable.getColumnModel().getColumn(0).setMaxWidth(150);
129 }
130 }
131 });
132 }
133 return jTree;
134 }
135
136 /**
137 * This method initializes jTable
138 *
139 * @return javax.swing.JTable
140 */
141 private JTable getJTable() {
142 if (jTable == null) {
143 jTable = new JTable();
144 }
145 return jTable;
146 }
147
148
149 /**
150 * @param root
151 */
152 public Browser(String title, TreeNode root) {
153 super();
154 initialize();
155 setTitle(title);
156 getJTree().setModel(new DefaultTreeModel(root));
157 }
158
159 /**
160 * This method initializes this
161 *
162 * @return void
163 */
164 private void initialize() {
165 this.setSize(921, 616);
166 this.setContentPane(getJContentPane());
167 this.setTitle("JFrame");
168 }
169
170 /**
171 * This method initializes jContentPane
172 *
173 * @return javax.swing.JPanel
174 */
175 private javax.swing.JPanel getJContentPane() {
176 if (jContentPane == null) {
177 GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
178 jContentPane = new javax.swing.JPanel();
179 jContentPane.setLayout(new GridBagLayout());
180 gridBagConstraints1.gridx = 0;
181 gridBagConstraints1.gridy = 0;
182 gridBagConstraints1.weightx = 1.0;
183 gridBagConstraints1.weighty = 1.0;
184 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
185 jContentPane.add(getJSplitPane(), gridBagConstraints1);
186 }
187 return jContentPane;
188 }
189
190 /**
191 * Shows objects in Browser. Blocks current thread until browser closes.
192 * @param o
193 * @param title
194 */
195 public static void show(Object o, String title) {
196 Visualizable vs = (Visualizable) ConvertingService.convert(o, Visualizable.class);
197 if (vs!=null) {
198 Object v = vs.toTreeNode(null, title);
199
200 if (v instanceof TreeNode) {
201 final Object monitor = new Object();
202 Browser browser = new Browser(title, (TreeNode) v) {
203 protected void processWindowEvent(WindowEvent e) {
204 super.processWindowEvent(e);
205 if (e.getID()==WindowEvent.WINDOW_CLOSED) {
206 synchronized (monitor) {
207 monitor.notifyAll();
208 }
209 }
210 }
211 };
212
213 browser.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
214 browser.setVisible(true);
215
216 synchronized (monitor) {
217 try {
218 monitor.wait();
219 } catch (InterruptedException ex) {
220 // Ignore
221 }
222 }
223 }
224 }
225 }
226
227 /**
228 * Shows object in browser with default close operation <code>WindowConstants.EXIT_ON_CLOSE</code>
229 * @param o
230 * @param title
231 */
232 public static void showAndExitOnClose(Object o, String title) {
233 Visualizable vs = (Visualizable) ConvertingService.convert(o, Visualizable.class);
234 if (vs!=null) {
235 Object v = vs.toTreeNode(null, title);
236
237 if (v instanceof TreeNode) {
238 Browser browser = new Browser(title, (TreeNode) v);
239 browser.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
240 browser.setVisible(true);
241 }
242 }
243 }
244
245} // @jve:decl-index=0:visual-constraint="10,10"
246