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 / DefaultHistoryPanelView.java @ 2314

History | View | Annotate | Download (4.53 KB)

1
package org.gvsig.tools.swing.impl.bookmarkshistory;
2

    
3
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 javax.swing.Box;
10
import javax.swing.ImageIcon;
11
import javax.swing.JList;
12
import javax.swing.JPanel;
13
import javax.swing.JScrollPane;
14
import javax.swing.JTextArea;
15

    
16

    
17
public class DefaultHistoryPanelView extends JPanel
18
{
19
   JList lstHistory = new JList();
20
   JTextArea txtFormula = new JTextArea();
21

    
22
   /**
23
    * Default constructor
24
    */
25
   public DefaultHistoryPanelView()
26
   {
27
      initializePanel();
28
   }
29

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

    
40
      boolean filled_cell_11 = false;
41
      CellConstraints cc = new CellConstraints();
42
      if ( cols.length > 0 && rows.length > 0 )
43
      {
44
         if ( cols[0] == 1 && rows[0] == 1 )
45
         {
46
            /** add a rigid area  */
47
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
48
            filled_cell_11 = true;
49
         }
50
      }
51

    
52
      for( int index = 0; index < cols.length; index++ )
53
      {
54
         if ( cols[index] == 1 && filled_cell_11 )
55
         {
56
            continue;
57
         }
58
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
59
      }
60

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

    
70
   }
71

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

    
97
   /**
98
    * Method for recalculating the component orientation for 
99
    * right-to-left Locales.
100
    * @param orientation the component orientation to be applied
101
    */
102
   public void applyComponentOrientation( ComponentOrientation orientation )
103
   {
104
      // Not yet implemented...
105
      // I18NUtils.applyComponentOrientation(this, orientation);
106
      super.applyComponentOrientation(orientation);
107
   }
108

    
109
   public JPanel createPanel()
110
   {
111
      JPanel jpanel1 = new JPanel();
112
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(0.2),CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(0.8),CENTER:2DLU:NONE");
113
      CellConstraints cc = new CellConstraints();
114
      jpanel1.setLayout(formlayout1);
115

    
116
      lstHistory.setName("lstHistory");
117
      JScrollPane jscrollpane1 = new JScrollPane();
118
      jscrollpane1.setViewportView(lstHistory);
119
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
120
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
121
      jpanel1.add(jscrollpane1,cc.xy(2,2));
122

    
123
      txtFormula.setName("txtFormula");
124
      JScrollPane jscrollpane2 = new JScrollPane();
125
      jscrollpane2.setViewportView(txtFormula);
126
      jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
127
      jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
128
      jpanel1.add(jscrollpane2,cc.xy(2,4));
129

    
130
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 });
131
      return jpanel1;
132
   }
133

    
134
   /**
135
    * Initializer
136
    */
137
   protected void initializePanel()
138
   {
139
      setLayout(new BorderLayout());
140
      add(createPanel(), BorderLayout.CENTER);
141
   }
142

    
143

    
144
}