19 package org.sleuthkit.autopsy.corecomponents;
21 import java.awt.Component;
22 import java.awt.Container;
23 import java.awt.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.Insets;
26 import javax.swing.JScrollPane;
27 import javax.swing.SwingUtilities;
35 class WrapLayout
extends FlowLayout {
53 public WrapLayout(
int align) {
69 public WrapLayout(
int align,
int hgap,
int vgap) {
70 super(align, hgap, vgap);
83 public Dimension preferredLayoutSize(Container target) {
84 return layoutSize(target,
true);
97 public Dimension minimumLayoutSize(Container target) {
98 Dimension minimum = layoutSize(target,
false);
99 minimum.width -= (getHgap() + 1);
112 private Dimension layoutSize(Container target,
boolean preferred) {
113 synchronized (target.getTreeLock()) {
118 int targetWidth = target.getSize().width;
119 Container container = target;
121 while (container.getSize().width == 0 && container.getParent() != null) {
122 container = container.getParent();
125 targetWidth = container.getSize().width;
127 if (targetWidth == 0) {
128 targetWidth = Integer.MAX_VALUE;
131 int hgap = getHgap();
132 int vgap = getVgap();
133 Insets insets = target.getInsets();
134 int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
135 int maxWidth = targetWidth - horizontalInsetsAndGap;
138 Dimension dim =
new Dimension(0, 0);
142 int nmembers = target.getComponentCount();
144 for (
int i = 0; i < nmembers; i++) {
145 Component m = target.getComponent(i);
148 Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
151 if (rowWidth + d.width > maxWidth) {
152 addRow(dim, rowWidth, rowHeight);
163 rowHeight = Math.max(rowHeight, d.height);
167 addRow(dim, rowWidth, rowHeight);
169 dim.width += horizontalInsetsAndGap;
170 dim.height += insets.top + insets.bottom + vgap * 2;
176 Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
178 if (scrollPane != null && target.isValid()) {
179 dim.width -= (hgap + 1);
194 private void addRow(Dimension dim,
int rowWidth,
int rowHeight) {
195 dim.width = Math.max(dim.width, rowWidth);
197 if (dim.height > 0) {
198 dim.height += getVgap();
201 dim.height += rowHeight;