Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.fmap.mapcontext.swing / org.gvsig.fmap.mapcontext.swing.impl / src / main / java / org / gvsig / fmap / mapcontext / raster / swing / impl / operations / OperationSelectorPanelView.java @ 43803

History | View | Annotate | Download (4.2 KB)

1
package org.gvsig.fmap.mapcontext.raster.swing.impl.operations;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.ComponentOrientation;
5
import java.awt.Container;
6
import java.awt.Dimension;
7

    
8
import javax.swing.Box;
9
import javax.swing.ImageIcon;
10
import javax.swing.JList;
11
import javax.swing.JPanel;
12
import javax.swing.JScrollPane;
13

    
14
import com.jgoodies.forms.layout.CellConstraints;
15
import com.jgoodies.forms.layout.FormLayout;
16

    
17

    
18
public class OperationSelectorPanelView extends JPanel
19
{
20
   JList lstOperations = new JList();
21

    
22
   /**
23
    * Default constructor
24
    */
25
   public OperationSelectorPanelView()
26
   {
27
      initializePanel();
28
   }
29

    
30
   /**
31
    * Adds fill components to empty cells in the first row and first column of the grid.
32
    * This ensures that the grid spacing will be the same as shown in the designer.
33
    * @param cols an array of column indices in the first row where fill components should be added.
34
    * @param rows an array of row indices in the first column where fill components should be added.
35
    */
36
   void addFillComponents( Container panel, int[] cols, int[] rows )
37
   {
38
      Dimension filler = new Dimension(10,10);
39

    
40
      boolean filled_cell_11 = false;
41
      CellConstraints cc = new CellConstraints();
42
      if ( cols.length > 0 && rows.length > 0 )
43
      {
44
         if ( cols[0] == 1 && rows[0] == 1 )
45
         {
46
            /** add a rigid area  */
47
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
48
            filled_cell_11 = true;
49
         }
50
      }
51

    
52
      for( int index = 0; index < cols.length; index++ )
53
      {
54
         if ( cols[index] == 1 && filled_cell_11 )
55
         {
56
            continue;
57
         }
58
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
59
      }
60

    
61
      for( int index = 0; index < rows.length; index++ )
62
      {
63
         if ( rows[index] == 1 && filled_cell_11 )
64
         {
65
            continue;
66
         }
67
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
68
      }
69

    
70
   }
71

    
72
   /**
73
    * Helper method to load an image file from the CLASSPATH
74
    * @param imageName the package and name of the file to load relative to the CLASSPATH
75
    * @return an ImageIcon instance with the specified image file
76
    * @throws IllegalArgumentException if the image resource cannot be loaded.
77
    */
78
   public ImageIcon loadImage( String imageName )
79
   {
80
      try
81
      {
82
         ClassLoader classloader = getClass().getClassLoader();
83
         java.net.URL url = classloader.getResource( imageName );
84
         if ( url != null )
85
         {
86
            ImageIcon icon = new ImageIcon( url );
87
            return icon;
88
         }
89
      }
90
      catch( Exception e )
91
      {
92
         e.printStackTrace();
93
      }
94
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
95
   }
96

    
97
   /**
98
    * Method for recalculating the component orientation for
99
    * right-to-left Locales.
100
    * @param orientation the component orientation to be applied
101
    */
102
   public void applyComponentOrientation( ComponentOrientation orientation )
103
   {
104
      // Not yet implemented...
105
      // I18NUtils.applyComponentOrientation(this, orientation);
106
      super.applyComponentOrientation(orientation);
107
   }
108

    
109
   public JPanel createPanel()
110
   {
111
      JPanel jpanel1 = new JPanel();
112
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:2DLU:NONE");
113
      CellConstraints cc = new CellConstraints();
114
      jpanel1.setLayout(formlayout1);
115

    
116
      lstOperations.setName("lstOperations");
117
      lstOperations.setToolTipText("_operations_selector");
118
      JScrollPane jscrollpane1 = new JScrollPane();
119
      jscrollpane1.setViewportView(lstOperations);
120
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
121
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
122
      jpanel1.add(jscrollpane1,new CellConstraints(2,2,1,1,CellConstraints.FILL,CellConstraints.FILL));
123

    
124
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3 });
125
      return jpanel1;
126
   }
127

    
128
   /**
129
    * Initializer
130
    */
131
   protected void initializePanel()
132
   {
133
      setLayout(new BorderLayout());
134
      add(createPanel(), BorderLayout.CENTER);
135
   }
136

    
137

    
138
}