Coverage Report - net.miginfocom.examples.SwtTest
 
Classes in this File Line Coverage Branch Coverage Complexity
SwtTest
N/A
N/A
1.667
SwtTest$1
N/A
N/A
1.667
SwtTest$2
N/A
N/A
1.667
 
 1  
 package net.miginfocom.examples;
 2  
 
 3  
 import net.miginfocom.swt.MigLayout;
 4  
 
 5  
 import org.eclipse.swt.SWT;
 6  
 import org.eclipse.swt.events.SelectionAdapter;
 7  
 import org.eclipse.swt.events.SelectionEvent;
 8  
 import org.eclipse.swt.layout.FillLayout;
 9  
 import org.eclipse.swt.widgets.Button;
 10  
 import org.eclipse.swt.widgets.Composite;
 11  
 import org.eclipse.swt.widgets.Display;
 12  
 import org.eclipse.swt.widgets.Label;
 13  
 import org.eclipse.swt.widgets.Shell;
 14  
 
 15  
 /*
 16  
  * License (BSD):
 17  
  * ==============
 18  
  *
 19  
  * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
 20  
  * All rights reserved.
 21  
  *
 22  
  * Redistribution and use in source and binary forms, with or without modification,
 23  
  * are permitted provided that the following conditions are met:
 24  
  * Redistributions of source code must retain the above copyright notice, this list
 25  
  * of conditions and the following disclaimer.
 26  
  * Redistributions in binary form must reproduce the above copyright notice, this
 27  
  * list of conditions and the following disclaimer in the documentation and/or other
 28  
  * materials provided with the distribution.
 29  
  * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
 30  
  * used to endorse or promote products derived from this software without specific
 31  
  * prior written permission.
 32  
  *
 33  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 34  
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 35  
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 36  
  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 37  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 38  
  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 39  
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 40  
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 41  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 42  
  * OF SUCH DAMAGE.
 43  
  *
 44  
  * @version 1.0
 45  
  * @author Mikael Grev, MiG InfoCom AB
 46  
  *         Date: 2006-sep-08
 47  
  */
 48  
 public class SwtTest
 49  
 {
 50  
 
 51  
         public static void main(final String[] args)
 52  
         {
 53  
                 final Display display = new Display();
 54  
                 final Shell shell = new Shell(display);
 55  
 
 56  
                 shell.setLayout(new FillLayout(SWT.VERTICAL));
 57  
 
 58  
                 final Composite cmpLabels = new Composite(shell, SWT.BORDER);
 59  
                 cmpLabels.setLayout(new MigLayout("wrap 5"));
 60  
 
 61  
                 final Label l0 = new Label(cmpLabels, SWT.NONE);
 62  
                 l0.setText("L 0");
 63  
                 final Label l1 = new Label(cmpLabels, SWT.NONE);
 64  
                 final Label l2 = new Label(cmpLabels, SWT.NONE);
 65  
                 l2.setText("L 2");
 66  
                 final Label l3 = new Label(cmpLabels, SWT.NONE);
 67  
                 final Label l4 = new Label(cmpLabels, SWT.NONE);
 68  
                 l4.setText("L 4");
 69  
 
 70  
                 final Composite cmpButtons = new Composite(shell, SWT.NONE);
 71  
                 cmpButtons.setLayout(new FillLayout());
 72  
 
 73  
                 final Button btn1 = new Button(cmpButtons, SWT.PUSH);
 74  
                 btn1.setText("Set 1");
 75  
                 btn1.addSelectionListener(new SelectionAdapter()
 76  
                 {
 77  
                         @Override
 78  
                         public void widgetSelected(final SelectionEvent e)
 79  
                         {
 80  
                                 l3.setText("");
 81  
                                 l1.setText("Some Text");
 82  
                                 cmpLabels.layout();
 83  
                                 cmpLabels.redraw();
 84  
                         }
 85  
                 });
 86  
 
 87  
                 final Button btn3 = new Button(cmpButtons, SWT.PUSH);
 88  
                 btn3.setText("Set 3");
 89  
                 btn3.addSelectionListener(new SelectionAdapter()
 90  
                 {
 91  
                         @Override
 92  
                         public void widgetSelected(final SelectionEvent e)
 93  
                         {
 94  
                                 l1.setText("");
 95  
                                 l3.setText("Some Text");
 96  
                                 cmpLabels.layout();
 97  
                                 cmpLabels.redraw();
 98  
                         }
 99  
                 });
 100  
 
 101  
                 shell.setSize(300, 100);
 102  
                 shell.open();
 103  
                 while (!shell.isDisposed()) {
 104  
                         if (!display.readAndDispatch()) {
 105  
                                 display.sleep();
 106  
                         }
 107  
                 }
 108  
                 display.dispose();
 109  
         }
 110  
 }