Skip to content

Commit

Permalink
port useful functions for channel table
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon committed Mar 25, 2024
1 parent a8813c2 commit e5f5066
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ChannelTableModel(final ChannelTableData tableData) {

@Override
public int getRowCount() {
return tableData_.getChannels().size();
return tableData_.getNumChannels();
}

@Override
Expand All @@ -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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChannelSpec> 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();
}
Expand Down Expand Up @@ -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_) {
Expand Down

0 comments on commit e5f5066

Please sign in to comment.