FileDocCategorySizeDatePackage
SWTSkinUtils.javaAPI DocAzureus 3.0.3.47157Tue Oct 02 09:00:16 BST 2007com.aelitis.azureus.ui.swt.skin

SWTSkinUtils

public class SWTSkinUtils extends Object
author
TuxPaper
created
Jun 8, 2006

Fields Summary
public static final int
TILE_NONE
public static final int
TILE_Y
public static final int
TILE_X
public static final int
TILE_CENTER_X
public static final int
TILE_CENTER_Y
public static final int
TILE_BOTH
private static Listener
imageDownListener
private static Listener
imageOverListener
Constructors Summary
Methods Summary
static voidaddMouseImageChangeListeners(Widget widget)

		if (widget.getData("hasMICL") != null) {
			return;
		}

		widget.addListener(SWT.MouseEnter, imageOverListener);
		widget.addListener(SWT.MouseExit, imageOverListener);
		//		new MouseEnterExitListener(widget);

		widget.addListener(SWT.MouseDown, imageDownListener);
		widget.addListener(SWT.MouseUp, imageDownListener);

		widget.setData("hasMICL", "1");
	
public static intgetAlignment(java.lang.String sAlign, int def)


	 
		imageOverListener = new SWTSkinImageChanger("-over", SWT.MouseEnter,
				SWT.MouseExit);
		imageDownListener = new SWTSkinImageChanger("-down", SWT.MouseDown,
				SWT.MouseUp);
	
		int align;

		if (sAlign.equalsIgnoreCase("center")) {
			align = SWT.CENTER;
		} else if (sAlign.equalsIgnoreCase("bottom")) {
			align = SWT.BOTTOM;
		} else if (sAlign.equalsIgnoreCase("top")) {
			align = SWT.TOP;
		} else if (sAlign.equalsIgnoreCase("left")) {
			align = SWT.LEFT;
		} else if (sAlign.equalsIgnoreCase("right")) {
			align = SWT.RIGHT;
		} else {
			align = def;
		}

		return align;
	
public static intgetTileMode(java.lang.String sTileMode)

param
tileMode
return

		int tileMode = TILE_NONE;
		if (sTileMode == null || sTileMode == "") {
			return tileMode;
		}

		sTileMode = sTileMode.toLowerCase();

		if (sTileMode.equals("tile")) {
			tileMode = TILE_X | TILE_Y;
		} else if (sTileMode.equals("tile-x")) {
			tileMode = TILE_X;
		} else if (sTileMode.equals("tile-y")) {
			tileMode = TILE_Y;
		} else if (sTileMode.equals("center-x")) {
			tileMode = TILE_CENTER_X;
		} else if (sTileMode.equals("center-y")) {
			tileMode = TILE_CENTER_Y;
		}

		return tileMode;
	
public static voidsetVisibility(SWTSkin skin, java.lang.String configID, java.lang.String viewID, boolean visible)

		setVisibility(skin, configID, viewID, visible, true, false);
	
public static voidsetVisibility(SWTSkin skin, java.lang.String configID, java.lang.String viewID, boolean visible, boolean save, boolean fast)

		SWTSkinObject skinObject = skin.getSkinObject(viewID);
		// XXX Following wont work at startup because main window is invisible..
		//		if (skinObject != null && skinObject.isVisible() != visible) {
		if (skinObject != null) {
			final Control control = skinObject.getControl();
			if (control != null && !control.isDisposed()) {
				Boolean wasVisible = (Boolean) control.getData("lastSlideVis");
				if (wasVisible != null && wasVisible.booleanValue() == visible) {
					return;
				}

				if (control.getData("Sliding") != null) {
					return;
				}
				control.setData("lastSlideVis", new Boolean(visible));
				if (visible) {
					final FormData fd = (FormData) control.getLayoutData();
					Point size = (Point) control.getData("v3.oldHeight");
					//System.out.println(control.getData("SkinID") + " oldHeight = " + size + ";v=" + control.getVisible() + ";s=" + control.getSize());
					if (size == null && control.getSize().y < 2) {
						size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
						if (fd.height > 0) {
							size.y = fd.height;
						}
						if (fd.width > 0) {
							size.x = fd.width;
						}
					}

					if (size != null) {
						if (fd != null && (fd.width != size.x || fd.height != size.y)) {
							if (fast) {
								fd.width = size.x;
								fd.height = size.y;
								control.setLayoutData(fd);
								Utils.relayout(control);
							} else {
								slide(control, fd, size);
							}
						}
					}
					control.setData("v3.oldHeight", null);
				} else {
					final FormData fd = (FormData) control.getLayoutData();
					if (fd != null) {
						Point oldSize = new Point(fd.width, fd.height);
						if (oldSize.y <= 0) {
							oldSize = null;
						}
						control.setData("v3.oldHeight", oldSize);
						final Point size = new Point(0, 0);

						if (fast) {
							fd.width = size.x;
							fd.height = size.y;
							control.setLayoutData(fd);
							Utils.relayout(control);
						} else {
							slide(control, fd, size);
						}
					}
				}
				skinObject.setVisible(visible);
				Utils.relayout(control);
			}

			if (save
					&& COConfigurationManager.getBooleanParameter(configID) != visible) {
				COConfigurationManager.setParameter(configID, visible);
			}
		}
	
private static voidslide(Control control, org.eclipse.swt.layout.FormData fd, org.eclipse.swt.graphics.Point size)

		//System.out.println("slid to " + size);
		AERunnable runnable = new AERunnable() {
			boolean firstTime = true;

			public void runSupport() {
				if (control.isDisposed()) {
					return;
				}

				if (firstTime) {
					firstTime = false;
					if (control.getData("Sliding") != null) {
						return;
					}
					control.setData("Sliding", "1");
				}

				int newWidth = (int) (fd.width + (size.x - fd.width) * 0.4);
				int h = fd.height >= 0 ? fd.height : control.getSize().y;
				int newHeight = (int) (h + (size.y - h) * 0.4);
				//System.out.println(control + "] newh=" + newHeight + " to " + size.y);

				if (newWidth == fd.width && newHeight == h) {
					fd.width = size.x;
					fd.height = size.y;
					//System.out.println(control + "] side to " + size.y + " done");
					control.setLayoutData(fd);
					control.setSize(size);
					Utils.relayout(control);
					control.setData("Sliding", null);
				} else {
					fd.width = newWidth;
					fd.height = newHeight;
					control.setLayoutData(fd);
					Utils.relayout(control);

					final AERunnable r = this;
					SimpleTimer.addEvent("slide", SystemTime.getCurrentTime() + 10,
							new TimerEventPerformer() {
								public void perform(TimerEvent event) {
									control.getDisplay().asyncExec(r);
								}
							});
				}
			}
		};
		control.getDisplay().asyncExec(runnable);