if (mouseButton == MouseEvent.BUTTON3 && getCurrentLayer() instanceof TileLayer && currentPointerState == PS_PAINT) { Point limp = mouseInitialPressLocation; int minx = Math.min(limp.x, tile.x); int miny = Math.min(limp.y, tile.y);   Rectangle bounds = new Rectangle( minx, miny, (Math.max(limp.x, tile.x) - minx)+1, (Math.max(limp.y, tile.y) - miny)+1);   MultilayerPlane mlp = new MultilayerPlane(bounds.width, bounds.height); TileLayer brushLayer = new TileLayer(bounds); brushLayer.copyFrom(getCurrentLayer()); mlp.addLayer(brushLayer); setBrush(new CustomBrush(mlp)); } else { doMouse(e); }
bMouseIsDragging = true;  doMouse(e);
    public void mouseDragged(MouseEvent e) {        mousePressLocation = mapView.screenToTileCoords(e.getX(), e.getY());        Point tile = mapView.screenToTileCoords(e.getX(), e.getY());        if (mouseButton == MouseEvent.BUTTON3 &&                getCurrentLayer() instanceof TileLayer &&                currentPointerState == PS_PAINT)        {            Point limp = mouseInitialPressLocation;            int minx = Math.min(limp.x, tile.x);            int miny = Math.min(limp.y, tile.y);            /*Rectangle oldArea = null;            if (currentBrush instanceof CustomBrush) {                oldArea = currentBrush.getBounds();            }*/            Rectangle bounds = new Rectangle(                    minx, miny,                    (Math.max(limp.x, tile.x) - minx)+1,                    (Math.max(limp.y, tile.y) - miny)+1);            // Right mouse button dragged: create and set custom brush            MultilayerPlane mlp =                new MultilayerPlane(bounds.width, bounds.height);            TileLayer brushLayer = new TileLayer(bounds);            brushLayer.copyFrom(getCurrentLayer());            mlp.addLayer(brushLayer);            setBrush(new CustomBrush(mlp));        }        else {            doMouse(e);        }        if (currentMap.inBounds(tile.x, tile.y)) {            tileCoordsLabel.setText(String.valueOf(tile.x) + ", " + tile.y);        } else {            tileCoordsLabel.setText(" ");        }        updateCursorHighlight(tile);    }