Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.gui / src / main / java / es / unex / sextante / gui / toolbox / TransparentScrollPane.java @ 541

History | View | Annotate | Download (1.74 KB)

1
package es.unex.sextante.gui.toolbox;
2

    
3
import java.awt.Component;
4
import java.awt.Graphics;
5
import javax.swing.ImageIcon;
6
import javax.swing.JComponent;
7
import javax.swing.JScrollPane;
8
import javax.swing.JViewport;
9

    
10
public class TransparentScrollPane
11
         extends
12
            JScrollPane {
13

    
14
   ImageIcon image = null;
15

    
16

    
17
   public TransparentScrollPane(final Component view,
18
                                final int vsbPolicy,
19
                                final int hsbPolicy) {
20

    
21
      super(view, vsbPolicy, hsbPolicy);
22
      if (view instanceof JComponent) {
23
         ((JComponent) view).setOpaque(false);
24
      }
25

    
26
      this.setOpaque(false);
27
      this.getViewport().setOpaque(false);
28

    
29
   }
30

    
31

    
32
   public TransparentScrollPane(final Component view) {
33

    
34
      this(view, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
35

    
36
   }
37

    
38

    
39
   public TransparentScrollPane(final int vsbPolicy,
40
                                final int hsbPolicy) {
41

    
42
      this(null, vsbPolicy, hsbPolicy);
43

    
44
   }
45

    
46

    
47
   public TransparentScrollPane() {
48

    
49
      this(null, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED);
50
   }
51

    
52

    
53
   @Override
54
   public void paintComponent(final Graphics g) {
55

    
56

    
57
      if (image != null) {
58
        g.setColor(this.getBackground());
59
        g.fillRect(0, 0, this.getWidth(), this.getHeight());
60
         final int h = image.getIconHeight();
61
         final int w = image.getIconWidth();
62
         g.drawImage(image.getImage(), getWidth() - w, getHeight() - h, null, null);
63
         getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);
64
      }
65
      super.paintComponent(g);
66

    
67
   }
68

    
69

    
70
   public void setBackgroundImage(final ImageIcon image) {
71

    
72
      this.image = image;
73

    
74
   }
75

    
76
}