Karsten Schmidt avatar Karsten Schmidt committed 95fd9bc

removing obsolete GUIType, adding IntRangeMinMax builder, minor updates to other classes

Comments (0)

Files changed (7)

src/toxi/gui/AnnoTest.java

     @GUIElement
     public String btRestart = "restart";
 
-    @GUIElement(label = "columns", builder = IntegerRangeBuilder.class)
+    @GUIElement(label = "columns")
     @Range(min = 1, max = 30)
     public int cols = 10;
 
-    @GUIElement(label = "ratio", builder = FloatRangeBuilder.class)
+    @GUIElement(label = "ratio")
     @Range(min = 0.01f, max = 1f)
     public float ratio = 0.5f;
 
     private void initGUI() {
         ControlP5 cp5 = new ControlP5(this);
         gui = new GUIManager(cp5);
-        gui.addDefaultMappings();
         gui.addMapping(toxi.util.datatypes.FloatRange.class,
                 new FloatRangeMinMaxBuilder());
-        gui.createControllers(this, 20, 20,null);        
+        gui.createControllers(this);        
         gui.addListenerFor("isActive", "toggleActive", this);
         gui.addListenerFor("btRestart", "doRestart", this);
     }
         e.controller().setLabel(e.value()>0 ? "enabled" : "disabled");
     }
     
-    public void keyPressed() {
-
-    }
-
     public void setup() {
         size(400, 400);
         options.add("png");

src/toxi/gui/GUIElement.java

 
     public String label() default NO_LABEL;
 
-    public GUIType type() default GUIType.DEFAULT;
-
     public int x() default -1;
 
     public int y() default -1;

src/toxi/gui/GUIManager.java

 import java.util.List;
 
 import toxi.geom.Vec2D;
+import toxi.util.datatypes.FloatRange;
+import toxi.util.datatypes.IntegerRange;
 import controlP5.ControlEvent;
 import controlP5.ControlListener;
 import controlP5.ControlP5;
             new HashMap<Class<?>, GUIElementBuilder>();
 
     public GUIManager(ControlP5 gui) {
+        this(gui,true);
+    }
+    
+    public GUIManager(ControlP5 gui, boolean useDefaults) {
         this.gui = gui;
+        if (useDefaults) {
+            addDefaultMappings();
+        }
     }
 
     public void addDefaultMappings() {
         addMapping(Boolean.class, new CheckboxBuilder());
-        addMapping(Integer.class, new IntegerRangeBuilder());
+        addMapping(Integer.class, new IntRangeBuilder());
         addMapping(Float.class, new FloatRangeBuilder());
         addMapping(Collection.class, new RadioBuilder());
         addMapping(String.class, new ButtonBuilder());
+        addMapping(FloatRange.class, new FloatRangeMinMaxBuilder());
+        addMapping(IntegerRange.class, new IntRangeMinMaxBuilder());
     }
 
     public void addListenerFor(String id, final String name,
         }
     }
 
+    public void createControllers(Object context) {
+        createControllers(context, null);
+    }
+    
     public void createControllers(Object context, Tab tab) {
         int x, y;
         GUIConfiguration config =
             y = config.y();
         } else {
             x = 20;
-            y = 20;
+            y = 40;
         }
         createControllers(context, x, y, tab);
     }

src/toxi/gui/GUIType.java

-/*
- * Copyright (c) 2010 Karsten Schmidt
- * 
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- * 
- * http://creativecommons.org/licenses/LGPL/2.1/
- * 
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package toxi.gui;
-
-public enum GUIType {
-    SLIDER, DIAL, BUTTON, DEFAULT;
-}

src/toxi/gui/IntRangeBuilder.java

+/*
+ * Copyright (c) 2010 Karsten Schmidt
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package toxi.gui;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import toxi.geom.Vec2D;
+import toxi.util.datatypes.IntegerRange;
+import controlP5.ControlEvent;
+import controlP5.ControlListener;
+import controlP5.Controller;
+import controlP5.Slider;
+
+public class IntRangeBuilder implements GUIElementBuilder {
+
+    protected static Slider createSlider(GUIManager gui, String id, int min,
+            int max, int curr, Vec2D pos, String label, ControlListener listener) {
+        Slider s =
+                gui.getGUI().addSlider(id, min, max, curr, (int) pos.x,
+                        (int) pos.y, 100, 14);
+        s.setLabel(label);
+        s.addListener(listener);
+        return s;
+    }
+
+    public List<Controller> createElementsFor(final Object context,
+            final Field field, GUIElement anno, Vec2D pos, String id,
+            String label, GUIManager gui) throws IllegalArgumentException,
+            IllegalAccessException {
+        List<Controller> controllers = new ArrayList<Controller>(1);
+        IntegerRange r = null;
+        boolean singleValue = false;
+        if (field.get(context).getClass() == Integer.class) {
+            Range ra = field.getAnnotation(Range.class);
+            if (ra != null) {
+                r = new IntegerRange((int) ra.min(), (int) ra.max());
+                r.setCurrent(field.getInt(context));
+                singleValue = true;
+            }
+        } else {
+            r = (IntegerRange) field.get(context);
+        }
+        final IntegerRange range = r;
+        final boolean isRange = !singleValue;
+        if (range != null) {
+            range.setCurrent(field.getInt(context));
+            Slider s =
+                    createSlider(gui, id, range.min, range.max,
+                            range.currValue, pos, label, new ControlListener() {
+
+                                public void controlEvent(ControlEvent e) {
+                                    try {
+                                        if (isRange) {
+                                            range.setCurrent((int) e.value());
+                                        } else {
+                                            field.setInt(context,
+                                                    (int) e.value());
+                                        }
+                                    } catch (IllegalArgumentException e1) {
+                                    } catch (IllegalAccessException e1) {
+                                    }
+                                }
+                            });
+            controllers.add(s);
+        }
+        return controllers;
+    }
+
+    public int getMinSpacing() {
+        return 20;
+    }
+}

src/toxi/gui/IntRangeMinMaxBuilder.java

+/*
+ * Copyright (c) 2010 Karsten Schmidt
+ * 
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ * 
+ * http://creativecommons.org/licenses/LGPL/2.1/
+ * 
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package toxi.gui;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import toxi.geom.Vec2D;
+import toxi.util.datatypes.FloatRange;
+import toxi.util.datatypes.IntegerRange;
+import controlP5.ControlEvent;
+import controlP5.ControlListener;
+import controlP5.Controller;
+import controlP5.Slider;
+
+public class IntRangeMinMaxBuilder extends FloatRangeBuilder implements
+        GUIElementBuilder {
+
+    public List<Controller> createElementsFor(final Object context,
+            final Field field, GUIElement anno, Vec2D pos, String id,
+            String label, GUIManager gui) throws IllegalArgumentException,
+            IllegalAccessException {
+        List<Controller> controllers = new ArrayList<Controller>(2);
+        final IntegerRange range = (IntegerRange) field.get(context);
+        Slider s =
+                createSlider(gui, id + "_min", range.min, range.max, range.min,
+                        pos, "min " + label, new ControlListener() {
+
+                            public void controlEvent(ControlEvent e) {
+                                range.min = (int)e.value();
+                            }
+                        });
+        controllers.add(s);
+        s =
+                createSlider(gui, id + "_max", range.min, range.max, range.max,
+                        pos.add(200, 0), "max " + label, new ControlListener() {
+
+                            public void controlEvent(ControlEvent e) {
+                                range.max = (int)e.value();
+                            }
+                        });
+        controllers.add(s);
+        return controllers;
+    }
+
+    @Override
+    public int getMinSpacing() {
+        return 20;
+    }
+
+}

src/toxi/gui/IntegerRangeBuilder.java

-/*
- * Copyright (c) 2010 Karsten Schmidt
- * 
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- * 
- * http://creativecommons.org/licenses/LGPL/2.1/
- * 
- * This library is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package toxi.gui;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-import toxi.geom.Vec2D;
-import toxi.util.datatypes.IntegerRange;
-import controlP5.ControlEvent;
-import controlP5.ControlListener;
-import controlP5.Controller;
-import controlP5.Slider;
-
-public class IntegerRangeBuilder implements GUIElementBuilder {
-
-    protected static Slider createSlider(GUIManager gui, String id, int min,
-            int max, int curr, Vec2D pos, String label, ControlListener listener) {
-        Slider s =
-                gui.getGUI().addSlider(id, min, max, curr, (int) pos.x,
-                        (int) pos.y, 100, 14);
-        s.setLabel(label);
-        s.addListener(listener);
-        return s;
-    }
-
-    public List<Controller> createElementsFor(final Object context,
-            final Field field, GUIElement anno, Vec2D pos, String id,
-            String label, GUIManager gui) throws IllegalArgumentException,
-            IllegalAccessException {
-        List<Controller> controllers = new ArrayList<Controller>(1);
-        IntegerRange r = null;
-        boolean singleValue = false;
-        if (field.get(context).getClass() == Integer.class) {
-            Range ra = field.getAnnotation(Range.class);
-            if (ra != null) {
-                r = new IntegerRange((int) ra.min(), (int) ra.max());
-                r.setCurrent(field.getInt(context));
-                singleValue = true;
-            }
-        } else {
-            r = (IntegerRange) field.get(context);
-        }
-        final IntegerRange range = r;
-        final boolean isRange = !singleValue;
-        if (range != null) {
-            range.setCurrent(field.getInt(context));
-            Slider s =
-                    createSlider(gui, id, range.min, range.max,
-                            range.currValue, pos, label, new ControlListener() {
-
-                                public void controlEvent(ControlEvent e) {
-                                    try {
-                                        if (isRange) {
-                                            range.setCurrent((int) e.value());
-                                        } else {
-                                            field.setInt(context,
-                                                    (int) e.value());
-                                        }
-                                    } catch (IllegalArgumentException e1) {
-                                    } catch (IllegalAccessException e1) {
-                                    }
-                                }
-                            });
-            controllers.add(s);
-        }
-        return controllers;
-    }
-
-    public int getMinSpacing() {
-        return 20;
-    }
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.