diff dwt/custom/TableTreeEditor.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 63a09873578e
line wrap: on
line diff
--- a/dwt/custom/TableTreeEditor.d	Tue Oct 07 14:41:31 2008 +0200
+++ b/dwt/custom/TableTreeEditor.d	Tue Oct 07 16:29:55 2008 +0200
@@ -7,20 +7,35 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
  *******************************************************************************/
-module dwt.custom;
+module dwt.custom.TableTreeEditor;
+
+import dwt.dwthelper.utils;
 
 
-import dwt.*;
-import dwt.graphics.*;
-import dwt.widgets.*;
-import dwt.events.*;
+import dwt.DWT;
+import dwt.events.ControlEvent;
+import dwt.events.ControlListener;
+import dwt.events.TreeEvent;
+import dwt.events.TreeListener;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Control;
+import dwt.widgets.Table;
+import dwt.widgets.TableColumn;
+import dwt.custom.ControlEditor;
+import dwt.custom.TableTree;
+import dwt.custom.TableTreeItem;
+
+import dwt.dwthelper.Runnable;
+
 /**
 *
 * A TableTreeEditor is a manager for a Control that appears above a cell in a TableTree
 * and tracks with the moving and resizing of that cell.  It can be used to display a
-* text widget above a cell in a TableTree so that the user can edit the contents of 
-* that cell.  It can also be used to display a button that can launch a dialog for 
+* text widget above a cell in a TableTree so that the user can edit the contents of
+* that cell.  It can also be used to display a button that can launch a dialog for
 * modifying the contents of the associated cell.
 *
 * <p> Here is an example of using a TableTreeEditor:
@@ -41,7 +56,7 @@
 *   }
 *   column1.setWidth(100);
 *   column2.pack();
-*   
+*
 *   final TableTreeEditor editor = new TableTreeEditor(tableTree);
 *   //The editor must have the same size as the cell and must
 *   //not be any smaller than 50 pixels.
@@ -50,23 +65,23 @@
 *   editor.minimumWidth = 50;
 *   // editing the second column
 *   final int EDITABLECOLUMN = 1;
-*   
+*
 *   tableTree.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
-*           TableTreeItem item = cast(TableTreeItem)e.item;
+*           TableTreeItem item = (TableTreeItem)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());
 *               }
 *           });
@@ -76,11 +91,13 @@
 *       }
 *   });
 * </pre></code>
-* 
+*
 * @deprecated As of 3.1 use TreeEditor with Tree, TreeItem and TreeColumn
 */
 public class TableTreeEditor : ControlEditor {
 
+    alias ControlEditor.setEditor setEditor;
+
     TableTree tableTree;
     TableTreeItem item;
     int column = -1;
@@ -96,15 +113,18 @@
     super(tableTree.getTable());
     this.tableTree = tableTree;
 
-    treeListener = new TreeListener () {
-        final Runnable runnable = new Runnable() {
-            public void run() {
-                if (editor is null || editor.isDisposed()) return;
-                if (TableTreeEditor.this.tableTree.isDisposed()) return;
-                layout();
-                editor.setVisible(true);
-            }
-        };
+    treeListener = new class() TreeListener  {
+        Runnable runnable;
+        this() {
+            runnable = new class() Runnable {
+                public void run() {
+                    if (editor is null || editor.isDisposed()) return;
+                    if (this.outer.outer.tableTree.isDisposed()) return;
+                    layout();
+                    editor.setVisible(true);
+                }
+            };
+        }
         public void treeCollapsed(TreeEvent e) {
             if (editor is null || editor.isDisposed ()) return;
             editor.setVisible(false);
@@ -117,8 +137,8 @@
         }
     };
     tableTree.addTreeListener(treeListener);
-    
-    columnListener = new ControlListener() {
+
+    columnListener = new class() ControlListener {
         public void controlMoved(ControlEvent e){
             layout ();
         }
@@ -126,11 +146,12 @@
             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() || item.tableItem is null) return new Rectangle(0, 0, 0, 0);
     Rectangle cell = item.getBounds(column);
     Rectangle area = tableTree.getClientArea();
@@ -144,11 +165,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) {
@@ -156,7 +177,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) {
@@ -170,7 +191,7 @@
  * 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 () {
+public override void dispose () {
     if (tableTree !is null && !tableTree.isDisposed()) {
         Table table = tableTree.getTable();
         if (table !is null && !table.isDisposed()) {
@@ -220,14 +241,14 @@
         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);
     layout();
 }
-public void setItem (TableTreeItem item) {  
+public void setItem (TableTreeItem item) {
     this.item = item;
     layout();
 }
@@ -237,17 +258,18 @@
 *
 * <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
 */
+alias ControlEditor.setEditor setEditor;
 public void setEditor (Control editor, TableTreeItem item, int column) {
     setItem(item);
     setColumn(column);
     setEditor(editor);
 }
-public void layout () {
+public override void layout () {
     if (tableTree is null || tableTree.isDisposed()) return;
     if (item is null || item.isDisposed()) return;
     Table table = tableTree.getTable();
@@ -256,4 +278,5 @@
     if (columnCount > 0 && (column < 0 || column >= columnCount)) return;
     super.layout();
 }
+
 }