changeset 3610:dc4e4b02468b octave-forge

support "characters" unit
author goffioul
date Tue, 10 Jul 2007 15:03:52 +0000
parents 6e89b0141a5f
children a727a0afe9fc
files extra/jhandles/src/org/octave/graphics/UIControlObject.java extra/jhandles/src/org/octave/graphics/Utils.java
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/extra/jhandles/src/org/octave/graphics/UIControlObject.java	Tue Jul 10 14:46:17 2007 +0000
+++ b/extra/jhandles/src/org/octave/graphics/UIControlObject.java	Tue Jul 10 15:03:52 2007 +0000
@@ -86,7 +86,7 @@
 			  "listbox",
 			  "popupmenu"}, "pushbutton");
 		TooltipString = new StringProperty(this, "TooltipString", "");
-		Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized"}, "pixels");
+		Units = new RadioProperty(this, "Units", new String[] {"pixels", "normalized", "characters"}, "pixels");
 		Value = new VectorProperty(this, "Value", new double[] {0}, -1);
 
 		listen(FontUnits);
--- a/extra/jhandles/src/org/octave/graphics/Utils.java	Tue Jul 10 14:46:17 2007 +0000
+++ b/extra/jhandles/src/org/octave/graphics/Utils.java	Tue Jul 10 15:03:52 2007 +0000
@@ -25,6 +25,7 @@
 import java.util.HashMap;
 import java.awt.Color;
 import java.awt.Font;
+import java.awt.FontMetrics;
 import java.awt.font.TextAttribute;
 import java.awt.Container;
 import java.awt.Component;
@@ -152,6 +153,13 @@
 
 			p = new double[] {pos[0]*w+1, pos[1]*h+1, pos[2]*w, pos[3]*h};
 		}
+		else if (fromUnits.equalsIgnoreCase("characters"))
+		{
+			FontMetrics fm = parent.getFontMetrics(Font.decode(""));
+			int w = fm.charWidth('x'), h = fm.getHeight();
+			
+			p = new double[] {pos[0]*w+1, pos[1]*h+1, pos[2]*w, pos[3]*h};
+		}
 
 		if (!toUnits.equalsIgnoreCase("pixels"))
 		{
@@ -166,6 +174,16 @@
 				p[2] /= w;
 				p[3] /= h;
 			}
+			else if (toUnits.equalsIgnoreCase("characters"))
+			{
+				FontMetrics fm = parent.getFontMetrics(Font.decode(""));
+				int w = fm.charWidth('x'), h = fm.getHeight();
+
+				p[0] = (p[0]-1)/w;
+				p[1] = (p[1]-1)/h;
+				p[2] /= w;
+				p[3] /= h;
+			}
 		}
 
 		return p;