Package net.xoetrope.swing.app

Source Code of net.xoetrope.swing.app.XuiProxy

package net.xoetrope.swing.app;

import java.awt.Container;
import java.awt.Image;
import java.awt.Window;
import java.net.URL;
import java.util.Hashtable;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;

import net.xoetrope.swing.SwingWidgetAdapter;
import net.xoetrope.xui.PageSupport;
import net.xoetrope.xui.XProject;

import net.xoetrope.xui.XApplicationContext;
import net.xoetrope.xui.XPage;
import net.xoetrope.xui.XStartupObject;

/**
* <p>The XuiProxy acts as a context for a XUI application embedded within
* another application, such as a Swing application. The proxy does not setup
* a frame or window as with other startup objects and instead it expects to
* be embedded within a container such as a JPanel. It is the launch
* application's reposnsibility to size and position the proxy as needed.
* </p>
* <p>Copyright (c) Xoetrope Ltd., 1998-2006. See license.txt for more details</p>
* @version $Revision: 1.1 $
*/
public class XuiProxy extends JPanel implements XStartupObject
{
  /**
   * The application window
   */
  protected Window appWindow;
 
  /**
   * The Application frame
   */
  protected JFrame clientFrame;

  /**
   * true if a popup window is in use
   */
  protected boolean bUseWindow;
 
  protected XApplicationContext applicationContext;
 
  /**
   * The panel holding the page content
   */
  protected Container pageHolder;
 
  /**
   * A default constructor. Most of the setup work is actually done by the initialize
   * method and is called by the main method or the init method depending on
   * whether or not an application of applet is being launched.
   * @param args the application command-line arguments
   * @param frame the parent frame
   */
  public XuiProxy()
  {
    this( null, null );
  }

  /**
    * Create a new aplication. Most of the setup work is actually done by the initialize
    * method and is called by the main method or the init method depending on
    * whether or not an application of applet is being launched.
    */
  public XuiProxy( String[] args, JFrame frame )
  {
    clientFrame = frame;
    SwingWidgetAdapter.getInstance();
    applicationContext = new XApplicationContext( this, args );
  }
 
  /**
   * Get the parent object
   * @return the parent
   */
  public Object getParentObject()
  {
    return getParent();
  }
 
  /**
   * Get the package name for the default widget set
   */
  public String getWidgetClassPackage()
  {
    return XPage.XUI_SWING_PACKAGE;
  }
 
  /**
   * Setup frameset. This method is called prior to the addition of any target
   * areas in the framset and prior to the display of any pages. Since this
   * applet does not support configurable framesets, this method ignores the
   * parameter values passed.
   * @param params the framset parameters if any
   */
  public void setupFrameset( Hashtable params )
  {   
  }
 
  /**
   * Display a window decoration, for example a toolbar
   * @param page the new page
   * @param constraint a value controlling how and where the decoration is
   * displayed, this value is application type specific
   * @return the page being displayed
   */
  public Object displayDecoration( PageSupport page, String constraint )
  {
    /** @todo fill in this implementation */
    return null;
  }

  /**
   * Validate and repaint the display
   */
  public void refresh()
  {
    if ( appWindow != null ) {
      appWindow.invalidate();
      appWindow.validate();
      appWindow.repaint();
    }
    layout();
  }

  /**
   * <p>Restore the normal page views, as in the case of the docking layout where
   * panels may be zoomed or minimized. The method is called prior to the
   * display of a new page.</p>
   * <p>In this context the method has no effect.</p>
   */
  public void restoreViews()
  {
  }
 
  /**
   * Get the content pane used by XUI - the container in which pages are
   * displayed
   * @return the page container
   */
  public Object getContentPaneEx()
  {
    return this;
  }
 
  public void setAppTitle( String title )
  {
    try {
      if ( clientFrame != null )
        clientFrame.setTitle( title );
    }
    catch ( Exception ex1 ) {
      ex1.printStackTrace();
    }
  }
 
  /**
   * Set the application icon
   * @param img the image name
   */
  public void setIcon( Image icon )
  {
    if ( icon != null )
      clientFrame.setIconImage( icon );
  }

  /**
   * Setup the main application window
   * @param context the application context for the new application
   * @param currentProject the current project
   * @param clientWidth the desired width for the new window
   * @param clientHeight the desired height for the new window
   */
  public void setupWindow( XApplicationContext context, XProject currentProject, int clientWidth, int clientHeight )
  {
    //currentProject.setStartupParam( "MainClass", null );
    bUseWindow = false;
   
    appWindow = null;
  
    currentProject.setApplet( null );
    currentProject.setStartupObject( this );
    currentProject.setAppFrame( clientFrame );
    currentProject.setAppWindow( appWindow );  
  }
 

  /**
   * Invoked when used as an applet. Sets up the startup file and initialises
   * the application. Reads the applet parameters and calls initialize.
   */
  public void init()
  {
    applicationContext.init();
  }

  /**
   * Gets the Frame containing the applet.
   * @return Frame which is the applet or application's parent
   */
  public JFrame getFrame()
  {
    if ( clientFrame != null )
      return clientFrame;
   
    Container parent;
    for ( parent = getParent(); parent != null; parent = parent.getParent() ) {
      if (( parent != null ) && ( parent instanceof JFrame ))
        return (JFrame)parent;
    }
   
    return null;
  }

  /**
   * Set the menubar.
   * @param mb the new menu bar
   */
  public void setMenuBar( JMenuBar mb )
  {
    clientFrame.setJMenuBar( mb );
  }

  /**
   * Get the menubar.
   * @return the menu bar
   */
  public Object getApplicationMenuBar()
  {
    return clientFrame.getJMenuBar();
  }

  /**
    * Set the menubar
    * @param mb the menubar
    */
  public void setApplicationMenuBar( Object mb )
  {
    clientFrame.setJMenuBar( (JMenuBar)mb );
   
    // Force the menu to refresh, otherwise the menu is not usable till the
    // frame is revalidated/resized
    ((JMenuBar)mb).setVisible( false );
    ((JMenuBar)mb).setVisible( true );
  }
 
 
  /**
   * <p>Gets the URL of the document in which this applet is embedded.
   * </p>
   * <p>
   * Returns null in this instance</p>
   * @return  the {@link java.net.URL} of the document that contains this
   *          applet.
   */
  public URL getDocumentBase()
  {
    return null;
  }

  /**
   * Get a startup parameter
   * <p>
   * Returns null in this instance</p>
   * @param param the name of the parameter
   */
  public String getParameter( String param )
  {
    return null;
  }
}
TOP

Related Classes of net.xoetrope.swing.app.XuiProxy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.