191 lines
6.6 KiB
Java
191 lines
6.6 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 com.foundation.view.*;
|
||
|
|
import com.foundation.view.resource.ResourceReference;
|
||
|
|
import org.eclipse.swt.SWT;
|
||
|
|
|
||
|
|
public class Label extends Component {
|
||
|
|
public static final int STYLE_SEPARATOR = SWT.SEPARATOR;
|
||
|
|
public static final int STYLE_HORIZONTAL = SWT.HORIZONTAL;
|
||
|
|
public static final int STYLE_VERTICAL = SWT.VERTICAL;
|
||
|
|
public static final int STYLE_SHADOW_IN = SWT.SHADOW_IN;
|
||
|
|
public static final int STYLE_SHADOW_OUT = SWT.SHADOW_OUT;
|
||
|
|
public static final int STYLE_SHADOW_NONE = SWT.SHADOW_NONE;
|
||
|
|
public static final int STYLE_LEFT = SWT.LEFT;
|
||
|
|
public static final int STYLE_RIGHT = SWT.RIGHT;
|
||
|
|
public static final int STYLE_CENTER = SWT.CENTER;
|
||
|
|
public static final int STYLE_WRAP = SWT.WRAP;
|
||
|
|
|
||
|
|
/** The label text. */
|
||
|
|
private SingleResourceAssociation text = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_TEXT, false, "");
|
||
|
|
/** The label image. */
|
||
|
|
private SingleResourceAssociation image = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_IMAGE, false, null);
|
||
|
|
/** A holder for the value of the text. */
|
||
|
|
private ResourceHolder textHolder = new ResourceHolder(this);
|
||
|
|
/** A holder for the value of the image. */
|
||
|
|
private ResourceHolder imageHolder = new ResourceHolder(this);
|
||
|
|
/**
|
||
|
|
* Label constructor.
|
||
|
|
* @param parent A composite control which will be the parent of the new instance (cannot be null).
|
||
|
|
* @param name The unique component name.
|
||
|
|
* @param style The style of control to construct
|
||
|
|
* @see #SEPARATOR
|
||
|
|
* @see #HORIZONTAL
|
||
|
|
* @see #VERTICAL
|
||
|
|
* @see #SHADOW_IN
|
||
|
|
* @see #SHADOW_OUT
|
||
|
|
* @see #SHADOW_NONE
|
||
|
|
* @see #LEFT
|
||
|
|
* @see #RIGHT
|
||
|
|
* @see #CENTER
|
||
|
|
* @see #WRAP
|
||
|
|
*/
|
||
|
|
public Label(Container parent, String name, int style) {
|
||
|
|
super(parent, name, style);
|
||
|
|
}//Label()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#initializeControl(int)
|
||
|
|
*/
|
||
|
|
protected void initializeControl(int style, Object data) {
|
||
|
|
setSwtWidget(new org.eclipse.swt.widgets.Label(((Container) getContainer()).getSwtParent(), style));
|
||
|
|
getSwtWidget().setData(this);
|
||
|
|
}//initializeControl()//
|
||
|
|
/**
|
||
|
|
* Gets the SWT label that represents this label.
|
||
|
|
* @return The SWT label providing visualization for this label.
|
||
|
|
*/
|
||
|
|
public org.eclipse.swt.widgets.Label getSwtLabel() {
|
||
|
|
return (org.eclipse.swt.widgets.Label) getSwtControl();
|
||
|
|
}//getSwtLabel()//
|
||
|
|
/**
|
||
|
|
* Sets the label's text. This will be the default text if there is a text attribute associated with this component.
|
||
|
|
* @param text The text that will appear in the label.
|
||
|
|
*/
|
||
|
|
public void setText(String text) {
|
||
|
|
verifyThread();
|
||
|
|
this.text.setDefaultValue(text);
|
||
|
|
}//setText()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default text resource.
|
||
|
|
* @param text The text to be displayed by this component.
|
||
|
|
*/
|
||
|
|
public void setText(ResourceReference text) {
|
||
|
|
verifyThread();
|
||
|
|
this.text.setDefaultValue(text);
|
||
|
|
}//setText()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the text.
|
||
|
|
* @param container The text association metadata.
|
||
|
|
*/
|
||
|
|
public void setTextAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.text.setAssociations(container);
|
||
|
|
}//setTextAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the association container used to access the image.
|
||
|
|
* @param container The image association metadata.
|
||
|
|
*/
|
||
|
|
public void setImageAssociation(SingleAssociationContainer container) {
|
||
|
|
verifyThread();
|
||
|
|
this.image.setAssociations(container);
|
||
|
|
}//setImageAssociation()//
|
||
|
|
/**
|
||
|
|
* Sets the label's image. This will be the default image if there is a image attribute associated with this component.
|
||
|
|
* @param image The image to be displayed by the label.
|
||
|
|
*/
|
||
|
|
public void setImage(JefImage image) {
|
||
|
|
verifyThread();
|
||
|
|
this.image.setDefaultValue(image);
|
||
|
|
}//setImage()//
|
||
|
|
/**
|
||
|
|
* Sets the component's default image resource.
|
||
|
|
* @param image The image to be displayed by this component.
|
||
|
|
*/
|
||
|
|
public void setImage(ResourceReference image) {
|
||
|
|
verifyThread();
|
||
|
|
this.image.setDefaultValue(image);
|
||
|
|
}//setImage()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewInitialize()
|
||
|
|
*/
|
||
|
|
protected void internalViewInitialize() {
|
||
|
|
text.initialize(true);
|
||
|
|
image.initialize(true);
|
||
|
|
super.internalViewInitialize();
|
||
|
|
}//internalViewInitialize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewRelease()
|
||
|
|
*/
|
||
|
|
protected void internalViewRelease() {
|
||
|
|
destroyImage((JefImage) imageHolder.getValue());
|
||
|
|
text.release();
|
||
|
|
image.release();
|
||
|
|
textHolder.release();
|
||
|
|
imageHolder.release();
|
||
|
|
super.internalViewRelease();
|
||
|
|
}//internalViewRelease()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalViewRefresh()
|
||
|
|
*/
|
||
|
|
protected void internalViewRefresh() {
|
||
|
|
super.internalViewRefresh();
|
||
|
|
internalViewRefreshText();
|
||
|
|
internalViewRefreshImage();
|
||
|
|
}//internalViewRefresh()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.Component#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 == textHolder) {
|
||
|
|
String value = newValue != null ? (String) newValue : "";
|
||
|
|
|
||
|
|
getSwtLabel().setText(value == null ? "" : value);
|
||
|
|
resize();
|
||
|
|
}//if//
|
||
|
|
else if(resource == imageHolder) {
|
||
|
|
destroyImage(getSwtLabel().getImage());
|
||
|
|
getSwtLabel().setImage(createImage((JefImage) newValue));
|
||
|
|
resize();
|
||
|
|
}//else if//
|
||
|
|
else {
|
||
|
|
super.internalResourceHolderChanged(resource, oldValue, newValue, flags);
|
||
|
|
}//else//
|
||
|
|
}//internalOnAssociationChanged()//
|
||
|
|
/**
|
||
|
|
* Refreshes the component's text.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshText() {
|
||
|
|
if(text.refresh()) {
|
||
|
|
textHolder.setValue(text.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshText()//
|
||
|
|
/**
|
||
|
|
* Refreshes the component's image.
|
||
|
|
*/
|
||
|
|
protected void internalViewRefreshImage() {
|
||
|
|
if(image.refresh()) {
|
||
|
|
imageHolder.setValue(image.getValue());
|
||
|
|
}//if//
|
||
|
|
}//internalViewRefreshImage()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.AbstractComponent#internalOnValueChanged(com.foundation.view.SingleResourceAssociation)
|
||
|
|
*/
|
||
|
|
protected void internalOnValueChanged(SingleResourceAssociation resourceAssociation, int flags) {
|
||
|
|
if(resourceAssociation == text) {
|
||
|
|
internalViewRefreshText();
|
||
|
|
}//if//
|
||
|
|
else if(resourceAssociation == image) {
|
||
|
|
internalViewRefreshImage();
|
||
|
|
}//else if//
|
||
|
|
else {
|
||
|
|
super.internalOnValueChanged(resourceAssociation, flags);
|
||
|
|
}//else//
|
||
|
|
}//internalOnValueChanged()//
|
||
|
|
}//Label//
|