Try to fix warnings by NetBeans
This commit is contained in:
@@ -77,7 +77,7 @@ public class ModpackWizard extends WizardBranchController {
|
||||
service.version(),
|
||||
(String) settings.get(ModpackInitializationPanel.KEY_GAME_VERSION),
|
||||
blackList);
|
||||
progress.finished(Summary.create(C.i18n("modpack.export_finished") + ": " + loc.getAbsolutePath(), null));
|
||||
progress.finished(new Summary(C.i18n("modpack.export_finished") + ": " + loc.getAbsolutePath(), null));
|
||||
} catch (IOException | GameException ex) {
|
||||
HMCLog.err("Failed to export modpack", ex);
|
||||
progress.failed(C.i18n("modpack.export_error") + ": " + ex.getClass().getName() + ", " + ex.getLocalizedMessage(), true);
|
||||
|
||||
@@ -207,15 +207,13 @@ public abstract class WizardDisplayer {
|
||||
if (new HashSet(Arrays.asList(s)).size() != s.length)
|
||||
throw new RuntimeException("steps are duplicated: " + Arrays.asList(s));
|
||||
if (s.length == 1 && Wizard.UNDETERMINED_STEP.equals(s[0]))
|
||||
// assert false : "Only ID may not be UNDETERMINED_ID"; //NOI18N
|
||||
// assert false : "Only ID may not be UNDETERMINED_ID";
|
||||
throw new RuntimeException("Only ID may not be UNDETERMINED_ID");
|
||||
for (int i = 0; i < s.length; i++)
|
||||
if (Wizard.UNDETERMINED_STEP.equals(s[i]) && i != s.length - 1)
|
||||
// assert false : "UNDETERMINED_ID may only be last element in" + //NOI18N
|
||||
// " ids array " + Arrays.asList(s); //NOI18N
|
||||
throw new RuntimeException("UNDETERMINED_ID may only be last element in"
|
||||
+ //NOI18N
|
||||
" ids array " + Arrays.asList(s)); //NOI18N)
|
||||
// assert false : "UNDETERMINED_ID may only be last element in" +
|
||||
// " ids array " + Arrays.asList(s);
|
||||
throw new RuntimeException("UNDETERMINED_ID may only be last element in ids array " + Arrays.asList(s));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
@@ -62,9 +61,6 @@ public class NavButtonManager implements ActionListener {
|
||||
*/
|
||||
static final String DEFERRED_FAILED = "FAILED_";
|
||||
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(NavButtonManager.class.getName());
|
||||
|
||||
JButton next = null;
|
||||
|
||||
JButton prev = null;
|
||||
@@ -105,7 +101,7 @@ public class NavButtonManager implements ActionListener {
|
||||
prev.setName(NAME_PREV);
|
||||
prev.setMnemonic(C.i18n("wizard.prev_mnemonic").charAt(0));
|
||||
|
||||
finish = new JButton(C.i18n("wizard.finish")); // NOI18N
|
||||
finish = new JButton(C.i18n("wizard.finish"));
|
||||
finish.setName(NAME_FINISH);
|
||||
finish.setMnemonic(C.i18n("wizard.finish_mnemonic").charAt(0));
|
||||
|
||||
@@ -127,7 +123,7 @@ public class NavButtonManager implements ActionListener {
|
||||
help.setVisible(helpAction != null);
|
||||
|
||||
// Use standard default-button-last order on Aqua L&F
|
||||
final boolean aqua = "Aqua".equals(UIManager.getLookAndFeel().getID()); // NOI18N
|
||||
final boolean aqua = "Aqua".equals(UIManager.getLookAndFeel().getID());
|
||||
|
||||
buttons = new JPanel() {
|
||||
public void doLayout() {
|
||||
@@ -163,7 +159,7 @@ public class NavButtonManager implements ActionListener {
|
||||
}
|
||||
};
|
||||
buttons.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, UIManager
|
||||
.getColor("textText"))); // NOI18N
|
||||
.getColor("textText")));
|
||||
|
||||
buttons.add(prev);
|
||||
buttons.add(next);
|
||||
@@ -494,7 +490,6 @@ public class NavButtonManager implements ActionListener {
|
||||
boolean closeWindow;
|
||||
|
||||
if (reallyCancel && parent.cancel()) {
|
||||
logger.fine("calling wizard cancel method on " + wizard);
|
||||
wizard.cancel(settings);
|
||||
return;
|
||||
}
|
||||
@@ -530,7 +525,7 @@ public class NavButtonManager implements ActionListener {
|
||||
if (window != null && parent.receiver == null && window instanceof JDialog)
|
||||
((JDialog) window).getRootPane().setDefaultButton(cancel);
|
||||
|
||||
cancel.setText(getCloseString()); // NOI18N
|
||||
cancel.setText(getCloseString());
|
||||
cancel.setMnemonic(C.i18n("wizard.close_mnemonic").charAt(0));
|
||||
cancel.setName(NAME_CLOSE);
|
||||
deferredStatus = null; // ?? should summary be different
|
||||
|
||||
@@ -3,12 +3,12 @@ package org.jackhuang.hellominecraft.utils.views.wizard.api.displayer;
|
||||
import java.awt.Container;
|
||||
import java.awt.EventQueue;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import org.jackhuang.hellominecraft.utils.C;
|
||||
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
|
||||
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.ResultProgressHandle;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.Summary;
|
||||
@@ -28,9 +28,6 @@ import org.jackhuang.hellominecraft.utils.views.wizard.spi.Summary;
|
||||
*/
|
||||
public class NavProgress implements ResultProgressHandle {
|
||||
|
||||
private static final Logger logger
|
||||
= Logger.getLogger(NavProgress.class.getName());
|
||||
|
||||
JProgressBar progressBar = new JProgressBar();
|
||||
|
||||
JLabel lbl = new JLabel();
|
||||
@@ -61,7 +58,7 @@ public class NavProgress implements ResultProgressHandle {
|
||||
|
||||
public void setProgress(final String description, final int currentStep, final int totalSteps) {
|
||||
invoke(() -> {
|
||||
lbl.setText(description == null ? " " : description); // NOI18N
|
||||
lbl.setText(description == null ? " " : description);
|
||||
setProgress(currentStep, totalSteps);
|
||||
});
|
||||
}
|
||||
@@ -99,8 +96,7 @@ public class NavProgress implements ResultProgressHandle {
|
||||
try {
|
||||
EventQueue.invokeAndWait(r);
|
||||
} catch (InvocationTargetException | InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
logger.severe("Error invoking operation " + ex.getClass().getName() + " " + ex.getMessage());
|
||||
HMCLog.err("NavProgress: Error invoking operation", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +123,7 @@ public class NavProgress implements ResultProgressHandle {
|
||||
|
||||
Runnable r = () -> {
|
||||
// cheap word wrap
|
||||
JLabel comp = new JLabel("<html><body>" + message); // NOI18N
|
||||
JLabel comp = new JLabel("<html><body>" + message);
|
||||
comp.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
parent.setCurrentWizardPanel(comp);
|
||||
parent.getTtlLabel().setText(C.i18n("wizard.failed"));
|
||||
|
||||
@@ -34,8 +34,6 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
@@ -125,7 +123,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
ttlLabel = new JLabel(wizard.getStepDescription(wizard.getAllSteps()[0]));
|
||||
ttlLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
|
||||
.createEmptyBorder(5, 5, 12, 5), BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager
|
||||
.getColor("textText")))); // NOI18N
|
||||
.getColor("textText"))));
|
||||
ttlPanel = new JPanel() {
|
||||
public void doLayout() {
|
||||
Dimension d = ttlLabel.getPreferredSize();
|
||||
@@ -142,7 +140,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
ttlPanel.add(ttlLabel);
|
||||
Font f = ttlLabel.getFont();
|
||||
if (f == null)
|
||||
f = UIManager.getFont("controlFont"); // NOI18N
|
||||
f = UIManager.getFont("controlFont");
|
||||
if (f != null) {
|
||||
f = f.deriveFont(Font.BOLD);
|
||||
ttlLabel.setFont(f);
|
||||
@@ -173,7 +171,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
outerPanel = new JPanel();
|
||||
|
||||
if (wizard.getAllSteps().length == 0)
|
||||
throw new IllegalArgumentException("Wizard has no steps"); // NOI18N
|
||||
throw new IllegalArgumentException("Wizard has no steps");
|
||||
|
||||
// initialize the ttl* stuff
|
||||
buildStepTitle();
|
||||
@@ -190,8 +188,8 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
}
|
||||
};
|
||||
outerPanel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); //NOI18N
|
||||
outerPanel.getActionMap().put("cancel", kbdCancel); //NOI18N
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel");
|
||||
outerPanel.getActionMap().put("cancel", kbdCancel);
|
||||
|
||||
instructions = createInstructionsPanel();
|
||||
|
||||
@@ -202,7 +200,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
inner.add(ttlPanel, BorderLayout.NORTH);
|
||||
|
||||
problem = new JLabel(" ");
|
||||
Color fg = UIManager.getColor("nb.errorColor"); // NOI18N
|
||||
Color fg = UIManager.getColor("nb.errorColor");
|
||||
problem.setForeground(fg == null ? Color.BLUE : fg);
|
||||
inner.add(problem, BorderLayout.SOUTH);
|
||||
problem.setPreferredSize(new Dimension(20, 20));
|
||||
@@ -254,10 +252,9 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
public Object show(final Wizard awizard, Rectangle bounds, Action helpAction,
|
||||
Map initialProperties) {
|
||||
if (!EventQueue.isDispatchThread() && !warned) {
|
||||
Logger.getLogger(WizardDisplayerImpl.class.getName()).log(Level.WARNING,
|
||||
"show() should be called from the AWT Event Thread. This "
|
||||
+ "call may deadlock - c.f. "
|
||||
+ "http://java.net/jira/browse/WIZARD-33", new Throwable());
|
||||
HMCLog.warn("WizardDisplayerImpl: show() should be called from the AWT Event Thread. This "
|
||||
+ "call may deadlock - c.f. "
|
||||
+ "http://java.net/jira/browse/WIZARD-33", new Throwable());
|
||||
warned = true;
|
||||
}
|
||||
createOuterPanel(awizard, bounds, helpAction, initialProperties);
|
||||
@@ -364,8 +361,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal forward "
|
||||
+ // NOI18N
|
||||
"navigation mode: " + i); // NOI18N
|
||||
+ "navigation mode: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +446,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
}
|
||||
}
|
||||
else {
|
||||
synchronized (this) {
|
||||
synchronized (WizardDisplayerImpl.this) {
|
||||
deferredResult = null;
|
||||
}
|
||||
buttonManager.getCancel().setEnabled(true);
|
||||
@@ -463,7 +459,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
}
|
||||
}
|
||||
};
|
||||
Thread runner = new Thread(run, "Wizard Background Result Thread " + r); // NOI18N
|
||||
Thread runner = new Thread(run, "Wizard Background Result Thread " + r);
|
||||
runner.start();
|
||||
}
|
||||
|
||||
@@ -553,7 +549,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
|
||||
void updateProblem() {
|
||||
String prob = wizard.getProblem();
|
||||
problem.setText(prob == null ? " " : prob); // NOI18N
|
||||
problem.setText(prob == null ? " " : prob);
|
||||
if (prob != null && prob.trim().length() == 0)
|
||||
// Issue 3 - provide ability to disable next w/o
|
||||
// showing the error line
|
||||
|
||||
@@ -72,7 +72,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
|
||||
public InstructionsPanelImpl(Wizard wiz) {
|
||||
this(null, wiz);
|
||||
Font f = UIManager.getFont("Tree.font"); //NOI18N
|
||||
Font f = UIManager.getFont("Tree.font");
|
||||
if (f != null)
|
||||
setFont(f);
|
||||
}
|
||||
@@ -123,9 +123,9 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
//In the event of classloader issues, also have a way to get
|
||||
//the image from UIManager - slightly more portable for large
|
||||
//apps
|
||||
img = (BufferedImage) UIManager.get("wizard.sidebar.image"); //NOI18N
|
||||
img = (BufferedImage) UIManager.get("wizard.sidebar.image");
|
||||
|
||||
String imgStr = System.getProperty("wizard.sidebar.image"); //NOI18N
|
||||
String imgStr = System.getProperty("wizard.sidebar.image");
|
||||
//image has not been loaded and user wishes to supply their own image
|
||||
if (img == null && imgStr != null) {
|
||||
//get an URL, works for jars
|
||||
@@ -137,21 +137,20 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
img = ImageIO.read(url);
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Could not load wizard image "
|
||||
+ //NOI18N
|
||||
ioe.getMessage());
|
||||
System.setProperty("wizard.sidebar.image", null); //NOI18N
|
||||
+ ioe.getMessage());
|
||||
System.setProperty("wizard.sidebar.image", null);
|
||||
img = null; //error loading img, set to null to use default
|
||||
}
|
||||
else { //URL was not successfully parsed, set img to null to use default
|
||||
System.err.println("Bad URL for wizard image " + imgStr); //NOI18N
|
||||
System.setProperty("wizard.sidebar.image", null); //NOI18N
|
||||
System.err.println("Bad URL for wizard image " + imgStr);
|
||||
System.setProperty("wizard.sidebar.image", null);
|
||||
img = null;
|
||||
}
|
||||
}
|
||||
if (img == null)
|
||||
try {
|
||||
img = ImageIO.read(InstructionsPanelImpl.class.getResourceAsStream(
|
||||
"/org/jackhuang/hellominecraft/wizard.jpg")); //NOI18N
|
||||
"/org/jackhuang/hellominecraft/wizard.jpg"));
|
||||
} catch (IOException ioe) {
|
||||
HMCLog.err("Failed to load wizard.jpg, maybe you fucking modified the launcher", ioe);
|
||||
}
|
||||
@@ -189,7 +188,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
|
||||
public final void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Font f = getFont() != null ? getFont() : UIManager.getFont("controlFont"); //NOI18N
|
||||
Font f = getFont() != null ? getFont() : UIManager.getFont("controlFont");
|
||||
FontMetrics fm = g.getFontMetrics(f);
|
||||
Insets ins = getInsets();
|
||||
int dx = ins.left;
|
||||
@@ -202,13 +201,13 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
//Don't fetch step list if in summary page, there will
|
||||
//only be the base ones
|
||||
steps = wizard.getAllSteps();
|
||||
String steps[] = this.steps;
|
||||
String[] steps2 = this.steps;
|
||||
if (inSummaryPage) {
|
||||
String summaryStep = C.i18n("wizard.summary");
|
||||
String[] nue = new String[steps.length + 1];
|
||||
System.arraycopy(steps, 0, nue, 0, steps.length);
|
||||
String[] nue = new String[steps2.length + 1];
|
||||
System.arraycopy(steps2, 0, nue, 0, steps2.length);
|
||||
nue[nue.length - 1] = summaryStep;
|
||||
steps = nue;
|
||||
steps2 = nue;
|
||||
}
|
||||
int y = fm.getMaxAscent() + ins.top + MARGIN;
|
||||
int x = ins.left + MARGIN;
|
||||
@@ -228,27 +227,27 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
|
||||
y += h + 10;
|
||||
int first = 0;
|
||||
int stop = steps.length;
|
||||
boolean wontFit = y + (h * (steps.length)) > getHeight();
|
||||
int stop = steps2.length;
|
||||
boolean wontFit = y + (h * (steps2.length)) > getHeight();
|
||||
if (wontFit) {
|
||||
//try to center the current step
|
||||
int availHeight = bottom - y;
|
||||
int willFit = availHeight / h;
|
||||
int currStepIndex = Arrays.asList(steps).indexOf(currentStep);
|
||||
int currStepIndex = Arrays.asList(steps2).indexOf(currentStep);
|
||||
int rangeStart = Math.max(0, currStepIndex - (willFit / 2));
|
||||
int rangeEnd = Math.min(rangeStart + willFit, steps.length);
|
||||
if (rangeStart + willFit > steps.length) {
|
||||
int rangeEnd = Math.min(rangeStart + willFit, steps2.length);
|
||||
if (rangeStart + willFit > steps2.length) {
|
||||
//Don't scroll off if there's room
|
||||
rangeStart = steps.length - willFit;
|
||||
rangeEnd = steps.length;
|
||||
rangeStart = steps2.length - willFit;
|
||||
rangeEnd = steps2.length;
|
||||
}
|
||||
steps = (String[]) steps.clone();
|
||||
steps2 = (String[]) steps2.clone();
|
||||
if (rangeStart != 0) {
|
||||
steps[rangeStart] = elipsis;
|
||||
steps2[rangeStart] = elipsis;
|
||||
first = rangeStart;
|
||||
}
|
||||
if (rangeEnd != steps.length && rangeEnd > 0) {
|
||||
steps[rangeEnd - 1] = elipsis;
|
||||
if (rangeEnd != steps2.length && rangeEnd > 0) {
|
||||
steps2[rangeEnd - 1] = elipsis;
|
||||
stop = rangeEnd;
|
||||
}
|
||||
}
|
||||
@@ -257,25 +256,25 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
g.setColor(getForeground());
|
||||
|
||||
for (int i = first; i < stop; i++) {
|
||||
boolean isUndetermined = Wizard.UNDETERMINED_STEP.equals(steps[i]);
|
||||
boolean isUndetermined = Wizard.UNDETERMINED_STEP.equals(steps2[i]);
|
||||
boolean canOnlyFinish = wizard.getForwardNavigationMode()
|
||||
== Wizard.MODE_CAN_FINISH;
|
||||
if (isUndetermined && canOnlyFinish)
|
||||
break;
|
||||
String curr;
|
||||
if (!elipsis.equals(steps[i]))
|
||||
if (!elipsis.equals(steps2[i]))
|
||||
if (inSummaryPage && i == this.steps.length)
|
||||
curr = (i + 1) + ". " + steps[i];
|
||||
curr = (i + 1) + ". " + steps2[i];
|
||||
else
|
||||
curr = (i + 1) + ". " + (isUndetermined
|
||||
? elipsis
|
||||
: steps[i].equals(elipsis) ? elipsis
|
||||
: wizard.getStepDescription(steps[i]));
|
||||
: steps2[i].equals(elipsis) ? elipsis
|
||||
: wizard.getStepDescription(steps2[i]));
|
||||
else
|
||||
curr = elipsis;
|
||||
if (curr != null) {
|
||||
boolean selected = (steps[i].equals(currentStep) && !inSummaryPage)
|
||||
|| (inSummaryPage && i == steps.length - 1);
|
||||
boolean selected = (steps2[i].equals(currentStep) && !inSummaryPage)
|
||||
|| (inSummaryPage && i == steps2.length - 1);
|
||||
if (selected)
|
||||
g.setFont(boldFont);
|
||||
|
||||
@@ -297,7 +296,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
|
||||
public final Dimension getPreferredSize() {
|
||||
Font f = getFont() != null ? getFont()
|
||||
: UIManager.getFont("controlFont"); //NOI18N
|
||||
: UIManager.getFont("controlFont");
|
||||
|
||||
Graphics g = getGraphics();
|
||||
if (g == null)
|
||||
@@ -307,25 +306,24 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
Insets ins = getInsets();
|
||||
int h = fm.getHeight();
|
||||
|
||||
String[] steps = wizard.getAllSteps();
|
||||
String[] steps2 = wizard.getAllSteps();
|
||||
int w = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
String desc = i + ". " + (Wizard.UNDETERMINED_STEP.equals(steps[i])
|
||||
for (int i = 0; i < steps2.length; i++) {
|
||||
String desc = i + ". " + (Wizard.UNDETERMINED_STEP.equals(steps2[i])
|
||||
? elipsis
|
||||
: //NOI18N
|
||||
wizard.getStepDescription(steps[i]));
|
||||
: wizard.getStepDescription(steps2[i]));
|
||||
if (desc != null)
|
||||
w = Math.max(w, fm.stringWidth(desc) + MARGIN);
|
||||
}
|
||||
if (Integer.MIN_VALUE == w)
|
||||
w = 250;
|
||||
BufferedImage img = getImage();
|
||||
if (img != null)
|
||||
w = Math.max(w, img.getWidth());
|
||||
BufferedImage image = getImage();
|
||||
if (image != null)
|
||||
w = Math.max(w, image.getWidth());
|
||||
//Make sure we can grow but not shrink
|
||||
w = Math.max(w, historicWidth);
|
||||
historicWidth = w;
|
||||
return new Dimension(w, ins.top + ins.bottom + ((h + 3) * steps.length));
|
||||
return new Dimension(w, ins.top + ins.bottom + ((h + 3) * steps2.length));
|
||||
}
|
||||
|
||||
private boolean inSummaryPage;
|
||||
|
||||
@@ -8,12 +8,11 @@ and include the License file at http://www.netbeans.org/cddl.txt.
|
||||
If applicable, add the following below the CDDL Header, with the fields
|
||||
enclosed by brackets [] replaced by your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]" */
|
||||
/*
|
||||
/*
|
||||
* MergeMap.java
|
||||
*
|
||||
* Created on February 22, 2005, 4:06 PM
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.modules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -28,38 +27,43 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* A map which proxies a collection of sub-maps each of which has a
|
||||
* unique id. Submaps can be added or removed en banc. Values from
|
||||
* removed maps are retained; if push ("someKnownId") happens, the
|
||||
* A map which proxies a collection of sub-maps each of which has a
|
||||
* unique id. Submaps can be added or removed en banc. Values from
|
||||
* removed maps are retained; if push ("someKnownId") happens, the
|
||||
* values previously added to the map while that ID was active reappear.
|
||||
* <p>
|
||||
* This allows us to implement backward/forward semantics for wizards,
|
||||
* in which each pane (identified with a unique ID) can add its own
|
||||
* settings to the settings map, but if the user presses the Back
|
||||
* button, the settings from the formerly active pane can disappear -
|
||||
* settings to the settings map, but if the user presses the Back
|
||||
* button, the settings from the formerly active pane can disappear -
|
||||
* but if the user moves forward again, they are not lost.
|
||||
* <p>
|
||||
* Calling remove("someKeyBelongingToAnEarlierId") will completely
|
||||
* remove that value; calling put ("someKeyBelongingToAnEarlierId", "newValue")
|
||||
* remove that value; calling put ("someKeyBelongingToAnEarlierId", "newValue")
|
||||
* replaces the earler value permanently.
|
||||
* <p>
|
||||
* <b><i><font color="red">This class is NOT AN API CLASS. There is no
|
||||
* <b><i><font color="red">This class is NOT AN API CLASS. There is no
|
||||
* commitment that it will remain backward compatible or even exist in the
|
||||
* future. The API of this library is in the packages <code>org.netbeans.api.wizard</code>
|
||||
* and <code>org.netbeans.spi.wizard</code></font></i></b>.
|
||||
* future. The API of this library is in the packages
|
||||
* <code>org.netbeans.api.wizard</code>
|
||||
* and <code>org.netbeans.spi.wizard</code></font></i></b>.
|
||||
*
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
public class MergeMap implements Map {
|
||||
private Stack order = new Stack();
|
||||
private Map id2map = new HashMap();
|
||||
|
||||
/** Creates a new instance of MergeMap */
|
||||
|
||||
private final Stack order = new Stack();
|
||||
private final Map id2map = new HashMap();
|
||||
|
||||
/**
|
||||
* Creates a new instance of MergeMap
|
||||
*/
|
||||
public MergeMap(String currID) {
|
||||
push (currID);
|
||||
push(currID);
|
||||
}
|
||||
|
||||
private static final String BASE = "__BASE"; //NOI18N
|
||||
|
||||
private static final String BASE = "__BASE";
|
||||
|
||||
/**
|
||||
* Creates a MergeMap with a set of key/value pairs that are
|
||||
* always there (they came from a legacy wizard - used for bridging the
|
||||
@@ -69,69 +73,64 @@ public class MergeMap implements Map {
|
||||
*/
|
||||
public MergeMap(String currId, Map everpresent) {
|
||||
order.push(BASE);
|
||||
id2map.put (BASE, everpresent);
|
||||
push (currId);
|
||||
id2map.put(BASE, everpresent);
|
||||
push(currId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move to a different ID (meaning add a new named map to proxy which can be
|
||||
* calved off if necessary).
|
||||
*/
|
||||
public Map push (String id) {
|
||||
// assert !order.contains(id) : id + " already present"; //NOI18N
|
||||
if (order.contains(id)) {
|
||||
throw new RuntimeException (id + " already present"); //NOI18N
|
||||
}
|
||||
// assert !order.contains(id) : id + " already present"; //NOI18N
|
||||
if (!order.isEmpty() && id.equals(order.peek())) {
|
||||
public Map push(String id) {
|
||||
// assert !order.contains(id) : id + " already present";
|
||||
if (order.contains(id))
|
||||
throw new RuntimeException(id + " already present");
|
||||
// assert !order.contains(id) : id + " already present";
|
||||
if (!order.isEmpty() && id.equals(order.peek()))
|
||||
return (Map) id2map.get(id);
|
||||
}
|
||||
Map result = (Map) id2map.get(id);
|
||||
if (result == null) {
|
||||
result = new HashMap();
|
||||
id2map.put (id, result);
|
||||
id2map.put(id, result);
|
||||
}
|
||||
order.push (id);
|
||||
order.push(id);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the ID of the current sub-map being written into.
|
||||
*/
|
||||
public String currID() {
|
||||
return (String) order.peek();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the current sub-map. Removes all of its settings from the
|
||||
* Remove the current sub-map. Removes all of its settings from the
|
||||
* MergedMap, but if push() is called with the returned value, the
|
||||
* values associated with the ID being removed will be restored.
|
||||
*/
|
||||
public String popAndCalve() {
|
||||
if (order.size() == 0) {
|
||||
throw new NoSuchElementException ("Cannot back out past first " + //NOI18N
|
||||
"entry"); //NOI18N
|
||||
}
|
||||
if (order.isEmpty())
|
||||
throw new NoSuchElementException("Cannot back out past first "
|
||||
+ "entry");
|
||||
//Get the current map
|
||||
String result = (String) order.peek();
|
||||
Map curr = (Map) id2map.get (result);
|
||||
Map curr = (Map) id2map.get(result);
|
||||
order.pop();
|
||||
|
||||
|
||||
//Though unlikely, it is possible that a later step in a wizard
|
||||
//overwrote a key/value pair from a previous step of the wizard.
|
||||
//We do not want to revert that write, so iterate all the keys
|
||||
//we're removing, and if any of them are in steps lower on the
|
||||
//we're removing, and if any of them are in steps lower on the
|
||||
//stack, change those lower steps values to whatever was written
|
||||
//into the map we're calving off
|
||||
|
||||
Set keysForCurr = curr.keySet();
|
||||
for (Iterator i=orderIterator(); i.hasNext();) {
|
||||
for (Iterator i = orderIterator(); i.hasNext();) {
|
||||
Map other = (Map) id2map.get(i.next());
|
||||
for (Iterator j=curr.keySet().iterator(); j.hasNext();) {
|
||||
for (Iterator j = curr.keySet().iterator(); j.hasNext();) {
|
||||
Object key = j.next();
|
||||
if (other.containsKey(key)) {
|
||||
other.put (key, curr.get(key));
|
||||
}
|
||||
if (other.containsKey(key))
|
||||
other.put(key, curr.get(key));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -144,9 +143,8 @@ public class MergeMap implements Map {
|
||||
public boolean containsKey(Object obj) {
|
||||
for (Iterator i = orderIterator(); i.hasNext();) {
|
||||
Map curr = (Map) id2map.get(i.next());
|
||||
if (curr.containsKey(obj)) {
|
||||
if (curr.containsKey(obj))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -154,9 +152,8 @@ public class MergeMap implements Map {
|
||||
public boolean containsValue(Object obj) {
|
||||
for (Iterator i = orderIterator(); i.hasNext();) {
|
||||
Map curr = (Map) id2map.get(i.next());
|
||||
if (curr.containsValue(obj)) {
|
||||
if (curr.containsValue(obj))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -165,7 +162,7 @@ public class MergeMap implements Map {
|
||||
HashSet result = new HashSet();
|
||||
for (Iterator i = orderIterator(); i.hasNext();) {
|
||||
Map curr = (Map) id2map.get(i.next());
|
||||
result.addAll (curr.entrySet());
|
||||
result.addAll(curr.entrySet());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -175,9 +172,8 @@ public class MergeMap implements Map {
|
||||
String id = (String) i.next();
|
||||
Map curr = (Map) id2map.get(id);
|
||||
Object result = curr.get(obj);
|
||||
if (result != null) {
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -190,42 +186,39 @@ public class MergeMap implements Map {
|
||||
HashSet result = new HashSet();
|
||||
for (Iterator i = orderIterator(); i.hasNext();) {
|
||||
Map curr = (Map) id2map.get(i.next());
|
||||
result.addAll (curr.keySet());
|
||||
result.addAll(curr.keySet());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object put(Object obj, Object obj1) {
|
||||
Map curr = (Map) id2map.get (order.peek());
|
||||
return curr.put (obj, obj1);
|
||||
Map curr = (Map) id2map.get(order.peek());
|
||||
return curr.put(obj, obj1);
|
||||
}
|
||||
|
||||
public void putAll(Map map) {
|
||||
Map curr = (Map) id2map.get (order.peek());
|
||||
curr.putAll (map);
|
||||
Map curr = (Map) id2map.get(order.peek());
|
||||
curr.putAll(map);
|
||||
}
|
||||
|
||||
private Object doRemove(Object obj) {
|
||||
Map curr = (Map) id2map.get (order.peek());
|
||||
Object result = curr.remove (obj);
|
||||
if (result == null) {
|
||||
Map curr = (Map) id2map.get(order.peek());
|
||||
Object result = curr.remove(obj);
|
||||
if (result == null)
|
||||
for (Iterator i = orderIterator(); i.hasNext();) {
|
||||
curr = (Map) id2map.get(i.next());
|
||||
result = curr.remove (obj);
|
||||
if (result != null) {
|
||||
result = curr.remove(obj);
|
||||
if (result != null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Object remove(Object obj) {
|
||||
//Ensure we remove any duplicates in upper arrays
|
||||
Object result = get(obj);
|
||||
while (get(obj) != null) {
|
||||
doRemove (obj);
|
||||
}
|
||||
while (get(obj) != null)
|
||||
doRemove(obj);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -237,54 +230,40 @@ public class MergeMap implements Map {
|
||||
public Collection values() {
|
||||
HashSet result = new HashSet();
|
||||
Set keys = keySet();
|
||||
for (Iterator i = keys.iterator(); i.hasNext();) {
|
||||
result.add (get(i.next()));
|
||||
}
|
||||
for (Iterator i = keys.iterator(); i.hasNext();)
|
||||
result.add(get(i.next()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private Iterator orderIterator() {
|
||||
return new ReverseIterator(order);
|
||||
}
|
||||
|
||||
|
||||
private static final class ReverseIterator implements Iterator {
|
||||
|
||||
private int pos;
|
||||
private List l;
|
||||
public ReverseIterator (Stack s) {
|
||||
pos = s.size()-1;
|
||||
private final List l;
|
||||
|
||||
public ReverseIterator(Stack s) {
|
||||
pos = s.size() - 1;
|
||||
l = new ArrayList(s);
|
||||
}
|
||||
|
||||
|
||||
public boolean hasNext() {
|
||||
return pos != -1;
|
||||
}
|
||||
|
||||
|
||||
public Object next() {
|
||||
if (pos < 0) {
|
||||
if (pos < 0)
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
Object result = l.get(pos);
|
||||
pos--;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Iterator i = keySet().iterator(); i.hasNext();) {
|
||||
Object key = (Object) i.next();
|
||||
sb.append ('[');
|
||||
sb.append (key);
|
||||
sb.append('=');
|
||||
sb.append(get(key));
|
||||
sb.append(']');
|
||||
if (i.hasNext()) sb.append (',');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,12 +9,11 @@ If applicable, add the following below the CDDL Header, with the fields
|
||||
enclosed by brackets [] replaced by your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]" */
|
||||
|
||||
/*
|
||||
/*
|
||||
* BranchingWizard.java
|
||||
*
|
||||
* Created on March 4, 2005, 10:56 PM
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.spi;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -25,7 +24,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A Wizard with indeterminate branches. The actual branch decision-making
|
||||
* A Wizard with indeterminate branches. The actual branch decision-making
|
||||
* is done by the WizardBranchController passed to the constructor.
|
||||
* <p/>
|
||||
* Wizards with arbitrary numbers of branches can be handled by a
|
||||
@@ -38,8 +37,9 @@ import java.util.Map;
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
final class BranchingWizard implements WizardImplementation {
|
||||
private final List listenerList = Collections.synchronizedList (
|
||||
new LinkedList());
|
||||
|
||||
private final List listenerList = Collections.synchronizedList(
|
||||
new LinkedList());
|
||||
|
||||
private final WizardBranchController brancher;
|
||||
final WizardImplementation initialSteps;
|
||||
@@ -63,70 +63,63 @@ final class BranchingWizard implements WizardImplementation {
|
||||
}
|
||||
|
||||
private void checkForSecondary() {
|
||||
if (wizardData == null) {
|
||||
if (wizardData == null)
|
||||
return;
|
||||
}
|
||||
|
||||
WizardImplementation newSecondary = createSecondary(wizardData);
|
||||
|
||||
/*
|
||||
/*
|
||||
* johnflournoy 7/20/07
|
||||
* check for secondary should be adding the secondary to the activeWizard
|
||||
* not the initial wizard. Adding it to the initial wizard was breaking
|
||||
* multiple branching - to accomplish this created a new method:
|
||||
* setSecondary()
|
||||
*/
|
||||
if (activeWizard instanceof BranchingWizard) {
|
||||
if (activeWizard instanceof BranchingWizard)
|
||||
((BranchingWizard) activeWizard).setSecondary(newSecondary);
|
||||
} else {
|
||||
this.setSecondary(newSecondary);
|
||||
}
|
||||
else
|
||||
this.setSecondary(newSecondary);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the secondary for this <code>BranchingWizard</code>.
|
||||
* Set the secondary for this <code>BranchingWizard</code>.
|
||||
*
|
||||
* @param newSecondary is a WizardImplementation.
|
||||
*/
|
||||
private void setSecondary(WizardImplementation newSecondary) {
|
||||
/* johnflournoy added additional condition: secondary != this */
|
||||
if ((((subsequentSteps == null) != (newSecondary == null))
|
||||
|| (subsequentSteps != null && !subsequentSteps.equals(newSecondary)))
|
||||
&& !this.equals(newSecondary)) {
|
||||
|
||||
/*
|
||||
* johnflournoy: only set the subsequent steps if it
|
||||
if ((((subsequentSteps == null) != (newSecondary == null))
|
||||
|| (subsequentSteps != null && !subsequentSteps.equals(newSecondary)))
|
||||
&& !this.equals(newSecondary))
|
||||
|
||||
/*
|
||||
* johnflournoy: only set the subsequent steps if it
|
||||
* this wizard owns the current step.
|
||||
*/
|
||||
if (Arrays.asList(initialSteps.getAllSteps()).contains(currStep)) {
|
||||
*/
|
||||
if (Arrays.asList(initialSteps.getAllSteps()).contains(currStep)) {
|
||||
subsequentSteps = newSecondary;
|
||||
fireStepsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getForwardNavigationMode() {
|
||||
return activeWizard.getForwardNavigationMode();
|
||||
}
|
||||
|
||||
private void setCurrent(WizardImplementation wizard) {
|
||||
if (activeWizard == wizard) {
|
||||
if (activeWizard == wizard)
|
||||
return;
|
||||
}
|
||||
|
||||
if (wizard == null) {
|
||||
if (wizard == null)
|
||||
throw new NullPointerException("Can't set current wizard to null");
|
||||
}
|
||||
|
||||
if ((activeWizard != null) && (wl != null)) {
|
||||
if ((activeWizard != null) && (wl != null))
|
||||
activeWizard.removeWizardObserver(wl);
|
||||
}
|
||||
|
||||
activeWizard = wizard;
|
||||
|
||||
if (wl == null) {
|
||||
if (wl == null)
|
||||
wl = new WL();
|
||||
}
|
||||
|
||||
activeWizard.addWizardObserver(wl);
|
||||
}
|
||||
@@ -140,17 +133,15 @@ final class BranchingWizard implements WizardImplementation {
|
||||
Object result = activeWizard.finish(settings);
|
||||
initialSteps.removeWizardObserver(wl);
|
||||
//Can be null, we allow bail-out with finish mid-wizard now
|
||||
if (subsequentSteps != null) {
|
||||
if (subsequentSteps != null)
|
||||
subsequentSteps.removeWizardObserver(wl);
|
||||
}
|
||||
return result;
|
||||
} catch (WizardException we) {
|
||||
if (we.getStepToReturnTo() != null) {
|
||||
initialSteps.addWizardObserver(wl);
|
||||
//Can be null, we allow bail-out with finish mid-wizard now
|
||||
if (subsequentSteps != null) {
|
||||
if (subsequentSteps != null)
|
||||
subsequentSteps.addWizardObserver(wl);
|
||||
}
|
||||
}
|
||||
throw we;
|
||||
}
|
||||
@@ -179,46 +170,40 @@ final class BranchingWizard implements WizardImplementation {
|
||||
|
||||
public final String getNextStep() {
|
||||
String result;
|
||||
if (currStep == null) {
|
||||
if (currStep == null)
|
||||
result = getAllSteps()[0];
|
||||
} else {
|
||||
else {
|
||||
String[] steps = getAllSteps();
|
||||
int idx = Arrays.asList(steps).indexOf(currStep);
|
||||
if (idx == -1) {
|
||||
throw new IllegalStateException("Current step not in" + //NOI18N
|
||||
" available steps: " + currStep + " not in " + //NOI18N
|
||||
Arrays.asList(steps));
|
||||
} else {
|
||||
if (idx == steps.length - 1) {
|
||||
if (subsequentSteps == null) {
|
||||
if (idx == -1)
|
||||
throw new IllegalStateException("Current step not in"
|
||||
+ " available steps: " + currStep + " not in "
|
||||
+ Arrays.asList(steps));
|
||||
else if (idx == steps.length - 1)
|
||||
if (subsequentSteps == null)
|
||||
result = UNDETERMINED_STEP;
|
||||
else
|
||||
result = subsequentSteps.getNextStep();
|
||||
else {
|
||||
WizardImplementation w = ownerOf(currStep);
|
||||
if (w == initialSteps && idx == initialSteps.getAllSteps().length - 1) {
|
||||
checkForSecondary();
|
||||
if (subsequentSteps != null)
|
||||
result = subsequentSteps.getAllSteps()[0];
|
||||
else
|
||||
result = UNDETERMINED_STEP;
|
||||
} else {
|
||||
result = subsequentSteps.getNextStep();
|
||||
}
|
||||
} else {
|
||||
WizardImplementation w = ownerOf(currStep);
|
||||
if (w == initialSteps && idx == initialSteps.getAllSteps().length - 1) {
|
||||
checkForSecondary();
|
||||
if (subsequentSteps != null) {
|
||||
result = subsequentSteps.getAllSteps()[0];
|
||||
} else {
|
||||
result = UNDETERMINED_STEP;
|
||||
}
|
||||
} else {
|
||||
result = w.getNextStep();
|
||||
}
|
||||
}
|
||||
} else
|
||||
result = w.getNextStep();
|
||||
}
|
||||
}
|
||||
return getProblem() == null ? result : UNDETERMINED_STEP.equals(result) ? result : null;
|
||||
}
|
||||
|
||||
public final String getPreviousStep() {
|
||||
if (activeWizard == subsequentSteps && subsequentSteps.getAllSteps()[0].equals(currStep)) {
|
||||
if (activeWizard == subsequentSteps && subsequentSteps.getAllSteps()[0].equals(currStep))
|
||||
return initialSteps.getAllSteps()[initialSteps.getAllSteps().length - 1];
|
||||
} else {
|
||||
else
|
||||
return activeWizard.getPreviousStep();
|
||||
}
|
||||
}
|
||||
|
||||
public final String getProblem() {
|
||||
@@ -227,17 +212,15 @@ final class BranchingWizard implements WizardImplementation {
|
||||
|
||||
public final String getStepDescription(String id) {
|
||||
WizardImplementation w = ownerOf(id);
|
||||
if (w == null) {
|
||||
if (w == null)
|
||||
return null;
|
||||
}
|
||||
return w.getStepDescription(id);
|
||||
}
|
||||
|
||||
|
||||
public final String getLongDescription(String id) {
|
||||
WizardImplementation w = ownerOf(id);
|
||||
if (w == null) {
|
||||
if (w == null)
|
||||
return null;
|
||||
}
|
||||
return w.getLongDescription(id);
|
||||
}
|
||||
|
||||
@@ -246,24 +229,22 @@ final class BranchingWizard implements WizardImplementation {
|
||||
checkForSecondary();
|
||||
return subsequentSteps;
|
||||
}
|
||||
if (Arrays.asList(initialSteps.getAllSteps()).contains(id)) {
|
||||
if (Arrays.asList(initialSteps.getAllSteps()).contains(id))
|
||||
return initialSteps;
|
||||
} else {
|
||||
else {
|
||||
/*
|
||||
* johnflournoy
|
||||
* johnflournoy
|
||||
* need to check an existing subsequentsteps to see if
|
||||
* we can find the owner of "id", otherwise we were losing
|
||||
* a wizard if we had multiple branches and we backed up to an
|
||||
* a wizard if we had multiple branches and we backed up to an
|
||||
* earlier wizard and then went down the same path again.
|
||||
*/
|
||||
if (subsequentSteps != null) {
|
||||
if (!Arrays.asList(subsequentSteps.getAllSteps()).contains(id)) {
|
||||
if (!Arrays.asList(subsequentSteps.getAllSteps()).contains(id))
|
||||
checkForSecondary();
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
checkForSecondary();
|
||||
}
|
||||
|
||||
|
||||
return subsequentSteps;
|
||||
}
|
||||
}
|
||||
@@ -273,35 +254,32 @@ final class BranchingWizard implements WizardImplementation {
|
||||
}
|
||||
|
||||
public final JComponent navigatingTo(String id, Map settings) {
|
||||
if (id == null) {
|
||||
if (id == null)
|
||||
throw new NullPointerException();
|
||||
}
|
||||
currStep = id;
|
||||
wizardData = settings;
|
||||
|
||||
WizardImplementation impl = ownerOf (id);
|
||||
if (impl == null) {
|
||||
throw new NullPointerException ("No owning WizardImplementation for" +
|
||||
" id " + id);
|
||||
}
|
||||
WizardImplementation impl = ownerOf(id);
|
||||
if (impl == null)
|
||||
throw new NullPointerException("No owning WizardImplementation for"
|
||||
+ " id " + id);
|
||||
setCurrent(impl);
|
||||
|
||||
return activeWizard.navigatingTo(id, settings);
|
||||
}
|
||||
|
||||
public final void removeWizardObserver (WizardObserver observer) {
|
||||
public final void removeWizardObserver(WizardObserver observer) {
|
||||
listenerList.remove(observer);
|
||||
}
|
||||
|
||||
public final void addWizardObserver (WizardObserver observer) {
|
||||
public final void addWizardObserver(WizardObserver observer) {
|
||||
listenerList.add(observer);
|
||||
}
|
||||
|
||||
private void fireStepsChanged() {
|
||||
WizardObserver[] listeners = (WizardObserver[])
|
||||
listenerList.toArray (new WizardObserver[0]);
|
||||
WizardObserver[] listeners = (WizardObserver[]) listenerList.toArray(new WizardObserver[0]);
|
||||
|
||||
for (int i = listeners.length - 1; i >= 0; i --) {
|
||||
for (int i = listeners.length - 1; i >= 0; i--) {
|
||||
WizardObserver l = (WizardObserver) listeners[i];
|
||||
l.stepsChanged(null);
|
||||
}
|
||||
@@ -310,20 +288,18 @@ final class BranchingWizard implements WizardImplementation {
|
||||
private void fireNavigabilityChanged() {
|
||||
checkForSecondary();
|
||||
|
||||
WizardObserver[] listeners = (WizardObserver[])
|
||||
listenerList.toArray (new WizardObserver[0]);
|
||||
WizardObserver[] listeners = (WizardObserver[]) listenerList.toArray(new WizardObserver[0]);
|
||||
|
||||
for (int i = listeners.length - 1; i >= 0; i --) {
|
||||
for (int i = listeners.length - 1; i >= 0; i--) {
|
||||
WizardObserver l = (WizardObserver) listeners[i];
|
||||
l.navigabilityChanged(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void fireSelectionChanged() {
|
||||
WizardObserver[] listeners = (WizardObserver[])
|
||||
listenerList.toArray (new WizardObserver[0]);
|
||||
WizardObserver[] listeners = (WizardObserver[]) listenerList.toArray(new WizardObserver[0]);
|
||||
|
||||
for (int i = listeners.length - 1; i >= 0; i --) {
|
||||
for (int i = listeners.length - 1; i >= 0; i--) {
|
||||
WizardObserver l = (WizardObserver) listeners[i];
|
||||
l.selectionChanged(null);
|
||||
}
|
||||
@@ -334,6 +310,7 @@ final class BranchingWizard implements WizardImplementation {
|
||||
}
|
||||
|
||||
private class WL implements WizardObserver {
|
||||
|
||||
public void stepsChanged(Wizard wizard) {
|
||||
fireStepsChanged();
|
||||
}
|
||||
|
||||
@@ -9,12 +9,11 @@ If applicable, add the following below the CDDL Header, with the fields
|
||||
enclosed by brackets [] replaced by your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]" */
|
||||
|
||||
/*
|
||||
/*
|
||||
* GenericListener.java
|
||||
*
|
||||
* Created on October 5, 2004, 12:36 AM
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.spi;
|
||||
|
||||
import java.awt.Component;
|
||||
@@ -30,8 +29,6 @@ import java.util.EventObject;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import javax.swing.tree.*;
|
||||
@@ -56,17 +53,15 @@ import javax.swing.tree.TreeSelectionModel;
|
||||
* validate its contents.
|
||||
*
|
||||
* If you use subclasses of the swing components, you will also need to subclass
|
||||
* this listener and override at least the methods isProbablyContainer, attachTo and detachFrom.
|
||||
* this listener and override at least the methods isProbablyContainer, attachTo
|
||||
* and detachFrom.
|
||||
*
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
final class GenericListener
|
||||
implements ActionListener, PropertyChangeListener, ItemListener,
|
||||
ContainerListener, DocumentListener, ChangeListener,
|
||||
ListSelectionListener, TreeSelectionListener, TableModelListener {
|
||||
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(GenericListener.class.getName());
|
||||
implements ActionListener, PropertyChangeListener, ItemListener,
|
||||
ContainerListener, DocumentListener, ChangeListener,
|
||||
ListSelectionListener, TreeSelectionListener, TableModelListener {
|
||||
|
||||
private final WizardPage wizardPage;
|
||||
|
||||
@@ -76,218 +71,191 @@ final class GenericListener
|
||||
* Set of components that we're listening to models of, so we can look
|
||||
* up the component from the model as needed
|
||||
*/
|
||||
private Set listenedTo = new HashSet();
|
||||
private final Set listenedTo = new HashSet();
|
||||
|
||||
private final WizardPage.CustomComponentListener extListener;
|
||||
private final WizardPage.CustomComponentNotifier extNotifier;
|
||||
|
||||
public GenericListener(WizardPage wizardPage, WizardPage.CustomComponentListener l,
|
||||
WizardPage.CustomComponentNotifier n) {
|
||||
WizardPage.CustomComponentNotifier n) {
|
||||
this.extListener = l;
|
||||
this.extNotifier = n;
|
||||
if ((extListener == null) != (extNotifier == null)) {
|
||||
if ((extListener == null) != (extNotifier == null))
|
||||
throw new RuntimeException();
|
||||
}
|
||||
// assert wizardPage != null : "WizardPage may not be null"; // NOI18N
|
||||
if (wizardPage == null) {
|
||||
throw new IllegalArgumentException("WizardPage may not be null"); // NOI18N)
|
||||
}
|
||||
// assert wizardPage != null : "WizardPage may not be null";
|
||||
if (wizardPage == null)
|
||||
throw new IllegalArgumentException("WizardPage may not be null");
|
||||
this.wizardPage = wizardPage;
|
||||
wizardPage.addContainerListener(this);
|
||||
}
|
||||
|
||||
public GenericListener (WizardPage page) {
|
||||
this (page, null, null);
|
||||
|
||||
public GenericListener(WizardPage page) {
|
||||
this(page, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the given component is likely to be a container such the each
|
||||
* Return true if the given component is likely to be a container such the
|
||||
* each
|
||||
* component within the container should be be considered as a user input.
|
||||
*
|
||||
*
|
||||
* @param c
|
||||
*
|
||||
* @return true if the component children should have this listener added.
|
||||
*/
|
||||
protected boolean isProbablyAContainer (Component c) {
|
||||
protected boolean isProbablyAContainer(Component c) {
|
||||
boolean result = extListener != null ? extListener.isContainer(c) : false;
|
||||
if (!result) {
|
||||
boolean isSwing = isSwingClass(c);
|
||||
if (isSwing) {
|
||||
result = c instanceof JPanel || c instanceof JSplitPane || c instanceof
|
||||
JToolBar || c instanceof JViewport || c instanceof JScrollPane ||
|
||||
c instanceof JFrame || c instanceof JRootPane || c instanceof
|
||||
Window || c instanceof Frame || c instanceof Dialog ||
|
||||
c instanceof JTabbedPane || c instanceof JInternalFrame ||
|
||||
c instanceof JDesktopPane || c instanceof JLayeredPane ||
|
||||
c instanceof Box;
|
||||
} else {
|
||||
if (isSwing)
|
||||
result = c instanceof JPanel || c instanceof JSplitPane || c instanceof JToolBar || c instanceof JViewport || c instanceof JScrollPane
|
||||
|| c instanceof JFrame || c instanceof JRootPane || c instanceof Window || c instanceof Frame || c instanceof Dialog
|
||||
|| c instanceof JTabbedPane || c instanceof JInternalFrame
|
||||
|| c instanceof JDesktopPane || c instanceof JLayeredPane
|
||||
|| c instanceof Box;
|
||||
else
|
||||
result = c instanceof Container;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if the given component is likely to be a swing primitive or a subclass.
|
||||
* The default implmentation here just checks for the package of the component to be "javax.swing"
|
||||
* If you use subclasses of swing components, you will need to override this method
|
||||
* Return true if the given component is likely to be a swing primitive or a
|
||||
* subclass.
|
||||
* The default implmentation here just checks for the package of the
|
||||
* component to be "javax.swing"
|
||||
* If you use subclasses of swing components, you will need to override this
|
||||
* method
|
||||
* to get proper behavior.
|
||||
*
|
||||
* @param c
|
||||
* @return true if the component should be examined more closely (see isProbablyAContainer)
|
||||
*
|
||||
* @return true if the component should be examined more closely (see
|
||||
* isProbablyAContainer)
|
||||
*/
|
||||
protected boolean isSwingClass (Component c)
|
||||
{
|
||||
protected boolean isSwingClass(Component c) {
|
||||
String packageName = c.getClass().getPackage().getName();
|
||||
boolean swing = packageName.equals ("javax.swing"); //NOI18N
|
||||
boolean swing = packageName.equals("javax.swing");
|
||||
return swing;
|
||||
}
|
||||
|
||||
protected void attachTo(Component jc) {
|
||||
if (extListener != null && extListener.accept (jc)) {
|
||||
if (extListener != null && extListener.accept(jc)) {
|
||||
extListener.startListeningTo(jc, extNotifier);
|
||||
listenedTo.add (jc);
|
||||
if (wizardPage.getMapKeyFor(jc) != null) {
|
||||
listenedTo.add(jc);
|
||||
if (wizardPage.getMapKeyFor(jc) != null)
|
||||
wizardPage.maybeUpdateMap(jc);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (isProbablyAContainer(jc)) {
|
||||
if (isProbablyAContainer(jc))
|
||||
attachToHierarchyOf((Container) jc);
|
||||
} else if (jc instanceof JList) {
|
||||
else if (jc instanceof JList) {
|
||||
listenedTo.add(jc);
|
||||
((JList) jc).addListSelectionListener(this);
|
||||
} else if (jc instanceof JComboBox) {
|
||||
} else if (jc instanceof JComboBox)
|
||||
((JComboBox) jc).addActionListener(this);
|
||||
} else if (jc instanceof JTree) {
|
||||
else if (jc instanceof JTree) {
|
||||
listenedTo.add(jc);
|
||||
((JTree) jc).getSelectionModel().addTreeSelectionListener(this);
|
||||
} else if (jc instanceof JToggleButton) {
|
||||
} else if (jc instanceof JToggleButton)
|
||||
((AbstractButton) jc).addItemListener(this);
|
||||
} else if (jc instanceof JFormattedTextField) { //JFormattedTextField must be tested before JTextCompoent
|
||||
else if (jc instanceof JFormattedTextField) //JFormattedTextField must be tested before JTextCompoent
|
||||
jc.addPropertyChangeListener("value", this);
|
||||
} else if (jc instanceof JTextComponent) {
|
||||
else if (jc instanceof JTextComponent) {
|
||||
listenedTo.add(jc);
|
||||
((JTextComponent) jc).getDocument().addDocumentListener(this);
|
||||
} else if (jc instanceof JColorChooser) {
|
||||
listenedTo.add(jc);
|
||||
((JColorChooser) jc).getSelectionModel().addChangeListener(this);
|
||||
} else if (jc instanceof JSpinner) {
|
||||
} else if (jc instanceof JSpinner)
|
||||
((JSpinner) jc).addChangeListener(this);
|
||||
} else if (jc instanceof JSlider) {
|
||||
else if (jc instanceof JSlider)
|
||||
((JSlider) jc).addChangeListener(this);
|
||||
} else if (jc instanceof JTable) {
|
||||
else if (jc instanceof JTable) {
|
||||
listenedTo.add(jc);
|
||||
((JTable) jc).getSelectionModel().addListSelectionListener(this);
|
||||
} else {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Don't know how to listen to a " + // NOI18N
|
||||
jc.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (accept(jc) && !(jc instanceof JPanel)) {
|
||||
jc.addPropertyChangeListener("name", this);
|
||||
if (wizardPage.getMapKeyFor(jc) != null) {
|
||||
if (wizardPage.getMapKeyFor(jc) != null)
|
||||
wizardPage.maybeUpdateMap(jc);
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isLoggable(Level.FINE) && accept(jc)) {
|
||||
logger.fine("Begin listening to " + jc); // NOI18N
|
||||
}
|
||||
}
|
||||
|
||||
protected void detachFrom(Component jc) {
|
||||
listenedTo.remove(jc);
|
||||
if (extListener != null && extListener.accept (jc)) {
|
||||
if (extListener != null && extListener.accept(jc))
|
||||
extListener.stopListeningTo(jc);
|
||||
}
|
||||
if (isProbablyAContainer(jc)) {
|
||||
if (isProbablyAContainer(jc))
|
||||
detachFromHierarchyOf((Container) jc);
|
||||
} else if (jc instanceof JList) {
|
||||
else if (jc instanceof JList)
|
||||
((JList) jc).removeListSelectionListener(this);
|
||||
} else if (jc instanceof JComboBox) {
|
||||
else if (jc instanceof JComboBox)
|
||||
((JComboBox) jc).removeActionListener(this);
|
||||
} else if (jc instanceof JTree) {
|
||||
else if (jc instanceof JTree)
|
||||
((JTree) jc).getSelectionModel().removeTreeSelectionListener(this);
|
||||
} else if (jc instanceof JToggleButton) {
|
||||
else if (jc instanceof JToggleButton)
|
||||
((AbstractButton) jc).removeActionListener(this);
|
||||
} else if (jc instanceof JTextComponent) {
|
||||
else if (jc instanceof JTextComponent) {
|
||||
} else if (jc instanceof JFormattedTextField) { //JFormattedTextField must be tested before JTextCompoent
|
||||
jc.removePropertyChangeListener("value", this);
|
||||
((JTextComponent) jc).getDocument().removeDocumentListener(this);
|
||||
} else if (jc instanceof JColorChooser) {
|
||||
} else if (jc instanceof JColorChooser)
|
||||
((JColorChooser) jc).getSelectionModel().removeChangeListener(this);
|
||||
} else if (jc instanceof JSpinner) {
|
||||
else if (jc instanceof JSpinner)
|
||||
((JSpinner) jc).removeChangeListener(this);
|
||||
} else if (jc instanceof JSlider) {
|
||||
else if (jc instanceof JSlider)
|
||||
((JSlider) jc).removeChangeListener(this);
|
||||
} else if (jc instanceof JTable) {
|
||||
else if (jc instanceof JTable)
|
||||
((JTable) jc).getSelectionModel().removeListSelectionListener(this);
|
||||
}
|
||||
|
||||
if (accept(jc) && !(jc instanceof JPanel)) {
|
||||
jc.removePropertyChangeListener("name", this);
|
||||
Object key = wizardPage.getMapKeyFor(jc);
|
||||
|
||||
if (key != null) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Named component removed from hierarchy: " + // NOI18N
|
||||
key + ". Removing any corresponding " + // NOI18N
|
||||
"value from the wizard settings map."); // NOI18N
|
||||
}
|
||||
|
||||
if (key != null)
|
||||
wizardPage.removeFromMap(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isLoggable(Level.FINE) && accept(jc)) {
|
||||
logger.fine("Stop listening to " + jc); // NOI18N
|
||||
}
|
||||
}
|
||||
|
||||
private void detachFromHierarchyOf(Container container) {
|
||||
container.removeContainerListener(this);
|
||||
Component[] components = container.getComponents();
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
detachFrom(components[i]); // Will callback recursively any nested JPanels
|
||||
}
|
||||
for (Component component : components)
|
||||
detachFrom(component); // Will callback recursively any nested JPanels
|
||||
}
|
||||
|
||||
void attachToHierarchyOf(Container container) {
|
||||
if (!Arrays.asList (container.getContainerListeners()).contains(this)) {
|
||||
if (!Arrays.asList(container.getContainerListeners()).contains(this))
|
||||
container.addContainerListener(this);
|
||||
}
|
||||
Component[] components = container.getComponents();
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
attachTo(components[i]); // Will recursively add any child components in
|
||||
}
|
||||
for (Component component : components)
|
||||
attachTo(component); // Will recursively add any child components in
|
||||
}
|
||||
|
||||
protected boolean accept(Component jc) {
|
||||
if (extListener != null && extListener.accept(jc)) {
|
||||
if (extListener != null && extListener.accept(jc))
|
||||
return true;
|
||||
}
|
||||
if (!(jc instanceof JComponent)) {
|
||||
if (!(jc instanceof JComponent))
|
||||
return false;
|
||||
}
|
||||
if (jc instanceof TableCellEditor || jc instanceof TreeCellEditor ||
|
||||
SwingUtilities.getAncestorOfClass(JTable.class, jc) != null ||
|
||||
SwingUtilities.getAncestorOfClass(JTree.class, jc) != null ||
|
||||
SwingUtilities.getAncestorOfClass(JList.class, jc) != null){
|
||||
if (jc instanceof TableCellEditor || jc instanceof TreeCellEditor
|
||||
|| SwingUtilities.getAncestorOfClass(JTable.class, jc) != null
|
||||
|| SwingUtilities.getAncestorOfClass(JTree.class, jc) != null
|
||||
|| SwingUtilities.getAncestorOfClass(JList.class, jc) != null)
|
||||
//Don't listen to cell editors, we can end up listening to them
|
||||
//multiple times, and the tree/table model will give us the event
|
||||
//we need
|
||||
return false;
|
||||
}
|
||||
return isProbablyAContainer (jc) ||
|
||||
jc instanceof JList ||
|
||||
jc instanceof JComboBox ||
|
||||
jc instanceof JTree ||
|
||||
jc instanceof JToggleButton || //covers toggle, radio, checkbox
|
||||
jc instanceof JTextComponent ||
|
||||
jc instanceof JColorChooser ||
|
||||
jc instanceof JSpinner ||
|
||||
jc instanceof JSlider;
|
||||
return isProbablyAContainer(jc)
|
||||
|| jc instanceof JList
|
||||
|| jc instanceof JComboBox
|
||||
|| jc instanceof JTree
|
||||
|| jc instanceof JToggleButton
|
||||
|| //covers toggle, radio, checkbox
|
||||
jc instanceof JTextComponent
|
||||
|| jc instanceof JColorChooser
|
||||
|| jc instanceof JSpinner
|
||||
|| jc instanceof JSlider;
|
||||
}
|
||||
|
||||
void setIgnoreEvents(boolean val) {
|
||||
@@ -299,59 +267,40 @@ final class GenericListener
|
||||
setIgnoreEvents(true);
|
||||
try {
|
||||
//XXX this could be prettier...
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Event received: " + e); // NOI18N
|
||||
}
|
||||
if (e instanceof EventObject && ((EventObject) e).getSource() instanceof Component) {
|
||||
if (e instanceof EventObject && ((EventObject) e).getSource() instanceof Component)
|
||||
wizardPage.userInputReceived((Component) ((EventObject) e).getSource(), e);
|
||||
} else if (e instanceof TreeSelectionEvent) {
|
||||
logger.fine("Looking for a tree for a tree selection event"); // NOI18N
|
||||
else if (e instanceof TreeSelectionEvent) {
|
||||
TreeSelectionModel mdl = (TreeSelectionModel) ((TreeSelectionEvent) e).getSource();
|
||||
for (Iterator i = listenedTo.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (o instanceof JTree && ((JTree) o).getSelectionModel() == mdl) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(" found it: " + o); // NOI18N
|
||||
}
|
||||
wizardPage.userInputReceived((Component) o, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (e instanceof DocumentEvent) {
|
||||
logger.fine("Looking for a JTextComponent for a DocumentEvent"); // NOI18N
|
||||
Document document = ((DocumentEvent) e).getDocument();
|
||||
for (Iterator i = listenedTo.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (o instanceof JTextComponent && ((JTextComponent) o).getDocument() == document) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(" found it: " + o); // NOI18N
|
||||
}
|
||||
wizardPage.userInputReceived((Component) o, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (e instanceof ListSelectionEvent) {
|
||||
logger.fine("Looking for a JList or JTable for a ListSelectionEvent"); // NOI18N
|
||||
ListSelectionModel model = (ListSelectionModel) ((ListSelectionEvent) e).getSource();
|
||||
for (Iterator i = listenedTo.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (o instanceof JList && ((JList) o).getSelectionModel() == model) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(" found it: " + o); // NOI18N
|
||||
}
|
||||
wizardPage.userInputReceived((Component) o, e);
|
||||
break;
|
||||
} else if (o instanceof JTable && ((JTable) o).getSelectionModel() == model) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(" found it: " + o); // NOI18N
|
||||
}
|
||||
wizardPage.userInputReceived((Component) o, e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
wizardPage.userInputReceived(null, e);
|
||||
}
|
||||
} finally {
|
||||
setIgnoreEvents(false);
|
||||
}
|
||||
@@ -366,19 +315,8 @@ final class GenericListener
|
||||
if (e.getSource() instanceof JComponent && "name".equals(e.getPropertyName())) {
|
||||
// Note - most components do NOT fire a property change on
|
||||
// setName(), but it is possible for this to be done intentionally
|
||||
if (e.getOldValue() instanceof String) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Name of component changed from " + e.getOldValue() + // NOI18N
|
||||
" to " + e.getNewValue() + ". Removing any values for " + // NOI18N
|
||||
e.getOldValue() + " from the wizard data map"); // NOI18N
|
||||
}
|
||||
if (e.getOldValue() instanceof String)
|
||||
wizardPage.removeFromMap(e.getOldValue());
|
||||
}
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Possibly update map for renamed component " + // NOI18N
|
||||
e.getSource());
|
||||
}
|
||||
|
||||
} else if (e.getSource() instanceof JFormattedTextField && "value".equals(e.getPropertyName())) {
|
||||
fire(e);
|
||||
@@ -395,18 +333,16 @@ final class GenericListener
|
||||
// extListener.startListeningTo(e.getChild(), extNotifier);
|
||||
// listenedTo.add (e.getChild());
|
||||
// } else if (accept(e.getChild())) {
|
||||
if (accept (e.getChild())) {
|
||||
if (accept(e.getChild()))
|
||||
attachTo(e.getChild());
|
||||
}
|
||||
}
|
||||
|
||||
public void componentRemoved(ContainerEvent e) {
|
||||
if (extListener != null && extListener.accept (e.getChild())) {
|
||||
extListener.stopListeningTo (e.getChild());
|
||||
listenedTo.remove (e.getChild());
|
||||
} else if (accept(e.getChild())) {
|
||||
if (extListener != null && extListener.accept(e.getChild())) {
|
||||
extListener.stopListeningTo(e.getChild());
|
||||
listenedTo.remove(e.getChild());
|
||||
} else if (accept(e.getChild()))
|
||||
detachFrom(e.getChild());
|
||||
}
|
||||
}
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
|
||||
@@ -172,11 +172,8 @@ final class SimpleWizardInfo implements WizardControllerImplementation {
|
||||
}
|
||||
|
||||
private int index() {
|
||||
SimpleWizard wizard = getWizard();
|
||||
if (wizard != null)
|
||||
return wizard.currentStepIndex();
|
||||
else
|
||||
return 0;
|
||||
SimpleWizard a = getWizard();
|
||||
return a == null ? 0 : a.currentStepIndex();
|
||||
}
|
||||
|
||||
public final void setBusy(boolean value) {
|
||||
@@ -281,11 +278,9 @@ final class SimpleWizardInfo implements WizardControllerImplementation {
|
||||
|
||||
// lookup the step by name
|
||||
boolean containsStep(String name) {
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
String step = steps[i];
|
||||
for (String step : steps)
|
||||
if (name.equals(step))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -308,7 +303,7 @@ final class SimpleWizardInfo implements WizardControllerImplementation {
|
||||
|
||||
return Arrays.equals(info.descriptions, descriptions)
|
||||
&& Arrays.equals(info.steps, steps)
|
||||
&& info.title == title;
|
||||
&& (info.title == null ? title == null : info.title.equals(title));
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
@@ -323,9 +318,4 @@ final class SimpleWizardInfo implements WizardControllerImplementation {
|
||||
boolean cancel(Map settings) {
|
||||
return provider.cancel(settings);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "SimpleWizardInfo@" + System.identityHashCode(this) + " for "
|
||||
+ provider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ and include the License file at http://www.netbeans.org/cddl.txt.
|
||||
If applicable, add the following below the CDDL Header, with the fields
|
||||
enclosed by brackets [] replaced by your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]" */
|
||||
/*
|
||||
/*
|
||||
* Summary.java
|
||||
*
|
||||
* Created on September 24, 2006, 4:05 AM
|
||||
@@ -16,7 +16,6 @@ enclosed by brackets [] replaced by your own identifying information:
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.spi;
|
||||
|
||||
import java.awt.Component;
|
||||
@@ -27,122 +26,114 @@ import javax.swing.JTextArea;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
/**
|
||||
* Object which may be returned from <code>WizardPage.WizardResultProducer.finish()</code>
|
||||
* or <code>WizardPanelProvider.finish()</code>, or passed to
|
||||
* <code>DeferredWizardResult.ResultProgressHandle.finish()</code>. If an
|
||||
* instance of <code>Summary</code> is used, then the UI should, rather
|
||||
* than disappearing, show the component provided by the <code>Summary</code>
|
||||
* object. Convenience constructors are provided for plain text and list style
|
||||
* Object which may be returned from
|
||||
* <code>WizardPage.WizardResultProducer.finish()</code>
|
||||
* or <code>WizardPanelProvider.finish()</code>, or passed to
|
||||
* <code>DeferredWizardResult.ResultProgressHandle.finish()</code>. If an
|
||||
* instance of <code>Summary</code> is used, then the UI should, rather
|
||||
* than disappearing, show the component provided by the <code>Summary</code>
|
||||
* object. Convenience constructors are provided for plain text and list style
|
||||
* views.
|
||||
*
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
public class Summary {
|
||||
|
||||
private final Component comp;
|
||||
private Object result;
|
||||
|
||||
//constructors package private - only unit tests should be able to subclass
|
||||
//Summary
|
||||
|
||||
Summary(String text, Object result) {
|
||||
|
||||
/**
|
||||
* Create a <code>Summary</code> object which will display the
|
||||
* passed <code>String</code> in a text component of some sort.
|
||||
*
|
||||
* @param text The text to display - must be non-null, greater than zero
|
||||
* length and not completely whitespace
|
||||
* @param result The result that should be returned when the Wizard is
|
||||
* closed
|
||||
*
|
||||
* @return the requested <code>Summary</code> object
|
||||
*/
|
||||
public Summary(String text, Object result) {
|
||||
//XXX this is creating components off the AWT thread - needs to change
|
||||
//to use invokeAndWait where appropriate
|
||||
if (text == null) {
|
||||
throw new NullPointerException ("Text is null"); //NOI18N
|
||||
}
|
||||
if (text.trim().length() == 0) {
|
||||
throw new IllegalArgumentException ("Text is empty or all " + //NOI18N
|
||||
"whitespace"); //NOI18N
|
||||
}
|
||||
if (text == null)
|
||||
throw new NullPointerException("Text is null");
|
||||
if (text.trim().length() == 0)
|
||||
throw new IllegalArgumentException("Text is empty or all whitespace");
|
||||
this.result = result;
|
||||
JTextArea jta = new JTextArea();
|
||||
jta.setText (text);
|
||||
jta.setText(text);
|
||||
jta.setWrapStyleWord(true);
|
||||
jta.setLineWrap(true);
|
||||
jta.getCaret().setBlinkRate(0);
|
||||
jta.setEditable(false);
|
||||
jta.getCaret().setVisible(true);
|
||||
Font f = UIManager.getFont ("Label.font");
|
||||
if (f != null) { //may be on old GTK L&F, etc.
|
||||
jta.setFont (f);
|
||||
}
|
||||
comp = new JScrollPane (jta);
|
||||
Font f = UIManager.getFont("Label.font");
|
||||
if (f != null) //may be on old GTK L&F, etc.
|
||||
jta.setFont(f);
|
||||
comp = new JScrollPane(jta);
|
||||
}
|
||||
|
||||
Summary(String[] items, Object result) {
|
||||
if (items == null) {
|
||||
throw new NullPointerException ("Items array null"); //NOI18N
|
||||
}
|
||||
if (items.length == 0) {
|
||||
throw new IllegalArgumentException ("Items array empty"); //NOI18N
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Summary</code> object that will display the passed
|
||||
* <code>String</code>s in a <code>JList</code> or similar.
|
||||
*
|
||||
* @param items A non-null list of one or more Strings to be displayed
|
||||
* @param result The result that should be returned when the Wizard is
|
||||
* closed
|
||||
*
|
||||
* @return the requested <code>Summary</code> object
|
||||
*/
|
||||
public Summary(String[] items, Object result) {
|
||||
if (items == null)
|
||||
throw new NullPointerException("Items array null");
|
||||
if (items.length == 0)
|
||||
throw new IllegalArgumentException("Items array empty");
|
||||
this.result = result;
|
||||
JList list = new JList(items);
|
||||
comp = new JScrollPane (list);
|
||||
comp = new JScrollPane(list);
|
||||
}
|
||||
|
||||
Summary(Component comp, Object result) {
|
||||
|
||||
/**
|
||||
* Create a <code>Summary</code> object that will display the passed
|
||||
* component.
|
||||
*
|
||||
* @param comp A custom component to show on the summary page after the
|
||||
* Wizard has been completed
|
||||
* @param result The result that should be returned when the
|
||||
* <code>Wizard</code> is
|
||||
* closed
|
||||
*
|
||||
* @return the requested <code>Summary</code> object
|
||||
*/
|
||||
public Summary(Component comp, Object result) {
|
||||
this.result = result;
|
||||
this.comp = comp;
|
||||
if (comp == null) {
|
||||
throw new NullPointerException ("Null component"); //NOI18N
|
||||
}
|
||||
if (comp == null)
|
||||
throw new NullPointerException("Null component");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Summary</code> object that will display the passed
|
||||
* <code>String</code>s in a <code>JList</code> or similar.
|
||||
* @param items A non-null list of one or more Strings to be displayed
|
||||
* @param result The result that should be returned when the Wizard is
|
||||
* closed
|
||||
* @return the requested <code>Summary</code> object
|
||||
*/
|
||||
public static Summary create (String[] items, Object result) {
|
||||
return new Summary (items, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Summary</code> object that will display the passed component.
|
||||
* @param comp A custom component to show on the summary page after the
|
||||
* Wizard has been completed
|
||||
* @param result The result that should be returned when the <code>Wizard</code> is
|
||||
* closed
|
||||
* @return the requested <code>Summary</code> object
|
||||
*/
|
||||
public static Summary create (Component comp, Object result) {
|
||||
return new Summary (comp, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Summary</code> object which will display the
|
||||
* passed <code>String</code> in a text component of some sort.
|
||||
* @param text The text to display - must be non-null, greater than zero
|
||||
* length and not completely whitespace
|
||||
* @param result The result that should be returned when the Wizard is
|
||||
* closed
|
||||
* @return the requested <code>Summary</code> object
|
||||
*/
|
||||
public static Summary create (String text, Object result) {
|
||||
return new Summary (text, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the component that will display the summary information.
|
||||
*
|
||||
* @return an appropriate component, the type of which may differ depending
|
||||
* on the factory method used to create this component
|
||||
*/
|
||||
* on the factory method used to create this component
|
||||
*/
|
||||
public Component getSummaryComponent() {
|
||||
return comp;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the object that represents the actual result of whatever the <code>Wizard</code>
|
||||
* that created this <code>Summary</code> object computes. Note this method may not
|
||||
* return another instance of <code>Summary</code> or an instance of
|
||||
* Get the object that represents the actual result of whatever the
|
||||
* <code>Wizard</code>
|
||||
* that created this <code>Summary</code> object computes. Note this method
|
||||
* may not
|
||||
* return another instance of <code>Summary</code> or an instance of
|
||||
* <code>DeferredWizardResult</code>.
|
||||
* @return the object passed to the factory method that created this
|
||||
* Summary object, or null.
|
||||
*/
|
||||
*
|
||||
* @return the object passed to the factory method that created this
|
||||
* Summary object, or null.
|
||||
*/
|
||||
public Object getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.spi;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -16,8 +15,10 @@ import java.util.Set;
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
final class Util {
|
||||
private Util(){}
|
||||
|
||||
|
||||
private Util() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of step ids from an array of WizardPages
|
||||
*/
|
||||
@@ -28,22 +29,21 @@ final class Util {
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
result[i] = pages[i].id();
|
||||
if (result[i] == null || uniqueNames.contains(result[i])) {
|
||||
result[i] = uniquify (getIDFromStaticMethod(pages[i].getClass()),
|
||||
uniqueNames);
|
||||
result[i] = uniquify(getIDFromStaticMethod(pages[i].getClass()),
|
||||
uniqueNames);
|
||||
pages[i].id = result[i];
|
||||
}
|
||||
uniqueNames.add (result[i]);
|
||||
uniqueNames.add(result[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static String uniquify (String s, Set /* <String> */ used) {
|
||||
|
||||
static String uniquify(String s, Set /* <String> */ used) {
|
||||
String test = s;
|
||||
if (test != null) {
|
||||
int ix = 0;
|
||||
while (used.contains(test)) {
|
||||
while (used.contains(test))
|
||||
test = s + "_" + ix++;
|
||||
}
|
||||
}
|
||||
return test;
|
||||
}
|
||||
@@ -56,24 +56,22 @@ final class Util {
|
||||
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
result[i] = pages[i].description();
|
||||
if (result[i] == null) {
|
||||
result[i] = getDescriptionFromStaticMethod (pages[i].getClass());
|
||||
}
|
||||
if (result[i] == null)
|
||||
result[i] = getDescriptionFromStaticMethod(pages[i].getClass());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static String getIDFromStaticMethod (Class clazz) {
|
||||
static String getIDFromStaticMethod(Class clazz) {
|
||||
// System.err.println("GetID by method for " + clazz);
|
||||
String result = null;
|
||||
try {
|
||||
Method m = clazz.getDeclaredMethod("getStep", new Class[] {});
|
||||
// assert m.getReturnType() == String.class;
|
||||
result = (String) m.invoke(clazz, (Object[]) null);
|
||||
if (result == null) {
|
||||
throw new NullPointerException ("getStep may not return null");
|
||||
}
|
||||
if (result == null)
|
||||
throw new NullPointerException("getStep may not return null");
|
||||
} catch (Exception ex) {
|
||||
//do nothing
|
||||
}
|
||||
@@ -85,27 +83,23 @@ final class Util {
|
||||
* class object passed
|
||||
*/
|
||||
static String[] getSteps(Class[] pages) {
|
||||
if (pages == null) {
|
||||
throw new NullPointerException("Null array of classes"); //NOI18N
|
||||
}
|
||||
if (pages == null)
|
||||
throw new NullPointerException("Null array of classes");
|
||||
|
||||
String[] result = new String[pages.length];
|
||||
|
||||
Set used = new HashSet (pages.length);
|
||||
Set used = new HashSet(pages.length);
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
if (pages[i] == null) {
|
||||
throw new NullPointerException("Null at " + i + " in array " + //NOI18N
|
||||
"of panel classes"); //NOI18N
|
||||
}
|
||||
if (pages[i] == null)
|
||||
throw new NullPointerException("Null at " + i + " in array "
|
||||
+ "of panel classes");
|
||||
|
||||
if (!WizardPage.class.isAssignableFrom(pages[i])) {
|
||||
throw new IllegalArgumentException(pages[i] +
|
||||
" is not a subclass of WizardPage"); //NOI18N
|
||||
}
|
||||
result[i] = uniquify (getIDFromStaticMethod (pages[i]), used);
|
||||
if (result[i] == null) {
|
||||
if (!WizardPage.class.isAssignableFrom(pages[i]))
|
||||
throw new IllegalArgumentException(pages[i]
|
||||
+ " is not a subclass of WizardPage");
|
||||
result[i] = uniquify(getIDFromStaticMethod(pages[i]), used);
|
||||
if (result[i] == null)
|
||||
result[i] = pages[i].getName();
|
||||
}
|
||||
}
|
||||
// System.err.println("Returning " + Arrays.asList(result));
|
||||
return result;
|
||||
@@ -120,7 +114,6 @@ final class Util {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get an array of descriptions by looking for the static method
|
||||
* getDescription() on each passed class object
|
||||
@@ -128,9 +121,8 @@ final class Util {
|
||||
static String[] getDescriptions(Class[] pages) {
|
||||
String[] result = new String[pages.length];
|
||||
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
for (int i = 0; i < pages.length; i++)
|
||||
result[i] = getDescriptionFromStaticMethod(pages[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -139,35 +131,33 @@ final class Util {
|
||||
String result = null;
|
||||
Method m;
|
||||
try {
|
||||
m = clazz.getDeclaredMethod("getDescription", (Class[]) null); //NOI18N
|
||||
m = clazz.getDeclaredMethod("getDescription", (Class[]) null);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Could not find or access " + //NOI18N
|
||||
"public static String " + clazz.getName() + //NOI18N
|
||||
".getDescription() - make sure it exists"); //NOI18N
|
||||
throw new IllegalArgumentException("Could not find or access "
|
||||
+ "public static String " + clazz.getName()
|
||||
+ ".getDescription() - make sure it exists");
|
||||
}
|
||||
|
||||
if (m.getReturnType() != String.class) {
|
||||
throw new IllegalArgumentException("getStep has wrong " //NOI18N
|
||||
+ " return type: " + m.getReturnType() + " on " + //NOI18N
|
||||
clazz);
|
||||
}
|
||||
if (m.getReturnType() != String.class)
|
||||
throw new IllegalArgumentException("getStep has wrong "
|
||||
+ " return type: " + m.getReturnType() + " on "
|
||||
+ clazz);
|
||||
|
||||
if (!Modifier.isStatic(m.getModifiers())) {
|
||||
throw new IllegalArgumentException("getStep is not " + //NOI18N
|
||||
"static on " + clazz); //NOI18N
|
||||
}
|
||||
if (!Modifier.isStatic(m.getModifiers()))
|
||||
throw new IllegalArgumentException("getStep is not "
|
||||
+ "static on " + clazz);
|
||||
|
||||
try {
|
||||
m.setAccessible(true);
|
||||
result= (String) m.invoke(null, (Object[]) null);
|
||||
result = (String) m.invoke(null, (Object[]) null);
|
||||
} catch (InvocationTargetException ite) {
|
||||
throw new IllegalArgumentException("Could not invoke " + //NOI18N
|
||||
"public static String " + clazz.getName() + //NOI18N
|
||||
".getDescription() - make sure it exists."); //NOI18N
|
||||
throw new IllegalArgumentException("Could not invoke "
|
||||
+ "public static String " + clazz.getName()
|
||||
+ ".getDescription() - make sure it exists.");
|
||||
} catch (IllegalAccessException iae) {
|
||||
throw new IllegalArgumentException("Could not invoke " + //NOI18N
|
||||
"public static String " + clazz.getName() + //NOI18N
|
||||
".getDescription() - make sure it exists."); //NOI18N
|
||||
throw new IllegalArgumentException("Could not invoke "
|
||||
+ "public static String " + clazz.getName()
|
||||
+ ".getDescription() - make sure it exists.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ and include the License file at http://www.netbeans.org/cddl.txt.
|
||||
If applicable, add the following below the CDDL Header, with the fields
|
||||
enclosed by brackets [] replaced by your own identifying information:
|
||||
"Portions Copyrighted [year] [name of copyright owner]" */
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.spi;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
@@ -21,33 +20,35 @@ import javax.swing.JComponent;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardDisplayer;
|
||||
|
||||
/**
|
||||
* Encapsulates the logic and state of a Wizard. A Wizard gathers information
|
||||
* Encapsulates the logic and state of a Wizard. A Wizard gathers information
|
||||
* into a Map, and then performs some action with that information when the
|
||||
* user clicks Finish. To display a wizard, pass it to one of the methods
|
||||
* user clicks Finish. To display a wizard, pass it to one of the methods
|
||||
* on <code>WizardDisplayer.getDefault()</code>.
|
||||
* <p>
|
||||
* A Wizard is a series of one or more steps represented
|
||||
* by panels in the user interface. Each step is identified by a unique String ID.
|
||||
* by panels in the user interface. Each step is identified by a unique String
|
||||
* ID.
|
||||
* Panels are created, usually on-demand, as the user navigates through
|
||||
* the UI of the wizard. Panels typically listen on components they contain
|
||||
* and put values into the Map where the wizard gathers data. Note that if the
|
||||
* the UI of the wizard. Panels typically listen on components they contain
|
||||
* and put values into the Map where the wizard gathers data. Note that if the
|
||||
* user navigates <i>backward</i>, data entered on pages after the current one
|
||||
* disappears from the Map.
|
||||
* <p>
|
||||
* To create a Wizard, you do not implement or instantiate this class directly,
|
||||
* but rather, use one of the convenience classes in this package. There are
|
||||
* but rather, use one of the convenience classes in this package. There are
|
||||
* three:
|
||||
* <ul>
|
||||
* <li><code>WizardPage</code> - use or subclass WizardPage, and pass an array
|
||||
* of instances, or an array of the <code>Class</code> objects of your subclasses
|
||||
* to <code>WizardPage.createWizard()</code>. This class offers the added
|
||||
* of instances, or an array of the <code>Class</code> objects of your
|
||||
* subclasses
|
||||
* to <code>WizardPage.createWizard()</code>. This class offers the added
|
||||
* convenience that standard Swing components will be listened to automatically,
|
||||
* and if their Name property is set, the value from the component will be
|
||||
* automatically put into the settings map.
|
||||
* automatically put into the settings map.
|
||||
* </li>
|
||||
*
|
||||
* <li><code>WizardPanelProvider</code> - subclass this to create a Wizard
|
||||
* with a fixed set of steps. You provide a set of unique ID strings to the
|
||||
* with a fixed set of steps. You provide a set of unique ID strings to the
|
||||
* constructor, for all of the steps in the wizard, and override
|
||||
* createPanel() to create the GUI component that should be displayed for
|
||||
* each step - it will be called on demand as the user moves through the
|
||||
@@ -55,12 +56,12 @@ import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardDisplayer;
|
||||
*
|
||||
* <li><code>WizardBranchController</code> - this is for creating complex
|
||||
* wizards with decision points after which the future steps change, depending
|
||||
* on what the user chooses. Create a simple wizard using WizardPage or
|
||||
* on what the user chooses. Create a simple wizard using WizardPage or
|
||||
* WizardPanelProvider to represent the initial steps.
|
||||
* Then override <code>getWizardForStep()</code> or
|
||||
* <code>getPanelProviderForStep()</code> to return a different Wizard to
|
||||
* represent the remaining steps at any point where the set of future steps
|
||||
* changes. You can have as many branch points as you want, simply by
|
||||
* changes. You can have as many branch points as you want, simply by
|
||||
* using WizardBranchController to create the wizards for different decision
|
||||
* points.
|
||||
* <p>
|
||||
@@ -81,58 +82,63 @@ import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardDisplayer;
|
||||
* @author Timothy Boudreau
|
||||
*/
|
||||
public final class Wizard {
|
||||
|
||||
/**
|
||||
* Constant that can be returned by <code>getForwardNavigationMode()</code>
|
||||
* to indicate that the Next button can be enabled (or the Finish button
|
||||
* if the current panel is the last one in the wizard).
|
||||
*/
|
||||
public static final int MODE_CAN_CONTINUE =
|
||||
WizardController.MODE_CAN_CONTINUE;
|
||||
*/
|
||||
public static final int MODE_CAN_CONTINUE
|
||||
= WizardController.MODE_CAN_CONTINUE;
|
||||
|
||||
/**
|
||||
* Constant that can be returned by <code>getForwardNavigationMode</code> to indicate
|
||||
* Constant that can be returned by <code>getForwardNavigationMode</code> to
|
||||
* indicate
|
||||
* that the Finish button can be enabled if the problem string is null.
|
||||
*/
|
||||
public static final int MODE_CAN_FINISH =
|
||||
WizardController.MODE_CAN_FINISH;
|
||||
public static final int MODE_CAN_FINISH
|
||||
= WizardController.MODE_CAN_FINISH;
|
||||
/**
|
||||
* Constant that can be returned by <code>getForwardNavigationMode</code> to indicate
|
||||
* that both the Finish and Next buttons can be enabled if the problem
|
||||
* string is null. This value is a bitmask - i.e.
|
||||
* <code>MODE_CAN_CONTINUE_OR_FINISH == MODE_CAN_CONTINUE |
|
||||
* Constant that can be returned by <code>getForwardNavigationMode</code> to
|
||||
* indicate
|
||||
* that both the Finish and Next buttons can be enabled if the problem
|
||||
* string is null. This value is a bitmask - i.e.
|
||||
* <code>MODE_CAN_CONTINUE_OR_FINISH == MODE_CAN_CONTINUE |
|
||||
* MODE_CAN_FINISH</code>
|
||||
*/
|
||||
public static final int MODE_CAN_CONTINUE_OR_FINISH =
|
||||
WizardController.MODE_CAN_CONTINUE_OR_FINISH;
|
||||
|
||||
public static final int MODE_CAN_CONTINUE_OR_FINISH
|
||||
= WizardController.MODE_CAN_CONTINUE_OR_FINISH;
|
||||
|
||||
/**
|
||||
* Special panel ID key indicating a branch point in the wizard,
|
||||
* after which the next step(s) are unknown.
|
||||
*/
|
||||
public static final String UNDETERMINED_STEP = "_#UndeterminedStep";
|
||||
|
||||
|
||||
final WizardImplementation impl; //package private for unit tests
|
||||
|
||||
/** Creates a new instance of Wizard */
|
||||
|
||||
/**
|
||||
* Creates a new instance of Wizard
|
||||
*/
|
||||
Wizard(WizardImplementation impl) {
|
||||
this.impl = impl;
|
||||
if (impl == null) {
|
||||
if (impl == null)
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the wizard that the user is navigating to a different panel,
|
||||
* as identified by the passed <code>id</code>.
|
||||
* @param id The id of the panel being navigated to
|
||||
*
|
||||
* @param id The id of the panel being navigated to
|
||||
* @param wizardData The data gathered thus far as the user has progressed
|
||||
* through the wizard. The contents of this map should not contain any
|
||||
* key/values that were assigned on future panels, if the user is
|
||||
* navigating backward.
|
||||
* through the wizard. The contents of this map should not contain any
|
||||
* key/values that were assigned on future panels, if the user is
|
||||
* navigating backward.
|
||||
*
|
||||
* @return The component that should be shown for step <code>id</code>
|
||||
* of the <code>Wizard</code>
|
||||
*/
|
||||
* of the <code>Wizard</code>
|
||||
*/
|
||||
public JComponent navigatingTo(String id, Map wizardData) {
|
||||
return impl.navigatingTo(id, wizardData);
|
||||
}
|
||||
@@ -140,7 +146,7 @@ public final class Wizard {
|
||||
/**
|
||||
* Get the current step the wizard is on, as determined by the most recent
|
||||
* call to <code>navigatingTo()</code>.
|
||||
*/
|
||||
*/
|
||||
public String getCurrentStep() {
|
||||
return impl.getCurrentStep();
|
||||
}
|
||||
@@ -148,31 +154,34 @@ public final class Wizard {
|
||||
/**
|
||||
* Get the id of the step that comes after current step returned by
|
||||
* <code>getCurrentStep()</code>.
|
||||
* @return Null if this is the last step of the wizard;
|
||||
* <code>UNDETERMINED_STEP</code> if this is a branch point and the
|
||||
* user yet needs to do some interaction with the UI of the current
|
||||
* panel to trigger computation of the id of the next step; otherwise,
|
||||
* the unique id of the next step.
|
||||
*/
|
||||
*
|
||||
* @return Null if this is the last step of the wizard;
|
||||
* <code>UNDETERMINED_STEP</code> if this is a branch point and the
|
||||
* user yet needs to do some interaction with the UI of the current
|
||||
* panel to trigger computation of the id of the next step; otherwise,
|
||||
* the unique id of the next step.
|
||||
*/
|
||||
public String getNextStep() {
|
||||
return impl.getNextStep();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the preceding step to the current one as returned by
|
||||
* <code>getCurrentStep()</code>, or null if the current step is the
|
||||
* <code>getCurrentStep()</code>, or null if the current step is the
|
||||
* first page of the wizard.
|
||||
*
|
||||
* @return the id of the previous step or null
|
||||
*/
|
||||
*/
|
||||
public String getPreviousStep() {
|
||||
return impl.getPreviousStep();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the problem string that should be displayed to the user.
|
||||
*
|
||||
* @return A string describing what the user needs to do to enable
|
||||
* the Next or Finish buttons, or null if the buttons may be enabled
|
||||
*/
|
||||
* the Next or Finish buttons, or null if the buttons may be enabled
|
||||
*/
|
||||
public String getProblem() {
|
||||
return impl.getProblem();
|
||||
}
|
||||
@@ -181,43 +190,49 @@ public final class Wizard {
|
||||
* Get the string IDs of all known steps in this wizard, terminating
|
||||
* with <code>UNDETERMINED_STEP</code> if subsequent steps of the
|
||||
* wizard depend on the user's interaction beyond that point.
|
||||
*
|
||||
* @return an array of strings which may individually be passed to
|
||||
* <code>navigatingTo</code> to change the current step of the wizard
|
||||
*/
|
||||
* <code>navigatingTo</code> to change the current step of the wizard
|
||||
*/
|
||||
public String[] getAllSteps() {
|
||||
return impl.getAllSteps();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a long description for this panel. The long description should be
|
||||
* Get a long description for this panel. The long description should be
|
||||
* used in preference to the short description in the top of a wizard
|
||||
* panel in the UI, if it returns non-null.
|
||||
*
|
||||
* @param stepId The ID of the step for which a description is requested
|
||||
*
|
||||
* @return A more detailed localized description or null
|
||||
*/
|
||||
*/
|
||||
public String getLongDescription(String stepId) {
|
||||
return impl.getLongDescription (stepId);
|
||||
return impl.getLongDescription(stepId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a localized String description of the step for the passed id,
|
||||
* which may be displayed in the UI of the wizard.
|
||||
*
|
||||
* @param id A step id among those returned by <code>getAllSteps()</code>
|
||||
*/
|
||||
*/
|
||||
public String getStepDescription(String id) {
|
||||
return impl.getStepDescription(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user has clicked the finish button. This method
|
||||
* Called when the user has clicked the finish button. This method
|
||||
* computes whatever the result of the wizard is.
|
||||
*
|
||||
* @param settings The complete set of key-value pairs gathered by the
|
||||
* various panels as the user proceeded through the wizard
|
||||
* various panels as the user proceeded through the wizard
|
||||
*
|
||||
* @return An implementation-dependent object that is the outcome of
|
||||
* the wizard. May be null. Special return values are instances of
|
||||
* DeferredWizardResult and Summary which will affect the behavior of
|
||||
* the UI.
|
||||
*/
|
||||
* the wizard. May be null. Special return values are instances of
|
||||
* DeferredWizardResult and Summary which will affect the behavior of
|
||||
* the UI.
|
||||
*/
|
||||
public Object finish(Map settings) throws WizardException {
|
||||
return impl.finish(settings);
|
||||
}
|
||||
@@ -225,20 +240,24 @@ public final class Wizard {
|
||||
/**
|
||||
* Called when the user has clicked the Cancel button in the wizard UI
|
||||
* or otherwise closed the UI component without completing the wizard.
|
||||
* @param settings The (possibly incomplete) set of key-value pairs gathered by the
|
||||
* various panels as the user proceeded through the wizard
|
||||
*
|
||||
* @param settings The (possibly incomplete) set of key-value pairs gathered
|
||||
* by the
|
||||
* various panels as the user proceeded through the wizard
|
||||
*
|
||||
* @return true if the UI may indeed be closed, false if closing should
|
||||
* not be permitted
|
||||
*/
|
||||
public boolean cancel (Map settings) {
|
||||
* not be permitted
|
||||
*/
|
||||
public boolean cancel(Map settings) {
|
||||
return impl.cancel(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the Wizard that should be displayed in its dialog
|
||||
* titlebar (if any).
|
||||
*
|
||||
* @return A localized string
|
||||
*/
|
||||
*/
|
||||
public String getTitle() {
|
||||
return impl.getTitle();
|
||||
}
|
||||
@@ -246,8 +265,9 @@ public final class Wizard {
|
||||
/**
|
||||
* Determine if the wizard is busy doing work in a background thread and
|
||||
* all navigation controls should be disabled.
|
||||
*
|
||||
* @return whether or not the wizard is busy
|
||||
*/
|
||||
*/
|
||||
public boolean isBusy() {
|
||||
return impl.isBusy();
|
||||
}
|
||||
@@ -255,23 +275,27 @@ public final class Wizard {
|
||||
/**
|
||||
* Get the navigation mode, which determines the enablement state of
|
||||
* the Next and Finish buttons.
|
||||
*
|
||||
* @return one of the constants <code>MODE_CAN_CONTINUE</code>,
|
||||
* <code>MODE_CAN_FINISH</code>, or <code>MODE_CAN_CONTINUE_OR_FINISH</code>.
|
||||
*/
|
||||
* <code>MODE_CAN_FINISH</code>, or
|
||||
* <code>MODE_CAN_CONTINUE_OR_FINISH</code>.
|
||||
*/
|
||||
public int getForwardNavigationMode() {
|
||||
return impl.getForwardNavigationMode();
|
||||
}
|
||||
|
||||
private volatile boolean listeningToImpl = false;
|
||||
private final List listeners = Collections.synchronizedList (
|
||||
new LinkedList());
|
||||
private final List listeners = Collections.synchronizedList(
|
||||
new LinkedList());
|
||||
|
||||
private WizardObserver l = null;
|
||||
|
||||
/**
|
||||
* Add a WizardObserver that will be notified of navigability and step
|
||||
* changes.
|
||||
*
|
||||
* @param observer A WizardObserver
|
||||
*/
|
||||
*/
|
||||
public void addWizardObserver(WizardObserver observer) {
|
||||
listeners.add(observer);
|
||||
if (!listeningToImpl) {
|
||||
@@ -283,11 +307,12 @@ public final class Wizard {
|
||||
|
||||
/**
|
||||
* Remove a WizardObserver.
|
||||
*
|
||||
* @param observer A WizardObserver
|
||||
*/
|
||||
*/
|
||||
public void removeWizardObserver(WizardObserver observer) {
|
||||
listeners.remove(observer);
|
||||
if (listeningToImpl && listeners.size() == 0) {
|
||||
if (listeningToImpl && listeners.isEmpty()) {
|
||||
impl.removeWizardObserver(l);
|
||||
l = null;
|
||||
listeningToImpl = false;
|
||||
@@ -295,28 +320,26 @@ public final class Wizard {
|
||||
}
|
||||
|
||||
private class ImplL implements WizardObserver {
|
||||
|
||||
public void stepsChanged(Wizard wizard) {
|
||||
WizardObserver[] l = (WizardObserver[]) listeners.toArray(
|
||||
new WizardObserver[listeners.size()]);
|
||||
for (int i = 0; i < l.length; i++) {
|
||||
l[i].stepsChanged(Wizard.this);
|
||||
}
|
||||
new WizardObserver[listeners.size()]);
|
||||
for (WizardObserver l1 : l)
|
||||
l1.stepsChanged(Wizard.this);
|
||||
}
|
||||
|
||||
public void navigabilityChanged(Wizard wizard) {
|
||||
WizardObserver[] l = (WizardObserver[]) listeners.toArray(
|
||||
new WizardObserver[listeners.size()]);
|
||||
for (int i = 0; i < l.length; i++) {
|
||||
l[i].navigabilityChanged(Wizard.this);
|
||||
}
|
||||
new WizardObserver[listeners.size()]);
|
||||
for (WizardObserver l1 : l)
|
||||
l1.navigabilityChanged(Wizard.this);
|
||||
}
|
||||
|
||||
public void selectionChanged(Wizard wizard) {
|
||||
WizardObserver[] l = (WizardObserver[]) listeners.toArray(
|
||||
new WizardObserver[listeners.size()]);
|
||||
for (int i = 0; i < l.length; i++) {
|
||||
l[i].selectionChanged(Wizard.this);
|
||||
}
|
||||
new WizardObserver[listeners.size()]);
|
||||
for (WizardObserver l1 : l)
|
||||
l1.selectionChanged(Wizard.this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,41 +347,40 @@ public final class Wizard {
|
||||
return impl.hashCode() * 17;
|
||||
}
|
||||
|
||||
public boolean equals (Object o) {
|
||||
if (o == this) {
|
||||
public boolean equals(Object o) {
|
||||
if (o == this)
|
||||
return true;
|
||||
} else if (o instanceof Wizard) {
|
||||
return impl.equals (((Wizard)o).impl);
|
||||
} else {
|
||||
else if (o instanceof Wizard)
|
||||
return impl.equals(((Wizard) o).impl);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to WizardDisplayer.showWizard()
|
||||
*/
|
||||
public void show () {
|
||||
*/
|
||||
public void show() {
|
||||
WizardDisplayer.showWizard(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to WizardDisplayer.showWizard()
|
||||
*/
|
||||
public Object show (Wizard wizard, Action help) {
|
||||
return WizardDisplayer.showWizard (wizard, help);
|
||||
*/
|
||||
public Object show(Wizard wizard, Action help) {
|
||||
return WizardDisplayer.showWizard(wizard, help);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to WizardDisplayer.showWizard()
|
||||
*/
|
||||
public Object show (Wizard wizard, Rectangle r) {
|
||||
return WizardDisplayer.showWizard (wizard, r);
|
||||
*/
|
||||
public Object show(Wizard wizard, Rectangle r) {
|
||||
return WizardDisplayer.showWizard(wizard, r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to WizardDisplayer.showWizard()
|
||||
*/
|
||||
public Object show (Wizard wizard, Rectangle r, Action help) {
|
||||
return WizardDisplayer.showWizard (wizard, r, help, null);
|
||||
*/
|
||||
public Object show(Wizard wizard, Rectangle r, Action help) {
|
||||
return WizardDisplayer.showWizard(wizard, r, help, null);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,7 @@ compliance with the License.
|
||||
or http://www.netbeans.org/cddl.txt.
|
||||
When distributing Covered Code, include this CDDL Header Notice in each file
|
||||
and include the License file at http://www.netbeans.org/cddl.txt.
|
||||
*/
|
||||
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.spi;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -14,76 +13,85 @@ import java.util.Map;
|
||||
/**
|
||||
* This is an optional interface for panels that want to be notified when
|
||||
* the next and back buttons are pressed.
|
||||
*
|
||||
*
|
||||
* The WizardPanelProvider is NOT required to create panels that implement
|
||||
* this interface.
|
||||
*
|
||||
*
|
||||
* Each of these methods returns a WizardPanelNavResult that can be used to
|
||||
* indicate PROCEED or REMAIN_ON_PAGE.
|
||||
*
|
||||
*
|
||||
* The result can also be an instance of a subclass of WizardPanelNavResult
|
||||
* that implements the <code>start</code> method to use a background thread
|
||||
* to determine if the next page can be shown.
|
||||
*
|
||||
* to determine if the next page can be shown.
|
||||
*
|
||||
* @author stanley@stanleyknutson.com
|
||||
*/
|
||||
public interface WizardPanel
|
||||
{
|
||||
public interface WizardPanel {
|
||||
|
||||
/**
|
||||
* This method is invoked when the "next" button has been pushed,
|
||||
* to do a final validation of input (such as doing a database login).
|
||||
*
|
||||
* If this method return false, then the "next" button will not change the
|
||||
* displayed panel. Presumably some error will have been shown to the user.
|
||||
*
|
||||
*
|
||||
* If this method return false, then the "next" button will not change the
|
||||
* displayed panel. Presumably some error will have been shown to the user.
|
||||
*
|
||||
* @param stepName
|
||||
* @param settings
|
||||
* @param wizard
|
||||
*
|
||||
* @return WizardPanelNavResult.PROCEED if the "next" button should proceed,
|
||||
* WizardPanelNavResult.REMAIN_ON_PAGE if "next" should not proceed,
|
||||
* or a instance of subclass of WizardPanelResult that will do some background computation
|
||||
* and call the progress.finished method with one of those constants
|
||||
* (or call progress.failed with the error message)
|
||||
* WizardPanelNavResult.REMAIN_ON_PAGE if "next" should not proceed,
|
||||
* or a instance of subclass of WizardPanelResult that will do some
|
||||
* background computation
|
||||
* and call the progress.finished method with one of those constants
|
||||
* (or call progress.failed with the error message)
|
||||
*/
|
||||
public WizardPanelNavResult allowNext (String stepName, Map settings, Wizard wizard);
|
||||
public WizardPanelNavResult allowNext(String stepName, Map settings, Wizard wizard);
|
||||
|
||||
/**
|
||||
* This method is invoked when the "back" button has been pushed,
|
||||
* to discard any data from the setings that will not been needed and for which the
|
||||
* to discard any data from the setings that will not been needed and for
|
||||
* which the
|
||||
* normal "just hide that data" is not the desired behavior.
|
||||
* (See MergeMap for discussion of the "hide the data" behavior)
|
||||
*
|
||||
* If this method return false, then the "next" button will not change the
|
||||
* displayed panel. Presumably some error will have been shown to the user.
|
||||
*
|
||||
*
|
||||
* If this method return false, then the "next" button will not change the
|
||||
* displayed panel. Presumably some error will have been shown to the user.
|
||||
*
|
||||
* @param stepName
|
||||
* @param settings
|
||||
* @param wizard
|
||||
*
|
||||
* @return WizardPanelNavResult.PROCEED if the "back" button should proceed,
|
||||
* WizardPanelNavResult.REMAIN_ON_PAGE if "back" should not proceed,
|
||||
* or a instance of subclass of WizardPanelResult that will do some background computation
|
||||
* and call the progress.finished method with one of those constants.
|
||||
* (or call progress.failed with the error message)
|
||||
* WizardPanelNavResult.REMAIN_ON_PAGE if "back" should not proceed,
|
||||
* or a instance of subclass of WizardPanelResult that will do some
|
||||
* background computation
|
||||
* and call the progress.finished method with one of those constants.
|
||||
* (or call progress.failed with the error message)
|
||||
*/
|
||||
public WizardPanelNavResult allowBack (String stepName, Map settings, Wizard wizard);
|
||||
public WizardPanelNavResult allowBack(String stepName, Map settings, Wizard wizard);
|
||||
|
||||
/**
|
||||
* This method is invoked when the "finish" button has been pushed,
|
||||
* to allow veto of the finish action BEFORE the wizard finish method is invoked.
|
||||
*
|
||||
* If this method return false, then the "finish" button will have no effect.
|
||||
* to allow veto of the finish action BEFORE the wizard finish method is
|
||||
* invoked.
|
||||
*
|
||||
* If this method return false, then the "finish" button will have no
|
||||
* effect.
|
||||
* Presumably some error will have been shown to the user.
|
||||
*
|
||||
*
|
||||
* @param stepName
|
||||
* @param settings
|
||||
* @param wizard
|
||||
* @return WizardPanelNavResult.PROCEED if the "finish" button should proceed,
|
||||
* WizardPanelNavResult.REMAIN_ON_PAGE if "finish" should not proceed,
|
||||
* or a instance of subclass of WizardPanelResult that will do some background computation
|
||||
* and call the progress.finished method with one of those constants.
|
||||
* (or call progress.failed with the error message)
|
||||
*
|
||||
* @return WizardPanelNavResult.PROCEED if the "finish" button should
|
||||
* proceed,
|
||||
* WizardPanelNavResult.REMAIN_ON_PAGE if "finish" should not proceed,
|
||||
* or a instance of subclass of WizardPanelResult that will do some
|
||||
* background computation
|
||||
* and call the progress.finished method with one of those constants.
|
||||
* (or call progress.failed with the error message)
|
||||
*/
|
||||
public WizardPanelNavResult allowFinish (String stepName, Map settings, Wizard wizard);
|
||||
public WizardPanelNavResult allowFinish(String stepName, Map settings, Wizard wizard);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user