Skip to content

Commit ac3a24a

Browse files
authored
Merge pull request #329 from bls337/main
start fixing channel ui problems
2 parents 2da566c + d8e4702 commit ac3a24a

File tree

3 files changed

+68
-49
lines changed

3 files changed

+68
-49
lines changed

src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTable.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
public class ChannelTable extends JScrollPane {
1919

2020
private JTable table_;
21-
private JComboBox<String> cmbPresets_;
21+
private final JComboBox<String> cmbPresets_;
22+
2223
private ChannelTableData tableData_;
2324
private ChannelTableModel tableModel_;
2425

@@ -30,7 +31,7 @@ public ChannelTable(final LightSheetManager model) {
3031
final String channelGroup = model_.acquisitions().settings().channelGroup();
3132
final ChannelSpec[] channels = model_.acquisitions().settings().channels();
3233

33-
tableData_ = new ChannelTableData(channels, channelGroup);
34+
tableData_ = new ChannelTableData(channelGroup, channels);
3435
tableModel_ = new ChannelTableModel(tableData_);
3536
table_ = new JTable(tableModel_);
3637

@@ -42,7 +43,6 @@ public ChannelTable(final LightSheetManager model) {
4243
for (String preset : presets) {
4344
cmbPresets_.addItem(preset);
4445
}
45-
//cmbPresets.addItem("None");
4646
//cmbPresets_.setSelectedItem(presets[0]);
4747
column.setCellEditor(new DefaultCellEditor(cmbPresets_));
4848

@@ -65,7 +65,7 @@ public ChannelTable(final LightSheetManager model) {
6565
* @param data the channel data
6666
*/
6767
public void setTableData(final ChannelTableData data) {
68-
this.tableData_ = data;
68+
tableData_ = data;
6969
tableModel_ = new ChannelTableModel(tableData_);
7070
table_ = new JTable(tableModel_);
7171
}
@@ -82,7 +82,13 @@ public JTable getTable() {
8282
return table_;
8383
}
8484

85-
public void updatePresetCombos(final String channelGroup) {
85+
/**
86+
* Update the preset combo box with the available configurations
87+
* for this channel group.
88+
*
89+
* @param channelGroup the channel group
90+
*/
91+
public void updatePresetComboBox(final String channelGroup) {
8692
final String[] presets = getAllPresets(channelGroup);
8793
cmbPresets_.removeAllItems();
8894
for (String preset : presets) {
@@ -91,32 +97,38 @@ public void updatePresetCombos(final String channelGroup) {
9197
cmbPresets_.setSelectedItem(channelGroup);
9298
}
9399

100+
// public void updateAvailableChannelConfigs(final String channelGroup) {
101+
//
102+
// }
103+
94104
// TODO: probably should be in the model
95105
private String[] getAllPresets(final String configGroup) {
96106
return model_.studio().core().getAvailableConfigs(configGroup).toArray();
97107
}
98108

99109
// TODO: probably should be in the model
100110
public String[] getAvailableGroups() {
101-
StrVector groups;
111+
// get all channel groups
112+
StrVector channelGroups;
102113
try {
103-
groups = model_.studio().core().getAllowedPropertyValues("Core", "ChannelGroup");
114+
channelGroups = model_.studio().core()
115+
.getAllowedPropertyValues("Core", "ChannelGroup");
104116
} catch (Exception e) {
105117
model_.studio().logs().logError(e);
106118
return new String[0];
107119
}
108-
ArrayList<String> strGroups = new ArrayList<>();
109-
// strGroups.add("None");
110-
for (String group : groups) {
120+
// filter channel groups
121+
ArrayList<String> groups = new ArrayList<>();
122+
for (String group : channelGroups) {
111123
// StrVector st = model_.studio().core().getAvailableConfigGroups();
112124
// for (String s : st)
113125
// System.out.println(s);
114126
// a channel group must have multiple presets to be detected
115127
if (model_.studio().core().getAvailableConfigs(group).size() > 1) {
116-
strGroups.add(group);
128+
groups.add(group);
117129
}
118130
}
119-
return strGroups.toArray(new String[0]);
131+
return groups.toArray(String[]::new);
120132
}
121133

122134
public void setHeaderRowColor(final boolean state) {

src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTablePanel.java

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

src/main/java/org/micromanager/lightsheetmanager/model/channels/ChannelTableData.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,36 @@
88
*/
99
public class ChannelTableData {
1010

11-
private final ArrayList<ChannelSpec> channels_;
1211
private String channelGroup_;
12+
private final ArrayList<ChannelSpec> channels_;
1313

1414
public ChannelTableData() {
1515
channels_ = new ArrayList<>();
1616
channelGroup_ = "";
1717
}
1818

19-
public ChannelTableData(final ChannelSpec[] channels, final String channelGroup) {
19+
public ChannelTableData(final String channelGroup, final ChannelSpec[] allChannels) {
2020
channels_ = new ArrayList<>();
21-
channelGroup_ = channelGroup;
22-
Collections.addAll(channels_, channels);
21+
setChannels(channelGroup, allChannels);
22+
//channelGroup_ = channelGroup;
23+
//Collections.addAll(channels_, allChannels);
2324
}
2425

2526
public ChannelSpec getChannelByIndex(final int index) {
2627
return channels_.get(index);
2728
}
2829

30+
public void setChannels(final String channelGroup, final ChannelSpec[] allChannels) {
31+
channels_.clear();
32+
channelGroup_ = channelGroup;
33+
// only add channel data in the channel group
34+
for (ChannelSpec channel : allChannels) {
35+
if (channel.getGroup().equals(channelGroup)) {
36+
channels_.add(channel);
37+
}
38+
}
39+
}
40+
2941
public ChannelSpec[] getChannels() {
3042
return channels_.toArray(new ChannelSpec[0]);
3143
}

0 commit comments

Comments
 (0)