-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathOSPTableInspector.java
More file actions
154 lines (139 loc) · 4.84 KB
/
OSPTableInspector.java
File metadata and controls
154 lines (139 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Open Source Physics software is free software as described near the bottom of this code file.
*
* For additional information and documentation on Open Source Physics please see:
* <http://www.opensourcephysics.org/>
*/
package org.opensourcephysics.controls;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
* A dialog that displays an editable table of properties using an OSPControlTable.
*
* @author Wolfgang Christian
* @version 1.0
*/
public class OSPTableInspector extends JDialog implements PropertyChangeListener {
// static fields
final static String FRAME_TITLE = ControlsRes.getString("OSPTableInspector.Properties_of"); //$NON-NLS-1$
// instance fields
private OSPControlTable table;
/**
* Constructs editable modal inspector for specified XMLControl.
*
*/
public OSPTableInspector() {
this(true, true);
}
/**
* Constructs modal inspector for specified XMLControl and sets editable flag.
*
* @param editable true to enable editing
*/
public OSPTableInspector(boolean editable) {
this(editable, true);
}
/**
* Constructs inspector for specified XMLControl and sets editable and modal flags.
*
* @param editable true to enable editing
* @param modal true if modal
*/
public OSPTableInspector(boolean editable, boolean modal) {
this(null, editable, modal);
}
/**
* Constructs inspector for specified XMLControl and sets editable and modal flags.
*
* @param owner the frame's owner
* @param editable true to enable editing
* @param modal true if modal
*/
public OSPTableInspector(Frame owner, boolean editable, boolean modal) {
super(owner, modal);
XMLControlElement control = new XMLControlElement();
table = new OSPControlTable(control);
table.setEditable(editable);
createGUI();
String s = XML.getExtension(control.getObjectClassName());
setTitle(FRAME_TITLE+" "+s+" \""+control.getPropertyName()+"\" "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
table.addPropertyChangeListener("cell", this); //$NON-NLS-1$
}
/**
* Gets the Control associated with this table.
*
* @return Control
*/
public Control getControl() {
return table;
}
/**
* Listens for property change events from XMLTable.
*
* @param e the property change event
*/
public void propertyChange(PropertyChangeEvent e) {
// forward event to listeners
firePropertyChange(e.getPropertyName(), e.getOldValue(), e.getNewValue());
}
/**
* Gets the XMLTable.
*
* @return the table
*/
public XMLTable getTable() {
return table;
}
// creates the GUI
private void createGUI() {
setSize(400, 300);
setContentPane(new JPanel(new BorderLayout()));
JScrollPane scrollpane = new JScrollPane(table);
scrollpane.createHorizontalScrollBar();
getContentPane().add(scrollpane, BorderLayout.CENTER);
if(!JDialog.isDefaultLookAndFeelDecorated()) {
return;
}
JPanel panel = new JPanel(new FlowLayout());
JButton closeButton = new JButton(ControlsRes.getString("OSPTableInspector.OK")); //$NON-NLS-1$
panel.add(closeButton);
getContentPane().add(panel, BorderLayout.SOUTH);
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
});
}
}
/*
* Open Source Physics software is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License (GPL) as
* published by the Free Software Foundation; either version 2 of the License,
* or(at your option) any later version.
* Code that uses any portion of the code in the org.opensourcephysics package
* or any subpackage (subdirectory) of this package must must also be be released
* under the GNU GPL license.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA
* or view the license online at http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2007 The Open Source Physics project
* http://www.opensourcephysics.org
*/