Skip to content
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
Expand Up @@ -18,7 +18,8 @@
public class ChannelTable extends JScrollPane {

private JTable table_;
private JComboBox<String> cmbPresets_;
private final JComboBox<String> cmbPresets_;

private ChannelTableData tableData_;
private ChannelTableModel tableModel_;

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

tableData_ = new ChannelTableData(channels, channelGroup);
tableData_ = new ChannelTableData(channelGroup, channels);
tableModel_ = new ChannelTableModel(tableData_);
table_ = new JTable(tableModel_);

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

Expand All @@ -65,7 +65,7 @@ public ChannelTable(final LightSheetManager model) {
* @param data the channel data
*/
public void setTableData(final ChannelTableData data) {
this.tableData_ = data;
tableData_ = data;
tableModel_ = new ChannelTableModel(tableData_);
table_ = new JTable(tableModel_);
}
Expand All @@ -82,7 +82,13 @@ public JTable getTable() {
return table_;
}

public void updatePresetCombos(final String channelGroup) {
/**
* Update the preset combo box with the available configurations
* for this channel group.
*
* @param channelGroup the channel group
*/
public void updatePresetComboBox(final String channelGroup) {
final String[] presets = getAllPresets(channelGroup);
cmbPresets_.removeAllItems();
for (String preset : presets) {
Expand All @@ -91,32 +97,38 @@ public void updatePresetCombos(final String channelGroup) {
cmbPresets_.setSelectedItem(channelGroup);
}

// public void updateAvailableChannelConfigs(final String 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;
// get all channel groups
StrVector channelGroups;
try {
groups = model_.studio().core().getAllowedPropertyValues("Core", "ChannelGroup");
channelGroups = 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) {
// filter channel groups
ArrayList<String> groups = new ArrayList<>();
for (String group : channelGroups) {
// StrVector st = model_.studio().core().getAvailableConfigGroups();
// for (String s : st)
// System.out.println(s);
// a channel group must have multiple presets to be detected
if (model_.studio().core().getAvailableConfigs(group).size() > 1) {
strGroups.add(group);
groups.add(group);
}
}
return strGroups.toArray(new String[0]);
return groups.toArray(String[]::new);
}

public void setHeaderRowColor(final boolean state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public class ChannelTablePanel extends Panel {
private ComboBox cmbChannelGroup_;
private ComboBox cmbChannelMode_;

private ChannelTable table_;
private final ChannelTable table_;

private final LightSheetManager model_;

public ChannelTablePanel(final LightSheetManager model, final CheckBox checkBox) {
super(checkBox);
model_ = Objects.requireNonNull(model);
table_ = new ChannelTable(model_);
createUserInterface();
createEventHandlers();
}
Expand All @@ -38,12 +39,9 @@ private void createUserInterface() {
lblChannelGroup_ = new JLabel("Channel group:");
lblChangeChannel_ = new JLabel("Change channel:");

table_ = new ChannelTable(model_);

Button.setDefaultSize(74, 24);
btnAddChannel_ = new Button("Add");
btnRemoveChannel_ = new Button("Remove");
btnRefresh_ = new Button("Refresh");
btnAddChannel_ = new Button("Add", 74, 24);
btnRemoveChannel_ = new Button("Remove", 74, 24);
btnRefresh_ = new Button("Refresh", 74, 24);

btnAddChannel_.setToolTipText("Add a new channel to the table.");
btnRemoveChannel_.setToolTipText("Remove the currently selected channel from the table.");
Expand All @@ -70,6 +68,16 @@ private void createUserInterface() {

private void createEventHandlers() {

// select channel group
cmbChannelGroup_.registerListener(e -> {
final String channelGroup = cmbChannelGroup_.getSelected();
table_.updatePresetComboBox(channelGroup);
table_.getData().setChannels(channelGroup, model_.acquisitions().settings().channels());
table_.getData().setChannelGroup(channelGroup);
model_.acquisitions().settingsBuilder().channelGroup(channelGroup);
table_.refreshData();
});

// add channel
btnAddChannel_.registerListener(e -> {
table_.getData().addEmptyChannel();
Expand All @@ -78,7 +86,7 @@ private void createEventHandlers() {
// table_.repaint();
// repaint();
//System.out.println("add channel");
table_.getData().printChannelData();
//table_.getData().printChannelData();
final ChannelSpec[] channels = table_.getData().getChannels();
model_.acquisitions().settingsBuilder().channels(channels);
model_.acquisitions().settingsBuilder().numChannels(channels.length);
Expand All @@ -87,7 +95,7 @@ private void createEventHandlers() {
// remove channel
btnRemoveChannel_.registerListener(e -> {
final int row = table_.getTable().getSelectedRow();
if (row != -1) {
if (row != -1) { // is any row selected?
table_.getData().removeChannel(row);
final ChannelSpec[] channels = table_.getData().getChannels();
model_.acquisitions().settingsBuilder().channels(channels);
Expand All @@ -97,41 +105,28 @@ private void createEventHandlers() {
}
});

// refresh
// refresh channel table
btnRefresh_.registerListener(e -> {
// TODO: use settings instead of GUI
table_.updatePresetCombos(cmbChannelGroup_.getSelected());
final Object currentLabel = cmbChannelGroup_.getSelectedItem();
final String[] groupLabels = table_.getAvailableGroups();
final String channelGroup = model_.acquisitions().settings().channelGroup();
final String[] groups = table_.getAvailableGroups();
cmbChannelGroup_.removeAllItems();
for (String label : groupLabels) {
cmbChannelGroup_.addItem(label);
//System.out.println(label);
if (label.equals(currentLabel)) {
cmbChannelGroup_.setSelectedItem(currentLabel);
for (String group : groups) {
cmbChannelGroup_.addItem(group);
if (group.equals(channelGroup)) {
// the currently selected channel group still exists
cmbChannelGroup_.setSelectedItem(channelGroup);
}
}
table_.updatePresetComboBox(channelGroup);
cmbChannelGroup_.updateUI();
// ChannelSpec[] ch = model_.acquisitions().settings().usedChannels();
// for (ChannelSpec c : ch)
// System.out.println(c);
});

// select channel mode
cmbChannelMode_.registerListener(e -> {
final int index = cmbChannelMode_.getSelectedIndex();
model_.acquisitions().settingsBuilder().channelMode(MultiChannelMode.getByIndex(index));
//System.out.println("getChannelMode: " + model_.acquisitions().getAcquisitionSettings().getChannelMode());
model_.acquisitions().settingsBuilder()
.channelMode(MultiChannelMode.getByIndex(cmbChannelMode_.getSelectedIndex()));
});

// select channel group
cmbChannelGroup_.registerListener(e -> {
final String channelGroup = cmbChannelGroup_.getSelected();
table_.updatePresetCombos(channelGroup);
table_.getData().setChannelGroup(channelGroup);
model_.acquisitions().settingsBuilder().channelGroup(channelGroup);
//System.out.println("getChannelGroup: " + model_.acquisitions().getAcquisitionSettings().getChannelGroup());
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,36 @@
*/
public class ChannelTableData {

private final ArrayList<ChannelSpec> channels_;
private String channelGroup_;
private final ArrayList<ChannelSpec> channels_;

public ChannelTableData() {
channels_ = new ArrayList<>();
channelGroup_ = "";
}

public ChannelTableData(final ChannelSpec[] channels, final String channelGroup) {
public ChannelTableData(final String channelGroup, final ChannelSpec[] allChannels) {
channels_ = new ArrayList<>();
channelGroup_ = channelGroup;
Collections.addAll(channels_, channels);
setChannels(channelGroup, allChannels);
//channelGroup_ = channelGroup;
//Collections.addAll(channels_, allChannels);
}

public ChannelSpec getChannelByIndex(final int index) {
return channels_.get(index);
}

public void setChannels(final String channelGroup, final ChannelSpec[] allChannels) {
channels_.clear();
channelGroup_ = channelGroup;
// only add channel data in the channel group
for (ChannelSpec channel : allChannels) {
if (channel.getGroup().equals(channelGroup)) {
channels_.add(channel);
}
}
}

public ChannelSpec[] getChannels() {
return channels_.toArray(new ChannelSpec[0]);
}
Expand Down
Loading