Coverage Report - net.miginfocom.demo.SwtDemo
 
Classes in this File Line Coverage Branch Coverage Complexity
SwtDemo
N/A
N/A
2.516
SwtDemo$1
N/A
N/A
2.516
SwtDemo$2
N/A
N/A
2.516
SwtDemo$3
N/A
N/A
2.516
SwtDemo$3$1
N/A
N/A
2.516
SwtDemo$3$2
N/A
N/A
2.516
SwtDemo$3$3
N/A
N/A
2.516
SwtDemo$3$4
N/A
N/A
2.516
SwtDemo$3$5
N/A
N/A
2.516
SwtDemo$4
N/A
N/A
2.516
SwtDemo$5
N/A
N/A
2.516
SwtDemo$6
N/A
N/A
2.516
SwtDemo$7
N/A
N/A
2.516
 
 1  
 package net.miginfocom.demo;
 2  
 
 3  
 import net.miginfocom.layout.*;
 4  
 import net.miginfocom.swt.MigLayout;
 5  
 import org.eclipse.swt.SWT;
 6  
 import org.eclipse.swt.custom.SashForm;
 7  
 import org.eclipse.swt.custom.StyledText;
 8  
 import org.eclipse.swt.events.ControlAdapter;
 9  
 import org.eclipse.swt.events.ControlEvent;
 10  
 import org.eclipse.swt.events.SelectionAdapter;
 11  
 import org.eclipse.swt.events.SelectionEvent;
 12  
 import org.eclipse.swt.graphics.Color;
 13  
 import org.eclipse.swt.graphics.Font;
 14  
 import org.eclipse.swt.graphics.FontData;
 15  
 import org.eclipse.swt.layout.FillLayout;
 16  
 import org.eclipse.swt.widgets.*;
 17  
 
 18  
 import java.io.FileWriter;
 19  
 import java.io.IOException;
 20  
 import java.util.Random;
 21  
 
 22  
 /*
 23  
  * License (BSD):
 24  
  * ==============
 25  
  *
 26  
  * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
 27  
  * All rights reserved.
 28  
  *
 29  
  * Redistribution and use in source and binary forms, with or without modification,
 30  
  * are permitted provided that the following conditions are met:
 31  
  * Redistributions of source code must retain the above copyright notice, this list
 32  
  * of conditions and the following disclaimer.
 33  
  * Redistributions in binary form must reproduce the above copyright notice, this
 34  
  * list of conditions and the following disclaimer in the documentation and/or other
 35  
  * materials provided with the distribution.
 36  
  * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
 37  
  * used to endorse or promote products derived from this software without specific
 38  
  * prior written permission.
 39  
  *
 40  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 41  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 42  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 43  
  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 44  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 45  
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 46  
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 47  
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 48  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 49  
  * OF SUCH DAMAGE.
 50  
  *
 51  
  * @version 1.0
 52  
  * @author Mikael Grev, MiG InfoCom AB
 53  
  *         Date: 2006-sep-08
 54  
  */
 55  
 public class SwtDemo
 56  
 {
 57  
         public static final int SELECTED_INDEX = 0;
 58  
 
 59  
         private static final String[][] panels = new String[][] {
 60  
 //                        {"BugTestApp", "BugTestApp, Disregard"},
 61  
                         {"Welcome", "\n\n         \"MigLayout makes complex layouts easy and normal layouts one-liners.\""},
 62  
                         {"Quick Start", "This is an example of how to build a common dialog type. Note that there are no special components, nested panels or absolute references to cell positions. If you look at the source code you will see that the layout code is very simple to understand."},
 63  
                         {"Plain", "A simple example on how simple it is to create normal forms. No builders needed since the whole layout manager works like a builder."},
 64  
                         {"Alignments", "Shows how the alignment of components are specified. At the top/left is the alignment for the column/row. The components have no alignments specified.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
 65  
                         {"Cell Alignments", "Shows how components are aligned when both column/row alignments and component constraints are specified. At the top/left are the alignment for the column/row and the text on the buttons is the component constraint that will override the column/row alignment if it is an alignment.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
 66  
                         {"Basic Sizes", "A simple example that shows how to use the column or row min/preferred/max size to set the sizes of the contained components and also an example that shows how to do this directly in the component constraints."},
 67  
                         {"Growing", "A simple example that shows how to use the growx and growy constraint to set the sizes and how they should grow to fit the available size. Both the column/row and the component grow/shrink constraints can be set, but the components will always be confined to the space given by its column/row."},
 68  
                         {"Grow Shrink", "Demonstrates the very flexible grow and shrink constraints that can be set on a component.\nComponents can be divided into grow/shrink groups and also have grow/shrink weight within each of those groups.\n\nBy default " +
 69  
                                                         "components shrink to their inherent (or specified) minimum size, but they don't grow."},
 70  
                         {"Span", "This example shows the powerful spanning and splitting that can be specified in the component constraints. With spanning any number of cells can be merged with the additional option to split that space for more than one component. This makes layouts very flexible and reduces the number of times you will need nested panels to very few."},
 71  
                         {"Flow Direction", "Shows the different flow directions. Flow direction for the layout specifies if the next cell will be in the x or y dimension. Note that it can be a different flow direction in the slit cell (the middle cell is slit in two). Wrap is set to 3 for all panels."},
 72  
                         {"Grouping", "Sizes for both components and columns/rows can be grouped so they get the same size. For instance buttons in a button bar can be given a size-group so that they will all get " +
 73  
                                                  "the same minimum and preferred size (the largest within the group). Size-groups can be set for the width, height or both."},
 74  
                         {"Units", "Demonstrates the basic units that are understood by MigLayout. These units can be extended by the user by adding one or more UnitConverter(s)."},
 75  
                         {"Component Sizes", "Minimum, preferred and maximum component sizes can be overridden in the component constraints using any unit type. The format to do this is short and simple to understand. You simply specify the " +
 76  
                                                                 "min, preferred and max sizes with a colon between.\n\nAbove are some examples of this. An exclamation mark means that the value will be used for all sizes."},
 77  
                         {"Bound Sizes", "Shows how to create columns that are stable between tabs using minimum sizes."},
 78  
                         {"Cell Position", "Even though MigLayout has automatic grid flow you can still specify the cell position explicitly. You can even combine absolute (x, y) and flow (skip, wrap and newline) constraints to build your layout."},
 79  
                         {"Orientation", "MigLayout supports not only right-to-left orientation, but also bottom-to-top. You can even set the flow direction so that the flow is vertical instead of horizontal. It will automatically " +
 80  
                                                         "pick up if right-to-left is to be used depending on the ComponentWrapper, but it can also be manually set for every layout."},
 81  
                         {"Absolute Position", "Demonstrates the option to place any number of components using absolute coordinates. This can be just the position (if min/preferred size) using \"x y p p\" format or" +
 82  
                                                                   "the bounds using the \"x1 y1 x2 y2\" format. Any unit can be used and percent is relative to the parent.\nAbsolute components will not disturb the flow or occupy cells in the grid. " +
 83  
                                                                   "Absolute positioned components will be taken into account when calculating the container's preferred size."},
 84  
                         {"Component Links", "Components can be linked to any side of any other component. It can be a forward, backward or cyclic link references, as long as it is stable and won't continue to change value over many iterations." +
 85  
                                                                 "Links are referencing the ID of another component. The ID can be overridden by the component's constrains or is provided by the ComponentWrapper. For instance it will use the component's 'name' on Swing.\n" +
 86  
                                                                 "Since the links can be combined with any expression (such as 'butt1.x+10' or 'max(button.x, 200)' the links are very customizable."},
 87  
                         {"Docking", "Docking components can be added around the grid. The docked component will get the whole width/height on the docked side by default, however this can be overridden. When all docked components are laid out, whatever space " +
 88  
                                                 "is left will be available for the normal grid laid out components. Docked components does not in any way affect the flow in the grid.\n\nSince the docking runs in the same code path " +
 89  
                                                 "as the normal layout code the same properties can be specified for the docking components. You can for instance set the sizes and alignment or link other components to their docked component's bounds."},
 90  
                         {"Button Bars", "Button order is very customizable and are by default different on the supported platforms. E.g. Gaps, button order and minimum button size are properties that are 'per platform'. MigLayout picks up the current platform automatically and adjusts the button order and minimum button size accordingly, all without using a button builder or any other special code construct."},
 91  
                         {"Debug", "Demonstrates the non-intrusive way to get visual debugging aid. There is no need to use a special DebugPanel or anything that will need code changes. The user can simply turn on debug on the layout manager by using the �debug� constraint and it will " +
 92  
                                           "continuously repaint the panel with debug information on top. This means you don't have to change your code to debug!"},
 93  
                         {"Layout Showdown", "This is an implementation of the Layout Showdown posted on java.net by John O'Conner. The first tab is a pure implemenetation of the showdown that follows all the rules. The second tab is a slightly fixed version that follows some improved layout guidelines." +
 94  
                                             "The source code is for bothe the first and for the fixed version. Note the simplification of the code for the fixed version. Writing better layouts with MiG Layout is reasier that writing bad.\n\nReference: http://weblogs.java.net/blog/joconner/archive/2006/10/more_informatio.html"},
 95  
                         {"API Constraints1", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."},
 96  
                         {"API Constraints2", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."},
 97  
         };
 98  
 
 99  
         private static int DOUBLE_BUFFER = 0;//SWT.DOUBLE_BUFFERED;
 100  
 
 101  
         private static int benchRuns = 0;
 102  
         private static long startupMillis = 0;
 103  
         private static long timeToShowMillis = 0;
 104  
         private static long benchRunTime = 0;
 105  
         private static String benchOutFileName = null;
 106  
         private static boolean append = false;
 107  
 
 108  
         private static long lastRunTimeStart = 0;
 109  
         private static StringBuffer runTimeSB = null;
 110  
 
 111  
         private static Display display = null;
 112  
 
 113  
         public static void main(String[] args)
 114  
         {
 115  
                 startupMillis = System.currentTimeMillis();
 116  
 
 117  
                 if (args.length > 0) {
 118  
                         for (int i = 0; i < args.length; i++) {
 119  
                                 String arg = args[i].trim();
 120  
                                 if (arg.startsWith("-bench")) {
 121  
                                         benchRuns = 10;
 122  
                                         try {
 123  
                                                 if (arg.length() > 6)
 124  
                                                         benchRuns = Integer.parseInt(arg.substring(6));
 125  
                                         } catch (Exception ex) {}
 126  
                                 } else if (arg.startsWith("-bout")) {
 127  
                                         benchOutFileName = arg.substring(5);
 128  
                                 } else if (arg.startsWith("-append")) {
 129  
                                         append = true;
 130  
                                 } else if (arg.startsWith("-verbose")) {
 131  
                                         runTimeSB = new StringBuffer(256);
 132  
                                 } else {
 133  
                                         System.out.println("Usage: [-bench[#_of_runs]] [-bout[benchmark_results_filename]] [-append]\n" +
 134  
                                                            " -bench Run demo as benchmark. Run count can be appended. 10 is default.\n" +
 135  
                                                            " -bout  Benchmark results output filename.\n" +
 136  
                                                            " -append Appends the result to the \"-bout\" file.\n" +
 137  
                                                            " -verbose Print the times of every run.\n" +
 138  
                                                            "\nExamples:\n" +
 139  
                                                            " java -jar swtdemoapp.jar -bench -boutC:/bench.txt -append\n" +
 140  
                                                            " java -jar swtdemoapp.jar -bench20\n" +
 141  
                                                            "NOTE! swt-win32-3232.dll must be in the current directory!");
 142  
                                         System.exit(0);
 143  
                                 }
 144  
                         }
 145  
                 }
 146  
 
 147  
                 if (benchRuns == 0)
 148  
                         LayoutUtil.setDesignTime(null, true);
 149  
 
 150  
                 new SwtDemo();
 151  
         }
 152  
 
 153  
         final List pickerList;
 154  
         final Composite layoutDisplayPanel;
 155  
         final StyledText descrTextArea;
 156  
 
 157  
         public SwtDemo()
 158  
         {
 159  
                 display = new Display();
 160  
                 final Shell shell = new Shell();
 161  
 
 162  
                 shell.setLayout(new MigLayout("wrap", "[]u[grow,fill]", "[grow,fill][pref!]"));
 163  
                 shell.setText("MigLayout SWT Demo v2.5 - Mig Layout v" + LayoutUtil.getVersion());
 164  
 
 165  
                 TabFolder layoutPickerTabPane = new TabFolder(shell, DOUBLE_BUFFER);
 166  
                 layoutPickerTabPane.setLayoutData("spany,grow");
 167  
                         pickerList = new List(layoutPickerTabPane, SWT.SINGLE | DOUBLE_BUFFER);
 168  
                         pickerList.setBackground(layoutPickerTabPane.getBackground());
 169  
                         deriveFont(pickerList, SWT.BOLD, -1);
 170  
                         TabItem tab = new TabItem(layoutPickerTabPane, DOUBLE_BUFFER);
 171  
                         tab.setControl(pickerList);
 172  
                         tab.setText("Example Browser");
 173  
                         for (int i = 0; i < panels.length; i++)
 174  
                                 pickerList.add(panels[i][0]);
 175  
 
 176  
                 layoutDisplayPanel = new Composite(shell, DOUBLE_BUFFER);
 177  
                 layoutDisplayPanel.setLayout(new MigLayout("fill, insets 0"));
 178  
 
 179  
                 TabFolder descriptionTabPane = new TabFolder(shell, DOUBLE_BUFFER);
 180  
                 descriptionTabPane.setLayoutData("growx,hmin 120,w 500:500");
 181  
                         descrTextArea = createTextArea(descriptionTabPane, "", "", SWT.MULTI | SWT.WRAP);
 182  
                         descrTextArea.setBackground(descriptionTabPane.getBackground());
 183  
                         tab = new TabItem(descriptionTabPane, DOUBLE_BUFFER);
 184  
                         tab.setControl(descrTextArea);
 185  
                         tab.setText("Description");
 186  
 
 187  
                 pickerList.addSelectionListener(new SelectionAdapter() {
 188  
                         public void widgetSelected(SelectionEvent e) {
 189  
                                 dispatchSelection();
 190  
                         }
 191  
                 });
 192  
 
 193  
                 shell.setSize(900, 650);
 194  
                 shell.open();
 195  
 
 196  
                 shell.layout();
 197  
 
 198  
 
 199  
                 if (benchRuns > 0) {
 200  
                         doBenchmark();
 201  
                 } else {
 202  
                         pickerList.select(SELECTED_INDEX);
 203  
                         dispatchSelection();
 204  
 
 205  
                         display.addFilter(SWT.KeyDown, new Listener() {
 206  
 
 207  
                                 public void handleEvent(Event e)
 208  
                                 {
 209  
                                         if (e.character == 'b') {
 210  
                                                 startupMillis = System.currentTimeMillis();
 211  
                                                 timeToShowMillis = System.currentTimeMillis() - startupMillis;
 212  
                                                 benchRuns = 1;
 213  
                                                 doBenchmark();
 214  
                                         }
 215  
                                 }
 216  
                         });
 217  
                 }
 218  
                 System.out.println(Display.getCurrent().getDPI());
 219  
 
 220  
                 while(!shell.isDisposed()){
 221  
                         if(!display.readAndDispatch())
 222  
                                 display.sleep();
 223  
                 }
 224  
 
 225  
                 display.dispose();
 226  
         }
 227  
 
 228  
         private static Control[] comps = null;  // thread hack...
 229  
         private static Control[] tabs = null;     // thread hack...
 230  
 
 231  
         private void doBenchmark()
 232  
         {
 233  
                 final int pCnt = pickerList.getItemCount();
 234  
                 Thread benchThread = new Thread() {
 235  
                                 public void run()
 236  
                                 {
 237  
                                         for (int j = 0; j < benchRuns; j++) {
 238  
                                                 lastRunTimeStart = System.currentTimeMillis();
 239  
                                                 final int jj = j;
 240  
                                                 for (int i = 0; i < pCnt; i++) {
 241  
                                                         final int ii = i;
 242  
                                                         try {
 243  
                                                                  display.syncExec(new Runnable() {
 244  
                                                                           public void run () {
 245  
                                                                                   pickerList.setSelection(ii);
 246  
                                                                                   dispatchSelection();
 247  
                                                                           }
 248  
                                                                    });
 249  
                                                         } catch (Exception e) {
 250  
                                                                 e.printStackTrace();
 251  
                                                         }
 252  
 
 253  
                                                         display.syncExec(new Runnable() {
 254  
                                                                  public void run() {
 255  
                                                                          comps = layoutDisplayPanel.getChildren();
 256  
                                                                  }
 257  
                                                          });
 258  
 
 259  
                                                         for (int cIx = 0; cIx < comps.length; cIx++) {
 260  
 
 261  
                                                                 if (comps[cIx] instanceof TabFolder) {
 262  
                                                                         final TabFolder tp = (TabFolder) comps[cIx];
 263  
 
 264  
                                                                         display.syncExec(new Runnable() {
 265  
                                                                                  public void run() {
 266  
                                                                                          tabs = tp.getTabList();
 267  
                                                                                  }
 268  
                                                                          });
 269  
 
 270  
                                                                         for (int k = 0; k < tabs.length; k++) {
 271  
                                                                                 final int kk = k;
 272  
                                                                                 try {
 273  
                                                                                         display.syncExec(new Runnable() {
 274  
                                                                                                  public void run() {
 275  
                                                                                                          tp.setSelection(kk);
 276  
 
 277  
                                                                                                          if (timeToShowMillis == 0)
 278  
                                                                                                                  timeToShowMillis = System.currentTimeMillis() - startupMillis;
 279  
                                                                                                  }
 280  
                                                                                          });
 281  
                                                                                 } catch (Exception e) {
 282  
                                                                                         e.printStackTrace();
 283  
                                                                                 };
 284  
                                                                         }
 285  
                                                                 }
 286  
                                                         }
 287  
                                                 }
 288  
                                                 if (runTimeSB != null) {
 289  
                                                    runTimeSB.append("Run ").append(jj).append(": ");
 290  
                                                    runTimeSB.append(System.currentTimeMillis() - lastRunTimeStart).append(" millis.\n");
 291  
                                                 }
 292  
                                         }
 293  
 
 294  
                                         benchRunTime = System.currentTimeMillis() - startupMillis - timeToShowMillis;
 295  
 
 296  
                                         final String message = "Java Version:       " + System.getProperty("java.version") + "\n" +
 297  
                                                          "Time to Show:       " + timeToShowMillis + " millis.\n" +
 298  
                                                          (runTimeSB != null ? runTimeSB.toString() : "") +
 299  
                                                          "Benchmark Run Time: " + benchRunTime + " millis.\n" +
 300  
                                                          "Average Run Time:   " + (benchRunTime / benchRuns) + " millis (" + benchRuns + " runs).\n\n";
 301  
 
 302  
                                         display.syncExec(new Runnable() {
 303  
                                                  public void run() {
 304  
                                                          if (benchOutFileName == null) {
 305  
                                                                  MessageBox messageBox = new MessageBox(display.getActiveShell(), SWT.OK | SWT.ICON_INFORMATION);
 306  
                                                                  messageBox.setText("Results");
 307  
                                                                  messageBox.setMessage(message);
 308  
                                                                  messageBox.open();
 309  
                                                          } else {
 310  
                                                                  FileWriter fw = null;
 311  
                                                                  try {
 312  
                                                                          fw = new FileWriter(benchOutFileName, append);
 313  
                                                                          fw.write(message);
 314  
                                                                  } catch(IOException ex) {
 315  
                                                                          ex.printStackTrace();
 316  
                                                                  } finally {
 317  
                                                                          if (fw != null)
 318  
                                                                                  try {fw.close();} catch(IOException ex) {}
 319  
                                                                  }
 320  
                                                          }
 321  
                                                  }
 322  
                                          });
 323  
 
 324  
                                         System.out.println(message);
 325  
 
 326  
                                         if (benchOutFileName != null)
 327  
                                                 System.exit(0);
 328  
                                 }
 329  
                         };
 330  
                         benchThread.start();
 331  
         }
 332  
 
 333  
         private void dispatchSelection()
 334  
         {
 335  
                 int ix = pickerList.getSelectionIndex();
 336  
                 if (ix == -1)
 337  
                         return;
 338  
 
 339  
                 String methodName = "create" + panels[ix][0].replace(' ', '_');
 340  
                 Control[] children = layoutDisplayPanel.getChildren();
 341  
                 for (int i = 0; i < children.length; i++)
 342  
                         children[i].dispose();
 343  
 
 344  
                 try {
 345  
                         Control child = (Control) SwtDemo.class.getMethod(methodName, new Class[] {Composite.class}).invoke(SwtDemo.this, new Object[] {layoutDisplayPanel});
 346  
                         child.setLayoutData("grow, wmin 500");
 347  
                         descrTextArea.setText(panels[ix][1]);
 348  
                         layoutDisplayPanel.layout();
 349  
                 } catch (Exception e1) {
 350  
                         e1.printStackTrace();   // Should never happpen...
 351  
                 }
 352  
         }
 353  
 
 354  
         public Control createTest(Composite parent)
 355  
         {
 356  
 //                TabFolder tabFolder = new TabFolder(parent2, DOUBLE_BUFFER);
 357  
 
 358  
                 Button button;
 359  
 
 360  
                 Composite composite = new Composite(parent, SWT.NONE);
 361  
                 composite.setLayout(new MigLayout("debug", "[right][grow]", ""));
 362  
 
 363  
                 button = new Button(composite, SWT.PUSH);
 364  
                 button.setText("New");
 365  
                 button.setLayoutData("span 2, align left, split, sgx button");
 366  
                 button = new Button(composite, SWT.PUSH);
 367  
                 button.setText("Edit");
 368  
                 button.setLayoutData("sgx button");
 369  
                 button = new Button(composite, SWT.PUSH);
 370  
                 button.setText("Cancel");
 371  
                 button.setLayoutData("sgx button");
 372  
                 button = new Button(composite, SWT.PUSH);
 373  
                 button.setText("Save");
 374  
                 button.setLayoutData("sgx button, wrap");
 375  
 
 376  
                 new Label(composite, SWT.NONE).setText("Name");
 377  
                 Text text = new Text(composite, SWT.BORDER);
 378  
                 text.setLayoutData("sgy control, pushx, growx, wrap");
 379  
 
 380  
                 new Label(composite, SWT.NONE).setText("Sex");
 381  
                 Combo combo = new Combo(composite, SWT.DROP_DOWN);
 382  
                 combo.setLayoutData("sgy control, w 50!, wrap");
 383  
                 combo.setItems(new String[]
 384  
                 { "M", "F", "-" });
 385  
 
 386  
 
 387  
                 return composite;
 388  
         }
 389  
 
 390  
         public Control createWelcome(Composite parent)
 391  
         {
 392  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 393  
 
 394  
                 TabItem tabPanel = createTabPanel(tabbedPane, "Welcome", new MigLayout());
 395  
 
 396  
                 MigLayout lm = new MigLayout("ins 20, fill");
 397  
                 Composite panel = createPanel(tabbedPane, lm);
 398  
                 tabPanel.setControl(panel);
 399  
 
 400  
                 String s = "MigLayout's main purpose is to make layouts for SWT and Swing, and possibly other frameworks, much more powerful and a lot easier to create, especially for manual coding.\n\n" +
 401  
                            "The motto is: \"MigLayout makes complex layouts easy and normal layouts one-liners.\"\n\n" +
 402  
                            "The layout engine is very flexible and advanced, something that is needed to make it simple to use yet handle almost all layout use-cases.\n\n" +
 403  
                            "MigLayout can handle all layouts that the commonly used Swing Layout Managers can handle and this with a lot of extra features. " +
 404  
                            "It also incorporates most, if not all, of the open source alternatives FormLayout's and TableLayout's functionality." +
 405  
                            "\n\n\nThanks to Karsten Lentzsch from JGoodies.com for allowing the reuse of the main demo application layout and for his inspiring talks that led to this layout Manager." +
 406  
                            "\n\n\nMikael Grev\n" +
 407  
                            "MiG InfoCom AB\n" +
 408  
                            "miglayout@miginfocom.com";
 409  
 
 410  
                 // One needs to set both min and pref for SWT wrapping text areas since it always returns the unwrapped size otherwise.
 411  
                 StyledText textArea = createTextArea(panel, s, "w 500:500, ay top, grow, push", 0);
 412  
                 textArea.setBackground(panel.getBackground());
 413  
                 textArea.setBackgroundMode(SWT.INHERIT_NONE);
 414  
 //                deriveFont(textArea, SWT.PATH_LINE_TO, -1);
 415  
 
 416  
                 return tabbedPane;
 417  
         }
 418  
 
 419  
         public Composite createAPI_Constraints1(Composite parent)
 420  
         {
 421  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 422  
 
 423  
                 LC layC = new LC().fill().wrap();
 424  
                 AC colC = new AC().align("right", 0).fill(1, 3).grow(100, 1, 3).align("right", 2).gap("15", 1);
 425  
                 AC rowC = new AC().align("top", 7).gap("15!", 6).grow(100, 8);
 426  
 
 427  
                 TabItem p1 = createTabPanel(tabbedPane, "Layout Showdown (improved)", new MigLayout(layC, colC, rowC));
 428  
 
 429  
                 // References to text fields not stored to reduce code clutter.
 430  
 
 431  
                 createList(p1, "Mouse, Mickey", new CC().dockWest().minWidth("150").gapX(null, "10"));
 432  
                 createLabel(p1, "Last Name",    "");
 433  
                 createTextField(p1, "",         "");
 434  
                 createLabel(p1, "First Name",   "");
 435  
                 createTextField(p1, "",         new CC().wrap());
 436  
                 createLabel(p1, "Phone",        "");
 437  
                 createTextField(p1, "",         "");
 438  
                 createLabel(p1, "Email",        "");
 439  
                 createTextField(p1, "",         "");
 440  
                 createLabel(p1, "Address 1",    "");
 441  
                 createTextField(p1,             "", new CC().spanX().growX());
 442  
                 createLabel(p1, "Address 2",    "");
 443  
                 createTextField(p1,             "", new CC().spanX().growX());
 444  
                 createLabel(p1, "City",         "");
 445  
                 createTextField(p1,             "", new CC().wrap());
 446  
                 createLabel(p1, "State",        "");
 447  
                 createTextField(p1, "",         "");
 448  
                 createLabel(p1, "Postal Code",  "");
 449  
                 createTextField(p1,             "", new CC().spanX(2).growX(0));
 450  
                 createLabel(p1, "Country",      "");
 451  
                 createTextField(p1, "",         new CC().wrap());
 452  
 
 453  
                 createButton(p1, "New",         new CC().spanX(5).split(5).tag("other"));
 454  
                 createButton(p1, "Delete",      new CC().tag("other"));
 455  
                 createButton(p1, "Edit",        new CC().tag("other"));
 456  
                 createButton(p1, "Save",        new CC().tag("other"));
 457  
                 createButton(p1, "Cancel",      new CC().tag("cancel"));
 458  
 
 459  
                 return tabbedPane;
 460  
         }
 461  
 
 462  
         public Composite createAPI_Constraints2(Composite parent)
 463  
         {
 464  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 465  
 
 466  
                 LC layC = new LC().fill().wrap();
 467  
                 AC colC = new AC().align("right", 0).fill(1, 3).grow(100, 1, 3).align("right", 2).gap("15", 1);
 468  
                 AC rowC = new AC().index(6).gap("15!").align("top").grow(100, 8);
 469  
 
 470  
                 TabItem p1 = createTabPanel(tabbedPane, "Layout Showdown (improved)", new MigLayout(layC, colC, rowC));
 471  
 
 472  
                 // References to text fields not stored to reduce code clutter.
 473  
 
 474  
                 createLabel(p1, "Last Name",    "");
 475  
                 createTextField(p1, "",         "");
 476  
                 createLabel(p1, "First Name",   "");
 477  
                 createTextField(p1, "",         new CC().wrap());
 478  
                 createLabel(p1, "Phone",        "");
 479  
                 createTextField(p1, "",         "");
 480  
                 createLabel(p1, "Email",        "");
 481  
                 createTextField(p1, "",         "");
 482  
                 createLabel(p1, "Address 1",    "");
 483  
                 createTextField(p1,             "", new CC().spanX().growX());
 484  
                 createLabel(p1, "Address 2",    "");
 485  
                 createTextField(p1,             "", new CC().spanX().growX());
 486  
                 createLabel(p1, "City",         "");
 487  
                 createTextField(p1,             "", new CC().wrap());
 488  
                 createLabel(p1, "State",        "");
 489  
                 createTextField(p1, "",         "");
 490  
                 createLabel(p1, "Postal Code",  "");
 491  
                 createTextField(p1,             "", new CC().spanX(2).growX(0));
 492  
                 createLabel(p1, "Country",      "");
 493  
                 createTextField(p1, "",         new CC().wrap());
 494  
 
 495  
                 createButton(p1, "New",         new CC().spanX(5).split(5).tag("other"));
 496  
                 createButton(p1, "Delete",      new CC().tag("other"));
 497  
                 createButton(p1, "Edit",        new CC().tag("other"));
 498  
                 createButton(p1, "Save",        new CC().tag("other"));
 499  
                 createButton(p1, "Cancel",      new CC().tag("cancel"));
 500  
 
 501  
                 return tabbedPane;
 502  
         }
 503  
 
 504  
         public Composite createLayout_Showdown(Composite parent)
 505  
         {
 506  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 507  
 
 508  
                 TabItem p1 = createTabPanel(tabbedPane, "Layout Showdown (pure)", new MigLayout("", "[]15[][grow,fill]15[grow]"));
 509  
 
 510  
                 // References to text fields not stored to reduce code clutter.
 511  
 
 512  
                 createList(p1, "Mouse, Mickey",   "spany, growy, wmin 150");
 513  
                 createLabel(p1, "Last Name",      "");
 514  
                 createTextField(p1, "",           "");
 515  
                 createLabel(p1, "First Name",     "split");  // split divides the cell
 516  
                 createTextField(p1, "",           "growx, wrap");
 517  
                 createLabel(p1, "Phone",          "");
 518  
                 createTextField(p1, "",           "");
 519  
                 createLabel(p1, "Email",          "split");
 520  
                 createTextField(p1, "",           "growx, wrap");
 521  
                 createLabel(p1, "Address 1",      "");
 522  
                 createTextField(p1, "",           "span, growx"); // span merges cells
 523  
                 createLabel(p1, "Address 2",      "");
 524  
                 createTextField(p1, "",           "span, growx");
 525  
                 createLabel(p1, "City",           "");
 526  
                 createTextField(p1, "",           "wrap"); // wrap continues on next line
 527  
                 createLabel(p1, "State",          "");
 528  
                 createTextField(p1, "",           "");
 529  
                 createLabel(p1, "Postal Code",    "split");
 530  
                 createTextField(p1, "",           "growx, wrap");
 531  
                 createLabel(p1, "Country",        "");
 532  
                 createTextField(p1, "",           "wrap 15");
 533  
 
 534  
                 createButton(p1, "New",           "span, split, align right");
 535  
                 createButton(p1, "Delete",        "");
 536  
                 createButton(p1, "Edit",          "");
 537  
                 createButton(p1, "Save",          "");
 538  
                 createButton(p1, "Cancel",        "wrap push");
 539  
 
 540  
 
 541  
                 // Fixed version *******************************************
 542  
 
 543  
 
 544  
                 TabItem p2 = createTabPanel(tabbedPane, "Layout Showdown (improved)", new MigLayout("", "[]15[][grow,fill]15[][grow,fill]"));
 545  
 
 546  
                 // References to text fields not stored to reduce code clutter.
 547  
 
 548  
                 createList(p2, "Mouse, Mickey",   "spany, growy, wmin 150");
 549  
                 createLabel(p2, "Last Name",      "");
 550  
                 createTextField(p2, "",           "");
 551  
                 createLabel(p2, "First Name",     "");
 552  
                 createTextField(p2, "",           "wrap");
 553  
                 createLabel(p2, "Phone",          "");
 554  
                 createTextField(p2, "",           "");
 555  
                 createLabel(p2, "Email",          "");
 556  
                 createTextField(p2, "",           "wrap");
 557  
                 createLabel(p2, "Address 1",      "");
 558  
                 createTextField(p2, "",           "span");
 559  
                 createLabel(p2, "Address 2",      "");
 560  
                 createTextField(p2, "",           "span");
 561  
                 createLabel(p2, "City",           "");
 562  
                 createTextField(p2, "",           "wrap");
 563  
                 createLabel(p2, "State",          "");
 564  
                 createTextField(p2, "",           "");
 565  
                 createLabel(p2, "Postal Code",    "");
 566  
                 createTextField(p2, "",           "width 50, grow 0, wrap");
 567  
                 createLabel(p2, "Country",        "");
 568  
                 createTextField(p2, "",           "wrap 15");
 569  
 
 570  
                 createButton(p2, "New",           "tag other, span, split");
 571  
                 createButton(p2, "Delete",        "tag other");
 572  
                 createButton(p2, "Edit",          "tag other");
 573  
                 createButton(p2, "Save",          "tag other");
 574  
                 createButton(p2, "Cancel",        "tag cancel, wrap push");
 575  
 
 576  
                 return tabbedPane;
 577  
         }
 578  
 
 579  
         public Composite createDocking(Composite parent)
 580  
         {
 581  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 582  
                 tabbedPane.setLayoutData("grow");
 583  
 
 584  
                 TabItem p1 = createTabPanel(tabbedPane, "Docking 1", new MigLayout("fill"));
 585  
 
 586  
                 createPanel(p1, "1. North", "north");
 587  
                 createPanel(p1, "2. West", "west");
 588  
                 createPanel(p1, "3. East", "east");
 589  
                 createPanel(p1, "4. South", "south");
 590  
 
 591  
                 Table table = new Table(getComposite(p1), DOUBLE_BUFFER);
 592  
                 for (int i = 0; i < 5; i++) {
 593  
                         TableColumn tc = new TableColumn(table, SWT.LEFT | SWT.V_SCROLL | SWT.SCROLL_LINE);
 594  
                         tc.setText("Column " + (i + 1));
 595  
                         tc.setWidth(100);
 596  
                 }
 597  
 
 598  
                 for (int r = 0; r < 15; r++) {
 599  
                         TableItem item1 = new TableItem(table,0);
 600  
                         String[] data = new String[6];
 601  
                         for (int c = 0; c < data.length; c++)
 602  
                                 data[c] = "Cell " + (r + 1) + ", " + (c + 1);
 603  
             item1.setText(data);
 604  
                 }
 605  
                 table.setHeaderVisible(true);
 606  
         table.setLinesVisible(true);
 607  
                 table.setLayoutData("grow");
 608  
 
 609  
 
 610  
                 TabItem p2 = createTabPanel(tabbedPane, "Docking 2 (fill)", new MigLayout("fill", "[c]", ""));
 611  
 
 612  
                 createPanel(p2, "1. North", "north");
 613  
                 createPanel(p2, "2. North", "north");
 614  
                 createPanel(p2, "3. West", "west");
 615  
                 createPanel(p2, "4. West", "west");
 616  
                 createPanel(p2, "5. South", "south");
 617  
                 createPanel(p2, "6. East", "east");
 618  
                 createButton(p2, "7. Normal", "");
 619  
                 createButton(p2, "8. Normal", "");
 620  
                 createButton(p2, "9. Normal", "");
 621  
 
 622  
                 TabItem p3 = createTabPanel(tabbedPane, "Docking 3", new MigLayout());
 623  
 
 624  
                 createPanel(p3, "1. North", "north");
 625  
                 createPanel(p3, "2. South", "south");
 626  
                 createPanel(p3, "3. West", "west");
 627  
                 createPanel(p3, "4. East", "east");
 628  
                 createButton(p3, "5. Normal", "");
 629  
 
 630  
                 TabItem p4 = createTabPanel(tabbedPane, "Docking 4", new MigLayout());
 631  
 
 632  
                 createPanel(p4, "1. North", "north");
 633  
                 createPanel(p4, "2. North", "north");
 634  
                 createPanel(p4, "3. West", "west");
 635  
                 createPanel(p4, "4. West", "west");
 636  
                 createPanel(p4, "5. South", "south");
 637  
                 createPanel(p4, "6. East", "east");
 638  
                 createButton(p4, "7. Normal", "");
 639  
                 createButton(p4, "8. Normal", "");
 640  
                 createButton(p4, "9. Normal", "");
 641  
 
 642  
                 TabItem p5 = createTabPanel(tabbedPane, "Docking 5 (fillx)", new MigLayout("fillx", "[c]", ""));
 643  
 
 644  
                 createPanel(p5, "1. North", "north");
 645  
                 createPanel(p5, "2. North", "north");
 646  
                 createPanel(p5, "3. West", "west");
 647  
                 createPanel(p5, "4. West", "west");
 648  
                 createPanel(p5, "5. South", "south");
 649  
                 createPanel(p5, "6. East", "east");
 650  
                 createButton(p5, "7. Normal", "");
 651  
                 createButton(p5, "8. Normal", "");
 652  
                 createButton(p5, "9. Normal", "");
 653  
 
 654  
                 TabItem p6 = createTabPanel(tabbedPane, "Random Docking", new MigLayout("fill"));
 655  
 
 656  
                 String[] sides = {"north", "east", "south", "west"};
 657  
                 Random rand = new Random();
 658  
                 for (int i = 0; i < 20; i++) {
 659  
                         int side = rand.nextInt(4);
 660  
                         createPanel(p6, ((i + 1) + " " + sides[side]), sides[side]);
 661  
                 }
 662  
                 createPanel(p6, "I'm in the Center!", "grow");
 663  
 
 664  
                 return tabbedPane;
 665  
         }
 666  
 
 667  
         public Control createAbsolute_Position(final Composite parent)
 668  
         {
 669  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 670  
 
 671  
                 // Pos tab
 672  
                 TabItem posTabPanel = createTabPanel(tabbedPane, "X Y Positions", new FillLayout());
 673  
                 final Composite posPanel = createPanel(posTabPanel, new MigLayout());
 674  
 
 675  
                 createButton(posPanel, "pos 0.5al 0al", null);
 676  
                 createButton(posPanel, "pos 1al 0al", null);
 677  
                 createButton(posPanel, "pos 0.5al 0.5al", null);
 678  
                 createButton(posPanel, "pos 5in 45lp", null);
 679  
                 createButton(posPanel, "pos 0.5al 0.5al", null);
 680  
                 createButton(posPanel, "pos 0.5al 1al", null);
 681  
                 createButton(posPanel, "pos 1al .25al", null);
 682  
                 createButton(posPanel, "pos visual.x2-pref visual.y2-pref", null);
 683  
                 createButton(posPanel, "pos 1al -1in", null);
 684  
                 createButton(posPanel, "pos 100 100", null);
 685  
                 createButton(posPanel, "pos (10+(20*3lp)) 200", null);
 686  
                 createButton(posPanel, "Drag Window! (pos 500-container.xpos 500-container.ypos)",
 687  
                              "pos 500-container.xpos 500-container.ypos");
 688  
 
 689  
                 // Bounds tab
 690  
                 TabItem boundsTabPanel = createTabPanel(tabbedPane, "X1 Y1 X2 Y2 Bounds", new FillLayout());
 691  
                 Composite boundsPanel = createPanel(boundsTabPanel, new MigLayout());
 692  
 
 693  
                 Label southLabel = createLabel(boundsPanel, "pos (visual.x+visual.w*0.1) visual.y2-40 (visual.x2-visual.w*0.1) visual.y2", null, SWT.CENTER | SWT.BORDER);
 694  
                 southLabel.setBackground(new Color(display, 200, 200, 255));
 695  
                 deriveFont(southLabel, SWT.BOLD, 10);
 696  
 
 697  
                 createButton(boundsPanel, "pos 0 0 container.x2 n", null);
 698  
                 createButton(boundsPanel, "pos visual.x 40 visual.x2 70", null);
 699  
                 createButton(boundsPanel, "pos visual.x 100 visual.x2 p", null);
 700  
                 createButton(boundsPanel, "pos 0.1al 0.4al n visual.y2-10", null);
 701  
                 createButton(boundsPanel, "pos 0.9al 0.4al n visual.y2-10", null);
 702  
                 createButton(boundsPanel, "pos 0.5al 0.5al, pad 3 0 -3 0", null);
 703  
                 createButton(boundsPanel, "pos n n 50% 50%", null);
 704  
                 createButton(boundsPanel, "pos 50% 50% n n", null);
 705  
                 createButton(boundsPanel, "pos 50% n n 50%", null);
 706  
                 createButton(boundsPanel, "pos n 50% 50% n", null);
 707  
 
 708  
                 // Glass pane tab
 709  
 //                final TabItem glassPanel = createTabPanel(tabbedPane, "GlassPane Substitute", parent, new SwtMigLayout("align c c"));
 710  
 //                final Button butt = new Button("Press me!!");
 711  
 //                glassPanel.add(butt);
 712  
 //
 713  
 //                butt.addActionListener(new ActionListener()                {
 714  
 //                        public void actionPerformed(ActionEvent e)
 715  
 //                        {
 716  
 //                                butt.setEnabled(false);
 717  
 //                                final JPanel bg = new JPanel(parent, new SwtMigLayout("align c c,fill")) {
 718  
 //                                        public void paint(Graphics g)
 719  
 //                                        {
 720  
 //                                                g.setColor(getBackground());
 721  
 //                                                g.fillRect(0, 0, getWidth(), getHeight());
 722  
 //                                                super.paint(g);
 723  
 //                                        }
 724  
 //                                };
 725  
 //                                bg.setOpaque(false);
 726  
 //                                configureActiveComponet(bg);
 727  
 //
 728  
 //                                final Label label = createLabel("You don't need a GlassPane to be cool!");
 729  
 //                                label.setFont(label.getFont().deriveFont(30f));
 730  
 //                                label.setForeground(new Color(255, 255, 255, 0));
 731  
 //                                bg.add(label, "align 50% 30%");
 732  
 //
 733  
 //                                glassPanel.add(bg, "pos 0 0 visual.x2 visual.y2", 0);
 734  
 //                                final long startTime = System.nanoTime();
 735  
 //                                final long endTime = startTime + 500000000L;
 736  
 //
 737  
 //                                glassPanel.revalidate();
 738  
 //
 739  
 //                                final javax.swing.Timer timer = new Timer(25, null);
 740  
 //
 741  
 //                                timer.addActionListener(new ActionListener() {
 742  
 //                                        public void actionPerformed(ActionEvent e)
 743  
 //                                        {
 744  
 //                                                long now = System.nanoTime();
 745  
 //                                                int alpha = (int) (((now - startTime) / (double) (endTime - startTime)) * 300);
 746  
 //                                                if (alpha < 150)
 747  
 //                                                        bg.setBackground(new Color(100, 100, 100, alpha));
 748  
 //
 749  
 //                                                if (alpha > 150 && alpha < 405) {
 750  
 //                                                        label.setForeground(new Color(255, 255, 255, (alpha - 150)));
 751  
 //                                                        bg.repaint();
 752  
 //                                                }
 753  
 //                                                if (alpha > 405)
 754  
 //                                                        timer.stop();
 755  
 //                                        }
 756  
 //                                });
 757  
 //                                timer.start();
 758  
 //                        }
 759  
 //                });
 760  
 //
 761  
 
 762  
                 parent.getShell().addControlListener(new ControlAdapter() {
 763  
                         public void controlMoved(ControlEvent e)
 764  
                         {
 765  
                                 if (!posPanel.isDisposed()) {
 766  
                                         posPanel.layout();
 767  
                                 } else {
 768  
                                         parent.getShell().removeControlListener(this);
 769  
                                 }
 770  
                         }
 771  
                 });
 772  
 
 773  
                 return tabbedPane;
 774  
         }
 775  
 
 776  
         public Control createComponent_Links(Composite parent)
 777  
         {
 778  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 779  
 
 780  
                 TabItem linksPanel = createTabPanel(tabbedPane, "Component Links", new MigLayout());
 781  
 
 782  
                 // Links tab
 783  
                 createButton(linksPanel, "Mini", "pos null ta.y ta.x2 null, pad 3 0 -3 0");
 784  
                 createTextArea(linksPanel, "Components, Please Link to Me!\nMy ID is: 'ta'", "id ta, pos 0.5al 0.5al, w 300");
 785  
                 createButton(linksPanel, "id b1,pos ta.x2 ta.y2", null);
 786  
                 createButton(linksPanel, "pos b1.x2+rel b1.y visual.x2 null", null);
 787  
                 createCheck(linksPanel, "pos (ta.x+indent) (ta.y2+rel)", null);
 788  
                 createButton(linksPanel, "pos ta.x2+rel ta.y visual.x2 null", null);
 789  
                 createButton(linksPanel, "pos null ta.y+(ta.h-pref)/2 ta.x-rel null", null);
 790  
                 createButton(linksPanel, "pos ta.x ta.y2+100 ta.x2 null", null);
 791  
 
 792  
                 // External tab
 793  
                 TabItem externalPanel = createTabPanel(tabbedPane, "External Components", new MigLayout());
 794  
 
 795  
                 Button extButt = createButton(externalPanel, "Bounds Externally Set!", "id ext, external");
 796  
                 extButt.setBounds(250, 130, 200, 40);
 797  
                 createButton(externalPanel, "pos ext.x2 ext.y2", "pos ext.x2 ext.y2");
 798  
                 createButton(externalPanel, "pos null null ext.x ext.y", "pos null null ext.x ext.y");
 799  
 
 800  
                 TabItem egTabPanel = createTabPanel(tabbedPane, "End Grouping", new FillLayout());
 801  
                 final Composite egPanel = createPanel(egTabPanel, new MigLayout());
 802  
 
 803  
                 createButton(egPanel, "id b1, endgroupx g1, pos 200 200", null);
 804  
                 createButton(egPanel, "id b2, endgroupx g1, pos (b1.x+2ind) (b1.y2+rel)", null);
 805  
                 createButton(egPanel, "id b3, endgroupx g1, pos (b1.x+4ind) (b2.y2+rel)", null);
 806  
                 createButton(egPanel, "id b4, endgroupx g1, pos (b1.x+6ind) (b3.y2+rel)", null);
 807  
 
 808  
                 // Group Bounds tab
 809  
                 TabItem gpTabPanel = createTabPanel(tabbedPane, "Group Bounds", new FillLayout());
 810  
                 final Composite gpPanel = createPanel(gpTabPanel, new MigLayout());
 811  
 
 812  
                 createButton(gpPanel, "id grp1.b1, pos n 0.5al 50% n", null);
 813  
                 createButton(gpPanel, "id grp1.b2, pos 50% 0.5al n n", null);
 814  
                 createButton(gpPanel, "id grp1.b3, pos 0.5al n n b1.y", null);
 815  
                 createButton(gpPanel, "id grp1.b4, pos 0.5al b1.y2 n n", null);
 816  
 
 817  
                 createButton(gpPanel, "pos n grp1.y2 grp1.x n", null);
 818  
                 createButton(gpPanel, "pos n n grp1.x grp1.y", null);
 819  
                 createButton(gpPanel, "pos grp1.x2 n n grp1.y", null);
 820  
                 createButton(gpPanel, "pos grp1.x2 grp1.y2", null);
 821  
 
 822  
                 Composite boundsPanel = createPanel(gpPanel, (Layout) null);
 823  
                 boundsPanel.setLayoutData("pos grp1.x grp1.y grp1.x2 grp1.y2");
 824  
                 boundsPanel.setBackground(new Color(display, 200, 200, 255));
 825  
 
 826  
                 return tabbedPane;
 827  
         }
 828  
 
 829  
         public Control createFlow_Direction(Composite parent)
 830  
         {
 831  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 832  
 
 833  
                 createFlowPanel(tabbedPane, "Layout: flowx, Cell: flowx", "", "flowx");
 834  
                 createFlowPanel(tabbedPane, "Layout: flowx, Cell: flowy", "", "flowy");
 835  
                 createFlowPanel(tabbedPane, "Layout: flowy, Cell: flowx", "flowy", "flowx");
 836  
                 createFlowPanel(tabbedPane, "Layout: flowy, Cell: flowy", "flowy", "flowy");
 837  
 
 838  
                 return tabbedPane;
 839  
         }
 840  
 
 841  
         private TabItem createFlowPanel(TabFolder parent, String text, String gridFlow, String cellFlow)
 842  
         {
 843  
                 MigLayout lm = new MigLayout("center, wrap 3," + gridFlow,
 844  
                                              "[110,fill]",
 845  
                                              "[110,fill]");
 846  
                 TabItem panel = createTabPanel(parent, text, lm);
 847  
 
 848  
                 for (int i = 0; i < 9; i++) {
 849  
                         Composite b = createPanel(panel, "" + (i + 1), cellFlow);
 850  
                         Font f = deriveFont(b, SWT.DEFAULT, 20);
 851  
                         b.getChildren()[0].setFont(f);
 852  
                 }
 853  
 
 854  
                 Composite b = createPanel(panel, "5:2", cellFlow + ",cell 1 1");
 855  
                 Font f = deriveFont(b, SWT.DEFAULT, 20);
 856  
                 b.getChildren()[0].setFont(f);
 857  
 
 858  
                 return panel;
 859  
         }
 860  
 
 861  
         public Control createDebug(Composite parent)
 862  
         {
 863  
                 return createPlainImpl(parent, true);
 864  
         }
 865  
 
 866  
         public Control createButton_Bars(final Composite parent)
 867  
         {
 868  
                 MigLayout lm = new MigLayout("ins 0 0 15lp 0",
 869  
                                                 "[grow]",
 870  
                                                 "[grow]u[baseline,nogrid]");
 871  
 
 872  
                 final Composite mainPanel = new Composite(parent, DOUBLE_BUFFER);
 873  
                 mainPanel.setLayout(lm);
 874  
 
 875  
                 TabFolder tabbedPane = new TabFolder(mainPanel, DOUBLE_BUFFER);
 876  
                 tabbedPane.setLayoutData("grow, wrap");
 877  
 
 878  
                 createButtonBarsPanel(tabbedPane, "Buttons", "help", false);
 879  
                 createButtonBarsPanel(tabbedPane, "Buttons with Help2", "help2", false);
 880  
                 createButtonBarsPanel(tabbedPane, "Buttons (Same width)", "help", true);
 881  
 
 882  
                 createLabel(mainPanel, "Button Order:", "");
 883  
                 final Label formatLabel = createLabel(mainPanel, "", "growx");
 884  
                 deriveFont(formatLabel, SWT.BOLD , -1);
 885  
 
 886  
                 final Button winButt = createToggleButton(mainPanel, "Windows", "wmin button");
 887  
                 final Button macButt = createToggleButton(mainPanel, "Mac OS X", "wmin button");
 888  
 
 889  
                 winButt.addSelectionListener(new SelectionAdapter() {
 890  
                         public void widgetSelected(SelectionEvent e)
 891  
                         {
 892  
                                 if (winButt.getSelection()) {
 893  
                                         PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
 894  
                                         formatLabel.setText("'" + PlatformDefaults.getButtonOrder() + "'");
 895  
                                         macButt.setSelection(false);
 896  
                                         mainPanel.layout();
 897  
                                 }
 898  
                         }
 899  
                 });
 900  
 
 901  
                 macButt.addSelectionListener(new SelectionAdapter() {
 902  
                         public void widgetSelected(SelectionEvent e)
 903  
                         {
 904  
                                 if (macButt.getSelection()) {
 905  
                                         PlatformDefaults.setPlatform(PlatformDefaults.MAC_OSX);
 906  
                                         formatLabel.setText("'" + PlatformDefaults.getButtonOrder() + "'");
 907  
                                         winButt.setSelection(false);
 908  
                                         mainPanel.layout();
 909  
                                 }
 910  
                         }
 911  
                 });
 912  
 
 913  
                 Button helpButt = createButton(mainPanel, "Help", "gap unrel,wmin button");
 914  
                 helpButt.addSelectionListener(new SelectionAdapter() {
 915  
                         public void widgetSelected(SelectionEvent e)
 916  
                         {
 917  
                                 MessageBox msgBox = new MessageBox(parent.getShell());
 918  
                                 msgBox.setMessage("See JavaDoc for PlatformConverter.getButtonBarOrder(..) for details on the format string.");
 919  
                                 msgBox.open();
 920  
                         }
 921  
                 });
 922  
 
 923  
                 (PlatformDefaults.getPlatform() == PlatformDefaults.WINDOWS_XP ?  winButt : macButt).setSelection(true);
 924  
 
 925  
                 return mainPanel;
 926  
         }
 927  
 
 928  
         private TabItem createButtonBarsPanel(TabFolder parent, String text, String helpTag, boolean sizeLocked)
 929  
         {
 930  
                 MigLayout lm = new MigLayout("nogrid, fillx, aligny 100%, gapy unrel");
 931  
                 TabItem panel = createTabPanel(parent, text, lm);
 932  
 
 933  
                 // Notice that the order in the rows below does not matter...
 934  
                 String[][] buttons = new String[][] {
 935  
                                 {"No", "Yes"},
 936  
                                 {"Help", "Close"},
 937  
                                 {"OK", "Help"},
 938  
                                 {"OK", "Cancel", "Help"},
 939  
                                 {"OK", "Cancel", "Apply", "Help"},
 940  
                                 {"No", "Yes", "Cancel"},
 941  
                                 {"Help", "< Move Back", "Move Forward >", "Cancel"},
 942  
                                 {"Print...", "Cancel", "Help"},
 943  
                 };
 944  
 
 945  
                 for (int r = 0; r < buttons.length; r++) {
 946  
                         for (int i = 0; i < buttons[r].length; i++) {
 947  
                                 String txt = buttons[r][i];
 948  
                                 String tag = txt;
 949  
 
 950  
                                 if (txt.equals("Help")) {
 951  
                                         tag = helpTag;
 952  
                                 } else if (txt.equals("< Move Back")) {
 953  
                                         tag = "back";
 954  
                                 } else if (txt.equals("Close")) {
 955  
                                         tag = "cancel";
 956  
                                 } else if (txt.equals("Move Forward >")) {
 957  
                                         tag = "next";
 958  
                                 } else if (txt.equals("Print...")) {
 959  
                                         tag = "other";
 960  
                                 }
 961  
                                 String wrap = (i == buttons[r].length - 1) ? ",wrap" : "";
 962  
                                 String sizeGroup = sizeLocked ? ("sgx " + r + ",") : "";
 963  
                                 createButton(panel, txt, sizeGroup + "tag " + tag + wrap);
 964  
                         }
 965  
                 }
 966  
 
 967  
                 return panel;
 968  
         }
 969  
 
 970  
         public Control createOrientation(Composite parent)
 971  
         {
 972  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 973  
 
 974  
                 MigLayout lm = new MigLayout("flowy", "[grow,fill]", "[]0[]15lp[]0[]");
 975  
                 TabItem mainPanel = createTabPanel(tabbedPane, "Orientation", lm);
 976  
 
 977  
                 // Default orientation
 978  
                 MigLayout defLM = new MigLayout("", "[][grow,fill]", "");
 979  
 
 980  
                 Composite defPanel = createPanel(mainPanel, defLM);
 981  
                 addSeparator(defPanel, "Default Orientation");
 982  
                 createLabel(defPanel, "Level", "");
 983  
                 createTextField(defPanel, "", "span,growx");
 984  
                 createLabel(defPanel, "Radar", "");
 985  
                 createTextField(defPanel, "", "");
 986  
                 createTextField(defPanel, "", "");
 987  
 
 988  
                 // Right-to-left, Top-to-bottom
 989  
                 MigLayout rtlLM = new MigLayout("rtl,ttb",
 990  
                                                    "[][grow,fill]",
 991  
                                                    "");
 992  
                 Composite rtlPanel = createPanel(mainPanel, rtlLM);
 993  
                 addSeparator(rtlPanel, "Right to Left");
 994  
                 createLabel(rtlPanel, "Level", "");
 995  
                 createTextField(rtlPanel, "", "span,growx");
 996  
                 createLabel(rtlPanel, "Radar", "");
 997  
                 createTextField(rtlPanel, "", "");
 998  
                 createTextField(rtlPanel, "", "");
 999  
 
 1000  
                 // Right-to-left, Bottom-to-top
 1001  
                 MigLayout rtlbLM = new MigLayout("rtl,btt",
 1002  
                                                  "[][grow,fill]",
 1003  
                                                  "");
 1004  
                 Composite rtlbPanel = createPanel(mainPanel, rtlbLM);
 1005  
                 addSeparator(rtlbPanel, "Right to Left, Bottom to Top");
 1006  
                 createLabel(rtlbPanel, "Level", "");
 1007  
                 createTextField(rtlbPanel, "", "span,growx");
 1008  
                 createLabel(rtlbPanel, "Radar", "");
 1009  
                 createTextField(rtlbPanel, "", "");
 1010  
                 createTextField(rtlbPanel, "", "");
 1011  
 
 1012  
                 // Left-to-right, Bottom-to-top
 1013  
                 MigLayout ltrbLM = new MigLayout("ltr,btt",
 1014  
                                                  "[][grow,fill]",
 1015  
                                                  "");
 1016  
 
 1017  
                 Composite ltrbPanel = createPanel(mainPanel, ltrbLM);
 1018  
                 addSeparator(ltrbPanel, "Left to Right, Bottom to Top");
 1019  
                 createLabel(ltrbPanel, "Level", "");
 1020  
                 createTextField(ltrbPanel, "", "span,growx");
 1021  
                 createLabel(ltrbPanel, "Radar", "");
 1022  
                 createTextField(ltrbPanel, "", "");
 1023  
                 createTextField(ltrbPanel, "", "");
 1024  
 
 1025  
                 return tabbedPane;
 1026  
         }
 1027  
 
 1028  
         public Control createCell_Position(Composite parent)
 1029  
         {
 1030  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1031  
 
 1032  
                 // Absolute grid position
 1033  
                 MigLayout absLM = new MigLayout("",
 1034  
                                                 "[100:pref,fill]",
 1035  
                                                 "[100:pref,fill]");
 1036  
 
 1037  
                 TabItem absPanel = createTabPanel(tabbedPane, "Absolute", absLM);
 1038  
                 createPanel(absPanel, "cell 0 0", null);
 1039  
                 createPanel(absPanel, "cell 2 0", null);
 1040  
                 createPanel(absPanel, "cell 3 0", null);
 1041  
                 createPanel(absPanel, "cell 1 1", null);
 1042  
                 createPanel(absPanel, "cell 0 2", null);
 1043  
                 createPanel(absPanel, "cell 2 2", null);
 1044  
                 createPanel(absPanel, "cell 2 2", null);
 1045  
 
 1046  
 
 1047  
                 // Relative grid position with wrap
 1048  
                 MigLayout relAwLM = new MigLayout("wrap",
 1049  
                                                   "[100:pref,fill][100:pref,fill][100:pref,fill][100:pref,fill]",
 1050  
                                                   "[100:pref,fill]");
 1051  
                 TabItem relAwPanel = createTabPanel(tabbedPane, "Relative + Wrap", relAwLM);
 1052  
                 createPanel(relAwPanel, "", null);
 1053  
                 createPanel(relAwPanel, "skip", null);
 1054  
                 createPanel(relAwPanel, "", null);
 1055  
                 createPanel(relAwPanel, "skip,wrap", null);
 1056  
                 createPanel(relAwPanel, "", null);
 1057  
                 createPanel(relAwPanel, "skip,split", null);
 1058  
                 createPanel(relAwPanel, "", null);
 1059  
 
 1060  
 
 1061  
                 // Relative grid position with manual wrap
 1062  
                 MigLayout relWLM = new MigLayout("",
 1063  
                                                  "[100:pref,fill]",
 1064  
                                                  "[100:pref,fill]");
 1065  
                 TabItem relWPanel = createTabPanel(tabbedPane, "Relative", relWLM);
 1066  
                 createPanel(relWPanel, "", null);
 1067  
                 createPanel(relWPanel, "skip", null);
 1068  
                 createPanel(relWPanel, "wrap", null);
 1069  
                 createPanel(relWPanel, "skip,wrap", null);
 1070  
                 createPanel(relWPanel, "", null);
 1071  
                 createPanel(relWPanel, "skip,split", null);
 1072  
                 createPanel(relWPanel, "", null);
 1073  
 
 1074  
 
 1075  
                 // Mixed relative and absolute grid position
 1076  
                 MigLayout mixLM = new MigLayout("",
 1077  
                                                    "[100:pref,fill]",
 1078  
                                                    "[100:pref,fill]");
 1079  
                 TabItem mixPanel = createTabPanel(tabbedPane, "Mixed", mixLM);
 1080  
                 createPanel(mixPanel, "", null);
 1081  
                 createPanel(mixPanel, "cell 2 0", null);
 1082  
                 createPanel(mixPanel, "", null);
 1083  
                 createPanel(mixPanel, "cell 1 1,wrap", null);
 1084  
                 createPanel(mixPanel, "", null);
 1085  
                 createPanel(mixPanel, "cell 2 2,split", null);
 1086  
                 createPanel(mixPanel, "", null);
 1087  
 
 1088  
                 return tabbedPane;
 1089  
         }
 1090  
 
 1091  
         public Control createPlain(Composite parent)
 1092  
         {
 1093  
                 return createPlainImpl(parent, false);
 1094  
         }
 1095  
 
 1096  
         private Control createPlainImpl(Composite parent, boolean debug)
 1097  
         {
 1098  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1099  
 
 1100  
                 MigLayout lm = new MigLayout((debug && benchRuns == 0 ? "debug" : ""), "[r][100lp, fill][60lp][95lp, fill]", "");
 1101  
                 TabItem panel = createTabPanel(tabbedPane, "Plain", lm);
 1102  
 
 1103  
                 addSeparator(panel, "Manufacturer");
 1104  
                 createLabel(panel, "Company", "");
 1105  
                 createTextField(panel, "", "span,growx");
 1106  
                 createLabel(panel, "Contact", "");
 1107  
                 createTextField(panel, "", "span,growx");
 1108  
                 createLabel(panel, "Order No", "");
 1109  
                 createTextField(panel, "", "wmin 15*6,wrap");
 1110  
 
 1111  
                 addSeparator(panel, "Inspector");
 1112  
                 createLabel(panel, "Name", "");
 1113  
                 createTextField(panel, "", "span,growx");
 1114  
                 createLabel(panel, "Reference No", "");
 1115  
                 createTextField(panel, "", "wrap");
 1116  
                 createLabel(panel, "Status", "");
 1117  
                 createCombo(panel, new String[] {"In Progress", "Finnished", "Released"}, "wrap");
 1118  
 
 1119  
                 addSeparator(panel, "Ship");
 1120  
                 createLabel(panel, "Shipyard", "");
 1121  
                 createTextField(panel, "", "span,growx");
 1122  
                 createLabel(panel, "Register No", "");
 1123  
                 createTextField(panel, "", "");
 1124  
                 createLabel(panel, "Hull No", "right");
 1125  
                 createTextField(panel, "", "wmin 15*6,wrap");
 1126  
                 createLabel(panel, "Project StructureType", "");
 1127  
                 createCombo(panel, new String[] {"New Building", "Convention", "Repair"}, "wrap");
 1128  
 
 1129  
                 if (debug)
 1130  
                         createLabel(panel, "Blue is component bounds. Cell bounds (red) can not be shown in SWT", "newline,ax left,span,gaptop 40");
 1131  
 
 1132  
                 return tabbedPane;
 1133  
         }
 1134  
 
 1135  
         public Control createBound_Sizes(Composite parent)
 1136  
         {
 1137  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1138  
 
 1139  
                 for (int i = 0; i < 2; i++) {   // Jumping for 0 and Stable for 1
 1140  
                         String colConstr = i == 0 ? "[right][300]" : "[right, 150lp:pref][300]";
 1141  
 
 1142  
                         MigLayout LM1 = new MigLayout("wrap", colConstr, "");
 1143  
                         TabItem panel1 = createTabPanel(tabbedPane, i == 0 ? "Jumping 1" : "Stable 1", LM1);
 1144  
                         createLabel(panel1, "File Number:", "");
 1145  
                         createTextField(panel1, "", "growx");
 1146  
                         createLabel(panel1, "RFQ Number:", "");
 1147  
                         createTextField(panel1, "", "growx");
 1148  
                         createLabel(panel1, "Entry Date:", "");
 1149  
                         createTextField(panel1, "        ", "wmin 6*6");
 1150  
                         createLabel(panel1, "Sales Person:", "");
 1151  
                         createTextField(panel1, "", "growx");
 1152  
 
 1153  
                         MigLayout LM2 = new MigLayout("wrap", colConstr, "");
 1154  
                         TabItem panel2 = createTabPanel(tabbedPane, i == 0 ? "Jumping 2" : "Stable 2", LM2);
 1155  
                         createLabel(panel2, "Shipper:", "");
 1156  
                         createTextField(panel2, "        ", "split 2");
 1157  
                         createTextField(panel2, "", "growx");
 1158  
                         createLabel(panel2, "Consignee:", "");
 1159  
                         createTextField(panel2, "        ", "split 2");
 1160  
                         createTextField(panel2, "", "growx");
 1161  
                         createLabel(panel2, "Departure:", "");
 1162  
                         createTextField(panel2, "        ", "split 2");
 1163  
                         createTextField(panel2, "", "growx");
 1164  
                         createLabel(panel2, "Destination:", "");
 1165  
                         createTextField(panel2, "        ", "split 2");
 1166  
                         createTextField(panel2, "", "growx");
 1167  
                 }
 1168  
                 return tabbedPane;
 1169  
         }
 1170  
 
 1171  
         public Control createComponent_Sizes(Composite parent)
 1172  
         {
 1173  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1174  
 
 1175  
                 MigLayout lm = new MigLayout("wrap", "[right][0:pref,grow]", "");
 1176  
 
 1177  
                 TabItem tabPanel = createTabPanel(tabbedPane, "Component Sizes", new FillLayout());
 1178  
 
 1179  
                 SashForm sashForm = new SashForm(getComposite(tabPanel), SWT.HORIZONTAL | SWT.SMOOTH);
 1180  
                 sashForm.setBackground(new Color(display, 255, 255, 255));
 1181  
                 sashForm.setBackgroundMode(SWT.INHERIT_FORCE);
 1182  
 
 1183  
                 Composite panel = createPanel(sashForm, lm, SWT.BORDER);
 1184  
                 createTextArea(sashForm, "Use slider to see how the components grow and shrink depending on the constraints set on them.", "");
 1185  
 
 1186  
                 createLabel(panel, "", "");
 1187  
                 createTextField(panel, "8       ", "");
 1188  
                 createLabel(panel, "width min!", null);
 1189  
                 createTextField(panel, "3  ", "width min!");
 1190  
                 createLabel(panel, "width pref!", "");
 1191  
                 createTextField(panel, "3  ", "width pref!");
 1192  
                 createLabel(panel, "width min:pref", null);
 1193  
                 createTextField(panel, "8       ", "width min:pref");
 1194  
                 createLabel(panel, "width min:100:150", null);
 1195  
                 createTextField(panel, "8       ", "width min:100:150");
 1196  
                 createLabel(panel, "width min:100:150, growx", null);
 1197  
                 createTextField(panel, "8       ", "width min:100:150, growx");
 1198  
                 createLabel(panel, "width min:100, growx", null);
 1199  
                 createTextField(panel, "8       ", "width min:100, growx");
 1200  
                 createLabel(panel, "width 40!", null);
 1201  
                 createTextField(panel, "8       ", "width 40!");
 1202  
                 createLabel(panel, "width 40:40:40", null);
 1203  
                 createTextField(panel, "8       ", "width 40:40:40");
 1204  
 
 1205  
                 return tabbedPane;
 1206  
         }
 1207  
 
 1208  
         public Control createCell_Alignments(Composite parent)
 1209  
         {
 1210  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1211  
 
 1212  
                 // Horizontal
 1213  
                 MigLayout hLM = new MigLayout("wrap",
 1214  
                                               "[grow,left][grow,center][grow,right][grow,fill,center]",
 1215  
                                               "[]unrel[][]");
 1216  
                 TabItem hPanel = createTabPanel(tabbedPane, "Horizontal", hLM);
 1217  
                 String[] sizes = new String[] {"", "growx", "growx 0", "left", "center", "right", "leading", "trailing"};
 1218  
                 createLabel(hPanel, "[left]", "c");
 1219  
                 createLabel(hPanel, "[center]", "c");
 1220  
                 createLabel(hPanel, "[right]", "c");
 1221  
                 createLabel(hPanel, "[fill,center]", "c, growx 0");
 1222  
 
 1223  
                 for (int r = 0; r < sizes.length; r++) {
 1224  
                         for (int c = 0; c < 4; c++) {
 1225  
                                 String text = sizes[r].length() > 0 ? sizes[r] : "default";
 1226  
                                 createButton(hPanel, text, sizes[r]);
 1227  
                         }
 1228  
                 }
 1229  
 
 1230  
                 // Vertical
 1231  
                 MigLayout vLM = new MigLayout("wrap,flowy",
 1232  
                                                  "[right][]",
 1233  
                                                  "[grow,top][grow,center][grow,bottom][grow,fill,bottom][grow,fill,baseline]");
 1234  
                 TabItem vPanel = createTabPanel(tabbedPane, "Vertical", vLM);
 1235  
                 String[] vSizes = new String[] {"", "growy", "growy 0", "top", "center", "bottom"};
 1236  
                 createLabel(vPanel, "[top]", "center");
 1237  
                 createLabel(vPanel, "[center]", "center");
 1238  
                 createLabel(vPanel, "[bottom]", "center");
 1239  
                 createLabel(vPanel, "[fill, bottom]", "center, growy 0");
 1240  
                 createLabel(vPanel, "[fill, baseline]", "center");
 1241  
 
 1242  
                 for (int c = 0; c < vSizes.length; c++) {
 1243  
                         for (int r = 0; r < 5; r++) {
 1244  
                                 String text = vSizes[c].length() > 0 ? vSizes[c] : "default";
 1245  
                                 createButton(vPanel, text, vSizes[c]);
 1246  
                         }
 1247  
                 }
 1248  
 
 1249  
                 return tabbedPane;
 1250  
         }
 1251  
 
 1252  
         public Control createUnits(Composite parent)
 1253  
         {
 1254  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1255  
 
 1256  
                 // Horizontal
 1257  
                 MigLayout hLM = new MigLayout("wrap",
 1258  
                                               "[right][]",
 1259  
                                               "");
 1260  
                 TabItem hPanel = createTabPanel(tabbedPane, "Horizontal", hLM);
 1261  
                 String[] sizes = new String[] {"72pt", "25.4mm", "2.54cm", "1in", "72px", "96px", "120px", "25%", "30sp"};
 1262  
                 for (int i = 0; i < sizes.length; i++) {
 1263  
                         createLabel(hPanel, sizes[i], "");
 1264  
                         createTextField(hPanel, "", "width " + sizes[i] + "");
 1265  
                 }
 1266  
 
 1267  
                 // Horizontal lp
 1268  
                 MigLayout hlpLM = new MigLayout("", "[right][][]", "");
 1269  
                 TabItem hlpPanel = createTabPanel(tabbedPane, "Horizontal LP", hlpLM);
 1270  
                 createLabel(hlpPanel, "9 cols", "");
 1271  
                 createTextField(hlpPanel, "", "wmin 9*6");
 1272  
                 String[] lpSizes = new String[] {"75lp", "75px", "88px", "100px"};
 1273  
                 createLabel(hlpPanel, "", "wrap");
 1274  
                 for (int i = 0; i < lpSizes.length; i++) {
 1275  
                         createLabel(hlpPanel, lpSizes[i], "");
 1276  
                         createTextField(hlpPanel, "", "width " + lpSizes[i] + ", wrap");
 1277  
                 }
 1278  
 
 1279  
                 // Vertical
 1280  
                 MigLayout vLM = new MigLayout("wrap,flowy",
 1281  
                                                  "[c]",
 1282  
                                                  "[top][top]");
 1283  
                 TabItem vPanel = createTabPanel(tabbedPane, "Vertical", vLM);
 1284  
                 String[] vSizes = new String[] {"72pt", "25.4mm", "2.54cm", "1in", "72px", "96px", "120px", "25%", "30sp"};
 1285  
                 for (int i = 0; i < sizes.length; i++) {
 1286  
                         createLabel(vPanel, vSizes[i], "");
 1287  
                         createTextArea(vPanel, "", "width 50!, height " + vSizes[i] + "");
 1288  
                 }
 1289  
 
 1290  
                 // Vertical lp
 1291  
                 MigLayout vlpLM = new MigLayout("wrap,flowy",
 1292  
                                                    "[c]",
 1293  
                                                    "[top][top]40px[top][top]");
 1294  
                 TabItem vlpPanel = createTabPanel(tabbedPane, "Vertical LP", vlpLM);
 1295  
                 createLabel(vlpPanel, "4 rows", "");
 1296  
                 createTextArea(vlpPanel, "\n\n\n\n", "width 50!");
 1297  
                 createLabel(vlpPanel, "field", "");
 1298  
                 createTextField(vlpPanel, "", "wmin 5*9");
 1299  
 
 1300  
                 String[] vlpSizes1 = new String[] {"63lp", "57px", "63px", "68px", "25%"};
 1301  
                 String[] vlpSizes2 = new String[] {"21lp", "21px", "23px", "24px", "10%"};
 1302  
                 for (int i = 0; i < vlpSizes1.length; i++) {
 1303  
                         createLabel(vlpPanel, vlpSizes1[i], "");
 1304  
                         createTextArea(vlpPanel, "", "width 50!, height " + vlpSizes1[i] + "");
 1305  
                         createLabel(vlpPanel, vlpSizes2[i], "");
 1306  
                         createTextField(vlpPanel, "", "height " + vlpSizes2[i] + "!,wmin 5*6");
 1307  
                 }
 1308  
 
 1309  
                 createLabel(vlpPanel, "button", "skip 2");
 1310  
                 createButton(vlpPanel, "...", "");
 1311  
 
 1312  
                 return tabbedPane;
 1313  
         }
 1314  
 
 1315  
         public Control createGrouping(Composite parent)
 1316  
         {
 1317  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1318  
 
 1319  
                 // Ungrouped
 1320  
                 MigLayout ugM = new MigLayout("", "[]push[][][]", "");
 1321  
                 TabItem ugPanel = createTabPanel(tabbedPane, "Ungrouped", ugM);
 1322  
                 createButton(ugPanel, "Help", "");
 1323  
                 createButton(ugPanel, "< Back", "gap push");
 1324  
                 createButton(ugPanel, "Forward >", "");
 1325  
                 createButton(ugPanel, "Apply", "gap unrel");
 1326  
                 createButton(ugPanel, "Cancel", "gap unrel");
 1327  
 
 1328  
                 // Grouped Components
 1329  
                 MigLayout gM = new MigLayout("nogrid, fillx");
 1330  
                 TabItem gPanel = createTabPanel(tabbedPane, "Grouped (Components)", gM);
 1331  
                 createButton(gPanel, "Help", "sg");
 1332  
                 createButton(gPanel, "< Back", "sg, gap push");
 1333  
                 createButton(gPanel, "Forward >", "sg");
 1334  
                 createButton(gPanel, "Apply", "sg, gap unrel");
 1335  
                 createButton(gPanel, "Cancel", "sg, gap unrel");
 1336  
 
 1337  
                 // Grouped Columns
 1338  
                 MigLayout gcM = new MigLayout("", "[sg,fill]push[sg,fill][sg,fill]unrel[sg,fill]unrel[sg,fill]", "");
 1339  
                 TabItem gcPanel = createTabPanel(tabbedPane, "Grouped (Columns)", gcM);
 1340  
                 createButton(gcPanel, "Help", "");
 1341  
                 createButton(gcPanel, "< Back", "");
 1342  
                 createButton(gcPanel, "Forward >", "");
 1343  
                 createButton(gcPanel, "Apply", "");
 1344  
                 createButton(gcPanel, "Cancel", "");
 1345  
 
 1346  
                 // Ungrouped Rows
 1347  
                 MigLayout ugrM = new MigLayout();     // no "sg" is the only difference to next panel
 1348  
                 TabItem ugrPanel = createTabPanel(tabbedPane, "Ungrouped Rows", ugrM);
 1349  
                 createLabel(ugrPanel, "File Number:", "");
 1350  
                 createTextField(ugrPanel, "30                            ", "wrap");
 1351  
                 createLabel(ugrPanel, "BL/MBL number:", "");
 1352  
                 createTextField(ugrPanel, "7      ", "split 2");
 1353  
                 createTextField(ugrPanel, "7      ", "wrap");
 1354  
                 createLabel(ugrPanel, "Entry Date:", "");
 1355  
                 createTextField(ugrPanel, "7      ", "wrap");
 1356  
                 createLabel(ugrPanel, "RFQ Number:", "");
 1357  
                 createTextField(ugrPanel, "30                            ", "wrap");
 1358  
                 createLabel(ugrPanel, "Goods:", "");
 1359  
                 createCheck(ugrPanel, "Dangerous", "wrap");
 1360  
                 createLabel(ugrPanel, "Shipper:", "");
 1361  
                 createTextField(ugrPanel, "30                            ", "wrap");
 1362  
                 createLabel(ugrPanel, "Customer:", "");
 1363  
                 createTextField(ugrPanel, "", "split 2,growx");
 1364  
                 createButton(ugrPanel, "...", "width 60px:pref,wrap");
 1365  
                 createLabel(ugrPanel, "Port of Loading:", "");
 1366  
                 createTextField(ugrPanel, "30                            ", "wrap");
 1367  
                 createLabel(ugrPanel, "Destination:", "");
 1368  
                 createTextField(ugrPanel, "30                            ", "wrap");
 1369  
 
 1370  
                 // Grouped Rows
 1371  
                 MigLayout grM = new MigLayout("", "[]", "[sg]");    // "sg" is the only difference to previous panel
 1372  
                 TabItem grPanel = createTabPanel(tabbedPane, "Grouped Rows", grM);
 1373  
                 createLabel(grPanel, "File Number:", "");
 1374  
                 createTextField(grPanel, "30                            ","wrap");
 1375  
                 createLabel(grPanel, "BL/MBL number:", "");
 1376  
                 createTextField(grPanel, "7      ","split 2");
 1377  
                 createTextField(grPanel, "7      ", "wrap");
 1378  
                 createLabel(grPanel, "Entry Date:", "");
 1379  
                 createTextField(grPanel, "7      ", "wrap");
 1380  
                 createLabel(grPanel, "RFQ Number:", "");
 1381  
                 createTextField(grPanel, "30                            ", "wrap");
 1382  
                 createLabel(grPanel, "Goods:", "");
 1383  
                 createCheck(grPanel, "Dangerous", "wrap");
 1384  
                 createLabel(grPanel, "Shipper:", "");
 1385  
                 createTextField(grPanel, "30                            ", "wrap");
 1386  
                 createLabel(grPanel, "Customer:", "");
 1387  
                 createTextField(grPanel, "", "split 2,growx");
 1388  
                 createButton(grPanel, "...", "width 50px:pref,wrap");
 1389  
                 createLabel(grPanel, "Port of Loading:", "");
 1390  
                 createTextField(grPanel, "30                            ", "wrap");
 1391  
                 createLabel(grPanel, "Destination:", "");
 1392  
                 createTextField(grPanel, "30                            ", "wrap");
 1393  
 
 1394  
                 return tabbedPane;
 1395  
         }
 1396  
 
 1397  
         public Control createSpan(Composite parent)
 1398  
         {
 1399  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1400  
 
 1401  
                 // Horizontal span
 1402  
                 MigLayout colLM = new MigLayout("",
 1403  
                                                 "[fill][25%,fill][105lp!,fill][150px!,fill]",
 1404  
                                                 "[]15[][]");
 1405  
                 TabItem colPanel = createTabPanel(tabbedPane, "Column Span/Split", colLM);
 1406  
                 createTextField(colPanel, "Col1 [ ]", "");
 1407  
                 createTextField(colPanel, "Col2 [25%]", "");
 1408  
                 createTextField(colPanel, "Col3 [105lp!]", "");
 1409  
                 createTextField(colPanel, "Col4 [150px!]", "wrap");
 1410  
 
 1411  
                 createLabel(colPanel, "Full Name:", "");
 1412  
                 createTextField(colPanel, "span, growx                              ", "span,growx");
 1413  
 
 1414  
                 createLabel(colPanel, "Phone:", "");
 1415  
                 createTextField(colPanel, "   ", "span 3, split 5");
 1416  
                 createTextField(colPanel, "     ", null);
 1417  
                 createTextField(colPanel, "     ", null);
 1418  
                 createTextField(colPanel, "       ", null);
 1419  
                 createLabel(colPanel, "(span 3, split 4)", "wrap");
 1420  
 
 1421  
                 createLabel(colPanel, "Zip/City:", "");
 1422  
                 createTextField(colPanel, "     ", "");
 1423  
                 createTextField(colPanel, "span 2, growx", null);
 1424  
 
 1425  
                 // Vertical span
 1426  
                 MigLayout rowLM = new MigLayout("wrap",
 1427  
                                                    "[225lp]para[225lp]",
 1428  
                                                    "[]3[]unrel[]3[]unrel[]3[]");
 1429  
                 TabItem rowPanel = createTabPanel(tabbedPane, "Row Span", rowLM);
 1430  
                 createLabel(rowPanel, "Name", "");
 1431  
                 createLabel(rowPanel, "Notes", "");
 1432  
                 createTextField(rowPanel, "growx", null);
 1433  
                 createTextArea(rowPanel, "spany,grow          ", "spany,grow,hmin 13*5");
 1434  
                 createLabel(rowPanel, "Phone", "");
 1435  
                 createTextField(rowPanel, "growx", null);
 1436  
                 createLabel(rowPanel, "Fax", "");
 1437  
                 createTextField(rowPanel, "growx", null);
 1438  
 
 1439  
 
 1440  
                 return tabbedPane;
 1441  
         }
 1442  
 
 1443  
         public Control createGrowing(Composite parent)
 1444  
         {
 1445  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1446  
 
 1447  
                 // All tab
 1448  
                 MigLayout allLM = new MigLayout("",
 1449  
                                                 "[pref!][grow,fill]",
 1450  
                                                 "[]15[]");
 1451  
                 TabItem allTab = createTabPanel(tabbedPane, "All", allLM);
 1452  
                 createLabel(allTab, "Fixed", "");
 1453  
                 createLabel(allTab, "Gets all extra space", "wrap");
 1454  
                 createTextField(allTab, "     ", "");
 1455  
                 createTextField(allTab, "     ", "");
 1456  
 
 1457  
                 // Half tab
 1458  
                 MigLayout halfLM = new MigLayout("",
 1459  
                                                  "[pref!][grow,fill]",
 1460  
                                                  "[]15[]");
 1461  
                 TabItem halfTab = createTabPanel(tabbedPane, "Half", halfLM);
 1462  
                 createLabel(halfTab, "Fixed", "");
 1463  
                 createLabel(halfTab, "Gets half of extra space", "");
 1464  
                 createLabel(halfTab, "Gets half of extra space", "wrap");
 1465  
                 createTextField(halfTab, "     ", "");
 1466  
                 createTextField(halfTab, "     ", "");
 1467  
                 createTextField(halfTab, "     ", "");
 1468  
 
 1469  
                 // Percent 1 tab
 1470  
                 MigLayout p1LM = new MigLayout("",
 1471  
                                                   "[pref!][0:0,grow 25,fill][0:0,grow 75,fill]",
 1472  
                                                   "[]15[]");
 1473  
                 TabItem p1Tab = createTabPanel(tabbedPane, "Percent 1", p1LM);
 1474  
                 createLabel(p1Tab, "Fixed", "");
 1475  
                 createLabel(p1Tab, "Gets 25% of extra space", "");
 1476  
                 createLabel(p1Tab, "Gets 75% of extra space", "wrap");
 1477  
                 createTextField(p1Tab, "     ", "");
 1478  
                 createTextField(p1Tab, "     ", "");
 1479  
                 createTextField(p1Tab, "     ", "");
 1480  
 
 1481  
                 // Percent 2 tab
 1482  
                 MigLayout p2LM = new MigLayout("",
 1483  
                                                   "[0:0,grow 33,fill][0:0,grow 67,fill]",
 1484  
                                                   "[]15[]");
 1485  
                 TabItem p2Tab = createTabPanel(tabbedPane, "Percent 2", p2LM);
 1486  
                 createLabel(p2Tab, "Gets 33% of extra space", "");
 1487  
                 createLabel(p2Tab, "Gets 67% of extra space", "wrap");
 1488  
                 createTextField(p2Tab, "     ", "");
 1489  
                 createTextField(p2Tab, "     ", "");
 1490  
 
 1491  
                 // Vertical 1 tab
 1492  
                 MigLayout v1LM = new MigLayout("flowy",
 1493  
                                                "[]15[]",
 1494  
                                                "[][c,pref!][c,grow 25,fill][c,grow 75,fill]");
 1495  
                 TabItem v1Tab = createTabPanel(tabbedPane, "Vertical 1", v1LM);
 1496  
                 createLabel(v1Tab, "Fixed", "skip");
 1497  
                 createLabel(v1Tab, "Gets 25% of extra space", "");
 1498  
                 createLabel(v1Tab, "Gets 75% of extra space", "wrap");
 1499  
                 createLabel(v1Tab, "new Text(SWT.MULTI | SWT.WRAP | SWT.BORDER)", "");
 1500  
                 createTextArea(v1Tab, "", "hmin 4*13");
 1501  
                 createTextArea(v1Tab, "", "hmin 4*13");
 1502  
                 createTextArea(v1Tab, "", "hmin 4*13");
 1503  
 
 1504  
                 // Vertical 2 tab
 1505  
                 MigLayout v2LM = new MigLayout("flowy",
 1506  
                                                   "[]15[]",
 1507  
                                                   "[][c,grow 33,fill][c,grow 67,fill]");
 1508  
                 TabItem v2Tab = createTabPanel(tabbedPane, "Vertical 2", v2LM);
 1509  
                 createLabel(v2Tab, "Gets 33% of extra space", "skip");
 1510  
                 createLabel(v2Tab, "Gets 67% of extra space", "wrap");
 1511  
                 createLabel(v2Tab, "new Text(SWT.MULTI | SWT.WRAP | SWT.BORDER)", "");
 1512  
                 createTextArea(v2Tab, "", "hmin 4*13");
 1513  
                 createTextArea(v2Tab, "", "hmin 4*13");
 1514  
 
 1515  
                 return tabbedPane;
 1516  
         }
 1517  
 
 1518  
         public Control createBasic_Sizes(Composite parent)
 1519  
         {
 1520  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1521  
 
 1522  
                 // Horizontal tab
 1523  
                 MigLayout horLM = new MigLayout("",
 1524  
                                                 "[]15[75px]25[min]25[]",
 1525  
                                                 "[]15");
 1526  
                 TabItem horTab = createTabPanel(tabbedPane, "Horizontal - Column size set", horLM);
 1527  
                 createLabel(horTab, "75px", "skip");
 1528  
                 createLabel(horTab, "Min", "");
 1529  
                 createLabel(horTab, "Pref", "wrap");
 1530  
 
 1531  
                 createLabel(horTab, "new Text(15)", "");
 1532  
                 createTextField(horTab, "               ", "wmin 10");
 1533  
                 createTextField(horTab, "               ", "wmin 10");
 1534  
                 createTextField(horTab, "               ", "wmin 10");
 1535  
 
 1536  
                 // Vertical tab 1
 1537  
                 MigLayout verLM = new MigLayout("flowy,wrap",
 1538  
                                                    "[]15[]",
 1539  
                                                    "[]15[c,45:45]15[c,min]15[c,pref]");
 1540  
                 TabItem verTab = createTabPanel(tabbedPane, "\"Vertical - Row sized\"", verLM);
 1541  
                 createLabel(verTab, "45px", "skip");
 1542  
                 createLabel(verTab, "Min", "");
 1543  
                 createLabel(verTab, "Pref", "");
 1544  
 
 1545  
                 createLabel(verTab, "new Text(SWT.MULTI)", "");
 1546  
                 createTextArea(verTab, "", "");
 1547  
                 createTextArea(verTab, "", "");
 1548  
                 createTextArea(verTab, "", "");
 1549  
 
 1550  
                 // Componentsized/Baseline 2
 1551  
                 MigLayout verLM2 = new MigLayout("flowy,wrap",
 1552  
                                                     "[]15[]",
 1553  
                                                     "[]15[baseline]15[baseline]15[baseline]");
 1554  
                 TabItem verTab2 = createTabPanel(tabbedPane, "\"Vertical - Component sized + Baseline\"", verLM2);
 1555  
                 createLabel(verTab2, "45px", "skip");
 1556  
                 createLabel(verTab2, "Min", "");
 1557  
                 createLabel(verTab2, "Pref", "");
 1558  
 
 1559  
                 createLabel(verTab2, "new Text(SWT.MULTI)", "");
 1560  
                 createTextArea(verTab2, "", "height 45");
 1561  
                 createTextArea(verTab2, "", "height min");
 1562  
                 createTextArea(verTab2, "", "height pref");
 1563  
 
 1564  
                 return tabbedPane;
 1565  
         }
 1566  
 
 1567  
         public Control createAlignments(Composite parent)
 1568  
         {
 1569  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1570  
 
 1571  
                 // Horizontal tab
 1572  
                 MigLayout horLM = new MigLayout("wrap",
 1573  
                                                 "[label]15[left]15[center]15[right]15[fill]15[]",
 1574  
                                                 "[]15[]");
 1575  
 
 1576  
                 String[] horLabels = new String[] {"[label]", "[left]", "[center]", "[right]", "[fill]", "[] (Default)"};
 1577  
                 TabItem horTab = createTabPanel(tabbedPane, "Horizontal", horLM);
 1578  
                 String[] horNames = new String[] {"First Name", "Phone Number", "Facsmile", "Email", "Address", "Other"};
 1579  
                 for (int c = 0; c < horLabels.length; c++)
 1580  
                         createLabel(horTab, horLabels[c], "");
 1581  
 
 1582  
                 for (int r = 0; r < horLabels.length; r++) {
 1583  
                         for (int c = 0; c < horNames.length; c++) {
 1584  
                                 if (c == 0) {
 1585  
                                         createLabel(horTab, horNames[r] + ":", "");
 1586  
                                 } else {
 1587  
                                         createButton(horTab, horNames[r], "");
 1588  
                                 }
 1589  
                         }
 1590  
                 }
 1591  
 
 1592  
                 // Vertical tab
 1593  
                 MigLayout verLM = new MigLayout("wrap,flowy",
 1594  
                                                 "[]unrel[]rel[]",
 1595  
                                                 "[top]15[center]15[bottom]15[fill]15[fill,baseline]15[baseline]15[]");
 1596  
 
 1597  
                 String[] verLabels = new String[] {"[top]", "[center]", "[bottom]", "[fill]", "[fill,baseline]", "[baseline]", "[] (Default)"};
 1598  
                 TabItem verTab = createTabPanel(tabbedPane, "Vertical", verLM);
 1599  
 
 1600  
                 for (int c = 0; c < verLabels.length; c++)
 1601  
                         createLabel(verTab, verLabels[c], "");
 1602  
 
 1603  
                 for (int c = 0; c < verLabels.length; c++)
 1604  
                         createButton(verTab, "A Button", "");
 1605  
 
 1606  
                 for (int c = 0; c < verLabels.length; c++)
 1607  
                         createTextField(verTab, "JTextFied", "");
 1608  
 
 1609  
                 for (int c = 0; c < verLabels.length; c++)
 1610  
                         createTextArea(verTab, "Text    ", "");
 1611  
 
 1612  
                 for (int c = 0; c < verLabels.length; c++)
 1613  
                         createTextArea(verTab, "Text\nwith two lines", "");
 1614  
 
 1615  
                 for (int c = 0; c < verLabels.length; c++)
 1616  
                         createTextArea(verTab, "Scrolling Text\nwith two lines", "");
 1617  
 
 1618  
                 return tabbedPane;
 1619  
         }
 1620  
 
 1621  
         public Control createQuick_Start(Composite parent)
 1622  
         {
 1623  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1624  
 
 1625  
                 MigLayout lm = new MigLayout("wrap",
 1626  
                                              "[right][fill,sizegroup]unrel[right][fill,sizegroup]",
 1627  
                                              "");
 1628  
 
 1629  
                 TabItem p = createTabPanel(tabbedPane, "Quick Start", lm);
 1630  
 
 1631  
                 addSeparator(p, "General");
 1632  
                 createLabel(p, "Company", "gap indent");
 1633  
                 createTextField(p, "", "span,growx");
 1634  
                 createLabel(p, "Contact", "gap indent");
 1635  
                 createTextField(p, "", "span,growx");
 1636  
 
 1637  
                 addSeparator(p, "Propeller");
 1638  
                 createLabel(p, "PTI/kW", "gap indent");
 1639  
                 createTextField(p, "", "wmin 130");
 1640  
                 createLabel(p, "Power/kW", "gap indent");
 1641  
                 createTextField(p, "", "wmin 130");
 1642  
                 createLabel(p, "R/mm", "gap indent");
 1643  
                 createTextField(p, "", "wmin 130");
 1644  
                 createLabel(p, "D/mm", "gap indent");
 1645  
                 createTextField(p, "", "wmin 130");
 1646  
 
 1647  
                 return tabbedPane;
 1648  
         }
 1649  
 
 1650  
         public Control createGrow_Shrink(Composite parent)
 1651  
         {
 1652  
                 TabFolder tabbedPane = new TabFolder(parent, DOUBLE_BUFFER);
 1653  
 
 1654  
                 // shrink tab
 1655  
                 MigLayout slm = new MigLayout("nogrid");
 1656  
                 TabItem shrinkTabPanel = createTabPanel(tabbedPane, "Shrink", new FillLayout());
 1657  
 
 1658  
 
 1659  
                 SashForm shrinkSash = new SashForm(getComposite(shrinkTabPanel), SWT.HORIZONTAL | SWT.SMOOTH);
 1660  
                 shrinkSash.setBackground(new Color(display, 255, 255, 255));
 1661  
                 shrinkSash.setBackgroundMode(SWT.INHERIT_FORCE);
 1662  
 
 1663  
                 Composite shrinkPanel = createPanel(shrinkSash, slm, SWT.BORDER);
 1664  
                 shrinkPanel.setLayoutData("wmin 100");
 1665  
 
 1666  
                 createTextField(shrinkPanel, "shp 110", "shp 110,w 10:130");
 1667  
                 createTextField(shrinkPanel, "Default (100)", "w 10:130");
 1668  
                 createTextField(shrinkPanel, "shp 90", "shp 90,w 10:130");
 1669  
 
 1670  
                 createTextField(shrinkPanel, "shrink 25", "newline,shrink 25,w 10:130");
 1671  
                 createTextField(shrinkPanel, "shrink 75", "shrink 75,w 10:130");
 1672  
 
 1673  
                 createTextField(shrinkPanel, "Default", "newline, w 10:130");
 1674  
                 createTextField(shrinkPanel, "Default", "w 10:130");
 1675  
 
 1676  
                 createTextField(shrinkPanel, "shrink 0", "newline,shrink 0,w 10:130");
 1677  
 
 1678  
                 createTextField(shrinkPanel, "shp 110",  "newline,shp 110,w 10:130");
 1679  
                 createTextField(shrinkPanel, "shp 100,shrink 25", "shp 100,shrink 25,w 10:130");
 1680  
                 createTextField(shrinkPanel, "shp 100,shrink 75", "shp 100,shrink 75,w 10:130");
 1681  
 
 1682  
                 createTextArea(shrinkSash, "Use the slider to see how the components shrink depending on the constraints set on them.\n\n'shp' means Shrink Priority. " +
 1683  
                                            "Lower values will be shrunk before higer ones and the default value is 100.\n\n'shrink' means Shrink Weight. " +
 1684  
                                            "Lower values relative to other's means they will shrink less when space is scarse. " +
 1685  
                                            "Shrink Weight is only relative to components with the same Shrink Priority. Default Shrink Weight is 100.\n\n" +
 1686  
                                            "The component's minimum size will always be honored.\n\nFor SWT, which doesn't have a component notion of minimum, " +
 1687  
                                            "preferred or maximum size, those sizes are set explicitly to minimum 10 and preferred 130 pixels.", "");
 1688  
 
 1689  
                 // Grow tab
 1690  
                 TabItem growTabPanel = createTabPanel(tabbedPane, "Grow", new FillLayout());
 1691  
 
 1692  
                 SashForm growSash = new SashForm(getComposite(growTabPanel), SWT.HORIZONTAL | SWT.SMOOTH);
 1693  
                 growSash.setBackground(new Color(display, 255, 255, 255));
 1694  
                 growSash.setBackgroundMode(SWT.INHERIT_FORCE);
 1695  
 
 1696  
                 Composite growPanel = createPanel(growSash, new MigLayout("nogrid", "[grow]"), SWT.BORDER);
 1697  
                 growPanel.setLayoutData("wmin 100");
 1698  
 
 1699  
                 createButton(growPanel, "gp 110, grow", "gp 110, grow, wmax 170");
 1700  
                 createButton(growPanel, "Default (100), grow", "grow, wmax 170");
 1701  
                 createButton(growPanel, "gp 90, grow", "gp 90, grow, wmax 170");
 1702  
 
 1703  
                 createButton(growPanel, "Default Button", "newline");
 1704  
 
 1705  
                 createButton(growPanel, "growx", "newline,growx,wrap");
 1706  
 
 1707  
                 createButton(growPanel, "gp 110, grow", "gp 110, grow, wmax 170");
 1708  
                 createButton(growPanel, "gp 100, grow 25", "gp 100, grow 25, wmax 170");
 1709  
                 createButton(growPanel, "gp 100, grow 75", "gp 100, grow 75, wmax 170");
 1710  
 
 1711  
                 createTextArea(growSash, "'gp' means Grow Priority. " +
 1712  
                                          "Lower values will be grown before higher ones and the default value is 100.\n\n'grow' means Grow Weight. " +
 1713  
                                          "Higher values relative to other's means they will grow more when space is up for takes. " +
 1714  
                                          "Grow Weight is only relative to components with the same Grow Priority. Default Grow Weight is 0 which means " +
 1715  
                                          "components will normally not grow. \n\nNote that the buttons in the first and last row have max width set to 170 to " +
 1716  
                                          "emphasize Grow Priority.\n\nThe component's maximum size will always be honored.", "");
 1717  
 
 1718  
                 return tabbedPane;
 1719  
         }
 1720  
 
 1721  
 
 1722  
         // **********************************************************
 1723  
         // * Helper Methods
 1724  
         // **********************************************************
 1725  
 
 1726  
 //        private final ToolTipListener toolTipListener = new ToolTipListener();
 1727  
 //        private final ConstraintListener constraintListener = new ConstraintListener();
 1728  
 
 1729  
         private Combo createCombo(Object parent, String[] texts, Object layout)
 1730  
         {
 1731  
                 Combo b = new Combo(getComposite(parent), SWT.DROP_DOWN);
 1732  
                 for (int i = 0; i < texts.length; i++)
 1733  
                         b.add(texts[i]);
 1734  
                 b.setLayoutData(layout);
 1735  
 
 1736  
 //                configureActiveComponet(b);
 1737  
 
 1738  
                 return b;
 1739  
         }
 1740  
 
 1741  
         private Label createLabel(Object parent, String text, Object layout)
 1742  
         {
 1743  
                 return createLabel(parent, text, layout, SWT.LEFT);
 1744  
         }
 1745  
 
 1746  
         private Label createLabel(Object parent, String text, Object layout, int style)
 1747  
         {
 1748  
                 final Label b = new Label(getComposite(parent), style | DOUBLE_BUFFER);
 1749  
                 b.setText(text);
 1750  
                 b.setLayoutData(layout != null ? layout : text);
 1751  
 //                b.setAlignment();
 1752  
 
 1753  
 //                configureActiveComponet(b);
 1754  
 
 1755  
                 return b;
 1756  
         }
 1757  
 
 1758  
         private Text createTextField(Object parent, String text, Object layout)
 1759  
         {
 1760  
                 final Text b = new Text(getComposite(parent), SWT.SINGLE | SWT.BORDER | DOUBLE_BUFFER);
 1761  
                 b.setText(text);
 1762  
                 b.setLayoutData(layout != null ? layout : text);
 1763  
 
 1764  
 //                configureActiveComponet(b);
 1765  
 
 1766  
                 return b;
 1767  
         }
 1768  
 
 1769  
         private Button createButton(Object parent, String text, Object layout)
 1770  
         {
 1771  
                 return createButton(getComposite(parent), text, layout, false);
 1772  
         }
 1773  
 
 1774  
         private Button createButton(Object parent, String text, Object layout, boolean bold)
 1775  
         {
 1776  
                 Button b = new Button(getComposite(parent), SWT.PUSH | SWT.NO_BACKGROUND | DOUBLE_BUFFER);
 1777  
                 b.setText(text.length() == 0 ? "\"\"" : text);
 1778  
                 b.setLayoutData(layout != null ? layout : text);
 1779  
 
 1780  
 //                configureActiveComponet(b);
 1781  
 
 1782  
                 return b;
 1783  
         }
 1784  
 
 1785  
         private Composite createPanel(Object parent, String text, Object layout)
 1786  
         {
 1787  
                 Color bg = new Color(display.getActiveShell().getDisplay(), 255, 255, 255);
 1788  
                 Composite panel = new Composite(getComposite(parent), DOUBLE_BUFFER | SWT.BORDER);
 1789  
                 panel.setLayout(new MigLayout("fill"));
 1790  
                 panel.setBackground(bg);
 1791  
                 panel.setLayoutData(layout != null ? layout : text);
 1792  
                 text = text.length() == 0 ? "\"\"" : text;
 1793  
                 Label label = createLabel(panel, text, "grow", SWT.NO_BACKGROUND | SWT.CENTER);
 1794  
                 label.setBackground(bg);
 1795  
 
 1796  
 //                configureActiveComponet(panel);
 1797  
 
 1798  
                 return panel;
 1799  
         }
 1800  
 
 1801  
         private TabItem createTabPanel(TabFolder parent, String text, Layout lm)
 1802  
         {
 1803  
                 Composite panel = new Composite(parent, DOUBLE_BUFFER);
 1804  
 //                panel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
 1805  
                 TabItem tab = new TabItem(parent, DOUBLE_BUFFER);
 1806  
                 tab.setControl(panel);
 1807  
                 tab.setText(text);
 1808  
                 if (lm != null)
 1809  
                         panel.setLayout(lm);
 1810  
 
 1811  
 //                configureActiveComponet(panel);
 1812  
                 return tab;
 1813  
         }
 1814  
 
 1815  
         private Composite createPanel(Object parent, Layout lm)
 1816  
         {
 1817  
                 return createPanel(parent, lm, 0);
 1818  
         }
 1819  
 
 1820  
         private Composite createPanel(Object parent, Layout lm, int style)
 1821  
         {
 1822  
                 Composite panel = new Composite(getComposite(parent), DOUBLE_BUFFER | style);
 1823  
                 panel.setLayout(lm);
 1824  
                 return panel;
 1825  
         }
 1826  
 
 1827  
         private Button createToggleButton(Object parent, String text, Object layout)
 1828  
         {
 1829  
                 Button b = new Button(getComposite(parent), SWT.TOGGLE | DOUBLE_BUFFER);
 1830  
                 b.setText(text.length() == 0 ? "\"\"" : text);
 1831  
                 b.setLayoutData(layout != null ? layout : text);
 1832  
 
 1833  
 //                configureActiveComponet(b);
 1834  
 
 1835  
                 return b;
 1836  
         }
 1837  
 
 1838  
         private Button createCheck(Object parent, String text, Object layout)
 1839  
         {
 1840  
                 Button b = new Button(getComposite(parent), SWT.CHECK | DOUBLE_BUFFER);
 1841  
                 b.setText(text);
 1842  
                 b.setLayoutData(layout != null ? layout : text);
 1843  
 //                configureActiveComponet(b);
 1844  
 
 1845  
                 return b;
 1846  
         }
 1847  
 
 1848  
         private List createList(Object parent, String text, Object layout)
 1849  
         {
 1850  
                 List list = new List(getComposite(parent), DOUBLE_BUFFER | SWT.BORDER);
 1851  
                 list.add(text);
 1852  
                 list.setLayoutData(layout);
 1853  
                 return list;
 1854  
         }
 1855  
 
 1856  
         private StyledText createTextArea(Object parent, String text, String layout)
 1857  
         {
 1858  
                 return createTextArea(parent, text, layout, SWT.MULTI | SWT.WRAP | SWT.BORDER | DOUBLE_BUFFER);
 1859  
         }
 1860  
 
 1861  
         private StyledText createTextArea(Object parent, String text, String layout, int style)
 1862  
         {
 1863  
                 StyledText ta = new StyledText(getComposite(parent), SWT.MULTI | SWT.WRAP | style | DOUBLE_BUFFER);
 1864  
                 ta.setText(text);
 1865  
 //                ta.setMargins(5, 5, 5, 5);
 1866  
                 ta.setLayoutData(layout != null ? layout : text);
 1867  
 
 1868  
 //                configureActiveComponet(ta);
 1869  
 
 1870  
                 return ta;
 1871  
         }
 1872  
 
 1873  
         public Composite getComposite(Object c)
 1874  
         {
 1875  
                 if (c instanceof Control)
 1876  
                         return (Composite) c;
 1877  
 
 1878  
                 return (Composite) ((TabItem) c).getControl();
 1879  
         }
 1880  
 
 1881  
         private Font deriveFont(Control cont, int style, int height)
 1882  
         {
 1883  
                 Font f = cont.getFont();
 1884  
                 FontData fd = f.getFontData()[0];
 1885  
                 if (style != SWT.DEFAULT)
 1886  
                         fd.setStyle(style);
 1887  
 
 1888  
                 if (height != -1)
 1889  
                         fd.setHeight(height);
 1890  
 
 1891  
                 Font font = new Font(display, fd);
 1892  
                 cont.setFont(font);
 1893  
                 return font;
 1894  
         }
 1895  
 
 1896  
 //        private Control configureActiveComponet(Control c)
 1897  
 //        {
 1898  
 //                c.addMouseMotionListener(toolTipListener);
 1899  
 //                c.addMouseListener(constraintListener);
 1900  
 //                return c;
 1901  
 //        }
 1902  
 
 1903  
         private void addSeparator(Object panel, String text)
 1904  
         {
 1905  
                 Label l = createLabel(panel, text, "gaptop para, span, split 2");
 1906  
                 l.setForeground(new Color(display, 0, 70, 213));
 1907  
 
 1908  
                 Label s = new Label(getComposite(panel), SWT.SEPARATOR | SWT.HORIZONTAL | DOUBLE_BUFFER);
 1909  
                 s.setLayoutData("gapleft rel, gaptop para, growx");
 1910  
 
 1911  
 //      configureActiveComponet(s);
 1912  
         }
 1913  
 
 1914  
 //        private class ConstraintListener extends MouseAdapter
 1915  
 //        {
 1916  
 //                public void mousePressed(MouseEvent e)
 1917  
 //                {
 1918  
 //                        if (e.isPopupTrigger())
 1919  
 //                                react(e);
 1920  
 //                }
 1921  
 //
 1922  
 //                public void mouseReleased(MouseEvent e)
 1923  
 //                {
 1924  
 //                        if (e.isPopupTrigger())
 1925  
 //                                react(e);
 1926  
 //                }
 1927  
 //
 1928  
 //                public void react(MouseEvent e)
 1929  
 //                {
 1930  
 //                        Control c = (Control) e.getSource();
 1931  
 //                        LayoutManager lm = c.getParent().getLayout();
 1932  
 //                        if (lm instanceof SwtMigLayout == false)
 1933  
 //                                lm = c.getLayout();
 1934  
 //
 1935  
 //                        if (lm instanceof SwtMigLayout) {
 1936  
 //                                MigLayout ffl = (MigLayout) lm;
 1937  
 //                                boolean isComp = ffl.isManagingComponent(c);
 1938  
 //                                String compConstr = isComp ? ffl.getComponentConstraints(c) : null;
 1939  
 //                                String rowsConstr = isComp ? null : ffl.getRowConstraints();
 1940  
 //                                String colsConstr = isComp ? null : ffl.getColumnConstraints();
 1941  
 //                                String layoutConstr = isComp ? null : ffl.getLayoutConstraints();
 1942  
 //
 1943  
 //                                ConstraintsDialog cDlg = new ConstraintsDialog(SwingDemo.this, layoutConstr, rowsConstr, colsConstr, compConstr);
 1944  
 //                                cDlg.pack();
 1945  
 //                                cDlg.setLocationRelativeTo(c);
 1946  
 //
 1947  
 //                                if (cDlg.showDialog()) {
 1948  
 //                                        try {
 1949  
 //                                                if (isComp) {
 1950  
 //                                                        String constrStr = cDlg.componentConstrTF.getText().trim();
 1951  
 //                                                        ffl.setComponentConstraints(c, constrStr);
 1952  
 //                                                        if (c instanceof Button) {
 1953  
 //                                                                c.setFont(BUTT_FONT);
 1954  
 //                                                                ((Button) c).setText(constrStr.length() == 0 ? "<Empty>" : constrStr);
 1955  
 //                                                        }
 1956  
 //                                                } else {
 1957  
 //                                                        ffl.setLayoutConstraints(cDlg.layoutConstrTF.getText());
 1958  
 //                                                        ffl.setRowConstraints(cDlg.rowsConstrTF.getText());
 1959  
 //                                                        ffl.setColumnConstraints(cDlg.colsConstrTF.getText());
 1960  
 //                                                }
 1961  
 //                                        } catch(Exception ex) {
 1962  
 //                                                StringWriter sw = new StringWriter();
 1963  
 //                                                ex.printStackTrace(new PrintWriter(sw));
 1964  
 //                                                JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(c), sw.toString(), "Error parsing Constraint!", JOptionPane.ERROR_MESSAGE);
 1965  
 //                                                return;
 1966  
 //                                        }
 1967  
 //
 1968  
 //                                        c.invalidate();
 1969  
 //                                        c.getParent().validate();
 1970  
 //                                }
 1971  
 //                        }
 1972  
 //                }
 1973  
 //        }
 1974  
 //
 1975  
 //        private static class ToolTipListener extends MouseMotionAdapter
 1976  
 //        {
 1977  
 //                public void mouseMoved(MouseEvent e)
 1978  
 //                {
 1979  
 //                        Control c = (Control) e.getSource();
 1980  
 //                        LayoutManager lm = c.getParent().getLayout();
 1981  
 //                        if (lm instanceof SwtMigLayout) {
 1982  
 //                                String constr = ((MigLayout) lm).getComponentConstraints(c);
 1983  
 //                                c.setToolTipText((constr != null ? ("\"" + constr + "\"") : "null"));
 1984  
 //                        }
 1985  
 //                }
 1986  
 //        }
 1987  
 //
 1988  
 //        private static class ConstraintsDialog extends JDialog implements ActionListener, KeyEventDispatcher
 1989  
 //        {
 1990  
 //                private static final Color ERROR_COLOR = new Color(255, 180, 180);
 1991  
 //                private final JPanel mainPanel = new JPanel(parent, new SwtMigLayout("fillx,flowy,ins dialog",
 1992  
 //                                                                               "[fill]",
 1993  
 //                                                                               "2[]2"));
 1994  
 //                final Text layoutConstrTF;
 1995  
 //                final Text rowsConstrTF;
 1996  
 //                final Text colsConstrTF;
 1997  
 //                final Text componentConstrTF;
 1998  
 //
 1999  
 //                private final Button okButt = new Button("OK");
 2000  
 //                private final Button cancelButt = new Button("Cancel");
 2001  
 //
 2002  
 //                private boolean okPressed = false;
 2003  
 //
 2004  
 //                public ConstraintsDialog(Frame owner, String layoutConstr, String rowsConstr, String colsConstr, String compConstr)
 2005  
 //                {
 2006  
 //                        super(owner, (compConstr != null ? "Edit Component Constraints" : "Edit Container Constraints"), true);
 2007  
 //
 2008  
 //                        layoutConstrTF = createConstraintField(layoutConstr);
 2009  
 //                        rowsConstrTF = createConstraintField(rowsConstr);
 2010  
 //                        colsConstrTF = createConstraintField(colsConstr);
 2011  
 //                        componentConstrTF = createConstraintField(compConstr);
 2012  
 //
 2013  
 //                        if (componentConstrTF != null) {
 2014  
 //                                mainPanel.add(new Label("Component Constraints"));
 2015  
 //                                mainPanel.add(componentConstrTF);
 2016  
 //                        }
 2017  
 //
 2018  
 //                        if (layoutConstrTF != null) {
 2019  
 //                                mainPanel.add(new Label("Container Layout Constraints"));
 2020  
 //                                mainPanel.add(layoutConstrTF);
 2021  
 //                        }
 2022  
 //
 2023  
 //                        if (rowsConstrTF != null) {
 2024  
 //                                mainPanel.add(new Label("Container Row Constraints"), "gaptop unrel");
 2025  
 //                                mainPanel.add(rowsConstrTF);
 2026  
 //                        }
 2027  
 //
 2028  
 //                        if (colsConstrTF != null) {
 2029  
 //                                mainPanel.add(new Label("Container Column Constraints"), "gaptop unrel");
 2030  
 //                                mainPanel.add(colsConstrTF);
 2031  
 //                        }
 2032  
 //
 2033  
 //                        mainPanel.add(okButt, "tag ok,split,flowx,gaptop 15");
 2034  
 //                        mainPanel.add(cancelButt, "tag cancel,gaptop 15");
 2035  
 //
 2036  
 //                        setContentPane(mainPanel);
 2037  
 //
 2038  
 //                        okButt.addActionListener(this);
 2039  
 //                        cancelButt.addActionListener(this);
 2040  
 //                }
 2041  
 //
 2042  
 //                public void addNotify()
 2043  
 //                {
 2044  
 //                        super.addNotify();
 2045  
 //                        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
 2046  
 //                }
 2047  
 //
 2048  
 //                public void removeNotify()
 2049  
 //                {
 2050  
 //                        KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
 2051  
 //                        super.removeNotify();
 2052  
 //                }
 2053  
 //
 2054  
 //                public boolean dispatchKeyEvent(KeyEvent e)
 2055  
 //                {
 2056  
 //                        if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
 2057  
 //                                dispose();
 2058  
 //                        return false;
 2059  
 //                }
 2060  
 //
 2061  
 //                public void actionPerformed(ActionEvent e)
 2062  
 //                {
 2063  
 //                        if (e.getSource() == okButt)
 2064  
 //                                okPressed = true;
 2065  
 //                        dispose();
 2066  
 //                }
 2067  
 //
 2068  
 //                private Text createConstraintField(String text)
 2069  
 //                {
 2070  
 //                        if (text == null)
 2071  
 //                                return null;
 2072  
 //
 2073  
 //                        final Text tf = new Text(text, 50);
 2074  
 //                        tf.setFont(new Font("monospaced", Font.PLAIN, 12));
 2075  
 //
 2076  
 //                        tf.addKeyListener(new KeyAdapter() {
 2077  
 //                                public void keyPressed(KeyEvent e)
 2078  
 //                                {
 2079  
 //                                        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
 2080  
 //                                                okButt.doClick();
 2081  
 //                                                return;
 2082  
 //                                        }
 2083  
 //
 2084  
 //                                        javax.swing.Timer timer = new Timer(50, new ActionListener() {
 2085  
 //                                                public void actionPerformed(ActionEvent e)
 2086  
 //                                                {
 2087  
 //                                                        String constr = tf.getText();
 2088  
 //                                                        try {
 2089  
 //                                                                if (tf == layoutConstrTF) {
 2090  
 //                                                                        MigLayout.validateLayoutConstraint(constr);
 2091  
 //                                                                } else if (tf == rowsConstrTF) {
 2092  
 //                                                                        MigLayout.validateRowConstraints(constr);
 2093  
 //                                                                } else if (tf == colsConstrTF) {
 2094  
 //                                                                        MigLayout.validateColumnConstraints(constr);
 2095  
 //                                                                } else if (tf == componentConstrTF) {
 2096  
 //                                                                        MigLayout.validateComponentConstraint(constr);
 2097  
 //                                                                }
 2098  
 //                                                                tf.setBackground(Color.WHITE);
 2099  
 //                                                                okButt.setEnabled(true);
 2100  
 //                                                        } catch(Exception ex) {
 2101  
 //                                                                tf.setBackground(ERROR_COLOR);
 2102  
 //                                                                okButt.setEnabled(false);
 2103  
 //                                                        }
 2104  
 //                                                }
 2105  
 //                                        });
 2106  
 //                                        timer.setRepeats(false);
 2107  
 //                                        timer.start();
 2108  
 //                                }
 2109  
 //                        });
 2110  
 //
 2111  
 //                        return tf;
 2112  
 //                }
 2113  
 //
 2114  
 //                private boolean showDialog()
 2115  
 //                {
 2116  
 //                        setVisible(true);
 2117  
 //                        return okPressed;
 2118  
 //                }
 2119  
 //        }
 2120  
 
 2121  
 }
 2122  
 
 2123  
 
 2124  
 
 2125