Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / tools / PointSelectionListenerUniqueSelect.java @ 45104

History | View | Annotate | Download (4.9 KB)

1
package org.gvsig.fmap.mapcontrol.tools;
2
import com.jeta.open.i18n.I18NUtils;
3
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5
import java.awt.BorderLayout;
6
import java.awt.ComponentOrientation;
7
import java.awt.Container;
8
import java.awt.Dimension;
9
import java.awt.event.WindowAdapter;
10
import java.awt.event.WindowEvent;
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JFrame;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JScrollPane;
17
import javax.swing.JTable;
18

    
19

    
20
public class PointSelectionListenerUniqueSelect extends JPanel
21
{
22
   JLabel lblSelect = new JLabel();
23
   JTable tblSelection = new JTable();
24

    
25
   /**
26
    * Default constructor
27
    */
28
   public PointSelectionListenerUniqueSelect()
29
   {
30
      initializePanel();
31
   }
32

    
33
   /**
34
    * Main method for panel
35
    */
36
   public static void main(String[] args)
37
   {
38
      JFrame frame = new JFrame();
39
      frame.setSize(600, 400);
40
      frame.setLocation(100, 100);
41
      frame.getContentPane().add(new PointSelectionListenerUniqueSelect());
42
      frame.setVisible(true);
43

    
44
      frame.addWindowListener( new WindowAdapter()
45
      {
46
         public void windowClosing( WindowEvent evt )
47
         {
48
            System.exit(0);
49
         }
50
      });
51
   }
52

    
53
   /**
54
    * Adds fill components to empty cells in the first row and first column of the grid.
55
    * This ensures that the grid spacing will be the same as shown in the designer.
56
    * @param cols an array of column indices in the first row where fill components should be added.
57
    * @param rows an array of row indices in the first column where fill components should be added.
58
    */
59
   void addFillComponents( Container panel, int[] cols, int[] rows )
60
   {
61
      Dimension filler = new Dimension(10,10);
62

    
63
      boolean filled_cell_11 = false;
64
      CellConstraints cc = new CellConstraints();
65
      if ( cols.length > 0 && rows.length > 0 )
66
      {
67
         if ( cols[0] == 1 && rows[0] == 1 )
68
         {
69
            /** add a rigid area  */
70
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
71
            filled_cell_11 = true;
72
         }
73
      }
74

    
75
      for( int index = 0; index < cols.length; index++ )
76
      {
77
         if ( cols[index] == 1 && filled_cell_11 )
78
         {
79
            continue;
80
         }
81
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
82
      }
83

    
84
      for( int index = 0; index < rows.length; index++ )
85
      {
86
         if ( rows[index] == 1 && filled_cell_11 )
87
         {
88
            continue;
89
         }
90
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
91
      }
92

    
93
   }
94

    
95
   /**
96
    * Helper method to load an image file from the CLASSPATH
97
    * @param imageName the package and name of the file to load relative to the CLASSPATH
98
    * @return an ImageIcon instance with the specified image file
99
    * @throws IllegalArgumentException if the image resource cannot be loaded.
100
    */
101
   public ImageIcon loadImage( String imageName )
102
   {
103
      try
104
      {
105
         ClassLoader classloader = getClass().getClassLoader();
106
         java.net.URL url = classloader.getResource( imageName );
107
         if ( url != null )
108
         {
109
            ImageIcon icon = new ImageIcon( url );
110
            return icon;
111
         }
112
      }
113
      catch( Exception e )
114
      {
115
         e.printStackTrace();
116
      }
117
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
118
   }
119

    
120
   /**
121
    * Method for recalculating the component orientation for 
122
    * right-to-left Locales.
123
    * @param orientation the component orientation to be applied
124
    */
125
   public void applyComponentOrientation( ComponentOrientation orientation )
126
   {
127
      // Not yet implemented...
128
      // I18NUtils.applyComponentOrientation(this, orientation);
129
      super.applyComponentOrientation(orientation);
130
   }
131

    
132
   public JPanel createPanel()
133
   {
134
      JPanel jpanel1 = new JPanel();
135
      FormLayout formlayout1 = new FormLayout("FILL:5PX:NONE,FILL:340PX:GROW(1.0),FILL:4PX:NONE","CENTER:4PX:NONE,CENTER:DEFAULT:NONE,CENTER:4PX:NONE,FILL:133PX:GROW(1.0),CENTER:5PX:NONE");
136
      CellConstraints cc = new CellConstraints();
137
      jpanel1.setLayout(formlayout1);
138

    
139
      lblSelect.setName("lblSelect");
140
      lblSelect.setText("_Choose_features_to_select");
141
      jpanel1.add(lblSelect,cc.xy(2,2));
142

    
143
      tblSelection.setName("tblSelection");
144
      JScrollPane jscrollpane1 = new JScrollPane();
145
      jscrollpane1.setViewportView(tblSelection);
146
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
147
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
148
      jpanel1.add(jscrollpane1,cc.xy(2,4));
149

    
150
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 });
151
      return jpanel1;
152
   }
153

    
154
   /**
155
    * Initializer
156
    */
157
   protected void initializePanel()
158
   {
159
      setLayout(new BorderLayout());
160
      add(createPanel(), BorderLayout.CENTER);
161
   }
162

    
163

    
164
}