Skip to content

Commit

Permalink
Merge pull request #162 from bls337/main
Browse files Browse the repository at this point in the history
minor improvements to channel table ui
  • Loading branch information
bls337 authored Oct 3, 2023
2 parents 89ca137 + a577ed1 commit 893d216
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.micromanager.lightsheetmanager.gui.tabs.channels;

import mmcorej.StrVector;
import org.micromanager.lightsheetmanager.model.LightSheetManagerModel;
import org.micromanager.lightsheetmanager.model.channels.ChannelSpec;
import org.micromanager.lightsheetmanager.model.channels.ChannelTableData;
Expand All @@ -10,11 +11,13 @@
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableColumn;
import java.util.ArrayList;
import java.util.Objects;

public class ChannelTable extends JScrollPane {

private JTable table_;
private JComboBox<String> cmbPresets_;
private ChannelTableData tableData_;
private ChannelTableModel tableModel_;

Expand All @@ -31,10 +34,16 @@ public ChannelTable(final LightSheetManagerModel model) {

// init presets combo box
TableColumn column = table_.getColumnModel().getColumn(1);
JComboBox<String> cmbPresets = new JComboBox<>();
cmbPresets.addItem("None");
cmbPresets.setSelectedIndex(0);
column.setCellEditor(new DefaultCellEditor(cmbPresets));
cmbPresets_ = new JComboBox<>();

final String channelGroup = model_.acquisitions().settings().channelGroup();
final String[] presets = getAllPresets(channelGroup);
for (String preset : presets) {
cmbPresets_.addItem(preset);
}
//cmbPresets.addItem("None");
cmbPresets_.setSelectedItem(presets[0]);
column.setCellEditor(new DefaultCellEditor(cmbPresets_));

// cancel JTable edits when focus is lost to prevent errors
table_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
Expand Down Expand Up @@ -72,4 +81,43 @@ public JTable getTable() {
return table_;
}

public void updatePresetCombos(final String channelGroup) {
//System.out.println("channelGroup: " + channelGroup);
final String[] presets = getAllPresets(channelGroup);
cmbPresets_.removeAllItems();
for (String preset : presets) {
cmbPresets_.addItem(preset);
//System.out.println("preset " + preset);
}
cmbPresets_.setSelectedItem(channelGroup);
}

// TODO: probably should be in the model
private String[] getAllPresets(final String configGroup) {
return model_.studio().core().getAvailableConfigs(configGroup).toArray();
}


// TODO: probably should be in the model
public String[] getAvailableGroups() {
StrVector groups;
try {
groups = model_.studio().core().getAllowedPropertyValues("Core", "ChannelGroup");
} catch (Exception e) {
model_.studio().logs().logError(e);
return new String[0];
}
ArrayList<String> strGroups = new ArrayList<>();
// strGroups.add("None");
for (String group : groups) {
// System.out.println("grp: " + group);
// StrVector st = model_.studio().core().getAvailableConfigGroups();
// for (String s : st)
// System.out.println(s);
if (model_.studio().core().getAvailableConfigs(group).size() > 1) {
strGroups.add(group);
}
}
return strGroups.toArray(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ private void createUserInterface() {
btnRemoveChannel_.setToolTipText("Remove the currently selected channel from the table.");
btnRefresh_.setToolTipText("Refresh the channel panel with the latest configuration groups settings.");

final String[] groupLabels = getAvailableGroups();
cmbChannelGroup_ = new ComboBox(groupLabels, groupLabels[0]);
final String[] groupLabels = table_.getAvailableGroups();
cmbChannelGroup_ = new ComboBox(groupLabels,
model_.acquisitions().settings().channelGroup());

cmbChannelMode_ = new ComboBox(MultiChannelMode.toArray(),
model_.acquisitions().settings().channelMode().toString());
Expand Down Expand Up @@ -92,8 +93,10 @@ private void createEventHandlers() {
});

btnRefresh_.registerListener(e -> {
// TODO: use settings instead of GUI
table_.updatePresetCombos(cmbChannelGroup_.getSelected());
final Object currentLabel = cmbChannelGroup_.getSelectedItem();
final String[] groupLabels = getAvailableGroups();
final String[] groupLabels = table_.getAvailableGroups();
cmbChannelGroup_.removeAllItems();
for (String label : groupLabels){
cmbChannelGroup_.addItem(label);
Expand All @@ -112,30 +115,13 @@ private void createEventHandlers() {
});

cmbChannelGroup_.registerListener(e -> {
asb.channelGroup(cmbChannelGroup_.getSelected());
final String selected = cmbChannelGroup_.getSelected();
table_.updatePresetCombos(selected);
asb.channelGroup(selected);
//System.out.println("getChannelGroup: " + model_.acquisitions().getAcquisitionSettings().getChannelGroup());
});
}

// TODO: probably should be in the model not gui
private String[] getAvailableGroups() {
StrVector groups;
try {
groups = model_.studio().core().getAllowedPropertyValues("Core", "ChannelGroup");
} catch (Exception e) {
model_.studio().logs().logError(e);
return new String[0];
}
ArrayList<String> strGroups = new ArrayList<>();
strGroups.add("None");
for (String group : groups) {
if (model_.studio().core().getAvailableConfigs(group).size() > 1) {
strGroups.add(group);
}
}
return strGroups.toArray(new String[0]);
}

/**
* Enable or disable items in the channel table panel.
*
Expand Down

0 comments on commit 893d216

Please sign in to comment.