* Contains all items that are placed on the grid. These are components with
* grid area definition.
*/
- private final LinkedList areas = new LinkedList();
+ private final LinkedList<Area> areas = new LinkedList<Area>();
/**
* Mapping from components to their respective areas.
// Inserts the component to right place at the list
// Respect top-down, left-right ordering
// component.setParent(this);
- final Iterator i = areas.iterator();
+ final Iterator<Area> i = areas.iterator();
int index = 0;
boolean done = false;
while (!done && i.hasNext()) {
- final Area existingArea = (Area) i.next();
+ final Area existingArea = i.next();
if ((existingArea.row1 >= row1 && existingArea.column1 > column1)
|| existingArea.row1 > row1) {
areas.add(index, area);
* if <code>area</code> overlaps with any existing area.
*/
private void checkExistingOverlaps(Area area) throws OverlapsException {
- for (final Iterator i = areas.iterator(); i.hasNext();) {
- final Area existingArea = (Area) i.next();
+ for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ final Area existingArea = i.next();
if (existingArea.overlaps(area)) {
// Component not added, overlaps with existing component
throw new OverlapsException(existingArea);
}
Area area = null;
- for (final Iterator i = areas.iterator(); area == null && i.hasNext();) {
- final Area a = (Area) i.next();
+ for (final Iterator<Area> i = areas.iterator(); area == null
+ && i.hasNext();) {
+ final Area a = i.next();
if (a.getComponent() == component) {
area = a;
}
public void removeComponent(int column, int row) {
// Finds the area
- for (final Iterator i = areas.iterator(); i.hasNext();) {
- final Area area = (Area) i.next();
+ for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ final Area area = i.next();
if (area.getColumn1() == column && area.getRow1() == row) {
removeComponent(area.getComponent());
return;
}
// Area iterator
- final Iterator areaiterator = areas.iterator();
+ final Iterator<Area> areaiterator = areas.iterator();
// Current item to be processed (fetch first item)
Area area = areaiterator.hasNext() ? (Area) areaiterator.next() : null;
// Collects rowspan related information here
- final HashMap cellUsed = new HashMap();
+ final HashMap<Integer, Integer> cellUsed = new HashMap<Integer, Integer>();
// Empty cell collector
int emptyCells = 0;
// Fetch next item
if (areaiterator.hasNext()) {
- area = (Area) areaiterator.next();
+ area = areaiterator.next();
} else {
area = null;
}
// Current column contains already an item,
// check if rowspan affects at current x,y position
- final int rowspanDepth = ((Integer) cellUsed
- .get(new Integer(curx))).intValue();
+ final int rowspanDepth = cellUsed
+ .get(new Integer(curx)).intValue();
if (rowspanDepth >= cury) {
// Checks for overlaps
if (cols > columns) {
- for (final Iterator i = areas.iterator(); i.hasNext();) {
- final Area area = (Area) i.next();
+ for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ final Area area = i.next();
if (area.column2 >= columns) {
throw new OutOfBoundsException(area);
}
// Checks for overlaps
if (this.rows > rows) {
- for (final Iterator i = areas.iterator(); i.hasNext();) {
- final Area area = (Area) i.next();
+ for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ final Area area = i.next();
if (area.row2 >= rows) {
throw new OutOfBoundsException(area);
}
// Gets the locations
Area oldLocation = null;
Area newLocation = null;
- for (final Iterator i = areas.iterator(); i.hasNext();) {
- final Area location = (Area) i.next();
+ for (final Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ final Area location = i.next();
final Component component = location.getComponent();
if (component == oldComponent) {
oldLocation = location;
@Override
public void removeAllComponents() {
super.removeAllComponents();
- componentToAlignment = new HashMap();
+ componentToAlignment = new HashMap<Component, Alignment>();
cursorX = 0;
cursorY = 0;
}
+ " in a gridlayout with height " + rows);
}
- for (Iterator i = areas.iterator(); i.hasNext();) {
- Area existingArea = (Area) i.next();
+ for (Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ Area existingArea = i.next();
// Areas ending below the row needs to be moved down or stretched
if (existingArea.row2 >= row) {
existingArea.row2++;
}
// Shrink or remove areas in the selected row
- for (Iterator i = areas.iterator(); i.hasNext();) {
- Area existingArea = (Area) i.next();
+ for (Iterator<Area> i = areas.iterator(); i.hasNext();) {
+ Area existingArea = i.next();
if (existingArea.row2 >= row) {
existingArea.row2--;
* @return Component in given cell or null if empty
*/
public Component getComponent(int x, int y) {
- for (final Iterator iterator = areas.iterator(); iterator.hasNext();) {
- final Area area = (Area) iterator.next();
+ for (final Iterator<Area> iterator = areas.iterator(); iterator
+ .hasNext();) {
+ final Area area = iterator.next();
if (area.getColumn1() <= x && x <= area.getColumn2()
&& area.getRow1() <= y && y <= area.getRow2()) {
return area.getComponent();
* in the grid
*/
public Area getComponentArea(Component component) {
- for (final Iterator iterator = areas.iterator(); iterator.hasNext();) {
- final Area area = (Area) iterator.next();
+ for (final Iterator<Area> iterator = areas.iterator(); iterator
+ .hasNext();) {
+ final Area area = iterator.next();
if (area.getComponent() == component) {
return area;
}
}
@Override
- public void changeVariables(Object source, Map variables) {
+ public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
if (variables.containsKey(CLICK_EVENT)) {