forked from open-ephys-plugins/network-events
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkEventsEditor.cpp
122 lines (91 loc) · 3.17 KB
/
NetworkEventsEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2013 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "NetworkEventsEditor.h"
#include "NetworkEvents.h"
#include <stdio.h>
NetworkEventsEditor::NetworkEventsEditor(NetworkEvents* parentNode)
: GenericEditor(parentNode)
{
desiredWidth = 180;
processor = parentNode;
restartConnection = std::make_unique<UtilityButton>("Restart Connection", Font("Fira Code", "Regular", 15.0f));
restartConnection->setBounds(20,45,130,18);
restartConnection->addListener(this);
addAndMakeVisible(restartConnection.get());
urlLabel = std::make_unique<Label>("Port", "Port:");
urlLabel->setBounds(20,85,140,25);
addAndMakeVisible(urlLabel.get());
labelPort = std::make_unique<Label>("Port", processor->getCurrPortString());
labelPort->setBounds(70,85,80,18);
labelPort->setColour(Label::textColourId, Colours::white);
labelPort->setColour(Label::backgroundColourId, Colours::grey);
labelPort->setEditable(true);
labelPort->addListener(this);
addAndMakeVisible(labelPort.get());
}
void NetworkEventsEditor::buttonClicked(Button* button)
{
if (button == restartConnection.get())
{
processor->restartConnection();
}
}
void NetworkEventsEditor::setLabelColor(juce::Colour color)
{
labelPort->setColour(Label::backgroundColourId, color);
}
void NetworkEventsEditor::setPortText(const String& text)
{
labelPort->setText(text, dontSendNotification);
}
void NetworkEventsEditor::labelTextChanged(juce::Label *label)
{
if (label == labelPort.get())
{
NetworkEvents *p = (NetworkEvents *)getProcessor();
uint16 port;
if (!portFromString(label->getText(), &port))
{
CoreServices::sendStatusMessage("NetworkEvents: Invalid port");
setPortText(p->getCurrPortString());
return;
}
p->setNewListeningPort(port);
}
}
NetworkEventsEditor::~NetworkEventsEditor()
{
}
bool NetworkEventsEditor::portFromString(const String& portString, uint16* port)
{
if (portString.trim() == "*") // wildcard, special case
{
*port = 0;
return true;
}
if (portString.indexOfAnyOf("0123456789") == -1)
{
return false;
}
int32 portInput = portString.getIntValue();
if (portInput <= 0 || portInput > (1 << 16) - 1)
{
return false;
}
*port = static_cast<uint16>(portInput);
return true;
}