add some localization items
This commit is contained in:
@@ -23,16 +23,14 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.UIManager;
|
||||
import org.jackhuang.hellominecraft.utils.C;
|
||||
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardDisplayer;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.MergeMap;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.NbBridge;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.DeferredWizardResult;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.Summary;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.Wizard;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardException;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardObserver;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardPage;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardPanel;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardPanelNavResult;
|
||||
|
||||
@@ -84,9 +82,6 @@ public class NavButtonManager implements ActionListener {
|
||||
|
||||
WizardDisplayerImpl parent;
|
||||
|
||||
String closeString = NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Close"); // NOI18N
|
||||
|
||||
boolean suppressMessageDialog = false;
|
||||
/**
|
||||
* Deferred status of not null means we are waiting for a deferred result to
|
||||
@@ -102,44 +97,28 @@ public class NavButtonManager implements ActionListener {
|
||||
|
||||
protected void buildButtons(Action helpAction) {
|
||||
|
||||
next = new JButton(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Next_>")); // NOI18N
|
||||
next = new JButton(C.i18n("wizard.next_>"));
|
||||
next.setName(NAME_NEXT);
|
||||
next.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Next_mnemonic").charAt(0)); // NOI18N
|
||||
next.setMnemonic(C.i18n("wizard.next_mnemonic").charAt(0));
|
||||
|
||||
prev = new JButton(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "<_Prev")); // NOI18N
|
||||
prev = new JButton(C.i18n("wizard.<_prev"));
|
||||
prev.setName(NAME_PREV);
|
||||
prev.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Prev_mnemonic").charAt(0)); // NOI18N
|
||||
prev.setMnemonic(C.i18n("wizard.prev_mnemonic").charAt(0));
|
||||
|
||||
finish = new JButton(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Finish")); // NOI18N
|
||||
finish = new JButton(C.i18n("wizard.finish")); // NOI18N
|
||||
finish.setName(NAME_FINISH);
|
||||
finish.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Finish_mnemonic").charAt(0)); // NOI18N
|
||||
finish.setMnemonic(C.i18n("wizard.finish_mnemonic").charAt(0));
|
||||
|
||||
cancel = new JButton(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Cancel")); // NOI18N
|
||||
cancel = new JButton(C.i18n("wizard.cancel"));
|
||||
cancel.setName(NAME_CANCEL);
|
||||
cancel.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Cancel_mnemonic").charAt(0)); // NOI18N
|
||||
cancel.setMnemonic(C.i18n("wizard.cancel_mnemonic").charAt(0));
|
||||
|
||||
help = new JButton();
|
||||
if (helpAction != null) {
|
||||
if (helpAction != null)
|
||||
help.setAction(helpAction);
|
||||
if (helpAction.getValue(Action.NAME) == null) {
|
||||
help.setText(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Help")); // NOI18N
|
||||
help.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Help_mnemonic").charAt(0)); // NOI18N
|
||||
}
|
||||
} else {
|
||||
help.setText(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Help")); // NOI18N
|
||||
help.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Help_mnemonic").charAt(0)); // NOI18N
|
||||
if (helpAction == null || helpAction.getValue(Action.NAME) == null) {
|
||||
help.setText(C.i18n("wizard.help"));
|
||||
help.setMnemonic(C.i18n("wizard.help_mnemonic").charAt(0));
|
||||
}
|
||||
|
||||
next.setDefaultCapable(true);
|
||||
@@ -224,24 +203,20 @@ public class NavButtonManager implements ActionListener {
|
||||
final boolean enableNext = nextStep != null && canContinue && problem == null && !isDeferredResult;
|
||||
final boolean enablePrevious = wizard.getPreviousStep() != null && !isDeferredResult;
|
||||
|
||||
final Runnable runnable = new Runnable() {
|
||||
|
||||
public void run() {
|
||||
next.setEnabled(enableNext);
|
||||
prev.setEnabled(enablePrevious);
|
||||
finish.setEnabled(enableFinish);
|
||||
JRootPane root = next.getRootPane();
|
||||
if (root != null)
|
||||
if (next.isEnabled())
|
||||
root.setDefaultButton(next);
|
||||
else if (finish.isEnabled())
|
||||
root.setDefaultButton(finish);
|
||||
else if (prev.isEnabled())
|
||||
root.setDefaultButton(prev);
|
||||
else
|
||||
root.setDefaultButton(null);
|
||||
|
||||
}
|
||||
final Runnable runnable = () -> {
|
||||
next.setEnabled(enableNext);
|
||||
prev.setEnabled(enablePrevious);
|
||||
finish.setEnabled(enableFinish);
|
||||
JRootPane root = next.getRootPane();
|
||||
if (root != null)
|
||||
if (next.isEnabled())
|
||||
root.setDefaultButton(next);
|
||||
else if (finish.isEnabled())
|
||||
root.setDefaultButton(finish);
|
||||
else if (prev.isEnabled())
|
||||
root.setDefaultButton(prev);
|
||||
else
|
||||
root.setDefaultButton(null);
|
||||
};
|
||||
|
||||
if (EventQueue.isDispatchThread())
|
||||
@@ -268,34 +243,42 @@ public class NavButtonManager implements ActionListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NAME_NEXT.equals(name))
|
||||
processNext();
|
||||
else if (NAME_PREV.equals(name))
|
||||
processPrev();
|
||||
else if (NAME_FINISH.equals(name))
|
||||
processFinish(event);
|
||||
else if (NAME_CLOSE.equals(name))
|
||||
processClose(event);
|
||||
if (null != name)
|
||||
switch (name) {
|
||||
case NAME_NEXT:
|
||||
processNext();
|
||||
break;
|
||||
case NAME_PREV:
|
||||
processPrev();
|
||||
break;
|
||||
case NAME_FINISH:
|
||||
processFinish(event);
|
||||
break;
|
||||
case NAME_CLOSE:
|
||||
processClose(event);
|
||||
// else ignore, we don't know it
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// else ignore, we don't know it
|
||||
|
||||
parent.updateProblem();
|
||||
}
|
||||
|
||||
void deferredResultFailed(final boolean canGoBack) {
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
if (!canGoBack)
|
||||
getCancel().setText(closeString);
|
||||
getPrev().setEnabled(true);
|
||||
getNext().setEnabled(false);
|
||||
getCancel().setEnabled(true);
|
||||
getFinish().setEnabled(false);
|
||||
final Runnable runnable = () -> {
|
||||
if (!canGoBack)
|
||||
getCancel().setText(getCloseString());
|
||||
getPrev().setEnabled(true);
|
||||
getNext().setEnabled(false);
|
||||
getCancel().setEnabled(true);
|
||||
getFinish().setEnabled(false);
|
||||
|
||||
if (NAME_CLOSE.equals(deferredStatus)) {
|
||||
// no action
|
||||
} else
|
||||
deferredStatus = DEFERRED_FAILED + deferredStatus;
|
||||
}
|
||||
if (NAME_CLOSE.equals(deferredStatus)) {
|
||||
// no action
|
||||
} else
|
||||
deferredStatus = DEFERRED_FAILED + deferredStatus;
|
||||
};
|
||||
if (EventQueue.isDispatchThread())
|
||||
runnable.run();
|
||||
@@ -326,23 +309,31 @@ public class NavButtonManager implements ActionListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (NAME_NEXT.equals(name))
|
||||
switch (name) {
|
||||
case NAME_NEXT:
|
||||
processNextProceed(o);
|
||||
else if (NAME_PREV.equals(name))
|
||||
break;
|
||||
// else ignore, we don't know it
|
||||
case NAME_PREV:
|
||||
processPrevProceed(o);
|
||||
else if (NAME_CANCEL.equals(name))
|
||||
break;
|
||||
case NAME_CANCEL:
|
||||
processCancel(o instanceof ActionEvent ? (ActionEvent) o
|
||||
: null, false);
|
||||
else if (NAME_FINISH.equals(name))
|
||||
break;
|
||||
case NAME_FINISH:
|
||||
// allowFinish on the "down" click of the finish button
|
||||
processFinishProceed(o);
|
||||
else if (NAME_CLOSE.equals(name)) {
|
||||
break;
|
||||
case NAME_CLOSE:
|
||||
// the "up" click of the finish button: wizard.finish was a deferred result
|
||||
Window dlg = getWindow();
|
||||
dlg.setVisible(false);
|
||||
dlg.dispose();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// else ignore, we don't know it
|
||||
|
||||
parent.updateProblem();
|
||||
}
|
||||
@@ -484,14 +475,10 @@ public class NavButtonManager implements ActionListener {
|
||||
curr = settings.popAndCalve();
|
||||
settings.push(id);
|
||||
parent.navigateTo(id);
|
||||
return;
|
||||
} catch (NoSuchElementException ex) {
|
||||
IllegalStateException e = new IllegalStateException("Exception "
|
||||
+ // NOI18N
|
||||
"said to return to " + id + " but no such "
|
||||
+ // NOI18N
|
||||
"step found"); // NOI18N
|
||||
e.initCause(ex);
|
||||
+ "said to return to " + id + " but no such "
|
||||
+ "step found", ex);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -504,11 +491,9 @@ public class NavButtonManager implements ActionListener {
|
||||
Wizard wizard = parent.getWizard();
|
||||
MergeMap settings = parent.getSettings();
|
||||
|
||||
// System.err.println("ProcessCancel " + reallyCancel + " receiver " + parent.receiver);
|
||||
boolean closeWindow = false;
|
||||
boolean closeWindow;
|
||||
|
||||
if (reallyCancel && parent.cancel()) {
|
||||
// System.err.println("DO CANCEL");
|
||||
logger.fine("calling wizard cancel method on " + wizard);
|
||||
wizard.cancel(settings);
|
||||
return;
|
||||
@@ -545,9 +530,8 @@ public class NavButtonManager implements ActionListener {
|
||||
if (window != null && parent.receiver == null && window instanceof JDialog)
|
||||
((JDialog) window).getRootPane().setDefaultButton(cancel);
|
||||
|
||||
cancel.setText(closeString); // NOI18N
|
||||
cancel.setMnemonic(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/api/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Close_mnemonic").charAt(0)); // NOI18N
|
||||
cancel.setText(getCloseString()); // NOI18N
|
||||
cancel.setMnemonic(C.i18n("wizard.close_mnemonic").charAt(0));
|
||||
cancel.setName(NAME_CLOSE);
|
||||
deferredStatus = null; // ?? should summary be different
|
||||
}
|
||||
@@ -565,7 +549,7 @@ public class NavButtonManager implements ActionListener {
|
||||
}
|
||||
|
||||
public String getCloseString() {
|
||||
return closeString;
|
||||
return C.i18n("wizard.close");
|
||||
}
|
||||
|
||||
public Window getWindow() {
|
||||
@@ -617,26 +601,22 @@ public class NavButtonManager implements ActionListener {
|
||||
}
|
||||
|
||||
public void navigabilityChanged(final Wizard wizard) {
|
||||
final Runnable runnable = new Runnable() {
|
||||
|
||||
public void run() {
|
||||
if (wizard.isBusy()) {
|
||||
next.setEnabled(false);
|
||||
prev.setEnabled(false);
|
||||
finish.setEnabled(false);
|
||||
cancel.setEnabled(false);
|
||||
parent.getOuterPanel().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
wasBusy = true;
|
||||
return;
|
||||
} else if (wasBusy) {
|
||||
cancel.setEnabled(true);
|
||||
parent.getOuterPanel().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
configureNavigationButtons(wizard, prev, next, finish);
|
||||
|
||||
parent.updateProblem();
|
||||
|
||||
final Runnable runnable = () -> {
|
||||
if (wizard.isBusy()) {
|
||||
next.setEnabled(false);
|
||||
prev.setEnabled(false);
|
||||
finish.setEnabled(false);
|
||||
cancel.setEnabled(false);
|
||||
parent.getOuterPanel().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
wasBusy = true;
|
||||
return;
|
||||
} else if (wasBusy) {
|
||||
cancel.setEnabled(true);
|
||||
parent.getOuterPanel().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
configureNavigationButtons(wizard, prev, next, finish);
|
||||
|
||||
parent.updateProblem();
|
||||
};
|
||||
if (EventQueue.isDispatchThread())
|
||||
runnable.run();
|
||||
|
||||
@@ -11,13 +11,10 @@ import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import org.jackhuang.hellominecraft.utils.C;
|
||||
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardDisplayer;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.InstructionsPanelImpl;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.NbBridge;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.ResultProgressHandle;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.Summary;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardPage;
|
||||
|
||||
/**
|
||||
* Show progress bar for deferred results, with a label showing percent done and
|
||||
@@ -75,49 +72,40 @@ public class NavProgress implements ResultProgressHandle {
|
||||
}
|
||||
|
||||
public void setProgress(final String description, final int currentStep, final int totalSteps) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
lbl.setText(description == null ? " " : description); // NOI18N
|
||||
setProgress(currentStep, totalSteps);
|
||||
}
|
||||
};
|
||||
invoke(r);
|
||||
invoke(() -> {
|
||||
lbl.setText(description == null ? " " : description); // NOI18N
|
||||
setProgress(currentStep, totalSteps);
|
||||
});
|
||||
}
|
||||
|
||||
public void setProgress(final int currentStep, final int totalSteps) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
if (totalSteps == -1)
|
||||
progressBar.setIndeterminate(true);
|
||||
else {
|
||||
if (currentStep > totalSteps || currentStep < 0) {
|
||||
if (currentStep == -1 && totalSteps == -1)
|
||||
return;
|
||||
throw new IllegalArgumentException("Bad step values: " // NOI18N
|
||||
+ currentStep + " out of " + totalSteps); // NOI18N
|
||||
}
|
||||
progressBar.setIndeterminate(false);
|
||||
progressBar.setMaximum(totalSteps);
|
||||
progressBar.setValue(currentStep);
|
||||
invoke(() -> {
|
||||
if (totalSteps == -1)
|
||||
progressBar.setIndeterminate(true);
|
||||
else {
|
||||
if (currentStep > totalSteps || currentStep < 0) {
|
||||
if (currentStep == -1 && totalSteps == -1)
|
||||
return;
|
||||
throw new IllegalArgumentException("Bad step values: "
|
||||
+ currentStep + " out of " + totalSteps);
|
||||
}
|
||||
|
||||
setUseBusy(false);
|
||||
progressBar.setIndeterminate(false);
|
||||
progressBar.setMaximum(totalSteps);
|
||||
progressBar.setValue(currentStep);
|
||||
}
|
||||
};
|
||||
invoke(r);
|
||||
|
||||
setUseBusy(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void setBusy(final String description) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
lbl.setText(description == null ? " " : description); // NOI18N
|
||||
invoke(() -> {
|
||||
lbl.setText(description == null ? " " : description);
|
||||
|
||||
progressBar.setIndeterminate(true);
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
setUseBusy(true);
|
||||
}
|
||||
};
|
||||
invoke(r);
|
||||
setUseBusy(true);
|
||||
});
|
||||
}
|
||||
|
||||
protected void setUseBusy(boolean useBusy) {
|
||||
@@ -137,7 +125,7 @@ public class NavProgress implements ResultProgressHandle {
|
||||
|
||||
private void ensureBusyInitialized() {
|
||||
if (busy.getIcon() == null) {
|
||||
URL url = getClass().getResource("busy.gif");
|
||||
URL url = getClass().getResource("/org/jackhuang/hellominecraft/busy.gif");
|
||||
Icon icon = new ImageIcon(url);
|
||||
busy.setIcon(icon);
|
||||
}
|
||||
@@ -149,29 +137,24 @@ public class NavProgress implements ResultProgressHandle {
|
||||
else
|
||||
try {
|
||||
EventQueue.invokeAndWait(r);
|
||||
} catch (InvocationTargetException ex) {
|
||||
} catch (InvocationTargetException | InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
logger.severe("Error invoking operation " + ex.getClass().getName() + " " + ex.getMessage());
|
||||
} catch (InterruptedException ex) {
|
||||
logger.severe("Error invoking operation " + ex.getClass().getName() + " " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void finished(final Object o) {
|
||||
isRunning = false;
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
if (o instanceof Summary) {
|
||||
Summary summary = (Summary) o;
|
||||
parent.handleSummary(summary);
|
||||
parent.setWizardResult(summary.getResult());
|
||||
} else if (parent.getDeferredResult() != null) {
|
||||
parent.setWizardResult(o);
|
||||
Runnable r = () -> {
|
||||
if (o instanceof Summary) {
|
||||
Summary summary = (Summary) o;
|
||||
parent.handleSummary(summary);
|
||||
parent.setWizardResult(summary.getResult());
|
||||
} else if (parent.getDeferredResult() != null) {
|
||||
parent.setWizardResult(o);
|
||||
|
||||
// handle result based on which button was pushed
|
||||
parent.getButtonManager().deferredResultFinished(o);
|
||||
}
|
||||
// handle result based on which button was pushed
|
||||
parent.getButtonManager().deferredResultFinished(o);
|
||||
}
|
||||
};
|
||||
invoke(r);
|
||||
@@ -181,19 +164,14 @@ public class NavProgress implements ResultProgressHandle {
|
||||
failMessage = message;
|
||||
isRunning = false;
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
// cheap word wrap
|
||||
JLabel comp = new JLabel("<html><body>" + message); // NOI18N
|
||||
comp.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
parent.setCurrentWizardPanel(comp);
|
||||
parent.getTtlLabel().setText(
|
||||
NbBridge
|
||||
.getString("org/netbeans/api/wizard/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Failed")); // NOI18N
|
||||
NavButtonManager bm = parent.getButtonManager();
|
||||
bm.deferredResultFailed(canGoBack);
|
||||
}
|
||||
Runnable r = () -> {
|
||||
// cheap word wrap
|
||||
JLabel comp = new JLabel("<html><body>" + message); // NOI18N
|
||||
comp.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
parent.setCurrentWizardPanel(comp);
|
||||
parent.getTtlLabel().setText(C.i18n("wizard.failed"));
|
||||
NavButtonManager bm = parent.getButtonManager();
|
||||
bm.deferredResultFailed(canGoBack);
|
||||
};
|
||||
invoke(r);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/* The contents of this file are subject to the terms of the Common Development
|
||||
and Distribution License (the License). You may not use this file except in
|
||||
compliance with the License.
|
||||
You can obtain a copy of the License at http://www.netbeans.org/cddl.html
|
||||
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.
|
||||
If applicable, add the following below the CDDL Header, with the fields
|
||||
enclosed by brackets [] replaced by your own identifying information:
|
||||
|
||||
Written by Stanley@StanleyKnutson.com based on code from Tim B.
|
||||
|
||||
/*
|
||||
* The contents of this file are subject to the terms of the Common Development
|
||||
* and Distribution License (the License). You may not use this file except in
|
||||
* compliance with the License.
|
||||
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html
|
||||
* 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.
|
||||
* If applicable, add the following below the CDDL Header, with the fields
|
||||
* enclosed by brackets [] replaced by your own identifying information:
|
||||
*
|
||||
* Written by Stanley@StanleyKnutson.com based on code from Tim B.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.utils.views.wizard.api.displayer;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
@@ -51,11 +51,12 @@ import javax.swing.WindowConstants;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
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.api.WizardDisplayer;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.api.WizardResultReceiver;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.InstructionsPanelImpl;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.MergeMap;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.modules.NbBridge;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.DeferredWizardResult;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.ResultProgressHandle;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.Summary;
|
||||
@@ -64,95 +65,85 @@ import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardPanel;
|
||||
|
||||
/**
|
||||
* Default implementation of WizardDisplayer.
|
||||
* <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>. <p>Use
|
||||
* 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>.
|
||||
* <p>
|
||||
* Use
|
||||
* <code>WizardDisplayer.showWizard()</code> or its other static methods to
|
||||
* display wizards in a way which will continue to work over time.
|
||||
*
|
||||
* @author stanley@StanleyKnutson.com
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
public class WizardDisplayerImpl extends WizardDisplayer
|
||||
{
|
||||
public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
|
||||
ResultProgressHandle progress = null;
|
||||
|
||||
ResultProgressHandle progress = null;
|
||||
JLabel ttlLabel = null;
|
||||
|
||||
JLabel ttlLabel = null;
|
||||
JPanel ttlPanel = null;
|
||||
|
||||
JPanel ttlPanel = null;
|
||||
Wizard wizard = null;
|
||||
|
||||
Wizard wizard = null;
|
||||
JPanel outerPanel = null;
|
||||
|
||||
JPanel outerPanel = null;
|
||||
NavButtonManager buttonManager = null;
|
||||
|
||||
NavButtonManager buttonManager = null;
|
||||
InstructionsPanel instructions = null;
|
||||
|
||||
InstructionsPanel instructions = null;
|
||||
MergeMap settings = null;
|
||||
|
||||
MergeMap settings = null;
|
||||
JPanel inner = null;
|
||||
|
||||
JPanel inner = null;
|
||||
JLabel problem = null;
|
||||
|
||||
JLabel problem = null;
|
||||
Object wizardResult = null;
|
||||
|
||||
Object wizardResult = null;
|
||||
|
||||
WizardResultReceiver receiver = null;
|
||||
WizardResultReceiver receiver = null;
|
||||
|
||||
/**
|
||||
* WizardPanel is the panel returned as the panel to display. Often a
|
||||
* subclass of WizardPanel
|
||||
*/
|
||||
JComponent wizardPanel = null;
|
||||
JComponent wizardPanel = null;
|
||||
|
||||
boolean inSummary = false;
|
||||
boolean inSummary = false;
|
||||
|
||||
DeferredWizardResult deferredResult = null;
|
||||
DeferredWizardResult deferredResult = null;
|
||||
|
||||
/**
|
||||
* Default constructor used by WizardDisplayer static methods.
|
||||
*
|
||||
*/
|
||||
public WizardDisplayerImpl()
|
||||
{
|
||||
public WizardDisplayerImpl() {
|
||||
}
|
||||
|
||||
protected void buildStepTitle()
|
||||
{
|
||||
|
||||
protected void buildStepTitle() {
|
||||
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
|
||||
ttlPanel = new JPanel()
|
||||
{
|
||||
public void doLayout()
|
||||
{
|
||||
.getColor("textText")))); // NOI18N
|
||||
ttlPanel = new JPanel() {
|
||||
public void doLayout() {
|
||||
Dimension d = ttlLabel.getPreferredSize();
|
||||
if (ttlLabel.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
|
||||
{
|
||||
ttlLabel.setBounds(getWidth() - d.width, 0, getWidth(), d.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
ttlLabel.setBounds(0, 0, getWidth(), d.height);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize()
|
||||
{
|
||||
public Dimension getPreferredSize() {
|
||||
return ttlLabel.getPreferredSize();
|
||||
}
|
||||
};
|
||||
ttlPanel.add(ttlLabel);
|
||||
Font f = ttlLabel.getFont();
|
||||
if (f == null)
|
||||
{
|
||||
f = UIManager.getFont("controlFont"); // NOI18N
|
||||
}
|
||||
if (f != null)
|
||||
{
|
||||
if (f != null) {
|
||||
f = f.deriveFont(Font.BOLD);
|
||||
ttlLabel.setFont(f);
|
||||
}
|
||||
@@ -161,33 +152,28 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
|
||||
/**
|
||||
* Show a wizard
|
||||
*
|
||||
* @param awizard is the wizard to be displayed
|
||||
* @param bounds for display, may be null for default of 0,0,400,600.
|
||||
*
|
||||
* @param awizard is the wizard to be displayed
|
||||
* @param bounds for display, may be null for default of
|
||||
* 0,0,400,600.
|
||||
* @param helpAction
|
||||
* @param initialProperties - initial values for the map
|
||||
*
|
||||
* @return value of the 'finish' processing
|
||||
* @see org.netbeans.api.wizard.WizardDisplayer#show(org.netbeans.spi.wizard.Wizard, java.awt.Rectangle, javax.swing.Action, java.util.Map)
|
||||
*
|
||||
* @see
|
||||
* org.netbeans.api.wizard.WizardDisplayer#show(org.netbeans.spi.wizard.Wizard,
|
||||
* java.awt.Rectangle, javax.swing.Action, java.util.Map)
|
||||
*/
|
||||
private JPanel createOuterPanel(final Wizard awizard, Rectangle bounds, Action helpAction,
|
||||
Map initialProperties)
|
||||
{
|
||||
Map initialProperties) {
|
||||
|
||||
this.wizard = awizard;
|
||||
|
||||
outerPanel = new JPanel();
|
||||
|
||||
// apply default size
|
||||
// we don't enforce any maximum size
|
||||
if (bounds == null)
|
||||
{
|
||||
bounds = new Rectangle(0,0, 600,400);
|
||||
}
|
||||
|
||||
if (wizard.getAllSteps().length == 0)
|
||||
{
|
||||
throw new IllegalArgumentException("Wizard has no steps"); // NOI18N
|
||||
}
|
||||
|
||||
// initialize the ttl* stuff
|
||||
buildStepTitle();
|
||||
@@ -195,17 +181,16 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
buttonManager = new NavButtonManager(this);
|
||||
|
||||
outerPanel.setLayout(new BorderLayout());
|
||||
|
||||
|
||||
Action kbdCancel = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JButton b = buttonManager.getCancel();
|
||||
if (b.isEnabled()) {
|
||||
if (b.isEnabled())
|
||||
b.doClick();
|
||||
}
|
||||
}
|
||||
};
|
||||
outerPanel.getInputMap(outerPanel.WHEN_IN_FOCUSED_WINDOW).put(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); //NOI18N
|
||||
outerPanel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); //NOI18N
|
||||
outerPanel.getActionMap().put("cancel", kbdCancel); //NOI18N
|
||||
|
||||
instructions = createInstructionsPanel();
|
||||
@@ -232,81 +217,67 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
// introduce the initial properties as if they had been set on page 1
|
||||
// even though they may be defaults for page 2
|
||||
if (initialProperties != null)
|
||||
{
|
||||
settings.putAll(initialProperties);
|
||||
}
|
||||
|
||||
wizardPanel = wizard.navigatingTo(first, settings);
|
||||
String desc = wizard.getLongDescription (first);
|
||||
if (desc != null) {
|
||||
ttlLabel.setText (desc);
|
||||
}
|
||||
String desc = wizard.getLongDescription(first);
|
||||
if (desc != null)
|
||||
ttlLabel.setText(desc);
|
||||
|
||||
inner.add(wizardPanel, BorderLayout.CENTER);
|
||||
|
||||
buttonManager.initializeNavigation();
|
||||
return outerPanel;
|
||||
}
|
||||
|
||||
|
||||
protected InstructionsPanel createInstructionsPanel() {
|
||||
return new InstructionsPanelImpl (wizard);
|
||||
return new InstructionsPanelImpl(wizard);
|
||||
}
|
||||
|
||||
public void install (Container c, Object layoutConstraint, Wizard awizard,
|
||||
Action helpAction, Map initialProperties, WizardResultReceiver receiver) {
|
||||
JPanel pnl = createOuterPanel (awizard, new Rectangle(), helpAction, initialProperties);
|
||||
if (layoutConstraint != null) {
|
||||
if (c instanceof RootPaneContainer) {
|
||||
((RootPaneContainer) c).getContentPane().add (pnl, layoutConstraint);
|
||||
} else {
|
||||
c.add (pnl, layoutConstraint);
|
||||
}
|
||||
} else {
|
||||
if (c instanceof RootPaneContainer) {
|
||||
((RootPaneContainer) c).getContentPane().add (pnl);
|
||||
} else {
|
||||
c.add (pnl);
|
||||
}
|
||||
}
|
||||
|
||||
public void install(Container c, Object layoutConstraint, Wizard awizard,
|
||||
Action helpAction, Map initialProperties, WizardResultReceiver receiver) {
|
||||
JPanel pnl = createOuterPanel(awizard, new Rectangle(), helpAction, initialProperties);
|
||||
if (layoutConstraint != null)
|
||||
if (c instanceof RootPaneContainer)
|
||||
((RootPaneContainer) c).getContentPane().add(pnl, layoutConstraint);
|
||||
else
|
||||
c.add(pnl, layoutConstraint);
|
||||
else if (c instanceof RootPaneContainer)
|
||||
((RootPaneContainer) c).getContentPane().add(pnl);
|
||||
else
|
||||
c.add(pnl);
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
|
||||
private static boolean warned;
|
||||
|
||||
public Object show(final Wizard awizard, Rectangle bounds, Action helpAction,
|
||||
Map initialProperties) {
|
||||
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());
|
||||
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());
|
||||
warned = true;
|
||||
}
|
||||
createOuterPanel (awizard, bounds, helpAction, initialProperties);
|
||||
createOuterPanel(awizard, bounds, helpAction, initialProperties);
|
||||
Object result = showInDialog(bounds);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected JDialog createDialog()
|
||||
{
|
||||
protected JDialog createDialog() {
|
||||
JDialog dlg;
|
||||
Object o = findLikelyOwnerWindow();
|
||||
if (o instanceof Frame)
|
||||
{
|
||||
dlg = new JDialog((Frame) o);
|
||||
}
|
||||
else if (o instanceof Dialog)
|
||||
{
|
||||
dlg = new JDialog((Dialog) o);
|
||||
}
|
||||
else
|
||||
{
|
||||
dlg = new JDialog();
|
||||
}
|
||||
return dlg;
|
||||
}
|
||||
|
||||
protected Object showInDialog(Rectangle bounds)
|
||||
{
|
||||
protected Object showInDialog(Rectangle bounds) {
|
||||
// TODO: add flag for "showInFrame"
|
||||
|
||||
JDialog dlg = createDialog();
|
||||
@@ -318,45 +289,28 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
dlg.getContentPane().setLayout(new BorderLayout());
|
||||
dlg.getContentPane().add(outerPanel, BorderLayout.CENTER);
|
||||
if (bounds != null)
|
||||
{
|
||||
dlg.setBounds(bounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
dlg.pack();
|
||||
}
|
||||
dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
dlg.addWindowListener(new WindowAdapter()
|
||||
{
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
if (!(e.getWindow() instanceof JDialog)) {
|
||||
dlg.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
if (!(e.getWindow() instanceof JDialog))
|
||||
return;
|
||||
}
|
||||
JDialog dlg = (JDialog) e.getWindow();
|
||||
boolean dontClose = false;
|
||||
if (!wizard.isBusy())
|
||||
{
|
||||
if (!wizard.isBusy()) {
|
||||
DeferredWizardResult defResult;
|
||||
synchronized(WizardDisplayerImpl.this) {
|
||||
synchronized (WizardDisplayerImpl.this) {
|
||||
defResult = deferredResult;
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
if (defResult != null && defResult.canAbort())
|
||||
{
|
||||
defResult.abort();
|
||||
}
|
||||
else if (defResult != null && !defResult.canAbort())
|
||||
{
|
||||
dontClose = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (!dontClose && wizard.cancel(settings))
|
||||
{
|
||||
} finally {
|
||||
if (!dontClose && wizard.cancel(settings)) {
|
||||
dlg.setVisible(false);
|
||||
dlg.dispose();
|
||||
}
|
||||
@@ -380,63 +334,58 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
return wizardResult;
|
||||
}
|
||||
|
||||
private Window findLikelyOwnerWindow()
|
||||
{
|
||||
private Window findLikelyOwnerWindow() {
|
||||
return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current wizard panel, or null if the currently displayed page
|
||||
* is not a WizardPanel.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WizardPanel getCurrentWizardPanel()
|
||||
{
|
||||
public WizardPanel getCurrentWizardPanel() {
|
||||
JComponent comp = wizardPanel;
|
||||
if (comp instanceof WizardPanel)
|
||||
{
|
||||
return (WizardPanel) comp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getCurrentStep()
|
||||
{
|
||||
public String getCurrentStep() {
|
||||
return settings.currID();
|
||||
}
|
||||
|
||||
// available in the package only
|
||||
static void checkLegalNavMode(int i)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case Wizard.MODE_CAN_CONTINUE:
|
||||
case Wizard.MODE_CAN_CONTINUE_OR_FINISH:
|
||||
case Wizard.MODE_CAN_FINISH:
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal forward " + // NOI18N
|
||||
"navigation mode: " + i); // NOI18N
|
||||
static void checkLegalNavMode(int i) {
|
||||
switch (i) {
|
||||
case Wizard.MODE_CAN_CONTINUE:
|
||||
case Wizard.MODE_CAN_CONTINUE_OR_FINISH:
|
||||
case Wizard.MODE_CAN_FINISH:
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Illegal forward "
|
||||
+ // NOI18N
|
||||
"navigation mode: " + i); // NOI18N
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* private static final class LDlg extends JDialog { public LDlg() {
|
||||
* } public LDlg (Frame frame) { super (frame); }
|
||||
*
|
||||
* } public LDlg (Frame frame) { super (frame); }
|
||||
*
|
||||
* public LDlg (Dialog dlg) { super (dlg); }
|
||||
*
|
||||
*
|
||||
* public void setVisible (boolean val) { if (!val) { Thread.dumpStack(); }
|
||||
* super.setVisible (val); } }
|
||||
*/
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set the currently displayed panel.
|
||||
* @parm comp is can be anything - it is not required to be a WizardPage or WizardPanel
|
||||
* */
|
||||
public void setCurrentWizardPanel(JComponent comp)
|
||||
{
|
||||
*
|
||||
* @parm comp is can be anything - it is not required to be a WizardPage or
|
||||
* WizardPanel
|
||||
*
|
||||
*/
|
||||
public void setCurrentWizardPanel(JComponent comp) {
|
||||
inner.add(comp, BorderLayout.CENTER);
|
||||
inner.remove(wizardPanel);
|
||||
wizardPanel = comp;
|
||||
@@ -445,37 +394,30 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
inner.repaint();
|
||||
comp.requestFocus();
|
||||
if (!inSummary)
|
||||
{
|
||||
buttonManager.updateButtons();
|
||||
}
|
||||
}
|
||||
|
||||
void handleSummary(Summary summary)
|
||||
{
|
||||
void handleSummary(Summary summary) {
|
||||
inSummary = true;
|
||||
instructions.setInSummaryPage(true);
|
||||
JComponent summaryComp = (JComponent) summary.getSummaryComponent(); // XXX
|
||||
if (summaryComp.getBorder() != null)
|
||||
{
|
||||
if (summaryComp.getBorder() != null) {
|
||||
CompoundBorder b = new CompoundBorder(new EmptyBorder(5, 5, 5, 5), summaryComp
|
||||
.getBorder());
|
||||
.getBorder());
|
||||
summaryComp.setBorder(b);
|
||||
}
|
||||
setCurrentWizardPanel((JComponent) summaryComp); // XXX
|
||||
ttlLabel.setText(NbBridge.getString("org/netbeans/api/wizard/Bundle", // NOI18N
|
||||
WizardDisplayer.class, "Summary")); // NOI18N
|
||||
ttlLabel.setText(C.i18n("wizard.summary"));
|
||||
getButtonManager().setSummaryShowingMode();
|
||||
summaryComp.requestFocus();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected ResultProgressHandle createProgressDisplay (boolean isUseBusy)
|
||||
{
|
||||
protected ResultProgressHandle createProgressDisplay(boolean isUseBusy) {
|
||||
return new NavProgress(this, isUseBusy);
|
||||
}
|
||||
|
||||
void handleDeferredWizardResult(final DeferredWizardResult r, final boolean inSummary)
|
||||
{
|
||||
|
||||
void handleDeferredWizardResult(final DeferredWizardResult r, final boolean inSummary) {
|
||||
synchronized (this) {
|
||||
deferredResult = r;
|
||||
}
|
||||
@@ -484,56 +426,30 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
Container inst = instructions.getComponent();
|
||||
progress.addProgressComponents(inst);
|
||||
inst.invalidate();
|
||||
if (inst instanceof JComponent) {
|
||||
((JComponent)inst).revalidate();
|
||||
}
|
||||
if (inst instanceof JComponent)
|
||||
((JComponent) inst).revalidate();
|
||||
inst.repaint();
|
||||
Runnable run = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Runnable run = new Runnable() {
|
||||
public void run() {
|
||||
if (!EventQueue.isDispatchThread())
|
||||
{
|
||||
try
|
||||
{
|
||||
EventQueue.invokeLater (new Runnable() {
|
||||
public void run() {
|
||||
buttonManager.getWindow()
|
||||
.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
}
|
||||
});
|
||||
try {
|
||||
EventQueue.invokeLater(() -> buttonManager.getWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)));
|
||||
r.start(settings, progress);
|
||||
if (progress.isRunning())
|
||||
{
|
||||
progress.failed("Start method did not inidicate " +
|
||||
"failure or finished in " + r, false);
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
progress.failed("Start method did not inidicate "
|
||||
+ "failure or finished in " + r, false);
|
||||
|
||||
} finally {
|
||||
try {
|
||||
EventQueue.invokeAndWait(this);
|
||||
}
|
||||
catch (InvocationTargetException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
} catch (InvocationTargetException | InterruptedException ex) {
|
||||
HMCLog.err("Failed to invoke and wait", ex);
|
||||
return;
|
||||
}
|
||||
catch (InterruptedException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
buttonManager.getWindow().setCursor(Cursor.getDefaultCursor());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
synchronized (this) {
|
||||
deferredResult = null;
|
||||
}
|
||||
@@ -541,9 +457,8 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
Container inst = instructions.getComponent();
|
||||
inst.removeAll();
|
||||
inst.invalidate();
|
||||
if (inst instanceof JComponent) {
|
||||
((JComponent)instructions).revalidate();
|
||||
}
|
||||
if (inst instanceof JComponent)
|
||||
((JComponent) instructions).revalidate();
|
||||
inst.repaint();
|
||||
}
|
||||
}
|
||||
@@ -552,123 +467,97 @@ public class WizardDisplayerImpl extends WizardDisplayer
|
||||
runner.start();
|
||||
}
|
||||
|
||||
public void navigateTo(String id)
|
||||
{
|
||||
public void navigateTo(String id) {
|
||||
JComponent comp = wizard.navigatingTo(id, getSettings());
|
||||
String description = wizard.getLongDescription (id);
|
||||
if (description == null) {
|
||||
description = wizard.getStepDescription (id);
|
||||
}
|
||||
String description = wizard.getLongDescription(id);
|
||||
if (description == null)
|
||||
description = wizard.getStepDescription(id);
|
||||
getTtlLabel().setText(description);
|
||||
setCurrentWizardPanel(comp);
|
||||
}
|
||||
|
||||
public NavButtonManager getButtonManager()
|
||||
{
|
||||
public NavButtonManager getButtonManager() {
|
||||
return buttonManager;
|
||||
}
|
||||
|
||||
public synchronized DeferredWizardResult getDeferredResult()
|
||||
{
|
||||
public synchronized DeferredWizardResult getDeferredResult() {
|
||||
return deferredResult;
|
||||
}
|
||||
|
||||
public InstructionsPanel getInstructions()
|
||||
{
|
||||
public InstructionsPanel getInstructions() {
|
||||
return instructions;
|
||||
}
|
||||
|
||||
public boolean isInSummary()
|
||||
{
|
||||
public boolean isInSummary() {
|
||||
return inSummary;
|
||||
}
|
||||
|
||||
public void setInSummary(final boolean state)
|
||||
{
|
||||
public void setInSummary(final boolean state) {
|
||||
inSummary = state;
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
instructions.setInSummaryPage(state);
|
||||
}
|
||||
};
|
||||
if (EventQueue.isDispatchThread()) {
|
||||
Runnable r = () -> instructions.setInSummaryPage(state);
|
||||
if (EventQueue.isDispatchThread())
|
||||
r.run();
|
||||
} else {
|
||||
EventQueue.invokeLater (r);
|
||||
}
|
||||
else
|
||||
EventQueue.invokeLater(r);
|
||||
}
|
||||
|
||||
public JPanel getOuterPanel()
|
||||
{
|
||||
public JPanel getOuterPanel() {
|
||||
return outerPanel;
|
||||
}
|
||||
|
||||
public MergeMap getSettings()
|
||||
{
|
||||
public MergeMap getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public JLabel getTtlLabel()
|
||||
{
|
||||
public JLabel getTtlLabel() {
|
||||
return ttlLabel;
|
||||
}
|
||||
|
||||
public JPanel getTtlPanel()
|
||||
{
|
||||
public JPanel getTtlPanel() {
|
||||
return ttlPanel;
|
||||
}
|
||||
|
||||
public Wizard getWizard()
|
||||
{
|
||||
public Wizard getWizard() {
|
||||
return wizard;
|
||||
}
|
||||
|
||||
public JComponent getWizardPanel()
|
||||
{
|
||||
public JComponent getWizardPanel() {
|
||||
return wizardPanel;
|
||||
}
|
||||
|
||||
public Object getWizardResult()
|
||||
{
|
||||
public Object getWizardResult() {
|
||||
return wizardResult;
|
||||
}
|
||||
|
||||
public void setWizardResult(Object wizardResult)
|
||||
{
|
||||
public void setWizardResult(Object wizardResult) {
|
||||
this.wizardResult = wizardResult;
|
||||
if (receiver != null) {
|
||||
if (receiver != null)
|
||||
receiver.finished(wizardResult);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setDeferredResult(DeferredWizardResult deferredResult)
|
||||
{
|
||||
public synchronized void setDeferredResult(DeferredWizardResult deferredResult) {
|
||||
this.deferredResult = deferredResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Will only be called if there is a WizardResultReceiver - i.e. if the
|
||||
* wizard is being displayed in some kind of custom container. Return
|
||||
* wizard is being displayed in some kind of custom container. Return
|
||||
* true to indicate we should not try to close the parent window.
|
||||
*/
|
||||
*/
|
||||
boolean cancel() {
|
||||
boolean result = receiver != null;
|
||||
if (result) {
|
||||
if (result)
|
||||
receiver.cancelled(settings);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void updateProblem()
|
||||
{
|
||||
void updateProblem() {
|
||||
String prob = wizard.getProblem();
|
||||
problem.setText(prob == null ? " " : prob); // NOI18N
|
||||
if (prob != null && prob.trim().length() == 0)
|
||||
{
|
||||
// Issue 3 - provide ability to disable next w/o
|
||||
// showing the error line
|
||||
prob = null;
|
||||
}
|
||||
Border b = prob == null ? BorderFactory.createEmptyBorder(1, 0, 0, 0) : BorderFactory
|
||||
.createMatteBorder(1, 0, 0, 0, problem.getForeground());
|
||||
|
||||
|
||||
@@ -43,6 +43,8 @@ import javax.swing.CellRendererPane;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.UIManager;
|
||||
import org.jackhuang.hellominecraft.utils.C;
|
||||
import org.jackhuang.hellominecraft.utils.logging.HMCLog;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.api.displayer.InstructionsPanel;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.Wizard;
|
||||
import org.jackhuang.hellominecraft.utils.views.wizard.spi.WizardObserver;
|
||||
@@ -149,9 +151,9 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
if (img == null)
|
||||
try {
|
||||
img = ImageIO.read(InstructionsPanelImpl.class.getResourceAsStream(
|
||||
"defaultWizard.png")); //NOI18N
|
||||
"/org/jackhuang/hellominecraft/wizard.jpg")); //NOI18N
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
HMCLog.err("Failed to load wizard.jpg, maybe you fucking modified the launcher", ioe);
|
||||
}
|
||||
this.img = img;
|
||||
this.wizard = wizard;
|
||||
@@ -202,9 +204,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
steps = wizard.getAllSteps();
|
||||
String steps[] = this.steps;
|
||||
if (inSummaryPage) {
|
||||
String summaryStep = NbBridge.getString(
|
||||
"org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "Summary"); //NOI18N
|
||||
String summaryStep = C.i18n("wizard.summary");
|
||||
String[] nue = new String[steps.length + 1];
|
||||
System.arraycopy(steps, 0, nue, 0, steps.length);
|
||||
nue[nue.length - 1] = summaryStep;
|
||||
@@ -217,8 +217,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
Font boldFont = f.deriveFont(Font.BOLD);
|
||||
|
||||
g.setFont(boldFont);
|
||||
g.drawString(NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "Steps"), x, y); //NOI18N
|
||||
g.drawString(C.i18n("wizard.steps"), x, y);
|
||||
|
||||
int underlineY = ins.top + MARGIN + fm.getAscent() + 3;
|
||||
g.drawLine(x, underlineY, x + (getWidth() - (x + ins.left + MARGIN)),
|
||||
@@ -230,8 +229,6 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
y += h + 10;
|
||||
int first = 0;
|
||||
int stop = steps.length;
|
||||
String elipsis = NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "elipsis"); //NOI18N
|
||||
boolean wontFit = y + (h * (steps.length)) > getHeight();
|
||||
if (wontFit) {
|
||||
//try to center the current step
|
||||
@@ -255,33 +252,6 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
stop = rangeEnd;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* if (wontFit) {
|
||||
* int currStepIndex = Arrays.asList (steps).indexOf(currentStep);
|
||||
* if (currStepIndex != -1) { //shouldn't happen
|
||||
* steps = (String[]) steps.clone();
|
||||
* first = Math.max (0, currStepIndex - 2);
|
||||
* if (first != 0) {
|
||||
* if (y + ((currStepIndex - first) * h) > getHeight()) {
|
||||
* //Best effort to keep current step on screen
|
||||
* first++;
|
||||
* }
|
||||
* if (first != currStepIndex) {
|
||||
* steps[first] = elipsis;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* if (y + ((stop - first) * h) > bottom) {
|
||||
* int avail = bottom - y;
|
||||
* int willFit = avail / h;
|
||||
* int last = first + willFit - 1;
|
||||
* if (last < steps.length - 1) {
|
||||
* steps[last] = elipsis;
|
||||
* stop = last + 1;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
g.setFont(getFont());
|
||||
g.setColor(getForeground());
|
||||
@@ -298,11 +268,9 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
curr = (i + 1) + ". " + steps[i];
|
||||
else
|
||||
curr = (i + 1) + ". " + (isUndetermined
|
||||
? NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "elipsis")
|
||||
: //NOI18N
|
||||
steps[i].equals(elipsis) ? elipsis
|
||||
: wizard.getStepDescription(steps[i])); //NOI18N
|
||||
? elipsis
|
||||
: steps[i].equals(elipsis) ? elipsis
|
||||
: wizard.getStepDescription(steps[i]));
|
||||
else
|
||||
curr = elipsis;
|
||||
if (curr != null) {
|
||||
@@ -313,10 +281,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
|
||||
int width = fm.stringWidth(curr);
|
||||
while (width > getWidth() - (ins.left + ins.right) && curr.length() > 5)
|
||||
curr = curr.substring(0, curr.length() - 5)
|
||||
+ NbBridge.getString(
|
||||
"org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "elipsis"); //NOI18N
|
||||
curr = curr.substring(0, curr.length() - 5) + elipsis;
|
||||
|
||||
g.drawString(curr, x, y);
|
||||
if (selected)
|
||||
@@ -328,6 +293,8 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
|
||||
private int historicWidth = Integer.MIN_VALUE;
|
||||
|
||||
String elipsis = "...";
|
||||
|
||||
public final Dimension getPreferredSize() {
|
||||
Font f = getFont() != null ? getFont()
|
||||
: UIManager.getFont("controlFont"); //NOI18N
|
||||
@@ -344,8 +311,7 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
int w = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
String desc = i + ". " + (Wizard.UNDETERMINED_STEP.equals(steps[i])
|
||||
? NbBridge.getString("org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "elipsis")
|
||||
? elipsis
|
||||
: //NOI18N
|
||||
wizard.getStepDescription(steps[i]));
|
||||
if (desc != null)
|
||||
@@ -414,12 +380,6 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
panel = pnl;
|
||||
if (pnl.getParent() instanceof Accessible)
|
||||
setAccessibleParent((Accessible) pnl.getParent());
|
||||
setAccessibleName(NbBridge.getString(
|
||||
"org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "ACN_InstructionsPanel")); //NOI18N
|
||||
setAccessibleDescription(NbBridge.getString(
|
||||
"org/jackhuang/hellominecraft/utils/views/wizard/modules/Bundle", //NOI18N
|
||||
InstructionsPanelImpl.class, "ACSD_InstructionsPanel")); //NOI18N
|
||||
}
|
||||
|
||||
JEditorPane pane;
|
||||
@@ -444,12 +404,10 @@ public class InstructionsPanelImpl extends JComponent implements WizardObserver,
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String[] s = wizard.getAllSteps();
|
||||
for (int i = 0; i < s.length; i++) {
|
||||
sb.append(wizard.getStepDescription(s[i]));
|
||||
sb.append('\n');
|
||||
}
|
||||
for (String item : s)
|
||||
sb.append(wizard.getStepDescription(item)).append('\n');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* The contents of this file are subject to the terms of the Common Development
|
||||
* and Distribution License (the License). You may not use this file except in
|
||||
* compliance with the License.
|
||||
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html
|
||||
* 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.
|
||||
* 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.modules;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Non API class for accessing a few things in NetBeans via reflection.
|
||||
*
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
public final class NbBridge {
|
||||
|
||||
private NbBridge() {
|
||||
}
|
||||
|
||||
public static String getString(String path, Class callerType, String key) {
|
||||
return getStringViaResourceBundle(path, key);
|
||||
}
|
||||
|
||||
private static String getStringViaResourceBundle(String path, String key) {
|
||||
return ResourceBundle.getBundle(path).getString(key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user