1 19 24 25 package org.netbeans.modules.xml.text.navigator; 26 27 import java.awt.*; 28 29 35 final class TrivialLayout implements LayoutManager { 36 public void addLayoutComponent (String name, Component comp) { 37 } 39 40 public void removeLayoutComponent (Component comp) { 41 } 43 44 public void layoutContainer (Container parent) { 45 if ( parent instanceof TapPanel ) { 46 layoutTapPanel ( (TapPanel) parent ); 47 } else { 48 layoutComp ( parent ); 49 } 50 } 51 52 55 private void layoutComp (Container parent) { 56 Component[] c = parent.getComponents (); 57 if ( c.length > 1 ) { 58 Dimension d1 = c[ 0 ].getPreferredSize (); 59 Dimension d2 = c[ 1 ].getPreferredSize (); 60 int labely = 0; 61 d1.width += 10; if ( d2.height > d1.height ) { 63 labely = ( d2.height / 2 ) - ( d1.height / 2 ); 64 } 65 if ( parent.getWidth () - d1.width < d2.width ) { 66 c[ 0 ].setBounds ( 0, 0, 0, 0 ); 67 c[ 1 ].setBounds ( 0, 0, parent.getWidth (), parent.getHeight () ); 68 } else { 69 c[ 0 ].setBounds ( 0, labely, d1.width, d1.height ); 70 c[ 1 ].setBounds ( d1.width + 1, 0, parent.getWidth () - d1.width, 71 Math.min ( parent.getHeight (), d2.height ) ); 72 } 73 } 74 } 75 76 79 private void layoutTapPanel (TapPanel tp) { 80 Component[] c = tp.getComponents (); 81 if ( c.length > 1 ) { 82 Dimension d1 = c[ 0 ].getPreferredSize (); 83 Dimension d2 = c[ 1 ].getPreferredSize (); 84 int labely = 0; 85 if ( d2.height > d1.height ) { 86 labely = ( ( d2.height / 2 ) - ( d1.height / 2 ) ) + 2; } 88 89 if ( tp.isExpanded () ) { 90 int top = tp.getOrientation () == tp.UP ? 0 : tp.getMinimumHeight (); 91 int height = Math.min ( tp.getHeight () - tp.getMinimumHeight (), d2.height ); 92 if ( tp.getWidth () - d1.width < d2.width ) { 93 c[ 0 ].setBounds ( 0, 0, 0, 0 ); 94 c[ 1 ].setBounds ( 0, top, tp.getWidth (), height ); 95 } else { 96 c[ 0 ].setBounds ( 0, top + labely, d1.width, d1.height ); 97 c[ 1 ].setBounds ( d1.width + 1, top, tp.getWidth () - d1.width, 98 height ); 99 } 100 } else { 101 c[ 0 ].setBounds ( 0, 0, 0, 0 ); 102 c[ 1 ].setBounds ( 0, 0, 0, 0 ); 103 } 104 } 105 } 106 107 108 public Dimension minimumLayoutSize (Container parent) { 109 Dimension result = new Dimension ( 20, 10 ); 110 Component[] c = parent.getComponents (); 111 TapPanel tp = (TapPanel) parent; 112 if ( c.length > 1 ) { 113 Dimension d1 = c[ 0 ].getPreferredSize (); 114 Dimension d2 = c[ 1 ].getPreferredSize (); 115 result.width = d1.width + d2.width; 116 result.height = tp.isExpanded () ? Math.max ( d1.height, d2.height ) + tp.getMinimumHeight () : tp.getMinimumHeight (); 117 } 118 return result; 119 } 120 121 public Dimension preferredLayoutSize (Container parent) { 122 return minimumLayoutSize ( parent ); 123 } 124 } 125 126 | Popular Tags |