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.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.ListSelectionListener;
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.io.File;
import java.util.Collection;
@@ -25,15 +33,19 @@ import java.util.List;
* @author Forge
* @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
* to the maximum of the collection
* to the maximum of the collection.
*
* @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;
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.
*/
public static void addExpandingHorizontalSpace(JPanel panel) {
public static void addExpandingHorizontalSpace(final JPanel panel) {
panel.add(Box.createHorizontalGlue());
}
/**
* Adds a Vertical Glue to panel
* Adds a Vertical Glue to panel.
*
* @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());
}
/**
* 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 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)));
}
/**
* 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.
*/
public static void addGap(JPanel panel) {
public static void addGap(final JPanel panel) {
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 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();
component.setFont(oldFont.deriveFont((float) newSize));
}
@@ -104,7 +116,7 @@ public class GuiUtils {
* @param iconName a {@link java.lang.String} 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 file = new File(base, iconName);
if (iconName.equals("") || !file.exists()) {
@@ -122,7 +134,7 @@ public class GuiUtils {
* @param height a int.
* @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));
}
@@ -133,7 +145,7 @@ public class GuiUtils {
* @param height a int.
* @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));
}
@@ -150,11 +162,13 @@ public class GuiUtils {
* choices are empty; otherwise, returns the first item in
* the List returned by getChoices.
*/
public static <T> T getChoiceOptional(String message, T... choices) {
if (choices == null || choices.length == 0) return null;
public static <T> T getChoiceOptional(final String message, final T... choices) {
if (choices == null || choices.length == 0) {
return null;
}
List<T> choice = getChoices(message, 0, 1, choices);
return choice.isEmpty() ? null : choice.get(0);
}//getChoiceOptional(String,T...)
} //getChoiceOptional(String,T...)
/**
* Like getChoiceOptional, but this takes an Iterator instead of a
@@ -169,18 +183,18 @@ public class GuiUtils {
* choices are empty; otherwise, returns the first item in
* the List returned by getChoices.
*/
public static <T> T getChoiceOptional(String message, Iterator<T> choices) {
if (choices == null | !choices.hasNext()) {
return null;
}
public static <T> T getChoiceOptional(final String message, final Iterator<T> choices) {
if (choices == null | !choices.hasNext()) {
return null;
}
// TODO: this is an expensive operation; it would be better to
// update getChoices to accept an Iterator.
T[] choicesArray = UtilFunctions.iteratorToArray(choices);
// TODO this is an expensive operation; it would be better to
// update getChoices to accept an Iterator.
T[] choicesArray = UtilFunctions.iteratorToArray(choices);
List<T> choice = getChoices(message, 0, 1, choicesArray);
List<T> choice = getChoices(message, 0, 1, choicesArray);
return choice.isEmpty() ? null : choice.get(0);
}//getChoiceOptional(String,Iterator<T>)
} //getChoiceOptional(String,Iterator<T>)
// returned Object will never be null
/**
@@ -191,11 +205,11 @@ public class GuiUtils {
* @param <T> 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);
assert choice.size() == 1;
return choice.get(0);
}//getChoice()
} //getChoice()
// returned Object will never be null
/**
@@ -206,9 +220,9 @@ public class GuiUtils {
* @param <T> a T 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);
}//getChoice()
} //getChoice()
// returned Object will never be null
/**
@@ -219,9 +233,9 @@ public class GuiUtils {
* @param <T> a T 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);
}//getChoice()
} //getChoice()
// returned Object will never be null
/**
@@ -234,11 +248,11 @@ public class GuiUtils {
* @param <T> a T 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);
final JList list = c.getJList();
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent ev) {
public void valueChanged(final ListSelectionEvent ev) {
if (list.getSelectedValue() instanceof Card && AllZone.getDisplay() != null) {
AllZone.getDisplay().setCard((Card) list.getSelectedValue());
}
@@ -246,14 +260,14 @@ public class GuiUtils {
});
c.show();
return c.getSelectedValues();
}//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
*/
public static void centerFrame(Frame frame) {
public static void centerFrame(final Frame frame) {
Dimension screen = frame.getToolkit().getScreenSize();
Rectangle bounds = frame.getBounds();
bounds.width = frame.getWidth();