01: /*
02: * PgsScrollPaneUI.java
03: *
04: * Created on 15. Mai 2005, 14:21
05: */
06:
07: package com.pagosoft.plaf;
08:
09: import javax.swing.*;
10: import javax.swing.border.*;
11: import javax.swing.plaf.*;
12: import javax.swing.plaf.metal.*;
13: import java.awt.*;
14: import java.awt.event.*;
15:
16: /**
17: * @author pago
18: */
19: public class PgsScrollPaneUI extends MetalScrollPaneUI {
20: public static ComponentUI createUI(JComponent x) {
21: return new PgsScrollPaneUI();
22: }
23:
24: public void installUI(JComponent c) {
25: super .installUI(c);
26: maybeRemoveBorder(scrollpane.getViewport().getView());
27: }
28:
29: private ScrollPaneContainerListener scrollPaneContainerListener;
30:
31: public void installListeners(JScrollPane c) {
32: super .installListeners(c);
33: if (scrollPaneContainerListener == null) {
34: scrollPaneContainerListener = new ScrollPaneContainerListener();
35: }
36: c.getViewport().addContainerListener(
37: scrollPaneContainerListener);
38: }
39:
40: public void uninstallListeners(JScrollPane c) {
41: super .uninstallListeners(c);
42: c.getViewport().removeContainerListener(
43: scrollPaneContainerListener);
44: }
45:
46: private Border lastChildBorder;
47:
48: public void maybeRemoveBorder(Component c) {
49: if (c instanceof JComponent) {
50: JComponent child = (JComponent) c;
51: lastChildBorder = child.getBorder();
52: child.setBorder(null);
53: }
54: }
55:
56: public void maybeAddBorder(Component c) {
57: if (c instanceof JComponent && lastChildBorder != null) {
58: JComponent child = (JComponent) c;
59: child.setBorder(lastChildBorder);
60: lastChildBorder = null;
61: }
62: }
63:
64: protected class ScrollPaneContainerListener implements
65: ContainerListener {
66: public void componentAdded(ContainerEvent e) {
67: maybeRemoveBorder(e.getChild());
68: }
69:
70: public void componentRemoved(ContainerEvent e) {
71: maybeAddBorder(e.getChild());
72: }
73: }
74: }
|