JFace's IconAndMessageDialog : JFace Dialog « 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 » JFace DialogScreenshots 
JFace's IconAndMessageDialog

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates JFace's IconAndMessageDialog class
 */
public class DumbUser extends ApplicationWindow {
  /**
   * DumbUser constructor
   */
  public DumbUser() {
    super(null);
  }

  /**
   * Runs the application
   */
  public void run() {
    // Don't return from open() until window closes
    setBlockOnOpen(true);

    // Open the main window
    open();

    // Dispose the display
    Display.getCurrent().dispose();
  }

  /**
   * Creates the main window's contents
   
   @param parent the main window
   @return Control
   */
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1true));

    // Create the button
    Button show = new Button(composite, SWT.NONE);
    show.setText("Show");

    final Shell shell = parent.getShell();

    // Display the dialog
    show.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent event) {
        // Create and show the dialog
        DumbMessageDialog dlg = new DumbMessageDialog(shell);
        dlg.open();
      }
    });

    parent.pack();
    return composite;
  }

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

/**
 * This class demonstrates the IconAndMessageDialog class
 */
class DumbMessageDialog extends IconAndMessageDialog {
  public static final int I_DUNNO_ID = IDialogConstants.CLIENT_ID;
  public static final String I_DUNNO_LABEL = "I Dunno";

  // The image
  private Image image;

  // The label for the "hidden" message
  private Label label;

  /**
   * DumbMessageDialog constructor
   
   @param parent the parent shell
   */
  public DumbMessageDialog(Shell parent) {
    super(parent);

    // Create the image
    try {
      image = new Image(parent.getDisplay()new FileInputStream("java2s.gif"));
    catch (FileNotFoundException e) {}

    // Set the default message
    message = "Are you sure you want to do something that dumb?";
  }

  /**
   * Sets the message
   
   @param message the message
   */
  public void setMessage(String message) {
    this.message = message;
  }

  /**
   * Closes the dialog
   
   @return boolean
   */
  public boolean close() {
    if (image != nullimage.dispose();
    return super.close();
  }

  /**
   * Creates the dialog area
   
   @param parent the parent composite
   @return Control
   */
  protected Control createDialogArea(Composite parent) {
    createMessageArea(parent);

    // Create a composite to hold the label
    Composite composite = new Composite(parent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    composite.setLayoutData(data);
    composite.setLayout(new FillLayout());

    // Create the label for the "hidden" message
    label = new Label(composite, SWT.LEFT);

    return composite;
  }

  /**
   * Creates the buttons
   
   @param parent the parent composite
   */
  protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL,
        true);
    createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
    createButton(parent, I_DUNNO_ID, I_DUNNO_LABEL, false);
  }

  /**
   * Handles a button press
   
   @param buttonId the ID of the pressed button
   */
  protected void buttonPressed(int buttonId) {
    // If they press I Dunno, close the dialog
    if (buttonId == I_DUNNO_ID) {
      setReturnCode(buttonId);
      close();
    else {
      // Otherwise, have some fun
      label.setText("Yeah, right. You know nothing.");
    }
  }

  /**
   * Gets the image to use
   */
  protected Image getImage() {
    return image;
  }
}
           
       
Related examples in the same category
1. JFace's ProgressMonitorDialogJFace's ProgressMonitorDialog
2. JFace's MessageDialogJFace's MessageDialog
3. JFace's InputDialogJFace's InputDialog
4. JFace's ErrorDialog classJFace's ErrorDialog class
5. JFace's TitleAreaDialogJFace's TitleAreaDialog
w_w___w_._ja_v__a2__s_.__c___om___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.