Ejemplo n.º 1
0
  private void setupPanels()
  {
    Border   border1, border2;
    int      row, col;
    MyButton btn;


    border2 = BorderFactory.createLoweredBevelBorder();
    
    JPanel mainPanel = new JPanel( new GridBagLayout() );
    
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL; 
    con.weightx = 1; con.anchor = GridBagConstraints.NORTHWEST;
    
    // Setup States Panels
    JPanel statesP = new JPanel( new GridBagLayout() );
    border1 = BorderFactory.createEmptyBorder (4, 4, 2, 4);
    statesP.setBorder( BorderFactory.createCompoundBorder(border1, border2) );
    
    JPanel statesP_in = new JPanel(new GridBagLayout() );
    
    row = 0; col = 0;
    Enumeration enum = parent.stateDefs.elements();
    
    while ( enum.hasMoreElements() ) {
        RecDef def = ( RecDef ) enum.nextElement();
      
        if ( def.stateVector.size() > 0 ) {
            con.gridx = col; con.gridy = row;

            btn = new MyButton( def.description,
                                "Press for " + def.description
                              + " histogram", this );
            statesP_in.add( btn, con);
            btn.setIcon( new ColoredRect( def.color ) );
            btn.setHorizontalAlignment( btn.LEFT );
		   
            con.gridx = col + 1;
            def.checkbox = new JCheckBox( "", true );
            statesP_in.add( def.checkbox, con ); 
	    def.checkbox.addItemListener( this ); 
            def.checkbox.setToolTipText( "Enable or disable "
                                       + def.description );
	
            if ( (col / 2) == numCols ) {
                col = 0; row ++; 
            }
            else
                col += 2;
        }
    }
    
    con.gridx = 0; con.gridy = 0;
    con.fill = GridBagConstraints.NONE;
    con.weightx = 0;
    statesP.add( statesP_in, con );
    
    // State Buttons Controls
    JPanel states_cntl = new JPanel( new GridLayout(2, 1) );
    states_cntl.add( new MyButton( "All States On",
                                   "Enable all states", this) ); 
    states_cntl.add( new MyButton( "All States Off",
                                   "Disable all states", this) );
    
    con.gridx = 1;
    statesP.add( states_cntl, con );
    
    con.gridx = 0; con.gridy = 0;
    mainPanel.add( statesP, con );
    
    // Setup Arrows Panels
    if ( parent.arrowDefs.size() > 0 ) {
        row = 0; col = 0;
        JPanel arrowsP = new JPanel( new GridBagLayout() );
        border1 = BorderFactory.createEmptyBorder (2, 4, 4, 4);
        arrowsP.setBorder( BorderFactory.createCompoundBorder( border1,
                                                               border2 ) );

        JPanel arrowsP_in = new JPanel( new GridBagLayout() );

        enum = parent.arrowDefs.elements();
        while ( enum.hasMoreElements() ) {
            RecDef def = ( RecDef ) enum.nextElement();
            if ( def.stateVector.size() > 0 ) {
                con.gridx = col; con.gridy = row;
                btn = new MyButton( def.description,
                                    "Press for " + def.description
                                  + " histogram", this );
                arrowsP_in.add( btn, con );
                btn.setIcon( new ColoredRect( def.color ) );
                btn.setHorizontalAlignment( btn.LEFT );

                con.gridx = col + 1;
                def.checkbox = new JCheckBox( "", true );
                arrowsP_in.add( def.checkbox, con ); 
                def.checkbox.addItemListener( this ); 
                def.checkbox.setToolTipText( "Enable or disable "
                                           + def.description );
                if ( (col / 2) == numCols ) {
                    col = 0; row ++; 
                }
                else
                    col += 2;
            }   //  Endof if ( def.stateVector.size() > 0 )
        }

        con.gridx = 0; con.gridy = 0;
        con.fill = GridBagConstraints.NONE;
        con.weightx = 0;
        arrowsP.add( arrowsP_in, con );
    
        // Arrow Buttons Controls
        JPanel arrows_cntl = new JPanel( new GridLayout(2, 1) );
        arrows_cntl.add( new MyButton( "All Arrows On",
                                       "Enable all arrows", this) ); 
        arrows_cntl.add( new MyButton( "All Arrows Off",
                                       "Disable all arrows", this) );
    
        con.gridx = 1;
        arrowsP.add( arrows_cntl, con );

        con.gridy = 2; con.gridx = 0;
        mainPanel.add( arrowsP, con );
    }   //  Endof  if ( parent.arrowDefs.size() > 0 )
      
    //Add mainPanel to JScrollPane
    JScrollPane sP = new JScrollPane (mainPanel);
    sP.setPreferredSize (new Dimension (100, 100));
    sP.setMinimumSize (new Dimension (100, 100));
    add (sP);
  }