selectImg = getNewImage(img, selection);
selection = new Rectangle(rx1, ry1, rw, rh); if (selection.width > 0 && selection.height > 0) { selectImg = getNewImage(img, selection); }
    protected void doTool(int x1, int y1, int x2, int y2)    {        //x1, y1 is start of drag        //x2, y2 is end/current place of drag        //		addUndo();        int c = pal.getSelectedColorIndex();        int tool = tools.getSelectedDrawingTool(), fill = tools.getFillType();        int rx1 = Math.min(x1, x2),            ry1 = Math.min(y1, y2),            rx2 = Math.max(x1, x2),            ry2 = Math.max(y1, y2),            w = Math.min(x2 - x1, img.length - rx1),            h = Math.min(y2 - y1, img[0].length - ry1),            rw = Math.min(rx2 - rx1, img.length - rx1),            rh = Math.min(ry2 - ry1, img[0].length - ry1);        switch (tool)        {            case Toolset.TOOL_EYEDROPER :                pal.setSelectedColor(getPointColor(x2, y2));                //undo();                break;            case Toolset.TOOL_PENCIL :                //undo();                drawPoint(x2, y2, c);                break;            case Toolset.TOOL_LINE :                drawLine(x1, y1, x2, y2, c);                break;            case Toolset.TOOL_RECTANGLE :                switch (fill)                {                    case Toolset.FILL_NONE :                        drawRect(rx1, ry1, rx2 - rx1, ry2 - ry1, c, false);                        break;                    case Toolset.FILL_OPQUE :                        drawRect(rx1, ry1, rx2 - rx1, ry2 - ry1, c, true);                        break;                    case Toolset.FILL_BACKGROUND :                        drawRect(rx1, ry1, rx2 - rx1, ry2 - ry1, 0, true);                        drawRect(rx1, ry1, rx2 - rx1, ry2 - ry1, c, false);                        break;                }                break;            case Toolset.TOOL_OVAL :                switch (fill)                {                    case Toolset.FILL_NONE :                        drawOval(rx1, ry1, rx2 - rx1, ry2 - ry1, c, false);                        break;                    case Toolset.FILL_OPQUE :                        drawOval(rx1, ry1, rx2 - rx1, ry2 - ry1, c, true);                        break;                    case Toolset.FILL_BACKGROUND :                        drawOval(rx1, ry1, rx2 - rx1, ry2 - ry1, 0, true);                        drawOval(rx1, ry1, rx2 - rx1, ry2 - ry1, c, false);                        break;                }                break;            case Toolset.TOOL_ROUND_RECTANGLE :                int curve = tools.getRoundedRectRadius();                switch (fill)                {                    case Toolset.FILL_NONE :                        drawRoundedRect(                            rx1,                            ry1,                            rx2 - rx1,                            ry2 - ry1,                            curve,                            curve,                            c,                            false);                        break;                    case Toolset.FILL_OPQUE :                        drawRoundedRect(                            rx1,                            ry1,                            rx2 - rx1,                            ry2 - ry1,                            curve,                            curve,                            c,                            true);                        break;                    case Toolset.FILL_BACKGROUND :                        drawRoundedRect(                            rx1,                            ry1,                            rx2 - rx1,                            ry2 - ry1,                            curve,                            curve,                            0,                            true);                        drawRoundedRect(                            rx1,                            ry1,                            rx2 - rx1,                            ry2 - ry1,                            curve,                            curve,                            c,                            false);                        break;                }                break;            case Toolset.TOOL_PAINT_BUCKET :                //undo();                //do on mouse release                break;            case Toolset.TOOL_SELECTION :                if (!isMakingSelect)                {                    //move selection                    //selection.setLocation(selx + (x2 - x1), sely + (y2 -                    // y1));                    selection.setLocation(selx + w, sely + h);                }                else                {                    //create new selection                    //selection = new Rectangle(rx1, ry1, rx2 - rx1, ry2 -                    // ry1);                    selection = new Rectangle(rx1, ry1, rw, rh);                    if (selection.width > 0 && selection.height > 0)                    {                        selectImg = getNewImage(img, selection);                    }                }                break;        }        repaint();    }