ImageLibrary.java

Index Score
net.sf.freecol.client.gui
FreeCol

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
SIZESize of the file in bytes
DOC_COMMENTNumber of javadoc comment lines
PARAMSNumber of formal parameter declarations
INTERFACE_COMPLEXITYInterface complexity
OPERANDSNumber of operands
DECL_COMMENTSComments in declarations
PROGRAM_LENGTHHalstead program length
COMMENTSComment lines
OPERATORSNumber of operators
EXITSProcedure exits
RETURNSNumber of return points from functions
UNIQUE_OPERANDSNumber of unique operands
LINESNumber of lines in the source file
PROGRAM_VOCABHalstead program vocabulary
LOGICAL_LINESNumber of statements
BLOCKSNumber of blocks
ELOCEffective lines of code
LOCLines of code
FUNCTIONSNumber of function declarations
CYCLOMATICCyclomatic complexity
JAVA0076JAVA0076 Use of magic number
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0173JAVA0173 Unused method parameter
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0031JAVA0031 Case statement not properly closed
COMPARISONSNumber of comparison operators
JAVA0034JAVA0034 Missing braces in if statement
JAVA0029JAVA0029 Private method not used
JAVA0130JAVA0130 Non-static method does not use instance fields
WHITESPACENumber of whitespace lines
JAVA0276JAVA0276 Unnecessary use of String constructor
UNIQUE_OPERATORSNumber of unique operators
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0160JAVA0160 Method does not throw specified exception
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0030JAVA0030 Private field not used
JAVA0287JAVA0287 Unnecessary null check
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0075JAVA0075 Method parameter hides field
JAVA0145JAVA0145 Tab character used in source file
/** * Copyright (C) 2002-2007 The FreeCol Team * * This file is part of FreeCol. * * FreeCol 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 2 of the License, or * (at your option) any later version. * * FreeCol 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 FreeCol. If not, see <http://www.gnu.org/licenses/>. */ package net.sf.freecol.client.gui; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Transparency; import java.awt.color.ColorSpace; import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.logging.Logger; import javax.swing.ImageIcon; import net.sf.freecol.FreeCol; import net.sf.freecol.client.gui.panel.ImageProvider; import net.sf.freecol.common.FreeColException; import net.sf.freecol.common.model.Colony; import net.sf.freecol.common.model.GoodsType; import net.sf.freecol.common.model.IndianSettlement; import net.sf.freecol.common.model.Nation; import net.sf.freecol.common.model.ResourceType; import net.sf.freecol.common.model.Settlement; import net.sf.freecol.common.model.Tension; import net.sf.freecol.common.model.Tile; import net.sf.freecol.common.model.TileType; import net.sf.freecol.common.model.Unit; import net.sf.freecol.common.model.UnitType; import net.sf.freecol.common.model.Map.Direction; import net.sf.freecol.common.model.Settlement.SettlementType; import net.sf.freecol.common.model.Unit.Role; import net.sf.freecol.common.resources.ResourceManager; /** * Holds various images that can be called upon by others in order to display * certain things. */ public final class ImageLibrary extends ImageProvider { private static final Logger logger = Logger.getLogger(ImageLibrary.class.getName()); public static final int RIVER_STYLES = 81; public static final String UNIT_SELECT = "unitSelect.image", DELETE = "delete.image", PLOWED = "model.improvement.Plow.image", TILE_TAKEN = "tileTaken.image", TILE_OWNED_BY_INDIANS = "nativeLand.image", LOST_CITY_RUMOUR = "lostCityRumour.image", DARKNESS = "halo.dark.image"; public static final int UNIT_BUTTON_WAIT = 0, UNIT_BUTTON_DONE = 1, UNIT_BUTTON_FORTIFY = 2, UNIT_BUTTON_SENTRY = 3, UNIT_BUTTON_CLEAR = 4, UNIT_BUTTON_PLOW = 5, UNIT_BUTTON_ROAD = 6, UNIT_BUTTON_BUILD = 7, UNIT_BUTTON_DISBAND = 8, UNIT_BUTTON_ZOOM_IN = 9, UNIT_BUTTON_ZOOM_OUT = 10, UNIT_BUTTON_COUNT = 11; private static final String path = new String("images/"), extension = new String(".png"), terrainDirectory = new String("terrain/"), tileName = new String("center"), borderName = new String("border"), unexploredDirectory = new String("unexplored/"), unexploredName = new String("unexplored"), riverDirectory = new String("river/"), riverName = new String("river"), unitButtonDirectory = new String("order-buttons/"), unitButtonName = new String("button"), settlementDirectory = new String("settlements/"), monarchDirectory = new String("monarch/"), coatOfArmsDirectory = new String("coat-of-arms/"); private final String dataDirectory; /** * A ArrayList of Image objects. */ private List<ImageIcon> rivers; private Map<Nation, ImageIcon> monarch; private Map<Nation, ImageIcon> coatOfArms; private EnumMap<SettlementType, Image> settlements; private Map<String, ImageIcon> terrain1, terrain2, overlay1, overlay2, forests, goods; private Map<String, ArrayList<ImageIcon>> border1, border2, coast1, coast2; // Holds the unit-order buttons private List<ArrayList<ImageIcon>> unitButtons; private EnumMap<Tension.Level, Image> alarmChips; private Map<Color, Image> colorChips; private Map<Color, Image> missionChips; private Map<Color, Image> expertMissionChips; /** * The scaling factor used when creating this * <code>ImageLibrary</code>. The value * <code>1</code> is used if this object is not * a result of a scaling operation. */ private final float scalingFactor; /** * The constructor to use. * * @throws FreeColException If one of the data files could not be found. */ public ImageLibrary() throws FreeColException { // This is the location of the data directory when running FreeCol // from its default location in the CVS repository. // dataDirectory = ""; // init(true); this(""); } /** * A constructor that takes a directory as FreeCol's home. * * @param freeColHome The home of the freecol files. * @throws FreeColException If one of the data files could not be found. */ public ImageLibrary(String freeColHome) throws FreeColException { this.scalingFactor = 1; // TODO: normally this check shouldn't be here. init(false) is the way // to go. if ("".equals(freeColHome)) { dataDirectory = "data/"; init(true); } else { dataDirectory = freeColHome; init(false); } } private ImageLibrary(String dataDirectory, float scalingFactor) { this.dataDirectory = dataDirectory; this.scalingFactor = scalingFactor; } /** * Performs all necessary init operations such as loading of data files. * * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net.sf.freecol/images. * @throws FreeColException If one of the data files could not be found. * */ private void init(boolean doLookup) throws FreeColException { GraphicsConfiguration gc = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); if (!ge.isHeadless()) { gc = ge.getDefaultScreenDevice() .getDefaultConfiguration(); } Class<FreeCol> resourceLocator = net.sf.freecol.FreeCol.class; loadTerrain(gc, resourceLocator, doLookup); loadForests(gc, resourceLocator, doLookup); loadRivers(gc, resourceLocator, doLookup); loadUnitButtons(gc, resourceLocator, doLookup); loadSettlements(gc, resourceLocator, doLookup); loadGoods(gc, resourceLocator, doLookup); loadMonarch(gc, resourceLocator, doLookup); loadCoatOfArms(gc, resourceLocator, doLookup); alarmChips = new EnumMap<Tension.Level, Image>(Tension.Level.class); colorChips = new HashMap<Color, Image>(); missionChips = new HashMap<Color, Image>(); expertMissionChips = new HashMap<Color, Image>(); } /** * Returns the scaling factor used when creating this ImageLibrary. * @return 1 unless {@link #getScaledImageLibrary} was used to create * this object. */ public float getScalingFactor() { return scalingFactor; } /** * Gets a scaled version of this <code>ImageLibrary</code>. * @param scalingFactor The factor used when scaling. 2 is twice * the size of the original images and 0.5 is half. * @return A new <code>ImageLibrary</code>. */ public ImageLibrary getScaledImageLibrary(float scalingFactor) throws FreeColException { ImageLibrary scaledLibrary = new ImageLibrary("", scalingFactor); scaledLibrary.rivers = scaleImages(rivers, scalingFactor); scaledLibrary.settlements = scaleImages(settlements, scalingFactor); //scaledLibrary.monarch = scaleImages(monarch); scaledLibrary.monarch = new HashMap<Nation, ImageIcon>(monarch); scaledLibrary.terrain1 = scaleImages(terrain1, scalingFactor); scaledLibrary.terrain2 = scaleImages(terrain2, scalingFactor); scaledLibrary.overlay1 = scaleImages(overlay1, scalingFactor); scaledLibrary.overlay2 = scaleImages(overlay2, scalingFactor); scaledLibrary.forests = scaleImages(forests, scalingFactor); scaledLibrary.goods = scaleImages(goods, scalingFactor); scaledLibrary.border1 = scaleImages2(border1, scalingFactor); scaledLibrary.border2 = scaleImages2(border2, scalingFactor); scaledLibrary.coast1 = scaleImages2(coast1, scalingFactor); scaledLibrary.coast2 = scaleImages2(coast2, scalingFactor); //scaledLibrary.unitButtons = scaleImages2(unitButtons); scaledLibrary.unitButtons = new ArrayList<ArrayList<ImageIcon>>(unitButtons); /* scaledLibrary.alarmChips = scaleChips(alarmChips, scalingFactor); scaledLibrary.colorChips = scaleChips(colorChips, scalingFactor); scaledLibrary.missionChips = scaleChips(missionChips, scalingFactor); scaledLibrary.expertMissionChips = scaleChips(expertMissionChips, scalingFactor); */ scaledLibrary.alarmChips = new EnumMap<Tension.Level, Image>(alarmChips); scaledLibrary.colorChips = new HashMap<Color, Image>(colorChips); scaledLibrary.missionChips = new HashMap<Color, Image>(missionChips); scaledLibrary.expertMissionChips = new HashMap<Color, Image>(expertMissionChips); return scaledLibrary; } public Image scaleImage(Image image, float scale) { return image.getScaledInstance(Math.round(image.getWidth(null) * scale), Math.round(image.getHeight(null) * scale), Image.SCALE_SMOOTH); } public ImageIcon scaleIcon(ImageIcon icon, float scale) { return new ImageIcon(scaleImage(icon.getImage(), scale)); } private EnumMap<SettlementType, Image> scaleImages(EnumMap<SettlementType, Image> input, float scale) { EnumMap<SettlementType, Image> result = new EnumMap<SettlementType, Image>(SettlementType.class); for (Entry<SettlementType, Image> entry : input.entrySet()) { result.put(entry.getKey(), scaleImage(entry.getValue(), scale)); } return result; } private Map<Color, Image> scaleChips(Map<Color, Image> input, float scale) { HashMap<Color, Image> output = new HashMap<Color, Image>(); for (Entry<Color, Image> entry : input.entrySet()) { output.put(entry.getKey(), scaleImage(entry.getValue(), scale)); } return output; } private Map<String, ImageIcon> scaleImages(Map<String, ImageIcon> input, float scale) { HashMap<String, ImageIcon> output = new HashMap<String, ImageIcon>(); for (Entry<String, ImageIcon> entry : input.entrySet()) { output.put(entry.getKey(), scaleIcon(entry.getValue(), scale)); } return output; } private ArrayList<ImageIcon> scaleImages(List<ImageIcon> input, float scale) { ArrayList<ImageIcon> output = new ArrayList<ImageIcon>(); for (ImageIcon icon : input) { if (icon == null) { output.add(null); } else { output.add(scaleIcon(icon, scale)); } } return output; } private Map<String, ArrayList<ImageIcon>> scaleImages2(Map<String, ArrayList<ImageIcon>> input, float scale) { HashMap<String, ArrayList<ImageIcon>> output = new HashMap<String, ArrayList<ImageIcon>>(); for (Entry<String, ArrayList<ImageIcon>> entry : input.entrySet()) { if (entry.getValue() == null) { output.put(entry.getKey(), null); } else { output.put(entry.getKey(), scaleImages(entry.getValue(), scale)); } } return output; } private ArrayList<ArrayList<ImageIcon>> scaleImages2(ArrayList<ArrayList<ImageIcon>> input, float scale) { ArrayList<ArrayList<ImageIcon>> output = new ArrayList<ArrayList<ImageIcon>>(); for (ArrayList<ImageIcon> list : input) { if (list == null) { output.add(null); } else { output.add(scaleImages(list, scale)); } } return output; } private EnumMap<Role, Map<UnitType, ImageIcon>> scaleUnitImages(EnumMap<Role, Map<UnitType, ImageIcon>> input, float f) { EnumMap<Role, Map<UnitType, ImageIcon>> result = new EnumMap<Role, Map<UnitType, ImageIcon>>(Role.class); for (Role role : Role.values()) { Map<UnitType, ImageIcon> oldMap = input.get(role); Map<UnitType, ImageIcon> newMap = new HashMap<UnitType, ImageIcon>(); for (Entry<UnitType, ImageIcon> entry : oldMap.entrySet()) { ImageIcon oldIcon = entry.getValue(); ImageIcon newIcon = new ImageIcon(oldIcon.getImage() .getScaledInstance(Math.round(oldIcon.getIconWidth() * f), Math.round(oldIcon.getIconHeight() * f), Image.SCALE_SMOOTH)); newMap.put(entry.getKey(), newIcon); } result.put(role, newMap); } return result; } /** * Finds the image file in the given <code>filePath</code>. * * @param filePath The path to the image file. * @param doLookup If <i>true</i> then the <code>resourceLocator</code> * is used when searching for the image file. * @return An ImageIcon with data loaded from the image file. * @exception FreeColException If the image could not be found. */ private ImageIcon findImage(String filePath, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { if (doLookup) { URL url = resourceLocator.getResource(filePath); if (url != null) { return new ImageIcon(url); } } File tmpFile = new File(filePath); if ((tmpFile == null) || !tmpFile.exists() || !tmpFile.isFile() || !tmpFile.canRead()) { throw new FreeColException("The data file \"" + filePath + "\" could not be found."); } return new ImageIcon(filePath); } /** * Loads the terrain-images from file into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net.sf.freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadTerrain(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { terrain1 = new HashMap<String, ImageIcon>(); terrain2 = new HashMap<String, ImageIcon>(); overlay1 = new HashMap<String, ImageIcon>(); overlay2 = new HashMap<String, ImageIcon>(); border1 = new HashMap<String, ArrayList<ImageIcon>>(); border2 = new HashMap<String, ArrayList<ImageIcon>>(); coast1 = new HashMap<String, ArrayList<ImageIcon>>(); coast2 = new HashMap<String, ArrayList<ImageIcon>>(); for (TileType type : FreeCol.getSpecification().getTileTypeList()) { String filePath = dataDirectory + path + type.getArtBasic() + tileName; terrain1.put(type.getId(), findImage(filePath + "0" + extension, resourceLocator, doLookup)); terrain2.put(type.getId(), findImage(filePath + "1" + extension, resourceLocator, doLookup)); if (type.getArtOverlay() != null) { filePath = dataDirectory + path + type.getArtOverlay(); overlay1.put(type.getId(), findImage(filePath + "0" + extension, resourceLocator, doLookup)); overlay2.put(type.getId(), findImage(filePath + "1" + extension, resourceLocator, doLookup)); } ArrayList<ImageIcon> tempArrayList1 = new ArrayList<ImageIcon>(); ArrayList<ImageIcon> tempArrayList2 = new ArrayList<ImageIcon>(); for (Direction direction : Direction.values()) { filePath = dataDirectory + path + type.getArtBasic() + borderName + "_" + direction.toString(); tempArrayList1.add(findImage(filePath + "_even" + extension, resourceLocator, doLookup)); tempArrayList2.add(findImage(filePath + "_odd" + extension, resourceLocator, doLookup)); } border1.put(type.getId(), tempArrayList1); border2.put(type.getId(), tempArrayList2); if (type.getArtCoast() != null) { tempArrayList1 = new ArrayList<ImageIcon>(); tempArrayList2 = new ArrayList<ImageIcon>(); for (Direction direction : Direction.values()) { filePath = dataDirectory + path + type.getArtCoast() + borderName + "_" + direction.toString(); tempArrayList1.add(findImage(filePath + "_even" + extension, resourceLocator, doLookup)); tempArrayList2.add(findImage(filePath + "_odd" + extension, resourceLocator, doLookup)); } coast1.put(type.getId(), tempArrayList1); coast2.put(type.getId(), tempArrayList2); } } String unexploredPath = dataDirectory + path + terrainDirectory + unexploredDirectory + tileName; terrain1.put(unexploredName, findImage(unexploredPath + "0" + extension, resourceLocator, doLookup)); terrain2.put(unexploredName, findImage(unexploredPath + "1" + extension, resourceLocator, doLookup)); ArrayList<ImageIcon> unexploredArrayList1 = new ArrayList<ImageIcon>(); ArrayList<ImageIcon> unexploredArrayList2 = new ArrayList<ImageIcon>(); for (Direction direction : Direction.values()) { unexploredPath = dataDirectory + path + terrainDirectory + unexploredDirectory + borderName + "_" + direction.toString(); unexploredArrayList1.add(findImage(unexploredPath + "_even" + extension, resourceLocator, doLookup)); unexploredArrayList2.add(findImage(unexploredPath + "_odd" + extension, resourceLocator, doLookup)); } border1.put(unexploredName, unexploredArrayList1); border2.put(unexploredName, unexploredArrayList2); } /** * Loads the river images from file into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net.sf.freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadRivers(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { rivers = new ArrayList<ImageIcon>(RIVER_STYLES); for (int i = 0; i < RIVER_STYLES; i++) { String filePath = dataDirectory + path + riverDirectory + riverName + i + extension; rivers.add(findImage(filePath, resourceLocator, doLookup)); } } /** * Loads the forest images from file into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net.sf.freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadForests(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { forests = new HashMap<String, ImageIcon>(); for (TileType type : FreeCol.getSpecification().getTileTypeList()) { if (type.getArtForest() != null) { String filePath = dataDirectory + path + type.getArtForest(); forests.put(type.getId(), findImage(filePath, resourceLocator, doLookup)); } } } /** * Loads the unit-order buttons from files into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net.sf.freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadUnitButtons(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { unitButtons = new ArrayList<ArrayList<ImageIcon>>(4); for (int i = 0; i < 4; i++) { unitButtons.add(new ArrayList<ImageIcon>(UNIT_BUTTON_COUNT)); } for (int i = 0; i < 4; i++) { String subDirectory; switch (i) { case 0: subDirectory = new String("order-buttons00/"); break; case 1: subDirectory = new String("order-buttons01/"); break; case 2: subDirectory = new String("order-buttons02/"); break; case 3: subDirectory = new String("order-buttons03/"); break; default: subDirectory = new String(""); break; } for (int j = 0; j < UNIT_BUTTON_COUNT; j++) { String filePath = dataDirectory + path + unitButtonDirectory + subDirectory + unitButtonName + j + extension; unitButtons.get(i).add(findImage(filePath, resourceLocator, doLookup)); } } } /** * Loads the colony pictures from files into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net.sf.freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadSettlements(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { settlements = new EnumMap<SettlementType, Image>(SettlementType.class); for (SettlementType settlementType : SettlementType.values()) { String filePath = dataDirectory + path + settlementDirectory + settlementType.toString().toLowerCase() + extension; settlements.put(settlementType, findImage(filePath, resourceLocator, doLookup).getImage()); } } /** * Loads the goods-images from file into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net/sf/freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadGoods(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { goods = new HashMap<String, ImageIcon>(); for (GoodsType type : FreeCol.getSpecification().getGoodsTypeList()) { String filePath = dataDirectory + path + type.getArt(); goods.put(type.getId(), findImage(filePath, resourceLocator, doLookup)); } /* * If all units are patched together in one graphics file then this is * the way to load them into different images: * * Image unitsImage = new ImageIcon(url).getImage(); BufferedImage * tempImage = gc.createCompatibleImage(42, 63, * Transparency.TRANSLUCENT); * tempImage.getGraphics().drawImage(unitsImage, 0, 0, null); * units.add(tempImage); */ } /** * Loads the monarch-images from file into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net/sf/freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadMonarch(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { monarch = new HashMap<Nation, ImageIcon>(); for (Nation nation : FreeCol.getSpecification().getNations()) { String monarchName = nation.getMonarchArt(); String filePath = dataDirectory + path + monarchDirectory + monarchName; monarch.put(nation, findImage(filePath, resourceLocator, doLookup)); } } /** * Loads the coat-of-arms images from file into memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param resourceLocator The class that is used to locate data files. * @param doLookup Must be set to 'false' if the path to the image files has * been manually provided by the user. If set to 'true' then a * lookup will be done to search for image files from * net.sf.freecol, in this case the images need to be placed in * net/sf/freecol/images. * @throws FreeColException If one of the data files could not be found. */ private void loadCoatOfArms(GraphicsConfiguration gc, Class<FreeCol> resourceLocator, boolean doLookup) throws FreeColException { coatOfArms = new HashMap<Nation, ImageIcon>(); for (Nation nation : FreeCol.getSpecification().getNations()) { String coatOfArmsName = nation.getCoatOfArms(); String filePath = dataDirectory + path + coatOfArmsDirectory + coatOfArmsName; coatOfArms.put(nation, findImage(filePath, resourceLocator, doLookup)); } } /** * Generates a color chip image and stores it in memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param c The color of the color chip to create. */ private void loadColorChip(GraphicsConfiguration gc, Color c) { BufferedImage tempImage = gc.createCompatibleImage(11, 17); Graphics g = tempImage.getGraphics(); if (c.equals(Color.BLACK)) { g.setColor(Color.WHITE); } else { g.setColor(Color.BLACK); } g.drawRect(0, 0, 10, 16); g.setColor(c); g.fillRect(1, 1, 9, 15); colorChips.put(c, tempImage); } /** * Generates a mission chip image and stores it in memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param c The color of the color chip to create. * @param expertMission Should be <code>true</code> if the mission chip * should represent an expert missionary. */ private void loadMissionChip(GraphicsConfiguration gc, Color c, boolean expertMission) { BufferedImage tempImage = gc.createCompatibleImage(10, 17); Graphics2D g = (Graphics2D) tempImage.getGraphics(); if (expertMission) { g.setColor(Color.BLACK); } else { g.setColor(Color.DARK_GRAY); } g.fillRect(0, 0, 10, 17); GeneralPath cross = new GeneralPath(GeneralPath.WIND_EVEN_ODD); cross.moveTo(4, 1); cross.lineTo(6, 1); cross.lineTo(6, 4); cross.lineTo(9, 4); cross.lineTo(9, 6); cross.lineTo(6, 6); cross.lineTo(6, 16); cross.lineTo(4, 16); cross.lineTo(4, 6); cross.lineTo(1, 6); cross.lineTo(1, 4); cross.lineTo(4, 4); cross.closePath(); if (expertMission && c.equals(Color.BLACK)) { g.setColor(Color.DARK_GRAY); } else if ((!expertMission) && c.equals(Color.DARK_GRAY)) { g.setColor(Color.BLACK); } else { g.setColor(c); } g.fill(cross); if (expertMission) { expertMissionChips.put(c, tempImage); } else { missionChips.put(c, tempImage); } } /** * Generates a alarm chip image and stores it in memory. * * @param gc The GraphicsConfiguration is needed to create images that are * compatible with the local environment. * @param alarm The alarm level. */ private void loadAlarmChip(GraphicsConfiguration gc, Tension.Level alarm) { BufferedImage tempImage = gc.createCompatibleImage(10, 17); Graphics2D g = (Graphics2D) tempImage.getGraphics(); g.setColor(Color.BLACK); g.drawRect(0, 0, 10, 16); switch(alarm) { case HAPPY: g.setColor(Color.GREEN); break; case CONTENT: g.setColor(Color.BLUE); break; case DISPLEASED: g.setColor(Color.YELLOW); break; case ANGRY: g.setColor(Color.ORANGE); break; case HATEFUL: g.setColor(Color.RED); break; } g.fillRect(1, 1, 8, 15); g.setColor(Color.BLACK); g.fillRect(4, 3, 2, 7); g.fillRect(4, 12, 2, 2); alarmChips.put(alarm, tempImage); } /** * Returns the monarch-image for the given tile. * * @param nation The nation this monarch rules. * @return the monarch-image for the given nation. */ public Image getMonarchImage(Nation nation) { return monarch.get(nation).getImage(); } /** * Returns the monarch-image icon for the given Nation. * * @param nation The nation this monarch rules. * @return the monarch-image for the given nation. */ public ImageIcon getMonarchImageIcon(Nation nation) { return monarch.get(nation); } /** * Returns the coat-of-arms image for the given Nation. * * @param nation The nation. * @return the coat-of-arms of this nation */ public ImageIcon getCoatOfArmsImageIcon(Nation nation) { return coatOfArms.get(nation); } /** * Returns the coat-of-arms image for the given Nation. * * @param nation The nation. * @return the coat-of-arms of this nation */ public Image getCoatOfArmsImage(Nation nation) { return coatOfArms.get(nation).getImage(); } /** * Returns the bonus-image for the given tile. * * @param tile * @return the bonus-image for the given tile. */ public Image getBonusImage(Tile tile) { if (tile.hasResource()) { return getBonusImage(tile.getTileItemContainer().getResource().getType()); } else { return null; } } public Image getBonusImage(ResourceType type) { return ResourceManager.getImage(type.getId() + ".image", scalingFactor); } /** * Returns the bonus-ImageIcon at the given index. * * @param type The type of the bonus-ImageIcon to return. */ public ImageIcon getBonusImageIcon(ResourceType type) { return new ImageIcon(getBonusImage(type)); } public ImageIcon getScaledBonusImageIcon(ResourceType type, float scale) { return getScaledImageIcon(getBonusImageIcon(type), scale); } /** * Converts an image to grayscale * * @param image Source image to convert * @return The image in grayscale */ private ImageIcon convertToGrayscale(Image image) { int width = image.getWidth(null); int height = image.getHeight(null); ColorConvertOp filter = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); BufferedImage srcImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); srcImage.createGraphics().drawImage(image, 0, 0, null); return new ImageIcon(filter.filter(srcImage, null)); } /** * Returns the scaled terrain-image for a terrain type (and position 0, 0). * * @param type The type of the terrain-image to return. * @param scale The scale of the terrain image to return. * @return The terrain-image */ public Image getScaledTerrainImage(TileType type, float scale) { // Index used for drawing the base is the artBasic value GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Image terrainImage = getTerrainImage(type, 0, 0); int width = getTerrainImageWidth(type); int height = getTerrainImageHeight(type); // Currently used for hills and mountains if (type.getArtOverlay() != null) { BufferedImage compositeImage = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT); Graphics2D g = compositeImage.createGraphics(); g.drawImage(terrainImage, 0, 0, null); g.drawImage(getOverlayImage(type, 0, 0), 0, 0, null); g.dispose(); terrainImage = compositeImage; } if (type.isForested()) { BufferedImage compositeImage = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT); Graphics2D g = compositeImage.createGraphics(); g.drawImage(terrainImage, 0, 0, null); g.drawImage(getForestImage(type), 0, 0, null); g.dispose(); terrainImage = compositeImage; } if (scale == 1f) { return terrainImage; } else { return terrainImage.getScaledInstance((int) (width * scale), (int) (height * scale), Image.SCALE_SMOOTH); } } /** * Returns the overlay-image for the given type. * * @param type The type of the terrain-image to return. * @param x The x-coordinate of the location of the tile that is being * drawn. * @param y The x-coordinate of the location of the tile that is being * drawn. * @return The terrain-image at the given index. */ public Image getOverlayImage(TileType type, int x, int y) { if ((x + y) % 2 == 0) { return overlay1.get(type.getId()).getImage(); } else { return overlay2.get(type.getId()).getImage(); } } /** * Returns the terrain-image for the given type. * * @param type The type of the terrain-image to return. * @param x The x-coordinate of the location of the tile that is being * drawn. * @param y The x-coordinate of the location of the tile that is being * drawn. * @return The terrain-image at the given index. */ public Image getTerrainImage(TileType type, int x, int y) { String key; if (type != null) { key = type.getId(); } else { key = unexploredName; } if ((x + y) % 2 == 0) { return terrain1.get(key).getImage(); } else { return terrain2.get(key).getImage(); } } /** * Returns the border terrain-image for the given type. * * @param type The type of the terrain-image to return. * @param direction a <code>Direction</code> value * @param x The x-coordinate of the location of the tile that is being * drawn. * @param y The x-coordinate of the location of the tile that is being * drawn. * @return The terrain-image at the given index. */ public Image getBorderImage(TileType type, Direction direction, int x, int y) { int borderType = direction.ordinal(); String key; if (type != null) { key = type.getId(); } else { key = unexploredName; } if ((x + y) % 2 == 0) { return border1.get(key).get(borderType).getImage(); } else { return border2.get(key).get(borderType).getImage(); } } /** * Returns the coast terrain-image for the given type. * * @param type The type of the terrain-image to return. * @param direction a <code>Direction</code> value * @param x The x-coordinate of the location of the tile that is being * drawn. * @param y The x-coordinate of the location of the tile that is being * drawn. * @return The terrain-image at the given index. */ public Image getCoastImage(TileType type, Direction direction, int x, int y) { int borderType = direction.ordinal(); String key; if (type != null) { key = type.getId(); } else { key = unexploredName; } if ((x + y) % 2 == 0) { return coast1.get(key).get(borderType).getImage(); } else { return coast2.get(key).get(borderType).getImage(); } } /** * Returns the river image at the given index. * * @param index The index of the image to return. * @return The image at the given index. */ public Image getRiverImage(int index) { return rivers.get(index).getImage(); } /** * Returns the forest image for a terrain type. * * @param type The type of the terrain-image to return. * @return The image at the given index. */ public Image getForestImage(TileType type) { return forests.get(type.getId()).getImage(); } /** * Returns the image with the given id. * * @param id The id of the image to return. * @return The image. */ public Image getMiscImage(String id) { return ResourceManager.getImage(id, scalingFactor); } /** * Returns the image with the given id. * * @param id The id of the image to return. * @return The image. */ public ImageIcon getMiscImageIcon(String id) { return new ImageIcon(getMiscImage(id)); } /** * Returns the unit-button image at the given index in the given state. * * @param index The index of the image to return. * @param state The state (normal, highlighted, pressed, disabled) * @return The image pointer */ public ImageIcon getUnitButtonImageIcon(int index, int state) { return unitButtons.get(state).get(index); } /** * Returns the goods-image at the given index. * * @param g The type of the goods-image to return. * @return The goods-image at the given index. */ public Image getGoodsImage(GoodsType g) { return getGoodsImageIcon(g).getImage(); } /** * Returns the goods-image for a goods type. * * @param g The type of the goods-image to return. * @return The goods-image at the given index. */ public ImageIcon getGoodsImageIcon(GoodsType g) { return goods.get(g.getId()); } /** * Returns the scaled goods-ImageIcon for a goods type. * * @param type The type of the goods-ImageIcon to return. * @param scale The scale of the goods-ImageIcon to return. * @return The goods-ImageIcon at the given index. */ public ImageIcon getScaledGoodsImageIcon(GoodsType type, float scale) { return getScaledImageIcon(getGoodsImageIcon(type), scale); } /** * Returns the color chip with the given color. * * @param color The color of the color chip to return. * @return The color chip with the given color. */ public Image getColorChip(Color color) { Image colorChip = colorChips.get(color); if (colorChip == null) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); loadColorChip(gc, color); colorChip = colorChips.get(color); } return colorChip; } /** * Returns the mission chip with the given color. * * @param color The color of the color chip to return. * @param expertMission Indicates whether or not the missionary is an * expert. * @return The color chip with the given color. */ public Image getMissionChip(Color color, boolean expertMission) { Image missionChip; if (expertMission) { missionChip = expertMissionChips.get(color); } else { missionChip = missionChips.get(color); } if (missionChip == null) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); loadMissionChip(gc, color, expertMission); if (expertMission) { missionChip = expertMissionChips.get(color); } else { missionChip = missionChips.get(color); } } return missionChip; } /** * Returns the alarm chip with the given color. * * @param alarm The alarm level. * @return The alarm chip. */ public Image getAlarmChip(Tension.Level alarm) { Image alarmChip = alarmChips.get(alarm); if (alarmChip == null) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); loadAlarmChip(gc, alarm); alarmChip = alarmChips.get(alarm); } return alarmChip; } /** * Returns the width of the terrain-image for a terrain type. * * @param type The type of the terrain-image. * @return The width of the terrain-image at the given index. */ public int getTerrainImageWidth(TileType type) { String key; if (type != null) { key = type.getId(); } else { key = unexploredName; } return terrain1.get(key).getIconWidth(); } /** * Returns the height of the terrain-image for a terrain type. * * @param type The type of the terrain-image. * @return The height of the terrain-image at the given index. */ public int getTerrainImageHeight(TileType type) { String key; if (type != null) { key = type.getId(); } else { key = unexploredName; } return terrain1.get(key).getIconHeight(); } /** * Returns the graphics that will represent the given settlement. * * @param settlementType The type of settlement whose graphics type is needed. * @return The graphics that will represent the given settlement. */ public Image getSettlementImage(SettlementType settlementType) { return settlements.get(settlementType); } /** * Returns the graphics that will represent the given settlement. * * @param settlement The settlement whose graphics type is needed. * @return The graphics that will represent the given settlement. */ public Image getSettlementImage(Settlement settlement) { if (settlement instanceof Colony) { Colony colony = (Colony) settlement; // TODO: Put it in specification if (colony.isUndead()) { return settlements.get(SettlementType.UNDEAD); } else { int stockadeLevel = 0; if (colony.getStockade() != null) { stockadeLevel = colony.getStockade().getLevel(); } switch(stockadeLevel) { case 0: if (colony.getUnitCount() <= 3) { return settlements.get(SettlementType.SMALL); } else if (colony.getUnitCount() <= 7) { return settlements.get(SettlementType.MEDIUM); } else { return settlements.get(SettlementType.LARGE); } case 1: if (colony.getUnitCount() > 7) { return settlements.get(SettlementType.LARGE_STOCKADE); } else if (colony.getUnitCount() > 3) { return settlements.get(SettlementType.MEDIUM_STOCKADE); } else { return settlements.get(SettlementType.SMALL_STOCKADE); } case 2: if (colony.getUnitCount() > 7) { return settlements.get(SettlementType.LARGE_FORT); } else { return settlements.get(SettlementType.MEDIUM_FORT); } case 3: return settlements.get(SettlementType.LARGE_FORTRESS); default: return settlements.get(SettlementType.SMALL); } } } else { // IndianSettlement return settlements.get(((IndianSettlement) settlement).getTypeOfSettlement()); } } /** * Returns the ImageIcon that will represent the given unit. * * @param unit The unit whose graphics type is needed. * @return an <code>ImageIcon</code> value */ public ImageIcon getUnitImageIcon(Unit unit) { return getUnitImageIcon(unit.getType(), unit.getRole()); } /** * Returns the ImageIcon that will represent a unit of the given type. * * @param unitType an <code>UnitType</code> value * @return an <code>ImageIcon</code> value */ public ImageIcon getUnitImageIcon(UnitType unitType) { final Image im = ResourceManager.getImage(unitType.getId() + ".image", scalingFactor); return (im != null) ? new ImageIcon(im) : null; } /** * Returns the ImageIcon that will represent a unit of the given * type and role. * * @param unitType an <code>UnitType</code> value * @param role a <code>Role</code> value * @return an <code>ImageIcon</code> value */ public ImageIcon getUnitImageIcon(UnitType unitType, Role role) { final String roleStr = (role != Role.DEFAULT) ? "." + role.getId() : ""; final Image im = ResourceManager.getImage(unitType.getId() + roleStr + ".image", scalingFactor); return (im != null) ? new ImageIcon(im) : null; } /** * Returns the ImageIcon that will represent the given unit. * * @param unit an <code>Unit</code> value * @param grayscale a <code>boolean</code> value * @return an <code>ImageIcon</code> value */ public ImageIcon getUnitImageIcon(Unit unit, boolean grayscale) { return getUnitImageIcon(unit.getType(), unit.getRole(), grayscale); } /** * Returns the ImageIcon that will represent a unit of the given type. * * @param unitType an <code>UnitType</code> value * @param grayscale a <code>boolean</code> value * @return an <code>ImageIcon</code> value */ public ImageIcon getUnitImageIcon(UnitType unitType, boolean grayscale) { return getUnitImageIcon(unitType, Role.DEFAULT, grayscale); } /** * Returns the ImageIcon that will represent a unit of the given * type and role. * * @param unitType an <code>UnitType</code> value * @param role a <code>Role</code> value * @param grayscale a <code>boolean</code> value * @return an <code>ImageIcon</code> value */ public ImageIcon getUnitImageIcon(UnitType unitType, Role role, boolean grayscale) { if (grayscale) { final String roleStr = (role != Role.DEFAULT) ? "." + role.getId() : ""; final Image im = ResourceManager.getGrayscaleImage(unitType.getId() + roleStr + ".image", scalingFactor); return (im != null) ? new ImageIcon(im) : null; } else { return getUnitImageIcon(unitType, role); } } /** * Returns the scaled ImageIcon. * * @param inputIcon an <code>ImageIcon</code> value * @param scale The scale of the ImageIcon to return. * @return The scaled ImageIcon. */ public ImageIcon getScaledImageIcon(ImageIcon inputIcon, float scale) { Image image = inputIcon.getImage(); return new ImageIcon(image.getScaledInstance(Math.round(image.getWidth(null) * scale), Math.round(image.getHeight(null) * scale), Image.SCALE_SMOOTH)); } /** * Returns the scaled ImageIcon. * * @param image an <code>Image</code> value * @param scale The scale of the ImageIcon to return. * @return The scaled ImageIcon. */ public ImageIcon getScaledImageIcon(Image image, float scale) { return new ImageIcon(image.getScaledInstance(Math.round(image.getWidth(null) * scale), Math.round(image.getHeight(null) * scale), Image.SCALE_SMOOTH)); } }

The table below shows all metrics for ImageLibrary.java.

MetricValueDescription
BLOCKS155.00Number of blocks
BLOCK_COMMENT16.00Number of block comment lines
COMMENTS468.00Comment lines
COMMENT_DENSITY 0.77Comment density
COMPARISONS72.00Number of comparison operators
CYCLOMATIC134.00Cyclomatic complexity
DECL_COMMENTS57.00Comments in declarations
DOC_COMMENT440.00Number of javadoc comment lines
ELOC606.00Effective lines of code
EXEC_COMMENTS 9.00Comments in executable code
EXITS139.00Procedure exits
FUNCTIONS64.00Number of function declarations
HALSTEAD_DIFFICULTY100.70Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY234.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 4.00JAVA0029 Private method not used
JAVA0030 1.00JAVA0030 Private field not used
JAVA0031 3.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 1.00JAVA0075 Method parameter hides field
JAVA007632.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 1.00JAVA0078 Floating point values compared with ==
JAVA0079 1.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 1.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA011620.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 4.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 3.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 1.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 8.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 7.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA027619.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 1.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1344.00Number of lines in the source file
LINE_COMMENT12.00Number of line comments
LOC735.00Lines of code
LOGICAL_LINES389.00Number of statements
LOOPS 4.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS2393.00Number of operands
OPERATORS3936.00Number of operators
PARAMS116.00Number of formal parameter declarations
PROGRAM_LENGTH6329.00Halstead program length
PROGRAM_VOCAB657.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS118.00Number of return points from functions
SIZE53149.00Size of the file in bytes
UNIQUE_OPERANDS606.00Number of unique operands
UNIQUE_OPERATORS51.00Number of unique operators
WHITESPACE141.00Number of whitespace lines