Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / deprecated / JImportHelpView.java @ 702

History | View | Annotate | Download (4.65 KB)

1
package org.gvsig.scripting.swing.impl.composer.deprecated;
2

    
3
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5
import java.awt.BorderLayout;
6
import java.awt.Color;
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.JLabel;
14
import javax.swing.JPanel;
15
import javax.swing.JTextField;
16

    
17

    
18
public class JImportHelpView extends JPanel
19
{
20
   JLabel lblFolder = new JLabel();
21
   JLabel lblName = new JLabel();
22
   JTextField txtFolder = new JTextField();
23
   JTextField txtName = new JTextField();
24
   JButton btnBrowse = new JButton();
25

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

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

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

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

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

    
74
   }
75

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

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

    
113
   public JPanel createPanel()
114
   {
115
      JPanel jpanel1 = new JPanel();
116
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
117
      CellConstraints cc = new CellConstraints();
118
      jpanel1.setLayout(formlayout1);
119

    
120
      lblFolder.setName("lblFolder");
121
      lblFolder.setText("Folder to import");
122
      jpanel1.add(lblFolder,cc.xy(2,2));
123

    
124
      lblName.setName("lblName");
125
      lblName.setText("Name");
126
      jpanel1.add(lblName,cc.xy(2,4));
127

    
128
      txtFolder.setBackground(new Color(236,233,216));
129
      txtFolder.setEditable(false);
130
      txtFolder.setName("txtFolder");
131
      jpanel1.add(txtFolder,cc.xy(4,2));
132

    
133
      txtName.setName("txtName");
134
      jpanel1.add(txtName,cc.xywh(4,4,3,1));
135

    
136
      btnBrowse.setActionCommand("Browse...");
137
      btnBrowse.setName("btnBrowse");
138
      btnBrowse.setText("Browse...");
139
      jpanel1.add(btnBrowse,cc.xy(6,2));
140

    
141
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5 });
142
      return jpanel1;
143
   }
144

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

    
154

    
155
}