avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pro...@apache.org
Subject cvs commit: jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels ButtonFactory.java ContextNavigationPanel.java EventContextualizable.java LogEnabledJPanel.java MBeanPanel.java AbstractContentPanel.java AbstractMBeanPanel.java ApplicationPanel.java HomePanel.java ModifyConfigurationPanel.java
Date Wed, 31 Jul 2002 20:43:04 GMT
proyal      2002/07/31 13:43:04

  Added:       phyre/src/java/org/apache/avalon/phyre/panels
                        ButtonFactory.java ContextNavigationPanel.java
                        EventContextualizable.java LogEnabledJPanel.java
                        MBeanPanel.java
  Removed:     phyre/src/java/org/apache/avalon/phyre/panels
                        AbstractContentPanel.java AbstractMBeanPanel.java
                        ApplicationPanel.java HomePanel.java
                        ModifyConfigurationPanel.java
  Log:
  * Removed old custom panels.
  * Added configurable nav panel
  * Added base class for LogEnabled'd panels
  * Added configurable MBean panel
  * Interface for panels that receive a context when loaded
  * Factory for panel buttons
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/ButtonFactory.java
  
  Index: ButtonFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.panels;
  
  import java.awt.Color;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JOptionPane;
  
  import org.apache.avalon.excalibur.property.PropertyException;
  import org.apache.avalon.excalibur.property.PropertyUtil;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.phyre.actions.Action;
  import org.apache.avalon.phyre.actions.ActionFactory;
  import org.apache.avalon.phyre.actions.listeners.ActionActionListener;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class ButtonFactory
  {
      public static JButton createButton( final ActionFactory actionFactory,
                                          final Context context,
                                          final Configuration c )
          throws ConfigurationException
      {
          final Configuration action = c.getChild( "action", false );
          String caption;
  
          try
          {
              caption = ( String ) PropertyUtil.resolveProperty( c.getChild( "caption" ).getValue(),
                                                                 context,
                                                                 false );
          }
          catch( PropertyException e )
          {
              throw new ConfigurationException( "Invalid property expansion in caption", e
);
          }
  
          if( null == action )
          {
              final JButton button = new JButton( caption );
  
              button.setForeground( Color.red );
              button.addActionListener( new ActionListener()
              {
                  public void actionPerformed( ActionEvent e )
                  {
                      JOptionPane.showMessageDialog( button,
                                                     "not implemented yet",
                                                     "Phyre",
                                                     JOptionPane.INFORMATION_MESSAGE,
                                                     null );
  
                  }
              } );
  
              return button;
          }
          else
          {
              final JButton button = new JButton( caption );
              final Action a = actionFactory.create( action.getAttribute( "type" ), action
);
  
              button.addActionListener( new ActionActionListener( a ) );
  
              return button;
          }
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/ContextNavigationPanel.java
  
  Index: ContextNavigationPanel.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.panels;
  
  import java.awt.BorderLayout;
  import java.awt.Component;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  import org.apache.avalon.excalibur.property.PropertyException;
  import org.apache.avalon.excalibur.property.PropertyUtil;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.phyre.actions.ActionFactory;
  import org.apache.avalon.phyre.container.NavigationPanelHelper;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class ContextNavigationPanel extends LogEnabledJPanel
      implements Configurable, Serviceable, NavigationPanelHelper, Contextualizable
  {
      private ActionFactory m_listenerFactory;
      private Component m_panel;
      private JPanel m_buttonPanel;
      private Context m_context;
  
      public ContextNavigationPanel()
      {
          super( new BorderLayout() );
      }
  
      public void contextualize( Context context )
          throws ContextException
      {
          m_context = context;
      }
  
      public void service( ServiceManager manager )
          throws ServiceException
      {
          m_listenerFactory = ( ActionFactory ) manager.lookup( ActionFactory.ROLE );
      }
  
      public void configure( Configuration configuration )
          throws ConfigurationException
      {
          final Configuration[] buttons = configuration.getChild( "navigation" ).getChildren();
          final JButton contextButton =
              ButtonFactory.createButton( m_listenerFactory,
                                          m_context,
                                          configuration.getChild( "context" ) );
  
          contextButton.addActionListener( new ActionListener()
          {
              public void actionPerformed( ActionEvent e )
              {
                  if( ActionEvent.ACTION_PERFORMED == e.getID() )
                  {
                      setNavigationPanel( m_buttonPanel );
                  }
              }
          } );
  
          add( contextButton, BorderLayout.NORTH );
  
          m_buttonPanel = new JPanel( new GridLayout( 0, 1 ) );
  
          for( int i = 0; i < buttons.length; i++ )
          {
              final String name = buttons[i].getName();
  
              if( "label".equals( name ) )
              {
  
                  try
                  {
                      final String caption = ( String ) PropertyUtil.resolveProperty(
                          buttons[i].getValue(),
                          m_context,
                          false );
  
                      m_buttonPanel.add( new JLabel( caption ) );
                  }
                  catch( PropertyException e )
                  {
                      throw new ConfigurationException( "Invalid property expansion in caption",
e );
                  }
              }
              else if( "button".equals( name ) )
              {
                  m_buttonPanel.add( ButtonFactory.createButton( m_listenerFactory, m_context,
buttons[i] ) );
              }
              else
              {
                  throw new ConfigurationException( "Unknown button type: " + name
                                                    + ", loc: " + buttons[i].getLocation()
);
              }
          }
  
          setNavigationPanel( m_buttonPanel );
      }
  
      public void setNavigationPanel( Component panel )
      {
          if( m_panel != null )
          {
              remove( m_panel );
          }
  
          add( panel, BorderLayout.CENTER );
          panel.validate();
          validate();
  
          m_panel = panel;
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/EventContextualizable.java
  
  Index: EventContextualizable.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.panels;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  
  /**
   * Interface for panels that are able to receive a context relating to the event
   * that may have spawned them
   *
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public interface EventContextualizable
  {
      void eventContext( final Context context ) throws ContextException;
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/LogEnabledJPanel.java
  
  Index: LogEnabledJPanel.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.panels;
  
  import java.awt.LayoutManager;
  import javax.swing.JPanel;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class LogEnabledJPanel extends JPanel implements LogEnabled
  {
      private Logger m_logger;
  
      public LogEnabledJPanel( LayoutManager layout )
      {
          super( layout );
      }
  
      public void enableLogging( final Logger logger )
      {
          m_logger = logger;
      }
  
      protected final Logger getLogger()
      {
          return m_logger;
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/phyre/src/java/org/apache/avalon/phyre/panels/MBeanPanel.java
  
  Index: MBeanPanel.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phyre.panels;
  
  import java.awt.BorderLayout;
  import java.awt.GridLayout;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanInfo;
  import javax.swing.JButton;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  import org.apache.avalon.excalibur.property.PropertyException;
  import org.apache.avalon.excalibur.property.PropertyUtil;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.phyre.actions.MBeanInvokeAction;
  import org.apache.avalon.phyre.actions.listeners.ActionActionListener;
  import org.apache.avalon.phyre.mbean.MBeanAccessor;
  
  /**
   * A panel that will show attributes from an MBean and optionally display buttons to invoke
   * no-arg operations.
   *
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   */
  public class MBeanPanel extends LogEnabledJPanel
      implements Configurable, Serviceable, Initializable, Contextualizable
  {
      private ServiceManager m_manager;
      private MBeanAccessor m_MBean;
      private Context m_context;
  
      private String m_objectName;
      private Configuration[] m_attributes;
      private Configuration[] m_operations;
  
      public MBeanPanel()
      {
          super( new BorderLayout() );
      }
  
      public void contextualize( Context context )
          throws ContextException
      {
          m_context = context;
      }
  
      public void service( ServiceManager manager )
          throws ServiceException
      {
          m_manager = manager;
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          m_objectName = configuration.getChild( "object-name" ).getValue();
          m_attributes = configuration.getChildren( "attribute" );
          m_operations = configuration.getChildren( "operation" );
      }
  
      public void initialize()
          throws Exception
      {
          final JPanel panel = new JPanel( new GridLayout( 0, 2 ) );
  
          final String objectName =
              ( String ) PropertyUtil.resolveProperty( m_objectName, m_context, false );
  
          m_MBean = ( MBeanAccessor ) m_manager.lookup( objectName );
  
          addAttributes( panel );
          add( panel, BorderLayout.CENTER );
  
          if( m_operations.length != 0 )
          {
              final JPanel opPanel = new JPanel();
  
              addOperations( opPanel );
              add( opPanel, BorderLayout.SOUTH );
          }
      }
  
      private void addAttributes( JPanel panel ) throws Exception
      {
          final MBeanInfo info = m_MBean.info();
          final MBeanAttributeInfo[] attributeInfos = info.getAttributes();
  
          if( m_attributes.length == 0 )
          {
              for( int i = 0; i < attributeInfos.length; i++ )
              {
                  addAttribute( panel,
                                attributeInfos[i].getName(),
                                attributeInfos[i].getDescription() );
              }
          }
          else
          {
              for( int i = 0; i < m_attributes.length; i++ )
              {
                  final String name = m_attributes[i].getAttribute( "name" );
                  final String description = getDescription( name, attributeInfos );
  
                  if( null == description )
                  {
                      throw new ConfigurationException( "Invalid MBean attribute: " + name
                                                        + ", loc: " + m_attributes[i].getLocation()
);
                  }
                  else
                  {
                      addAttribute( panel, name, description );
                  }
              }
          }
      }
  
      private void addAttribute( final JPanel panel, final String name, final String description
)
          throws Exception
      {
          final Object o = m_MBean.get( name );
  
          panel.add( new JLabel( description ) );
          panel.add( new JLabel( o == null ? "" :  o.toString() ) );
      }
  
      private String getDescription( final String name, final MBeanAttributeInfo[] infos )
      {
          for( int i = 0; i < infos.length; i++ )
          {
              if( name.equals( infos[i].getName() ) )
              {
                  return infos[i].getDescription();
              }
          }
  
          return null;
      }
  
      private void addOperations( final JPanel panel )
          throws ConfigurationException, PropertyException
      {
          for( int i = 0; i < m_operations.length; i++ )
          {
              final String caption =
                  ( String ) PropertyUtil.resolveProperty(
                      m_operations[i].getChild( "caption" ).getValue(),
                      m_context,
                      false );
  
              final JButton button = new JButton( caption );
  
              button.addActionListener(
                  new ActionActionListener(
                      new MBeanInvokeAction( m_operations[i].getAttribute( "name" ), m_MBean
) ) );
  
              panel.add( button );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message