You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/03/05 10:40:52 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui AbstractInternalFrame.java MenuBar.java ProfileSampleFrame.java ProfilerFrame.java
leif 02/03/05 01:40:52
Modified: src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui
AbstractInternalFrame.java MenuBar.java
ProfileSampleFrame.java ProfilerFrame.java
Log:
Added the ability to save the desktop state of the ProfilerFrame.
Revision Changes Path
1.2 +96 -13 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/AbstractInternalFrame.java
Index: AbstractInternalFrame.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/AbstractInternalFrame.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractInternalFrame.java 3 Mar 2002 15:59:44 -0000 1.1
+++ AbstractInternalFrame.java 5 Mar 2002 09:40:52 -0000 1.2
@@ -16,10 +16,14 @@
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+
/**
*
* @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
- * @version CVS $Revision: 1.1 $ $Date: 2002/03/03 15:59:44 $
+ * @version CVS $Revision: 1.2 $ $Date: 2002/03/05 09:40:52 $
* @since 4.1
*/
abstract class AbstractInternalFrame
@@ -28,10 +32,52 @@
{
private ProfilerFrame m_profilerFrame;
private JInternalFrame m_nextFrame;
+ private boolean m_loaded;
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
+ AbstractInternalFrame( Configuration stateConfig,
+ boolean resizable,
+ boolean closable,
+ boolean maximizable,
+ boolean iconifiable,
+ ProfilerFrame profilerFrame )
+ {
+ m_profilerFrame = profilerFrame;
+
+ // Look for the location and size of the frame.
+ int x = stateConfig.getAttributeAsInteger( "x", getX() );
+ int y = stateConfig.getAttributeAsInteger( "y", getY() );
+ int width = stateConfig.getAttributeAsInteger( "width", getWidth() );
+ int height = stateConfig.getAttributeAsInteger( "height", getHeight() );
+ setLocation( x, y );
+ setSize( width, height );
+
+ // Look for the window state.
+ try
+ {
+ if ( stateConfig.getAttributeAsBoolean( "iconized", false ) )
+ {
+ setIcon( true );
+ }
+ else if ( stateConfig.getAttributeAsBoolean( "maximized", false ) )
+ {
+ this.setMaximum( true );
+ }
+ }
+ catch ( java.beans.PropertyVetoException e ) {}
+
+ // Set the content pane so that it is the right color
+ JPanel contentPane = new JPanel();
+ contentPane.setLayout( new BorderLayout() );
+ setContentPane( contentPane );
+
+ addInternalFrameListener( this );
+
+ m_loaded = true;
+ }
+
AbstractInternalFrame( String title,
boolean resizable,
boolean closable,
@@ -49,6 +95,8 @@
setContentPane( contentPane );
addInternalFrameListener( this );
+
+ m_loaded = true;
}
/*---------------------------------------------------------------
@@ -68,19 +116,22 @@
Math.min( maxSize.height, size.height ) ) );
size = getSize();
}
-
- // Position the frame
- int max = (int)Math.min( Math.ceil( ( maxSize.width - size.width ) / 20.0 ),
- Math.ceil( ( maxSize.height - size.height ) / 20.0 ) );
-
- JInternalFrame[] frames = desktop.getAllFrames();
- int pos;
- if (max > 0) {
- pos = ( frames.length % max ) * 20;
- } else {
- pos = 0;
+
+ if ( !m_loaded )
+ {
+ // Position the frame
+ int max = (int)Math.min( Math.ceil( ( maxSize.width - size.width ) / 20.0 ),
+ Math.ceil( ( maxSize.height - size.height ) / 20.0 ) );
+
+ JInternalFrame[] frames = desktop.getAllFrames();
+ int pos;
+ if (max > 0) {
+ pos = ( frames.length % max ) * 20;
+ } else {
+ pos = 0;
+ }
+ setLocation( pos, pos );
}
- setLocation( pos, pos );
desktop.add( this );
}
@@ -97,6 +148,38 @@
pack();
setMinimumSize( getSize() );
+ }
+
+ /**
+ * Allows subclasses to fill in configuration information. At the least, they must set
+ * a type attribute.
+ */
+ abstract protected void getState( DefaultConfiguration stateConfig );
+ //throws ConfigurationException;
+
+ final Configuration getState() //throws ConfigurationException
+ {
+ DefaultConfiguration stateConfig = new DefaultConfiguration( "inner-frame", "-" );
+
+ // Save the location and size of the frame.
+ stateConfig.setAttribute( "x", Integer.toString( getX() ) );
+ stateConfig.setAttribute( "y", Integer.toString( getY() ) );
+ stateConfig.setAttribute( "width", Integer.toString( getWidth() ) );
+ stateConfig.setAttribute( "height", Integer.toString( getHeight() ) );
+
+ // Save the window state.
+ if ( isIcon() )
+ {
+ stateConfig.setAttribute( "iconized", "true" );
+ }
+ else if ( isMaximum() )
+ {
+ stateConfig.setAttribute( "maximized", "true" );
+ }
+
+ getState( stateConfig );
+
+ return stateConfig;
}
/*---------------------------------------------------------------
1.3 +61 -7 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/MenuBar.java
Index: MenuBar.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/MenuBar.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MenuBar.java 5 Mar 2002 04:14:06 -0000 1.2
+++ MenuBar.java 5 Mar 2002 09:40:52 -0000 1.3
@@ -29,7 +29,7 @@
/**
*
* @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/03/05 04:14:06 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/03/05 09:40:52 $
* @since 4.1
*/
public class MenuBar
@@ -38,6 +38,8 @@
private ProfilerFrame m_frame;
private ProfilerManager m_profilerManager;
+ private JMenu m_menuFile;
+
private JMenu m_menuProfilables;
private JMenu m_menuOptions;
@@ -55,6 +57,7 @@
m_frame = frame;
m_profilerManager = profilerManager;
+ add( buildFileMenu() );
add( buildProfilablesMenu() );
add( buildOptionsMenu() );
add( buildWindowMenu() );
@@ -63,6 +66,62 @@
/*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
+ private JMenu buildFileMenu()
+ {
+ m_menuFile = new JMenu( "File" );
+ m_menuFile.setMnemonic( 'F' );
+
+ // Clear
+ Action newAction = new AbstractAction( "New" )
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ m_frame.fileNew();
+ }
+ };
+ JMenuItem newItem = new JMenuItem( newAction );
+ newItem.setMnemonic( 'N' );
+ m_menuFile.add( newItem );
+
+ // Open
+ Action openAction = new AbstractAction( "Open ..." )
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ m_frame.fileOpen();
+ }
+ };
+ JMenuItem open = new JMenuItem( openAction );
+ open.setMnemonic( 'O' );
+ m_menuFile.add( open );
+
+ // Save
+ Action saveAction = new AbstractAction( "Save" )
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ m_frame.fileSave();
+ }
+ };
+ JMenuItem save = new JMenuItem( saveAction );
+ save.setMnemonic( 'S' );
+ m_menuFile.add( save );
+
+ // Save As
+ Action saveAsAction = new AbstractAction( "Save As ..." )
+ {
+ public void actionPerformed( ActionEvent event )
+ {
+ m_frame.fileSaveAs();
+ }
+ };
+ JMenuItem saveAs = new JMenuItem( saveAsAction );
+ saveAs.setMnemonic( 'A' );
+ m_menuFile.add( saveAs );
+
+ return m_menuFile;
+ }
+
private JMenu buildProfilablesMenu()
{
m_menuProfilables = new JMenu( "Profilables" );
@@ -297,12 +356,7 @@
{
public void actionPerformed( ActionEvent event )
{
- JInternalFrame[] frames = m_frame.getDesktopPane().getAllFrames();
- for ( int i = 0; i < frames.length; i++ )
- {
- frames[i].setVisible( false );
- frames[i].dispose();
- }
+ m_frame.closeAllFrames();
}
};
1.3 +139 -55 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/ProfileSampleFrame.java
Index: ProfileSampleFrame.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/ProfileSampleFrame.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProfileSampleFrame.java 4 Mar 2002 08:58:11 -0000 1.2
+++ ProfileSampleFrame.java 5 Mar 2002 09:40:52 -0000 1.3
@@ -7,25 +7,36 @@
*/
package org.apache.avalon.excalibur.altprofile.profiler.gui;
+import java.awt.Dimension;
+
+import javax.swing.event.InternalFrameEvent;
+
+import org.apache.avalon.excalibur.altprofile.profiler.NoSuchProfilableException;
+import org.apache.avalon.excalibur.altprofile.profiler.NoSuchProfilePointException;
+import org.apache.avalon.excalibur.altprofile.profiler.NoSuchProfileSampleException;
+import org.apache.avalon.excalibur.altprofile.profiler.ProfilableDescriptor;
import org.apache.avalon.excalibur.altprofile.profiler.ProfilerManager;
+import org.apache.avalon.excalibur.altprofile.profiler.ProfilePointDescriptor;
import org.apache.avalon.excalibur.altprofile.profiler.ProfileSampleDescriptor;
import org.apache.avalon.excalibur.altprofile.profiler.ProfileSampleListener;
import org.apache.avalon.excalibur.altprofile.profiler.ProfileSampleSnapshot;
-import java.awt.Dimension;
-
-import javax.swing.event.InternalFrameEvent;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
/**
*
* @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/03/04 08:58:11 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/03/05 09:40:52 $
* @since 4.1
*/
class ProfileSampleFrame
extends AbstractInternalFrame
implements ProfileSampleListener, Runnable
{
+ public static final String FRAME_TYPE = "sample-frame";
+
private ProfileSampleDescriptor m_descriptor;
private ProfilerManager m_profilerManager;
private LineChart m_lineChart;
@@ -35,76 +46,75 @@
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
- ProfileSampleFrame( String title,
- ProfileSampleDescriptor descriptor,
+ ProfileSampleFrame( Configuration stateConfig,
ProfilerManager profilerManager,
ProfilerFrame profilerFrame )
+ throws ConfigurationException
{
- super( title, true, true, true, true, profilerFrame );
+ super( stateConfig, true, true, true, true, profilerFrame );
- m_descriptor = descriptor;
m_profilerManager = profilerManager;
- m_descriptor.addProfileSampleListener( this );
-
- // Decide on a line interval based on the interval of the sample.
- long interval = descriptor.getInterval();
- int hInterval;
- String format;
- String detailFormat;
- if ( interval < 1000 )
+ String sampleName = stateConfig.getAttribute( "sample" );
+ try
{
- // Once per 10 seconds.
- hInterval = (int)(10000 / interval);
- format = "{2}:{3}:{4}";
- detailFormat = "{0}/{1} {2}:{3}:{4}.{5}";
- }
- else if ( interval < 60000 )
- {
- // Once per minute.
- hInterval = (int)(60000 / interval);
- format = "{2}:{3}:{4}";
- detailFormat = "{0}/{1} {2}:{3}:{4}";
- }
- else if ( interval < 600000 )
- {
- // Once per 10 minutes
- hInterval = (int)(600000 / interval);
- format = "{0}/{1} {2}:{3}";
- detailFormat = "{0}/{1} {2}:{3}";
+ ProfilableDescriptor profilableDescriptor =
+ m_profilerManager.getProfilableDescriptor( sampleName );
+ ProfilePointDescriptor profilePointDescriptor =
+ profilableDescriptor.getProfilePointDescriptor( sampleName );
+ ProfileSampleDescriptor profileSampleDescriptor =
+ profilePointDescriptor.getProfileSampleDescriptor( sampleName );
+
+ m_descriptor = profileSampleDescriptor;
+
+ setTitle( profilableDescriptor, profilePointDescriptor, profileSampleDescriptor );
}
- else if ( interval < 3600000 )
+ catch ( NoSuchProfilableException e )
{
- // Once per hour.
- hInterval = (int)(3600000 / interval);
- format = "{0}/{1} {2}:{3}";
- detailFormat = "{0}/{1} {2}:{3}";
+ throw new ConfigurationException( e.getMessage(), e );
}
- else if ( interval < 86400000 )
+ catch ( NoSuchProfilePointException e )
{
- // Once per day.
- hInterval = (int)(86400000 / interval);
- format = "{0}/{1}";
- detailFormat = "{0}/{1} {2}:{3}";
+ throw new ConfigurationException( e.getMessage(), e );
}
- else
+ catch ( NoSuchProfileSampleException e )
{
- // Default to every 10 points.
- hInterval = 10;
- format = "{0}/{1} {2}:{3}";
- detailFormat = "{0}/{1} {2}:{3}";
+ throw new ConfigurationException( e.getMessage(), e );
}
- m_lineChart = new LineChart( hInterval, (int)descriptor.getInterval(), format, detailFormat, 20 );
+ init();
+ }
+
+ ProfileSampleFrame( ProfilableDescriptor profilableDescriptor,
+ ProfilePointDescriptor profilePointDescriptor,
+ ProfileSampleDescriptor profileSampleDescriptor,
+ ProfilerManager profilerManager,
+ ProfilerFrame profilerFrame )
+ {
+ super( "", true, true, true, true, profilerFrame );
- getContentPane().add( m_lineChart );
+ setTitle( profilableDescriptor, profilePointDescriptor, profileSampleDescriptor );
- setSize(new Dimension(600, 120));
+ m_descriptor = profileSampleDescriptor;
+ m_profilerManager = profilerManager;
- update();
+ init();
- m_runner = new Thread( this, descriptor.getName() + "_sampleFrame" );
- m_runner.start();
+ setSize(new Dimension(600, 120));
+ }
+
+ /*---------------------------------------------------------------
+ * AbstractInternalFrame Methods
+ *-------------------------------------------------------------*/
+ /**
+ * Allows subclasses to fill in configuration information. At the least, they must set
+ * a type attribute.
+ */
+ protected void getState( DefaultConfiguration stateConfig )
+ //throws ConfigurationException
+ {
+ stateConfig.setAttribute( "type", FRAME_TYPE );
+ stateConfig.setAttribute( "sample", m_descriptor.getName() );
}
/*---------------------------------------------------------------
@@ -156,6 +166,80 @@
/*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
+ private void setTitle( ProfilableDescriptor profilableDescriptor,
+ ProfilePointDescriptor profilePointDescriptor,
+ ProfileSampleDescriptor profileSampleDescriptor )
+ {
+ String title = profilableDescriptor.getDescription() + " : " +
+ profilePointDescriptor.getDescription() + " : " +
+ profileSampleDescriptor.getDescription();
+
+ setTitle( title );
+ }
+
+ private void init()
+ {
+ m_descriptor.addProfileSampleListener( this );
+
+ // Decide on a line interval based on the interval of the sample.
+ long interval = m_descriptor.getInterval();
+ int hInterval;
+ String format;
+ String detailFormat;
+ if ( interval < 1000 )
+ {
+ // Once per 10 seconds.
+ hInterval = (int)(10000 / interval);
+ format = "{2}:{3}:{4}";
+ detailFormat = "{0}/{1} {2}:{3}:{4}.{5}";
+ }
+ else if ( interval < 60000 )
+ {
+ // Once per minute.
+ hInterval = (int)(60000 / interval);
+ format = "{2}:{3}:{4}";
+ detailFormat = "{0}/{1} {2}:{3}:{4}";
+ }
+ else if ( interval < 600000 )
+ {
+ // Once per 10 minutes
+ hInterval = (int)(600000 / interval);
+ format = "{0}/{1} {2}:{3}";
+ detailFormat = "{0}/{1} {2}:{3}";
+ }
+ else if ( interval < 3600000 )
+ {
+ // Once per hour.
+ hInterval = (int)(3600000 / interval);
+ format = "{0}/{1} {2}:{3}";
+ detailFormat = "{0}/{1} {2}:{3}";
+ }
+ else if ( interval < 86400000 )
+ {
+ // Once per day.
+ hInterval = (int)(86400000 / interval);
+ format = "{0}/{1}";
+ detailFormat = "{0}/{1} {2}:{3}";
+ }
+ else
+ {
+ // Default to every 10 points.
+ hInterval = 10;
+ format = "{0}/{1} {2}:{3}";
+ detailFormat = "{0}/{1} {2}:{3}";
+ }
+
+ m_lineChart =
+ new LineChart( hInterval, m_descriptor.getInterval(), format, detailFormat, 20 );
+
+ getContentPane().add( m_lineChart );
+
+ update();
+
+ m_runner = new Thread( this, m_descriptor.getName() + "_sampleFrame" );
+ m_runner.start();
+ }
+
void update()
{
ProfileSampleSnapshot snapshot = m_descriptor.getSnapshot();
1.3 +347 -7 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/ProfilerFrame.java
Index: ProfilerFrame.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/altprofile/profiler/gui/ProfilerFrame.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProfilerFrame.java 5 Mar 2002 04:13:46 -0000 1.2
+++ ProfilerFrame.java 5 Mar 2002 09:40:52 -0000 1.3
@@ -8,32 +8,55 @@
package org.apache.avalon.excalibur.altprofile.profiler.gui;
import java.awt.BorderLayout;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import javax.swing.JDesktopPane;
+import javax.swing.JDialog;
+import javax.swing.JFileChooser;
import javax.swing.JFrame;
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
+import javax.swing.filechooser.FileFilter;
import org.apache.avalon.excalibur.altprofile.profiler.ProfilableDescriptor;
import org.apache.avalon.excalibur.altprofile.profiler.ProfilerManager;
import org.apache.avalon.excalibur.altprofile.profiler.ProfilePointDescriptor;
import org.apache.avalon.excalibur.altprofile.profiler.ProfileSampleDescriptor;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
+
+import org.xml.sax.SAXException;
+
/**
*
* @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
- * @version CVS $Revision: 1.2 $ $Date: 2002/03/05 04:13:46 $
+ * @version CVS $Revision: 1.3 $ $Date: 2002/03/05 09:40:52 $
* @since 4.1
*/
public class ProfilerFrame
extends JFrame
{
+ private String m_title;
private ProfilerManager m_profilerManager;
private JDesktopPane m_desktopPane;
private MenuBar m_menuBar;
+ private File m_desktopFile;
+ private File m_desktopFileDir;
+
/*---------------------------------------------------------------
* Constructors
*-------------------------------------------------------------*/
@@ -46,7 +69,9 @@
*/
public ProfilerFrame( ProfilerManager profilerManager, String title )
{
- super( title );
+ super();
+
+ m_title = title;
m_profilerManager = profilerManager;
@@ -56,8 +81,156 @@
/*---------------------------------------------------------------
* Methods
*-------------------------------------------------------------*/
+ /**
+ * Loads the desktop state from the specified file.
+ */
+ public void loadDesktopStateFromFile( File file, boolean showErrorDialog )
+ throws SAXException, IOException, ConfigurationException
+ {
+ FileInputStream is = new FileInputStream( file );
+ try
+ {
+ loadDesktopStateFromStream( is, showErrorDialog );
+ }
+ finally
+ {
+ is.close();
+ }
+
+ m_desktopFile = file;
+ m_desktopFileDir = file.getParentFile();
+ updateTitle();
+ }
+
+ /**
+ * Loads the desktop state from the specified input stream.
+ */
+ public void loadDesktopStateFromStream( InputStream is, boolean showErrorDialog )
+ throws SAXException, IOException, ConfigurationException
+ {
+ // Ride on top of the Configuration classes to load the state.
+ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ Configuration stateConfig = builder.build( is );
+
+ loadDesktopStateFromConfiguration( stateConfig, showErrorDialog );
+ }
+
+ /**
+ * Loads the desktop state from the specified input stream.
+ */
+ public void loadDesktopStateFromConfiguration( Configuration stateConfig,
+ boolean showErrorDialog )
+ throws ConfigurationException
+ {
+ // Start by closing any open frames.
+ closeAllFrames();
+
+ // Look for the location and size of the frame.
+ int x = stateConfig.getAttributeAsInteger( "x", getX() );
+ int y = stateConfig.getAttributeAsInteger( "y", getY() );
+ int width = stateConfig.getAttributeAsInteger( "width", getWidth() );
+ int height = stateConfig.getAttributeAsInteger( "height", getHeight() );
+ setLocation( x, y );
+ setSize( width, height );
+ validate();
+
+ // Look for inner frames in the config file.
+ Configuration[] innerFrameStateConfigs = stateConfig.getChildren( "inner-frame" );
+ for ( int i = 0; i < innerFrameStateConfigs.length; i++ )
+ {
+ Configuration innerFrameStateConfig = innerFrameStateConfigs[i];
+
+ String type = innerFrameStateConfig.getAttribute( "type" );
+
+ AbstractInternalFrame frame = null;
+ if ( type.equals( ProfileSampleFrame.FRAME_TYPE ) )
+ {
+ try
+ {
+ frame = new ProfileSampleFrame( innerFrameStateConfig, m_profilerManager, this );
+ }
+ catch ( Exception e )
+ {
+ if ( showErrorDialog )
+ {
+ showErrorDialog( "Unable to load inner frame.", e );
+ }
+ }
+ }
+
+ if ( frame != null )
+ {
+ frame.addToDesktop( m_desktopPane );
+ frame.show();
+ }
+ }
+ }
+
+ /**
+ * Loads the desktop state to the specified file.
+ */
+ public void saveDesktopStateToFile( File file )
+ throws SAXException, IOException, ConfigurationException
+ {
+ FileOutputStream os = new FileOutputStream( file );
+ try
+ {
+ saveDesktopStateToStream( os );
+ }
+ finally
+ {
+ os.close();
+ }
+
+ m_desktopFile = file;
+ m_desktopFileDir = file.getParentFile();
+ updateTitle();
+ }
+
+ /**
+ * Saves the desktop state to the specified input stream.
+ */
+ public void saveDesktopStateToStream( OutputStream os )
+ throws SAXException, IOException, ConfigurationException
+ {
+ Configuration stateConfig = saveDesktopStateToConfiguration();
+
+ // Ride on top of the Configuration classes to save the state.
+ DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
+ serializer.setIndent( true );
+ serializer.serialize( os, stateConfig );
+ }
+
+ /**
+ * Loads the desktop state from the specified input stream.
+ */
+ public Configuration saveDesktopStateToConfiguration()
+ {
+ DefaultConfiguration stateConfig = new DefaultConfiguration( "profiler-frame", "-" );
+
+ // Save the location and size of the frame.
+ stateConfig.setAttribute( "x", Integer.toString( getX() ) );
+ stateConfig.setAttribute( "y", Integer.toString( getY() ) );
+ stateConfig.setAttribute( "width", Integer.toString( getWidth() ) );
+ stateConfig.setAttribute( "height", Integer.toString( getHeight() ) );
+
+ // Save the inner frames in reverse order so they will be correct when loaded.
+ JInternalFrame[] frames = m_desktopPane.getAllFrames();
+ for ( int i = frames.length - 1; i >= 0; i-- )
+ {
+ if ( frames[i] instanceof AbstractInternalFrame )
+ {
+ stateConfig.addChild( ((AbstractInternalFrame)frames[i]).getState() );
+ }
+ }
+
+ return stateConfig;
+ }
+
private void init()
{
+ updateTitle();
+
getContentPane().setLayout(new BorderLayout());
// Create a DesktopPane and place it in a BevelBorder
@@ -76,23 +249,190 @@
setSize( 640, 480 );
}
+ private void updateTitle()
+ {
+ if ( m_desktopFile == null )
+ {
+ setTitle( m_title );
+ }
+ else
+ {
+ setTitle( m_title + " - " + m_desktopFile.getAbsolutePath() );
+ }
+ }
+
+
JDesktopPane getDesktopPane()
{
return m_desktopPane;
}
+ private void showErrorDialog( String message, Throwable t )
+ {
+ JOptionPane.showMessageDialog( this,
+ "<html><body><font color=\"black\">" + message + "</font><br><br>" +
+ "<font color=\"black\">Reason: " + t.getMessage() + "</font></body></html>",
+ m_title + " Error", JOptionPane.ERROR_MESSAGE );
+ /*
+ JOptionPane optionPane = new JOptionPane( JOptionPane.OK_OPTION );
+ optionPane.setMessage( "<html><body>" + message + "<p>Reason: " + t.getMessage() + "</body></html>" );
+ JDialog dialog = optionPane.createDialog( this, m_title + " Error" );
+ dialog.show();
+ */
+ }
+
+
+ void fileNew()
+ {
+ m_desktopFile = null;
+ closeAllFrames();
+ updateTitle();
+ }
+
+ void fileOpen()
+ {
+ JFileChooser chooser = new JFileChooser();
+
+ FileFilter filter = new FileFilter()
+ {
+ public boolean accept( File f )
+ {
+ if ( f.isDirectory() )
+ {
+ return true;
+ }
+ else
+ {
+ return f.getName().endsWith( ".desktop" );
+ }
+ }
+
+ public String getDescription()
+ {
+ return "Desktop state files";
+ }
+ };
+
+ if ( m_desktopFile != null )
+ {
+ chooser.setCurrentDirectory( m_desktopFile.getParentFile() );
+ }
+ else
+ {
+ chooser.setCurrentDirectory( new File( System.getProperty( "user.dir" ) ) );
+ }
+
+ chooser.setFileFilter( filter );
+
+ int returnVal = chooser.showOpenDialog( this );
+ if ( returnVal == JFileChooser.APPROVE_OPTION )
+ {
+ try
+ {
+ loadDesktopStateFromFile( chooser.getSelectedFile(), true );
+ }
+ catch ( Exception e )
+ {
+ showErrorDialog( "Unable to load desktop file.", e );
+ }
+ }
+ }
+
+ void fileSave()
+ {
+ if ( m_desktopFile != null )
+ {
+ try
+ {
+ saveDesktopStateToFile( m_desktopFile );
+ }
+ catch ( Exception e )
+ {
+ showErrorDialog( "Unable to save desktop file.", e );
+ }
+ }
+ else
+ {
+ fileSaveAs();
+ }
+ }
+
+ void fileSaveAs()
+ {
+ JFileChooser chooser = new JFileChooser();
+
+ FileFilter filter = new FileFilter()
+ {
+ public boolean accept( File f )
+ {
+ System.out.println( "Test '" + f.getAbsolutePath() + "'" );
+ if ( f.isDirectory() )
+ {
+ return true;
+ }
+ else
+ {
+ return f.getName().endsWith( ".desktop" );
+ }
+ }
+
+ public String getDescription()
+ {
+ return "Desktop state files";
+ }
+ };
+
+ if ( m_desktopFile != null )
+ {
+ chooser.setCurrentDirectory( m_desktopFile.getParentFile() );
+ }
+ else
+ {
+ chooser.setCurrentDirectory( new File( System.getProperty( "user.dir" ) ) );
+ }
+
+ chooser.setFileFilter( filter );
+
+ int returnVal = chooser.showSaveDialog( this );
+ if ( returnVal == JFileChooser.APPROVE_OPTION )
+ {
+ File file = chooser.getSelectedFile();
+ if ( file.getName().indexOf( '.' ) < 0 )
+ {
+ // Did not specify an extension. Add one.
+ file = new File( file.getAbsolutePath() + ".desktop" );
+ }
+
+ try
+ {
+ saveDesktopStateToFile( file );
+ }
+ catch ( Exception e )
+ {
+ showErrorDialog( "Unable to save desktop file.", e );
+ }
+ }
+ }
+
+ void closeAllFrames()
+ {
+ JInternalFrame[] frames = m_desktopPane.getAllFrames();
+ for ( int i = 0; i < frames.length; i++ )
+ {
+ frames[i].setVisible( false );
+ frames[i].dispose();
+ }
+ }
+
void openProfileSampleFrame( final ProfilableDescriptor profilableDescriptor,
final ProfilePointDescriptor profilePointDescriptor,
final ProfileSampleDescriptor profileSampleDescriptor )
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- String title = profilableDescriptor.getDescription() + " : " +
- profilePointDescriptor.getDescription() + " : " +
- profileSampleDescriptor.getDescription();
-
- ProfileSampleFrame frame = new ProfileSampleFrame( title, profileSampleDescriptor,
- m_profilerManager, ProfilerFrame.this );
+ ProfileSampleFrame frame = new ProfileSampleFrame( profilableDescriptor,
+ profilePointDescriptor,profileSampleDescriptor, m_profilerManager,
+ ProfilerFrame.this );
frame.addToDesktop( m_desktopPane );
frame.show();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>