1 19 27 28 package org.netbeans.modules.xml.schema.abe; 29 30 import java.awt.Component ; 31 import java.awt.Dimension ; 32 import java.awt.dnd.Autoscroll ; 33 import javax.swing.JPanel ; 34 35 39 public class AutoSizingPanel extends ABEBaseDropPanel{ 40 private static final long serialVersionUID = 7526472295622776147L; 41 42 private boolean horizontalScaling = false; 43 private boolean verticalScaling = false; 44 private boolean fixedHeight = false; 45 private boolean fixedWidth = false; 46 private int fixedPanelHeight; 47 private int fixedPanelWidth; 48 49 private int interComponentSpacing = 0; 50 51 public AutoSizingPanel(InstanceUIContext context){ 52 super(context); 53 } 54 55 public Dimension getPreferredSize() { 56 int width = 0; 57 int height = 0; 58 for(Component child: this.getComponents()){ 59 Dimension dim = child.getPreferredSize(); 60 int curW = dim.width; 61 int curH = dim.height; 62 if(horizontalScaling) 63 width += curW + getInterComponentSpacing(); 64 else 65 width = width < curW ? curW : width; 66 67 if(verticalScaling) 68 height += curH + getInterComponentSpacing(); 69 else 70 height = height < curH ? curH : height; 71 } 72 73 if(isFixedHeight()){ 74 height = getFixedPanelHeight(); 75 } 76 if(isFixedWidth()){ 77 width = getFixedPanelWidth(); 78 } 79 80 return new Dimension (width, height); 81 } 82 83 public Dimension getMinimumSize() { 84 return getPreferredSize(); 85 } 86 87 public boolean isHorizontalScaling() { 88 return horizontalScaling; 89 } 90 91 public void setHorizontalScaling(boolean horizontalScaling) { 92 this.horizontalScaling = horizontalScaling; 93 } 94 95 public boolean isVerticalScaling() { 96 return verticalScaling; 97 } 98 99 public void setVerticalScaling(boolean verticalScaling) { 100 this.verticalScaling = verticalScaling; 101 } 102 103 public boolean isFixedHeight() { 104 return fixedHeight; 105 } 106 107 public void setFixedHeight(boolean fixedHeight) { 108 this.fixedHeight = fixedHeight; 109 } 110 111 public boolean isFixedWidth() { 112 return fixedWidth; 113 } 114 115 public void setFixedWidth(boolean fixedWidth) { 116 this.fixedWidth = fixedWidth; 117 } 118 119 public int getFixedPanelHeight() { 120 return fixedPanelHeight; 121 } 122 123 public void setFixedPanelHeight(int fixedPanelHeight) { 124 this.fixedPanelHeight = fixedPanelHeight; 125 } 126 127 public int getFixedPanelWidth() { 128 return fixedPanelWidth; 129 } 130 131 public void setFixedPanelWidth(int fixedPanelWidth) { 132 this.fixedPanelWidth = fixedPanelWidth; 133 } 134 135 public int getInterComponentSpacing() { 136 return interComponentSpacing; 137 } 138 139 public void setInterComponentSpacing(int interComponentSpacing) { 140 this.interComponentSpacing = interComponentSpacing; 141 } 142 143 public void accept(UIVisitor visitor) { 144 } 146 147 148 149 } 150 | Popular Tags |