| 1 19 20 package org.netbeans.modules.subversion.ui.diff; 21 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.Insets ; 26 import java.awt.LayoutManager ; 27 28 37 public class VerticalFlowLayout implements LayoutManager { 38 39 private final Component parent; 40 41 45 public VerticalFlowLayout(Component parent) { 46 this.parent = parent; 47 } 48 49 public void addLayoutComponent(String name, Component comp) { 50 } 51 52 public void removeLayoutComponent(Component comp) { 53 } 54 55 public Dimension preferredLayoutSize(Container target) { 56 synchronized (target.getTreeLock()) { 57 Dimension dim = new Dimension (0, 0); 58 int nmembers = target.getComponentCount(); 59 60 for (int i = 0 ; i < nmembers ; i++) { 61 Component m = target.getComponent(i); 62 if (m.isVisible()) { 63 Dimension d = m.getPreferredSize(); 64 dim.width = Math.max(dim.width, d.width); 65 dim.height += d.height; 66 } 67 } 68 Insets insets = target.getInsets(); 69 dim.width += insets.left + insets.right; 70 dim.height += insets.top + insets.bottom; 71 return dim; 72 } 73 } 74 75 public Dimension minimumLayoutSize(Container target) { 76 synchronized (target.getTreeLock()) { 77 Dimension dim = new Dimension (0, 0); 78 int nmembers = target.getComponentCount(); 79 80 for (int i = 0 ; i < nmembers ; i++) { 81 Component m = target.getComponent(i); 82 if (m.isVisible()) { 83 Dimension d = m.getMinimumSize(); 84 dim.width = Math.max(dim.width, d.width); 85 dim.height += d.height; 86 } 87 } 88 Insets insets = target.getInsets(); 89 dim.width += insets.left + insets.right; 90 dim.height += insets.top + insets.bottom; 91 return dim; 92 } 93 } 94 95 public void layoutContainer(Container target) { 96 97 synchronized (target.getTreeLock()) { 98 Insets insets = target.getInsets(); 99 int maxwidth = parent.getWidth() - (insets.left + insets.right); 100 int nmembers = target.getComponentCount(); 101 int x = insets.left, y = insets.top; 102 103 for (int i = 0 ; i < nmembers ; i++) { 104 Component m = target.getComponent(i); 105 if (m.isVisible()) { 106 Dimension d = m.getPreferredSize(); 107 m.setSize(maxwidth, d.height); 108 m.setLocation(x, y); 109 y += d.height; 110 } 111 } 112 } 113 } 114 115 } 116 | Popular Tags |