Skip to content
Browse files

Merge branch 'v0.2' of git@github.com:Uko/BUMMEL.git into logic_elements

  • Loading branch information...
2 parents 00640dc + 40c52ed commit bead7638c3463efadbee4b1ca2795762bd9755d3 @Procurares Procurares committed Apr 8, 2012
View
2 LogicElements/src/net/unikernel/bummel/logic_elements/And/element_info.xml
@@ -7,6 +7,6 @@
<ports>
<port name="input1" direction="left" offset="0.5" indent="0" />
<port name="input2" direction="left" offset="-0.5" indent="0" />
- <port name="output" direction="right" offset="0" indent="0" />
+ <port name="output" direction="right" offset="0" indent="0.2" />
</ports>
</element_info>
View
3 LogicElements/src/net/unikernel/bummel/logic_elements/Generator/Generator.java
@@ -3,6 +3,7 @@
import java.util.Map;
import net.unikernel.bummel.project_model.api.BasicElement;
import net.unikernel.bummel.project_model.api.Element.ElementData;
+import net.unikernel.bummel.project_model.api.Toggle;
import org.openide.util.lookup.ServiceProvider;
/**
@@ -14,7 +15,7 @@
*/
@ServiceProvider(service=BasicElement.class)
@ElementData(dataFile="element_info.xml")
-public class Generator extends BasicElement
+public class Generator extends BasicElement implements Toggle
{
public Generator()
View
2 LogicElements/src/net/unikernel/bummel/logic_elements/Generator/element_info.xml
@@ -6,6 +6,6 @@
<graphics state="1" filename="graphic1.svg" />
</images>
<ports>
- <port name="output" direction="right" offset="0" indent="0" />
+ <port name="output" direction="right" offset="0" indent="0.25" />
</ports>
</element_info>
View
4 LogicElements/src/net/unikernel/bummel/logic_elements/Generator/graphic.svg
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
- <circle cx="18" cy="18" r="10" style="stroke: #000000; stroke-width: 2; fill: none" />
- <path d="M20,2 A17,17 0 0 1 34,16 M34,20 A17,17 0 0 1 20,34 M16,34 A17,17 0 0 1 2,20 M2,16 A17,17 0 0 1 16,2" style="stroke: #000000; stroke-width: 3; fill: none" />
+ <circle cx="17" cy="17" r="10" style="stroke: #000000; stroke-width: 2; fill: none" />
+ <path d="M19,2 A17,17 0 0 1 32,15 M32,19 A17,17 0 0 1 19,32 M15,32 A17,17 0 0 1 2,19 M2,15 A17,17 0 0 1 15,2" style="stroke: #000000; stroke-width: 3; fill: none" />
</svg>
View
4 LogicElements/src/net/unikernel/bummel/logic_elements/Generator/graphic1.svg
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
- <circle cx="18" cy="18" r="10" style="stroke: #000000; stroke-width: 2; fill: yellow" />
- <path d="M20,2 A17,17 0 0 1 34,16 M34,20 A17,17 0 0 1 20,34 M16,34 A17,17 0 0 1 2,20 M2,16 A17,17 0 0 1 16,2" style="stroke: yellow; stroke-width: 3; fill: none" />
+ <circle cx="17" cy="17" r="10" style="stroke: #000000; stroke-width: 2; fill: yellow" />
+ <path d="M19,2 A17,17 0 0 1 32,15 M32,19 A17,17 0 0 1 19,32 M15,32 A17,17 0 0 1 2,19 M2,15 A17,17 0 0 1 15,2" style="stroke: yellow; stroke-width: 3; fill: none" />
</svg>
View
4 LogicElements/src/net/unikernel/bummel/logic_elements/Not/graphic.svg
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
- <polygon points="2,2 2,32 30,16" style="stroke: #000000; stroke-width: 3; fill: none" />
- <circle cx="35" cy="16" r="4" style="stroke: #000000; stroke-width: 2; fill: none" />
+ <polygon points="2,3 2,32 30,17" style="stroke: #000000; stroke-width: 3; fill: none" />
+ <circle cx="35" cy="17" r="4" style="stroke: #000000; stroke-width: 2; fill: none" />
</svg>
View
6 LogicElements/src/net/unikernel/bummel/logic_elements/Or/element_info.xml
@@ -5,8 +5,8 @@
<graphics state="0" filename="graphic.svg" />
</images>
<ports>
- <port name="input1" direction="left" offset="0.5" indent="0" />
- <port name="input2" direction="left" offset="-0.5" indent="0" />
- <port name="output" direction="right" offset="0" indent="0" />
+ <port name="input1" direction="left" offset="0.5" indent="0.1" />
+ <port name="input2" direction="left" offset="-0.5" indent="0.1" />
+ <port name="output" direction="right" offset="0" indent="0.1" />
</ports>
</element_info>
View
2 LogicElements/src/net/unikernel/bummel/logic_elements/Or/graphic.svg
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
- <path d="M15,2 Q25,3 35,16 Q25,31 15,32 H2 Q10,16 2,2 Z" style="stroke: #000000; stroke-width: 3; fill:none" />
+ <path d="M15,2 Q25,3 35,17 Q25,31 15,32 H2 Q10,16 2,2 Z" style="stroke: #000000; stroke-width: 3; fill:none" />
</svg>
View
11 ProjectModel/src/net/unikernel/bummel/project_model/api/Toggle.java
@@ -0,0 +1,11 @@
+package net.unikernel.bummel.project_model.api;
+
+/**
+ * This interface just indicates the elements that allow to change their state from GUI.
+ * On this stage it's hardcoded for the logical generator.
+ * @author mcangel
+ */
+public interface Toggle
+{
+
+}
View
36 VisualEditor/src/net/unikernel/bummel/visual_editor/CircuitGraphPinScene.java
@@ -11,7 +11,10 @@
import javax.swing.JPopupMenu;
import net.unikernel.bummel.project_model.api.BasicElement;
import net.unikernel.bummel.project_model.api.Circuit;
+import net.unikernel.bummel.project_model.api.Toggle;
import org.netbeans.api.visual.action.*;
+import org.netbeans.api.visual.action.WidgetAction.State;
+import org.netbeans.api.visual.action.WidgetAction.WidgetMouseEvent;
import org.netbeans.api.visual.anchor.AnchorFactory;
import org.netbeans.api.visual.anchor.AnchorShape;
import org.netbeans.api.visual.anchor.PointShape;
@@ -38,6 +41,17 @@
private long edgeCounter = 0;
private WidgetAction connectAction = ActionFactory.createConnectAction(interractionLayer, new SceneConnectProvider());
private WidgetAction reconnetAction = ActionFactory.createReconnectAction(new SceneReconnectProvider());
+ private WidgetAction toggleGeneratorAction = new WidgetAction.Adapter(){
+
+ @Override
+ public State mouseClicked(Widget widget, WidgetMouseEvent event)
+ {
+ ((ElementNode)findObject(widget)).getLookup().lookup(BasicElement.class).setState(
+ (((ElementNode)findObject(widget)).getLookup().lookup(BasicElement.class).getState()+1)%2);
+ hardcodedCircuitRun();
+ return State.CONSUMED;
+ }
+ };
private Circuit circuit;
public CircuitGraphPinScene(final Circuit circuit)
@@ -90,17 +104,21 @@ public void accept(Widget widget, Point point, Transferable transferable)
@Override
protected Widget attachNodeWidget(ElementNode node)
{
- ElementWidget widget = null;
- try
- {
- widget = new ElementWidget(this, node);
- }
- catch (MalformedURLException | SVGException ex)
- {
- Exceptions.printStackTrace(ex);
- }
+ ElementWidget widget = null;
+ try
+ {
+ widget = new ElementWidget(this, node);
+ }
+ catch (MalformedURLException | SVGException ex)
+ {
+ Exceptions.printStackTrace(ex);
+ }
mainLayer.addChild(widget);
+ if(node.getLookup().lookup(BasicElement.class) instanceof Toggle)
+ {
+ widget.getActions().addAction(toggleGeneratorAction);
+ }
widget.getActions().addAction(createSelectAction());
widget.getActions().addAction(ActionFactory.createMoveAction());
widget.getActions().addAction(ActionFactory.createPopupMenuAction(new PopupMenuProvider()
View
9 VisualEditor/src/net/unikernel/bummel/visual_editor/ElementNode.java
@@ -48,6 +48,15 @@ public String getPortDirection(String port)
return ps.getPortDirection(port);
}
+ public Double getPortIndent(String port)
+ {
+ if(ps == null)
+ {
+ constructPortsScanner();
+ }
+ return ps.getPortsIndent(port);
+ }
+
public Double getPortOffset(String port)
{
if(ps == null)
View
46 VisualEditor/src/net/unikernel/bummel/visual_editor/ElementPortWidget.java
@@ -20,6 +20,7 @@
public class ElementPortWidget extends Widget
{
String port;
+ ElementNode node;
ImageWidget line;
ImageWidget anchorWidget;
List<Image> anchorGlyphs;
@@ -29,6 +30,7 @@
public ElementPortWidget(Scene scene, ElementNode node, String port)
{
super(scene);
+ this.node = node;
this.port = port;
setLayout(LayoutFactory.createAbsoluteLayout());
Graphics2D g2d;
@@ -119,4 +121,48 @@ protected void notifyStateChanged(ObjectState previousState, ObjectState state)
anchorWidget.setImage(anchorGlyphs.get(0));
}
}
+
+ public void indentPort(int size)
+ {
+ Double indent = node.getPortIndent(port);
+ int newLength = (int) (length + size*indent);
+ BufferedImage lineImage;
+ Graphics2D g2d;
+ switch (node.getPortDirection(port))
+ {
+ default:
+ case "right":
+ lineImage = new BufferedImage(newLength, 1, BufferedImage.TYPE_INT_ARGB);
+ //draw line
+ g2d = ((Graphics2D) lineImage.getGraphics());
+ g2d.setPaint(Color.BLACK);
+ g2d.drawLine(0, 0, newLength - 1, 0);
+ line.setPreferredLocation(new Point((int)(-size*indent), 0));
+ break;
+ case "left":
+ lineImage = new BufferedImage(newLength, 1, BufferedImage.TYPE_INT_ARGB);
+ //draw line
+ g2d = ((Graphics2D) lineImage.getGraphics());
+ g2d.setPaint(Color.BLACK);
+ g2d.drawLine(0, 0, newLength - 1, 0);
+ break;
+
+ //next cases are default - there is need to implement them and check the result
+ case "up":
+ lineImage = new BufferedImage(1, newLength, BufferedImage.TYPE_INT_ARGB);
+ //draw line
+ g2d = ((Graphics2D) lineImage.getGraphics());
+ g2d.setPaint(Color.BLACK);
+ g2d.drawLine(0, 0, 0, length - 1);
+ break;
+ case "down":
+ lineImage = new BufferedImage(1, newLength, BufferedImage.TYPE_INT_ARGB);
+ //draw line
+ g2d = ((Graphics2D) lineImage.getGraphics());
+ g2d.setPaint(Color.BLACK);
+ g2d.drawLine(0, 0, 0, length - 1);
+ break;
+ }
+ line.setImage(lineImage);
+ }
}
View
2 VisualEditor/src/net/unikernel/bummel/visual_editor/ElementWidget.java
@@ -65,11 +65,13 @@ public void attachPortWidget(ElementPortWidget widget)
widget.setPreferredLocation(new Point(imageWidget.getPreferredBounds().width,
//offset from the middle, offset in "percents" of the height half
(int) (imageWidget.getPreferredBounds().height*(1+elNode.getPortOffset(widget.getPort()).doubleValue())/2)));
+ widget.indentPort(imageWidget.getPreferredBounds().width);
break;
case "left":
widget.setPreferredLocation(new Point(0,
//offset from the middle, offset in "percents" of the height half
(int) (imageWidget.getPreferredBounds().height*(1+elNode.getPortOffset(widget.getPort()).doubleValue())/2)));
+ widget.indentPort(imageWidget.getPreferredBounds().width);
break;
case "up":
widget.setPreferredLocation(new Point((int) (imageWidget.getPreferredBounds().width*(1+elNode.getPortOffset(widget.getPort()).doubleValue())/2),imageWidget.getPreferredBounds().height));

0 comments on commit bead763

Please sign in to comment.
Something went wrong with that request. Please try again.