FProgressBar created and applied to splash frame.

Various parts of preload process detailed in progress bar.

Further organization of FView to remove this-shouldn't-be-here stuff.
This commit is contained in:
Doublestrike
2012-01-22 01:21:00 +00:00
parent 7346601577
commit 47d647bc24
10 changed files with 349 additions and 514 deletions

3
.gitattributes vendored
View File

@@ -11113,8 +11113,6 @@ src/main/java/forge/view/editor/EditorTopLevel.java -text
src/main/java/forge/view/editor/package-info.java svneol=native#text/plain
src/main/java/forge/view/home/HomeTopLevel.java -text
src/main/java/forge/view/home/SplashFrame.java -text
src/main/java/forge/view/home/SplashProgressComponent.java -text
src/main/java/forge/view/home/SplashProgressModel.java -text
src/main/java/forge/view/home/StartButton.java -text
src/main/java/forge/view/home/SubButton.java -text
src/main/java/forge/view/home/ViewConstructed.java -text
@@ -11143,6 +11141,7 @@ src/main/java/forge/view/toolbox/FButton.java -text
src/main/java/forge/view/toolbox/FList.java -text
src/main/java/forge/view/toolbox/FOverlay.java -text
src/main/java/forge/view/toolbox/FPanel.java -text
src/main/java/forge/view/toolbox/FProgressBar.java -text
src/main/java/forge/view/toolbox/FRoundedPanel.java -text
src/main/java/forge/view/toolbox/FScrollPane.java -text
src/main/java/forge/view/toolbox/FSkin.java -text

View File

@@ -38,8 +38,6 @@ import java.util.zip.ZipFile;
import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.generator.FindNonDirectoriesSkipDotDirectoriesGenerator;
import net.slightlymagic.braids.util.generator.GeneratorFunctions;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import net.slightlymagic.braids.util.progress_monitor.StderrProgressMonitor;
import com.google.code.jyield.Generator;
import com.google.code.jyield.YieldUtils;
@@ -49,7 +47,7 @@ import forge.card.CardRulesReader;
import forge.card.replacement.ReplacementHandler;
import forge.card.trigger.TriggerHandler;
import forge.error.ErrorViewer;
import forge.view.FView;
import forge.view.toolbox.FProgressBar;
/**
* <p>
@@ -262,18 +260,7 @@ public class CardReader implements Runnable {
*/
protected final Card loadCardsUntilYouFind(final String cardName) {
Card result = null;
// Try to retrieve card loading progress monitor model.
// If no progress monitor present, output results to console.
BraidsProgressMonitor monitor = null;
final FView view = Singletons.getView();
if (view != null) {
monitor = view.getCardLoadingProgressMonitor();
}
if (monitor == null) {
monitor = new StderrProgressMonitor(1, 0L);
}
final FProgressBar barProgress = Singletons.getView().getProgressBar();
// Iterate through txt files or zip archive.
// Report relevant numbers to progress monitor model.
@@ -285,18 +272,19 @@ public class CardReader implements Runnable {
this.findNonDirsIterable = YieldUtils.toIterable(findNonDirsGen);
}
if (monitor != null) {
monitor.setTotalUnitsThisPhase(this.estimatedFilesRemaining);
if (barProgress != null) {
barProgress.setMaximum((int) this.estimatedFilesRemaining);
barProgress.setDescription("Preloading card images: ");
}
for (final File cardTxtFile : this.findNonDirsIterable) {
if (!cardTxtFile.getName().endsWith(CardReader.CARD_FILE_DOT_EXTENSION)) {
monitor.incrementUnitsCompletedThisPhase(1L);
barProgress.increment();
continue;
}
result = this.loadCard(cardTxtFile);
monitor.incrementUnitsCompletedThisPhase(1L);
barProgress.increment();
if ((cardName != null) && cardName.equals(result.getName())) {
break; // no thread leak here if entire card DB is loaded,
@@ -304,9 +292,8 @@ public class CardReader implements Runnable {
}
} // endfor
} else {
monitor.setTotalUnitsThisPhase(this.estimatedFilesRemaining);
barProgress.setMaximum((int) this.estimatedFilesRemaining);
ZipEntry entry;
// zipEnum was initialized in the constructor.
@@ -314,18 +301,17 @@ public class CardReader implements Runnable {
entry = this.zipEnum.nextElement();
if (entry.isDirectory() || !entry.getName().endsWith(CardReader.CARD_FILE_DOT_EXTENSION)) {
monitor.incrementUnitsCompletedThisPhase(1L);
barProgress.increment();
continue;
}
result = this.loadCard(entry);
monitor.incrementUnitsCompletedThisPhase(1L);
barProgress.increment();
if ((cardName != null) && cardName.equals(result.getName())) {
break;
}
}
} // endif
return result;

View File

@@ -22,14 +22,18 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.SwingUtilities;
import forge.AllZone;
import forge.Card;
import forge.CardReader;
import forge.Singletons;
import forge.card.CardRules;
import forge.error.ErrorViewer;
import forge.item.CardDb;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.view.toolbox.FProgressBar;
/**
* <p>
@@ -76,12 +80,25 @@ public class PreloadingCardFactory extends AbstractCardFactory {
try {
this.readCards(file);
final FProgressBar barProgress = Singletons.getView().getProgressBar();
if (barProgress != null) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
barProgress.reset();
barProgress.setDescription("Creating card objects: ");
}
});
}
// initialize CardList allCards
final Iterator<String> it = this.getMap().keySet().iterator();
if (barProgress != null) { barProgress.setMaximum(this.getMap().size()); }
Card c;
while (it.hasNext()) {
c = this.getCard(it.next().toString(), AllZone.getHumanPlayer());
this.getAllCards().add(c);
if (barProgress != null) { barProgress.increment(); }
}
} catch (final Exception ex) {
ErrorViewer.showError(ex);

View File

@@ -147,10 +147,11 @@ public class ControlSettings {
});
}
private void updateSkin() throws Exception {
private void updateSkin() {
String name = view.getLstChooseSkin().getSelectedValue().toString();
FSkin skin = new FSkin(name);
skin.loadFontAndImages();
skin.loadFontsAndImages();
prefs.setSkin(name);
Singletons.getView().setSkin(skin);

View File

@@ -20,16 +20,15 @@ package forge.view;
import javax.swing.SwingUtilities;
import net.slightlymagic.braids.util.UtilFunctions;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import forge.AllZone;
import forge.ComputerAIGeneral;
import forge.ComputerAIInput;
import forge.Constant;
import forge.control.FControl;
import forge.error.ErrorViewer;
import forge.game.GameType;
import forge.view.home.SplashFrame;
import forge.view.toolbox.CardFaceSymbols;
import forge.view.toolbox.FProgressBar;
import forge.view.toolbox.FSkin;
/**
@@ -39,6 +38,7 @@ import forge.view.toolbox.FSkin;
public class FView {
private transient SplashFrame splashFrame;
private FProgressBar barProgress = null;
private FSkin skin;
/**
@@ -55,7 +55,11 @@ public class FView {
UtilFunctions.invokeInEventDispatchThreadAndWait(new Runnable() {
@Override
public void run() {
FView.this.splashFrame = new SplashFrame(FView.this.skin);
try {
FView.this.splashFrame = new SplashFrame(FView.this.skin);
} catch (Exception e) {
e.printStackTrace();
}
}
});
@@ -68,20 +72,21 @@ public class FView {
}
/**
* Get the progress monitor for loading all cards at once.
* Allows singleton (global) access to a progress bar (which must be set first).
*
* @return a progress monitor having only one phase; may be null
*/
public final BraidsProgressMonitor getCardLoadingProgressMonitor() {
BraidsProgressMonitor result;
public final FProgressBar getProgressBar() {
return this.barProgress;
}
if (this.splashFrame == null) {
result = null;
} else {
result = this.splashFrame.getMonitorModel();
}
return result;
/**
* Sets a progress bar so it can be accessed via singletons.
*
* @param bar0 &emsp; An FProgressBar object
*/
public final void setProgressBar(FProgressBar bar0) {
this.barProgress = bar0;
}
/** @return FSkin */
@@ -89,10 +94,7 @@ public class FView {
return this.skin;
}
/**
* @param skin0
* &emsp; FSkin
*/
/** @param skin0 &emsp; FSkin */
public void setSkin(final FSkin skin0) {
this.skin = skin0;
}
@@ -102,42 +104,39 @@ public class FView {
* for initial display.
*/
public final void initialize() {
// For the following two blocks, check if user has cancelled
// SplashFrame.
// Note: Error thrown sometimes because log file cannot be accessed
if (!this.splashFrame.getSplashHasBeenClosed()) {
AllZone.getCardFactory(); // forces preloading of all cards
}
this.setProgressBar(splashFrame.getProgressBar());
if (!this.splashFrame.getSplashHasBeenClosed()) {
try {
// Preloads all cards (using progress bar).
AllZone.getCardFactory();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
FView.this.skin.loadFontAndImages();
// Preloads skin components (using progress bar).
FView.this.skin.loadFontsAndImages();
CardFaceSymbols.loadImages();
// Does not use progress bar, due to be deprecated in favor of skin.
CardFaceSymbols.loadImages();
Constant.Runtime.setGameType(GameType.Constructed);
barProgress.setDescription("Creating display components.");
final GuiTopLevel g = new GuiTopLevel();
AllZone.setDisplay(g);
g.getController().changeState(FControl.HOME_SCREEN);
g.pack();
g.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
FView.this.splashFrame.dispose();
// Enable only one of the following two lines.
// The second is useful for debugging.
FView.this.splashFrame = null;
// FView.this.splashFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
} catch (final Exception ex) {
ErrorViewer.showError(ex);
// TODO there must be a better place for this. ////////////
Constant.Runtime.setGameType(GameType.Constructed);
AllZone.getInputControl().setComputer(new ComputerAIInput(new ComputerAIGeneral()));
/////////////////////////////////////
final GuiTopLevel g = new GuiTopLevel();
AllZone.setDisplay(g);
g.getController().changeState(FControl.HOME_SCREEN);
g.pack();
FView.this.splashFrame.dispose();
FView.this.splashFrame = null;
barProgress.setDescription("Forge is ready to launch.");
g.setVisible(true);
}
} // End if(splashHasBeenClosed) */
});
} // End FView()
}

View File

@@ -20,10 +20,11 @@ package forge.view.home;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
@@ -33,10 +34,8 @@ import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
import forge.view.toolbox.FProgressBar;
import forge.view.toolbox.FSkin;
/**
@@ -44,8 +43,6 @@ import forge.view.toolbox.FSkin;
*/
@SuppressWarnings("serial")
public class SplashFrame extends JFrame {
// Inits: Visual changes can be made here.
private static final int BAR_PADDING_X = 20;
private static final int BAR_PADDING_Y = 20;
private static final int BAR_HEIGHT = 57;
@@ -55,65 +52,57 @@ public class SplashFrame extends JFrame {
private static final int DISCLAIMER_FONT_SIZE = 9;
private static final Color DISCLAIMER_COLOR = Color.white;
// private static final int CLOSEBTN_PADDING_X = 15;
private static final int CLOSEBTN_PADDING_Y = 15;
private static final int CLOSEBTN_SIDELENGTH = 15;
private static final Color CLOSEBTN_COLOR = new Color(215, 208, 188);
private SplashProgressModel monitorModel = null;
private SplashProgressComponent monitorView = null;
private boolean splashHasBeenClosed = false;
private final FProgressBar barLoader;
/**
* <p>
* Create the frame; this <strong>must</strong> be called from an event
* dispatch thread.
* </p>
*
* <!-- CheckStyle won't let me use at-throws. --> Throws
*
* @param skin
* the skin {@link IllegalStateException} if not called from an
* event dispatch thread.
* @param skin &emsp; An FSkin object, must be passed here since it hasn't
* been set in the view yet.
* @throws Exception {@link IllegalStateException} if not called from an
* event dispatch thread.
*/
public SplashFrame(final FSkin skin) {
public SplashFrame(final FSkin skin) throws Exception {
super();
if (!SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("SplashFrame() must be called from an event dispatch thread.");
throw new IllegalStateException(
"SplashFrame() must be called from an event dispatch thread.");
}
this.setUndecorated(true);
// Set preferred JFrame properties.
final ImageIcon bgIcon = skin.getIcon(FSkin.SkinProp.BG_SPLASH);
final int splashWidthPx = bgIcon.getIconWidth();
final int splashHeightPx = bgIcon.getIconHeight();
this.setUndecorated(true);
this.setMinimumSize(new Dimension(splashWidthPx, splashHeightPx));
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setIconImage(Toolkit.getDefaultToolkit().getImage("res/images/symbols-13/favicon.png"));
this.setTitle("Loading Forge...");
// Insert JPanel to hold content above background
final JPanel contentPane = new JPanel();
this.setContentPane(contentPane);
contentPane.setLayout(null);
final JPanel pnlContent = new JPanel();
this.setContentPane(pnlContent);
pnlContent.setLayout(null);
// Add disclaimer
final JLabel lblDisclaimer = new JLabel(
"<html><center>Forge is not affiliated in any way with Wizards of the Coast."
+ "<br>Forge is open source software, released under the GNU Public License.</center></html>");
final JLabel lblDisclaimer = new JLabel("<html><center>"
+ "Forge is not affiliated in any way with Wizards of the Coast."
+ "<br>Forge is open source software, released under"
+ "the GNU Public License.</center></html>");
lblDisclaimer.setBounds(0, SplashFrame.DISCLAIMER_TOP, splashWidthPx, SplashFrame.DISCLAIMER_HEIGHT);
lblDisclaimer.setFont(new Font("Tahoma", Font.PLAIN, SplashFrame.DISCLAIMER_FONT_SIZE));
lblDisclaimer.setHorizontalAlignment(SwingConstants.CENTER);
lblDisclaimer.setForeground(SplashFrame.DISCLAIMER_COLOR);
contentPane.add(lblDisclaimer);
pnlContent.add(lblDisclaimer);
// Add close button
final JButton btnClose = new JButton("X");
@@ -124,10 +113,10 @@ public class SplashFrame extends JFrame {
btnClose.setOpaque(false);
btnClose.setBackground(new Color(0, 0, 0));
btnClose.setFocusPainted(false);
contentPane.add(btnClose);
pnlContent.add(btnClose);
// Action handler: button hover effect
btnClose.addMouseListener(new java.awt.event.MouseAdapter() {
// Actions and listeners for close button (also mapped to ESC)
final MouseAdapter madClose = new MouseAdapter() {
@Override
public void mouseEntered(final java.awt.event.MouseEvent evt) {
btnClose.setBorder(BorderFactory.createLineBorder(Color.white));
@@ -139,104 +128,35 @@ public class SplashFrame extends JFrame {
btnClose.setBorder(BorderFactory.createLineBorder(SplashFrame.CLOSEBTN_COLOR));
btnClose.setForeground(SplashFrame.CLOSEBTN_COLOR);
}
});
};
// Action handler: button close
btnClose.addActionListener(new CloseAction());
final Action actClose = new AbstractAction() {
@Override
public void actionPerformed(final ActionEvent e) {
System.exit(0);
}
};
// Action handler: esc key close
contentPane.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escAction");
btnClose.addMouseListener(madClose);
btnClose.addActionListener(actClose);
pnlContent.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escAction");
pnlContent.getActionMap().put("escAction", actClose);
contentPane.getActionMap().put("escAction", new CloseAction());
// Set UI to color splash bar filled/unfilled states with skin colors
UIManager.put("ProgressBar.background", skin.getColor(FSkin.SkinProp.PRELOAD_EMPTY_BG));
UIManager.put("ProgressBar.selectionBackground", skin.getColor(FSkin.SkinProp.PRELOAD_EMPTY_TXT));
UIManager.put("ProgressBar.foreground", skin.getColor(FSkin.SkinProp.PRELOAD_FULL_BG));
UIManager.put("ProgressBar.selectionForeground", skin.getColor(FSkin.SkinProp.PRELOAD_FULL_TXT));
UIManager.put("ProgressBar.border", new LineBorder(skin.getColor(FSkin.SkinProp.CLR_THEME), 0));
// Instantiate model and view and tie together.
this.monitorModel = new SplashProgressModel();
this.monitorView = new SplashProgressComponent();
this.monitorModel.setCurrentView(this.monitorView);
this.monitorView.setCurrentModel(this.monitorModel);
// Add prog bar + message, bg image
this.monitorView.displayUpdate("Assembling file list...");
this.monitorView.setBounds(SplashFrame.BAR_PADDING_X, splashHeightPx - SplashFrame.BAR_PADDING_Y
barLoader = new FProgressBar();
barLoader.setString("Welcome to Forge.");
barLoader.setBounds(SplashFrame.BAR_PADDING_X, splashHeightPx - SplashFrame.BAR_PADDING_Y
- SplashFrame.BAR_HEIGHT, splashWidthPx - (2 * SplashFrame.BAR_PADDING_X), SplashFrame.BAR_HEIGHT);
contentPane.add(this.monitorView);
pnlContent.add(barLoader);
contentPane.setOpaque(false);
final JLabel bgLabel = new JLabel(bgIcon);
// Do not pass Integer.MIN_VALUE directly here; it must be packaged in
// an Integer instance. Otherwise, GUI components will not draw unless
// moused over.
this.getLayeredPane().add(bgLabel, Integer.valueOf(Integer.MIN_VALUE));
bgLabel.setBounds(0, 0, splashWidthPx, splashHeightPx);
pnlContent.add(bgLabel);
this.pack();
}
/**
* Getter for progress bar view.
*
* @return the SplashViewProgressMonitor progress bar used in the splash
* frame.
*/
public final SplashProgressComponent getMonitorView() {
return this.monitorView;
/** @return FProgressBar &emsp; The preloader. */
public final FProgressBar getProgressBar() {
return this.barLoader;
}
/**
* Getter for progress monitor model.
*
* @return the BraidsProgressMonitor model used in the splash frame.
*/
public final BraidsProgressMonitor getMonitorModel() {
return this.monitorModel;
}
/**
* Returns state of splash frame, to determine if GUI should continue
* loading.
*
* @return SplashHasBeenClosed boolean.
*/
public final boolean getSplashHasBeenClosed() {
return this.splashHasBeenClosed;
}
/**
* Sets state of splash frame, to determine if GUI should continue loading.
*
* @param neoState
* the new splash has been closed
*/
public final void setSplashHasBeenClosed(final boolean neoState) {
this.splashHasBeenClosed = neoState;
}
/**
* <p>
* closeAction
* </p>
* Closes the splash frame by toggling "has been closed" switch (to cancel
* preloading) and dispose() (to discard JFrame).
*
* @param splashHasBeenClosed
* boolean.
*/
private class CloseAction extends AbstractAction {
@Override
public void actionPerformed(final ActionEvent e) {
SplashFrame.this.setSplashHasBeenClosed(true);
SplashFrame.this.dispose();
}
}
}

View File

@@ -1,151 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* 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 forge.view.home;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
import net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor;
/**
* Swing component view, to be used with BaseProgressMonitor.
*
*/
@SuppressWarnings("serial")
public class SplashProgressComponent extends JProgressBar {
private BaseProgressMonitor currentModel;
private double completed;
private double total;
/**
* Constructor: Must be called from an event dispatch thread.
*
*/
public SplashProgressComponent() {
super();
if (!SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("must be called from within an event dispatch thread");
}
this.setString("");
this.setStringPainted(true);
}
/**
* Updates progress bar stripe and text with current state of model.
*
*/
public final void updateProgressBar() {
// Update bar "stripe"
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SplashProgressComponent.this.stripeUpdate();
}
});
// Update bar message
// Note: shouldUpdateUI() severely retards motion
// of the preloader, so is temporarily disabled.
// if (getCurrentModel().shouldUpdateUI()) {
if ((this.getCurrentModel().getNumPhases() > 1)) {
this.displayUpdate("Phase " + this.getCurrentModel().getCurrentPhase() + ". "
// + getUnitsCompletedSoFarThisPhase() + " units processed. "
// + "Overall: " + getTotalPercentCompleteAsString() +
// "% complete, "
+ "Overall ETA in " + this.getCurrentModel().getRelativeETAAsString(true) + ".");
} else {
this.displayUpdate(
// "Overall: " +
this.getCurrentModel().getUnitsCompletedSoFarThisPhase() + " units processed; "
// + "(" + getTotalPercentCompleteAsString() + "%); "
+ "ETA in " + this.getCurrentModel().getRelativeETAAsString(true) + ".");
}
// getCurrentModel().justUpdatedUI();
// }
if ((this.getCurrentModel().getCurrentPhase() == this.getCurrentModel().getNumPhases())
&& (this.getCurrentModel().getUnitsCompletedSoFarThisPhase() >= this.getCurrentModel()
.getTotalUnitsThisPhase())) {
this.displayUpdate("Done! Firing up the GUI...");
}
}
/**
* Shows the message inside the progress dialog; does not always work on all
* platforms.
*
* @param message
* the message to display
*/
public final void displayUpdate(final String message) {
final Runnable proc = new Runnable() {
@Override
public void run() {
SplashProgressComponent.this.setString(message);
SplashProgressComponent.this.getCurrentModel().justUpdatedUI();
}
};
if (SwingUtilities.isEventDispatchThread()) {
proc.run();
} else {
SwingUtilities.invokeLater(proc);
}
}
/**
* Moves the stripe inside the progress dialog.
*
*/
public final void stripeUpdate() {
this.completed = this.getCurrentModel().getUnitsCompletedSoFarThisPhase();
this.total = this.getCurrentModel().getTotalUnitsThisPhase();
this.setValue((int) Math.round(((int) this.completed / this.total) * 100));
}
/**
* Resets the stripe inside the progress dialog back to zero.
*
*/
public final void stripeReset() {
this.setValue(0);
}
/**
* Retrieves the model from which this component uses data.
*
* @param neoModel
* the new current model
*/
public final void setCurrentModel(final BaseProgressMonitor neoModel) {
this.currentModel = neoModel;
}
/**
* Sets model from which this component uses data.
*
* @return the current model
*/
public final BraidsProgressMonitor getCurrentModel() {
return this.currentModel;
}
}

View File

@@ -1,80 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* 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 forge.view.home;
import net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor;
/**
* Creates an instance of BaseProgressMonitor that is used in the splash frame.
*
* Not all mutators notify the view yet.
*
*/
public class SplashProgressModel extends BaseProgressMonitor {
private SplashProgressComponent currentView = null;
/**
* Constructor called with no arguments, indicating 1 phase and number of
* phase units assumed to be 1 also (can be updated later).
*
*/
public SplashProgressModel() {
super();
}
/*
* (non-Javadoc)
*
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#
* incrementUnitsCompletedThisPhase(long)
*/
/**
* Increment units completed this phase.
*
* @param numUnits
* long
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#incrementUnitsCompletedThisPhase(long)
*/
@Override
public final void incrementUnitsCompletedThisPhase(final long numUnits) {
super.incrementUnitsCompletedThisPhase(numUnits);
this.getCurrentView().updateProgressBar();
}
/**
* Gets view from which data is sent for display.
*
* @return the current view
*/
public final SplashProgressComponent getCurrentView() {
return this.currentView;
}
/**
* Sets view to which data is sent for display.
*
* @param neoView
* the new current view
*/
public final void setCurrentView(final SplashProgressComponent neoView) {
this.currentView = neoView;
}
}

View File

@@ -0,0 +1,116 @@
package forge.view.toolbox;
import java.util.Date;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
/**
* A simple progress bar component using the Forge skin.
*
* Can show
*
*/
public class FProgressBar extends JProgressBar {
private static final long serialVersionUID = 3479715871723156426L;
private int tempVal = 0;
private long startMillis = 0;
private long tempMillis = 0;
private float timePerUnit = 0;
private int eta = 0;
private boolean isIncrementing = false;
private int hours, minutes, seconds;
private String desc = "";
private String str = "";
private boolean showETA = true;
private boolean showCount = true;
/** */
public FProgressBar() {
super();
this.reset();
this.setStringPainted(true);
}
/** @param s0 &emsp; A description to prepend before statistics. */
public void setDescription(final String s0) {
this.desc = s0;
this.setString(s0);
}
/** */
public void increment() {
if (isIncrementing) { System.out.println("Rejected."); return; }
isIncrementing = true;
tempVal++;
this.setValue(tempVal);
str = desc;
if (showCount) { calculateCount(tempVal); }
if (showETA) { calculateETA(tempVal); }
updateString();
isIncrementing = false;
}
private void calculateCount(int v0) {
str += " " + v0 + " of " + this.getMaximum();
}
/** */
private void calculateETA(int v0) {
tempMillis = new Date().getTime();
timePerUnit = (tempMillis - startMillis) / (float) v0;
eta = (int) ((this.getMaximum() - v0) * timePerUnit) / 1000;
seconds = eta;
hours = seconds >= 3600 ? (seconds / 3600) : 0;
seconds = eta % 3600;
minutes = seconds >= 60 ? (seconds / 60) : 0;
seconds = eta % 60 + 1;
str += ", ETA " + String.format("%02d", hours) + ":"
+ String.format("%02d", minutes) + ":"
+ String.format("%02d", seconds);
}
private void updateString() {
this.setString(str);
}
/** Resets the various values required for this class. */
public void reset() {
if (!SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException(
"FProgressBar > reset() must be accessed from an event dispatch thread.");
}
this.setIndeterminate(true);
this.setValue(0);
this.tempVal = 0;
this.startMillis = new Date().getTime();
this.setIndeterminate(false);
this.setShowETA(true);
this.setShowCount(true);
}
/** @param b0 &emsp; Boolean, show the ETA statistic or not */
public void setShowETA(boolean b0) {
this.showETA = b0;
}
/** @return b0 &emsp; Boolean, show the ETA statistic or not */
public boolean isShowETA() {
return showETA;
}
/** @param b0 &emsp; Boolean, show the ETA statistic or not */
public void setShowCount(boolean b0) {
this.showCount = b0;
}
/** @return b0 &emsp; Boolean, show the ETA statistic or not */
public boolean isShowCount() {
return showCount;
}
}

View File

@@ -30,7 +30,11 @@ import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import forge.Singletons;
import forge.gui.GuiUtils;
/**
@@ -47,11 +51,6 @@ public class FSkin {
BG_TEXTURE, /** */
BG_MATCH, /** */
PRELOAD_EMPTY_BG, /** */
PRELOAD_EMPTY_TXT, /** */
PRELOAD_FULL_BG, /** */
PRELOAD_FULL_TXT, /** */
CLR_THEME, /** */
CLR_BORDERS, /** */
CLR_ZEBRA, /** */
@@ -135,13 +134,13 @@ public class FSkin {
private BufferedImage bimDefaultSprite;
private BufferedImage bimPreferredSprite;
private int preferredH, preferredW;
private FProgressBar barProgress;
/**
* FSkin constructor. No arguments, will generate default skin settings,
* fonts, and backgrounds.
* @throws IOException for splash image file
*/
public FSkin() throws IOException {
public FSkin() {
this("default");
}
@@ -169,11 +168,11 @@ public class FSkin {
this.setIcon(SkinProp.BG_SPLASH, img.getSubimage(0, 0, w, h - 100));
this.setColor(SkinProp.PRELOAD_EMPTY_BG, this.getColorFromPixel(img.getRGB(25, h - 75)));
this.setColor(SkinProp.PRELOAD_EMPTY_TXT, this.getColorFromPixel(img.getRGB(75, h - 75)));
this.setColor(SkinProp.PRELOAD_FULL_BG, this.getColorFromPixel(img.getRGB(25, h - 25)));
this.setColor(SkinProp.PRELOAD_FULL_TXT, this.getColorFromPixel(img.getRGB(75, h - 25)));
UIManager.put("ProgressBar.background", this.getColorFromPixel(img.getRGB(25, h - 75)));
UIManager.put("ProgressBar.selectionBackground", this.getColorFromPixel(img.getRGB(75, h - 75)));
UIManager.put("ProgressBar.foreground", this.getColorFromPixel(img.getRGB(25, h - 25)));
UIManager.put("ProgressBar.selectionForeground", this.getColorFromPixel(img.getRGB(75, h - 25)));
UIManager.put("ProgressBar.border", new LineBorder(Color.BLACK, 0));
} catch (final IOException e) {
System.err.println(this.notfound + preferredDir + FILE_SPLASH);
e.printStackTrace();
@@ -185,21 +184,34 @@ public class FSkin {
* collection of all symbols) and the preferred (which may be
* incomplete).
*
* Font must be present in the skin folder, and will not
* be replaced by default. The fonts are pre-derived
* in this method and saved in a HashMap for future access.
*
* Color swatches must be present in the preferred
* sprite, and will not be replaced by default.
*
* Background images must be present in skin folder,
* and will not be replaced by default.
*
* Font must be present in the skin folder, and will not
* be replaced by default. The fonts are pre-derived
* in this method and saved in a HashMap for future access.
*
* Icons, however, will be pulled from the two sprites. Obviously,
* preferred takes precedence over default, but if something is
* missing, the default picture is retrieved.
*/
public void loadFontAndImages() {
public void loadFontsAndImages() {
barProgress = Singletons.getView().getProgressBar();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
barProgress.reset();
barProgress.setShowETA(false);
barProgress.setDescription("Processing fonts and image sprites: ");
}
});
barProgress.setMaximum(57);
// Grab and test the two sprite files.
final File f1 = new File(defaultDir + FILE_SPRITE);
final File f2 = new File(preferredDir + FILE_SPRITE);
@@ -220,27 +232,27 @@ public class FSkin {
// Exceptions handled inside method.
this.font = GuiUtils.newFont(FILE_SKINS_DIR + preferredName + "/" + FILE_FONT);
plainFonts = new HashMap<Integer, Font>();
plainFonts.put(10, font.deriveFont(Font.PLAIN, 10));
plainFonts.put(11, font.deriveFont(Font.PLAIN, 11));
plainFonts.put(12, font.deriveFont(Font.PLAIN, 12));
plainFonts.put(13, font.deriveFont(Font.PLAIN, 13));
plainFonts.put(14, font.deriveFont(Font.PLAIN, 14));
plainFonts.put(15, font.deriveFont(Font.PLAIN, 15));
plainFonts.put(16, font.deriveFont(Font.PLAIN, 16));
plainFonts.put(18, font.deriveFont(Font.PLAIN, 18));
plainFonts.put(20, font.deriveFont(Font.PLAIN, 20));
plainFonts.put(22, font.deriveFont(Font.PLAIN, 22));
setFontAndIncrement(10);
setFontAndIncrement(11);
setFontAndIncrement(12);
setFontAndIncrement(13);
setFontAndIncrement(14);
setFontAndIncrement(15);
setFontAndIncrement(16);
setFontAndIncrement(18);
setFontAndIncrement(20);
setFontAndIncrement(22);
boldFonts = new HashMap<Integer, Font>();
boldFonts.put(12, font.deriveFont(Font.BOLD, 12));
boldFonts.put(14, font.deriveFont(Font.BOLD, 14));
boldFonts.put(16, font.deriveFont(Font.BOLD, 16));
boldFonts.put(18, font.deriveFont(Font.BOLD, 18));
boldFonts.put(20, font.deriveFont(Font.BOLD, 20));
setBoldFontAndIncrement(12);
setBoldFontAndIncrement(14);
setBoldFontAndIncrement(16);
setBoldFontAndIncrement(18);
setBoldFontAndIncrement(20);
italicFonts = new HashMap<Integer, Font>();
italicFonts.put(12, font.deriveFont(Font.ITALIC, 12));
italicFonts.put(14, font.deriveFont(Font.ITALIC, 14));
setItalicFontAndIncrement(12);
setItalicFontAndIncrement(14);
// Put various images into map (except sprite and splash).
// Exceptions handled inside method.
@@ -250,6 +262,7 @@ public class FSkin {
// Sprite
final File file = new File(preferredDir + FILE_SPRITE);
BufferedImage image;
try {
image = ImageIO.read(file);
@@ -260,61 +273,61 @@ public class FSkin {
this.setColor(SkinProp.CLR_ACTIVE, this.getColorFromPixel(image.getRGB(70, 90)));
this.setColor(SkinProp.CLR_INACTIVE, this.getColorFromPixel(image.getRGB(70, 110)));
this.setColor(SkinProp.CLR_TEXT, this.getColorFromPixel(image.getRGB(70, 130)));
this.setIcon(SkinProp.ICON_ZONE_HAND, 280, 40, 40, 40);
this.setIcon(SkinProp.ICON_ZONE_LIBRARY, 280, 0, 40, 40);
this.setIcon(SkinProp.ICON_ZONE_GRAVEYARD, 320, 0, 40, 40);
this.setIcon(SkinProp.ICON_ZONE_EXILE, 320, 40, 40, 40);
this.setIcon(SkinProp.ICON_ZONE_FLASHBACK, 280, 80, 40, 40);
this.setIcon(SkinProp.ICON_ZONE_POISON, 320, 80, 40, 40);
this.setIcon(SkinProp.ICON_MANA_BLACK, 360, 160, 40, 40);
this.setIcon(SkinProp.ICON_MANA_BLUE, 360, 200, 40, 40);
this.setIcon(SkinProp.ICON_MANA_RED, 400, 160, 40, 40);
this.setIcon(SkinProp.ICON_MANA_GREEN, 400, 200, 40, 40);
this.setIcon(SkinProp.ICON_MANA_WHITE, 440, 200, 40, 40);
this.setIcon(SkinProp.ICON_MANA_COLORLESS, 440, 240, 40, 40);
this.setIcon(SkinProp.ICON_DOCK_SETTINGS, 80, 640, 80, 80);
this.setIcon(SkinProp.ICON_DOCK_SHORTCUTS, 160, 640, 80, 80);
this.setIcon(SkinProp.ICON_DOCK_CONCEDE, 240, 640, 80, 80);
this.setIcon(SkinProp.ICON_DOCK_ENDTURN, 320, 640, 80, 80);
this.setIcon(SkinProp.ICON_DOCK_DECKLIST, 400, 640, 80, 80);
this.setIcon(SkinProp.IMG_LOGO, 480, 0, 200, 200);
this.setIcon(SkinProp.IMG_FAVICON, 0, 720, 80, 80);
this.setIcon(SkinProp.IMG_BTN_START_UP, 480, 200, 160, 80);
this.setIcon(SkinProp.IMG_BTN_START_OVER, 480, 280, 160, 80);
this.setIcon(SkinProp.IMG_BTN_START_DOWN, 480, 360, 160, 80);
this.setIcon(SkinProp.IMG_BTN_UP_LEFT, 80, 0, 40, 40);
this.setIcon(SkinProp.IMG_BTN_UP_CENTER, 120, 0, 1, 40);
this.setIcon(SkinProp.IMG_BTN_UP_RIGHT, 160, 0, 40, 40);
this.setIcon(SkinProp.IMG_BTN_OVER_LEFT, 80, 40, 40, 40);
this.setIcon(SkinProp.IMG_BTN_OVER_CENTER, 120, 40, 1, 40);
this.setIcon(SkinProp.IMG_BTN_OVER_RIGHT, 160, 40, 40, 40);
this.setIcon(SkinProp.IMG_BTN_DOWN_LEFT, 80, 80, 40, 40);
this.setIcon(SkinProp.IMG_BTN_DOWN_CENTER, 120, 80, 1, 40);
this.setIcon(SkinProp.IMG_BTN_DOWN_RIGHT, 160, 80, 40, 40);
this.setIcon(SkinProp.IMG_BTN_FOCUS_LEFT, 80, 120, 40, 40);
this.setIcon(SkinProp.IMG_BTN_FOCUS_CENTER, 120, 120, 1, 40);
this.setIcon(SkinProp.IMG_BTN_FOCUS_RIGHT, 160, 120, 40, 40);
this.setIcon(SkinProp.IMG_BTN_TOGGLE_LEFT, 80, 160, 40, 40);
this.setIcon(SkinProp.IMG_BTN_TOGGLE_CENTER, 120, 160, 1, 40);
this.setIcon(SkinProp.IMG_BTN_TOGGLE_RIGHT, 160, 160, 40, 40);
this.setIcon(SkinProp.IMG_BTN_DISABLED_LEFT, 80, 200, 40, 40);
this.setIcon(SkinProp.IMG_BTN_DISABLED_CENTER, 120, 200, 1, 40);
this.setIcon(SkinProp.IMG_BTN_DISABLED_RIGHT, 160, 200, 40, 40);
} catch (final IOException e) {
System.err.println(this.notfound + preferredDir + FILE_SPRITE);
e.printStackTrace();
}
this.setIconAndIncrement(SkinProp.ICON_ZONE_HAND, 280, 40, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_ZONE_LIBRARY, 280, 0, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_ZONE_GRAVEYARD, 320, 0, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_ZONE_EXILE, 320, 40, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_ZONE_FLASHBACK, 280, 80, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_ZONE_POISON, 320, 80, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_MANA_BLACK, 360, 160, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_MANA_BLUE, 360, 200, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_MANA_RED, 400, 160, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_MANA_GREEN, 400, 200, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_MANA_WHITE, 440, 200, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_MANA_COLORLESS, 440, 240, 40, 40);
this.setIconAndIncrement(SkinProp.ICON_DOCK_SETTINGS, 80, 640, 80, 80);
this.setIconAndIncrement(SkinProp.ICON_DOCK_SHORTCUTS, 160, 640, 80, 80);
this.setIconAndIncrement(SkinProp.ICON_DOCK_CONCEDE, 240, 640, 80, 80);
this.setIconAndIncrement(SkinProp.ICON_DOCK_ENDTURN, 320, 640, 80, 80);
this.setIconAndIncrement(SkinProp.ICON_DOCK_DECKLIST, 400, 640, 80, 80);
this.setIconAndIncrement(SkinProp.IMG_LOGO, 480, 0, 200, 200);
this.setIconAndIncrement(SkinProp.IMG_FAVICON, 0, 720, 80, 80);
this.setIconAndIncrement(SkinProp.IMG_BTN_START_UP, 480, 200, 160, 80);
this.setIconAndIncrement(SkinProp.IMG_BTN_START_OVER, 480, 280, 160, 80);
this.setIconAndIncrement(SkinProp.IMG_BTN_START_DOWN, 480, 360, 160, 80);
this.setIconAndIncrement(SkinProp.IMG_BTN_UP_LEFT, 80, 0, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_UP_CENTER, 120, 0, 1, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_UP_RIGHT, 160, 0, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_OVER_LEFT, 80, 40, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_OVER_CENTER, 120, 40, 1, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_OVER_RIGHT, 160, 40, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_DOWN_LEFT, 80, 80, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_DOWN_CENTER, 120, 80, 1, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_DOWN_RIGHT, 160, 80, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_FOCUS_LEFT, 80, 120, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_FOCUS_CENTER, 120, 120, 1, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_FOCUS_RIGHT, 160, 120, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_TOGGLE_LEFT, 80, 160, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_TOGGLE_CENTER, 120, 160, 1, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_TOGGLE_RIGHT, 160, 160, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_DISABLED_LEFT, 80, 200, 40, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_DISABLED_CENTER, 120, 200, 1, 40);
this.setIconAndIncrement(SkinProp.IMG_BTN_DISABLED_RIGHT, 160, 200, 40, 40);
}
/**
@@ -349,6 +362,20 @@ public class FSkin {
return plainFonts.get(size);
}
private void setFontAndIncrement(int size) {
plainFonts.put(size, font.deriveFont(Font.PLAIN, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setBoldFontAndIncrement(int size) {
boldFonts.put(size, font.deriveFont(Font.BOLD, size));
if (barProgress != null) { barProgress.increment(); }
}
private void setItalicFontAndIncrement(int size) {
italicFonts.put(size, font.deriveFont(Font.ITALIC, size));
if (barProgress != null) { barProgress.increment(); }
}
/**
* @param size - integer, pixel size
* @return {@link java.awt.font} font1
@@ -451,7 +478,7 @@ public class FSkin {
* @param w0 &emsp; Width of sub-image
* @param h0 &emsp; Height of sub-image
*/
public void setIcon(final SkinProp s0,
private void setIconAndIncrement(final SkinProp s0,
final int x0, final int y0, final int w0, final int h0) {
// Test if requested sub-image in inside bounds of preferred sprite.
// (Height and width of preferred sprite were set in loadFontAndImages.)
@@ -498,6 +525,7 @@ public class FSkin {
BufferedImage img = (exists ? bimPreferredSprite : bimDefaultSprite);
BufferedImage bi0 = img.getSubimage(x0, y0, w0, h0);
this.icons.put(s0, new ImageIcon(bi0));
if (barProgress != null) { barProgress.increment(); }
}
/**