1 19 20 package org.netbeans.core.windows.view.ui; 21 22 import java.awt.Component ; 23 import org.netbeans.core.windows.view.ViewElement; 24 25 28 class MultiSplitCell { 29 30 private ViewElement view; 31 private double normalizedResizeWeight = 0.0; 33 private double initialSplitWeight; 34 private int requiredSize = -1; 36 private boolean dirty = false; 37 private boolean isHorizontalSplit; 38 39 MultiSplitCell( ViewElement view, double initialSplitWeight, boolean isHorizontalSplit ) { 40 this.view = view; 41 this.initialSplitWeight = initialSplitWeight; 42 this.isHorizontalSplit = isHorizontalSplit; 43 } 44 45 public boolean equals( Object o ) { 46 if( o instanceof MultiSplitCell ) { 47 MultiSplitCell cell = (MultiSplitCell)o; 48 return getComponent().equals( cell.getComponent() ); 49 } 50 return super.equals( o ); 51 } 52 53 boolean isDirty() { 54 return dirty; 55 } 56 57 void setDirty( boolean isDirty ) { 58 this.dirty = isDirty; 59 } 60 61 void maybeResetToInitialSize( int newSize ) { 62 if( -1 == requiredSize ) { 63 requiredSize = getSize(); 64 if( requiredSize <= 0 || requiredSize >= newSize ) { 65 requiredSize = (int)(newSize * initialSplitWeight + 0.5); 66 } 67 dirty = true; 68 } 69 } 70 71 double getResizeWeight() { 72 return view.getResizeWeight(); 73 } 74 75 Component getComponent() { 76 return view.getComponent(); 77 } 78 79 84 int getMinimumSize() { 85 if( isHorizontalSplit ) 86 return getComponent().getMinimumSize().width; 87 return getComponent().getMinimumSize().height; 88 } 89 90 int getRequiredSize() { 91 if( -1 == requiredSize ) { 92 if( isHorizontalSplit ) 93 return getComponent().getPreferredSize().width; 94 return getComponent().getPreferredSize().height; 95 } 96 return requiredSize; 97 } 98 101 void layout( int x, int y, int width, int height ) { 102 if( isHorizontalSplit ) { 103 dirty |= x != getLocation() || requiredSize != width; 104 requiredSize = width; 105 } else { 106 dirty |= y != getLocation() || requiredSize != height; 107 requiredSize = height; 108 } 109 getComponent().setBounds( x, y, width, height ); 110 } 111 112 void setRequiredSize( int newRequiredSize ) { 113 dirty |= newRequiredSize != requiredSize; 114 this.requiredSize = newRequiredSize; 115 } 116 117 int getLocation() { 118 if( isHorizontalSplit ) 119 return getComponent().getLocation().x; 120 return getComponent().getLocation().y; 121 } 122 123 int getSize() { 124 if( isHorizontalSplit ) 125 return getComponent().getSize().width; 126 return getComponent().getSize().height; 127 } 128 129 double getNormalizedResizeWeight() { 130 return normalizedResizeWeight; 131 } 132 133 void setNormalizedResizeWeight( double newNormalizedResizeWeight ) { 134 this.normalizedResizeWeight = newNormalizedResizeWeight; 135 } 136 137 ViewElement getViewElement() { 138 return view; 139 } 140 } 141 | Popular Tags |