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 / project / documents / view / toc / actions / LayerErrorsView.java @ 42811

History | View | Annotate | Download (5.85 KB)

1
package org.gvsig.app.project.documents.view.toc.actions;
2

    
3
import com.jeta.open.i18n.I18NUtils;
4
import com.jgoodies.forms.layout.CellConstraints;
5
import com.jgoodies.forms.layout.FormLayout;
6
import java.awt.BorderLayout;
7
import java.awt.Color;
8
import java.awt.ComponentOrientation;
9
import java.awt.Container;
10
import java.awt.Dimension;
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JEditorPane;
15
import javax.swing.JFrame;
16
import javax.swing.JLabel;
17
import javax.swing.JPanel;
18
import javax.swing.JScrollPane;
19
import javax.swing.JTextField;
20

    
21

    
22
public class LayerErrorsView extends JPanel
23
{
24
   JLabel lblLayer = new JLabel();
25
   JTextField txtLayerName = new JTextField();
26
   JLabel lblProblem = new JLabel();
27
   JEditorPane txtMessage = new JEditorPane();
28
   JButton btnClose = new JButton();
29
   JButton btnViewParameters = new JButton();
30

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

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

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

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

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

    
79
   }
80

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

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

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

    
125
      lblLayer.setName("lblLayer");
126
      lblLayer.setText("Layer:");
127
      jpanel1.add(lblLayer,cc.xy(2,2));
128

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

    
134
      lblProblem.setName("lblProblem");
135
      lblProblem.setText("Problem:");
136
      jpanel1.add(lblProblem,cc.xy(2,4));
137

    
138
      txtMessage.setEditable(false);
139
      txtMessage.setName("txtMessage");
140
      JScrollPane jscrollpane1 = new JScrollPane();
141
      jscrollpane1.setViewportView(txtMessage);
142
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
143
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
144
      jpanel1.add(jscrollpane1,cc.xywh(2,6,3,1));
145

    
146
      jpanel1.add(createPanel1(),cc.xywh(2,8,3,1));
147
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9 });
148
      return jpanel1;
149
   }
150

    
151
   public JPanel createPanel1()
152
   {
153
      JPanel jpanel1 = new JPanel();
154
      FormLayout formlayout1 = new FormLayout("RIGHT:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
155
      CellConstraints cc = new CellConstraints();
156
      jpanel1.setLayout(formlayout1);
157

    
158
      btnClose.setActionCommand("Close");
159
      btnClose.setName("btnClose");
160
      btnClose.setText("Close");
161
      jpanel1.add(btnClose,cc.xy(3,1));
162

    
163
      btnViewParameters.setActionCommand("View parameters");
164
      btnViewParameters.setName("btnViewParameters");
165
      btnViewParameters.setText("View properties of data source");
166
      jpanel1.add(btnViewParameters,cc.xy(1,1));
167

    
168
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
169
      return jpanel1;
170
   }
171

    
172
   /**
173
    * Initializer
174
    */
175
   protected void initializePanel()
176
   {
177
      setLayout(new BorderLayout());
178
      add(createPanel(), BorderLayout.CENTER);
179
   }
180

    
181

    
182
}