/** * Get the fluff image for the specified unit, if available. * * @param unit * The unit. * @return An image file, if one is available, else {@code null}. */ public static Image getFluffImage(final Entity unit) { Image fluff = null; fluff = loadFluffImage(unit); if (fluff == null) { fluff = loadFluffImageHeuristic(unit); } return fluff; }
public void setMech(Entity entity, TROView troView){ reset(); txtMek.setText(troView.processTemplate()); txtMek.setCaretPosition(0); Image image = FluffImageHelper.getFluffImage(entity); icon = null; if(null != image) { // We don't want this window to be too big, so scale large images if (image.getWidth(this) > DEFAULT_WIDTH) { double aspect_ratio = (float)image.getWidth(this) / image.getHeight(this); image = image.getScaledInstance(DEFAULT_WIDTH, (int)(DEFAULT_WIDTH/aspect_ratio), Image.SCALE_FAST); } icon = new ImageIcon(image); lblMek.setIcon(icon); } }
/** * Attempt to load a fluff image by combining elements of type and name. * * @param unit * The unit. * @return An image or {@code null}. */ protected static Image loadFluffImageHeuristic(final Entity unit) { Image fluff = null; String dir = DIR_NAME_MECH; if (unit instanceof Aero) { dir = DIR_NAME_AERO; } else if (unit instanceof BattleArmor) { dir = DIR_NAME_BA; } else if (unit instanceof Tank) { dir = DIR_NAME_VEHICLE; } File fluff_image_file = findFluffImage( new MegaMekFile(Configuration.fluffImagesDir(), dir).getFile(), unit); if (fluff_image_file != null) { fluff = new ImageIcon(fluff_image_file.toString()).getImage(); } return fluff; }
public void setMech(Entity entity, MechView mechView){ reset(); txtMek.setText(mechView.getMechReadout()); txtMek.setCaretPosition(0); Image image = FluffImageHelper.getFluffImage(entity); icon = null; if(null != image) { // We don't want this window to be too big, so scale large images if (image.getWidth(this) > DEFAULT_WIDTH) { double aspect_ratio = (float)image.getWidth(this) / image.getHeight(this); image = image.getScaledInstance(DEFAULT_WIDTH, (int)(DEFAULT_WIDTH/aspect_ratio), Image.SCALE_FAST); } icon = new ImageIcon(image); lblMek.setIcon(icon); } }
Image image = FluffImageHelper.getFluffImage(entity); if(null == image) { image = getImageFor(unit, lblImage);