for (int y = Math.min(mouseInitialPressLocation.y, tile.y); y <= Math.max(mouseInitialPressLocation.y, tile.y); y++) { for (int x = Math.min(mouseInitialPressLocation.x, tile.x); x <= Math.max(mouseInitialPressLocation.x, tile.x); x++) { marqueeSelection.select(x, y); } } mapView.repaintRegion(new Rectangle(Math.min(mouseInitialPressLocation.x, tile.x), Math.min(mouseInitialPressLocation.y, tile.y), Math.max(mouseInitialPressLocation.x, tile.x), Math.max(mouseInitialPressLocation.y, tile.y)));
Rectangle oldArea = marqueeSelection.getSelectedArea(); int minx = Math.min(mouseInitialPressLocation.x, tile.x); int miny = Math.min(mouseInitialPressLocation.y, tile.y);  marqueeSelection.selectRegion(new Rectangle(minx,miny, Math.max(mouseInitialPressLocation.x, tile.x)-minx, Math.max(mouseInitialPressLocation.y, tile.y)-miny));  if(oldArea != null) { oldArea.add(marqueeSelection.getSelectedArea()); mapView.repaintRegion(oldArea); }
    private void doMouse(MouseEvent event) {        if (currentMap == null || currentLayer < 0) {            return;        }        Point tile = mapView.screenToTileCoords(event.getX(), event.getY());        MapLayer layer = currentMap.getLayer(currentLayer);        if (layer == null) {            return;        } else if (mouseButton == MouseEvent.BUTTON3) {            Tile newTile = layer.getTileAt(tile.x, tile.y);            if (newTile != currentMap.getNullTile()) {                setCurrentTile(newTile);            }        } else if (mouseButton == MouseEvent.BUTTON1) {            switch (currentPointerState) {                case PS_PAINT:                    paintEdit.setPresentationName("Paint");                    currentBrush.commitPaint(                            currentMap, tile.x, tile.y, currentLayer);                    mapView.repaintRegion(                            currentBrush.getCenteredBounds(tile.x, tile.y));                    break;                case PS_ERASE:                    paintEdit.setPresentationName("Erase");                    layer.setTileAt(tile.x, tile.y, currentMap.getNullTile());                    mapView.repaintRegion(new Rectangle(tile.x, tile.y, 1, 1));                    break;                case PS_POUR:                    paintEdit = null;                    Tile oldTile = layer.getTileAt(tile.x, tile.y);                    pour(layer, tile.x, tile.y, currentTile, oldTile);                    mapView.repaint();                    break;                case PS_EYED:                    Tile newTile = layer.getTileAt(tile.x, tile.y);                    if (newTile != currentMap.getNullTile()) {                        setCurrentTile(newTile);                    }                    break;                case PS_MOVE:                    layer.translate(                            tile.x - this.mousePressLocation.x,                            tile.y - mousePressLocation.y);                    mapView.repaint();                    break;				case PS_MARQUEE:                    if (marqueeSelection != null) {                        for (int y = Math.min(mouseInitialPressLocation.y, tile.y); y <= Math.max(mouseInitialPressLocation.y, tile.y); y++) {                            for (int x = Math.min(mouseInitialPressLocation.x, tile.x); x <= Math.max(mouseInitialPressLocation.x, tile.x); x++) {                                marqueeSelection.select(x, y);                            }                        }                        mapView.repaintRegion(new Rectangle(Math.min(mouseInitialPressLocation.x, tile.x), Math.min(mouseInitialPressLocation.y, tile.y),                                    Math.max(mouseInitialPressLocation.x, tile.x), Math.max(mouseInitialPressLocation.y, tile.y)));                    }                    break;            }        }    }