Package net.xoetrope.swing.app

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

package net.xoetrope.swing.app;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import java.util.Hashtable;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
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.XProjectManager;
import net.xoetrope.xui.XStartupObject;

/**
* A startup class for a desktop/MDI style of application
* <p>Copyright: (c) Xoetrope Ltd., 1998-2003<br>
* License:      see license.txt
* @version $Revision: 1.2 $
*/
public class XDesktopApp extends JFrame implements XStartupObject
{
  protected JDesktopPane desktopPane;
  protected XApplicationContext applicationContext; 

  /**
   * Creates a new instance of XDesktopApp
   * @param args the startup arguments
   */
  public XDesktopApp( String[] args )
  {
    super( "XUI" );
    desktopPane = new JDesktopPane();

    //Set up the GUI.
    setContentPane( desktopPane );

    // Make dragging a little faster but perhaps uglier.
    desktopPane.setDragMode( JDesktopPane.OUTLINE_DRAG_MODE );

    XInternalFrameWidgetAdapter.getInstance();
    applicationContext = new XApplicationContext( this, "net.xoetrope.swing.app.XInternalFrame", args );
  }
 
  /**
   * Get the package name for the default widget set
   */
  public String getWidgetClassPackage()
  {
    return XPage.XUI_SWING_PACKAGE;
  }
 
  /**
   * Get the content pane used by XUI - the container in which pages are
   * displayed
   * @return the page container
   */
  public Object getContentPaneEx()
  {
    return getContentPane();
  }
 
  /**
   * Get a startup parameter
   * @param param the name of the parameter
   */
  public String getParameter( String param )
  {
    return "";
  }
 
  public Object getParentObject()
  {
    return super.getParent();
  }
 
  /**
   * Gets the URL of the document in which this applet is embedded.
   * For example, suppose an applet is contained
   * within the document:
   * <blockquote><pre>
   *    http://java.sun.com/products/jdk/1.2/index.html
   * </pre></blockquote>
   * The document base is:
   * <blockquote><pre>
   *    http://java.sun.com/products/jdk/1.2/index.html
   * </pre></blockquote>
   *
   * @return  the {@link java.net.URL} of the document that contains this
   *          applet.
   * @see     java.applet.Applet#getCodeBase()
   */
  public URL getDocumentBase()
  {
    return null;
  }
 
  /**
   * 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()
  {
    invalidate();
    validate();
    repaint();
  }

  /**
   * <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()
  {
  }
 
  public void setAppTitle( String title )
  {
    setTitle( title );
  }
 
  /**
   * Set the application icon
   * @param img the image name
   */
  public void setIcon( Image img )
  {
    setIconImage( img );
  }
 
  /**
   * Setup the windowing.
   * @param context the owner application context
   * @param currentProject the owner project
   * @param clientWidth the desired width of the application
   * @param clientHeight the desired height of the application
   */
  public void setupWindow( XApplicationContext context, XProject currentProject, int clientWidth, int clientHeight )
  {
    currentProject.setStartupParam( "MainClass", "net.xoetrope.swing.app.XDesktopApp" );

    setSize( clientWidth, clientHeight );
    addWindowListener( context );

   
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = getSize();
    String center = null;
    try {
      center = currentProject.getStartupParam( "CenterWin" );
    }
    catch ( Exception ex ) {
    }
    if ( ( center != null ) && ( center.compareTo( "true" ) == 0 ) )
      setLocation(( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );
    setVisible( true );
   
    currentProject.setApplet( null );
    currentProject.setStartupObject( this );
    currentProject.setAppFrame( this );
    currentProject.setAppWindow( null );
  }

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

  /**
    * Set the menubar
    * @param mb the menubar
    */
  public void setApplicationMenuBar( Object mb )
  {
    setJMenuBar( (JMenuBar)mb );
  }
 
  /**
   * Create the GUI and show it.  For thread safety,
   * this method should be invoked from the
   * event-dispatching thread.
   */
  private static void createAndShowGUI( String[] args )
  {
    //Make sure we have nice window decorations.... but this causes a problem
    // with the Windows LAF in JDK 1.5 at least - Luan
    //JFrame.setDefaultLookAndFeelDecorated( true );

    //Create and set up the window.
    XDesktopApp frame = new XDesktopApp( args );
    frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );

    //Display the window.
    frame.setVisible( true );
  }

  /**
   * main method to be invoked as an application. This method is invoked as the
   * entry point to the 'Application', it is not used if an Applet is being
   * launched. This method establishes the frame within which the application
   * runs. If overloading this method remeber to call the setup method.
   * @param args the command line arguments
   */
  public static void main( String args[] )
  {
    final String[] theArgs = args;
   
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater( new Runnable() {
      public void run()
      {
        createAndShowGUI( theArgs );
      }
    });
  }
}
TOP

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

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.