Statistics
| Revision:

gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / SelectAreaPanelView.java @ 9460

History | View | Annotate | Download (4.87 KB)

1
package org.gvsig.online.swing.impl;
2

    
3
import com.jeta.open.i18n.I18NUtils;
4
import com.jgoodies.forms.layout.CellConstraints;
5
import com.jgoodies.forms.layout.FormLayout;
6
import java.awt.BorderLayout;
7
import java.awt.ComponentOrientation;
8
import java.awt.Container;
9
import java.awt.Dimension;
10
import javax.swing.Box;
11
import javax.swing.ImageIcon;
12
import javax.swing.JButton;
13
import javax.swing.JFrame;
14
import javax.swing.JPanel;
15

    
16

    
17
public class SelectAreaPanelView extends JPanel
18
{
19
   JButton btnZoomPlus = new JButton();
20
   JButton btnZoomMinus = new JButton();
21
   JPanel containerMapControl = new JPanel();
22

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

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

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

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

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

    
71
   }
72

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

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

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

    
117
      btnZoomPlus.setActionCommand("JButton");
118
      btnZoomPlus.setName("btnZoomPlus");
119
      btnZoomPlus.setText("+");
120
      btnZoomPlus.setToolTipText("_Zoom_plus");
121
      jpanel1.add(btnZoomPlus,cc.xy(2,4));
122

    
123
      btnZoomMinus.setActionCommand("JButton");
124
      btnZoomMinus.setName("btnZoomMinus");
125
      btnZoomMinus.setText("-");
126
      btnZoomMinus.setToolTipText("_Zoom_minus");
127
      jpanel1.add(btnZoomMinus,cc.xy(4,4));
128

    
129
      jpanel1.add(createPanel1(),cc.xywh(2,2,4,1));
130
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6 },new int[]{ 1,2,3,4,5 });
131
      return jpanel1;
132
   }
133

    
134
   public JPanel createPanel1()
135
   {
136
      JPanel jpanel1 = new JPanel();
137
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:GROW(1.0)");
138
      CellConstraints cc = new CellConstraints();
139
      jpanel1.setLayout(formlayout1);
140

    
141
      containerMapControl.setName("containerMapControl");
142
      jpanel1.add(containerMapControl,new CellConstraints(1,1,1,1,CellConstraints.FILL,CellConstraints.FILL));
143

    
144
      addFillComponents(jpanel1,new int[0],new int[0]);
145
      return jpanel1;
146
   }
147

    
148
   /**
149
    * Initializer
150
    */
151
   protected void initializePanel()
152
   {
153
      setLayout(new BorderLayout());
154
      add(createPanel(), BorderLayout.CENTER);
155
   }
156

    
157

    
158
}