Changeset 101 for java/main/src/main/java/com/framsticks/gui
- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- Location:
- java/main/src/main/java/com/framsticks/gui
- Files:
-
- 3 added
- 2 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/gui/Browser.java
r100 r101 1 1 package com.framsticks.gui; 2 2 3 import com.framsticks.communication.File; 4 import com.framsticks.communication.queries.NeedFile; 5 import com.framsticks.communication.queries.NeedFileAcceptor; 3 6 import com.framsticks.core.*; 4 7 import com.framsticks.gui.console.Console; … … 9 12 import com.framsticks.params.annotations.FramsClassAnnotation; 10 13 import com.framsticks.params.annotations.ParamAnnotation; 14 import com.framsticks.parsers.FileSource; 11 15 import com.framsticks.remote.RemoteTree; 12 16 import com.framsticks.util.FramsticksException; … … 22 26 23 27 import javax.swing.*; 28 import javax.swing.filechooser.FileNameExtensionFilter; 24 29 25 30 import org.apache.logging.log4j.Logger; … … 30 35 import java.awt.datatransfer.StringSelection; 31 36 import java.awt.event.ActionEvent; 37 import java.awt.event.ActionListener; 38 import java.awt.event.WindowAdapter; 39 import java.awt.event.WindowEvent; 40 import java.io.IOException; 32 41 import java.util.ArrayList; 33 42 import java.util.LinkedList; 34 43 import java.util.List; 44 import java.util.regex.Matcher; 45 import java.util.regex.Pattern; 46 35 47 import com.framsticks.util.dispatching.RunAt; 48 import com.framsticks.util.lang.Strings; 36 49 37 50 /** … … 132 145 } 133 146 147 protected static final Pattern extensionFilterPattern = Pattern.compile("\\*\\.(\\S+)"); 148 134 149 @AutoAppendAnnotation 135 public void addTree( Tree tree) {150 public void addTree(final Tree tree) { 136 151 log.debug("adding tree: {}", tree); 137 152 tree.setDispatcher(new SwingDispatcher<Tree>()); 138 153 tree.setExceptionHandler(this); 139 154 trees.add(tree); 155 156 final NeedFileAcceptor acceptor = new NeedFileAcceptor() { 157 158 protected boolean done = false; 159 160 @Override 161 public boolean acceptNeed(final NeedFile needFile) { 162 final JFileChooser chooser = new JFileChooser(); 163 final JFrame frame = new JFrame(); 164 165 frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 166 167 frame.addWindowListener(new WindowAdapter() { 168 @Override 169 public void windowClosing(WindowEvent e) { 170 if (!done) { 171 needFile.getFuture().handle(new FramsticksException().msg("user closed the window")); 172 } 173 frame.setVisible(false); 174 frame.dispose(); 175 } 176 }); 177 178 frame.setTitle(Strings.toStringEmptyProof(needFile.getDescription(), "Choose file")); 179 chooser.setMultiSelectionEnabled(false); 180 Matcher matcher = extensionFilterPattern.matcher(needFile.getSuggestedName()); 181 if (matcher.matches()) { 182 chooser.setFileFilter(new FileNameExtensionFilter(Strings.toStringEmptyProof(needFile.getDescription(), "file"), Strings.takeGroup(needFile.getSuggestedName(), matcher, 1).toString())); 183 } 184 185 frame.getContentPane().add(chooser); 186 187 chooser.addActionListener(new ActionListener() { 188 189 @Override 190 public void actionPerformed(ActionEvent event) { 191 if (event.getActionCommand().equals("CancelSelection")) { 192 needFile.getFuture().handle(new FramsticksException().msg("user cancelled choose")); 193 frame.setVisible(false); 194 frame.dispose(); 195 } 196 if (event.getActionCommand().equals("ApproveSelection")) { 197 File file = null; 198 String filename = chooser.getSelectedFile().getAbsolutePath(); 199 try { 200 file = new File("", new FileSource(filename)); 201 } catch (IOException e) { 202 needFile.getFuture().handle(new FramsticksException().msg("failed to open choosed file").arg("filename", filename).cause(e)); 203 } 204 if (file != null) { 205 done = true; 206 needFile.getFuture().pass(file); 207 } 208 frame.setVisible(false); 209 frame.dispose(); 210 } 211 } 212 }); 213 frame.setVisible(true); 214 return true; 215 } 216 }; 217 218 tree.dispatch(new RunAt<Tree>(this) { 219 @Override 220 protected void runAt() { 221 log.debug("adding need file acceptor: {}", acceptor); 222 tree.addNeedFileAcceptor(Integer.MAX_VALUE, acceptor); 223 } 224 }); 225 140 226 } 141 227 … … 143 229 // final Tree i = trees.get("localhost"); 144 230 // i.dispatch(new RunAt<Tree>(future) { 145 // 146 // 147 // 148 // 149 // 150 // 151 // 152 // 153 // 154 // 155 // 156 // 157 // 158 // 159 // 231 // @Override 232 // protected void runAt() { 233 // TreeOperations.tryGet(i, path, new FutureHandler<Path>(future) { 234 // @Override 235 // protected void result(final Path p) { 236 // future.pass(p); 237 // mainFrame.dispatch(new RunAt<Frame>(future) { 238 // @Override 239 // protected void runAt() { 240 // mainFrame.goTo(p); 241 // } 242 // }); 243 // } 244 // }); 245 // } 160 246 // }); 161 247 } … … 183 269 protected void runAt() { 184 270 final Path p = Path.to(i, "/"); 271 log.debug("adding path: {}", p); 185 272 dispatch(new RunAt<Browser>(this) { 186 273 @Override -
java/main/src/main/java/com/framsticks/gui/Frame.java
r100 r101 243 243 @Override 244 244 public void actionPerformed(ActionEvent actionEvent) { 245 interrupt ();245 interruptJoinable(); 246 246 } 247 247 }); … … 268 268 log.debug("trying mount: {}", path); 269 269 if (!tree.getAssignedRoot().isResolved()) { 270 log.debug("root not yet assigned, geting root"); 270 271 tree.get(path, new FutureHandler<Path>(this) { 271 272 -
java/main/src/main/java/com/framsticks/gui/FrameJoinable.java
r100 r101 31 31 */ 32 32 public FrameJoinable() { 33 statusBar = new StatusBar( );33 statusBar = new StatusBar(this); 34 34 } 35 35 … … 101 101 @Override 102 102 protected void runAt() { 103 finish ();103 finishJoinable(); 104 104 } 105 105 }); … … 135 135 public void windowClosing(WindowEvent e) { 136 136 log.info("received closing"); 137 interrupt ();137 interruptJoinable(); 138 138 } 139 139 }); -
java/main/src/main/java/com/framsticks/gui/Gui.java
r100 r101 7 7 import javax.swing.Box; 8 8 import javax.swing.BoxLayout; 9 import javax.swing.JComponent; 9 10 import javax.swing.JLabel; 10 11 import javax.swing.JPanel; 12 import javax.swing.border.TitledBorder; 11 13 12 14 import org.apache.logging.log4j.Logger; … … 24 26 import com.framsticks.params.CompositeParam; 25 27 import com.framsticks.params.Param; 28 import com.framsticks.params.ParamFlags; 26 29 import com.framsticks.params.PrimitiveParam; 27 30 import com.framsticks.params.types.BinaryParam; … … 101 104 } 102 105 103 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, Collection<P> params, Map<P, C> components, Class<C> controlType) {104 JPanel panel = owner.getPanelForControls();106 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, JPanel panel, Collection<P> params, Map<String, C> components, Class<C> controlType) { 107 panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); 105 108 for (P param : params) { 106 if (param. isUserHidden()) {109 if (param.hasFlag(ParamFlags.USERHIDDEN)) { 107 110 continue; 108 111 } … … 122 125 line.setLayout(new BoxLayout(line, BoxLayout.LINE_AXIS)); 123 126 line.setAlignmentX(JPanel.LEFT_ALIGNMENT); 124 JLabel label = new JLabel(Strings.notEmpty(param.getName()) ? param.getName() : (Strings.notEmpty(param.getId()) ? param.getId() : "?")); 125 label.setToolTipText(control.getToolTipText()); 126 label.setHorizontalAlignment(JLabel.RIGHT); 127 Dimension labelSize = new Dimension(150, 30); 128 label.setMaximumSize(labelSize); 129 label.setMinimumSize(labelSize); 130 label.setPreferredSize(labelSize); 131 line.add(label); 132 line.add(Box.createRigidArea(new Dimension(8, 0))); 127 133 128 line.add(control); 134 129 line.revalidate(); 135 130 panel.add(line); 136 131 panel.add(Box.createRigidArea(new Dimension(0, 8))); 132 components.put(param.getId(), control); 137 133 //component.setAlignmentX(LEFT_ALIGNMENT); 138 components.put(param, control);134 // components.put(param.getId(), control); 139 135 } 140 136 141 137 } 138 139 public static String getBestName(Param param) { 140 if (Strings.notEmpty(param.getName())) { 141 return param.getName(); 142 } 143 if (Strings.notEmpty(param.getId())) { 144 return param.getId(); 145 } 146 return "?"; 147 } 148 149 public static void setupTitledControl(Control control, JComponent... components) { 150 151 control.setLayout(new BoxLayout(control, BoxLayout.PAGE_AXIS)); 152 control.setBorder(new TitledBorder(Gui.getBestName(control.getParam()))); 153 for (JComponent c : components) { 154 // control.add(Box.createRigidArea(new Dimension(0, 4))); 155 control.add(c); 156 } 157 } 158 159 public static void layoutInRow(JPanel panel, JComponent first, JComponent... components) { 160 panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); 161 panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); 162 163 panel.add(first); 164 for (JComponent c : components) { 165 panel.add(Box.createRigidArea(new Dimension(8, 0))); 166 panel.add(c); 167 } 168 } 169 170 public static void addLeftToLabel(Control control, JComponent... components) { 171 172 JLabel label = new JLabel(getBestName(control.getParam())); 173 label.setToolTipText(control.getToolTipText()); 174 label.setHorizontalAlignment(JLabel.LEFT); 175 Dimension labelSize = new Dimension(150, 30); 176 label.setMaximumSize(labelSize); 177 label.setMinimumSize(labelSize); 178 label.setPreferredSize(labelSize); 179 180 layoutInRow(control, label, components); 181 182 } 142 183 } -
java/main/src/main/java/com/framsticks/gui/MainFrame.java
r100 r101 73 73 } 74 74 75 // private void onConnectionEstablished() {76 // assert isActive();77 78 // addNodeActionToTreePopupMenu("Open in console", new NodeAction() {79 // @Override80 // public void actionPerformed(TreeNode treeNode) {81 // assert isActive();82 // }83 // });84 85 86 87 88 // // browser.addNodeActionToTreePopupMenu("Resolve recursively", new NodeAction() {89 // // @Override90 // // public void actionPerformed(TreeNode treeNode) {91 // // final Child child = treeNode.getChild();92 // // //server.invokeLater(new Runnable() {93 // // @Override94 // // public void run() {95 // // resolveRecursively(child);96 // // }97 // // });98 // // }99 // // });100 101 102 // // addNodeActionToTreePopupMenu("Store in file", new NodeAction() {103 // // @Override104 // // public void actionPerformed(final TreeNode treeNode) {105 // // // final Node node = treeNode.getNode();106 // // // server.invokeLater(new Runnable() {107 // // // @Override108 // // // public void run() {109 // // // try {110 // // // log.info("storing");111 // // // //File file = new File();112 // // // StoreStream stream = new StoreStream(file, server.getManager());113 // // // stream.store(node);114 // // // } catch (FileNotFoundException e) {115 // // // e.printStackTrace();116 // // // }117 // // // }118 // // // });119 // // }120 // // });121 122 123 // // arguments.forEach("resolve", new UnaryFunctor<Boolean, String>() {124 // // @Override125 // // public Boolean call(final String s) {126 // // server.getManager().resolvePath(s, new StateFunctor() {127 // // @Override128 // // public void call(Exception e) {129 // // if (e != null) {130 // // log.error("failed to resolve: {}", s);131 // // return;132 // // }133 // // log.info("succeeded to resolve: {}", s);134 // // }135 // // });136 // // return true;137 // // }138 // // });139 140 141 // // arguments.forEach("console", new UnaryFunctor<Boolean, String>() {142 // // @Override143 // // public Boolean call(String s) {144 // // showConsoleFrame().setCommandLine(s);145 // // return true;146 // // }147 // // });148 // }149 150 151 // /**152 // * Creates panel with start, step, stop buttons.153 // */154 // @Override155 // protected JPanel createLeftTopPanel() {156 // assert isActive();157 // Dimension buttonDimension = new Dimension(45, 45);158 159 // JPanel panel = new JPanel();160 161 // stop = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STOP));162 // stop.addActionListener(new ActionListener() {163 164 // public void actionPerformed(ActionEvent e) {165 // setSimulationRunning(false);166 // }167 168 // });169 170 // stop.setPreferredSize(buttonDimension);171 // stop.setToolTipText("Simulation Stop");172 // stop.setEnabled(false);173 174 // step = new JButton(ImageProvider.loadImage(ImageProvider.SIM_STEP));175 // /*176 // step.addActionListener(new ActionListener() {177 178 // public void actionPerformed(ActionEvent e) {179 // connection.send(new CallQuery().setMethod("step").setPath("/simulator"));180 // }181 182 // });183 // */184 185 // step.setPreferredSize(buttonDimension);186 // step.setToolTipText("Simulation Step");187 188 // start = new JButton(ImageProvider.loadImage(ImageProvider.SIM_START));189 // start.addActionListener(new ActionListener() {190 191 // public void actionPerformed(ActionEvent e) {192 // setSimulationRunning(true);193 // }194 195 // });196 197 // start.setPreferredSize(buttonDimension);198 // start.setToolTipText("Start Simulation");199 200 // JPanel buttonPanel = new JPanel();201 // buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));202 // buttonPanel.add(Box.createHorizontalStrut(5));203 // buttonPanel.add(stop);204 // buttonPanel.add(Box.createHorizontalStrut(10));205 // buttonPanel.add(step);206 // buttonPanel.add(Box.createHorizontalStrut(10));207 // buttonPanel.add(start);208 // buttonPanel.add(Box.createHorizontalStrut(5));209 210 // buttonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory211 // .createRaisedBevelBorder(), "Simulation Control",212 // TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION213 // ));214 215 // panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));216 // panel.add(Box.createHorizontalGlue());217 // panel.add(buttonPanel);218 // panel.add(Box.createHorizontalGlue());219 // return panel;220 // }221 75 222 76 /** … … 248 102 } 249 103 250 // public ConsoleFrame showConsoleFrame() {251 // assert isActive();252 // /*253 // ConsoleFrame consoleFrame = new ConsoleFrame(connection);254 // consoleFrame.show(MainFrame.this);255 // return consoleFrame;256 // */257 // return null;258 // }259 260 104 /** 261 105 * Closes connection with manager. -
java/main/src/main/java/com/framsticks/gui/ModifiablePanel.java
r100 r101 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.ActionListener; 11 import static com.framsticks.core.TreeOperations.*; 11 12 12 13 /** … … 24 25 protected final JLabel label; 25 26 protected final JButton applyButton; 27 protected final JButton revertButton; 26 28 protected final JPanel centerPanel; 27 29 … … 32 34 log.debug("create panel for type: {}", className); 33 35 34 35 36 36 JPanel pageEndPanel = new JPanel(); 37 37 pageEndPanel.setLayout(new BoxLayout(pageEndPanel, BoxLayout.X_AXIS)); … … 41 41 applyButton.setName("apply"); 42 42 43 revertButton = new JButton("Revert"); 44 revertButton.setName("revert"); 45 46 pageEndPanel.add(applyButton); 47 pageEndPanel.add(Box.createHorizontalStrut(10)); 48 49 pageEndPanel.add(revertButton); 50 pageEndPanel.add(Box.createHorizontalStrut(10)); 51 52 pageEndPanel.setPreferredSize(new Dimension(0, 30)); 53 43 54 applyButton.addActionListener(new ActionListener() { 44 55 public void actionPerformed(ActionEvent e) { … … 46 57 } 47 58 }); 48 pageEndPanel.add(applyButton);49 59 50 pageEndPanel.add(Box.createHorizontalStrut(10)); 51 pageEndPanel.setPreferredSize(new Dimension(0, 30)); 60 revertButton.addActionListener(new ActionListener() { 61 public void actionPerformed(ActionEvent e) { 62 revertChanges(); 63 } 64 }); 52 65 53 66 label = new JLabel(); … … 67 80 68 81 protected abstract void applyChanges(); 82 protected abstract void revertChanges(); 69 83 70 84 protected void setupContentComponent(Component contentComponent) { … … 73 87 } 74 88 89 protected void refreshControlButtons() { 90 assert frame.isActive(); 91 boolean hasChanges = hasSideNotes(getTree(), getCurrentObject(), treeAtFrame.getUserChangesKey()); 92 applyButton.setEnabled(hasChanges); 93 revertButton.setEnabled(hasChanges); 94 } 95 75 96 } -
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r100 r101 5 5 import com.framsticks.gui.controls.ControlOwner; 6 6 import com.framsticks.gui.controls.ValueControl; 7 import com.framsticks.gui.controls.ValueControlListener;8 7 import com.framsticks.params.Access; 9 8 import com.framsticks.params.Param; 10 import com.framsticks.params.ValueParam;11 9 12 10 import org.apache.logging.log4j.Logger; … … 16 14 17 15 import java.util.Collection; 18 import java.util. IdentityHashMap;16 import java.util.HashMap; 19 17 import java.util.Map; 20 18 import static com.framsticks.util.lang.Containers.filterInstanceof; 21 19 22 20 import com.framsticks.util.FramsticksException; 21 22 import static com.framsticks.core.TreeOperations.*; 23 23 24 24 @SuppressWarnings("serial") … … 27 27 private static final Logger log = LogManager.getLogger(ObjectPanel.class); 28 28 29 final protected Map< Param, Control> components = new IdentityHashMap<Param, Control>();30 final protected Map< ValueParam, ValueControl> valueControls = new IdentityHashMap<ValueParam, ValueControl>();29 final protected Map<String, Control> controls = new HashMap<String, Control>(); 30 final protected Map<String, ValueControl> valueControls = new HashMap<String, ValueControl>(); 31 31 32 32 protected final JPanel contentPanel; … … 38 38 contentPanel = new JPanel(); 39 39 scrollPane = new JScrollPane(contentPanel); 40 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); 40 41 41 setupContentComponent(scrollPane); 42 42 43 Gui.fillWithControls(this, params, components, Control.class);43 Gui.fillWithControls(this, contentPanel, params, controls, Control.class); 44 44 setName(framsClass.getId()); 45 45 46 for (final ValueControl c : filterInstanceof(co mponents.values(), ValueControl.class)) {47 valueControls.put(c.getParam() , c);46 for (final ValueControl c : filterInstanceof(controls.values(), ValueControl.class)) { 47 valueControls.put(c.getParam().getId(), c); 48 48 c.setUserEnabled(true); 49 c.setListener(new ValueControlListener() {50 @Override51 public boolean onChange(Object newValue) {52 if (currentPath == null) {53 return true;54 }55 boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), c, newValue);56 refreshControlButtons();57 return result;58 }59 });60 49 } 61 50 … … 68 57 assert frame.isActive(); 69 58 assert currentPath != null; 70 treeAtFrame.pushLocalChanges(currentPath); 59 treeAtFrame.pushUserChangesToTree(currentPath); 60 refreshControlButtons(); 71 61 } 72 62 73 protected void refreshControlButtons() { 74 assert frame.isActive(); 75 applyButton.setEnabled(treeAtFrame.hasLocalChanges(currentPath.getTopObject())); 63 64 @Override 65 protected void revertChanges() { 66 assert currentPath != null; 67 removeSideNote(currentPath, treeAtFrame.getUserChangesKey()); 68 pullValuesFromLocalToUser(bindAccess(currentPath)); 76 69 } 77 70 … … 81 74 log.debug("refreshing components"); 82 75 83 final Map<ValueControl, Object> values = new IdentityHashMap<ValueControl, Object>(); 84 for (Map.Entry<ValueParam, ValueControl> e : valueControls.entrySet()) { 85 values.put(e.getValue(), access.get(e.getKey().getId(), Object.class)); 76 UserChanges userChanges = getSideNote(currentPath, treeAtFrame.getUserChangesKey()); 77 78 79 for (Map.Entry<String, ValueControl> e : valueControls.entrySet()) { 80 String id = e.getKey(); 81 Object value; 82 if (userChanges != null && userChanges.changes.containsKey(id)) { 83 value = userChanges.changes.get(id); 84 } else { 85 value = access.get(id, Object.class); 86 } 87 88 e.getValue().pushValueToUserInterface(value); 86 89 } 87 90 88 89 NodeAtFrame nodeAtFrame = treeAtFrame.getLocalInfo(currentPath.getTopObject()); 90 if (nodeAtFrame != null) { 91 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 92 values.put(e.getKey(), e.getValue()); 93 } 91 for (Map.Entry<String, Control> e : controls.entrySet()) { 92 e.getValue().refreshState(); 94 93 } 95 94 96 for (Map.Entry<ValueControl, Object> e : values.entrySet()) {97 e.getKey().pushValueToUserInterface(e.getValue());98 }99 95 refreshControlButtons(); 100 ObjectPanel.this.revalidate(); 101 96 // ObjectPanel.this.revalidate(); 102 97 } 103 98 … … 105 100 public String getTitle() { 106 101 return "Properties"; 107 }108 109 @Override110 public JPanel getPanelForControls() {111 return contentPanel;112 102 } 113 103 … … 122 112 } 123 113 114 @Override 115 public boolean onValueChange(ValueControl control, Object newValue) { 116 if (currentPath == null) { 117 return true; 118 } 119 boolean result = treeAtFrame.changeValue(currentPath.assureResolved().getTopObject(), control, newValue); 120 refreshControlButtons(); 121 return result; 122 } 123 124 124 } -
java/main/src/main/java/com/framsticks/gui/StatusBar.java
r100 r101 15 15 import com.framsticks.util.FramsticksException; 16 16 import com.framsticks.util.dispatching.Dispatcher; 17 import com.framsticks.util.dispatching.Dispatching; 17 18 import com.framsticks.util.dispatching.ExceptionResultHandler; 18 19 import com.framsticks.util.dispatching.RunAt; 19 20 20 public class StatusBar implements ExceptionResultHandler , Dispatcher<StatusBar>{21 public class StatusBar implements ExceptionResultHandler { 21 22 private static final Logger log = LogManager.getLogger(StatusBar.class); 22 23 … … 24 25 protected JPanel swing; 25 26 protected ExceptionResultHandler exceptionHandler; 27 protected final Dispatcher<?> dispatcher; 26 28 27 29 /** 28 30 * 29 31 */ 30 public StatusBar() { 32 public StatusBar(Dispatcher<?> dispatcher) { 33 this.dispatcher = dispatcher; 34 } 35 36 @SuppressWarnings({"rawtypes", "unchecked"}) 37 public void showInfo(final Object value) { 38 Dispatching.dispatchIfNotActive(dispatcher, new RunAt(this) { 39 40 @Override 41 protected void runAt() { 42 String text = value.toString(); 43 log.info("info: {}", text); 44 statusBar.setText(text); 45 46 } 47 }); 31 48 } 32 49 33 50 @Override 51 @SuppressWarnings({"rawtypes", "unchecked"}) 34 52 public void handle(final FramsticksException exception) { 35 dispatch (new RunAt<StatusBar>(this) {53 dispatcher.dispatch(new RunAt(this) { 36 54 37 55 @Override … … 58 76 } 59 77 60 @Override61 public boolean isActive() {62 return SwingDispatcher.getInstance().isActive();63 }64 65 @Override66 public void dispatch(RunAt<? extends StatusBar> runnable) {67 SwingDispatcher.getInstance().dispatch(runnable);68 }69 70 78 /** 71 79 * @return the swing -
java/main/src/main/java/com/framsticks/gui/SwingDispatcher.java
r98 r101 1 1 package com.framsticks.gui; 2 2 3 import java.awt.event.ActionEvent;4 import java.awt.event.ActionListener;5 3 6 4 import com.framsticks.util.dispatching.AbstractJoinable; 7 5 import com.framsticks.util.dispatching.Dispatcher; 8 import com.framsticks.util.dispatching.JoinableDispatcher;9 import com.framsticks.util.dispatching.Task;10 6 import com.framsticks.util.dispatching.ThrowExceptionHandler; 11 7 … … 16 12 * @author Piotr Sniegowski 17 13 */ 18 public class SwingDispatcher<C> extends AbstractJoinable implements JoinableDispatcher<C> {14 public class SwingDispatcher<C> extends AbstractJoinable implements Dispatcher<C> { 19 15 20 16 @SuppressWarnings("rawtypes") … … 42 38 @Override 43 39 public final void dispatch(RunAt<? extends C> runnable) { 44 if (runnable instanceof Task) {45 final Task<?> task = (Task<?>) runnable;46 Timer timer = new Timer(0, null);47 timer.addActionListener(new ActionListener() {48 49 @Override50 public void actionPerformed(ActionEvent event) {51 task.run();52 }53 54 });55 timer.setInitialDelay((int) (task.getMoment() - System.currentTimeMillis()));56 timer.setRepeats(false);57 timer.start();58 return;59 }60 40 SwingUtilities.invokeLater(runnable); 61 41 } … … 73 53 @Override 74 54 protected void joinableInterrupt() { 75 finish ();55 finishJoinable(); 76 56 } 77 57 -
java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java
r100 r101 4 4 import org.apache.logging.log4j.LogManager; 5 5 6 import com.framsticks.core.SideNoteKey; 6 7 import com.framsticks.core.Tree; 7 8 import com.framsticks.core.Node; 8 9 import com.framsticks.core.Path; 9 import com.framsticks.core.TreeOperations;10 import static com.framsticks.core.TreeOperations.*; 10 11 import com.framsticks.gui.controls.ValueControl; 11 12 import com.framsticks.params.CompositeParam; 12 13 import com.framsticks.params.FramsClass; 14 import com.framsticks.params.PrimitiveParam; 13 15 14 16 import java.util.*; … … 30 32 protected Node rootNode; 31 33 34 protected final SideNoteKey<UserChanges> userChangesKey = SideNoteKey.make(UserChanges.class); 35 32 36 public TreeAtFrame(Tree tree, Frame frame) { 33 37 this.frame = frame; … … 44 48 public Tree getTree() { 45 49 return tree; 50 } 51 52 /** 53 * @return the userChangesKey 54 */ 55 public SideNoteKey<UserChanges> getUserChangesKey() { 56 return userChangesKey; 46 57 } 47 58 … … 71 82 if (panels.isEmpty()) { 72 83 panel = new EmptyTreePanel(parameters); 73 } else 84 } else if (panels.size() == 1) { 74 85 panel = panels.get(0); 75 86 } else { … … 83 94 } 84 95 85 86 public boolean hasLocalChanges(Object object) {87 NodeAtFrame nodeAtFrame = tree.getSideNote(object, this, NodeAtFrame.class);88 if (nodeAtFrame == null) {89 return false;90 }91 return !nodeAtFrame.localChanges.isEmpty();92 }93 94 public NodeAtFrame assureLocalInfo(Object object) {95 assert frame.isActive();96 NodeAtFrame nodeAtFrame = tree.getSideNote(object, this, NodeAtFrame.class);97 98 if (nodeAtFrame == null) {99 nodeAtFrame = new NodeAtFrame();100 // log.debug();101 tree.putSideNote(object, this, nodeAtFrame);102 }103 return nodeAtFrame;104 }105 106 public NodeAtFrame getLocalInfo(Object object) {107 return tree.getSideNote(object, this, NodeAtFrame.class);108 }109 110 96 public boolean changeValue(Object object, ValueControl component, Object newValue) { 111 97 log.debug("changing value of {} to '{}'", component, newValue); 112 98 113 assureLocalInfo(object).localChanges.put(component, newValue);99 getOrCreateSideNote(tree, object, userChangesKey).changes.put(component.getParam().getId(), newValue); 114 100 115 101 return true; 116 102 } 117 103 118 public void pushLocalChanges(Path path) { 104 105 public void pushUserChangesToTree(final Path path) { 119 106 assert frame.isActive(); 120 107 path.assureResolved(); 121 108 122 NodeAtFrame nodeAtFrame = getLocalInfo(path.getTopObject());123 if ( nodeAtFrame== null) {109 final UserChanges userChanges = getSideNote(path, userChangesKey); 110 if (userChanges == null) { 124 111 return; 125 112 } 126 for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) { 127 TreeOperations.set(path, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(frame) { 113 removeSideNote(path, userChangesKey); 114 115 for (final Map.Entry<String, Object> e : userChanges.changes.entrySet()) { 116 set(path, getParam(path, e.getKey(), PrimitiveParam.class), e.getValue(), new FutureHandler<Integer>(frame) { 128 117 @Override 129 118 protected void result(Integer flag) { 119 assert frame.isActive(); 120 userChanges.changes.remove(e.getKey()); 130 121 } 131 122 }); -
java/main/src/main/java/com/framsticks/gui/TreePanel.java
r100 r101 2 2 3 3 import com.framsticks.core.Path; 4 import com.framsticks.core.TreeOperations; 4 import com.framsticks.core.Tree; 5 import static com.framsticks.core.TreeOperations.*; 5 6 import com.framsticks.gui.tree.AbstractNode; 6 7 import com.framsticks.gui.tree.TreeNode; … … 28 29 } 29 30 setCurrentPath(path); 30 pullValuesFromLocalToUser( TreeOperations.bindAccess(path));31 pullValuesFromLocalToUser(bindAccess(path)); 31 32 } 32 33 … … 79 80 return treeAtFrame; 80 81 } 81 82 public final Object getCurrentObject() { 83 assert currentPath != null; 84 return currentPath.getTopObject(); 85 } 86 public final Tree getTree() { 87 assert currentPath != null; 88 return currentPath.getTree(); 89 } 82 90 83 91 public final String getClassName() { -
java/main/src/main/java/com/framsticks/gui/controls/CheckBoxControl.java
r100 r101 10 10 import org.apache.logging.log4j.LogManager; 11 11 12 import com.framsticks.gui.Gui; 12 13 import com.framsticks.params.types.BooleanParam; 13 14 … … 31 32 }); 32 33 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); 33 addAsOnlyChild(checkBox);34 Gui.addLeftToLabel(this, checkBox); 34 35 } 35 36 -
java/main/src/main/java/com/framsticks/gui/controls/Control.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import java.awt.BorderLayout;3 // import java.awt.BorderLayout; 4 4 5 import javax.swing.JComponent; 5 6 6 import javax.swing.JPanel; 7 7 8 import com.framsticks.core.Path; 8 9 import com.framsticks.params.ParamFlags; 9 10 import com.framsticks.params.Param; 10 11 import com.framsticks.util.FramsticksException; 12 import com.framsticks.util.Misc; 11 13 import com.framsticks.util.dispatching.ExceptionResultHandler; 12 14 … … 57 59 58 60 public final boolean isReadonly() { 59 return !userEnabled || param.hasFlag(ParamFlags.READONLY) ;61 return !userEnabled || param.hasFlag(ParamFlags.READONLY) || param.hasFlag(ParamFlags.USERREADONLY); 60 62 } 61 63 62 protected void addAsOnlyChild(JComponent component) {63 this.setLayout(new BorderLayout());64 this.add(component, BorderLayout.CENTER);65 }66 64 67 65 @Override … … 74 72 owner.handle(exception); 75 73 } 74 75 public Path getCurrentPath() { 76 return owner.getCurrentPath(); 77 } 78 79 public Path assureCurrentPath() { 80 return Misc.throwIfNull(owner.getCurrentPath()); 81 } 82 83 public void refreshState() { 84 } 76 85 } -
java/main/src/main/java/com/framsticks/gui/controls/ControlOwner.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import javax.swing.JPanel;4 3 5 4 import com.framsticks.core.Path; … … 9 8 public interface ControlOwner extends ExceptionResultHandler { 10 9 11 public JPanel getPanelForControls();12 10 public Path getCurrentPath(); 13 11 public Frame getFrame(); 12 public boolean onValueChange(ValueControl control, Object newValue); 14 13 15 14 } -
java/main/src/main/java/com/framsticks/gui/controls/EnumControl.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.gui.Gui; 3 4 import com.framsticks.params.types.EnumParam; 4 5 import com.framsticks.util.lang.Numbers; … … 35 36 } 36 37 }); 37 addAsOnlyChild(list);38 Gui.addLeftToLabel(this, list); 38 39 } 39 40 -
java/main/src/main/java/com/framsticks/gui/controls/EventControl.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import java.awt.Dimension;4 3 import java.awt.event.ActionEvent; 5 4 import java.awt.event.ActionListener; 6 7 import javax.swing.JButton; 8 5 import java.text.SimpleDateFormat; 6 import java.util.ArrayList; 7 import java.util.Date; 8 import java.util.List; 9 10 11 12 import com.framsticks.core.Path; 13 import com.framsticks.core.SideNoteKey; 14 import com.framsticks.gui.Frame; 15 import com.framsticks.gui.Gui; 16 import com.framsticks.gui.table.AbstractTableModel; 17 import com.framsticks.params.EventListener; 9 18 import com.framsticks.params.types.EventParam; 19 import com.framsticks.util.FramsticksUnsupportedOperationException; 20 import com.framsticks.util.dispatching.Dispatching; 21 import com.framsticks.util.dispatching.FutureHandler; 22 import com.framsticks.util.dispatching.RunAt; 23 import com.framsticks.util.lang.Pair; 24 25 import static com.framsticks.core.TreeOperations.*; 10 26 11 27 /** … … 13 29 */ 14 30 @SuppressWarnings("serial") 15 public class EventControl extends Control {31 public class EventControl extends HistoryControl { 16 32 // private static final Logger log = LogManager.getLogger(EventControl.class.getName()); 17 33 18 protected final JButton button; 19 boolean subscribed = true; 34 @SuppressWarnings("rawtypes") 35 protected final SideNoteKey<EventListener> listenerKey = SideNoteKey.make(EventListener.class); 36 37 public static class History { 38 protected final List<Pair<Date, Object>> entries = new ArrayList<>(); 39 }; 40 41 protected final SideNoteKey<History> historyKey = SideNoteKey.make(History.class); 42 protected TableModel tableModel; 20 43 21 44 public EventControl(final EventParam eventParam) { 22 45 super(eventParam); 23 46 24 button = new JButton("subscribe"); 25 this.add(button); 26 this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); 27 28 button.addActionListener(new ActionListener() { 47 mainButton.setText("Subscribe"); 48 mainButton.setName("subscription"); 49 50 tableModel = new TableModel(); 51 resultsTable.setModel(tableModel); 52 53 mainButton.addActionListener(new ActionListener() { 29 54 @Override 30 55 public void actionPerformed(ActionEvent e) { 31 if (subscribed) { 32 //panel.getCurrentTreeNode().unsubscribe(eventParam); 33 } else { 34 //panel.getCurrentTreeNode().subscribe(eventParam); 56 final Path path = assureCurrentPath(); 57 EventListener<?> listener = getSideNote(path, listenerKey); 58 if (listener != null) { 59 removeSideNote(path, listenerKey); 60 refreshState(); 61 path.getTree().removeListener(path, getParam(), listener, FutureHandler.doNothing(Void.class, owner.getFrame())); 62 return; 35 63 } 64 65 final EventListener<Object> newListener = new EventListener<Object>() { 66 @Override 67 public void action(final Object argument) { 68 /** actions can be invoked from anywhere */ 69 Dispatching.dispatchIfNotActive(owner.getFrame(), new RunAt<Frame>(owner.getFrame()) { 70 71 @Override 72 protected void runAt() { 73 getOrCreateSideNote(path.getTree(), path.getTopObject(), historyKey).entries.add(Pair.make(new Date(), argument)); 74 refreshTable(); 75 } 76 }); 77 // owner.getFrame().getStatusBar().showInfo("event " + param + " happened: " + argument); 78 } 79 }; 80 81 path.getTree().addListener(path, getParam(), newListener, Object.class, new FutureHandler<Void>(owner.getFrame()) { 82 83 @Override 84 protected void result(Void result) { 85 putSideNote(path, listenerKey, newListener); 86 refreshState(); 87 } 88 }); 89 36 90 } 37 91 }); 38 92 93 updateFoldState(); 94 Gui.setupTitledControl(this, controlRow, resultsScrollPane); 39 95 } 40 96 41 97 @Override 42 98 protected void updateEnabled(boolean enabled) { 43 button.setEnabled(enabled); 44 } 45 46 /* 47 @Override 48 public void refresh() { 49 subscribed = panel.getCurrentTreeNode().hasSubscribed((EventParam)param); 50 button.setText(subscribed ? "unsubscribe" : "subscribe"); 51 this.revalidate(); 52 } 53 */ 99 mainButton.setEnabled(enabled); 100 } 101 102 public boolean isListening() { 103 return hasSideNote(getCurrentPath(), listenerKey); 104 } 105 106 protected void refreshButtonState() { 107 mainButton.setText(isListening() ? "Don't listen" : "Listen"); 108 } 109 110 @Override 111 protected void refreshTable() { 112 History history = getSideNote(assureCurrentPath(), historyKey); 113 tableModel.entries = history != null ? history.entries : null; 114 tableModel.refreshAll(); 115 } 116 117 @Override 118 protected void clearTable() { 119 History history = getSideNote(assureCurrentPath(), historyKey); 120 if (history != null) { 121 history.entries.clear(); 122 } 123 refreshTable(); 124 } 125 126 public void refreshState() { 127 refreshButtonState(); 128 refreshTable(); 129 } 130 131 @Override 132 public EventParam getParam() { 133 return (EventParam) param; 134 } 135 136 137 public class TableModel extends AbstractTableModel { 138 139 List<Pair<Date, Object>> entries; 140 SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss:SSS"); 141 142 @Override 143 public Class<?> getColumnClass(int columnIndex) { 144 return String.class; 145 } 146 147 @Override 148 public int getColumnCount() { 149 return 2; 150 } 151 152 @Override 153 public String getColumnName(int columnIndex) { 154 return columnIndex == 0 ? "Occured at" : "Argument"; 155 } 156 157 @Override 158 public int getRowCount() { 159 if (entries == null) { 160 return 0; 161 } 162 if (isFolded()) { 163 return entries.isEmpty() ? 0 : 1; 164 } 165 return entries.size(); 166 } 167 168 @Override 169 public Object getValueAt(int rowIndex, int columnIndex) { 170 if (entries == null) { 171 return null; 172 } 173 Pair<Date, Object> entry; 174 if (isFolded()) { 175 if (rowIndex > 0) { 176 return null; 177 } 178 if (entries.isEmpty()) { 179 return null; 180 } 181 entry = entries.get(entries.size() - 1); 182 } else { 183 entry = entries.get(rowIndex); 184 } 185 return columnIndex == 0 ? format.format(entry.first) : entry.second; 186 } 187 188 @Override 189 public boolean isCellEditable(int rowIndex, int columnIndex) { 190 return false; 191 } 192 193 @Override 194 public void setValueAt(Object value, int rowIndex, int columnIndex) { 195 throw new FramsticksUnsupportedOperationException().msg("setting value in event history"); 196 } 197 198 199 } 54 200 } -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r100 r101 5 5 import com.framsticks.gui.Gui; 6 6 import com.framsticks.params.Param; 7 import com.framsticks.params.ValueParam;8 7 import com.framsticks.params.types.ProcedureParam; 9 8 import com.framsticks.util.dispatching.ExceptionResultHandler; 10 9 import com.framsticks.util.dispatching.FutureHandler; 11 10 import com.framsticks.util.dispatching.ThrowExceptionHandler; 12 import com.framsticks.util.swing.TooltipConstructor;13 11 14 12 import javax.swing.*; 15 import javax.swing.border.BevelBorder;16 13 17 14 import org.apache.logging.log4j.Logger; … … 20 17 import java.awt.event.ActionEvent; 21 18 import java.awt.event.ActionListener; 22 import java.util. IdentityHashMap;19 import java.util.HashMap; 23 20 import java.util.LinkedList; 24 21 import java.util.List; … … 26 23 27 24 @SuppressWarnings("serial") 28 public class ProcedureControl extends Control implements ControlOwner {25 public class ProcedureControl extends HistoryControl implements ControlOwner { 29 26 30 27 private static final Logger log = LogManager.getLogger(ProcedureControl.class); 31 28 32 protected final J Button procedureButton;29 protected final JPanel argumentsPanel; 33 30 34 final protected Map< ValueParam, ValueControl> components = new IdentityHashMap<>();31 final protected Map<String, ValueControl> components = new HashMap<>(); 35 32 36 33 public ProcedureControl(ProcedureParam procedureParam) { 37 34 super(procedureParam); 38 35 39 this.setToolTipText(new TooltipConstructor()40 .append("name", procedureParam.getName())41 .append("id", procedureParam.getId())42 .append("help", procedureParam.getHelp())43 .build());44 36 45 procedureButton = new JButton("Call");46 procedureButton.setName("call");37 mainButton.setText("Call"); 38 mainButton.setName("call"); 47 39 48 this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));49 40 50 Gui.fillWithControls(this, procedureParam.getArgumentsType(), components, ValueControl.class); 41 argumentsPanel = new JPanel(); 42 argumentsPanel.setName("arguments"); 43 44 Gui.fillWithControls(this, argumentsPanel, procedureParam.getArgumentsType(), components, ValueControl.class); 51 45 52 46 if (components.size() != procedureParam.getArgumentsType().size()) { 53 procedureButton.setEnabled(false); 54 } 55 if (!components.isEmpty()) { 56 this.setBorder(new BevelBorder(BevelBorder.RAISED)); 47 mainButton.setEnabled(false); 57 48 } 58 49 59 procedureButton.addActionListener(new ActionListener() {50 mainButton.addActionListener(new ActionListener() { 60 51 @Override 61 52 public void actionPerformed(ActionEvent e) { … … 65 56 final List<Object> arguments = new LinkedList<Object>(); 66 57 for (Param arg : getParam().getArgumentsType()) { 67 Object value = components.get(arg ).getCurrentValue();58 Object value = components.get(arg.getId()).getCurrentValue(); 68 59 arguments.add(value); 69 60 log.debug("argument {}: {}", arg, value); … … 74 65 } 75 66 }); 76 this.add(procedureButton); 67 68 updateFoldState(); 69 Gui.setupTitledControl(this, argumentsPanel, controlRow, resultsScrollPane); 77 70 78 71 } 72 79 73 80 74 public static void callProcedure(final Path path, final ProcedureParam param, Object[] arguments) { … … 93 87 94 88 @Override 95 public JPanel getPanelForControls() {96 return this;97 }98 99 @Override100 89 public ProcedureParam getParam() { 101 90 return (ProcedureParam) param; … … 104 93 @Override 105 94 protected void updateEnabled(boolean enabled) { 106 procedureButton.setEnabled(enabled);95 mainButton.setEnabled(enabled); 107 96 for (ValueControl vc : components.values()) { 108 97 vc.setUserEnabled(enabled); … … 120 109 } 121 110 111 @Override 112 public boolean onValueChange(ValueControl control, Object newValue) { 113 return true; 114 } 115 116 @Override 117 protected void refreshTable() { 118 // TODO Auto-generated method stub 119 120 } 121 122 @Override 123 protected void clearTable() { 124 // TODO Auto-generated method stub 125 126 } 127 122 128 } -
java/main/src/main/java/com/framsticks/gui/controls/SliderControl.java
r100 r101 18 18 import org.apache.logging.log4j.LogManager; 19 19 20 import com.framsticks.gui.Gui; 20 21 import com.framsticks.params.types.DecimalParam; 21 22 import com.framsticks.params.types.FloatParam; … … 98 99 slider.setPaintTicks(true); 99 100 100 this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); 101 this.setAlignmentX(Box.CENTER_ALIGNMENT); 102 this.setAlignmentY(Box.CENTER_ALIGNMENT); 103 104 JPanel sliderPanel = new JPanel(); 105 // sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.LINE_AXIS)); 101 106 102 107 103 … … 140 136 })); 141 137 142 JPanel sVPanel = new JPanel(); 143 sVPanel.setLayout(new BoxLayout(sVPanel, BoxLayout.LINE_AXIS)); 144 sVPanel.add(text); 145 Layout.copyComponentDimensions(sVPanel, text); 146 147 JPanel sPanel = new JPanel(); 148 sPanel.setLayout(new BoxLayout(sPanel, BoxLayout.LINE_AXIS)); 149 138 JPanel valuePanel = new JPanel(); 139 valuePanel.setLayout(new BoxLayout(valuePanel, BoxLayout.LINE_AXIS)); 140 valuePanel.add(text); 141 Layout.copyComponentDimensions(valuePanel, text); 142 143 144 JPanel sliderPanel = new JPanel(); 150 145 sliderPanel.setLayout(new BorderLayout()); 151 146 sliderPanel.add(slider, BorderLayout.CENTER); … … 153 148 sliderPanel.setMinimumSize(new Dimension(0, 60)); 154 149 155 sPanel.add(sVPanel); 156 sPanel.add(sliderPanel); 157 158 this.add(sPanel); 150 151 this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); 152 this.setAlignmentX(Box.CENTER_ALIGNMENT); 153 this.setAlignmentY(Box.CENTER_ALIGNMENT); 154 155 Gui.addLeftToLabel(this, valuePanel, sliderPanel); 159 156 } 160 157 -
java/main/src/main/java/com/framsticks/gui/controls/TextAreaControl.java
r100 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.gui.Gui; 3 4 import com.framsticks.params.PrimitiveParam; 4 5 … … 27 28 textArea.setMaximumSize(new Dimension(Integer.MAX_VALUE, maxSize)); 28 29 29 this.revalidate(); 30 Gui.setupTitledControl(this, textScrollPane); 31 // this.revalidate(); 30 32 } 31 33 -
java/main/src/main/java/com/framsticks/gui/controls/TextFieldControl.java
r98 r101 1 1 package com.framsticks.gui.controls; 2 2 3 import com.framsticks.gui.Gui; 3 4 import com.framsticks.params.PrimitiveParam; 4 5 import com.framsticks.util.lang.Strings; … … 33 34 addDefaultDocumentListener(textField); 34 35 35 addAsOnlyChild(textField);36 Gui.addLeftToLabel(this, textField); 36 37 } 37 38 -
java/main/src/main/java/com/framsticks/gui/controls/ValueControl.java
r100 r101 12 12 import com.framsticks.util.lang.FlagsUtil; 13 13 import com.framsticks.util.swing.TooltipConstructor; 14 // import static com.framsticks.core.TreeOperations.*; 14 15 15 16 /** … … 20 21 private static final Logger log = 21 22 LogManager.getLogger(ValueControl.class); 22 23 /**24 *25 */26 protected ValueControlListener listener;27 23 28 24 public ValueControl(PrimitiveParam<?> primitiveParam) { … … 64 60 public abstract Object pullValueFromUserInterface(); 65 61 66 public void setListener(ValueControlListener listener) {67 this.listener = listener;68 }69 70 62 protected Object filterValueThroughConstraints(Object candidate) { 71 Object oldValue = pullValueFromUserInterface(); 63 Object oldValue = pullValueFromUserInterface();//bindAccess(owner.getCurrentPath()).get(getParam(), Object.class); 72 64 try { 73 65 ReassignResult<?> res = getParam().reassign(candidate, oldValue); … … 92 84 protected boolean notifyOfChange() { 93 85 if (!programmaticChange) { 94 if (listener == null) { 95 return true; 96 } 97 return listener.onChange(getCurrentValue()); 86 return owner.onValueChange(this, getCurrentValue()); 98 87 } 99 88 return true; -
java/main/src/main/java/com/framsticks/gui/table/ListPanel.java
r100 r101 54 54 table = new JTable(tableModel); 55 55 tableModel.setupTable(); 56 table.setShowGrid(false); 56 57 57 58 scrollPane = new JScrollPane(table); … … 72 73 73 74 @Override 75 protected void revertChanges() { 76 } 77 78 @Override 74 79 public void pullValuesFromLocalToUser(Access access) { 75 80 tableModel.attachSource(Casting.throwCast(ListAccess.class, access)); 81 refreshControlButtons(); 76 82 } 77 83 … … 87 93 return table; 88 94 } 95 89 96 } -
java/main/src/main/java/com/framsticks/gui/table/PrimitiveColumn.java
r100 r101 2 2 3 3 import com.framsticks.params.PrimitiveParam; 4 import com.framsticks.util. UnsupportedOperationException;4 import com.framsticks.util.FramsticksUnsupportedOperationException; 5 5 6 6 public class PrimitiveColumn extends Column { … … 31 31 @Override 32 32 public int setValueAt(int rowIndex, Object value) { 33 throw new UnsupportedOperationException().msg("setting value in table");33 throw new FramsticksUnsupportedOperationException().msg("setting value in table"); 34 34 } 35 35 -
java/main/src/main/java/com/framsticks/gui/table/TableModel.java
r100 r101 3 3 import java.util.ArrayList; 4 4 import java.util.Collections; 5 import java.util.LinkedList;6 5 import java.util.List; 7 6 … … 10 9 import javax.swing.JTable; 11 10 import javax.swing.UIManager; 12 import javax.swing.event.TableModelEvent;13 import javax.swing.event.TableModelListener;14 11 15 12 import org.apache.logging.log4j.Logger; … … 23 20 import com.framsticks.util.lang.Casting; 24 21 25 public class TableModel implements javax.swing.table.TableModel {22 public class TableModel extends AbstractTableModel { 26 23 27 24 private static final Logger log = LogManager.getLogger(TableModel.class); 28 25 29 protected List<TableModelListener> listeners = new LinkedList<>();30 26 protected ListAccess access; 31 27 protected Access elementAccess; … … 52 48 } 53 49 54 protected void refreshAll() {55 for (TableModelListener l : listeners) {56 l.tableChanged(new TableModelEvent(this));57 }58 }59 50 60 51 /** … … 74 65 } 75 66 76 @Override77 public void addTableModelListener(TableModelListener listener) {78 listeners.add(listener);79 }80 67 81 68 @Override … … 114 101 } 115 102 116 @Override117 public void removeTableModelListener(TableModelListener listener) {118 listeners.remove(listener);119 }120 103 121 104 -
java/main/src/main/java/com/framsticks/gui/tree/TreeModel.java
r100 r101 17 17 import com.framsticks.core.Node; 18 18 import com.framsticks.core.Path; 19 import com.framsticks.core.SideNoteKey; 19 20 import com.framsticks.core.TreeOperations; 20 21 import com.framsticks.gui.Frame; … … 24 25 import com.framsticks.params.ListAccess; 25 26 import com.framsticks.params.PrimitiveParam; 26 import com.framsticks.params. Util;27 import com.framsticks.params.ParamsUtil; 27 28 import com.framsticks.params.ValueParam; 28 29 import com.framsticks.params.types.EventParam; 29 30 import com.framsticks.util.FramsticksException; 30 31 import com.framsticks.util.Misc; 31 import com.framsticks.util. UnsupportedOperationException;32 import com.framsticks.util.FramsticksUnsupportedOperationException; 32 33 import com.framsticks.util.dispatching.FutureHandler; 33 34 import com.framsticks.util.lang.Casting; … … 91 92 @Override 92 93 public void valueForPathChanged(TreePath path, Object value) { 93 throw new UnsupportedOperationException().msg("changing value of tree node");94 throw new FramsticksUnsupportedOperationException().msg("changing value of tree node"); 94 95 } 95 96 … … 133 134 public TreeModelEvent prepareModelEventRegarding(Access access, String id, TreePath treeListPath) { 134 135 135 int number = Util.getNumberOfCompositeParamChild(access, access.get(id, Object.class));136 int number = ParamsUtil.getNumberOfCompositeParamChild(access, access.get(id, Object.class)); 136 137 if (number == -1) { 137 138 log.debug("encountered minor tree inconsistency in {}", treeListPath); … … 438 439 439 440 440 protected final Object createdTag = new Object();441 protected final SideNoteKey<Boolean> createdTag = SideNoteKey.make(Boolean.class); 441 442 442 443 -
java/main/src/main/java/com/framsticks/gui/tree/TreeNode.java
r100 r101 4 4 import java.util.Iterator; 5 5 import java.util.LinkedList; 6 import java.util.List;7 6 8 7 import org.apache.logging.log4j.LogManager; … … 11 10 import com.framsticks.core.Node; 12 11 import com.framsticks.core.Path; 12 import com.framsticks.core.SideNoteKey; 13 13 import com.framsticks.core.Tree; 14 14 import com.framsticks.gui.Frame; … … 59 59 hashCode = System.identityHashCode(path.getTopObject()); 60 60 61 if ( getTree().getSideNote(path.getTopObject(), getTreeModel().createdTag, Object.class) == getTreeModel().createdTag) {61 if (isMarked(path.getTree(), path.getTopObject(), getTreeModel().createdTag, false)) { 62 62 return; 63 63 } 64 64 65 65 // path.getTree().putSideNote(path.getTopObject(), Textual.class, path.getTextual()); 66 path.getTree().putSideNote(path.getTopObject(), getTreeModel().createdTag, getTreeModel().createdTag);66 mark(path.getTree(), path.getTopObject(), getTreeModel().createdTag, true); 67 67 68 68 /** Iterate over all EventParams and for matching ValueParams register listeners. */ … … 239 239 } 240 240 Access access = bindAccessForTreeObject(child); 241 CompositeParam param = getTree().getSideNote(child, CompositeParam.class, CompositeParam.class);241 CompositeParam param = getTree().getSideNote(child, Path.OBJECT_PARAM_KEY); 242 242 String name = param.getId(); 243 243 … … 262 262 } 263 263 264 // public static class Textual {265 // }266 264 267 265 public String getTextual() { 268 266 return textual; 269 // return getTree().getSideNote(lock(), Textual.class, String.class); 270 } 271 272 protected final Object listenersTag = new Object(); 273 274 public List<EventListener<?>> getListeners() { 275 @SuppressWarnings("unchecked") 276 List<EventListener<?>> result = getTree().getSideNote(lock(), listenersTag, List.class); 277 if (result == null) { 278 result = new LinkedList<>(); 279 getTree().putSideNote(lock(), listenersTag, result); 280 } 281 282 return result; 283 } 267 } 268 269 @SuppressWarnings("rawtypes") 270 protected final SideNoteKey<LinkedList> listenersTag = SideNoteKey.make(LinkedList.class); 284 271 285 272 protected <A> void tryAddListener(final Path path, final EventParam eventParam, Class<A> argumentType, final EventListener<A> listener) { 286 273 getTree().addListener(path, eventParam, listener, argumentType, new FutureHandler<Void>(getFrame()) { 274 @SuppressWarnings("unchecked") 287 275 @Override 288 276 protected void result(Void result) { 289 277 assert getFrame().isActive(); 290 278 log.debug("registered gui listener for {} at {}", eventParam, path); 291 get Listeners().add(listener);279 getOrCreateSideNote(getTree(), lock(), listenersTag).add(listener); 292 280 } 293 281 });
Note: See TracChangeset
for help on using the changeset viewer.