Package org.openstreetmap.josm.gui
Class Notification
- java.lang.Object
-
- org.openstreetmap.josm.gui.Notification
-
public class Notification extends java.lang.Object
A Notification Message similar to a popup window, but without disrupting the user's workflow. Non-modal info panel that vanishes after a certain time. This class only holds the data for a notification,NotificationManageris responsible for building the message panel and displaying it on screen. example:Notification note = new Notification("Hi there!"); note.setIcon(JOptionPane.INFORMATION_MESSAGE); // optional note.setDuration(Notification.TIME_SHORT); // optional note.show();
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Componentcontentstatic intDEFAULT_CONTENT_WIDTHDefault width of a notificationprivate intdurationprivate java.lang.StringhelpTopicprivate javax.swing.Iconiconstatic intTIME_DEFAULTShort message of one or two lines (5 s).static intTIME_LONGSomewhat longer message (10 s).static intTIME_SHORTVery short and very easy to grasp message (3 s).static intTIME_VERY_LONGLong text.
-
Constructor Summary
Constructors Constructor Description Notification()Constructs a newNotificationwithout content.Notification(java.lang.String msg)Constructs a newNotificationwith the given textual content.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)java.awt.ComponentgetContent()Gets the content component to use.private java.lang.ObjectgetContentTextOrComponent()intgetDuration()Gets the time the notification should be displayedjava.lang.StringgetHelpTopic()Gets the help topic for this notificationjavax.swing.IcongetIcon()Gets the icon that should be displayed next to the notificationinthashCode()voidreplaceExisting(Notification oldNotification)Display the notification by replacing the given queued/displaying notificationNotificationsetContent(java.awt.Component content)Set the content of the message.NotificationsetContent(java.lang.String msg)Set the notification text.NotificationsetDuration(int duration)Set the time after which the message is hidden.NotificationsetHelpTopic(java.lang.String helpTopic)Display a help button at the bottom of the notification window.NotificationsetIcon(int messageType)Set an icon to display on the left part of the message window by choosing from the default JOptionPane icons.NotificationsetIcon(javax.swing.Icon icon)Set an icon to display on the left part of the message window.voidshow()Display the notification.java.lang.StringtoString()
-
-
-
Field Detail
-
DEFAULT_CONTENT_WIDTH
public static final int DEFAULT_CONTENT_WIDTH
Default width of a notification- See Also:
- Constant Field Values
-
TIME_SHORT
public static final int TIME_SHORT
Very short and very easy to grasp message (3 s). E.g. "Please select at least one node".
-
TIME_DEFAULT
public static final int TIME_DEFAULT
Short message of one or two lines (5 s).
-
TIME_LONG
public static final int TIME_LONG
Somewhat longer message (10 s).
-
TIME_VERY_LONG
public static final int TIME_VERY_LONG
Long text. (Make sure is still sensible to show as a notification)
-
content
private java.awt.Component content
-
duration
private int duration
-
icon
private javax.swing.Icon icon
-
helpTopic
private java.lang.String helpTopic
-
-
Constructor Detail
-
Notification
public Notification()
Constructs a newNotificationwithout content.
-
Notification
public Notification(java.lang.String msg)
Constructs a newNotificationwith the given textual content.- Parameters:
msg- The text to display
-
-
Method Detail
-
setContent
public Notification setContent(java.awt.Component content)
Set the content of the message.- Parameters:
content- any Component to be shown- Returns:
- the current Object, for convenience
- See Also:
setContent(java.lang.String)
-
setContent
public Notification setContent(java.lang.String msg)
Set the notification text. (Convenience method)- Parameters:
msg- the message String. Will be wrapped in <html>, so you can use <br> and other markup directly.- Returns:
- the current Object, for convenience
- See Also:
Notification(java.lang.String)
-
setDuration
public Notification setDuration(int duration)
Set the time after which the message is hidden.- Parameters:
duration- the time (in milliseconds) Preset valuesTIME_SHORT,TIME_DEFAULT,TIME_LONGandTIME_VERY_LONGcan be used.- Returns:
- the current Object, for convenience
-
setIcon
public Notification setIcon(javax.swing.Icon icon)
Set an icon to display on the left part of the message window.- Parameters:
icon- the icon (null means no icon is displayed)- Returns:
- the current Object, for convenience
-
setIcon
public Notification setIcon(int messageType)
Set an icon to display on the left part of the message window by choosing from the default JOptionPane icons.- Parameters:
messageType- one of the following: JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE, JOptionPane.PLAIN_MESSAGE- Returns:
- the current Object, for convenience
-
setHelpTopic
public Notification setHelpTopic(java.lang.String helpTopic)
Display a help button at the bottom of the notification window.- Parameters:
helpTopic- the help topic- Returns:
- the current Object, for convenience
-
getContent
public java.awt.Component getContent()
Gets the content component to use.- Returns:
- The content
-
getDuration
public int getDuration()
Gets the time the notification should be displayed- Returns:
- The time to display the notification
-
getIcon
public javax.swing.Icon getIcon()
Gets the icon that should be displayed next to the notification- Returns:
- The icon to display
-
getHelpTopic
public java.lang.String getHelpTopic()
Gets the help topic for this notification- Returns:
- The help topic
-
show
public void show()
Display the notification.
-
replaceExisting
public void replaceExisting(Notification oldNotification)
Display the notification by replacing the given queued/displaying notification- Parameters:
oldNotification- the notification to replace- Since:
- 17628
-
getContentTextOrComponent
private java.lang.Object getContentTextOrComponent()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-