From f45c6c09f50d64216d996a2bbf84b9bc9a9cb68f Mon Sep 17 00:00:00 2001 From: slapshot5 Date: Sat, 10 Sep 2011 14:54:42 +0000 Subject: [PATCH] Checkstyle fixes in GuiUtils --- src/main/java/forge/gui/GuiUtils.java | 104 +++++++++++++++----------- 1 file changed, 59 insertions(+), 45 deletions(-) diff --git a/src/main/java/forge/gui/GuiUtils.java b/src/main/java/forge/gui/GuiUtils.java index 20286c2b761..bcd57d10269 100644 --- a/src/main/java/forge/gui/GuiUtils.java +++ b/src/main/java/forge/gui/GuiUtils.java @@ -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 components) { + public static void setWidthToMax(final Collection 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)); } @@ -147,17 +159,19 @@ public class GuiUtils { * @param is automatically inferred. * * @return null if choices is missing, empty, or if the users' - * choices are empty; otherwise, returns the first item in + * choices are empty; otherwise, returns the first item in * the List returned by getChoices. */ - public static T getChoiceOptional(String message, T... choices) { - if (choices == null || choices.length == 0) return null; + public static T getChoiceOptional(final String message, final T... choices) { + if (choices == null || choices.length == 0) { + return null; + } List 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 + * Like getChoiceOptional, but this takes an Iterator instead of a * variable number of arguments. * * @@ -166,21 +180,21 @@ public class GuiUtils { * @param is automatically inferred. * * @return null if choices is missing, empty, or if the users' - * choices are empty; otherwise, returns the first item in + * choices are empty; otherwise, returns the first item in * the List returned by getChoices. */ - public static T getChoiceOptional(String message, Iterator choices) { - if (choices == null | !choices.hasNext()) { - return null; - } + public static T getChoiceOptional(final String message, final Iterator 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); - - List choice = getChoices(message, 0, 1, choicesArray); + // TODO this is an expensive operation; it would be better to + // update getChoices to accept an Iterator. + T[] choicesArray = UtilFunctions.iteratorToArray(choices); + + List choice = getChoices(message, 0, 1, choicesArray); return choice.isEmpty() ? null : choice.get(0); - }//getChoiceOptional(String,Iterator) + } //getChoiceOptional(String,Iterator) // returned Object will never be null /** @@ -191,11 +205,11 @@ public class GuiUtils { * @param a T object. * @return a T object. */ - public static T getChoice(String message, T... choices) { + public static T getChoice(final String message, final T... choices) { List 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 a T object. * @return a {@link java.util.List} object. */ - public static List getChoicesOptional(String message, T... choices) { + public static List 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 a T object. * @return a {@link java.util.List} object. */ - public static List getChoices(String message, T... choices) { + public static List 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 a T object. * @return a {@link java.util.List} object. */ - public static List getChoices(String message, int min, int max, T... choices) { + public static List getChoices(final String message, final int min, final int max, final T... choices) { ListChooser c = new ListChooser(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();