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 / extension / dispose / DisposablesDoListLayout.java @ 41043

History | View | Annotate | Download (5.38 KB)

1
package org.gvsig.app.extension.dispose;
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.JButton;
11
import javax.swing.JLabel;
12
import javax.swing.JPanel;
13
import javax.swing.JSplitPane;
14

    
15
import com.jgoodies.forms.layout.CellConstraints;
16
import com.jgoodies.forms.layout.FormLayout;
17

    
18

    
19
public class DisposablesDoListLayout extends JPanel
20
{
21
   JButton disposeButton = new JButton();
22
   JButton closeButton = new JButton();
23
   JButton disposeAllButton = new JButton();
24
   JLabel messageLabel = new JLabel();
25
   JButton refreshButton = new JButton();
26
   JSplitPane splitPanel = new JSplitPane();
27

    
28
   /**
29
    * Default constructor
30
    */
31
   public DisposablesDoListLayout()
32
   {
33
      initializePanel();
34
   }
35

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

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

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

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

    
76
   }
77

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

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

    
115
   public JPanel createPanel()
116
   {
117
      JPanel jpanel1 = new JPanel();
118
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL: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");
119
      CellConstraints cc = new CellConstraints();
120
      jpanel1.setLayout(formlayout1);
121

    
122
      JLabel jlabel1 = new JLabel();
123
      jlabel1.setText("Disposables do list");
124
      jpanel1.add(jlabel1,cc.xywh(2,2,8,1));
125

    
126
      disposeButton.setActionCommand("Dispose");
127
      disposeButton.setEnabled(false);
128
      disposeButton.setName("disposeButton");
129
      disposeButton.setText("Dispose");
130
      jpanel1.add(disposeButton,cc.xy(7,6));
131

    
132
      closeButton.setActionCommand("Close");
133
      closeButton.setName("closeButton");
134
      closeButton.setText("Close");
135
      jpanel1.add(closeButton,cc.xy(9,6));
136

    
137
      disposeAllButton.setActionCommand("Dispose all");
138
      disposeAllButton.setName("disposeAllButton");
139
      disposeAllButton.setText("Dispose all");
140
      jpanel1.add(disposeAllButton,cc.xy(5,6));
141

    
142
      messageLabel.setName("messageLabel");
143
      jpanel1.add(messageLabel,cc.xy(2,6));
144

    
145
      refreshButton.setActionCommand("Refresh");
146
      refreshButton.setName("refreshButton");
147
      refreshButton.setText("Refresh");
148
      jpanel1.add(refreshButton,cc.xy(3,6));
149

    
150
      splitPanel.setDividerLocation(120);
151
      splitPanel.setLastDividerLocation(-1);
152
      splitPanel.setName("splitPanel");
153
      splitPanel.setOneTouchExpandable(true);
154
      splitPanel.setOrientation(0);
155
      jpanel1.add(splitPanel,cc.xywh(2,4,8,1));
156

    
157
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10 },new int[]{ 1,2,3,4,5,6,7 });
158
      return jpanel1;
159
   }
160

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

    
170

    
171
}