Mercurial > projects > dwt-mac
diff dwt/custom/TableEditor.d @ 41:6337764516f1
Sync dwt/custom with dwt-linux (took copy of complete folder)
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 16:29:55 +0200 |
parents | e831403a80a9 |
children | 07399639c0c8 |
line wrap: on
line diff
--- a/dwt/custom/TableEditor.d Tue Oct 07 14:41:31 2008 +0200 +++ b/dwt/custom/TableEditor.d Tue Oct 07 16:29:55 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,14 +7,26 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> *******************************************************************************/ -module dwt.custom; +module dwt.custom.TableEditor; + +import dwt.dwthelper.utils; + -import dwt.*; -import dwt.events.*; -import dwt.graphics.*; -import dwt.widgets.*; +import dwt.DWT; +import dwt.events.ControlEvent; +import dwt.events.ControlListener; +import dwt.graphics.Rectangle; +import dwt.widgets.Control; +import dwt.widgets.Display; +import dwt.widgets.Table; +import dwt.widgets.TableColumn; +import dwt.widgets.TableItem; +import dwt.custom.ControlEditor; +import dwt.dwthelper.Runnable; /** * @@ -34,7 +46,7 @@ * } * column1.pack(); * column2.pack(); -* +* * final TableEditor editor = new TableEditor(table); * //The editor must have the same size as the cell and must * //not be any smaller than 50 pixels. @@ -43,23 +55,23 @@ * editor.minimumWidth = 50; * // editing the second column * final int EDITABLECOLUMN = 1; -* +* * table.addSelectionListener(new SelectionAdapter() { * public void widgetSelected(SelectionEvent e) { * // Clean up any previous editor control * Control oldEditor = editor.getEditor(); * if (oldEditor !is null) oldEditor.dispose(); -* +* * // Identify the selected row -* TableItem item = cast(TableItem)e.item; +* TableItem item = (TableItem)e.item; * if (item is null) return; -* +* * // The control that will be the editor must be a child of the Table * Text newEditor = new Text(table, DWT.NONE); * newEditor.setText(item.getText(EDITABLECOLUMN)); * newEditor.addModifyListener(new ModifyListener() { * public void modifyText(ModifyEvent e) { -* Text text = cast(Text)editor.getEditor(); +* Text text = (Text)editor.getEditor(); * editor.getItem().setText(EDITABLECOLUMN, text.getText()); * } * }); @@ -69,6 +81,9 @@ * } * }); * </pre></code> +* +* @see <a href="http://www.eclipse.org/swt/snippets/#tableeditor">TableEditor snippets</a> +* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class TableEditor : ControlEditor { Table table; @@ -86,8 +101,8 @@ public this (Table table) { super(table); this.table = table; - - columnListener = new ControlListener() { + + columnListener = new class() ControlListener { public void controlMoved(ControlEvent e){ layout (); } @@ -95,16 +110,16 @@ layout (); } }; - timer = new Runnable () { + timer = new class() Runnable { public void run() { layout (); } }; - + // To be consistent with older versions of DWT, grabVertical defaults to true grabVertical = true; } -Rectangle computeBounds () { +override Rectangle computeBounds () { if (item is null || column is -1 || item.isDisposed()) return new Rectangle(0, 0, 0, 0); Rectangle cell = item.getBounds(column); Rectangle rect = item.getImageBounds(column); @@ -121,11 +136,11 @@ if (grabHorizontal) { editorRect.width = Math.max(cell.width, minimumWidth); } - + if (grabVertical) { editorRect.height = Math.max(cell.height, minimumHeight); } - + if (horizontalAlignment is DWT.RIGHT) { editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment is DWT.LEFT) { @@ -133,7 +148,7 @@ } else { // default is CENTER editorRect.x += (cell.width - editorRect.width)/2; } - + if (verticalAlignment is DWT.BOTTOM) { editorRect.y += cell.height - editorRect.height; } else if (verticalAlignment is DWT.TOP) { @@ -147,7 +162,7 @@ * Removes all associations between the TableEditor and the cell in the table. The * Table and the editor Control are <b>not</b> disposed. */ -public void dispose () { +public override void dispose () { if (table !is null && !table.isDisposed()) { if (this.column > -1 && this.column < table.getColumnCount()){ TableColumn tableColumn = table.getColumn(this.column); @@ -193,8 +208,8 @@ } /** * Sets the zero based index of the column of the cell being tracked by this editor. -* -* @param column the zero based index of the column of the cell being tracked by this editor +* +* @param column the zero based index of the column of the cell being tracked by this editor */ public void setColumn(int column) { int columnCount = table.getColumnCount(); @@ -211,18 +226,23 @@ this.column = -1; } - if (column < 0 || column >= table.getColumnCount()) return; - + if (column < 0 || column >= table.getColumnCount()) return; + this.column = column; TableColumn tableColumn = table.getColumn(this.column); tableColumn.addControlListener(columnListener); resize(); } -public void setItem (TableItem item) { +/** +* Specifies the <code>TableItem</code> that is to be edited. +* +* @param item the item to be edited +*/ +public void setItem (TableItem item) { this.item = item; resize(); } -public void setEditor (Control editor) { +public override void setEditor (Control editor) { super.setEditor(editor); resize(); } @@ -231,7 +251,7 @@ * * <p>Note: The Control provided as the editor <b>must</b> be created with its parent being the Table control * specified in the TableEditor constructor. -* +* * @param editor the Control that is displayed above the cell being edited * @param item the TableItem for the row of the cell being tracked by this editor * @param column the zero based index of the column of the cell being tracked by this editor @@ -241,7 +261,7 @@ setColumn(column); setEditor(editor); } -public void layout () { +public override void layout () { if (table is null || table.isDisposed()) return; if (item is null || item.isDisposed()) return; int columnCount = table.getColumnCount();