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 @ 46829

History | View | Annotate | Download (8.76 KB)

1
package org.gvsig.app.extension.dispose;
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.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.JFrame;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JSplitPane;
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
   JButton refreshButton = new JButton();
25
   JSplitPane splitPanel = new JSplitPane();
26
   JLabel lblTotalMemory = new JLabel();
27
   JLabel lblFreeMemory = new JLabel();
28
   JLabel lblMaxMemory = new JLabel();
29
   JLabel lblActiveThreads = new JLabel();
30
   JLabel lblObjectPendingFinalization = new JLabel();
31
   JLabel messageLabel = new JLabel();
32
   JButton btnGC = new JButton();
33
   JButton btnRefreshMemory = new JButton();
34

    
35
   /**
36
    * Default constructor
37
    */
38
   public DisposablesDoListLayout()
39
   {
40
      initializePanel();
41
   }
42

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

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

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

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

    
83
   }
84

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

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

    
122
   public JPanel createPanel()
123
   {
124
      JPanel jpanel1 = new JPanel();
125
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,CENTER: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,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:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
126
      CellConstraints cc = new CellConstraints();
127
      jpanel1.setLayout(formlayout1);
128

    
129
      JLabel jlabel1 = new JLabel();
130
      jlabel1.setText("Disposables do list");
131
      jpanel1.add(jlabel1,cc.xywh(2,2,12,1));
132

    
133
      disposeButton.setActionCommand("Dispose");
134
      disposeButton.setEnabled(false);
135
      disposeButton.setName("disposeButton");
136
      disposeButton.setText("Dispose");
137
      jpanel1.add(disposeButton,cc.xy(11,6));
138

    
139
      closeButton.setActionCommand("Close");
140
      closeButton.setName("closeButton");
141
      closeButton.setText("Close");
142
      jpanel1.add(closeButton,cc.xy(13,6));
143

    
144
      disposeAllButton.setActionCommand("Dispose all");
145
      disposeAllButton.setName("disposeAllButton");
146
      disposeAllButton.setText("Dispose all");
147
      jpanel1.add(disposeAllButton,cc.xy(9,6));
148

    
149
      refreshButton.setActionCommand("Refresh");
150
      refreshButton.setName("refreshButton");
151
      refreshButton.setText("Refresh");
152
      jpanel1.add(refreshButton,cc.xy(7,6));
153

    
154
      splitPanel.setDividerLocation(40);
155
      splitPanel.setLastDividerLocation(-1);
156
      splitPanel.setName("splitPanel");
157
      splitPanel.setOneTouchExpandable(true);
158
      splitPanel.setOrientation(0);
159
      jpanel1.add(splitPanel,cc.xywh(2,4,12,1));
160

    
161
      jpanel1.add(createPanel1(),cc.xywh(2,8,12,1));
162
      messageLabel.setName("messageLabel");
163
      messageLabel.setText("Pending ?");
164
      messageLabel.setHorizontalAlignment(JLabel.TRAILING);
165
      jpanel1.add(messageLabel,new CellConstraints(2,6,1,1,CellConstraints.LEFT,CellConstraints.DEFAULT));
166

    
167
      btnGC.setActionCommand("GC");
168
      btnGC.setName("btnGC");
169
      btnGC.setText("GC");
170
      jpanel1.add(btnGC,cc.xy(5,6));
171

    
172
      btnRefreshMemory.setActionCommand("Refresh memory        ");
173
      btnRefreshMemory.setName("btnRefreshMemory");
174
      btnRefreshMemory.setText("Refresh memory        ");
175
      jpanel1.add(btnRefreshMemory,cc.xy(3,6));
176

    
177
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14 },new int[]{ 1,2,3,4,5,6,7,8,9 });
178
      return jpanel1;
179
   }
180

    
181
   public JPanel createPanel1()
182
   {
183
      JPanel jpanel1 = new JPanel();
184
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
185
      CellConstraints cc = new CellConstraints();
186
      jpanel1.setLayout(formlayout1);
187

    
188
      JLabel jlabel1 = new JLabel();
189
      jlabel1.setText("Total mem.");
190
      jlabel1.setToolTipText("Total memory in Kb");
191
      jpanel1.add(jlabel1,cc.xy(1,1));
192

    
193
      JLabel jlabel2 = new JLabel();
194
      jlabel2.setText("Free mem.");
195
      jpanel1.add(jlabel2,cc.xy(5,1));
196

    
197
      JLabel jlabel3 = new JLabel();
198
      jlabel3.setText("Max mem.");
199
      jpanel1.add(jlabel3,cc.xy(9,1));
200

    
201
      lblTotalMemory.setName("lblTotalMemory");
202
      lblTotalMemory.setText("0");
203
      lblTotalMemory.setToolTipText("Total memory in Kb");
204
      jpanel1.add(lblTotalMemory,cc.xy(3,1));
205

    
206
      lblFreeMemory.setName("lblFreeMemory");
207
      lblFreeMemory.setText("0");
208
      lblFreeMemory.setToolTipText("Free memory in Kb");
209
      jpanel1.add(lblFreeMemory,cc.xy(7,1));
210

    
211
      lblMaxMemory.setName("lblMaxMemory");
212
      lblMaxMemory.setText("0");
213
      lblMaxMemory.setToolTipText("Max memory in kb");
214
      jpanel1.add(lblMaxMemory,cc.xy(11,1));
215

    
216
      JLabel jlabel4 = new JLabel();
217
      jlabel4.setText("Threads");
218
      jlabel4.setToolTipText("Active threads");
219
      jpanel1.add(jlabel4,cc.xy(13,1));
220

    
221
      lblActiveThreads.setName("lblActiveThreads");
222
      lblActiveThreads.setText("0");
223
      lblActiveThreads.setToolTipText("Active threads");
224
      jpanel1.add(lblActiveThreads,cc.xy(15,1));
225

    
226
      JLabel jlabel5 = new JLabel();
227
      jlabel5.setText("O.P.F");
228
      jlabel5.setToolTipText("Objects pending finalization count.");
229
      jpanel1.add(jlabel5,cc.xy(17,1));
230

    
231
      lblObjectPendingFinalization.setName("lblObjectPendingFinalization");
232
      lblObjectPendingFinalization.setText("0");
233
      lblObjectPendingFinalization.setToolTipText("Objects pending finalization count.");
234
      jpanel1.add(lblObjectPendingFinalization,cc.xy(19,1));
235

    
236
      addFillComponents(jpanel1,new int[]{ 2,4,6,8,10,12,14,16,18 },new int[0]);
237
      return jpanel1;
238
   }
239

    
240
   /**
241
    * Initializer
242
    */
243
   protected void initializePanel()
244
   {
245
      setLayout(new BorderLayout());
246
      add(createPanel(), BorderLayout.CENTER);
247
   }
248

    
249

    
250
}