Open Ephys GUI
 All Classes Functions Variables Pages
ChannelSelector.h
1 /*
2  ------------------------------------------------------------------
3 
4  This file is part of the Open Ephys GUI
5  Copyright (C) 2012 Open Ephys
6 
7  ------------------------------------------------------------------
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef __CHANNELSELECTOR_H_68124E35__
25 #define __CHANNELSELECTOR_H_68124E35__
26 
27 #include "../../../JuceLibraryCode/JuceHeader.h"
28 #include "GenericEditor.h"
29 #include "../../AccessClass.h"
30 
31 #include <stdio.h>
32 
33 /**
34 
35  Automatically creates an interactive editor for selecting channels
36 
37  @see GenericEditor
38 
39 */
40 
42 class EditorButton;
43 
44 class ChannelSelector : public Component,
45  public Button::Listener,
46  public AccessClass,
47  public Timer
48 {
49 public:
50 
51  /** constructor */
52  ChannelSelector(bool createButtons, Font& titleFont);
53 
54  /** destructor */
56 
57  /** button callback */
58  void buttonClicked(Button* button);
59 
60  /** Return an array of selected channels. */
61  Array<int> getActiveChannels();
62 
63  /** Set the selected channels. */
64  void setActiveChannels(Array<int>);
65 
66  /** Set the total number of channels. */
67  void setNumChannels(int);
68 
69  /** Return whether a particular channel should be recording. */
70  bool getRecordStatus(int chan);
71 
72  /** Return whether a particular channel should be monitored. */
73  bool getAudioStatus(int chan);
74 
75  /** Return component's desired width. */
76  int getDesiredWidth();
77 
78 
79  void inactivateButtons();
80 
81  void activateButtons();
82 
83  void setRadioStatus(bool);
84 
85  void paramButtonsToggledByDefault(bool t) {paramsToggled = t;}
86  //void paramButtonsActiveByDefault(bool t) {paramsActive = t;}
87 
88  bool eventsOnly;
89 
90 private:
91 
92  EditorButton* audioButton;
93  EditorButton* recordButton;
94  EditorButton* paramsButton;
95  EditorButton* allButton;
96  EditorButton* noneButton;
97 
98  Array<ChannelSelectorButton*> parameterButtons;
99  Array<ChannelSelectorButton*> audioButtons;
100  Array<ChannelSelectorButton*> recordButtons;
101 
102  bool paramsToggled;
103  bool paramsActive;
104  bool radioStatus;
105 
106  bool isNotSink;
107  bool moveRight;
108  bool moveLeft;
109 
110  int offsetLR;
111  int offsetUD;
112 
113  int parameterOffset;
114  int audioOffset;
115  int recordOffset;
116 
117  int desiredOffset;
118 
119  void resized();
120 
121  void addButton();
122  void removeButton();
123  void refreshButtonBoundaries();
124 
125  void timerCallback();
126 
127  void paint(Graphics& g);
128 
129  Font& titleFont;
130 
131  enum {AUDIO, RECORD, PARAMETER};
132 
133 };
134 
135 
136 class EditorButton : public Button
137 {
138 public:
139  EditorButton(const String& name, Font& f);
140  ~EditorButton() {}
141 
142  bool getState() {return isEnabled;}
143 
144  void setState(bool state)
145  {
146  isEnabled = state;
147 
148  if (!state)
149  {
150  removeListener((Button::Listener*) getParentComponent());
151  } else {
152  addListener((Button::Listener*) getParentComponent());
153  }
154 
155  repaint();
156  }
157 
158 private:
159  void paintButton(Graphics& g, bool isMouseOver, bool isButtonDown);
160 
161  void resized();
162 
163  Path outlinePath;
164 
165  int type;
166  Font buttonFont;
167 
168  bool isEnabled;
169 
170  ColourGradient selectedGrad, selectedOverGrad, neutralGrad, neutralOverGrad;
171 };
172 
173 class ChannelSelectorButton : public Button
174 {
175 public:
176  ChannelSelectorButton(int num, int type, Font& f);
178 
179  int getType() {return type;}
180  int getChannel() {return num;}
181  void setActive(bool t);
182 
183 private:
184  void paintButton(Graphics& g, bool isMouseOver, bool isButtonDown);
185 
186  int type;
187  int num;
188  Font buttonFont;
189  bool isActive;
190 };
191 
192 
193 #endif // __CHANNELSELECTOR_H_68124E35__