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