1687 lines
63 KiB
Java
1687 lines
63 KiB
Java
|
|
/*
|
||
|
|
* Copyright (c) 2003,2009 Declarative Engineering LLC.
|
||
|
|
* All rights reserved. This program and the accompanying materials
|
||
|
|
* are made available under the terms of the Declarative Engineering LLC
|
||
|
|
* verson 1 which accompanies this distribution, and is available at
|
||
|
|
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
|
||
|
|
*/
|
||
|
|
package com.foundation.view.swt;
|
||
|
|
|
||
|
|
import org.eclipse.swt.SWT;
|
||
|
|
import org.eclipse.swt.events.KeyEvent;
|
||
|
|
import org.eclipse.swt.events.KeyListener;
|
||
|
|
import org.eclipse.swt.events.MouseEvent;
|
||
|
|
import org.eclipse.swt.events.MouseListener;
|
||
|
|
import org.eclipse.swt.graphics.Color;
|
||
|
|
import org.eclipse.swt.graphics.Font;
|
||
|
|
import org.eclipse.swt.graphics.GC;
|
||
|
|
import org.eclipse.swt.graphics.Image;
|
||
|
|
import org.eclipse.swt.graphics.Pattern;
|
||
|
|
import org.eclipse.swt.graphics.Rectangle;
|
||
|
|
import org.eclipse.swt.widgets.Composite;
|
||
|
|
import org.eclipse.swt.widgets.Control;
|
||
|
|
import org.eclipse.swt.widgets.Display;
|
||
|
|
import org.eclipse.swt.widgets.Event;
|
||
|
|
import org.eclipse.swt.widgets.Listener;
|
||
|
|
import org.eclipse.swt.widgets.Shell;
|
||
|
|
|
||
|
|
import com.common.thread.IRunnable;
|
||
|
|
import com.common.thread.Scheduler;
|
||
|
|
import com.common.util.IHashSet;
|
||
|
|
import com.common.util.IIterator;
|
||
|
|
import com.common.util.IList;
|
||
|
|
import com.common.util.LiteHashSet;
|
||
|
|
import com.common.util.LiteList;
|
||
|
|
import com.foundation.view.*;
|
||
|
|
import com.foundation.view.resource.ResourceReference;
|
||
|
|
import com.foundation.view.swt.util.SwtUtilities;
|
||
|
|
|
||
|
|
/*
|
||
|
|
* The component is the base class for all standard view components.
|
||
|
|
*/
|
||
|
|
public abstract class Component extends AbstractComponent implements KeyListener {
|
||
|
|
public static final int STYLE_BORDER = SWT.BORDER;
|
||
|
|
public static final int STYLE_LEFT_TO_RIGHT = SWT.LEFT_TO_RIGHT;
|
||
|
|
public static final int STYLE_RIGHT_TO_LEFT = SWT.RIGHT_TO_LEFT;
|
||
|
|
|
||
|
|
public static final int LINK_TARGET_IS_VISIBLE = AbstractComponent.LAST_LINK_TARGET + 1;
|
||
|
|
public static final int LINK_TARGET_IS_ENABLED = AbstractComponent.LAST_LINK_TARGET + 2;
|
||
|
|
public static final int LINK_TARGET_GAIN_FOCUS = AbstractComponent.LAST_LINK_TARGET + 3;
|
||
|
|
public static final int LINK_TARGET_TOOL_TIP_TEXT = AbstractComponent.LAST_LINK_TARGET + 4;
|
||
|
|
public static final int LINK_TARGET_BACKGROUND_COLOR = AbstractComponent.LAST_LINK_TARGET + 5;
|
||
|
|
public static final int LINK_TARGET_FOREGROUND_COLOR = AbstractComponent.LAST_LINK_TARGET + 6;
|
||
|
|
public static final int LINK_TARGET_FONT = AbstractComponent.LAST_LINK_TARGET + 7;
|
||
|
|
public static final int LAST_LINK_TARGET = AbstractComponent.LAST_LINK_TARGET + 7;
|
||
|
|
|
||
|
|
/** The reference to the popup menu. Not all components must allow a popup menu. */
|
||
|
|
private Menu menu = null;
|
||
|
|
/** The component's name. This allows lookup of components in the view by the name. */
|
||
|
|
private String name = null;
|
||
|
|
/** The resource defining the visible state for the component. */
|
||
|
|
private SingleResourceAssociation isVisible = null;
|
||
|
|
/** The resource defining the enabled state for the component. */
|
||
|
|
private SingleResourceAssociation isEnabled = null;
|
||
|
|
/** The resource defining the tool tip text for the component. */
|
||
|
|
private SingleResourceAssociation toolTipText = null;
|
||
|
|
/** The resource defining the component's background color. */
|
||
|
|
private SingleResourceAssociation backgroundColor = null;
|
||
|
|
/** The resource defining the component's foreground color. */
|
||
|
|
private SingleResourceAssociation foregroundColor = null;
|
||
|
|
/** The container's title resource which may be used in different ways depending on the context (such as a frame title, or a tab title). */
|
||
|
|
private SingleResourceAssociation containerTitle = null;
|
||
|
|
/** The container's image resource which may be used in different ways depending on the context (such as a frame icon, or a tab image). */
|
||
|
|
private SingleResourceAssociation containerImage = null;
|
||
|
|
/** The container's background image resource. */
|
||
|
|
private SingleResourceAssociation backgroundImage = null;
|
||
|
|
/** The font used by the label. */
|
||
|
|
private SingleResourceAssociation font = null;
|
||
|
|
/** The event associations for the focus gained event. */
|
||
|
|
private IHashSet gainFocusEventAssociations = null;
|
||
|
|
/** Whether the parent container has been disabled. The active enabled state for this component is: isParentEnabled && isLocallyEnabled. */
|
||
|
|
protected boolean isParentEnabled = true;
|
||
|
|
/** Whether this component has been disabled. The active enabled state for this component is: isParentEnabled && isLocallyEnabled. */
|
||
|
|
protected boolean isLocallyEnabled = true;
|
||
|
|
/** Whether the component was given a specific size and thus should not be packed. */
|
||
|
|
private boolean hasSpecificSize = false;
|
||
|
|
/** The optional decimal scale to be used by the component if it deals with decimal values. */
|
||
|
|
private Integer decimalScale = null;
|
||
|
|
/** A holder for the value of the tool tip text. */
|
||
|
|
private ResourceHolder toolTipTextHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the foreground color. */
|
||
|
|
private ResourceHolder foregroundColorHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the background color. */
|
||
|
|
private ResourceHolder backgroundColorHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the font. */
|
||
|
|
private ResourceHolder fontHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the visibility flag. */
|
||
|
|
private ResourceHolder isVisibleHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the enabled state flag. */
|
||
|
|
private ResourceHolder isEnabledHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the container title. */
|
||
|
|
private ResourceHolder containerTitleHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the container image. */
|
||
|
|
private ResourceHolder containerImageHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the background image. */
|
||
|
|
private ResourceHolder backgroundImageHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the change notification image. */
|
||
|
|
private Object changeImage = null;
|
||
|
|
/** A holder for the value of the change notification text. */
|
||
|
|
private Object changeText = null;
|
||
|
|
/** A holder for the value of the update notification image. */
|
||
|
|
private Object updateImage = null;
|
||
|
|
/** A holder for the value of the update notification text. */
|
||
|
|
private Object updateText = null;
|
||
|
|
/** A holder for the value of the update notification timeout. */
|
||
|
|
private Integer updateTimeout = null;
|
||
|
|
/** The task used to remove the update decoration. */
|
||
|
|
private UpdateControlDecorationRemovalTask updateControlDecorationRemovalTask = null;
|
||
|
|
/** The currently displayed control decoration notifying the user that the value in the control has been updated. */
|
||
|
|
private ControlDecoration updateControlDecoration = null;
|
||
|
|
/** The swt image used by the container of this component to represent the component. */
|
||
|
|
private Image swtContainerImage = null;
|
||
|
|
/** The set of key bindings in search order. */
|
||
|
|
private IList keyBindings = null;
|
||
|
|
/** The swt image used by the component as the background. This overrides the background gradient. */
|
||
|
|
private Image currentBackgroundImage = null;
|
||
|
|
/** The gradient to be used for the background image, or null if none is to be used. */
|
||
|
|
private JefGradient currentBackgroundGradient = null;
|
||
|
|
/** The gradient to be used for the background image, or null if none is to be used. */
|
||
|
|
private Image currentBackgroundGradientImage = null;
|
||
|
|
/** The currently active background color (if using a solid color - versus a gradient). This is used to ensure that the correct color is destroyed when cleaning up. */
|
||
|
|
private Color currentBackgroundColor = null;
|
||
|
|
/** The currently active foreground color. This is used to ensure that the correct color is destroyed when cleaning up. */
|
||
|
|
private Color currentForegroundColor = null;
|
||
|
|
/** The currently active font. This is used to ensure that the correct font is destroyed when cleaning up. */
|
||
|
|
private Font currentFont = null;
|
||
|
|
/** Whether the initialization routine has completed. */
|
||
|
|
//private boolean isInitializationComplete = false;
|
||
|
|
/** The listener for the resize event that refreshes the background image. */
|
||
|
|
private Listener backgroundImageResizeListener = null;
|
||
|
|
/** Whether the control should render a custom background. */
|
||
|
|
private boolean useCustomBackground = false;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Encapsulates the images used by the overlay rendering (utilized when the component is a composite and has no background but does have a background color).
|
||
|
|
*/
|
||
|
|
private static class OverlayBufferSet {
|
||
|
|
public Image originalImage = null;
|
||
|
|
public Image bufferImage = null;
|
||
|
|
}//OverlayBufferSet//
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The task used to remove stale updated decorations on controls.
|
||
|
|
*/
|
||
|
|
private class UpdateControlDecorationRemovalTask implements Runnable {
|
||
|
|
public UpdateControlDecorationRemovalTask() {
|
||
|
|
Integer timeout = getUpdateDecorationTimeout();
|
||
|
|
|
||
|
|
getSwtControl().getDisplay().timerExec(timeout == null || timeout.intValue() <= 0 ? 10000 : timeout.intValue(), this);
|
||
|
|
}//UpdateControlDecorationRemovalTask()//
|
||
|
|
public void reset() {
|
||
|
|
Integer timeout = getUpdateDecorationTimeout();
|
||
|
|
|
||
|
|
getSwtControl().getDisplay().timerExec(timeout == null || timeout.intValue() <= 0 ? 10000 : timeout.intValue(), this);
|
||
|
|
}//reset()//
|
||
|
|
public void run() {
|
||
|
|
if(updateControlDecoration != null && updateControlDecorationRemovalTask == UpdateControlDecorationRemovalTask.this && !getSwtControl().isDisposed()) {
|
||
|
|
removeDecoration(updateControlDecoration);
|
||
|
|
updateControlDecoration = null;
|
||
|
|
updateControlDecorationRemovalTask = null;
|
||
|
|
}//if//
|
||
|
|
}//evaluate()//
|
||
|
|
}//UpdateControlDecorationRemovalTask//
|
||
|
|
|
||
|
|
/**
|
||
|
|
* A listener interface so that other interested components can get notification when the tool tip text is altered.
|
||
|
|
*/
|
||
|
|
public interface IComponentListener {
|
||
|
|
/**
|
||
|
|
* Notifies the listener when the component's tool tip has been altered.
|
||
|
|
* @param component The component whose tool tip was modified.
|
||
|
|
* @param newToolTipText The new tool tip.
|
||
|
|
*/
|
||
|
|
public void toolTipTextChanged(Component component, String newToolTipText);
|
||
|
|
/**
|
||
|
|
* Notifies the listener when the container's title is altered.
|
||
|
|
* @param component The component whose title was modified.
|
||
|
|
* @param newTitle The new title.
|
||
|
|
*/
|
||
|
|
public void titleChanged(Component component, String newTitle);
|
||
|
|
/**
|
||
|
|
* Notifies the listener when the container's image is altered.
|
||
|
|
* @param component The component whose image was modified.
|
||
|
|
* @param newImage The new image.
|
||
|
|
*/
|
||
|
|
public void imageChanged(Component component, Image newImage);
|
||
|
|
}//IComponentListener//
|
||
|
|
/**
|
||
|
|
* Component default constructor.
|
||
|
|
* <p>Warning: This is only for use by the framework. This should never be called to create a useable instance.</p>
|
||
|
|
*/
|
||
|
|
public Component() {
|
||
|
|
}//Component()//
|
||
|
|
/**
|
||
|
|
* Component constructor.
|
||
|
|
* <p>WARNING: The super class <b>must</b> call <code>setSwtControl(org.eclipse.swt.widgets.Control)</code> after setting up the native control.
|
||
|
|
* @param parent The parent container for this container.
|
||
|
|
* @param name The component's name. This allows lookup of components in the view by the name.
|
||
|
|
* @param style The component's style.
|
||
|
|
*/
|
||
|
|
public Component(IAbstractContainer parent, String name, int style) {
|
||
|
|
super(parent, style);
|
||
|
|
|
||
|
|
this.name = name;
|
||
|
|
initialize();
|
||
|
|
|
||
|
|
if(parent != null) {
|
||
|
|
parent.addComponent(this);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if((style & SWT.NO_BACKGROUND) > 0) {
|
||
|
|
useCustomBackground = true;
|
||
|
|
}//if//
|
||
|
|
}//Component()//
|
||
|
|
/**
|
||
|
|
* Component constructor.
|
||
|
|
* <p>WARNING: The super class <b>must</b> call <code>setSwtControl(org.eclipse.swt.widgets.Control)</code> after setting up the native control.
|
||
|
|
* @param parent The parent container for this container.
|
||
|
|
* @param name The component's name. This allows lookup of components in the view by the name.
|
||
|
|
* @param viewContext The context under which this view component operates. For all but the outer most control this can be null.
|
||
|
|
* @param style The component's style.
|
||
|
|
* @param data The optional data passed to the initializeControl(int, java.lang.Object) method.
|
||
|
|
*/
|
||
|
|
public Component(IAbstractContainer parent, String name, IViewContext viewContext, int style, Object data) {
|
||
|
|
super(parent, viewContext, style, data);
|
||
|
|
|
||
|
|
this.name = name;
|
||
|
|
initialize();
|
||
|
|
|
||
|
|
if(parent != null) {
|
||
|
|
parent.addComponent(this);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if((style & SWT.NO_BACKGROUND) > 0) {
|
||
|
|
useCustomBackground = true;
|
||
|
|
}//if//
|
||
|
|
}//Component()//
|
||
|
|
/**
|
||
|
|
* Initializes the component.
|
||
|
|
* <p>Note: This is separated so that a view can be instantiated via the default constructor for the purpose of determining the reflection metadata associated with the view. Any other call to the default constructor will create an invalid view.</p>
|
||
|
|
*/
|
||
|
|
private void initialize() {
|
||
|
|
isVisible = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_BOOLEAN, false, getDefaultVisibility() ? Boolean.TRUE : Boolean.FALSE);
|
||
|
|
isEnabled = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_BOOLEAN, false, Boolean.TRUE);
|
||
|
|
toolTipText = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_TEXT, false, null);
|
||
|
|
backgroundColor = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_GRADIENT, false, null);
|
||
|
|
foregroundColor = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_COLOR, false, null);
|
||
|
|
font = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_FONT, false, null);
|
||
|
|
containerTitle = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_TEXT, false, "");
|
||
|
|
containerImage = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_IMAGE, false, null);
|
||
|
|
backgroundImage = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_IMAGE, false, null);
|
||
|
|
}//initialize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#getShell()
|
||
|
|
*/
|
||
|
|
public Shell getShell() {
|
||
|
|
return getSwtControl() != null && !getSwtControl().isDisposed() ? getSwtControl().getShell() : null;
|
||
|
|
}//getShell()//
|
||
|
|
/**
|
||
|
|
* Stops the component's rendering until the startRendering() method is called.
|
||
|
|
* This method tracks the number of times it is called. You must call start for each stop call.
|
||
|
|
*/
|
||
|
|
public void stopRendering() {
|
||
|
|
//getSwtControl().setRedraw(false);
|
||
|
|
}//stopRendering()//
|
||
|
|
/**
|
||
|
|
* Starts the component's rendering.
|
||
|
|
* This method tracks the number of times it is called. You must call start for each stop call.
|
||
|
|
*/
|
||
|
|
public void startRendering() {
|
||
|
|
//getSwtControl().setRedraw(true);
|
||
|
|
}//startRendering()//
|
||
|
|
/**
|
||
|
|
* TODO: Is this code necessary?
|
||
|
|
*/
|
||
|
|
public void redraw() {
|
||
|
|
//getSwtControl().redraw();
|
||
|
|
}//redraw()//
|
||
|
|
/**
|
||
|
|
* Gets the window which contains this component.
|
||
|
|
* @return The window containing this component.
|
||
|
|
*/
|
||
|
|
public Window getContainingWindow() {
|
||
|
|
Component next = this;
|
||
|
|
|
||
|
|
while((next != null) && (!(next instanceof Window))) {
|
||
|
|
next = (Component) next.getContainer();
|
||
|
|
}//while//
|
||
|
|
|
||
|
|
return (Window) next;
|
||
|
|
}//getContainingWindow()//
|
||
|
|
/**
|
||
|
|
* Gets whether the component is visible by default.
|
||
|
|
* @return Whether or not the components implementation is visible by default.
|
||
|
|
*/
|
||
|
|
protected boolean getDefaultVisibility() {
|
||
|
|
return true;
|
||
|
|
}//getDefaultVisibility()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.IDecoration#getMenuBar()
|
||
|
|
*/
|
||
|
|
public Menu getMenu() {
|
||
|
|
verifyThread();
|
||
|
|
|
||
|
|
return menu;
|
||
|
|
}//getMenuBar()//
|
||
|
|
/**
|
||
|
|
* Sets the component's popup or floating menu.
|
||
|
|
* @param menu The normally hidden menu that appears based on user interaction (usually a right click on a windows system).
|
||
|
|
*/
|
||
|
|
public void setMenu(Menu menu) {
|
||
|
|
verifyThread();
|
||
|
|
|
||
|
|
if(isInitialized() && this.menu != null) {
|
||
|
|
this.menu.internalViewReleaseAll();
|
||
|
|
getSwtControl().setMenu(null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
this.menu = menu;
|
||
|
|
|
||
|
|
if((isInitialized()) && (menu != null)) {
|
||
|
|
menu.internalViewInitializeAll();
|
||
|
|
getSwtControl().setMenu(menu.getSwtMenu());
|
||
|
|
}//if//
|
||
|
|
}//setMenu()//
|
||
|
|
/**
|
||
|
|
* Gets the component's name.
|
||
|
|
* @return The name of this component.
|
||
|
|
*/
|
||
|
|
public String getName() {
|
||
|
|
return name;
|
||
|
|
}//getName()//
|
||
|
|
/**
|
||
|
|
* Gets the widget encapsulated by this component.
|
||
|
|
* @return The encapsulated widget, or null if this component does not have a viewable element.
|
||
|
|
*/
|
||
|
|
public Control getSwtControl() {
|
||
|
|
return (Control) getSwtWidget();
|
||
|
|
}//getSwtControl()//
|
||
|
|
/**
|
||
|
|
* Sets the layout data for the component.
|
||
|
|
* @param layoutData The data that describes how the component is to be layed out within its parent.
|
||
|
|
*/
|
||
|
|
public void setLayoutData(Object layoutData) {
|
||
|
|
verifyThread();
|
||
|
|
getSwtControl().setLayoutData(layoutData);
|
||
|
|
resize();
|
||
|
|
}//setLayoutData()//
|
||
|
|
/**
|
||
|
|
* Sets the component bounds.
|
||
|
|
* @param x The upper left point's X coordinate.
|
||
|
|
* @param y The upper left point's Y coordinate.
|
||
|
|
* @param width The number of pixels of width.
|
||
|
|
* @param height The number of pixels of height.
|
||
|
|
*/
|
||
|
|
public void setBounds(int x, int y, int width, int height) {
|
||
|
|
verifyThread();
|
||
|
|
getSwtControl().setBounds(x, y, width, height);
|
||
|
|
hasSpecificSize = true;
|
||
|
|
resize();
|
||
|
|
}//setBounds()//
|
||
|
|
/**
|
||
|
|
* Sets the component's location.
|
||
|
|
* @param x The upper left point's X coordinate.
|
||
|
|
* @param y The upper left point's Y coordinate.
|
||
|
|
*/
|
||
|
|
public void setLocation(int x, int y) {
|
||
|
|
verifyThread();
|
||
|
|
getSwtControl().setLocation(x, y);
|
||
|
|
resize();
|
||
|
|
}//setLocation()//
|
||
|
|
/**
|
||
|
|
* Sets the component's size.
|
||
|
|
* @param width The number of pixels of width.
|
||
|
|
* @param height The number of pixels of height.
|
||
|
|
*/
|
||
|
|
public void setSize(int width, int height) {
|
||
|
|
verifyThread();
|
||
|
|
getSwtControl().setSize(width, height);
|
||
|
|
hasSpecificSize = true;
|
||
|
|
resize();
|
||
|
|
}//setSize()//
|
||
|
|
/**
|
||
|
|
* Sets the focus to be on this component.
|
||
|
|
*/
|
||
|
|
public void setFocus() {
|
||
|
|
getSwtControl().setFocus();
|
||
|
|
}//setFocus()//
|
||
|
|
/**
|
||
|
|
* Sets the association container for the gain focus event.
|
||
|
|
* @param association The association.
|
||
|
|
*/
|
||
|
|
public void addGainFocusEventAssociation(IEventAssociation association) {
|
||
|
|
if(gainFocusEventAssociations == null) {
|
||
|
|
gainFocusEventAssociations = new LiteHashSet(4);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
association.setChangeListener(this);
|
||
|
|
gainFocusEventAssociations.add(association);
|
||
|
|
|
||
|
|
if(isInitialized()) {
|
||
|
|
association.register();
|
||
|
|
}//if//
|
||
|
|
}//setGainFocusEventAssociation()//
|
||
|
|
/**
|
||
|
|
* Adds a key binding to the component.
|
||
|
|
* @param keyBinding The key binding which will be notified when the key combination occurs.
|
||
|
|
*/
|
||
|
|
public void addKeyBinding(IKeyBinding keyBinding) {
|
||
|
|
if(keyBindings == null) {
|
||
|
|
keyBindings = new LiteList(10, 40);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
keyBindings.add(keyBinding);
|
||
|
|
|
||
|
|
if(isInitialized()) {
|
||
|
|
if(keyBindings.getSize() == 1) {
|
||
|
|
getSwtControl().addKeyListener(this);
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
}//addKeyBinding()//
|
||
|
|
/**
|
||
|
|
* Gets the change decoration text by recursively navigating the component hierarchy searching for text that was set by the view.
|
||
|
|
* @return The change decoration's text resource reference or actual text.
|
||
|
|
*/
|
||
|
|
public Object getChangeDecorationText() {
|
||
|
|
return changeText != null ? changeText : getContainer() instanceof Component ? ((Component) getContainer()).getChangeDecorationText() : null;
|
||
|
|
}//getChangeDecorationText()//
|
||
|
|
/**
|
||
|
|
* Gets the change decoration image by recursively navigating the component hierarchy searching for an image that was set by the view.
|
||
|
|
* @return The change decoration's resource reference.
|
||
|
|
*/
|
||
|
|
public Object getChangeDecorationImage() {
|
||
|
|
return changeImage != null ? changeImage : getContainer() instanceof Component ? ((Component) getContainer()).getChangeDecorationImage() : null;
|
||
|
|
}//getChangeDecorationImage()//
|
||
|
|
/**
|
||
|
|
* Gets the ControlDecoration for displaying a change in the data.
|
||
|
|
* @return The decoration used to display a data change or null if not enough data was provided.
|
||
|
|
*/
|
||
|
|
public ControlDecoration getChangeControlDecoration() {
|
||
|
|
Object text = getChangeDecorationText();
|
||
|
|
Object image = getChangeDecorationImage();
|
||
|
|
|
||
|
|
return image != null ? new ControlDecoration(image, text) : null;
|
||
|
|
}//getChangeControlDecoration()//
|
||
|
|
/**
|
||
|
|
* Gets the update decoration text by recursively navigating the component hierarchy searching for text that was set by the view.
|
||
|
|
* @return The update decoration's text resource reference or actual text.
|
||
|
|
*/
|
||
|
|
public Object getUpdateDecorationText() {
|
||
|
|
return updateText != null ? updateText : getContainer() instanceof Component ? ((Component) getContainer()).getUpdateDecorationText() : null;
|
||
|
|
}//getUpdateDecorationText()//
|
||
|
|
/**
|
||
|
|
* Gets the update decoration image by recursively navigating the component hierarchy searching for an image that was set by the view.
|
||
|
|
* @return The update decoration's resource reference.
|
||
|
|
*/
|
||
|
|
public Object getUpdateDecorationImage() {
|
||
|
|
return updateImage != null ? updateImage : getContainer() instanceof Component ? ((Component) getContainer()).getUpdateDecorationImage() : null;
|
||
|
|
}//getUpdateDecorationImage()//
|
||
|
|
/**
|
||
|
|
* Gets the update decoration timeout by recursively navigating the component hierarchy searching for timeout that was set by the view.
|
||
|
|
* @return The update decoration's timeout resource reference or actual timeout.
|
||
|
|
*/
|
||
|
|
public Integer getUpdateDecorationTimeout() {
|
||
|
|
return updateTimeout != null ? updateTimeout : getContainer() instanceof Component ? ((Component) getContainer()).getUpdateDecorationTimeout() : null;
|
||
|
|
}//getUpdateDecorationTimeout()//
|
||
|
|
/**
|
||
|
|
* Gets the ControlDecoration for displaying an update of the data.
|
||
|
|
* <p>Note: This differs from the change control decoration in that the user has not made any local changes.</p>
|
||
|
|
* @return The decoration used to display a data update or null if not enough data was provided.
|
||
|
|
*/
|
||
|
|
public ControlDecoration getUpdateControlDecoration() {
|
||
|
|
Object text = getUpdateDecorationText();
|
||
|
|
Object image = getUpdateDecorationImage();
|
||
|
|
|
||
|
|
return image != null ? new ControlDecoration(image, text) : null;
|
||
|
|
}//getUpdateControlDecoration()//
|
||
|
|
/**
|
||
|
|
* Displays the update control decoration.
|
||
|
|
*/
|
||
|
|
public void displayUpdateControlDecoration() {
|
||
|
|
if(updateControlDecoration != null) {
|
||
|
|
updateControlDecorationRemovalTask.reset();
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
updateControlDecoration = getUpdateControlDecoration();
|
||
|
|
updateControlDecorationRemovalTask = new UpdateControlDecorationRemovalTask();
|
||
|
|
|
||
|
|
if(updateControlDecoration != null) {
|
||
|
|
Control control = addDecoration(updateControlDecoration);
|
||
|
|
|
||
|
|
if(control != null) {
|
||
|
|
control.addMouseListener(new MouseListener() {
|
||
|
|
public void mouseUp(MouseEvent e) {
|
||
|
|
}//mouseUp()//
|
||
|
|
public void mouseDown(MouseEvent e) {
|
||
|
|
removeDecoration(updateControlDecoration);
|
||
|
|
updateControlDecoration = null;
|
||
|
|
}//mouseDown()//
|
||
|
|
public void mouseDoubleClick(MouseEvent e) {
|
||
|
|
}//mouseDoubleClick()//
|
||
|
|
});
|
||
|
|
}//if//
|
||
|
|
//TODO: Add a holder, implement the useage of the timer.
|
||
|
|
//if(updateTimeout > 0) {
|
||
|
|
|
||
|
|
//}//if//
|
||
|
|
}//if//
|
||
|
|
}//else//
|
||
|
|
}//displayUpdateControlDecoration()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access whether the control is enabled.
|
||
|
|
* @param container The enabled state association metadata.
|
||
|
|
*/
|
||
|
|
public void setIsEnabledAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.isEnabled.setAssociations(container);
|
||
|
|
}//setIsEnabledAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access whether the control is visible.
|
||
|
|
* @param container The visible state association metadata.
|
||
|
|
*/
|
||
|
|
public void setIsVisibleAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.isVisible.setAssociations(container);
|
||
|
|
}//setIsVisibleAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the foreground color.
|
||
|
|
* @param container The forground color association metadata.
|
||
|
|
*/
|
||
|
|
public void setForegroundColorAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.foregroundColor.setAssociations(container);
|
||
|
|
}//setForegroundColorAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the background color.
|
||
|
|
* @param container The background color association metadata.
|
||
|
|
*/
|
||
|
|
public void setBackgroundColorAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.backgroundColor.setAssociations(container);
|
||
|
|
}//setBackgroundColorAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the font.
|
||
|
|
* @param container The font association metadata.
|
||
|
|
*/
|
||
|
|
public void setFontAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.font.setAssociations(container);
|
||
|
|
}//setFontAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the tool tip text.
|
||
|
|
* @param container The tool tip association metadata.
|
||
|
|
*/
|
||
|
|
public void setToolTipTextAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.toolTipText.setAssociations(container);
|
||
|
|
}//setToolTipTextAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the title.
|
||
|
|
* @param container The title association metadata.
|
||
|
|
*/
|
||
|
|
public void setContainerTitleAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.containerTitle.setAssociations(container);
|
||
|
|
}//setContainerTitleAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the image.
|
||
|
|
* @param container The image association metadata.
|
||
|
|
*/
|
||
|
|
public void setContainerImageAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.containerImage.setAssociations(container);
|
||
|
|
}//setContainerImageAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets whether the component is visible.
|
||
|
|
* @param isVisible Whether the user can see the component.
|
||
|
|
*/
|
||
|
|
public void setIsVisible(boolean isVisible) {
|
||
|
|
verifyThread();
|
||
|
|
this.isVisible.externalSetValue(isVisible ? Boolean.TRUE : Boolean.FALSE);
|
||
|
|
}//setIsVisible()//
|
||
|
|
/**
|
||
|
|
* Sets the enabled state.
|
||
|
|
* @param isEnabled Whether the user can interact with the component.
|
||
|
|
*/
|
||
|
|
public void setIsEnabled(boolean isEnabled) {
|
||
|
|
verifyThread();
|
||
|
|
this.isEnabled.externalSetValue(isEnabled ? Boolean.TRUE : Boolean.FALSE);
|
||
|
|
}//setIsEnabled()//
|
||
|
|
/**
|
||
|
|
* Sets the default enabled state.
|
||
|
|
* @param isEnabled Whether the user can interact with the component if no other value is provided.
|
||
|
|
*/
|
||
|
|
public void setDefaultIsEnabled(boolean isEnabled) {
|
||
|
|
verifyThread();
|
||
|
|
this.isEnabled.setDefaultValue(isEnabled ? Boolean.TRUE : Boolean.FALSE);
|
||
|
|
}//setDefaultIsEnabled()//
|
||
|
|
/**
|
||
|
|
* Sets the default enabled state resource.
|
||
|
|
* @param isEnabled Whether the user can interact with the component if no other value is provided.
|
||
|
|
*/
|
||
|
|
public void setDefaultIsEnabled(ResourceReference isEnabled) {
|
||
|
|
verifyThread();
|
||
|
|
this.isEnabled.setDefaultValue(isEnabled);
|
||
|
|
}//setDefaultIsEnabled()//
|
||
|
|
/**
|
||
|
|
* Sets the default visibility.
|
||
|
|
* @param isVisible Whether the user can see the component if no other value is provided.
|
||
|
|
*/
|
||
|
|
public void setDefaultIsVisible(boolean isVisible) {
|
||
|
|
verifyThread();
|
||
|
|
this.isVisible.setDefaultValue(isVisible ? Boolean.TRUE : Boolean.FALSE);
|
||
|
|
}//setDefaultIsVisible()//
|
||
|
|
/**
|
||
|
|
* Sets the default visibility resource.
|
||
|
|
* @param isVisible Whether the user can see the component if no other value is provided.
|
||
|
|
*/
|
||
|
|
public void setDefaultIsVisible(ResourceReference isVisible) {
|
||
|
|
verifyThread();
|
||
|
|
this.isVisible.setDefaultValue(isVisible);
|
||
|
|
}//setDefaultIsVisible()//
|
||
|
|
/**
|
||
|
|
* Gets the component's current tool tip text.
|
||
|
|
* @return The tool tip text displayed by this component.
|
||
|
|
*/
|
||
|
|
protected String getToolTipText() {
|
||
|
|
return (String) this.toolTipText.getValue();
|
||
|
|
}//getToolTipText()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default tool tip text.
|
||
|
|
* @param toolTipText The tool tip text to be displayed by this component.
|
||
|
|
*/
|
||
|
|
public void setDefaultToolTipText(String toolTipText) {
|
||
|
|
verifyThread();
|
||
|
|
this.toolTipText.setDefaultValue(toolTipText);
|
||
|
|
}//setDefaultToolTipText()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default tool tip text resource.
|
||
|
|
* @param tooltipText The tool tip text to be displayed by this component.
|
||
|
|
*/
|
||
|
|
public void setDefaultToolTipText(ResourceReference toolTipText) {
|
||
|
|
verifyThread();
|
||
|
|
this.toolTipText.setDefaultValue(toolTipText);
|
||
|
|
}//setDefaultToolTipText()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default background color.
|
||
|
|
* @param backgroundColor The default background color.
|
||
|
|
*/
|
||
|
|
public void setDefaultBackgroundColor(JefGradient backgroundColor) {
|
||
|
|
verifyThread();
|
||
|
|
this.backgroundColor.setDefaultValue(backgroundColor);
|
||
|
|
}//setDefaultBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default background color resource.
|
||
|
|
* @param backgroundColor The default background color resource.
|
||
|
|
*/
|
||
|
|
public void setDefaultBackgroundColor(ResourceReference backgroundColor) {
|
||
|
|
verifyThread();
|
||
|
|
this.backgroundColor.setDefaultValue(backgroundColor);
|
||
|
|
}//setDefaultBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default foreground color.
|
||
|
|
* @param foregroundColor The default foreground color.
|
||
|
|
*/
|
||
|
|
public void setDefaultForegroundColor(JefColor foregroundColor) {
|
||
|
|
verifyThread();
|
||
|
|
this.foregroundColor.setDefaultValue(foregroundColor);
|
||
|
|
}//setDefaultForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default foreground color resource.
|
||
|
|
* @param foregroundColor The default foreground color resource.
|
||
|
|
*/
|
||
|
|
public void setDefaultForegroundColor(ResourceReference foregroundColor) {
|
||
|
|
verifyThread();
|
||
|
|
this.foregroundColor.setDefaultValue(foregroundColor);
|
||
|
|
}//setDefaultForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the default font.
|
||
|
|
* @param font The default font.
|
||
|
|
*/
|
||
|
|
public void setDefaultFont(JefFont[] font) {
|
||
|
|
verifyThread();
|
||
|
|
this.font.setDefaultValue(font);
|
||
|
|
}//setDefaultFont()//
|
||
|
|
/**
|
||
|
|
* Sets the default font resource.
|
||
|
|
* @param font The default font resource.
|
||
|
|
*/
|
||
|
|
public void setDefaultFont(ResourceReference font) {
|
||
|
|
verifyThread();
|
||
|
|
this.font.setDefaultValue(font);
|
||
|
|
}//setDefaultFont()//
|
||
|
|
/**
|
||
|
|
* Sets the change decoration image.
|
||
|
|
* @param image The image to use for the change decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultChangeImage(JefImage image) {
|
||
|
|
verifyThread();
|
||
|
|
changeImage = image;
|
||
|
|
}//setDefaultChangeImage()//
|
||
|
|
/**
|
||
|
|
* Sets the change decoration image.
|
||
|
|
* @param image The image to use for the change decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultChangeImage(ResourceReference image) {
|
||
|
|
verifyThread();
|
||
|
|
changeImage = image;
|
||
|
|
}//setDefaultChangeImage()//
|
||
|
|
/**
|
||
|
|
* Sets the change decoration text.
|
||
|
|
* @param text The text to use for the change decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultChangeText(String text) {
|
||
|
|
verifyThread();
|
||
|
|
changeText = text;
|
||
|
|
}//setDefaultChangeImage()//
|
||
|
|
/**
|
||
|
|
* Sets the change decoration text.
|
||
|
|
* @param text The text to use for the change decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultChangeText(ResourceReference text) {
|
||
|
|
verifyThread();
|
||
|
|
changeText = text;
|
||
|
|
}//setDefaultChangeText()//
|
||
|
|
/**
|
||
|
|
* Sets the update decoration text.
|
||
|
|
* @param text The text to use for the update decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultUpdateText(String text) {
|
||
|
|
verifyThread();
|
||
|
|
updateText = text;
|
||
|
|
}//setDefaultUpdateImage()//
|
||
|
|
/**
|
||
|
|
* Sets the update decoration text.
|
||
|
|
* @param text The text to use for the update decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultUpdateText(ResourceReference text) {
|
||
|
|
verifyThread();
|
||
|
|
updateText = text;
|
||
|
|
}//setDefaultUpdateText()//
|
||
|
|
/**
|
||
|
|
* Sets the update decoration image.
|
||
|
|
* @param image The image to use for the update decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultUpdateImage(JefImage image) {
|
||
|
|
verifyThread();
|
||
|
|
updateImage = image;
|
||
|
|
}//setDefaultUpdateImage()//
|
||
|
|
/**
|
||
|
|
* Sets the update decoration image.
|
||
|
|
* @param image The image to use for the update decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultUpdateImage(ResourceReference image) {
|
||
|
|
verifyThread();
|
||
|
|
updateImage = image;
|
||
|
|
}//setDefaultUpdateImage()//
|
||
|
|
/**
|
||
|
|
* Sets the timeout for the update decoration.
|
||
|
|
* @param updateTimeout The number of seconds before removing the update decoration.
|
||
|
|
*/
|
||
|
|
public void setDefaultUpdateTimeout(Integer updateTimeout) {
|
||
|
|
verifyThread();
|
||
|
|
this.updateTimeout = updateTimeout;
|
||
|
|
}//setDefaultUpdateTimeout()//
|
||
|
|
/**
|
||
|
|
* Gets the optional decimal scale to be used by the component if it deals with decimal values.
|
||
|
|
* @return The optional decimal scale which if negative by default should trim extra zeros (note that BigDecimal does not automatically do this).
|
||
|
|
*/
|
||
|
|
public Integer getDecimalScale() {
|
||
|
|
verifyThread();
|
||
|
|
return decimalScale;
|
||
|
|
}//getDecimalScale()//
|
||
|
|
/**
|
||
|
|
* Sets the optional decimal scale to be used by the component if it deals with decimal values.
|
||
|
|
* @param decimalScale The optional decimal scale which if negative by default should trim extra zeros (note that BigDecimal does not automatically do this).
|
||
|
|
*/
|
||
|
|
public void setDecimalScale(Integer decimalScale) {
|
||
|
|
verifyThread();
|
||
|
|
this.decimalScale = decimalScale;
|
||
|
|
}//setDecimalScale()//
|
||
|
|
/**
|
||
|
|
* Gets the container's title.
|
||
|
|
* <p>Note: Also see IComponentListener and addListener(..) to receive notification when the title changes.</p>
|
||
|
|
* @return The container's title to be used when needed (example: a tab in a tab panel, or title bar of the window).
|
||
|
|
*/
|
||
|
|
public String getContainerTitle() {
|
||
|
|
verifyThread();
|
||
|
|
return (String) this.containerTitle.getValue();
|
||
|
|
}//setContainerTitle()//
|
||
|
|
/**
|
||
|
|
* Sets the container's title.
|
||
|
|
* @param title The container's title to be used when needed (example: a tab in a tab panel, or title bar of the window).
|
||
|
|
*/
|
||
|
|
public void setDefaultContainerTitle(String title) {
|
||
|
|
verifyThread();
|
||
|
|
this.containerTitle.setDefaultValue(title);
|
||
|
|
}//setDefaultContainerTitle()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default title resource.
|
||
|
|
* @param title The title to be displayed by this component.
|
||
|
|
*/
|
||
|
|
public void setDefaultContainerTitle(ResourceReference title) {
|
||
|
|
verifyThread();
|
||
|
|
this.containerTitle.setDefaultValue(title);
|
||
|
|
}//setDefaultContainerTitle()//
|
||
|
|
/**
|
||
|
|
* Gets the container's image.
|
||
|
|
* <p>Note: Also see IComponentListener and addListener(..) to receive notification when the title changes.</p>
|
||
|
|
* @return The image data that will be displayed by the container when an image is needed to represent it (example: a tab in a tab panel).
|
||
|
|
*/
|
||
|
|
public Image getContainerImage() {
|
||
|
|
return swtContainerImage;
|
||
|
|
}//getContainerImage()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default image resource.
|
||
|
|
* @param image The image to be displayed by this component.
|
||
|
|
*/
|
||
|
|
public void setDefaultContainerImage(ResourceReference image) {
|
||
|
|
verifyThread();
|
||
|
|
this.containerImage.setDefaultValue(image);
|
||
|
|
}//setDefaultContainerImage()//
|
||
|
|
/**
|
||
|
|
* Sets the container's default image.
|
||
|
|
* @param image The image data that will be displayed by the container when an image is needed to represent it (example: a tab in a tab panel).
|
||
|
|
*/
|
||
|
|
public void setDefaultContainerImage(JefImage image) {
|
||
|
|
verifyThread();
|
||
|
|
this.containerImage.setDefaultValue(image);
|
||
|
|
}//setDefaultContainerImage()//
|
||
|
|
/**
|
||
|
|
* Sets the component background image.
|
||
|
|
* @param image The image to be displayed by the component in the background.
|
||
|
|
*/
|
||
|
|
public void setDefaultBackgroundImage(JefImage image) {
|
||
|
|
verifyThread();
|
||
|
|
this.backgroundImage.setDefaultValue(image);
|
||
|
|
}//setDefaultBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Sets the component's background image resource.
|
||
|
|
* @param image The image to be displayed by this component in the background.
|
||
|
|
*/
|
||
|
|
public void setDefaultBackgroundImage(ResourceReference image) {
|
||
|
|
verifyThread();
|
||
|
|
this.backgroundImage.setDefaultValue(image);
|
||
|
|
}//setDefaultBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Sets an association container used to access the background image.
|
||
|
|
* @param container The image association metadata.
|
||
|
|
*/
|
||
|
|
public void setBackgroundImageAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.backgroundImage.setAssociations(container);
|
||
|
|
}//setBackgroundImageAssociation()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewRefresh()
|
||
|
|
*/
|
||
|
|
protected void internalViewRefresh() {
|
||
|
|
internalViewRefreshIsVisible();
|
||
|
|
internalViewRefreshIsEnabled();
|
||
|
|
internalViewRefreshToolTipText();
|
||
|
|
internalViewRefreshBackgroundColor();
|
||
|
|
internalViewRefreshForegroundColor();
|
||
|
|
internalViewRefreshFont();
|
||
|
|
internalViewRefreshContainerTitle();
|
||
|
|
internalViewRefreshContainerImage();
|
||
|
|
internalViewRefreshBackgroundImage();
|
||
|
|
}//internalViewRefresh()//
|
||
|
|
/**
|
||
|
|
* Refreshes whether the component is enabled based on the attribute value or if null the default flag value.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshIsEnabled() {
|
||
|
|
if(isEnabled.refresh()) {
|
||
|
|
isEnabledHolder.setValue(isEnabled.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshIsEnabled()//
|
||
|
|
/**
|
||
|
|
* Refreshes whether the component is visible based on the attribute value or if null the default flag value.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshIsVisible() {
|
||
|
|
if(isVisible.refresh()) {
|
||
|
|
isVisibleHolder.setValue(isVisible.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshIsVisible()//
|
||
|
|
/**
|
||
|
|
* Refreshes the tool tip text from the tool tip text attribute and the default tool tip text.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshToolTipText() {
|
||
|
|
if(toolTipText.refresh()) {
|
||
|
|
toolTipTextHolder.setValue(toolTipText.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshToolTipText()//
|
||
|
|
/**
|
||
|
|
* Refreshes the component's background color.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshBackgroundColor() {
|
||
|
|
if(backgroundColor.refresh()) {
|
||
|
|
backgroundColorHolder.setValue(backgroundColor.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Refreshes the component's foreground color.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshForegroundColor() {
|
||
|
|
if(foregroundColor.refresh()) {
|
||
|
|
foregroundColorHolder.setValue(foregroundColor.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Refreshes the title from the title attribute and the default title.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshContainerTitle() {
|
||
|
|
if(containerTitle.refresh()) {
|
||
|
|
containerTitleHolder.setValue(containerTitle.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshContainerTitle()//
|
||
|
|
/**
|
||
|
|
* Refreshes the image from the image url attribute and the default image url.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshContainerImage() {
|
||
|
|
if(containerImage.refresh()) {
|
||
|
|
containerImageHolder.setValue(containerImage.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshContainerImage()//
|
||
|
|
/**
|
||
|
|
* Refreshes the image and places it in the holder.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshBackgroundImage() {
|
||
|
|
if(backgroundImage.refresh()) {
|
||
|
|
backgroundImageHolder.setValue(backgroundImage.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Updates the background image for the control.
|
||
|
|
* The subclass can override this method if there is more than one potential source for the background image.
|
||
|
|
*/
|
||
|
|
protected void controlUpdateBackgroundImage() {
|
||
|
|
if(getCurrentBackgroundImage() != null) {
|
||
|
|
getSwtControl().setBackgroundImage(getCurrentBackgroundImage());
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
getSwtControl().setBackgroundImage(getCurrentBackgroundGradientImage());
|
||
|
|
}//else//
|
||
|
|
}//controlUpdateBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Updates the background color for the control.
|
||
|
|
* The subclass can override this method if there is more than one potential source for the background color.
|
||
|
|
*/
|
||
|
|
protected void controlUpdateBackgroundColor() {
|
||
|
|
getSwtControl().setBackground(getCurrentBackgroundColor());
|
||
|
|
}//controlUpdateBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Updates the foreground color for the control.
|
||
|
|
* The subclass can override this method if there is more than one potential source for the foreground color.
|
||
|
|
*/
|
||
|
|
protected void controlUpdateForegroundColor() {
|
||
|
|
getSwtControl().setForeground(getCurrentForegroundColor());
|
||
|
|
}//controlUpdateForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Updates the font for the control.
|
||
|
|
* The subclass can override this method if there is more than one potential source for the font.
|
||
|
|
*/
|
||
|
|
protected void controlUpdateFont() {
|
||
|
|
getSwtControl().setFont(getCurrentFont());
|
||
|
|
}//controlUpdateFont()//
|
||
|
|
/**
|
||
|
|
* Sets the background image using the gradient data.
|
||
|
|
* Note that any previous background image will be disposed.
|
||
|
|
* <p>Warning: Don't call this method if there is a background image set since the gradient shouldn't over write it and won't properly dispose of the resources.</p>
|
||
|
|
* @param gradient The gradient to be used.
|
||
|
|
*/
|
||
|
|
protected void internalSetBackgroundImage(JefGradient gradient) {
|
||
|
|
Image image = null;
|
||
|
|
|
||
|
|
//Dispose of the old gradient background image.//
|
||
|
|
if(getCurrentBackgroundGradientImage() != null) {
|
||
|
|
getCurrentBackgroundGradientImage().dispose();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentBackgroundColor(gradient != null ? createColor(gradient.getStartColor()) : null);
|
||
|
|
|
||
|
|
if(gradient != null) {
|
||
|
|
Rectangle clientArea = getSwtControl() instanceof Composite ? ((Composite) getSwtControl()).getClientArea() : getSwtControl().getBounds();
|
||
|
|
|
||
|
|
if(clientArea.width != 0 && clientArea.height != 0) {
|
||
|
|
Display display = getSwtControl().getDisplay();
|
||
|
|
Color c1 = createColor(gradient.getStartColor());
|
||
|
|
Color c2 = createColor(gradient.getEndColor());
|
||
|
|
Pattern pattern = new Pattern(display, (gradient.getDirection() == JefGradient.REVERSE_DIAGONAL ? clientArea.width : 0), 0, (gradient.getDirection() == JefGradient.VERTICAL ? 1 : gradient.getDirection() == JefGradient.REVERSE_DIAGONAL ? 0 : clientArea.width), (gradient.getDirection() == JefGradient.HORIZONTAL ? 1 : clientArea.height), c1, gradient.getStartColor().getAlpha(), c2, gradient.getEndColor().getAlpha());
|
||
|
|
GC gc;
|
||
|
|
|
||
|
|
//Note: Using an image instead of a paint call because the image doesn't flicker like a paint call will. A paint call will however paint the background of controls like button (but with horrible flickering). See snippets.swt.BackgroundGradient where testing was done. This code won't work with button, and perhaps other components.//
|
||
|
|
image = new Image(display, Math.max(1, clientArea.width), Math.max(1, clientArea.height));
|
||
|
|
gc = new GC(image);
|
||
|
|
|
||
|
|
//Force the x/y values to zero since getBounds uses them to provide the upper left point of the control.//
|
||
|
|
clientArea.x = 0;
|
||
|
|
clientArea.y = 0;
|
||
|
|
clientArea.width = Math.max(1, clientArea.width);
|
||
|
|
clientArea.height = Math.max(1, clientArea.height);
|
||
|
|
gc.setBackgroundPattern(pattern);
|
||
|
|
gc.fillRectangle(clientArea);
|
||
|
|
|
||
|
|
gc.dispose();
|
||
|
|
destroyColor(c1);
|
||
|
|
destroyColor(c2);
|
||
|
|
pattern.dispose();
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentBackgroundGradient(gradient);
|
||
|
|
setCurrentBackgroundGradientImage(image);
|
||
|
|
controlUpdateBackgroundColor();
|
||
|
|
controlUpdateBackgroundImage();
|
||
|
|
}//controlSetBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Sets the control's background image.
|
||
|
|
* @param image The image to use for the background.
|
||
|
|
*/
|
||
|
|
protected void internalSetBackgroundImage(JefImage image) {
|
||
|
|
if(getCurrentBackgroundImage() != null) {
|
||
|
|
destroyImage(getCurrentBackgroundImage());
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentBackgroundImage(createImage(image));
|
||
|
|
controlUpdateBackgroundImage();
|
||
|
|
}//internalSetBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Sets the control's background color.
|
||
|
|
* @param color The background color.
|
||
|
|
*/
|
||
|
|
protected void internalSetBackgroundColor(JefGradient color) {
|
||
|
|
if(useCustomBackground) {
|
||
|
|
setCurrentBackgroundGradient(color);
|
||
|
|
}//if//
|
||
|
|
else if((color == null) || (color != null && color.getEndColor() == null)) {
|
||
|
|
//Dispose of the old background color.//
|
||
|
|
if(getCurrentBackgroundColor() != null) {
|
||
|
|
destroyColor(getCurrentBackgroundColor());
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
//Dispose of the old background gradient since you can't have both a color and a gradient.//
|
||
|
|
if(getCurrentBackgroundGradientImage() != null) {
|
||
|
|
getCurrentBackgroundGradientImage().dispose();
|
||
|
|
setCurrentBackgroundGradientImage(null);
|
||
|
|
setCurrentBackgroundGradient(null);
|
||
|
|
controlUpdateBackgroundImage();
|
||
|
|
unregisterBackgroundImageResizeListener();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentBackgroundColor(createColor(color == null ? null : color.getStartColor()));
|
||
|
|
controlUpdateBackgroundColor();
|
||
|
|
}//else if//
|
||
|
|
else {
|
||
|
|
//Dispose of the old background color since you can't have both a color and a gradient.//
|
||
|
|
if(getCurrentBackgroundColor() != null) {
|
||
|
|
destroyColor(getCurrentBackgroundColor());
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentBackgroundGradient(color);
|
||
|
|
registerBackgroundImageResizeListener();
|
||
|
|
internalSetBackgroundImage(color);
|
||
|
|
}//else//
|
||
|
|
}//internalSetBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets up the listener to render a custom background.
|
||
|
|
*/
|
||
|
|
protected void registerCustomBackgroundRenderer() {
|
||
|
|
if(!getSwtControl().isDisposed()) {
|
||
|
|
getSwtControl().addListener(SWT.Paint, new Listener() {
|
||
|
|
private OverlayBufferSet overlayBufferSet = new OverlayBufferSet();
|
||
|
|
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
renderCustomBackground(event.gc, overlayBufferSet);
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
}//if//
|
||
|
|
}//registerCustomBackgroundRenderer()//
|
||
|
|
/**
|
||
|
|
* Renders a custom overlay background.
|
||
|
|
*/
|
||
|
|
protected void renderCustomBackground(GC gc, OverlayBufferSet overlayBufferSet) {
|
||
|
|
JefGradient gradient = getCurrentBackgroundGradient();
|
||
|
|
|
||
|
|
if(gradient != null && gradient.getStartColor() != null) {
|
||
|
|
Rectangle bounds = getSwtControl().getBounds();
|
||
|
|
|
||
|
|
if(overlayBufferSet.originalImage == null) {
|
||
|
|
overlayBufferSet.originalImage = new Image(getDisplay(), bounds.width, bounds.height);
|
||
|
|
gc.copyArea(overlayBufferSet.originalImage, 0, 0);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(overlayBufferSet.bufferImage == null || bounds.width != overlayBufferSet.bufferImage.getImageData().width || bounds.height != overlayBufferSet.bufferImage.getImageData().height) {
|
||
|
|
JefColor jefColor = gradient.getStartColor();
|
||
|
|
Color color = createColor(jefColor);
|
||
|
|
GC bufferGc = null;
|
||
|
|
|
||
|
|
if(overlayBufferSet.bufferImage != null) {
|
||
|
|
overlayBufferSet.bufferImage.dispose();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
overlayBufferSet.bufferImage = new Image(getDisplay(), bounds.width, bounds.height);
|
||
|
|
bufferGc = new GC(overlayBufferSet.bufferImage);
|
||
|
|
bufferGc.setAdvanced(true);
|
||
|
|
bufferGc.drawImage(overlayBufferSet.originalImage, 0, 0);
|
||
|
|
bufferGc.setAlpha(jefColor.getAlpha());
|
||
|
|
bufferGc.setBackground(color);
|
||
|
|
bufferGc.fillRectangle(bounds);
|
||
|
|
bufferGc.dispose();
|
||
|
|
destroyColor(color);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
gc.drawImage(overlayBufferSet.bufferImage, 0, 0);
|
||
|
|
}//if//
|
||
|
|
}//renderCustomBackground()//
|
||
|
|
/**
|
||
|
|
* Unregisters the resize listener that updates the background image.
|
||
|
|
*/
|
||
|
|
protected void unregisterBackgroundImageResizeListener() {
|
||
|
|
if(!getSwtControl().isDisposed() && backgroundImageResizeListener != null) {
|
||
|
|
getSwtControl().removeListener(SWT.Resize, backgroundImageResizeListener);
|
||
|
|
backgroundImageResizeListener = null;
|
||
|
|
}//if//
|
||
|
|
}//unregisterBackgroundImageResizeListener()//
|
||
|
|
/**
|
||
|
|
* Registers the resize listener that updates the background image.
|
||
|
|
*/
|
||
|
|
protected void registerBackgroundImageResizeListener() {
|
||
|
|
if(!getSwtControl().isDisposed() && backgroundImageResizeListener == null) {
|
||
|
|
getSwtControl().addListener(SWT.Resize, backgroundImageResizeListener = new Listener() {
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
internalSetBackgroundImage(getCurrentBackgroundGradient());
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
}//if//
|
||
|
|
}//registerBackgroundImageResizeListener()//
|
||
|
|
/**
|
||
|
|
* Sets the control's foreground color.
|
||
|
|
* @param color The foreground color.
|
||
|
|
*/
|
||
|
|
protected void internalSetForegroundColor(JefColor color) {
|
||
|
|
if(currentForegroundColor != null) {
|
||
|
|
destroyColor(currentForegroundColor);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentForegroundColor(createColor(color));
|
||
|
|
controlUpdateForegroundColor();
|
||
|
|
}//controlSetForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the control's font.
|
||
|
|
* @param color The font.
|
||
|
|
*/
|
||
|
|
protected void internalSetFont(JefFont[] font) {
|
||
|
|
if(currentFont != null) {
|
||
|
|
destroyFont(currentFont);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
setCurrentFont(createFont(font));
|
||
|
|
controlUpdateFont();
|
||
|
|
}//controlSetFont()//
|
||
|
|
/**
|
||
|
|
* Gets the current background image used by the component.
|
||
|
|
* @return The currently used background image, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected Image getCurrentBackgroundImage() {
|
||
|
|
return currentBackgroundImage;
|
||
|
|
}//getCurrentBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Sets the current background image used by the component.
|
||
|
|
* @param currentBackgroundImage The currently used background image, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected void setCurrentBackgroundImage(Image currentBackgroundImage) {
|
||
|
|
this.currentBackgroundImage = currentBackgroundImage;
|
||
|
|
}//setCurrentBackgroundImage()//
|
||
|
|
/**
|
||
|
|
* Gets the current background gradient used by the component.
|
||
|
|
* @return The currently used background gradient, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected JefGradient getCurrentBackgroundGradient() {
|
||
|
|
return currentBackgroundGradient;
|
||
|
|
}//getCurrentBackgroundGradient()//
|
||
|
|
/**
|
||
|
|
* Sets the current background gradient used by the component.
|
||
|
|
* @param currentBackgroundGradient The currently used background gradient, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected void setCurrentBackgroundGradient(JefGradient currentBackgroundGradient) {
|
||
|
|
this.currentBackgroundGradient = currentBackgroundGradient;
|
||
|
|
}//setCurrentBackgroundGradient()//
|
||
|
|
/**
|
||
|
|
* Gets the current background gradient image used by the component.
|
||
|
|
* @return The currently used background gradient image, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected Image getCurrentBackgroundGradientImage() {
|
||
|
|
return currentBackgroundGradientImage;
|
||
|
|
}//getCurrentBackgroundGradientImage()//
|
||
|
|
/**
|
||
|
|
* Sets the current background gradient image used by the component.
|
||
|
|
* @param currentBackgroundGradientImage The currently used background gradient image, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected void setCurrentBackgroundGradientImage(Image currentBackgroundGradientImage) {
|
||
|
|
this.currentBackgroundGradientImage = currentBackgroundGradientImage;
|
||
|
|
}//setCurrentBackgroundGradientImage()//
|
||
|
|
/**
|
||
|
|
* Gets the current foreground color used by the component.
|
||
|
|
* @return The currently used foreground color, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected Color getCurrentForegroundColor() {
|
||
|
|
return currentForegroundColor;
|
||
|
|
}//getCurrentForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the current foreground color used by the component.
|
||
|
|
* @param currentForegroundColor The currently used foreground color, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected void setCurrentForegroundColor(Color currentForegroundColor) {
|
||
|
|
this.currentForegroundColor = currentForegroundColor;
|
||
|
|
}//setCurrentForegroundColor()//
|
||
|
|
/**
|
||
|
|
* Gets the current background color used by the component.
|
||
|
|
* @return The currently used background color, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected Color getCurrentBackgroundColor() {
|
||
|
|
return currentBackgroundColor;
|
||
|
|
}//getCurrentBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Sets the current background color used by the component.
|
||
|
|
* @param currentBackgroundColor The currently used background color, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected void setCurrentBackgroundColor(Color currentBackgroundColor) {
|
||
|
|
this.currentBackgroundColor = currentBackgroundColor;
|
||
|
|
}//setCurrentBackgroundColor()//
|
||
|
|
/**
|
||
|
|
* Gets the current font used by the component.
|
||
|
|
* @return The currently used font, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected Font getCurrentFont() {
|
||
|
|
return currentFont;
|
||
|
|
}//getCurrentFont()//
|
||
|
|
/**
|
||
|
|
* Sets the current font used by the component.
|
||
|
|
* @param currentFont The currently used font, or null if none is provided.
|
||
|
|
*/
|
||
|
|
protected void setCurrentFont(Font currentFont) {
|
||
|
|
this.currentFont = currentFont;
|
||
|
|
}//setCurrentFont()//
|
||
|
|
/**
|
||
|
|
* Refreshes the component's font.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshFont() {
|
||
|
|
if(font.refresh()) {
|
||
|
|
fontHolder.setValue(font.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshFont()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewRefreshAll()
|
||
|
|
*/
|
||
|
|
public void internalViewRefreshAll() {
|
||
|
|
if(getMenu() != null) {
|
||
|
|
getMenu().internalViewRefreshAll();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewRefreshAll();
|
||
|
|
}//internalViewRefreshAll()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewSynchronizeAll()
|
||
|
|
*/
|
||
|
|
public void internalViewSynchronizeAll() {
|
||
|
|
if(getMenu() != null) {
|
||
|
|
getMenu().internalViewSynchronizeAll();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewSynchronizeAll();
|
||
|
|
}//internalViewSynchronizeAll()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewInitializeAll()
|
||
|
|
*/
|
||
|
|
public void internalViewInitializeAll() {
|
||
|
|
super.internalViewInitializeAll();
|
||
|
|
|
||
|
|
if(menu != null) {
|
||
|
|
menu.internalViewInitializeAll();
|
||
|
|
getSwtControl().setMenu(menu.getSwtMenu());
|
||
|
|
}//if//
|
||
|
|
}//internalViewInitializeAll()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewReleaseAll()
|
||
|
|
*/
|
||
|
|
public void internalViewReleaseAll() {
|
||
|
|
if(getMenu() != null) {
|
||
|
|
getMenu().internalViewReleaseAll();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewReleaseAll();
|
||
|
|
}//internalViewReleaseAll()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewInitialize()
|
||
|
|
*/
|
||
|
|
protected void internalViewInitialize() {
|
||
|
|
isVisible.initialize();
|
||
|
|
isEnabled.initialize();
|
||
|
|
toolTipText.initialize();
|
||
|
|
backgroundColor.initialize();
|
||
|
|
foregroundColor.initialize();
|
||
|
|
font.initialize();
|
||
|
|
containerTitle.initialize();
|
||
|
|
containerImage.initialize();
|
||
|
|
backgroundImage.initialize();
|
||
|
|
|
||
|
|
if(gainFocusEventAssociations != null) {
|
||
|
|
IIterator iterator = gainFocusEventAssociations.iterator();
|
||
|
|
|
||
|
|
while(iterator.hasNext()) {
|
||
|
|
((IEventAssociation) iterator.next()).register();
|
||
|
|
}//while//
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(keyBindings != null && keyBindings.getSize() > 0) {
|
||
|
|
getSwtControl().addKeyListener(this);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(useCustomBackground) {
|
||
|
|
registerCustomBackgroundRenderer();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewInitialize();
|
||
|
|
resize();
|
||
|
|
}//internalViewInitialize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewRelease()
|
||
|
|
*/
|
||
|
|
protected void internalViewRelease() {
|
||
|
|
// if(getSwtControl() instanceof Shell) {
|
||
|
|
// ((Shell) getSwtControl()).setLayoutDeferred(false);
|
||
|
|
// }//if//
|
||
|
|
|
||
|
|
isVisible.release();
|
||
|
|
isEnabled.release();
|
||
|
|
toolTipText.release();
|
||
|
|
backgroundColor.release();
|
||
|
|
foregroundColor.release();
|
||
|
|
font.release();
|
||
|
|
containerTitle.release();
|
||
|
|
containerImage.release();
|
||
|
|
backgroundImage.release();
|
||
|
|
|
||
|
|
if(gainFocusEventAssociations != null) {
|
||
|
|
IIterator iterator = gainFocusEventAssociations.iterator();
|
||
|
|
|
||
|
|
while(iterator.hasNext()) {
|
||
|
|
((IEventAssociation) iterator.next()).unregister();
|
||
|
|
}//while//
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(getContainer() != null) {
|
||
|
|
getContainer().getComponents().remove(this);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
toolTipTextHolder.release();
|
||
|
|
foregroundColorHolder.release();
|
||
|
|
backgroundColorHolder.release();
|
||
|
|
fontHolder.release();
|
||
|
|
isVisibleHolder.release();
|
||
|
|
isEnabledHolder.release();
|
||
|
|
containerImageHolder.release();
|
||
|
|
containerTitleHolder.release();
|
||
|
|
backgroundImageHolder.release();
|
||
|
|
|
||
|
|
if(getCurrentBackgroundImage() != null) {
|
||
|
|
destroyImage(getCurrentBackgroundImage());
|
||
|
|
setCurrentBackgroundImage(null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(getCurrentBackgroundGradientImage() != null) {
|
||
|
|
getCurrentBackgroundGradientImage().dispose();
|
||
|
|
setCurrentBackgroundGradientImage(null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(getCurrentForegroundColor() != null) {
|
||
|
|
destroyColor(getCurrentForegroundColor());
|
||
|
|
setCurrentForegroundColor(null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(getCurrentBackgroundColor() != null) {
|
||
|
|
destroyColor(getCurrentBackgroundColor());
|
||
|
|
setCurrentBackgroundColor(null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(getCurrentFont() != null) {
|
||
|
|
destroyFont(getCurrentFont());
|
||
|
|
setCurrentFont(null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(swtContainerImage != null) {
|
||
|
|
destroyImage(swtContainerImage);
|
||
|
|
swtContainerImage = null;
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewRelease();
|
||
|
|
|
||
|
|
if(getSwtControl() != null && !getSwtControl().isDisposed()) {
|
||
|
|
getSwtControl().dispose();
|
||
|
|
}//if//
|
||
|
|
}//internalViewRelease()//
|
||
|
|
/**
|
||
|
|
* Performs the actual work of enable or disabling the component.
|
||
|
|
* @param isEnabled Whether the enabled state should be altered to be enabled, otherwise it is altered to be disabled.
|
||
|
|
* @param isLocal Whether this change in state is locally generated, or from the parent container.
|
||
|
|
*/
|
||
|
|
protected void internalSetEnabledState(boolean isEnabled, boolean isLocal) {
|
||
|
|
//Some components may not have controls, such as value holders.//
|
||
|
|
if(getSwtControl() != null && !getSwtControl().isDisposed()) {
|
||
|
|
if(isLocal) {
|
||
|
|
isLocallyEnabled = isEnabled;
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
isParentEnabled = isEnabled;
|
||
|
|
}//else//
|
||
|
|
|
||
|
|
getSwtControl().setEnabled(isLocallyEnabled && isParentEnabled);
|
||
|
|
}//if//
|
||
|
|
}//internalSetEnabledState()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalOnLinkInvoked(int, java.lang.Object)
|
||
|
|
*/
|
||
|
|
protected void internalOnLinkInvoked(int linkTarget, Object data) {
|
||
|
|
switch(linkTarget) {
|
||
|
|
case LINK_TARGET_IS_VISIBLE: {
|
||
|
|
boolean isVisible = data != null && data instanceof Boolean ? ((Boolean) data).booleanValue() : false;
|
||
|
|
|
||
|
|
if(getSwtControl().getVisible() != isVisible) {
|
||
|
|
getSwtControl().setVisible(isVisible);
|
||
|
|
|
||
|
|
//Never resize shells when changing visibility since nothing about the size should have changed from when the shell was first created.//
|
||
|
|
if(!(getSwtControl() instanceof Shell)) {
|
||
|
|
resize();
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case LINK_TARGET_IS_ENABLED: {
|
||
|
|
internalSetEnabledState(data != null && data instanceof Boolean ? ((Boolean) data).booleanValue() : false, true);
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case LINK_TARGET_GAIN_FOCUS: {
|
||
|
|
getSwtControl().setFocus();
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case LINK_TARGET_TOOL_TIP_TEXT: {
|
||
|
|
getSwtControl().setToolTipText(data instanceof String ? (String) data : "");
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case LINK_TARGET_BACKGROUND_COLOR: {
|
||
|
|
internalSetBackgroundColor(data instanceof JefGradient ? (JefGradient) data : data instanceof JefColor ? new JefGradient((JefColor) data) : null);
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case LINK_TARGET_FOREGROUND_COLOR: {
|
||
|
|
internalSetForegroundColor(data instanceof JefColor ? (JefColor) data : null);
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case LINK_TARGET_FONT: {
|
||
|
|
internalSetFont(data instanceof JefFont ? new JefFont[] {(JefFont) data} : data instanceof JefFont[] ? (JefFont[]) data : null);
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
default: {
|
||
|
|
super.internalOnLinkInvoked(linkTarget, data);
|
||
|
|
break;
|
||
|
|
}//default//
|
||
|
|
}//switch//
|
||
|
|
}//internalOnLinkInvoked()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalOnValueChanged(com.foundation.view.SingleResourceAssociation)
|
||
|
|
*/
|
||
|
|
protected void internalOnValueChanged(SingleResourceAssociation resourceAssociation, int flags) {
|
||
|
|
if(resourceAssociation == isVisible) {
|
||
|
|
internalViewRefreshIsVisible();
|
||
|
|
}//if//
|
||
|
|
else if(resourceAssociation == isEnabled) {
|
||
|
|
internalViewRefreshIsEnabled();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == toolTipText) {
|
||
|
|
internalViewRefreshToolTipText();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == foregroundColor) {
|
||
|
|
internalViewRefreshForegroundColor();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == backgroundColor) {
|
||
|
|
internalViewRefreshBackgroundColor();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == font) {
|
||
|
|
internalViewRefreshFont();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == containerTitle) {
|
||
|
|
internalViewRefreshContainerTitle();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == containerImage) {
|
||
|
|
internalViewRefreshContainerImage();
|
||
|
|
}//else if//
|
||
|
|
else if(resourceAssociation == backgroundImage) {
|
||
|
|
internalViewRefreshBackgroundImage();
|
||
|
|
}//else if//
|
||
|
|
else {
|
||
|
|
super.internalOnValueChanged(resourceAssociation, flags);
|
||
|
|
}//else//
|
||
|
|
}//internalOnValueChanged()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalResourceHolderChanged(com.foundation.view.swt.ResourceHolder, java.lang.Object, java.lang.Object)
|
||
|
|
*/
|
||
|
|
protected void internalResourceHolderChanged(ResourceHolder resource, Object oldValue, Object newValue, int flags) {
|
||
|
|
if(resource == toolTipTextHolder) {
|
||
|
|
String value = newValue != null ? newValue.toString() : null;
|
||
|
|
IIterator listeners = getListeners(IComponentListener.class);
|
||
|
|
|
||
|
|
//Set the control's tool tip text. This is normally enough, but some controls may need extra processing (hence the listeners).//
|
||
|
|
getSwtControl().setToolTipText(value);
|
||
|
|
|
||
|
|
//Notify all the listeners.//
|
||
|
|
while(listeners.hasNext()) {
|
||
|
|
((IComponentListener) listeners.next()).toolTipTextChanged(this, value);
|
||
|
|
}//while//
|
||
|
|
}//if//
|
||
|
|
else if(resource == containerTitleHolder) {
|
||
|
|
IIterator listeners = getListeners(IComponentListener.class);
|
||
|
|
|
||
|
|
//Notify all the listeners.//
|
||
|
|
while(listeners.hasNext()) {
|
||
|
|
((IComponentListener) listeners.next()).titleChanged(this, (String) newValue);
|
||
|
|
}//while//
|
||
|
|
}//else if//
|
||
|
|
else if(resource == containerImageHolder) {
|
||
|
|
IIterator listeners = getListeners(IComponentListener.class);
|
||
|
|
|
||
|
|
destroyImage(swtContainerImage);
|
||
|
|
swtContainerImage = createImage((JefImage) containerImageHolder.getValue());
|
||
|
|
|
||
|
|
//Notify all the listeners.//
|
||
|
|
while(listeners.hasNext()) {
|
||
|
|
((IComponentListener) listeners.next()).imageChanged(this, swtContainerImage);
|
||
|
|
}//while//
|
||
|
|
}//else if//
|
||
|
|
else if(resource == backgroundColorHolder) {
|
||
|
|
internalSetBackgroundColor(newValue instanceof JefColor ? new JefGradient((JefColor) newValue, null, JefGradient.DIAGONAL) : (JefGradient) newValue);
|
||
|
|
}//else if//
|
||
|
|
else if(resource == foregroundColorHolder) {
|
||
|
|
internalSetForegroundColor((JefColor) newValue);
|
||
|
|
}//else if//
|
||
|
|
else if(resource == fontHolder) {
|
||
|
|
internalSetFont(newValue == null || newValue instanceof JefFont[] ? (JefFont[]) newValue : new JefFont[] {(JefFont) newValue});
|
||
|
|
resize();
|
||
|
|
}//else if//
|
||
|
|
else if(resource == isVisibleHolder) {
|
||
|
|
if(!getSwtControl().isDisposed()) {
|
||
|
|
getSwtControl().setVisible(((Boolean) newValue).booleanValue());
|
||
|
|
|
||
|
|
//Never resize shells when changing visibility since nothing about the size should have changed from when the shell was first created.//
|
||
|
|
if(!(getSwtControl() instanceof Shell)) {
|
||
|
|
resize();
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
}//else if//
|
||
|
|
else if(resource == isEnabledHolder) {
|
||
|
|
internalSetEnabledState(((Boolean) newValue).booleanValue(), true);
|
||
|
|
|
||
|
|
//Never resize shells when changing the enabled state since nothing about the size should have changed from when the shell was first created.//
|
||
|
|
if(!(getSwtControl() instanceof Shell)) {
|
||
|
|
resize();
|
||
|
|
}//if//
|
||
|
|
}//else if//
|
||
|
|
else if(resource == backgroundImageHolder) {
|
||
|
|
internalSetBackgroundImage((JefImage) backgroundImageHolder.getValue());
|
||
|
|
}//else if//
|
||
|
|
else {
|
||
|
|
super.internalResourceHolderChanged(resource, oldValue, newValue, flags);
|
||
|
|
}//else//
|
||
|
|
}//internalOnAssociationChanged()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalOnEventFired(com.foundation.view.IEventAssociation, java.lang.Object[])
|
||
|
|
*/
|
||
|
|
protected void internalOnEventFired(IEventAssociation eventAssociation, Object[] eventArguments) {
|
||
|
|
if((gainFocusEventAssociations != null) && (gainFocusEventAssociations.containsValue(eventAssociation))) {
|
||
|
|
setFocus();
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
super.internalOnEventFired(eventAssociation, eventArguments);
|
||
|
|
}//else//
|
||
|
|
}//internalOnEventFired()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalInitializationComplete()
|
||
|
|
*/
|
||
|
|
protected void internalInitializationComplete() {
|
||
|
|
/* This doesn't work at this time because it doesn't make the startup of complex views faster and doesn't fix odd rendering in the table/tree cell components.
|
||
|
|
if(getSwtControl() instanceof Composite) {
|
||
|
|
if(!hasSpecificSize) {
|
||
|
|
getSwtControl().pack(true);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
((Composite) getSwtControl()).layout(true, true);
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
if(!hasSpecificSize) {
|
||
|
|
getSwtControl().pack(true);
|
||
|
|
}//if//
|
||
|
|
}//else//
|
||
|
|
|
||
|
|
isInitializationComplete = true;
|
||
|
|
*/
|
||
|
|
}//internalInitializationComplete()//
|
||
|
|
/**
|
||
|
|
* Forces the component to resize and requests that the window layout.
|
||
|
|
*/
|
||
|
|
public void resize() {
|
||
|
|
if(getSwtControl() != null && !getSwtControl().isDisposed()) {
|
||
|
|
flushLayoutCache();
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(isInitialized() && !isSuspendingLayouts()) {
|
||
|
|
if(!hasSpecificSize) {
|
||
|
|
getSwtControl().pack(true);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(getSwtControl() instanceof Shell) {
|
||
|
|
((Shell) getSwtControl()).layout();
|
||
|
|
}//if//
|
||
|
|
else if(getSwtControl().getParent() != null) {
|
||
|
|
getSwtControl().getParent().layout();
|
||
|
|
}//else if//
|
||
|
|
|
||
|
|
//Allow the parents of this component to adjust to the children resizing.//
|
||
|
|
if(!hasSpecificSize && getContainer() != null && getContainer() instanceof Container) {
|
||
|
|
((Container) getContainer()).postResize();
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
}//resize()//
|
||
|
|
/**
|
||
|
|
* Clears any cached data in the component's layout due to a change in the component's state that would invalidate any cached layout information.
|
||
|
|
*/
|
||
|
|
public void flushLayoutCache() {
|
||
|
|
Control control = getSwtControl();
|
||
|
|
|
||
|
|
if(control.getLayoutData() instanceof com.foundation.view.swt.layout.LayoutData) {
|
||
|
|
((com.foundation.view.swt.layout.LayoutData) control.getLayoutData()).flushCache();
|
||
|
|
}//if//
|
||
|
|
}//flushLayoutCache()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
|
||
|
|
*/
|
||
|
|
public void keyPressed(KeyEvent event) {
|
||
|
|
int modifiers = SwtUtilities.convertKeyModifiers(event.stateMask);
|
||
|
|
int character = event.keyCode;
|
||
|
|
|
||
|
|
if(keyBindings != null) {
|
||
|
|
for(int index = 0; (event.doit) && (index < keyBindings.getSize()); index++) {
|
||
|
|
IKeyBinding keyBinding = (IKeyBinding) keyBindings.get(index);
|
||
|
|
|
||
|
|
if(keyBinding.getModifiers() == modifiers) {
|
||
|
|
if(keyBinding.getKeyCode() != null) {
|
||
|
|
if(keyBinding.getKeyCode().intValue() == character) {
|
||
|
|
keyBinding.invoke(new Object[] {new Integer(modifiers), new Integer(character)}, true);
|
||
|
|
event.doit = false;
|
||
|
|
}//if//
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
//TODO: Can we detect a modifier key being pressed without a non-modifier key?
|
||
|
|
}//else//
|
||
|
|
}//if//
|
||
|
|
}//for//
|
||
|
|
}//if//
|
||
|
|
}//keyPressed()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
|
||
|
|
*/
|
||
|
|
public void keyReleased(KeyEvent event) {
|
||
|
|
}//keyReleased()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see java.lang.Object#toString()
|
||
|
|
*/
|
||
|
|
public String toString() {
|
||
|
|
return super.toString() + (getName() != null ? " (named: " + getName() + ")" : "");
|
||
|
|
}//toString()//
|
||
|
|
}//Component//
|