From e5f506634f375507c9d418f8ffee781f379cc9a0 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 25 Mar 2024 15:49:55 -0700 Subject: [PATCH] port useful functions for channel table --- .../gui/tabs/channels/ChannelTableModel.java | 6 ++-- .../gui/tabs/channels/ChannelTablePanel.java | 4 +-- .../model/channels/ChannelTableData.java | 28 +++++++++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTableModel.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTableModel.java index 67f584e..89cd857 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTableModel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/channels/ChannelTableModel.java @@ -23,7 +23,7 @@ public ChannelTableModel(final ChannelTableData tableData) { @Override public int getRowCount() { - return tableData_.getChannels().size(); + return tableData_.getNumChannels(); } @Override @@ -48,7 +48,7 @@ public boolean isCellEditable(int row, int col) { @Override public Object getValueAt(int row, int col) { - ChannelSpec channelSpec = tableData_.getChannels().get(row); + ChannelSpec channelSpec = tableData_.getChannelByIndex(row); switch (col) { case 0: return channelSpec.isUsed(); @@ -65,7 +65,7 @@ public Object getValueAt(int row, int col) { @Override public void setValueAt(Object value, int row, int col) { - ChannelSpec channelSpec = tableData_.getChannels().get(row); + ChannelSpec channelSpec = tableData_.getChannelByIndex(row); switch (col) { case 0: if (value instanceof Boolean) { 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 652baa3..4265245 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 @@ -76,7 +76,7 @@ private void createEventHandlers() { // repaint(); System.out.println("add channel"); table_.getData().printChannelData(); - final ChannelSpec[] channels = table_.getData().getChannelArray(); + final ChannelSpec[] channels = table_.getData().getChannels(); model_.acquisitions().settingsBuilder().channels(channels); model_.acquisitions().settingsBuilder().numChannels(channels.length); }); @@ -85,7 +85,7 @@ private void createEventHandlers() { final int row = table_.getTable().getSelectedRow(); if (row != -1) { table_.getData().removeChannel(row); - final ChannelSpec[] channels = table_.getData().getChannelArray(); + final ChannelSpec[] channels = table_.getData().getChannels(); model_.acquisitions().settingsBuilder().channels(channels); model_.acquisitions().settingsBuilder().numChannels(channels.length); table_.refreshData(); diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/channels/ChannelTableData.java b/src/main/java/org/micromanager/lightsheetmanager/model/channels/ChannelTableData.java index 6b72a64..30c732e 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/channels/ChannelTableData.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/channels/ChannelTableData.java @@ -13,26 +13,29 @@ public class ChannelTableData { public ChannelTableData() { channels_ = new ArrayList<>(); - channelGroup_ = "None"; + channelGroup_ = ""; } public ChannelTableData(final ChannelSpec[] channels, final String channelGroup) { channels_ = new ArrayList<>(); - // TODO: Objects.requireNonNull - if (channels != null) { - Collections.addAll(channels_, channels); - } channelGroup_ = channelGroup; + Collections.addAll(channels_, channels); } - public ArrayList getChannels() { - return channels_; + public ChannelSpec getChannelByIndex(final int index) { + return channels_.get(index); } - public ChannelSpec[] getChannelArray() { + public ChannelSpec[] getChannels() { return channels_.toArray(new ChannelSpec[0]); } + public ChannelSpec[] getUsedChannels() { + return channels_.stream() + .filter(ChannelSpec::isUsed) + .toArray(ChannelSpec[]::new); + } + public int getNumChannels() { return channels_.size(); } @@ -61,6 +64,15 @@ public String getChannelGroup() { return channelGroup_; } + public double getChannelOffset(final String channelName) { + for (ChannelSpec channel : channels_) { + if (channel.getName().equals(channelName)) { + return channel.getOffset(); + } + } + return 0.0; + } + public void printChannelData() { System.out.println("[ChannelTableData]"); for (ChannelSpec channel : channels_) {