Quellcode durchsuchen

Layout API changes (#1041) to server-side. Client-side implementation still not done.

svn changeset:2659/svn branch:trunk
tags/6.7.0.beta1
Jouni Koivuviita vor 16 Jahren
Ursprung
Commit
e0ff6f0cfd

+ 10
- 0
src/com/itmill/toolkit/demo/reservation/GoogleMap.java Datei anzeigen

public void clear() { public void clear() {
setContainerDataSource(null); setContainerDataSource(null);
} }
public void setSizeFull() {
// TODO Auto-generated method stub
}
public void setSizeUndefined() {
// TODO Auto-generated method stub
}
} }

+ 11
- 1
src/com/itmill/toolkit/terminal/Sizeable.java Datei anzeigen



Development of Browser User Interfaces Made Easy Development of Browser User Interfaces Made Easy


Copyright (C) 2000-2006 IT Mill Ltd
Copyright (C) 2000-2007 IT Mill Ltd
************************************************************************* *************************************************************************


* the units used in height property. * the units used in height property.
*/ */
public void setHeightUnits(int units); public void setHeightUnits(int units);
/**
* Sets the size to 100% x 100%.
*/
public void setSizeFull();
/**
* Clears any size settings.
*/
public void setSizeUndefined();


} }

+ 2
- 2
src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java Datei anzeigen

if ("gc".equals(c.getTag())) { if ("gc".equals(c.getTag())) {
column++; column++;
int w; int w;
if (c.hasAttribute("w")) {
w = c.getIntAttribute("w");
if (c.hasAttribute("cols")) {
w = c.getIntAttribute("cols");
} else } else
w = 1; w = 1;
((FlexCellFormatter) getCellFormatter()).setColSpan( ((FlexCellFormatter) getCellFormatter()).setColSpan(

+ 1
- 2
src/com/itmill/toolkit/tests/TestForBasicApplicationLayout.java Datei anzeigen

Panel p = new Panel("Accordion Panel"); Panel p = new Panel("Accordion Panel");
p.setHeight(100); p.setHeight(100);
p.setHeightUnits(Panel.UNITS_PERCENTAGE); p.setHeightUnits(Panel.UNITS_PERCENTAGE);
p.addStyleName(Panel.STYLE_NO_PADDING);
tab = new TabSheet(); tab = new TabSheet();
tab.setWidth(100); tab.setWidth(100);
cal.setLocale(new Locale("en", "US")); cal.setLocale(new Locale("en", "US"));
report.addComponent(cal); report.addComponent(cal);
((ExpandLayout) report.getLayout()).expand(controls); ((ExpandLayout) report.getLayout()).expand(controls);
report.setStyle("light");
report.addStyleName(Panel.STYLE_LIGHT);
report.setHeight(100); report.setHeight(100);
report.setHeightUnits(Sizeable.UNITS_PERCENTAGE); report.setHeightUnits(Sizeable.UNITS_PERCENTAGE);

+ 12
- 0
src/com/itmill/toolkit/tests/TestForWindowing.java Datei anzeigen

import com.itmill.toolkit.ui.OptionGroup; import com.itmill.toolkit.ui.OptionGroup;
import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Select; import com.itmill.toolkit.ui.Select;
import com.itmill.toolkit.ui.Slider;
import com.itmill.toolkit.ui.Window; import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent; import com.itmill.toolkit.ui.Button.ClickEvent;
import com.itmill.toolkit.ui.Button.ClickListener; import com.itmill.toolkit.ui.Button.ClickListener;
w.addComponent(s1); w.addComponent(s1);
w.addComponent(TestForWindowing.this.s2); 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); getApplication().getMainWindow().addWindow(w);


} }

+ 61
- 0
src/com/itmill/toolkit/tests/featurebrowser/FeatureBrowser.java Datei anzeigen

// TODO Auto-generated method stub // 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
}
} }

+ 0
- 1
src/com/itmill/toolkit/tests/featurebrowser/PropertyPanel.java Datei anzeigen

// Layout // Layout
setCaption("Properties"); setCaption("Properties");
addComponent(formsLayout); addComponent(formsLayout);
addStyleName(Panel.STYLE_NO_PADDING);


setWidth(100); setWidth(100);
setWidthUnits(Table.UNITS_PERCENTAGE); setWidthUnits(Table.UNITS_PERCENTAGE);

+ 10
- 7
src/com/itmill/toolkit/ui/AbstractComponent.java Datei anzeigen



package com.itmill.toolkit.ui; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; 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 * An abstract class that defines default implementation for the

+ 204
- 0
src/com/itmill/toolkit/ui/AbstractLayout.java Datei anzeigen

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()]);
}

}

+ 2
- 1
src/com/itmill/toolkit/ui/CustomLayout.java Datei anzeigen

* @VERSION@ * @VERSION@
* @since 3.0 * @since 3.0
*/ */
public class CustomLayout extends AbstractComponentContainer implements Layout {
public class CustomLayout extends AbstractLayout {


/** /**
* Custom layout slots containing the components. * Custom layout slots containing the components.
* if the paint operation failed. * if the paint operation failed.
*/ */
public void paintContent(PaintTarget target) throws PaintException { public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);


target.addAttribute("template", templateName); target.addAttribute("template", templateName);
// Adds all items in all the locations // Adds all items in all the locations

+ 22
- 0
src/com/itmill/toolkit/ui/Embedded.java Datei anzeigen

} }
} }


/*
* (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);
}

} }

+ 330
- 152
src/com/itmill/toolkit/ui/GridLayout.java Datei anzeigen



Development of Browser User Interfaces Made Easy Development of Browser User Interfaces Made Easy


Copyright (C) 2000-2006 IT Mill Ltd
Copyright (C) 2000-2007 IT Mill Ltd
************************************************************************* *************************************************************************


package com.itmill.toolkit.ui; package com.itmill.toolkit.ui;


import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map;


import com.itmill.toolkit.terminal.PaintException; import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget; import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.terminal.Sizeable;


/** /**
* <p> * <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>
* *
* <p> * <p>
* Each component in a <code>GridLayout</code> uses a certain * 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> * </p>
* *
* @author IT Mill Ltd. * @author IT Mill Ltd.
* @VERSION@ * @VERSION@
* @since 3.0 * @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 * Cursor X position: this is where the next component with unspecified x,y
private LinkedList areas = new LinkedList(); private LinkedList areas = new LinkedList();


/** /**
* Mapping from components to threir respective areas.
* Mapping from components to their respective areas.
*/ */
private LinkedList components = new LinkedList(); 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);
} }


/** /**
/** /**
* <p> * <p>
* Adds a component with a specified area to the grid. The area the new * 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>
* *
* <p> * <p>
* *
* @param c * @param c
* the component to be added. * 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. * <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 * @throws OverlapsException
* if the new component overlaps with any of the components * if the new component overlaps with any of the components
* already in the grid. * already in the grid.
* @throws OutOfBoundsException * @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) if (component == null)
throw new NullPointerException("Component must not be null"); throw new NullPointerException("Component must not be null");
"Component is already in the container"); "Component is already in the container");


// Creates the area // 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 // Checks the validity of the coordinates
if (x2 < x1 || y2 < y2)
if (column2 < column1 || row2 < row1)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Illegal coordinates for the component"); "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); throw new OutOfBoundsException(area);


// Checks that newItem does not overlap with existing items // Checks that newItem does not overlap with existing items
boolean done = false; boolean done = false;
while (!done && i.hasNext()) { while (!done && i.hasNext()) {
Area existingArea = (Area) i.next(); 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); areas.add(index, area);
components.add(index, component); components.add(index, component);
done = true; done = true;
} }


/** /**
* 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 * 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 * @param c
* the component to be added. * 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);
} }


/** /**
*/ */
public void space() { public void space() {
cursorX++; cursorX++;
if (cursorX >= width) {
if (cursorX >= cols) {
cursorX = 0; cursorX = 0;
cursorY++; cursorY++;
} }
* Adds the component into this container to the cursor position. If the * Adds the component into this container to the cursor position. If the
* cursor position is already occupied, the cursor is moved forwards to find * 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 * free position. If the cursor goes out from the bottom of the grid, the
* grid is automaticly extended.
* grid is automatically extended.
* *
* @param c * @param c
* the component to be added. * the component to be added.
} }


// Extends the grid if needed // 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); addComponent(component, cursorX, cursorY);
} }
components.remove(component); components.remove(component);
if (area != null) if (area != null)
areas.remove(area); areas.remove(area);
componentToAlignment.remove(component);


requestRepaint(); 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 // Finds the area
for (Iterator i = areas.iterator(); i.hasNext();) { for (Iterator i = areas.iterator(); i.hasNext();) {
Area area = (Area) i.next(); Area area = (Area) i.next();
if (area.getX1() == x && area.getY1() == y) {
if (area.getColumn1() == column && area.getRow1() == row) {
removeComponent(area.getComponent()); removeComponent(area.getComponent());
return; return;
} }
*/ */
public void paintContent(PaintTarget target) throws PaintException { 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 // Area iterator
Iterator areaiterator = areas.iterator(); Iterator areaiterator = areas.iterator();
int emptyCells = 0; int emptyCells = 0;


// Iterates every applicable row // Iterates every applicable row
for (int cury = 0; cury < height; cury++) {
for (int cury = 0; cury < rows; cury++) {
target.startTag("gr"); target.startTag("gr");


// Iterates every applicable column // 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 // 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 // First check if empty cell needs to be rendered
if (emptyCells > 0) { if (emptyCells > 0) {
} }


// Now proceed rendering current item // 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.startTag("gc");


target.addAttribute("x", curx); target.addAttribute("x", curx);
// Checks if empty cell needs to be rendered // Checks if empty cell needs to be rendered
if (emptyCells > 0) { if (emptyCells > 0) {
target.startTag("gc"); target.startTag("gc");
target.addAttribute("x", width - emptyCells);
target.addAttribute("x", cols - emptyCells);
target.addAttribute("y", cury); target.addAttribute("y", cury);
if (emptyCells > 1) { if (emptyCells > 1) {
target.addAttribute("w", emptyCells); target.addAttribute("w", emptyCells);
} }


/** /**
* 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. * @author IT Mill Ltd.
* @version * @version
public class Area { 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. * Component painted on the area.
* *
* @param component * @param component
* the component connected to the area. * 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. * <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. * <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. * <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. * <code>c</code> is supposed to occupy.
* @throws OverlapsException * @throws OverlapsException
* if the new component overlaps with any of the components * if the new component overlaps with any of the components
* already in the grid * 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; this.component = component;
} }


* this area, <code>false</code> if it doesn't. * this area, <code>false</code> if it doesn't.
*/ */
public boolean overlaps(Area other) { 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();


} }


} }


/** /**
* 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() { 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() { 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() { 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() { 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;
} }


} }
} }


/** /**
* 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) { 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 // The the param
if (width < 1)
if (columns < 1)
throw new IllegalArgumentException( 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 // In case of no change
if (this.width == width)
if (this.cols == columns)
return; return;


// Checks for overlaps // Checks for overlaps
if (this.width > width)
if (this.cols > columns)
for (Iterator i = areas.iterator(); i.hasNext();) { for (Iterator i = areas.iterator(); i.hasNext();) {
Area area = (Area) i.next(); Area area = (Area) i.next();
if (area.x2 >= width)
if (area.column2 >= columns)
throw new OutOfBoundsException(area); throw new OutOfBoundsException(area);
} }


this.width = width;
this.cols = columns;


requestRepaint(); 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) { 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 // The the param
if (height < 1)
if (rows < 1)
throw new IllegalArgumentException( 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 // In case of no change
if (this.height == height)
if (this.rows == rows)
return; return;


// Checks for overlaps // Checks for overlaps
if (this.height > height)
if (this.rows > rows)
for (Iterator i = areas.iterator(); i.hasNext();) { for (Iterator i = areas.iterator(); i.hasNext();) {
Area area = (Area) i.next(); Area area = (Area) i.next();
if (area.y2 >= height)
if (area.row2 >= rows)
throw new OutOfBoundsException(area); throw new OutOfBoundsException(area);
} }


this.height = height;
this.rows = rows;


requestRepaint(); 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 * Gets the current cursor x-position. The cursor position points the
* position for the next component that is added without specifying its * 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() { public int getCursorX() {
return cursorX; return cursorX;
/** /**
* Gets the current cursor y-position. The cursor position points the * Gets the current cursor y-position. The cursor position points the
* position for the next component that is added without specifying its * 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() { public int getCursorY() {
return cursorY; return cursorY;
addComponent(newComponent); addComponent(newComponent);
else if (newLocation == null) { else if (newLocation == null) {
removeComponent(oldComponent); removeComponent(oldComponent);
addComponent(newComponent, oldLocation.getX1(),
oldLocation.getY1(), oldLocation.getX2(), oldLocation
.getY2());
addComponent(newComponent, oldLocation.getColumn1(), oldLocation
.getRow1(), oldLocation.getColumn2(), oldLocation.getRow2());
} else { } else {
oldLocation.setComponent(newComponent); oldLocation.setComponent(newComponent);
newLocation.setComponent(oldComponent); newLocation.setComponent(oldComponent);
*/ */
public void removeAllComponents() { public void removeAllComponents() {
super.removeAllComponents(); super.removeAllComponents();
this.componentToAlignment = new HashMap();
this.cursorX = 0; this.cursorX = 0;
this.cursorY = 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
- 1
src/com/itmill/toolkit/ui/Layout.java Datei anzeigen



package com.itmill.toolkit.ui; package com.itmill.toolkit.ui;


import com.itmill.toolkit.terminal.Sizeable;


/** /**
* Extension to the {@link ComponentContainer} interface which adds the * Extension to the {@link ComponentContainer} interface which adds the
* layouting control to the elements in the container. This is required by the * layouting control to the elements in the container. This is required by the
* @VERSION@ * @VERSION@
* @since 3.0 * @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);


} }

+ 106
- 6
src/com/itmill/toolkit/ui/OrderedLayout.java Datei anzeigen



package com.itmill.toolkit.ui; 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.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map;

import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;


/** /**
* Ordered layout. * Ordered layout.
* @VERSION@ * @VERSION@
* @since 3.0 * @since 3.0
*/ */
public class OrderedLayout extends AbstractComponentContainer implements Layout {
public class OrderedLayout extends AbstractLayout {


/* Predefined orientations ***************************************** */ /* Predefined orientations ***************************************** */


/** /**
* Components are to be layed out vertically.
* Components are to be laid out vertically.
*/ */
public static int ORIENTATION_VERTICAL = 0; 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; public static int ORIENTATION_HORIZONTAL = 1;


*/ */
private LinkedList components = new LinkedList(); 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. * Orientation of the layout.
*/ */
private int orientation; 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 * Creates a new ordered layout. The order of the layout is
* <code>ORIENTATION_VERTICAL</code>. * <code>ORIENTATION_VERTICAL</code>.
public void removeComponent(Component c) { public void removeComponent(Component c) {
super.removeComponent(c); super.removeComponent(c);
components.remove(c); components.remove(c);
componentToAlignment.remove(c);
requestRepaint(); requestRepaint();
} }


* if the paint operation failed. * if the paint operation failed.
*/ */
public void paintContent(PaintTarget target) throws PaintException { public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);


// Adds the attributes: orientation // Adds the attributes: orientation
// note that the default values (b/vertival) are omitted // note that the default values (b/vertival) are omitted
if (orientation == ORIENTATION_HORIZONTAL) if (orientation == ORIENTATION_HORIZONTAL)
target.addAttribute("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 // Adds all items in all the locations
for (Iterator i = components.iterator(); i.hasNext();) { for (Iterator i = components.iterator(); i.hasNext();) {
Component c = (Component) i.next(); Component c = (Component) i.next();
if (c != null) { if (c != null) {
// Paint child component UIDL
c.paint(target); 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);
} }


/** /**
components.remove(oldComponent); components.remove(oldComponent);
components.add(newLocation, oldComponent); components.add(newLocation, oldComponent);
components.remove(newComponent); components.remove(newComponent);
componentToAlignment.remove(newComponent);
components.add(oldLocation, newComponent); components.add(oldLocation, newComponent);
} else { } else {
components.remove(newComponent); components.remove(newComponent);
components.add(oldLocation, newComponent); components.add(oldLocation, newComponent);
components.remove(oldComponent); components.remove(oldComponent);
componentToAlignment.remove(oldComponent);
components.add(newLocation, oldComponent); components.add(newLocation, oldComponent);
} }


requestRepaint(); 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;
}
} }

+ 3
- 118
src/com/itmill/toolkit/ui/Panel.java Datei anzeigen

import com.itmill.toolkit.terminal.PaintException; import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget; import com.itmill.toolkit.terminal.PaintTarget;
import com.itmill.toolkit.terminal.Scrollable; import com.itmill.toolkit.terminal.Scrollable;
import com.itmill.toolkit.terminal.Sizeable;


/** /**
* Panel - a simple single component container. * Panel - a simple single component container.
* @VERSION@ * @VERSION@
* @since 3.0 * @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 { ComponentContainer.ComponentDetachListener, Action.Container {


public static final String STYLE_LIGHT = "light"; public static final String STYLE_LIGHT = "light";


public static final String STYLE_EMPHASIZE = "emphasize"; 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. * Layout of the panel.
*/ */
private Layout layout; 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. * Scroll X position.
*/ */
public void paintContent(PaintTarget target) throws PaintException { public void paintContent(PaintTarget target) throws PaintException {
layout.paint(target); 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()) { if (isScrollable()) {
target.addVariable(this, "scrollleft", getScrollOffsetX()); target.addVariable(this, "scrollleft", getScrollOffsetX());
return layout.getComponentIterator(); 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 * Called when one or more variables handled by the implementing class are
* changed. * changed.


} }


/**
* 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 */ /* Scrolling functionality */


/* Documented in interface */ /* Documented in interface */

+ 6
- 57
src/com/itmill/toolkit/ui/SplitPanel.java Datei anzeigen

* @VERSION@ * @VERSION@
* @since 5.0 * @since 5.0
*/ */
public class SplitPanel extends AbstractComponentContainer implements Layout,
Sizeable {
public class SplitPanel extends AbstractLayout {


/* Predefined orientations ***************************************** */ /* Predefined orientations ***************************************** */


*/ */
private int orientation; private int orientation;


private int height;

private int heightUnit;

private int width;

private int widthUnit;

private int pos = 50; private int pos = 50;


private int posUnit = UNITS_PERCENTAGE; private int posUnit = UNITS_PERCENTAGE;
*/ */
public SplitPanel() { public SplitPanel() {
orientation = ORIENTATION_VERTICAL; orientation = ORIENTATION_VERTICAL;
setSizeFull();
} }


/** /**
*/ */
public SplitPanel(int orientation) { public SplitPanel(int orientation) {
this.orientation = orientation; this.orientation = orientation;
setSizeFull();
} }


/** /**
* if the paint operation failed. * if the paint operation failed.
*/ */
public void paintContent(PaintTarget target) throws PaintException { 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]; String position = pos + UNIT_SYMBOLS[posUnit];


/** /**
* Moves the position of the splitter with given position and unit. * Moves the position of the splitter with given position and unit.
* *
* Supported Units are {@link Sizeable}.UNITS_PERSENTAGE and
* Sizeable.UNITS_PIXELS
*
* @param pos * @param pos
* size of the first region * 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) { public void setSplitPosition(int pos, int unit) {
this.pos = pos; this.pos = pos;
this.posUnit = unit; 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;
}
} }

+ 5
- 55
src/com/itmill/toolkit/ui/TabSheet.java Datei anzeigen

* @VERSION@ * @VERSION@
* @since 3.0 * @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 * 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"; public static final String STYLE_NO_PADDING = "nopad";


*/ */
private boolean tabsHidden; 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. * Constructs a new Tabsheet. Tabsheet is immediate by default.
*/ */
* if the paint operation failed. * if the paint operation failed.
*/ */
public void paintContent(PaintTarget target) throws PaintException { public void paintContent(PaintTarget target) throws PaintException {

super.paintContent(target);
if (areTabsHidden()) if (areTabsHidden())
target.addAttribute("hidetabs", true); 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"); target.startTag("tabs");


for (Iterator i = getComponentIterator(); i.hasNext();) { for (Iterator i = getComponentIterator(); i.hasNext();) {
fireEvent(new SelectedTabChangeEvent(this)); 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();
}
} }

+ 40
- 16
src/com/itmill/toolkit/ui/Table.java Datei anzeigen

} }


/** /**
* 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. * would support this.
* *
* @return True iff sorting is disabled. * @return True iff sorting is disabled.
} }


/** /**
* 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. * columns are given even in the case where datasource would support this.
* *
* @param sortDisabled * @param sortDisabled
} }


/** /**
* Gets the height property units.
* Gets height property unit.
* *
* @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits() * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
*/ */
} }


/** /**
* Gets the width property units.
* Gets width property unit.
* *
* @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits() * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
*/ */
} }


/** /**
* Sets the height units.
* Sets height units.
* *
* @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int) * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
*/ */
} }


/** /**
* 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 * Sizeable.UNITS_PERCENTAGE. Setting to any other throws
* IllegalArgumentException. * IllegalArgumentException.
* *
} }


/** /**
* 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() * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
*/ */
public int getHeight() { public int getHeight() {
} }


/** /**
* 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() * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
*/ */
public int getWidth() { public int getWidth() {
} }


/** /**
* 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 * @param height
* the height to set. * the height to set.
} }


/** /**
* 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 * @param width
* the width to set. * the width to set.
} }
} }


/*
* (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);
}

} }

Laden…
Abbrechen
Speichern