Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2508 - in development/main/depot: . cli content content/src/main/net/dpml/depot/content station station/src/main/net/dpml/depot/prefs station/src/main/net/dpml/depot/station station/src/main/net/dpml/depot/station/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: r2508 - in development/main/depot: . cli content content/src/main/net/dpml/depot/content station station/src/main/net/dpml/depot/prefs station/src/main/net/dpml/depot/station station/src/main/net/dpml/depot/station/prefs
  • Date: Wed, 11 May 2005 09:31:44 +0000

Author: mcconnell AT dpml.net
Date: Wed May 11 09:31:43 2005
New Revision: 2508

Added:
development/main/depot/cli/
development/main/depot/cli/README.TXT
development/main/depot/station/src/main/net/dpml/depot/prefs/
- copied from r2504,
development/main/depot/station/src/main/net/dpml/depot/station/prefs/

development/main/depot/station/src/main/net/dpml/depot/station/CachePanel.java

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

development/main/depot/station/src/main/net/dpml/depot/station/ContentHandlerPanel.java

development/main/depot/station/src/main/net/dpml/depot/station/DefaultCellRenderer.java

development/main/depot/station/src/main/net/dpml/depot/station/GenericTable.java

development/main/depot/station/src/main/net/dpml/depot/station/HostPanel.java

development/main/depot/station/src/main/net/dpml/depot/station/IconHelper.java
development/main/depot/station/src/main/net/dpml/depot/station/Main.java

development/main/depot/station/src/main/net/dpml/depot/station/NodeTableModel.java

development/main/depot/station/src/main/net/dpml/depot/station/ResourcePanel.java

development/main/depot/station/src/main/net/dpml/depot/station/TransitDialog.java
development/main/depot/station/src/main/net/dpml/depot/station/package.html
Removed:
development/main/depot/station/src/main/net/dpml/depot/station/prefs/
Modified:
development/main/depot/content/ (props changed)

development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerDescriptor.java

development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistry.java

development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistryControlPanel.java
development/main/depot/index.xml
development/main/depot/station/build.xml

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

development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerPanel.java
Log:
reshuffle content so that the swing stuff is managed as a depot subproject
and the content handler controller plugin is renamed from station to content.

Added: development/main/depot/cli/README.TXT
==============================================================================
--- (empty file)
+++ development/main/depot/cli/README.TXT Wed May 11 09:31:43 2005
@@ -0,0 +1,2 @@
+
+A commandline handler that will read a classpath from preferences, create
the initial classloader, and deloy. The cli handler will be 100% standalone
(no dependencies). Preference node selection will be based on a profile name.
\ No newline at end of file

Modified:
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerDescriptor.java
==============================================================================
---
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerDescriptor.java
(original)
+++
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerDescriptor.java
Wed May 11 09:31:43 2005
@@ -15,7 +15,7 @@
* limitations under the License.
*/

-package net.dpml.depot.station;
+package net.dpml.depot.content;

import java.net.URI;
import java.net.URISyntaxException;

Modified:
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistry.java
==============================================================================
---
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistry.java
(original)
+++
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistry.java
Wed May 11 09:31:43 2005
@@ -15,7 +15,7 @@
* limitations under the License.
*/

-package net.dpml.depot.station;
+package net.dpml.depot.content;

import java.io.IOException;
import java.net.URI;

Modified:
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistryControlPanel.java
==============================================================================
---
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistryControlPanel.java
(original)
+++
development/main/depot/content/src/main/net/dpml/depot/content/DepotContentHandlerRegistryControlPanel.java
Wed May 11 09:31:43 2005
@@ -15,7 +15,7 @@
* limitations under the License.
*/

-package net.dpml.depot.station;
+package net.dpml.depot.content;

import java.awt.Dialog;
import java.awt.Dimension;

Modified: development/main/depot/index.xml
==============================================================================
--- development/main/depot/index.xml (original)
+++ development/main/depot/index.xml Wed May 11 09:31:43 2005
@@ -23,13 +23,26 @@

<!-- Station -->

+ <project basedir="content">
+ <info>
+ <group>dpml/depot</group>
+ <name>dpml-depot-content</name>
+ <types>
+ <type>jar</type>
+ <type>plugin</type>
+ </types>
+ </info>
+ <dependencies>
+ <include key="dpml-transit-main" tag="api"/>
+ </dependencies>
+ </project>
+
<project basedir="station">
<info>
<group>dpml/depot</group>
<name>dpml-depot-station</name>
<types>
<type>jar</type>
- <type>plugin</type>
</types>
</info>
<dependencies>

Modified: development/main/depot/station/build.xml
==============================================================================
--- development/main/depot/station/build.xml (original)
+++ development/main/depot/station/build.xml Wed May 11 09:31:43 2005
@@ -7,7 +7,7 @@
<transit:import uri="artifact:template:dpml/magic/standard"/>

<target name="package" depends="standard.package">
- <x:export class="net.dpml.depot.station.DepotContentHandlerRegistry"/>
+ <x:export class="net.dpml.depot.station.TransitDialog"/>
</target>

</project>

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/station/prefs/ContentHandlerControllerPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerControllerPanel.java
Wed May 11 09:31:43 2005
@@ -292,6 +292,7 @@
String controlClassname = classname + "ControlPanel";
ClassLoader classloader = getControllerClassLoader( uri
);
m_dialog = createControlPanel( classloader,
controlClassname, parent );
+ m_dialog.setModal( true );
setEnabled( true );
}
catch( ClassNotFoundException e )
@@ -311,6 +312,7 @@
{
if( m_dialog != null )
{
+ m_dialog.setLocationRelativeTo( (Component)
event.getSource() );
m_dialog.setVisible( true );
}
}

Modified:
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerPanel.java
==============================================================================
---
development/main/depot/station/src/main/net/dpml/depot/station/prefs/ContentHandlerPanel.java
(original)
+++
development/main/depot/station/src/main/net/dpml/depot/prefs/ContentHandlerPanel.java
Wed May 11 09:31:43 2005
@@ -57,7 +57,6 @@

import net.dpml.transit.Transit;
import net.dpml.transit.util.ExceptionHelper;
-import net.dpml.transit.cache.CacheHandler;
import net.dpml.transit.host.ResourceHost;
import net.dpml.transit.util.Util;
import net.dpml.transit.content.ContentHandlerRegistry;
@@ -155,20 +154,21 @@
holder.setLayout( new BoxLayout( holder, BoxLayout.Y_AXIS ) );
holder.setBorder( new EmptyBorder( 0, 6, 0, 6 ) );
holder.setBackground( Color.white );
- JPanel cache = new JPanel();
- cache.setBackground( Color.white );
- cache.setLayout( new BorderLayout() );
- cache.add( label, BorderLayout.WEST );
- cache.setBorder(
+
+ JPanel panel = new JPanel();
+ panel.setBackground( Color.white );
+ panel.setLayout( new BorderLayout() );
+ panel.add( label, BorderLayout.WEST );
+ panel.setBorder(
new CompoundBorder(
- new TitledBorder( null, "Cache", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ new TitledBorder( null, "Controller", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
JButton button = new JButton( new ControllerAction( parent,
"Controller" ) );
- JPanel cacheButtonHolder = new JPanel();
- cacheButtonHolder.setBackground( Color.white );
- cacheButtonHolder.setLayout( new BorderLayout() );
- cacheButtonHolder.add( button, BorderLayout.SOUTH );
- cache.add( cacheButtonHolder, BorderLayout.EAST );
- holder.add( cache );
+ JPanel buttons = new JPanel();
+ buttons.setBackground( Color.white );
+ buttons.setLayout( new BorderLayout() );
+ buttons.add( button, BorderLayout.SOUTH );
+ panel.add( buttons, BorderLayout.EAST );
+ holder.add( panel );
return holder;
}


Added:
development/main/depot/station/src/main/net/dpml/depot/station/CachePanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/CachePanel.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,321 @@
+/*
+ * 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.station;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.JFileChooser;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.host.ResourceManager;
+import net.dpml.transit.util.Util;
+
+
+/**
+ * Control panel for editing the cache preferences.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class CachePanel extends JPanel implements PreferenceChangeListener,
PropertyChangeListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+ private JLabel m_label;
+ private JButton m_ok;
+ private JButton m_revert;
+
+ private File m_target;
+
+ private Preferences m_cachePrefs;
+
+ private PropertyChangeSupport m_propertyChangeSupport;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public CachePanel( JDialog parent ) throws Exception
+ {
+ m_parent = parent;
+ m_propertyChangeSupport = new PropertyChangeSupport( this );
+
+ m_cachePrefs = Preferences.userNodeForPackage( CacheHandler.class );
+
+ setLayout( new BorderLayout() );
+ setBackground( Color.white );
+
+ File cache = getCurrentCacheFile();
+ String filename = cache.getCanonicalPath();
+
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ Transit.class.getClassLoader(),
"net/dpml/transit/images/cache.jpg", "Filename", "Directory: " + filename );
+ label.setBorder( new EmptyBorder( 0, 5, 0, 0 ) );
+ m_label = label;
+ m_ok = new JButton( new OKAction( "OK" ) );
+ m_revert = new JButton( new RevertAction( "Undo" ) );
+
+ m_cachePrefs.addPreferenceChangeListener( this );
+
+ if( null == cache )
+ {
+ // setup an error dialog content
+ }
+ else
+ {
+ // create a label containing an icon and the current filename
+
+ JPanel panel = new JPanel();
+ panel.setLayout( new BorderLayout() );
+ panel.setBackground( Color.white );
+ panel.add( label, BorderLayout.WEST );
+ add( panel, BorderLayout.NORTH );
+
+ // add controls for modification of the cache value
+
+ JPanel buttonHolder = new JPanel();
+ buttonHolder.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ buttonHolder.add( m_revert );
+ buttonHolder.add( new JButton( new ChangeAction( "Change" ) ) );
+ buttonHolder.add( m_ok );
+ buttonHolder.add( new JButton( new CloseAction( "Cancel" ) ) );
+ buttonHolder.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ buttonHolder.setBackground( Color.white );
+ add( buttonHolder, BorderLayout.SOUTH );
+
+ m_propertyChangeSupport.addPropertyChangeListener( this );
+ }
+ }
+
+ /**
+ * 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 )
+ {
+ File cache = getCurrentCacheFile();
+ boolean flag = ( false == cache.equals( m_target ) );
+ m_ok.setEnabled( flag );
+ m_revert.setEnabled( flag );
+ }
+
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ if( null == m_target )
+ {
+ File cache = getCurrentCacheFile();
+ String path = convertToPath( cache );
+ String text = "Directory: " + path;
+ m_label.setText( text );
+ }
+ }
+
+ private class CloseAction extends AbstractAction
+ {
+ CloseAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_parent.hide();
+ if( m_target != null )
+ {
+ File cache = getCurrentCacheFile();
+ String filename = convertToPath( cache );
+ final String text = "Directory: " + filename;
+ m_label.setText( text );
+ m_target = null;
+ }
+ m_ok.setEnabled( false );
+ }
+ }
+
+ private class OKAction extends AbstractAction
+ {
+ OKAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ if( null != m_target )
+ {
+ File file = getCurrentCacheFile();
+ if( false == file.equals( m_target ) )
+ {
+ String path = convertToPath( m_target );
+ m_cachePrefs.put( "location", path );
+ }
+ }
+ m_parent.hide();
+ }
+ }
+
+ private class RevertAction extends AbstractAction
+ {
+ RevertAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ File old = m_target;
+ m_target = getCurrentCacheFile();
+ String text = "Directory: " + convertToPath( m_target );
+ m_label.setText( text );
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ this, "location", old, m_target);
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+
+ private class ChangeAction extends AbstractAction
+ {
+ ChangeAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ File file = getCurrentCacheFile();
+ JFileChooser chooser = new JFileChooser();
+ chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
+ chooser.setCurrentDirectory( file );
+ int result = chooser.showOpenDialog( m_parent );
+ if( result == JFileChooser.APPROVE_OPTION )
+ {
+ m_target = chooser.getSelectedFile();
+ String text = "Directory: " + convertToPath( m_target );
+ m_label.setText( text );
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ this, "location", file, m_target );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+ }
+
+ private String convertToPath( File file )
+ {
+ try
+ {
+ return file.getCanonicalPath();
+ }
+ catch( Exception e )
+ {
+ return file.toString();
+ }
+ }
+
+ private File getCurrentCacheFile()
+ {
+ File file = getUserCacheFile();
+ if( null == file )
+ {
+ return getDefaultCacheFile();
+ }
+ else
+ {
+ return file;
+ }
+ }
+
+ private File getUserCacheFile()
+ {
+ String filename = m_cachePrefs.get( "location", null );
+ if( null == filename )
+ {
+ return null;
+ }
+ else
+ {
+ return new File( filename );
+ }
+ }
+
+ private File getDefaultCacheFile()
+ {
+ Preferences node = Preferences.systemNodeForPackage(
CacheHandler.class );
+ String filename = node.get( "location", null );
+ if( null == filename )
+ {
+ throw new IllegalStateException( "missing system location
preference: " + node );
+ }
+ else
+ {
+ return new File( filename );
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/ContentHandlerControllerPanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/ContentHandlerControllerPanel.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,497 @@
+/*
+ * 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.station;
+
+import java.io.IOException;
+import java.awt.Color;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.lang.reflect.Constructor;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.JOptionPane;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.JFileChooser;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.content.ContentHandlerRegistry;
+import net.dpml.transit.repository.Plugin;
+
+
+/**
+ * Control panel for editing the cache preferences.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class ContentHandlerControllerPanel extends JPanel implements
PreferenceChangeListener, PropertyChangeListener, DocumentListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+ private JTextField m_base;
+ private JButton m_ok;
+ private JButton m_revert;
+ private JButton m_settings;
+
+ private Preferences m_preferences;
+
+ private PropertyChangeSupport m_propertyChangeSupport;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public ContentHandlerControllerPanel( JDialog parent ) throws Exception
+ {
+ m_parent = parent;
+ m_propertyChangeSupport = new PropertyChangeSupport( this );
+
+ m_preferences = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+
+ setLayout( new BorderLayout() );
+ setBackground( Color.white );
+
+ m_ok = new JButton( new OKAction( "OK" ) );
+ m_revert = new JButton( new RevertAction( "Undo" ) );
+ m_preferences.addPreferenceChangeListener( this );
+
+ // create a label containing an icon and label
+
+ {
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ Transit.class.getClassLoader(),
"net/dpml/transit/images/source.png", "URI", "Controller 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 content handler artifact uri and
a
+ // button for optional controller 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 JButton( new SettingsAction( "Controller
Settings", m_parent ) );
+ settingsPanel.add( m_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( "Cancel" ) ) );
+ 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", artifact, 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 );
+ }
+
+ 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();
+ 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_dialog;
+
+ SettingsAction( String name, Dialog parent )
+ {
+ super( name );
+ String controllerPath = getControllerPathFromPreferences();
+ if( null == controllerPath )
+ {
+ setEnabled( false );
+ }
+ else
+ {
+ try
+ {
+ URI uri = new URI( controllerPath );
+ String classname = getControllerClassname( uri );
+ String controlClassname = classname + "ControlPanel";
+ ClassLoader classloader = getControllerClassLoader( uri
);
+ m_dialog = createControlPanel( classloader,
controlClassname, parent );
+ 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.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 TransitException
+ {
+ try
+ {
+ Class cls = classloader.loadClass( classname );
+ Class[] params = new Class[]{ Dialog.class};
+ Object[] args = new Object[]{ parent };
+ Constructor cons = cls.getConstructor( params );
+ return (Dialog) cons.newInstance( args );
+ }
+ 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
+ {
+ OKAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ 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" );
+ m_parent.hide();
+ }
+ else
+ {
+ boolean validated = validateControllerSpec( m_parent,
text );
+ if( validated )
+ {
+ m_parent.hide();
+ m_preferences.put( "uri", text );
+ }
+ }
+ }
+ }
+ }
+
+ private boolean validateControllerSpec( Component component, String spec
)
+ {
+ 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 );
+ }
+
+ 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 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( ContentHandlerRegistry.class.isAssignableFrom( c ) )
+ {
+ return true;
+ }
+ else
+ {
+ final String title = "Controller URI Error";
+ final String message = "Plugin class does not implement " +
ContentHandlerRegistry.class.getName() + ".";
+ JOptionPane.showMessageDialog( component, message, title,
JOptionPane.ERROR_MESSAGE );
+ return false;
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/ContentHandlerPanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/ContentHandlerPanel.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,404 @@
+/*
+ * Copyright 2004 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.station;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.ListSelectionModel;
+import javax.swing.JOptionPane;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.host.ResourceHost;
+import net.dpml.transit.util.Util;
+import net.dpml.transit.content.ContentHandlerRegistry;
+
+/**
+ * Runnable plugin that handles DPML environment setup.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class ContentHandlerPanel extends JPanel implements
ListSelectionListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+
+ private GenericTable m_table;
+
+ private JButton m_edit;
+ private JButton m_delete;
+
+ private String m_selection; // selected hostname
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public ContentHandlerPanel( JDialog parent ) throws Exception
+ {
+ m_parent = parent;
+
+ m_edit = new JButton( new EditAction( "Edit" ) );
+ m_delete = new JButton( new DeleteAction( "Delete" ) );
+
+ setLayout( new BorderLayout() );
+ setBorder( new EmptyBorder( 10, 6, 10, 6 ) );
+ setBackground( Color.white );
+
+ JPanel contentHandlerPanel = new JPanel();
+ contentHandlerPanel.setBackground( Color.white );
+
+ contentHandlerPanel.setLayout( new BorderLayout() );
+ TitledBorder tb =
+ new TitledBorder(
+ new EmptyBorder( 0,0,0,0 ), "Content Handlers",
TitledBorder.LEFT, TitledBorder.TOP );
+ contentHandlerPanel.setBorder( new CompoundBorder( tb, border5 ) );
+
+ Preferences prefs = Preferences.userNodeForPackage(
ContentHandlerRegistry.class );
+ TableColumnModel columns = createContentHandlerColumnModel();
+ NodeTableModel model = new NodeTableModel( prefs );
+ m_table = new GenericTable( model, columns );
+ m_table.setShowVerticalLines( false );
+ m_table.setShowHorizontalLines( false );
+ m_table.getSelectionModel().addListSelectionListener( this );
+
+ JScrollPane scroller = createScrollPanel( m_table );
+ contentHandlerPanel.add( scroller, BorderLayout.CENTER );
+ JPanel buttonHolder = new JPanel();
+ buttonHolder.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ buttonHolder.add( new JButton( new AddAction( "Add" ) ) );
+ buttonHolder.add( m_edit );
+ buttonHolder.add( m_delete );
+ buttonHolder.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ buttonHolder.setBackground( Color.white );
+ contentHandlerPanel.add( buttonHolder, BorderLayout.SOUTH );
+
+ JPanel controllerPanel = createContentHandlerControllerPanel( parent
);
+
+ add( controllerPanel, BorderLayout.NORTH );
+ add( contentHandlerPanel, BorderLayout.CENTER );
+ }
+
+ //--------------------------------------------------------------
+ // utilities
+ //--------------------------------------------------------------
+
+ private JPanel createContentHandlerControllerPanel( JDialog parent )
+ {
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ ResourcePanel.class.getClassLoader(),
+ "net/dpml/transit/images/misc.png",
+ "Artifact",
+ "Content Handler Controller settings." );
+ label.setBorder( new EmptyBorder( 0, 5, 0, 0 ) );
+
+ JPanel holder = new JPanel();
+ holder.setLayout( new BoxLayout( holder, BoxLayout.Y_AXIS ) );
+ holder.setBorder( new EmptyBorder( 0, 6, 0, 6 ) );
+ holder.setBackground( Color.white );
+ JPanel cache = new JPanel();
+ cache.setBackground( Color.white );
+ cache.setLayout( new BorderLayout() );
+ cache.add( label, BorderLayout.WEST );
+ cache.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Cache", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ JButton button = new JButton( new ControllerAction( parent,
"Controller" ) );
+ JPanel cacheButtonHolder = new JPanel();
+ cacheButtonHolder.setBackground( Color.white );
+ cacheButtonHolder.setLayout( new BorderLayout() );
+ cacheButtonHolder.add( button, BorderLayout.SOUTH );
+ cache.add( cacheButtonHolder, BorderLayout.EAST );
+ holder.add( cache );
+ return holder;
+ }
+
+ private static class ControllerAction extends AbstractAction
+ {
+ JDialog m_parent;
+
+ ControllerAction( JDialog parent, String name )
+ {
+ super( name );
+ m_parent = parent;
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Content Handler Controller" );
+ Dimension size = new Dimension( 400, 240 );
+
+ JPanel frame = new JPanel();
+ frame.setLayout( new BorderLayout() );
+ frame.setBackground( Color.white );
+ frame.setBorder( new EmptyBorder( 10, 6, 0, 6 ) );
+
+ JPanel panel = new ContentHandlerControllerPanel( dialog );
+ frame.add( panel, BorderLayout.CENTER );
+ dialog.setContentPane( frame );
+ dialog.setSize( size );
+ dialog.setLocationRelativeTo( (Component) event.getSource()
);
+ dialog.setResizable( true );
+ dialog.setVisible(true);
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to handle the
'Controller' action. "
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ 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();
+ }
+ }
+ }
+
+ /**
+ * Creation of a parameterized scroll pane.
+ * @param view the viewport view
+ * @return the scroll pane wrapping the supplied view
+ */
+ private static JScrollPane createScrollPanel( Component view )
+ {
+ JScrollPane scroller = new JScrollPane();
+ scroller.setVerticalScrollBarPolicy(
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
+ scroller.setHorizontalScrollBarPolicy(
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
+ scroller.getViewport().setBackground( Color.white );
+ scroller.setViewportView( view );
+ return scroller;
+ }
+
+ /**
+ * Utility method to construct the hosts table column model.
+ * @return the table
+ */
+ private static TableColumnModel createContentHandlerColumnModel()
+ {
+ TableColumn iconColumn = new TableColumn( 0, 30, new
DefaultCellRenderer(), null );
+ iconColumn.setHeaderValue( "" );
+ iconColumn.setMaxWidth( 30 );
+ iconColumn.setMinWidth( 30 );
+ TableColumn typeColumn = new TableColumn( 1, 100, new
DefaultCellRenderer(), null );
+ typeColumn.setHeaderValue( "Type" );
+ TableColumnModel model = new DefaultTableColumnModel();
+ model.addColumn( iconColumn );
+ model.addColumn( typeColumn );
+ return model;
+ }
+
+ private class AddAction extends AbstractAction
+ {
+ public AddAction( String name )
+ {
+ super( name );
+ setEnabled( true );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ String name = JOptionPane.showInputDialog( m_parent, "Content
Handler Name:" );
+ if( null == name )
+ {
+ return;
+ }
+
+ /*
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Host: " + name );
+ JPanel panel = new HostPanel( dialog, name );
+ 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 )
+ {
+ final String error =
+ "Unexpected error while attempting to construct host
dialog."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ */
+ }
+ }
+
+ private class EditAction extends AbstractAction
+ {
+ public EditAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ /*
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Host: " + m_selection );
+ JPanel panel = new HostPanel( dialog, m_selection );
+ 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 )
+ {
+ final String error =
+ "Unexpected error while attempting to construct host
dialog."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ */
+ }
+ }
+
+ private class DeleteAction extends AbstractAction
+ {
+ public DeleteAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ if( null == m_selection )
+ {
+ return;
+ }
+ /*
+ Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
+ Preferences target = hosts.node( m_selection );
+ try
+ {
+ target.removeNode();
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to delete a host
preferences node."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ */
+ }
+ }
+
+ public void valueChanged( ListSelectionEvent event )
+ {
+ if( !event.getValueIsAdjusting() )
+ {
+ ListSelectionModel model = m_table.getSelectionModel();
+ synchronized( model )
+ {
+ int n = model.getMinSelectionIndex();
+ if( ( n == model.getMaxSelectionIndex() ) && ( n > -1 ) )
+ {
+ m_selection = (String) m_table.getValueAt( n, 1 );
+ m_edit.setEnabled( true );
+ m_delete.setEnabled( true );
+ }
+ else
+ {
+ m_selection = null;
+ m_edit.setEnabled( false );
+ m_delete.setEnabled( false );
+ }
+ }
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/DefaultCellRenderer.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/DefaultCellRenderer.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2005 Stephen 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.station;
+
+import java.awt.Component;
+import java.awt.Font;
+import javax.swing.ImageIcon;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.SwingConstants;
+import javax.swing.border.EmptyBorder;
+import javax.swing.table.DefaultTableCellRenderer;
+
+class DefaultCellRenderer extends DefaultTableCellRenderer
+{
+
//--------------------------------------------------------------------------
+ // state
+
//--------------------------------------------------------------------------
+
+ private static final EmptyBorder border = new EmptyBorder(1,5,1,3);
+
+
//--------------------------------------------------------------------------
+ // constructor
+
//--------------------------------------------------------------------------
+
+ /**
+ * Creation of a new cell renderer using the default font.
+ */
+ public DefaultCellRenderer( )
+ {
+ }
+
+
//--------------------------------------------------------------------------
+ // implementation
+
//--------------------------------------------------------------------------
+
+ public Component getTableCellRendererComponent(
+ JTable table, Object object, boolean selected, boolean focus, int row,
int column )
+ {
+ JLabel label =
+ (JLabel) super.getTableCellRendererComponent(
+ table, object, selected, focus, row, column );
+ label.setBorder( border );
+ label.setHorizontalAlignment( SwingConstants.LEFT );
+
+ if( object == null )
+ {
+ label.setIcon( null );
+ label.setText( null );
+ return label;
+ }
+
+ if( object instanceof ImageIcon )
+ {
+ label.setText( null );
+ label.setIcon( (ImageIcon) object );
+ return label;
+ }
+ else if( object instanceof Boolean )
+ {
+ JCheckBox checkBox = new JCheckBox();
+ checkBox.setSelected( ((Boolean)object).booleanValue() );
+ if( selected )
+ {
+ checkBox.setForeground(table.getSelectionForeground());
+ checkBox.setBackground(table.getSelectionBackground());
+ }
+ else
+ {
+ checkBox.setForeground(table.getForeground());
+ checkBox.setBackground(table.getBackground());
+ }
+ checkBox.setBorder( new EmptyBorder(0,20,0,10) );
+ checkBox.setHorizontalAlignment(JCheckBox.LEFT);
+ return checkBox;
+ }
+ else
+ {
+ return label;
+ }
+ }
+}
+

Added:
development/main/depot/station/src/main/net/dpml/depot/station/GenericTable.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/GenericTable.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2005 Stephen 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.station;
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.Color;
+
+import javax.swing.JTable;
+import javax.swing.table.TableModel;
+import javax.swing.table.TableColumnModel;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+
+/**
+ * A table mapping the collection of preference nodes to hosts.
+ */
+public class GenericTable extends JTable implements ListSelectionListener,
FocusListener
+{
+
//--------------------------------------------------------------------------
+ // static
+
//--------------------------------------------------------------------------
+
+ /**
+ * The enabled color.
+ */
+ private static final Color ENABLED_COLOR = new Color( 204, 204, 255 );
+
+ /**
+ * The disabled color.
+ */
+ private static final Color DISABLED_COLOR = new Color( 228, 228, 255 );
+
+ /**
+ * Double-click count.
+ */
+ private static final int TWO = 2;
+
+ /**
+ * Row height.
+ */
+ private static final int ROW_HEIGHT = 18;
+
+
//--------------------------------------------------------------------------
+ // state
+
//--------------------------------------------------------------------------
+
+ /**
+ * The currently selected item if only 1 instance is selected.
+ */
+ private Object m_selection;
+
+ /**
+ * The table data model.
+ */
+ private TableModel m_data;
+
+
//--------------------------------------------------------------------------
+ // constructor
+
//--------------------------------------------------------------------------
+
+ /**
+ * Creation of a new hosts table.
+ * @param entity the entity that this table is presenting
+ * @param data a table model containing the data to layout in view
+ * @param columns the table column model to apply
+ */
+ public GenericTable( TableModel data, TableColumnModel columns )
+ {
+ super( data, columns );
+
+ m_data = data;
+ setShowGrid( false );
+ setRowHeight( ROW_HEIGHT );
+ getTableHeader().setReorderingAllowed( false );
+
+ MouseListener popupListener = new PopupListener();
+ addMouseListener( popupListener );
+ addFocusListener( this );
+ }
+
+
//--------------------------------------------------------------------------
+ // ListSelectionListener
+
//--------------------------------------------------------------------------
+
+ /**
+ * Listens to changes in the selected state of the table and
+ * propergates a <code>ContextEvent</code> referencing this table as
+ * the event's panel when the table selection changes.
+ * @param event a list selection event
+ */
+ public void valueChanged( ListSelectionEvent event )
+ {
+ super.valueChanged( event );
+ if( !event.getValueIsAdjusting() )
+ {
+ ListSelectionModel model = getSelectionModel();
+ synchronized( model )
+ {
+ int n = model.getMinSelectionIndex();
+ if( ( n == model.getMaxSelectionIndex() ) && ( n > -1 ) )
+ {
+ m_selection = m_data.getValueAt( n, -1 );
+ }
+ else if( m_selection != null )
+ {
+ m_selection = null;
+ }
+ }
+ }
+ }
+
+
//--------------------------------------------------------------------------
+ // FocusListener
+
//--------------------------------------------------------------------------
+
+ /**
+ * Handle the focus gained event.
+ * @param event the focus event
+ */
+ public void focusGained( FocusEvent event )
+ {
+ setSelectionBackground( ENABLED_COLOR );
+ }
+
+ /**
+ * Handle the focus lost event.
+ * @param event the focus event
+ */
+ public void focusLost( FocusEvent event )
+ {
+ setSelectionBackground( DISABLED_COLOR );
+ }
+
+ /**
+ * Mouse adapter.
+ */
+ private class PopupListener extends MouseAdapter
+ {
+ /**
+ * Handle a mouse event.
+ * @param event the mouse pressed event
+ */
+ public void mousePressed( MouseEvent event )
+ {
+ handleMouseEvent( event );
+ }
+
+ /**
+ * Handle a mouse event.
+ * @param event the mouse released event
+ */
+ public void mouseReleased( MouseEvent event )
+ {
+ handleMouseEvent( event );
+ }
+ }
+
+ /**
+ * Handle a mouse event within the table.
+ * @param event the mouse event
+ */
+ protected void handleMouseEvent( MouseEvent event )
+ {
+ if( event.isPopupTrigger() )
+ {
+System.out.println( "# POPUP TRIGGER" );
+ int j = rowAtPoint( event.getPoint() );
+ if( j > -1 )
+ {
+ if( !isRowSelected( j ) )
+ {
+ clearSelection();
+ setRowSelectionInterval( j, j );
+ }
+ }
+ else
+ {
+ clearSelection();
+ }
+ }
+ else if( SwingUtilities.isLeftMouseButton( event ) &&
event.getClickCount() == TWO )
+ {
+System.out.println( "# DOUBLE CLICK" );
+ int j = rowAtPoint( event.getPoint() );
+ if( j > -1 )
+ {
+ if( !isRowSelected( j ) )
+ {
+ clearSelection();
+ setRowSelectionInterval( j, j );
+ }
+ }
+ else
+ {
+ clearSelection();
+ }
+ }
+ }
+
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/HostPanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/HostPanel.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,499 @@
+/*
+ * 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.station;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Date;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.JFileChooser;
+import javax.swing.JCheckBox;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+import javax.swing.JComboBox;
+import javax.swing.ImageIcon;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.text.Document;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.host.ResourceManager;
+import net.dpml.transit.host.HostDescriptor;
+import net.dpml.transit.host.ResourceHost;
+import net.dpml.transit.util.Util;
+
+/**
+ * A interactive panel that presents the preferences for a single host.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class HostPanel extends JPanel implements PreferenceChangeListener,
PropertyChangeListener, DocumentListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+
+ private JLabel m_label;
+ private JCheckBox m_enabled;
+ private JCheckBox m_trusted;
+ private JTextField m_base;
+
+ private JButton m_ok;
+ private JButton m_revert;
+
+ private Preferences m_hostsPrefs;
+ private Preferences m_hostPrefs;
+
+ private PropertyChangeSupport m_propertyChangeSupport;
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public HostPanel( JDialog parent, String name ) throws Exception
+ {
+ m_parent = parent;
+ m_propertyChangeSupport = new PropertyChangeSupport( this );
+
+ setLayout( new BorderLayout() );
+ setBackground( Color.white );
+ setBorder( new EmptyBorder( 10, 6, 0, 6 ) );
+
+ m_hostsPrefs = Preferences.userNodeForPackage( ResourceHost.class );
+ m_hostPrefs = m_hostsPrefs.node( name ); // TODO: host could have
been removed
+ m_hostPrefs.addPreferenceChangeListener( this );
+
+ HostDescriptor descriptor = new HostDescriptor( m_hostPrefs );
+
+ //
+ // create the dialog label containing the host descriptor name
+ //
+
+ m_label =
+ IconHelper.createImageIconJLabel(
+ Transit.class.getClassLoader(),
"net/dpml/transit/images/server.png", "Host", "Host: " + name );
+
+ m_label.setBorder( new EmptyBorder( 0, 5, 0, 10 ) );
+ JPanel labelPanel = new JPanel();
+ labelPanel.setLayout( new BorderLayout() );
+ labelPanel.setBackground( Color.white );
+ labelPanel.add( m_label, BorderLayout.WEST );
+ labelPanel.setBorder( new EmptyBorder( 10, 6, 10, 6 ) );
+
+ //
+ // create a panel to hold things in the center of the dialog
+ //
+
+ JPanel panel = new JPanel();
+ panel.setLayout( new BoxLayout( panel, BoxLayout.Y_AXIS ) );
+ panel.setBackground( Color.white );
+
+ //
+ // create a box layout for the host base url and groups button
+ // TODO: action support for groups
+ //
+
+ JPanel paths = new JPanel();
+ panel.add( paths );
+ paths.setLayout( new BorderLayout() );
+ paths.setBackground( Color.white );
+ paths.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Base URL", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+
+ m_base = new JTextField( descriptor.getBasePath() );
+ m_base.getDocument().addDocumentListener( this ); // listen for
changes
+ m_base.setBackground( Color.white );
+ JPanel basePanel = new JPanel();
+ basePanel.setLayout( new BorderLayout() );
+ basePanel.setBackground( Color.white );
+ basePanel.setBorder( new EmptyBorder( 0, 0, 0, 30 ) );
+ basePanel.add( m_base, BorderLayout.CENTER );
+
+ JButton knownGroups = new JButton( "Groups" );
+ knownGroups.setEnabled( false );
+ JPanel groupsPanel = new JPanel();
+ groupsPanel.setLayout( new BorderLayout() );
+ groupsPanel.setBackground( Color.white );
+ groupsPanel.add( knownGroups, BorderLayout.EAST );
+
+ paths.add( basePanel, BorderLayout.CENTER );
+ paths.add( groupsPanel, BorderLayout.EAST );
+
+ //
+ // create a box layout to hold the layout strategy and the
credentials
+ //
+
+ JPanel layoutPlusCredentials = new JPanel();
+ layoutPlusCredentials.setLayout( new BoxLayout(
layoutPlusCredentials, BoxLayout.X_AXIS ) );
+ layoutPlusCredentials.setBackground( Color.white );
+ panel.add( layoutPlusCredentials );
+
+ // repository layout strategy
+ // TODO: need to figure out how to get a layout 'friendly name' and
associate
+ // this with a class name.
+
+ JPanel layout = new JPanel();
+ layout.setLayout( new BorderLayout() );
+ layout.setBackground( Color.white );
+ layout.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Repository Layout", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ layoutPlusCredentials.add( layout );
+
+ JComboBox strategy = new JComboBox( new Object[]{ " Classic Layout "
} );
+ layout.add( strategy, BorderLayout.SOUTH );
+
+ // sign-on credentials
+
+ JPanel credentials = new JPanel();
+ credentials.setLayout( new BoxLayout( credentials, BoxLayout.X_AXIS
) );
+ credentials.setBackground( Color.white );
+ credentials.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Credentials", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ // TODO: action support for credential settings
+ ImageIcon keysIcon = IconHelper.createImageIcon(
+ Transit.class.getClassLoader(),
"net/dpml/transit/images/password.png", "Credentials" );
+ JLabel keys = new JLabel( keysIcon );
+ JButton settings = new JButton( "Settings" );
+ settings.setEnabled( false );
+ JPanel settingsPanel = new JPanel();
+ settingsPanel.setLayout( new BorderLayout() );
+ settingsPanel.setBackground( Color.white );
+ settingsPanel.add( keys, BorderLayout.WEST );
+ settingsPanel.add( settings, BorderLayout.EAST );
+ credentials.add( settingsPanel );
+ layoutPlusCredentials.add( credentials );
+
+ //
+ // create a box layout for the enabled and trusted checkboxs
+ //
+
+ JPanel holder = new JPanel();
+ holder.setLayout( new BoxLayout( holder, BoxLayout.Y_AXIS ) );
+ holder.setBackground( Color.white );
+ holder.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Parameters", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ panel.add( holder );
+
+ // add enabled status
+
+ m_enabled = new JCheckBox( new EnableAction( "Enabled" ) );
+ m_enabled.setBackground( Color.white );
+ m_enabled.setSelected( descriptor.getEnabled() );
+
+ JPanel enabledPanel = new JPanel();
+ enabledPanel.setLayout( new BorderLayout() );
+ enabledPanel.setBackground( Color.white );
+ enabledPanel.add( m_enabled, BorderLayout.WEST );
+ enabledPanel.add( m_enabled );
+ holder.add( enabledPanel );
+
+ // add trusted status
+
+ m_trusted = new JCheckBox( new TrustedAction( "Trusted" ) );
+ m_trusted.setBackground( Color.white );
+ m_trusted.setSelected( descriptor.getTrusted() );
+
+ JPanel trustedPanel = new JPanel();
+ trustedPanel.setLayout( new BorderLayout() );
+ trustedPanel.setBackground( Color.white );
+ trustedPanel.add( m_trusted, BorderLayout.WEST );
+ trustedPanel.add( m_trusted );
+ holder.add( trustedPanel );
+
+ //
+ // add commmit/revert controls and assemble the dialog
+ //
+
+ m_ok = new JButton( new OKAction( "OK", this ) );
+ m_revert = new JButton( new RevertAction( "Undo Changes" ) );
+ JPanel buttonHolder = new JPanel();
+ buttonHolder.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ buttonHolder.add( m_revert );
+ buttonHolder.add( m_ok );
+ buttonHolder.add( new JButton( new CloseAction( "Cancel" ) ) );
+ buttonHolder.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ buttonHolder.setBackground( Color.white );
+
+ JPanel thing = new JPanel();
+ thing.setLayout( new BorderLayout() );
+ thing.add( panel, BorderLayout.NORTH );
+ thing.setBackground( Color.white );
+
+ add( labelPanel, BorderLayout.NORTH );
+ add( thing , BorderLayout.CENTER );
+ add( buttonHolder, BorderLayout.SOUTH );
+
+ m_propertyChangeSupport.addPropertyChangeListener( this );
+ }
+
+ //--------------------------------------------------------------
+ // PreferenceChangeListener
+ //--------------------------------------------------------------
+
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ }
+
+ //--------------------------------------------------------------
+ // 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 this host.
+ */
+ public void propertyChange( PropertyChangeEvent event )
+ {
+ boolean flag = false;
+ {
+ boolean value = m_enabled.isSelected();
+ if( m_hostPrefs.getBoolean( "enabled", true ) != value )
+ {
+ flag = true;
+ }
+ }
+ {
+ boolean value = m_trusted.isSelected();
+ if( m_hostPrefs.getBoolean( "trusted", false ) != value )
+ {
+ flag = true;
+ }
+ }
+ {
+ String path = m_base.getText();
+ if( false == path.equals( m_hostPrefs.get( "base", null ) ) )
+ {
+ flag = true;
+ }
+ }
+ m_ok.setEnabled( flag );
+ m_revert.setEnabled( flag );
+ }
+
+ //--------------------------------------------------------------
+ // DocumentListener
+ //--------------------------------------------------------------
+
+ public void insertUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ public void removeUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ public void changedUpdate( DocumentEvent event )
+ {
+ fireBaseChangedEvent();
+ }
+
+ private void fireBaseChangedEvent()
+ {
+ String path = m_hostPrefs.get( "base", null );
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ m_base, "base", path, m_base.getText() );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+
+ //--------------------------------------------------------------
+ // utility classes
+ //--------------------------------------------------------------
+
+ private class EnableAction extends AbstractAction
+ {
+ EnableAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ boolean selected = m_enabled.isSelected();
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ this, "enabled", new Boolean( !selected ), new Boolean(
selected ) );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+
+ private class TrustedAction extends AbstractAction
+ {
+ TrustedAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ boolean selected = m_trusted.isSelected();
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ this, "trusted", new Boolean( !selected ), new Boolean(
selected ) );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+
+ /**
+ * Action that handles the 'Cancel' dialog button.
+ */
+ private class CloseAction extends AbstractAction
+ {
+ CloseAction( String name )
+ {
+ super( name );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_parent.hide();
+ m_ok.setEnabled( false );
+ }
+ }
+
+ private class OKAction extends AbstractAction
+ {
+ private PropertyChangeListener m_listener;
+
+ OKAction( String name, PropertyChangeListener listener )
+ {
+ super( name );
+ setEnabled( false );
+ m_listener = listener;
+ }
+
+ // TODO: we need a solution in place under which we log
+ // information about preference changes
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_parent.hide();
+ m_propertyChangeSupport.removePropertyChangeListener( m_listener
);
+ {
+ boolean value = m_enabled.isSelected();
+ if( m_hostPrefs.getBoolean( "enabled", true ) != value )
+ {
+ m_hostPrefs.putBoolean( "enabled", value );
+ }
+ }
+ {
+ boolean value = m_trusted.isSelected();
+ if( m_hostPrefs.getBoolean( "trusted", true ) != value )
+ {
+ m_hostPrefs.putBoolean( "trusted", value );
+ }
+ }
+ {
+ String value = m_base.getText();
+ if( false == value.equals( m_hostPrefs.get( "base", null ) )
)
+ {
+ m_hostPrefs.put( "base", value );
+ }
+ }
+ try
+ {
+ m_hostPrefs.putLong( "modified", new Date().getTime() ); //
trigger event broadcast
+ m_hostPrefs.flush();
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private class RevertAction extends AbstractAction
+ {
+ RevertAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ m_enabled.setSelected( m_hostPrefs.getBoolean( "enabled", true )
);
+ m_trusted.setSelected( m_hostPrefs.getBoolean( "trusted", false
) );
+ m_base.setText( m_hostPrefs.get( "base", null ) );
+ try
+ {
+ m_hostPrefs.flush();
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ }
+ PropertyChangeEvent e =
+ new PropertyChangeEvent(
+ this, "revert", null, null );
+ m_propertyChangeSupport.firePropertyChange( e );
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/IconHelper.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/IconHelper.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,53 @@
+/*
+ * 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.station;
+
+import java.net.URL;
+
+import javax.swing.JLabel;
+import javax.swing.ImageIcon;
+
+/**
+ */
+class IconHelper
+{
+ public static JLabel createImageIconJLabel( ClassLoader classloader,
String path, String description, String text )
+ {
+ ImageIcon icon = createImageIcon( classloader, path, description );
+ JLabel label = new JLabel( text, icon, JLabel.LEFT );
+ return label;
+ }
+
+ public static ImageIcon createImageIcon( ClassLoader classloader, String
path, String description )
+ {
+ URL url = classloader.getResource( path );
+ if( null != url )
+ {
+ return new ImageIcon( url );
+ }
+ else
+ {
+ final String error =
+ "Supplied image icon resource path is unknown ["
+ + path
+ + "].";
+ throw new IllegalArgumentException( error );
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/Main.java
==============================================================================
--- (empty file)
+++ development/main/depot/station/src/main/net/dpml/depot/station/Main.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2004 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.station;
+
+import java.util.prefs.Preferences;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+import javax.swing.SwingUtilities;
+
+import net.dpml.transit.Transit;
+
+
+/**
+ * CLI hander for the depot package.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id: Main.java 2480 2005-05-10 04:44:32Z mcconnell AT dpml.net $
+ */
+public final class Main
+{
+ public static void main( final String[] args )
+ throws Exception
+ {
+ //
+ // Setup transit protocol handler
+ //
+
+ System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);
+
+ Logger logger = Logger.getLogger( "depot" );
+
+ //
+ // check if a prefs reset has been requested
+ //
+
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.equals( "-reset" ) )
+ {
+ try
+ {
+ Preferences usr = Preferences.userNodeForPackage(
Transit.class );
+ logger.info( "resetting preferences: " + usr );
+ usr.removeNode();
+ usr.flush();
+ Preferences sys = Preferences.systemNodeForPackage(
Transit.class );
+ logger.info( "resetting preferences: " + sys );
+ sys.removeNode();
+ sys.flush();
+ }
+ catch( Throwable e )
+ {
+ logger.log( Level.SEVERE, "preference rest failed", e );
+ }
+ }
+ }
+
+ //
+ // check if a prefs are enabled (default is true)
+ //
+
+ System.setProperty( "dpml.transit.preferences.enabled", "true" );
+
+ //
+ //
+
+ SwingUtilities.invokeLater(
+ new Runnable() {
+ public void run()
+ {
+ setup();
+ }
+ } );
+ }
+
+ private static void setup()
+ {
+ try
+ {
+ new TransitDialog();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Constructor (disabled).
+ */
+ private Main()
+ {
+ // disabled
+ }
+}
+

Added:
development/main/depot/station/src/main/net/dpml/depot/station/NodeTableModel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/NodeTableModel.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2005 Stephen 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.station;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeEvent;
+import java.util.Arrays;
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.prefs.Preferences;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.NodeChangeEvent;
+
+import java.net.URL;
+
+import javax.swing.table.AbstractTableModel;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.host.ResourceHost;
+
+/**
+ * Table model used to manage features of an adapter.
+ */
+class NodeTableModel extends AbstractTableModel implements NodeChangeListener
+{
+
//--------------------------------------------------------------------------
+ // static
+
//--------------------------------------------------------------------------
+
+ /**
+ * Default small icon path.
+ */
+ private static final String ICON_PATH =
"net/dpml/transit/images/item.gif";
+
+ /**
+ * Constant row identifier for the icon.
+ */
+ public static final int ICON = 0;
+
+ /**
+ * Constant row identifier for the name.
+ */
+ public static final int VALUE = 1;
+
+ /**
+ * Number of columns.
+ */
+ private static final int COLUMN_COUNT = 2;
+
+ /**
+ * Default small icon.
+ */
+ private static final Icon FEATURE_ICON =
+ IconHelper.createImageIcon( Transit.class.getClassLoader(), ICON_PATH,
"Features" );
+
+ private final Preferences m_preferences;
+
+
//--------------------------------------------------------------------------
+ // constructor
+
//--------------------------------------------------------------------------
+
+ /**
+ * Creation of a new feature table model.
+ * @param entity the reference entity
+ */
+ public NodeTableModel( Preferences prefs )
+ {
+ super();
+ m_preferences = prefs;
+ prefs.addNodeChangeListener( this );
+ }
+
+
//--------------------------------------------------------------------------
+ // NodeChangeListener
+
//--------------------------------------------------------------------------
+
+ /**
+ * Handle the addition of a host following a preferences node change.
+ *
+ * @param event the node addition event
+ */
+ public void childAdded( NodeChangeEvent event )
+ {
+ fireTableStructureChanged();
+ }
+
+ public void childRemoved( NodeChangeEvent event )
+ {
+ fireTableStructureChanged();
+ }
+
+
//--------------------------------------------------------------------------
+ // NodeTableModel
+
//--------------------------------------------------------------------------
+
+ /**
+ * Returns the number of model columns.
+ * @return int the number of columns maintained by the model
+ */
+ public int getColumnCount()
+ {
+ return COLUMN_COUNT;
+ }
+
+ /**
+ * Returns the number of rows in the model. The value returned is
+ * equivilent to the number of elements in the list backing the model.
+ * @return int the number of rows maintained by the model
+ */
+ public int getRowCount()
+ {
+ try
+ {
+ return getPreferences().childrenNames().length;
+ }
+ catch( Throwable e )
+ {
+ return 0;
+ }
+ }
+
+ /**
+ * Returns the feature object at the request column and row combination.
+ * If the col index is out of range the method returns the agent
corresponding
+ * to the row identifier.
+ * @param row the row index
+ * @param col the column index
+ * @return Object
+ */
+ public Object getValueAt( int row, int col )
+ {
+ Object result = "";
+ if( row > getRowCount() )
+ {
+ return result;
+ }
+
+ switch( col )
+ {
+ case ICON :
+ return FEATURE_ICON;
+ default:
+ return getHostAtRow( row );
+ }
+ }
+
+ private String getHostAtRow( int row )
+ {
+ try
+ {
+ String[] names = getPreferences().childrenNames();
+ return names[ row ];
+ }
+ catch( Throwable e )
+ {
+ return "";
+ }
+ }
+
+ Preferences getPreferences()
+ {
+ return m_preferences;
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/ResourcePanel.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/ResourcePanel.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,412 @@
+/*
+ * Copyright 2004 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.station;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.awt.FlowLayout;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Insets;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.prefs.Preferences;
+
+import javax.swing.Action;
+import javax.swing.AbstractAction;
+import javax.swing.BoxLayout;
+import javax.swing.JDialog;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import javax.swing.ListSelectionModel;
+import javax.swing.JOptionPane;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.TitledBorder;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;
+import net.dpml.transit.cache.CacheHandler;
+import net.dpml.transit.host.ResourceHost;
+import net.dpml.transit.util.Util;
+
+
+
+/**
+ * Runnable plugin that handles DPML environment setup.
+ *
+ * @author <a href="mailto:mcconnell AT osm.net";>OSM</a>
+ */
+public class ResourcePanel extends JPanel implements ListSelectionListener
+{
+ //--------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------
+
+ static EmptyBorder border5 = new EmptyBorder( 5, 5, 5, 5);
+
+ //--------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------
+
+ private final JDialog m_parent;
+
+ private GenericTable m_table;
+
+ private JButton m_edit;
+ private JButton m_delete;
+
+ private String m_hostName; // selected hostname
+
+ //--------------------------------------------------------------
+ // constructor
+ //--------------------------------------------------------------
+
+ public ResourcePanel( JDialog parent ) throws Exception
+ {
+ m_parent = parent;
+
+ m_edit = new JButton( new EditAction( "Edit" ) );
+ m_delete = new JButton( new DeleteAction( "Delete" ) );
+
+ setLayout( new BorderLayout() );
+ setBorder( new EmptyBorder( 10, 6, 10, 6 ) );
+ setBackground( Color.white );
+
+ JPanel hostPanel = new JPanel();
+ hostPanel.setBackground( Color.white );
+
+ hostPanel.setLayout( new BorderLayout() );
+ TitledBorder tb =
+ new TitledBorder(
+ new EmptyBorder( 0,0,0,0 ), "Resource Hosts", TitledBorder.LEFT,
TitledBorder.TOP );
+ hostPanel.setBorder( new CompoundBorder( tb, border5 ) );
+
+ Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
+ TableColumnModel columns = createHostsColumnModel();
+ NodeTableModel model = new NodeTableModel( hosts );
+ m_table = new GenericTable( model, columns );
+ m_table.setShowVerticalLines( false );
+ m_table.setShowHorizontalLines( false );
+ m_table.getSelectionModel().addListSelectionListener( this );
+
+ JScrollPane scroller = createScrollPanel( m_table );
+ hostPanel.add( scroller, BorderLayout.CENTER );
+ JPanel buttonHolder = new JPanel();
+ buttonHolder.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
+ buttonHolder.add( new JButton( new AddAction( "Add" ) ) );
+ buttonHolder.add( m_edit );
+ buttonHolder.add( m_delete );
+ buttonHolder.setBorder( new EmptyBorder( 10, 10, 5, 0 ) );
+ buttonHolder.setBackground( Color.white );
+ hostPanel.add( buttonHolder, BorderLayout.SOUTH );
+
+ JPanel cachePanel = createCachePanel( parent );
+
+ add( cachePanel, BorderLayout.NORTH );
+ add( hostPanel, BorderLayout.CENTER );
+ }
+
+ private JPanel createCachePanel( JDialog parent )
+ {
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ ResourcePanel.class.getClassLoader(),
+ "net/dpml/transit/images/cache.jpg",
+ "Properties",
+ "Cache handler properties and settings." );
+ label.setBorder( new EmptyBorder( 0, 5, 0, 0 ) );
+
+ JPanel holder = new JPanel();
+ holder.setLayout( new BoxLayout( holder, BoxLayout.Y_AXIS ) );
+ holder.setBorder( new EmptyBorder( 0, 6, 0, 6 ) );
+ holder.setBackground( Color.white );
+ JPanel cache = new JPanel();
+ cache.setBackground( Color.white );
+ cache.setLayout( new BorderLayout() );
+ cache.add( label, BorderLayout.WEST );
+ cache.setBorder(
+ new CompoundBorder(
+ new TitledBorder( null, "Cache", TitledBorder.LEFT,
TitledBorder.TOP), border5 ) );
+ JButton button = new JButton( new CacheAction( parent, "Cache" ) );
+ JPanel cacheButtonHolder = new JPanel();
+ cacheButtonHolder.setBackground( Color.white );
+ cacheButtonHolder.setLayout( new BorderLayout() );
+ cacheButtonHolder.add( button, BorderLayout.SOUTH );
+ cache.add( cacheButtonHolder, BorderLayout.EAST );
+ holder.add( cache );
+ return holder;
+ }
+
+ private static class CacheAction extends AbstractAction
+ {
+ JDialog m_parent;
+
+ CacheAction( JDialog parent, String name )
+ {
+ super( name );
+ m_parent = parent;
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Cache" );
+ Dimension size = new Dimension( 400, 160 );
+
+ JPanel frame = new JPanel();
+ frame.setLayout( new BorderLayout() );
+ frame.setBackground( Color.white );
+ frame.setBorder( new EmptyBorder( 10, 6, 0, 6 ) );
+
+ JPanel panel = new CachePanel( dialog );
+ frame.add( panel, BorderLayout.CENTER );
+ dialog.setContentPane( frame );
+ dialog.setSize( size );
+ dialog.setLocationRelativeTo( (Component) event.getSource()
);
+ dialog.setResizable( true );
+ dialog.setVisible(true);
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to handle the 'Cache'
action. "
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ 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();
+ }
+ }
+ }
+
+ //--------------------------------------------------------------
+ // utilities
+ //--------------------------------------------------------------
+
+ private static JPanel createLabel( String name )
+ {
+ JLabel label = new JLabel( name );
+ label.setBorder( new EmptyBorder( 10, 10, 10, 10 ) );
+ JPanel panel = new JPanel( new FlowLayout( FlowLayout.LEFT ) );
+ panel.add( label );
+ return panel;
+ }
+
+ /**
+ * Creation of a parameterized scroll pane.
+ * @param view the viewport view
+ * @return the scroll pane wrapping the supplied view
+ */
+ private static JScrollPane createScrollPanel( Component view )
+ {
+ JScrollPane scroller = new JScrollPane();
+ scroller.setVerticalScrollBarPolicy(
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
+ scroller.setHorizontalScrollBarPolicy(
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
+ scroller.getViewport().setBackground( Color.white );
+ scroller.setViewportView( view );
+ return scroller;
+ }
+
+ /**
+ * Utility method to construct the hosts table column model.
+ * @return the table
+ */
+ private static TableColumnModel createHostsColumnModel()
+ {
+ TableColumn iconColumn = new TableColumn( 0, 30, new
DefaultCellRenderer(), null );
+ iconColumn.setHeaderValue("");
+ iconColumn.setMaxWidth( 30 );
+ iconColumn.setMinWidth( 30 );
+ TableColumn hostColumn = new TableColumn( 1, 100, new
DefaultCellRenderer(), null );
+ hostColumn.setHeaderValue("Host");
+ TableColumnModel columnModel = new DefaultTableColumnModel();
+ columnModel.addColumn( iconColumn );
+ columnModel.addColumn( hostColumn );
+ return columnModel;
+ }
+
+ private class AddAction extends AbstractAction
+ {
+ public AddAction( String name )
+ {
+ super( name );
+ setEnabled( true );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ // TODO: create a dialog that collects the host name and the
base url
+ // and use this to create a new host entry then lauch the host
edit
+ // dialog box. The following is just a placeholder that does
nothing
+ // useful.
+
+ String name = JOptionPane.showInputDialog( m_parent, "Host
name:" );
+ if( null == name )
+ {
+ return;
+ }
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Host: " + name );
+ JPanel panel = new HostPanel( dialog, name );
+ 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 )
+ {
+ final String error =
+ "Unexpected error while attempting to construct host
dialog."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ }
+ }
+
+ private class EditAction extends AbstractAction
+ {
+ public EditAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ try
+ {
+ JDialog dialog = new JDialog( m_parent, true );
+ dialog.setTitle( "Resource Host: " + m_hostName );
+ JPanel panel = new HostPanel( dialog, m_hostName );
+ 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 )
+ {
+ final String error =
+ "Unexpected error while attempting to construct host
dialog."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ }
+ }
+
+ private class DeleteAction extends AbstractAction
+ {
+ public DeleteAction( String name )
+ {
+ super( name );
+ setEnabled( false );
+ }
+
+ public void actionPerformed( ActionEvent event )
+ {
+ if( null == m_hostName )
+ {
+ return;
+ }
+ Preferences hosts = Preferences.userNodeForPackage(
ResourceHost.class );
+ Preferences target = hosts.node( m_hostName );
+ try
+ {
+ target.removeNode();
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while attempting to delete a host
preferences node."
+ + "\nCODEBASE: "
+ +
ResourcePanel.class.getProtectionDomain().getCodeSource().getLocation().toString();
+ String message = ExceptionHelper.packException( error, e,
true );
+ System.out.println( message );
+ }
+ }
+ }
+
+ public void valueChanged( ListSelectionEvent event )
+ {
+ if( !event.getValueIsAdjusting() )
+ {
+ ListSelectionModel model = m_table.getSelectionModel();
+ synchronized( model )
+ {
+ int n = model.getMinSelectionIndex();
+ if( ( n == model.getMaxSelectionIndex() ) && ( n > -1 ) )
+ {
+ m_hostName = (String) m_table.getValueAt( n, 1 );
+ m_edit.setEnabled( true );
+ m_delete.setEnabled( true );
+ }
+ else
+ {
+ m_hostName = null;
+ m_edit.setEnabled( false );
+ m_delete.setEnabled( false );
+ }
+ }
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/TransitDialog.java
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/TransitDialog.java
Wed May 11 09:31:43 2005
@@ -0,0 +1,268 @@
+/*
+ * 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.station;
+
+import java.net.URL;
+
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.Dimension;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.ActionListener;
+import java.awt.Font;
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Map;
+
+import java.util.prefs.Preferences;
+
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.UIManager;
+import javax.swing.border.EmptyBorder;
+import javax.swing.AbstractAction;
+import javax.swing.JDialog;
+import javax.swing.JButton;
+import javax.swing.Action;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.BoxLayout;
+import javax.swing.Box;
+import javax.swing.ImageIcon;
+import javax.swing.SwingUtilities;
+
+import net.dpml.transit.Transit;
+
+/**
+ */
+public class TransitDialog extends JDialog
+{
+ /**
+ * The DPML icon.
+ */
+ private static String DPML_ICON_FILENAME =
"net/dpml/transit/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;
+
+ private List m_listeners = new LinkedList();
+
+ public TransitDialog() throws Exception
+ {
+ super();
+
+ String classname = UIManager.getSystemLookAndFeelClassName();
+ UIManager.setLookAndFeel( classname );
+
+ setTitle( "DPML Transit" );
+ Dimension size = new Dimension( DEFAULT_DIALOG_WIDTH,
DEFAULT_DIALOG_HEIGHT );
+ setSize( size );
+
+ JLabel label =
+ IconHelper.createImageIconJLabel(
+ Transit.class.getClassLoader(), DPML_ICON_FILENAME, "", "DPML
Transit" );
+ 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();
+
+ ResourcePanel transitPanel = new ResourcePanel( this );
+ ContentHandlerPanel contentPanel = new ContentHandlerPanel( this );
+ tabbedPane.addTab( "Resources", transitPanel );
+ tabbedPane.addTab( "Content", contentPanel );
+ tabbedPane.addTab( "Logging", new JPanel() );
+ tabbedPane.addTab( "Properties", 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() );
+
+ addWindowListener(
+ new WindowAdapter()
+ {
+ public void windowClosing(WindowEvent e)
+ {
+ System.exit(0);
+ }
+ }
+ );
+
+ 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;
+ }
+ }
+
+ /**
+ * Creation of a panel containing a section in which a name banner is
presented.
+ * @param name the name to assign
+ * @param view the properties content view
+ * @return the panel containing a name header and property content view
+ */
+ private static JPanel createNamedPanel( final String name, Component
view )
+ {
+ JPanel panel = createNamedPanel( name );
+ JPanel holder = new JPanel( new BorderLayout() );
+ holder.add( view, BorderLayout.CENTER );
+ panel.add( holder );
+ return panel;
+ }
+
+ /**
+ * Create the panel holding a name.
+ * @param name the name to assign
+ * @return the panel containing the name as a label
+ */
+ private static JPanel createNamedPanel( final String name )
+ {
+ JPanel panel = new JPanel();
+ panel.setLayout( new BorderLayout() );
+
+ //
+ // Create the header holding the panel name
+ //
+
+ JLabel label = new JLabel( name );
+ label.setBackground( Color.white );
+ label.setBorder( new EmptyBorder( 5, OFFSET, 5, OFFSET ) );
+ JPanel labelHolder = new JPanel( new FlowLayout( FlowLayout.LEFT ) );
+ labelHolder.add( label );
+ labelHolder.setBackground( Color.white );
+ panel.add( labelHolder, BorderLayout.NORTH );
+
+ return panel;
+ }
+
+ 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 TransitDialog();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+}

Added:
development/main/depot/station/src/main/net/dpml/depot/station/package.html
==============================================================================
--- (empty file)
+++
development/main/depot/station/src/main/net/dpml/depot/station/package.html
Wed May 11 09:31:43 2005
@@ -0,0 +1,8 @@
+
+<body>
+<p>
+The prefs package contains a set of classes dealing with interactive
+management of Transit cache and host preferences.
+</p>
+</body>
+



  • svn commit: r2508 - in development/main/depot: . cli content content/src/main/net/dpml/depot/content station station/src/main/net/dpml/depot/prefs station/src/main/net/dpml/depot/station station/src/main/net/dpml/depot/station/prefs, mcconnell, 05/11/2005

Archive powered by MHonArc 2.6.24.

Top of Page