svn changeset:2659/svn branch:trunktags/6.7.0.beta1
@@ -216,4 +216,14 @@ public class GoogleMap extends AbstractComponent implements Sizeable, | |||
public void clear() { | |||
setContainerDataSource(null); | |||
} | |||
public void setSizeFull() { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setSizeUndefined() { | |||
// TODO Auto-generated method stub | |||
} | |||
} |
@@ -4,7 +4,7 @@ | |||
Development of Browser User Interfaces Made Easy | |||
Copyright (C) 2000-2006 IT Mill Ltd | |||
Copyright (C) 2000-2007 IT Mill Ltd | |||
************************************************************************* | |||
@@ -177,5 +177,15 @@ public interface Sizeable { | |||
* the units used in height property. | |||
*/ | |||
public void setHeightUnits(int units); | |||
/** | |||
* Sets the size to 100% x 100%. | |||
*/ | |||
public void setSizeFull(); | |||
/** | |||
* Clears any size settings. | |||
*/ | |||
public void setSizeUndefined(); | |||
} |
@@ -39,8 +39,8 @@ public class IGridLayout extends FlexTable implements Paintable, Container { | |||
if ("gc".equals(c.getTag())) { | |||
column++; | |||
int w; | |||
if (c.hasAttribute("w")) { | |||
w = c.getIntAttribute("w"); | |||
if (c.hasAttribute("cols")) { | |||
w = c.getIntAttribute("cols"); | |||
} else | |||
w = 1; | |||
((FlexCellFormatter) getCellFormatter()).setColSpan( |
@@ -50,7 +50,6 @@ public class TestForBasicApplicationLayout extends CustomComponent { | |||
Panel p = new Panel("Accordion Panel"); | |||
p.setHeight(100); | |||
p.setHeightUnits(Panel.UNITS_PERCENTAGE); | |||
p.addStyleName(Panel.STYLE_NO_PADDING); | |||
tab = new TabSheet(); | |||
tab.setWidth(100); | |||
@@ -70,7 +69,7 @@ public class TestForBasicApplicationLayout extends CustomComponent { | |||
cal.setLocale(new Locale("en", "US")); | |||
report.addComponent(cal); | |||
((ExpandLayout) report.getLayout()).expand(controls); | |||
report.setStyle("light"); | |||
report.addStyleName(Panel.STYLE_LIGHT); | |||
report.setHeight(100); | |||
report.setHeightUnits(Sizeable.UNITS_PERCENTAGE); | |||
@@ -9,6 +9,7 @@ import com.itmill.toolkit.ui.Label; | |||
import com.itmill.toolkit.ui.OptionGroup; | |||
import com.itmill.toolkit.ui.OrderedLayout; | |||
import com.itmill.toolkit.ui.Select; | |||
import com.itmill.toolkit.ui.Slider; | |||
import com.itmill.toolkit.ui.Window; | |||
import com.itmill.toolkit.ui.Button.ClickEvent; | |||
import com.itmill.toolkit.ui.Button.ClickListener; | |||
@@ -57,6 +58,17 @@ public class TestForWindowing extends CustomComponent { | |||
w.addComponent(s1); | |||
w.addComponent(TestForWindowing.this.s2); | |||
Slider s = new Slider(); | |||
s.setCaption("Volume"); | |||
s.setMax(13); | |||
s.setMin(12); | |||
s.setResolution(2); | |||
s.setImmediate(true); | |||
//s.setOrientation(Slider.ORIENTATION_VERTICAL); | |||
//s.setArrows(false); | |||
w.addComponent(s); | |||
getApplication().getMainWindow().addWindow(w); | |||
} |
@@ -279,4 +279,65 @@ public class FeatureBrowser extends CustomComponent implements | |||
// TODO Auto-generated method stub | |||
} | |||
public void setMargin(boolean enabled) { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setMargin(boolean top, boolean right, boolean bottom, | |||
boolean left) { | |||
// TODO Auto-generated method stub | |||
} | |||
public int getHeight() { | |||
// TODO Auto-generated method stub | |||
return 0; | |||
} | |||
public int getHeightUnits() { | |||
// TODO Auto-generated method stub | |||
return 0; | |||
} | |||
public int getWidth() { | |||
// TODO Auto-generated method stub | |||
return 0; | |||
} | |||
public int getWidthUnits() { | |||
// TODO Auto-generated method stub | |||
return 0; | |||
} | |||
public void setHeight(int height) { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setHeightUnits(int units) { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setSizeFull() { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setSizeUndefined() { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setWidth(int width) { | |||
// TODO Auto-generated method stub | |||
} | |||
public void setWidthUnits(int units) { | |||
// TODO Auto-generated method stub | |||
} | |||
} |
@@ -71,7 +71,6 @@ public class PropertyPanel extends Panel implements Button.ClickListener, | |||
// Layout | |||
setCaption("Properties"); | |||
addComponent(formsLayout); | |||
addStyleName(Panel.STYLE_NO_PADDING); | |||
setWidth(100); | |||
setWidthUnits(Table.UNITS_PERCENTAGE); |
@@ -28,11 +28,7 @@ | |||
package com.itmill.toolkit.ui; | |||
import com.itmill.toolkit.Application; | |||
import com.itmill.toolkit.event.EventRouter; | |||
import com.itmill.toolkit.event.MethodEventSource; | |||
import com.itmill.toolkit.terminal.*; | |||
import java.lang.reflect.Method; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Iterator; | |||
@@ -40,8 +36,15 @@ import java.util.LinkedList; | |||
import java.util.Locale; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.HashSet; | |||
import java.lang.reflect.Method; | |||
import com.itmill.toolkit.Application; | |||
import com.itmill.toolkit.event.EventRouter; | |||
import com.itmill.toolkit.event.MethodEventSource; | |||
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.VariableOwner; | |||
/** | |||
* An abstract class that defines default implementation for the |
@@ -0,0 +1,204 @@ | |||
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()]); | |||
} | |||
} |
@@ -61,7 +61,7 @@ import java.util.HashMap; | |||
* @VERSION@ | |||
* @since 3.0 | |||
*/ | |||
public class CustomLayout extends AbstractComponentContainer implements Layout { | |||
public class CustomLayout extends AbstractLayout { | |||
/** | |||
* Custom layout slots containing the components. | |||
@@ -173,6 +173,7 @@ public class CustomLayout extends AbstractComponentContainer implements Layout { | |||
* if the paint operation failed. | |||
*/ | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
super.paintContent(target); | |||
target.addAttribute("template", templateName); | |||
// Adds all items in all the locations |
@@ -528,4 +528,26 @@ public class Embedded extends AbstractComponent implements Sizeable { | |||
} | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* @see com.itmill.toolkit.terminal.Sizeable#setSizeFull() | |||
*/ | |||
public void setSizeFull() { | |||
setWidth(100); | |||
setHeight(100); | |||
setWidthUnits(UNITS_PERCENTAGE); | |||
setHeightUnits(UNITS_PERCENTAGE); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined() | |||
*/ | |||
public void setSizeUndefined() { | |||
setWidth(-1); | |||
setHeight(-1); | |||
setWidthUnits(UNITS_PIXELS); | |||
setHeightUnits(UNITS_PIXELS); | |||
} | |||
} |
@@ -4,7 +4,7 @@ | |||
Development of Browser User Interfaces Made Easy | |||
Copyright (C) 2000-2006 IT Mill Ltd | |||
Copyright (C) 2000-2007 IT Mill Ltd | |||
************************************************************************* | |||
@@ -29,26 +29,28 @@ | |||
package com.itmill.toolkit.ui; | |||
import java.util.Collections; | |||
import java.util.Iterator; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.LinkedList; | |||
import java.util.Map; | |||
import com.itmill.toolkit.terminal.PaintException; | |||
import com.itmill.toolkit.terminal.PaintTarget; | |||
import com.itmill.toolkit.terminal.Sizeable; | |||
/** | |||
* <p> | |||
* A container that consists of components with certain coordinates on a grid. | |||
* It also maintains cursor for adding component in left to right, top to bottom | |||
* order. | |||
* A container that consists of components with certain coordinates (cell | |||
* position) on a grid. It also maintains cursor for adding component in left to | |||
* right, top to bottom order. | |||
* </p> | |||
* | |||
* <p> | |||
* Each component in a <code>GridLayout</code> uses a certain | |||
* {@link GridLayout.Area area} (x1,y1,x2,y2) from the grid. One should not add | |||
* components that would overlap with the existing components because in such | |||
* case an {@link OverlapsException} is thrown. Adding component with cursor | |||
* automatically extends the grid by increasing the grid height. | |||
* {@link GridLayout.Area area} (column1,row1,column2,row2) from the grid. One | |||
* should not add components that would overlap with the existing components | |||
* because in such case an {@link OverlapsException} is thrown. Adding component | |||
* with cursor automatically extends the grid by increasing the grid height. | |||
* </p> | |||
* | |||
* @author IT Mill Ltd. | |||
@@ -56,17 +58,17 @@ import com.itmill.toolkit.terminal.PaintTarget; | |||
* @VERSION@ | |||
* @since 3.0 | |||
*/ | |||
public class GridLayout extends AbstractComponentContainer implements Layout { | |||
public class GridLayout extends AbstractLayout { | |||
/** | |||
* Initial grid x size. | |||
* Initial grid columns. | |||
*/ | |||
private int width = 0; | |||
private int cols = 0; | |||
/** | |||
* Initial grid y size. | |||
* Initial grid rows. | |||
*/ | |||
private int height = 0; | |||
private int rows = 0; | |||
/** | |||
* Cursor X position: this is where the next component with unspecified x,y | |||
@@ -87,23 +89,63 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
private LinkedList areas = new LinkedList(); | |||
/** | |||
* Mapping from components to threir respective areas. | |||
* Mapping from components to their respective areas. | |||
*/ | |||
private LinkedList components = new LinkedList(); | |||
/** | |||
* Constructor for grid of given size. Note that grid's final size depends | |||
* on the items that are added into the grid. Grid grows if you add | |||
* components outside the grid's area. | |||
* Mapping from components to alignments (horizontal + vertical). | |||
*/ | |||
private Map componentToAlignment = new HashMap(); | |||
/** | |||
* Contained component should be aligned horizontally to the left. | |||
*/ | |||
private int ALIGNMENT_LEFT = 1; | |||
/** | |||
* Contained component should be aligned horizontally to the right. | |||
*/ | |||
private int ALIGNMENT_RIGHT = 2; | |||
/** | |||
* Contained component should be aligned vertically to the top. | |||
*/ | |||
private int ALIGNMENT_TOP = 4; | |||
/** | |||
* Contained component should be aligned vertically to the bottom. | |||
*/ | |||
private int ALIGNMENT_BOTTOM = 8; | |||
/** | |||
* Contained component should be horizontally aligned to center. | |||
*/ | |||
private int HORIZONTAL_ALIGNMENT_CENTER = 16; | |||
/** | |||
* Contained component should be vertically aligned to center. | |||
*/ | |||
private int VERTICAL_ALIGNMENT_CENTER = 32; | |||
/** | |||
* Is spacing between contained components enabled. Defaults to false. | |||
*/ | |||
private boolean spacing = false; | |||
/** | |||
* Constructor for grid of given size (number of cells). Note that grid's | |||
* final size depends on the items that are added into the grid. Grid grows | |||
* if you add components outside the grid's area. | |||
* | |||
* @param width | |||
* the Width of the grid. | |||
* @param height | |||
* the Height of the grid. | |||
*/ | |||
public GridLayout(int width, int height) { | |||
setWidth(width); | |||
setHeight(height); | |||
* @param columns | |||
* Number of columns in the grid. | |||
* @param rows | |||
* Number of rows in the grid. | |||
*/ | |||
public GridLayout(int columns, int rows) { | |||
setColumns(columns); | |||
setRows(rows); | |||
} | |||
/** | |||
@@ -116,8 +158,8 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
/** | |||
* <p> | |||
* Adds a component with a specified area to the grid. The area the new | |||
* component should take is defined by specifying the upper left corner (x1, | |||
* y1) and the lower right corner (x2, y2) of the area. | |||
* component should take is defined by specifying the upper left corner | |||
* (column1, row1) and the lower right corner (column2, row2) of the area. | |||
* </p> | |||
* | |||
* <p> | |||
@@ -128,26 +170,27 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
* | |||
* @param c | |||
* the component to be added. | |||
* @param x1 | |||
* the X-coordinate of the upper left corner of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param y1 | |||
* the Y-coordinate of the upper left corner of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param x2 | |||
* the X-coordinate of the lower right corner of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param y2 | |||
* the Y-coordinate of the lower right corner of the area | |||
* @param column1 | |||
* the column of the upper left corner of the area <code>c</code> | |||
* is supposed to occupy. | |||
* @param row1 | |||
* the row of the upper left corner of the area <code>c</code> | |||
* is supposed to occupy. | |||
* @param column2 | |||
* the column of the lower right corner of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param row2 | |||
* the row of the lower right corner of the area <code>c</code> | |||
* is supposed to occupy. | |||
* @throws OverlapsException | |||
* if the new component overlaps with any of the components | |||
* already in the grid. | |||
* @throws OutOfBoundsException | |||
* if the coordinates are outside of the grid area. | |||
* if the cells are outside of the grid area. | |||
*/ | |||
public void addComponent(Component component, int x1, int y1, int x2, int y2) | |||
throws OverlapsException, OutOfBoundsException { | |||
public void addComponent(Component component, int column1, int row1, | |||
int column2, int row2) throws OverlapsException, | |||
OutOfBoundsException { | |||
if (component == null) | |||
throw new NullPointerException("Component must not be null"); | |||
@@ -158,13 +201,13 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
"Component is already in the container"); | |||
// Creates the area | |||
Area area = new Area(component, x1, y1, x2, y2); | |||
Area area = new Area(component, column1, row1, column2, row2); | |||
// Checks the validity of the coordinates | |||
if (x2 < x1 || y2 < y2) | |||
if (column2 < column1 || row2 < row1) | |||
throw new IllegalArgumentException( | |||
"Illegal coordinates for the component"); | |||
if (x1 < 0 || y1 < 0 || x2 >= width || y2 >= height) | |||
if (column1 < 0 || row1 < 0 || column2 >= cols || row2 >= rows) | |||
throw new OutOfBoundsException(area); | |||
// Checks that newItem does not overlap with existing items | |||
@@ -178,8 +221,8 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
boolean done = false; | |||
while (!done && i.hasNext()) { | |||
Area existingArea = (Area) i.next(); | |||
if ((existingArea.y1 >= y1 && existingArea.x1 > x1) | |||
|| existingArea.y1 > y1) { | |||
if ((existingArea.row1 >= row1 && existingArea.column1 > column1) | |||
|| existingArea.row1 > row1) { | |||
areas.add(index, area); | |||
components.add(index, component); | |||
done = true; | |||
@@ -215,19 +258,19 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
} | |||
/** | |||
* Adds the component into this container to coordinates x1,y1 (NortWest | |||
* Adds the component into this container to cells column1,row1 (NortWest | |||
* corner of the area.) End coordinates (SouthEast corner of the area) are | |||
* the same as x1,y1. Component width and height is 1. | |||
* the same as column1,row1. Component width and height is 1. | |||
* | |||
* @param c | |||
* the component to be added. | |||
* @param x | |||
* the X-coordinate. | |||
* @param y | |||
* the Y-coordinate. | |||
* @param column | |||
* the column index. | |||
* @param row | |||
* the row index. | |||
*/ | |||
public void addComponent(Component c, int x, int y) { | |||
this.addComponent(c, x, y, x, y); | |||
public void addComponent(Component c, int column, int row) { | |||
this.addComponent(c, column, row, column, row); | |||
} | |||
/** | |||
@@ -250,7 +293,7 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
*/ | |||
public void space() { | |||
cursorX++; | |||
if (cursorX >= width) { | |||
if (cursorX >= cols) { | |||
cursorX = 0; | |||
cursorY++; | |||
} | |||
@@ -260,7 +303,7 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
* Adds the component into this container to the cursor position. If the | |||
* cursor position is already occupied, the cursor is moved forwards to find | |||
* free position. If the cursor goes out from the bottom of the grid, the | |||
* grid is automaticly extended. | |||
* grid is automatically extended. | |||
* | |||
* @param c | |||
* the component to be added. | |||
@@ -280,8 +323,8 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
} | |||
// Extends the grid if needed | |||
width = cursorX >= width ? cursorX + 1 : width; | |||
height = cursorY >= height ? cursorY + 1 : height; | |||
cols = cursorX >= cols ? cursorX + 1 : cols; | |||
rows = cursorY >= rows ? cursorY + 1 : rows; | |||
addComponent(component, cursorX, cursorY); | |||
} | |||
@@ -310,25 +353,26 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
components.remove(component); | |||
if (area != null) | |||
areas.remove(area); | |||
componentToAlignment.remove(component); | |||
requestRepaint(); | |||
} | |||
/** | |||
* Removes the component specified with it's top-left corner coordinates | |||
* from this grid. | |||
* Removes the component specified with it's cell index. | |||
* | |||
* @param x | |||
* the Component's top-left corner's X-coordinate. | |||
* @param y | |||
* the Component's top-left corner's Y-coordinate. | |||
* @param column | |||
* the Component's column. | |||
* @param row | |||
* the Component's row. | |||
*/ | |||
public void removeComponent(int x, int y) { | |||
public void removeComponent(int column, int row) { | |||
// Finds the area | |||
for (Iterator i = areas.iterator(); i.hasNext();) { | |||
Area area = (Area) i.next(); | |||
if (area.getX1() == x && area.getY1() == y) { | |||
if (area.getColumn1() == column && area.getRow1() == row) { | |||
removeComponent(area.getComponent()); | |||
return; | |||
} | |||
@@ -355,8 +399,14 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
*/ | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
target.addAttribute("h", height); | |||
target.addAttribute("w", width); | |||
super.paintContent(target); | |||
// TODO refactor attribute names in future release. | |||
target.addAttribute("rows", rows); | |||
target.addAttribute("cols", cols); | |||
if (this.spacing) | |||
target.addAttribute("spacing", this.spacing); | |||
// Area iterator | |||
Iterator areaiterator = areas.iterator(); | |||
@@ -371,14 +421,15 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
int emptyCells = 0; | |||
// Iterates every applicable row | |||
for (int cury = 0; cury < height; cury++) { | |||
for (int cury = 0; cury < rows; cury++) { | |||
target.startTag("gr"); | |||
// Iterates every applicable column | |||
for (int curx = 0; curx < width; curx++) { | |||
for (int curx = 0; curx < cols; curx++) { | |||
// Checks if current item is located at curx,cury | |||
if (area != null && (area.y1 == cury) && (area.x1 == curx)) { | |||
if (area != null && (area.row1 == cury) | |||
&& (area.column1 == curx)) { | |||
// First check if empty cell needs to be rendered | |||
if (emptyCells > 0) { | |||
@@ -393,8 +444,8 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
} | |||
// Now proceed rendering current item | |||
int cols = (area.x2 - area.x1) + 1; | |||
int rows = (area.y2 - area.y1) + 1; | |||
int cols = (area.column2 - area.column1) + 1; | |||
int rows = (area.row2 - area.row1) + 1; | |||
target.startTag("gc"); | |||
target.addAttribute("x", curx); | |||
@@ -480,7 +531,7 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
// Checks if empty cell needs to be rendered | |||
if (emptyCells > 0) { | |||
target.startTag("gc"); | |||
target.addAttribute("x", width - emptyCells); | |||
target.addAttribute("x", cols - emptyCells); | |||
target.addAttribute("y", cury); | |||
if (emptyCells > 1) { | |||
target.addAttribute("w", emptyCells); | |||
@@ -507,9 +558,9 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
} | |||
/** | |||
* This class defines an area on a grid. An Area is defined by the | |||
* coordinates of its upper left corner (x1,y1) and lower right corner | |||
* (x2,y2). | |||
* This class defines an area on a grid. An Area is defined by the cells of | |||
* its upper left corner (column1,row1) and lower right corner | |||
* (column2,row2). | |||
* | |||
* @author IT Mill Ltd. | |||
* @version | |||
@@ -519,24 +570,24 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
public class Area { | |||
/** | |||
* X-coordinate of the upper left corner of the area. | |||
* The column of the upper left corner cell of the area. | |||
*/ | |||
private int x1; | |||
private int column1; | |||
/** | |||
* Y-coordinate of the upper left corner of the area. | |||
* The row of the upper left corner cell of the area. | |||
*/ | |||
private int y1; | |||
private int row1; | |||
/** | |||
* X-coordinate of the lower right corner of the area. | |||
* The column of the lower right corner cell of the area. | |||
*/ | |||
private int x2; | |||
private int column2; | |||
/** | |||
* Y-coordinate of the lower right corner of the area. | |||
* The row of the lower right corner cell of the area. | |||
*/ | |||
private int y2; | |||
private int row2; | |||
/** | |||
* Component painted on the area. | |||
@@ -550,27 +601,28 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
* | |||
* @param component | |||
* the component connected to the area. | |||
* @param x1 | |||
* the X-coordinate of the upper left corner of the area | |||
* @param column1 | |||
* The column of the upper left corner cell of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param y1 | |||
* the Y-coordinate of the upper left corner of the area | |||
* @param row1 | |||
* The row of the upper left corner cell of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param x2 | |||
* the X-coordinate of the lower right corner of the area | |||
* @param column2 | |||
* The column of the lower right corner cell of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @param y2 | |||
* the Y-coordinate of the lower right corner of the area | |||
* @param row2 | |||
* The row of the lower right corner cell of the area | |||
* <code>c</code> is supposed to occupy. | |||
* @throws OverlapsException | |||
* if the new component overlaps with any of the components | |||
* already in the grid | |||
*/ | |||
public Area(Component component, int x1, int y1, int x2, int y2) { | |||
this.x1 = x1; | |||
this.y1 = y1; | |||
this.x2 = x2; | |||
this.y2 = y2; | |||
public Area(Component component, int column1, int row1, int column2, | |||
int row2) { | |||
this.column1 = column1; | |||
this.row1 = row1; | |||
this.column2 = column2; | |||
this.row2 = row2; | |||
this.component = component; | |||
} | |||
@@ -584,8 +636,8 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
* this area, <code>false</code> if it doesn't. | |||
*/ | |||
public boolean overlaps(Area other) { | |||
return x1 <= other.getX2() && y1 <= other.getY2() | |||
&& x2 >= other.getX1() && y2 >= other.getY1(); | |||
return column1 <= other.getColumn2() && row1 <= other.getRow2() | |||
&& column2 >= other.getColumn1() && row2 >= other.getRow1(); | |||
} | |||
@@ -614,39 +666,75 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
} | |||
/** | |||
* Gets the top-left corner x-coordinate. | |||
* @deprecated Use getColumn1() instead. | |||
* | |||
* @return the top-left corner of x-coordinate. | |||
* @see com.itmill.toolkit.ui.GridLayout#getColumn1() | |||
*/ | |||
public int getX1() { | |||
return x1; | |||
return getColumn1(); | |||
} | |||
/** | |||
* Gets the column of the top-left corner cell. | |||
* | |||
* @return the column of the top-left corner cell. | |||
*/ | |||
public int getColumn1() { | |||
return column1; | |||
} | |||
/** | |||
* Gets the bottom-right corner x-coordinate. | |||
* @deprecated Use getColumn2() instead. | |||
* | |||
* @return the x-coordinate. | |||
* @see com.itmill.toolkit.ui.GridLayout#getColumn2() | |||
*/ | |||
public int getX2() { | |||
return x2; | |||
return getColumn2(); | |||
} | |||
/** | |||
* Gets the top-left corner y-coordinate. | |||
* Gets the column of the bottom-right corner cell. | |||
* | |||
* @return the y-coordinate. | |||
* @return the column of the bottom-right corner cell. | |||
*/ | |||
public int getColumn2() { | |||
return column2; | |||
} | |||
/** | |||
* @deprecated Use getRow1() instead. | |||
* | |||
* @see com.itmill.toolkit.ui.GridLayout#getRow1() | |||
*/ | |||
public int getY1() { | |||
return y1; | |||
return getRow1(); | |||
} | |||
/** | |||
* Returns the bottom-right corner y-coordinate. | |||
* Gets the row of the top-left corner cell. | |||
* | |||
* @return the y-coordinate. | |||
* @return the row of the top-left corner cell. | |||
*/ | |||
public int getRow1() { | |||
return row1; | |||
} | |||
/** | |||
* @deprecated Use getRow2() instead. | |||
* | |||
* @see com.itmill.toolkit.ui.GridLayout#getRow2() | |||
*/ | |||
public int getY2() { | |||
return y2; | |||
return getRow2(); | |||
} | |||
/** | |||
* Gets the row of the bottom-right corner cell. | |||
* | |||
* @return the row of the bottom-right corner cell. | |||
*/ | |||
public int getRow2() { | |||
return row2; | |||
} | |||
} | |||
@@ -727,92 +815,148 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
} | |||
/** | |||
* Sets the width of the grid. The width can not be reduced if there are any | |||
* areas that would be outside of the shrunk grid. | |||
* | |||
* @param width | |||
* the New width of the grid. | |||
* Sets the width of the layout. | |||
* <p> | |||
* <strong>NOTE:</strong> The behaviour of this methdod has changed in | |||
* version 5.0. Now this method won't set the number of columns in the grid | |||
* like it used to (use {@link #setColumns()} for that). Instead, it sets | |||
* the actual visual width of the layout in pixels or in another unit | |||
* specified in {@link Sizeable}.UNIT_SYMBOLS. | |||
* </p> | |||
*/ | |||
public void setWidth(int width) { | |||
super.setWidth(width); | |||
} | |||
/** | |||
* Gets the width of the layout. | |||
* <p> | |||
* <strong>NOTE:</strong> The behaviour of this methdod has changed in | |||
* version 5.0. Now this method won't return the number of columns in the | |||
* grid like it used to (use {@link #getColumns()} for that). Instead, it | |||
* returns the actual visual width of the layout in pixels or in another | |||
* unit specified in {@link Sizeable}.UNIT_SYMBOLS. | |||
* </p> | |||
*/ | |||
public int getWidth() { | |||
return super.getWidth(); | |||
} | |||
/** | |||
* Sets the number of columns in the grid. The column count can not be | |||
* reduced if there are any areas that would be outside of the shrunk grid. | |||
* | |||
* @param columns | |||
* the new number of columns in the grid. | |||
*/ | |||
public void setColumns(int columns) { | |||
// The the param | |||
if (width < 1) | |||
if (columns < 1) | |||
throw new IllegalArgumentException( | |||
"The grid width and height must be at least 1"); | |||
"The number of columns and rows in the grid must be at least 1"); | |||
// In case of no change | |||
if (this.width == width) | |||
if (this.cols == columns) | |||
return; | |||
// Checks for overlaps | |||
if (this.width > width) | |||
if (this.cols > columns) | |||
for (Iterator i = areas.iterator(); i.hasNext();) { | |||
Area area = (Area) i.next(); | |||
if (area.x2 >= width) | |||
if (area.column2 >= columns) | |||
throw new OutOfBoundsException(area); | |||
} | |||
this.width = width; | |||
this.cols = columns; | |||
requestRepaint(); | |||
} | |||
/** | |||
* Get the width of the grids. | |||
* Get the number of columns in the grid. | |||
* | |||
* @return the width of the grid. | |||
* @return the number of columns in the grid. | |||
*/ | |||
public final int getWidth() { | |||
return this.width; | |||
public final int getColumns() { | |||
return this.cols; | |||
} | |||
/** | |||
* Sets the height of the grid. The width can not be reduced if there are | |||
* any areas that would be outside of the shrunk grid. | |||
* | |||
* @param height | |||
* the height of the grid. | |||
* Set the height of the layout. | |||
* <p> | |||
* <strong>NOTE:</strong> The behaviour of this methdod has changed in | |||
* version 5.0. Now this method won't set the number of rows in the grid | |||
* like it used to (use {@link #setRows()} for that). Instead, it sets the | |||
* actual visual height of the layout in pixels or in another unit specified | |||
* in {@link Sizeable}.UNIT_SYMBOLS. | |||
* </p> | |||
*/ | |||
public void setHeight(int height) { | |||
super.setHeight(height); | |||
} | |||
/** | |||
* Gets the height of the layout. | |||
* <p> | |||
* <strong>NOTE:</strong> The behaviour of this methdod has changed in | |||
* version 5.0. Now this method won't return the number of rows in the grid | |||
* like it used to (use {@link #getRows()} for that). Instead, it returns | |||
* the actual visual height of the layout in pixels or in another unit | |||
* specified in {@link Sizeable}.UNIT_SYMBOLS. | |||
* </p> | |||
*/ | |||
public int getHeight() { | |||
return super.getHeight(); | |||
} | |||
/** | |||
* Sets the number of rows in the grid. The number of rows can not be | |||
* reduced if there are any areas that would be outside of the shrunk grid. | |||
* | |||
* @param rows | |||
* the new number of rows in the grid. | |||
*/ | |||
public void setRows(int rows) { | |||
// The the param | |||
if (height < 1) | |||
if (rows < 1) | |||
throw new IllegalArgumentException( | |||
"The grid width and height must be at least 1"); | |||
"The number of columns and rows in the grid must be at least 1"); | |||
// In case of no change | |||
if (this.height == height) | |||
if (this.rows == rows) | |||
return; | |||
// Checks for overlaps | |||
if (this.height > height) | |||
if (this.rows > rows) | |||
for (Iterator i = areas.iterator(); i.hasNext();) { | |||
Area area = (Area) i.next(); | |||
if (area.y2 >= height) | |||
if (area.row2 >= rows) | |||
throw new OutOfBoundsException(area); | |||
} | |||
this.height = height; | |||
this.rows = rows; | |||
requestRepaint(); | |||
} | |||
/** | |||
* Gets the height of the grid. | |||
* Get the number of rows in the grid. | |||
* | |||
* @return int - how many cells high the grid is. | |||
* @return the number of rows in the grid. | |||
*/ | |||
public final int getHeight() { | |||
return this.height; | |||
public final int getRows() { | |||
return this.rows; | |||
} | |||
/** | |||
* Gets the current cursor x-position. The cursor position points the | |||
* position for the next component that is added without specifying its | |||
* coordinates. When the cursor position is occupied, the next component | |||
* will be added to first free position after the cursor. | |||
* coordinates (grid cell). When the cursor position is occupied, the next | |||
* component will be added to first free position after the cursor. | |||
* | |||
* @return the Cursor x-coordinate. | |||
* @return the grid column the Cursor is on. | |||
*/ | |||
public int getCursorX() { | |||
return cursorX; | |||
@@ -821,10 +965,10 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
/** | |||
* Gets the current cursor y-position. The cursor position points the | |||
* position for the next component that is added without specifying its | |||
* coordinates. When the cursor position is occupied, the next component | |||
* will be added to first free position after the cursor. | |||
* coordinates (grid cell). When the cursor position is occupied, the next | |||
* component will be added to first free position after the cursor. | |||
* | |||
* @return the Cursor y-coordinate. | |||
* @return the grid row the Cursor is on. | |||
*/ | |||
public int getCursorY() { | |||
return cursorY; | |||
@@ -849,9 +993,8 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
addComponent(newComponent); | |||
else if (newLocation == null) { | |||
removeComponent(oldComponent); | |||
addComponent(newComponent, oldLocation.getX1(), | |||
oldLocation.getY1(), oldLocation.getX2(), oldLocation | |||
.getY2()); | |||
addComponent(newComponent, oldLocation.getColumn1(), oldLocation | |||
.getRow1(), oldLocation.getColumn2(), oldLocation.getRow2()); | |||
} else { | |||
oldLocation.setComponent(newComponent); | |||
newLocation.setComponent(oldComponent); | |||
@@ -866,8 +1009,43 @@ public class GridLayout extends AbstractComponentContainer implements Layout { | |||
*/ | |||
public void removeAllComponents() { | |||
super.removeAllComponents(); | |||
this.componentToAlignment = new HashMap(); | |||
this.cursorX = 0; | |||
this.cursorY = 0; | |||
} | |||
/** | |||
* Set alignment for one contained component in this layout. | |||
* | |||
* @param childComponent | |||
* the component to align within it's layout cell. | |||
* @param horizontalAlignment | |||
* the horizontal alignment for the child component (left, | |||
* center, right). | |||
* @param verticalAlignment | |||
* the vertical alignment for the child component (top, center, | |||
* bottom). | |||
*/ | |||
public void setComponentAlignment(Component childComponent, | |||
int horizontalAlignment, int verticalAlignment) { | |||
componentToAlignment.put(childComponent, new Integer( | |||
horizontalAlignment + verticalAlignment)); | |||
} | |||
/** | |||
* Enable spacing between child components within this layout. | |||
* | |||
* <p> | |||
* <strong>NOTE:</strong> This will only affect spaces between components, | |||
* not also all around spacing of the layout (i.e. do not mix this with HTML | |||
* Table elements cellspacing-attribute). Use {@link #setMargin(boolean)} to | |||
* add extra space around the layout. | |||
* </p> | |||
* | |||
* @param enabled | |||
*/ | |||
public void setSpacing(boolean enabled) { | |||
this.spacing = enabled; | |||
} | |||
} |
@@ -28,6 +28,9 @@ | |||
package com.itmill.toolkit.ui; | |||
import com.itmill.toolkit.terminal.Sizeable; | |||
/** | |||
* Extension to the {@link ComponentContainer} interface which adds the | |||
* layouting control to the elements in the container. This is required by the | |||
@@ -39,6 +42,30 @@ package com.itmill.toolkit.ui; | |||
* @VERSION@ | |||
* @since 3.0 | |||
*/ | |||
public interface Layout extends ComponentContainer { | |||
public interface Layout extends ComponentContainer, Sizeable { | |||
/** | |||
* Enable layout margins. Affects all four sides of the layout. This will | |||
* tell the client-side implementation to leave extra space around the | |||
* layout. The client-side implementation decides the actual amount, and it | |||
* can vary between themes. | |||
* | |||
* @param enabled | |||
*/ | |||
public void setMargin(boolean enabled); | |||
/** | |||
* Enable specific layout margins. This will tell the client-side | |||
* implementation to leave extra space around the layout in specified edges, | |||
* clockwise from top (top, right, bottom, left). The client-side | |||
* implementation decides the actual amount, and it can vary between themes. | |||
* | |||
* @param top | |||
* @param right | |||
* @param bottom | |||
* @param left | |||
*/ | |||
public void setMargin(boolean top, boolean right, boolean bottom, | |||
boolean left); | |||
} |
@@ -28,11 +28,13 @@ | |||
package com.itmill.toolkit.ui; | |||
import com.itmill.toolkit.terminal.PaintException; | |||
import com.itmill.toolkit.terminal.PaintTarget; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.LinkedList; | |||
import java.util.Map; | |||
import com.itmill.toolkit.terminal.PaintException; | |||
import com.itmill.toolkit.terminal.PaintTarget; | |||
/** | |||
* Ordered layout. | |||
@@ -45,17 +47,17 @@ import java.util.LinkedList; | |||
* @VERSION@ | |||
* @since 3.0 | |||
*/ | |||
public class OrderedLayout extends AbstractComponentContainer implements Layout { | |||
public class OrderedLayout extends AbstractLayout { | |||
/* Predefined orientations ***************************************** */ | |||
/** | |||
* Components are to be layed out vertically. | |||
* Components are to be laid out vertically. | |||
*/ | |||
public static int ORIENTATION_VERTICAL = 0; | |||
/** | |||
* Components are to be layed out horizontally. | |||
* Components are to be laid out horizontally. | |||
*/ | |||
public static int ORIENTATION_HORIZONTAL = 1; | |||
@@ -64,11 +66,51 @@ public class OrderedLayout extends AbstractComponentContainer implements Layout | |||
*/ | |||
private LinkedList components = new LinkedList(); | |||
/** | |||
* Mapping from components to alignments (horizontal + vertical). | |||
*/ | |||
private Map componentToAlignment = new HashMap(); | |||
/** | |||
* Contained component should be aligned horizontally to the left. | |||
*/ | |||
private int ALIGNMENT_LEFT = 1; | |||
/** | |||
* Contained component should be aligned horizontally to the right. | |||
*/ | |||
private int ALIGNMENT_RIGHT = 2; | |||
/** | |||
* Contained component should be aligned vertically to the top. | |||
*/ | |||
private int ALIGNMENT_TOP = 4; | |||
/** | |||
* Contained component should be aligned vertically to the bottom. | |||
*/ | |||
private int ALIGNMENT_BOTTOM = 8; | |||
/** | |||
* Contained component should be horizontally aligned to center. | |||
*/ | |||
private int HORIZONTAL_ALIGNMENT_CENTER = 16; | |||
/** | |||
* Contained component should be vertically aligned to center. | |||
*/ | |||
private int VERTICAL_ALIGNMENT_CENTER = 32; | |||
/** | |||
* Orientation of the layout. | |||
*/ | |||
private int orientation; | |||
/** | |||
* Is spacing between contained components enabled. Defaults to false. | |||
*/ | |||
private boolean spacing = false; | |||
/** | |||
* Creates a new ordered layout. The order of the layout is | |||
* <code>ORIENTATION_VERTICAL</code>. | |||
@@ -147,6 +189,7 @@ public class OrderedLayout extends AbstractComponentContainer implements Layout | |||
public void removeComponent(Component c) { | |||
super.removeComponent(c); | |||
components.remove(c); | |||
componentToAlignment.remove(c); | |||
requestRepaint(); | |||
} | |||
@@ -169,19 +212,40 @@ public class OrderedLayout extends AbstractComponentContainer implements Layout | |||
* if the paint operation failed. | |||
*/ | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
super.paintContent(target); | |||
// Adds the attributes: orientation | |||
// note that the default values (b/vertival) are omitted | |||
if (orientation == ORIENTATION_HORIZONTAL) | |||
target.addAttribute("orientation", "horizontal"); | |||
if (this.spacing) | |||
target.addAttribute("spacing", this.spacing); | |||
// Store alignment info in this String | |||
String alignments = ""; | |||
// Adds all items in all the locations | |||
for (Iterator i = components.iterator(); i.hasNext();) { | |||
Component c = (Component) i.next(); | |||
if (c != null) { | |||
// Paint child component UIDL | |||
c.paint(target); | |||
// Get alignment info for component | |||
if (componentToAlignment.containsKey(c)) | |||
alignments += ((Integer) componentToAlignment.get(c)) | |||
.intValue(); | |||
else | |||
// Default alignment is top-left | |||
alignments += ALIGNMENT_TOP + ALIGNMENT_LEFT; | |||
if (i.hasNext()) | |||
alignments += ","; | |||
} | |||
} | |||
// Add child component alignment info to layout tag | |||
target.addAttribute("alignments", alignments); | |||
} | |||
/** | |||
@@ -238,15 +302,51 @@ public class OrderedLayout extends AbstractComponentContainer implements Layout | |||
components.remove(oldComponent); | |||
components.add(newLocation, oldComponent); | |||
components.remove(newComponent); | |||
componentToAlignment.remove(newComponent); | |||
components.add(oldLocation, newComponent); | |||
} else { | |||
components.remove(newComponent); | |||
components.add(oldLocation, newComponent); | |||
components.remove(oldComponent); | |||
componentToAlignment.remove(oldComponent); | |||
components.add(newLocation, oldComponent); | |||
} | |||
requestRepaint(); | |||
} | |||
} | |||
/** | |||
* Set alignment for one contained component in this layout. | |||
* | |||
* @param childComponent | |||
* the component to align within it's layout cell. | |||
* @param horizontalAlignment | |||
* the horizontal alignment for the child component (left, | |||
* center, right). | |||
* @param verticalAlignment | |||
* the vertical alignment for the child component (top, center, | |||
* bottom). | |||
*/ | |||
public void setComponentAlignment(Component childComponent, | |||
int horizontalAlignment, int verticalAlignment) { | |||
componentToAlignment.put(childComponent, new Integer( | |||
horizontalAlignment + verticalAlignment)); | |||
} | |||
/** | |||
* Enable spacing between child components within this layout. | |||
* | |||
* <p> | |||
* <strong>NOTE:</strong> This will only affect spaces between components, | |||
* not also all around spacing of the layout (i.e. do not mix this with HTML | |||
* Table elements cellspacing-attribute). Use {@link #setMargin(boolean)} to | |||
* add extra space around the layout. | |||
* </p> | |||
* | |||
* @param enabled | |||
*/ | |||
public void setSpacing(boolean enabled) { | |||
this.spacing = enabled; | |||
} | |||
} |
@@ -39,7 +39,6 @@ import com.itmill.toolkit.terminal.KeyMapper; | |||
import com.itmill.toolkit.terminal.PaintException; | |||
import com.itmill.toolkit.terminal.PaintTarget; | |||
import com.itmill.toolkit.terminal.Scrollable; | |||
import com.itmill.toolkit.terminal.Sizeable; | |||
/** | |||
* Panel - a simple single component container. | |||
@@ -49,46 +48,19 @@ import com.itmill.toolkit.terminal.Sizeable; | |||
* @VERSION@ | |||
* @since 3.0 | |||
*/ | |||
public class Panel extends AbstractComponentContainer implements Sizeable, | |||
Scrollable, ComponentContainer.ComponentAttachListener, | |||
public class Panel extends AbstractLayout implements Scrollable, | |||
ComponentContainer.ComponentAttachListener, | |||
ComponentContainer.ComponentDetachListener, Action.Container { | |||
public static final String STYLE_LIGHT = "light"; | |||
public static final String STYLE_EMPHASIZE = "emphasize"; | |||
/** | |||
* Use this stylename with {@link #addStyleName(String)} to remove padding | |||
* between Panel borders and content. The actual client-side implementation | |||
* will determine which stylenames it implements. | |||
*/ | |||
public static final String STYLE_NO_PADDING = "nopad"; | |||
/** | |||
* Layout of the panel. | |||
*/ | |||
private Layout layout; | |||
/** | |||
* Width of the panel or -1 if unspecified. | |||
*/ | |||
private int width = -1; | |||
/** | |||
* Height of the panel or -1 if unspecified. | |||
*/ | |||
private int height = -1; | |||
/** | |||
* Width unit. | |||
*/ | |||
private int widthUnit = Sizeable.UNITS_PIXELS; | |||
/** | |||
* Height unit. | |||
*/ | |||
private int heightUnit = Sizeable.UNITS_PIXELS; | |||
/** | |||
* Scroll X position. | |||
*/ | |||
@@ -210,12 +182,7 @@ public class Panel extends AbstractComponentContainer implements Sizeable, | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
layout.paint(target); | |||
if (height > -1) | |||
target.addVariable(this, "height", getHeight() | |||
+ UNIT_SYMBOLS[getHeightUnits()]); | |||
if (width > -1) | |||
target.addVariable(this, "width", getWidth() | |||
+ UNIT_SYMBOLS[getWidthUnits()]); | |||
super.paintContent(target); | |||
if (isScrollable()) { | |||
target.addVariable(this, "scrollleft", getScrollOffsetX()); | |||
@@ -305,52 +272,6 @@ public class Panel extends AbstractComponentContainer implements Sizeable, | |||
return layout.getComponentIterator(); | |||
} | |||
/** | |||
* Gets the height in pixels. | |||
* | |||
* @return The height in pixels or negative value if not assigned. | |||
* @see com.itmill.toolkit.terminal.Sizeable#getHeight() | |||
*/ | |||
public int getHeight() { | |||
return height; | |||
} | |||
/** | |||
* Gets the Width in pixel. | |||
* | |||
* @return The width in pixels or negative value if not assigned. | |||
* @see com.itmill.toolkit.terminal.Sizeable#getWidth() | |||
*/ | |||
public int getWidth() { | |||
return width; | |||
} | |||
/** | |||
* Sets the height in pixels. Use negative value to let the client decide | |||
* the height. | |||
* | |||
* @param height | |||
* the height to set. | |||
* @see com.itmill.toolkit.terminal.Sizeable#setHeight(int) | |||
*/ | |||
public void setHeight(int height) { | |||
this.height = height; | |||
requestRepaint(); | |||
} | |||
/** | |||
* Sets the width in pixels. Use negative value to allow the client decide | |||
* the width. | |||
* | |||
* @param width | |||
* the width to set. | |||
* @see com.itmill.toolkit.terminal.Sizeable#setWidth(int) | |||
*/ | |||
public void setWidth(int width) { | |||
this.width = width; | |||
requestRepaint(); | |||
} | |||
/** | |||
* Called when one or more variables handled by the implementing class are | |||
* changed. | |||
@@ -396,42 +317,6 @@ public class Panel extends AbstractComponentContainer implements Sizeable, | |||
} | |||
/** | |||
* Gets the height property units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits() | |||
*/ | |||
public int getHeightUnits() { | |||
return heightUnit; | |||
} | |||
/** | |||
* Gets the width property units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits() | |||
*/ | |||
public int getWidthUnits() { | |||
return widthUnit; | |||
} | |||
/** | |||
* Sets the height units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int) | |||
*/ | |||
public void setHeightUnits(int units) { | |||
heightUnit = units; | |||
} | |||
/** | |||
* Sets the width units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int) | |||
*/ | |||
public void setWidthUnits(int units) { | |||
widthUnit = units; | |||
} | |||
/* Scrolling functionality */ | |||
/* Documented in interface */ |
@@ -45,8 +45,7 @@ import com.itmill.toolkit.terminal.Sizeable; | |||
* @VERSION@ | |||
* @since 5.0 | |||
*/ | |||
public class SplitPanel extends AbstractComponentContainer implements Layout, | |||
Sizeable { | |||
public class SplitPanel extends AbstractLayout { | |||
/* Predefined orientations ***************************************** */ | |||
@@ -69,14 +68,6 @@ public class SplitPanel extends AbstractComponentContainer implements Layout, | |||
*/ | |||
private int orientation; | |||
private int height; | |||
private int heightUnit; | |||
private int width; | |||
private int widthUnit; | |||
private int pos = 50; | |||
private int posUnit = UNITS_PERCENTAGE; | |||
@@ -87,6 +78,7 @@ public class SplitPanel extends AbstractComponentContainer implements Layout, | |||
*/ | |||
public SplitPanel() { | |||
orientation = ORIENTATION_VERTICAL; | |||
setSizeFull(); | |||
} | |||
/** | |||
@@ -98,6 +90,7 @@ public class SplitPanel extends AbstractComponentContainer implements Layout, | |||
*/ | |||
public SplitPanel(int orientation) { | |||
this.orientation = orientation; | |||
setSizeFull(); | |||
} | |||
/** | |||
@@ -217,18 +210,8 @@ public class SplitPanel extends AbstractComponentContainer implements Layout, | |||
* if the paint operation failed. | |||
*/ | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
// TODO refine size attributes | |||
if (width > 0) { | |||
target.addAttribute("width", width + UNIT_SYMBOLS[widthUnit]); | |||
} else { | |||
target.addAttribute("width", "100%"); | |||
} | |||
if (height > 0) { | |||
target.addAttribute("height", height + UNIT_SYMBOLS[heightUnit]); | |||
} else { | |||
target.addAttribute("height", "100%"); | |||
} | |||
super.paintContent(target); | |||
String position = pos + UNIT_SYMBOLS[posUnit]; | |||
@@ -293,47 +276,13 @@ public class SplitPanel extends AbstractComponentContainer implements Layout, | |||
/** | |||
* Moves the position of the splitter with given position and unit. | |||
* | |||
* Supported Units are {@link Sizeable}.UNITS_PERSENTAGE and | |||
* Sizeable.UNITS_PIXELS | |||
* | |||
* @param pos | |||
* size of the first region | |||
* @oaran unit the unit (from {@link Sizeable}) in which the size is given. | |||
* @param unit the unit (from {@link Sizeable}) in which the size is given. | |||
*/ | |||
public void setSplitPosition(int pos, int unit) { | |||
this.pos = pos; | |||
this.posUnit = unit; | |||
} | |||
public int getHeight() { | |||
return height; | |||
} | |||
public int getHeightUnits() { | |||
return heightUnit; | |||
} | |||
public int getWidth() { | |||
return width; | |||
} | |||
public int getWidthUnits() { | |||
return widthUnit; | |||
} | |||
public void setHeight(int height) { | |||
this.height = height; | |||
} | |||
public void setHeightUnits(int units) { | |||
this.heightUnit = units; | |||
} | |||
public void setWidth(int width) { | |||
this.width = width; | |||
} | |||
public void setWidthUnits(int units) { | |||
this.widthUnit = units; | |||
} | |||
} |
@@ -44,12 +44,12 @@ import com.itmill.toolkit.terminal.*; | |||
* @VERSION@ | |||
* @since 3.0 | |||
*/ | |||
public class TabSheet extends AbstractComponentContainer implements Sizeable { | |||
public class TabSheet extends AbstractLayout { | |||
/** | |||
* Use this stylename with {@link #addStyleName(String)} to remove padding | |||
* between TabSheet borders and content. The actual client-side implementation | |||
* will determine which stylenames it implements. | |||
* between TabSheet borders and content. The actual client-side | |||
* implementation will determine which stylenames it implements. | |||
*/ | |||
public static final String STYLE_NO_PADDING = "nopad"; | |||
@@ -80,14 +80,6 @@ public class TabSheet extends AbstractComponentContainer implements Sizeable { | |||
*/ | |||
private boolean tabsHidden; | |||
private int height = -1; | |||
private int heightUnit; | |||
private int width = -1; | |||
private int widthUnit; | |||
/** | |||
* Constructs a new Tabsheet. Tabsheet is immediate by default. | |||
*/ | |||
@@ -206,18 +198,11 @@ public class TabSheet extends AbstractComponentContainer implements Sizeable { | |||
* if the paint operation failed. | |||
*/ | |||
public void paintContent(PaintTarget target) throws PaintException { | |||
super.paintContent(target); | |||
if (areTabsHidden()) | |||
target.addAttribute("hidetabs", true); | |||
if (width > -1) { | |||
target.addAttribute("width", getWidth() + UNIT_SYMBOLS[widthUnit]); | |||
} | |||
if (height > -1) { | |||
target.addAttribute("height", getHeight() | |||
+ UNIT_SYMBOLS[heightUnit]); | |||
} | |||
target.startTag("tabs"); | |||
for (Iterator i = getComponentIterator(); i.hasNext();) { | |||
@@ -507,39 +492,4 @@ public class TabSheet extends AbstractComponentContainer implements Sizeable { | |||
fireEvent(new SelectedTabChangeEvent(this)); | |||
} | |||
public int getHeight() { | |||
return height; | |||
} | |||
public int getHeightUnits() { | |||
return heightUnit; | |||
} | |||
public int getWidth() { | |||
return width; | |||
} | |||
public int getWidthUnits() { | |||
return widthUnit; | |||
} | |||
public void setHeight(int height) { | |||
this.height = height; | |||
requestRepaint(); | |||
} | |||
public void setHeightUnits(int units) { | |||
this.heightUnit = units; | |||
requestRepaint(); | |||
} | |||
public void setWidth(int width) { | |||
this.width = width; | |||
requestRepaint(); | |||
} | |||
public void setWidthUnits(int units) { | |||
this.widthUnit = units; | |||
requestRepaint(); | |||
} | |||
} |
@@ -2421,9 +2421,9 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Is sorting disabled alltogether. | |||
* Is sorting disabled altogether. | |||
* | |||
* True iff no sortable columns are given even in the case where datasource | |||
* True iff no sortable columns are given even in the case where data source | |||
* would support this. | |||
* | |||
* @return True iff sorting is disabled. | |||
@@ -2433,9 +2433,9 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Disables the sorting alltogether. | |||
* Disables the sorting altogether. | |||
* | |||
* To disable sorting alltogether, set to true. In this case no sortable | |||
* To disable sorting altogether, set to true. In this case no sortable | |||
* columns are given even in the case where datasource would support this. | |||
* | |||
* @param sortDisabled | |||
@@ -2449,7 +2449,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Gets the height property units. | |||
* Gets height property unit. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits() | |||
*/ | |||
@@ -2458,7 +2458,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Gets the width property units. | |||
* Gets width property unit. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits() | |||
*/ | |||
@@ -2467,7 +2467,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Sets the height units. | |||
* Sets height units. | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int) | |||
*/ | |||
@@ -2476,7 +2476,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Sets the width units. Tabel supports only Sizeable.UNITS_PIXELS and | |||
* Sets width units. Table supports only Sizeable.UNITS_PIXELS and | |||
* Sizeable.UNITS_PERCENTAGE. Setting to any other throws | |||
* IllegalArgumentException. | |||
* | |||
@@ -2491,9 +2491,10 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Gets the height in pixels. | |||
* Gets height. | |||
* | |||
* @return the height in pixels or negative value if not assigned. | |||
* @return height value as a positive integer or negative value if not | |||
* assigned. | |||
* @see com.itmill.toolkit.terminal.Sizeable#getHeight() | |||
*/ | |||
public int getHeight() { | |||
@@ -2501,9 +2502,10 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Gets the width in pixels. | |||
* Gets width. | |||
* | |||
* @return the width in pixels or negative value if not assigned. | |||
* @return width value as positive integer or negative value if not | |||
* assigned. | |||
* @see com.itmill.toolkit.terminal.Sizeable#getWidth() | |||
*/ | |||
public int getWidth() { | |||
@@ -2511,8 +2513,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Sets the height in pixels. Use negative value to let the client decide | |||
* the height. | |||
* Sets height. Use negative value to let the client decide the height. | |||
* | |||
* @param height | |||
* the height to set. | |||
@@ -2523,8 +2524,7 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
/** | |||
* Sets the width in pixels. Use negative value to allow the client decide | |||
* the width. | |||
* Sets width. Use negative value to allow the client decide the width. | |||
* | |||
* @param width | |||
* the width to set. | |||
@@ -2547,4 +2547,28 @@ public class Table extends AbstractSelect implements Action.Container, | |||
} | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setSizeFull() | |||
*/ | |||
public void setSizeFull() { | |||
setWidth(100); | |||
setHeight(100); | |||
setWidthUnits(UNITS_PERCENTAGE); | |||
setHeightUnits(UNITS_PERCENTAGE); | |||
} | |||
/* | |||
* (non-Javadoc) | |||
* | |||
* @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined() | |||
*/ | |||
public void setSizeUndefined() { | |||
setWidth(-1); | |||
setHeight(-1); | |||
setWidthUnits(UNITS_PIXELS); | |||
setHeightUnits(UNITS_PIXELS); | |||
} | |||
} |