net.java.truelicense.swing.nexes.WizardModel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truelicense-swing Show documentation
Show all versions of truelicense-swing Show documentation
The TrueLicense Swing module provides a graphical user interface for
consuming license keys.
/*
* Copyright (C) 2005-2013 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package net.java.truelicense.swing.nexes;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import javax.swing.Icon;
import net.java.truelicense.core.util.Objects;
/**
* The model for the Wizard component, which tracks the text, icons, and enabled
* state of each of the buttons, as well as the current panel that is displayed.
*
* @author Robert Eckstein (original code)
* @author Christian Schlichtherle (revision)
*/
public class WizardModel {
/**
* Property identification string for the current panel getPanelDescriptor.
*/
public static final String CURRENT_PANEL_DESCRIPTOR_PROPERTY
= "currentPanelDescriptor"; // NOI18N
/**
* Property identification String for the Back button's text
*/
public static final String BACK_BUTTON_TEXT_PROPERTY
= "backButtonText"; // NOI18N
/**
* Property identification String for the Back button's icon
*/
public static final String BACK_BUTTON_ICON_PROPERTY
= "backButtonIcon"; // NOI18N
/**
* Property identification String for the Back button's enabled state
*/
public static final String BACK_BUTTON_ENABLED_PROPERTY
= "backButtonEnabled"; // NOI18N
/**
* Property identification String for the Next button's text
*/
public static final String NEXT_BUTTON_TEXT_PROPERTY
= "nextButtonText"; // NOI18N
/**
* Property identification String for the Next button's icon
*/
public static final String NEXT_BUTTON_ICON_PROPERTY
= "nextButtonIcon"; // NOI18N
/**
* Property identification String for the Next button's enabled state
*/
public static final String NEXT_BUTTON_ENABLED_PROPERTY
= "nextButtonEnabled"; // NOI18N
/**
* Property identification String for the Cancel button's text
*/
public static final String CANCEL_BUTTON_TEXT_PROPERTY
= "cancelButtonText"; // NOI18N
/**
* Property identification String for the Cancel button's icon
*/
public static final String CANCEL_BUTTON_ICON_PROPERTY
= "cancelButtonIcon"; // NOI18N
/**
* Property identification String for the Cancel button's enabled state
*/
public static final String CANCEL_BUTTON_ENABLED_PROPERTY
= "cancelButtonEnabled"; // NOI18N
private final Map
panels = new HashMap();
private final Map buttonsText = new HashMap();
private final Map buttonsIcon = new HashMap();
private final Map buttonsEnabled = new HashMap();
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private WizardPanelDescriptor currentPanelDescriptor;
/** Adds the given wizard panel getPanelDescriptor to this model. */
public void addPanelDescriptor(WizardPanelDescriptor wpd) {
panels.put(wpd.getIdentifier(), wpd);
}
@CheckForNull WizardPanelDescriptor getPanelDescriptor(@CheckForNull String id) {
return panels.get(id);
}
/** Returns the current wizard panel getPanelDescriptor. */
public @CheckForNull WizardPanelDescriptor getCurrentPanelDescriptor() {
return currentPanelDescriptor;
}
/** Sets the current wizard panel getPanelDescriptor. */
public void setCurrentPanelDescriptor(final @CheckForNull WizardPanelDescriptor nwpd) {
if (null != nwpd && !nwpd.equals(panels.get(nwpd.getIdentifier())))
throw new IllegalArgumentException();
final WizardPanelDescriptor owpd = currentPanelDescriptor;
currentPanelDescriptor = nwpd;
firePropertyChange(CURRENT_PANEL_DESCRIPTOR_PROPERTY, owpd, nwpd);
}
public @CheckForNull String getBackButtonText() {
return buttonsText.get(BACK_BUTTON_TEXT_PROPERTY);
}
public void setBackButtonText(@CheckForNull String newText) {
final String oldText = getBackButtonText();
if (!Objects.equals(oldText, newText)) {
buttonsText.put(BACK_BUTTON_TEXT_PROPERTY, newText);
firePropertyChange(BACK_BUTTON_TEXT_PROPERTY, oldText, newText);
}
}
public @CheckForNull String getNextButtonText() {
return buttonsText.get(NEXT_BUTTON_TEXT_PROPERTY);
}
public void setNextButtonText(final @CheckForNull String newText) {
final String oldText = getNextButtonText();
if (!Objects.equals(oldText, newText)) {
buttonsText.put(NEXT_BUTTON_TEXT_PROPERTY, newText);
firePropertyChange(NEXT_BUTTON_TEXT_PROPERTY, oldText, newText);
}
}
public @CheckForNull String getCancelButtonText() {
return buttonsText.get(CANCEL_BUTTON_TEXT_PROPERTY);
}
public void setCancelButtonText(final @CheckForNull String newText) {
final String oldText = getCancelButtonText();
if (!Objects.equals(oldText, newText)) {
buttonsText.put(CANCEL_BUTTON_TEXT_PROPERTY, newText);
firePropertyChange(CANCEL_BUTTON_TEXT_PROPERTY, oldText, newText);
}
}
public @CheckForNull Icon getBackButtonIcon() {
return buttonsIcon.get(BACK_BUTTON_ICON_PROPERTY);
}
public void setBackButtonIcon(final @CheckForNull Icon newIcon) {
final Icon oldIcon = getBackButtonIcon();
if (!Objects.equals(oldIcon, newIcon)) {
buttonsIcon.put(BACK_BUTTON_ICON_PROPERTY, newIcon);
firePropertyChange(BACK_BUTTON_ICON_PROPERTY, oldIcon, newIcon);
}
}
public @CheckForNull Icon getNextButtonIcon() {
return buttonsIcon.get(NEXT_BUTTON_ICON_PROPERTY);
}
public void setNextButtonIcon(final @CheckForNull Icon newIcon) {
final Icon oldIcon = getNextButtonIcon();
if (!Objects.equals(oldIcon, newIcon)) {
buttonsIcon.put(NEXT_BUTTON_ICON_PROPERTY, newIcon);
firePropertyChange(NEXT_BUTTON_ICON_PROPERTY, oldIcon, newIcon);
}
}
public @CheckForNull Icon getCancelButtonIcon() {
return buttonsIcon.get(CANCEL_BUTTON_ICON_PROPERTY);
}
public void setCancelButtonIcon(final @CheckForNull Icon newIcon) {
final Icon oldIcon = getCancelButtonIcon();
if (!Objects.equals(oldIcon, newIcon)) {
buttonsIcon.put(CANCEL_BUTTON_ICON_PROPERTY, newIcon);
firePropertyChange(CANCEL_BUTTON_ICON_PROPERTY, oldIcon, newIcon);
}
}
public @CheckForNull Boolean getBackButtonEnabled() {
return buttonsEnabled.get(BACK_BUTTON_ENABLED_PROPERTY);
}
public void setBackButtonEnabled(final @CheckForNull Boolean newValue) {
final Boolean oldValue = getBackButtonEnabled();
if (!Objects.equals(oldValue, newValue)) {
buttonsEnabled.put(BACK_BUTTON_ENABLED_PROPERTY, newValue);
firePropertyChange(BACK_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
}
}
public @CheckForNull Boolean getNextButtonEnabled() {
return buttonsEnabled.get(NEXT_BUTTON_ENABLED_PROPERTY);
}
public void setNextButtonEnabled(final @CheckForNull Boolean newValue) {
final Boolean oldValue = getNextButtonEnabled();
if (!Objects.equals(oldValue, newValue)) {
buttonsEnabled.put(NEXT_BUTTON_ENABLED_PROPERTY, newValue);
firePropertyChange(NEXT_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
}
}
public @CheckForNull Boolean getCancelButtonEnabled() {
return buttonsEnabled.get(CANCEL_BUTTON_ENABLED_PROPERTY);
}
public void setCancelButtonEnabled(final @CheckForNull Boolean newValue) {
final Boolean oldValue = getCancelButtonEnabled();
if (!Objects.equals(oldValue, newValue)) {
buttonsEnabled.put(CANCEL_BUTTON_ENABLED_PROPERTY, newValue);
firePropertyChange(CANCEL_BUTTON_ENABLED_PROPERTY, oldValue, newValue);
}
}
public void addPropertyChangeListener(PropertyChangeListener pcl) {
pcs.addPropertyChangeListener(pcl);
}
public void removePropertyChangeListener(PropertyChangeListener pcl) {
pcs.removePropertyChangeListener(pcl);
}
private void firePropertyChange(
String propertyName,
@CheckForNull Object oldValue,
@CheckForNull Object newValue) {
pcs.firePropertyChange(propertyName, oldValue, newValue);
}
}