Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor improvements to channel table ui #162

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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