package org.openslx.dozmod.gui.wizard; import java.awt.Color; import java.awt.Dialog; import javax.swing.Icon; import javax.swing.JPanel; import javax.swing.UIManager; @SuppressWarnings("serial") public abstract class WizardPage extends JPanel { private static final Color WARNING_COLOR = new Color(200, 100, 0); private final String title; private String description = null; private String message = null; private boolean isError = false; private boolean isComplete = false; protected final Wizard wizard; /** * Whether the user is allowed to go back to this page once they clicked * next. */ protected boolean canComeBack = true; public WizardPage(Wizard wizard, String title) { if (wizard == null) throw new NullPointerException("WizardPage needs a Wizard"); this.wizard = wizard; this.title = title; } public String getTitle() { return this.title; } public String getMessage() { if (this.message != null) return this.message; return this.description; } private void updateHeader() { if (this.wizard != null) this.wizard.updateHeader(this); } protected Dialog getDialog() { return wizard; } public boolean isComplete() { return this.isComplete; } /* * Feedback from the pages */ /** * Called when the user wants to advance to the next page. You have the * chance to run some sanity checks and return false if you want to prevent * the user from switching the page, but in general it is recommended to * disable the next button as long as there are errors in the current page. * * @return true allows to flip the page, false cancels */ protected boolean wantNextOrFinish() { return isComplete; } /** * Called when the page is being shown. This can be caused by three possible * events: * 1) The wizard opens and this is the fist page * 2) The user clicked "Previous" and this is the previous page * 3) The user clicked "Next" and this is the next page */ protected void onPageEnter() { } /** * Called when the page is being hidden. This can be caused by three * possible events: * 1) The user clicked finish and this is the page currently displayed * 2) The user clicked "Previous" and this is the current page * 3) The user clicked "Next" and this is the current page */ protected void onPageLeave() { } /* * Setters from derived classes */ protected void setPageComplete(boolean b) { if (isComplete == b) return; isComplete = b; if (wizard != null) wizard.updateButtons(this); } protected void setDescription(String description) { this.message = null; this.description = description; this.updateHeader(); } protected void setErrorMessage(String message) { this.message = message; this.isError = true; this.updateHeader(); } protected void setWarningMessage(String message) { this.message = message; this.isError = false; this.updateHeader(); } protected Icon getMessageIcon() { if (message == null) return null; if (isError) return UIManager.getIcon("OptionPane.errorIcon"); return UIManager.getIcon("OptionPane.warningIcon"); } public Color getMessageColor() { if (message == null) return Color.BLACK; if (isError) return Color.RED; return WARNING_COLOR; } }