choosing files for modpack
This commit is contained in:
@@ -25,7 +25,7 @@ import org.jackhuang.hellominecraft.utils.logging.logger.Logger;
|
||||
*/
|
||||
public class HMCLog {
|
||||
|
||||
public static Logger logger = new Logger("Hello Minecraft!");
|
||||
private static final Logger logger = new Logger("Hello Minecraft!");
|
||||
|
||||
public static void log(String message) {
|
||||
logger.info(message);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ZipEngine {
|
||||
} else {
|
||||
pathName = file.getPath().substring(basePath.length() + 1);
|
||||
if (pathNameCallback != null)
|
||||
pathName = pathNameCallback.apply(pathName, true);
|
||||
pathName = pathNameCallback.apply(pathName, false);
|
||||
if (pathName == null)
|
||||
continue;
|
||||
putFile(file, pathName);
|
||||
|
||||
@@ -110,11 +110,13 @@ public abstract class Task {
|
||||
return new DoubleTask(t, this);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
public boolean run() {
|
||||
try {
|
||||
executeTask();
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
HMCLog.err("Failed to execute task", t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.views.checktree;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
|
||||
public class CheckBoxTreeCellRenderer extends JPanel implements TreeCellRenderer {
|
||||
|
||||
protected JCheckBox check;
|
||||
protected CheckBoxTreeLabel label;
|
||||
|
||||
public CheckBoxTreeCellRenderer() {
|
||||
setLayout(null);
|
||||
add(check = new JCheckBox());
|
||||
add(label = new CheckBoxTreeLabel());
|
||||
check.setBackground(UIManager.getColor("Tree.textBackground"));
|
||||
label.setForeground(UIManager.getColor("Tree.textForeground"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回的是一个<code>JPanel</code>对象,该对象中包含一个<code>JCheckBox</code>对象
|
||||
* 和一个<code>JLabel</code>对象。并且根据每个结点是否被选中来决定<code>JCheckBox</code>
|
||||
* 是否被选中。
|
||||
*/
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree, Object value,
|
||||
boolean selected, boolean expanded, boolean leaf, int row,
|
||||
boolean hasFocus) {
|
||||
String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus);
|
||||
setEnabled(tree.isEnabled());
|
||||
check.setSelected(((CheckBoxTreeNode) value).isSelected());
|
||||
label.setFont(tree.getFont());
|
||||
label.setText(stringValue);
|
||||
label.setSelected(selected);
|
||||
label.setFocus(hasFocus);
|
||||
if (leaf)
|
||||
label.setIcon(UIManager.getIcon("Tree.leafIcon"));
|
||||
else if (expanded)
|
||||
label.setIcon(UIManager.getIcon("Tree.openIcon"));
|
||||
else
|
||||
label.setIcon(UIManager.getIcon("Tree.closedIcon"));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension dCheck = check.getPreferredSize();
|
||||
Dimension dLabel = label.getPreferredSize();
|
||||
return new Dimension(dCheck.width + dLabel.width, dCheck.height < dLabel.height ? dLabel.height : dCheck.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLayout() {
|
||||
Dimension dCheck = check.getPreferredSize();
|
||||
Dimension dLabel = label.getPreferredSize();
|
||||
int yCheck = 0;
|
||||
int yLabel = 0;
|
||||
if (dCheck.height < dLabel.height)
|
||||
yCheck = (dLabel.height - dCheck.height) / 2;
|
||||
else
|
||||
yLabel = (dCheck.height - dLabel.height) / 2;
|
||||
check.setLocation(0, yCheck);
|
||||
check.setBounds(0, yCheck, dCheck.width, dCheck.height);
|
||||
label.setLocation(dCheck.width, yLabel);
|
||||
label.setBounds(dCheck.width, yLabel, dLabel.width, dLabel.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color color) {
|
||||
if (color instanceof ColorUIResource)
|
||||
color = null;
|
||||
super.setBackground(color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.views.checktree;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
|
||||
public class CheckBoxTreeLabel extends JLabel {
|
||||
|
||||
private boolean isSelected;
|
||||
private boolean hasFocus;
|
||||
|
||||
public CheckBoxTreeLabel() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color color) {
|
||||
if (color instanceof ColorUIResource)
|
||||
color = null;
|
||||
super.setBackground(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
/*String str;
|
||||
if ((str = getText()) != null)
|
||||
if (0 < str.length()) {
|
||||
if (isSelected)
|
||||
g.setColor(UIManager.getColor("Tree.selectionBackground"));
|
||||
else
|
||||
g.setColor(UIManager.getColor("Tree.textBackground"));
|
||||
Dimension d = getPreferredSize();
|
||||
int imageOffset = 0;
|
||||
Icon currentIcon = getIcon();
|
||||
if (currentIcon != null)
|
||||
imageOffset = currentIcon.getIconWidth() + Math.max(0, getIconTextGap() - 1);
|
||||
g.fillRect(imageOffset, 0, d.width - 1 - imageOffset, d.height);
|
||||
if (hasFocus) {
|
||||
g.setColor(UIManager.getColor("Tree.selectionBorderColor"));
|
||||
g.drawRect(imageOffset, 0, d.width - 1 - imageOffset, d.height - 1);
|
||||
}
|
||||
}*/
|
||||
super.paint(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension retDimension = super.getPreferredSize();
|
||||
if (retDimension != null)
|
||||
retDimension = new Dimension(retDimension.width + 3, retDimension.height);
|
||||
return retDimension;
|
||||
}
|
||||
|
||||
public void setSelected(boolean isSelected) {
|
||||
this.isSelected = isSelected;
|
||||
}
|
||||
|
||||
public void setFocus(boolean hasFocus) {
|
||||
this.hasFocus = hasFocus;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.views.checktree;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class CheckBoxTreeNode extends DefaultMutableTreeNode {
|
||||
|
||||
protected boolean isSelected;
|
||||
|
||||
public CheckBoxTreeNode() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public CheckBoxTreeNode(Object userObject) {
|
||||
this(userObject, true, false);
|
||||
}
|
||||
|
||||
public CheckBoxTreeNode(Object userObject, boolean allowsChildren, boolean isSelected) {
|
||||
super(userObject, allowsChildren);
|
||||
this.isSelected = isSelected;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return isSelected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean _isSelected) {
|
||||
this.isSelected = _isSelected;
|
||||
|
||||
if (_isSelected) {
|
||||
// 如果选中,则将其所有的子结点都选中
|
||||
if (children != null)
|
||||
for (Object obj : children) {
|
||||
CheckBoxTreeNode node = (CheckBoxTreeNode) obj;
|
||||
if (_isSelected != node.isSelected())
|
||||
node.setSelected(_isSelected);
|
||||
}
|
||||
// 向上检查,如果父结点的所有子结点都被选中,那么将父结点也选中
|
||||
CheckBoxTreeNode pNode = (CheckBoxTreeNode) parent;
|
||||
// 开始检查pNode的所有子节点是否都被选中
|
||||
if (pNode != null) {
|
||||
int index = 0;
|
||||
for (; index < pNode.children.size(); ++index) {
|
||||
CheckBoxTreeNode pChildNode = (CheckBoxTreeNode) pNode.children.get(index);
|
||||
if (!pChildNode.isSelected())
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* 表明pNode所有子结点都已经选中,则选中父结点,
|
||||
* 该方法是一个递归方法,因此在此不需要进行迭代,因为
|
||||
* 当选中父结点后,父结点本身会向上检查的。
|
||||
*/
|
||||
if (index == pNode.children.size())
|
||||
if (pNode.isSelected() != _isSelected)
|
||||
pNode.setSelected(_isSelected);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* 如果是取消父结点导致子结点取消,那么此时所有的子结点都应该是选择上的;
|
||||
* 否则就是子结点取消导致父结点取消,然后父结点取消导致需要取消子结点,但
|
||||
* 是这时候是不需要取消子结点的。
|
||||
*/
|
||||
if (children != null) {
|
||||
int index = 0;
|
||||
for (; index < children.size(); ++index) {
|
||||
CheckBoxTreeNode childNode = (CheckBoxTreeNode) children.get(index);
|
||||
if (!childNode.isSelected())
|
||||
break;
|
||||
}
|
||||
// 从上向下取消的时候
|
||||
if (index == children.size())
|
||||
for (int i = 0; i < children.size(); ++i) {
|
||||
CheckBoxTreeNode node = (CheckBoxTreeNode) children.get(i);
|
||||
if (node.isSelected() != _isSelected)
|
||||
node.setSelected(_isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
// 向上取消,只要存在一个子节点不是选上的,那么父节点就不应该被选上。
|
||||
CheckBoxTreeNode pNode = (CheckBoxTreeNode) parent;
|
||||
if (pNode != null && pNode.isSelected() != _isSelected)
|
||||
pNode.setSelected(_isSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Hello Minecraft! Launcher.
|
||||
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see {http://www.gnu.org/licenses/}.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.utils.views.checktree;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
public class CheckBoxTreeNodeSelectionListener extends MouseAdapter {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent event) {
|
||||
JTree tree = (JTree) event.getSource();
|
||||
int x = event.getX();
|
||||
int y = event.getY();
|
||||
int row = tree.getRowForLocation(x, y);
|
||||
TreePath path = tree.getPathForRow(row);
|
||||
if (path != null) {
|
||||
CheckBoxTreeNode node = (CheckBoxTreeNode) path.getLastPathComponent();
|
||||
if (node != null) {
|
||||
boolean isSelected = !node.isSelected();
|
||||
node.setSelected(isSelected);
|
||||
((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,8 @@ package org.jackhuang.hellominecraft.utils.views.wizard.api.displayer;
|
||||
import java.awt.Container;
|
||||
import java.awt.EventQueue;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
@@ -38,14 +35,10 @@ public class NavProgress implements ResultProgressHandle {
|
||||
|
||||
JLabel lbl = new JLabel();
|
||||
|
||||
JLabel busy = new JLabel();
|
||||
|
||||
WizardDisplayerImpl parent;
|
||||
|
||||
String failMessage = null;
|
||||
|
||||
boolean isUseBusy = false;
|
||||
|
||||
Container ipanel = null;
|
||||
|
||||
boolean isInitialized = false;
|
||||
@@ -55,18 +48,13 @@ public class NavProgress implements ResultProgressHandle {
|
||||
*/
|
||||
boolean isRunning = true;
|
||||
|
||||
NavProgress(WizardDisplayerImpl impl, boolean useBusy) {
|
||||
NavProgress(WizardDisplayerImpl impl) {
|
||||
this.parent = impl;
|
||||
isUseBusy = useBusy;
|
||||
}
|
||||
|
||||
public void addProgressComponents(Container panel) {
|
||||
panel.add(lbl);
|
||||
if (isUseBusy) {
|
||||
ensureBusyInitialized();
|
||||
panel.add(busy);
|
||||
} else
|
||||
panel.add(progressBar);
|
||||
panel.add(progressBar);
|
||||
isInitialized = true;
|
||||
ipanel = panel;
|
||||
}
|
||||
@@ -93,8 +81,6 @@ public class NavProgress implements ResultProgressHandle {
|
||||
progressBar.setMaximum(totalSteps);
|
||||
progressBar.setValue(currentStep);
|
||||
}
|
||||
|
||||
setUseBusy(false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -103,34 +89,9 @@ public class NavProgress implements ResultProgressHandle {
|
||||
lbl.setText(description == null ? " " : description);
|
||||
|
||||
progressBar.setIndeterminate(true);
|
||||
|
||||
setUseBusy(true);
|
||||
});
|
||||
}
|
||||
|
||||
protected void setUseBusy(boolean useBusy) {
|
||||
if (isInitialized)
|
||||
if (useBusy && (!isUseBusy)) {
|
||||
ipanel.remove(progressBar);
|
||||
ensureBusyInitialized();
|
||||
ipanel.add(busy);
|
||||
ipanel.invalidate();
|
||||
} else if (!useBusy && isUseBusy) {
|
||||
ipanel.remove(busy);
|
||||
ipanel.add(progressBar);
|
||||
ipanel.invalidate();
|
||||
}
|
||||
isUseBusy = useBusy;
|
||||
}
|
||||
|
||||
private void ensureBusyInitialized() {
|
||||
if (busy.getIcon() == null) {
|
||||
URL url = getClass().getResource("/org/jackhuang/hellominecraft/busy.gif");
|
||||
Icon icon = new ImageIcon(url);
|
||||
busy.setIcon(icon);
|
||||
}
|
||||
}
|
||||
|
||||
private void invoke(Runnable r) {
|
||||
if (EventQueue.isDispatchThread())
|
||||
r.run();
|
||||
|
||||
@@ -413,8 +413,8 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
|
||||
}
|
||||
|
||||
protected ResultProgressHandle createProgressDisplay(boolean isUseBusy) {
|
||||
return new NavProgress(this, isUseBusy);
|
||||
protected ResultProgressHandle createProgressDisplay() {
|
||||
return new NavProgress(this);
|
||||
}
|
||||
|
||||
void handleDeferredWizardResult(final DeferredWizardResult r, final boolean inSummary) {
|
||||
@@ -422,7 +422,7 @@ public class WizardDisplayerImpl extends WizardDisplayer {
|
||||
deferredResult = r;
|
||||
}
|
||||
wizardPanel.setEnabled(false);
|
||||
progress = createProgressDisplay(r.isUseBusy());
|
||||
progress = createProgressDisplay();
|
||||
Container inst = instructions.getComponent();
|
||||
progress.addProgressComponents(inst);
|
||||
inst.invalidate();
|
||||
|
||||
@@ -9,7 +9,7 @@ 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]" */
|
||||
|
||||
/*
|
||||
/*
|
||||
* DeferredWizardResult.java
|
||||
*
|
||||
* Created on September 24, 2006, 3:42 AM
|
||||
@@ -17,95 +17,84 @@ 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.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* Object which can be returned from
|
||||
* Object which can be returned from
|
||||
* <code>WizardPage.WizardResultProducer.finish()</code>
|
||||
* or <code>WizardPanelProvider.finish()</code>. A DeferredWizardResult does
|
||||
* not immediately calculate its result; it is used for cases where some
|
||||
* or <code>WizardPanelProvider.finish()</code>. A DeferredWizardResult does
|
||||
* not immediately calculate its result; it is used for cases where some
|
||||
* time consuming work needs to be performed to compute the result (such as
|
||||
* creating files on disk), and a progress bar should be shown until the work
|
||||
* is completed.
|
||||
*
|
||||
* @see org.jackhuang.hellominecraft.utils.views.wizard.spi.ResultProgressHandle
|
||||
*
|
||||
* @author Tim Boudreau
|
||||
*/
|
||||
public abstract class DeferredWizardResult {
|
||||
|
||||
private final boolean canAbort;
|
||||
private final boolean useBusy;
|
||||
/**
|
||||
* Creates a new instance of DeferredWizardResult which cannot be
|
||||
|
||||
/**
|
||||
* Creates a new instance of DeferredWizardResult which cannot be
|
||||
* aborted and shows a progress bar.
|
||||
*/
|
||||
public DeferredWizardResult() {
|
||||
useBusy = false;
|
||||
canAbort = false;
|
||||
}
|
||||
|
||||
/** Creates a new instance of DeferredWizardResult which may or may not
|
||||
* be able to be aborted.
|
||||
|
||||
/**
|
||||
* Creates a new instance of DeferredWizardResult which may or may not
|
||||
* be able to be aborted.
|
||||
*
|
||||
* @param canAbort determine if background computation can be aborted by
|
||||
* calling the <code>abort()</code> method
|
||||
* calling the <code>abort()</code> method
|
||||
*/
|
||||
public DeferredWizardResult (boolean canAbort) {
|
||||
public DeferredWizardResult(boolean canAbort) {
|
||||
this.canAbort = canAbort;
|
||||
this.useBusy = false;
|
||||
}
|
||||
|
||||
/** Creates a new instance of DeferredWizardResult which may or may not
|
||||
* be able to be aborted, and which may simply disable the wizard's UI
|
||||
* instead of showing a progress bar while the background work runs.
|
||||
*
|
||||
* @param canAbort
|
||||
* @param useBusy
|
||||
*/
|
||||
public DeferredWizardResult (boolean canAbort, boolean useBusy) {
|
||||
this.canAbort = canAbort;
|
||||
this.useBusy = useBusy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Begin computing the result. This method is called on a background
|
||||
|
||||
/**
|
||||
* Begin computing the result. This method is called on a background
|
||||
* thread, not the AWT event thread, and computation can immediately begin.
|
||||
* Use the progress handle to set progress as the work progresses.
|
||||
*
|
||||
* IMPORTANT: This method MUST call either progress.finished with the result,
|
||||
* or progress.failed with an error message. If this method returns without
|
||||
* Use the progress handle to set progress as the work progresses.
|
||||
*
|
||||
* IMPORTANT: This method MUST call either progress.finished with the
|
||||
* result,
|
||||
* or progress.failed with an error message. If this method returns without
|
||||
* calling either of those methods, it will be assumed to have failed.
|
||||
*
|
||||
*
|
||||
* @param settings The settings gathered over the course of the wizard
|
||||
* @param progress A handle which can be used to affect the progress bar.
|
||||
*/
|
||||
public abstract void start (Map settings, ResultProgressHandle progress);
|
||||
|
||||
public abstract void start(Map settings, ResultProgressHandle progress);
|
||||
|
||||
/**
|
||||
* If true, the background thread can be aborted. If it is possible to
|
||||
* If true, the background thread can be aborted. If it is possible to
|
||||
* abort, then the UI may allow the dialog to be closed while the result
|
||||
* is being computed.
|
||||
*/
|
||||
*/
|
||||
public final boolean canAbort() {
|
||||
return canAbort;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Abort computation of the result. This method will usually be called on
|
||||
* Abort computation of the result. This method will usually be called on
|
||||
* the event thread, after <code>start()<code> has been called, and before
|
||||
* <code>finished()</code> has been called on the <code>ResultProgressHandle</code>
|
||||
* <code>finished()</code> has been called on the
|
||||
* <code>ResultProgressHandle</code>
|
||||
* that is passed to <code>start()</code>, for example, if the user clicks
|
||||
* the close button on the dialog showing the wizard while the result is
|
||||
* being computed.
|
||||
* <p>
|
||||
* <b>This method does <i>nothing</i> by default</b> - it is left empty so
|
||||
* that people who do not want to support aborting background work do not
|
||||
* have to override it. It is up to the implementor
|
||||
* to set a flag or otherwise notify the background thread to halt
|
||||
* computation. A simple method for doing so is as follows:
|
||||
* have to override it. It is up to the implementor
|
||||
* to set a flag or otherwise notify the background thread to halt
|
||||
* computation. A simple method for doing so is as follows:
|
||||
* <pre>
|
||||
* volatile Thread thread;
|
||||
* public void start (Map settings, ResultProgressHandle handle) {
|
||||
@@ -113,8 +102,8 @@ public abstract class DeferredWizardResult {
|
||||
* synchronized (this) {
|
||||
* thread = Thread.currentThread();
|
||||
* }
|
||||
*
|
||||
* //do the background computation, update progress. Every so often,
|
||||
*
|
||||
* //do the background computation, update progress. Every so often,
|
||||
* //check Thread.interrupted() and exit if true
|
||||
* } finally {
|
||||
* synchronized (this) {
|
||||
@@ -122,31 +111,17 @@ public abstract class DeferredWizardResult {
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* public synchronized void abort() {
|
||||
* if (thread != null) thread.interrupt();
|
||||
* }
|
||||
* </pre>
|
||||
* or you can use a <code>volatile boolean</code> flag that you set in
|
||||
* <code>abort()</code> and periodically check in the body of <code>start()</code>.
|
||||
*
|
||||
*/
|
||||
* <code>abort()</code> and periodically check in the body of
|
||||
* <code>start()</code>.
|
||||
*
|
||||
*/
|
||||
public void abort() {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the UI should be completely disabled while the background
|
||||
* work is running (i.e. you do not want a progress bar, you just want all
|
||||
* navigation disabled [note on some window managers, the user will still
|
||||
* be able to click the dialog's window drag-bar close button, so you still
|
||||
* should override abort() to stop computation if possible]).
|
||||
*
|
||||
* @return true if no progress bar should be displayed and the UI should
|
||||
* just disable itself
|
||||
*/
|
||||
public final boolean isUseBusy()
|
||||
{
|
||||
return useBusy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,23 +5,22 @@ 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;
|
||||
|
||||
/**
|
||||
* Result class for the methods in WizardPanel.
|
||||
*
|
||||
*
|
||||
* For immediate action, one of the two constantants PROCEED or REMAIN_ON_PAGE
|
||||
* should be returned. Otherwise an instance of a subclass should be returned
|
||||
* should be returned. Otherwise an instance of a subclass should be returned
|
||||
* that computes a Boolean result.
|
||||
*
|
||||
*
|
||||
* @author stanley@stanleyknutson.com
|
||||
*/
|
||||
public abstract class WizardPanelNavResult extends DeferredWizardResult
|
||||
{
|
||||
public abstract class WizardPanelNavResult extends DeferredWizardResult {
|
||||
|
||||
/**
|
||||
* value for procced to next step in the wizard.
|
||||
*/
|
||||
@@ -31,59 +30,43 @@ public abstract class WizardPanelNavResult extends DeferredWizardResult
|
||||
*/
|
||||
public static final WizardPanelNavResult REMAIN_ON_PAGE = new WPNRimmediate(false);
|
||||
|
||||
public WizardPanelNavResult(boolean useBusy) {
|
||||
super (false, useBusy);
|
||||
private WizardPanelNavResult() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WizardPanelNavResult(boolean useBusy, boolean canAbort) {
|
||||
super (canAbort, useBusy);
|
||||
}
|
||||
|
||||
public WizardPanelNavResult() {
|
||||
super (false, false);
|
||||
}
|
||||
|
||||
public boolean isDeferredComputation()
|
||||
{
|
||||
public boolean isDeferredComputation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* internal class for the constants only
|
||||
*/
|
||||
private final static class WPNRimmediate extends WizardPanelNavResult
|
||||
{
|
||||
private final static class WPNRimmediate extends WizardPanelNavResult {
|
||||
|
||||
boolean value;
|
||||
|
||||
WPNRimmediate (boolean v)
|
||||
{
|
||||
|
||||
WPNRimmediate(boolean v) {
|
||||
value = v;
|
||||
}
|
||||
public boolean isDeferredComputation()
|
||||
{
|
||||
|
||||
public boolean isDeferredComputation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals (Object o)
|
||||
{
|
||||
if (o instanceof WPNRimmediate && ((WPNRimmediate)o).value == value)
|
||||
{
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof WPNRimmediate && ((WPNRimmediate) o).value == value)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
|
||||
public int hashCode() {
|
||||
return value ? 1 : 2;
|
||||
}
|
||||
|
||||
public void start(Map settings, ResultProgressHandle progress)
|
||||
{
|
||||
|
||||
public void start(Map settings, ResultProgressHandle progress) {
|
||||
// Should never get here, this is supposed to be immediate!
|
||||
throw new RuntimeException("Immediate result was called as deferral!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user