diff options
author | Veronika Irvine <veronika> | 2003-06-20 20:48:14 +0000 |
---|---|---|
committer | Veronika Irvine <veronika> | 2003-06-20 20:48:14 +0000 |
commit | 32f745f166ca3f555ac0c5b5405a19c39b921edc (patch) | |
tree | 50e4c8e360a03d00523783fa14c0216d9477b848 | |
parent | 76c26a9d62b45485432ac316c623d26313f2dab3 (diff) | |
download | eclipse.platform.swt-32f745f166ca3f555ac0c5b5405a19c39b921edc.tar.gz eclipse.platform.swt-32f745f166ca3f555ac0c5b5405a19c39b921edc.tar.xz eclipse.platform.swt-32f745f166ca3f555ac0c5b5405a19c39b921edc.zip |
25356
3 files changed, 99 insertions, 52 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableEditor.java index 7485ee4222..a53281cdb8 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableEditor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableEditor.java @@ -12,6 +12,7 @@ package org.eclipse.swt.custom; import org.eclipse.swt.*; +import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; @@ -58,11 +59,10 @@ import org.eclipse.swt.widgets.*; * </pre></code> */ public class TableEditor extends ControlEditor { - Table table; TableItem item; int column = -1; - Listener columnListener; + ControlListener columnListener; /** * Creates a TableEditor for the specified Table. * @@ -73,29 +73,37 @@ public TableEditor (Table table) { super(table); this.table = table; - columnListener = new Listener() { - public void handleEvent(Event e) { + columnListener = new ControlListener() { + public void controlMoved(ControlEvent e){ + resize (); + } + public void controlResized(ControlEvent e){ resize (); } }; - + + // To be consistent with older versions of SWT, grabVertical defaults to true + grabVertical = true; } Rectangle computeBounds () { if (item == null || column == -1 || item.isDisposed()) return new Rectangle(0, 0, 0, 0); - Rectangle cell = item.getBounds(column); - Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, cell.height); Rectangle area = table.getClientArea(); if (cell.x < area.x + area.width) { if (cell.x + cell.width > area.x + area.width) { - cell.width = area.width - cell.x; + cell.width = area.x + area.width - cell.x; } } - - if (grabHorizontal){ + Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight); + + if (grabHorizontal) { editorRect.width = Math.max(cell.width, minimumWidth); } + if (grabVertical) { + editorRect.height = Math.max(cell.height, minimumHeight); + } + if (horizontalAlignment == SWT.RIGHT) { editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment == SWT.LEFT) { @@ -104,6 +112,13 @@ Rectangle computeBounds () { editorRect.x += (cell.width - editorRect.width)/2; } + if (verticalAlignment == SWT.BOTTOM) { + editorRect.y += cell.height - editorRect.height; + } else if (verticalAlignment == SWT.TOP) { + // do nothing - cell.y is the right answer + } else { // default is CENTER + editorRect.y += (cell.height - editorRect.height)/2; + } return editorRect; } /** @@ -111,11 +126,9 @@ Rectangle computeBounds () { * Table and the editor Control are <b>not</b> disposed. */ public void dispose () { - if (this.column > -1 && this.column < table.getColumnCount()){ TableColumn tableColumn = table.getColumn(this.column); - tableColumn.removeListener(SWT.Resize, columnListener); - tableColumn.removeListener(SWT.Move, columnListener); + tableColumn.removeControlListener(columnListener); } columnListener = null; table = null; @@ -141,7 +154,6 @@ public TableItem getItem () { return item; } public void setColumn(int column) { - int columnCount = table.getColumnCount(); // Separately handle the case where the table has no TableColumns. // In this situation, there is a single default column. @@ -150,11 +162,9 @@ public void setColumn(int column) { resize(); return; } - if (this.column > -1 && this.column < columnCount){ TableColumn tableColumn = table.getColumn(this.column); - tableColumn.removeListener(SWT.Resize, columnListener); - tableColumn.removeListener(SWT.Move, columnListener); + tableColumn.removeControlListener(columnListener); this.column = -1; } @@ -162,8 +172,7 @@ public void setColumn(int column) { this.column = column; TableColumn tableColumn = table.getColumn(this.column); - tableColumn.addListener(SWT.Resize, columnListener); - tableColumn.addListener(SWT.Move, columnListener); + tableColumn.addControlListener(columnListener); resize(); } public void setItem (TableItem item) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeEditor.java index d0e27615b7..a1ce5624c9 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeEditor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TableTreeEditor.java @@ -126,23 +126,29 @@ public TableTreeEditor (TableTree tableTree) { resize (); } }; - + + // To be consistent with older versions of SWT, grabVertical defaults to true + grabVertical = true; } Rectangle computeBounds () { if (item == null || column == -1 || item.isDisposed() || item.tableItem == null) return new Rectangle(0, 0, 0, 0); Rectangle cell = item.getBounds(column); - Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, cell.height); Rectangle area = tableTree.getClientArea(); if (cell.x < area.x + area.width) { if (cell.x + cell.width > area.x + area.width) { - cell.width = area.width - cell.x; + cell.width = area.x + area.width - cell.x; } } - - if (grabHorizontal){ + Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight); + + if (grabHorizontal) { editorRect.width = Math.max(cell.width, minimumWidth); } + if (grabVertical) { + editorRect.height = Math.max(cell.height, minimumHeight); + } + if (horizontalAlignment == SWT.RIGHT) { editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment == SWT.LEFT) { @@ -151,14 +157,20 @@ Rectangle computeBounds () { editorRect.x += (cell.width - editorRect.width)/2; } + if (verticalAlignment == SWT.BOTTOM) { + editorRect.y += cell.height - editorRect.height; + } else if (verticalAlignment == SWT.TOP) { + // do nothing - cell.y is the right answer + } else { // default is CENTER + editorRect.y += (cell.height - editorRect.height)/2; + } return editorRect; } /** - * Removes all associations between the TableEditor and the cell in the table. The - * Table and the editor Control are <b>not</b> disposed. + * Removes all associations between the TableTreeEditor and the cell in the table tree. The + * TableTree and the editor Control are <b>not</b> disposed. */ public void dispose () { - if (treeListener != null) tableTree.removeTreeListener(treeListener); treeListener = null; @@ -167,7 +179,6 @@ public void dispose () { TableColumn tableColumn = table.getColumn(this.column); tableColumn.removeControlListener(columnListener); } - tableTree = null; item = null; column = -1; @@ -182,9 +193,25 @@ public void dispose () { public int getColumn () { return column; } +/** +* Returns the TableTreeItem for the row of the cell being tracked by this editor. +* +* @return the TableTreeItem for the row of the cell being tracked by this editor +*/ +public TableTreeItem getItem () { + return item; +} public void setColumn(int column) { Table table = tableTree.getTable(); - if (this.column > -1 && this.column < table.getColumnCount()){ + int columnCount = table.getColumnCount(); + // Separately handle the case where the table has no TableColumns. + // In this situation, there is a single default column. + if (columnCount == 0) { + this.column = (column == 0) ? 0 : -1; + resize(); + return; + } + if (this.column > -1 && this.column < columnCount){ TableColumn tableColumn = table.getColumn(this.column); tableColumn.removeControlListener(columnListener); this.column = -1; @@ -195,17 +222,8 @@ public void setColumn(int column) { this.column = column; TableColumn tableColumn = table.getColumn(this.column); tableColumn.addControlListener(columnListener); - resize(); } -/** -* Returns the TableItem for the row of the cell being tracked by this editor. -* -* @return the TableItem for the row of the cell being tracked by this editor -*/ -public TableTreeItem getItem () { - return item; -} public void setItem (TableTreeItem item) { this.item = item; resize(); @@ -224,13 +242,15 @@ public void setItem (TableTreeItem item) { public void setEditor (Control editor, TableTreeItem item, int column) { setItem(item); setColumn(column); - super.setEditor(editor); + setEditor(editor); } void resize () { if (tableTree.isDisposed()) return; if (item == null || item.isDisposed()) return; Table table = tableTree.getTable(); - if (column < 0 || column >= table.getColumnCount()) return; + int columnCount = table.getColumnCount(); + if (columnCount == 0 && column != 0) return; + if (columnCount > 0 && (column < 0 || column >= columnCount)) return; super.resize(); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java index 8d1c16b0be..bf40e13631 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/TreeEditor.java @@ -69,12 +69,13 @@ public class TreeEditor extends ControlEditor { public TreeEditor (Tree tree) { super(tree); this.tree = tree; - treeListener = new TreeAdapter () { + + treeListener = new TreeListener () { final Runnable runnable = new Runnable() { public void run() { if (TreeEditor.this.tree.isDisposed() || editor == null) return; resize(); - if (editor == null || editor.isDisposed ()) return; + if (editor == null || editor.isDisposed()) return; editor.setVisible(true); } }; @@ -92,10 +93,12 @@ public TreeEditor (Tree tree) { } }; tree.addTreeListener(treeListener); + + // To be consistent with older versions of SWT, grabVertical defaults to true + grabVertical = true; } Rectangle computeBounds () { if (item == null || item.isDisposed()) return new Rectangle(0, 0, 0, 0); - Rectangle cell = item.getBounds(); Rectangle area = tree.getClientArea(); if (cell.x < area.x + area.width) { @@ -103,24 +106,40 @@ Rectangle computeBounds () { cell.width = area.x + area.width - cell.x; } } - Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, cell.height); - + Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight); + if (grabHorizontal) { - editorRect.width = Math.max(area.x + area.width - cell.x, minimumWidth); + // Bounds of tree item only include the text area - stretch out to include + // entire client area + cell.width = area.x + area.width - cell.x; + editorRect.width = Math.max(cell.width, minimumWidth); + } + + if (grabVertical) { + editorRect.height = Math.max(cell.height, minimumHeight); } if (horizontalAlignment == SWT.RIGHT) { - editorRect.x = Math.max(cell.x, cell.x + cell.width - editorRect.width); + editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment == SWT.LEFT) { // do nothing - cell.x is the right answer } else { // default is CENTER - editorRect.x = Math.max(cell.x, cell.x + (cell.width - editorRect.width)/2); + editorRect.x += (cell.width - editorRect.width)/2; } + // don't let the editor overlap with the +/- of the tree + editorRect.x = Math.max(cell.x, editorRect.x); + if (verticalAlignment == SWT.BOTTOM) { + editorRect.y += cell.height - editorRect.height; + } else if (verticalAlignment == SWT.TOP) { + // do nothing - cell.y is the right answer + } else { // default is CENTER + editorRect.y += (cell.height - editorRect.height)/2; + } return editorRect; } /** - * Removes all associations between the TreeEditor and the cell in the tree. The + * Removes all associations between the TreeEditor and the row in the tree. The * tree and the editor Control are <b>not</b> disposed. */ public void dispose () { @@ -155,10 +174,9 @@ public void setItem (TreeItem item) { * @param column the zero based index of the column of the cell being tracked by this editor */ public void setEditor (Control editor, TreeItem item) { - setItem (item); - super.setEditor (editor); + setItem(item); + setEditor(editor); } - void resize () { if (tree.isDisposed()) return; if (item == null || item.isDisposed()) return; |