421 lines
14 KiB
Java
421 lines
14 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.tcv.swt.client;
|
||
|
|
|
||
|
|
import org.eclipse.swt.events.*;
|
||
|
|
import org.eclipse.swt.graphics.*;
|
||
|
|
import org.eclipse.swt.widgets.Event;
|
||
|
|
|
||
|
|
import com.foundation.tcv.client.view.ResourceHolder;
|
||
|
|
import com.foundation.tcv.swt.*;
|
||
|
|
import com.foundation.tcv.view.ViewMessage;
|
||
|
|
import com.foundation.view.JefImage;
|
||
|
|
|
||
|
|
public class Frame extends Container implements IDecoration, IFrame, Component.IComponentListener {
|
||
|
|
/** A holder for the value of the container images. */
|
||
|
|
private ResourceHolder containerImagesHolder = new ResourceHolder(this);
|
||
|
|
/** The swt images used by the container of this component to represent the component. */
|
||
|
|
private Image[] swtContainerImages = null;
|
||
|
|
private Menu menuBar = null;
|
||
|
|
/** Whether to send closed events to the server. */
|
||
|
|
private boolean sendClosedEvent = false;
|
||
|
|
/** Whether to send activated or deactivated events to the server. */
|
||
|
|
private boolean sendActivatedEvents = false;
|
||
|
|
/**
|
||
|
|
* Frame constructor.
|
||
|
|
*/
|
||
|
|
public Frame() {
|
||
|
|
super();
|
||
|
|
}//Frame()//
|
||
|
|
/**
|
||
|
|
* Gets the SWT decorations that represents this frame.
|
||
|
|
* @return The decorations providing visualization for this frame.
|
||
|
|
*/
|
||
|
|
public org.eclipse.swt.widgets.Decorations getSwtDecorations() {
|
||
|
|
return (org.eclipse.swt.widgets.Decorations) getSwtControl();
|
||
|
|
}//getSwtDecorations()//
|
||
|
|
/**
|
||
|
|
* Gets the frame's default button.
|
||
|
|
* @return The default button in this container.
|
||
|
|
*/
|
||
|
|
public Button getDefaultButton() {
|
||
|
|
return (Button) getSwtDecorations().getDefaultButton().getData();
|
||
|
|
}//getDefaultButton()//
|
||
|
|
/**
|
||
|
|
* Sets the frame's default button.
|
||
|
|
* @param defaultButton The default button in this container.
|
||
|
|
*/
|
||
|
|
public void setDefaultButton(Button defaultButton) {
|
||
|
|
getSwtDecorations().setDefaultButton(defaultButton != null ? defaultButton.getSwtButton() : null);
|
||
|
|
}//setDefaultButton()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.IDecoration#getMenuBar()
|
||
|
|
*/
|
||
|
|
public Menu getMenuBar() {
|
||
|
|
return menuBar;
|
||
|
|
}//getMenuBar()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.view.swt.IDecoration#setMenuBar(com.foundation.view.swt.Menu)
|
||
|
|
*/
|
||
|
|
public void setMenuBar(Menu menuBar) {
|
||
|
|
this.menuBar = menuBar;
|
||
|
|
}//setMenuBar()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.Container#center()
|
||
|
|
*/
|
||
|
|
public void center() {
|
||
|
|
Rectangle window = getSwtDecorations().getBounds();
|
||
|
|
Rectangle screen = getSwtDecorations().getMonitor().getBounds();
|
||
|
|
int x = (int) ((screen.width / 2) - (window.width / 2));
|
||
|
|
int y = (int) ((screen.height / 2) - (window.height / 2));
|
||
|
|
|
||
|
|
if(x < screen.x) {
|
||
|
|
x = screen.x;
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(y < screen.y) {
|
||
|
|
y = screen.y;
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
getSwtDecorations().setLocation(x, y);
|
||
|
|
}//center()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.Container#center(long[])
|
||
|
|
*/
|
||
|
|
public void center(long[] centerOnView) {
|
||
|
|
Frame frame = (Frame) getComponent(centerOnView);
|
||
|
|
Rectangle windowRect = getSwtDecorations().getBounds();
|
||
|
|
Rectangle screen = getSwtDecorations().getDisplay().getBounds();
|
||
|
|
Rectangle componentRect = frame.getSwtDecorations().getBounds();
|
||
|
|
|
||
|
|
int x = (int) ((componentRect.width / 2) - (windowRect.width / 2) + componentRect.x);
|
||
|
|
int y = (int) ((componentRect.height / 2) - (windowRect.height / 2) + componentRect.y);
|
||
|
|
|
||
|
|
if((x + windowRect.width) - screen.x > screen.width) {
|
||
|
|
x = (int) (screen.width - windowRect.width + screen.x);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if((y + windowRect.height) - screen.y > screen.height) {
|
||
|
|
y = (int) (screen.height - windowRect.height + screen.y);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(x < screen.x) {
|
||
|
|
x = screen.x;
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
if(y < screen.y) {
|
||
|
|
y = screen.y;
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
getSwtDecorations().setLocation(x, y);
|
||
|
|
}//center()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitializeAll()
|
||
|
|
*/
|
||
|
|
protected void internalViewInitializeAll() {
|
||
|
|
super.internalViewInitializeAll();
|
||
|
|
|
||
|
|
if(getMenuBar() != null) {
|
||
|
|
getMenuBar().internalViewInitializeAll();
|
||
|
|
}//if//
|
||
|
|
}//internalViewInitializeAll()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewReleaseAll()
|
||
|
|
*/
|
||
|
|
protected void internalViewReleaseAll() {
|
||
|
|
super.internalViewReleaseAll();
|
||
|
|
|
||
|
|
if(getMenuBar() != null) {
|
||
|
|
getMenuBar().internalViewReleaseAll();
|
||
|
|
}//if//
|
||
|
|
}//internalViewReleaseAll()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronizeAll()
|
||
|
|
*/
|
||
|
|
protected void internalViewSynchronizeAll() {
|
||
|
|
super.internalViewSynchronizeAll();
|
||
|
|
|
||
|
|
if(getMenuBar() != null) {
|
||
|
|
getMenuBar().internalViewSynchronizeAll();
|
||
|
|
}//if//
|
||
|
|
}//internalViewSynchronizeAll()//
|
||
|
|
/**
|
||
|
|
* Registers the listener(s) necessary to capture shell events.
|
||
|
|
*/
|
||
|
|
protected void registerShellListeners() {
|
||
|
|
/*
|
||
|
|
getSwtDecorations().addControlListener(new ControlListener() {
|
||
|
|
private boolean wasLastMaximized = false;
|
||
|
|
|
||
|
|
public void controlResized(ControlEvent e) {
|
||
|
|
boolean isMaximized = getSwtDecorations().getMaximized();
|
||
|
|
|
||
|
|
if(isMaximized != wasLastMaximized) {
|
||
|
|
wasLastMaximized = isMaximized;
|
||
|
|
shellMaximized(isMaximized);
|
||
|
|
}//if//
|
||
|
|
}//controlResized()//
|
||
|
|
public void controlMoved(ControlEvent e) {
|
||
|
|
}//controlMoved()//
|
||
|
|
});
|
||
|
|
getSwtDecorations().addListener(SWT.Iconify, new org.eclipse.swt.widgets.Listener() {
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
shellIconified(event);
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
getSwtDecorations().addListener(SWT.Deiconify, new org.eclipse.swt.widgets.Listener() {
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
shellDeiconified(event);
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
*/
|
||
|
|
|
||
|
|
/* GCJ Doesn't like this... since it isn't used I am commenting it.
|
||
|
|
getSwtDecorations().addListener(SWT.Close, new org.eclipse.swt.widgets.Listener() {
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
shellClosed(event);
|
||
|
|
event.doit = false;
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
getSwtDecorations().addListener(SWT.Activate, new org.eclipse.swt.widgets.Listener() {
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
shellActivated(event);
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
getSwtDecorations().addListener(SWT.Deactivate, new org.eclipse.swt.widgets.Listener() {
|
||
|
|
public void handleEvent(Event event) {
|
||
|
|
shellDeactivated(event);
|
||
|
|
}//handleEvent()//
|
||
|
|
});
|
||
|
|
*/
|
||
|
|
}//registerShellListeners()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewInitialize()
|
||
|
|
*/
|
||
|
|
protected void internalViewInitialize() {
|
||
|
|
//Add this component as a shell listener so we get shell events.//
|
||
|
|
registerShellListeners();
|
||
|
|
//Register for image and title changes. Note: it is not necessary to initialize the title & image since they will be updated on the container's refresh and an event will fire if they are anything other than null.//
|
||
|
|
registerListener(this);
|
||
|
|
|
||
|
|
if(getContainerTitle() != null) {
|
||
|
|
getSwtDecorations().setText(getContainerTitle());
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewInitialize();
|
||
|
|
}//internalViewInitialize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewRelease()
|
||
|
|
*/
|
||
|
|
protected void internalViewRelease() {
|
||
|
|
containerImagesHolder.release();
|
||
|
|
|
||
|
|
if(swtContainerImages != null) {
|
||
|
|
destroyImages(swtContainerImages);
|
||
|
|
swtContainerImages = null;
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
super.internalViewRelease();
|
||
|
|
unregisterListener(this);
|
||
|
|
}//internalViewRelease()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalViewSynchronize()
|
||
|
|
*/
|
||
|
|
protected void internalViewSynchronize() {
|
||
|
|
super.internalViewSynchronize();
|
||
|
|
}//internalViewSynchronize()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.Component#internalResourceHolderChanged(com.foundation.tcv.client.view.ResourceHolder, java.lang.Object, java.lang.Object)
|
||
|
|
*/
|
||
|
|
protected void internalResourceHolderChanged(ResourceHolder resource, Object oldValue, Object newValue, int flags) {
|
||
|
|
if(resource == containerImagesHolder) {
|
||
|
|
destroyImages(swtContainerImages);
|
||
|
|
swtContainerImages = createImages(containerImagesHolder.getValue() instanceof JefImage ? new JefImage[] {(JefImage) containerImagesHolder.getValue()} : (JefImage[]) containerImagesHolder.getValue());
|
||
|
|
getSwtDecorations().setImages(swtContainerImages == null ? new Image[0] : swtContainerImages);
|
||
|
|
}//if//
|
||
|
|
else {
|
||
|
|
super.internalResourceHolderChanged(resource, oldValue, newValue, flags);
|
||
|
|
}//else//
|
||
|
|
}//internalOnAssociationChanged()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.AbstractComponent#internalProcessMessage(com.foundation.tcv.model.ViewMessage)
|
||
|
|
*/
|
||
|
|
public Object internalProcessMessage(ViewMessage viewMessage) {
|
||
|
|
Object retVal = null;
|
||
|
|
|
||
|
|
switch(viewMessage.getMessageNumber()) {
|
||
|
|
case MESSAGE_INITIALIZE: {
|
||
|
|
if(getSwtControl() == null) {
|
||
|
|
int[] data = (int[]) viewMessage.getMessageData();
|
||
|
|
|
||
|
|
setContainer((Container) getComponent(data[0]));
|
||
|
|
setSwtWidget(new org.eclipse.swt.widgets.Decorations(getContainer().getSwtComposite(), data[1]));
|
||
|
|
getSwtWidget().setData(this);
|
||
|
|
|
||
|
|
//If the container has already been initialized then force the parent to re-layout so that this component will appear.//
|
||
|
|
if(getContainer().isInitialized()) {
|
||
|
|
getContainer().getSwtComposite().layout(true, true);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
registerListener(this);
|
||
|
|
}//if//
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_REQUEST_CLOSED_NOTIFICATION: {
|
||
|
|
sendClosedEvent = ((Boolean) viewMessage.getMessageData()).booleanValue();
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_MAXIMIZE: {
|
||
|
|
boolean isMaximized = ((Boolean) viewMessage.getMessageData()).booleanValue();
|
||
|
|
|
||
|
|
if(getSwtDecorations().getMaximized() != isMaximized) {
|
||
|
|
getSwtDecorations().setMaximized(isMaximized);
|
||
|
|
}//if//
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_MINIMIZE: {
|
||
|
|
boolean isMinimized = ((Boolean) viewMessage.getMessageData()).booleanValue();
|
||
|
|
|
||
|
|
if(getSwtDecorations().getMinimized() != isMinimized) {
|
||
|
|
getSwtDecorations().setMinimized(isMinimized);
|
||
|
|
}//if//
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_SHOW: {
|
||
|
|
if(getSwtDecorations().getMinimized()) {
|
||
|
|
getSwtDecorations().setMinimized(false);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
resize();
|
||
|
|
getSwtDecorations().setVisible(true);
|
||
|
|
getSwtDecorations().setFocus();
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_SEND_ACTIVATED_EVENTS: {
|
||
|
|
sendActivatedEvents = ((Boolean) viewMessage.getMessageData()).booleanValue();
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_SET_DEFAULT_BUTTON: {
|
||
|
|
setDefaultButton(viewMessage.getMessageData() != null ? (Button) getComponent(((Integer) viewMessage.getMessageData()).intValue()) : null);
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
case MESSAGE_SET_CONTAINER_IMAGES: {
|
||
|
|
containerImagesHolder.setValue(viewMessage.getMessageData());
|
||
|
|
break;
|
||
|
|
}//case//
|
||
|
|
default: {
|
||
|
|
retVal = super.internalProcessMessage(viewMessage);
|
||
|
|
}//case//
|
||
|
|
}//switch//
|
||
|
|
|
||
|
|
return retVal;
|
||
|
|
}//internalProcessMessage()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellClosed(ShellEvent e) {
|
||
|
|
if(sendClosedEvent) {
|
||
|
|
sendRoundTripMessage(MESSAGE_IS_CLOSED, null, null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
e.doit = false;
|
||
|
|
}//shellClosed()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellClosed(Event e) {
|
||
|
|
//TODO: Why have two shell closed methods? Which gets called?//
|
||
|
|
if(sendClosedEvent) {
|
||
|
|
sendRoundTripMessage(MESSAGE_IS_CLOSED, null, null);
|
||
|
|
}//if//
|
||
|
|
|
||
|
|
e.doit = false;
|
||
|
|
}//shellClosed()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellActivated(ShellEvent e) {
|
||
|
|
if(sendActivatedEvents) {
|
||
|
|
sendMessage(MESSAGE_IS_ACTIVATED, Boolean.TRUE);
|
||
|
|
}//if//
|
||
|
|
}//shellActivated()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellActivated(Event e) {
|
||
|
|
if(sendActivatedEvents) {
|
||
|
|
sendMessage(MESSAGE_IS_ACTIVATED, Boolean.TRUE);
|
||
|
|
}//if//
|
||
|
|
}//shellActivated()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellDeactivated(ShellEvent e) {
|
||
|
|
if(sendActivatedEvents) {
|
||
|
|
sendMessage(MESSAGE_IS_ACTIVATED, Boolean.FALSE);
|
||
|
|
}//if//
|
||
|
|
}//shellDeactivated()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellDeactivated(Event e) {
|
||
|
|
if(sendActivatedEvents) {
|
||
|
|
sendMessage(MESSAGE_IS_ACTIVATED, Boolean.FALSE);
|
||
|
|
}//if//
|
||
|
|
}//shellDeactivated()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellDeiconified(ShellEvent e) {
|
||
|
|
//if(!suspendResizeEvents) {
|
||
|
|
// sendMessage(MESSAGE_SET_MINIMIZED, Boolean.FALSE);
|
||
|
|
//}//if//
|
||
|
|
}//shellDeiconified()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellDeiconified(Event e) {
|
||
|
|
//if(!suspendResizeEvents) {
|
||
|
|
// sendMessage(MESSAGE_SET_MINIMIZED, Boolean.FALSE);
|
||
|
|
//}//if//
|
||
|
|
}//shellDeiconified()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellIconified(ShellEvent e) {
|
||
|
|
//if(!suspendResizeEvents) {
|
||
|
|
// sendMessage(MESSAGE_SET_MINIMIZED, Boolean.TRUE);
|
||
|
|
//}//if//
|
||
|
|
}//shellIconified()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
|
||
|
|
*/
|
||
|
|
public void shellIconified(Event e) {
|
||
|
|
//if(!suspendResizeEvents) {
|
||
|
|
// sendMessage(MESSAGE_SET_MINIMIZED, Boolean.TRUE);
|
||
|
|
//}//if//
|
||
|
|
}//shellIconified()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.Component.IComponentListener#imageChanged(com.foundation.tcv.swt.client.Component, org.eclipse.swt.graphics.Image)
|
||
|
|
*/
|
||
|
|
public void imageChanged(Component component, Image newImage) {
|
||
|
|
getSwtDecorations().setImage(newImage);
|
||
|
|
}//imageChanged()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.Component.IComponentListener#titleChanged(com.foundation.tcv.swt.client.Component, java.lang.String)
|
||
|
|
*/
|
||
|
|
public void titleChanged(Component component, String newTitle) {
|
||
|
|
getSwtDecorations().setText(newTitle);
|
||
|
|
}//titleChanged()//
|
||
|
|
/* (non-Javadoc)
|
||
|
|
* @see com.foundation.tcv.swt.client.Component.IComponentListener#toolTipTextChanged(com.foundation.tcv.swt.client.Component, java.lang.String)
|
||
|
|
*/
|
||
|
|
public void toolTipTextChanged(Component component, String newToolTipText) {
|
||
|
|
getSwtDecorations().setToolTipText(newToolTipText);
|
||
|
|
}//toolTipTextChanged()//
|
||
|
|
}//Frame//
|