TransitionPropertiesEditor.java
Go to the documentation of this file.
00001 package edu.tum.cs.ias.knowrob.vis.applets;
00002 
00003 import java.util.HashMap;
00004 import java.util.Map;
00005 
00006 import controlP5.Button;
00007 import controlP5.ControlEvent;
00008 import controlP5.ControlListener;
00009 import controlP5.ControlP5;
00010 import controlP5.ControlWindow;
00011 import controlP5.ListBox;
00012 import controlP5.ListBoxItem;
00013 import edu.tum.cs.ias.knowrob.vis.actions.ActionTransition;
00014 import edu.tum.cs.ias.knowrob.vis.actions.FsmActionResult;
00015 import edu.tum.cs.ias.knowrob.vis.themes.GreyTheme;
00016 
00017 
00025 public class TransitionPropertiesEditor {
00026 
00027         public ControlP5 controlP5;
00028         ControlWindow controlWindow;
00029         DialogListener dialogListener;
00030         
00031         private ActionTransition transition;
00032         
00033         String recipe_owl_file = "";
00034 
00035         public PlanVisAppletFsm app;
00036 
00037         private Map<Integer, ListBoxItem> id2button;
00038         ListBoxItem cur = null;
00039         ListBox props;
00040         
00048         public TransitionPropertiesEditor(PlanVisAppletFsm applet, ActionTransition t) {
00049                 
00050                 this.app = applet;
00051                 transition = t;
00052                 
00053                 controlP5 = new ControlP5(app);
00054                 GreyTheme.applyStyle(controlP5);
00055                 
00056                 controlWindow = controlP5.addControlWindow("controlP5window",200,200,350,150)
00057                                                                  .setBackground(app.color(50))
00058                                                                  .setUpdateMode(ControlWindow.NORMAL)
00059                                                                  .setTitle("Edit state transitions");
00060 
00061                 controlP5.addTextlabel("from action", "From action: " + transition.getFrom().getLabel(), 20, 30 );
00062                 controlP5.addTextlabel("to action",   "To action: " + transition.getFrom().getLabel(),   20, 65 );
00063                 
00064                 Button b = GreyTheme.applyStyle(controlP5.addButton("apply", 23, 220, 30, 80, 20)).moveTo(controlWindow);
00065                 
00066                 
00067                 props = controlP5.addListBox("Transition type", 10, 30, 200, 125);
00068                 props.setBarHeight(15).setItemHeight(15);
00069                 props.setColorValue(app.color(120,40,40));
00070                 GreyTheme.applyStyle(props, 15).moveTo(controlWindow);
00071 
00072                 id2button = new HashMap<Integer, ListBoxItem>();
00073                 int props_idx = 0;
00074                 for(FsmActionResult r : FsmActionResult.values()) { // TODO: read from / convert to OWL (via method in FsmActionResult?)
00075                         
00076                         ListBoxItem i = props.addItem(r.toString(), props_idx);
00077 
00078                         if(transition.getCause().endsWith(i.getName())) {
00079                                 i.setColorBackground(120);
00080                                 cur = i;
00081                         }
00082                         
00083                         id2button.put(props_idx, i);
00084                         props_idx++;
00085                 }
00086                                 
00087                 dialogListener = new DialogListener();
00088 
00089                 b.addListener(dialogListener);
00090                 props.addListener(dialogListener);
00091 
00092         }
00093 
00094 
00105         public class DialogListener implements ControlListener {
00106 
00107                 public void controlEvent(ControlEvent ev) {
00108                         try {
00109                                 
00110                                 if (ev != null && ev.isGroup()) {
00111                                         
00112                                         if(ev.getGroup().getName().equals("Transition type")) {
00113                                                 
00114                                                 if(cur!=null)
00115                                                         cur.setColorBackground(80);
00116                                                 
00117                                                 cur = id2button.get((int)ev.getValue());
00118                                                 cur.setColorBackground(120);
00119                                                 
00120                                         }
00121                                         
00122                                 } else if (ev.isController()) {
00123                                         
00124                                         if(ev.getController().getName().equals("apply")) {
00125                                                 
00126                                                 transition.setCause(FsmActionResult.toOWLIdentifier(
00127                                                                                                 FsmActionResult.fromString(
00128                                                                                                                 id2button.get((int)props.getValue()).getName())));
00129                                                 controlWindow.hide();
00130                                                 return;
00131                                         }
00132                                 }
00133                                 
00134                         } catch (Exception e ) {
00135                                 e.printStackTrace();
00136                         }
00137                 }
00138         }
00139         
00140 }


mod_vis
Author(s): Moritz Tenorth, Jakob Engel
autogenerated on Mon Oct 6 2014 01:30:00