From 5959ef92ba016e44ce652439cb8af75aa86e877b Mon Sep 17 00:00:00 2001 From: BomMadsen Date: Mon, 9 Jul 2018 16:15:47 +0200 Subject: [PATCH] SDK 1.3.55 --- .../assembly.xml | 23 ++ com.ur.urcap.examples.helloworldswing/pom.xml | 280 ++++++++++++++++++ .../helloworldswing/impl/Activator.java | 18 ++ ...elloWorldInstallationNodeContribution.java | 78 +++++ .../HelloWorldInstallationNodeService.java | 35 +++ .../impl/HelloWorldInstallationNodeView.java | 89 ++++++ .../HelloWorldProgramNodeContribution.java | 108 +++++++ .../impl/HelloWorldProgramNodeService.java | 51 ++++ .../impl/HelloWorldProgramNodeView.java | 116 ++++++++ .../examples/helloworldswing/impl/Style.java | 33 +++ .../helloworldswing/impl/V3Style.java | 12 + .../helloworldswing/impl/V5Style.java | 12 + .../src/main/resources/META-INF/LICENSE | 28 ++ 13 files changed, 883 insertions(+) create mode 100755 com.ur.urcap.examples.helloworldswing/assembly.xml create mode 100755 com.ur.urcap.examples.helloworldswing/pom.xml create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Activator.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeContribution.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeService.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeView.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeContribution.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeService.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeView.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Style.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V3Style.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V5Style.java create mode 100755 com.ur.urcap.examples.helloworldswing/src/main/resources/META-INF/LICENSE diff --git a/com.ur.urcap.examples.helloworldswing/assembly.xml b/com.ur.urcap.examples.helloworldswing/assembly.xml new file mode 100755 index 0000000..9e7ffd3 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/assembly.xml @@ -0,0 +1,23 @@ + + sources + + tar.gz + + false + + + . + + pom.xml + assembly.xml + + true + + + src + true + + + diff --git a/com.ur.urcap.examples.helloworldswing/pom.xml b/com.ur.urcap.examples.helloworldswing/pom.xml new file mode 100755 index 0000000..bdce5b6 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/pom.xml @@ -0,0 +1,280 @@ + + + + 4.0.0 + + com.ur.urcap.examples + helloworldswing + 1.0-SNAPSHOT + Hello World Swing + bundle + + + + + + + + + com.ur.urcap.examples.helloworldswing + Universal Robots + Energivej 25, 5260 Odense S, Denmark + Copyright (C) 2009-2017 Universal Robots. All Rights Reserved + Hello World Swing sample URCap + Sample license + + + + + localhost + root + easybot + + + + + + + ur + easybot + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.6 + 1.6 + + + + maven-jar-plugin + 3.0.2 + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + maven-resources-plugin + 3.0.2 + + + org.apache.felix + maven-bundle-plugin + 2.4.0 + true + + + bundle-manifest + process-classes + + manifest + + + + + + + URCap + com.ur.urcap.examples.helloworldswing.impl.Activator + ${urcap.vendor} + ${urcap.contactAddress} + ${urcap.copyright} + ${urcap.licenseType} + ${urcap.description} + + + com.ur.urcap.api*;version="[1.2.92,2.0.0)", + * + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + + + package-urcap + package + + exec + + + cp + target/${project.build.finalName}.jar target/${project.build.finalName}.urcap + . + + + + + + maven-assembly-plugin + + + assembly.xml + + + + + package + + single + + + + + + + + + + org.osgi + org.osgi.core + 4.3.0 + + + + com.ur.urcap + api + 1.3.0 + provided + + + + + junit + junit + 4.12 + test + + + + + + remote + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + + remote-install-urcap + install + + exec + + + sshpass + -p ${urcap.install.password} scp -o StrictHostKeyChecking=no target/${project.build.finalName}.jar ${urcap.install.username}@${urcap.install.host}:/root/.urcaps/${urcap.symbolicname}.jar + . + + + + remote-restart-ui + install + + exec + + + sshpass + -p ${urcap.install.password} ssh ${urcap.install.username}@${urcap.install.host} pkill java + . + + + + + + + + + local + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + + local-install-urcap + install + + exec + + + cp + target/${project.build.finalName}.jar ${user.home}/.urcaps/${urcap.symbolicname}.jar + . + + + + + + + + + ursim + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + + ursim-install-urcap + install + + exec + + + cp + target/${project.build.finalName}.jar ${ursim.home}/.urcaps/${urcap.symbolicname}.jar + . + + + + + + + + + ursimvm + + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + + ursimvm-install-urcap + install + + exec + + + sshpass + -p ${ursimvm.install.password} scp -o StrictHostKeyChecking=no target/${project.build.finalName}.jar ${ursimvm.install.username}@${ursimvm.install.host}:/home/ur/ursim-current/.urcaps/${urcap.symbolicname}.jar + . + + + + + + + + + diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Activator.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Activator.java new file mode 100755 index 0000000..a57fc98 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Activator.java @@ -0,0 +1,18 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeService; +import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeService; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + @Override + public void start(final BundleContext context) throws Exception { + context.registerService(SwingInstallationNodeService.class, new HelloWorldInstallationNodeService(), null); + context.registerService(SwingProgramNodeService.class, new HelloWorldProgramNodeService(), null); + } + + @Override + public void stop(BundleContext context) throws Exception { + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeContribution.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeContribution.java new file mode 100755 index 0000000..b60ab46 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeContribution.java @@ -0,0 +1,78 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +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 Swing"; + 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 Swing 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 getCallbackForTextField() { + return new KeyboardInputCallback() { + @Override + public void onOk(String value) { + setPopupTitle(value); + view.setPopupText(value); + } + }; + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeService.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeService.java new file mode 100755 index 0000000..9356290 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeService.java @@ -0,0 +1,35 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +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 java.util.Locale; + +public class HelloWorldInstallationNodeService implements SwingInstallationNodeService { + + @Override + public void configureContribution(ContributionConfiguration configuration) { + } + + @Override + public String getTitle(Locale locale) { + return "Hello World Swing"; + } + + @Override + public HelloWorldInstallationNodeView createView(ViewAPIProvider apiProvider) { + SystemAPI systemAPI = apiProvider.getSystemAPI(); + Style style = systemAPI.getSoftwareVersion().getMajorVersion() >= 5 ? new V5Style() : new V3Style(); + return new HelloWorldInstallationNodeView(style); + } + + @Override + public HelloWorldInstallationNodeContribution createInstallationNode(InstallationAPIProvider apiProvider, HelloWorldInstallationNodeView view, DataModel model, CreationContext context) { + return new HelloWorldInstallationNodeContribution(apiProvider, model, view); + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeView.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeView.java new file mode 100755 index 0000000..813fe4a --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldInstallationNodeView.java @@ -0,0 +1,89 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView; +import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput; + +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 { + + 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); + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeContribution.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeContribution.java new file mode 100755 index 0000000..6a73ea0 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeContribution.java @@ -0,0 +1,108 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import com.ur.urcap.api.contribution.ProgramNodeContribution; +import com.ur.urcap.api.contribution.program.ProgramAPIProvider; +import com.ur.urcap.api.domain.ProgramAPI; +import com.ur.urcap.api.domain.data.DataModel; +import com.ur.urcap.api.domain.script.ScriptWriter; +import com.ur.urcap.api.domain.undoredo.UndoRedoManager; +import com.ur.urcap.api.domain.undoredo.UndoableChanges; +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 HelloWorldProgramNodeContribution implements ProgramNodeContribution { + private static final String NAME = "name"; + + private final ProgramAPI programAPI; + private final UndoRedoManager undoRedoManager; + private final KeyboardInputFactory keyboardFactory; + + private final HelloWorldProgramNodeView view; + private final DataModel model; + + public HelloWorldProgramNodeContribution(ProgramAPIProvider apiProvider, HelloWorldProgramNodeView view, DataModel model) { + this.programAPI = apiProvider.getProgramAPI(); + this.undoRedoManager = apiProvider.getProgramAPI().getUndoRedoManager(); + this.keyboardFactory = apiProvider.getUserInterfaceAPI().getUserInteraction().getKeyboardInputFactory(); + + this.view = view; + this.model = model; + } + + @Override + public void openView() { + view.setPopupText(getName()); + updatePopupMessageAndPreview(); + } + + @Override + public void closeView() { + } + + @Override + public String getTitle() { + return "Hello World Swing: " + (model.isSet(NAME) ? getName() : ""); + } + + @Override + public boolean isDefined() { + return getInstallation().isDefined() && !getName().isEmpty(); + } + + @Override + public void generateScript(ScriptWriter writer) { + // Directly generate this Program Node's popup message + access the popup title through a global variable + writer.appendLine("popup(\"" + generatePopupMessage() + "\", hello_world_swing_popup_title, False, False, blocking=True)"); + writer.writeChildren(); + } + + public KeyboardTextInput getKeyboardForTextField() { + KeyboardTextInput keyboardInput = keyboardFactory.createStringKeyboardInput(); + keyboardInput.setInitialValue(getName()); + return keyboardInput; + } + + public KeyboardInputCallback getCallbackForTextField() { + return new KeyboardInputCallback() { + @Override + public void onOk(String value) { + setPopupTitle(value); + view.setPopupText(value); + } + }; + } + + public void setPopupTitle(final String value) { + undoRedoManager.recordChanges(new UndoableChanges() { + @Override + public void executeChanges() { + if ("".equals(value)) { + model.remove(NAME); + } else { + model.set(NAME, value); + } + } + }); + + updatePopupMessageAndPreview(); + } + + private String generatePopupMessage() { + return model.isSet(NAME) ? "Hello " + getName() + ", welcome to PolyScope!" : "No name set"; + } + + private void updatePopupMessageAndPreview() { + view.setMessagePreview(generatePopupMessage()); + view.setTitlePreview(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set"); + } + + private String getName() { + return model.get(NAME, ""); + } + + private HelloWorldInstallationNodeContribution getInstallation() { + return programAPI.getInstallationNode(HelloWorldInstallationNodeContribution.class); + } + +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeService.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeService.java new file mode 100755 index 0000000..25d5a69 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeService.java @@ -0,0 +1,51 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +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; + +public class HelloWorldProgramNodeService implements SwingProgramNodeService { + + @Override + public String getId() { + return "HelloWorldSwingNode"; + } + + @Override + public void configureContribution(ContributionConfiguration configuration) { + configuration.setChildrenAllowed(true); + } + + @Override + public String getTitle(Locale locale) { + String title = "Hello World Swing"; + if ("ru".equals(locale.getLanguage())) { + title = "Привет мир Swing"; + } else if ("de".equals(locale.getLanguage())) { + title = "Hallo Welt Swing"; + } + return title; + } + + @Override + public HelloWorldProgramNodeView createView(ViewAPIProvider apiProvider) { + SystemAPI systemAPI = apiProvider.getSystemAPI(); + Style style = systemAPI.getSoftwareVersion().getMajorVersion() >= 5 ? new V5Style() : new V3Style(); + return new HelloWorldProgramNodeView(style); + } + + @Override + public HelloWorldProgramNodeContribution createNode( + ProgramAPIProvider apiProvider, + HelloWorldProgramNodeView view, + DataModel model, + CreationContext context) { + return new HelloWorldProgramNodeContribution(apiProvider, view, model); + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeView.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeView.java new file mode 100755 index 0000000..a19cd96 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/HelloWorldProgramNodeView.java @@ -0,0 +1,116 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import com.ur.urcap.api.contribution.ContributionProvider; +import com.ur.urcap.api.contribution.program.swing.SwingProgramNodeView; +import com.ur.urcap.api.domain.userinteraction.keyboard.KeyboardTextInput; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class HelloWorldProgramNodeView implements SwingProgramNodeView{ + + private final Style style; + private JTextField jTextField; + private JLabel previewTitle; + private JLabel previewMessage; + + public HelloWorldProgramNodeView(Style style) { + this.style = style; + } + + @Override + public void buildUI(JPanel jPanel, final ContributionProvider provider) { + jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); + + jPanel.add(createInfo()); + jPanel.add(createVerticalSpacing(style.getVerticalSpacing())); + jPanel.add(createInput(provider)); + jPanel.add(createVerticalSpacing(style.getExtraLargeVerticalSpacing())); + jPanel.add(createPreview()); + } + + private Box createInfo() { + Box infoBox = Box.createHorizontalBox(); + infoBox.setAlignmentX(Component.LEFT_ALIGNMENT); + infoBox.add(new JLabel("This program node will open a popup on execution.")); + return infoBox; + } + + private Box createInput(final ContributionProvider provider) { + Box inputBox = Box.createHorizontalBox(); + inputBox.setAlignmentX(Component.LEFT_ALIGNMENT); + inputBox.add(new JLabel("Enter your name:")); + 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 = provider.get().getKeyboardForTextField(); + keyboardInput.show(jTextField, provider.get().getCallbackForTextField()); + } + }); + + inputBox.add(jTextField); + return inputBox; + } + + private Box createPreview() { + Box previewBox = Box.createVerticalBox(); + JLabel preview = new JLabel("Preview"); + preview.setFont(preview.getFont().deriveFont(Font.BOLD, style.getSmallHeaderFontSize())); + + Box titleBox = Box.createHorizontalBox(); + titleBox.setAlignmentX(Component.LEFT_ALIGNMENT); + titleBox.add(new JLabel("Title:")); + titleBox.add(createHorizontalSpacing()); + previewTitle = new JLabel("my title"); + titleBox.add(previewTitle); + + Box messageBox = Box.createHorizontalBox(); + messageBox.setAlignmentX(Component.LEFT_ALIGNMENT); + messageBox.add(new JLabel("Message:")); + messageBox.add(createHorizontalSpacing()); + previewMessage = new JLabel("my message"); + messageBox.add(previewMessage); + + previewBox.add(preview); + previewBox.add(createVerticalSpacing(style.getLargeVerticalSpacing())); + previewBox.add(titleBox); + previewBox.add(createVerticalSpacing(style.getVerticalSpacing())); + previewBox.add(messageBox); + + return previewBox; + } + + private Component createVerticalSpacing(int height) { + return Box.createRigidArea(new Dimension(0, height)); + } + + private Component createHorizontalSpacing() { + return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0)); + } + + public void setPopupText(String popupText) { + jTextField.setText(popupText); + } + + public void setMessagePreview(String message) { + previewMessage.setText(message); + } + + public void setTitlePreview(String title) { + previewTitle.setText(title); + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Style.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Style.java new file mode 100755 index 0000000..ef36b86 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/Style.java @@ -0,0 +1,33 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import java.awt.*; + +public abstract class Style { + private static final int HORIZONTAL_SPACING = 10; + private static final int VERTICAL_SPACING = 10; + private static final int LARGE_VERTICAL_SPACING = 25; + private static final int XLARGE_VERTICAL_SPACING = 50; + private static final int SMALL_HEADER_FONT_SIZE = 16; + + public int getHorizontalSpacing() { + return HORIZONTAL_SPACING; + } + + public int getVerticalSpacing() { + return VERTICAL_SPACING; + } + + public int getExtraLargeVerticalSpacing() { + return XLARGE_VERTICAL_SPACING; + } + + public int getLargeVerticalSpacing() { + return LARGE_VERTICAL_SPACING; + } + + public int getSmallHeaderFontSize() { + return SMALL_HEADER_FONT_SIZE; + } + + public abstract Dimension getInputfieldSize(); +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V3Style.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V3Style.java new file mode 100755 index 0000000..6c2249f --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V3Style.java @@ -0,0 +1,12 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import java.awt.*; + +public class V3Style extends Style { + private static final Dimension INPUTFIELD_SIZE = new Dimension(200, 24); + + @Override + public Dimension getInputfieldSize() { + return INPUTFIELD_SIZE; + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V5Style.java b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V5Style.java new file mode 100755 index 0000000..6326295 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/java/com/ur/urcap/examples/helloworldswing/impl/V5Style.java @@ -0,0 +1,12 @@ +package com.ur.urcap.examples.helloworldswing.impl; + +import java.awt.*; + +public class V5Style extends Style { + private static final Dimension INPUTFIELD_SIZE = new Dimension(200, 30); + + @Override + public Dimension getInputfieldSize() { + return INPUTFIELD_SIZE; + } +} diff --git a/com.ur.urcap.examples.helloworldswing/src/main/resources/META-INF/LICENSE b/com.ur.urcap.examples.helloworldswing/src/main/resources/META-INF/LICENSE new file mode 100755 index 0000000..6f73257 --- /dev/null +++ b/com.ur.urcap.examples.helloworldswing/src/main/resources/META-INF/LICENSE @@ -0,0 +1,28 @@ +Example: +Copyright (c) , +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. All advertising materials mentioning features or use of this software + must display the following acknowledgement: + This product includes software developed by the . +4. Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file