Open Ephys GUI
 All Classes Functions Variables Pages
EditorViewport.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 __EDITORVIEWPORT_H_80260F3F__
25 #define __EDITORVIEWPORT_H_80260F3F__
26 
27 #include "../../JuceLibraryCode/JuceHeader.h"
28 #include "../Processors/ProcessorGraph.h"
29 #include "../Processors/Editors/GenericEditor.h"
30 #include "../Processors/Editors/SplitterEditor.h"
31 #include "../Processors/Editors/MergerEditor.h"
32 
33 #include "../AccessClass.h"
34 #include "DataViewport.h"
35 
36 /**
37 
38  Allows the user to view and edit the signal chain.
39 
40  The EditorViewport is one of the most important classes in the GUI application.
41 
42  @see UIComponent, ProcessorGraph
43 
44 */
45 
46 class GenericEditor;
48 class SignalChainManager;
49 class EditorScrollButton;
51 
52 class EditorViewport : public Component,
53  public DragAndDropTarget,
54  public AccessClass,
55  public Button::Listener
56 
57 {
58 public:
59 
60  EditorViewport();//ProcessorGraph* pgraph, DataViewport* tabComp);
61  ~EditorViewport();
62 
63  void paint (Graphics& g);
64 
65  // Creating and deleting editors:
66  void deleteNode(GenericEditor* editor);
67  void selectEditor(GenericEditor* e);
68 
69  void makeEditorVisible(GenericEditor* e, bool highlight = true);
70  void makeEditorVisibleAndUpdateSettings(GenericEditor* e);
71  void refreshEditors();
72 
73  void clearSignalChain();
74 
75  void signalChainCanBeEdited(bool t);
76 
77  // DragAndDropTarget methods:
78  bool isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/);
79  void itemDragEnter (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*x*/, int /*y*/);
80  void itemDragMove (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*x*/, int /*y*/);
81  void itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/);
82  void itemDropped (const String& sourceDescription, Component* /*sourceComponent*/, int /*x*/, int /*y*/);
83 
84  // mouse and keypress methods:
85  void mouseDown(const MouseEvent &e);
86  void mouseDrag(const MouseEvent &e);
87  void mouseUp(const MouseEvent &e);
88  void mouseExit(const MouseEvent &e);
89  //void mouseEnter(const MouseEvent &e);
90  //void mouseExit
91  //void modifierKeysChanged (const ModifierKeys & modifiers);
92  bool keyPressed (const KeyPress &key);
93  void moveSelection( const KeyPress &key);
94  void buttonClicked(Button* button);
95 
96  Array<SignalChainTabButton*, CriticalSection> requestSignalChain() {return signalChainArray;}
97 
98  // loading and saving!
99  const String saveState();
100  const String loadState();
101 
102  XmlElement* createNodeXml(GenericEditor*, int);
103  XmlElement* switchNodeXml(GenericProcessor*);
104 
105  void checkScrollButtons(int topTab);
106 
107  bool isSignalChainEmpty();
108 
109  int leftmostEditor;
110 
111  File currentFile;
112 
113 private:
114 
115  String message;
116  bool somethingIsBeingDraggedOver;
117  bool shiftDown;
118 
119  bool canEdit;
120  GenericEditor* lastEditor;
121  GenericEditor* lastEditorClicked;
122 
123  int selectionIndex;
124 
125  Array<GenericEditor*, CriticalSection> editorArray;
126  Array<SignalChainTabButton*, CriticalSection> signalChainArray;
127 
128  ScopedPointer<SignalChainManager> signalChainManager;
129 
130  Font font;
131  Image sourceDropImage;
132 
133  void createNewTab(GenericEditor* editor);
134  void removeTab(int tabIndex);
135 
136  int borderSize, tabSize, tabButtonSize;
137 
138  int insertionPoint;
139  bool componentWantsToMove;
140  int indexOfMovingComponent;
141 
142  int currentTab;
143 
144  enum actions {ADD, MOVE, REMOVE, ACTIVATE, UPDATE};
145  enum directions1 {LEFT, RIGHT};
146  enum directions2 {UP, DOWN};
147 
148  EditorScrollButton* leftButton;
149  EditorScrollButton* rightButton;
150  SignalChainScrollButton* upButton;
151  SignalChainScrollButton* downButton;
152 
153  void resized();
154 
155  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EditorViewport);
156 
157 };
158 
159 class SignalChainTabButton : public Button
160 {
161 public:
164 
165  void setEditor(GenericEditor* p) {firstEditor = p;}
166  void setManager(SignalChainManager* scm_) {scm = scm_;}
167  GenericEditor* getEditor() {return firstEditor;}
168 
169  void setNumber(int n) {num = n;}
170 
171  bool hasNewConnections() {return configurationChanged;}
172  void hasNewConnections(bool t) {configurationChanged = t;}
173 
174  int offset;
175 
176 private:
177 
178  GenericEditor* firstEditor;
179 
180  SignalChainManager* scm;
181 
182  void paintButton(Graphics &g, bool isMouseOver, bool isButtonDown);
183 
184  void clicked();
185 
186  enum actions {ADD, MOVE, REMOVE, ACTIVATE};
187 
188  int num;
189  bool configurationChanged;
190 
191  Font buttonFont;
192 
193 };
194 
195 #endif // __EDITORVIEWPORT_H_80260F3F__