if (layer instanceof TileLayer) {
if (layer instanceof TileLayer && !bMouseIsDragging) {
    private void doMouse(MouseEvent event) {        if (currentMap == null || currentLayer < 0) {            return;        }        Point tile = mapView.screenToTileCoords(event.getX(), event.getY());        MapLayer layer = getCurrentLayer();        if (layer == null) {            return;        } else if (mouseButton == MouseEvent.BUTTON3) {            if (layer instanceof TileLayer) {                Tile newTile = ((TileLayer)layer).getTileAt(tile.x, tile.y);                setCurrentTile(newTile);            } else if (layer instanceof ObjectGroup) {                // TODO: Add support for ObjectGroups here            }        } else if (mouseButton == MouseEvent.BUTTON1) {            switch (currentPointerState) {                case PS_PAINT:                    paintEdit.setPresentationName("Paint");                    if (layer instanceof TileLayer) {                        try {                            mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));                        } catch (Exception e) {                            e.printStackTrace();                        }                    }                    break;                case PS_ERASE:                    paintEdit.setPresentationName("Erase");                    if (layer instanceof TileLayer) {                        ((TileLayer) layer).setTileAt(tile.x, tile.y, null);                    }                    mapView.repaintRegion(new Rectangle(tile.x, tile.y, 1, 1));                    break;                case PS_POUR:  // POUR only works on TileLayers                    paintEdit = null;                    if (layer instanceof TileLayer) {                        Tile oldTile = ((TileLayer)layer).getTileAt(tile.x, tile.y);                        pour((TileLayer) layer, tile.x, tile.y, currentTile, oldTile);                        mapView.repaint();                    }                    break;                case PS_EYED:                    if (layer instanceof TileLayer) {                        Tile newTile = ((TileLayer)layer).getTileAt(                                tile.x, tile.y);                        setCurrentTile(newTile);                    } else if (layer instanceof ObjectGroup) {                        // TODO: Add support for ObjectGroups here                    }                    break;                case PS_MOVE:                    Point translation = new Point(                            tile.x - mousePressLocation.x,                            tile.y - mousePressLocation.y);                    layer.translate(translation.x, translation.y);                    moveDist.translate(translation.x, translation.y);                    mapView.repaint();                    break;                case PS_MARQUEE:                    if (marqueeSelection != null) {                        Point limp = mouseInitialPressLocation;                        Rectangle oldArea =                            marqueeSelection.getSelectedAreaBounds();                        int minx = Math.min(limp.x, tile.x);                        int miny = Math.min(limp.y, tile.y);                        Rectangle selRect = new Rectangle(                                minx, miny,                                (Math.max(limp.x, tile.x) - minx)+1,                                (Math.max(limp.y, tile.y) - miny)+1);                        if (event.isShiftDown()) {                            marqueeSelection.add(new Area(selRect));                        } else if (event.isControlDown()) {                            marqueeSelection.subtract(new Area(selRect));                        } else {                            marqueeSelection.selectRegion(selRect);                        }                        if (oldArea != null) {                            oldArea.add(                                    marqueeSelection.getSelectedAreaBounds());                            mapView.repaintRegion(oldArea);                        }                    }                    break;            }        }    }