Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 45524 Details for
Bug 133279
GridLayout generated code points to unavailable package.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Fixed SWT constants usage in the GridLayout code
patch_133279_correct_naming_and_constants.txt (text/plain), 43.00 KB, created by
Michael Golubev
on 2006-06-29 05:32:17 EDT
(
hide
)
Description:
Fixed SWT constants usage in the GridLayout code
Filename:
MIME Type:
Creator:
Michael Golubev
Created:
2006-06-29 05:32:17 EDT
Size:
43.00 KB
patch
obsolete
>Index: src/org/eclipse/gmf/internal/codegen/draw2d/GridLayout.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/codegen/draw2d/GridLayout.java >diff -N src/org/eclipse/gmf/internal/codegen/draw2d/GridLayout.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/codegen/draw2d/GridLayout.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,787 @@ >+package org.eclipse.gmf.internal.codegen.draw2d; >+ >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.draw2d.AbstractLayout; >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.LayoutManager; >+import org.eclipse.draw2d.geometry.Dimension; >+import org.eclipse.draw2d.geometry.Rectangle; >+import org.eclipse.swt.SWT; >+ >+ >+/** >+ * Lays out children into a Grid arrangement in which overall aligment and >+ * spacing can be configured, as well as specfic layout requirements for the >+ * each individual member of the GridLayout. This layout is a Draw2D port of the >+ * swt GridLayout. >+ * >+ * <code>GridLayout</code> has a number of configuration fields, and the >+ * Figures it lays out can have an associated layout data object, called >+ * <code>GridLayoutData</code> (similar to the swt GridLayoutData object). The power of >+ * <code>GridLayout</code> lies in the ability to configure >+ * <code>GridLayoutData</code> for each Figure in the layout. >+ * <p> >+ * The following code creates a container Figure managed by a >+ * <code>GridLayout</code> with 2 columns, containing 3 RectangleFigure >+ * shapes, the last of which has been given further layout instructions. >+ * Note that it is the <code>GridLayout</code> method <code>setConstraint</code> >+ * that binds the child <code>Figure</code> to its layout <code>GridLayoutData</code> object. >+ * >+ * <pre> >+ * Figure container = new Figure(); >+ * GridLayout gridLayout = new GridLayout(); >+ * gridLayout.numColumns = 2; >+ * container.setLayout(gridLayout); >+ * >+ * Shape rect; >+ * rect = new RectangleFigure(); >+ * container.add(rect); >+ * >+ * rect = new RectangleFigure(); >+ * container.add(rect); >+ * >+ * rect = new RectangleFigure(); >+ * GridLayoutData GridLayoutData = new GridLayoutData(); >+ * GridLayoutData.widthHint = 150; >+ * layout.setConstraint(rect, GridLayoutData); >+ * >+ * container.add(rect); >+ * </pre> >+ * >+ * <p> >+ * The <code>numColumns</code> field is the most important field in a >+ * <code>GridLayout</code>. Widgets are laid out in columns from left to >+ * right, and a new row is created when <code>numColumns</code>+ 1 figures >+ * are added to the <code>Figure<code> parent container. >+ * >+ * @see GridLayoutData >+ * >+ * @author Asim Ullah >+ * created: Sep 10, 2004 >+ */ >+public class GridLayout extends AbstractLayout { >+ /** >+ * numColumns specifies the number of cell columns in the layout. >+ * >+ * The default value is 1. >+ */ >+ public int numColumns = 1; >+ >+ /** >+ * makeColumnsEqualWidth specifies whether all columns in the layout will be >+ * forced to have the same width. >+ * >+ * The default value is false. >+ */ >+ public boolean makeColumnsEqualWidth = false; >+ >+ /** >+ * marginWidth specifies the number of pixels of horizontal margin that will >+ * be placed along the left and right edges of the layout. >+ * >+ * The default value is 5. >+ */ >+ public int marginWidth = 5; >+ >+ /** >+ * marginHeight specifies the number of pixels of vertical margin that will >+ * be placed along the top and bottom edges of the layout. >+ * >+ * The default value is 5. >+ */ >+ public int marginHeight = 5; >+ >+ /** >+ * horizontalSpacing specifies the number of pixels between the right edge >+ * of one cell and the left edge of its neighbouring cell to the right. >+ * >+ * The default value is 5. >+ */ >+ public int horizontalSpacing = 5; >+ >+ /** >+ * verticalSpacing specifies the number of pixels between the bottom edge of >+ * one cell and the top edge of its neighbouring cell underneath. >+ * >+ * The default value is 5. >+ */ >+ public int verticalSpacing = 5; >+ >+ /** The layout contraints */ >+ protected Map constraints = new HashMap(); >+ >+ /** >+ * Default Constructor >+ */ >+ public GridLayout() { >+ super(); >+ } >+ >+ /** >+ * Constructs a new instance of this class given the number of columns, and >+ * whether or not the columns should be forced to have the same width. >+ * >+ * @param numColumns >+ * the number of columns in the grid >+ * @param makeColumnsEqualWidth >+ * whether or not the columns will have equal width >+ * >+ */ >+ public GridLayout(int numColumns, boolean makeColumnsEqualWidth) { >+ this.numColumns = numColumns; >+ this.makeColumnsEqualWidth = makeColumnsEqualWidth; >+ } >+ >+ /** >+ * @param child >+ * @param wHint >+ * @param hHint >+ * @return >+ */ >+ protected Dimension getChildSize(IFigure child, int wHint, int hHint) { >+ return child.getPreferredSize(wHint, hHint); >+ } >+ >+ GridLayoutData getData(IFigure[][] grid, int row, int column, int rowCount, >+ int columnCount, boolean first) { >+ IFigure figure = grid[row][column]; >+ if (figure != null) { >+ GridLayoutData data = (GridLayoutData) getConstraint(figure); >+ int hSpan = Math.max(1, Math.min(data.horizontalSpan, columnCount)); >+ int vSpan = Math.max(1, data.verticalSpan); >+ int i = first ? row + vSpan - 1 : row - vSpan + 1; >+ int j = first ? column + hSpan - 1 : column - hSpan + 1; >+ if (0 <= i && i < rowCount) { >+ if (0 <= j && j < columnCount) { >+ if (figure == grid[i][j]) >+ return data; >+ } >+ } >+ } >+ return null; >+ } >+ >+ void initChildren(IFigure container) >+ { >+ List children = container.getChildren(); >+ for (int i = 0; i < children.size(); i++) { >+ IFigure child = (IFigure) children.get(i); >+ if (child.getLayoutManager()==null) >+ child.setLayoutManager(this); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.draw2d.AbstractLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, >+ * int, int) >+ */ >+ protected Dimension calculatePreferredSize(IFigure container, int wHint, >+ int hHint) { >+ Dimension size = layout(container, false, 0, 0, wHint, hHint, /* flushCache */ >+ true); >+ if (wHint != SWT.DEFAULT) >+ size.width = wHint; >+ if (hHint != SWT.DEFAULT) >+ size.height = hHint; >+ >+ return size; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure) >+ */ >+ public void layout(IFigure container) { >+ //initChildren( container); >+ Rectangle rect = container.getClientArea(); >+ layout(container, true, rect.x, rect.y, rect.width, rect.height, /* flushCache */ >+ true); >+ >+ } >+ >+ Dimension layout(IFigure container, boolean move, int x, int y, int width, >+ int height, boolean flushCache) { >+ if (numColumns < 1) >+ return new Dimension(marginWidth * 2, marginHeight * 2); >+ List children = container.getChildren(); >+ for (int i = 0; i < children.size(); i++) { >+ IFigure child = (IFigure) children.get(i); >+ >+ GridLayoutData data = (GridLayoutData) getConstraint(child); >+ if (data == null) >+ setConstraint(child, data = new GridLayoutData()); >+ if (flushCache) >+ data.flushCache(); >+ data.computeSize(child, flushCache); >+ } >+ >+ /* Build the grid */ >+ int row = 0, column = 0, rowCount = 0, columnCount = numColumns; >+ IFigure[][] grid = new IFigure[4][columnCount]; >+ for (int i = 0; i < children.size(); i++) { >+ IFigure child = (IFigure) children.get(i); >+ GridLayoutData data = (GridLayoutData) getConstraint(child); >+ int hSpan = Math.max(1, Math.min(data.horizontalSpan, columnCount)); >+ int vSpan = Math.max(1, data.verticalSpan); >+ while (true) { >+ int lastRow = row + vSpan; >+ if (lastRow >= grid.length) { >+ IFigure[][] newGrid = new IFigure[lastRow + 4][columnCount]; >+ System.arraycopy(grid, 0, newGrid, 0, grid.length); >+ grid = newGrid; >+ } >+ if (grid[row] == null) { >+ grid[row] = new IFigure[columnCount]; >+ } >+ while (column < columnCount && grid[row][column] != null) { >+ column++; >+ } >+ int endCount = column + hSpan; >+ if (endCount <= columnCount) { >+ int index = column; >+ while (index < endCount && grid[row][index] == null) { >+ index++; >+ } >+ if (index == endCount) >+ break; >+ column = index; >+ } >+ if (column + hSpan >= columnCount) { >+ column = 0; >+ row++; >+ } >+ } >+ for (int j = 0; j < vSpan; j++) { >+ if (grid[row + j] == null) { >+ grid[row + j] = new IFigure[columnCount]; >+ } >+ for (int k = 0; k < hSpan; k++) { >+ grid[row + j][column + k] = child; >+ } >+ } >+ rowCount = Math.max(rowCount, row + vSpan); >+ column += hSpan; >+ } >+ >+ /* Column widths */ >+ int availableWidth = width - horizontalSpacing * (columnCount - 1) >+ - marginWidth * 2; >+ int expandCount = 0; >+ int[] widths = new int[columnCount]; >+ int[] minWidths = new int[columnCount]; >+ boolean[] expandColumn = new boolean[columnCount]; >+ for (int j = 0; j < columnCount; j++) { >+ for (int i = 0; i < rowCount; i++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, columnCount, true); >+ if (data != null) { >+ int hSpan = Math.max(1, Math.min(data.horizontalSpan, >+ columnCount)); >+ if (hSpan == 1) { >+ int w = data.cacheWidth + data.horizontalIndent; >+ widths[j] = Math.max(widths[j], w); >+ if (data.grabExcessHorizontalSpace) { >+ if (!expandColumn[j]) >+ expandCount++; >+ expandColumn[j] = true; >+ } >+ if (data.widthHint != SWT.DEFAULT >+ || !data.grabExcessHorizontalSpace) { >+ minWidths[j] = Math.max(minWidths[j], w); >+ } >+ } >+ } >+ } >+ for (int i = 0; i < rowCount; i++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, columnCount, >+ false); >+ if (data != null) { >+ int hSpan = Math.max(1, Math.min(data.horizontalSpan, >+ columnCount)); >+ if (hSpan > 1) { >+ int spanWidth = 0, spanMinWidth = 0, spanExpandCount = 0; >+ for (int k = 0; k < hSpan; k++) { >+ spanWidth += widths[j - k]; >+ spanMinWidth += minWidths[j - k]; >+ if (expandColumn[j - k]) >+ spanExpandCount++; >+ } >+ if (data.grabExcessHorizontalSpace >+ && spanExpandCount == 0) { >+ expandCount++; >+ expandColumn[j] = true; >+ } >+ int w = data.cacheWidth + data.horizontalIndent >+ - spanWidth - (hSpan - 1) * horizontalSpacing; >+ if (w > 0) { >+ if (spanExpandCount == 0) { >+ widths[j] += w; >+ } else { >+ int delta = w / spanExpandCount; >+ int remainder = w % spanExpandCount, last = -1; >+ for (int k = 0; k < hSpan; k++) { >+ if (expandColumn[j - k]) { >+ widths[last = j - k] += delta; >+ } >+ } >+ if (last > -1) >+ widths[last] += remainder; >+ } >+ } >+ if (data.widthHint != SWT.DEFAULT >+ || !data.grabExcessHorizontalSpace) { >+ w = data.cacheWidth + data.horizontalIndent >+ - spanMinWidth - (hSpan - 1) >+ * horizontalSpacing; >+ if (w > 0) { >+ if (spanExpandCount == 0) { >+ minWidths[j] += w; >+ } else { >+ int delta = w / spanExpandCount; >+ int remainder = w % spanExpandCount, last = -1; >+ for (int k = 0; k < hSpan; k++) { >+ if (expandColumn[j - k]) { >+ minWidths[last = j - k] += delta; >+ } >+ } >+ if (last > -1) >+ minWidths[last] += remainder; >+ } >+ } >+ } >+ } >+ } >+ } >+ } >+ if (makeColumnsEqualWidth) { >+ int minColumnWidth = 0; >+ int columnWidth = 0; >+ for (int i = 0; i < columnCount; i++) { >+ minColumnWidth = Math.max(minColumnWidth, minWidths[i]); >+ columnWidth = Math.max(columnWidth, widths[i]); >+ } >+ columnWidth = width == SWT.DEFAULT || expandCount == 0 >+ ? columnWidth >+ : Math.max(minColumnWidth, availableWidth / columnCount); >+ for (int i = 0; i < columnCount; i++) { >+ expandColumn[i] = expandCount > 0; >+ widths[i] = columnWidth; >+ } >+ } else { >+ if (width != SWT.DEFAULT && expandCount > 0) { >+ int totalWidth = 0; >+ for (int i = 0; i < columnCount; i++) { >+ totalWidth += widths[i]; >+ } >+ int count = expandCount; >+ int delta = (availableWidth - totalWidth) / count; >+ int remainder = (availableWidth - totalWidth) % count; >+ int last = -1; >+ while (totalWidth != availableWidth) { >+ for (int j = 0; j < columnCount; j++) { >+ if (expandColumn[j]) { >+ if (widths[j] + delta > minWidths[j]) { >+ widths[last = j] = widths[j] + delta; >+ } else { >+ widths[j] = minWidths[j]; >+ expandColumn[j] = false; >+ count--; >+ } >+ } >+ } >+ if (last > -1) >+ widths[last] += remainder; >+ >+ for (int j = 0; j < columnCount; j++) { >+ for (int i = 0; i < rowCount; i++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, >+ columnCount, false); >+ if (data != null) { >+ int hSpan = Math.max(1, Math.min( >+ data.horizontalSpan, columnCount)); >+ if (hSpan > 1) { >+ if (data.widthHint != SWT.DEFAULT >+ || !data.grabExcessHorizontalSpace) { >+ int spanWidth = 0, spanExpandCount = 0; >+ for (int k = 0; k < hSpan; k++) { >+ spanWidth += widths[j - k]; >+ if (expandColumn[j - k]) >+ spanExpandCount++; >+ } >+ int w = data.cacheWidth >+ + data.horizontalIndent >+ - spanWidth - (hSpan - 1) >+ * horizontalSpacing; >+ if (w > 0) { >+ if (spanExpandCount == 0) { >+ widths[j] += w; >+ } else { >+ int delta2 = w >+ / spanExpandCount; >+ int remainder2 = w >+ % spanExpandCount, last2 = -1; >+ for (int k = 0; k < hSpan; k++) { >+ if (expandColumn[j - k]) { >+ widths[last2 = j - k] += delta2; >+ } >+ } >+ if (last2 > -1) >+ widths[last2] += remainder2; >+ } >+ } >+ } >+ } >+ } >+ } >+ } >+ if (count == 0) >+ break; >+ totalWidth = 0; >+ for (int i = 0; i < columnCount; i++) { >+ totalWidth += widths[i]; >+ } >+ delta = (availableWidth - totalWidth) / count; >+ remainder = (availableWidth - totalWidth) % count; >+ last = -1; >+ } >+ } >+ } >+ >+ /* Wrapping */ >+ GridLayoutData[] flush = null; >+ int flushLength = 0; >+ if (width != SWT.DEFAULT) { >+ for (int j = 0; j < columnCount; j++) { >+ for (int i = 0; i < rowCount; i++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, columnCount, >+ false); >+ if (data != null) { >+ if (data.heightHint == SWT.DEFAULT) { >+ IFigure child = grid[i][j]; >+ //TEMPORARY CODE >+ int hSpan = Math.max(1, Math.min( >+ data.horizontalSpan, columnCount)); >+ int currentWidth = 0; >+ for (int k = 0; k < hSpan; k++) { >+ currentWidth += widths[j - k]; >+ } >+ currentWidth += (hSpan - 1) * horizontalSpacing >+ - data.horizontalIndent; >+ if ((currentWidth != data.cacheWidth && data.horizontalAlignment == GridLayoutData.FILL) >+ || (data.cacheWidth > currentWidth)) { >+ int trim = 0; >+ /* >+ // *Note*: Left this in place from SWT >+ // GridLayout. Not sure if Draw2D Borders or >+ // Scrollbars 'trim' will need to be takeninto account. >+ >+ if (child instanceof Group) { >+ Group g =(Group)child; trim = g.getSize ().x - >+ g.getClientArea ().width; >+ } else if (child instanceof Scrollable) { >+ Rectangle rect = >+ ((Scrollable) child).computeTrim (0, 0, 0,0); >+ trim = rect.width; } >+ else { >+ trim = child.getBorderWidth () * 2; >+ } >+ */ >+ int oldWidthHint = data.widthHint; >+ data.widthHint = Math.max(0, currentWidth >+ - trim); >+ data.cacheWidth = data.cacheHeight = SWT.DEFAULT; >+ data.computeSize(child, false); >+ data.widthHint = oldWidthHint; >+ if (flush == null) >+ flush = new GridLayoutData[children.size()]; >+ flush[flushLength++] = data; >+ } >+ } >+ } >+ } >+ } >+ } >+ >+ /* Row heights */ >+ int availableHeight = height - verticalSpacing * (rowCount - 1) >+ - marginHeight * 2; >+ expandCount = 0; >+ int[] heights = new int[rowCount]; >+ int[] minHeights = new int[rowCount]; >+ boolean[] expandRow = new boolean[rowCount]; >+ for (int i = 0; i < rowCount; i++) { >+ for (int j = 0; j < columnCount; j++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, columnCount, true); >+ if (data != null) { >+ int vSpan = Math.max(1, Math.min(data.verticalSpan, >+ rowCount)); >+ if (vSpan == 1) { >+ int h = data.cacheHeight; // + data.verticalIndent; >+ heights[i] = Math.max(heights[i], h); >+ if (data.grabExcessVerticalSpace) { >+ if (!expandRow[i]) >+ expandCount++; >+ expandRow[i] = true; >+ } >+ if (data.heightHint != SWT.DEFAULT >+ || !data.grabExcessVerticalSpace) { >+ minHeights[i] = Math.max(minHeights[i], h); >+ } >+ } >+ } >+ } >+ for (int j = 0; j < columnCount; j++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, columnCount, >+ false); >+ if (data != null) { >+ int vSpan = Math.max(1, Math.min(data.verticalSpan, >+ rowCount)); >+ if (vSpan > 1) { >+ int spanHeight = 0, spanMinHeight = 0, spanExpandCount = 0; >+ for (int k = 0; k < vSpan; k++) { >+ spanHeight += heights[i - k]; >+ spanMinHeight += minHeights[i - k]; >+ if (expandRow[i - k]) >+ spanExpandCount++; >+ } >+ if (data.grabExcessVerticalSpace >+ && spanExpandCount == 0) { >+ expandCount++; >+ expandRow[i] = true; >+ } >+ int h = data.cacheHeight - spanHeight - (vSpan - 1) >+ * verticalSpacing; // + data.verticalalIndent >+ if (h > 0) { >+ if (spanExpandCount == 0) { >+ heights[i] += h; >+ } else { >+ int delta = h / spanExpandCount; >+ int remainder = h % spanExpandCount, last = -1; >+ for (int k = 0; k < vSpan; k++) { >+ if (expandRow[i - k]) { >+ heights[last = i - k] += delta; >+ } >+ } >+ if (last > -1) >+ heights[last] += remainder; >+ } >+ } >+ if (data.heightHint != SWT.DEFAULT >+ || !data.grabExcessVerticalSpace) { >+ h = data.cacheHeight - spanMinHeight - (vSpan - 1) >+ * verticalSpacing; // + data.verticalIndent >+ if (h > 0) { >+ if (spanExpandCount == 0) { >+ minHeights[i] += h; >+ } else { >+ int delta = h / spanExpandCount; >+ int remainder = h % spanExpandCount, last = -1; >+ for (int k = 0; k < vSpan; k++) { >+ if (expandRow[i - k]) { >+ minHeights[last = i - k] += delta; >+ } >+ } >+ if (last > -1) >+ minHeights[last] += remainder; >+ } >+ } >+ } >+ } >+ } >+ } >+ } >+ if (height != SWT.DEFAULT && expandCount > 0) { >+ int totalHeight = 0; >+ for (int i = 0; i < rowCount; i++) { >+ totalHeight += heights[i]; >+ } >+ int count = expandCount; >+ int delta = (availableHeight - totalHeight) / count; >+ int remainder = (availableHeight - totalHeight) % count; >+ int last = -1; >+ while (totalHeight != availableHeight) { >+ for (int i = 0; i < rowCount; i++) { >+ if (expandRow[i]) { >+ if (heights[i] + delta > minHeights[i]) { >+ heights[last = i] = heights[i] + delta; >+ } else { >+ heights[i] = minHeights[i]; >+ expandRow[i] = false; >+ count--; >+ } >+ } >+ } >+ if (last > -1) >+ heights[last] += remainder; >+ >+ for (int i = 0; i < rowCount; i++) { >+ for (int j = 0; j < columnCount; j++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, >+ columnCount, false); >+ if (data != null) { >+ int vSpan = Math.max(1, Math.min(data.verticalSpan, >+ rowCount)); >+ if (vSpan > 1) { >+ if (data.heightHint != SWT.DEFAULT >+ || !data.grabExcessVerticalSpace) { >+ int spanHeight = 0, spanExpandCount = 0; >+ for (int k = 0; k < vSpan; k++) { >+ spanHeight += heights[i - k]; >+ if (expandRow[i - k]) >+ spanExpandCount++; >+ } >+ int h = data.cacheHeight - spanHeight >+ - (vSpan - 1) * verticalSpacing; // + >+ // data.verticalIndent >+ if (h > 0) { >+ if (spanExpandCount == 0) { >+ heights[i] += h; >+ } else { >+ int delta2 = h / spanExpandCount; >+ int remainder2 = h >+ % spanExpandCount, last2 = -1; >+ for (int k = 0; k < vSpan; k++) { >+ if (expandRow[i - k]) { >+ heights[last2 = i - k] += delta2; >+ } >+ } >+ if (last2 > -1) >+ heights[last2] += remainder2; >+ } >+ } >+ } >+ } >+ } >+ } >+ } >+ if (count == 0) >+ break; >+ totalHeight = 0; >+ for (int i = 0; i < rowCount; i++) { >+ totalHeight += heights[i]; >+ } >+ delta = (availableHeight - totalHeight) / count; >+ remainder = (availableHeight - totalHeight) % count; >+ last = -1; >+ } >+ } >+ >+ /* Position the IFigures */ >+ if (move) { >+ int gridY = y + marginHeight; >+ for (int i = 0; i < rowCount; i++) { >+ int gridX = x + marginWidth; >+ for (int j = 0; j < columnCount; j++) { >+ GridLayoutData data = getData(grid, i, j, rowCount, columnCount, >+ true); >+ if (data != null) { >+ int hSpan = Math.max(1, Math.min(data.horizontalSpan, >+ columnCount)); >+ int vSpan = Math.max(1, data.verticalSpan); >+ int cellWidth = 0, cellHeight = 0; >+ for (int k = 0; k < hSpan; k++) { >+ cellWidth += widths[j + k]; >+ } >+ for (int k = 0; k < vSpan; k++) { >+ cellHeight += heights[i + k]; >+ } >+ cellWidth += horizontalSpacing * (hSpan - 1); >+ int childX = gridX + data.horizontalIndent; >+ int childWidth = Math.min(data.cacheWidth, cellWidth); >+ switch (data.horizontalAlignment) { >+ case GridLayoutData.CENTER : >+ childX = gridX >+ + Math.max(0, >+ (cellWidth - childWidth) / 2); >+ break; >+ case GridLayoutData.END : >+ childX = gridX >+ + Math.max(0, cellWidth - childWidth); >+ break; >+ case GridLayoutData.FILL : >+ childWidth = cellWidth - data.horizontalIndent; >+ break; >+ } >+ cellHeight += verticalSpacing * (vSpan - 1); >+ int childY = gridY; // + data.verticalIndent; >+ int childHeight = Math >+ .min(data.cacheHeight, cellHeight); >+ switch (data.verticalAlignment) { >+ case GridLayoutData.CENTER : >+ childY = gridY >+ + Math.max(0, >+ (cellHeight - childHeight) / 2); >+ break; >+ case GridLayoutData.END : >+ childY = gridY >+ + Math.max(0, cellHeight - childHeight); >+ break; >+ case GridLayoutData.FILL : >+ childHeight = cellHeight; // - >+ // data.verticalIndent; >+ break; >+ } >+ IFigure child = grid[i][j]; >+ if (child != null) { >+ // following param could be replaced by >+ // Rectangle.SINGLETON >+ child.setBounds(new Rectangle(childX, childY, >+ childWidth, childHeight)); >+ } >+ } >+ gridX += widths[j] + horizontalSpacing; >+ } >+ gridY += heights[i] + verticalSpacing; >+ } >+ } >+ >+ // clean up cache >+ for (int i = 0; i < flushLength; i++) { >+ flush[i].cacheWidth = flush[i].cacheHeight = -1; >+ } >+ >+ int totalDefaultWidth = 0; >+ int totalDefaultHeight = 0; >+ for (int i = 0; i < columnCount; i++) { >+ totalDefaultWidth += widths[i]; >+ } >+ for (int i = 0; i < rowCount; i++) { >+ totalDefaultHeight += heights[i]; >+ } >+ totalDefaultWidth += horizontalSpacing * (columnCount - 1) >+ + marginWidth * 2; >+ totalDefaultHeight += verticalSpacing * (rowCount - 1) + marginHeight >+ * 2; >+ return new Dimension(totalDefaultWidth, totalDefaultHeight); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.draw2d.LayoutManager#getConstraint(org.eclipse.draw2d.IFigure) >+ */ >+ public Object getConstraint(IFigure child) { >+ return constraints.get(child); >+ } >+ >+ /** >+ * Sets the layout constraint of the given figure. The constraints can only >+ * be of type {@link GridLayoutData}. >+ * >+ * @see LayoutManager#setConstraint(IFigure, Object) >+ */ >+ public void setConstraint(IFigure figure, Object newConstraint) { >+ super.setConstraint(figure, newConstraint); >+ if (newConstraint != null) >+ { >+ constraints.put(figure, newConstraint); >+ >+ } >+ } >+ >+} >Index: src/org/eclipse/gmf/internal/codegen/draw2d/GridLayoutData.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/codegen/draw2d/GridLayoutData.java >diff -N src/org/eclipse/gmf/internal/codegen/draw2d/GridLayoutData.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/codegen/draw2d/GridLayoutData.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,453 @@ >+package org.eclipse.gmf.internal.codegen.draw2d; >+ >+import org.eclipse.draw2d.IFigure; >+import org.eclipse.draw2d.geometry.Dimension; >+import org.eclipse.swt.SWT; >+ >+ >+/** >+ * <code>GridLayoutData</code> is the layout data object associated with >+ * <code>GridLayout</code>. To set a <code>GridLayoutData</code> object into a >+ * <code>Figure</code>, you use the <code>setConstraint()</code> method of >+ * <code>GridLayout</code> to map the <code>Figure</code> to its layout >+ * <code>GridLayoutData</code>. >+ * <p> >+ * There are two ways to create a <code>GridLayoutData</code> object with certain >+ * fields set. The first is to set the fields directly, like this: >+ * >+ * <pre> >+ * GridLayoutData gridData = new GridLayoutData(); >+ * gridData.horizontalAlignment = GridLayoutData.FILL; >+ * gridData.grabExcessHorizontalSpace = true; >+ * >+ * // associate the figure to the GridLayoutData object >+ * myGridlayout.setConstraint(myFigure, gridData); >+ * </pre> >+ * >+ * The second is to take advantage of convenience style bits defined by >+ * <code>GridLayoutData</code>: >+ * >+ * <pre> >+ * GridLayoutData gridData = new GridLayoutData(GridLayoutData.HORIZONTAL_ALIGN_FILL | GridLayoutData.GRAB_HORIZONTAL); >+ * </pre> >+ * >+ * </p> >+ * <p> >+ * NOTE: Do not reuse <code>GridLayoutData</code> objects. Every child in the parent >+ * <code>Figure</code> that is managed by the <code>GridLayout</code> must >+ * have a unique <code>GridLayoutData</code> object. If the layout data for a Grid >+ * member in a <code>GridLayout</code> is null at layout time, a unique >+ * <code>GridLayoutData</code> object is created for it. >+ * </p> >+ * >+ * [GMF]: NOTE: The set of the ALIGNMENT constants is changed in this class >+ * comparing to original version to match the set of constants in the generated >+ * code. E.g, <code>GridLayoutData.BEGINNING = SWT.BEGINNING - 1</code>. >+ * Thus, this implementation is NOT intended to use SWT.* constants for >+ * alignment. >+ * >+ * @see GridLayout >+ */ >+public final class GridLayoutData { >+ /** >+ * verticalAlignment specifies how figures will be positioned vertically >+ * within a cell. >+ * >+ * The default value is CENTER. >+ * >+ * Possible values are: >+ * >+ * <code>GridLayoutData.BEGINNING = SWT.BEGINNING - 1</code> (or >+ * <code>SWT.TOP - 1</code>): Position the figure at the top of the cell >+ * >+ * <code>GridLayoutData.CENTER = SWT.CENTER - 1</code>: Position the >+ * figure in the vertical center of the cell >+ * >+ * <code>GridLayoutData.END = SWT.END - 1</code> (or >+ * <code>SWT.BOTTOM - 1</code>): Position the figure at the bottom of the >+ * cell >+ * >+ * <code>GridLayoutData.FILL = SWT.FILL - 1</code>: Resize the figure to >+ * fill the cell vertically >+ */ >+ public int verticalAlignment = CENTER; >+ >+ /** >+ * horizontalAlignment specifies how figures will be positioned horizontally >+ * within a cell. >+ * >+ * The default value is BEGINNING. >+ * >+ * Possible values are: >+ * >+ * <code>GridLayoutData.BEGINNING = SWT.BEGINNING - 1</code> (or >+ * <code>SWT.TOP - 1</code>): Position the figure at the left of the cell >+ * >+ * <code>GridLayoutData.CENTER = SWT.CENTER - 1</code>: Position the >+ * figure in the horizontal center of the cell >+ * >+ * <code>GridLayoutData.END = SWT.END - 1</code> (or >+ * <code>SWT.BOTTOM - 1</code>): Position the figure at the right of the >+ * cell >+ * >+ * <code>GridLayoutData.FILL = SWT.FILL - 1</code>: : Resize the figure >+ * to fill the cell horizontally >+ */ >+ public int horizontalAlignment = BEGINNING; >+ >+ /** >+ * widthHint specifies a minimum width for the column. A value of >+ * SWT.DEFAULT indicates that no minimum width is specified. >+ * >+ * The default value is SWT.DEFAULT. >+ */ >+ public int widthHint = SWT.DEFAULT; >+ >+ /** >+ * heightHint specifies a minimum height for the row. A value of >+ * SWT.DEFAULT indicates that no minimum height is specified. >+ * >+ * The default value is SWT.DEFAULT. >+ */ >+ public int heightHint = SWT.DEFAULT; >+ >+ /** >+ * horizontalIndent specifies the number of pixels of indentation >+ * that will be placed along the left side of the cell. >+ * >+ * The default value is 0. >+ */ >+ public int horizontalIndent = 0; >+ >+ /** >+ * horizontalSpan specifies the number of column cells that the figure >+ * will take up. >+ * >+ * The default value is 1. >+ */ >+ public int horizontalSpan = 1; >+ >+ /** >+ * verticalSpan specifies the number of row cells that the figure >+ * will take up. >+ * >+ * The default value is 1. >+ */ >+ public int verticalSpan = 1; >+ >+ /** >+ * grabExcessHorizontalSpace specifies whether the cell will be made >+ * wide enough to fit the remaining horizontal space. >+ * >+ * The default value is false. >+ */ >+ public boolean grabExcessHorizontalSpace = false; >+ >+ /** >+ * grabExcessVerticalSpace specifies whether the cell will be made >+ * tall enough to fit the remaining vertical space. >+ * >+ * The default value is false. >+ */ >+ public boolean grabExcessVerticalSpace = false; >+ >+ /** >+ * Value for horizontalAlignment or verticalAlignment. >+ * Position the figure at the top or left of the cell. >+ */ >+ public static final int BEGINNING = 0; //SWT.BEGINNING - 1; >+ >+ /** >+ * Value for horizontalAlignment or verticalAlignment. >+ * Position the figure in the vertical or horizontal center of the cell >+ */ >+ public static final int CENTER = 1; >+ >+ /** >+ * Value for horizontalAlignment or verticalAlignment. >+ * Position the figure at the bottom or right of the cell >+ */ >+ public static final int END = 2; >+ >+ /** >+ * Value for horizontalAlignment or verticalAlignment. >+ * Resize the figure to fill the cell horizontally or vertically. >+ */ >+ public static final int FILL = 3; //SWT.FILL - 1; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code>. >+ * Position the figure at the top of the cell. >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, GridLayoutData.BEGINNING, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int VERTICAL_ALIGN_BEGINNING = 1 << 1; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to position the >+ * figure in the vertical center of the cell. >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, GridLayoutData.CENTER, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int VERTICAL_ALIGN_CENTER = 1 << 2; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to position the >+ * figure at the bottom of the cell. >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, GridLayoutData.END, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int VERTICAL_ALIGN_END = 1 << 3; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fill the cell vertically. >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, GridLayoutData.FILL, boolean, boolean)</code> >+ * instead >+ */ >+ public static final int VERTICAL_ALIGN_FILL = 1 << 4; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to position the >+ * figure at the left of the cell. >+ * Not recommended. Use >+ * <code>new GridLayoutData(GridLayoutData.BEGINNING, int, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int HORIZONTAL_ALIGN_BEGINNING = 1 << 5; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to position the >+ * figure in the horizontal center of the cell. >+ * Not recommended. Use >+ * <code>new GridLayoutData(GridLayoutData.CENTER, int, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int HORIZONTAL_ALIGN_CENTER = 1 << 6; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to position the >+ * figure at the right of the cell. >+ * Not recommended. Use >+ * <code>new GridLayoutData(GridLayoutData.END, int, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int HORIZONTAL_ALIGN_END = 1 << 7; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fill the cell horizontally. >+ * Not recommended. Use >+ * <code>new GridLayoutData(GridLayoutData.FILL, int, boolean, boolean)</code> >+ * instead. >+ */ >+ public static final int HORIZONTAL_ALIGN_FILL = 1 << 8; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fit the remaining horizontal space. >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, int, true, boolean)</code> >+ * instead. >+ */ >+ public static final int GRAB_HORIZONTAL = 1 << 9; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fit the remaining vertical space. >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, int, boolean, true)</code> >+ * instead. >+ */ >+ public static final int GRAB_VERTICAL = 1 << 10; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fill the cell vertically and to fit the remaining >+ * vertical space. >+ * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL >+ * Not recommended. Use >+ * <code>new GridLayoutData(int, GridLayoutData.FILL, boolean, true)</code> >+ * instead. >+ */ >+ public static final int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fill the cell horizontally and to fit the remaining >+ * horizontal space. >+ * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL >+ * Not recommended. Use >+ * <code>new GridLayoutData(GridLayoutData.FILL, int, true, boolean)</code> >+ * instead. >+ */ >+ public static final int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL; >+ >+ /** >+ * Style bit for <code>new GridLayoutData(int)</code> to resize the >+ * figure to fill the cell horizontally and vertically and >+ * to fit the remaining horizontal and vertical space. >+ * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL >+ * Not recommended. Use >+ * <code>new GridLayoutData(GridLayoutData.FILL, GridLayoutData.FILL, true, true)</code> >+ * instead. >+ */ >+ public static final int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL; >+ >+ int cacheWidth = -1, cacheHeight = -1; >+ int [][] cache = new int[2][4]; >+ int cacheIndex = -1; >+ >+/** >+ * Constructs a new instance of GridLayoutData using >+ * default values. >+ */ >+public GridLayoutData () { >+ super (); >+} >+ >+/** >+ * Constructs a new instance based on the GridLayoutData style. >+ * This constructor is not recommended. >+ * >+ * @param style the GridLayoutData style >+ */ >+public GridLayoutData (int style) { >+ super (); >+ if ((style & VERTICAL_ALIGN_BEGINNING) != 0) verticalAlignment = BEGINNING; >+ if ((style & VERTICAL_ALIGN_CENTER) != 0) verticalAlignment = CENTER; >+ if ((style & VERTICAL_ALIGN_FILL) != 0) verticalAlignment = FILL; >+ if ((style & VERTICAL_ALIGN_END) != 0) verticalAlignment = END; >+ if ((style & HORIZONTAL_ALIGN_BEGINNING) != 0) horizontalAlignment = BEGINNING; >+ if ((style & HORIZONTAL_ALIGN_CENTER) != 0) horizontalAlignment = CENTER; >+ if ((style & HORIZONTAL_ALIGN_FILL) != 0) horizontalAlignment = FILL; >+ if ((style & HORIZONTAL_ALIGN_END) != 0) horizontalAlignment = END; >+ grabExcessHorizontalSpace = (style & GRAB_HORIZONTAL) != 0; >+ grabExcessVerticalSpace = (style & GRAB_VERTICAL) != 0; >+} >+ >+/** >+ * Constructs a new instance of GridLayoutData according to the parameters. >+ * >+ * @param horizontalAlignment how figure will be positioned horizontally within a cell >+ * @param verticalAlignment how figure will be positioned vertically within a cell >+ * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space >+ * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space >+ * >+ */ >+public GridLayoutData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace) { >+ this (horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace, grabExcessVerticalSpace, 1, 1); >+} >+ >+/** >+ * Constructs a new instance of GridLayoutData according to the parameters. >+ * >+ * @param horizontalAlignment how figure will be positioned horizontally within a cell >+ * @param verticalAlignment how figure will be positioned vertically within a cell >+ * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space >+ * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space >+ * @param horizontalSpan the number of column cells that the figure will take up >+ * @param verticalSpan the number of row cells that the figure will take up >+ * >+ */ >+public GridLayoutData (int horizontalAlignment, int verticalAlignment, boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace, int horizontalSpan, int verticalSpan) { >+ super (); >+ this.horizontalAlignment = horizontalAlignment; >+ this.verticalAlignment = verticalAlignment; >+ this.grabExcessHorizontalSpace = grabExcessHorizontalSpace; >+ this.grabExcessVerticalSpace = grabExcessVerticalSpace; >+ this.horizontalSpan = horizontalSpan; >+ this.verticalSpan = verticalSpan; >+} >+ >+/** >+ * Constructs a new instance of GridLayoutData according to the parameters. >+ * A value of SWT.DEFAULT indicates that no minimum width or >+ * no minumum height is specified. >+ * >+ * @param width a minimum width for the column >+ * @param height a minimum height for the row >+ * >+ */ >+public GridLayoutData (int width, int height) { >+ super (); >+ this.widthHint = width; >+ this.heightHint = height; >+} >+ >+Dimension computeSize (IFigure figure, boolean flushCache) { >+ if (cacheWidth != -1 && cacheHeight != -1) { >+ return new Dimension (cacheWidth, cacheHeight); >+ } >+ for (int i = 0; i < cacheIndex + 1; i++) { >+ if (cache [i][0] == widthHint && cache [i][1] == heightHint) { >+ cacheWidth = cache [i][2]; >+ cacheHeight = cache [i][3]; >+ return new Dimension (cacheWidth, cacheHeight); >+ } >+ } >+ >+ Dimension size = figure.getPreferredSize(widthHint,heightHint); >+ if (widthHint!=-1) size.width = widthHint; >+ if (heightHint!=-1) size.height = heightHint; >+ >+ if (cacheIndex < cache.length - 1) cacheIndex++; >+ cache [cacheIndex][0] = widthHint; >+ cache [cacheIndex][1] = heightHint; >+ cacheWidth = cache [cacheIndex][2] = size.width; >+ cacheHeight = cache [cacheIndex][3] = size.height; >+ return size; >+} >+ >+ >+void flushCache () { >+ cacheWidth = cacheHeight = -1; >+ cacheIndex = -1; >+} >+ >+String getName () { >+ String string = getClass ().getName (); >+ int index = string.lastIndexOf ('.'); >+ if (index == -1) return string; >+ return string.substring (index + 1, string.length ()); >+} >+ >+public String toString () { >+ >+ String hAlign = ""; >+ switch (horizontalAlignment) { >+ case FILL: hAlign = "GridLayoutData.FILL"; break; >+ case BEGINNING: hAlign = "GridLayoutData.BEGINNING"; break; >+ case END: hAlign = "GridLayoutData.LEFT"; break; >+ case CENTER: hAlign = "GridLayoutData.CENTER"; break; >+ default: hAlign = "Undefined "+horizontalAlignment; break; >+ } >+ String vAlign = ""; >+ switch (verticalAlignment) { >+ case FILL: vAlign = "GridLayoutData.FILL"; break; >+ case BEGINNING: vAlign = "GridLayoutData.BEGINNING"; break; >+ case END: vAlign = "GridLayoutData.END"; break; >+ case CENTER: vAlign = "GridLayoutData.CENTER"; break; >+ default: vAlign = "Undefined "+verticalAlignment; break; >+ } >+ String string = getName()+" {"; >+ string += "horizontalAlignment="+hAlign+" "; >+ if (horizontalIndent != 0) string += "horizontalIndent="+horizontalIndent+" "; >+ if (horizontalSpan != 1) string += "horizontalSpan="+horizontalSpan+" "; >+ if (grabExcessHorizontalSpace) string += "grabExcessHorizontalSpace="+grabExcessHorizontalSpace+" "; >+ if (widthHint != SWT.DEFAULT) string += "widthHint="+widthHint+" "; >+ string += "verticalAlignment="+vAlign+" "; >+ if (verticalSpan != 1) string += "verticalSpan="+verticalSpan+" "; >+ if (grabExcessVerticalSpace) string += "grabExcessVerticalSpace="+grabExcessVerticalSpace+" "; >+ if (heightHint != SWT.DEFAULT) string += "heightHint="+heightHint+" "; >+ string = string.trim(); >+ string += "}"; >+ return string; >+ >+} >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 133279
:
38601
|
45523
| 45524 |
64018