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 / JNewScriptPanelLayout.java @ 369

History | View | Annotate | Download (6.48 KB)

1
package org.gvsig.scripting.swing.impl.composer;
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.JComboBox;
11
import javax.swing.JLabel;
12
import javax.swing.JPanel;
13
import javax.swing.JScrollPane;
14
import javax.swing.JTextArea;
15
import javax.swing.JTextField;
16

    
17
import com.jgoodies.forms.layout.CellConstraints;
18
import com.jgoodies.forms.layout.FormLayout;
19

    
20

    
21
public class JNewScriptPanelLayout extends JPanel
22
{
23
   JLabel Name_ = new JLabel();
24
   JTextField name = new JTextField();
25
   JTextArea description = new JTextArea();
26
   JComboBox units = new JComboBox();
27
   JComboBox languages = new JComboBox();
28
   JTextField saveTo = new JTextField();
29
   JPanel saveToPanel = new JPanel();
30
   JTextField createdBy = new JTextField();
31
   JTextField version = new JTextField();
32

    
33
   /**
34
    * Default constructor
35
    */
36
   public JNewScriptPanelLayout()
37
   {
38
      initializePanel();
39
   }
40

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

    
51
      boolean filled_cell_11 = false;
52
      CellConstraints cc = new CellConstraints();
53
      if ( cols.length > 0 && rows.length > 0 )
54
      {
55
         if ( cols[0] == 1 && rows[0] == 1 )
56
         {
57
            /** add a rigid area  */
58
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
59
            filled_cell_11 = true;
60
         }
61
      }
62

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

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

    
81
   }
82

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

    
108
   /**
109
    * Method for recalculating the component orientation for 
110
    * right-to-left Locales.
111
    * @param orientation the component orientation to be applied
112
    */
113
   public void applyComponentOrientation( ComponentOrientation orientation )
114
   {
115
      // Not yet implemented...
116
      // I18NUtils.applyComponentOrientation(this, orientation);
117
      super.applyComponentOrientation(orientation);
118
   }
119

    
120
   public JPanel createPanel()
121
   {
122
      JPanel jpanel1 = new JPanel();
123
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:MIN(12DLU;DEFAULT):GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
124
      CellConstraints cc = new CellConstraints();
125
      jpanel1.setLayout(formlayout1);
126

    
127
      Name_.setName("Name:");
128
      Name_.setText("Name:");
129
      jpanel1.add(Name_,cc.xy(2,2));
130

    
131
      JLabel jlabel1 = new JLabel();
132
      jlabel1.setText("Description:");
133
      jpanel1.add(jlabel1,new CellConstraints(2,4,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
134

    
135
      JLabel jlabel2 = new JLabel();
136
      jlabel2.setText("Type:");
137
      jpanel1.add(jlabel2,cc.xy(2,6));
138

    
139
      JLabel jlabel3 = new JLabel();
140
      jlabel3.setText("Language:");
141
      jpanel1.add(jlabel3,cc.xy(2,8));
142

    
143
      JLabel jlabel4 = new JLabel();
144
      jlabel4.setText("Save on:");
145
      jpanel1.add(jlabel4,cc.xy(2,10));
146

    
147
      JLabel jlabel5 = new JLabel();
148
      jlabel5.setText("Author:");
149
      jpanel1.add(jlabel5,cc.xy(2,13));
150

    
151
      JLabel jlabel6 = new JLabel();
152
      jlabel6.setText("Version:");
153
      jpanel1.add(jlabel6,cc.xy(2,15));
154

    
155
      name.setName("name");
156
      jpanel1.add(name,cc.xy(3,2));
157

    
158
      description.setName("description");
159
      JScrollPane jscrollpane1 = new JScrollPane();
160
      jscrollpane1.setViewportView(description);
161
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
162
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
163
      jpanel1.add(jscrollpane1,new CellConstraints(3,4,1,1,CellConstraints.FILL,CellConstraints.FILL));
164

    
165
      units.setName("units");
166
      jpanel1.add(units,cc.xy(3,6));
167

    
168
      languages.setName("languages");
169
      jpanel1.add(languages,cc.xy(3,8));
170

    
171
      saveTo.setEditable(false);
172
      saveTo.setName("saveTo");
173
      saveTo.setScrollOffset(300);
174
      saveTo.setSelectionEnd(85);
175
      saveTo.setSelectionStart(85);
176
      saveTo.setText("esto es una pruaba a ver que pasa con un texto grande a ver si me deja editarlo o no.");
177
      jpanel1.add(saveTo,new CellConstraints(3,10,1,1,CellConstraints.LEFT,CellConstraints.DEFAULT));
178

    
179
      saveToPanel.setName("saveToPanel");
180
      jpanel1.add(saveToPanel,cc.xy(3,11));
181

    
182
      createdBy.setName("createdBy");
183
      jpanel1.add(createdBy,cc.xy(3,13));
184

    
185
      version.setName("version");
186
      jpanel1.add(version,cc.xy(3,15));
187

    
188
      addFillComponents(jpanel1,new int[]{ 1,2,3,4 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 });
189
      return jpanel1;
190
   }
191

    
192
   /**
193
    * Initializer
194
    */
195
   protected void initializePanel()
196
   {
197
      setLayout(new BorderLayout());
198
      add(createPanel(), BorderLayout.CENTER);
199
   }
200

    
201

    
202
}