# HG changeset patch
# User Frank Benoit
run
+ * method is invoked to do the real work.
+ * + * Actions support a predefined set of properties (and possibly others as well). + * Clients of an action may register property change listeners so that they get + * notified whenever the value of a property changes. + *
+ *
+ * Clients should subclass the abstract base class Action
to define
+ * concrete actions rather than implementing IAction
from scratch.
+ *
+ * This interface exists only to define the API for actions. + * It is not intended to be implemented by clients. + *
+ * + * @see Action + */ +public interface IAction { + + /** + * Action style constant (value0
) indicating action style
+ * is not specified yet. By default, the action will assume a push button
+ * style. If setChecked
is called, then the style will change
+ * to a check box, or if setMenuCreator
is called, then the
+ * style will change to a drop down menu.
+ *
+ * @since 2.1
+ */
+ public static int AS_UNSPECIFIED = 0x00;
+
+ /**
+ * Action style constant (value 1
) indicating action is
+ * a simple push button.
+ */
+ public static int AS_PUSH_BUTTON = 0x01;
+
+ /**
+ * Action style constant (value 2
) indicating action is
+ * a check box (or a toggle button).
+ */
+ public static int AS_CHECK_BOX = 0x02;
+
+ /**
+ * Action style constant (value 4
) indicating action is
+ * a drop down menu.
+ */
+ public static int AS_DROP_DOWN_MENU = 0x04;
+
+ /**
+ * Action style constant (value 8
) indicating action is
+ * a radio button.
+ *
+ * @since 2.1
+ */
+ public static int AS_RADIO_BUTTON = 0x08;
+
+ /**
+ * Property name of an action's text (value "text"
).
+ */
+ public static const String TEXT = "text"; //$NON-NLS-1$
+
+ /**
+ * Property name of an action's enabled state
+ * (value "enabled"
).
+ */
+ public static const String ENABLED = "enabled"; //$NON-NLS-1$
+
+ /**
+ * Property name of an action's image (value "image"
).
+ */
+ public static const String IMAGE = "image"; //$NON-NLS-1$
+
+ /**
+ * Property name of an action's tooltip text (value "toolTipText"
).
+ */
+ public static const String TOOL_TIP_TEXT = "toolTipText"; //$NON-NLS-1$
+
+ /**
+ * Property name of an action's description (value "description"
).
+ * Typically the description is shown as a (longer) help text in the status line.
+ */
+ public static const String DESCRIPTION = "description"; //$NON-NLS-1$
+
+ /**
+ * Property name of an action's checked status (value
+ * "checked"
). Applicable when the style is
+ * AS_CHECK_BOX
or AS_RADIO_BUTTON
.
+ */
+ public static const String CHECKED = "checked"; //$NON-NLS-1$
+
+ /**
+ * Property name of an action's success/fail result
+ * (value "result"
). The values are
+ * bool.TRUE
if running the action succeeded and
+ * bool.FALSE
if running the action failed or did not
+ * complete.
+ * + * Not all actions report whether they succeed or fail. This property + * is provided for use by actions that may be invoked by clients that can + * take advantage of this information when present (for example, actions + * used in cheat sheets). Clients should always assume that running the + * action succeeded in the absence of notification to the contrary. + *
+ * + * @since 3.0 + */ + public static const String RESULT = "result"; //$NON-NLS-1$ + + /** + * Property name of an action's handler. Some actions delegate some or all + * of their behaviour or state to another object. In this case, if the + * object to which behaviour has been delegated changes, then a property + * change event should be sent with this name. + * + * This is used to support backward compatibility of actions within the + * commands framework. + * + * @since 3.1 + */ + public static const String HANDLED = IHandlerAttributes.ATTRIBUTE_HANDLED; + + /** + * Adds a property change listener to this action. + * Has no effect if an identical listener is already registered. + * + * @param listener a property change listener + */ + public void addPropertyChangeListener(IPropertyChangeListener listener); + + /** + * Returns the accelerator keycode for this action. + * The result is the bit-wise OR of zero or more modifier masks + * and a key, as explained inMenuItem.getAccelerator
.
+ *
+ * @return the accelerator keycode
+ * @see dwt.widgets.MenuItem#getAccelerator()
+ */
+ public int getAccelerator();
+
+ /**
+ * Returns the action definition id of this action.
+ *
+ * @return the action definition id of this action, or
+ * null
if none
+ * @since 2.0
+ */
+ public String getActionDefinitionId();
+
+ /**
+ * Returns the action's description if it has one.
+ * Otherwise it returns getToolTipText()
.
+ *
+ * @return a description for the action; may be null
+ */
+ public String getDescription();
+
+ /**
+ * Returns the disabled image for this action as an image descriptor.
+ *
+ * This method is associated with the IMAGE
property;
+ * property change events are reported when its value changes.
+ *
null
if this action has no image
+ * @see #IMAGE
+ */
+ public ImageDescriptor getDisabledImageDescriptor();
+
+ /**
+ * Returns a help listener for this action.
+ *
+ * @return a help listener for this action
+ */
+ public HelpListener getHelpListener();
+
+ /**
+ * Returns the hover image for this action as an image descriptor.
+ *
+ * Hover images will be used on platforms that support changing the image
+ * when the user hovers over the item. This method is associated with
+ * the IMAGE
property;
+ * property change events are reported when its value changes.
+ *
null
if this action has no image
+ * @see #IMAGE
+ */
+ public ImageDescriptor getHoverImageDescriptor();
+
+ /**
+ * Returns a unique identifier for this action, or null
if it has
+ * none.
+ *
+ * @return the action id, or null
if none
+ */
+ public String getId();
+
+ /**
+ * Returns the image for this action as an image descriptor.
+ *
+ * This method is associated with the IMAGE
property;
+ * property change events are reported when its value changes.
+ *
null
if this action has no image
+ * @see #IMAGE
+ */
+ public ImageDescriptor getImageDescriptor();
+
+ /**
+ * Returns the menu creator for this action.
+ *
+ * @return the menu creator, or null
if none
+ */
+ public IMenuCreator getMenuCreator();
+
+ /**
+ * Return this action's style.
+ *
+ * @return one of AS_PUSH_BUTTON
, AS_CHECK_BOX
,
+ * AS_RADIO_BUTTON
and AS_DROP_DOWN_MENU
.
+ */
+ public int getStyle();
+
+ /**
+ * Returns the text for this action.
+ *
+ * This method is associated with the TEXT
property;
+ * property change events are reported when its value changes.
+ *
null
if none
+ * @see #TEXT
+ */
+ public String getText();
+
+ /**
+ * Returns the tool tip text for this action.
+ *
+ * This method is associated with the TOOL_TIP_TEXT
property;
+ * property change events are reported when its value changes.
+ *
null
if none
+ * @see #TOOL_TIP_TEXT
+ */
+ public String getToolTipText();
+
+ /**
+ * Returns the checked status of this action. Applicable only if the style is
+ * AS_CHECK_BOX
or AS_RADIO_BUTTON
.
+ *
+ * This method is associated with the CHECKED
property;
+ * property change events are reported when its value changes.
+ *
+ * This method is associated with the ENABLED
property;
+ * property change events are reported when its value changes.
+ *
true
if enabled, and
+ * false
if disabled
+ * @see #ENABLED
+ */
+ public bool isEnabled();
+
+ /**
+ * Returns whether this action is handled. In the default case, this is
+ * always true
. However, if the action delegates some of its
+ * behaviour to some other object, then this method should answer whether
+ * such an object is currently available.
+ *
+ * @return true
if all of the action's behaviour is
+ * available; false
otherwise.
+ * @since 3.1
+ */
+ public bool isHandled();
+
+ /**
+ * Removes the given listener from this action.
+ * Has no effect if an identical listener is not registered.
+ *
+ * @param listener a property change listener
+ */
+ public void removePropertyChangeListener(IPropertyChangeListener listener);
+
+ /**
+ * Runs this action.
+ * Each action implementation must define the steps needed to carry out this action.
+ * The default implementation of this method in Action
+ * does nothing.
+ */
+ public void run();
+
+ /**
+ * Runs this action, passing the triggering DWT event.
+ * As of 2.0, ActionContributionItem
calls this method
+ * instead of run()
.
+ * The default implementation of this method in Action
+ * simply calls run()
for backwards compatibility.
+ *
+ * @param event the DWT event which triggered this action being run
+ * @since 2.0
+ */
+ public void runWithEvent(Event event);
+
+ /**
+ * Sets the action definition id of this action.
+ *
+ * @param id the action definition id
+ * @since 2.0
+ */
+ public void setActionDefinitionId(String id);
+
+ /**
+ * Sets the checked status of this action. Applicable for the styles
+ * AS_CHECK_BOX
or AS_RADIO_BUTTON
.
+ *
+ * Fires a property change event for the CHECKED
property
+ * if the checked status actually changes as a consequence.
+ *
+ * Fires a property change event for the DESCRIPTION
property
+ * if the description actually changes as a consequence.
+ *
null
to clear the description
+ * @see #DESCRIPTION
+ */
+ public void setDescription(String text);
+
+ /**
+ * Sets the disabled image for this action, as an image descriptor.
+ *
+ * Disabled images will be used on platforms that support changing the image
+ * when the item is disabled.Fires a property change event for
+ * the IMAGE
property
+ * if the image actually changes as a consequence.
+ *
null
if this
+ * action should not have an image
+ * @see #IMAGE
+ */
+ public void setDisabledImageDescriptor(ImageDescriptor newImage);
+
+ /**
+ * Sets the enabled state of this action.
+ *
+ * When an action is in the enabled state, the control associated with
+ * it is active; triggering it will end up inkoking this action's
+ * run
method.
+ *
+ * Fires a property change event for the ENABLED
property
+ * if the enabled state actually changes as a consequence.
+ *
true
to enable, and
+ * false
to disable
+ * @see #ENABLED
+ */
+ public void setEnabled(bool enabled);
+
+ /**
+ * Sets a help listener for this action.
+ *
+ * @param listener a help listener for this action
+ */
+ public void setHelpListener(HelpListener listener);
+
+ /**
+ * Sets the hover image for this action, as an image descriptor.
+ *
+ * Hover images will be used on platforms that support changing the image
+ * when the user hovers over the item.Fires a property change event for
+ * the IMAGE
property
+ * if the image actually changes as a consequence.
+ *
null
if this
+ * action should not have an image
+ * @see #IMAGE
+ */
+ public void setHoverImageDescriptor(ImageDescriptor newImage);
+
+ /**
+ * Sets the unique identifier for this action. This is used to identify actions
+ * when added to a contribution manager.
+ * It should be set when the action is created. It should not be modified once
+ * the action is part of an action contribution item.
+ *
+ * @param id the action id
+ *
+ * @see ActionContributionItem
+ * @see IContributionItem#getId
+ */
+ public void setId(String id);
+
+ /**
+ * Sets the image for this action, as an image descriptor.
+ *
+ * Fires a property change event for the IMAGE
property
+ * if the image actually changes as a consequence.
+ *
null
if this
+ * action should not have an image
+ * @see #IMAGE
+ */
+ public void setImageDescriptor(ImageDescriptor newImage);
+
+ /**
+ * Sets the menu creator for this action. Applicable for style
+ * AS_DROP_DOWN_MENU
.
+ *
+ * @param creator the menu creator, or null
if none
+ */
+ public void setMenuCreator(IMenuCreator creator);
+
+ /**
+ * Sets the text for this action.
+ * + * An accelerator specification may follow the actual text, separated from it by + * an '@' or a '\t' character. An accelerator specification consists of zero or more + * modifier tokens followed by a key code token. The tokens are separated by a '+' character. + *
+ *
+ * Fires a property change event for the TEXT
property
+ * if the text actually changes as a consequence.
+ *
null
if none
+ * @see #TEXT
+ * @see Action#findModifier
+ * @see Action#findKeyCode
+ */
+ public void setText(String text);
+
+ /**
+ * Sets the tool tip text for this action.
+ *
+ * Fires a property change event for the TOOL_TIP_TEXT
property
+ * if the tool tip text actually changes as a consequence.
+ *
null
if none
+ * @see #TOOL_TIP_TEXT
+ */
+ public void setToolTipText(String text);
+
+ /**
+ *
+ * Sets the accelerator keycode that this action maps to. This is a bitwise OR
+ * of zero or more DWT key modifier masks (i.e. DWT.CTRL or DWT.ALT) and a
+ * character code. For example, for Ctrl+Z, use DWT.CTRL | 'Z'
.
+ * Use 0 for no accelerator.
+ *
+ * This method should no longer be used for actions in the Eclipse workbench.
+ * IWorkbenchCommandSupport
and
+ * IWorkbenchContextSupport
provide all the functionality
+ * required for key bindings. If you set an accelerator using this method, then
+ * it will not work in the workbench if it conflicts any existing key binding,
+ * or if there is a different key binding defined for this action's definition
+ * id. The definition id should be used instead -- referring to the command in
+ * the workbench from which the key binding should be retrieved.
+ *
getMenu
. Does nothing
+ * if there is no menu. This method will be executed only when the
+ * parent of the menu is disposed.
+ */
+ public void dispose();
+
+ /**
+ * Returns the DWT menu, created as a pop up menu parented by the
+ * given control. In most cases, this menu can be created once, cached and reused
+ * when the pop-up/drop-down action occurs. If the menu must be dynamically
+ * created (i.e., each time it is popped up or dropped down), the old menu
+ * should be disposed of before replacing it with the new menu.
+ *
+ * @param parent the parent control
+ * @return the menu, or null
if the menu could not
+ * be created
+ */
+ public Menu getMenu(Control parent);
+
+ /**
+ * Returns an DWT menu created as a drop down menu parented by the
+ * given menu. In most cases, this menu can be created once, cached and reused
+ * when the pop-up/drop-down action occurs. If the menu must be dynamically
+ * created (i.e., each time it is popped up or dropped down), the old menu
+ * should be disposed of before replacing it with the new menu.
+ *
+ * @param parent the parent menu
+ * @return the menu, or null
if the menu could not
+ * be created
+ */
+ public Menu getMenu(Menu parent);
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/dialogs/AnimatorFactory.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/dialogs/AnimatorFactory.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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
+ * Subclasses should override this method.
+ *
+ * @param control the DWT Control to de displayed
+ * @return the ControlAnimator.
+ * @since 3.2
+ */
+ public ControlAnimator createAnimator(Control control) {
+ return new ControlAnimator(control);
+ }
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/dialogs/ControlAnimator.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/dialogs/ControlAnimator.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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
+ * Instances of this class can be created using an AnimatorFactory.
+ *
+ * @since 3.2
+ */
+
+
+public class ControlAnimator {
+ /** the control that will be displayed or hidden */
+ protected Control control;
+
+ /**
+ * Constructs a new ControlAnimator instance and passes along the
+ * control that will be displayed or hidden.
+ *
+ * @param control the control that will be displayed or hidden.
+ */
+ public this(Control control) {
+ this.control = control;
+ }
+
+ /**
+ * Displays or hides a control at the bottom of the parent composite
+ * and makes use of the control's DWT visible flag.
+ * Subclasses should override this method.
+ * Note that the file is not accessed until its
+ *
+ * This package defines a concrete image descriptor implementation
+ * which reads an image from a file (
+ * Using this abstract class involves defining a concrete subclass
+ * and providing an implementation for the
+ * There are two ways to get an Image from an ImageDescriptor. The method
+ * createImage will always return a new Image which must be disposed by
+ * the caller. Alternatively, createResource() returns a shared
+ * Image. When the caller is done with an image obtained from createResource,
+ * they must call destroyResource() rather than disposing the Image directly.
+ * The result of createResource() can be safely cast to an Image.
+ *
+ */
+ protected static const ImageData DEFAULT_IMAGE_DATA;
+
+ static this(){
+ DEFAULT_IMAGE_DATA = new ImageData(6, 6, 1, new PaletteData( [ new RGB(255, 0, 0) ] ));
+ }
+
+ /**
+ * Constructs an image descriptor.
+ */
+ protected this() {
+ // do nothing
+ }
+
+ /**
+ * Creates and returns a new image descriptor from a file.
+ * Convenience method for
+ *
+ * Note that this sort of ImageDescriptor is slower and consumes more resources than
+ * a regular image descriptor. It will also never generate results that look as nice as
+ * a hand-drawn image. Clients are encouraged to supply their own disabled/grayed/etc. images
+ * rather than using a default image and transforming it.
+ *
+ * Note: this method differs from createResource(Device) in that the returned image
+ * must be disposed directly, whereas an image obtained from createResource(...)
+ * must be disposed by calling destroyResource(...). It is not possible to
+ * mix-and-match. If you obtained the Image from this method, you must not dispose
+ * it by calling destroyResource. Clients are encouraged to use
+ * create/destroyResource and downcast the result to Image rather than using
+ * createImage.
+ *
+ * Note: it is still possible for this method to return
+ * Note: Even if
+ * Note: it is still possible for this method to return
+ * Note: Even if
+ * This framework method is declared public so that it is
+ * possible to request an image descriptor's image data without
+ * creating an DWT image object.
+ *
+ * Returns
+ * Use
+ * Assertion failure exceptions, like most runtime exceptions, are
+ * thrown when something is misbehaving. Assertion failures are invariably
+ * unspecified behavior; consequently, clients should never rely on
+ * these being thrown (or not thrown). If you find yourself in the
+ * position where you need to catch an assertion failure, you have most
+ * certainly written your program incorrectly.
+ *
+ * Note that an
+ * This class is not declared public to prevent some misuses; programs that catch
+ * or otherwise depend on assertion failures are susceptible to unexpected
+ * breakage when assertions in the code are added or removed.
+ *
+ * As a general rule, parameters passed to API methods must not be
+ *
+ * As a general rule, parameters passed to API methods must not be
+ * This is preferred over the real distance when searching
+ * for the closest point, since it avoids square roots. Returns a new difference Rectangle whose x, y, width, and height are equal to the difference of the corresponding
+ * attributes from the given rectangles Returns a new Rectangle whose x, y, width, and height is the sum of the x, y, width, and height values of
+ * both rectangles respectively. Returns a rectangle which, when added to another rectangle, will expand each side
+ * by the given number of units. This is commonly used to store margin sizes. For example:
+ * Clients may provide their own implementation to change
+ * how errors are logged from within JFace.
+ *
+ * Usage:
+ * true
if the control should be shown,
+ * and false
otherwise.
+ */
+ public void setVisible(bool visible){
+ // Using the DWT visible flag to determine if the control has
+ // already been displayed or hidden. Return if already displayed
+ // and visible is true, or if already hidden and visible is false.
+ if (!(control.isVisible() ^ visible))
+ return;
+ control.setVisible(visible);
+ Rectangle parentBounds = control.getParent().getBounds();
+ int bottom = parentBounds.height;
+ int endY = visible ? bottom - control.getBounds().height
+ : bottom;
+ Point loc = control.getLocation();
+ control.setLocation(loc.x,endY);
+ }
+
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/dialogs/ErrorSupportProvider.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/dialogs/ErrorSupportProvider.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 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 null
if the
+ * cause is nonexistent or unknown.
+ *
+ * @return the cause or null
+ * @since 3.1
+ */
+ public Exception getCause() {
+ return cause;
+ }
+
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/resource/FileImageDescriptor.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/resource/FileImageDescriptor.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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 null
if none.
+ */
+ private ClassInfo location;
+
+ /**
+ * The name of the file.
+ */
+ private String name;
+
+ /**
+ * Creates a new file image descriptor.
+ * The file has the given file name and is located
+ * in the given class's resource directory. If the given
+ * class is null
, the file name must be absolute.
+ * getImageDate
method is called.
+ * null
+ * @param filename the name of the file
+ */
+ this(ClassInfo clazz, String filename) {
+ this.location = clazz;
+ this.name = filename;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on Object.
+ */
+ public bool equals(Object o) {
+ if (!( cast(FileImageDescriptor)o )) {
+ return false;
+ }
+ FileImageDescriptor other = cast(FileImageDescriptor) o;
+ if (location !is null) {
+ if ( location.name != other.location.name ) {
+ return false;
+ }
+ } else {
+ if (other.location !is null) {
+ return false;
+ }
+ }
+ return name == other.name;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on ImageDesciptor.
+ * Returns null if the image data cannot be read.
+ */
+ public ImageData getImageData() {
+ InputStream in_ = getStream();
+ ImageData result = null;
+ if (in_ !is null) {
+ try {
+ result = new ImageData(in_);
+ } catch (DWTException e) {
+ if (e.code !is DWT.ERROR_INVALID_IMAGE) {
+ throw e;
+ // fall through otherwise
+ }
+ } finally {
+ in_.close();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns a stream on the image contents. Returns
+ * null if a stream could not be opened.
+ *
+ * @return the buffered stream on the file or null
+ * if the file cannot be found
+ */
+ private InputStream getStream() {
+ InputStream is_ = null;
+
+ if (location !is null) {
+ is_ = ClassInfoGetResourceAsStream( location, name);
+
+ } else {
+ try {
+ is_ = new FileInputStream(name);
+ } catch (/+FileNotFoundException+/ IOException e) {
+ return null;
+ }
+ }
+ if (is_ is null) {
+ return null;
+ } else {
+ return new BufferedInputStream(is_);
+ }
+ }
+
+ /* (non-Javadoc)
+ * Method declared on Object.
+ */
+ public override hash_t toHash() {
+ int code = dwt.dwthelper.utils.toHash(name);
+ if (location !is null) {
+ code += location.toHash();
+ }
+ return code;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on Object.
+ */
+ /**
+ * The FileImageDescriptor
implementation of this Object
method
+ * returns a string representation of this object which is suitable only for debugging.
+ */
+ public override String toString() {
+ return "FileImageDescriptor(location=" ~ location.toString() ~ ", name=" ~ name ~ ")";//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
+ }
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/resource/ImageDataImageDescriptor.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/resource/ImageDataImageDescriptor.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 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 FileImageDescriptor
).
+ * It also provides abstract framework classes (this one and
+ * CompositeImageDescriptor
) which may be subclassed to define
+ * news kinds of image descriptors.
+ * getImageData
+ * method.
+ * new FileImageDescriptor(location,filename)
.
+ *
+ * @param location the class whose resource directory contain the file
+ * @param filename the file name
+ * @return a new image descriptor
+ */
+ public static ImageDescriptor createFromFile(ClassInfo location, String filename) {
+ return new FileImageDescriptor(location, filename);
+ }
+
+ /**
+ * Creates and returns a new image descriptor given ImageData
+ * describing the image.
+ *
+ * @since 3.1
+ *
+ * @param data contents of the image
+ * @return newly created image descriptor
+ */
+ public static ImageDescriptor createFromImageData(ImageData data) {
+ return new ImageDataImageDescriptor(data);
+ }
+
+ /**
+ * Creates and returns a new image descriptor for the given image. Note
+ * that disposing the original Image will cause the descriptor to become invalid.
+ *
+ * @since 3.1
+ *
+ * @param img image to create
+ * @return a newly created image descriptor
+ */
+ public static ImageDescriptor createFromImage(Image img) {
+ return new ImageDataImageDescriptor(img);
+ }
+
+ /**
+ * Creates an ImageDescriptor based on the given original descriptor, but with additional
+ * DWT flags.
+ *
+ * null
+ * in extreme cases, for example if DWT runs out of image handles.
+ * null
if the image could not be
+ * created
+ */
+ public Image createImage() {
+ return createImage(true);
+ }
+
+ /**
+ * Creates and returns a new DWT image for this image descriptor. The
+ * returned image must be explicitly disposed using the image's dispose
+ * call. The image will not be automatically garbage collected. In the event
+ * of an error, a default image is returned if
+ * returnMissingImageOnError
is true, otherwise
+ * null
is returned.
+ * returnMissingImageOnError
is true, it is
+ * still possible for this method to return null
in extreme
+ * cases, for example if DWT runs out of image handles.
+ * null
if the image could not be
+ * created
+ */
+ public Image createImage(bool returnMissingImageOnError) {
+ return createImage(returnMissingImageOnError, Display.getCurrent());
+ }
+
+ /**
+ * Creates and returns a new DWT image for this image descriptor. The
+ * returned image must be explicitly disposed using the image's dispose
+ * call. The image will not be automatically garbage collected. A default
+ * image is returned in the event of an error.
+ * null
+ * in extreme cases, for example if DWT runs out of image handles.
+ * null
if the image could not be
+ * created
+ * @since 2.0
+ */
+ public Image createImage(Device device) {
+ return createImage(true, device);
+ }
+
+ /**
+ * Creates and returns a new DWT image for this image descriptor. The
+ * returned image must be explicitly disposed using the image's dispose
+ * call. The image will not be automatically garbage collected. In the even
+ * of an error, a default image is returned if
+ * returnMissingImageOnError
is true, otherwise
+ * null
is returned.
+ * returnMissingImageOnError
is true, it is
+ * still possible for this method to return null
in extreme
+ * cases, for example if DWT runs out of image handles.
+ * null
if the image could not be
+ * created
+ * @since 2.0
+ */
+ public Image createImage(bool returnMissingImageOnError, Device device) {
+
+ ImageData data = getImageData();
+ if (data is null) {
+ if (!returnMissingImageOnError) {
+ return null;
+ }
+ data = DEFAULT_IMAGE_DATA;
+ }
+
+ /*
+ * Try to create the supplied image. If there is an DWT Exception try and create
+ * the default image if that was requested. Return null if this fails.
+ */
+
+ try {
+ if (data.transparentPixel >= 0) {
+ ImageData maskData = data.getTransparencyMask();
+ return new Image(device, data, maskData);
+ }
+ return new Image(device, data);
+ } catch (DWTException exception) {
+ if (returnMissingImageOnError) {
+ try {
+ return new Image(device, DEFAULT_IMAGE_DATA);
+ } catch (DWTException nextException) {
+ return null;
+ }
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Creates and returns a new DWT ImageData
object
+ * for this image descriptor.
+ * Note that each call returns a new DWT image data object.
+ * null
if the image data could not be created.
+ * null
+ */
+ public abstract ImageData getImageData();
+
+ /**
+ * Returns the shared image descriptor for a missing image.
+ *
+ * @return the missing image descriptor
+ */
+ public static ImageDescriptor getMissingImageDescriptor() {
+ return MissingImageDescriptor.getInstance();
+ }
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/resource/MissingImageDescriptor.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/resource/MissingImageDescriptor.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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 MissingImageDescriptor.getInstance
to
+ * access the singleton instance maintained in an
+ * internal state variable.
+ * URLImageDescriptor
implementation of this Object
method
+ * returns a string representation of this object which is suitable only for debugging.
+ */
+ public override String toString() {
+ return "URLImageDescriptor(" ~ url.toString ~ ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/Assert.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/util/Assert.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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 Assert
is useful for for embedding runtime sanity checks
+ * in code. The static predicate methods all test a condition and throw some
+ * type of unchecked exception if the condition does not hold.
+ * assert
statement is slated to be added to the
+ * Java language in JDK 1.4, rending this class obsolete.
+ *
+ * @deprecated As of 3.3, replaced by {@link dwtx.core.runtime.Assert}
+ * AssertionFailedException
is a runtime exception thrown
+ * by some of the methods in Assert
.
+ * true
, an IllegalArgumentException
+ * is thrown.
+ *
+ * @param expression the outcome of the check
+ * @return true
if the check passes (does not return
+ * if the check fails)
+ * @exception IllegalArgumentException if the legality test failed
+ */
+ public static bool isLegal(bool expression) {
+ // succeed as quickly as possible
+ if (expression) {
+ return true;
+ }
+ return isLegal(expression, "");//$NON-NLS-1$
+ }
+
+ /**
+ * Asserts that an argument is legal. If the given bool is
+ * not true
, an IllegalArgumentException
+ * is thrown.
+ * The given message is included in that exception, to aid debugging.
+ *
+ * @param expression the outcome of the check
+ * @param message the message to include in the exception
+ * @return true
if the check passes (does not return
+ * if the check fails)
+ * @exception IllegalArgumentException if the legality test failed
+ */
+ public static bool isLegal(bool expression, String message) {
+ if (!expression) {
+ throw new IllegalArgumentException("assertion failed; " ~ message); //$NON-NLS-1$
+ }
+ return expression;
+ }
+
+ /**
+ * Asserts that the given object is not null
. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * null
unless explicitly allowed in the method's
+ * specification. Similarly, results returned from API methods are never
+ * null
unless explicitly allowed in the method's
+ * specification. Implementations are encouraged to make regular use of
+ * Assert.isNotNull
to ensure that null
+ * parameters are detected as early as possible.
+ * null
+ */
+ public static void isNotNull(Object object) {
+ // succeed as quickly as possible
+ if (object !is null) {
+ return;
+ }
+ isNotNull(object, "");//$NON-NLS-1$
+ }
+
+ /**
+ * Asserts that the given object is not null
. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * The given message is included in that exception, to aid debugging.
+ * null
unless explicitly allowed in the method's
+ * specification. Similarly, results returned from API methods are never
+ * null
unless explicitly allowed in the method's
+ * specification. Implementations are encouraged to make regular use of
+ * Assert.isNotNull
to ensure that null
+ * parameters are detected as early as possible.
+ * null
+ */
+ public static void isNotNull(Object object, String message) {
+ if (object is null) {
+ throw new AssertionFailedException("null argument;" ~ message);//$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Asserts that the given bool is true
. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ *
+ * @param expression the outcome of the check
+ * @return true
if the check passes (does not return
+ * if the check fails)
+ */
+ public static bool isTrue(bool expression) {
+ // succeed as quickly as possible
+ if (expression) {
+ return true;
+ }
+ return isTrue(expression, "");//$NON-NLS-1$
+ }
+
+ /**
+ * Asserts that the given bool is true
. If this
+ * is not the case, some kind of unchecked exception is thrown.
+ * The given message is included in that exception, to aid debugging.
+ *
+ * @param expression the outcome of the check
+ * @param message the message to include in the exception
+ * @return true
if the check passes (does not return
+ * if the check fails)
+ */
+ public static bool isTrue(bool expression, String message) {
+ if (!expression) {
+ throw new AssertionFailedException("Assertion failed: " ~ message);//$NON-NLS-1$
+ }
+ return expression;
+ }
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/Geometry.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/util/Geometry.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,812 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2006 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
+ *
+ * @param rect1 first rectangle
+ * @param rect2 rectangle to subtract
+ * @return the difference between the two rectangles (computed as rect1 - rect2)
+ * @since 3.3
+ */
+ public static Rectangle subtract(Rectangle rect1, Rectangle rect2) {
+ return new Rectangle(rect1.x - rect2.x, rect1.y - rect2.y, rect1.width - rect2.width, rect1.height - rect2.height);
+ }
+
+ /**
+ *
+ * // Compute the client area, in the coordinate system of the input composite's parent
+ * Rectangle clientArea = Display.getCurrent().map(inputComposite,
+ * inputComposite.getParent(), inputComposite.getClientArea());
+ *
+ * // Compute the margins for a given Composite by subtracting the client area from the composite's bounds
+ * Rectangle margins = Geometry.subtract(inputComposite.getBounds(), clientArea);
+ *
+ * // Now apply these margins to a new GridLayout
+ * GridLayout layout = GridLayoutFactory.fillDefaults().margins(margins).create();
+ *
+ *
+ * @param left distance to expand the left side (negative values move the edge inward)
+ * @param right distance to expand the right side (negative values move the edge inward)
+ * @param top distance to expand the top (negative values move the edge inward)
+ * @param bottom distance to expand the bottom (negative values move the edge inward)
+ *
+ * @return a difference rectangle that, when added to another rectangle, will cause each
+ * side to expand by the given number of units
+ * @since 3.3
+ */
+ public static Rectangle createDiffRectangle(int left, int right, int top, int bottom) {
+ return new Rectangle(-left, -top, left + right, top + bottom);
+ }
+
+ /**
+ * Moves each edge of the given rectangle outward by the given amount. Negative values
+ * cause the rectangle to contract. Does not allow the rectangle's width or height to be
+ * reduced below zero.
+ *
+ * @param rect normalized rectangle to modify
+ * @param left distance to move the left edge outward (negative values move the edge inward)
+ * @param right distance to move the right edge outward (negative values move the edge inward)
+ * @param top distance to move the top edge outward (negative values move the edge inward)
+ * @param bottom distance to move the bottom edge outward (negative values move the edge inward)
+ * @since 3.1
+ */
+ public static void expand(Rectangle rect, int left, int right, int top, int bottom) {
+ rect.x -= left;
+ rect.width = Math.max(0, rect.width + left + right);
+ rect.y -= top;
+ rect.height = Math.max(0, rect.height + top + bottom);
+ }
+
+ /**
+ * Normalizes the given rectangle. That is, any rectangle with
+ * negative width or height becomes a rectangle with positive
+ * width or height that extends to the upper-left of the original
+ * rectangle.
+ *
+ * @param rect rectangle to modify
+ * @since 3.0
+ */
+ public static void normalize(Rectangle rect) {
+ if (rect.width < 0) {
+ rect.width = -rect.width;
+ rect.x -= rect.width;
+ }
+
+ if (rect.height < 0) {
+ rect.height = -rect.height;
+ rect.y -= rect.height;
+ }
+ }
+
+ /**
+ * Converts the given rectangle from display coordinates to the local coordinate system
+ * of the given object into display coordinates.
+ *
+ * @param coordinateSystem local coordinate system being converted to
+ * @param toConvert rectangle to convert
+ * @return a rectangle in control coordinates
+ * @since 3.0
+ */
+ public static Rectangle toControl(Control coordinateSystem,
+ Rectangle toConvert) {
+ return(coordinateSystem.getDisplay().map
+ (null,coordinateSystem,toConvert));
+ }
+
+ /**
+ * Converts the given rectangle from the local coordinate system of the given object
+ * into display coordinates.
+ *
+ * @param coordinateSystem local coordinate system being converted from
+ * @param toConvert rectangle to convert
+ * @return a rectangle in display coordinates
+ * @since 3.0
+ */
+ public static Rectangle toDisplay(Control coordinateSystem,
+ Rectangle toConvert) {
+ return(coordinateSystem.getDisplay().map
+ (coordinateSystem,null,toConvert));
+
+ }
+
+ /**
+ * Determines where the given point lies with respect to the given rectangle.
+ * Returns a combination of DWT.LEFT, DWT.RIGHT, DWT.TOP, and DWT.BOTTOM, combined
+ * with bitwise or (for example, returns DWT.TOP | DWT.LEFT if the point is to the
+ * upper-left of the rectangle). Returns 0 if the point lies within the rectangle.
+ * Positions are in screen coordinates (ie: a point is to the upper-left of the
+ * rectangle if its x and y coordinates are smaller than any point in the rectangle)
+ *
+ * @param boundary normalized boundary rectangle
+ * @param toTest point whose relative position to the rectangle is being computed
+ * @return one of DWT.LEFT | DWT.TOP, DWT.TOP, DWT.RIGHT | DWT.TOP, DWT.LEFT, 0,
+ * DWT.RIGHT, DWT.LEFT | DWT.BOTTOM, DWT.BOTTOM, DWT.RIGHT | DWT.BOTTOM
+ * @since 3.0
+ */
+ public static int getRelativePosition(Rectangle boundary, Point toTest) {
+ int result = 0;
+
+ if (toTest.x < boundary.x) {
+ result |= DWT.LEFT;
+ } else if (toTest.x >= boundary.x + boundary.width) {
+ result |= DWT.RIGHT;
+ }
+
+ if (toTest.y < boundary.y) {
+ result |= DWT.TOP;
+ } else if (toTest.y >= boundary.y + boundary.height) {
+ result |= DWT.BOTTOM;
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the distance from the point to the nearest edge of the given
+ * rectangle. Returns negative values if the point lies outside the rectangle.
+ *
+ * @param boundary rectangle to test
+ * @param toTest point to test
+ * @return the distance between the given point and the nearest edge of the rectangle.
+ * Returns positive values for points inside the rectangle and negative values for points
+ * outside the rectangle.
+ * @since 3.1
+ */
+ public static int getDistanceFrom(Rectangle boundary, Point toTest) {
+ int side = getClosestSide(boundary, toTest);
+ return getDistanceFromEdge(boundary, toTest, side);
+ }
+
+ /**
+ * Returns the edge of the given rectangle is closest to the given
+ * point.
+ *
+ * @param boundary rectangle to test
+ * @param toTest point to compare
+ * @return one of DWT.LEFT, DWT.RIGHT, DWT.TOP, or DWT.BOTTOM
+ *
+ * @since 3.0
+ */
+ public static int getClosestSide(Rectangle boundary, Point toTest) {
+ int[] sides = [ DWT.LEFT, DWT.RIGHT, DWT.TOP, DWT.BOTTOM ];
+
+ int closestSide = DWT.LEFT;
+ int closestDistance = Integer.MAX_VALUE;
+
+ for (int idx = 0; idx < sides.length; idx++) {
+ int side = sides[idx];
+
+ int distance = getDistanceFromEdge(boundary, toTest, side);
+
+ if (distance < closestDistance) {
+ closestDistance = distance;
+ closestSide = side;
+ }
+ }
+
+ return closestSide;
+ }
+
+ /**
+ * Returns a copy of the given rectangle
+ *
+ * @param toCopy rectangle to copy
+ * @return a copy of the given rectangle
+ * @since 3.0
+ */
+ public static Rectangle copy(Rectangle toCopy) {
+ return new Rectangle(toCopy.x, toCopy.y, toCopy.width, toCopy.height);
+ }
+
+ /**
+ * Returns the size of the rectangle, as a Point
+ *
+ * @param rectangle rectangle whose size is being computed
+ * @return the size of the given rectangle
+ * @since 3.0
+ */
+ public static Point getSize(Rectangle rectangle) {
+ return new Point(rectangle.width, rectangle.height);
+ }
+
+ /**
+ * Sets the size of the given rectangle to the given size
+ *
+ * @param rectangle rectangle to modify
+ * @param newSize new size of the rectangle
+ * @since 3.0
+ */
+ public static void setSize(Rectangle rectangle, Point newSize) {
+ rectangle.width = newSize.x;
+ rectangle.height = newSize.y;
+ }
+
+ /**
+ * Sets the x,y position of the given rectangle. For a normalized
+ * rectangle (a rectangle with positive width and height), this will
+ * be the upper-left corner of the rectangle.
+ *
+ * @param rectangle rectangle to modify
+ * @param newSize new size of the rectangle
+ *
+ * @since 3.0
+ */
+ public static void setLocation(Rectangle rectangle, Point newSize) {
+ rectangle.width = newSize.x;
+ rectangle.height = newSize.y;
+ }
+
+ /**
+ * Returns the x,y position of the given rectangle. For normalized rectangles
+ * (rectangles with positive width and height), this is the upper-left
+ * corner of the rectangle.
+ *
+ * @param toQuery rectangle to query
+ * @return a Point containing the x,y position of the rectangle
+ *
+ * @since 3.0
+ */
+ public static Point getLocation(Rectangle toQuery) {
+ return new Point(toQuery.x, toQuery.y);
+ }
+
+ /**
+ * Returns a new rectangle with the given position and dimensions, expressed
+ * as points.
+ *
+ * @param position the (x,y) position of the rectangle
+ * @param size the size of the new rectangle, where (x,y) -> (width, height)
+ * @return a new Rectangle with the given position and size
+ *
+ * @since 3.0
+ */
+ public static Rectangle createRectangle(Point position, Point size) {
+ return new Rectangle(position.x, position.y, size.x, size.y);
+ }
+
+ /**
+ * Repositions the 'inner' rectangle to lie completely within the bounds of the 'outer'
+ * rectangle if possible. One use for this is to ensure that, when setting a control's bounds,
+ * that they will always lie within its parent's client area (to avoid clipping).
+ *
+ * @param inner The 'inner' rectangle to be repositioned (should be smaller than the 'outer' rectangle)
+ * @param outer The 'outer' rectangle
+ */
+ public static void moveInside(Rectangle inner, Rectangle outer) {
+ // adjust X
+ if (inner.x < outer.x) {
+ inner.x = outer.x;
+ }
+ if ((inner.x + inner.width) > (outer.x + outer.width)) {
+ inner.x -= (inner.x + inner.width) - (outer.x + outer.width);
+ }
+
+ // Adjust Y
+ if (inner.y < outer.y) {
+ inner.y = outer.y;
+ }
+ if ((inner.y + inner.height) > (outer.y + outer.height)) {
+ inner.y -= (inner.y + inner.height) - (outer.y + outer.height);
+ }
+ }
+
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/ILogger.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/util/ILogger.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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:
+ * Chris Gross (schtoo@schtoo.com) - initial API and implementation
+ * (bug 49497 [RCP] JFace dependency on dwtx.core.runtime enlarges standalone JFace applications)
+ * Port to the D programming language:
+ * Frank Benoit
+ * // Expands the left, right, top, and bottom
+ * // of the given control by 10, 5, 1, and 15 units respectively
+ *
+ * Rectangle margins = Geometry.createDifferenceRect(10,5,1,15);
+ * Rectangle bounds = someControl.getBounds();
+ * someControl.setBounds(Geometry.add(bounds, margins));
+ *
+ * OpenStrategy handler = new OpenStrategy(control);
+ * handler.addOpenListener(new IOpenEventListener() {
+ * public void handleOpen(SelectionEvent e) {
+ * ... // code to handle the open event.
+ * }
+ * });
+ *
+ *
+ * Usage: + *
+ * IPropertyChangeListener listener = + * new IPropertyChangeListener() { + * public void propertyChange(PropertyChangeEvent event) { + * ... // code to deal with occurrence of property change + * } + * }; + * emitter.addPropertyChangeListener(listener); + * ... + * emitter.removePropertyChangeListener(listener); + *+ * + */ +public interface IPropertyChangeListener : EventListener { + /** + * Notification that a property has changed. + *
+ * This method gets called when the observed object fires a property + * change event. + *
+ * + * @param event the property change event object describing which property + * changed and how + */ + public void propertyChange(PropertyChangeEvent event); +} diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/ISafeRunnableRunner.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/util/ISafeRunnableRunner.d Fri Mar 28 17:08:33 2008 +0100 @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2005, 2006 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: + * Chris Gross (schtoo@schtoo.com) - initial API and implementation + * (bug 49497 [RCP] JFace dependency on dwtx.core.runtime enlarges standalone JFace applications) + * Port to the D programming language: + * Frank Benoit+ * Clients may provide their own implementation to change + * how safe runnables are run from within JFace. + *
+ * + * @see SafeRunnable#getRunner() + * @see SafeRunnable#setRunner(ISafeRunnableRunner) + * @see SafeRunnable#run(ISafeRunnable) + * @since 3.1 + */ +public interface ISafeRunnableRunner { + + /** + * Runs the runnable. AllISafeRunnableRunners
must catch any exception
+ * thrown by the ISafeRunnable
and pass the exception to
+ * ISafeRunnable.handleException()
.
+ * @param code the code executed as a save runnable
+ *
+ * @see SafeRunnable#run(ISafeRunnable)
+ */
+ public abstract void run(ISafeRunnable code);
+
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/ListenerList.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/util/ListenerList.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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
+ * Note that the add
method checks for and eliminates duplicates
+ * based on identity (not equality). Likewise, the remove
method
+ * compares based on identity.
+ *
+ * Use the getListeners
method when notifying listeners. Note
+ * that no garbage is created if no listeners are registered. The recommended
+ * code sequence for notifying all registered listeners of say,
+ * FooListener.eventHappened
, is:
+ *
+ *
+ * Object[] listeners = myListenerList.getListeners(); + * for (int i = 0; i < listeners.length; ++i) { + * ((FooListener) listeners[i]).eventHappened(event); + * } + *+ * + * + * + * @deprecated Please use {@link dwtx.core.runtime.ListenerList} instead. + * Please note that the {@link #ListenerList(int)} and + * {@link dwtx.core.runtime.ListenerList#ListenerList(int)} + * constructors have different semantics. Please read the javadoc + * carefully. Also note that the equivalent of + * {@link #ListenerList()} is actually + * {@link dwtx.core.runtime.ListenerList#ListenerList(int)} + * with {@link dwtx.core.runtime.ListenerList#IDENTITY} as + * the argument. + */ +public class ListenerList : dwtx.core.runtime.ListenerList.ListenerList { + + /** + * Creates a listener list with an initial capacity of 1. + */ + public this() { + super(IDENTITY); + } + + /** + * Creates a listener list with the given initial capacity. + * + * @param capacity + * the number of listeners which this list can initially accept + * without growing its internal representation; must be at least + * 1 + */ + public this(int capacity) { + // the runtime ListenerList does not support capacity + this(); + } +} diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/OpenStrategy.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/util/OpenStrategy.d Fri Mar 28 17:08:33 2008 +0100 @@ -0,0 +1,495 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 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
+ * Usage: + *
+ * OpenStrategy handler = new OpenStrategy(control); + * handler.addOpenListener(new IOpenEventListener() { + * public void handleOpen(SelectionEvent e) { + * ... // code to handle the open event. + * } + * }); + *+ * + */ +public class OpenStrategy { + /** + * Default behavior. Double click to open the item. + */ + public static const int DOUBLE_CLICK = 0; + + /** + * Single click will open the item. + */ + public static const int SINGLE_CLICK = 1; + + /** + * Hover will select the item. + */ + public static const int SELECT_ON_HOVER = 1 << 1; + + /** + * Open item when using arrow keys + */ + public static const int ARROW_KEYS_OPEN = 1 << 2; + + /** A single click will generate + * an open event but key arrows will not do anything. + * + * @deprecated + */ + public static const int NO_TIMER = SINGLE_CLICK; + + /** A single click will generate an open + * event and key arrows will generate an open event after a + * small time. + * + * @deprecated + */ + public static const int FILE_EXPLORER = SINGLE_CLICK | ARROW_KEYS_OPEN; + + /** Pointing to an item will change the selection + * and a single click will gererate an open event + * + * @deprecated + */ + public static const int ACTIVE_DESKTOP = SINGLE_CLICK | SELECT_ON_HOVER; + + // Time used in FILE_EXPLORER and ACTIVE_DESKTOP + private static const int TIME = 500; + + /* SINGLE_CLICK or DOUBLE_CLICK; + * In case of SINGLE_CLICK, the bits SELECT_ON_HOVER and ARROW_KEYS_OPEN + * my be set as well. */ + private static int CURRENT_METHOD = DOUBLE_CLICK; + + private Listener eventHandler; + + private ListenerList openEventListeners; + + private ListenerList selectionEventListeners; + + private ListenerList postSelectionEventListeners; + + /** + * @param control the control the strategy is applied to + */ + public this(Control control) { + openEventListeners = new ListenerList(); + selectionEventListeners = new ListenerList(); + postSelectionEventListeners = new ListenerList(); + initializeHandler(control.getDisplay()); + addListener(control); + } + + /** + * Adds an IOpenEventListener to the collection of openEventListeners + * @param listener the listener to add + */ + public void addOpenListener(IOpenEventListener listener) { + openEventListeners.add(cast(Object)listener); + } + + /** + * Removes an IOpenEventListener to the collection of openEventListeners + * @param listener the listener to remove + */ + public void removeOpenListener(IOpenEventListener listener) { + openEventListeners.remove(cast(Object)listener); + } + + /** + * Adds an SelectionListener to the collection of selectionEventListeners + * @param listener the listener to add + */ + public void addSelectionListener(SelectionListener listener) { + selectionEventListeners.add(cast(Object)listener); + } + + /** + * Removes an SelectionListener to the collection of selectionEventListeners + * @param listener the listener to remove + */ + public void removeSelectionListener(SelectionListener listener) { + selectionEventListeners.remove(cast(Object)listener); + } + + /** + * Adds an SelectionListener to the collection of selectionEventListeners + * @param listener the listener to add + */ + public void addPostSelectionListener(SelectionListener listener) { + postSelectionEventListeners.add(cast(Object)listener); + } + + /** + * Removes an SelectionListener to the collection of selectionEventListeners + * @param listener the listener to remove + */ + public void removePostSelectionListener(SelectionListener listener) { + postSelectionEventListeners.remove(cast(Object)listener); + } + + /** + * This method is internal to the framework; it should not be implemented outside + * the framework. + * @return the current used single/double-click method + * + */ + public static int getOpenMethod() { + return CURRENT_METHOD; + } + + /** + * Set the current used single/double-click method. + * + * This method is internal to the framework; it should not be implemented outside + * the framework. + * @param method the method to be used + * @see OpenStrategy#DOUBLE_CLICK + * @see OpenStrategy#SINGLE_CLICK + * @see OpenStrategy#SELECT_ON_HOVER + * @see OpenStrategy#ARROW_KEYS_OPEN + */ + public static void setOpenMethod(int method) { + if (method is DOUBLE_CLICK) { + CURRENT_METHOD = method; + return; + } + if ((method & SINGLE_CLICK) is 0) { + throw new IllegalArgumentException("Invalid open mode"); //$NON-NLS-1$ + } + if ((method & (SINGLE_CLICK | SELECT_ON_HOVER | ARROW_KEYS_OPEN)) is 0) { + throw new IllegalArgumentException("Invalid open mode"); //$NON-NLS-1$ + } + CURRENT_METHOD = method; + } + + /** + * @return true if editors should be activated when opened. + */ + public static bool activateOnOpen() { + return getOpenMethod() is DOUBLE_CLICK; + } + + /* + * Adds all needed listener to the control in order to implement + * single-click/double-click strategies. + */ + private void addListener(Control c) { + c.addListener(DWT.MouseEnter, eventHandler); + c.addListener(DWT.MouseExit, eventHandler); + c.addListener(DWT.MouseMove, eventHandler); + c.addListener(DWT.MouseDown, eventHandler); + c.addListener(DWT.MouseUp, eventHandler); + c.addListener(DWT.KeyDown, eventHandler); + c.addListener(DWT.Selection, eventHandler); + c.addListener(DWT.DefaultSelection, eventHandler); + c.addListener(DWT.Collapse, eventHandler); + c.addListener(DWT.Expand, eventHandler); + } + + /* + * Fire the selection event to all selectionEventListeners + */ + private void fireSelectionEvent(SelectionEvent e) { + if (e.item !is null && e.item.isDisposed()) { + return; + } + Object l[] = selectionEventListeners.getListeners(); + for (int i = 0; i < l.length; i++) { + (cast(SelectionListener) l[i]).widgetSelected(e); + } + } + + /* + * Fire the default selection event to all selectionEventListeners + */ + private void fireDefaultSelectionEvent(SelectionEvent e) { + Object l[] = selectionEventListeners.getListeners(); + for (int i = 0; i < l.length; i++) { + (cast(SelectionListener) l[i]).widgetDefaultSelected(e); + } + } + + /* + * Fire the post selection event to all postSelectionEventListeners + */ + private void firePostSelectionEvent(SelectionEvent e) { + if (e.item !is null && e.item.isDisposed()) { + return; + } + Object l[] = postSelectionEventListeners.getListeners(); + for (int i = 0; i < l.length; i++) { + (cast(SelectionListener) l[i]).widgetSelected(e); + } + } + + /* + * Fire the open event to all openEventListeners + */ + private void fireOpenEvent(SelectionEvent e) { + if (e.item !is null && e.item.isDisposed()) { + return; + } + Object l[] = openEventListeners.getListeners(); + for (int i = 0; i < l.length; i++) { + (cast(IOpenEventListener) l[i]).handleOpen(e); + } + } + + //Initialize event handler. + private void initializeHandler( Display display_) { + eventHandler = new class() Listener { + Display display; + bool timerStarted = false; + + Event mouseUpEvent = null; + + Event mouseMoveEvent = null; + + SelectionEvent selectionPendent = null; + + bool enterKeyDown = false; + + SelectionEvent defaultSelectionPendent = null; + + bool arrowKeyDown = false; + + int[] count; + + long startTime; + + bool collapseOccurred = false; + + bool expandOccurred = false; + + this(){ + display = display_; + startTime = System.currentTimeMillis(); + count = new int[1]; + } + + public void handleEvent( Event e) { + if (e.type is DWT.DefaultSelection) { + SelectionEvent event = new SelectionEvent(e); + fireDefaultSelectionEvent(event); + if (CURRENT_METHOD is DOUBLE_CLICK) { + fireOpenEvent(event); + } else { + if (enterKeyDown) { + fireOpenEvent(event); + enterKeyDown = false; + defaultSelectionPendent = null; + } else { + defaultSelectionPendent = event; + } + } + return; + } + + switch (e.type) { + case DWT.MouseEnter: + case DWT.MouseExit: + mouseUpEvent = null; + mouseMoveEvent = null; + selectionPendent = null; + break; + case DWT.MouseMove: + if ((CURRENT_METHOD & SELECT_ON_HOVER) is 0) { + return; + } + if (e.stateMask !is 0) { + return; + } + if (e.widget.getDisplay().getFocusControl() !is e.widget) { + return; + } + mouseMoveEvent = e; + Runnable runnable = new class() Runnable { + public void run() { + long time = System.currentTimeMillis(); + int diff = cast(int) (time - startTime); + if (diff <= TIME) { + display.timerExec(diff * 2 / 3, this ); + } else { + timerStarted = false; + setSelection(mouseMoveEvent); + } + } + }; + startTime = System.currentTimeMillis(); + if (!timerStarted) { + timerStarted = true; + display.timerExec(TIME * 2 / 3, runnable ); + } + break; + case DWT.MouseDown: + mouseUpEvent = null; + arrowKeyDown = false; + break; + case DWT.Expand: + expandOccurred = true; + break; + case DWT.Collapse: + collapseOccurred = true; + break; + case DWT.MouseUp: + mouseMoveEvent = null; + if ((e.button !is 1) || ((e.stateMask & ~DWT.BUTTON1) !is 0)) { + return; + } + if (selectionPendent !is null + && !(collapseOccurred || expandOccurred)) { + mouseSelectItem(selectionPendent); + } else { + mouseUpEvent = e; + collapseOccurred = false; + expandOccurred = false; + } + break; + case DWT.KeyDown: + mouseMoveEvent = null; + mouseUpEvent = null; + arrowKeyDown = ((e.keyCode is DWT.ARROW_UP) || (e.keyCode is DWT.ARROW_DOWN)) + && e.stateMask is 0; + if (e.character is DWT.CR) { + if (defaultSelectionPendent !is null) { + fireOpenEvent(new SelectionEvent(e)); + enterKeyDown = false; + defaultSelectionPendent = null; + } else { + enterKeyDown = true; + } + } + break; + case DWT.Selection: + SelectionEvent event = new SelectionEvent(e); + fireSelectionEvent(event); + mouseMoveEvent = null; + if (mouseUpEvent !is null) { + mouseSelectItem(event); + } else { + selectionPendent = event; + } + count[0]++; + // In the case of arrowUp/arrowDown when in the arrowKeysOpen mode, we + // want to delay any selection until the last arrowDown/Up occurs. This + // handles the case where the user presses arrowDown/Up successively. + // We only want to open an editor for the last selected item. + display.asyncExec(new class() Runnable { + int id; + Event e2; + this(){ id = count[0]; e2 = e; } + public void run() { + if (arrowKeyDown) { + display.timerExec(TIME, new class() Runnable { + int id2; + Event e3; + this(){ id2 = id; e3 = e2; } + public void run() { + if (id2 is count[0]) { + firePostSelectionEvent(new SelectionEvent(e3)); + if ((CURRENT_METHOD & ARROW_KEYS_OPEN) !is 0) { + fireOpenEvent(new SelectionEvent(e3)); + } + } + } + }); + } else { + firePostSelectionEvent(new SelectionEvent(e2)); + } + } + }); + break; + } + } + + void mouseSelectItem(SelectionEvent e) { + if ((CURRENT_METHOD & SINGLE_CLICK) !is 0) { + fireOpenEvent(e); + } + mouseUpEvent = null; + selectionPendent = null; + } + + void setSelection(Event e) { + if (e is null) { + return; + } + Widget w = e.widget; + if (w.isDisposed()) { + return; + } + + SelectionEvent selEvent = new SelectionEvent(e); + + /*ISSUE: May have to create a interface with method: + setSelection(Point p) so that user's custom widgets + can use this class. If we keep this option. */ + if ( auto tree = cast(Tree)w) { + TreeItem item = tree.getItem(new Point(e.x, e.y)); + if (item !is null) { + tree.setSelection([ item ]); + } + selEvent.item = item; + } else if ( auto table = cast(Table)w) { + TableItem item = table.getItem(new Point(e.x, e.y)); + if (item !is null) { + table.setSelection([ item ]); + } + selEvent.item = item; + } else if ( auto table = cast(TableTree)w) { + TableTreeItem item = table.getItem(new Point(e.x, e.y)); + if (item !is null) { + table.setSelection([ item ]); + } + selEvent.item = item; + } else { + return; + } + if (selEvent.item is null) { + return; + } + fireSelectionEvent(selEvent); + firePostSelectionEvent(selEvent); + } + }; + } +} diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/Policy.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/util/Policy.d Fri Mar 28 17:08:33 2008 +0100 @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2004, 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 + * Chris Gross (schtoo@schtoo.com) - support for ILogger added + * (bug 49497 [RCP] JFace dependency on dwtx.core.runtime enlarges standalone JFace applications) + * Port to the D programming language: + * Frank Benoit
null
to use the default
+ * logger
+ * @since 3.1
+ */
+ public static void setLog(ILogger logger) {
+ log = logger;
+ }
+
+ /**
+ * Returns the logger used by JFace to log errors.
+ *
+ * The default logger prints the status to System.err
.
+ *
null
if this has not been set
+ * @since 3.3
+ */
+ public static ErrorSupportProvider getErrorSupportProvider() {
+ return errorSupportProvider;
+ }
+
+}
diff -r 6518c18a01f7 -r c87617952847 dwtx/jface/util/PropertyChangeEvent.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/util/PropertyChangeEvent.d Fri Mar 28 17:08:33 2008 +0100
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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 + * This concrete class was designed to be instantiated, but may + * also be subclassed if required. + *
+ *
+ * The JFace frameworks contain classes that report property
+ * change events for internal state changes that may be of interest
+ * to external parties. A special listener interface
+ * (IPropertyChangeListener
) is defined for this purpose,
+ * and a typical class allow listeners to be registered via
+ * an addPropertyChangeListener
method.
+ *
null
if
+ * not known or not relevant.
+ */
+ private Object oldValue;
+
+ /**
+ * The new value of the changed property, or null
if
+ * not known or not relevant.
+ */
+ private Object newValue;
+
+ /**
+ * Creates a new property change event.
+ *
+ * @param source the object whose property has changed
+ * @param property the property that has changed (must not be null
)
+ * @param oldValue the old value of the property, or null
if none
+ * @param newValue the new value of the property, or null
if none
+ */
+ public this(Object source, String property, Object oldValue,
+ Object newValue) {
+ super(source);
+ Assert.isTrue( property.length > 0 );
+ this.propertyName = property;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ /**
+ * Returns the new value of the property.
+ *
+ * @return the new value, or null
if not known
+ * or not relevant (for instance if the property was removed).
+ */
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ /**
+ * Returns the old value of the property.
+ *
+ * @return the old value, or null
if not known
+ * or not relevant (for instance if the property was just
+ * added and there was no old value).
+ */
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ /**
+ * Returns the name of the property that changed.
+ * + * Warning: there is no guarantee that the property name returned + * is a constant string. Callers must compare property names using + * equals, not is. + *
+ * + * @return the name of the property that changed + */ + public String getProperty() { + return propertyName; + } +}