setBrush(new CustomBrush(brushLayer));
setBrush(TOOL_PAINT, new CustomBrush(brushLayer)); setCurrentBrush(TOOL_PAINT);
    public void mouseReleased(MouseEvent event) {        MapLayer layer = getCurrentLayer();        Point limp = mouseInitialPressLocation;        if (currentPointerState == PS_MARQUEE) {           // Uncommented to allow single tile selections           /*           Point tile = mapView.screenToTileCoords(event.getX(), event.getY());           if (tile.y - limp.y == 0 && tile.x - limp.x == 0) {               if (marqueeSelection != null) {                   currentMap.removeLayerSpecial(marqueeSelection);                   marqueeSelection = null;               }           }           */           // There should be a proper notification mechanism for this...           tileInstancePropertiesDialog.setSelection(marqueeSelection);        } else if (currentPointerState == PS_MOVE) {            if (layer != null && moveDist.x != 0 || moveDist.x != 0) {                undoSupport.postEdit(new MoveLayerEdit(layer, moveDist));            }        } else if (currentPointerState == PS_PAINT) {            currentBrush.endPaint();        }        // STAMP        if (bMouseIsDragging && mouseButton == MouseEvent.BUTTON3 &&                getCurrentLayer() instanceof TileLayer &&                currentPointerState == PS_PAINT)        {            Point tile = mapView.screenToTileCoords(event.getX(), event.getY());            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);            // Right mouse button dragged: create and set custom brush            TileLayer brushLayer = new TileLayer(bounds);            brushLayer.copyFrom(getCurrentLayer());            // Do a quick check to make sure the selection is not empty            if (brushLayer.isEmpty()) {                JOptionPane.showMessageDialog(appFrame,                        Resources.getString("dialog.selection.empty"),                        Resources.getString("dialog.selection.empty"),                        JOptionPane.WARNING_MESSAGE);            } else {                setBrush(new CustomBrush(brushLayer));            }            //get rid of any visible marquee            if (marqueeSelection != null) {                currentMap.removeLayerSpecial(marqueeSelection);                marqueeSelection = null;            }        }        if (paintEdit != null) {            if (layer != null) {                try {                    MapLayer endLayer = paintEdit.getStart().createDiff(layer);                    paintEdit.end(endLayer);                    undoSupport.postEdit(paintEdit);                } catch (Exception e) {                    e.printStackTrace();                }            }            paintEdit = null;        }        mouseButton = MouseEvent.NOBUTTON;        bMouseIsDown = false;        bMouseIsDragging = false;    }