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

port useful functions for channel table #259

Merged
merged 1 commit into from
Mar 25, 2024
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 @@ -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
Loading