svn changeset:5527/svn branch:trunktags/6.7.0.beta1
@@ -68,7 +68,7 @@ public interface Sizeable { | |||
*/ | |||
public static final int UNITS_ROWS = 9; | |||
public static final int SIZE_UNDEFINED = -1; | |||
public static final float SIZE_UNDEFINED = -1; | |||
/** | |||
* Textual representations of units symbols. Supported units and their | |||
@@ -96,7 +96,7 @@ public interface Sizeable { | |||
* | |||
* @return width of the object in units specified by widthUnits property. | |||
*/ | |||
public int getWidth(); | |||
public float getWidth(); | |||
/** | |||
* Sets the width of the object. Negative number implies unspecified size | |||
@@ -110,7 +110,7 @@ public interface Sizeable { | |||
* separately (and components might have different default | |||
* unit). | |||
*/ | |||
public void setWidth(int width); | |||
public void setWidth(float width); | |||
/** | |||
* Gets the height of the object. Negative number implies unspecified size | |||
@@ -118,7 +118,7 @@ public interface Sizeable { | |||
* | |||
* @return height of the object in units specified by heightUnits property. | |||
*/ | |||
public int getHeight(); | |||
public float getHeight(); | |||
/** | |||
* Sets the height of the object. Negative number implies unspecified size | |||
@@ -127,12 +127,12 @@ public interface Sizeable { | |||
* @param height | |||
* the height of the object in units specified by heightUnits | |||
* property. | |||
* @deprecated Consider using {@link #setHeight(String)} instead. This | |||
* method works, but is error-prone since the unit must be set | |||
* separately (and components might have different default | |||
* unit). | |||
* @deprecated Consider using {@link #setHeight(String)} or | |||
* {@link #setHeight(float, int)} instead. This method works, | |||
* but is error-prone since the unit must be set separately (and | |||
* components might have different default unit). | |||
*/ | |||
public void setHeight(int height); | |||
public void setHeight(float height); | |||
/** | |||
* Gets the width property units. | |||
@@ -147,7 +147,8 @@ public interface Sizeable { | |||
* @param units | |||
* the units used in width property. | |||
* @deprecated Consider setting width and unit simultaneously using | |||
* {@link #setWidth(String)}, which is less error-prone. | |||
* {@link #setWidth(String)} or {@link #setWidth(float, int)}, | |||
* which is less error-prone. | |||
*/ | |||
public void setWidthUnits(int units); | |||
@@ -164,7 +165,8 @@ public interface Sizeable { | |||
* @param units | |||
* the units used in height property. | |||
* @deprecated Consider setting height and unit simultaneously using | |||
* {@link #setHeight(String)}, which is less error-prone. | |||
* {@link #setHeight(String)} or {@link #setHeight(float, int)}, | |||
* which is less error-prone. | |||
*/ | |||
public void setHeightUnits(int units); | |||
@@ -186,6 +188,32 @@ public interface Sizeable { | |||
*/ | |||
public void setHeight(String height); | |||
/** | |||
* Sets the width of the object. Negative number implies unspecified size | |||
* (terminal is free to set the size). | |||
* | |||
* @param width | |||
* the width of the object. | |||
* @param unit | |||
* the unit used for the width. Possible values include | |||
* UNITS_PIXELS, UNITS_POINTS, UNITS_PICAS, UNITS_EM, UNITS_EX, | |||
* UNITS_MM, UNITS_CM, UNITS_INCH, UNITS_PERCENTAGE, UNITS_ROWS. | |||
*/ | |||
public void setWidth(float width, int unit); | |||
/** | |||
* Sets the height of the object. Negative number implies unspecified size | |||
* (terminal is free to set the size). | |||
* | |||
* @param height | |||
* the height of the object. | |||
* @param unit | |||
* the unit used for the width. Possible values include | |||
* UNITS_PIXELS, UNITS_POINTS, UNITS_PICAS, UNITS_EM, UNITS_EX, | |||
* UNITS_MM, UNITS_CM, UNITS_INCH, UNITS_PERCENTAGE, UNITS_ROWS. | |||
*/ | |||
public void setHeight(float height, int unit); | |||
/** | |||
* Sets the width of the component using String presentation. | |||
* |
@@ -280,7 +280,7 @@ public class FeatureBrowser extends CustomComponent implements | |||
} | |||
public int getHeight() { | |||
public float getHeight() { | |||
// TODO Auto-generated method stub | |||
return 0; | |||
} | |||
@@ -290,7 +290,7 @@ public class FeatureBrowser extends CustomComponent implements | |||
return 0; | |||
} | |||
public int getWidth() { | |||
public float getWidth() { | |||
// TODO Auto-generated method stub | |||
return 0; | |||
} | |||
@@ -300,7 +300,7 @@ public class FeatureBrowser extends CustomComponent implements | |||
return 0; | |||
} | |||
public void setHeight(int height) { | |||
public void setHeight(float height) { | |||
// TODO Auto-generated method stub | |||
} | |||
@@ -320,7 +320,7 @@ public class FeatureBrowser extends CustomComponent implements | |||
} | |||
public void setWidth(int width) { | |||
public void setWidth(float width) { | |||
// TODO Auto-generated method stub | |||
} |
@@ -52,7 +52,7 @@ public class Ticket1435 extends Application { | |||
Panel container = new Panel(); | |||
// Last known height before the panel was collapsed | |||
private int lastHeight = -1; | |||
private float lastHeight = -1; | |||
private int lastHeightUnit = -1; | |||
public ButtonPanel(String labelString) { |
@@ -0,0 +1,62 @@ | |||
package com.itmill.toolkit.tests.tickets; | |||
import com.itmill.toolkit.Application; | |||
import com.itmill.toolkit.data.Property; | |||
import com.itmill.toolkit.data.Property.ValueChangeEvent; | |||
import com.itmill.toolkit.terminal.Sizeable; | |||
import com.itmill.toolkit.terminal.UserError; | |||
import com.itmill.toolkit.ui.Button; | |||
import com.itmill.toolkit.ui.Label; | |||
import com.itmill.toolkit.ui.TextField; | |||
import com.itmill.toolkit.ui.Window; | |||
public class Ticket2090 extends Application { | |||
Label label = new Label(); | |||
Button target = new Button(); | |||
Window w = new Window("#2090"); | |||
@Override | |||
public void init() { | |||
setMainWindow(w); | |||
final TextField width = new TextField("Width"); | |||
width.setImmediate(true); | |||
final TextField height = new TextField("Height"); | |||
height.setImmediate(true); | |||
w.addComponent(width); | |||
w.addComponent(height); | |||
w.addComponent(label); | |||
w.addComponent(target); | |||
height.addListener(new Property.ValueChangeListener() { | |||
public void valueChange(ValueChangeEvent event) { | |||
try { | |||
target.setHeight(height.toString()); | |||
height.setComponentError(null); | |||
updateLabel(); | |||
} catch (Exception e) { | |||
height.setComponentError(new UserError(e.getMessage())); | |||
} | |||
} | |||
}); | |||
width.addListener(new Property.ValueChangeListener() { | |||
public void valueChange(ValueChangeEvent event) { | |||
try { | |||
target.setWidth(width.toString()); | |||
width.setComponentError(null); | |||
updateLabel(); | |||
} catch (Exception e) { | |||
width.setComponentError(new UserError(e.getMessage())); | |||
} | |||
} | |||
}); | |||
} | |||
private void updateLabel() { | |||
label.setValue("width: " + target.getWidth() | |||
+ Sizeable.UNIT_SYMBOLS[target.getWidthUnits()] + ", height: " | |||
+ target.getHeight() | |||
+ Sizeable.UNIT_SYMBOLS[target.getHeightUnits()]); | |||
} | |||
} |
@@ -21,7 +21,6 @@ import com.itmill.toolkit.terminal.ErrorMessage; | |||
import com.itmill.toolkit.terminal.PaintException; | |||
import com.itmill.toolkit.terminal.PaintTarget; | |||
import com.itmill.toolkit.terminal.Resource; | |||
import com.itmill.toolkit.terminal.Sizeable; | |||
import com.itmill.toolkit.terminal.Terminal; | |||
/** | |||
@@ -120,12 +119,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
/* Sizeable fields */ | |||
private int width = SIZE_UNDEFINED; | |||
private int height = SIZE_UNDEFINED; | |||
private float width = SIZE_UNDEFINED; | |||
private float height = SIZE_UNDEFINED; | |||
private int widthUnit = UNITS_PIXELS; | |||
private int heightUnit = UNITS_PIXELS; | |||
private static final Pattern sizePattern = Pattern | |||
.compile("^(\\d+)(%|px|em|ex|in|cm|mm|pt|pc)$"); | |||
.compile("^(-?\\d+(\\.\\d+)?)(%|px|em|ex|in|cm|mm|pt|pc)?$"); | |||
private ComponentErrorHandler errorHandler = null; | |||
@@ -1008,77 +1007,59 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
/* Sizeable and other size related methods */ | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getHeight() | |||
*/ | |||
public int getHeight() { | |||
public float getHeight() { | |||
return height; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits() | |||
*/ | |||
public int getHeightUnits() { | |||
return heightUnit; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getWidth() | |||
*/ | |||
public int getWidth() { | |||
public float getWidth() { | |||
return width; | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits() | |||
*/ | |||
public int getWidthUnits() { | |||
return widthUnit; | |||
} | |||
/** | |||
* Sets the height without setting the height unit. | |||
* | |||
* @see link {@link Sizeable#setHeight(int)} | |||
* @see link {@link Sizeable#setHeight(String)} | |||
* @see link {@link Sizeable#setHeightUnits(int)} | |||
* @deprecated Error-prone; consider using {link {@link #setHeight(String)} | |||
* or {link {@link #setHeight(int, int)} instead. | |||
*/ | |||
public void setHeight(int height) { | |||
public void setHeight(float height) { | |||
this.height = height; | |||
requestRepaint(); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
/** | |||
* Sets the height property units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int) | |||
* @param units | |||
* the units used in height property. | |||
* @deprecated Consider setting height and unit simultaneously using | |||
* {@link #setHeight(String)} or {@link #setHeight(float, int)}, | |||
* which is less error-prone. | |||
*/ | |||
public void setHeightUnits(int unit) { | |||
heightUnit = unit; | |||
requestRepaint(); | |||
} | |||
public void setHeight(int height, int unit) { | |||
setHeight(height); | |||
setHeightUnits(unit); | |||
/** | |||
* Sets the height of the object. Negative number implies unspecified size | |||
* (terminal is free to set the size). | |||
* | |||
* @param height | |||
* the height of the object in units specified by heightUnits | |||
* property. | |||
* @deprecated Consider using {@link #setHeight(String)} or | |||
* {@link #setHeight(float, int)} instead. This method works, | |||
* but is error-prone since the unit must be set separately (and | |||
* components might have different default unit). | |||
*/ | |||
public void setHeight(float height, int unit) { | |||
this.height = height; | |||
heightUnit = unit; | |||
requestRepaint(); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setSizeFull() | |||
*/ | |||
public void setSizeFull() { | |||
height = 100; | |||
width = 100; | |||
@@ -1087,11 +1068,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
requestRepaint(); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined() | |||
*/ | |||
public void setSizeUndefined() { | |||
height = -1; | |||
width = -1; | |||
@@ -1101,52 +1077,62 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
} | |||
/** | |||
* Sets the width without setting the width unit. | |||
* Sets the width of the object. Negative number implies unspecified size | |||
* (terminal is free to set the size). | |||
* | |||
* @see link {@link Sizeable#setWidth(int)} | |||
* @see link {@link Sizeable#setWidth(String)} | |||
* @see link {@link Sizeable#setWidthUnits(int)} | |||
* @deprecated Error-prone; consider using {link {@link #setWidth(String)} | |||
* or {link {@link #setWidth(int, int)} instead. | |||
*/ | |||
public void setWidth(int width) { | |||
* @param width | |||
* the width of the object in units specified by widthUnits | |||
* property. | |||
* @deprecated Consider using {@link #setWidth(String)} instead. This method | |||
* works, but is error-prone since the unit must be set | |||
* separately (and components might have different default | |||
* unit). | |||
*/ | |||
public void setWidth(float width) { | |||
this.width = width; | |||
requestRepaint(); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
/** | |||
* Sets the width property units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int) | |||
* @param units | |||
* the units used in width property. | |||
* @deprecated Consider setting width and unit simultaneously using | |||
* {@link #setWidth(String)} or {@link #setWidth(float, int)}, | |||
* which is less error-prone. | |||
*/ | |||
public void setWidthUnits(int unit) { | |||
widthUnit = unit; | |||
requestRepaint(); | |||
} | |||
public void setWidth(int width, int unit) { | |||
setWidth(width); | |||
setWidthUnits(unit); | |||
public void setWidth(float width, int unit) { | |||
this.width = width; | |||
widthUnit = unit; | |||
requestRepaint(); | |||
} | |||
public void setWidth(String width) { | |||
int[] p = parseStringSize(width); | |||
setWidth(p[0]); | |||
setWidthUnits(p[1]); | |||
float[] p = parseStringSize(width); | |||
this.width = p[0]; | |||
widthUnit = (int) p[1]; | |||
requestRepaint(); | |||
} | |||
public void setHeight(String height) { | |||
int[] p = parseStringSize(height); | |||
setHeight(p[0]); | |||
setHeightUnits(p[1]); | |||
float[] p = parseStringSize(height); | |||
this.height = p[0]; | |||
heightUnit = (int) p[1]; | |||
requestRepaint(); | |||
} | |||
/* | |||
* Returns array with size in index 0 unit in index 1. Null or empty string | |||
* will produce {-1,UNITS_PIXELS} | |||
*/ | |||
private static int[] parseStringSize(String s) { | |||
int[] values = { -1, UNITS_PIXELS }; | |||
private static float[] parseStringSize(String s) { | |||
float[] values = { -1, UNITS_PIXELS }; | |||
if (s == null) { | |||
return values; | |||
} | |||
@@ -1157,26 +1143,32 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
Matcher matcher = sizePattern.matcher(s); | |||
if (matcher.find()) { | |||
values[0] = Integer.parseInt(matcher.group(1)); | |||
String unit = matcher.group(2); | |||
if (unit.equals("%")) { | |||
values[1] = UNITS_PERCENTAGE; | |||
} else if (unit.equals("px")) { | |||
values[1] = UNITS_PIXELS; | |||
} else if (unit.equals("em")) { | |||
values[1] = UNITS_EM; | |||
} else if (unit.equals("ex")) { | |||
values[1] = UNITS_EX; | |||
} else if (unit.equals("in")) { | |||
values[1] = UNITS_INCH; | |||
} else if (unit.equals("cm")) { | |||
values[1] = UNITS_CM; | |||
} else if (unit.equals("mm")) { | |||
values[1] = UNITS_MM; | |||
} else if (unit.equals("pt")) { | |||
values[1] = UNITS_POINTS; | |||
} else if (unit.equals("pc")) { | |||
values[1] = UNITS_PICAS; | |||
values[0] = Float.parseFloat(matcher.group(1)); | |||
if (values[0] < 0) { | |||
values[0] = -1; | |||
} else { | |||
String unit = matcher.group(3); | |||
if (unit == null) { | |||
values[1] = UNITS_PIXELS; | |||
} else if (unit.equals("px")) { | |||
values[1] = UNITS_PIXELS; | |||
} else if (unit.equals("%")) { | |||
values[1] = UNITS_PERCENTAGE; | |||
} else if (unit.equals("em")) { | |||
values[1] = UNITS_EM; | |||
} else if (unit.equals("ex")) { | |||
values[1] = UNITS_EX; | |||
} else if (unit.equals("in")) { | |||
values[1] = UNITS_INCH; | |||
} else if (unit.equals("cm")) { | |||
values[1] = UNITS_CM; | |||
} else if (unit.equals("mm")) { | |||
values[1] = UNITS_MM; | |||
} else if (unit.equals("pt")) { | |||
values[1] = UNITS_POINTS; | |||
} else if (unit.equals("pc")) { | |||
values[1] = UNITS_PICAS; | |||
} | |||
} | |||
} else { | |||
throw new IllegalArgumentException("Invalid size argument: \"" + s |
@@ -286,15 +286,10 @@ public class Panel extends AbstractComponentContainer implements Scrollable, | |||
final Integer newWidth = (Integer) variables.get("width"); | |||
final Integer newHeight = (Integer) variables.get("height"); | |||
if (newWidth != null && newWidth.intValue() != getWidth()) { | |||
setWidth(newWidth.intValue()); | |||
// ensure units, as we are reading pixels | |||
setWidthUnits(UNITS_PIXELS); | |||
setWidth(newWidth.intValue(), UNITS_PIXELS); | |||
} | |||
if (newHeight != null && newHeight.intValue() != getHeight()) { | |||
setHeight(newHeight.intValue()); | |||
// ensure units, as we are reading pixels | |||
setHeightUnits(UNITS_PIXELS); | |||
setHeight(newHeight.intValue(), UNITS_PIXELS); | |||
} | |||
// Scrolling |
@@ -341,12 +341,10 @@ public class Slider extends AbstractField { | |||
this.size = size; | |||
switch (orientation) { | |||
case ORIENTATION_HORIZONTAL: | |||
setWidth(size); | |||
setWidthUnits(UNITS_PIXELS); | |||
setWidth(size, UNITS_PIXELS); | |||
break; | |||
default: | |||
setHeight(size); | |||
setHeightUnits(UNITS_PIXELS); | |||
setHeight(size, UNITS_PIXELS); | |||
break; | |||
} | |||
requestRepaint(); |