123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package com.itmill.toolkit.ui;
-
- import com.itmill.toolkit.terminal.PaintException;
- import com.itmill.toolkit.terminal.PaintTarget;
-
- /**
- * An abstract class that defines default implementation for the {@link Layout}
- * interface.
- *
- * @author IT Mill Ltd.
- * @version
- * @VERSION@
- * @since 5.0
- */
- public abstract class AbstractLayout extends AbstractComponentContainer
- implements Layout {
-
- /**
- * Layout edge margins, clockwise from top: top, right, bottom, left. Each
- * is set to true, if the client-side implementation should leave extra
- * space at that edge.
- */
- private boolean[] margins;
-
- /**
- * Height of the layout. Set to -1 for undefined height.
- */
- private int height = -1;
-
- /**
- * Height unit.
- *
- * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
- */
- private int heightUnit = UNITS_PIXELS;
-
- /**
- * Width of the layout. Set to -1 for undefined width.
- */
- private int width = -1;
-
- /**
- * Width unit.
- *
- * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
- */
- private int widthUnit = UNITS_PIXELS;
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.ui.AbstractComponent#getTag()
- */
- public abstract String getTag();
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.ui.Layout#setMargin(boolean)
- */
- public void setMargin(boolean enabled) {
- margins = new boolean[] { enabled, enabled, enabled, enabled };
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.ui.Layout#setMargin(boolean, boolean, boolean,
- * boolean)
- */
- public void setMargin(boolean topEnabled, boolean rightEnabled,
- boolean bottomEnabled, boolean leftEnabled) {
- margins = new boolean[] { topEnabled, rightEnabled, bottomEnabled,
- leftEnabled };
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
- */
- public int 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() {
- return width;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
- */
- public int getWidthUnits() {
- return widthUnit;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
- */
- public void setHeight(int height) {
- this.height = height;
- requestRepaint();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
- */
- public void setHeightUnits(int units) {
- this.heightUnit = units;
- requestRepaint();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
- */
- public void setSizeFull() {
- height = 100;
- width = 100;
- heightUnit = UNITS_PERCENTAGE;
- widthUnit = UNITS_PERCENTAGE;
- requestRepaint();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
- */
- public void setSizeUndefined() {
- height = -1;
- width = -1;
- heightUnit = UNITS_PIXELS;
- widthUnit = UNITS_PIXELS;
- requestRepaint();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
- */
- public void setWidth(int width) {
- this.width = width;
- requestRepaint();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
- */
- public void setWidthUnits(int units) {
- this.widthUnit = units;
- requestRepaint();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.itmill.toolkit.ui.AbstractComponent#paintContent(com.itmill.toolkit.terminal.PaintTarget)
- */
- public void paintContent(PaintTarget target) throws PaintException {
- super.paintContent(target);
-
- // Add margin info. Defaults to false.
- if (margins == null)
- setMargin(false);
- target.addAttribute("marginTop", margins[0]);
- target.addAttribute("marginRight", margins[1]);
- target.addAttribute("marginBottom", margins[2]);
- target.addAttribute("marginLeft", margins[3]);
-
- // Add size info
- if (getHeight() > -1)
- target.addAttribute("height", getHeight()
- + UNIT_SYMBOLS[getHeightUnits()]);
- if (getWidth() > -1)
- target.addAttribute("height", getWidth()
- + UNIT_SYMBOLS[getWidthUnits()]);
- }
-
- }
|