selectImg = this.getNewImage(img, selection);
selection = new Rectangle(rx1, ry1, rx2 - rx1, ry2 - ry1); if (selection.width > 0 && selection.height > 0) { selectImg = this.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();        Graphics g = img.getGraphics();        g.setColor(pal.getSelectedColor());        int tool = tools.getSelectedDrawingTool(), fill = tools.getFillType();        int rx1 = x1, ry1 = y1, rx2 = x2, ry2 = y2;        if (x1 > x2)        {            rx1 = x2;            rx2 = x1;        }        if (y1 > y2)        {            ry1 = y2;            ry2 = y1;        }        switch (tool)        {            case Toolset.TOOL_EYEDROPER:                pal.setSelectedColor(getPointColor(x2, y2));                //undo();                break;            case Toolset.TOOL_PENCIL:                //undo();                g.drawLine(x2, y2, x2, y2);                //this.drawLine(rx1, ry1, rx2, ry2,                // pal.getSelectedColorIndex());                break;            case Toolset.TOOL_LINE:                g.drawLine(x1, y1, x2, y2);                break;            case Toolset.TOOL_RECTANGLE:                switch (fill)                {                    case Toolset.FILL_NONE:                        g.drawRect(rx1, ry1, rx2 - rx1, ry2 - ry1);                        break;                    case Toolset.FILL_OPQUE:                        g.fillRect(rx1, ry1, rx2 - rx1, ry2 - ry1);                        break;                    case Toolset.FILL_BACKGROUND:                        g.setColor(pal.getColorOf(0));                        g.fillRect(rx1, ry1, rx2 - rx1, ry2 - ry1);                        g.setColor(pal.getSelectedColor());                        g.drawRect(rx1, ry1, rx2 - rx1, ry2 - ry1);                        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);                     */                    case Toolset.FILL_NONE:                        g.drawOval(rx1, ry1, rx2 - rx1, ry2 - ry1);                        break;                    case Toolset.FILL_OPQUE:                        g.fillOval(rx1, ry1, rx2 - rx1, ry2 - ry1);                        break;                    case Toolset.FILL_BACKGROUND:                        g.setColor(pal.getColorOf(0));                        g.fillOval(rx1, ry1, rx2 - rx1, ry2 - ry1);                        g.setColor(pal.getSelectedColor());                        g.drawOval(rx1, ry1, rx2 - rx1, ry2 - ry1);                        break;                }                break;            case Toolset.TOOL_ROUND_RECTANGLE:                int curve = tools.getRoundedRectRadius();                switch (fill)                {                    case Toolset.FILL_NONE:                        g.drawRoundRect(rx1, ry1, rx2 - rx1, ry2 - ry1, curve,                            curve);                        break;                    case Toolset.FILL_OPQUE:                        g.fillRoundRect(rx1, ry1, rx2 - rx1, ry2 - ry1, curve,                            curve);                        break;                    case Toolset.FILL_BACKGROUND:                        g.setColor(pal.getColorOf(0));                        g.fillRoundRect(rx1, ry1, rx2 - rx1, ry2 - ry1, curve,                            curve);                        g.setColor(pal.getSelectedColor());                        g.drawRoundRect(rx1, ry1, rx2 - rx1, ry2 - ry1, curve,                            curve);                        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));                }                else                {                    //create new selection                    selection = new Rectangle(rx1, ry1, rx2 - rx1, ry2 - ry1);                    if (selection.width > 0 && selection.height > 0)                    {                        selectImg = this.getNewImage(img, selection);                    }                }                break;        }        repaint();    }