package org.jgrasstools.nww.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.ComponentOrientation; import java.awt.Container; import java.awt.Dimension; import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.border.TitledBorder; import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; public class LayersPanelView extends JPanel { JPanel _layersGridView = new JPanel(); /** * Default constructor */ public LayersPanelView() { initializePanel(); } /** * Adds fill components to empty cells in the first row and first column of the grid. * This ensures that the grid spacing will be the same as shown in the designer. * @param cols an array of column indices in the first row where fill components should be added. * @param rows an array of row indices in the first column where fill components should be added. */ void addFillComponents( Container panel, int[] cols, int[] rows ) { Dimension filler = new Dimension(10,10); boolean filled_cell_11 = false; CellConstraints cc = new CellConstraints(); if ( cols.length > 0 && rows.length > 0 ) { if ( cols[0] == 1 && rows[0] == 1 ) { /** add a rigid area */ panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); filled_cell_11 = true; } } for( int index = 0; index < cols.length; index++ ) { if ( cols[index] == 1 && filled_cell_11 ) { continue; } panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); } for( int index = 0; index < rows.length; index++ ) { if ( rows[index] == 1 && filled_cell_11 ) { continue; } panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); } } /** * Helper method to load an image file from the CLASSPATH * @param imageName the package and name of the file to load relative to the CLASSPATH * @return an ImageIcon instance with the specified image file * @throws IllegalArgumentException if the image resource cannot be loaded. */ public ImageIcon loadImage( String imageName ) { try { ClassLoader classloader = getClass().getClassLoader(); java.net.URL url = classloader.getResource( imageName ); if ( url != null ) { ImageIcon icon = new ImageIcon( url ); return icon; } } catch( Exception e ) { e.printStackTrace(); } throw new IllegalArgumentException( "Unable to load image: " + imageName ); } /** * Method for recalculating the component orientation for * right-to-left Locales. * @param orientation the component orientation to be applied */ public void applyComponentOrientation( ComponentOrientation orientation ) { // Not yet implemented... // I18NUtils.applyComponentOrientation(this, orientation); super.applyComponentOrientation(orientation); } public JScrollPane createlayersGridView() { _layersGridView.setName("layersGridView"); TitledBorder titledborder1 = new TitledBorder(null,"Layers",TitledBorder.DEFAULT_JUSTIFICATION,TitledBorder.DEFAULT_POSITION,null,new Color(49,106,196)); _layersGridView.setBorder(titledborder1); JScrollPane jscrollpane1 = new JScrollPane(); jscrollpane1.setViewportView(_layersGridView); jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); CellConstraints cc = new CellConstraints(); _layersGridView.setLayout(formlayout1); addFillComponents(_layersGridView,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73 }); return jscrollpane1; } /** * Initializer */ protected void initializePanel() { setLayout(new BorderLayout()); add(createlayersGridView(), BorderLayout.CENTER); } }