Skip to content

Commit 95f9f00

Browse files
committed
Use viewport to display Spike Detector table
1 parent 06420ed commit 95f9f00

2 files changed

Lines changed: 55 additions & 19 deletions

File tree

Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.cpp

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ void PopupThresholdComponent::sliderValueChanged(Slider* slider)
198198
lockButton->getToggleState(), // isLocked
199199
slider->getValue()); // value
200200

201-
owner->repaint();
202201
}
203202

204203
void PopupThresholdComponent::buttonClicked(Button* button)
@@ -222,8 +221,7 @@ void PopupThresholdComponent::buttonClicked(Button* button)
222221
thresholdType); // threshold type
223222

224223
createSliders();
225-
226-
owner->repaint();
224+
227225
}
228226

229227
ThresholdSelectorCustomComponent::ThresholdSelectorCustomComponent(SpikeChannel* channel_, bool acquisitionIsActive_)
@@ -303,7 +301,7 @@ void ThresholdSelectorCustomComponent::paint(Graphics& g)
303301

304302
if (channel == nullptr)
305303
return;
306-
304+
307305
thresholdString = "";
308306

309307
switch (thresholder_type->getSelectedIndex())
@@ -578,6 +576,8 @@ void SpikeDetectorTableModel::broadcastThresholdTypeToSelectedRows(int rowThatWa
578576
}
579577

580578
table->updateContent();
579+
580+
table->repaint();
581581
}
582582

583583
void SpikeDetectorTableModel::broadcastThresholdToSelectedRows(int rowThatWasClicked,
@@ -588,7 +588,7 @@ void SpikeDetectorTableModel::broadcastThresholdToSelectedRows(int rowThatWasCli
588588
{
589589
SparseSet<int> selectedRows = table->getSelectedRows();
590590

591-
//std::cout << "Broadcasting value." << std::endl;
591+
//std::cout << "Broadcasting value for " << rowThatWasClicked << ", " << channelIndex << std::endl;
592592

593593
float actualValue;
594594

@@ -639,12 +639,18 @@ void SpikeDetectorTableModel::broadcastThresholdToSelectedRows(int rowThatWasCli
639639
Component* c = table->getCellComponent(SpikeDetectorTableModel::Columns::THRESHOLD, i);
640640

641641
if (c != nullptr)
642+
{
643+
//std::cout << "Repainting" << std::endl;
642644
c->repaint();
645+
}
646+
643647

644648
}
645649
}
646650

647651
table->updateContent();
652+
653+
table->repaint();
648654
}
649655

650656
Component* SpikeDetectorTableModel::refreshComponentForCell(int rowNumber,
@@ -949,7 +955,7 @@ void SpikeChannelGenerator::buttonClicked(Button* button)
949955
int numSpikeChannelsToAdd = spikeChannelCountLabel->getText().getIntValue();
950956
SpikeChannel::Type channelType = (SpikeChannel::Type) spikeChannelTypeSelector->getSelectedId();
951957

952-
std::cout << "Button clicked! Sending " << startChannels.size() << " start channels " << std::endl;
958+
//std::cout << "Button clicked! Sending " << startChannels.size() << " start channels " << std::endl;
953959

954960
if (startChannels.size() == 0)
955961
editor->addSpikeChannels(window, channelType, numSpikeChannelsToAdd);
@@ -1008,7 +1014,7 @@ void SpikeChannelGenerator::channelStateChanged(Array<int> selectedChannels)
10081014
{
10091015
startChannels = selectedChannels;
10101016

1011-
std::cout << "Size of start channels: " << startChannels.size() << std::endl;
1017+
//std::cout << "Size of start channels: " << startChannels.size() << std::endl;
10121018
}
10131019

10141020
void SpikeChannelGenerator::paint(Graphics& g)
@@ -1054,46 +1060,66 @@ PopupConfigurationWindow::PopupConfigurationWindow(SpikeDetectorEditor* editor_,
10541060
electrodeTable->setHeaderHeight(30);
10551061
electrodeTable->setRowHeight(30);
10561062
electrodeTable->setMultipleSelectionEnabled(true);
1063+
1064+
viewport = std::make_unique<Viewport>();
10571065

1058-
addChildComponent(electrodeTable.get());
1066+
viewport->setViewedComponent(electrodeTable.get(), false);
1067+
viewport->setScrollBarsShown(true, false);
1068+
viewport->getVerticalScrollBar().addListener(this);
10591069

1070+
addAndMakeVisible(viewport.get());
10601071
update(spikeChannels);
10611072

10621073

10631074
}
10641075

1076+
void PopupConfigurationWindow::scrollBarMoved(ScrollBar* scrollBar, double newRangeStart)
1077+
{
1078+
1079+
if (!updating)
1080+
{
1081+
scrollDistance = viewport->getViewPositionY();
1082+
}
1083+
1084+
}
1085+
10651086

10661087
void PopupConfigurationWindow::update(Array<SpikeChannel*> spikeChannels)
10671088
{
10681089

10691090
if (spikeChannels.size() > 0)
10701091
{
10711092

1093+
updating = true;
1094+
10721095
tableModel->update(spikeChannels);
10731096

10741097
int maxRows = 16;
10751098

1076-
int numRows = spikeChannels.size() <= maxRows ? spikeChannels.size() : maxRows;
1099+
int numRowsVisible = spikeChannels.size() <= maxRows ? spikeChannels.size() : maxRows;
10771100

10781101
int scrollBarWidth = 0;
10791102

1080-
electrodeTable->getHorizontalScrollBar().setVisible(false);
1081-
10821103
if (spikeChannels.size() > maxRows)
10831104
{
1084-
electrodeTable->getVerticalScrollBar().setVisible(true);
1105+
viewport->getVerticalScrollBar().setVisible(true);
10851106
scrollBarWidth += 20;
10861107
}
10871108
else {
1088-
electrodeTable->getVerticalScrollBar().setVisible(false);
1109+
viewport->getVerticalScrollBar().setVisible(false);
10891110
}
1090-
1091-
setSize(530 + scrollBarWidth, (numRows + 1) * 30 + 10 + 40);
1092-
electrodeTable->setBounds(5, 5, 520 + scrollBarWidth, (numRows + 1) * 30);
1111+
1112+
setSize(530 + scrollBarWidth, (numRowsVisible + 1) * 30 + 10 + 40);
1113+
viewport->setBounds(5, 5, 520 + scrollBarWidth, (numRowsVisible + 1) * 30);
1114+
electrodeTable->setBounds(0, 0, 520 + scrollBarWidth, (spikeChannels.size() + 1) * 30);
1115+
1116+
viewport->setViewPosition(0, scrollDistance);
10931117

10941118
electrodeTable->setVisible(true);
10951119

1096-
spikeChannelGenerator->setBounds(60, electrodeTable->getBottom() + 8, 420, 30);
1120+
spikeChannelGenerator->setBounds(60, viewport->getBottom() + 8, 420, 30);
1121+
1122+
updating = false;
10971123

10981124
}
10991125
else {

Plugins/BasicSpikeDisplay/SpikeDetector/PopupConfigurationWindow.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ class SpikeChannelGenerator :
449449
/**
450450
* Popup window used to edit Spike Channel settings
451451
*/
452-
class PopupConfigurationWindow : public Component
452+
class PopupConfigurationWindow : public Component,
453+
public ScrollBar::Listener
453454
{
454455

455456
public:
@@ -463,7 +464,7 @@ class PopupConfigurationWindow : public Component
463464
~PopupConfigurationWindow() { }
464465

465466
/** Updates the window with a new set of Spike Channels*/
466-
void update(Array<SpikeChannel*> spikeChannels);\
467+
void update(Array<SpikeChannel*> spikeChannels);
467468

468469
/** Custom table header component (not currently used)*/
469470
//std::unique_ptr<TableHeaderComponent> tableHeader;
@@ -473,11 +474,20 @@ class PopupConfigurationWindow : public Component
473474

474475
/** Custom list box for Spike Channel settings*/
475476
std::unique_ptr<TableListBox> electrodeTable;
477+
478+
/** Listens for viewport scrolling */
479+
void scrollBarMoved(ScrollBar* scrollBar, double newRangeStart);
476480

477481
private:
478482
SpikeDetectorEditor* editor;
479483

480484
std::unique_ptr<SpikeChannelGenerator> spikeChannelGenerator;
485+
486+
std::unique_ptr<Viewport> viewport;
487+
488+
int scrollDistance = 0;
489+
490+
bool updating = false;
481491
};
482492

483493

0 commit comments

Comments
 (0)