Browse Source

Improved the IDE: can now create new packages and source files within the IDE

Stan Hebben 6 years ago
parent
commit
e2af32d350
50 changed files with 794 additions and 189 deletions
  1. 1
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java
  2. 4
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourcePackage.java
  3. 23
    6
      DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java
  4. 6
    6
      DrawableGui/src/main/java/org/openzen/drawablegui/DButtonStyle.java
  5. 3
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java
  6. 34
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java
  7. 89
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DLabel.java
  8. 30
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DLabelStyle.java
  9. 4
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java
  10. 3
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java
  11. 2
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java
  12. 52
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DPaddedBorder.java
  13. 0
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/live/ImmutableLiveBool.java
  14. 31
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/ImmutableLiveString.java
  15. 6
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveArrayList.java
  16. 0
    6
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveBool.java
  17. 0
    25
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveConcatList.java
  18. 3
    23
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveEmptyList.java
  19. 2
    10
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveList.java
  20. 0
    25
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveMappedList.java
  21. 0
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LivePredicateBool.java
  22. 9
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LivePrefixedList.java
  23. 0
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveString.java
  24. 18
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveBool.java
  25. 22
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveList.java
  26. 14
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveString.java
  27. 1
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveBool.java
  28. 1
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveString.java
  29. 104
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/SortedLiveList.java
  30. 1
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDialog.java
  31. 4
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeNode.java
  32. 23
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java
  33. 4
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/IDEPackage.java
  34. 2
    1
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalLibrary.java
  35. 3
    1
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java
  36. 47
    8
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalPackage.java
  37. 4
    4
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalProjectDevelopmentHost.java
  38. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java
  39. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectToolbar.java
  40. 8
    29
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  41. 89
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreatePackageDialog.java
  42. 89
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java
  43. 2
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java
  44. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/LibraryTreeNode.java
  45. 1
    5
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ModuleTreeNode.java
  46. 28
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/PackageTreeNode.java
  47. 3
    3
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ProjectOverviewNode.java
  48. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ProjectTreeNode.java
  49. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/RootTreeNode.java
  50. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/SourceFileTreeNode.java

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java View File

106
 	}
106
 	}
107
 	
107
 	
108
 	private SourcePackage loadPackage(String name, File directory) {
108
 	private SourcePackage loadPackage(String name, File directory) {
109
-		SourcePackage pkg = new SourcePackage(name);
109
+		SourcePackage pkg = new SourcePackage(directory, name);
110
 		
110
 		
111
 		for (File file : directory.listFiles()) {
111
 		for (File file : directory.listFiles()) {
112
 			if (file.isDirectory()) {
112
 			if (file.isDirectory()) {

+ 4
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourcePackage.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.constructor.module;
6
 package org.openzen.zenscript.constructor.module;
7
 
7
 
8
+import java.io.File;
8
 import java.util.HashMap;
9
 import java.util.HashMap;
9
 import java.util.Map;
10
 import java.util.Map;
10
 
11
 
13
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
14
  */
15
  */
15
 public class SourcePackage {
16
 public class SourcePackage {
17
+	public final File directory;
16
 	public final String name;
18
 	public final String name;
17
 	public final Map<String, SourcePackage> subPackages = new HashMap<>();
19
 	public final Map<String, SourcePackage> subPackages = new HashMap<>();
18
 	public final Map<String, SourceFile> sourceFiles = new HashMap<>();
20
 	public final Map<String, SourceFile> sourceFiles = new HashMap<>();
19
 	
21
 	
20
-	public SourcePackage(String name) {
22
+	public SourcePackage(File directory, String name) {
23
+		this.directory = directory;
21
 		this.name = name;
24
 		this.name = name;
22
 	}
25
 	}
23
 	
26
 	

+ 23
- 6
DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java View File

9
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LiveString;
10
 import org.openzen.drawablegui.live.LiveString;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
+import org.openzen.drawablegui.style.DShadow;
12
 import org.openzen.drawablegui.style.DStyleClass;
13
 import org.openzen.drawablegui.style.DStyleClass;
13
 import org.openzen.drawablegui.style.DStylePath;
14
 import org.openzen.drawablegui.style.DStylePath;
14
 
15
 
21
 	private final LiveString label;
22
 	private final LiveString label;
22
 	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
23
 	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
23
 	private final LiveBool disabled;
24
 	private final LiveBool disabled;
25
+	private final Runnable action;
24
 	
26
 	
25
 	private DUIContext context;
27
 	private DUIContext context;
26
 	private DIRectangle bounds;
28
 	private DIRectangle bounds;
31
 	private boolean hovering = false;
33
 	private boolean hovering = false;
32
 	private boolean pressing = false;
34
 	private boolean pressing = false;
33
 	
35
 	
34
-	public DButton(DStyleClass styleClass, LiveString label, LiveBool disabled) {
36
+	public DButton(DStyleClass styleClass, LiveString label, LiveBool disabled, Runnable action) {
35
 		this.styleClass = styleClass;
37
 		this.styleClass = styleClass;
36
 		this.label = label;
38
 		this.label = label;
37
 		this.disabled = disabled;
39
 		this.disabled = disabled;
40
+		this.action = action;
38
 	}
41
 	}
39
 
42
 
40
 	@Override
43
 	@Override
44
 		DStylePath path = parent.getChild("Button", styleClass);
47
 		DStylePath path = parent.getChild("Button", styleClass);
45
 		this.style = new DButtonStyle(context.getStylesheets().get(context, path));
48
 		this.style = new DButtonStyle(context.getStylesheets().get(context, path));
46
 		fontMetrics = context.getFontMetrics(style.font);
49
 		fontMetrics = context.getFontMetrics(style.font);
50
+		
51
+		dimensionPreferences.setValue(new DDimensionPreferences(
52
+				style.paddingLeft + style.paddingRight + fontMetrics.getWidth(label.getValue()),
53
+				style.paddingTop + style.paddingBottom + fontMetrics.getAscent() + fontMetrics.getDescent()));
47
 	}
54
 	}
48
 
55
 
49
 	@Override
56
 	@Override
69
 	@Override
76
 	@Override
70
 	public void paint(DCanvas canvas) {
77
 	public void paint(DCanvas canvas) {
71
 		int backgroundColor = style.backgroundColorNormal;
78
 		int backgroundColor = style.backgroundColorNormal;
72
-		if (hovering)
79
+		DShadow shadow = style.shadowNormal;
80
+		if (hovering) {
73
 			backgroundColor = style.backgroundColorHover;
81
 			backgroundColor = style.backgroundColorHover;
74
-		if (pressing)
82
+			shadow = style.shadowNormal;
83
+		}
84
+		if (pressing) {
75
 			backgroundColor = style.backgroundColorPress;
85
 			backgroundColor = style.backgroundColorPress;
76
-		if (disabled.getValue())
86
+			shadow = style.shadowPress;
87
+		}
88
+		if (disabled.getValue()) {
77
 			backgroundColor = style.backgroundColorDisabled;
89
 			backgroundColor = style.backgroundColorDisabled;
90
+			shadow = style.shadowDisabled;
91
+		}
78
 		
92
 		
79
-		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, backgroundColor);
93
+		DPath shape = DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 2 * context.getScale());
94
+		canvas.shadowPath(shape, DTransform2D.IDENTITY, shadow);
95
+		canvas.fillPath(shape, DTransform2D.IDENTITY, backgroundColor);
96
+		canvas.drawText(style.font, style.textColor, bounds.x + style.paddingLeft, bounds.y + style.paddingTop + fontMetrics.getAscent(), label.getValue());
80
 	}
97
 	}
81
 
98
 
82
 	@Override
99
 	@Override
108
 		pressing = false;
125
 		pressing = false;
109
 		
126
 		
110
 		if (!disabled.getValue()) {
127
 		if (!disabled.getValue()) {
111
-			// TODO
128
+			action.run();
112
 		}
129
 		}
113
 		
130
 		
114
 		repaint();
131
 		repaint();

+ 6
- 6
DrawableGui/src/main/java/org/openzen/drawablegui/DButtonStyle.java View File

35
 	public DButtonStyle(DStyleDefinition style) {
35
 	public DButtonStyle(DStyleDefinition style) {
36
 		this.paddingTop = style.getDimension("paddingTop", new DDpDimension(4));
36
 		this.paddingTop = style.getDimension("paddingTop", new DDpDimension(4));
37
 		this.paddingBottom = style.getDimension("paddingBottom", new DDpDimension(4));
37
 		this.paddingBottom = style.getDimension("paddingBottom", new DDpDimension(4));
38
-		this.paddingLeft = style.getDimension("paddingLeft", new DDpDimension(4));
39
-		this.paddingRight = style.getDimension("paddingRight", new DDpDimension(4));
38
+		this.paddingLeft = style.getDimension("paddingLeft", new DDpDimension(8));
39
+		this.paddingRight = style.getDimension("paddingRight", new DDpDimension(8));
40
 		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getTextScale())));
40
 		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getTextScale())));
41
 		textColor = style.getColor("textColor", 0xFF000000);
41
 		textColor = style.getColor("textColor", 0xFF000000);
42
 		textColorDisabled = style.getColor("textColorDisabled", 0xFF888888);
42
 		textColorDisabled = style.getColor("textColorDisabled", 0xFF888888);
46
 		backgroundColorPress = style.getColor("backgroundColorPress", 0xFFE5EFF8);
46
 		backgroundColorPress = style.getColor("backgroundColorPress", 0xFFE5EFF8);
47
 		backgroundColorDisabled = style.getColor("backgroundColorDisabled", 0xFFE5EFF8);
47
 		backgroundColorDisabled = style.getColor("backgroundColorDisabled", 0xFFE5EFF8);
48
 		
48
 		
49
-		shadowNormal = style.getShadow("shadowNormal", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
50
-		shadowHover = style.getShadow("shadowHover", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
51
-		shadowPress = style.getShadow("shadowPress", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
52
-		shadowDisabled = style.getShadow("shadowDisabled", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
49
+		shadowNormal = style.getShadow("shadowNormal", context -> new DShadow(0xFF888888, 0, 1f * context.getScale(), 4 * context.getScale()));
50
+		shadowHover = style.getShadow("shadowHover", context -> new DShadow(0xFF888888, 0, 1f * context.getScale(), 4 * context.getScale()));
51
+		shadowPress = style.getShadow("shadowPress", context -> new DShadow(0xFF888888, 0, 1f * context.getScale(), 3 * context.getScale()));
52
+		shadowDisabled = style.getShadow("shadowDisabled", context -> new DShadow(0xFF888888, 0, 1f * context.getScale(), 3 * context.getScale()));
53
 	}
53
 	}
54
 }
54
 }

+ 3
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java View File

93
 	@Override
93
 	@Override
94
 	public void setBounds(DIRectangle bounds) {
94
 	public void setBounds(DIRectangle bounds) {
95
 		this.bounds = bounds;
95
 		this.bounds = bounds;
96
+		layout();
96
 	}
97
 	}
97
 
98
 
98
 	@Override
99
 	@Override
197
 				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
198
 				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
198
 				int newX = x + preferences.preferredWidth;
199
 				int newX = x + preferences.preferredWidth;
199
 				layout(element, x, newX - x);
200
 				layout(element, x, newX - x);
200
-				x = newX;
201
+				x = newX + style.spacing;
201
 			}
202
 			}
202
 		} else {
203
 		} else {
203
 			int delta = bounds.width - myPreferences.preferredWidth;
204
 			int delta = bounds.width - myPreferences.preferredWidth;
237
 				y = bounds.y + style.paddingTop;
238
 				y = bounds.y + style.paddingTop;
238
 				break;
239
 				break;
239
 		}
240
 		}
240
-		element.component.setBounds(new DIRectangle(bounds.x + x, y, width, height));
241
+		element.component.setBounds(new DIRectangle(x, y, width, height));
241
 	}
242
 	}
242
 	
243
 	
243
 	private void updateDimensionPreferences() {
244
 	private void updateDimensionPreferences() {

+ 34
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java View File

8
 import org.openzen.drawablegui.listeners.ListenerHandle;
8
 import org.openzen.drawablegui.listeners.ListenerHandle;
9
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LiveString;
10
 import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.MutableLiveString;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
 import org.openzen.drawablegui.style.DDimension;
13
 import org.openzen.drawablegui.style.DDimension;
13
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStyleClass;
18
  * @author Hoofdgebruiker
19
  * @author Hoofdgebruiker
19
  */
20
  */
20
 public class DInputField implements DComponent {
21
 public class DInputField implements DComponent {
21
-	public final LiveString value;
22
+	public final MutableLiveString value;
22
 	private final ListenerHandle<LiveString.Listener> valueListener;
23
 	private final ListenerHandle<LiveString.Listener> valueListener;
23
 	
24
 	
24
 	private final DStyleClass styleClass;
25
 	private final DStyleClass styleClass;
32
 	private int cursorFrom = -1;
33
 	private int cursorFrom = -1;
33
 	private int cursorTo = -1;
34
 	private int cursorTo = -1;
34
 	
35
 	
36
+	private Runnable onEnter = null;
37
+	private Runnable onEscape = null;
38
+	
35
 	private boolean cursorBlink = true;
39
 	private boolean cursorBlink = true;
36
 	private DTimerHandle blinkTimer;
40
 	private DTimerHandle blinkTimer;
37
 	
41
 	
38
-	public DInputField(DStyleClass styleClass, LiveString value, DDimension preferredWidth) {
42
+	public DInputField(DStyleClass styleClass, MutableLiveString value, DDimension preferredWidth) {
39
 		this.styleClass = styleClass;
43
 		this.styleClass = styleClass;
40
 		this.value = value;
44
 		this.value = value;
41
 		this.preferredWidth = preferredWidth;
45
 		this.preferredWidth = preferredWidth;
45
 		cursorTo = value.getValue().length();
49
 		cursorTo = value.getValue().length();
46
 	}
50
 	}
47
 	
51
 	
52
+	public void setOnEnter(Runnable onEnter) {
53
+		this.onEnter = onEnter;
54
+	}
55
+	
56
+	public void setOnEscape(Runnable onEscape) {
57
+		this.onEscape = onEscape;
58
+	}
59
+	
48
 	@Override
60
 	@Override
49
 	public void close() {
61
 	public void close() {
50
 		valueListener.close();
62
 		valueListener.close();
126
 		}
138
 		}
127
 	}
139
 	}
128
 	
140
 	
141
+	@Override
142
+	public void onMouseEnter(DMouseEvent e) {
143
+		context.setCursor(DUIContext.Cursor.TEXT);
144
+	}
145
+	
146
+	@Override
147
+	public void onMouseExit(DMouseEvent e) {
148
+		context.setCursor(DUIContext.Cursor.NORMAL);
149
+	}
150
+	
129
 	@Override
151
 	@Override
130
 	public void onMouseClick(DMouseEvent e) {
152
 	public void onMouseClick(DMouseEvent e) {
131
 		context.getWindow().focus(this);
153
 		context.getWindow().focus(this);
160
 			case ENTER:
182
 			case ENTER:
161
 				enter();
183
 				enter();
162
 				break;
184
 				break;
185
+			case ESCAPE:
186
+				escape();
187
+				break;
163
 			default:
188
 			default:
164
 				if (e.character == DKeyEvent.CHAR_UNDEFINED)
189
 				if (e.character == DKeyEvent.CHAR_UNDEFINED)
165
 					return;
190
 					return;
218
 	}
243
 	}
219
 	
244
 	
220
 	private void enter() {
245
 	private void enter() {
221
-		
246
+		if (onEnter != null)
247
+			onEnter.run();
248
+	}
249
+	
250
+	private void escape() {
251
+		if (onEscape != null)
252
+			onEscape.run();
222
 	}
253
 	}
223
 }
254
 }

+ 89
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DLabel.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.listeners.ListenerHandle;
9
+import org.openzen.drawablegui.live.LiveObject;
10
+import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.SimpleLiveObject;
12
+import org.openzen.drawablegui.style.DStyleClass;
13
+import org.openzen.drawablegui.style.DStylePath;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class DLabel implements DComponent {
20
+	private final LiveString label;
21
+	private final DStyleClass styleClass;
22
+	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
23
+	private final ListenerHandle<LiveString.Listener> labelListener;
24
+	
25
+	private DUIContext context;
26
+	private DIRectangle bounds;
27
+	private DLabelStyle style;
28
+	private DFontMetrics fontMetrics;
29
+	
30
+	public DLabel(DStyleClass styleClass, LiveString label) {
31
+		this.styleClass = styleClass;
32
+		this.label = label;
33
+		
34
+		labelListener = label.addListener(this::onLabelChanged);
35
+	}
36
+
37
+	@Override
38
+	public void setContext(DStylePath parent, DUIContext context) {
39
+		this.context = context;
40
+		
41
+		DStylePath path = parent.getChild("label", styleClass);
42
+		style = new DLabelStyle(context.getStylesheets().get(context, path));
43
+		
44
+		fontMetrics = context.getFontMetrics(style.font);
45
+		calculateDimension();
46
+	}
47
+
48
+	@Override
49
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
50
+		return preferences;
51
+	}
52
+
53
+	@Override
54
+	public DIRectangle getBounds() {
55
+		return bounds;
56
+	}
57
+
58
+	@Override
59
+	public int getBaselineY() {
60
+		return style.border.getPaddingTop() + fontMetrics.getAscent();
61
+	}
62
+
63
+	@Override
64
+	public void setBounds(DIRectangle bounds) {
65
+		this.bounds = bounds;
66
+	}
67
+
68
+	@Override
69
+	public void paint(DCanvas canvas) {
70
+		style.border.paint(canvas, bounds);
71
+		canvas.drawText(style.font, style.color, bounds.x + style.border.getPaddingLeft(), bounds.y + style.border.getPaddingTop() + fontMetrics.getAscent(), label.getValue());
72
+	}
73
+
74
+	@Override
75
+	public void close() {
76
+		labelListener.close();
77
+	}
78
+	
79
+	private void onLabelChanged(String oldValue, String newValue) {
80
+		calculateDimension();
81
+		context.repaint(bounds);
82
+	}
83
+	
84
+	private void calculateDimension() {
85
+		preferences.setValue(new DDimensionPreferences(
86
+			style.border.getPaddingLeft() + fontMetrics.getWidth(label.getValue()) + style.border.getPaddingRight(),
87
+			style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingTop()));
88
+	}
89
+}

+ 30
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DLabelStyle.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.border.DBorder;
9
+import org.openzen.drawablegui.border.DPaddedBorder;
10
+import org.openzen.drawablegui.style.DStyleDefinition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class DLabelStyle {
17
+	public final DBorder border;
18
+	public final DFont font;
19
+	public final int color;
20
+	
21
+	public DLabelStyle(DStyleDefinition style) {
22
+		border = style.getBorder("border", context -> new DPaddedBorder(
23
+				(int)(4 * context.getScale()),
24
+				(int)(4 * context.getScale()),
25
+				(int)(4 * context.getScale()),
26
+				(int)(4 * context.getScale())));
27
+		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getTextScale())));
28
+		color = style.getColor("color", 0xFF000000);
29
+	}
30
+}

+ 4
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java View File

40
 	
40
 	
41
 	DUIWindow openView(int x, int y, DAnchor anchor, DComponent root);
41
 	DUIWindow openView(int x, int y, DAnchor anchor, DComponent root);
42
 	
42
 	
43
+	default int dp(float dp) {
44
+		return (int)(dp * getScale());
45
+	}
46
+	
43
 	enum Cursor {
47
 	enum Cursor {
44
 		NORMAL,
48
 		NORMAL,
45
 		HAND,
49
 		HAND,

+ 3
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java View File

93
 	@Override
93
 	@Override
94
 	public void setBounds(DIRectangle bounds) {
94
 	public void setBounds(DIRectangle bounds) {
95
 		this.bounds = bounds;
95
 		this.bounds = bounds;
96
+		layout();
96
 	}
97
 	}
97
 
98
 
98
 	@Override
99
 	@Override
206
 			for (Element element : components) {
207
 			for (Element element : components) {
207
 				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
208
 				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
208
 				float scaledSize = preferences.preferredHeight + deltaScaled * element.grow;
209
 				float scaledSize = preferences.preferredHeight + deltaScaled * element.grow;
209
-				float idealUnspacedX = y + scaledSize;
210
-				int newY = (int)(idealUnspacedX + 0.5f);
210
+				float idealUnspacedY = y + scaledSize;
211
+				int newY = (int)(idealUnspacedY + 0.5f);
211
 				layout(element, y, newY - y);
212
 				layout(element, y, newY - y);
212
 				y = newY + style.spacing;
213
 				y = newY + style.spacing;
213
 			}
214
 			}

+ 2
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java View File

16
 public class DEmptyBorder implements DBorder {
16
 public class DEmptyBorder implements DBorder {
17
 	public static final DEmptyBorder INSTANCE = new DEmptyBorder();
17
 	public static final DEmptyBorder INSTANCE = new DEmptyBorder();
18
 	
18
 	
19
+	private DEmptyBorder() {}
20
+	
19
 	@Override
21
 	@Override
20
 	public void paint(DCanvas canvas, DIRectangle bounds) {
22
 	public void paint(DCanvas canvas, DIRectangle bounds) {
21
 		
23
 		

+ 52
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/border/DPaddedBorder.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.border;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DIRectangle;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DPaddedBorder implements DBorder {
16
+	private final int left;
17
+	private final int top;
18
+	private final int right;
19
+	private final int bottom;
20
+	
21
+	public DPaddedBorder(int left, int top, int right, int bottom) {
22
+		this.left = left;
23
+		this.top = top;
24
+		this.right = right;
25
+		this.bottom = bottom;
26
+	}
27
+
28
+	@Override
29
+	public void paint(DCanvas canvas, DIRectangle bounds) {
30
+		// nothing to paint
31
+	}
32
+
33
+	@Override
34
+	public int getPaddingLeft() {
35
+		return left;
36
+	}
37
+
38
+	@Override
39
+	public int getPaddingRight() {
40
+		return right;
41
+	}
42
+
43
+	@Override
44
+	public int getPaddingTop() {
45
+		return top;
46
+	}
47
+
48
+	@Override
49
+	public int getPaddingBottom() {
50
+		return bottom;
51
+	}
52
+}

+ 0
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/live/ImmutableLiveBool.java View File

27
 		return value;
27
 		return value;
28
 	}
28
 	}
29
 
29
 
30
-	@Override
31
-	public void setValue(boolean value) {
32
-		throw new UnsupportedOperationException("Cannot modify an immutable value");
33
-	}
34
-
35
 	@Override
30
 	@Override
36
 	public ListenerHandle<Listener> addListener(Listener listener) {
31
 	public ListenerHandle<Listener> addListener(Listener listener) {
37
 		return new DummyListenerHandle<>(listener);
32
 		return new DummyListenerHandle<>(listener);

+ 31
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/ImmutableLiveString.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+import org.openzen.drawablegui.listeners.DummyListenerHandle;
9
+import org.openzen.drawablegui.listeners.ListenerHandle;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class ImmutableLiveString implements LiveString {
16
+	private final String value;
17
+
18
+	public ImmutableLiveString(String value) {
19
+		this.value = value;
20
+	}
21
+	
22
+	@Override
23
+	public ListenerHandle<Listener> addListener(Listener listener) {
24
+		return new DummyListenerHandle<>(listener);
25
+	}
26
+
27
+	@Override
28
+	public String getValue() {
29
+		return value;
30
+	}
31
+}

+ 6
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveArrayList.java View File

15
  *
15
  *
16
  * @author Hoofdgebruiker
16
  * @author Hoofdgebruiker
17
  */
17
  */
18
-public class LiveArrayList<T> implements LiveList<T> {
18
+public class LiveArrayList<T> implements MutableLiveList<T> {
19
 	private final List<T> values = new ArrayList<>();
19
 	private final List<T> values = new ArrayList<>();
20
 	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
20
 	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
21
 
21
 
67
 	public T get(int index) {
67
 	public T get(int index) {
68
 		return values.get(index);
68
 		return values.get(index);
69
 	}
69
 	}
70
+	
71
+	@Override
72
+	public void close() {
73
+		// TODO: close closeables
74
+	}
70
 
75
 
71
 	@Override
76
 	@Override
72
 	public Iterator<T> iterator() {
77
 	public Iterator<T> iterator() {

+ 0
- 6
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveBool.java View File

14
 public interface LiveBool {
14
 public interface LiveBool {
15
 	public boolean getValue();
15
 	public boolean getValue();
16
 	
16
 	
17
-	public void setValue(boolean value);
18
-	
19
-	default void toggle() {
20
-		setValue(!getValue());
21
-	}
22
-	
23
 	public ListenerHandle<Listener> addListener(Listener listener);
17
 	public ListenerHandle<Listener> addListener(Listener listener);
24
 	
18
 	
25
 	public interface Listener {
19
 	public interface Listener {

+ 0
- 25
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveConcatList.java View File

36
 		bListener.close();
36
 		bListener.close();
37
 	}
37
 	}
38
 
38
 
39
-	@Override
40
-	public void add(T value) {
41
-		throw new UnsupportedOperationException("Cannot modify a concat list");
42
-	}
43
-
44
-	@Override
45
-	public void add(int index, T value) {
46
-		throw new UnsupportedOperationException("Cannot modify a concat list");
47
-	}
48
-
49
-	@Override
50
-	public void set(int index, T value) {
51
-		throw new UnsupportedOperationException("Cannot modify a concat list");
52
-	}
53
-
54
-	@Override
55
-	public void remove(int index) {
56
-		throw new UnsupportedOperationException("Cannot modify a concat list");
57
-	}
58
-
59
-	@Override
60
-	public void remove(T value) {
61
-		throw new UnsupportedOperationException("Cannot modify a concat list");
62
-	}
63
-
64
 	@Override
39
 	@Override
65
 	public int indexOf(T value) {
40
 	public int indexOf(T value) {
66
 		int result = a.indexOf(value);
41
 		int result = a.indexOf(value);

+ 3
- 23
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveEmptyList.java View File

20
 	public static <T> LiveEmptyList<T> get() {
20
 	public static <T> LiveEmptyList<T> get() {
21
 		return INSTANCE;
21
 		return INSTANCE;
22
 	}
22
 	}
23
-
24
-	@Override
25
-	public void add(T value) {
26
-		throw new UnsupportedOperationException("Immutable list");
27
-	}
28
-
29
-	@Override
30
-	public void add(int index, T value) {
31
-		throw new UnsupportedOperationException("Immutable list");
32
-	}
33
-
34
-	@Override
35
-	public void set(int index, T value) {
36
-		throw new UnsupportedOperationException("Immutable list");
37
-	}
38
-
39
-	@Override
40
-	public void remove(int index) {
41
-		throw new UnsupportedOperationException("Immutable list");
42
-	}
43
-
23
+	
44
 	@Override
24
 	@Override
45
-	public void remove(T value) {
46
-		throw new UnsupportedOperationException("Immutable list");
25
+	public void close() {
26
+		
47
 	}
27
 	}
48
 
28
 
49
 	@Override
29
 	@Override

+ 2
- 10
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveList.java View File

13
  * @author Hoofdgebruiker
13
  * @author Hoofdgebruiker
14
  */
14
  */
15
 public interface LiveList<T> extends Iterable<T> {
15
 public interface LiveList<T> extends Iterable<T> {
16
-	void add(T value);
17
-	
18
-	void add(int index, T value);
19
-	
20
-	void set(int index, T value);
21
-	
22
-	void remove(int index);
23
-	
24
-	void remove(T value);
25
-	
26
 	int indexOf(T value);
16
 	int indexOf(T value);
27
 	
17
 	
28
 	int size();
18
 	int size();
29
 	
19
 	
30
 	T get(int index);
20
 	T get(int index);
31
 	
21
 	
22
+	void close();
23
+	
32
 	@Override
24
 	@Override
33
 	Iterator<T> iterator();
25
 	Iterator<T> iterator();
34
 	
26
 	

+ 0
- 25
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveMappedList.java View File

37
 		mappingListenerHandle.close();
37
 		mappingListenerHandle.close();
38
 	}
38
 	}
39
 
39
 
40
-	@Override
41
-	public void add(U value) {
42
-		throw new UnsupportedOperationException("Cannot modify a mapped list");
43
-	}
44
-
45
-	@Override
46
-	public void add(int index, U value) {
47
-		throw new UnsupportedOperationException("Cannot modify a mapped list");
48
-	}
49
-
50
-	@Override
51
-	public void set(int index, U value) {
52
-		throw new UnsupportedOperationException("Cannot modify a mapped list");
53
-	}
54
-
55
-	@Override
56
-	public void remove(int index) {
57
-		throw new UnsupportedOperationException("Cannot modify a mapped list");
58
-	}
59
-
60
-	@Override
61
-	public void remove(U value) {
62
-		throw new UnsupportedOperationException("Cannot modify a mapped list");
63
-	}
64
-
65
 	@Override
40
 	@Override
66
 	public int indexOf(U value) {
41
 	public int indexOf(U value) {
67
 		return mapped.indexOf(value);
42
 		return mapped.indexOf(value);

+ 0
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/live/LivePredicateBool.java View File

32
 	public void close() {
32
 	public void close() {
33
 		sourceListener.close();
33
 		sourceListener.close();
34
 	}
34
 	}
35
-	
36
-	@Override
37
-	public void setValue(boolean value) {
38
-		throw new UnsupportedOperationException("Cannot modify a calculated value");
39
-	}
40
 
35
 
41
 	@Override
36
 	@Override
42
 	public boolean getValue() {
37
 	public boolean getValue() {

+ 9
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/live/LivePrefixedList.java View File

17
 	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
17
 	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
18
 	private final T prefix;
18
 	private final T prefix;
19
 	private final LiveList<T> values;
19
 	private final LiveList<T> values;
20
+	private final ListenerHandle<LiveList.Listener<T>> baseListener;
20
 	
21
 	
21
 	public LivePrefixedList(T prefix, LiveList<T> values) {
22
 	public LivePrefixedList(T prefix, LiveList<T> values) {
22
 		this.prefix = prefix;
23
 		this.prefix = prefix;
23
 		this.values = values;
24
 		this.values = values;
25
+		this.baseListener = values.addListener(new BaseListener());
24
 	}
26
 	}
25
-
27
+	
26
 	@Override
28
 	@Override
29
+	public void close() {
30
+		baseListener.close();
31
+	}
32
+
33
+	/*@Override
27
 	public void add(T value) {
34
 	public void add(T value) {
28
 		values.add(value);
35
 		values.add(value);
29
 	}
36
 	}
54
 	@Override
61
 	@Override
55
 	public void remove(T value) {
62
 	public void remove(T value) {
56
 		values.remove(value);
63
 		values.remove(value);
57
-	}
64
+	}*/
58
 
65
 
59
 	@Override
66
 	@Override
60
 	public int indexOf(T value) {
67
 	public int indexOf(T value) {

+ 0
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveString.java View File

16
 	
16
 	
17
 	String getValue();
17
 	String getValue();
18
 	
18
 	
19
-	void setValue(String value);
20
-	
21
 	interface Listener {
19
 	interface Listener {
22
 		void onChanged(String oldValue, String newValue);
20
 		void onChanged(String oldValue, String newValue);
23
 	}
21
 	}

+ 18
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveBool.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface MutableLiveBool extends LiveBool {
13
+	void setValue(boolean value);
14
+	
15
+	default void toggle() {
16
+		setValue(!getValue());
17
+	}
18
+}

+ 22
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveList.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface MutableLiveList<T> extends LiveList<T> {
13
+	void add(T value);
14
+	
15
+	void add(int index, T value);
16
+	
17
+	void set(int index, T value);
18
+	
19
+	void remove(int index);
20
+	
21
+	void remove(T value);
22
+}

+ 14
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveString.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface MutableLiveString extends LiveString {
13
+	void setValue(String value);
14
+}

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveBool.java View File

12
  *
12
  *
13
  * @author Hoofdgebruiker
13
  * @author Hoofdgebruiker
14
  */
14
  */
15
-public class SimpleLiveBool implements LiveBool {
15
+public class SimpleLiveBool implements MutableLiveBool {
16
 	private final ListenerList<LiveBool.Listener> listeners = new ListenerList<>();
16
 	private final ListenerList<LiveBool.Listener> listeners = new ListenerList<>();
17
 	private boolean value;
17
 	private boolean value;
18
 	
18
 	

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveString.java View File

12
  *
12
  *
13
  * @author Hoofdgebruiker
13
  * @author Hoofdgebruiker
14
  */
14
  */
15
-public class SimpleLiveString implements LiveString {
15
+public class SimpleLiveString implements MutableLiveString {
16
 	private final ListenerList<Listener> listeners = new ListenerList<>();
16
 	private final ListenerList<Listener> listeners = new ListenerList<>();
17
 	
17
 	
18
 	private String value;
18
 	private String value;

+ 104
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/SortedLiveList.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+import java.util.ArrayList;
9
+import java.util.Collections;
10
+import java.util.Comparator;
11
+import java.util.Iterator;
12
+import java.util.List;
13
+import org.openzen.drawablegui.listeners.ListenerHandle;
14
+import org.openzen.drawablegui.listeners.ListenerList;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class SortedLiveList<T> implements LiveList<T>, LiveList.Listener<T> {
21
+	private final LiveList<T> original;
22
+	private final Comparator<T> ordering;
23
+	private final List<T> sorted;
24
+	private final ListenerHandle<LiveList.Listener<T>> originalListener;
25
+	private final ListenerList<Listener<T>> listeners = new ListenerList<>();
26
+	
27
+	public SortedLiveList(LiveList<T> original, Comparator<T> ordering) {
28
+		this.original = original;
29
+		this.ordering = ordering;
30
+		
31
+		sorted = new ArrayList<>();
32
+		for (T item : original)
33
+			sorted.add(item);
34
+		
35
+		Collections.sort(sorted, ordering);
36
+		originalListener = original.addListener(this);
37
+	}
38
+	
39
+	@Override
40
+	public void close() {
41
+		original.close();
42
+		originalListener.close();
43
+	}
44
+
45
+	@Override
46
+	public int indexOf(T value) {
47
+		return sorted.indexOf(value);
48
+	}
49
+
50
+	@Override
51
+	public int size() {
52
+		return sorted.size();
53
+	}
54
+
55
+	@Override
56
+	public T get(int index) {
57
+		return sorted.get(index);
58
+	}
59
+
60
+	@Override
61
+	public Iterator<T> iterator() {
62
+		return sorted.iterator();
63
+	}
64
+
65
+	@Override
66
+	public ListenerHandle<Listener<T>> addListener(Listener<T> listener) {
67
+		return listeners.add(listener);
68
+	}
69
+
70
+	@Override
71
+	public void onInserted(int index, T value) {
72
+		internalAdd(value);
73
+	}
74
+
75
+	@Override
76
+	public void onChanged(int index, T oldValue, T newValue) {
77
+		internalRemove(oldValue);
78
+		internalAdd(newValue);
79
+	}
80
+
81
+	@Override
82
+	public void onRemoved(int index, T oldValue) {
83
+		internalRemove(oldValue);
84
+	}
85
+	
86
+	private void internalAdd(T value) {
87
+		int atIndex = 0;
88
+		while (atIndex < sorted.size() && ordering.compare(value, sorted.get(atIndex)) > 0)
89
+			atIndex++;
90
+		
91
+		sorted.add(atIndex, value);
92
+		final int finalAtIndex = atIndex;
93
+		listeners.accept(listener -> listener.onInserted(finalAtIndex, value));
94
+	}
95
+	
96
+	private void internalRemove(T value) {
97
+		int index = sorted.indexOf(value);
98
+		if (index < 0)
99
+			return;
100
+		
101
+		sorted.remove(index);
102
+		listeners.accept(listener -> listener.onRemoved(index, value));
103
+	}
104
+}

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDialog.java View File

87
 
87
 
88
 	@Override
88
 	@Override
89
 	public void close() {
89
 	public void close() {
90
-		System.exit(0);
90
+		dispose();
91
 	}
91
 	}
92
 
92
 
93
 	@Override
93
 	@Override

+ 4
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeNode.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DColorableIcon;
8
 import org.openzen.drawablegui.DColorableIcon;
9
 import org.openzen.drawablegui.DMouseEvent;
9
 import org.openzen.drawablegui.DMouseEvent;
10
-import org.openzen.drawablegui.live.LiveBool;
11
 import org.openzen.drawablegui.live.LiveList;
10
 import org.openzen.drawablegui.live.LiveList;
11
+import org.openzen.drawablegui.live.MutableLiveBool;
12
 
12
 
13
 /**
13
 /**
14
  *
14
  *
15
  * @author Hoofdgebruiker
15
  * @author Hoofdgebruiker
16
  */
16
  */
17
 public interface DTreeNode<N extends DTreeNode<N>> {
17
 public interface DTreeNode<N extends DTreeNode<N>> {
18
+	void close();
19
+	
18
 	DColorableIcon getIcon();
20
 	DColorableIcon getIcon();
19
 	
21
 	
20
 	String getTitle();
22
 	String getTitle();
21
 	
23
 	
22
 	LiveList<N> getChildren();
24
 	LiveList<N> getChildren();
23
 	
25
 	
24
-	LiveBool isCollapsed();
26
+	MutableLiveBool isCollapsed();
25
 	
27
 	
26
 	boolean isLeaf();
28
 	boolean isLeaf();
27
 	
29
 	

+ 23
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java View File

21
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.LiveObject;
22
 import org.openzen.drawablegui.live.SimpleLiveObject;
22
 import org.openzen.drawablegui.live.SimpleLiveObject;
23
 import org.openzen.drawablegui.DUIContext;
23
 import org.openzen.drawablegui.DUIContext;
24
+import org.openzen.drawablegui.live.LiveList;
24
 import org.openzen.drawablegui.style.DStylePath;
25
 import org.openzen.drawablegui.style.DStylePath;
25
 
26
 
26
 /**
27
 /**
217
 		// nothing to clean up
218
 		// nothing to clean up
218
 	}
219
 	}
219
 	
220
 	
220
-	private class Row implements Closeable, LiveBool.Listener {
221
+	private class Row implements Closeable, LiveBool.Listener, LiveList.Listener<N> {
221
 		private final int x;
222
 		private final int x;
222
 		private final N node;
223
 		private final N node;
223
 		private final ListenerHandle<LiveBool.Listener> collapseListener;
224
 		private final ListenerHandle<LiveBool.Listener> collapseListener;
225
+		private final ListenerHandle<LiveList.Listener<N>> childListener;
224
 		
226
 		
225
 		public Row(int x, N node) {
227
 		public Row(int x, N node) {
226
 			this.x = x;
228
 			this.x = x;
227
 			this.node = node;
229
 			this.node = node;
228
 			this.collapseListener = node.isCollapsed().addListener(this);
230
 			this.collapseListener = node.isCollapsed().addListener(this);
231
+			this.childListener = node.getChildren().addListener(this);
229
 		}
232
 		}
230
 
233
 
231
 		@Override
234
 		@Override
233
 			updateLayout();
236
 			updateLayout();
234
 			context.repaint(bounds);
237
 			context.repaint(bounds);
235
 		}
238
 		}
239
+
240
+		@Override
241
+		public void onInserted(int index, N value) {
242
+			updateLayout();
243
+			context.repaint(bounds);
244
+		}
245
+
246
+		@Override
247
+		public void onChanged(int index, N oldValue, N newValue) {
248
+			updateLayout();
249
+			context.repaint(bounds);
250
+		}
251
+
252
+		@Override
253
+		public void onRemoved(int index, N oldValue) {
254
+			updateLayout();
255
+			context.repaint(bounds);
256
+		}
236
 		
257
 		
237
 		@Override
258
 		@Override
238
 		public void close() {
259
 		public void close() {
239
 			collapseListener.close();
260
 			collapseListener.close();
261
+			childListener.close();
240
 		}
262
 		}
241
 	}
263
 	}
242
 }
264
 }

+ 4
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/IDEPackage.java View File

17
 	public LiveList<IDEPackage> getSubPackages();
17
 	public LiveList<IDEPackage> getSubPackages();
18
 	
18
 	
19
 	public LiveList<IDESourceFile> getSourceFiles();
19
 	public LiveList<IDESourceFile> getSourceFiles();
20
+	
21
+	public IDEPackage createSubPackage(String name);
22
+	
23
+	public IDESourceFile createSourceFile(String name);
20
 }
24
 }

+ 2
- 1
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalLibrary.java View File

7
 
7
 
8
 import org.openzen.drawablegui.live.LiveArrayList;
8
 import org.openzen.drawablegui.live.LiveArrayList;
9
 import org.openzen.drawablegui.live.LiveList;
9
 import org.openzen.drawablegui.live.LiveList;
10
+import org.openzen.drawablegui.live.MutableLiveList;
10
 import org.openzen.zenscript.constructor.Library;
11
 import org.openzen.zenscript.constructor.Library;
11
 import org.openzen.zenscript.constructor.module.ModuleReference;
12
 import org.openzen.zenscript.constructor.module.ModuleReference;
12
 import org.openzen.zenscript.ide.host.IDELibrary;
13
 import org.openzen.zenscript.ide.host.IDELibrary;
18
  */
19
  */
19
 public class LocalLibrary implements IDELibrary {
20
 public class LocalLibrary implements IDELibrary {
20
 	private final Library library;
21
 	private final Library library;
21
-	private final LiveList<IDEModule> modules;
22
+	private final MutableLiveList<IDEModule> modules;
22
 	
23
 	
23
 	public LocalLibrary(Library library) {
24
 	public LocalLibrary(Library library) {
24
 		this.library = library;
25
 		this.library = library;

+ 3
- 1
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java View File

15
  */
15
  */
16
 public class LocalModule implements IDEModule {
16
 public class LocalModule implements IDEModule {
17
 	private final ModuleReference module;
17
 	private final ModuleReference module;
18
+	private final LocalPackage rootPackage;
18
 	
19
 	
19
 	public LocalModule(ModuleReference module) {
20
 	public LocalModule(ModuleReference module) {
20
 		this.module = module;
21
 		this.module = module;
22
+		rootPackage = new LocalPackage(module.getRootPackage());
21
 	}
23
 	}
22
 
24
 
23
 	@Override
25
 	@Override
27
 
29
 
28
 	@Override
30
 	@Override
29
 	public IDEPackage getRootPackage() {
31
 	public IDEPackage getRootPackage() {
30
-		return new LocalPackage(module.getRootPackage());
32
+		return rootPackage;
31
 	}
33
 	}
32
 }
34
 }

+ 47
- 8
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalPackage.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
+import java.io.File;
9
+import java.io.IOException;
8
 import java.util.Arrays;
10
 import java.util.Arrays;
9
 import org.openzen.drawablegui.live.LiveArrayList;
11
 import org.openzen.drawablegui.live.LiveArrayList;
10
 import org.openzen.drawablegui.live.LiveList;
12
 import org.openzen.drawablegui.live.LiveList;
13
+import org.openzen.drawablegui.live.MutableLiveList;
14
+import org.openzen.drawablegui.live.SortedLiveList;
15
+import org.openzen.zenscript.constructor.module.SourceFile;
11
 import org.openzen.zenscript.constructor.module.SourcePackage;
16
 import org.openzen.zenscript.constructor.module.SourcePackage;
12
 import org.openzen.zenscript.ide.host.IDEPackage;
17
 import org.openzen.zenscript.ide.host.IDEPackage;
13
 import org.openzen.zenscript.ide.host.IDESourceFile;
18
 import org.openzen.zenscript.ide.host.IDESourceFile;
18
  */
23
  */
19
 public class LocalPackage implements IDEPackage {
24
 public class LocalPackage implements IDEPackage {
20
 	private final SourcePackage pkg;
25
 	private final SourcePackage pkg;
21
-	private final LiveList<IDEPackage> subPackages = new LiveArrayList<>();
22
-	private final LiveList<IDESourceFile> sourceFiles = new LiveArrayList<>();
26
+	private final MutableLiveList<IDEPackage> subPackages = new LiveArrayList<>();
27
+	private final MutableLiveList<IDESourceFile> sourceFiles = new LiveArrayList<>();
28
+	
29
+	private final LiveList<IDEPackage> subPackagesSorted;
30
+	private final LiveList<IDESourceFile> sourceFilesSorted;
23
 	
31
 	
24
 	public LocalPackage(SourcePackage pkg) {
32
 	public LocalPackage(SourcePackage pkg) {
25
 		this.pkg = pkg;
33
 		this.pkg = pkg;
32
 				.toArray(new String[pkg.sourceFiles.size()]);
40
 				.toArray(new String[pkg.sourceFiles.size()]);
33
 		Arrays.sort(sourceFileKeys);
41
 		Arrays.sort(sourceFileKeys);
34
 		
42
 		
35
-		for (String subKey : subPackageKeys) {
36
-			subPackages.add(new LocalPackage(pkg.subPackages.get(subKey)));
43
+		for (SourcePackage subPackage : pkg.subPackages.values()) {
44
+			subPackages.add(new LocalPackage(subPackage));
37
 		}
45
 		}
38
-		for (String sourceFileKey : sourceFileKeys) {
39
-			sourceFiles.add(new LocalSourceFile(pkg.sourceFiles.get(sourceFileKey)));
46
+		for (SourceFile sourceFile : pkg.sourceFiles.values()) {
47
+			sourceFiles.add(new LocalSourceFile(sourceFile));
40
 		}
48
 		}
49
+		
50
+		subPackagesSorted = new SortedLiveList<>(subPackages, (a, b) -> a.getName().compareTo(b.getName()));
51
+		sourceFilesSorted = new SortedLiveList<>(sourceFiles, (a, b) -> a.getName().compareTo(b.getName()));
41
 	}
52
 	}
42
 	
53
 	
43
 	@Override
54
 	@Override
47
 
58
 
48
 	@Override
59
 	@Override
49
 	public LiveList<IDEPackage> getSubPackages() {
60
 	public LiveList<IDEPackage> getSubPackages() {
50
-		return subPackages;
61
+		return subPackagesSorted;
51
 	}
62
 	}
52
 
63
 
53
 	@Override
64
 	@Override
54
 	public LiveList<IDESourceFile> getSourceFiles() {
65
 	public LiveList<IDESourceFile> getSourceFiles() {
55
-		return sourceFiles;
66
+		return sourceFilesSorted;
67
+	}
68
+	
69
+	@Override
70
+	public IDEPackage createSubPackage(String name) {
71
+		File file = new File(this.pkg.directory, name);
72
+		file.mkdir();
73
+		
74
+		SourcePackage sourcePackage = new SourcePackage(file, name);
75
+		IDEPackage pkg = new LocalPackage(sourcePackage);
76
+		this.pkg.subPackages.put(name, sourcePackage);
77
+		subPackages.add(pkg);
78
+		return pkg;
79
+	}
80
+	
81
+	@Override
82
+	public IDESourceFile createSourceFile(String name) {
83
+		File file = new File(this.pkg.directory, name);
84
+		try {
85
+			file.createNewFile();
86
+		} catch (IOException ex) {
87
+			ex.printStackTrace(); // TODO
88
+		}
89
+		
90
+		SourceFile sourceFile = new SourceFile(name, file);
91
+		IDESourceFile localSourceFile = new LocalSourceFile(sourceFile);
92
+		this.pkg.sourceFiles.put(name, sourceFile);
93
+		sourceFiles.add(localSourceFile);
94
+		return localSourceFile;
56
 	}
95
 	}
57
 }
96
 }

+ 4
- 4
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalProjectDevelopmentHost.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
-import java.util.List;
9
 import org.openzen.drawablegui.live.LiveArrayList;
8
 import org.openzen.drawablegui.live.LiveArrayList;
10
 import org.openzen.drawablegui.live.LiveList;
9
 import org.openzen.drawablegui.live.LiveList;
10
+import org.openzen.drawablegui.live.MutableLiveList;
11
 import org.openzen.zenscript.constructor.Library;
11
 import org.openzen.zenscript.constructor.Library;
12
 import org.openzen.zenscript.constructor.Project;
12
 import org.openzen.zenscript.constructor.Project;
13
 import org.openzen.zenscript.constructor.module.ModuleReference;
13
 import org.openzen.zenscript.constructor.module.ModuleReference;
23
  */
23
  */
24
 public class LocalProjectDevelopmentHost implements DevelopmentHost {
24
 public class LocalProjectDevelopmentHost implements DevelopmentHost {
25
 	private final Project project;
25
 	private final Project project;
26
-	private final LiveList<IDEModule> modules;
27
-	private final LiveList<IDELibrary> libraries;
28
-	private final LiveList<IDETarget> targets;
26
+	private final MutableLiveList<IDEModule> modules;
27
+	private final MutableLiveList<IDELibrary> libraries;
28
+	private final MutableLiveList<IDETarget> targets;
29
 	
29
 	
30
 	public LocalProjectDevelopmentHost(Project project) {
30
 	public LocalProjectDevelopmentHost(Project project) {
31
 		this.project = project;
31
 		this.project = project;

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java View File

6
 package org.openzen.zenscript.ide.ui;
6
 package org.openzen.zenscript.ide.ui;
7
 
7
 
8
 import org.openzen.drawablegui.live.LiveArrayList;
8
 import org.openzen.drawablegui.live.LiveArrayList;
9
-import org.openzen.drawablegui.live.LiveList;
10
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
10
+import org.openzen.drawablegui.live.MutableLiveList;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
 
12
 
13
 /**
13
 /**
15
  * @author Hoofdgebruiker
15
  * @author Hoofdgebruiker
16
  */
16
  */
17
 public class IDEAspectBar {
17
 public class IDEAspectBar {
18
-	public final LiveList<IDEAspectToolbar> toolbars = new LiveArrayList<>();
18
+	public final MutableLiveList<IDEAspectToolbar> toolbars = new LiveArrayList<>();
19
 	public final LiveObject<IDEAspectToolbar> active = new SimpleLiveObject<>(null);
19
 	public final LiveObject<IDEAspectToolbar> active = new SimpleLiveObject<>(null);
20
 }
20
 }

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectToolbar.java View File

7
 
7
 
8
 import org.openzen.drawablegui.DDrawable;
8
 import org.openzen.drawablegui.DDrawable;
9
 import org.openzen.drawablegui.live.LiveArrayList;
9
 import org.openzen.drawablegui.live.LiveArrayList;
10
-import org.openzen.drawablegui.live.LiveList;
10
+import org.openzen.drawablegui.live.MutableLiveList;
11
 
11
 
12
 /**
12
 /**
13
  *
13
  *
18
 	public final DDrawable icon;
18
 	public final DDrawable icon;
19
 	public final String title;
19
 	public final String title;
20
 	public final String description;
20
 	public final String description;
21
-	public final LiveList<IDEAspectBarControl> controls = new LiveArrayList<>();
21
+	public final MutableLiveList<IDEAspectBarControl> controls = new LiveArrayList<>();
22
 	
22
 	
23
 	public IDEAspectToolbar(int order, DDrawable icon, String title, String description) {
23
 	public IDEAspectToolbar(int order, DDrawable icon, String title, String description) {
24
 		this.order = order;
24
 		this.order = order;

+ 8
- 29
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.ui;
6
 package org.openzen.zenscript.ide.ui;
7
 
7
 
8
-import org.openzen.drawablegui.DAnchor;
9
-import org.openzen.drawablegui.DComponent;
10
-import org.openzen.drawablegui.DEmptyView;
11
-import org.openzen.drawablegui.DIRectangle;
12
-import org.openzen.drawablegui.DInputField;
13
-import org.openzen.drawablegui.DUIWindow;
14
-import org.openzen.drawablegui.form.DForm;
15
-import org.openzen.drawablegui.form.DFormComponent;
16
 import org.openzen.drawablegui.live.LiveBool;
8
 import org.openzen.drawablegui.live.LiveBool;
17
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
18
 import org.openzen.drawablegui.live.LivePredicateBool;
10
 import org.openzen.drawablegui.live.LivePredicateBool;
19
-import org.openzen.drawablegui.live.SimpleLiveBool;
20
 import org.openzen.drawablegui.live.SimpleLiveObject;
11
 import org.openzen.drawablegui.live.SimpleLiveObject;
21
-import org.openzen.drawablegui.live.SimpleLiveString;
22
-import org.openzen.drawablegui.style.DDpDimension;
23
 import org.openzen.drawablegui.style.DStyleClass;
12
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.zenscript.ide.host.DevelopmentHost;
13
 import org.openzen.zenscript.ide.host.DevelopmentHost;
25
 import org.openzen.zenscript.ide.host.IDEModule;
14
 import org.openzen.zenscript.ide.host.IDEModule;
26
 import org.openzen.zenscript.ide.host.IDEPackage;
15
 import org.openzen.zenscript.ide.host.IDEPackage;
27
 import org.openzen.zenscript.ide.host.IDESourceFile;
16
 import org.openzen.zenscript.ide.host.IDESourceFile;
28
 import org.openzen.zenscript.ide.host.IDETarget;
17
 import org.openzen.zenscript.ide.host.IDETarget;
18
+import org.openzen.zenscript.ide.ui.dialog.CreatePackageDialog;
19
+import org.openzen.zenscript.ide.ui.dialog.CreateSourceFileDialog;
29
 import org.openzen.zenscript.ide.ui.icons.AddBoxIcon;
20
 import org.openzen.zenscript.ide.ui.icons.AddBoxIcon;
30
 import org.openzen.zenscript.ide.ui.icons.BuildIcon;
21
 import org.openzen.zenscript.ide.ui.icons.BuildIcon;
31
 import org.openzen.zenscript.ide.ui.icons.PlayIcon;
22
 import org.openzen.zenscript.ide.ui.icons.PlayIcon;
76
 	private void init() {
67
 	private void init() {
77
 		projectToolbar = new IDEAspectToolbar(0, ShadedProjectIcon.PURPLE, "Project", "Project management");
68
 		projectToolbar = new IDEAspectToolbar(0, ShadedProjectIcon.PURPLE, "Project", "Project management");
78
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.BLUE, AddBoxIcon.GRAY, addContentDisabled, e -> {
69
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.BLUE, AddBoxIcon.GRAY, addContentDisabled, e -> {
79
-			DComponent input = new DInputField(DStyleClass.EMPTY, new SimpleLiveString(""), new DDpDimension(100));
80
-			DForm root = new DForm(DStyleClass.EMPTY, new DFormComponent("Package name:", input));
81
-			
82
-			DUIWindow window = e.window;
83
-			DIRectangle rectangle = window.getWindowBounds();
84
-			DUIWindow newWindow = e.window.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_LEFT, "Create package", root);
85
-			
86
-			newWindow.focus(input);
70
+			CreatePackageDialog dialog = new CreatePackageDialog(this, contextModule.getValue(), contextPackage.getValue());
71
+			dialog.open(e.window);
87
 		}));
72
 		}));
88
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, AddBoxIcon.GRAY, addContentDisabled, e -> {
73
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, AddBoxIcon.GRAY, addContentDisabled, e -> {
89
-			DComponent input = new DInputField(DStyleClass.EMPTY, new SimpleLiveString(""), new DDpDimension(100));
90
-			DForm root = new DForm(DStyleClass.EMPTY, new DFormComponent("Filename:", input));
91
-			
92
-			DUIWindow window = e.window;
93
-			DIRectangle rectangle = window.getWindowBounds();
94
-			DUIWindow newWindow = e.window.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_LEFT, "Create file", root);
95
-			
96
-			newWindow.focus(input);
74
+			CreateSourceFileDialog dialog = new CreateSourceFileDialog(this, contextModule.getValue(), contextPackage.getValue());
75
+			dialog.open(e.window);
97
 		}));
76
 		}));
98
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, e -> {
77
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, e -> {
99
 			
78
 			
119
 		contextFile.setValue(null);
98
 		contextFile.setValue(null);
120
 	}
99
 	}
121
 	
100
 	
122
-	public void setContextPackage(IDEPackage pkg) {
123
-		contextModule.setValue(null);
101
+	public void setContextPackage(IDEModule module, IDEPackage pkg) {
102
+		contextModule.setValue(module);
124
 		contextPackage.setValue(pkg);
103
 		contextPackage.setValue(pkg);
125
 		contextFile.setValue(null);
104
 		contextFile.setValue(null);
126
 	}
105
 	}

+ 89
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreatePackageDialog.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.dialog;
7
+
8
+import org.openzen.drawablegui.DAnchor;
9
+import org.openzen.drawablegui.DButton;
10
+import org.openzen.drawablegui.DComponent;
11
+import org.openzen.drawablegui.DHorizontalLayout;
12
+import org.openzen.drawablegui.DIRectangle;
13
+import org.openzen.drawablegui.DInputField;
14
+import org.openzen.drawablegui.DLabel;
15
+import org.openzen.drawablegui.DUIWindow;
16
+import org.openzen.drawablegui.DVerticalLayout;
17
+import org.openzen.drawablegui.form.DForm;
18
+import org.openzen.drawablegui.form.DFormComponent;
19
+import org.openzen.drawablegui.live.ImmutableLiveBool;
20
+import org.openzen.drawablegui.live.ImmutableLiveString;
21
+import org.openzen.drawablegui.live.SimpleLiveString;
22
+import org.openzen.drawablegui.style.DDpDimension;
23
+import org.openzen.drawablegui.style.DStyleClass;
24
+import org.openzen.zenscript.ide.host.IDEModule;
25
+import org.openzen.zenscript.ide.host.IDEPackage;
26
+import org.openzen.zenscript.ide.ui.IDEWindow;
27
+
28
+/**
29
+ *
30
+ * @author Hoofdgebruiker
31
+ */
32
+public class CreatePackageDialog {
33
+	private final IDEWindow ideWindow;
34
+	private final IDEModule module;
35
+	private final IDEPackage pkg;
36
+	
37
+	private final SimpleLiveString name;
38
+	
39
+	private final DComponent root;
40
+	private final DInputField input;
41
+	
42
+	private DUIWindow window;
43
+	
44
+	public CreatePackageDialog(IDEWindow ideWindow, IDEModule module, IDEPackage pkg) {
45
+		this.ideWindow = ideWindow;
46
+		this.module = module;
47
+		this.pkg = pkg;
48
+		
49
+		name = new SimpleLiveString("");
50
+		input = new DInputField(DStyleClass.EMPTY, name, new DDpDimension(100));
51
+		input.setOnEnter(this::ok);
52
+		input.setOnEscape(this::cancel);
53
+		
54
+		DForm form = new DForm(
55
+				DStyleClass.EMPTY,
56
+				new DFormComponent("Module:", new DLabel(DStyleClass.EMPTY, new ImmutableLiveString(module.getName()))),
57
+				new DFormComponent("Parent package:", new DLabel(DStyleClass.EMPTY, new ImmutableLiveString(pkg.getName().isEmpty() ? "(module root)" : pkg.getName()))),
58
+				new DFormComponent("Package name:", input));
59
+
60
+		DButton ok = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Create"), ImmutableLiveBool.FALSE, this::ok);
61
+		DButton cancel = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Cancel"), ImmutableLiveBool.FALSE, this::cancel);
62
+		DHorizontalLayout buttons = new DHorizontalLayout(
63
+				DStyleClass.EMPTY,
64
+				DHorizontalLayout.Alignment.RIGHT,
65
+				new DHorizontalLayout.Element(cancel, 0, 0, DHorizontalLayout.ElementAlignment.TOP),
66
+				new DHorizontalLayout.Element(ok, 0, 0, DHorizontalLayout.ElementAlignment.TOP));
67
+
68
+		root = new DVerticalLayout(
69
+				DStyleClass.EMPTY,
70
+				DVerticalLayout.Alignment.MIDDLE,
71
+				new DVerticalLayout.Element(form, 1, 1, DVerticalLayout.ElementAlignment.CENTER),
72
+				new DVerticalLayout.Element(buttons, 0, 0, DVerticalLayout.ElementAlignment.RIGHT));
73
+	}
74
+	
75
+	public void open(DUIWindow parent) {
76
+		DIRectangle rectangle = parent.getWindowBounds();
77
+		window = parent.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_LEFT, "Create package", root);
78
+		window.focus(input);
79
+	}
80
+	
81
+	private void cancel() {
82
+		window.close();
83
+	}
84
+	
85
+	private void ok() {
86
+		window.close();
87
+		pkg.createSubPackage(name.getValue());
88
+	}
89
+}

+ 89
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java View File

1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.dialog;
7
+
8
+import org.openzen.drawablegui.DAnchor;
9
+import org.openzen.drawablegui.DButton;
10
+import org.openzen.drawablegui.DComponent;
11
+import org.openzen.drawablegui.DHorizontalLayout;
12
+import org.openzen.drawablegui.DIRectangle;
13
+import org.openzen.drawablegui.DInputField;
14
+import org.openzen.drawablegui.DLabel;
15
+import org.openzen.drawablegui.DUIWindow;
16
+import org.openzen.drawablegui.DVerticalLayout;
17
+import org.openzen.drawablegui.form.DForm;
18
+import org.openzen.drawablegui.form.DFormComponent;
19
+import org.openzen.drawablegui.live.ImmutableLiveBool;
20
+import org.openzen.drawablegui.live.ImmutableLiveString;
21
+import org.openzen.drawablegui.live.SimpleLiveString;
22
+import org.openzen.drawablegui.style.DDpDimension;
23
+import org.openzen.drawablegui.style.DStyleClass;
24
+import org.openzen.zenscript.ide.host.IDEModule;
25
+import org.openzen.zenscript.ide.host.IDEPackage;
26
+import org.openzen.zenscript.ide.ui.IDEWindow;
27
+
28
+/**
29
+ *
30
+ * @author Hoofdgebruiker
31
+ */
32
+public class CreateSourceFileDialog {
33
+	private final IDEWindow ideWindow;
34
+	private final IDEModule module;
35
+	private final IDEPackage pkg;
36
+	
37
+	private final SimpleLiveString name;
38
+	
39
+	private final DComponent root;
40
+	private final DInputField input;
41
+	
42
+	private DUIWindow window;
43
+	
44
+	public CreateSourceFileDialog(IDEWindow ideWindow, IDEModule module, IDEPackage pkg) {
45
+		this.ideWindow = ideWindow;
46
+		this.module = module;
47
+		this.pkg = pkg;
48
+		
49
+		name = new SimpleLiveString("");
50
+		input = new DInputField(DStyleClass.EMPTY, name, new DDpDimension(100));
51
+		input.setOnEnter(this::ok);
52
+		input.setOnEscape(this::cancel);
53
+		
54
+		DForm form = new DForm(
55
+				DStyleClass.EMPTY,
56
+				new DFormComponent("Module:", new DLabel(DStyleClass.EMPTY, new ImmutableLiveString(module.getName()))),
57
+				new DFormComponent("Package:", new DLabel(DStyleClass.EMPTY, new ImmutableLiveString(pkg.getName().isEmpty() ? "(module root)" : pkg.getName()))),
58
+				new DFormComponent("Filename:", input));
59
+
60
+		DButton ok = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Create"), ImmutableLiveBool.FALSE, this::ok);
61
+		DButton cancel = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Cancel"), ImmutableLiveBool.FALSE, this::cancel);
62
+		DHorizontalLayout buttons = new DHorizontalLayout(
63
+				DStyleClass.EMPTY,
64
+				DHorizontalLayout.Alignment.RIGHT,
65
+				new DHorizontalLayout.Element(cancel, 0, 0, DHorizontalLayout.ElementAlignment.TOP),
66
+				new DHorizontalLayout.Element(ok, 0, 0, DHorizontalLayout.ElementAlignment.TOP));
67
+
68
+		root = new DVerticalLayout(
69
+				DStyleClass.EMPTY,
70
+				DVerticalLayout.Alignment.MIDDLE,
71
+				new DVerticalLayout.Element(form, 1, 1, DVerticalLayout.ElementAlignment.CENTER),
72
+				new DVerticalLayout.Element(buttons, 0, 0, DVerticalLayout.ElementAlignment.RIGHT));
73
+	}
74
+	
75
+	public void open(DUIWindow parent) {
76
+		DIRectangle rectangle = parent.getWindowBounds();
77
+		window = parent.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_LEFT, "Create source file", root);
78
+		window.focus(input);
79
+	}
80
+	
81
+	private void cancel() {
82
+		window.close();
83
+	}
84
+	
85
+	private void ok() {
86
+		window.close();
87
+		pkg.createSourceFile(name.getValue() + ".zs");
88
+	}
89
+}

+ 2
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java View File

19
 import org.openzen.drawablegui.live.LiveList;
19
 import org.openzen.drawablegui.live.LiveList;
20
 import org.openzen.drawablegui.live.LiveMappedList;
20
 import org.openzen.drawablegui.live.LiveMappedList;
21
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.LiveObject;
22
+import org.openzen.drawablegui.live.MutableLiveList;
22
 import org.openzen.drawablegui.live.SimpleLiveObject;
23
 import org.openzen.drawablegui.live.SimpleLiveObject;
23
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.drawablegui.style.DStylePath;
25
 import org.openzen.drawablegui.style.DStylePath;
29
  */
30
  */
30
 public class TabbedView extends BaseComponentGroup {
31
 public class TabbedView extends BaseComponentGroup {
31
 	private final DStyleClass styleClass;
32
 	private final DStyleClass styleClass;
32
-	public final LiveList<TabbedViewComponent> tabs = new LiveArrayList<>();
33
+	public final MutableLiveList<TabbedViewComponent> tabs = new LiveArrayList<>();
33
 	private final LiveObject<DDimensionPreferences> preferences = new ImmutableLiveObject<>(DDimensionPreferences.EMPTY);
34
 	private final LiveObject<DDimensionPreferences> preferences = new ImmutableLiveObject<>(DDimensionPreferences.EMPTY);
34
 	public final LiveObject<TabbedViewComponent> currentTab = new SimpleLiveObject<>(null);
35
 	public final LiveObject<TabbedViewComponent> currentTab = new SimpleLiveObject<>(null);
35
 	
36
 	

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/LibraryTreeNode.java View File

26
 		modules = new LiveMappedList<>(library.getModules(), module -> new ModuleTreeNode(window, module));
26
 		modules = new LiveMappedList<>(library.getModules(), module -> new ModuleTreeNode(window, module));
27
 	}
27
 	}
28
 	
28
 	
29
+	@Override
30
+	public void close() {
31
+		modules.close();
32
+	}
33
+	
29
 	@Override
34
 	@Override
30
 	public DColorableIcon getIcon() {
35
 	public DColorableIcon getIcon() {
31
 		return LibraryIcon.INSTANCE;
36
 		return LibraryIcon.INSTANCE;

+ 1
- 5
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ModuleTreeNode.java View File

16
  * @author Hoofdgebruiker
16
  * @author Hoofdgebruiker
17
  */
17
  */
18
 public class ModuleTreeNode extends PackageTreeNode {
18
 public class ModuleTreeNode extends PackageTreeNode {
19
-	private final IDEModule module;
20
-	private final IDEWindow window;
21
-	
22
 	public ModuleTreeNode(IDEWindow window, IDEModule module) {
19
 	public ModuleTreeNode(IDEWindow window, IDEModule module) {
23
 		super(window, module.getRootPackage());
20
 		super(window, module.getRootPackage());
24
 		
21
 		
25
-		this.module = module;
26
-		this.window = window;
22
+		init(module);
27
 	}
23
 	}
28
 
24
 
29
 	@Override
25
 	@Override

+ 28
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/PackageTreeNode.java View File

6
 package org.openzen.zenscript.ide.ui.view.project;
6
 package org.openzen.zenscript.ide.ui.view.project;
7
 
7
 
8
 import org.openzen.drawablegui.DColorableIcon;
8
 import org.openzen.drawablegui.DColorableIcon;
9
+import org.openzen.drawablegui.DMouseEvent;
9
 import org.openzen.drawablegui.live.LiveConcatList;
10
 import org.openzen.drawablegui.live.LiveConcatList;
10
 import org.openzen.drawablegui.live.LiveList;
11
 import org.openzen.drawablegui.live.LiveList;
11
 import org.openzen.drawablegui.live.LiveMappedList;
12
 import org.openzen.drawablegui.live.LiveMappedList;
13
+import org.openzen.zenscript.ide.host.IDEModule;
12
 import org.openzen.zenscript.ide.host.IDEPackage;
14
 import org.openzen.zenscript.ide.host.IDEPackage;
13
 import org.openzen.zenscript.ide.ui.IDEWindow;
15
 import org.openzen.zenscript.ide.ui.IDEWindow;
14
 import org.openzen.zenscript.ide.ui.icons.FolderIcon;
16
 import org.openzen.zenscript.ide.ui.icons.FolderIcon;
18
  * @author Hoofdgebruiker
20
  * @author Hoofdgebruiker
19
  */
21
  */
20
 public class PackageTreeNode extends ProjectOverviewNode {
22
 public class PackageTreeNode extends ProjectOverviewNode {
23
+	protected final IDEWindow window;
24
+	protected IDEModule module;
21
 	private final IDEPackage pkg;
25
 	private final IDEPackage pkg;
22
-	private final LiveList<ProjectOverviewNode> contents;
26
+	private LiveList<ProjectOverviewNode> contents;
23
 	
27
 	
24
 	public PackageTreeNode(IDEWindow window, IDEPackage pkg) {
28
 	public PackageTreeNode(IDEWindow window, IDEPackage pkg) {
29
+		this.window = window;
30
+		this.pkg = pkg;
31
+	}
32
+	
33
+	public PackageTreeNode(IDEWindow window, IDEModule module, IDEPackage pkg) {
34
+		this.window = window;
35
+		this.module = module;
25
 		this.pkg = pkg;
36
 		this.pkg = pkg;
26
 		
37
 		
38
+		init(module);
39
+	}
40
+	
41
+	protected final void init(IDEModule module) {
42
+		this.module = module;
27
 		contents = new LiveConcatList<>(
43
 		contents = new LiveConcatList<>(
28
-				new LiveMappedList<>(pkg.getSubPackages(), sub -> new PackageTreeNode(window, sub)),
44
+				new LiveMappedList<>(pkg.getSubPackages(), sub -> new PackageTreeNode(window, module, sub)),
29
 				new LiveMappedList<>(pkg.getSourceFiles(), source -> new SourceFileTreeNode(window, source))
45
 				new LiveMappedList<>(pkg.getSourceFiles(), source -> new SourceFileTreeNode(window, source))
30
 		);
46
 		);
31
 	}
47
 	}
48
+	
49
+	@Override
50
+	public void close() {
51
+		contents.close();
52
+	}
32
 
53
 
33
 	@Override
54
 	@Override
34
 	public LiveList<ProjectOverviewNode> getChildren() {
55
 	public LiveList<ProjectOverviewNode> getChildren() {
54
 	public boolean isLeaf() {
75
 	public boolean isLeaf() {
55
 		return false;
76
 		return false;
56
 	}
77
 	}
78
+	
79
+	@Override
80
+	public void onMouseClick(DMouseEvent e) {
81
+		window.setContextPackage(module, pkg);
82
+	}
57
 }
83
 }

+ 3
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ProjectOverviewNode.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.ui.view.project;
6
 package org.openzen.zenscript.ide.ui.view.project;
7
 
7
 
8
-import org.openzen.drawablegui.live.LiveBool;
8
+import org.openzen.drawablegui.live.MutableLiveBool;
9
 import org.openzen.drawablegui.live.SimpleLiveBool;
9
 import org.openzen.drawablegui.live.SimpleLiveBool;
10
 import org.openzen.drawablegui.tree.DTreeNode;
10
 import org.openzen.drawablegui.tree.DTreeNode;
11
 
11
 
14
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
15
  */
15
  */
16
 public abstract class ProjectOverviewNode implements DTreeNode<ProjectOverviewNode> {
16
 public abstract class ProjectOverviewNode implements DTreeNode<ProjectOverviewNode> {
17
-	private final LiveBool collapsed = new SimpleLiveBool();
17
+	private final MutableLiveBool collapsed = new SimpleLiveBool();
18
 	
18
 	
19
 	public abstract Kind getKind();
19
 	public abstract Kind getKind();
20
 	
20
 	
21
 	@Override
21
 	@Override
22
-	public LiveBool isCollapsed() {
22
+	public MutableLiveBool isCollapsed() {
23
 		return collapsed;
23
 		return collapsed;
24
 	}
24
 	}
25
 	
25
 	

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ProjectTreeNode.java View File

29
 		modules = new LiveMappedList<>(host.getModules(), module -> new ModuleTreeNode(window, module));
29
 		modules = new LiveMappedList<>(host.getModules(), module -> new ModuleTreeNode(window, module));
30
 	}
30
 	}
31
 	
31
 	
32
+	@Override
33
+	public void close(){
34
+		modules.close();
35
+	}
36
+	
32
 	@Override
37
 	@Override
33
 	public DColorableIcon getIcon() {
38
 	public DColorableIcon getIcon() {
34
 		return ProjectIcon.INSTANCE;
39
 		return ProjectIcon.INSTANCE;

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/RootTreeNode.java View File

29
 				new LiveMappedList<>(host.getLibraries(), library -> new LibraryTreeNode(window, library)));
29
 				new LiveMappedList<>(host.getLibraries(), library -> new LibraryTreeNode(window, library)));
30
 	}
30
 	}
31
 	
31
 	
32
+	@Override
33
+	public void close() {
34
+		children.close();
35
+	}
36
+	
32
 	@Override
37
 	@Override
33
 	public DColorableIcon getIcon() {
38
 	public DColorableIcon getIcon() {
34
 		return ProjectIcon.INSTANCE;
39
 		return ProjectIcon.INSTANCE;

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/SourceFileTreeNode.java View File

25
 		this.window = window;
25
 		this.window = window;
26
 		this.sourceFile = sourceFile;
26
 		this.sourceFile = sourceFile;
27
 	}
27
 	}
28
+	
29
+	@Override
30
+	public void close() {
31
+		
32
+	}
28
 
33
 
29
 	@Override
34
 	@Override
30
 	public Kind getKind() {
35
 	public Kind getKind() {

Loading…
Cancel
Save