avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client InstrumentClientFrame.java InstrumentSampleFrame.java MenuBar.java
Date Mon, 05 Aug 2002 02:15:44 GMT
leif        2002/08/04 19:15:44

  Modified:    instrument/src/client/org/apache/excalibur/instrument/client
                        InstrumentClientFrame.java
                        InstrumentSampleFrame.java MenuBar.java
  Log:
  Fix a problem where child instrumentables could not be accessed from the
  menu bar.
  
  Revision  Changes    Path
  1.2       +4 -8      jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client/InstrumentClientFrame.java
  
  Index: InstrumentClientFrame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client/InstrumentClientFrame.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InstrumentClientFrame.java	29 Jul 2002 16:05:19 -0000	1.1
  +++ InstrumentClientFrame.java	5 Aug 2002 02:15:44 -0000	1.2
  @@ -320,15 +320,13 @@
       }
   
       void openInstrumentSampleFrame( final InstrumentManagerConnection connection,
  -                                    final InstrumentableDescriptor instrumentableDescriptor,
  -                                    final InstrumentDescriptor instrumentDescriptor,
  -                                    final InstrumentSampleDescriptor instrumentSampleDescriptor
)
  +                                    final InstrumentSampleDescriptor sampleDescriptor )
       {
           SwingUtilities.invokeLater( new Runnable()
           {
               public void run()
               {
  -                String sampleName = instrumentSampleDescriptor.getName();
  +                String sampleName = sampleDescriptor.getName();
                   InstrumentSampleFrame frame = new InstrumentSampleFrame( connection,
                       sampleName, InstrumentClientFrame.this );
   
  @@ -397,7 +395,6 @@
        * Instrument-CreateSample callback.
        */
       void instrumentCreateSample( final InstrumentManagerConnection connection,
  -                                 final InstrumentableDescriptor instrumentableDescriptor,
                                    final InstrumentDescriptor instrumentDescriptor )
       {
           SwingUtilities.invokeLater( new Runnable()
  @@ -429,8 +426,7 @@
                               dialog.getSampleType() );
   
                       // Show a frame for the new sample
  -                    openInstrumentSampleFrame( connection, instrumentableDescriptor,
  -                        instrumentDescriptor, sampleDescriptor );
  +                    openInstrumentSampleFrame( connection, sampleDescriptor );
                   }
               }
           } );
  
  
  
  1.2       +106 -65   jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client/InstrumentSampleFrame.java
  
  Index: InstrumentSampleFrame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client/InstrumentSampleFrame.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InstrumentSampleFrame.java	29 Jul 2002 16:05:19 -0000	1.1
  +++ InstrumentSampleFrame.java	5 Aug 2002 02:15:44 -0000	1.2
  @@ -41,8 +41,8 @@
       public static final String FRAME_TYPE = "sample-frame";
   
       private InstrumentManagerConnection m_connection;
  -    private InstrumentableDescriptor m_instrumentableDescriptor;
  -    private InstrumentDescriptor m_instrumentDescriptor;
  +    //private InstrumentableDescriptor m_instrumentableDescriptor;
  +    //private InstrumentDescriptor m_instrumentDescriptor;
       private InstrumentSampleDescriptor m_instrumentSampleDescriptor;
       private String m_instrumentSampleName;
       private LineChart m_lineChart;
  @@ -155,29 +155,109 @@
        * Methods
        *-------------------------------------------------------------*/
       /**
  -     * Sets the title of the frame.
  +     * Sets the title of the frame and obtains a reference to the
  +     *  InstrumentSampleDescriptor in the process.  The title is made up of the
  +     *  descriptions of all the elements up to the sample in reverse order.
        * <p>
        * Only called when synchronized.
        */
  -    private void setTitle()
  +    private void setTitleAndFindSample()
       {
  -        String title;
  +        // Initialize the sample reference.
  +        m_instrumentSampleDescriptor = null;
  +        
           InstrumentManagerClient manager = m_connection.getInstrumentManagerClient();
  -        if ( manager == null )
  +        StringBuffer sb = new StringBuffer( m_connection.getTitle() );
  +        sb.insert( 0, " / " );
  +        
  +        try
           {
  -            title = m_connection.getTitle() + " : " + m_instrumentSampleName;
  +            if ( manager == null )
  +            {
  +                sb.insert( 0, m_instrumentSampleName );
  +            }
  +            else
  +            {
  +                // Look for the root Instrumentable from the Instrument Manager.
  +                InstrumentableDescriptor instrumentable;
  +                try
  +                {
  +                    instrumentable =
  +                        manager.getInstrumentableDescriptor( m_instrumentSampleName );
  +                    sb.insert( 0, instrumentable.getDescription() );
  +                }
  +                catch ( NoSuchInstrumentableException e )
  +                {
  +                    sb.insert( 0, "Instrumentable Not found (" + m_instrumentSampleName
+ ")" );
  +                    instrumentable = null;
  +                }
  +                sb.insert( 0, " / " );
  +                
  +                if ( instrumentable != null )
  +                {
  +                    boolean foundChild = true;
  +                    while ( foundChild )
  +                    {
  +                        // There may be a child Instrumentable that contains the sample.
  +                        try
  +                        {
  +                            InstrumentableDescriptor childInstrumentable =
  +                                instrumentable.getChildInstrumentableDescriptor(
  +                                m_instrumentSampleName );
  +                            instrumentable = childInstrumentable;
  +                            sb.insert( 0, instrumentable.getDescription() );
  +                            sb.insert( 0, " / " );
  +                        }
  +                        catch ( NoSuchInstrumentableException e )
  +                        {
  +                            foundChild = false;
  +                        }
  +                    }
  +                    
  +                    // Now get the Instrument 
  +                    InstrumentDescriptor instrument;
  +                    try
  +                    {
  +                        instrument =
  +                            instrumentable.getInstrumentDescriptor( m_instrumentSampleName
);
  +                        sb.insert( 0, instrument.getDescription() );
  +                    }
  +                    catch ( NoSuchInstrumentException e )
  +                    {
  +                        sb.insert( 0, "Instrument Not found (" + m_instrumentSampleName
+ ")" );
  +                        instrument = null;
  +                    }
  +                    sb.insert( 0, " / " );
  +                    
  +                    if ( instrument != null )
  +                    {
  +                        // Now get the InstrumentSample
  +                        InstrumentSampleDescriptor sample;
  +                        try
  +                        {
  +                            sample =
  +                                instrument.getInstrumentSampleDescriptor( m_instrumentSampleName
);
  +                            sb.insert( 0, sample.getDescription() );
  +                        }
  +                        catch ( NoSuchInstrumentSampleException e )
  +                        {
  +                            sb.insert( 0, "Sample Not found (" + m_instrumentSampleName
+ ")" );
  +                            sample = null;
  +                        }
  +                        m_instrumentSampleDescriptor = sample;
  +                    }
  +                }
  +            }
           }
  -        else
  +        catch ( AltrmiInvocationException e )
           {
  -            title = m_connection.getTitle() + " : " +
  -                m_instrumentableDescriptor.getDescription() + " : " +
  -                m_instrumentDescriptor.getDescription() + " : " +
  -                m_instrumentSampleDescriptor.getDescription();
  +            // Connection to the InstrumentManager failed.
  +            sb.insert( 0, e.getMessage() );
           }
   
  -        setTitle( title );
  +        setTitle( sb.toString() );
       }
  -
  +    
       private void init()
       {
           synchronized (this)
  @@ -185,62 +265,26 @@
               // Clean out the content pane
               getContentPane().removeAll();
   
  -            InstrumentManagerClient manager = m_connection.getInstrumentManagerClient();
  -            if ( manager == null )
  +            // Set the title and locate the InstrumentSampleDescriptor
  +            setTitleAndFindSample();
  +
  +            InstrumentSampleDescriptor sample = m_instrumentSampleDescriptor;
  +            if ( sample == null )
               {
                   // Not connected.
  -                m_instrumentableDescriptor = null;
  -                m_instrumentDescriptor = null;
  -                m_instrumentSampleDescriptor = null;
  -
                   JLabel label = new JLabel( "Not Connected" );
                   label.setForeground( Color.red );
                   label.setHorizontalAlignment( SwingConstants.CENTER );
                   label.setVerticalAlignment( SwingConstants.CENTER );
  -
  +                
                   getContentPane().add( label );
               }
               else
               {
                   try
                   {
  -                    // Look up the descriptors.
  -                    try
  -                    {
  -                        m_instrumentableDescriptor =
  -                            manager.getInstrumentableDescriptor( m_instrumentSampleName
);
  -                    }
  -                    catch ( NoSuchInstrumentableException e )
  -                    {
  -                        // Frame no longer valid.
  -                        hideFrame();
  -                        return;
  -                    }
  -                    try
  -                    {
  -                        m_instrumentDescriptor = m_instrumentableDescriptor.
  -                            getInstrumentDescriptor( m_instrumentSampleName );
  -                    }
  -                    catch ( NoSuchInstrumentException e )
  -                    {
  -                        // Frame no longer valid.
  -                        hideFrame();
  -                        return;
  -                    }
  -                    try
  -                    {
  -                        m_instrumentSampleDescriptor = m_instrumentDescriptor.
  -                            getInstrumentSampleDescriptor( m_instrumentSampleName );
  -                    }
  -                    catch ( NoSuchInstrumentSampleException e )
  -                    {
  -                        // Frame no longer valid.
  -                        hideFrame();
  -                        return;
  -                    }
  -
                       // Decide on a line interval based on the interval of the sample.
  -                    long interval = m_instrumentSampleDescriptor.getInterval();
  +                    long interval = sample.getInterval();
                       int hInterval;
                       String format;
                       String detailFormat;
  @@ -286,10 +330,10 @@
                           format = "{0}/{1} {2}:{3}";
                           detailFormat = "{0}/{1} {2}:{3}";
                       }
  -
  -                    m_lineChart = new LineChart( hInterval,
  -                        m_instrumentSampleDescriptor.getInterval(), format, detailFormat,
20 );
  -
  +            
  +                    m_lineChart = new LineChart( hInterval, sample.getInterval(),
  +                        format, detailFormat, 20 );
  +            
                       getContentPane().add( m_lineChart );
                   }
                   catch ( AltrmiInvocationException e )
  @@ -298,9 +342,6 @@
                       m_connection.close();
                   }
               }
  -
  -            // Set the title last so that the descriptors can be reloaded if necessary.
  -            setTitle();
           }
   
           update();
  
  
  
  1.2       +62 -14    jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client/MenuBar.java
  
  Index: MenuBar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument/src/client/org/apache/excalibur/instrument/client/MenuBar.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MenuBar.java	29 Jul 2002 16:05:19 -0000	1.1
  +++ MenuBar.java	5 Aug 2002 02:15:44 -0000	1.2
  @@ -48,7 +48,7 @@
   
       private JMenu m_menuWindow;
   
  -    private boolean m_showUnconfigured;
  +    private boolean m_showUnconfigured = true;
   
       /*---------------------------------------------------------------
        * Constructors
  @@ -362,6 +362,66 @@
   
           try
           {
  +            InstrumentableDescriptor[] descriptors =
  +                instrumentableDescriptor.getChildInstrumentableDescriptors();
  +
  +            for( int i = 0; i < descriptors.length; i++ )
  +            {
  +                InstrumentableDescriptor descriptor = descriptors[ i ];
  +
  +                if( showAll || descriptor.isConfigured() )
  +                {
  +                    String description = descriptor.getDescription();
  +
  +                    Action action = new AbstractAction( description )
  +                    {
  +                        public void actionPerformed( ActionEvent event )
  +                        {
  +                        }
  +                    };
  +                    action.putValue( "InstrumentManagerConnection", connection );
  +                    action.putValue( "InstrumentableDescriptor", descriptor );
  +
  +                    JMenu menu = new LargeMenu( action );
  +
  +                    // Set up a Listener to handle the selected event.
  +                    menu.addMenuListener( new MenuListener()
  +                    {
  +                        public void menuSelected( MenuEvent event )
  +                        {
  +                            JMenu menu = (JMenu)event.getSource();
  +                            Action action = menu.getAction();
  +
  +                            rebuildInstrumentableMenu(
  +                                menu,
  +                                (InstrumentManagerConnection)action.getValue(
  +                                    "InstrumentManagerConnection" ),
  +                                (InstrumentableDescriptor)action.getValue(
  +                                    "InstrumentableDescriptor" ) );
  +                        }
  +
  +                        public void menuDeselected( MenuEvent event )
  +                        {
  +                        }
  +
  +                        public void menuCanceled( MenuEvent event )
  +                        {
  +                        }
  +                    } );
  +
  +                    instrumentableMenu.add( menu );
  +                }
  +            }
  +        }
  +        catch ( AltrmiInvocationException e )
  +        {
  +            // Something went wrong, so close the connection.
  +            connection.close();
  +            return;
  +        }
  +        
  +        try
  +        {
               InstrumentDescriptor[] descriptors =
                   instrumentableDescriptor.getInstrumentDescriptors();
   
  @@ -380,7 +440,6 @@
                           }
                       };
                       action.putValue( "InstrumentManagerConnection", connection );
  -                    action.putValue( "InstrumentableDescriptor", instrumentableDescriptor
);
                       action.putValue( "InstrumentDescriptor", descriptor );
   
                       JMenu menu = new LargeMenu( action );
  @@ -397,8 +456,6 @@
                                   menu,
                                   (InstrumentManagerConnection)action.getValue(
                                       "InstrumentManagerConnection" ),
  -                                (InstrumentableDescriptor)action.getValue(
  -                                    "InstrumentableDescriptor" ),
                                   (InstrumentDescriptor)action.getValue(
                                       "InstrumentDescriptor" ) );
                           }
  @@ -425,7 +482,6 @@
   
       private void rebuildInstrumentMenu( JMenu instrumentMenu,
                                           InstrumentManagerConnection connection,
  -                                        InstrumentableDescriptor instrumentableDescriptor,
                                           InstrumentDescriptor instrumentDescriptor )
       {
           instrumentMenu.removeAll();
  @@ -442,12 +498,10 @@
   
                   m_frame.instrumentCreateSample(
                       (InstrumentManagerConnection)action.getValue( "InstrumentManagerConnection"
),
  -                    (InstrumentableDescriptor)action.getValue( "InstrumentableDescriptor"
),
                       (InstrumentDescriptor)action.getValue( "InstrumentDescriptor" ) );
               }
           };
           createAction.putValue( "InstrumentManagerConnection", connection );
  -        createAction.putValue( "InstrumentableDescriptor", instrumentableDescriptor );
           createAction.putValue( "InstrumentDescriptor", instrumentDescriptor );
   
           JMenuItem createItem = new JMenuItem( createAction );
  @@ -481,17 +535,11 @@
                                   m_frame.openInstrumentSampleFrame(
                                       (InstrumentManagerConnection)action.getValue(
                                           "InstrumentManagerConnection" ),
  -                                    (InstrumentableDescriptor)action.getValue(
  -                                        "InstrumentableDescriptor" ),
  -                                    (InstrumentDescriptor)action.getValue(
  -                                        "InstrumentDescriptor" ),
                                       (InstrumentSampleDescriptor)action.getValue(
                                           "InstrumentSampleDescriptor" ) );
                               }
                           };
                           action.putValue( "InstrumentManagerConnection", connection );
  -                        action.putValue( "InstrumentableDescriptor", instrumentableDescriptor
);
  -                        action.putValue( "InstrumentDescriptor", instrumentDescriptor );
                           action.putValue( "InstrumentSampleDescriptor", descriptor );
   
                           JMenuItem item = new JMenuItem( action );
  
  
  

--
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