public void mouseReleased(MouseEvent e) {
        int ex = e.getModifiersEx();
        if ((ex & (MouseEvent.SHIFT_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK
                | MouseEvent.META_DOWN_MASK)) == 0 && e.isPopupTrigger()) {
            doPopupMenu(e);
            return;
        }
        sim.tempMouseMode = sim.mouseMode;
        sim.selectedArea = null;
        sim.dragging = false;
        boolean circuitChanged = false;
        if (sim.heldSwitchElm != null) {
            sim.heldSwitchElm.mouseUp();
            sim.heldSwitchElm = null;
            circuitChanged = true;
        }
        if (sim.dragElm != null) {
            // if the element is zero size then don't create it
            if (sim.dragElm.x == sim.dragElm.x2 && sim.dragElm.y == sim.dragElm.y2) {
                sim.dragElm.delete();
            } else {
                sim.addElement(sim.dragElm);
                circuitChanged = true;
            }
            sim.dragElm = null;
        }
        if (circuitChanged) {
            sim.needAnalyze();
        }
        if (sim.dragElm != null) {
            sim.dragElm.delete();
        }
        sim.dragElm = null;
        sim.cv.repaintCanvas();
    }