@@ -23,13 +23,14 @@ public class ChannelTablePanel extends Panel {
2323 private ComboBox cmbChannelGroup_ ;
2424 private ComboBox cmbChannelMode_ ;
2525
26- private ChannelTable table_ ;
26+ private final ChannelTable table_ ;
2727
2828 private final LightSheetManager model_ ;
2929
3030 public ChannelTablePanel (final LightSheetManager model , final CheckBox checkBox ) {
3131 super (checkBox );
3232 model_ = Objects .requireNonNull (model );
33+ table_ = new ChannelTable (model_ );
3334 createUserInterface ();
3435 createEventHandlers ();
3536 }
@@ -38,12 +39,9 @@ private void createUserInterface() {
3839 lblChannelGroup_ = new JLabel ("Channel group:" );
3940 lblChangeChannel_ = new JLabel ("Change channel:" );
4041
41- table_ = new ChannelTable (model_ );
42-
43- Button .setDefaultSize (74 , 24 );
44- btnAddChannel_ = new Button ("Add" );
45- btnRemoveChannel_ = new Button ("Remove" );
46- btnRefresh_ = new Button ("Refresh" );
42+ btnAddChannel_ = new Button ("Add" , 74 , 24 );
43+ btnRemoveChannel_ = new Button ("Remove" , 74 , 24 );
44+ btnRefresh_ = new Button ("Refresh" , 74 , 24 );
4745
4846 btnAddChannel_ .setToolTipText ("Add a new channel to the table." );
4947 btnRemoveChannel_ .setToolTipText ("Remove the currently selected channel from the table." );
@@ -70,6 +68,16 @@ private void createUserInterface() {
7068
7169 private void createEventHandlers () {
7270
71+ // select channel group
72+ cmbChannelGroup_ .registerListener (e -> {
73+ final String channelGroup = cmbChannelGroup_ .getSelected ();
74+ table_ .updatePresetComboBox (channelGroup );
75+ table_ .getData ().setChannels (channelGroup , model_ .acquisitions ().settings ().channels ());
76+ table_ .getData ().setChannelGroup (channelGroup );
77+ model_ .acquisitions ().settingsBuilder ().channelGroup (channelGroup );
78+ table_ .refreshData ();
79+ });
80+
7381 // add channel
7482 btnAddChannel_ .registerListener (e -> {
7583 table_ .getData ().addEmptyChannel ();
@@ -78,7 +86,7 @@ private void createEventHandlers() {
7886// table_.repaint();
7987// repaint();
8088 //System.out.println("add channel");
81- table_ .getData ().printChannelData ();
89+ // table_.getData().printChannelData();
8290 final ChannelSpec [] channels = table_ .getData ().getChannels ();
8391 model_ .acquisitions ().settingsBuilder ().channels (channels );
8492 model_ .acquisitions ().settingsBuilder ().numChannels (channels .length );
@@ -87,7 +95,7 @@ private void createEventHandlers() {
8795 // remove channel
8896 btnRemoveChannel_ .registerListener (e -> {
8997 final int row = table_ .getTable ().getSelectedRow ();
90- if (row != -1 ) {
98+ if (row != -1 ) { // is any row selected?
9199 table_ .getData ().removeChannel (row );
92100 final ChannelSpec [] channels = table_ .getData ().getChannels ();
93101 model_ .acquisitions ().settingsBuilder ().channels (channels );
@@ -97,41 +105,28 @@ private void createEventHandlers() {
97105 }
98106 });
99107
100- // refresh
108+ // refresh channel table
101109 btnRefresh_ .registerListener (e -> {
102- // TODO: use settings instead of GUI
103- table_ .updatePresetCombos (cmbChannelGroup_ .getSelected ());
104- final Object currentLabel = cmbChannelGroup_ .getSelectedItem ();
105- final String [] groupLabels = table_ .getAvailableGroups ();
110+ final String channelGroup = model_ .acquisitions ().settings ().channelGroup ();
111+ final String [] groups = table_ .getAvailableGroups ();
106112 cmbChannelGroup_ .removeAllItems ();
107- for (String label : groupLabels ) {
108- cmbChannelGroup_ .addItem (label );
109- //System.out.println(label);
110- if ( label . equals ( currentLabel )) {
111- cmbChannelGroup_ .setSelectedItem (currentLabel );
113+ for (String group : groups ) {
114+ cmbChannelGroup_ .addItem (group );
115+ if ( group . equals ( channelGroup )) {
116+ // the currently selected channel group still exists
117+ cmbChannelGroup_ .setSelectedItem (channelGroup );
112118 }
113119 }
120+ table_ .updatePresetComboBox (channelGroup );
114121 cmbChannelGroup_ .updateUI ();
115- // ChannelSpec[] ch = model_.acquisitions().settings().usedChannels();
116- // for (ChannelSpec c : ch)
117- // System.out.println(c);
118122 });
119123
120124 // select channel mode
121125 cmbChannelMode_ .registerListener (e -> {
122- final int index = cmbChannelMode_ .getSelectedIndex ();
123- model_ .acquisitions ().settingsBuilder ().channelMode (MultiChannelMode .getByIndex (index ));
124- //System.out.println("getChannelMode: " + model_.acquisitions().getAcquisitionSettings().getChannelMode());
126+ model_ .acquisitions ().settingsBuilder ()
127+ .channelMode (MultiChannelMode .getByIndex (cmbChannelMode_ .getSelectedIndex ()));
125128 });
126129
127- // select channel group
128- cmbChannelGroup_ .registerListener (e -> {
129- final String channelGroup = cmbChannelGroup_ .getSelected ();
130- table_ .updatePresetCombos (channelGroup );
131- table_ .getData ().setChannelGroup (channelGroup );
132- model_ .acquisitions ().settingsBuilder ().channelGroup (channelGroup );
133- //System.out.println("getChannelGroup: " + model_.acquisitions().getAcquisitionSettings().getChannelGroup());
134- });
135130 }
136131
137132 /**
0 commit comments