+ All Categories
Home > Documents > Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on...

Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on...

Date post: 04-Jun-2020
Category:
Upload: others
View: 24 times
Download: 0 times
Share this document with a friend
40
NetBeans Rich Client Platform Nodes & Explorer API Anton Epple http://www.eppleton.de Dialogs API Anton Epple Eppleton IT Consulting
Transcript
Page 1: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

NetBeans Rich Client Platform

Nodes & Explorer API

Anton Epplehttp://www.eppleton.de

Dialogs API

Anton EppleEppleton IT Consulting

Page 2: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

2

NetBeans Rich Client Platform

Introduction

The Dialogs API helps in creating dialogs & wizards

Is based on java.awt.Dialog

Helps creating standard dialogs as well as custom ones

Resembles JOptionPane in many aspects

Integrated with NetBeans Window System & Help System

Simplifies maintaining a standardized Look & Feel

Page 3: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

3

NetBeans Rich Client Platform

Agenda

1. Notifications

2. Standard Dialogs

3. Custom Dialogs

4. Wizards

Page 4: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

4

NetBeans Rich Client Platform

Agenda

1. Notifications

2. Standard Dialogs

3. Custom Dialogs

4. Wizards

Page 5: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

5

NetBeans Rich Client Platform

Notifications

Notifications:

NotifyDescriptor for setting the Properties of a Dialog

Message as a String, Icon or Component

Arrays for more than one message

Specify Type of Message (set's the Icon)

DialogDisplayer to show the message

Page 6: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

6

NetBeans Rich Client Platform

Notifications

Types of Messages:

Defined as constants in NotifyDescriptor

Constant Message type / Symbol

PLAIN_MESSAGE Neutral message without symbol

INFORMATION_MESSAGE Standard info symbol

QUESTION_MESSAGE Questionmark

WARNING_MESSAGE Warning sign

ERROR_MESSAGE Error sign

Page 7: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

7

NetBeans Rich Client Platform

Notifications

Buttons:

Defined as constants in NotifyDescriptor

Constant Controls

DEFAULT_OPTIONS Default controls for the chosen dialog type:e.g. OK Button for PLAIN_MESSAGE

OK_OPTION OK Button

OK_CANCEL_OPTION OK- and Cancel- Button

YES_NO_OPTION Yes- and No- Button

YES_NO_CANCEL_OPTION Yes-, No- and Cancel-Button

Page 8: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

8

NetBeans Rich Client Platform

Notifications

Example:

1. Create new Action “ShowDialog” in Menu “Window”:

2. Add to actionPerformed: public void actionPerformed(ActionEvent e) { NotifyDescriptor d = new NotifyDescriptor( "Text", // Message or Component to show "Title", // Dialog title NotifyDescriptor.OK_CANCEL_OPTION, // Controls NotifyDescriptor.INFORMATION_MESSAGE,// Symbol null, // Custom Controls (Object []) null // initial value ); Object response = DialogDisplayer.getDefault().notify(d); }

Page 9: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

9

NetBeans Rich Client Platform

Notifications

Example:

3. Run and invoke:

Page 10: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

10

NetBeans Rich Client Platform

Notifications

Possible return values:

Constant Action

OK_OPTION OK-button was pressed

YES_OPTION Yes-button was pressed

NO_OPTION No-button was pressed

CANCEL_OPTION Cancel-button was pressed

CLOSED_OPTION Dialog closed without pressing button

Page 11: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

11

NetBeans Rich Client Platform

Agenda

1. Notifications

2. Standard Dialogs

3. Custom Dialogs

4. Wizards

5. Recap

Page 12: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

12

NetBeans Rich Client Platform

Standard Dialogs

Standard Dialogs

For the most common dialog types NotifyDescriptor has four subclasses:

NotifyDescriptor.Message

NotifyDescriptor.Confirmation

NotifyDescriptor.InputLine

NotifyDescriptor.Exception

Page 13: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

13

NetBeans Rich Client Platform

Standard Dialogs

NotifyDescriptor.Message

Change the NotifyDescriptor in actionPerformed to:

NotifyDescriptor d = new NotifyDescriptor.Message(“Place any String here”);

Page 14: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

14

NetBeans Rich Client Platform

Standard Dialogs

NotifyDescriptor.Confirmation

Change the NotifyDescriptor in actionPerformed to:

NotifyDescriptor d = new NotifyDescriptor.Confirmation("Do you really want to format the harddrive?", "This is a question");

Page 15: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

15

NetBeans Rich Client Platform

Standard Dialogs

NotifyDescriptor.InputLine

Change the NotifyDescriptor in actionPerformed to:NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine("Name:","Please enter your name");Object response = DialogDisplayer.getDefault().notify(d);System.out.println("name "+ d.getInputText());

Page 16: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

16

NetBeans Rich Client Platform

Standard Dialogs

NotifyDescriptor.Exception

Change the NotifyDesccriptor in actionPerformed to:

NotifyDescriptor d = new NotifyDescriptor.Exception(new Exception(“Something went wrong!”));

Page 17: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

17

NetBeans Rich Client Platform

Agenda

1. Notifications

2. Standard Dialogs

3. Custom Dialogs

4. Wizards

Page 18: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

18

NetBeans Rich Client Platform

Custom Dialogs

DialogDescriptor

For more customized dialogs you can use the DialogDescriptor class

DialogDescriptor is an Extension of NotifyDescriptor

It accepts a Component to display, an ActionListener to react on controls.

When supplying a HelpCtx it will automatically display a Help button

Page 19: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

19

NetBeans Rich Client Platform

Custom Dialogs

DialogDescriptor Example: Asynchronous Login Dialog

As an example we'll create a Login Dialog to display on startup, so we'll create a Module Installer to display it

We'll use the Form Builder to design the JPanel

To display it asynchronously ( so it doesn't halt the startup process) we'll give it an ActionListener to react on input

If the login is incorrect we'll use the LifecycleManager to shutdown the application

Page 20: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

20

NetBeans Rich Client Platform

Custom Dialogs

DialogDescriptor Example: Login Panel

1. Create a new JPanel “LoginPanel” with the Form Builder:

Page 21: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

21

NetBeans Rich Client Platform

Custom Dialogs

2. Add methods to get the UserName and Password, and set a failure message:

public String getUserName() { return jTextField1.getText(); } public char[] getPassword(){ return jPasswordField1.getPassword(); } public void setInfo(String info){ jLabel3.setText(info); }

Page 22: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

22

NetBeans Rich Client Platform

Custom Dialogs

3. Create a new Module Installer (new File → Module Development → Module Installer) and override restored:

private LoginPanel loginPanel = new LoginPanel(); private DialogDescriptor d = null; @Override public void restored() { d = new DialogDescriptor(loginPanel, "Login", true, this); d.setClosingOptions(new Object[]{}); // not closeable DialogDisplayer.getDefault().notifyLater(d); }

Page 23: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

23

NetBeans Rich Client Platform

Custom Dialogs

4. Dialogdescriptor expects an ActionListener as the constructor's fourth parameter, we fix this by implementing ActionListener:

public class Installer extends ModuleInstall implements ActionListener {… public void actionPerformed(ActionEvent arg0) { if (arg0.getSource() == DialogDescriptor.CANCEL_OPTION){ LifecycleManager.getDefault().exit(); } else if (!loginPanel.getUserName().equals("Toni")){// do real check here loginPanel.setInfo("Wrong Username or Password"); } else { d.setClosingOptions(null);// can close } }

Page 24: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

24

NetBeans Rich Client Platform

Custom Dialogs

5. Run the application:

Page 25: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

25

NetBeans Rich Client Platform

Custom Dialogs

6. Finally fix the bug in restored() method :-) :...// if someone simply closes the dialog d.addPropertyChangeListener(new PropertyChangeListener() {

public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName().equals(DialogDescriptor.PROP_VALUE) && e.getNewValue()== DialogDescriptor.CLOSED_OPTION){ LifecycleManager.getDefault().exit(); } } });DialogDisplayer.getDefault().notifyLater(d);

Page 26: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

26

NetBeans Rich Client Platform

Custom Dialogs

Creating Dialogs without the help of Dialogs API:

File → New File → Java GUI Forms → JDialog

Getting the main Frame as parent:

Page 27: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

27

NetBeans Rich Client Platform

Custom Dialogs

Creating Dialogs without the help of Dialogs API:

File → New File → Java GUI Forms → JDialog

Getting the main Frame as parent:

Frame f = WindowManager.getDefault().getMainWindow();

Page 28: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

28

NetBeans Rich Client Platform

Agenda

1. Notifications

2. Standard Dialogs

3. Custom Dialogs

4. Wizards

Page 29: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

29

NetBeans Rich Client Platform

Wizards

NetBeans Wizard Architecture

WizardDescriptor:

Controller for wizard, manages the Panels

Subclass of DialogDescriptor

Is typically used as DataModel to store the data collected between individual Wizard steps as Properties

Each wizard step typically consists of two classes

A Visual Panel, normally a JPanel without dependencies on Wizard specific classes

A WizardDescriptor.Panel <Data> acting as a Controller

Page 30: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

30

NetBeans Rich Client Platform

Wizards

NetBeans Wizard Architecture

MyWizardAction

MyWizardDescriptor

creates

ChangeListener<<interface>>

WizardDescriptor

MyWizardPanel1ChangeListener<<interface>>

creates (1..*)

MyVisualPanel1EventListener<<interface>>

creates (1)

WizardDescriptor.Panel<<interface>>

JPanel

Page 31: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

31

NetBeans Rich Client Platform

Wizards

The Wizard Wizard creates a skeleton implementation

1. New File → Module Development → Wizard

Page 32: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

32

NetBeans Rich Client Platform

Wizards

2.

Page 33: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

33

NetBeans Rich Client Platform

Wizards

3. The Wizard generates 5 Files:

The generated WizardAction uses the standard WizardDescriptor to invoke the Wizard

Page 34: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

34

NetBeans Rich Client Platform

Wizards

Generated code DemoWizardAction:

WizardDescriptor wizardDescriptor = new WizardDescriptor(getPanels());

// {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()

wizardDescriptor.setTitleFormat(new MessageFormat("{0}"));

wizardDescriptor.setTitle("Your wizard dialog title here");

Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);

dialog.setVisible(true);

dialog.toFront();

boolean cancelled = wizardDescriptor.getValue() !=

WizardDescriptor.FINISH_OPTION;

if (!cancelled) {

// Use WizardDescriptor.getProperty to read the values entered by User

}

Page 35: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

35

NetBeans Rich Client Platform

Wizards

Generated code DemoWizardAction:

private WizardDescriptor.Panel[] getPanels() {

if (panels == null) {

// creates the Panels

panels = new WizardDescriptor.Panel[]{

new DemoWizardPanel1(),

new DemoWizardPanel2()

};

String[] steps = new String[panels.length];

for (int i = 0; i < panels.length; i++) {

… // sets Properties like display name, etc.

Page 36: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

36

NetBeans Rich Client Platform

Wizards

Client Properties for WizardDescriptor.Panel:

Property (WizardPanel_...) Type Meaning

...autoWizardStyle Boolean Turn on subtitle creation

...contentDisplayed Boolean Show step overview Panel

...helpDisplayed Boolean Show help in extra tab

...contentNumbered Boolean Turn on numbering of steps

...contentSelectedIndex Integer Index number of step (starts with 0)

...contentData String [] Names of steps

...image Image Background for overview Panel

...errorMessage String Shown when invalid state

...helpURL URL URL for this Panel's help

Page 37: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

37

NetBeans Rich Client Platform

Wizards

Generated code DemoWizardPanel1:

public Component getComponent() { // returns the Visual Panel return component; }

public boolean isValid() { // can Proceed? return true; }

public final void addChangeListener(ChangeListener l) { // the WizardDescriptor registers here }

public final void removeChangeListener(ChangeListener l) { }

Page 38: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

38

NetBeans Rich Client Platform

Wizards

Generated code DemoWizardPanel1:

// You can use a settings object to keep track of state. Normally the // settings object will be the WizardDescriptor, so you can use // WizardDescriptor.getProperty & putProperty to store information entered // by the user. public void readSettings(Object settings) { this.model = (WizardDescriptor) settings; }

public void storeSettings(Object settings) { model.putProperty(MyVisualPanel1.PROPERTY_SAMPLE, getComponent().getSample() ); }

Page 39: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

39

NetBeans Rich Client Platform

Agenda

1. Notifications

2. Standard Dialogs

3. Custom Dialogs

4. Wizards

Page 40: Dialogs API - edu.netbeans.org · The Dialogs API helps in creating dialogs & wizards Is based on java.awt.Dialog Helps creating standard dialogs as well as custom ones Resembles

NetBeans Rich Client Platform

Q&A


Recommended