1 19 20 package org.netbeans.swing.tabcontrol.plaf; 21 22 import java.awt.*; 23 import javax.swing.JComponent ; 24 25 33 class StackLayout implements LayoutManager { 34 37 private static Dimension emptySize = null; 38 41 private Component visibleComp = null; 42 43 47 public void showComponent(Component c, Container parent) { 48 if (visibleComp != c) { 49 if (!parent.isAncestorOf(c) && c != null) { 50 parent.add(c); 51 } 52 synchronized (parent.getTreeLock()) { 53 if (visibleComp != null) { 54 visibleComp.setVisible(false); 55 } 56 visibleComp = c; 57 if (c != null) { 58 visibleComp.setVisible(true); 59 } 60 if (c instanceof JComponent ) { 62 ((JComponent )c).revalidate(); 63 } 64 else { 65 parent.validate(); } 67 } 68 } 69 } 70 71 72 public Component getVisibleComponent() { 73 return visibleComp; 74 } 75 76 79 80 public void addLayoutComponent(String name, Component comp) { 81 synchronized (comp.getTreeLock()) { 82 comp.setVisible(false); 83 if (comp == visibleComp) { 86 visibleComp = null; 87 } 88 90 } 91 } 92 93 108 109 public void removeLayoutComponent(Component comp) { 110 synchronized (comp.getTreeLock()) { 111 if (comp == visibleComp) { 112 visibleComp = null; 113 } 114 comp.setVisible(true); 117 } 118 } 119 120 public void layoutContainer(Container parent) { 121 if (visibleComp != null) { 122 synchronized (parent.getTreeLock()) { 123 Insets insets = parent.getInsets(); 124 visibleComp.setBounds(insets.left, insets.top, parent.getWidth() 125 - (insets.left + insets.right), parent.getHeight() 126 - (insets.top + insets.bottom)); 127 } 128 } 129 } 130 131 public Dimension minimumLayoutSize(Container parent) { 132 return getEmptySize(); 133 } 134 135 public Dimension preferredLayoutSize(Container parent) { 136 return getEmptySize(); 137 } 138 139 142 private static Dimension getEmptySize() { 143 return new Dimension(50, 50); 144 } 145 146 } | Popular Tags |