1 19 20 package com.sshtools.ui.awt; 21 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.LayoutManager ; 26 27 28 class ToolLayout 29 implements LayoutManager { 30 private Separator separator; 31 32 ToolLayout(Separator separator) { 33 this.separator = separator; 34 } 35 36 public void removeLayoutComponent(Component comp) { 37 } 38 39 public void layoutContainer(Container parent) { 40 int c = parent.getComponentCount(); 41 Dimension s = new Dimension (); 42 Component comp; 43 int x = 0; 44 int w = 0; 45 for (int i = 0; i < c; i++) { 46 comp = parent.getComponent(i); 47 if (comp == separator) { 48 w = parent.getSize().width; 49 comp.setBounds(0, 50 parent.getSize().height - 51 separator.getPreferredSize().height, w, 52 separator.getPreferredSize().height); 53 } 54 else { 55 w = comp.getPreferredSize().width; 56 comp.setBounds(x, 0, w, 57 parent.getSize().height - 58 separator.getPreferredSize().height); 59 x += w; 60 } 61 } 62 } 63 64 public void addLayoutComponent(String name, Component comp) { 65 } 66 67 public Dimension minimumLayoutSize(Container parent) { 68 int c = parent.getComponentCount(); 69 Dimension s = new Dimension (); 70 Component comp; 71 for (int i = 0; i < c; i++) { 72 comp = parent.getComponent(i); 73 s.width += comp.getMinimumSize().width; 74 s.height = Math.max(s.height, comp.getMinimumSize().height); 75 } 76 s.height += separator.getMinimumSize().height; 77 return s; 78 } 79 80 public Dimension preferredLayoutSize(Container parent) { 81 int c = parent.getComponentCount(); 82 Dimension s = new Dimension (); 83 Component comp; 84 for (int i = 0; i < c; i++) { 85 comp = parent.getComponent(i); 86 s.width += comp.getPreferredSize().width; 87 s.height = Math.max(s.height, comp.getPreferredSize().height); 88 } 89 s.height += separator.getPreferredSize().height; 90 return s; 91 } 92 93 } | Popular Tags |