public void handleResize() {
        winSize = cv.getCanvasSize();
        if (winSize.width == 0) {
            return;
        }
        dbimage = new BufferedImage(winSize.width, winSize.height, BufferedImage.TYPE_4BYTE_ABGR);
        int h = winSize.height / 5;
        /*if (h < 128 && winSize.height > 300)
         h = 128;*/
        circuitArea = new Rectangle(0, 0, winSize.width, winSize.height - h);
        int i;
        int minx = 1000, maxx = 0, miny = 1000, maxy = 0;
        for (i = 0; i != elmList.size(); i++) {
            CircuitElm ce = getElm(i);
            // centered text causes problems when trying to center the circuit,
            // so we special-case it here
            if (!ce.isCenteredText()) {
                minx = min(ce.x, min(ce.x2, minx));
                maxx = max(ce.x, max(ce.x2, maxx));
            }
            miny = min(ce.y, min(ce.y2, miny));
            maxy = max(ce.y, max(ce.y2, maxy));
        }
        // center circuit; we don't use snapGrid() because that rounds
        int dx = gridMask & ((circuitArea.width - (maxx - minx)) / 2 - minx);
        int dy = gridMask & ((circuitArea.height - (maxy - miny)) / 2 - miny);
        if (dx + minx < 0) {
            dx = gridMask & (-minx);
        }
        if (dy + miny < 0) {
            dy = gridMask & (-miny);
        }
        for (i = 0; i != elmList.size(); i++) {
            CircuitElm ce = getElm(i);
            ce.move(dx, dy);
        }
        // after moving elements, need this to avoid singular matrix probs
        needAnalyze();
        circuitBottom = 0;
    }