source: java/main/src/main/java/com/framsticks/gui/table/TableModel.java @ 101

Last change on this file since 101 was 101, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 4.1 KB
Line 
1package com.framsticks.gui.table;
2
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.List;
6
7import javax.swing.JCheckBox;
8import javax.swing.JComponent;
9import javax.swing.JTable;
10import javax.swing.UIManager;
11
12import org.apache.logging.log4j.Logger;
13import org.apache.logging.log4j.LogManager;
14
15import com.framsticks.params.Access;
16import com.framsticks.params.ListAccess;
17import com.framsticks.params.Param;
18import com.framsticks.params.PrimitiveParam;
19import com.framsticks.params.types.ProcedureParam;
20import com.framsticks.util.lang.Casting;
21
22public class TableModel extends AbstractTableModel {
23
24        private static final Logger log = LogManager.getLogger(TableModel.class);
25
26        protected ListAccess access;
27        protected Access elementAccess;
28        protected final List<Column> columns = new ArrayList<>();
29        protected final ListPanel listPanel;
30        protected JTable table;
31
32        /**
33         * @param listPanel
34         */
35        public TableModel(ListPanel listPanel) {
36                this.listPanel = listPanel;
37        }
38
39        /**
40         * @return the listPanel
41         */
42        public ListPanel getListPanel() {
43                return listPanel;
44        }
45
46        public JTable getTable() {
47                return listPanel.getTable();
48        }
49
50
51        /**
52         * @param table the table to set
53         */
54        public void setupTable() {
55                getTable().setDefaultRenderer(ProcedureParam.class, new ProcedureRenderer());
56                getTable().setDefaultEditor(ProcedureParam.class, new ProcedureEditor(new JCheckBox()));
57        }
58
59        public void attachSource(ListAccess access) {
60                this.access = Casting.assertCast(ListAccess.class, access.cloneAccess().select(access.getSelected()));
61
62                this.elementAccess = this.access.getElementAccess().cloneAccess();
63                log.debug("attached {}", access);
64                refreshAll();
65        }
66
67
68        @Override
69        public Class<?> getColumnClass(int columnIndex) {
70                // log.debug("returning column type {}", columnParams.get(columnIndex).getStorageType());
71                return columns.get(columnIndex).getColumnClass();
72        }
73
74        @Override
75        public int getColumnCount() {
76                // log.debug("returning column count {}", columnParams.size());
77                return columns.size();
78        }
79
80        @Override
81        public String getColumnName(int columnIndex) {
82                return columns.get(columnIndex).getParam().getName();
83        }
84
85        @Override
86        public int getRowCount() {
87                // log.debug("returning row count {}", access.getParamCount());
88                return access == null ? 0 : access.getParamCount();
89        }
90
91        @Override
92        public Object getValueAt(int rowIndex, int columnIndex) {
93                assert (rowIndex < access.getParamCount() && columnIndex < columns.size());
94
95                return columns.get(columnIndex).getValueAt(rowIndex);
96        }
97
98        @Override
99        public boolean isCellEditable(int rowIndex, int columnIndex) {
100                return columns.get(columnIndex).isEditable();
101        }
102
103
104
105        @Override
106        public void setValueAt(Object value, int rowIndex, int columnIndex) {
107                assert (rowIndex < access.getParamCount() && columnIndex < columns.size());
108                // Object object = getObjectAt(rowIndex, columnIndex);
109                // if (object == null) {
110                //      return;
111                // }
112                columns.get(columnIndex).setValueAt(rowIndex, value);
113        }
114
115        public void addColumn(Column column) {
116                log.debug("added {}", column);
117                columns.add(column);
118        }
119
120        /**
121         * @return the access
122         */
123        public ListAccess getAccess() {
124                return access;
125        }
126
127        /**
128         * @return the elementAccess
129         */
130        public Access getElementAccess() {
131                return elementAccess;
132        }
133
134        /**
135         * @return the columnParams
136         */
137        public List<Column> getColumns() {
138                return Collections.unmodifiableList(columns);
139        }
140
141
142        public boolean addColumnIfSupported(Param param) {
143                if (param instanceof PrimitiveParam) {
144                        addColumn(new PrimitiveColumn((PrimitiveParam<?>) param, this));
145                        return true;
146                }
147                if (param instanceof ProcedureParam) {
148                        if (((ProcedureParam) param).getArgumentsType().size() == 0) {
149                                addColumn(new ProcedureColumn((ProcedureParam) param, this));
150                                return true;
151                        }
152                        return false;
153                }
154                return false;
155        }
156
157        public static void transferCellAppeariance(JTable table, JComponent component, boolean isSelected) {
158                if (isSelected) {
159                        component.setForeground(table.getSelectionForeground());
160                        component.setBackground(table.getSelectionBackground());
161                } else {
162                        component.setForeground(table.getForeground());
163                        component.setBackground(UIManager.getColor("Button.background"));
164                }
165
166        }
167
168}
Note: See TracBrowser for help on using the repository browser.