1 11 12 package org.eclipse.pde.internal.ui.editor; 13 14 import org.eclipse.swt.layout.GridLayout; 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Display; 17 import org.eclipse.ui.forms.widgets.TableWrapLayout; 18 19 23 public class FormLayoutFactory { 24 25 public static final int DEFAULT_CLEAR_MARGIN = 2; 32 33 public static final int CONTROL_HORIZONTAL_INDENT = 3; 35 36 38 public static final int FORM_BODY_MARGIN_TOP = 12; 40 public static final int FORM_BODY_MARGIN_BOTTOM = 12; 41 public static final int FORM_BODY_MARGIN_LEFT = 6; 42 public static final int FORM_BODY_MARGIN_RIGHT = 6; 43 public static final int FORM_BODY_HORIZONTAL_SPACING = 20; 44 public static final int FORM_BODY_VERTICAL_SPACING = 17; 47 public static final int FORM_BODY_MARGIN_HEIGHT = 0; 48 public static final int FORM_BODY_MARGIN_WIDTH = 0; 49 50 public static final int SECTION_CLIENT_MARGIN_TOP = 5; 52 public static final int SECTION_CLIENT_MARGIN_BOTTOM = 5; 53 public static final int SECTION_CLIENT_MARGIN_LEFT = 2; 56 public static final int SECTION_CLIENT_MARGIN_RIGHT = 2; 59 public static final int SECTION_CLIENT_HORIZONTAL_SPACING = 5; 60 public static final int SECTION_CLIENT_VERTICAL_SPACING = 5; 61 public static final int SECTION_CLIENT_MARGIN_HEIGHT = 0; 62 public static final int SECTION_CLIENT_MARGIN_WIDTH = 0; 63 64 public static final int SECTION_HEADER_VERTICAL_SPACING = 6; 65 66 public static final int CLEAR_MARGIN_TOP = DEFAULT_CLEAR_MARGIN; 68 public static final int CLEAR_MARGIN_BOTTOM = DEFAULT_CLEAR_MARGIN; 69 public static final int CLEAR_MARGIN_LEFT = DEFAULT_CLEAR_MARGIN; 70 public static final int CLEAR_MARGIN_RIGHT = DEFAULT_CLEAR_MARGIN; 71 public static final int CLEAR_HORIZONTAL_SPACING = 0; 72 public static final int CLEAR_VERTICAL_SPACING = 0; 73 public static final int CLEAR_MARGIN_HEIGHT = 0; 74 public static final int CLEAR_MARGIN_WIDTH = 0; 75 76 public static final int FORM_PANE_MARGIN_TOP = 0; 78 public static final int FORM_PANE_MARGIN_BOTTOM = 0; 79 public static final int FORM_PANE_MARGIN_LEFT = 0; 80 public static final int FORM_PANE_MARGIN_RIGHT = 0; 81 public static final int FORM_PANE_HORIZONTAL_SPACING = FORM_BODY_HORIZONTAL_SPACING; 82 public static final int FORM_PANE_VERTICAL_SPACING = FORM_BODY_VERTICAL_SPACING; 83 public static final int FORM_PANE_MARGIN_HEIGHT = 0; 84 public static final int FORM_PANE_MARGIN_WIDTH = 0; 85 86 public static final int MASTER_DETAILS_MARGIN_TOP = 0; 88 public static final int MASTER_DETAILS_MARGIN_BOTTOM = 0; 89 public static final int MASTER_DETAILS_MARGIN_LEFT = 0; 91 public static final int MASTER_DETAILS_MARGIN_RIGHT = 1; 93 public static final int MASTER_DETAILS_HORIZONTAL_SPACING = FORM_BODY_HORIZONTAL_SPACING; 94 public static final int MASTER_DETAILS_VERTICAL_SPACING = FORM_BODY_VERTICAL_SPACING; 95 public static final int MASTER_DETAILS_MARGIN_HEIGHT = 0; 96 public static final int MASTER_DETAILS_MARGIN_WIDTH = 0; 97 98 101 private FormLayoutFactory() { 102 } 104 105 111 public static GridLayout createFormGridLayout(boolean makeColumnsEqualWidth, 112 int numColumns) { 113 GridLayout layout = new GridLayout(); 114 115 layout.marginHeight = FORM_BODY_MARGIN_HEIGHT; 116 layout.marginWidth = FORM_BODY_MARGIN_WIDTH; 117 118 layout.marginTop = FORM_BODY_MARGIN_TOP; 119 layout.marginBottom = FORM_BODY_MARGIN_BOTTOM; 120 layout.marginLeft = FORM_BODY_MARGIN_LEFT; 121 layout.marginRight = FORM_BODY_MARGIN_RIGHT; 122 123 layout.horizontalSpacing = FORM_BODY_HORIZONTAL_SPACING; 124 layout.verticalSpacing = FORM_BODY_VERTICAL_SPACING; 125 126 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 127 layout.numColumns = numColumns; 128 129 return layout; 130 } 131 132 139 public static GridLayout createClearGridLayout(boolean makeColumnsEqualWidth, 140 int numColumns) { 141 GridLayout layout = new GridLayout(); 142 143 layout.marginHeight = CLEAR_MARGIN_HEIGHT; 144 layout.marginWidth = CLEAR_MARGIN_WIDTH; 145 146 layout.marginTop = CLEAR_MARGIN_TOP; 147 layout.marginBottom = CLEAR_MARGIN_BOTTOM; 148 layout.marginLeft = CLEAR_MARGIN_LEFT; 149 layout.marginRight = CLEAR_MARGIN_RIGHT; 150 151 layout.horizontalSpacing = CLEAR_HORIZONTAL_SPACING; 152 layout.verticalSpacing = CLEAR_VERTICAL_SPACING; 153 154 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 155 layout.numColumns = numColumns; 156 157 return layout; 158 } 159 160 166 public static TableWrapLayout createFormTableWrapLayout( 167 boolean makeColumnsEqualWidth, 168 int numColumns) { 169 TableWrapLayout layout = new TableWrapLayout(); 170 171 layout.topMargin = FORM_BODY_MARGIN_TOP; 172 layout.bottomMargin = FORM_BODY_MARGIN_BOTTOM; 173 layout.leftMargin = FORM_BODY_MARGIN_LEFT; 174 layout.rightMargin = FORM_BODY_MARGIN_RIGHT; 175 176 layout.horizontalSpacing = FORM_BODY_HORIZONTAL_SPACING; 177 layout.verticalSpacing = FORM_BODY_VERTICAL_SPACING; 178 179 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 180 layout.numColumns = numColumns; 181 182 return layout; 183 } 184 185 191 public static TableWrapLayout createFormPaneTableWrapLayout( 192 boolean makeColumnsEqualWidth, 193 int numColumns) { 194 TableWrapLayout layout = new TableWrapLayout(); 195 196 layout.topMargin = FORM_PANE_MARGIN_TOP; 197 layout.bottomMargin = FORM_PANE_MARGIN_BOTTOM; 198 layout.leftMargin = FORM_PANE_MARGIN_LEFT; 199 layout.rightMargin = FORM_PANE_MARGIN_RIGHT; 200 201 layout.horizontalSpacing = FORM_PANE_HORIZONTAL_SPACING; 202 layout.verticalSpacing = FORM_PANE_VERTICAL_SPACING; 203 204 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 205 layout.numColumns = numColumns; 206 207 return layout; 208 } 209 210 216 public static GridLayout createFormPaneGridLayout(boolean makeColumnsEqualWidth, 217 int numColumns) { 218 GridLayout layout = new GridLayout(); 219 220 layout.marginHeight = FORM_PANE_MARGIN_HEIGHT; 221 layout.marginWidth = FORM_PANE_MARGIN_WIDTH; 222 223 layout.marginTop = FORM_PANE_MARGIN_TOP; 224 layout.marginBottom = FORM_PANE_MARGIN_BOTTOM; 225 layout.marginLeft = FORM_PANE_MARGIN_LEFT; 226 layout.marginRight = FORM_PANE_MARGIN_RIGHT; 227 228 layout.horizontalSpacing = FORM_PANE_HORIZONTAL_SPACING; 229 layout.verticalSpacing = FORM_PANE_VERTICAL_SPACING; 230 231 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 232 layout.numColumns = numColumns; 233 234 return layout; 235 } 236 237 244 public static TableWrapLayout createClearTableWrapLayout( 245 boolean makeColumnsEqualWidth, 246 int numColumns) { 247 TableWrapLayout layout = new TableWrapLayout(); 248 249 layout.topMargin = CLEAR_MARGIN_TOP; 250 layout.bottomMargin = CLEAR_MARGIN_BOTTOM; 251 layout.leftMargin = CLEAR_MARGIN_LEFT; 252 layout.rightMargin = CLEAR_MARGIN_RIGHT; 253 254 layout.horizontalSpacing = CLEAR_HORIZONTAL_SPACING; 255 layout.verticalSpacing = CLEAR_VERTICAL_SPACING; 256 257 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 258 layout.numColumns = numColumns; 259 260 return layout; 261 } 262 263 269 public static GridLayout createMasterGridLayout( 270 boolean makeColumnsEqualWidth, 271 int numColumns) { 272 GridLayout layout = new GridLayout(); 273 274 layout.marginHeight = MASTER_DETAILS_MARGIN_HEIGHT; 275 layout.marginWidth = MASTER_DETAILS_MARGIN_WIDTH; 276 277 layout.marginTop = MASTER_DETAILS_MARGIN_TOP; 278 layout.marginBottom = MASTER_DETAILS_MARGIN_BOTTOM; 279 layout.marginLeft = MASTER_DETAILS_MARGIN_LEFT; 280 int marginRight = MASTER_DETAILS_HORIZONTAL_SPACING; 288 if (marginRight > 0) { 289 marginRight = marginRight / 2; 290 if (marginRight > 0) { 291 marginRight--; 292 } 293 } 294 layout.marginRight = marginRight; 295 296 layout.horizontalSpacing = MASTER_DETAILS_HORIZONTAL_SPACING; 297 layout.verticalSpacing = MASTER_DETAILS_VERTICAL_SPACING; 298 299 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 300 layout.numColumns = numColumns; 301 302 return layout; 303 } 304 305 311 public static GridLayout createDetailsGridLayout( 312 boolean makeColumnsEqualWidth, 313 int numColumns) { 314 GridLayout layout = new GridLayout(); 315 316 layout.marginHeight = MASTER_DETAILS_MARGIN_HEIGHT; 317 layout.marginWidth = MASTER_DETAILS_MARGIN_WIDTH; 318 319 layout.marginTop = MASTER_DETAILS_MARGIN_TOP; 320 layout.marginBottom = MASTER_DETAILS_MARGIN_BOTTOM; 321 int marginLeft = MASTER_DETAILS_HORIZONTAL_SPACING; 329 if (marginLeft > 0) { 330 marginLeft = marginLeft / 2; 331 if (marginLeft > 0) { 332 marginLeft--; 333 } 334 } 335 layout.marginLeft = marginLeft; 336 layout.marginRight = MASTER_DETAILS_MARGIN_RIGHT; 337 338 layout.horizontalSpacing = MASTER_DETAILS_HORIZONTAL_SPACING; 339 layout.verticalSpacing = MASTER_DETAILS_VERTICAL_SPACING; 340 341 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 342 layout.numColumns = numColumns; 343 344 return layout; 345 } 346 347 354 public static GridLayout createSectionClientGridLayout(boolean makeColumnsEqualWidth, 355 int numColumns) { 356 GridLayout layout = new GridLayout(); 357 358 layout.marginHeight = SECTION_CLIENT_MARGIN_HEIGHT; 359 layout.marginWidth = SECTION_CLIENT_MARGIN_WIDTH; 360 361 layout.marginTop = SECTION_CLIENT_MARGIN_TOP; 362 layout.marginBottom = SECTION_CLIENT_MARGIN_BOTTOM; 363 layout.marginLeft = SECTION_CLIENT_MARGIN_LEFT; 364 layout.marginRight = SECTION_CLIENT_MARGIN_RIGHT; 365 366 layout.horizontalSpacing = SECTION_CLIENT_HORIZONTAL_SPACING; 367 layout.verticalSpacing = SECTION_CLIENT_VERTICAL_SPACING; 368 369 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 370 layout.numColumns = numColumns; 371 372 return layout; 373 } 374 375 382 public static TableWrapLayout createSectionClientTableWrapLayout(boolean makeColumnsEqualWidth, 383 int numColumns) { 384 TableWrapLayout layout = new TableWrapLayout(); 385 386 layout.topMargin = SECTION_CLIENT_MARGIN_TOP; 387 layout.bottomMargin = SECTION_CLIENT_MARGIN_BOTTOM; 388 layout.leftMargin = SECTION_CLIENT_MARGIN_LEFT; 389 layout.rightMargin = SECTION_CLIENT_MARGIN_RIGHT; 390 391 layout.horizontalSpacing = SECTION_CLIENT_HORIZONTAL_SPACING; 392 layout.verticalSpacing = SECTION_CLIENT_VERTICAL_SPACING; 393 394 layout.makeColumnsEqualWidth = makeColumnsEqualWidth; 395 layout.numColumns = numColumns; 396 397 return layout; 398 } 399 400 409 public static void visualizeLayoutArea(Composite container, int color) { 410 container.setBackground(Display.getCurrent().getSystemColor(color)); 411 } 412 } 413 | Popular Tags |