Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / panels / SelectAttributesPanelView.java @ 44395

History | View | Annotate | Download (5.13 KB)

1
package org.gvsig.export.swing.impl.panels;
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 SelectAttributesPanelView extends JPanel
21
{
22
   JLabel lblHeader = new JLabel();
23
   JPanel jplAttributes = new JPanel();
24
   JTable tblAttributes = new JTable();
25

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

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

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

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

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

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

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

    
94
   }
95

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

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

    
133
   public JPanel createPanel()
134
   {
135
      JPanel jpanel1 = new JPanel();
136
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:8DLU:NONE,FILL:8DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:53DLU:NONE,CENTER:2DLU:NONE");
137
      CellConstraints cc = new CellConstraints();
138
      jpanel1.setLayout(formlayout1);
139

    
140
      lblHeader.setName("lblHeader");
141
      lblHeader.setText("_Select_name_type_size_and_attributes_to_export");
142
      jpanel1.add(lblHeader,cc.xywh(2,2,3,1));
143

    
144
      jplAttributes.setAutoscrolls(true);
145
      jplAttributes.setName("jplAttributes");
146
      jpanel1.add(jplAttributes,cc.xy(4,5));
147

    
148
      tblAttributes.setName("tblAttributes");
149
      JScrollPane jscrollpane1 = new JScrollPane();
150
      jscrollpane1.setViewportView(tblAttributes);
151
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
152
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
153
      jpanel1.add(jscrollpane1,cc.xy(4,4));
154

    
155
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6 });
156
      return jpanel1;
157
   }
158

    
159
   /**
160
    * Initializer
161
    */
162
   protected void initializePanel()
163
   {
164
      setLayout(new BorderLayout());
165
      add(createPanel(), BorderLayout.CENTER);
166
   }
167

    
168

    
169
}