Statistics
| Revision:

gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / bookmarkshistory / DefaultBookmarksPanelView.java @ 2339

History | View | Annotate | Download (7.35 KB)

1 1986 omartinez
package org.gvsig.tools.swing.impl.bookmarkshistory;
2 2314 omartinez
import com.jeta.open.i18n.I18NUtils;
3 1986 omartinez
import com.jgoodies.forms.layout.CellConstraints;
4
import com.jgoodies.forms.layout.FormLayout;
5
import java.awt.BorderLayout;
6
import java.awt.ComponentOrientation;
7
import java.awt.Container;
8
import java.awt.Dimension;
9
import java.awt.event.WindowAdapter;
10
import java.awt.event.WindowEvent;
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JFrame;
15
import javax.swing.JLabel;
16
import javax.swing.JList;
17
import javax.swing.JPanel;
18
import javax.swing.JScrollPane;
19
import javax.swing.JTextArea;
20
import javax.swing.JTextField;
21
22
23
public class DefaultBookmarksPanelView extends JPanel
24
{
25
   JList lstBookmarks = new JList();
26
   JLabel lblName = new JLabel();
27
   JLabel lblLastUse = new JLabel();
28 2314 omartinez
   JLabel lblLabel = new JLabel();
29 1986 omartinez
   JTextArea txtLabel = new JTextArea();
30
   JTextField txtName = new JTextField();
31
   JTextField txtLastUse = new JTextField();
32
   JButton btnDelete = new JButton();
33
   JButton btnModify = new JButton();
34
   JButton btnAccept = new JButton();
35
   JButton btnDiscard = new JButton();
36
37
   /**
38
    * Default constructor
39
    */
40
   public DefaultBookmarksPanelView()
41
   {
42
      initializePanel();
43
   }
44
45
   /**
46
    * Adds fill components to empty cells in the first row and first column of the grid.
47
    * This ensures that the grid spacing will be the same as shown in the designer.
48
    * @param cols an array of column indices in the first row where fill components should be added.
49
    * @param rows an array of row indices in the first column where fill components should be added.
50
    */
51
   void addFillComponents( Container panel, int[] cols, int[] rows )
52
   {
53
      Dimension filler = new Dimension(10,10);
54
55
      boolean filled_cell_11 = false;
56
      CellConstraints cc = new CellConstraints();
57
      if ( cols.length > 0 && rows.length > 0 )
58
      {
59
         if ( cols[0] == 1 && rows[0] == 1 )
60
         {
61
            /** add a rigid area  */
62
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
63
            filled_cell_11 = true;
64
         }
65
      }
66
67
      for( int index = 0; index < cols.length; index++ )
68
      {
69
         if ( cols[index] == 1 && filled_cell_11 )
70
         {
71
            continue;
72
         }
73
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
74
      }
75
76
      for( int index = 0; index < rows.length; index++ )
77
      {
78
         if ( rows[index] == 1 && filled_cell_11 )
79
         {
80
            continue;
81
         }
82
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
83
      }
84
85
   }
86
87
   /**
88
    * Helper method to load an image file from the CLASSPATH
89
    * @param imageName the package and name of the file to load relative to the CLASSPATH
90
    * @return an ImageIcon instance with the specified image file
91
    * @throws IllegalArgumentException if the image resource cannot be loaded.
92
    */
93
   public ImageIcon loadImage( String imageName )
94
   {
95
      try
96
      {
97
         ClassLoader classloader = getClass().getClassLoader();
98
         java.net.URL url = classloader.getResource( imageName );
99
         if ( url != null )
100
         {
101
            ImageIcon icon = new ImageIcon( url );
102
            return icon;
103
         }
104
      }
105
      catch( Exception e )
106
      {
107
         e.printStackTrace();
108
      }
109
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
110
   }
111
112
   /**
113
    * Method for recalculating the component orientation for
114
    * right-to-left Locales.
115
    * @param orientation the component orientation to be applied
116
    */
117
   public void applyComponentOrientation( ComponentOrientation orientation )
118
   {
119
      // Not yet implemented...
120
      // I18NUtils.applyComponentOrientation(this, orientation);
121
      super.applyComponentOrientation(orientation);
122
   }
123
124
   public JPanel createPanel()
125
   {
126
      JPanel jpanel1 = new JPanel();
127
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(0.7),CENTER:2DLU:NONE,FILL:DEFAULT:GROW(0.3),CENTER:2DLU:NONE");
128
      CellConstraints cc = new CellConstraints();
129
      jpanel1.setLayout(formlayout1);
130
131
      lstBookmarks.setName("lstBookmarks");
132
      JScrollPane jscrollpane1 = new JScrollPane();
133
      jscrollpane1.setViewportView(lstBookmarks);
134
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
135
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
136
      jpanel1.add(jscrollpane1,cc.xywh(2,2,3,1));
137
138
      jpanel1.add(createPanel1(),cc.xy(2,4));
139
      jpanel1.add(createPanel2(),cc.xy(4,4));
140
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5 });
141
      return jpanel1;
142
   }
143
144
   public JPanel createPanel1()
145
   {
146
      JPanel jpanel1 = new JPanel();
147
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:GROW(1.0)");
148
      CellConstraints cc = new CellConstraints();
149
      jpanel1.setLayout(formlayout1);
150
151
      lblName.setName("lblName");
152
      lblName.setText("_Name");
153
      jpanel1.add(lblName,cc.xy(1,1));
154
155
      lblLastUse.setName("lblLastUse");
156 2314 omartinez
      lblLastUse.setText("_Last_use");
157 1986 omartinez
      jpanel1.add(lblLastUse,cc.xy(1,3));
158
159 2314 omartinez
      lblLabel.setName("lblLabel");
160
      lblLabel.setText("_Label");
161
      jpanel1.add(lblLabel,cc.xy(1,5));
162 1986 omartinez
163 2314 omartinez
      txtLabel.setName("txtLabel");
164 1986 omartinez
      JScrollPane jscrollpane1 = new JScrollPane();
165
      jscrollpane1.setViewportView(txtLabel);
166
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
167
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
168
      jpanel1.add(jscrollpane1,new CellConstraints(1,7,3,1,CellConstraints.DEFAULT,CellConstraints.FILL));
169
170
      txtName.setName("txtName");
171
      jpanel1.add(txtName,cc.xy(3,1));
172
173
      txtLastUse.setName("txtLastUse");
174
      jpanel1.add(txtLastUse,cc.xy(3,3));
175
176
      addFillComponents(jpanel1,new int[]{ 2 },new int[]{ 2,4,6 });
177
      return jpanel1;
178
   }
179
180
   public JPanel createPanel2()
181
   {
182
      JPanel jpanel1 = new JPanel();
183
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0)");
184
      CellConstraints cc = new CellConstraints();
185
      jpanel1.setLayout(formlayout1);
186
187
      btnDelete.setActionCommand("Delete");
188
      btnDelete.setName("btnDelete");
189 2314 omartinez
      btnDelete.setText("_Delete");
190 1986 omartinez
      jpanel1.add(btnDelete,cc.xy(1,1));
191
192
      btnModify.setActionCommand("Delete");
193
      btnModify.setName("btnModify");
194 2314 omartinez
      btnModify.setText("_Modify");
195 1986 omartinez
      jpanel1.add(btnModify,cc.xy(1,3));
196
197
      btnAccept.setActionCommand("Delete");
198
      btnAccept.setName("btnAccept");
199 2314 omartinez
      btnAccept.setText("_Accept");
200 1986 omartinez
      jpanel1.add(btnAccept,cc.xy(1,5));
201
202
      btnDiscard.setActionCommand("Delete");
203
      btnDiscard.setName("btnDiscard");
204 2314 omartinez
      btnDiscard.setText("_Discard");
205 1986 omartinez
      jpanel1.add(btnDiscard,cc.xy(1,7));
206
207
      addFillComponents(jpanel1,new int[0],new int[]{ 2,4,6,8 });
208
      return jpanel1;
209
   }
210
211
   /**
212
    * Initializer
213
    */
214
   protected void initializePanel()
215
   {
216
      setLayout(new BorderLayout());
217
      add(createPanel(), BorderLayout.CENTER);
218
   }
219
220
221
}