You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/12/06 19:27:48 UTC
svn commit: r887733 - in /incubator/pivot/trunk:
tutorials/src/org/apache/pivot/tutorials/layout/ tutorials/www/
wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/skin/
Author: gbrown
Date: Sun Dec 6 18:27:47 2009
New Revision: 887733
URL: http://svn.apache.org/viewvc?rev=887733&view=rev
Log:
Minor simplification to GridPane API (replace column sequence with a column count; GridPane.Column did not provide sufficient value as a standalone class).
Modified:
incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/grid_panes.wtkx
incubator/pivot/trunk/tutorials/www/grid-panes.xml
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPaneListener.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/GridPaneSkin.java
Modified: incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/grid_panes.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/grid_panes.wtkx?rev=887733&r1=887732&r2=887733&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/grid_panes.wtkx (original)
+++ incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/layout/grid_panes.wtkx Sun Dec 6 18:27:47 2009
@@ -22,16 +22,8 @@
<content>
<Border>
<content>
- <GridPane wtkx:id="gridPane" styles="{horizontalSpacing:1, verticalSpacing:1,
+ <GridPane columnCount="5" styles="{horizontalSpacing:1, verticalSpacing:1,
showHorizontalGridLines:true, showVerticalGridLines:true}">
- <columns>
- <GridPane.Column/>
- <GridPane.Column/>
- <GridPane.Column/>
- <GridPane.Column/>
- <GridPane.Column/>
- </columns>
-
<rows>
<GridPane.Row>
<Label text="0, 0" styles="{horizontalAlignment:'center',
Modified: incubator/pivot/trunk/tutorials/www/grid-panes.xml
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/grid-panes.xml?rev=887733&r1=887732&r2=887733&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/grid-panes.xml (original)
+++ incubator/pivot/trunk/tutorials/www/grid-panes.xml Sun Dec 6 18:27:47 2009
@@ -60,6 +60,76 @@
<source type="xml" location="org/apache/pivot/tutorials/layout/grid_panes.wtkx">
<![CDATA[
+ <Window title="Grid Panes" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <Border>
+ <content>
+ <GridPane columnCount="5" styles="{horizontalSpacing:1, verticalSpacing:1,
+ showHorizontalGridLines:true, showVerticalGridLines:true}">
+ <rows>
+ <GridPane.Row>
+ <Label text="0, 0" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="0, 1" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="0, 2" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="0, 3" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <GridPane.Filler/>
+ </GridPane.Row>
+ <GridPane.Row>
+ <Label text="1, 0" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="1, 1" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="1, 2" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <GridPane.Filler/>
+ <Label text="1, 4" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ </GridPane.Row>
+ <GridPane.Row>
+ <Label text="2, 0" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="2, 1" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <GridPane.Filler/>
+ <Label text="2, 3" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="2, 4" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ </GridPane.Row>
+ <GridPane.Row>
+ <Label text="3, 0" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <GridPane.Filler/>
+ <Label text="3, 2" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="3, 3" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="3, 4" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ </GridPane.Row>
+ <GridPane.Row>
+ <GridPane.Filler/>
+ <Label text="4, 1" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="4, 2" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="4, 3" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ <Label text="4, 4" styles="{horizontalAlignment:'center',
+ verticalAlignment:'center'}"/>
+ </GridPane.Row>
+ </rows>
+ </GridPane>
+ </content>
+ </Border>
+ </content>
+ </Window>
]]>
</source>
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java?rev=887733&r1=887732&r2=887733&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPane.java Sun Dec 6 18:27:47 2009
@@ -46,31 +46,10 @@
return gridPane;
}
- /**
- * Sets the grid pane with which this row is associated.
- *
- * @param gridPane
- * The row's grid pane, or <tt>null</tt> if the row does not
- * currently belong to a grid.
- */
private void setGridPane(GridPane gridPane) {
this.gridPane = gridPane;
}
- /**
- * Sets the visible flag for all components in the row.
- * <p>
- * This is a convenience method that iterates through the row, calling
- * <tt>setVisible</tt> on all components.
- */
- public void setVisible(boolean visible) {
- if (gridPane != null) {
- for (Component component : cells) {
- component.setVisible(visible);
- }
- }
- }
-
@Override
public int add(Component component) {
int i = getLength();
@@ -170,53 +149,6 @@
}
/**
- * Represents a grid pane column.
- */
- public static class Column {
- private GridPane gridPane = null;
-
- /**
- * Returns the grid pane with which this column is associated.
- *
- * @return
- * The column's grid pane, or <tt>null</tt> if the column does not
- * currently belong to a grid.
- */
- public GridPane getGridPane() {
- return gridPane;
- }
-
- /**
- * Sets the grid pane with which this column is associated.
- *
- * @param gridPane
- * The column's grid pane, or <tt>null</tt> if the column does not
- * currently belong to a grid.
- */
- private void setGridPane(GridPane gridPane) {
- this.gridPane = gridPane;
- }
-
- /**
- * Sets the visible flag for all components in the column.
- * <p>
- * This is a convenience method that iterates through the components in
- * the column, calling <tt>setVisible</tt> on all such components.
- */
- public void setVisible(boolean visible) {
- if (gridPane != null) {
- int columnIndex = gridPane.columns.indexOf(this);
-
- for (Row row : gridPane.rows) {
- if (row.getLength() > columnIndex) {
- row.get(columnIndex).setVisible(visible);
- }
- }
- }
- }
- }
-
- /**
* Grid pane skin interface. Grid pane skins must implement
* this interface to facilitate additional communication between the
* component and the skin.
@@ -325,92 +257,6 @@
}
/**
- * Class that manages a grid pane's column list. Callers get access to the
- * column sequence via {@link GridPane#getColumns()}.
- */
- public final class ColumnSequence implements Sequence<Column>, Iterable<Column> {
- private ColumnSequence() {
- }
-
- @Override
- public int add(Column column) {
- int i = getLength();
- insert(column, i);
-
- return i;
- }
-
- @Override
- public void insert(Column column, int index) {
- if (column == null) {
- throw new IllegalArgumentException("column is null.");
- }
-
- if (column.getGridPane() != null) {
- throw new IllegalArgumentException
- ("column is already in use by another grid pane.");
- }
-
- columns.insert(column, index);
- column.setGridPane(GridPane.this);
-
- // Notify listeners
- gridPaneListeners.columnInserted(GridPane.this, index);
- }
-
- @Override
- public Column update(int index, Column column) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public int remove(Column column) {
- int index = indexOf(column);
- if (index != -1) {
- remove(index, 1);
- }
-
- return index;
- }
-
- @Override
- public Sequence<Column> remove(int index, int count) {
- Sequence<Column> removed = columns.remove(index, count);
-
- if (count > 0) {
- for (int i = 0, n = removed.getLength(); i < n; i++) {
- Column column = removed.get(i);
- column.setGridPane(null);
- }
-
- gridPaneListeners.columnsRemoved(GridPane.this, index, removed);
- }
-
- return removed;
- }
-
- @Override
- public Column get(int index) {
- return columns.get(index);
- }
-
- @Override
- public int indexOf(Column column) {
- return columns.indexOf(column);
- }
-
- @Override
- public int getLength() {
- return columns.getLength();
- }
-
- @Override
- public Iterator<Column> iterator() {
- return new ImmutableIterator<Column>(columns.iterator());
- }
- }
-
- /**
* Component that can be used as filler for empty cells.
*/
public static class Filler extends Component {
@@ -422,32 +268,24 @@
private static class GridPaneListenerList extends ListenerList<GridPaneListener>
implements GridPaneListener {
@Override
- public void rowInserted(GridPane gridPane, int index) {
+ public void columnCountChanged(GridPane gridPane, int previousColumnCount) {
for (GridPaneListener listener : this) {
- listener.rowInserted(gridPane, index);
+ listener.columnCountChanged(gridPane, previousColumnCount);
}
}
@Override
- public void rowsRemoved(GridPane gridPane, int index,
- Sequence<GridPane.Row> rows) {
- for (GridPaneListener listener : this) {
- listener.rowsRemoved(gridPane, index, rows);
- }
- }
-
- @Override
- public void columnInserted(GridPane gridPane, int index) {
+ public void rowInserted(GridPane gridPane, int index) {
for (GridPaneListener listener : this) {
- listener.columnInserted(gridPane, index);
+ listener.rowInserted(gridPane, index);
}
}
@Override
- public void columnsRemoved(GridPane gridPane, int index,
- Sequence<GridPane.Column> columns) {
+ public void rowsRemoved(GridPane gridPane, int index,
+ Sequence<GridPane.Row> rows) {
for (GridPaneListener listener : this) {
- listener.columnsRemoved(gridPane, index, columns);
+ listener.rowsRemoved(gridPane, index, rows);
}
}
@@ -475,11 +313,10 @@
}
}
- private ArrayList<Row> rows = null;
- private RowSequence rowSequence = new RowSequence();
+ private int columnCount;
- private ArrayList<Column> columns = null;
- private ColumnSequence columnSequence = new ColumnSequence();
+ private ArrayList<Row> rows = new ArrayList<Row>();
+ private RowSequence rowSequence = new RowSequence();
private GridPaneListenerList gridPaneListeners = new GridPaneListenerList();
@@ -487,7 +324,7 @@
* Creates a new <tt>GridPane</tt> with empty row and column sequences.
*/
public GridPane() {
- this(new ArrayList<Column>());
+ this(0);
}
/**
@@ -496,13 +333,12 @@
* @param columns
* The column sequence to use. A copy of this sequence will be made
*/
- public GridPane(Sequence<Column> columns) {
- if (columns == null) {
- throw new IllegalArgumentException("columns is null");
+ public GridPane(int columnCount) {
+ if (columnCount < 0) {
+ throw new IllegalArgumentException("columnCount is negative.");
}
- this.rows = new ArrayList<Row>();
- this.columns = new ArrayList<Column>(columns);
+ setColumnCount(columnCount);
installThemeSkin(GridPane.class);
}
@@ -518,6 +354,27 @@
}
/**
+ * Returns the number of columns in the grid pane.
+ */
+ public int getColumnCount() {
+ return columnCount;
+ }
+
+ /**
+ * Sets the number of columns in the grid pane.
+ *
+ * @param columnCount
+ */
+ public void setColumnCount(int columnCount) {
+ int previousColumnCount = this.columnCount;
+
+ if (previousColumnCount != columnCount) {
+ this.columnCount = columnCount;
+ gridPaneListeners.columnCountChanged(this, previousColumnCount);
+ }
+ }
+
+ /**
* Returns the grid pane row sequence.
*
* @return
@@ -554,16 +411,6 @@
}
/**
- * Returns the grid pane column sequence.
- *
- * @return
- * The grid pane column sequence
- */
- public ColumnSequence getColumns() {
- return columnSequence;
- }
-
- /**
* Returns the index of the column at a given location.
*
* @param x
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPaneListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPaneListener.java?rev=887733&r1=887732&r2=887733&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPaneListener.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/GridPaneListener.java Sun Dec 6 18:27:47 2009
@@ -27,20 +27,15 @@
*/
public static class Adapter implements GridPaneListener {
@Override
- public void rowInserted(GridPane gridPane, int index) {
- }
-
- @Override
- public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows) {
+ public void columnCountChanged(GridPane gridPane, int previousColumnCount) {
}
@Override
- public void columnInserted(GridPane gridPane, int index) {
+ public void rowInserted(GridPane gridPane, int index) {
}
@Override
- public void columnsRemoved(GridPane gridPane, int index,
- Sequence<GridPane.Column> columns) {
+ public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows) {
}
@Override
@@ -57,38 +52,29 @@
}
/**
- * Called when a row has been inserted into a grid pane.
- *
- * @param gridPane
- * @param index
- */
- public void rowInserted(GridPane gridPane, int index);
-
- /**
- * Called when rows have been removed from a grid pane.
+ * Called when a grid pane's column count has changed.
*
* @param gridPane
- * @param index
- * @param rows
+ * @param previousColumnCount
*/
- public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows);
+ public void columnCountChanged(GridPane gridPane, int previousColumnCount);
/**
- * Called when a column has been inserted into a grid pane.
+ * Called when a row has been inserted into a grid pane.
*
* @param gridPane
* @param index
*/
- public void columnInserted(GridPane gridPane, int index);
+ public void rowInserted(GridPane gridPane, int index);
/**
- * Called when column's have been removed from a grid pane.
+ * Called when rows have been removed from a grid pane.
*
* @param gridPane
* @param index
- * @param columns
+ * @param rows
*/
- public void columnsRemoved(GridPane gridPane, int index, Sequence<GridPane.Column> columns);
+ public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows);
/**
* Called when a cell has been inserted into a grid pane.
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/GridPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/GridPaneSkin.java?rev=887733&r1=887732&r2=887733&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/GridPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/GridPaneSkin.java Sun Dec 6 18:27:47 2009
@@ -49,10 +49,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
visibleRows = new boolean[rowCount];
visibleColumns = new boolean[columnCount];
@@ -118,10 +117,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
Metadata metadata = new Metadata();
@@ -160,10 +158,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
Metadata metadata = new Metadata();
@@ -202,10 +199,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
Metadata metadata = new Metadata();
@@ -255,10 +251,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
Metadata metadata = new Metadata();
@@ -300,10 +295,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
int width = getWidth();
int height = getHeight();
@@ -345,10 +339,9 @@
GridPane gridPane = (GridPane)getComponent();
GridPane.RowSequence rows = gridPane.getRows();
- GridPane.ColumnSequence columns = gridPane.getColumns();
+ int columnCount = gridPane.getColumnCount();
int rowCount = rows.getLength();
- int columnCount = columns.getLength();
int width = getWidth();
int height = getHeight();
@@ -680,10 +673,8 @@
@Override
public int getColumnAt(int x) {
GridPane gridPane = (GridPane)getComponent();
- GridPane.ColumnSequence columns = gridPane.getColumns();
-
- int columnCount = columns.getLength();
+ int columnCount = gridPane.getColumnCount();
int columnIndex = -1;
for (int j = 0, columnX = padding.left; columnX <= x && j < columnCount; j++) {
@@ -702,9 +693,7 @@
@Override
public Bounds getColumnBounds(int column) {
GridPane gridPane = (GridPane)getComponent();
- GridPane.ColumnSequence columns = gridPane.getColumns();
-
- int columnCount = columns.getLength();
+ int columnCount = gridPane.getColumnCount();
if (column < 0
|| column >= columnCount) {
@@ -721,25 +710,18 @@
}
// GridPaneListener methods
-
@Override
- public void rowInserted(GridPane gridPane, int index) {
+ public void columnCountChanged(GridPane gridPane, int previousColumnCount) {
invalidateComponent();
}
@Override
- public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows) {
- invalidateComponent();
- }
-
- @Override
- public void columnInserted(GridPane gridPane, int index) {
+ public void rowInserted(GridPane gridPane, int index) {
invalidateComponent();
}
@Override
- public void columnsRemoved(GridPane gridPane, int index,
- Sequence<GridPane.Column> columns) {
+ public void rowsRemoved(GridPane gridPane, int index, Sequence<GridPane.Row> rows) {
invalidateComponent();
}