Mercurial > forge
changeset 3714:6c8ac3e3212b octave-forge
implement "Position" property for figures + implement more units types
author | goffioul |
---|---|
date | Wed, 01 Aug 2007 14:12:46 +0000 |
parents | 489b317deba1 |
children | 0f78c8045269 |
files | extra/jhandles/src/org/octave/graphics/AxesObject.java extra/jhandles/src/org/octave/graphics/FigureObject.java extra/jhandles/src/org/octave/graphics/HandleObject.java extra/jhandles/src/org/octave/graphics/Property.java extra/jhandles/src/org/octave/graphics/PropertySet.java extra/jhandles/src/org/octave/graphics/UIControlObject.java extra/jhandles/src/org/octave/graphics/UIPanelObject.java extra/jhandles/src/org/octave/graphics/Utils.java |
diffstat | 8 files changed, 122 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/jhandles/src/org/octave/graphics/AxesObject.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/AxesObject.java Wed Aug 01 14:12:46 2007 +0000 @@ -82,7 +82,8 @@ } private String currentUnits; - protected int autoMode = 0; + // TODO: remove + //protected int autoMode = 0; RenderCanvas canvas; LegendObject legend; @@ -210,7 +211,7 @@ Position = new VectorProperty(this, "Position", new double[0], -1); OuterPosition = new VectorProperty(this, "OuterPosition", new double[] {0,0,1,1}, -1); Units = new RadioProperty(this, "Units", - new String[] { "pixels", "normalized" }, "normalized"); + new String[] { "pixels", "normalized", "characters", "inches", "centimeters", "points" }, "normalized"); currentUnits = "normalized"; Projection = new RadioProperty(this, "Projection", new String[] { "orthogonal", "perspective" }, "orthogonal"); AxesColor = new ColorProperty(this, "Color", Color.white, new String[] {"none"}, null); @@ -1507,6 +1508,7 @@ } } + /* TODO: remove void autoSet(Property p, Object value) { autoMode++; @@ -1518,6 +1520,7 @@ { return (autoMode > 0); } + */ protected void autoScale() {
--- a/extra/jhandles/src/org/octave/graphics/FigureObject.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/FigureObject.java Wed Aug 01 14:12:46 2007 +0000 @@ -61,6 +61,7 @@ private AxesObject mouseAxes = null; private int mouseOp = OP_NONE; private int defaultMouseOp = OP_ZOOM; + private String currentUnits; public static final int OP_NONE = 0; public static final int OP_ZOOM = 1; @@ -77,7 +78,9 @@ RadioProperty NextPlot; BooleanProperty NumberTitle; RadioProperty PaperOrientation; + VectorProperty Position; CallbackProperty ResizeFcn; + RadioProperty Units; // Constructor @@ -133,12 +136,19 @@ Alphamap = new VectorProperty(this, "Alphamap", amap, -1); PaperOrientation = new RadioProperty(this, "PaperOrientation", new String[] {"portrait", "landscape"}, "portrait"); IntegerHandle = new BooleanProperty(this, "IntegerHandle", true); + Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized", "inches", "centimeters", + "points", "characters"}, "pixels"); + currentUnits = Units.getValue(); + Position = new VectorProperty(this, "Position", new double[] { + frame.getX()+1, frame.getY()+1, frame.getWidth(), frame.getHeight()}, 4); updateTitle(); listen(Name); listen(NumberTitle); listen(IntegerHandle); + listen(Position); + listen(Units); // show window frame frame.setVisible(true); @@ -247,6 +257,19 @@ updateTitle(); else if (p == IntegerHandle) updateHandle(); + else if (p == Position && !isAutoMode()) + { + double[] pos = Utils.convertPosition(Position.getVector(), Units.getValue(), "pixels", null); + Dimension d = Utils.getScreenSize(); + pos[0]--; + pos[1] = d.height-pos[1]-pos[3]+1; + frame.setBounds((int)pos[0], (int)pos[1], (int)pos[2], (int)pos[3]); + } + else if (p == Units) + { + updatePosition(); + currentUnits = Units.getValue(); + } } public Component getComponent() @@ -254,6 +277,12 @@ return axPanel; } + public Object get(Property p) + { + if (p == Position) + updatePosition(); + return super.get(p); + } // WindowListener interface @@ -403,6 +432,14 @@ public void componentHidden(ComponentEvent e) {} + private void updatePosition() + { + Dimension d = Utils.getScreenSize(); + double[] pos = new double[] {frame.getX()+1, d.height-frame.getY()-frame.getHeight()+1, + frame.getWidth(), frame.getHeight()}; + autoSet(Position, Utils.convertPosition(pos, "pixels", Units.getValue(), null)); + } + public void componentMoved(ComponentEvent e) {} public void componentResized(ComponentEvent e)
--- a/extra/jhandles/src/org/octave/graphics/HandleObject.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/HandleObject.java Wed Aug 01 14:12:46 2007 +0000 @@ -31,6 +31,7 @@ private Renderer.CachedData cachedData = null; private boolean valid = false; private List notifierList = new LinkedList(); + protected int autoMode = 0; private static int handleSeed = -1; private static HashMap handleMap = new HashMap(); @@ -244,6 +245,18 @@ return null; } + protected void autoSet(Property p, Object value) + { + autoMode++; + p.set(value, true); + autoMode--; + } + + protected boolean isAutoMode() + { + return (autoMode > 0); + } + /* HandleNotifier.Sink interface */ public void addNotifier(HandleNotifier hn)
--- a/extra/jhandles/src/org/octave/graphics/Property.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/Property.java Wed Aug 01 14:12:46 2007 +0000 @@ -113,6 +113,7 @@ if (setFlag) { System.out.println("WARNING: " + getName() + ".set (" + ((HandleObject)getParent()).getHandle() + "): recursive behavior detected, not setting"); + Thread.dumpStack(); return; }
--- a/extra/jhandles/src/org/octave/graphics/PropertySet.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/PropertySet.java Wed Aug 01 14:12:46 2007 +0000 @@ -90,7 +90,10 @@ { Property p = (Property)it.next(); if (p.isVisible()) + { + get(p); /* force any getter to execute */ System.out.println(" " + p.getName() + " = " + p); + } } }
--- a/extra/jhandles/src/org/octave/graphics/UIControlObject.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/UIControlObject.java Wed Aug 01 14:12:46 2007 +0000 @@ -86,7 +86,8 @@ "listbox", "popupmenu"}, "pushbutton"); TooltipString = new StringProperty(this, "TooltipString", ""); - Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized", "characters"}, "pixels"); + Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized", "characters", "inches", + "centimeters", "points"}, "pixels"); Value = new VectorProperty(this, "Value", new double[] {0}, -1); listen(FontUnits);
--- a/extra/jhandles/src/org/octave/graphics/UIPanelObject.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/UIPanelObject.java Wed Aug 01 14:12:46 2007 +0000 @@ -83,7 +83,8 @@ TitlePosition = new RadioProperty(this, "TitlePosition", new String[] { "lefttop", "centertop", "righttop", "leftbottom", "centerbottom", "rightbottom"}, "lefttop"); - Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized"}, "normalized"); + Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized", "characters", + "inches", "centimeters", "points"}, "normalized"); listen(BackgroundColor); listen(FontAngle);
--- a/extra/jhandles/src/org/octave/graphics/Utils.java Sun Jul 29 13:18:32 2007 +0000 +++ b/extra/jhandles/src/org/octave/graphics/Utils.java Wed Aug 01 14:12:46 2007 +0000 @@ -31,6 +31,8 @@ import java.awt.Component; import java.awt.Insets; import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Dimension; import javax.swing.UIManager; public class Utils @@ -138,17 +140,32 @@ return new Font(map); } + public static Rectangle getScreenRectangle() + { + return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); + } + + public static Dimension getScreenSize() + { + return Toolkit.getDefaultToolkit().getScreenSize(); + } + + public static int getScreenResolution() + { + return Toolkit.getDefaultToolkit().getScreenResolution(); + } + public static double[] convertPosition(double[] pos, String fromUnits, String toUnits, Component parent) { double[] p = null; - boolean isContainer = (parent instanceof Container); + boolean isContainer = (parent != null && parent instanceof Container); if (fromUnits.equalsIgnoreCase("pixels")) p = (double[])pos.clone(); else if (fromUnits.equalsIgnoreCase("normalized")) { Insets ir = (isContainer ? ((Container)parent).getInsets() : new Insets(0, 0, 0, 0)); - Rectangle r = parent.getBounds(); + Rectangle r = (parent != null ? parent.getBounds() : getScreenRectangle()); int w = r.width-ir.left-ir.right, h = r.height-ir.top-ir.bottom; p = new double[] {pos[0]*w+1, pos[1]*h+1, pos[2]*w, pos[3]*h}; @@ -160,13 +177,28 @@ p = new double[] {pos[0]*w+1, pos[1]*h+1, pos[2]*w, pos[3]*h}; } + else if (fromUnits.equalsIgnoreCase("points")) + { + double f = getScreenResolution()/72.0; + p = new double[] {pos[0]*f+1, pos[1]*f+1, pos[2]*f, pos[3]*f}; + } + else if (fromUnits.equalsIgnoreCase("inches")) + { + double f = getScreenResolution(); + p = new double[] {pos[0]*f+1, pos[1]*f+1, pos[2]*f, pos[3]*f}; + } + else if (fromUnits.equalsIgnoreCase("centimeters")) + { + double f = getScreenResolution()/2.54; + p = new double[] {pos[0]*f+1, pos[1]*f+1, pos[2]*f, pos[3]*f}; + } if (!toUnits.equalsIgnoreCase("pixels")) { if (toUnits.equalsIgnoreCase("normalized")) { Insets ir = (isContainer ? ((Container)parent).getInsets() : new Insets(0, 0, 0, 0)); - Rectangle r = parent.getBounds(); + Rectangle r = (parent != null ? parent.getBounds() : getScreenRectangle()); int w = r.width-ir.left-ir.right, h = r.height-ir.top-ir.bottom; p[0] = (p[0]-1)/w; @@ -184,6 +216,30 @@ p[2] /= w; p[3] /= h; } + else if (toUnits.equalsIgnoreCase("inches")) + { + double f = getScreenResolution(); + p[0] = (p[0]-1)/f; + p[1] = (p[1]-1)/f; + p[2] /= f; + p[3] /= f; + } + else if (toUnits.equalsIgnoreCase("centimeters")) + { + double f = getScreenResolution()/2.54; + p[0] = (p[0]-1)/f; + p[1] = (p[1]-1)/f; + p[2] /= f; + p[3] /= f; + } + else if (toUnits.equalsIgnoreCase("inches")) + { + double f = getScreenResolution()/72.0; + p[0] = (p[0]-1)/f; + p[1] = (p[1]-1)/f; + p[2] /= f; + p[3] /= f; + } } return p;