/* * 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.server; import com.common.debug.*; import com.foundation.view.*; import com.foundation.view.resource.ResourceReference; import com.foundation.tcv.swt.*; import com.foundation.tcv.server.controller.*; import com.foundation.tcv.view.ViewMessage; public class Frame extends Container implements IFrame, IDecoration { /** The container's images resource (similar to component's containerImage, but allows multiple images to be specified). */ private SingleResourceAssociation containerImages; /** The optional method which will be called when the frame is closed. */ private IMethodAssociation closedMethod = null; /** The optional method which will be called when the frame is activated. */ private IMethodAssociation activatedMethod = null; /** The optional method which will be called when the frame is deactivated. */ private IMethodAssociation deactivatedMethod = null; /** The optional menu bar for the frame. */ private Menu menuBar = null; /** A cached reference to the button that is the default button for the frame. */ private Button currentDefaultButton = null; /** Whether the server has already requested minimize/maximize events from the client. */ private boolean isRequestingActivationEvents = false; /** * Frame default constructor. *

Warning: This is only for use by the framework. This should never be called to create a useable instance.

*/ public Frame() { }//Frame()// /** * Frame constructor. * This constructor is only used by the Window subclass. * @param sessionViewController The view controller for the current client session. * @param name The unique component name. */ protected Frame(SessionViewController sessionViewController, String name, int style) { super(sessionViewController, name, style); containerImages = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_IMAGES, false, null); }//Frame()// /** * Frame constructor. * @param parent The parent frame. * @param name The unique component name. * @param style The frame style. * @see #STYLE_BORDER * @see #STYLE_H_SCROLL * @see #STYLE_V_SCROLL * @see #STYLE_BORDER * @see #STYLE_LEFT_TO_RIGHT * @see #STYLE_RIGHT_TO_LEFT * @see #STYLE_NO_BACKGROUND * @see #STYLE_NO_FOCUS * @see #STYLE_NO_MERGE_PAINTS * @see #STYLE_NO_REDRAW_RESIZE * @see #STYLE_NO_RADIO_GROUP * @see #STYLE_CLOSE * @see #STYLE_MIN * @see #STYLE_MAX * @see #STYLE_RESIZE * @see #STYLE_TITLE * @see #STYLE_NO_TRIM * @see #STYLE_SHELL_TRIM * @see #STYLE_DIALOG_TRIM * @see #STYLE_ON_TOP * @see #STYLE_TOOL */ public Frame(Container parent, String name, int style) { super(parent, name, style); containerImages = new SingleResourceAssociation(this, this, getViewContext(), SingleResourceAssociation.TYPE_IMAGES, false, null); sendMessage(MESSAGE_INITIALIZE, new int[] {parent.getNumber(), style}); }//Frame()// /** * Sets the association container used to access the image array. * @param container The images association metadata. */ public void setContainerImagesAssociation(SingleAssociationContainer container) { verifyThread(); this.containerImages.setAssociations(container); }//setContainerImagesAssociation()// /** * Sets the component's default image array resource. * @param images The images to be displayed by this component. */ public void setDefaultContainerImages(ResourceReference images) { verifyThread(); this.containerImages.setDefaultValue(images); }//setDefaultContainerImages()// /** * Sets the container's default images. * @param images The image data array that will be displayed by the container when an image is needed to represent it (example: a tab in a tab panel). */ public void setDefaultContainerImages(JefImage[] images) { verifyThread(); this.containerImages.setDefaultValue(images); }//setDefaultContainerImages()// /** * Refreshes the images for the frame. */ protected void internalViewRefreshContainerImages() { if(containerImages.refresh()) { sendMessage(MESSAGE_SET_CONTAINER_IMAGES, containerImages.getValue()); }//if// }//internalViewRefreshContainerImages()// /* (non-Javadoc) * @see com.foundation.view.IView#maximize() */ public void maximize() { sendMessage(MESSAGE_MAXIMIZE, null); }//maximize()// /* (non-Javadoc) * @see com.foundation.view.IView#minimize() */ public void minimize() { sendMessage(MESSAGE_MINIMIZE, null); }//minimize()// /* (non-Javadoc) * @see com.foundation.view.IView#show() */ public void show() { sendMessage(MESSAGE_SHOW, null); }//show()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.Component#getDefaultVisibility() */ protected boolean getDefaultVisibility() { return false; }//getDefaultVisibility()// /** * Sets the method to be called when the frame is closed. * @param closedMethod The method to notify when the close function is performed. */ public void setClosedMethod(IMethodAssociation closedMethod) { this.closedMethod = closedMethod; sendMessage(MESSAGE_REQUEST_CLOSED_NOTIFICATION, closedMethod != null ? Boolean.TRUE : Boolean.FALSE); }//setClosedMethod()// /** * Sets the method to be called when the frame is activated. * @param activatedMethod The method to notify when the activated function is performed. */ public void setActivatedMethod(IMethodAssociation activatedMethod) { this.activatedMethod = activatedMethod; if((activatedMethod != null) && (!isRequestingActivationEvents)) { sendMessage(MESSAGE_SEND_ACTIVATED_EVENTS, Boolean.TRUE); isRequestingActivationEvents = true; }//if// }//setActivatedMethod()// /** * Sets the method to be called when the frame is deactivated. * @param deactivatedMethod The method to notify when the deactivated function is performed. */ public void setDeactivatedMethod(IMethodAssociation deactivatedMethod) { this.deactivatedMethod = deactivatedMethod; if((activatedMethod != null) && (!isRequestingActivationEvents)) { sendMessage(MESSAGE_SEND_ACTIVATED_EVENTS, Boolean.TRUE); isRequestingActivationEvents = true; }//if// }//setDeactivatedMethod()// /** * Gets the frame's default button. * @return The default button in this container. */ public Button getDefaultButton() { return currentDefaultButton; }//getDefaultButton()// /** * Sets the frame's default button. * @param defaultButton The default button in this container. */ public void setDefaultButton(Button defaultButton) { currentDefaultButton = defaultButton; sendMessage(MESSAGE_SET_DEFAULT_BUTTON, defaultButton != null ? new Integer(((Button) defaultButton).getNumber()) : null); }//setDefaultButton()// /* (non-Javadoc) * @see com.foundation.view.swt.IDecoration#getMenuBar() */ public Menu getMenuBar() { verifyThread(); return menuBar; }//getMenuBar()// /* (non-Javadoc) * @see com.foundation.view.swt.IDecoration#setMenuBar(com.foundation.view.swt.Menu) */ public void setMenuBar(Menu menuBar) { verifyThread(); if(isInitialized() && this.menuBar != null) { this.menuBar.internalViewReleaseAll(); }//if// this.menuBar = menuBar; if(isInitialized()) { menuBar.internalViewInitializeAll(); }//if// }//setMenuBar()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitializeAll() */ protected void internalViewInitializeAll() { super.internalViewInitializeAll(); //Initialize the menu bar if there is one.// if(getMenuBar() != null) { getMenuBar().internalViewInitializeAll(); }//if// }//internalViewInitializeAll()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewReleaseAll() */ protected void internalViewReleaseAll() { super.internalViewReleaseAll(); if(getMenuBar() != null) { getMenuBar().internalViewReleaseAll(); }//if// }//internalViewReleaseAll()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefreshAll() */ protected void internalViewRefreshAll() { super.internalViewRefreshAll(); if(getMenuBar() != null) { getMenuBar().internalViewRefreshAll(); }//if// }//internalViewRefreshAll()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewInitialize() */ protected void internalViewInitialize() { containerImages.initialize(); super.internalViewInitialize(); }//internalViewInitialize()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRelease() */ protected void internalViewRelease() { containerImages.release(); super.internalViewRelease(); }//internalViewRelease()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#internalViewRefresh() */ protected void internalViewRefresh() { try { internalViewRefreshContainerImages(); super.internalViewRefresh(); }//try// catch(Throwable e) { Debug.log(e); }//catch// }//internalViewRefresh()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.Component#internalOnValueChanged(com.foundation.view.SingleResourceAssociation, boolean) */ protected void internalOnValueChanged(SingleResourceAssociation resourceAssociation, int flags) { if(resourceAssociation == containerImages) { internalViewRefreshContainerImages(); }//if// else { super.internalOnValueChanged(resourceAssociation, flags); }//else// }//internalOnValueChanged()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#processMessage(com.foundation.tcv.model.ViewMessage) */ public Object processMessage(ViewMessage viewMessage) { Object retVal = null; switch(viewMessage.getMessageNumber()) { case MESSAGE_IS_CLOSED: { if(closedMethod != null) { closedMethod.invoke(null, false); }//if// break; }//case// case MESSAGE_IS_ACTIVATED: { Boolean isActivated = (Boolean) viewMessage.getMessageData(); if(isActivated.booleanValue()) { if(activatedMethod != null) { activatedMethod.invoke(null, false); }//if// }//if// else { if(deactivatedMethod != null) { deactivatedMethod.invoke(null, false); }//if// }//else// break; }//case// default: { retVal = super.processMessage(viewMessage); break; }//default// }//switch// return retVal; }//processMessage()// /* (non-Javadoc) * @see com.foundation.tcv.swt.server.AbstractComponent#getClientClassName() */ protected String getClientClassName() { return "com.foundation.tcv.swt.client.Frame"; }//getClientClassName()// }//Frame//