avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craft...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client MenuBar.java InstrumentClientFrame.java
Date Thu, 17 Oct 2002 15:56:18 GMT
crafterm    2002/10/17 08:56:18

  Modified:    instrument-client/src/java/org/apache/excalibur/instrument/client
                        MenuBar.java InstrumentClientFrame.java
  Log:
  Applied patch from Matthias Stoeckel <Matthias.Stoeckel@dresdner-bank.com>
  which adds support for tiling sample windows (relative, horizontally &
  vertically).
  
  Revision  Changes    Path
  1.3       +41 -1     jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/MenuBar.java
  
  Index: MenuBar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/MenuBar.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MenuBar.java	22 Aug 2002 16:50:38 -0000	1.2
  +++ MenuBar.java	17 Oct 2002 15:56:17 -0000	1.3
  @@ -580,6 +580,46 @@
       {
           m_menuWindow.removeAll();
   
  +        // Tile window menu choice
  +        Action tileFramesAction = new AbstractAction( "Tile frames" )
  +        {
  +            public void actionPerformed( ActionEvent event )
  +            {
  +                m_frame.tileFrames();
  +            }
  +        };
  +
  +        JMenuItem tileFrames = new JMenuItem( tileFramesAction );
  +        tileFrames.setMnemonic( 't' );
  +        m_menuWindow.add( tileFrames );
  +
  +
  +        // Tile window vertically menu choice
  +        Action tileFramesVAction = new AbstractAction( "Tile frames vertically" )
  +        {
  +            public void actionPerformed( ActionEvent event )
  +            {
  +                m_frame.tileFramesV();
  +            }
  +        };
  +
  +        JMenuItem tileFramesV = new JMenuItem( tileFramesVAction );
  +        tileFramesV.setMnemonic( 'v' );
  +        m_menuWindow.add( tileFramesV );
  +
  +        // Tile window horizontally menu choice
  +        Action tileFramesHAction = new AbstractAction( "Tile frames horizontally" )
  +        {
  +            public void actionPerformed( ActionEvent event )
  +            {
  +                m_frame.tileFramesH();
  +            }
  +        };
  +
  +        JMenuItem tileFramesH = new JMenuItem( tileFramesHAction );
  +        tileFramesH.setMnemonic( 'h' );
  +        m_menuWindow.add( tileFramesH );
  +
           // Close All menu choice
           Action closeAllAction = new AbstractAction( "Close All" )
           {
  
  
  
  1.4       +108 -1    jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentClientFrame.java
  
  Index: InstrumentClientFrame.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentClientFrame.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InstrumentClientFrame.java	23 Aug 2002 10:03:48 -0000	1.3
  +++ InstrumentClientFrame.java	17 Oct 2002 15:56:17 -0000	1.4
  @@ -20,6 +20,7 @@
   import java.io.InputStream;
   import java.io.OutputStream;
   import java.util.HashMap;
  +import java.util.ArrayList;
   
   import javax.swing.ImageIcon;
   import javax.swing.JDesktopPane;
  @@ -699,6 +700,112 @@
               frames[ i ].setVisible( false );
               frames[ i ].dispose();
           }
  +    }
  +    
  +    /**
  +     * Tile all open frames
  +     */
  +    void tileFrames()
  +    {
  +        ArrayList openframes = getOpenFrames();
  +        
  +        int count = openframes.size();
  +        if( count == 0) return;
  +        
  +        // Determine the number of rows and columns
  +        int rows = (int) Math.sqrt( count );
  +        int cols = rows;
  +        
  +        // Be sure to have enough grid positions
  +        if ( rows*cols < count )
  +        {
  +            rows++;
  +            if ( rows*cols < count )
  +            {
  +                cols++;
  +            }
  +        }
  +
  +        reorganizeFrames( rows, cols, openframes );
  +    }
  +    
  +    /**
  +     * Get a list with all open frames. 
  +     *
  +     * @return ArrayList with references to all open internal frames
  +     */
  +    ArrayList getOpenFrames()
  +    {
  +        JInternalFrame[] frames = m_desktopPane.getAllFrames();
  +        int count = frames.length;
  +        
  +        // No frames
  +        if (count == 0) return new ArrayList();
  +    
  +        // add only open frames to the list
  +        ArrayList openframes = new ArrayList();
  +        for ( int i = 0; i < count; i++ )
  +        {
  +            JInternalFrame f = frames[i];
  +            if( ( f.isClosed() == false ) && ( f.isIcon() == false ) )
  +                openframes.add( f );
  +        }
  +        return openframes;
  +    }
  +    
  +    /**
  +     * Reorganizes a list of internal frames to a specific
  +     * number of rows and columns.
  +     *
  +     * @param rows number of rows to use
  +     * @param cols number of columns to use
  +     * @param frames list with <code>JInternalFrames</code>
  +     */  
  +    void reorganizeFrames( int rows, int cols, ArrayList frames )
  +    {
  +        // Determine the size of one windows
  +        Dimension desktopsize = m_desktopPane.getSize();
  +        int w = desktopsize.width / cols;
  +        int h = desktopsize.height / rows;
  +        int x = 0;
  +        int y = 0;
  +        int count = frames.size();
  +
  +        for ( int i = 0; i < rows; ++i)
  +        {
  +            for ( int j = 0; j < cols && ( (i * cols ) + j < count ); ++j)

  +            {
  +                JInternalFrame f = (JInternalFrame) frames.get( ( i * cols ) + j );
  +                m_desktopPane.getDesktopManager().resizeFrame( f, x, y, w, h );
  +                x += w;
  +            }
  +            y += h;
  +            x = 0;   
  +        }
  +    }
  +    
  +    /**
  +     * Tiles all internal frames horizontally
  +     */
  +    void tileFramesH()
  +    {
  +        ArrayList openframes=getOpenFrames();
  +        
  +        int count = openframes.size();
  +        if( count == 0) return; 
  +        reorganizeFrames( count,1,openframes );
  +    }
  +    
  +    /**
  +     * Tiles all internal frames vertically
  +     */
  +    void tileFramesV()
  +    {
  +        ArrayList openframes = getOpenFrames();
  +        
  +        int count=openframes.size();
  +        if( count == 0) return;
  +        reorganizeFrames( 1, count, openframes );
       }
       
       InstrumentManagerConnection[] getInstrumentManagerConnections()
  
  
  

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