Browse Source

build installation node
toolbar ui wip

Martin Kunz 5 years ago
parent
commit
db509a515d

+ 2 - 2
pom.xml

@@ -98,7 +98,7 @@
 					<instructions>
 						<!--********** DO NOT MODIFY THE ENTRIES OF THIS SECTION **********-->
 						<Bundle-Category>URCap</Bundle-Category>
-						<Bundle-Activator>uraxis.Activator</Bundle-Activator>
+						<Bundle-Activator>urgrip.Activator</Bundle-Activator>
 						<Bundle-Vendor>${urcap.vendor}</Bundle-Vendor>
 						<Bundle-ContactAddress>${urcap.contactAddress}</Bundle-ContactAddress>
 						<Bundle-Copyright>${urcap.copyright}</Bundle-Copyright>
@@ -145,7 +145,7 @@
 		<dependency>
 			<groupId>com.ur.urcap</groupId>
 			<artifactId>api</artifactId>
-			<version>1.7.0</version>
+			<version>1.9.0</version>
 			<scope>provided</scope>
 		</dependency>
 		<dependency>

+ 8 - 3
src/main/java/uraxis/Activator.java

@@ -1,11 +1,14 @@
-package uraxis;
+package urgrip;
 
+import com.ur.urcap.api.contribution.InstallationNodeService;
+import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeService;
 import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeService;
 import com.ur.urcap.api.contribution.toolbar.swing.SwingToolbarService;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import uraxis.programnodes.GripperNodeService;
-import uraxis.toolbar.MyToolbarService;
+import urgrip.installation.HelloWorldInstallationNodeService;
+import urgrip.programnodes.GripperNodeService;
+import urgrip.toolbar.MyToolbarService;
 
 public class Activator implements BundleActivator {
 
@@ -15,6 +18,8 @@ public class Activator implements BundleActivator {
 
 		context.registerService(SwingToolbarService.class, new MyToolbarService(), null);
 		context.registerService(SwingProgramNodeService.class, new GripperNodeService(), null);
+		context.registerService(SwingInstallationNodeService.class, new HelloWorldInstallationNodeService(), null);
+
 	}
 
 	@Override

+ 78 - 0
src/main/java/urgrip/installation/HelloWorldInstallationNodeContribution.java

@@ -0,0 +1,78 @@
+package urgrip.installation;
+
+import com.ur.urcap.api.contribution.InstallationNodeContribution;
+import com.ur.urcap.api.contribution.installation.InstallationAPIProvider;
+import com.ur.urcap.api.domain.data.DataModel;
+import com.ur.urcap.api.domain.script.ScriptWriter;
+import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputCallback;
+import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardInputFactory;
+import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput;
+
+public class HelloWorldInstallationNodeContribution implements InstallationNodeContribution {
+
+	private static final String POPUPTITLE_KEY = "popuptitle";
+	private static final String DEFAULT_VALUE = "Hello World";
+	private final HelloWorldInstallationNodeView view;
+	private final KeyboardInputFactory keyboardFactory;
+
+	private DataModel model;
+
+	public HelloWorldInstallationNodeContribution(InstallationAPIProvider apiProvider, DataModel model, HelloWorldInstallationNodeView view) {
+		this.keyboardFactory = apiProvider.getUserInterfaceAPI().getUserInteraction().getKeyboardInputFactory();
+		this.model = model;
+		this.view = view;
+	}
+
+	@Override
+	public void openView() {
+		view.setPopupText(getPopupTitle());
+	}
+
+	@Override
+	public void closeView() {
+
+	}
+
+	public boolean isDefined() {
+		return !getPopupTitle().isEmpty();
+	}
+
+	@Override
+	public void generateScript(ScriptWriter writer) {
+		// Store the popup title in a global variable so it is globally available to all Hello World program nodes.
+		writer.assign("hello_world_swing_popup_title", "\"" + getPopupTitle() + "\"");
+	}
+
+	public String getPopupTitle() {
+		return model.get(POPUPTITLE_KEY, DEFAULT_VALUE);
+	}
+
+	public void setPopupTitle(String message) {
+		if ("".equals(message)) {
+			resetToDefaultValue();
+		} else {
+			model.set(POPUPTITLE_KEY, message);
+		}
+	}
+
+	private void resetToDefaultValue() {
+		view.setPopupText(DEFAULT_VALUE);
+		model.set(POPUPTITLE_KEY, DEFAULT_VALUE);
+	}
+
+	public KeyboardTextInput getInputForTextField() {
+		KeyboardTextInput keyboardInput = keyboardFactory.createStringKeyboardInput();
+		keyboardInput.setInitialValue(getPopupTitle());
+		return keyboardInput;
+	}
+
+	public KeyboardInputCallback<String> getCallbackForTextField() {
+		return new KeyboardInputCallback<String>() {
+			@Override
+			public void onOk(String value) {
+				setPopupTitle(value);
+				view.setPopupText(value);
+			}
+		};
+	}
+}

+ 37 - 0
src/main/java/urgrip/installation/HelloWorldInstallationNodeService.java

@@ -0,0 +1,37 @@
+package urgrip.installation;
+
+import com.ur.urcap.api.contribution.ViewAPIProvider;
+import com.ur.urcap.api.contribution.installation.ContributionConfiguration;
+import com.ur.urcap.api.contribution.installation.CreationContext;
+import com.ur.urcap.api.contribution.installation.InstallationAPIProvider;
+import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeService;
+import com.ur.urcap.api.domain.SystemAPI;
+import com.ur.urcap.api.domain.data.DataModel;
+import urgrip.programnodes.Style;
+import urgrip.programnodes.V5Style;
+
+import java.util.Locale;
+
+public class HelloWorldInstallationNodeService implements SwingInstallationNodeService<HelloWorldInstallationNodeContribution, HelloWorldInstallationNodeView> {
+
+	@Override
+	public void configureContribution(ContributionConfiguration configuration) {
+	}
+
+	@Override
+	public String getTitle(Locale locale) {
+		return "Hello World";
+	}
+
+	@Override
+	public HelloWorldInstallationNodeView createView(ViewAPIProvider apiProvider) {
+		SystemAPI systemAPI = apiProvider.getSystemAPI();
+		Style style =  new V5Style();
+		return new HelloWorldInstallationNodeView(style);
+	}
+
+	@Override
+	public HelloWorldInstallationNodeContribution createInstallationNode(InstallationAPIProvider apiProvider, HelloWorldInstallationNodeView view, DataModel model, CreationContext context) {
+		return new HelloWorldInstallationNodeContribution(apiProvider, model, view);
+	}
+}

+ 90 - 0
src/main/java/urgrip/installation/HelloWorldInstallationNodeView.java

@@ -0,0 +1,90 @@
+package urgrip.installation;
+
+import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView;
+import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput;
+import urgrip.programnodes.Style;
+
+import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.JTextPane;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+public class HelloWorldInstallationNodeView implements SwingInstallationNodeView<HelloWorldInstallationNodeContribution> {
+
+	private final Style style;
+	private JTextField jTextField;
+
+	public HelloWorldInstallationNodeView(Style style) {
+		this.style = style;
+	}
+
+	@Override
+	public void buildUI(JPanel jPanel, final HelloWorldInstallationNodeContribution installationNode) {
+		jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
+
+		jPanel.add(createInfo());
+		jPanel.add(createVerticalSpacing());
+		jPanel.add(createInput(installationNode));
+	}
+
+	private Box createInfo() {
+		Box infoBox = Box.createVerticalBox();
+		infoBox.setAlignmentX(Component.LEFT_ALIGNMENT);
+		JTextPane pane = new JTextPane();
+		pane.setBorder(BorderFactory.createEmptyBorder());
+		SimpleAttributeSet attributeSet = new SimpleAttributeSet();
+		StyleConstants.setLineSpacing(attributeSet, 0.5f);
+		StyleConstants.setLeftIndent(attributeSet, 0f);
+		pane.setParagraphAttributes(attributeSet, false);
+		pane.setText("The popup title below is shared between all Hello World program nodes.\nThe title cannot be empty.");
+		pane.setEditable(false);
+		pane.setMaximumSize(pane.getPreferredSize());
+		pane.setBackground(infoBox.getBackground());
+		infoBox.add(pane);
+		return infoBox;
+	}
+
+	private Box createInput(final HelloWorldInstallationNodeContribution installationNode) {
+		Box inputBox = Box.createHorizontalBox();
+		inputBox.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+		inputBox.add(new JLabel("Popup title:"));
+		inputBox.add(createHorizontalSpacing());
+
+		jTextField = new JTextField();
+		jTextField.setFocusable(false);
+		jTextField.setPreferredSize(style.getInputfieldSize());
+		jTextField.setMaximumSize(jTextField.getPreferredSize());
+		jTextField.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mousePressed(MouseEvent e) {
+				KeyboardTextInput keyboardInput = installationNode.getInputForTextField();
+				keyboardInput.show(jTextField, installationNode.getCallbackForTextField());
+			}
+		});
+		inputBox.add(jTextField);
+
+		return inputBox;
+	}
+
+	private Component createHorizontalSpacing() {
+		return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0));
+	}
+
+	private Component createVerticalSpacing() {
+		return Box.createRigidArea(new Dimension(0, style.getVerticalSpacing()));
+	}
+
+	public void setPopupText(String t) {
+		jTextField.setText(t);
+	}
+}

+ 1 - 1
src/main/java/uraxis/programnodes/GripperNodeContribution.java

@@ -1,4 +1,4 @@
-package uraxis.programnodes;
+package urgrip.programnodes;
 
 import com.ur.urcap.api.contribution.ProgramNodeContribution;
 import com.ur.urcap.api.contribution.program.ProgramAPIProvider;

+ 4 - 7
src/main/java/uraxis/programnodes/GripperNodeService.java

@@ -1,11 +1,10 @@
-package uraxis.programnodes;
+package urgrip.programnodes;
 
 import com.ur.urcap.api.contribution.ViewAPIProvider;
 import com.ur.urcap.api.contribution.program.ContributionConfiguration;
 import com.ur.urcap.api.contribution.program.CreationContext;
 import com.ur.urcap.api.contribution.program.ProgramAPIProvider;
 import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeService;
-import com.ur.urcap.api.domain.SystemAPI;
 import com.ur.urcap.api.domain.data.DataModel;
 
 import java.util.Locale;
@@ -15,7 +14,7 @@ public class GripperNodeService implements SwingProgramNodeService<GripperNodeCo
 
     @Override
     public String getId() {
-        return "FestoABS";
+        return "Grip";
     }
 
     @Override
@@ -25,14 +24,12 @@ public class GripperNodeService implements SwingProgramNodeService<GripperNodeCo
 
     @Override
     public String getTitle(Locale locale) {
-        return "FestoABS";
+        return "Grip";
     }
 
     @Override
     public GripperNodeView createView(ViewAPIProvider apiProvider) {
-        SystemAPI systemAPI = apiProvider.getSystemAPI();
-        Style style =  new V5Style();
-        return new GripperNodeView(style);
+        return new GripperNodeView(new V5Style());
     }
 
     @Override

+ 1 - 1
src/main/java/uraxis/programnodes/GripperNodeView.java

@@ -1,4 +1,4 @@
-package uraxis.programnodes;
+package urgrip.programnodes;
 
 import com.ur.urcap.api.contribution.ContributionProvider;
 import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeView;

+ 1 - 1
src/main/java/uraxis/programnodes/Style.java

@@ -1,4 +1,4 @@
-package uraxis.programnodes;
+package urgrip.programnodes;
 
 import java.awt.*;
 

+ 1 - 1
src/main/java/uraxis/programnodes/V5Style.java

@@ -1,4 +1,4 @@
-package uraxis.programnodes;
+package urgrip.programnodes;
 
 import java.awt.*;
 

+ 16 - 0
src/main/java/urgrip/toolbar/HandleButton.java

@@ -0,0 +1,16 @@
+package urgrip.toolbar;
+
+public class HandleButton {
+
+    public void down() {
+
+    }
+
+    public void up() {
+
+    }
+
+    public void action() {
+
+    }
+}

+ 1 - 1
src/main/java/uraxis/toolbar/IOHandler.java

@@ -1,4 +1,4 @@
-package uraxis.toolbar;
+package urgrip.toolbar;
 
 import java.util.Collection;
 import java.util.Iterator;

+ 42 - 0
src/main/java/urgrip/toolbar/MyButton.java

@@ -0,0 +1,42 @@
+package urgrip.toolbar;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class MyButton implements ChangeListener, ActionListener {
+
+    private final JButton button;
+    private final HandleButton cb;
+
+    public MyButton(JButton b, HandleButton cb) {
+        b.addChangeListener(this);
+        b.addActionListener(this);
+        this.button=b;
+        this.cb=cb;
+    }
+
+    @Override
+    public void stateChanged(ChangeEvent e) {
+
+        ButtonModel model = (ButtonModel) e.getSource();
+        if(e.getSource()==button) {
+            if(model.isPressed())
+                cb.down();
+            else cb.up();
+
+        }
+    }
+
+    public void close() {
+        button.removeChangeListener(this);
+    }
+
+
+    @Override
+    public void actionPerformed(ActionEvent e) {
+        cb.action();
+    }
+}

+ 56 - 13
src/main/java/uraxis/toolbar/MyToolbarContribution.java

@@ -1,18 +1,13 @@
-package uraxis.toolbar;
+package urgrip.toolbar;
 
 import com.ur.urcap.api.contribution.toolbar.ToolbarAPIProvider;
 import com.ur.urcap.api.contribution.toolbar.ToolbarContext;
 import com.ur.urcap.api.contribution.toolbar.swing.SwingToolbarContribution;
 import com.ur.urcap.api.domain.io.DigitalIO;
-import com.ur.urcap.api.domain.io.IO;
-import com.ur.urcap.api.domain.io.IOModel;
-import uraxis.Activator;
 
 import javax.swing.*;
 import java.awt.*;
-import java.awt.event.ActionEvent;
 import java.util.*;
-import java.util.Timer;
 
 class MyToolbarContribution implements SwingToolbarContribution {
     private static final int VERTICAL_SPACE = 10;
@@ -24,6 +19,13 @@ class MyToolbarContribution implements SwingToolbarContribution {
     private JLabel demoToolStatus;
     private HashMap<String, JCheckBox> boxes=new HashMap<>();
     private DigitalIO out0,out1, in0, in1;
+    private JButton bGrip;
+    private JButton bRelease;
+    private JButton bBlow;
+    private JButton couple;
+    private JButton decouple;
+    private JButton bCouple;
+    private JButton bDecouple;
 
 
     MyToolbarContribution(ToolbarContext context) {
@@ -34,8 +36,12 @@ class MyToolbarContribution implements SwingToolbarContribution {
 
     @Override
     public void openView() {
-        IOModel ioModel = apiProvider.getApplicationAPI().getIOModel();
-        Collection<IO> ios = ioModel.getIOs();
+
+    }
+
+    @Override
+    public void closeView() {
+
     }
 
     private void InitializeIO() {
@@ -45,10 +51,6 @@ class MyToolbarContribution implements SwingToolbarContribution {
         in1 = 	ioHandler.getDigitalIO("tool_in[1]");
     }
 
-    @Override
-    public void closeView() {
-    }
-
     public void buildUI(JPanel jPanel) {
         jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
         jPanel.add(createHeader());
@@ -61,7 +63,7 @@ class MyToolbarContribution implements SwingToolbarContribution {
         Box headerBox = Box.createHorizontalBox();
         headerBox.setAlignmentX(Component.CENTER_ALIGNMENT);
 
-        JLabel header = new JLabel("Festo Axis Control");
+        JLabel header = new JLabel("Gripper");
         header.setFont(header.getFont().deriveFont(Font.BOLD, HEADER_FONT_SIZE));
         headerBox.add(header);
         return headerBox;
@@ -69,6 +71,46 @@ class MyToolbarContribution implements SwingToolbarContribution {
 
     private Box createButtons() {
         Box box = Box.createHorizontalBox();
+
+        bGrip = new JButton("grip");
+        box.add(bGrip);
+        new MyButton(bGrip, new HandleButton() {
+            @Override public void action() {
+                out0.setValue(true);
+            }
+        });
+
+        bRelease = new JButton("release");
+        box.add(bRelease);
+        new MyButton(bRelease, new HandleButton() {
+            @Override public void action() {
+                out0.setValue(false);
+            }
+        });
+
+        bBlow = new JButton("blow out");
+        box.add(bBlow);
+        new MyButton(bBlow, new HandleButton() {
+            @Override public void action() {
+                out0.setValue(false);
+            }
+        });
+
+        bCouple = new JButton("couple");
+        box.add(bCouple);
+        new MyButton(bCouple, new HandleButton() {
+            @Override public void action() {
+                out0.setValue(false);
+            }
+        });
+
+        bDecouple = new JButton("decouple");
+        box.add(bDecouple);
+        new MyButton(bDecouple, new HandleButton() {
+            @Override public void action() {
+                out0.setValue(false);
+            }
+        });
         return box;
     }
 
@@ -91,4 +133,5 @@ class MyToolbarContribution implements SwingToolbarContribution {
     }
 
 
+
 }

+ 1 - 1
src/main/java/uraxis/toolbar/MyToolbarService.java

@@ -1,4 +1,4 @@
-package uraxis.toolbar;
+package urgrip.toolbar;
 
 import com.ur.urcap.api.contribution.toolbar.ToolbarConfiguration;
 import com.ur.urcap.api.contribution.toolbar.ToolbarContext;

+ 0 - 39
src/main/resources/uraxis/installation.html

@@ -1,39 +0,0 @@
-<!DOCTYPE html>
-<html>
-	<head>
-		<title>Fexto Axis</title>
-		<style>
-			label {
-				display: inline-block;
-				width: 100px;
-				height: 28px;
-			}
-			input {
-				display: inline-block;
-				width: 200px;
-				height: 28px;
-			}
-		</style>
-	</head>
-	<body>
-		<h1>Festo Axis</h1>
-		<form>
-			<p>Fest Achse Config</p>
-			<br />
-
-			<label for="textIP">Daemon IP</label>
-			<input id="textIP" type="text" style="font-size: 18px;" /><br/>
-			<label for="textIP">Daemon Port</label>
-			<input id="textPort" type="text" style="font-size: 18px;" /><br/>
-            <input id="btnReady" type="button" style="font-size: 18px;" />
-
-            <input id="btnEnableDaemon" type="button" style="font-size: 18px;" />
-			<input id="btnDisableDaemon" type="button" style="font-size: 18px;" />
-			<br>
-			<label  id="lblStatus" style="width: 400px;height: 200px;vertical-align: top"></label>
-			<label id="lblDaemonStatus" style="width: 200px">Status of daemon</label>
-			<br>
-
-		</form>
-	</body>
-</html>

+ 1 - 1
src/test/java/uraxis/AppTest.java

@@ -1,4 +1,4 @@
-package uraxis;
+package urgrip;
 
 import junit.framework.Test;
 import junit.framework.TestCase;