Changeset 13129 in josm for trunk


Ignore:
Timestamp:
2017-11-19T19:07:47+01:00 (6 years ago)
Author:
Don-vip
Message:

see #15476 - fix checkstyle/pmd warnings, add some javadoc

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

    r13127 r13129  
    6767    private static final BooleanProperty AGPIFO_STYLE2 =
    6868        new BooleanProperty("geoimage.agpifo-style-drag-and-zoom", false);
    69     private static int DRAG_BUTTON;
    70     private static int ZOOM_BUTTON;
     69    private static int dragButton;
     70    private static int zoomButton;
    7171
    7272    /** Alternative to mouse wheel zoom; esp. handy if no mouse wheel is present **/
     
    8787    private static final BooleanProperty BILIN_UPSAMP =
    8888        new BooleanProperty("geoimage.bilinear-upsampling", false);
    89     private static double BILIN_UPPER;
    90     private static double BILIN_LOWER;
     89    private static double bilinUpper;
     90    private static double bilinLower;
    9191
    9292    @Override
    9393    public void preferenceChanged(PreferenceChangeEvent e) {
    9494        if (e == null ||
    95             e.getKey().equals(AGPIFO_STYLE2.getKey()))
    96         {
    97             DRAG_BUTTON = AGPIFO_STYLE2.get() ? 1 : 3;
    98             ZOOM_BUTTON = DRAG_BUTTON == 1 ? 3 : 1;
     95            e.getKey().equals(AGPIFO_STYLE2.getKey())) {
     96            dragButton = AGPIFO_STYLE2.get() ? 1 : 3;
     97            zoomButton = dragButton == 1 ? 3 : 1;
    9998        }
    10099        if (e == null ||
    101100            e.getKey().equals(MAX_ZOOM.getKey()) ||
    102101            e.getKey().equals(BILIN_DOWNSAMP.getKey()) ||
    103             e.getKey().equals(BILIN_UPSAMP.getKey()))
    104         {
    105             BILIN_UPPER = (BILIN_UPSAMP.get() ? 2*MAX_ZOOM.get() : (BILIN_DOWNSAMP.get() ? 0.5 : 0));
    106             BILIN_LOWER = (BILIN_DOWNSAMP.get() ? 0 : 1);
    107         }
    108     }
    109 
    110     /** Manage the visible rectangle of an image with full bounds stored in init. **/
     102            e.getKey().equals(BILIN_UPSAMP.getKey())) {
     103            bilinUpper = (BILIN_UPSAMP.get() ? 2*MAX_ZOOM.get() : (BILIN_DOWNSAMP.get() ? 0.5 : 0));
     104            bilinLower = (BILIN_DOWNSAMP.get() ? 0 : 1);
     105        }
     106    }
     107
     108    /**
     109     * Manage the visible rectangle of an image with full bounds stored in init.
     110     * @since 13127
     111     */
    111112    public static class VisRect extends Rectangle {
    112113        private final Rectangle init;
    113114
     115        /**
     116         * Constructs a new {@code VisRect}.
     117         * @param     x the specified X coordinate
     118         * @param     y the specified Y coordinate
     119         * @param     width  the width of the rectangle
     120         * @param     height the height of the rectangle
     121         */
    114122        public VisRect(int x, int y, int width, int height) {
    115123            super(x, y, width, height);
     
    122130        }
    123131
     132        /**
     133         * Constructs a new {@code VisRect} from another one.
     134         * @param v rectangle to copy
     135         */
    124136        public VisRect(VisRect v) {
    125137            super(v);
     
    127139        }
    128140
     141        /**
     142         * Constructs a new empty {@code VisRect}.
     143         */
    129144        public VisRect() {
    130145            this(0, 0, 0, 0);
     
    269284
    270285        private boolean mouseIsDragging(MouseEvent e) {
    271             return (DRAG_BUTTON == 1 && SwingUtilities.isLeftMouseButton(e)) ||
    272                    (DRAG_BUTTON == 2 && SwingUtilities.isMiddleMouseButton(e)) ||
    273                    (DRAG_BUTTON == 3 && SwingUtilities.isRightMouseButton(e));
     286            return (dragButton == 1 && SwingUtilities.isLeftMouseButton(e)) ||
     287                   (dragButton == 2 && SwingUtilities.isMiddleMouseButton(e)) ||
     288                   (dragButton == 3 && SwingUtilities.isRightMouseButton(e));
    274289        }
    275290
    276291        private boolean mouseIsZoomSelecting(MouseEvent e) {
    277             return (ZOOM_BUTTON == 1 && SwingUtilities.isLeftMouseButton(e)) ||
    278                    (ZOOM_BUTTON == 2 && SwingUtilities.isMiddleMouseButton(e)) ||
    279                    (ZOOM_BUTTON == 3 && SwingUtilities.isRightMouseButton(e));
     292            return (zoomButton == 1 && SwingUtilities.isLeftMouseButton(e)) ||
     293                   (zoomButton == 2 && SwingUtilities.isMiddleMouseButton(e)) ||
     294                   (zoomButton == 3 && SwingUtilities.isRightMouseButton(e));
    280295        }
    281296
     
    636651            double scale = target.width / (double) r.width; // pixel ratio is 1:1
    637652
    638             if (selectedRect == null && BILIN_LOWER < scale && scale < BILIN_UPPER) {
     653            if (selectedRect == null && bilinLower < scale && scale < bilinUpper) {
    639654                BufferedImage bi = ImageProvider.toBufferedImage(image, r);
    640655                r.x = r.y = 0;
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r13127 r13129  
    617617     * implementation, which adds support for HiDPI displays. The effect will be
    618618     * that in HiDPI mode, when GUI elements are scaled by a factor 1.5, 2.0, etc.,
    619      * the images are not just up-scaled, but a higher resolution version of the
    620      * image is rendered instead.
     619     * the images are not just up-scaled, but a higher resolution version of the image is rendered instead.
    621620     * <p>
    622      * Use {@link HiDPISupport#getBaseImage(java.awt.Image)} to extract the original
    623      * image from a multi-resolution image.
     621     * Use {@link HiDPISupport#getBaseImage(java.awt.Image)} to extract the original image from a multi-resolution image.
    624622     * <p>
    625      * See {@link HiDPISupport#processMRImage} for how to process the image without
    626      * removing the multi-resolution magic.
     623     * See {@link HiDPISupport#processMRImage} for how to process the image without removing the multi-resolution magic.
    627624     * @param multiResolution true, if multi-resolution image is requested
    628625     * @return the current object, for convenience
     
    821818            // This method is called from different thread and modifying HashMap concurrently can result
    822819            // for example in loops in map entries (ie freeze when such entry is retrieved)
    823             // Yes, it did happen to me :-)
    824820            if (name == null)
    825821                return null;
     
    911907                        // and redundant when you have a whole ton of objects. So,
    912908                        // index the cache by the name of the icon we're looking for
    913                         // and don't bother to create a URL unless we're actually
    914                         // creating the image.
     909                        // and don't bother to create a URL unless we're actually creating the image.
    915910                        URL path = getImageUrl(fullName);
    916911                        if (path == null) {
     
    16181613     * has a transparency set to {@code TRANSLUCENT} and uses the correct transparent color.
    16191614     *
    1620      * @return a <code>BufferedImage</code> containing the decoded
    1621      * contents of the input, or <code>null</code>.
     1615     * @return a <code>BufferedImage</code> containing the decoded contents of the input, or <code>null</code>.
    16221616     *
    16231617     * @throws IllegalArgumentException if <code>input</code> is <code>null</code>.
     
    16731667     * has a transparency set to {@code TRANSLUCENT} and uses the correct transparent color.
    16741668     *
    1675      * @return a <code>BufferedImage</code> containing the decoded
    1676      * contents of the input, or <code>null</code>.
     1669     * @return a <code>BufferedImage</code> containing the decoded contents of the input, or <code>null</code>.
    16771670     *
    16781671     * @throws IllegalArgumentException if <code>input</code> is <code>null</code>.
     
    17171710     * has a transparency set to {@code TRANSLUCENT} and uses the correct transparent color.
    17181711     *
    1719      * @return a <code>BufferedImage</code> containing the decoded
    1720      * contents of the input, or <code>null</code>.
     1712     * @return a <code>BufferedImage</code> containing the decoded contents of the input, or <code>null</code>.
    17211713     *
    17221714     * @throws IllegalArgumentException if <code>input</code> is <code>null</code>.
     
    19871979    public static BufferedImage toBufferedImage(Image image, Rectangle crop_area) {
    19881980        BufferedImage buffImage = null;
    1989 
    19901981        Rectangle r = new Rectangle(image.getWidth(null), image.getHeight(null));
    19911982        if (r.intersection(crop_area).equals(crop_area)) {
    19921983            buffImage = new BufferedImage(crop_area.width, crop_area.height, BufferedImage.TYPE_INT_ARGB);
    19931984            Graphics2D g2 = buffImage.createGraphics();
    1994             g2.drawImage(image,
    1995                 0, 0, crop_area.width, crop_area.height,
    1996                 crop_area.x, crop_area.y,
    1997                 crop_area.x + crop_area.width, crop_area.y + crop_area.height,
    1998                 null);
     1985            g2.drawImage(image, 0, 0, crop_area.width, crop_area.height,
     1986                crop_area.x, crop_area.y, crop_area.x + crop_area.width, crop_area.y + crop_area.height, null);
    19991987            g2.dispose();
    20001988        }
Note: See TracChangeset for help on using the changeset viewer.