CoolBarTest : CoolBar « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » CoolBarScreenshots 
CoolBarTest
CoolBarTest

//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import java.io.*;

import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;

public class CoolBarTest {
  private static final String IMAGE_PATH = "images"
      + System.getProperty("file.separator");

  private Image circle;
  private Image square;
  private Image star;
  private Image triangle;

  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("CoolBar Test");
    createImages(shell);
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    disposeImages();
    display.dispose();
  }

  /**
   * Creates the window contents
   
   @param shell the parent shell
   */
  private void createContents(Shell shell) {
    shell.setLayout(new GridLayout(1false));
    CoolBar coolbar = createCoolBar(shell);
    coolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  }

  /**
   * Creates the CoolBar
   
   @param shell the parent shell
   @return CoolBar
   */
  private CoolBar createCoolBar(Shell shell) {
    CoolBar coolbar = new CoolBar(shell, SWT.NONE);

    // Create toolbar coolitem
    final CoolItem item = new CoolItem(coolbar, SWT.DROP_DOWN);
    item.setControl(createToolBar(coolbar));
    calcSize(item);

    // Add a listener to handle clicks on the chevron button
    item.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        calcSize(item);
      }
    });

    // Create combo coolitem
    CoolItem item2 = new CoolItem(coolbar, SWT.NONE);
    item2.setControl(createCombo(coolbar));
    calcSize(item2);

    // Create a dropdown coolitem
    item2 = new CoolItem(coolbar, SWT.NONE);
    item2.setControl(createStackedButtons(coolbar));
    calcSize(item2);

    return coolbar;
  }

  /**
   * Creates the ToolBar
   
   @param composite the parent composite
   @return Control
   */
  private Control createToolBar(Composite composite) {
    ToolBar toolBar = new ToolBar(composite, SWT.NONE);
    ToolItem item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(circle);
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(square);
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(star);
    item = new ToolItem(toolBar, SWT.PUSH);
    item.setImage(triangle);
    return toolBar;
  }

  /**
   * Creates the Combo
   
   @param composite the parent composite
   @return Control
   */
  private Control createCombo(Composite composite) {
    // A bug with Windows causes the Combo not to drop
    // down if you add it directly to the CoolBar.
    // To work around this, create a Composite, add the
    // Combo to it, and add the Composite to the CoolBar.
    // This should work both on Windows and on all other
    // platforms.
    Composite c = new Composite(composite, SWT.NONE);
    c.setLayout(new FillLayout());
    Combo combo = new Combo(c, SWT.DROP_DOWN);
    combo.add("Option One");
    combo.add("Option Two");
    combo.add("Option Three");
    return c;
  }

  /**
   * Creates two stacked buttons
   
   @param composite the parent composite
   @return Control
   */
  private Control createStackedButtons(Composite composite) {
    Composite c = new Composite(composite, SWT.NONE);
    c.setLayout(new GridLayout(1false));
    new Button(c, SWT.PUSH).setText("Button One");
    new Button(c, SWT.PUSH).setText("Button Two");
    return c;
  }

  /**
   * Helper method to calculate the size of the cool item
   
   @param item the cool item
   */
  private void calcSize(CoolItem item) {
    Control control = item.getControl();
    Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    pt = item.computeSize(pt.x, pt.y);
    item.setSize(pt);
  }

  /**
   * Creates the images
   
   @param shell the parent shell
   */
  private void createImages(Shell shell) {
    try {
      circle = new Image(shell.getDisplay()new FileInputStream(IMAGE_PATH
          "circle.gif"));
      square = new Image(shell.getDisplay()new FileInputStream(IMAGE_PATH
          "square.gif"));
      star = new Image(shell.getDisplay()new FileInputStream(IMAGE_PATH
          "star.gif"));
      triangle = new Image(shell.getDisplay()new FileInputStream(IMAGE_PATH
          "triangle.gif"));
    catch (IOException e) {
      // Images not found; handle gracefully
    }
  }
  
  /**
   * Disposes the images
   */
  private void disposeImages() {
    if (circle != null)
      circle.dispose();
    if (square != null)
      square.dispose();
    if (star != null)
      star.dispose();
    if (triangle != null)
      triangle.dispose();
  }

  /**
   * The entry point for the application
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    new CoolBarTest().run();
  }
}



           
       
Related examples in the same category
1. SWT CoolBar Test DemoSWT CoolBar Test Demo
2. CoolBar ExamplesCoolBar Examples
3. Coolbar Example 2
4. Coolbar Example
5. SWT ToolBar DemoSWT ToolBar Demo
6. SWY CoolBarClassSWY CoolBarClass
7. Drop-down a chevron menu containing hidden tool itemsDrop-down a chevron menu containing hidden tool items
8. Create a coolbar (relayout when resized)Create a coolbar (relayout when resized)
9. CoolBar example snippet: create a cool barCoolBar example snippet: create a cool bar
10. Control example snippet: print mouse state and button (down, move, up)Control example snippet: print mouse state and button (down, move, up)
11. Control example snippet: print key state, code and characterControl example snippet: print key state, code and character
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.