1 42 package org.jfree.ui; 43 44 import java.awt.Component ; 45 import java.awt.Container ; 46 import java.awt.Dimension ; 47 import java.awt.Insets ; 48 import java.awt.LayoutManager ; 49 import java.awt.Rectangle ; 50 51 60 public final class OverlayLayout implements LayoutManager { 61 62 66 private boolean ignoreInvisible; 67 68 73 public OverlayLayout(final boolean ignoreInvisible) { 74 this.ignoreInvisible = ignoreInvisible; 75 } 76 77 80 public OverlayLayout() { 81 82 } 83 84 93 public void addLayoutComponent(final String name, final Component comp) { 94 } 95 96 101 public void removeLayoutComponent(final Component comp) { 102 } 103 104 109 public void layoutContainer(final Container parent) { 110 synchronized (parent.getTreeLock()) { 111 final Insets ins = parent.getInsets(); 112 113 final Rectangle bounds = parent.getBounds(); 114 final int width = bounds.width - ins.left - ins.right; 115 final int height = bounds.height - ins.top - ins.bottom; 116 117 final Component [] comps = parent.getComponents(); 118 119 for (int i = 0; i < comps.length; i++) { 120 final Component c = comps[i]; 121 if ((comps[i].isVisible() == false) && this.ignoreInvisible) { 122 continue; 123 } 124 c.setBounds(ins.left, ins.top, width, height); 125 } 126 } 127 } 128 129 137 public Dimension minimumLayoutSize(final Container parent) { 138 synchronized (parent.getTreeLock()) { 139 final Insets ins = parent.getInsets(); 140 final Component [] comps = parent.getComponents(); 141 int height = 0; 142 int width = 0; 143 for (int i = 0; i < comps.length; i++) { 144 if ((comps[i].isVisible() == false) && this.ignoreInvisible) { 145 continue; 146 } 147 148 final Dimension pref = comps[i].getMinimumSize(); 149 if (pref.height > height) { 150 height = pref.height; 151 } 152 if (pref.width > width) { 153 width = pref.width; 154 } 155 } 156 return new Dimension (width + ins.left + ins.right, 157 height + ins.top + ins.bottom); 158 } 159 } 160 161 169 public Dimension preferredLayoutSize(final Container parent) { 170 synchronized (parent.getTreeLock()) { 171 final Insets ins = parent.getInsets(); 172 final Component [] comps = parent.getComponents(); 173 int height = 0; 174 int width = 0; 175 for (int i = 0; i < comps.length; i++) { 176 if ((comps[i].isVisible() == false) && this.ignoreInvisible) { 177 continue; 178 } 179 180 final Dimension pref = comps[i].getPreferredSize(); 181 if (pref.height > height) { 182 height = pref.height; 183 } 184 if (pref.width > width) { 185 width = pref.width; 186 } 187 } 188 return new Dimension (width + ins.left + ins.right, 189 height + ins.top + ins.bottom); 190 } 191 } 192 193 } 194 | Popular Tags |