diff examples/controlexample/AlignableTab.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children 8a1930f94cbb
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/controlexample/AlignableTab.d	Sat May 10 13:32:45 2008 -0700
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwtexamples.controlexample.AlignableTab;
+
+
+
+import dwt.DWT;
+import dwt.events.SelectionAdapter;
+import dwt.events.SelectionEvent;
+import dwt.events.SelectionListener;
+import dwt.layout.GridData;
+import dwt.layout.GridLayout;
+import dwt.widgets.Button;
+import dwt.widgets.Group;
+import dwt.widgets.Widget;
+
+import dwtexamples.controlexample.Tab;
+import dwtexamples.controlexample.ControlExample;
+
+/**
+ * <code>AlignableTab</code> is the abstract
+ * superclass of example controls that can be
+ * aligned.
+ */
+abstract class AlignableTab : Tab {
+
+    /* Alignment Controls */
+    Button leftButton, rightButton, centerButton;
+
+    /* Alignment Group */
+    Group alignmentGroup;
+
+    /**
+     * Creates the Tab within a given instance of ControlExample.
+     */
+    this(ControlExample instance) {
+        super(instance);
+    }
+
+    /**
+     * Creates the "Other" group.
+     */
+    void createOtherGroup () {
+        super.createOtherGroup ();
+
+        /* Create the group */
+        alignmentGroup = new Group (otherGroup, DWT.NONE);
+        alignmentGroup.setLayout (new GridLayout ());
+        alignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL |
+            GridData.VERTICAL_ALIGN_FILL));
+        alignmentGroup.setText (ControlExample.getResourceString("Alignment"));
+
+        /* Create the controls */
+        leftButton = new Button (alignmentGroup, DWT.RADIO);
+        leftButton.setText (ControlExample.getResourceString("Left"));
+        centerButton = new Button (alignmentGroup, DWT.RADIO);
+        centerButton.setText(ControlExample.getResourceString("Center"));
+        rightButton = new Button (alignmentGroup, DWT.RADIO);
+        rightButton.setText (ControlExample.getResourceString("Right"));
+
+        /* Add the listeners */
+        SelectionListener selectionListener = new class() SelectionAdapter {
+            public void widgetSelected(SelectionEvent event) {
+                if (!(cast(Button) event.widget).getSelection ()) return;
+                setExampleWidgetAlignment ();
+            }
+        };
+        leftButton.addSelectionListener (selectionListener);
+        centerButton.addSelectionListener (selectionListener);
+        rightButton.addSelectionListener (selectionListener);
+    }
+
+    /**
+     * Sets the alignment of the "Example" widgets.
+     */
+    abstract void setExampleWidgetAlignment ();
+
+    /**
+     * Sets the state of the "Example" widgets.
+     */
+    void setExampleWidgetState () {
+        super.setExampleWidgetState ();
+        Widget [] widgets = getExampleWidgets ();
+        if (widgets.length !is 0) {
+            leftButton.setSelection ((widgets [0].getStyle () & DWT.LEFT) !is 0);
+            centerButton.setSelection ((widgets [0].getStyle () & DWT.CENTER) !is 0);
+            rightButton.setSelection ((widgets [0].getStyle () & DWT.RIGHT) !is 0);
+        }
+    }
+}