Java/SWT JFace Eclipse/Sash

Материал из Java эксперт
Версия от 05:57, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Create a sash (allow it to be moved)

/*
 * Sash example snippet: create a sash (allow it to be moved)
 *
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
public class Snippet54 {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    final Sash sash = new Sash(shell, SWT.BORDER | SWT.VERTICAL);
    sash.setBounds(10, 10, 32, 100);
    sash.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        sash.setBounds(e.x, e.y, e.width, e.height);
      }
    });
    shell.open();
    sash.setFocus();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    display.dispose();
  }
}





Demonstrates a Sash

//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner@interspatial.ru)
//Robert Harris (rbrt_harris@yahoo.ru)
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
 * This class demonstrates a Sash
 */
public class SashExampleThree {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash Three");
    createContents(shell);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
  /**
   * Creates the contents of the main window
   * 
   * @param composite the parent composite
   */
  public void createContents(Composite composite) {
    composite.setLayout(new FormLayout());
    // Create the sash first, so the other controls
    // can be attached to it.
    final Sash sash = new Sash(composite, SWT.VERTICAL);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0); // Attach to top
    data.bottom = new FormAttachment(100, 0); // Attach to bottom
    data.left = new FormAttachment(50, 0); // Attach halfway across
    sash.setLayoutData(data);
    sash.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        // We reattach to the left edge, and we use the x value of the event to
        // determine the offset from the left
        ((FormData) sash.getLayoutData()).left = new FormAttachment(0, event.x);
        // Until the parent window does a layout, the sash will not be redrawn in
        // its new location.
        sash.getParent().layout();
      }
    });
    // Create the first text box and attach its right edge
    // to the sash
    Text one = new Text(composite, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    one.setLayoutData(data);
    // Create the second text box and attach its left edge
    // to the sash
    Text Three = new Text(composite, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    Three.setLayoutData(data);
  }
  /**
   * Application entry point
   * 
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    new SashExampleThree().run();
  }
}





Demonstrates a Sash 2

//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner@interspatial.ru)
//Robert Harris (rbrt_harris@yahoo.ru)
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
 * This class demonstrates a Sash
 */
public class SashExampleOne {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash One");
    createContents(shell);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
  /**
   * Creates the contents of the main window
   * 
   * @param composite the parent composite
   */
  public void createContents(Composite composite) {
    composite.setLayout(new FillLayout());
    new Text(composite, SWT.BORDER);
    new Sash(composite, SWT.VERTICAL);
    new Text(composite, SWT.BORDER);
  }
  /**
   * Application entry point
   * 
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    new SashExampleOne().run();
  }
}





Demonstrates a Sash 3

//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner@interspatial.ru)
//Robert Harris (rbrt_harris@yahoo.ru)
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
 * This class demonstrates a Sash
 */
public class SashExampleTwo {
  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Sash Two");
    createContents(shell);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
  /**
   * Creates the contents of the main window
   * 
   * @param composite the parent composite
   */
  public void createContents(Composite composite) {
    composite.setLayout(new FormLayout());
    // Create the sash first, so the other controls
    // can be attached to it.
    Sash sash = new Sash(composite, SWT.VERTICAL);
    FormData data = new FormData();
    data.top = new FormAttachment(0, 0); // Attach to top
    data.bottom = new FormAttachment(100, 0); // Attach to bottom
    data.left = new FormAttachment(50, 0); // Attach halfway across
    sash.setLayoutData(data);
    // Create the first text box and attach its right edge
    // to the sash
    Text one = new Text(composite, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(sash, 0);
    one.setLayoutData(data);
    // Create the second text box and attach its left edge
    // to the sash
    Text two = new Text(composite, SWT.BORDER);
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(sash, 0);
    data.right = new FormAttachment(100, 0);
    two.setLayoutData(data);
  }
  /**
   * Application entry point
   * 
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    new SashExampleTwo().run();
  }
}





Displays a vertical sash

//Send questions, comments, bug reports, etc. to the authors:
//Rob Warner (rwarner@interspatial.ru)
//Robert Harris (rbrt_harris@yahoo.ru)
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
/**
 * This class displays a vertical sash
 */
public class VerticalSash {
  public static void main(String[] args) {
    new VerticalSash().run();
  }
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Vertical Sash");
    shell.setLayout(new FillLayout());
    Sash sash = new Sash(shell, SWT.VERTICAL);
    new Composite(shell, SWT.NONE);
    new Composite(shell, SWT.NONE);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}





Sash Example

/******************************************************************************
 * All Right Reserved. 
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * 
 * Created on 2004-4-7 13:28:17 by JACK
 * $Id$
 * 
 *****************************************************************************/
/*
 * Sash example snippet: create a sash (allow it to be moved)
 *
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Sash;
import org.eclipse.swt.widgets.Shell;
public class SashExample {
public static void main (String [] args) {
  Display display = new Display ();
  Shell shell = new Shell (display);
  final Sash sash = new Sash (shell, SWT.BORDER | SWT.VERTICAL);
  sash.setBounds (10, 10, 15, 60);
  sash.addListener (SWT.Selection, new Listener () {
    public void handleEvent (Event e) {
      System.out.println("Selected. ");
      sash.setBounds (e.x, e.y, e.width, e.height);
    }
  });
  shell.open ();
  sash.setFocus ();
  while (!shell.isDisposed ()) {
    if (!display.readAndDispatch ()) display.sleep ();
  }
  display.dispose ();
}
}