Checkstyle fixes in GuiUtils

This commit is contained in:
slapshot5
2011-09-10 14:54:42 +00:00
parent 7e5c9f679e
commit f45c6c09f5

View File

@@ -5,13 +5,21 @@ import forge.Card;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import javax.swing.*; import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import net.slightlymagic.braids.util.UtilFunctions; import net.slightlymagic.braids.util.UtilFunctions;
import java.awt.*; import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
@@ -25,15 +33,19 @@ import java.util.List;
* @author Forge * @author Forge
* @version $Id$ * @version $Id$
*/ */
public class GuiUtils { public final class GuiUtils {
private GuiUtils() {
throw new AssertionError();
}
/** /**
* This method takes a collection of components and sets the width of each component * This method takes a collection of components and sets the width of each component
* to the maximum of the collection * to the maximum of the collection.
* *
* @param components a {@link java.util.Collection} object. * @param components a {@link java.util.Collection} object.
*/ */
public static void setWidthToMax(Collection<Component> components) { public static void setWidthToMax(final Collection<Component> components) {
int maxWidth = 0; int maxWidth = 0;
for (Component c : components) { for (Component c : components) {
@@ -51,49 +63,49 @@ public class GuiUtils {
} }
/** /**
* Adds a Horizontal Glue to panel * Adds a Horizontal Glue to panel.
* *
* @param panel a {@link javax.swing.JPanel} object. * @param panel a {@link javax.swing.JPanel} object.
*/ */
public static void addExpandingHorizontalSpace(JPanel panel) { public static void addExpandingHorizontalSpace(final JPanel panel) {
panel.add(Box.createHorizontalGlue()); panel.add(Box.createHorizontalGlue());
} }
/** /**
* Adds a Vertical Glue to panel * Adds a Vertical Glue to panel.
* *
* @param panel a {@link javax.swing.JPanel} object. * @param panel a {@link javax.swing.JPanel} object.
*/ */
public static void addExpandingVerticalSpace(JPanel panel) { public static void addExpandingVerticalSpace(final JPanel panel) {
panel.add(Box.createHorizontalGlue()); panel.add(Box.createHorizontalGlue());
} }
/** /**
* Adds a rigid area of size strutSize to panel * Adds a rigid area of size strutSize to panel.
* *
* @param panel a {@link javax.swing.JPanel} object. * @param panel a {@link javax.swing.JPanel} object.
* @param strutSize a int. * @param strutSize a int.
*/ */
public static void addGap(JPanel panel, int strutSize) { public static void addGap(final JPanel panel, final int strutSize) {
panel.add(Box.createRigidArea(new Dimension(strutSize, strutSize))); panel.add(Box.createRigidArea(new Dimension(strutSize, strutSize)));
} }
/** /**
* Adds a rigid area of size 5 to panel * Adds a rigid area of size 5 to panel.
* *
* @param panel a {@link javax.swing.JPanel} object. * @param panel a {@link javax.swing.JPanel} object.
*/ */
public static void addGap(JPanel panel) { public static void addGap(final JPanel panel) {
panel.add(Box.createRigidArea(new Dimension(5, 5))); panel.add(Box.createRigidArea(new Dimension(5, 5)));
} }
/** /**
* Sets the font size of a component * Sets the font size of a component.
* *
* @param component a {@link java.awt.Component} object. * @param component a {@link java.awt.Component} object.
* @param newSize a int. * @param newSize a int.
*/ */
public static void setFontSize(Component component, int newSize) { public static void setFontSize(final Component component, final int newSize) {
Font oldFont = component.getFont(); Font oldFont = component.getFont();
component.setFont(oldFont.deriveFont((float) newSize)); component.setFont(oldFont.deriveFont((float) newSize));
} }
@@ -104,7 +116,7 @@ public class GuiUtils {
* @param iconName a {@link java.lang.String} object. * @param iconName a {@link java.lang.String} object.
* @return a {@link javax.swing.ImageIcon} object. * @return a {@link javax.swing.ImageIcon} object.
*/ */
public static ImageIcon getIconFromFile(String iconName) { public static ImageIcon getIconFromFile(final String iconName) {
File base = ForgeProps.getFile(NewConstants.IMAGE_ICON); File base = ForgeProps.getFile(NewConstants.IMAGE_ICON);
File file = new File(base, iconName); File file = new File(base, iconName);
if (iconName.equals("") || !file.exists()) { if (iconName.equals("") || !file.exists()) {
@@ -122,7 +134,7 @@ public class GuiUtils {
* @param height a int. * @param height a int.
* @return a {@link javax.swing.ImageIcon} object. * @return a {@link javax.swing.ImageIcon} object.
*/ */
public static ImageIcon getResizedIcon(ImageIcon icon, int width, int height) { public static ImageIcon getResizedIcon(final ImageIcon icon, final int width, final int height) {
return new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH)); return new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
} }
@@ -133,7 +145,7 @@ public class GuiUtils {
* @param height a int. * @param height a int.
* @return a {@link javax.swing.ImageIcon} object. * @return a {@link javax.swing.ImageIcon} object.
*/ */
public static ImageIcon getEmptyIcon(int width, int height) { public static ImageIcon getEmptyIcon(final int width, final int height) {
return new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)); return new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB));
} }
@@ -150,8 +162,10 @@ public class GuiUtils {
* choices are empty; otherwise, returns the first item in * choices are empty; otherwise, returns the first item in
* the List returned by getChoices. * the List returned by getChoices.
*/ */
public static <T> T getChoiceOptional(String message, T... choices) { public static <T> T getChoiceOptional(final String message, final T... choices) {
if (choices == null || choices.length == 0) return null; if (choices == null || choices.length == 0) {
return null;
}
List<T> choice = getChoices(message, 0, 1, choices); List<T> choice = getChoices(message, 0, 1, choices);
return choice.isEmpty() ? null : choice.get(0); return choice.isEmpty() ? null : choice.get(0);
} //getChoiceOptional(String,T...) } //getChoiceOptional(String,T...)
@@ -169,12 +183,12 @@ public class GuiUtils {
* choices are empty; otherwise, returns the first item in * choices are empty; otherwise, returns the first item in
* the List returned by getChoices. * the List returned by getChoices.
*/ */
public static <T> T getChoiceOptional(String message, Iterator<T> choices) { public static <T> T getChoiceOptional(final String message, final Iterator<T> choices) {
if (choices == null | !choices.hasNext()) { if (choices == null | !choices.hasNext()) {
return null; return null;
} }
// TODO: this is an expensive operation; it would be better to // TODO this is an expensive operation; it would be better to
// update getChoices to accept an Iterator. // update getChoices to accept an Iterator.
T[] choicesArray = UtilFunctions.iteratorToArray(choices); T[] choicesArray = UtilFunctions.iteratorToArray(choices);
@@ -191,7 +205,7 @@ public class GuiUtils {
* @param <T> a T object. * @param <T> a T object.
* @return a T object. * @return a T object.
*/ */
public static <T> T getChoice(String message, T... choices) { public static <T> T getChoice(final String message, final T... choices) {
List<T> choice = getChoices(message, 1, 1, choices); List<T> choice = getChoices(message, 1, 1, choices);
assert choice.size() == 1; assert choice.size() == 1;
return choice.get(0); return choice.get(0);
@@ -206,7 +220,7 @@ public class GuiUtils {
* @param <T> a T object. * @param <T> a T object.
* @return a {@link java.util.List} object. * @return a {@link java.util.List} object.
*/ */
public static <T> List<T> getChoicesOptional(String message, T... choices) { public static <T> List<T> getChoicesOptional(final String message, final T... choices) {
return getChoices(message, 0, choices.length, choices); return getChoices(message, 0, choices.length, choices);
} //getChoice() } //getChoice()
@@ -219,7 +233,7 @@ public class GuiUtils {
* @param <T> a T object. * @param <T> a T object.
* @return a {@link java.util.List} object. * @return a {@link java.util.List} object.
*/ */
public static <T> List<T> getChoices(String message, T... choices) { public static <T> List<T> getChoices(final String message, final T... choices) {
return getChoices(message, 1, choices.length, choices); return getChoices(message, 1, choices.length, choices);
} //getChoice() } //getChoice()
@@ -234,11 +248,11 @@ public class GuiUtils {
* @param <T> a T object. * @param <T> a T object.
* @return a {@link java.util.List} object. * @return a {@link java.util.List} object.
*/ */
public static <T> List<T> getChoices(String message, int min, int max, T... choices) { public static <T> List<T> getChoices(final String message, final int min, final int max, final T... choices) {
ListChooser<T> c = new ListChooser<T>(message, min, max, choices); ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
final JList list = c.getJList(); final JList list = c.getJList();
list.addListSelectionListener(new ListSelectionListener() { list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent ev) { public void valueChanged(final ListSelectionEvent ev) {
if (list.getSelectedValue() instanceof Card && AllZone.getDisplay() != null) { if (list.getSelectedValue() instanceof Card && AllZone.getDisplay() != null) {
AllZone.getDisplay().setCard((Card) list.getSelectedValue()); AllZone.getDisplay().setCard((Card) list.getSelectedValue());
} }
@@ -249,11 +263,11 @@ public class GuiUtils {
} //getChoice() } //getChoice()
/** /**
* Centers a frame on the screen based on its current size * Centers a frame on the screen based on its current size.
* *
* @param frame a fully laid-out frame * @param frame a fully laid-out frame
*/ */
public static void centerFrame(Frame frame) { public static void centerFrame(final Frame frame) {
Dimension screen = frame.getToolkit().getScreenSize(); Dimension screen = frame.getToolkit().getScreenSize();
Rectangle bounds = frame.getBounds(); Rectangle bounds = frame.getBounds();
bounds.width = frame.getWidth(); bounds.width = frame.getWidth();