Skip to content

Commit

Permalink
allow user to override validation icons
Browse files Browse the repository at this point in the history
  • Loading branch information
jidesoft committed Nov 21, 2013
1 parent 38a7b21 commit 0ff7b65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Expand Up @@ -8,15 +8,49 @@

import javafx.event.EventType;

/**
* A class to provide all the icons for the validation results.
*/
@SuppressWarnings("UnusedDeclaration")
public class ValidationIcons {
public static final String ICON_CORRECT = "/jidefx/scene/control/decoration/overlay_correct.png"; //NON-NLS
public static final String ICON_INFO = "/jidefx/scene/control/decoration/overlay_info.png"; //NON-NLS
public static final String ICON_ATTENTION = "/jidefx/scene/control/decoration/overlay_warning.png"; //NON-NLS
public static final String ICON_QUESTION = "/jidefx/scene/control/decoration/overlay_question.png"; //NON-NLS
public static final String ICON_ERROR = "/jidefx/scene/control/decoration/overlay_error.png"; //NON-NLS
private static ValidationIcons INSTANCE = null;

/**
* Gets a new instance which will be used globally to get the validation icons.
*
* @return the instance of {@code ValidationIcons}.
*/
public static ValidationIcons getInstance() {
if (INSTANCE == null) {
INSTANCE = new ValidationIcons();
}
return INSTANCE;
}

/**
* Sets a new instance which will be used globally to get the validation icons.
*
* @param instance a new instance of {@code ValidationIcons}.
*/
public static void setInstance(ValidationIcons instance) {
INSTANCE = instance;
}

public static String getValidationResultIcon(EventType<ValidationEvent> type) {
/**
* By default, we use our own icons inside the JideFX but you can override this method to return another set of
* icons and then call {@link #setInstance(ValidationIcons)} to set your instance.
*
* @param type the event type
* @return a full path to the icon in the class path format. For example, if you have an error.png icon under
* package com.mycompany.myicons, the full path would be "/com/mycompany/myicons/error.png". In the other
* word, the icon must be in the classpath in order for the icon to be used by {@code ValidationIcons}.
*/
public String getValidationResultIcon(EventType<ValidationEvent> type) {
if (ValidationEvent.VALIDATION_ERROR.equals(type)) {
return ICON_ERROR;
}
Expand Down
Expand Up @@ -501,7 +501,7 @@ public void handle(ValidationEvent event) {
}

Label label;
ImageView graphic = new ImageView(ValidationIcons.getValidationResultIcon(event.getEventType()));
ImageView graphic = new ImageView(ValidationIcons.getInstance().getValidationResultIcon(event.getEventType()));
if (resultDecorator != null && exists(targetNode, resultDecorator)) {
label = (Label) resultDecorator.getNode();
label.setGraphic(graphic);
Expand Down

0 comments on commit 0ff7b65

Please sign in to comment.