gt:             if (pixelBorderShown) {
context: /*
   * Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de)
   *
   * This program 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 3 of the License, or (at your option)
   * any later version.
   * This program 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 this program; if not, see http://www.gnu.org/licenses/
   */
  
  package com.bc.ceres.glayer.support;
  
  import com.bc.ceres.binding.Property;
  import com.bc.ceres.binding.PropertyContainer;
  import com.bc.ceres.binding.PropertySet;
  import com.bc.ceres.core.Assert;
  import com.bc.ceres.glayer.Layer;
  import com.bc.ceres.glayer.LayerContext;
  import com.bc.ceres.glayer.LayerType;
  import com.bc.ceres.glayer.LayerTypeRegistry;
  import com.bc.ceres.glayer.annotations.LayerTypeMetadata;
  import com.bc.ceres.glevel.MultiLevelModel;
  import com.bc.ceres.glevel.MultiLevelRenderer;
  import com.bc.ceres.glevel.MultiLevelSource;
  import com.bc.ceres.glevel.support.ConcurrentMultiLevelRenderer;
  import com.bc.ceres.glevel.support.DefaultMultiLevelModel;
  import com.bc.ceres.glevel.support.DefaultMultiLevelRenderer;
  import com.bc.ceres.glevel.support.DefaultMultiLevelSource;
  import com.bc.ceres.grender.InteractiveRendering;
  import com.bc.ceres.grender.Rendering;
  import com.bc.ceres.grender.Viewport;
  
  import java.awt.BasicStroke;
  import java.awt.Color;
  import java.awt.Graphics2D;
  import java.awt.Paint;
  import java.awt.Rectangle;
  import java.awt.RenderingHints;
  import java.awt.Shape;
  import java.awt.Stroke;
  import java.awt.geom.AffineTransform;
  import java.awt.geom.Line2D;
  import java.awt.geom.Rectangle2D;
  import java.awt.image.RenderedImage;
  
  /**
   * A multi-resolution capable image layer.
   *
   * @author Norman Fomferra
   */
  public class ImageLayer extends Layer {
  
      private static final Type LAYER_TYPE = LayerTypeRegistry.getLayerType(Type.class);
  
      public static final String PROPERTY_NAME_MULTI_LEVEL_SOURCE = "multiLevelSource";
      public static final String PROPERTY_NAME_BORDER_SHOWN = "borderShown";
      public static final String PROPERTY_NAME_BORDER_WIDTH = "borderWidth";
      public static final String PROPERTY_NAME_BORDER_COLOR = "borderColor";
      public static final String PROPERTY_NAME_PIXEL_BORDER_SHOWN = "pixelBorderShown";
      public static final String PROPERTY_NAME_PIXEL_BORDER_WIDTH = "pixelBorderWidth";
      public static final String PROPERTY_NAME_PIXEL_BORDER_COLOR = "pixelBorderColor";
  
      public static final boolean DEFAULT_BORDER_SHOWN = false;
      public static final Color DEFAULT_BORDER_COLOR = new Color(204, 204, 255);
      public static final double DEFAULT_BORDER_WIDTH = 1.0;
  
      public static final Boolean DEFAULT_PIXEL_BORDER_SHOWN = true;
      public static final Color DEFAULT_PIXEL_BORDER_COLOR = new Color(255, 255, 204);
      public static final double DEFAULT_PIXEL_BORDER_WIDTH = 0.0;
  
      private static final double MIN_PIXEL_SIZE_IN_VIEW = 16.0;
  
      /**
       * @deprecated since BEAM 4.7, no replacement; kept for compatibility of sessions
       */
      @Deprecated
      private static final String PROPERTY_NAME_IMAGE_TO_MODEL_TRANSFORM = "imageToModelTransform";
  
      private MultiLevelSource multiLevelSource;
  
      private MultiLevelRenderer multiLevelRenderer;
  
      /**
       * Constructs a single-resolution-level image layer.
       *
       * @param image the image
       */
      public ImageLayer(RenderedImage image) {
          this(image, new AffineTransform(), 1);
      }
  
      /**
       * Constructs a multi-resolution-level image layer.
       *
       * @param image                 the image
       * @param imageToModelTransform the transformation from image to model CS
       * @param levelCount            the number of resolution levels
       */
      public ImageLayer(RenderedImage image, AffineTransform imageToModelTransform, int levelCount) {
          this(new DefaultMultiLevelSource(image,
                                           new DefaultMultiLevelModel(levelCount, imageToModelTransform,
                                                                      DefaultMultiLevelModel.getModelBounds(
                                                                              imageToModelTransform, image))
          ));
      }
  
      /**
       * Constructs a multi-resolution-level image layer.
       *
       * @param multiLevelSource the multi-resolution-level image
       */
      public ImageLayer(MultiLevelSource multiLevelSource) {
          this(LAYER_TYPE, multiLevelSource, initConfiguration(LAYER_TYPE.createLayerConfig(null), multiLevelSource));
      }
  
      public ImageLayer(Type layerType, MultiLevelSource multiLevelSource, PropertySet configuration) {
          super(layerType, configuration);
          Assert.notNull(multiLevelSource);
          this.multiLevelSource = multiLevelSource;
          setName("Image Layer");
      }
  
      @Override
      public void regenerate() {
          clearCaches();
          fireLayerDataChanged(getModelBounds());
      }
  
      public RenderedImage getImage() {
          return getImage(0);
      }
  
      public MultiLevelSource getMultiLevelSource() {
          return multiLevelSource;
      }
  
      public void setMultiLevelSource(MultiLevelSource multiLevelSource) {
          Assert.notNull(multiLevelSource);
          if (multiLevelSource != this.multiLevelSource) {
              final Rectangle2D region;
              final Rectangle2D oldBounds = this.multiLevelSource.getModel().getModelBounds();
              final Rectangle2D newBounds = multiLevelSource.getModel().getModelBounds();
              if (oldBounds == null) {
                  region = newBounds;
              } else if (newBounds == null) {
                  region = oldBounds;
              } else {
                  region = oldBounds.createUnion(newBounds);
              }
              clearCaches();
              this.multiLevelSource = multiLevelSource;
              multiLevelRenderer = null;
              fireLayerDataChanged(region);
          }
      }
  
      public AffineTransform getImageToModelTransform() {
          return getImageToModelTransform(0);
      }
  
      public AffineTransform getModelToImageTransform() {
          return getModelToImageTransform(0);
      }
  
      public RenderedImage getImage(int level) {
          return multiLevelSource.getImage(level);
      }
  
      public AffineTransform getImageToModelTransform(int level) {
          return multiLevelSource.getModel().getImageToModelTransform(level);
      }
  
      public AffineTransform getModelToImageTransform(int level) {
          return multiLevelSource.getModel().getModelToImageTransform(level);
      }
  
      public int getLevel(Viewport vp) {
          return getLevel(multiLevelSource.getModel(), vp);
      }
  
      public static int getLevel(MultiLevelModel model, Viewport vp) {
          final AffineTransform i2m = model.getImageToModelTransform(0);
          final double i2mScale = Math.sqrt(Math.abs(i2m.getDeterminant()));
          final double m2vScale = 1.0 / vp.getZoomFactor();
          final double scale = m2vScale / i2mScale;
          return model.getLevel(scale);
      }
  
      @Override
      protected Rectangle2D getLayerModelBounds() {
          return multiLevelSource.getModel().getModelBounds();
      }
  
      @Override
      protected void renderLayer(Rendering rendering) {
          if (multiLevelSource == MultiLevelSource.NULL) {
              return;
          }
          final int level = getLevel(rendering.getViewport());
          final MultiLevelRenderer renderer = getRenderer(rendering);
          renderer.renderImage(rendering, multiLevelSource, level);
          renderImageGridIndicators(rendering, level);
      }
  
      private void renderImageGridIndicators(Rendering rendering, int level) {
          final boolean pixelBorderShown = level == 0 && isPixelBorderShown();
          final boolean imageBorderShown = isBorderShown();
          if (!pixelBorderShown && !imageBorderShown) {
              return;
          }
  
          final Graphics2D graphics2D = rendering.getGraphics();
          final Object oldAntialiasing = graphics2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
          final Paint oldPaint = graphics2D.getPaint();
          final Stroke oldStroke = graphics2D.getStroke();
          try {
              graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  