2
* Copyright (C) 2014 Andrew Reid and the ModelGUI Project <http://mgui.wikidot.com>
4
* This file is part of ModelGUI[core] (mgui-core).
6
* ModelGUI[core] is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* ModelGUI[core] 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
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with ModelGUI[core]. If not, see <http://www.gnu.org/licenses/>.
20
package mgui.io.domestic.shapes;
22
import java.awt.event.ActionEvent;
24
import java.util.Vector;
26
import javax.swing.JFrame;
27
import javax.swing.JLabel;
28
import javax.swing.JScrollPane;
29
import javax.swing.JTable;
30
import javax.swing.table.AbstractTableModel;
32
import mgui.interfaces.InterfaceEnvironment;
33
import mgui.interfaces.InterfaceSession;
34
import mgui.interfaces.gui.InterfaceComboBox;
35
import mgui.interfaces.io.InterfaceIODialogBox;
36
import mgui.interfaces.layouts.LineLayout;
37
import mgui.interfaces.layouts.LineLayoutConstraints;
38
import mgui.interfaces.shapes.ShapeSet3DInt;
39
import mgui.io.InterfaceIOOptions;
40
import mgui.io.InterfaceIOPanel;
42
/*********************************************
43
* Dialog box for loading a ModelGUI shape. The default implementation is for XML encoding.
50
public class ShapeInputDialogBox extends InterfaceIODialogBox {
52
protected JLabel lblShapeSet = new JLabel("Add to shape set:");
53
protected InterfaceComboBox cmbShapeSet = new InterfaceComboBox(InterfaceComboBox.RenderMode.LongestItem,
57
protected JLabel lblSurfaces = new JLabel("Surfaces:");
59
protected JTable table;
60
protected JScrollPane scrColumns;
62
protected LineLayout lineLayout;
64
protected int table_offset = 0;
66
public ShapeInputDialogBox(){
71
public ShapeInputDialogBox(JFrame frame, InterfaceIOPanel panel, InterfaceIOOptions options){
72
super(frame, panel, options);
73
ShapeInputOptions _options = (ShapeInputOptions)options;
74
if (_options.shape_set == null)
75
_options.shape_set = InterfaceSession.getDisplayPanel().getCurrentShapeSet();
80
protected void init(){
83
this.setDialogSize(570,400);
84
this.setTitle("Surface Input Options");
86
lineLayout = new LineLayout(InterfaceEnvironment.getLineHeight(), 5, 0);
87
this.setMainLayout(lineLayout);
91
LineLayoutConstraints c = new LineLayoutConstraints(1, 1, 0.05, 0.3, 1);
92
mainPanel.add(lblShapeSet, c);
93
c = new LineLayoutConstraints(1, 1, 0.35, 0.6, 1);
94
mainPanel.add(cmbShapeSet, c);
95
c = new LineLayoutConstraints(2, 2, 0.05, 0.9, 1);
96
mainPanel.add(lblSurfaces, c);
102
void updateShapeSets(){
104
if (!InterfaceSession.isInit()) return;
105
ShapeSet3DInt current_set = (ShapeSet3DInt)cmbShapeSet.getSelectedItem();
106
ShapeSet3DInt shape_set = new ShapeSet3DInt();
107
InterfaceSession.getWorkspace().populateShapeTypeCombo(cmbShapeSet, shape_set);
109
if (current_set != null)
110
cmbShapeSet.setSelectedItem(current_set);
114
public void showDialog(){
115
ShapeInputOptions _options = (ShapeInputOptions)options;
116
if (_options == null) _options = new ShapeInputOptions();
117
if (_options.shape_set == null)
118
_options.shape_set = InterfaceSession.getDisplayPanel().getCurrentShapeSet();
121
if (_options.shape_set != null)
122
cmbShapeSet.setSelectedItem(_options.shape_set);
128
protected void updateTable(){
130
if (options == null) return;
131
ShapeInputOptions _options = (ShapeInputOptions)options;
133
//header and new table model
134
if (scrColumns != null) mainPanel.remove(scrColumns);
136
if (_options.getFiles() == null){
137
lblSurfaces.setVisible(false);
141
lblSurfaces.setVisible(true);
143
Vector<String> v_files = new Vector<String>();
144
Vector<String> v_names = new Vector<String>();
146
File[] files = options.getFiles();
147
String[] names = _options.names;
149
for (int i = 0; i < files.length; i++){
150
v_files.add(files[i].getName());
151
v_names.add(names[i]);
154
Vector<Vector> values = new Vector<Vector>(files.length);
155
for (int i = 0; i < files.length; i++){
156
Vector v = new Vector(4);
157
v.add(v_names.get(i));
158
v.add(v_files.get(i));
162
Vector<String> header = new Vector<String>(4);
164
header.add("Filename");
166
TableModel model = new TableModel(values, header);
167
table = new JTable(model);
168
scrColumns = new JScrollPane(table);
169
table.getColumnModel().getColumn(0).setPreferredWidth(15);
171
LineLayoutConstraints c = new LineLayoutConstraints(4 + table_offset, 8 + table_offset, 0.05, 0.9, 1);
173
mainPanel.add(scrColumns, c);
174
lineLayout.setFlexibleComponent(scrColumns);
175
mainPanel.updateUI();
180
public void actionPerformed(ActionEvent e){
183
if (e.getActionCommand().equals(DLG_CMD_OK)){
185
ShapeInputOptions _options = (ShapeInputOptions)options;
192
for (int i = 0; i < table.getModel().getRowCount(); i++)
193
_options.names[i] = (String)table.getValueAt(i, 0);
195
_options.shape_set = (ShapeSet3DInt)cmbShapeSet.getSelectedItem();
201
super.actionPerformed(e);
205
protected class TableModel extends AbstractTableModel {
208
Vector<String> columns;
210
public TableModel(Vector<Vector> data, Vector<String> columns){
212
this.columns = columns;
215
public int getColumnCount() {
216
return columns.size();
219
public int getRowCount() {
224
public String getColumnName(int col) {
225
return columns.get(col);
228
public Object getValueAt(int row, int col) {
229
return data.get(row).get(col);
233
public Class getColumnClass(int c) {
234
return getValueAt(0, c).getClass();
238
* Column names not editable
241
public boolean isCellEditable(int row, int col) {
242
if (col == 1) return false;
247
public void setValueAt(Object value, int row, int col) {
248
data.get(row).set(col, value);
249
fireTableCellUpdated(row, col);