com.pekinsoft.spi.StatusDisplayer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ServiceProviders Show documentation
Show all versions of ServiceProviders Show documentation
An API that allows for dynamic application features and loose coupling.
The newest version!
/*
* Copyright (C) 2022 PekinSOFT Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* *****************************************************************************
* Project : Application
* Class : StatusDisplayer.java
* Author : Sean Carrick
* Created : Dec 12, 2022
* Modified : Dec 12, 2022
*
* Purpose: See class JavaDoc for explanation
*
* Revision History:
*
* WHEN BY REASON
* ------------ ------------------- -----------------------------------------
* Dec 12, 2022 Sean Carrick Initial creation.
* *****************************************************************************
*/
package com.pekinsoft.spi;
import java.awt.Color;
import java.awt.Font;
import javax.swing.UIManager;
import org.openide.util.Lookup;
/**
* {@code StatusDisplayer} allows for an application to provide an object that
* displays status messages to the user. Typically, an application will only
* provide a single {@code StatusDisplayer}, which will be, by default, the
* *default {@code StatusDisplayer}*.
*
* To retrieve the application's {@code StatusDisplayer} implementation, one
* only needs to do the following in order to display a message in it:
*
* StatusDisplayer.getDefault().setMessage("message to set", MessageType.NORMAL);
*
* By doing the above, the default {@code StatusDisplayer} will display
* the text "message to set" in its message component. By setting the type of
* the message displayed to {@code MessageType.NORMAL}, the message will be
* displayed in the desktop's default color. To alter the color, simply use one
* of the other `MessageType` constants:
*
* - {@code MessageType.INFO} —
* Displays in bold, blue text.
*
- {@code MessageType.WARNING} —
* Displays in bold, orange text.
*
- {@code MessageType.ERROR} —
* Displays in bold, red text.
*
- {@code MessageType.NORMAL} — Displays in the standard,
* default colored text.
*
*
* @author Sean Carrick <sean at pekinsoft dot com>
*
* @version 1.3
* @since 1.0
*/
public interface StatusDisplayer {
/**
* Sets the message to be displayed in the {@code StatusDisplayer}
* implementation, as well as the type of message that is to be displayed,
* which needs to be one of the `MessageType` constants:
*
* - {@code MessageType.INFO} — **
* Displays in bold, blue text**.
* - {@code MessageType.WARNING} —
* **
* Displays in bold, orange text**.
* - {@code MessageType.ERROR} — **
* Displays in bold, red text**.
* - {@code MessageType.NORMAL} — Displays in the standard,
* default colored text.
*
* @param message the message text to be displayed
* @param type the type of message to be displayed; one of the `MessageType`
* constants for `NORMAL`, `INFO`, `WARNING`,
* or `ERROR`
*/
public void setMessage(String message, MessageType type);
/**
* Convenience method for setting a {@code MessageType.NORMAL} message to
* the {@code StatusDisplayer} implementation. This default method simply
* calls the {@link #setMessage(java.lang.String, com.pekinsoft.spi.StatusDisplayer.MessageType)
* setMessage(String, MessageType)} method passing on the `message`
* and setting the type to {@code MessageType.NORMAL}.
*
* @param message the message text to be displayed
*/
public default void setMessage(String message) {
setMessage(message, MessageType.NORMAL);
}
public static StatusDisplayer getDefault() {
return Lookup.getDefault().lookup(StatusDisplayer.class);
}
public static enum MessageType {
NORMAL,
INFO,
WARNING,
ERROR;
public Color asColor() {
switch (this) {
case ERROR:
return Color.red;
case INFO:
return Color.blue;
case NORMAL:
return UIManager.getColor("textText");
case WARNING:
return Color.orange;
default:
return NORMAL.asColor();
}
}
public Font getFont() {
Font f = UIManager.getFont("TextField.font");
switch (this) {
case NORMAL:
return f;
default:
return f.deriveFont(Font.BOLD);
}
}
}
}