Custom Components : Form « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » SWT JFace Eclipse » FormScreenshots 
Custom Components
Custom Components


/*******************************************************************************
 * All Right Reserved. Copyright (c) 1998, 2004 Jackwind Li Guojie
 
 * Created on 2004-6-14 10:55:42 by JACK $Id$
 *  
 ******************************************************************************/
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.HyperlinkGroup;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ImageHyperlink;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

public class CustomWidgets extends ApplicationWindow {
  FormToolkit toolkit;
  Form form;

  /**
   @param parentShell
   */
  public CustomWidgets(Shell parentShell) {
    super(parentShell);
  }
  
  private void demoSections() {
    form.getBody().setLayout(new TableWrapLayout());
    
    Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | 
        Section.TREE_NODE | Section.EXPANDED);
    
    section.setText("This is the title");
    toolkit.createCompositeSeparator(section);
    section.setDescription("-= This is a description -=");
    
    FormText text = toolkit.createFormText(section, false);
    text.setText(
      "This is a long text. The user can show or hide this text "
        "by expanding or collapsing the expandable composite.",
      false,
      false);
    section.setClient(text);
  }
 
  private void demoExpandableComposite() {
    form.getBody().setLayout(new TableWrapLayout());

    ExpandableComposite ec1 =
      toolkit.createExpandableComposite(
        form.getBody(),
        ExpandableComposite.TREE_NODE | ExpandableComposite.EXPANDED);
    ec1.setText("This is the title");

    FormText text = toolkit.createFormText(ec1, false);
    text.setText(
      "This is a long text. The user can show or hide this text "
        "by expanding or collapsing the expandable composite.",
      false,
      false);
    ec1.setClient(text);

    ec1.addExpansionListener(new ExpansionAdapter() {
      public void expansionStateChanged(ExpansionEvent e) {
        // resizes the application window.
        getShell().pack(true);
      }
    });
  }

  private void demoFormTextXML() {
    form.getBody().setLayout(new TableWrapLayout());
    FormText text = toolkit.createFormText(form.getBody()true);

    Image image = new Image(form.getDisplay()"icons/eclipse0.gif");
    text.setImage("eclipse", image);
    text.setText(
      "<form>"
        "<p><img href=\"eclipse\"/> Eclipse Projects: </p>"
        "<li><b>Platform</b> - Eclipse frameworks</li>"
        "<li><b>JDT</b> - Java development tools</li>"
        "<li><b>PDE</b> - Plug-in development environment</li>"
        "</form>",
      true,
      false);

  }

  private void demoFormTextNormal() {
    form.getBody().setLayout(new TableWrapLayout());

    FormText text = toolkit.createFormText(form.getBody()true);
    // text.setLayoutData(new TableWrapData(TableWrapData.FILL));

    text.setText(
      "Eclipse is a kind of universal tool platform - an open extensible "
        "IDE for anything and nothing in particular. For more details, please "
        "visit http://www.eclipse.org for more details.",
      false,
      false);

  }

  private void demoFormTextURL() {
    form.getBody().setLayout(new TableWrapLayout());

    FormText text = toolkit.createFormText(form.getBody()true);

    HyperlinkGroup group = new HyperlinkGroup(form.getDisplay());
    group.setForeground(form.getDisplay().getSystemColor(SWT.COLOR_BLUE));
    group.setActiveForeground(
      form.getDisplay().getSystemColor(SWT.COLOR_BLUE));

    text.setHyperlinkSettings(group);

    text.setText(
      "Eclipse is a kind of universal tool platform - an open extensible "
        "IDE for anything and nothing in particular. For more details, please "
        "visit http://www.eclipse.org web site.",
      false,
      true);

    text.addHyperlinkListener(new HyperlinkAdapter() {
      public void linkActivated(HyperlinkEvent e) {
        System.out.println("Link activated: " + e.getHref());
      }
    });

  }

  private void demoHyperlinks() {
    form.getBody().setLayout(new GridLayout());

    Hyperlink hyperlink =
      toolkit.createHyperlink(
        form.getBody(),
        "This is a hyperlink to Eclipse.org",
        SWT.NULL);
    hyperlink.setHref("http://www.eclipse.org");
    hyperlink.setForeground(
      getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
    hyperlink.addHyperlinkListener(new IHyperlinkListener() {
      public void linkEntered(HyperlinkEvent e) {
        System.out.println("Mouse entered.");
      }

      public void linkExited(HyperlinkEvent e) {
        System.out.println("Mouse left.");
      }

      public void linkActivated(HyperlinkEvent e) {
        System.out.println("Hyperlink activated.");
        System.out.println("HREF = " + e.getHref());
      }
    });

    ImageHyperlink imageHyperlink =
      toolkit.createImageHyperlink(form.getBody(), SWT.NULL);
    imageHyperlink.setText("This is an image hyperlink.");
    imageHyperlink.setForeground(
      getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
    imageHyperlink.setImage(
      new Image(getShell().getDisplay()"icons/eclipse0.gif"));
    imageHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
      public void linkActivated(HyperlinkEvent e) {
        System.out.println("Image hyperlink activated.");
      }
    });

    HyperlinkGroup group = new HyperlinkGroup(getShell().getDisplay());
    group.add(hyperlink);
    group.add(imageHyperlink);

    group.setActiveBackground(
      getShell().getDisplay().getSystemColor(SWT.COLOR_YELLOW));
    group.setActiveForeground(
      getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    group.setForeground(
      getShell().getDisplay().getSystemColor(SWT.COLOR_BLUE));
  }

  /*
   * (non-Javadoc)
   
   * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
   */
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    // Sets up the toolkit.
    toolkit = new FormToolkit(getShell().getDisplay());

    // Creates a form instance.
    form = toolkit.createForm(composite);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Sets title.
    form.setText("Custom Form Widgets Demo");

    // demoHyperlinks();
    
    // demoFormTextNormal();
    // demoFormTextURL();
    // demoFormTextXML();

    // demoExpandableComposite();
    demoSections();

    return composite;
  }

  public static void main(String[] args) {
    CustomWidgets win = new CustomWidgets(null);
    win.setBlockOnOpen(true);

    win.open();
  }

}

           
       
Related examples in the same category
1. Email FormEmail Form
2. Simple Form 1Simple Form 1
3. HTML FormHTML Form
w_w_w_.__ja_v__a___2s__.___c__o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.