From: <pg...@us...> - 2007-05-24 23:26:44
|
Revision: 159 http://simulacion.svn.sourceforge.net/simulacion/?rev=159&view=rev Author: pguyot Date: 2007-05-24 16:26:41 -0700 (Thu, 24 May 2007) Log Message: ----------- More work on the applet GUI, which is nearly completely functional. Modified Paths: -------------- simulacion/src/fr/lip6/sma/simulacion/app/ApplicationWindow.java simulacion/src/fr/lip6/sma/simulacion/app/LocalizedWindow.java simulacion/src/fr/lip6/sma/simulacion/app/ModalWindow.java simulacion/src/fr/lip6/sma/simulacion/avatar/AvatarDialog2D.java simulacion/src/fr/lip6/sma/simulacion/gui/BaseApplet.java simulacion/src/fr/lip6/sma/simulacion/gui/GraphicalUserInterface.java simulacion/src/fr/lip6/sma/simulacion/gui/SwingAppletGUI.java simulacion/src/fr/lip6/sma/simulacion/gui/SwingApplicationGUI.java simulacion/src/fr/lip6/sma/simulacion/gui/Window.java simulacion/src/fr/lip6/sma/simulacion/gui/WindowImplementation.java Added Paths: ----------- simulacion/src/fr/lip6/sma/simulacion/gui/WindowKind.java Modified: simulacion/src/fr/lip6/sma/simulacion/app/ApplicationWindow.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/app/ApplicationWindow.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/app/ApplicationWindow.java 2007-05-24 23:26:41 UTC (rev 159) @@ -32,6 +32,8 @@ import java.lang.reflect.InvocationTargetException; import java.security.AccessControlException; +import fr.lip6.sma.simulacion.gui.WindowKind; + /** * Classe de base pour les fen\xEAtres des applications Simulaci\xF3n. * G\xE8re la traduction des \xE9l\xE9ments graphiques et la fermeture. @@ -63,6 +65,8 @@ * @param inApplication application object. */ protected ApplicationWindow(Application inApplication) { + super(WindowKind.MAIN_WINDOW, inApplication.getConfiguration()); + // On note le mod\xE8le. mApplication = inApplication; Modified: simulacion/src/fr/lip6/sma/simulacion/app/LocalizedWindow.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/app/LocalizedWindow.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/app/LocalizedWindow.java 2007-05-24 23:26:41 UTC (rev 159) @@ -41,6 +41,7 @@ import fr.lip6.sma.simulacion.gui.Window; import fr.lip6.sma.simulacion.gui.WindowAdapter; import fr.lip6.sma.simulacion.gui.WindowEvent; +import fr.lip6.sma.simulacion.gui.WindowKind; /** * Classe pour une fen\xEAtre dans la langue de l'utilisateur. C'est la classe de @@ -63,9 +64,20 @@ private boolean mShown; /** - * Constructeur par d\xE9faut. + * Default constructor. */ public LocalizedWindow() { + this(WindowKind.REGULAR_WINDOW); + } + + /** + * Constructor from a window kind. + * + * @param inWindowKind kind of window. + */ + public LocalizedWindow(WindowKind inWindowKind) { + super(inWindowKind); + mLocalizationEngine = LocalizationEngine.getEngine(); init(); } @@ -76,6 +88,17 @@ * @param inConfigPath path to the configuration file. */ public LocalizedWindow(String inConfigPath) { + this(WindowKind.REGULAR_WINDOW, inConfigPath); + } + + /** + * Constructor from a window kind and the configuration file. + * + * @param inWindowKind kind of window. + * @param inConfigPath path to the configuration file. + */ + public LocalizedWindow(WindowKind inWindowKind, String inConfigPath) { + super(inWindowKind); mLocalizationEngine = LocalizationEngine.getEngine(inConfigPath); init(); } @@ -86,6 +109,17 @@ * @param inConfig reference on the configuration. */ public LocalizedWindow(Configuration inConfig) { + this(WindowKind.REGULAR_WINDOW, inConfig); + } + + /** + * Constructor from a window kind and the configuration. + * + * @param inWindowKind kind of window. + * @param inConfig reference on the configuration. + */ + public LocalizedWindow(WindowKind inWindowKind, Configuration inConfig) { + super(inWindowKind); mLocalizationEngine = LocalizationEngine.getEngine(inConfig); init(); } Modified: simulacion/src/fr/lip6/sma/simulacion/app/ModalWindow.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/app/ModalWindow.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/app/ModalWindow.java 2007-05-24 23:26:41 UTC (rev 159) @@ -28,21 +28,20 @@ package fr.lip6.sma.simulacion.app; // imports +import fr.lip6.sma.simulacion.gui.WindowKind; /** - * Classe de base pour une fen\xEAtre sans d\xE9coration, centr\xE9e. + * Base class for a centered, undecorated window. * * @author Paul Guyot <pau...@ac...> * @version $Revision$ - * - * @see "aucun test d\xE9fini." */ public class ModalWindow extends LocalizedWindow { /** - * Constructeur par d\xE9faut. + * Default constructor. */ public ModalWindow() { - setUndecorated(true); + super(WindowKind.UNDECORATED_WINDOW); } } Modified: simulacion/src/fr/lip6/sma/simulacion/avatar/AvatarDialog2D.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/avatar/AvatarDialog2D.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/avatar/AvatarDialog2D.java 2007-05-24 23:26:41 UTC (rev 159) @@ -122,87 +122,98 @@ synchronized (this) { if (mKeepRunning) { // R\xE9cup\xE9ration des couches. - final Map[] theLayers = mModel.getImageCollection(mCollectionID) + final Map[] theLayers = + mModel.getImageCollection(mCollectionID) .getLayers(inNewAttitude); - // Cr\xE9ation/remplacement du tableau des indices et des couches. - final int nbLayers = theLayers.length; - mIndexes = new int[nbLayers][]; - mSequences = new Image[nbLayers][][]; - mLayerIsHorizontal = new boolean[nbLayers]; - - // Dimension maximale des couches. - int maxWidth = 0; - int maxHeight = 0; - - // It\xE9ration sur les couches. - int indexLayers; - for ( - indexLayers = 0; - indexLayers < nbLayers; - indexLayers++) { - int layerHeight = 0; - int layerWidth = 0; - - final boolean isHorizontal = theLayers[indexLayers].get( - AvatarImageCollection.LAYER_ORIENTATION_KEY) - .equals( - AvatarImageCollection - .LAYER_HORIZONTAL_ORIENTATION); - mLayerIsHorizontal[indexLayers] = isHorizontal; - - // On r\xE9cup\xE8re les s\xE9quences. - final Image[][] slices = (Image[][]) - theLayers[indexLayers].get( - AvatarImageCollection.LAYER_SLICES_KEY); - final int nbSlices = slices.length; - mSequences[indexLayers] = slices; - mIndexes[indexLayers] = new int[nbSlices]; + if (theLayers != null) { + final Dimension myNewSize = updateLayers(theLayers); - // On commence par les premi\xE8res images. - int indexSlices; - for ( - indexSlices = 0; - indexSlices < nbSlices; - indexSlices++) { - mIndexes[indexLayers][indexSlices] = 0; - - // Calcul de la taille de cette couche. - if (isHorizontal) { - layerHeight += - mSequences[indexLayers][indexSlices][0] - .getHeight(this); - } else { - layerWidth += - mSequences[indexLayers][indexSlices][0] - .getWidth(this); - } - } - - if (isHorizontal) { - layerWidth = - mSequences[indexLayers][0][0].getWidth(this); - } else { - layerHeight = - mSequences[indexLayers][0][0].getHeight(this); - } - - if (layerWidth > maxWidth) { - maxWidth = layerWidth; - } - if (layerHeight > maxHeight) { - maxHeight = layerHeight; - } + // Define that as our new preferred size. + setPreferredSize(myNewSize); } - - // On se redimensionne en fonction de la taille des images. - setPreferredSize( - new Dimension(maxWidth, maxHeight)); } } } /** + * Update the layer arrays to build the image. + * + * @param inLayers new layers. + * @return the dimension of the image. + */ + private Dimension updateLayers(Map[] inLayers) { + // Cr\xE9ation/remplacement du tableau des indices et des + // couches. + final int nbLayers = inLayers.length; + mIndexes = new int[nbLayers][]; + mSequences = new Image[nbLayers][][]; + mLayerIsHorizontal = new boolean[nbLayers]; + + // Dimension maximale des couches. + int maxWidth = 0; + int maxHeight = 0; + + // It\xE9ration sur les couches. + int indexLayers; + for ( + indexLayers = 0; + indexLayers < nbLayers; + indexLayers++) { + int layerHeight = 0; + int layerWidth = 0; + + final boolean isHorizontal = + inLayers[indexLayers].get( + AvatarImageCollection.LAYER_ORIENTATION_KEY) + .equals(AvatarImageCollection.LAYER_HORIZONTAL_ORIENTATION); + mLayerIsHorizontal[indexLayers] = isHorizontal; + + // On r\xE9cup\xE8re les s\xE9quences. + final Image[][] slices = (Image[][]) + inLayers[indexLayers].get( + AvatarImageCollection.LAYER_SLICES_KEY); + final int nbSlices = slices.length; + mSequences[indexLayers] = slices; + mIndexes[indexLayers] = new int[nbSlices]; + + // On commence par les premi\xE8res images. + int indexSlices; + for ( + indexSlices = 0; + indexSlices < nbSlices; + indexSlices++) { + mIndexes[indexLayers][indexSlices] = 0; + + // Calcul de la taille de cette couche. + if (isHorizontal) { + layerHeight += + mSequences[indexLayers][indexSlices][0].getHeight(this); + } else { + layerWidth += + mSequences[indexLayers][indexSlices][0].getWidth(this); + } + } + + if (isHorizontal) { + layerWidth = mSequences[indexLayers][0][0].getWidth(this); + } else { + layerHeight = mSequences[indexLayers][0][0].getHeight(this); + } + + if (layerWidth > maxWidth) { + maxWidth = layerWidth; + } + if (layerHeight > maxHeight) { + maxHeight = layerHeight; + } + } + + // Return the dimension of the image. + return new Dimension(maxWidth, maxHeight); + } + + /** * M\xE9thode invoqu\xE9e pour dessiner le composant. * * @param inGraphics contexte pour dessiner Modified: simulacion/src/fr/lip6/sma/simulacion/gui/BaseApplet.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/BaseApplet.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/gui/BaseApplet.java 2007-05-24 23:26:41 UTC (rev 159) @@ -28,10 +28,12 @@ package fr.lip6.sma.simulacion.gui; // imports +import java.awt.Component; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.swing.JApplet; +import javax.swing.JLayeredPane; /** * Base class for the applet. @@ -48,6 +50,11 @@ private final Class mMainClass; /** + * Pane for the items in the applet. + */ + private final JLayeredPane mLayeredPane; + + /** * Constructor from a class. * * @param inMainClass class with the main entry point. @@ -57,6 +64,10 @@ new SwingAppletGUI(this); mMainClass = inMainClass; + + // We use a JLayeredPane. + mLayeredPane = new JLayeredPane(); + add(mLayeredPane); } /** @@ -96,6 +107,34 @@ theExecThread.start(); } } + + /** + * Add a window. + * + * @param inWindow window to add. + * @param inKind kind of the window to add. + */ + public void addWindow(Component inWindow, WindowKind inKind) { + int theLevel; + switch (inKind) { + case REGULAR_WINDOW: + theLevel = 0; + break; + + case UNDECORATED_WINDOW: + theLevel = 10; + break; + + case MAIN_WINDOW: + theLevel = -10; + break; + + default: + theLevel = 0; + } + mLayeredPane.add(inWindow, new Integer(theLevel)); + validate(); + } } // ======================================================================== // Modified: simulacion/src/fr/lip6/sma/simulacion/gui/GraphicalUserInterface.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/GraphicalUserInterface.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/gui/GraphicalUserInterface.java 2007-05-24 23:26:41 UTC (rev 159) @@ -77,9 +77,11 @@ * Create a window. * * @param inHook hook for the subclass method calls. + * @param inKind kind of window to create. * @return a new window. */ - public abstract WindowImplementation createWindow(WindowHook inHook); + public abstract WindowImplementation createWindow( + WindowHook inHook, WindowKind inKind); /** * Create the GUI. @@ -90,14 +92,7 @@ } } -// ========================================================================= // -// If just one piece of mail gets lost, well, they'll just think they forgot // -// to send it. But if *two* pieces of mail get lost, hell, they'll just // -// think the other guy hasn't gotten around to answering his mail. And if // -// *fifty* pieces of mail get lost, can you imagine it, if *fifty* pieces of // -// mail get lost, why they'll think someone *else* is broken! And if 1Gb of // -// mail gets lost, they'll just *know* that Arpa [ucbarpa.berkeley.edu] is // -// down and think it's a conspiracy to keep them from their God given right // -// to receive Net Mail ... // -// -- Casey Leedom // -// ========================================================================= // +// ====================================================================== // +// Real Users find the one combination of bizarre input values that shuts // +// down the system for days. // +// ====================================================================== // Modified: simulacion/src/fr/lip6/sma/simulacion/gui/SwingAppletGUI.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/SwingAppletGUI.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/gui/SwingAppletGUI.java 2007-05-24 23:26:41 UTC (rev 159) @@ -28,9 +28,12 @@ package fr.lip6.sma.simulacion.gui; // imports +import java.awt.Color; import java.awt.Dimension; +import javax.swing.BorderFactory; import javax.swing.JInternalFrame; +import javax.swing.JRootPane; /** * Class for the swing applet GUI. @@ -45,9 +48,9 @@ private final BaseApplet mApplet; /** - * Class for the internal frames in the applet. + * Class for an undecorated frame in the applet. */ - private static final class AppletFrame extends JInternalFrame + private static final class AppletUndecoratedFrame extends JRootPane implements WindowImplementation { /** * Reference on the hook for overridden methods. @@ -58,6 +61,11 @@ * Reference on the applet we belong to. */ private final BaseApplet mApplet; + + /** + * Kind of window. + */ + private final WindowKind mWindowKind; /** * If we've been added to the applet. @@ -67,12 +75,19 @@ /** * Constructor from the hook and the applet. * - * @param inHook hook for overriden methods. - * @param inApplet applet we belong to. + * @param inHook hook for overriden methods. + * @param inApplet applet we belong to. + * @param inWindowKind kind of window. */ - private AppletFrame(WindowHook inHook, BaseApplet inApplet) { + private AppletUndecoratedFrame( + WindowHook inHook, + BaseApplet inApplet, + WindowKind inWindowKind) { mHook = inHook; mApplet = inApplet; + mWindowKind = inWindowKind; + + setBorder(BorderFactory.createLineBorder(Color.BLACK)); } /** @@ -97,7 +112,7 @@ public void setVisible(boolean inVisible) { if (inVisible && !mAdded) { mAdded = true; - mApplet.add(this); + mApplet.addWindow(this, mWindowKind); } super.setVisible(inVisible); @@ -107,17 +122,122 @@ * {@inheritDoc} */ public void addWindowListener(WindowListener inWindowListener) { - addInternalFrameListener( - new ListenerProxy(mHook.getProxy(), inWindowListener)); + // TODO: implement a window listener. } /** * {@inheritDoc} */ - public void setUndecorated(boolean inUndecorated) { + public void dispose() { + setVisible(false); + } + + /** + * {@inheritDoc} + */ + public void pack() { + setSize(getPreferredSize()); + } + + /** + * {@inheritDoc} + */ + public void setDefaultCloseOperation(int inOperation) { + // TODO: implement close operation stuff. + } + + /** + * {@inheritDoc} + */ + public void setResizable(boolean inResizable) { // This space for rent. } + + /** + * {@inheritDoc} + */ + public void setTitle(String inTitle) { + // This space for rent. + } } + + /** + * Class for the internal frames in the applet. + */ + private static final class AppletFrame extends JInternalFrame + implements WindowImplementation { + /** + * Reference on the hook for overridden methods. + */ + private final WindowHook mHook; + + /** + * Reference on the applet we belong to. + */ + private final BaseApplet mApplet; + + /** + * Kind of window. + */ + private final WindowKind mWindowKind; + + /** + * If we've been added to the applet. + */ + private boolean mAdded; + + /** + * Constructor from the hook and the applet. + * + * @param inHook hook for overriden methods. + * @param inApplet applet we belong to. + * @param inWindowKind kind of window. + */ + private AppletFrame( + WindowHook inHook, + BaseApplet inApplet, + WindowKind inWindowKind) { + mHook = inHook; + mApplet = inApplet; + mWindowKind = inWindowKind; + } + + /** + * {@inheritDoc} + */ + public void addNotify() { + super.addNotify(); + mHook.addNotify(); + } + + /** + * {@inheritDoc} + */ + public void removeNotify() { + super.removeNotify(); + mHook.removeNotify(); + } + + /** + * {@inheritDoc} + */ + public void setVisible(boolean inVisible) { + if (inVisible && !mAdded) { + mAdded = true; + mApplet.addWindow(this, mWindowKind); + } + + super.setVisible(inVisible); + } + + /** + * {@inheritDoc} + */ + public void addWindowListener(WindowListener inWindowListener) { + addInternalFrameListener( + new ListenerProxy(mHook.getProxy(), inWindowListener)); + } + } /** * Constructor from the base applet. @@ -136,13 +256,19 @@ } /** - * Create a window. + * {@inheritDoc} * - * @param inHook hook for the subclass method calls. - * @return a new window. + * We currently ignore inKind parameter. */ - public WindowImplementation createWindow(final WindowHook inHook) { - final WindowImplementation theResult = new AppletFrame(inHook, mApplet); + public WindowImplementation createWindow( + WindowHook inHook, WindowKind inKind) { + WindowImplementation theResult; + if ((inKind == WindowKind.MAIN_WINDOW) + || (inKind == WindowKind.UNDECORATED_WINDOW)) { + theResult = new AppletUndecoratedFrame(inHook, mApplet, inKind); + } else { + theResult = new AppletFrame(inHook, mApplet, inKind); + } return theResult; } Modified: simulacion/src/fr/lip6/sma/simulacion/gui/SwingApplicationGUI.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/SwingApplicationGUI.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/gui/SwingApplicationGUI.java 2007-05-24 23:26:41 UTC (rev 159) @@ -53,10 +53,14 @@ /** * Constructor from a hook. * - * @param inHook hook for overridden methods. + * @param inHook hook for overridden methods. + * @param inKind kind of windows. */ - private ApplicationFrame(WindowHook inHook) { + private ApplicationFrame(WindowHook inHook, WindowKind inKind) { mHook = inHook; + if (inKind == WindowKind.UNDECORATED_WINDOW) { + setUndecorated(true); + } } /** @@ -99,13 +103,11 @@ } /** - * Create a window. - * - * @param inHook hook for the subclass method calls. - * @return a new window. + * {@inheritDoc} */ - public WindowImplementation createWindow(final WindowHook inHook) { - return new ApplicationFrame(inHook); + public WindowImplementation createWindow( + WindowHook inHook, WindowKind inKind) { + return new ApplicationFrame(inHook, inKind); } } Modified: simulacion/src/fr/lip6/sma/simulacion/gui/Window.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/Window.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/gui/Window.java 2007-05-24 23:26:41 UTC (rev 159) @@ -68,13 +68,15 @@ private boolean mCenterWindow; /** - * Default constructor. + * Constructor from a window kind. + * + * @param inKind kind of window we want. */ - public Window() { + public Window(WindowKind inKind) { // Note the associated GUI. mGraphicalUserInterface = GraphicalUserInterface.getGUI(); // Ask the GUI for a window implementation. - mImplementation = mGraphicalUserInterface.createWindow(this); + mImplementation = mGraphicalUserInterface.createWindow(this, inKind); } /** @@ -304,13 +306,6 @@ /** * {@inheritDoc} */ - public void setUndecorated(boolean inUndecorated) { - mImplementation.setUndecorated(inUndecorated); - } - - /** - * {@inheritDoc} - */ public void dispose() { mImplementation.dispose(); } Modified: simulacion/src/fr/lip6/sma/simulacion/gui/WindowImplementation.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/WindowImplementation.java 2007-05-24 22:11:07 UTC (rev 158) +++ simulacion/src/fr/lip6/sma/simulacion/gui/WindowImplementation.java 2007-05-24 23:26:41 UTC (rev 159) @@ -186,14 +186,6 @@ void setVisible(boolean inVisible); /** - * Remove (or reset) the decoration for this window. - * - * @param inUndecorated if this window should be undecorated. - * @see javax.swing.JFrame#setUndecorated(boolean) - */ - void setUndecorated(boolean inUndecorated); - - /** * Dispose this window. * * @see javax.swing.JFrame#dispose() Added: simulacion/src/fr/lip6/sma/simulacion/gui/WindowKind.java =================================================================== --- simulacion/src/fr/lip6/sma/simulacion/gui/WindowKind.java (rev 0) +++ simulacion/src/fr/lip6/sma/simulacion/gui/WindowKind.java 2007-05-24 23:26:41 UTC (rev 159) @@ -0,0 +1,49 @@ +// ============================== +// File: WindowKind.java +// Project: Simulaci\xF3n +// Written by: Paul Guyot (pau...@ac...) +// +// Created on: 20/5/2007 +// Tabs: 4 spaces +// +// This software is governed by the CeCILL license under French law and abiding +// by the rules of distribution of free software. You can use, modify and/ or +// redistribute the software under the terms of the CeCILL license as +// circulated by CEA, CNRS and INRIA at the following URL +// "http://www.cecill.info". +// +// As a counterpart to the access to the source code and rights to copy, modify +// and redistribute granted by the license, users are provided only with a +// limited warranty and the software's author, the holder of the economic +// rights, and the successive licensors have only limited liability. +// +// The fact that you are presently reading this means that you have had +// knowledge of the CeCILL license and that you accept its terms. +// +// =========== +// $Id$ +// =========== + +// package +package fr.lip6.sma.simulacion.gui; + +/** + * Window kinds. + * + * @author Paul Guyot <pau...@ac...> + * @version $Revision$ + */ +public enum WindowKind { + /** A regular window. */ + REGULAR_WINDOW, + + /** A window without native window manager decorations */ + UNDECORATED_WINDOW, + + /** The main window, which is undecorated for applets */ + MAIN_WINDOW; +} + +// ======================== // +// Beware the new TTY code! // +// ======================== // Property changes on: simulacion/src/fr/lip6/sma/simulacion/gui/WindowKind.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Revision Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |