projects
/
Mograsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implemented functional GUIAm2901 without layout
[Mograsim.git]
/
net.mograsim.logic.ui
/
src
/
net
/
mograsim
/
logic
/
ui
/
model
/
components
/
GUIComponent.java
diff --git
a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java
b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java
index
7254d8b
..
22f1fbf
100644
(file)
--- a/
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java
+++ b/
net.mograsim.logic.ui/src/net/mograsim/logic/ui/model/components/GUIComponent.java
@@
-1,8
+1,12
@@
package net.mograsim.logic.ui.model.components;
import java.util.ArrayList;
package net.mograsim.logic.ui.model.components;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@
-15,8
+19,8
@@
public abstract class GUIComponent
{
protected final ViewModelModifiable model;
private final Rectangle bounds;
{
protected final ViewModelModifiable model;
private final Rectangle bounds;
- private final
List<Pin> pins
;
- protected final
List
<Pin> pinsUnmodifiable;
+ private final
Map<String, Pin> pinsByName
;
+ protected final
Collection
<Pin> pinsUnmodifiable;
private final List<Consumer<? super GUIComponent>> componentMovedListeners;
private final List<Consumer<? super Pin>> pinAddedListeners;
private final List<Consumer<? super GUIComponent>> componentMovedListeners;
private final List<Consumer<? super Pin>> pinAddedListeners;
@@
-31,8
+35,8
@@
public abstract class GUIComponent
{
this.model = model;
this.bounds = new Rectangle(0, 0, 0, 0);
{
this.model = model;
this.bounds = new Rectangle(0, 0, 0, 0);
- this.pins
= new ArrayList
<>();
- this.pinsUnmodifiable = Collections.unmodifiable
List(pins
);
+ this.pins
ByName = new HashMap
<>();
+ this.pinsUnmodifiable = Collections.unmodifiable
Collection(pinsByName.values()
);
this.componentMovedListeners = new ArrayList<>();
this.pinAddedListeners = new ArrayList<>();
this.componentMovedListeners = new ArrayList<>();
this.pinAddedListeners = new ArrayList<>();
@@
-46,7
+50,7
@@
public abstract class GUIComponent
public void destroy()
{
public void destroy()
{
- pins.forEach(p -> pinRemovedListeners.forEach(l -> l.accept(p)));
+ pins
ByName.values()
.forEach(p -> pinRemovedListeners.forEach(l -> l.accept(p)));
model.componentDestroyed(this);
}
model.componentDestroyed(this);
}
@@
-76,13
+80,21
@@
public abstract class GUIComponent
}
/**
}
/**
- * Returns a
list
of pins of this component.
+ * Returns a
collection
of pins of this component.
*/
*/
- public
List
<Pin> getPins()
+ public
Collection
<Pin> getPins()
{
return pinsUnmodifiable;
}
{
return pinsUnmodifiable;
}
+ public Pin getPin(String name)
+ {
+ Pin pin = pinsByName.get(name);
+ if (pin == null)
+ throw new IllegalArgumentException("No pin with the name " + name);
+ return pin;
+ }
+
// @formatter:off
public void addComponentMovedListener (Consumer<? super GUIComponent> listener) {componentMovedListeners.add (listener);}
public void addPinAddedListener (Consumer<? super Pin > listener) {pinAddedListeners .add (listener);}
// @formatter:off
public void addComponentMovedListener (Consumer<? super GUIComponent> listener) {componentMovedListeners.add (listener);}
public void addPinAddedListener (Consumer<? super Pin > listener) {pinAddedListeners .add (listener);}
@@
-119,15
+131,17
@@
public abstract class GUIComponent
protected void addPin(Pin pin)
{
protected void addPin(Pin pin)
{
- pins.add(pin);
+ if (pinsByName.containsKey(pin.name))
+ throw new IllegalArgumentException("Duplicate pin name: " + pin.name);
+ pinsByName.put(pin.name, pin);
callPinAddedListeners(pin);
pin.addRedrawListener(redrawListenerForSubcomponents);
callRedrawListeners();
}
callPinAddedListeners(pin);
pin.addRedrawListener(redrawListenerForSubcomponents);
callRedrawListeners();
}
- protected void removePin(
Pin pin
)
+ protected void removePin(
String name
)
{
{
-
pins.remove(pin
);
+
Pin pin = pinsByName.remove(name
);
callPinRemovedListeners(pin);
pin.removeRedrawListener(redrawListenerForSubcomponents);
callRedrawListeners();
callPinRemovedListeners(pin);
pin.removeRedrawListener(redrawListenerForSubcomponents);
callRedrawListeners();
@@
-140,4
+154,10
@@
public abstract class GUIComponent
{
return identifierDelegate.get();
}
{
return identifierDelegate.get();
}
+
+ @SuppressWarnings("static-method")
+ public Map<String, Object> getInstantiationParameters()
+ {
+ return new TreeMap<>();
+ }
}
\ No newline at end of file
}
\ No newline at end of file