|
@@ -1,146 +0,0 @@
|
|
|
-package uraxis;
|
|
|
-
|
|
|
-import com.ur.urcap.api.contribution.ProgramNodeContribution;
|
|
|
-import com.ur.urcap.api.domain.URCapAPI;
|
|
|
-import com.ur.urcap.api.domain.data.DataModel;
|
|
|
-import com.ur.urcap.api.domain.script.ScriptWriter;
|
|
|
-import com.ur.urcap.api.ui.annotation.Input;
|
|
|
-import com.ur.urcap.api.ui.annotation.Label;
|
|
|
-import com.ur.urcap.api.ui.component.InputEvent;
|
|
|
-import com.ur.urcap.api.ui.component.InputRadioButton;
|
|
|
-import com.ur.urcap.api.ui.component.InputTextField;
|
|
|
-import com.ur.urcap.api.ui.component.LabelComponent;
|
|
|
-
|
|
|
-import java.awt.*;
|
|
|
-import java.util.Timer;
|
|
|
-import java.util.TimerTask;
|
|
|
-
|
|
|
-public class MyDaemonProgramNodeContribution implements ProgramNodeContribution {
|
|
|
- private static final String POS = "pos";
|
|
|
- private static final String ABSOLUTE = "absolute";
|
|
|
-
|
|
|
-
|
|
|
- private final DataModel model;
|
|
|
- private final URCapAPI api;
|
|
|
- private Timer uiTimer;
|
|
|
-
|
|
|
- public MyDaemonProgramNodeContribution(URCapAPI api, DataModel model) {
|
|
|
- this.api = api;
|
|
|
- this.model = model;
|
|
|
- }
|
|
|
-
|
|
|
- @Input(id = "pos")
|
|
|
- private InputTextField posTextField;
|
|
|
-
|
|
|
- @Input(id = "rbAbs")
|
|
|
- private InputRadioButton radioAbsButton;
|
|
|
-
|
|
|
- @Input(id = "rbRel")
|
|
|
- private InputRadioButton radioRelButton;
|
|
|
-
|
|
|
- @Label(id = "titlePreviewLabel")
|
|
|
- private LabelComponent titlePreviewLabel;
|
|
|
-
|
|
|
- @Label(id = "messagePreviewLabel")
|
|
|
- private LabelComponent messagePreviewLabel;
|
|
|
-
|
|
|
- @Input(id = "pos")
|
|
|
- public void onInput(InputEvent event) {
|
|
|
- if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
|
|
|
- setPos(posTextField.getText());
|
|
|
- updatePreview();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void openView() {
|
|
|
- posTextField.setText(getPos());
|
|
|
- if(isAbsolute())
|
|
|
- radioAbsButton.setSelected();
|
|
|
- else
|
|
|
- radioRelButton.setSelected();
|
|
|
- //UI updates from non-GUI threads must use EventQueue.invokeLater (or SwingUtilities.invokeLater)
|
|
|
- uiTimer = new Timer(true);
|
|
|
- uiTimer.schedule(new TimerTask() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- EventQueue.invokeLater(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- updatePreview();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }, 0, 1000);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public void closeView() {
|
|
|
- uiTimer.cancel();
|
|
|
- if(radioAbsButton.isSelected())
|
|
|
- model.set(ABSOLUTE, true);
|
|
|
- else model.set(ABSOLUTE, false);
|
|
|
- System.out.println("closeView " + radioAbsButton.isSelected());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getTitle() {
|
|
|
- return "Axis " + (isAbsolute()?"Abs":"Rel") + (model.isSet(POS) ? getPos() : "");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean isDefined() {
|
|
|
- // return getInstallation().isDefined() && !getName().isEmpty();
|
|
|
- return !getPos().isEmpty();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void generateScript(ScriptWriter writer) {
|
|
|
- // Interact with the daemon process through XML-RPC calls
|
|
|
- // Note, alternatively plain sockets can be used.
|
|
|
- // if(radioRelButton.isSelected()) {
|
|
|
- // writer.appendLine( getInstallation().getXMLRPCVariable() + ".rel(\"" + getName() + "\")");
|
|
|
- // }
|
|
|
- // else if(radioAbsButton.isSelected()) {
|
|
|
- // writer.appendLine( getInstallation().getXMLRPCVariable() + ".abs(\"" + getName() + "\")");
|
|
|
- // }
|
|
|
- if(isAbsolute()) {
|
|
|
- writer.appendLine( getInstallation().getXMLRPCVariable() + ".abs(\"" + getPos() + "\")");
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- writer.appendLine( getInstallation().getXMLRPCVariable() + ".rel(\"" + getPos() + "\")");
|
|
|
- writer.writeChildren();
|
|
|
- }
|
|
|
-
|
|
|
- private void updatePreview() {
|
|
|
- titlePreviewLabel.setText("pos: " + (radioAbsButton.isSelected()?"Abs":"Rel"));
|
|
|
- //messagePreviewLabel.setText(message);
|
|
|
- }
|
|
|
-
|
|
|
- private String getPos() {
|
|
|
- return model.get(POS, "0");
|
|
|
- }
|
|
|
-
|
|
|
- private void setPos(String name) {
|
|
|
- if ("".equals(name)){
|
|
|
- model.remove(POS);
|
|
|
- }else{
|
|
|
- model.set(POS, name);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private boolean isAbsolute() {
|
|
|
- return model.get(ABSOLUTE, true);
|
|
|
- }
|
|
|
-
|
|
|
- private void setAbsolute(boolean absolute) {
|
|
|
- model.set(ABSOLUTE, absolute);
|
|
|
- }
|
|
|
-
|
|
|
- private MyDaemonInstallationNodeContribution getInstallation(){
|
|
|
- return api.getInstallationNode(MyDaemonInstallationNodeContribution.class);
|
|
|
- }
|
|
|
-}
|