Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2567 - development/main/depot/station/src/main/net/dpml/depot/prefs

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2567 - development/main/depot/station/src/main/net/dpml/depot/prefs
  • Date: Sun, 15 May 2005 23:22:59 +0000

Author: mcconnell AT dpml.net
Date: Sun May 15 23:22:56 2005
New Revision: 2567

Added:

development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesFrame.java

development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesPanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/PluginSetupPanel.java
Removed:

development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerPanel.java
Modified:

development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesDialog.java
development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java

development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java

development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
Log:
Update the Depot implementation so that we create a Frame by default when
running as a command-line based application - but also provide a dialog based
variant to allow easy integration into an IDE.

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerMainPanel.java
Sun May 15 23:22:56 2005
@@ -21,11 +21,15 @@
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
+import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
+import java.awt.Window;
+import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.net.ContentHandler;
import java.util.prefs.Preferences;

import javax.swing.AbstractAction;
@@ -45,6 +49,7 @@

import net.dpml.transit.Transit;
import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.content.ContentHandlerRegistry;

/**
* Runnable plugin that handles DPML environment setup.
@@ -63,7 +68,7 @@
// state
//--------------------------------------------------------------

- private final JDialog m_parent;
+ private final Window m_parent;

private GenericTable m_table;

@@ -79,7 +84,7 @@
// constructor
//--------------------------------------------------------------

- public ContentHandlerMainPanel( JDialog parent ) throws Exception
+ public ContentHandlerMainPanel( Window parent ) throws Exception
{
m_parent = parent;

@@ -160,7 +165,7 @@
// utilities
//--------------------------------------------------------------

- private JPanel createContentHandlerControllerPanel( JDialog parent )
+ private JPanel createContentHandlerControllerPanel( Window parent )
{
JLabel label =
IconHelper.createImageIconJLabel(
@@ -182,7 +187,7 @@
panel.setBorder(
new CompoundBorder(
new TitledBorder( null, "Controller", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
- JButton button = new JButton( new ControllerAction( parent,
"Controller" ) );
+ JButton button = new JButton( new ControllerAction( "Controller" ) );
JPanel buttons = new JPanel();
buttons.setBackground( Color.white );
buttons.setLayout( new BorderLayout() );
@@ -192,21 +197,28 @@
return holder;
}

- private static class ControllerAction extends AbstractAction
+ private class ControllerAction extends AbstractAction
{
- JDialog m_parent;
-
- ControllerAction( JDialog parent, String name )
+ /**
+ */
+ ControllerAction( String name )
{
super( name );
- m_parent = parent;
}

public void actionPerformed( ActionEvent event )
{
try
{
- JDialog dialog = new JDialog( m_parent, true );
+ JDialog dialog = null;
+ if( m_parent instanceof Dialog )
+ {
+ dialog = new JDialog( (Dialog) m_parent, true );
+ }
+ else
+ {
+ dialog = new JDialog( (Frame) m_parent, true );
+ }
dialog.setTitle( "Content Handler Controller" );
Dimension size = new Dimension( 400, 240 );

@@ -215,7 +227,7 @@
frame.setBackground( Color.white );
frame.setBorder( new EmptyBorder( 10, 6, 0, 6 ) );

- JPanel panel = new ContentHandlerControllerPanel( dialog );
+ JPanel panel = new PluginSetupPanel( dialog, m_preferences,
ContentHandlerRegistry.class );
frame.add( panel, BorderLayout.CENTER );
dialog.setContentPane( frame );
dialog.setSize( size );
@@ -234,7 +246,7 @@
}
}

- private static class CloseAction extends AbstractAction
+ private class CloseAction extends AbstractAction
{
private JDialog m_dialog;

@@ -302,10 +314,18 @@
return;
}

-
try
{
- JDialog dialog = new JDialog( m_parent, true );
+ JDialog dialog = null;
+ if( m_parent instanceof Dialog )
+ {
+ dialog = new JDialog( (Dialog) m_parent, true );
+ }
+ else
+ {
+ dialog = new JDialog( (Frame) m_parent, true );
+ }
+
dialog.setTitle( "Content Handler" );
Dimension size = new Dimension( 400, 240 );

@@ -315,26 +335,13 @@
frame.setBorder( new EmptyBorder( 10, 6, 0, 6 ) );

Preferences node = m_preferences.node( name );
- JPanel panel = new ContentHandlerPanel( dialog, node );
+ JPanel panel = new PluginSetupPanel( dialog, node,
ContentHandler.class );
frame.add( panel, BorderLayout.CENTER );
dialog.setContentPane( frame );
dialog.setSize( size );
dialog.setLocationRelativeTo( (Component) event.getSource()
);
dialog.setResizable( true );
dialog.setVisible(true);
-
- /*
- JDialog dialog = new JDialog( m_parent, true );
- Preferences node = m_preferences.node( name );
- dialog.setTitle( "Content Handler: " + name );
- JPanel panel = new ContentHandlerPanel( dialog, node );
- dialog.setContentPane( panel );
- Dimension size = new Dimension( 400, 360 );
- dialog.setSize( size );
- dialog.setLocationRelativeTo( (Component) event.getSource()
);
- dialog.setResizable( true );
- dialog.setVisible( true );
- */
}
catch( Throwable e )
{
@@ -365,7 +372,16 @@
{
try
{
- JDialog dialog = new JDialog( m_parent, true );
+ JDialog dialog = null;
+ if( m_parent instanceof Dialog )
+ {
+ dialog = new JDialog( (Dialog) m_parent, true );
+ }
+ else
+ {
+ dialog = new JDialog( (Frame) m_parent, true );
+ }
+
dialog.setTitle( "Content Handler" );
Dimension size = new Dimension( 400, 240 );

@@ -375,7 +391,7 @@
frame.setBorder( new EmptyBorder( 10, 6, 0, 6 ) );

Preferences node = m_preferences.node( m_selection );
- JPanel panel = new ContentHandlerPanel( dialog, node );
+ JPanel panel = new PluginSetupPanel( dialog, node,
ContentHandler.class );
frame.add( panel, BorderLayout.CENTER );
dialog.setContentPane( frame );
dialog.setSize( size );

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesDialog.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesDialog.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesDialog.java
Sun May 15 23:22:56 2005
@@ -87,48 +87,9 @@
setTitle( "DPML Depot" );
Dimension size = new Dimension( DEFAULT_DIALOG_WIDTH,
DEFAULT_DIALOG_HEIGHT );
setSize( size );
-
- JLabel label =
- IconHelper.createImageIconJLabel(
- Transit.class.getClassLoader(), DPML_ICON_FILENAME, "", "DPML
Depot" );
- label.setBorder( new EmptyBorder( 5, 0, 0, 0 ) );
-
- JTabbedPane tabbedPane = new JTabbedPane();
- tabbedPane.setBorder( new EmptyBorder( 0, OFFSET, OFFSET, OFFSET ) );
-
- //
- // add the individual application control panels as tabbed panes
- //
-
- JPanel panel = new JPanel();
-
- TransitPanel transitPanel = new TransitPanel( this );
- ContentHandlerMainPanel contentPanel = new ContentHandlerMainPanel(
this );
- tabbedPane.addTab( "Transit", transitPanel );
- tabbedPane.addTab( "Content", contentPanel );
- tabbedPane.addTab( "Logging", new JPanel() );
- tabbedPane.addTab( "Profiles", new JPanel() );
-
- //
- // add the Close button
- //
-
- ButtonPanel buttons = new ButtonPanel();
- buttons.setBorder( new EmptyBorder( 0, 7, 7, 7 ) );
-
- //
- // package
- //
-
- JPanel holder = new JPanel( new BorderLayout() );
- holder.add( label, BorderLayout.NORTH );
- holder.add( tabbedPane, BorderLayout.CENTER );
- holder.add( buttons, BorderLayout.SOUTH );
-
- setContentPane( holder );
- setSize( size );
- getRootPane().setDefaultButton( buttons.getDefaultButton() );
-
+ DepotPreferencesPanel panel = new DepotPreferencesPanel( this );
+ setContentPane( panel );
+ getRootPane().setDefaultButton( panel.getDefaultButton() );
addWindowListener(
new WindowAdapter()
{
@@ -138,51 +99,10 @@
}
}
);
-
setLocation( 300, 200 );
setVisible(true);
}

-
- private static class ButtonPanel extends Box
- {
- private JButton m_close;
-
- ButtonPanel()
- {
- super( BoxLayout.Y_AXIS );
-
- m_close = new JButton( );
- Action closeAction = new CancelAction( "Close" );
- m_close.setAction( closeAction );
- JPanel buttonPanel = new JPanel( new FlowLayout(
FlowLayout.RIGHT ) );
- buttonPanel.add( m_close );
- add( buttonPanel );
- }
-
- JButton getDefaultButton()
- {
- return m_close;
- }
- }
-
- private static class CancelAction extends AbstractAction
- {
- public CancelAction( String label )
- {
- super( label );
- }
-
- /**
- * Called when the cancel button is trigged.
- * @param event the action event
- */
- public void actionPerformed( ActionEvent event )
- {
- System.exit(0);
- }
- }
-
public static void main( String[] args ) throws Exception
{
SwingUtilities.invokeLater(

Added:
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesFrame.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesFrame.java
Sun May 15 23:22:56 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.depot.prefs;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.border.EmptyBorder;
+
+import net.dpml.transit.Transit;
+
+/**
+ * Dialog that presents the default preferences for DPML applications
including
+ * Transit cache and repository settings, transit content handler plugins,
logging
+ * preferences and application profiles runnable via the depot command line
script.
+ */
+public class DepotPreferencesFrame extends JFrame
+{
+ /**
+ * The DPML icon.
+ */
+ private static String DPML_ICON_FILENAME =
"net/dpml/depot/prefs/images/dpml.gif";
+
+ /**
+ * The default dialog width.
+ */
+ private static final int DEFAULT_DIALOG_WIDTH = 400;
+
+ /**
+ * The default dialog height.
+ */
+ private static final int DEFAULT_DIALOG_HEIGHT = 550;
+
+ /**
+ * Empty boarder offset.
+ */
+ private static final int OFFSET = 10;
+
+ /**
+ * Empty boarder offset.
+ */
+ private static final int LEAD = 20;
+
+ /**
+ * Null offset
+ */
+ private static final int ZERO = 0;
+
+ public DepotPreferencesFrame() throws Exception
+ {
+ super();
+
+ String classname = UIManager.getSystemLookAndFeelClassName();
+ UIManager.setLookAndFeel( classname );
+
+ setTitle( "DPML Depot" );
+ Dimension size = new Dimension( DEFAULT_DIALOG_WIDTH,
DEFAULT_DIALOG_HEIGHT );
+ setSize( size );
+ DepotPreferencesPanel panel = new DepotPreferencesPanel( this );
+ setContentPane( panel );
+ getRootPane().setDefaultButton( panel.getDefaultButton() );
+ addWindowListener(
+ new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ }
+ );
+ setLocation( 300, 200 );
+ setVisible(true);
+ }
+
+ public static void main( String[] args ) throws Exception
+ {
+ SwingUtilities.invokeLater(
+ new Runnable() {
+ public void run()
+ {
+ setup();
+ }
+ } );
+ }
+
+ private static void setup()
+ {
+ try
+ {
+ new DepotPreferencesFrame();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesPanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/DepotPreferencesPanel.java
Sun May 15 23:22:56 2005
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.depot.prefs;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.border.EmptyBorder;
+
+import net.dpml.transit.Transit;
+
+/**
+ * Panel that presents the default preferences for DPML applications
including
+ * Transit cache and repository settings, transit content handler plugins,
logging
+ * preferences and application profiles runnable via the depot command line
script.
+ */
+public class DepotPreferencesPanel extends JPanel
+{
+ /**
+ * The DPML icon.
+ */
+ private static String DPML_ICON_FILENAME =
"net/dpml/depot/prefs/images/dpml.gif";
+
+ /**
+ * Empty boarder offset.
+ */
+ private static final int OFFSET = 10;
+
+ /**
+ * Empty boarder offset.
+ */
+ private static final int LEAD = 20;
+
+ /**
+ * Null offset
+ */
+ private static final int ZERO = 0;
+
+ private ButtonPanel m_buttons;
+
+
+ public DepotPreferencesPanel( Window window ) throws Exception
+ {
+ super( new BorderLayout() );
+
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ Transit.class.getClassLoader(), DPML_ICON_FILENAME, "", "DPML
Depot" );
+ label.setBorder( new EmptyBorder( 5, 0, 0, 0 ) );
+
+ JTabbedPane tabbedPane = new JTabbedPane();
+ tabbedPane.setBorder( new EmptyBorder( 0, OFFSET, OFFSET, OFFSET ) );
+
+ //
+ // add the individual application control panels as tabbed panes
+ //
+
+ JPanel panel = new JPanel();
+
+ TransitPanel transitPanel = new TransitPanel( window );
+ ContentHandlerMainPanel contentPanel = new ContentHandlerMainPanel(
window );
+ tabbedPane.addTab( "Transit", transitPanel );
+ tabbedPane.addTab( "Content", contentPanel );
+ tabbedPane.addTab( "Logging", new JPanel() );
+ tabbedPane.addTab( "Profiles", new JPanel() );
+
+ //
+ // add the Close button
+ //
+
+ m_buttons = new ButtonPanel();
+ m_buttons.setBorder( new EmptyBorder( 0, 7, 7, 7 ) );
+
+ //
+ // package
+ //
+
+ add( label, BorderLayout.NORTH );
+ add( tabbedPane, BorderLayout.CENTER );
+ add( m_buttons, BorderLayout.SOUTH );
+ }
+
+ public JButton getDefaultButton()
+ {
+ return m_buttons.getDefaultButton();
+ }
+
+ private static class ButtonPanel extends Box
+ {
+ private JButton m_close;
+
+ ButtonPanel()
+ {
+ super( BoxLayout.Y_AXIS );
+
+ m_close = new JButton( );
+ Action closeAction = new CancelAction( "Close" );
+ m_close.setAction( closeAction );
+ JPanel buttonPanel = new JPanel( new FlowLayout(
FlowLayout.RIGHT ) );
+ buttonPanel.add( m_close );
+ add( buttonPanel );
+ }
+
+ JButton getDefaultButton()
+ {
+ return m_close;
+ }
+ }
+
+ private static class CancelAction extends AbstractAction
+ {
+ public CancelAction( String label )
+ {
+ super( label );
+ }
+
+ /**
+ * Called when the cancel button is trigged.
+ * @param event the action event
+ */
+ public void actionPerformed( ActionEvent event )
+ {
+ System.exit(0);
+ }
+ }
+
+ public static void main( String[] args ) throws Exception
+ {
+ SwingUtilities.invokeLater(
+ new Runnable() {
+ public void run()
+ {
+ setup();
+ }
+ } );
+ }
+
+ private static void setup()
+ {
+ try
+ {
+ new DepotPreferencesDialog();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+}

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java
==============================================================================
--- development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java
(original)
+++ development/main/depot/station/src/main/net/dpml/depot/prefs/Main.java
Sun May 15 23:22:56 2005
@@ -97,7 +97,7 @@
{
try
{
- new DepotPreferencesDialog();
+ new DepotPreferencesFrame();
}
catch( Exception e )
{

Added:
development/main/depot/station/src/main/net/dpml/depot/prefs/PluginSetupPanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/PluginSetupPanel.java
Sun May 15 23:22:56 2005
@@ -0,0 +1,546 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.depot.prefs;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.ContentHandler;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.Preferences;
+
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.repository.Plugin;
+import net.dpml.transit.repository.Repository;
+
+/**
+ * Control panel for editing the cache preferences.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+class PluginSetupPanel extends JPanel implements PreferenceChangeListener,
PropertyChangeListener, DocumentListener
+{
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+ private JTextField m_base;
+ private JButton m_ok;
+ private JButton m_revert;
+ private SettingsAction m_settings;
+ private Preferences m_preferences;
+ private PropertyChangeSupport m_propertyChangeSupport;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ /**
+ * Creation of a standard plugin setup panel containing
+ * an user modifiable plugin artifact uri and a controller
+ * parameters button. If a class named [classname]ControlPanel
+ * exists (where [classname] is the plugin classname), the control
+ * panel class will be used to construct a dialog for the selected
+ * plugin. If a class named [classname]Installer exists, the
+ * installer will be instantiated as part of plugin dialog
+ * establishment.
+ *
+ * @param parent the parent dialog
+ * @param prefs the user preferences for the node
net/dpml/transit/content/[type]
+ * @param service the class that a plugin controller must implement
+ */
+ public PluginSetupPanel( JDialog parent, Preferences prefs, Class
service ) throws Exception
+ {
+ m_parent = parent;
+ m_propertyChangeSupport = new PropertyChangeSupport( this );
+ m_preferences = prefs;
+
+ m_ok = new JButton( new OKAction( "Install", service ) );
+ m_revert = new JButton( new RevertAction( "Undo" ) );
+ m_preferences.addPreferenceChangeListener( this );
+
+ setLayout( new BorderLayout() );
+ setBackground( Color.white );
+
+ // create a label containing an icon and label
+
+ {
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ getClass().getClassLoader(), SOURCE_IMG_PATH, "URI", "Plugin
URI" );
+ label.setBorder( new EmptyBorder( 0, 5, 0, 0 ) );
+ JPanel panel = new JPanel();
+ panel.setLayout( new BorderLayout() );
+ panel.setBackground( Color.white );
+ panel.add( label, BorderLayout.WEST );
+ add( panel, BorderLayout.NORTH );
+ }
+
+ // add a test field containing the plugin artifact uri and a
+ // button for optional plugin configuration
+
+ {
+ JPanel holder = new JPanel();
+ holder.setBackground( Color.white );
+ holder.setLayout( new BorderLayout() );
+
+ JPanel panel = new JPanel();
+ panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) );
+ panel.setBackground( Color.white );
+ panel.setBorder( new EmptyBorder( 10, 10, 10, 10 ) );
+ {
+ // add the text field
+
+ JPanel padding = new JPanel();
+ padding.setBackground( Color.white );
+ padding.setLayout( new BorderLayout() );
+ padding.setBorder( new EmptyBorder( 10, 2, 5, 2) );
+ String artifact = getControllerFieldTextFromPreferences();
+ m_base = new JTextField( artifact );
+ m_base.getDocument().addDocumentListener( this ); // listen
for changes
+ m_base.setBackground( Color.white );
+ padding.add( m_base );
+ panel.add( padding );
+ }
+ {
+ // add the optional controller settings button
+
+ JPanel settingsPanel = new JPanel();
+ settingsPanel.setBorder(
+ new CompoundBorder(
+ new TitledBorder(
+ null, "Controller Settings", TitledBorder.LEFT,
TitledBorder.TOP),
+ new EmptyBorder( 5, 5, 5, 10)
+ )
+ );
+ settingsPanel.setBackground( Color.white );
+ settingsPanel.setLayout( new BorderLayout() );
+ m_settings = new SettingsAction( "Controller Settings",
m_parent );
+ JButton settings = new JButton( m_settings );
+ settingsPanel.add( settings, BorderLayout.EAST );
+ panel.add( settingsPanel );
+ }
+ holder.add( panel, BorderLayout.NORTH );
+ add( holder, BorderLayout.CENTER );
+ }
+
+ // add revert, ok, and cancel
+
+ {
+ JPanel panel = new JPanel();
+ panel.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ panel.add( m_revert );
+ panel.add( m_ok );
+ panel.add( new JButton( new CloseAction( "Close" ) ) );
+ panel.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ panel.setBackground( Color.white );
+ add( panel, BorderLayout.SOUTH );
+ }
+
+ m_propertyChangeSupport.addPropertyChangeListener( this );
+ }
+
+ //--------------------------------------------------------------
+ // DocumentListener
+ //--------------------------------------------------------------
+
+ public void insertUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ public void removeUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ public void changedUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ private void fireBaseChangedEvent()
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ m_base, "base", null, m_base.getText() );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+
+ //--------------------------------------------------------------
+ // PropertyChangeListener
+ //--------------------------------------------------------------
+
+ /**
+ * The actions dealing with changes to the dialog raise change events
that
+ * are captured here. This listener checks changes and enables or
disabled
+ * the ok and undo buttons based on the state of controls relative to the
+ * underlying preferences for the cache.
+ */
+ public void propertyChange( PropertyChangeEvent event )
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ boolean flag = ( false == artifact.equals( m_base.getText() ) );
+ m_ok.setEnabled( flag );
+ m_revert.setEnabled( flag );
+ if( !flag )
+ {
+ m_settings.setup();
+ }
+ else
+ {
+ m_settings.setEnabled( false );
+ }
+ }
+
+ private String getControllerFieldTextFromPreferences()
+ {
+ return m_preferences.get( "uri", "artifact:plugin:" );
+ }
+
+ private String getControllerPathFromPreferences()
+ {
+ return m_preferences.get( "uri", null );
+ }
+
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ if( false == m_base.getText().equals( artifact ) )
+ {
+ m_base.setText( artifact );
+ }
+ }
+
+ private class CloseAction extends AbstractAction
+ {
+ CloseAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_parent.hide();
+ }
+ }
+
+ private class SettingsAction extends AbstractAction
+ {
+ private Dialog m_parent;
+ private Dialog m_dialog;
+
+ SettingsAction( String name, Dialog parent )
+ {
+ super( name );
+ m_parent = parent;
+ setup();
+ }
+
+ public void setup()
+ {
+ String controllerPath = getControllerPathFromPreferences();
+ if( null == controllerPath )
+ {
+ setEnabled( false );
+ }
+ else
+ {
+ try
+ {
+ URI uri = new URI( controllerPath );
+ String classname = getControllerClassname( uri );
+ String controlClassname = classname +
CONTROL_PANEL_SUFFIX;
+ ClassLoader classloader = getControllerClassLoader( uri
);
+ m_dialog = createControlPanel( classloader,
controlClassname, m_parent );
+ m_dialog.setModal( true );
+ setEnabled( true );
+ }
+ catch( ClassNotFoundException e )
+ {
+ setEnabled( false );
+ }
+ catch( Throwable e )
+ {
+ System.err.println( e.toString() );
+ e.printStackTrace();
+ setEnabled( false );
+ }
+ }
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ if( m_dialog != null )
+ {
+ m_dialog.setLocationRelativeTo( (Component)
event.getSource() );
+ m_dialog.setVisible( true );
+ }
+ }
+
+ private String getControllerClassname( URI uri ) throws Exception
+ {
+ URL url = new URL( uri.toString() );
+ Plugin plugin = (Plugin) url.getContent( new Class[]{
Plugin.class } );
+ return plugin.getClassname();
+ }
+
+ private ClassLoader getControllerClassLoader( URI uri ) throws
Exception
+ {
+ URL url = new URL( uri.toString() );
+ return (ClassLoader) url.getContent( new Class[]{
ClassLoader.class } );
+ }
+
+ private Dialog createControlPanel( ClassLoader classloader, String
classname, Dialog parent )
+ throws ClassNotFoundException, TransitException
+ {
+ try
+ {
+ Repository repository =
Transit.getInstance().getRepository();
+ Class cls = classloader.loadClass( classname );
+ Object[] args = new Object[]{ parent };
+ return (Dialog) repository.instantiate( cls, args );
+ }
+ catch( ClassNotFoundException e )
+ {
+ throw e;
+ }
+ catch( Throwable e )
+ {
+ String error =
+ "Unable to establish a control panel using the class ["
+ + classname
+ + "].";
+ throw new TransitException( error, e );
+ }
+ }
+ }
+
+ private class RevertAction extends AbstractAction
+ {
+ RevertAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ String artifact = getControllerFieldTextFromPreferences();
+ String old = m_base.getText();
+ m_base.setText( artifact );
+ PropertyChangeEvent e =
+ new PropertyChangeEvent( this, "uri", old, artifact );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+
+ private class OKAction extends AbstractAction
+ {
+ private Class m_service;
+
+ OKAction( String name, Class service )
+ {
+ super( name );
+ setEnabled( false );
+ m_service = service;
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ String text = m_base.getText();
+ String artifact = getControllerFieldTextFromPreferences();
+ if( false == text.equals( artifact ) )
+ {
+ if( "".equals( text ) )
+ {
+ m_preferences.remove( "uri" );
+ }
+ else
+ {
+ boolean validated = validateControllerSpec( m_parent,
text, m_service );
+ if( validated )
+ {
+ m_preferences.put( "uri", text );
+ }
+ }
+ }
+ m_ok.setEnabled( false );
+ m_revert.setEnabled( false );
+ m_settings.setup();
+ }
+ }
+
+ private boolean validateControllerSpec( Component component, String
spec, Class service )
+ {
+ URI uri = createControllerURI( component, spec );
+ if( null == uri )
+ {
+ return false;
+ }
+ URL url = getURLFromURI( component, uri );
+ if( null == url )
+ {
+ return false;
+ }
+ Plugin plugin = getPluginFromURL( component, url );
+ if( null == plugin )
+ {
+ return false;
+ }
+ String classname = plugin.getClassname();
+ return checkPluginClass( component, url, service );
+ }
+
+ private URI createControllerURI( Component component, String spec )
+ {
+ try
+ {
+ return new URI( spec );
+ }
+ catch( URISyntaxException e )
+ {
+ final String title = "Controller URI Error";
+ final String message = "Invalid uri.";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ }
+
+ private URL getURLFromURI( Component component, URI uri )
+ {
+ try
+ {
+ String spec = uri.toString();
+ return new URL( spec );
+ }
+ catch( IOException e )
+ {
+ final String title = "Controller URI Error";
+ final String message = "Cannot convert the uri to a url.";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ }
+
+ private Plugin getPluginFromURL( Component component, URL url )
+ {
+ try
+ {
+ return (Plugin) url.getContent( new Class[]{ Plugin.class } );
+ }
+ catch( Throwable e )
+ {
+ final String title = "Controller URI Error";
+ final String message = e.getMessage();
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return null;
+ }
+ }
+
+ private boolean checkPluginClass( Component component, URL url, Class
service )
+ {
+ Class c = null;
+ try
+ {
+ c = (Class) url.getContent( new Class[]{ Class.class } );
+ }
+ catch( Throwable e )
+ {
+ final String title = "Controller URI Error";
+ final String message = e.getMessage();
+ e.printStackTrace();
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return false;
+ }
+ if( false == service.isAssignableFrom( c ) )
+ {
+ final String title = "Controller URI Error";
+ final String message = "Plugin class does not implement " +
service.getName() + ".";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ System.out.println( c.getClassLoader().toString() );
+ return false;
+ }
+ else
+ {
+ //
+ // check for an installer class
+ //
+
+ String installer = c.getName() + "Installer";
+ try
+ {
+ Class install = c.getClassLoader().loadClass( installer );
+ install.newInstance();
+ return true;
+ }
+ catch( ClassNotFoundException e )
+ {
+ return true;
+ }
+ catch( Throwable e )
+ {
+ final String title = "Controller URI Error";
+ final String message = "Plugin class install error in " +
installer + ".";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return false;
+ }
+ }
+ }
+
+ //--------------------------------------------------------------
+ // static utils
+ //--------------------------------------------------------------
+
+ private static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ private static String SOURCE_IMG_PATH =
"net/dpml/depot/prefs/images/source.png";
+
+ private static final String CONTROL_PANEL_SUFFIX = "ControlPanel";
+}
+

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitPanel.java
Sun May 15 23:22:56 2005
@@ -23,6 +23,9 @@
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
+import java.awt.Window;
+import java.awt.Dialog;
+import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -63,7 +66,7 @@
// state
//--------------------------------------------------------------

- private final JDialog m_parent;
+ private final Window m_parent;

private GenericTable m_table;
private EditAction m_editAction;
@@ -76,7 +79,7 @@
// constructor
//--------------------------------------------------------------

- public TransitPanel( JDialog parent ) throws Exception
+ public TransitPanel( Window parent ) throws Exception
{
Transit.getInstance();

@@ -118,7 +121,7 @@
buttonHolder.setBackground( Color.white );
hostPanel.add( buttonHolder, BorderLayout.SOUTH );

- JPanel cachePanel = createCachePanel( parent );
+ JPanel cachePanel = createCachePanel();

add( cachePanel, BorderLayout.NORTH );
add( hostPanel, BorderLayout.CENTER );
@@ -150,7 +153,7 @@
}
}

- private JPanel createCachePanel( JDialog parent )
+ private JPanel createCachePanel()
{
JLabel label =
IconHelper.createImageIconJLabel(
@@ -171,7 +174,7 @@
cache.setBorder(
new CompoundBorder(
new TitledBorder( null, "Cache", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
- JButton button = new JButton( new CacheAction( parent, "Cache" ) );
+ JButton button = new JButton( new CacheAction( "Cache" ) );
JPanel cacheButtonHolder = new JPanel();
cacheButtonHolder.setBackground( Color.white );
cacheButtonHolder.setLayout( new BorderLayout() );
@@ -181,21 +184,27 @@
return holder;
}

- private static class CacheAction extends AbstractAction
+ private class CacheAction extends AbstractAction
{
- JDialog m_parent;
-
- CacheAction( JDialog parent, String name )
+ CacheAction( String name )
{
super( name );
- m_parent = parent;
}

public void actionPerformed( ActionEvent event )
{
try
{
- JDialog dialog = new JDialog( m_parent, true );
+ JDialog dialog = null;
+ if( m_parent instanceof Dialog )
+ {
+ dialog = new JDialog( (Dialog) m_parent, true );
+ }
+ else
+ {
+ dialog = new JDialog( (Frame) m_parent, true );
+ }
+
dialog.setTitle( "Resource Cache" );
Dimension size = new Dimension( 400, 160 );

@@ -222,22 +231,6 @@
System.err.println( message );
}
}
-
- private static class CloseAction extends AbstractAction
- {
- private JDialog m_dialog;
-
- CloseAction( String name, JDialog dialog )
- {
- super( name );
- m_dialog = dialog;
- }
-
- public void actionPerformed( ActionEvent event )
- {
- m_dialog.hide();
- }
- }
}

//--------------------------------------------------------------
@@ -310,7 +303,15 @@
}
try
{
- JDialog dialog = new JDialog( m_parent, true );
+ JDialog dialog = null;
+ if( m_parent instanceof Dialog )
+ {
+ dialog = new JDialog( (Dialog) m_parent, true );
+ }
+ else
+ {
+ dialog = new JDialog( (Frame) m_parent, true );
+ }
dialog.setTitle( "Resource Host: " + name );
JPanel panel = new TransitResourceHostPanel( dialog, name );
dialog.setContentPane( panel );
@@ -349,7 +350,15 @@
{
try
{
- JDialog dialog = new JDialog( m_parent, true );
+ JDialog dialog = null;
+ if( m_parent instanceof Dialog )
+ {
+ dialog = new JDialog( (Dialog) m_parent, true );
+ }
+ else
+ {
+ dialog = new JDialog( (Frame) m_parent, true );
+ }
dialog.setTitle( "Resource Host: " + m_selection );
JPanel panel = new TransitResourceHostPanel( dialog,
m_selection );
dialog.setContentPane( panel );

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/TransitResourceHostPanel.java
Sun May 15 23:22:56 2005
@@ -410,6 +410,7 @@

public void actionPerformed( ActionEvent event )
{
+long now = System.currentTimeMillis();
m_parent.hide();
m_propertyChangeSupport.removePropertyChangeListener( m_listener
);
{
@@ -442,6 +443,8 @@
{
e.printStackTrace();
}
+long diff = System.currentTimeMillis() - now;
+System.out.println( "# OK: " + diff );
}
}




  • svn commit: r2567 - development/main/depot/station/src/main/net/dpml/depot/prefs, mcconnell, 05/15/2005

Archive powered by MHonArc 2.6.24.

Top of Page