Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
363 lines (290 loc) · 11.6 KB

File metadata and controls

363 lines (290 loc) · 11.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
package dataModelFX;
import java.util.ArrayList;
import PamController.PamController;
import PamModel.PamModuleInfo;
import dataModelFX.ConnectionNodeParams.PAMConnectionNodeType;
import dataModelFX.connectionNodes.ModuleIconFactory;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Tooltip;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import pamViewFX.fxNodes.PamBorderPane;
import pamViewFX.fxNodes.PamScrollPane;
import pamViewFX.fxNodes.PamTilePane;
import pamViewFX.fxNodes.PamTitledPane;
import pamViewFX.fxNodes.PamVBox;
import pamViewFX.fxNodes.connectionPane.structures.ConnectionGroupBody;
import pamViewFX.fxNodes.connectionPane.structures.ExtensionSocketStructure;
import pamViewFX.fxStyles.PamStylesManagerFX;
/**
* A pane which shows a list of all the available modules. These can be dragged
* into the data model pane to create a module and add to the PAMGuarf data model.
*
* @author Jamie Macaulay
*
*/
public class DataModelModulePane extends PamBorderPane {
/**
* Reference to the data model pane.
*/
@SuppressWarnings("unused")
private DataModelPaneFX dataModelPaneFX;
/**
* List of possible modules (not the modules actually added to the model).
*/
private ArrayList<ModuleRectangle> moduleRectangles;
/**
* The main scroll panes holder
*/
private PamScrollPane moduleSelectPane;
//data for dragging modules between panes.
public static final String MODULE_DRAG_KEY="module";
public ObjectProperty<ModuleRectangle> draggingModule=new SimpleObjectProperty<>();
public ObjectProperty<StructureRectangle> draggingStructure=new SimpleObjectProperty<>();
public DataModelModulePane(DataModelPaneFX dataModelPaneFX) {
this.dataModelPaneFX=dataModelPaneFX;
this.setCenter(createPane());
}
private PamScrollPane createPane(){
moduleSelectPane=new PamScrollPane();
moduleSelectPane.getStylesheets().addAll(PamStylesManagerFX.getPamStylesManagerFX().getCurStyle().getSlidingDialogCSS());
moduleSelectPane.setPrefWidth(250);
moduleSelectPane.getStyleClass().add("scroll-pane-dark");
// //////TEST///////
// MenuButton m = new MenuButton("Add Modules ");
// m.showingProperty().addListener(new ChangeListener<Boolean>() {
// @Override
// public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
// if(newValue) {
// m.getItems().removeAll(m.getItems());
// m.getItems().add(PamModuleInfo.getModulesMenu(PamController.getInstance().getGuiManagerFX().getMainScene()));
// }
// }
// });
// //moduleSelectPane.add(m, 0, 0);
// ////////////////
moduleSelectPane.setFitToWidth(true);
return moduleSelectPane;
}
/**
* Update the list of modules.
* Task: 1) Makes modules which can no longer be added to the pane a different colours
* 2) Disables the module so it cannot be dragged,
*/
public void updateModuleListPane(){
for (int i=0; i<moduleRectangles.size(); i++){
if (moduleRectangles.get(i).getPamModuleInfo().getMaxNumber()>0){
int nModules=PamController.getInstance().findControlledUnits(moduleRectangles.get(i).getPamModuleInfo().getModuleClass()).size();
if (nModules>=moduleRectangles.get(i).getPamModuleInfo().getMaxNumber()){
//show disabled colour
moduleRectangles.get(i).setOpacity(ModuleNodeParams.DISABLED_OPACITY);
moduleRectangles.get(i).setDisable(true);
continue;
}
}
moduleRectangles.get(i).setOpacity(1);
moduleRectangles.get(i).setDisable(false);
}
}
/**
* Create a a set of module rectangles to populate the module list pane.
*/
protected void populateModuleListPane(){
moduleRectangles=new ArrayList<ModuleRectangle>();
//get the list of module
ArrayList<PamModuleInfo> moduleList = PamModuleInfo.getModuleList();
//list of module group names
ArrayList<String> moduleGroups=new ArrayList<String>();
//holder pane
PamVBox moduleSelectPane=new PamVBox();
//get all menu groups
String moduleGroup;
for (int i=0; i<moduleList.size(); i++){
moduleGroup=moduleList.get(i).getModulesMenuGroup().getMenuName();
if (!moduleGroups.contains(moduleGroup) && DataModelPaneFX.isFXModule(moduleList.get(i))) moduleGroups.add(moduleGroup);
moduleList.get(i).getModulesMenuGroup().getMenuName();
}
//create a set of titled panes
PamTitledPane[] titledPanes=new PamTitledPane[moduleGroups.size()];
//create tile pane to hold modules
PamTilePane[] moduleTilePanes=new PamTilePane[moduleGroups.size()];
for (int i=0; i<moduleGroups.size(); i++){
moduleTilePanes[i]=new PamTilePane(15,15);
moduleTilePanes[i].setPadding(new Insets(15));
moduleTilePanes[i].setPrefColumns(3);
titledPanes[i]=new PamTitledPane(moduleGroups.get(i), moduleTilePanes[i]);
//add modules to tile pane, only if in the correct group.
for (int j=0; j<moduleList.size(); j++){
moduleList.get(i).getModulesMenuGroup().getMenuName();
if (DataModelPaneFX.isFXModule(moduleList.get(j)) &&
moduleList.get(j).getModulesMenuGroup().getMenuName()==moduleGroups.get(i)) {
//add to list
moduleRectangles.add(createModuleRectangle(moduleList.get(j)));
moduleTilePanes[i].getChildren().add(moduleRectangles.get(moduleRectangles.size()-1));
}
}
moduleSelectPane.getChildren().add(titledPanes[i]);
}
moduleSelectPane.getChildren().add(createStucturePane());
//update colours
updateModuleListPane();
//
this.moduleSelectPane.setContent(moduleSelectPane);
}
/**
* Create a structure pane. This contains non module structures which can be used in the data model.
* Structures can be nodes which aggregate plugs, create groups of modules etc.
* @return the structure pane.
*/
private PamTitledPane createStucturePane() {
PamTilePane structurePane=new PamTilePane(15,15);
structurePane.setPadding(new Insets(15));
//now add all the structures we want.
StructureRectangle rect;
rect = createStructureRectangle(ConnectionGroupBody.getGroupStructureIcon(ModuleNodeParams.DEFAULT_WIDTH), PAMConnectionNodeType.PAMGroupStructure);
structurePane.getChildren().add(rect);
rect = createStructureRectangle(ExtensionSocketStructure.getStructureIcon(ModuleNodeParams.DEFAULT_WIDTH), PAMConnectionNodeType.PAMExtensionStructure);
structurePane.getChildren().add(rect);
PamTitledPane strcutureTitledPane = new PamTitledPane("Data Model Structures", structurePane);
return strcutureTitledPane;
}
/**
* Create an icon which represents a connection structure.,
* @param icon - the icon.
* @return the connection structure.
*/
private StructureRectangle createStructureRectangle(Node icon, PAMConnectionNodeType type){
//create the icon
StructureRectangle rect = new StructureRectangle(icon, type);
rect.setOnDragDetected(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event){
//only drag if can create
// if (pamModuleInfo.canCreate()) <- does not work for some reason; module
Dragboard dragboard = rect.startDragAndDrop(TransferMode.MOVE);
dragboard.setDragView(new ImageView(rect.snapshot(new SnapshotParameters(), null)).getImage());
ClipboardContent clipboardContent = new ClipboardContent();
clipboardContent.putString(MODULE_DRAG_KEY);
dragboard.setContent(clipboardContent);
draggingStructure.set(rect);
event.consume();
}
});
return rect;
}
/**
* Create a rectangle which represents the module.
* @param pamModuleInfo - module info
* @return the newly created rectangle.
*/
protected ModuleRectangle createModuleRectangle(PamModuleInfo pamModuleInfo){
Node icon=ModuleIconFactory.getInstance().getModuleNode(pamModuleInfo.getClassName());
ModuleRectangle rect;
if (icon==null) rect = new ModuleRectangle(pamModuleInfo, ModuleNodeParams.DEFAULT_WIDTH,ModuleNodeParams.DEFAULT_HEIGHT);
else rect = new ModuleRectangle(pamModuleInfo, icon, ModuleNodeParams.DEFAULT_WIDTH,ModuleNodeParams.DEFAULT_HEIGHT);
rect.setOnDragDetected(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event){
//only drag if can create
// if (pamModuleInfo.canCreate()) <- does not work for some reason; module
Dragboard dragboard = rect.startDragAndDrop(TransferMode.MOVE);
dragboard.setDragView(new ImageView(rect.snapshot(new SnapshotParameters(), null)).getImage());
ClipboardContent clipboardContent = new ClipboardContent();
clipboardContent.putString(MODULE_DRAG_KEY);
dragboard.setContent(clipboardContent);
draggingModule.set(rect);
event.consume();
}
});
Tooltip tp = new Tooltip(pamModuleInfo.getDefaultName());
tp.getStyleClass().removeAll(tp.getStyleClass());
Tooltip.install(rect, tp);
return rect;
}
/**
* A pane containing the icon for a structure.
* @author Jamie Macaulay
*
*/
public class StructureRectangle extends StackPane {
private PAMConnectionNodeType type;
public StructureRectangle(Node rectangle, PAMConnectionNodeType type ) {
this.getChildren().add(rectangle);
this.type=type;
}
public PAMConnectionNodeType getStructureType() {
return type;
}
}
/**
* Rectangle which holds reference to which type of module it's associated with.
* @author Jamie Macaulay
*
*/
class ModuleRectangle extends StackPane {
private static final double corner=15;
/**
* PamModuleInfo associated with the module rectangle.
*/
private PamModuleInfo pamModuleInfo;
public PamModuleInfo getPamModuleInfo() {
return pamModuleInfo;
}
public void setPamModuleInfo(PamModuleInfo pamModuleInfo) {
this.pamModuleInfo = pamModuleInfo;
}
ModuleRectangle(PamModuleInfo pamModuleInfo, double width, double height){
super();
this.pamModuleInfo=pamModuleInfo;
this.setWidth(width);
this.setHeight(height);
getChildren().add(createRect(width, height));
}
public ModuleRectangle(PamModuleInfo pamModuleInfo, Node imageIcon, double width, double height) {
super();
this.pamModuleInfo=pamModuleInfo;
//imageView.setOpacity(0.9);
getChildren().addAll(createRect(width, height), imageIcon);
}
private Rectangle createRect(double width, double height){
Rectangle rect=new Rectangle(width,height);
rect.setArcWidth(corner);
rect.setArcHeight(corner);
rect.setFill(new Color(ModuleNodeParams.DEFAULT_COLOUR[0],
ModuleNodeParams.DEFAULT_COLOUR[1],ModuleNodeParams.DEFAULT_COLOUR[2],1));
return rect;
}
}
/**
* Get the module drag key. Used for drag and drop listeners between module and connection panes.
* @return the module drag key string.
*/
public String getModuleDragKey() {
return DataModelModulePane.MODULE_DRAG_KEY;
}
/**
* Get the dragging module properties. Used for drag and drop listeners between module and connection panes.
* @return the dragging module properties
*/
public ObjectProperty<ModuleRectangle> getDraggingModule() {
return draggingModule;
}
/**
* Get the dragging structure properties. Used when dragging structures into the
* @return the dragging structure.
*/
public ObjectProperty<StructureRectangle> getDraggingStructure() {
return draggingStructure;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.