1 30 31 package com.jgoodies.looks.common; 32 33 import java.awt.Component ; 34 import java.awt.Container ; 35 import java.awt.Dimension ; 36 import java.awt.Insets ; 37 38 import javax.swing.plaf.basic.BasicOptionPaneUI ; 39 40 import com.jgoodies.looks.LookUtils; 41 42 49 50 public final class ExtButtonAreaLayout 51 extends BasicOptionPaneUI.ButtonAreaLayout { 52 53 59 public ExtButtonAreaLayout(boolean syncAllWidths, int padding) { 60 super(syncAllWidths, padding); 61 } 62 63 public void layoutContainer(Container container) { 64 Component [] children = container.getComponents(); 65 66 if (children != null && children.length > 0) { 67 int numChildren = children.length; 68 Dimension [] sizes = new Dimension [numChildren]; 69 int counter; 70 int yLocation = container.getInsets().top; 71 72 if (syncAllWidths) { 73 int maxWidth = getMinimumButtonWidth(); 74 75 for (counter = 0; counter < numChildren; counter++) { 76 sizes[counter] = children[counter].getPreferredSize(); 77 maxWidth = Math.max(maxWidth, sizes[counter].width); 78 } 79 80 int xLocation; 81 int xOffset; 82 83 if (getCentersChildren()) { 84 xLocation = 85 (container.getSize().width 86 - (maxWidth * numChildren 87 + (numChildren - 1) * padding)) 88 / 2; 89 xOffset = padding + maxWidth; 90 } else { 91 if (numChildren > 1) { 92 xLocation = 0; 93 xOffset = 94 (container.getSize().width 95 - (maxWidth * numChildren)) 96 / (numChildren - 1) 97 + maxWidth; 98 } else { 99 xLocation = (container.getSize().width - maxWidth) / 2; 100 xOffset = 0; 101 } 102 } 103 for (counter = 0; counter < numChildren; counter++) { 104 children[counter].setBounds( 105 xLocation, 106 yLocation, 107 maxWidth, 108 sizes[counter].height); 109 xLocation += xOffset; 110 } 111 } else { 112 int totalWidth = 0; 113 114 for (counter = 0; counter < numChildren; counter++) { 115 sizes[counter] = children[counter].getPreferredSize(); 116 totalWidth += sizes[counter].width; 117 } 118 totalWidth += ((numChildren - 1) * padding); 119 120 boolean cc = getCentersChildren(); 121 int xOffset; 122 int xLocation; 123 124 if (cc) { 125 xLocation = (container.getSize().width - totalWidth) / 2; 126 xOffset = padding; 127 } else { 128 if (numChildren > 1) { 129 xOffset = 130 (container.getSize().width - totalWidth) 131 / (numChildren - 1); 132 xLocation = 0; 133 } else { 134 xLocation = 135 (container.getSize().width - totalWidth) / 2; 136 xOffset = 0; 137 } 138 } 139 140 for (counter = 0; counter < numChildren; counter++) { 141 children[counter].setBounds( 142 xLocation, 143 yLocation, 144 sizes[counter].width, 145 sizes[counter].height); 146 xLocation += xOffset + sizes[counter].width; 147 } 148 } 149 } 150 } 151 152 public Dimension minimumLayoutSize(Container c) { 153 if (c != null) { 154 Component [] children = c.getComponents(); 155 156 if (children != null && children.length > 0) { 157 Dimension aSize; 158 int numChildren = children.length; 159 int height = 0; 160 Insets cInsets = c.getInsets(); 161 int extraHeight = cInsets.top + cInsets.bottom; 162 163 if (syncAllWidths) { 164 int maxWidth = getMinimumButtonWidth(); 165 166 for (int counter = 0; counter < numChildren; counter++) { 167 aSize = children[counter].getPreferredSize(); 168 height = Math.max(height, aSize.height); 169 maxWidth = Math.max(maxWidth, aSize.width); 170 } 171 return new Dimension ( 172 maxWidth * numChildren + (numChildren - 1) * padding, 173 extraHeight + height); 174 } else { 175 int totalWidth = 0; 176 177 for (int counter = 0; counter < numChildren; counter++) { 178 aSize = children[counter].getPreferredSize(); 179 height = Math.max(height, aSize.height); 180 totalWidth += aSize.width; 181 } 182 totalWidth += ((numChildren - 1) * padding); 183 return new Dimension (totalWidth, extraHeight + height); 184 } 185 } 186 } 187 return new Dimension (0, 0); 188 } 189 190 199 private int getMinimumButtonWidth() { 200 return LookUtils.IS_LOW_RESOLUTION ? 75 : 100; 201 } 202 203 } | Popular Tags |