Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / preferencespage / dal / DALView.java @ 43564

History | View | Annotate | Download (4.66 KB)

1
package org.gvsig.app.gui.preferencespage.dal;
2

    
3
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5

    
6
import java.awt.BorderLayout;
7
import java.awt.ComponentOrientation;
8
import java.awt.Container;
9
import java.awt.Dimension;
10

    
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JComboBox;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JTextField;
17

    
18
import org.gvsig.andami.preferences.AbstractPreferencePage;
19
import org.gvsig.tools.ToolsLocator;
20
import org.gvsig.tools.i18n.I18nManager;
21

    
22

    
23
public abstract class DALView extends AbstractPreferencePage
24
{
25
   JLabel lblAccuracy = new JLabel();
26
   JLabel lblDALEvaluator = new JLabel();
27
   JComboBox cboDALEvaluator = new JComboBox();
28
   JTextField txtAccuracy = new JTextField();
29

    
30
   /**
31
    * Default constructor
32
    */
33
   public DALView()
34
   {
35
      initializePanel();
36
   }
37

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

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

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

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

    
78
   }
79

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

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

    
117
   public JPanel createPanel()
118
   {
119
      I18nManager i18nManager = ToolsLocator.getI18nManager();
120
      JPanel jpanel1 = new JPanel();
121
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE");
122
      CellConstraints cc = new CellConstraints();
123
      jpanel1.setLayout(formlayout1);
124

    
125
      lblAccuracy.setName("lblAccuracy");
126
      lblAccuracy.setText(i18nManager.getTranslation("_precision_comparing_decimal_numbers"));
127
      jpanel1.add(lblAccuracy,cc.xy(2,4));
128

    
129
      lblDALEvaluator.setName("lblDALEvaluator");
130
      lblDALEvaluator.setText(i18nManager.getTranslation("_default_expression_evaluator"));
131
      jpanel1.add(lblDALEvaluator,cc.xy(2,2));
132

    
133
      cboDALEvaluator.setName("cboDALEvaluator");
134
      jpanel1.add(cboDALEvaluator,cc.xy(4,2));
135

    
136
      txtAccuracy.setName("txtAccuracy");
137
      jpanel1.add(txtAccuracy,cc.xy(4,4));
138

    
139
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5 });
140
      return jpanel1;
141
   }
142

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

    
152

    
153
}