Some further FrameManager wrangling and a proper bridge for managed applets.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@32 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -42,7 +42,6 @@ import java.awt.EventQueue;
|
|||||||
import javax.swing.JLayeredPane;
|
import javax.swing.JLayeredPane;
|
||||||
import javax.swing.RepaintManager;
|
import javax.swing.RepaintManager;
|
||||||
import javax.swing.JRootPane;
|
import javax.swing.JRootPane;
|
||||||
import javax.swing.RootPaneContainer;
|
|
||||||
import javax.swing.event.AncestorEvent;
|
import javax.swing.event.AncestorEvent;
|
||||||
import javax.swing.event.AncestorListener;
|
import javax.swing.event.AncestorListener;
|
||||||
|
|
||||||
@@ -122,15 +121,30 @@ public abstract class FrameManager
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a bridge between either {@link ManagedJFrame} or {@link
|
||||||
|
* ManagedJApplet} and the frame manager.
|
||||||
|
*/
|
||||||
|
public static interface ManagedRoot
|
||||||
|
{
|
||||||
|
/** Configures the root with a reference to its frame manager. */
|
||||||
|
public void init (FrameManager fmgr);
|
||||||
|
|
||||||
|
/** Returns the window at the root of the UI hierarchy. */
|
||||||
|
public Window getWindow ();
|
||||||
|
|
||||||
|
/** Returns the top-level Swing pane. */
|
||||||
|
public JRootPane getRootPane();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a frame manager that will use a {@link SystemMediaTimer} to
|
* Creates a frame manager that will use a {@link SystemMediaTimer} to
|
||||||
* obtain timing information, which is available on every platform, but
|
* obtain timing information, which is available on every platform, but
|
||||||
* returns inaccurate time stamps on many platforms.
|
* returns inaccurate time stamps on many platforms.
|
||||||
*
|
*
|
||||||
* @see #newInstance(Window, RootPaneContainer, MediaTimer)
|
* @see #newInstance(ManagedRoot, MediaTimer)
|
||||||
*/
|
*/
|
||||||
public static FrameManager newInstance (
|
public static FrameManager newInstance (ManagedRoot root)
|
||||||
Window window, RootPaneContainer root)
|
|
||||||
{
|
{
|
||||||
// first try creating a PerfTimer which is the best if we're using
|
// first try creating a PerfTimer which is the best if we're using
|
||||||
// JDK1.4.2
|
// JDK1.4.2
|
||||||
@@ -142,20 +156,14 @@ public abstract class FrameManager
|
|||||||
"System.currentTimeMillis() based timer.");
|
"System.currentTimeMillis() based timer.");
|
||||||
timer = new SystemMediaTimer();
|
timer = new SystemMediaTimer();
|
||||||
}
|
}
|
||||||
return newInstance(window, root, timer);
|
return newInstance(root, timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a frame manager that will do its rendering to the
|
* Constructs a frame manager that will do its rendering to the supplied
|
||||||
* supplied frame. It is likely that the caller will want to have put
|
* root.
|
||||||
* the frame into full-screen exclusive mode prior to providing it to
|
|
||||||
* the frame manager so that the frame manager can take advantage of
|
|
||||||
* optimizations available in that mode.
|
|
||||||
*
|
|
||||||
* @see GraphicsDevice#setFullScreenWindow
|
|
||||||
*/
|
*/
|
||||||
public static FrameManager newInstance (
|
public static FrameManager newInstance (ManagedRoot root, MediaTimer timer)
|
||||||
Window window, RootPaneContainer root, MediaTimer timer)
|
|
||||||
{
|
{
|
||||||
FrameManager fmgr;
|
FrameManager fmgr;
|
||||||
if (_useFlip.getValue()) {
|
if (_useFlip.getValue()) {
|
||||||
@@ -165,21 +173,18 @@ public abstract class FrameManager
|
|||||||
Log.info("Creating back frame manager.");
|
Log.info("Creating back frame manager.");
|
||||||
fmgr = new BackFrameManager();
|
fmgr = new BackFrameManager();
|
||||||
}
|
}
|
||||||
fmgr.init(window, root, timer);
|
fmgr.init(root, timer);
|
||||||
return fmgr;
|
return fmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this frame manager and prepares it for operation.
|
* Initializes this frame manager and prepares it for operation.
|
||||||
*/
|
*/
|
||||||
protected void init (
|
protected void init (ManagedRoot root, MediaTimer timer)
|
||||||
Window window, RootPaneContainer root, MediaTimer timer)
|
|
||||||
{
|
{
|
||||||
_window = window;
|
_window = root.getWindow();
|
||||||
_root = root;
|
_root = root;
|
||||||
if (window instanceof ManagedJFrame) {
|
_root.init(this);
|
||||||
((ManagedJFrame)window).init(this);
|
|
||||||
}
|
|
||||||
_timer = timer;
|
_timer = timer;
|
||||||
|
|
||||||
// set up our custom repaint manager
|
// set up our custom repaint manager
|
||||||
@@ -773,7 +778,7 @@ public abstract class FrameManager
|
|||||||
protected Window _window;
|
protected Window _window;
|
||||||
|
|
||||||
/** Provides access to our Swing bits. */
|
/** Provides access to our Swing bits. */
|
||||||
protected RootPaneContainer _root;
|
protected ManagedRoot _root;
|
||||||
|
|
||||||
/** Used to obtain timing measurements. */
|
/** Used to obtain timing measurements. */
|
||||||
protected MediaTimer _timer;
|
protected MediaTimer _timer;
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Nenya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
|
||||||
|
// http://www.threerings.net/code/nenya/
|
||||||
|
//
|
||||||
|
// This library is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of the GNU Lesser General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
// Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public
|
||||||
|
// License along with this library; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
package com.threerings.media;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Shape;
|
||||||
|
import java.awt.Window;
|
||||||
|
import javax.swing.JApplet;
|
||||||
|
|
||||||
|
import com.threerings.media.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When using the {@link FrameManager} in an Applet, one must use this
|
||||||
|
* top-level class.
|
||||||
|
*/
|
||||||
|
public class ManagedJApplet extends JApplet
|
||||||
|
{
|
||||||
|
// from interface FrameManager.ManagedRoot
|
||||||
|
public void init (FrameManager fmgr)
|
||||||
|
{
|
||||||
|
_fmgr = fmgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// from interface FrameManager.ManagedRoot
|
||||||
|
public Window getWindow ()
|
||||||
|
{
|
||||||
|
Component parent = getParent();
|
||||||
|
while (!(parent instanceof Window) && parent != null) {
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
return (Window)parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the frame manager managing this frame.
|
||||||
|
*/
|
||||||
|
public FrameManager getFrameManager ()
|
||||||
|
{
|
||||||
|
return _fmgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from Component
|
||||||
|
public void paint (Graphics g)
|
||||||
|
{
|
||||||
|
// we catch paint requests and forward them on to the repaint
|
||||||
|
// infrastructure
|
||||||
|
update(g);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from Component
|
||||||
|
public void update (Graphics g)
|
||||||
|
{
|
||||||
|
Shape clip = g.getClip();
|
||||||
|
Rectangle dirty;
|
||||||
|
if (clip != null) {
|
||||||
|
dirty = clip.getBounds();
|
||||||
|
} else {
|
||||||
|
dirty = getRootPane().getBounds();
|
||||||
|
// account for our frame insets
|
||||||
|
Insets insets = getInsets();
|
||||||
|
dirty.x += insets.left;
|
||||||
|
dirty.y += insets.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_fmgr != null) {
|
||||||
|
_fmgr.restoreFromBack(dirty);
|
||||||
|
} else {
|
||||||
|
Log.info("Dropping AWT dirty rect " + dirty + " (" + clip + ").");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FrameManager _fmgr;
|
||||||
|
}
|
||||||
@@ -26,10 +26,12 @@ import java.awt.GraphicsConfiguration;
|
|||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Shape;
|
import java.awt.Shape;
|
||||||
|
import java.awt.Window;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import com.threerings.media.Log;
|
import com.threerings.media.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,6 +39,7 @@ import com.threerings.media.Log;
|
|||||||
* class.
|
* class.
|
||||||
*/
|
*/
|
||||||
public class ManagedJFrame extends JFrame
|
public class ManagedJFrame extends JFrame
|
||||||
|
implements FrameManager.ManagedRoot
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a managed frame with no title.
|
* Constructs a managed frame with no title.
|
||||||
@@ -62,14 +65,18 @@ public class ManagedJFrame extends JFrame
|
|||||||
super(gc);
|
super(gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// from interface FrameManager.ManagedRoot
|
||||||
* Called by our frame manager when it's ready to go.
|
|
||||||
*/
|
|
||||||
public void init (FrameManager fmgr)
|
public void init (FrameManager fmgr)
|
||||||
{
|
{
|
||||||
_fmgr = fmgr;
|
_fmgr = fmgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from interface FrameManager.ManagedRoot
|
||||||
|
public Window getWindow ()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the frame manager managing this frame.
|
* Returns the frame manager managing this frame.
|
||||||
*/
|
*/
|
||||||
@@ -107,9 +114,6 @@ public class ManagedJFrame extends JFrame
|
|||||||
|
|
||||||
if (_fmgr != null) {
|
if (_fmgr != null) {
|
||||||
_fmgr.restoreFromBack(dirty);
|
_fmgr.restoreFromBack(dirty);
|
||||||
} else {
|
|
||||||
Log.info("Dropping AWT dirty rect " + StringUtil.toString(dirty) +
|
|
||||||
" [clip=" + StringUtil.toString(clip) + "].");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class PathViz extends MediaPanel
|
|||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
ManagedJFrame frame = new ManagedJFrame("Path viz");
|
ManagedJFrame frame = new ManagedJFrame("Path viz");
|
||||||
FrameManager fmgr = FrameManager.newInstance(frame, frame);
|
FrameManager fmgr = FrameManager.newInstance(frame);
|
||||||
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
frame.setContentPane(new PathViz(fmgr));
|
frame.setContentPane(new PathViz(fmgr));
|
||||||
|
|||||||
@@ -26,17 +26,17 @@ import java.awt.Component;
|
|||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import com.samskivert.swing.VGroupLayout;
|
import com.samskivert.swing.VGroupLayout;
|
||||||
|
|
||||||
|
import com.threerings.media.ManagedJFrame;
|
||||||
import com.threerings.media.SafeScrollPane;
|
import com.threerings.media.SafeScrollPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main application window.
|
* The main application window.
|
||||||
*/
|
*/
|
||||||
public class ScrollingFrame extends JFrame
|
public class ScrollingFrame extends ManagedJFrame
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a frame in which the scrolling test app can operate.
|
* Creates a frame in which the scrolling test app can operate.
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class ScrollingTestApp
|
|||||||
_frame = new ScrollingFrame(gc);
|
_frame = new ScrollingFrame(gc);
|
||||||
|
|
||||||
// set up our frame manager
|
// set up our frame manager
|
||||||
_framemgr = FrameManager.newInstance(_frame, _frame);
|
_framemgr = FrameManager.newInstance(_frame);
|
||||||
|
|
||||||
// we don't need to configure anything
|
// we don't need to configure anything
|
||||||
ResourceManager rmgr = new ResourceManager("rsrc");
|
ResourceManager rmgr = new ResourceManager("rsrc");
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class ViewerApp
|
|||||||
|
|
||||||
// create the window
|
// create the window
|
||||||
_frame = new ViewerFrame(gc);
|
_frame = new ViewerFrame(gc);
|
||||||
_framemgr = FrameManager.newInstance(_frame, _frame);
|
_framemgr = FrameManager.newInstance(_frame);
|
||||||
|
|
||||||
// we don't need to configure anything
|
// we don't need to configure anything
|
||||||
ResourceManager rmgr = new ResourceManager("rsrc");
|
ResourceManager rmgr = new ResourceManager("rsrc");
|
||||||
|
|||||||
@@ -33,10 +33,12 @@ import javax.swing.JMenuBar;
|
|||||||
|
|
||||||
import com.samskivert.swing.util.MenuUtil;
|
import com.samskivert.swing.util.MenuUtil;
|
||||||
|
|
||||||
|
import com.threerings.media.ManagedJFrame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The viewer frame is the main application window.
|
* The viewer frame is the main application window.
|
||||||
*/
|
*/
|
||||||
public class ViewerFrame extends JFrame
|
public class ViewerFrame extends ManagedJFrame
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Creates a frame in which the viewer application can operate.
|
* Creates a frame in which the viewer application can operate.
|
||||||
|
|||||||
Reference in New Issue
Block a user