Ignore:
Timestamp:
07/14/13 23:20:04 (11 years ago)
Author:
psniegowski
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/gui/controls/EventControl.java

    r100 r101  
    11package com.framsticks.gui.controls;
    22
    3 import java.awt.Dimension;
    43import java.awt.event.ActionEvent;
    54import java.awt.event.ActionListener;
    6 
    7 import javax.swing.JButton;
    8 
     5import java.text.SimpleDateFormat;
     6import java.util.ArrayList;
     7import java.util.Date;
     8import java.util.List;
     9
     10
     11
     12import com.framsticks.core.Path;
     13import com.framsticks.core.SideNoteKey;
     14import com.framsticks.gui.Frame;
     15import com.framsticks.gui.Gui;
     16import com.framsticks.gui.table.AbstractTableModel;
     17import com.framsticks.params.EventListener;
    918import com.framsticks.params.types.EventParam;
     19import com.framsticks.util.FramsticksUnsupportedOperationException;
     20import com.framsticks.util.dispatching.Dispatching;
     21import com.framsticks.util.dispatching.FutureHandler;
     22import com.framsticks.util.dispatching.RunAt;
     23import com.framsticks.util.lang.Pair;
     24
     25import static com.framsticks.core.TreeOperations.*;
    1026
    1127/**
     
    1329 */
    1430@SuppressWarnings("serial")
    15 public class EventControl extends Control {
     31public class EventControl extends HistoryControl {
    1632        // private static final Logger log = LogManager.getLogger(EventControl.class.getName());
    1733
    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;
    2043
    2144        public EventControl(final EventParam eventParam) {
    2245                super(eventParam);
    2346
    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() {
    2954                        @Override
    3055                        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;
    3563                                }
     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
    3690                        }
    3791                });
    3892
     93                updateFoldState();
     94                Gui.setupTitledControl(this, controlRow, resultsScrollPane);
    3995        }
    4096
    4197        @Override
    4298        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        }
    54200}
Note: See TracChangeset for help on using the changeset viewer.