From a577ed1800a57ec56e7ca8d903c05bb25d42c5a9 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 3 Oct 2023 10:08:47 -0700 Subject: [PATCH] minor improvements to channel table ui --- .../gui/tabs/channels/ChannelTable.java | 56 +++++++++++++++++-- .../gui/tabs/channels/ChannelTablePanel.java | 32 +++-------- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTable.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTable.java index 7e28935..738eb4d 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTable.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTable.java @@ -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; @@ -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 cmbPresets_; private ChannelTableData tableData_; private ChannelTableModel tableModel_; @@ -31,10 +34,16 @@ public ChannelTable(final LightSheetManagerModel model) { // init presets combo box TableColumn column = table_.getColumnModel().getColumn(1); - JComboBox 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); @@ -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 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]); + } } diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTablePanel.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTablePanel.java index 6574b97..8fcb7e1 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTablePanel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTablePanel.java @@ -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()); @@ -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); @@ -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 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. *