Mercurial > projects > dwt-linux
changeset 139:35300367f4d4
ControlExample some more tabs
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 21 Jan 2008 22:25:26 +0100 |
parents | 31981a851d5b |
children | c3880d67f906 |
files | dwt/graphics/RGB.d dwt/widgets/Text.d dwtexamples/controlexample/AlignableTab.d dwtexamples/controlexample/CComboTab.d dwtexamples/controlexample/CanvasTab.d dwtexamples/controlexample/ComboTab.d dwtexamples/controlexample/ControlExample.d dwtexamples/controlexample/CoolBarTab.d dwtexamples/controlexample/DialogTab.d dwtexamples/controlexample/Tab.d |
diffstat | 10 files changed, 293 insertions(+), 180 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/graphics/RGB.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwt/graphics/RGB.d Mon Jan 21 22:25:26 2008 +0100 @@ -224,7 +224,7 @@ * @return a String representation of the <code>RGB</code> */ public override char[] toString() { - return Format( "RGB {}, {}, {}}", red, green, blue ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return Format( "RGB {{{}, {}, {}}", red, green, blue ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } }
--- a/dwt/widgets/Text.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwt/widgets/Text.d Mon Jan 21 22:25:26 2008 +0100 @@ -329,6 +329,7 @@ } } +alias Scrollable.computeSize computeSize; override public Point computeSize (int wHint, int hHint, bool changed) { checkWidget (); if (wHint !is DWT.DEFAULT && wHint < 0) wHint = 0;
--- a/dwtexamples/controlexample/AlignableTab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/AlignableTab.d Mon Jan 21 22:25:26 2008 +0100 @@ -24,7 +24,7 @@ import dwt.widgets.Group; import dwt.widgets.Widget; -import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.Tab; import dwtexamples.controlexample.ControlExample; /**
--- a/dwtexamples/controlexample/CComboTab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/CComboTab.d Mon Jan 21 22:25:26 2008 +0100 @@ -20,6 +20,9 @@ import dwt.widgets.Group; import dwt.widgets.Widget; +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + class CComboTab : Tab { /* Example widgets and groups that contain them */ @@ -29,7 +32,7 @@ /* Style widgets added to the "Style" group */ Button flatButton, readOnlyButton; - static String [] ListData = {ControlExample.getResourceString("ListData1_0"), + static char[] [] ListData = {ControlExample.getResourceString("ListData1_0"), ControlExample.getResourceString("ListData1_1"), ControlExample.getResourceString("ListData1_2"), ControlExample.getResourceString("ListData1_3"), @@ -42,7 +45,7 @@ /** * Creates the Tab within a given instance of ControlExample. */ - CComboTab(ControlExample instance) { + this(ControlExample instance) { super(instance); } @@ -97,21 +100,21 @@ * Gets the "Example" widget children. */ Widget [] getExampleWidgets () { - return new Widget [] {combo1}; + return [cast(Widget) combo1]; } /** * Returns a list of set/get API method names (without the set/get prefix) * that can be used to set/get values in the example control(s). */ - String[] getMethodNames() { - return new String[] {"Editable", "Items", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"}; + char[][] getMethodNames() { + return ["Editable", "Items", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"]; } /** * Gets the text for the tab folder item. */ - String getTabText () { + char[] getTabText () { return "CCombo"; }
--- a/dwtexamples/controlexample/CanvasTab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/CanvasTab.d Mon Jan 21 22:25:26 2008 +0100 @@ -35,8 +35,11 @@ import dwt.widgets.TabFolder; import dwt.widgets.Widget; +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + class CanvasTab : Tab { - static final int colors [] = { + static const int colors [] = [ DWT.COLOR_RED, DWT.COLOR_GREEN, DWT.COLOR_BLUE, @@ -49,8 +52,8 @@ DWT.COLOR_DARK_MAGENTA, DWT.COLOR_DARK_YELLOW, DWT.COLOR_DARK_CYAN - }; - static final String canvasString = "Canvas"; //$NON-NLS-1$ + ]; + static final char[] canvasString = "Canvas"; //$NON-NLS-1$ /* Example widgets and groups that contain them */ Canvas canvas; @@ -70,7 +73,7 @@ /** * Creates the Tab within a given instance of ControlExample. */ - CanvasTab(ControlExample instance) { + this(ControlExample instance) { super(instance); } @@ -87,7 +90,7 @@ fillDamageButton.setText (ControlExample.getResourceString("FillDamage")); /* Add the listeners */ - caretButton.addSelectionListener (new SelectionAdapter () { + caretButton.addSelectionListener (new class() SelectionAdapter { public void widgetSelected (SelectionEvent event) { setCaret (); } @@ -126,7 +129,7 @@ /* Create the example widgets */ paintCount = 0; cx = 0; cy = 0; canvas = new Canvas (canvasGroup, style); - canvas.addPaintListener(new PaintListener () { + canvas.addPaintListener(new class() PaintListener { public void paintControl(PaintEvent e) { paintCount++; GC gc = e.gc; @@ -142,7 +145,7 @@ gc.drawString(canvasString, cx + (size.x - extent.x) / 2, cy - extent.y + (size.y - 10) / 2, true); } }); - canvas.addControlListener(new ControlAdapter() { + canvas.addControlListener(new class() ControlAdapter { public void controlResized(ControlEvent event) { Point size = canvas.getSize (); maxX = size.x * 3 / 2; maxY = size.y * 3 / 2; @@ -152,18 +155,18 @@ ScrollBar bar = canvas.getHorizontalBar(); if (bar !is null) { hookListeners (bar); - bar.addSelectionListener(new SelectionAdapter() { + bar.addSelectionListener(new class() SelectionAdapter { public void widgetSelected(SelectionEvent event) { - scrollHorizontal ((ScrollBar)event.widget); + scrollHorizontal (cast(ScrollBar)event.widget); } }); } bar = canvas.getVerticalBar(); if (bar !is null) { hookListeners (bar); - bar.addSelectionListener(new SelectionAdapter() { + bar.addSelectionListener(new class() SelectionAdapter { public void widgetSelected(SelectionEvent event) { - scrollVertical ((ScrollBar)event.widget); + scrollVertical (cast(ScrollBar)event.widget); } }); } @@ -211,7 +214,7 @@ * its preferred size, and then resizes the shell, we * recalculate the preferred size correctly. */ - tabFolderPage.addControlListener(new ControlAdapter() { + tabFolderPage.addControlListener(new class() ControlAdapter { public void controlResized(ControlEvent e) { setExampleWidgetSize (); } @@ -224,21 +227,21 @@ * Gets the "Example" widget children. */ Widget [] getExampleWidgets () { - return new Widget [] {canvas}; + return [ cast(Widget) canvas ]; } /** * Returns a list of set/get API method names (without the set/get prefix) * that can be used to set/get values in the example control(s). */ - String[] getMethodNames() { - return new String[] {"ToolTipText"}; + char[][] getMethodNames() { + return ["ToolTipText"]; } /** * Gets the text for the tab folder item. */ - String getTabText () { + char[] getTabText () { return "Canvas"; }
--- a/dwtexamples/controlexample/ComboTab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/ComboTab.d Mon Jan 21 22:25:26 2008 +0100 @@ -1,4 +1,4 @@ -/******************************************************************************* +/******************************************************************************* * Copyright (c) 2000, 2007 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 @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package dwtexamples.controlexample; +module dwtexamples.controlexample.ComboTab; @@ -24,56 +24,62 @@ import dwt.widgets.TabFolder; import dwt.widgets.Widget; -class ComboTab extends Tab { +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; + +class ComboTab : Tab { /* Example widgets and groups that contain them */ Combo combo1; Group comboGroup; - + /* Style widgets added to the "Style" group */ Button dropDownButton, readOnlyButton, simpleButton; - - static String [] ListData = {ControlExample.getResourceString("ListData0_0"), - ControlExample.getResourceString("ListData0_1"), - ControlExample.getResourceString("ListData0_2"), - ControlExample.getResourceString("ListData0_3"), - ControlExample.getResourceString("ListData0_4"), - ControlExample.getResourceString("ListData0_5"), - ControlExample.getResourceString("ListData0_6"), - ControlExample.getResourceString("ListData0_7"), - ControlExample.getResourceString("ListData0_8")}; + + static char[] [] ListData; /** * Creates the Tab within a given instance of ControlExample. */ - ComboTab(ControlExample instance) { + this(ControlExample instance) { super(instance); + if( ListData.length is 0 ){ + ListData = [ControlExample.getResourceString("ListData0_0"), + ControlExample.getResourceString("ListData0_1"), + ControlExample.getResourceString("ListData0_2"), + ControlExample.getResourceString("ListData0_3"), + ControlExample.getResourceString("ListData0_4"), + ControlExample.getResourceString("ListData0_5"), + ControlExample.getResourceString("ListData0_6"), + ControlExample.getResourceString("ListData0_7"), + ControlExample.getResourceString("ListData0_8")]; + } } - + /** * Creates the "Example" group. */ void createExampleGroup () { super.createExampleGroup (); - + /* Create a group for the combo box */ comboGroup = new Group (exampleGroup, DWT.NONE); comboGroup.setLayout (new GridLayout ()); comboGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); comboGroup.setText ("Combo"); } - + /** * Creates the "Example" widgets. */ void createExampleWidgets () { - + /* Compute the widget style */ int style = getDefaultStyle(); if (dropDownButton.getSelection ()) style |= DWT.DROP_DOWN; if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY; if (simpleButton.getSelection ()) style |= DWT.SIMPLE; - + /* Create the example widgets */ combo1 = new Combo (comboGroup, style); combo1.setItems (ListData); @@ -81,7 +87,7 @@ combo1.setText(ListData [2]); } } - + /** * Creates the tab folder page. * @@ -97,12 +103,12 @@ * its preferred size, and then resizes the shell, we * recalculate the preferred size correctly. */ - tabFolderPage.addControlListener(new ControlAdapter() { + tabFolderPage.addControlListener(new class() ControlAdapter { public void controlResized(ControlEvent e) { setExampleWidgetSize (); } }); - + return tabFolderPage; } @@ -111,7 +117,7 @@ */ void createStyleGroup () { super.createStyleGroup (); - + /* Create the extra widgets */ dropDownButton = new Button (styleGroup, DWT.RADIO); dropDownButton.setText ("DWT.DROP_DOWN"); @@ -120,29 +126,29 @@ readOnlyButton = new Button (styleGroup, DWT.CHECK); readOnlyButton.setText ("DWT.READ_ONLY"); } - + /** * Gets the "Example" widget children. */ Widget [] getExampleWidgets () { - return new Widget [] {combo1}; + return [ cast(Widget) combo1]; } - + /** * Returns a list of set/get API method names (without the set/get prefix) * that can be used to set/get values in the example control(s). */ - String[] getMethodNames() { - return new String[] {"Items", "Orientation", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"}; + char[][] getMethodNames() { + return ["Items", "Orientation", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"]; } /** * Gets the text for the tab folder item. */ - String getTabText () { + char[] getTabText () { return "Combo"; } - + /** * Sets the state of the "Example" widgets. */
--- a/dwtexamples/controlexample/ControlExample.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/ControlExample.d Mon Jan 21 22:25:26 2008 +0100 @@ -39,12 +39,12 @@ import dwtexamples.controlexample.Tab; import dwtexamples.controlexample.ButtonTab; -/+ import dwtexamples.controlexample.CanvasTab; import dwtexamples.controlexample.ComboTab; import dwtexamples.controlexample.CoolBarTab; -import dwtexamples.controlexample.DateTimeTab; +//import dwtexamples.controlexample.DateTimeTab; import dwtexamples.controlexample.DialogTab; +/+ import dwtexamples.controlexample.ExpandBarTab; import dwtexamples.controlexample.GroupTab; import dwtexamples.controlexample.LabelTab; @@ -144,12 +144,12 @@ Tab[] createTabs() { return [ cast(Tab) new ButtonTab (this), - /+ new CanvasTab (this), new ComboTab (this), new CoolBarTab (this), - new DateTimeTab (this), + //new DateTimeTab (this), new DialogTab (this), + /+ new ExpandBarTab (this), new GroupTab (this), new LabelTab (this), @@ -224,23 +224,23 @@ return res; } - /** - * Gets a string from the resource bundle and binds it - * with the given arguments. If the key is not found, - * return the key. - */ - static char[] getResourceString(char[] key, Object[] args) { - char[] res; - try { - res = Format(getResourceString(key), args); - } catch (NoSuchElementException e) { - return key; - } - if( res is null ){ - return "!" ~ key ~ "!"; //$NON-NLS-1$ //$NON-NLS-2$ - } - return res; - } +// /** +// * Gets a string from the resource bundle and binds it +// * with the given arguments. If the key is not found, +// * return the key. +// */ +// static char[] getResourceString(char[] key, Object[] args) { +// char[] res; +// try { +// res = Format(getResourceString(key), args); +// } catch (NoSuchElementException e) { +// return key; +// } +// if( res is null ){ +// return "!" ~ key ~ "!"; //$NON-NLS-1$ //$NON-NLS-2$ +// } +// return res; +// } /** * Loads the resources
--- a/dwtexamples/controlexample/CoolBarTab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/CoolBarTab.d Mon Jan 21 22:25:26 2008 +0100 @@ -37,6 +37,10 @@ import dwt.widgets.ToolItem; import dwt.widgets.Widget; +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; +import tango.util.Convert; + class CoolBarTab : Tab { /* Example widgets and group that contains them */ CoolBar coolBar; @@ -72,7 +76,7 @@ lockedButton.setText (ControlExample.getResourceString("Locked")); /* Add the listeners */ - lockedButton.addSelectionListener (new SelectionAdapter () { + lockedButton.addSelectionListener (new class() SelectionAdapter { public void widgetSelected (SelectionEvent event) { setWidgetLocked (); } @@ -206,8 +210,7 @@ Control control = coolItem.getControl(); Point size = control.computeSize(DWT.DEFAULT, DWT.DEFAULT); Point coolSize = coolItem.computeSize(size.x, size.y); - if (control instanceof ToolBar) { - ToolBar bar = (ToolBar)control; + if ( auto bar = cast(ToolBar)control ) { if (bar.getItemCount() > 0) { if (vertical) { size.y = bar.getItem(0).getBounds().height; @@ -225,11 +228,11 @@ if (order !is null && order.length is coolBar.getItemCount()) { coolBar.setItemLayout(order, wrapIndices, sizes); } else { - coolBar.setWrapIndices(new int[] {1, 3}); + coolBar.setWrapIndices([1, 3]); } /* Add a listener to resize the group box to match the coolbar */ - coolBar.addListener(DWT.Resize, new Listener() { + coolBar.addListener(DWT.Resize, new class() Listener { public void handleEvent(Event event) { exampleGroup.layout(); } @@ -285,28 +288,28 @@ * Gets the "Example" widget children. */ Widget [] getExampleWidgets () { - return new Widget [] {coolBar}; + return [ cast(Widget) coolBar]; } /** * Returns a list of set/get API method names (without the set/get prefix) * that can be used to set/get values in the example control(s). */ - String[] getMethodNames() { - return new String[] {"ToolTipText"}; + char[][] getMethodNames() { + return ["ToolTipText"]; } /** * Gets the short text for the tab folder item. */ - public String getShortTabText() { + public char[] getShortTabText() { return "CB"; } /** * Gets the text for the tab folder item. */ - String getTabText () { + char[] getTabText () { return "CoolBar"; } @@ -335,7 +338,7 @@ * Listens to widgetSelected() events on DWT.DROP_DOWN type ToolItems * and opens/closes a menu when appropriate. */ - class DropDownSelectionListener extends SelectionAdapter { + class DropDownSelectionListener : SelectionAdapter { private Menu menu = null; private bool visible = false; @@ -344,21 +347,21 @@ if (menu is null) { // Lazy create the menu. menu = new Menu(shell); - menu.addMenuListener(new MenuAdapter() { + menu.addMenuListener(new class() MenuAdapter { public void menuHidden(MenuEvent e) { visible = false; } }); for (int i = 0; i < 9; ++i) { - final String text = ControlExample.getResourceString("DropDownData_" + i); - if (text.length() !is 0) { + final char[] text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(i)); + if (text.length !is 0) { MenuItem menuItem = new MenuItem(menu, DWT.NONE); menuItem.setText(text); /* * Add a menu selection listener so that the menu is hidden * when the user selects an item from the drop down menu. */ - menuItem.addSelectionListener(new SelectionAdapter() { + menuItem.addSelectionListener(new class() SelectionAdapter { public void widgetSelected(SelectionEvent e) { setMenuVisible(false); } @@ -384,8 +387,8 @@ setMenuVisible(false); } else { // Position the menu below and vertically aligned with the the drop down tool button. - final ToolItem toolItem = (ToolItem) event.widget; - final ToolBar toolBar = toolItem.getParent(); + ToolItem toolItem = cast(ToolItem) event.widget; + ToolBar toolBar = toolItem.getParent(); Rectangle toolItemBounds = toolItem.getBounds(); Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); @@ -409,7 +412,7 @@ * Listens to widgetSelected() events on DWT.DROP_DOWN type CoolItems * and opens/closes a menu when appropriate. */ - class CoolItemSelectionListener extends SelectionAdapter { + class CoolItemSelectionListener : SelectionAdapter { private Menu menu = null; public void widgetSelected(SelectionEvent event) { @@ -430,7 +433,7 @@ } /* Get the cool item and convert its bounds to display coordinates. */ - CoolItem coolItem = (CoolItem) event.widget; + CoolItem coolItem = cast(CoolItem) event.widget; Rectangle itemBounds = coolItem.getBounds (); itemBounds.width = event.x - itemBounds.x; Point pt = coolBar.toDisplay(new Point (itemBounds.x, itemBounds.y)); @@ -438,7 +441,7 @@ itemBounds.y = pt.y; /* Get the toolbar from the cool item. */ - ToolBar toolBar = (ToolBar) coolItem.getControl (); + ToolBar toolBar = cast(ToolBar) coolItem.getControl (); ToolItem[] tools = toolBar.getItems (); int toolCount = tools.length; @@ -452,7 +455,7 @@ toolBounds.x = pt.x; toolBounds.y = pt.y; Rectangle intersection = itemBounds.intersection (toolBounds); - if (!intersection.equals (toolBounds)) break; + if (intersection!=toolBounds) break; i++; } @@ -467,13 +470,13 @@ if ((tool.getStyle() & DWT.DROP_DOWN) !is 0) { MenuItem menuItem = new MenuItem (menu, DWT.CASCADE); menuItem.setImage(image); - String text = tool.getToolTipText(); + char[] text = tool.getToolTipText(); if (text !is null) menuItem.setText(text); Menu m = new Menu(menu); menuItem.setMenu(m); for (int k = 0; k < 9; ++k) { - text = ControlExample.getResourceString("DropDownData_" + k); - if (text.length() !is 0) { + text = ControlExample.getResourceString("DropDownData_" ~ to!(char[])(k)); + if (text.length !is 0) { MenuItem mi = new MenuItem(m, DWT.NONE); mi.setText(text); /* Application code to perform the action for the submenu item would go here. */ @@ -484,7 +487,7 @@ } else { MenuItem menuItem = new MenuItem (menu, DWT.NONE); menuItem.setImage(image); - String text = tool.getToolTipText(); + char[] text = tool.getToolTipText(); if (text !is null) menuItem.setText(text); } /* Application code to perform the action for the menu item would go here. */
--- a/dwtexamples/controlexample/DialogTab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/DialogTab.d Mon Jan 21 22:25:26 2008 +0100 @@ -33,6 +33,10 @@ import dwt.widgets.Text; import dwt.widgets.Widget; +import dwtexamples.controlexample.Tab; +import dwtexamples.controlexample.ControlExample; +import tango.text.convert.Format; + class DialogTab : Tab { /* Example widgets and groups that contain them */ Group dialogStyleGroup, resultGroup; @@ -50,17 +54,20 @@ Button primaryModalButton, applicationModalButton, systemModalButton; Button saveButton, openButton, multiButton; - static String [] FilterExtensions = {"*.txt", "*.bat", "*.doc", "*"}; - static String [] FilterNames = {ControlExample.getResourceString("FilterName_0"), - ControlExample.getResourceString("FilterName_1"), - ControlExample.getResourceString("FilterName_2"), - ControlExample.getResourceString("FilterName_3")}; + static const char[] [] FilterExtensions = ["*.txt", "*.bat", "*.doc", "*"]; + static char[] [] FilterNames; /** * Creates the Tab within a given instance of ControlExample. */ this(ControlExample instance) { super(instance); + if( FilterNames.length is 0 ){ + FilterNames = [ ControlExample.getResourceString("FilterName_0"), + ControlExample.getResourceString("FilterName_1"), + ControlExample.getResourceString("FilterName_2"), + ControlExample.getResourceString("FilterName_3")]; + } } /** @@ -131,102 +138,102 @@ if (multiButton.getEnabled () && multiButton.getSelection ()) style |= DWT.MULTI; /* Open the appropriate dialog type */ - String name = dialogCombo.getText (); + char[] name = dialogCombo.getText (); - if (name.equals (ControlExample.getResourceString("ColorDialog"))) { + if (name == ControlExample.getResourceString("ColorDialog")) { ColorDialog dialog = new ColorDialog (shell ,style); dialog.setRGB (new RGB (100, 100, 100)); dialog.setText (ControlExample.getResourceString("Title")); RGB result = dialog.open (); - textWidget.append (ControlExample.getResourceString("ColorDialog") + Text.DELIMITER); - textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER + Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("ColorDialog")~"{}", Text.DELIMITER)); + textWidget.append (Format( ControlExample.getResourceString("Result")~"{}{}", result, Text.DELIMITER, Text.DELIMITER)); return; } - if (name.equals (ControlExample.getResourceString("DirectoryDialog"))) { + if (name == ControlExample.getResourceString("DirectoryDialog")) { DirectoryDialog dialog = new DirectoryDialog (shell, style); dialog.setMessage (ControlExample.getResourceString("Example_string")); dialog.setText (ControlExample.getResourceString("Title")); - String result = dialog.open (); - textWidget.append (ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER); - textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER + Text.DELIMITER); + char[] result = dialog.open (); + textWidget.append (ControlExample.getResourceString("DirectoryDialog") ~ Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER ~ Text.DELIMITER); return; } - if (name.equals (ControlExample.getResourceString("FileDialog"))) { + if (name== ControlExample.getResourceString("FileDialog")) { FileDialog dialog = new FileDialog (shell, style); dialog.setFileName (ControlExample.getResourceString("readme_txt")); dialog.setFilterNames (FilterNames); dialog.setFilterExtensions (FilterExtensions); dialog.setText (ControlExample.getResourceString("Title")); - String result = dialog.open(); - textWidget.append (ControlExample.getResourceString("FileDialog") + Text.DELIMITER); - textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER); + char[] result = dialog.open(); + textWidget.append (ControlExample.getResourceString("FileDialog") ~ Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER); if ((dialog.getStyle () & DWT.MULTI) !is 0) { - String [] files = dialog.getFileNames (); + char[] [] files = dialog.getFileNames (); for (int i=0; i<files.length; i++) { - textWidget.append ("\t" + files [i] + Text.DELIMITER); + textWidget.append ("\t" ~ files [i] ~ Text.DELIMITER); } } textWidget.append (Text.DELIMITER); return; } - if (name.equals (ControlExample.getResourceString("FontDialog"))) { + if (name == ControlExample.getResourceString("FontDialog")) { FontDialog dialog = new FontDialog (shell, style); dialog.setText (ControlExample.getResourceString("Title")); FontData result = dialog.open (); - textWidget.append (ControlExample.getResourceString("FontDialog") + Text.DELIMITER); - textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER + Text.DELIMITER); + textWidget.append (ControlExample.getResourceString("FontDialog") ~ Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER ~ Text.DELIMITER); return; } - if (name.equals (ControlExample.getResourceString("PrintDialog"))) { + if (name == ControlExample.getResourceString("PrintDialog")) { PrintDialog dialog = new PrintDialog (shell, style); dialog.setText(ControlExample.getResourceString("Title")); PrinterData result = dialog.open (); - textWidget.append (ControlExample.getResourceString("PrintDialog") + Text.DELIMITER); - textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER + Text.DELIMITER); + textWidget.append (ControlExample.getResourceString("PrintDialog") ~ Text.DELIMITER); + textWidget.append (Format( ControlExample.getResourceString("Result"), result ) ~ Text.DELIMITER ~ Text.DELIMITER); return; } - if (name.equals(ControlExample.getResourceString("MessageBox"))) { + if (name == ControlExample.getResourceString("MessageBox")) { MessageBox dialog = new MessageBox (shell, style); dialog.setMessage (ControlExample.getResourceString("Example_string")); dialog.setText (ControlExample.getResourceString("Title")); int result = dialog.open (); - textWidget.append (ControlExample.getResourceString("MessageBox") + Text.DELIMITER); + textWidget.append (ControlExample.getResourceString("MessageBox") ~ Text.DELIMITER); /* * The resulting integer depends on the original * dialog style. Decode the result and display it. */ switch (result) { case DWT.OK: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.OK"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.OK")); break; case DWT.YES: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.YES"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.YES")); break; case DWT.NO: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.NO"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.NO")); break; case DWT.CANCEL: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.CANCEL"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.CANCEL")); break; case DWT.ABORT: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.ABORT"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.ABORT")); break; case DWT.RETRY: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.RETRY"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.RETRY")); break; case DWT.IGNORE: - textWidget.append (ControlExample.getResourceString("Result", new String [] {"DWT.IGNORE"})); + textWidget.append (Format( ControlExample.getResourceString("Result"), "DWT.IGNORE")); break; default: - textWidget.append(ControlExample.getResourceString("Result", new String [] {"" + result})); + textWidget.append(Format( ControlExample.getResourceString("Result"), result)); break; } - textWidget.append (Text.DELIMITER + Text.DELIMITER); + textWidget.append (Text.DELIMITER ~ Text.DELIMITER); } } @@ -265,14 +272,14 @@ void createControlWidgets () { /* Create the combo */ - String [] strings = { + char[] [] strings = [ ControlExample.getResourceString("ColorDialog"), ControlExample.getResourceString("DirectoryDialog"), ControlExample.getResourceString("FileDialog"), ControlExample.getResourceString("FontDialog"), ControlExample.getResourceString("PrintDialog"), ControlExample.getResourceString("MessageBox"), - }; + ]; dialogCombo = new Combo (dialogStyleGroup, DWT.READ_ONLY); dialogCombo.setItems (strings); dialogCombo.setText (strings [0]); @@ -359,17 +366,17 @@ } /* Add the listeners */ - dialogCombo.addSelectionListener (new SelectionAdapter () { + dialogCombo.addSelectionListener (new class() SelectionAdapter { public void widgetSelected (SelectionEvent event) { dialogSelected (event); } }); - createButton.addSelectionListener (new SelectionAdapter () { + createButton.addSelectionListener (new class() SelectionAdapter { public void widgetSelected (SelectionEvent event) { createButtonSelected (event); } }); - SelectionListener buttonStyleListener = new SelectionAdapter () { + SelectionListener buttonStyleListener = new class() SelectionAdapter { public void widgetSelected (SelectionEvent event) { buttonStyleSelected (event); } @@ -446,9 +453,9 @@ void dialogSelected (SelectionEvent event) { /* Enable/Disable the buttons */ - String name = dialogCombo.getText (); - bool isMessageBox = name.equals (ControlExample.getResourceString("MessageBox")); - bool isFileDialog = name.equals (ControlExample.getResourceString("FileDialog")); + char[] name = dialogCombo.getText (); + bool isMessageBox = ( name == ControlExample.getResourceString("MessageBox")); + bool isFileDialog = ( name == ControlExample.getResourceString("FileDialog")); okButton.setEnabled (isMessageBox); cancelButton.setEnabled (isMessageBox); yesButton.setEnabled (isMessageBox); @@ -482,13 +489,13 @@ * Gets the "Example" widget children. */ Widget [] getExampleWidgets () { - return new Widget [0]; + return null; } /** * Gets the text for the tab folder item. */ - String getTabText () { + char[] getTabText () { return "Dialog"; }
--- a/dwtexamples/controlexample/Tab.d Mon Jan 21 19:16:10 2008 +0100 +++ b/dwtexamples/controlexample/Tab.d Mon Jan 21 22:25:26 2008 +0100 @@ -65,10 +65,14 @@ import dwt.widgets.TableItem; import dwt.widgets.Text; import dwt.widgets.Widget; +import dwt.widgets.Canvas; +import dwt.widgets.CoolBar; import dwtexamples.controlexample.ControlExample; import tango.text.convert.Format; +import tango.io.Stdout; + /** * <code>Tab</code> is the abstract superclass of every page * in the example's tab folder. Each page in the tab folder @@ -188,11 +192,80 @@ bool samplePopup = false; + + struct ReflectTypeInfo{ + ReflectMethodInfo[ char[] ] methods; + } + struct ReflectMethodInfo{ + TypeInfo returnType; + TypeInfo[] argumentTypes; + } + static ReflectTypeInfo[ ClassInfo ] reflectTypeInfos; + + static ReflectMethodInfo createMethodInfo( TypeInfo ret, TypeInfo[] args ... ){ + ReflectMethodInfo res; + res.returnType = ret; + foreach( arg; args ){ + res.argumentTypes ~= arg; + } + return res; + } + static void createSetterGetter( ref ReflectTypeInfo ti, char[] name, TypeInfo type ){ + ti.methods[ "get" ~ name ] = createMethodInfo( type ); + ti.methods[ "set" ~ name ] = createMethodInfo( typeid(void), type ); + } + + static void registerTypes(){ + if( reflectTypeInfos.length > 0 ){ + return; + } + + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Selection", typeid(bool) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Button.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ Canvas.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "Orientation", typeid(int) ); + createSetterGetter( ti, "Items", typeid(char[]) ); + createSetterGetter( ti, "Selection", typeid(Point) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "TextLimit", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + createSetterGetter( ti, "VisibleItemCount", typeid(int) ); + reflectTypeInfos[ Combo.classinfo ] = ti; + } + { + ReflectTypeInfo ti; + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + reflectTypeInfos[ CoolBar.classinfo ] = ti; + } + /+{ + ReflectTypeInfo ti; + createSetterGetter( ti, "Editable", typeid(bool) ); + createSetterGetter( ti, "Items", typeid(char[]) ); + createSetterGetter( ti, "Selection", typeid(Point) ); + createSetterGetter( ti, "Text", typeid(char[]) ); + createSetterGetter( ti, "TextLimit", typeid(int) ); + createSetterGetter( ti, "ToolTipText", typeid(char[]) ); + createSetterGetter( ti, "VisibleItemCount", typeid(int) ); + reflectTypeInfos[ CCombo.classinfo ] = ti; + }+/ + } /** * Creates the Tab within a given instance of ControlExample. */ this(ControlExample instance) { this.instance = instance; + registerTypes(); } /** @@ -790,26 +863,35 @@ } char[] parameterInfo(char[] methodRoot) { + char[] methodName = "get" ~ methodRoot; + auto mthi = getMethodInfo( methodName ); + char[] typeNameString = mthi.returnType.toString; //PORTING_LEFT -/+ - char[] typeName = null; - ClassInfo returnType = getReturnType(methodRoot); - bool isArray = returnType.isArray(); - if (isArray) { - typeName = returnType.getComponentType().getName(); - } else { - typeName = returnType.getName(); - } - char[] typeNameString = typeName; - int index = typeName.lastIndexOf('.'); - if (index !is -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1); - char[] info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : "")); - if (isArray) { - typeNameString += "[]"; - } - return ControlExample.getResourceString("Parameter_Info", [typeNameString, info]); -+/ -return null; + +// char[] typeName = null; +// ClassInfo returnType = getReturnType(methodRoot); + bool isArray = false; + TypeInfo ti = mthi.returnType; + + if ( auto tia = cast(TypeInfo_Array) mthi.returnType ) { + ti = tia.value; + isArray = true; + } + if ( auto tia = cast(TypeInfo_Class ) ti ) { + } else if ( auto tia = cast(TypeInfo_Interface ) ti ) { + } else { + } + //char[] typeNameString = typeName; + char[] info; +// int index = typeName.lastIndexOf('.'); +// if (index !is -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1); +// char[] info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : "")); +// if (isArray) { +// typeNameString += "[]"; +// } +// return ControlExample.getResourceString("Parameter_Info", [typeNameString, info]); + + return Format( ControlExample.getResourceString("Parameter_Info"), typeNameString, info ); } void getValue() { @@ -845,20 +927,28 @@ +/ } - ClassInfo getReturnType(char[] methodRoot) { -//PORTING_LEFT -/+ - ClassInfo returnType = null; - char[] methodName = "get" + methodRoot; + private ReflectMethodInfo getMethodInfo( char[] methodName ){ Widget[] widgets = getExampleWidgets(); - try { - java.lang.reflect.Method method = widgets[0].getClass().getMethod(methodName, null); - returnType = method.getReturnType(); - } catch (Exception e) { + if( widgets.length is 0 ){ + Stdout.formatln( "getWidgets returns null in {}", this.classinfo.name ); } - return returnType; -+/ -return null; + if( auto rti = widgets[0].classinfo in reflectTypeInfos ){ + if( auto mthi = methodName in rti.methods ){ + return *mthi; + } + else{ + Stdout.formatln( "method unknown {} in type {} in {}", methodName, widgets[0].classinfo.name, this.classinfo.name ); + } + } + else{ + Stdout.formatln( "type unknown {} in {}", widgets[0].classinfo.name, this.classinfo.name ); + } + } + + TypeInfo getReturnType(char[] methodRoot) { + char[] methodName = "get" ~ methodRoot; + auto mthi = getMethodInfo( methodName ); + return mthi.returnType; } void setValue() { @@ -1128,7 +1218,7 @@ * @return an array containing custom event names */ char[] [] getCustomEventNames () { - return new char[] [0]; + return null; } /** @@ -1152,7 +1242,7 @@ * @return an array containing the example widgets */ Widget [] getExampleWidgets () { - return new Widget [0]; + return null; } /**