⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 visualization2dpanelwithfdp.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }
        lastPoint = e.getPoint();
    }

    /**
     * Invoked when the mouse cursor has been moved onto a component
     * but no buttons have been pushed.
     */
    public void mouseMoved(MouseEvent e) {
//        System.out.println("Moved: " + e.getPoint());
//        if (lastPoint==null) lastPoint = e.getPoint();
//        if (state == MouseState.BUTTON1_PRESSED) {
//            moveX += e.getPoint().x-lastPoint.x;
//            moveY += e.getPoint().y-lastPoint.y;
//        }
//        lastPoint = e.getPoint();
    }

    /**
     * Invoked when the mouse button has been clicked (pressed
     * and released) on a component.
     */
    public void mouseClicked(MouseEvent e) {
    }

    /**
     * Invoked when a mouse button has been pressed on a component.
     */
    public void mousePressed(MouseEvent e) {
        if (e.getButton() == MouseEvent.BUTTON1) {
            state = MouseState.BUTTON1_PRESSED;
        }
        else if (e.getButton() == MouseEvent.BUTTON3 && e.isAltDown()) {
            if (fdpThread != null && fdpThread.isRunning()) {
                fdpThread.setRunning(false);
            } else {
                fdpThread = new FdpThread(fdp, this);
                fdpThread.start();
            }
        }
    }

    /**
     * Invoked when a mouse button has been released on a component.
     */
    public void mouseReleased(MouseEvent e) {
        state = MouseState.NONE;
    }

    /**
     * Invoked when the mouse enters a component.
     */
    public void mouseEntered(MouseEvent e) {

    }

    /**
     * Invoked when the mouse exits a component.
     */
    public void mouseExited(MouseEvent e) {

    }

    /**
     * Invoked when the mouse wheel is rotated.
     *
     * @see java.awt.event.MouseWheelEvent
     */
    public void mouseWheelMoved(MouseWheelEvent e) {
        increaseZoom(((double) e.getWheelRotation()) /10d);
        repaint();
    }

    /**
     * Sets the new zoom and recalculates the center of the zoom.
     * @param amount
     */
    private void increaseZoom(double amount) {
        double zoomDifference = amount;
        zoom += amount;
        Point2D.Double centerPoint = new Point2D.Double(((double) (getWidth() >> 1)), ((double) (getHeight() >> 1)));
        AffineTransform transform = AffineTransform.getTranslateInstance(moveX, moveY);
        AffineTransform scale = AffineTransform.getScaleInstance(zoom,zoom);
        transform.concatenate(scale);

        try {
            centerPoint = (Point2D.Double) transform.inverseTransform(centerPoint, null);
            moveX = (moveX - (zoomDifference * centerPoint.getX()));
            moveY = (moveY - (zoomDifference * centerPoint.getY()));
        } catch (NoninvertibleTransformException e) {
            System.err.println("Error: " + e.toString());
        }

    }

    /*
    private void setZoomFactor() {
        int centerX = this.getWidth() / 2;
        int centerY = this.getHeight() / 2;
        Point2D p2 = new Point2D.Double(centerX, centerY);
        AffineTransform scaleTransformation = AffineTransform.getScaleInstance(zoom, zoom);
        AffineTransform translateTransformation = AffineTransform.getTranslateInstance(moveX, moveY);
        translateTransformation.concatenate(scaleTransformation);
        Point2D dp = null;
        double zoomDiff = zoomFactor;
        zoomFactor = singleZoomFactor*singleZoomFactor;
        zoomDiff = zoomFactor - zoomDiff;
        try {
            dp = translateTransformation.inverseTransform(p2, null);
            translateX = translateX - (zoomDiff * dp.getX());
            translateY = translateY - (zoomDiff * dp.getY());
        } catch (NoninvertibleTransformException e) {
            log.error(e.toString());
            e.printStackTrace();
        }
//        translate.setLocation(translate.x - (int)  , translate.y - (int) (v*centerY));
//        System.out.println("Zoomfactor: " + zoomFactor);
        repaint();
    }
    */

    private float getMax(int index) {
        float f = points[0][index];
        for (int i = 1; i < points.length; i++) {
            if (f < points[i][index]) f = points[i][index];
        }
        return f;
    }

    private float getMin(int index) {
        float f = points[0][index];
        for (int i = 1; i < points.length; i++) {
            if (f > points[i][index]) f = points[i][index];
        }
        return f;
    }

}

class ImageLoaderThread implements Runnable {
    private Visualization2DPanelWithFdp panel;
    private EmirConfiguration emirConfiguration = EmirConfiguration.getInstance();
    int imageLoaderStartWait = emirConfiguration.getInt("MdsVisPanel.ImageLoader.StartWait");
    int imageLoaderStepWait = emirConfiguration.getInt("MdsVisPanel.ImageLoader.StepWait");

    public ImageLoaderThread(Visualization2DPanelWithFdp panel) {
        this.panel = panel;
    }

    public void run() {
        try {
            Thread.sleep(imageLoaderStartWait);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        while (panel.initNextImage()) {
            try {
                Thread.sleep(imageLoaderStepWait);
            } catch (InterruptedException e) {
                e.printStackTrace(); 
            }
        }
    }
}

class FdpThread extends Thread {
    FDP fdp;
    JPanel panel;
    private EmirConfiguration emirConfiguration = EmirConfiguration.getInstance();
    private float STOP_CONDITION = emirConfiguration.getFloat("MdsVisPanel.FDP.StopCondition");
    private int fdpStepWait = emirConfiguration.getInt("MdsVisPanel.FDP.StepWait");
    private int fdpStartWait = emirConfiguration.getInt("MdsVisPanel.FDP.StartWait");

    private boolean running = false;

    public FdpThread(FDP fdp, JPanel panel) {
        this.fdp = fdp;
        this.panel = panel;
    }

    public FdpThread(FDP fdp, int fdpStepWait, JPanel panel, float stopAtMovement) {
        this.fdp = fdp;
        this.fdpStepWait = fdpStepWait;
        this.panel = panel;
        this.STOP_CONDITION = stopAtMovement;
    }

    public FdpThread(FDP fdp, int fdpStepWait, JPanel panel) {
        this.fdp = fdp;
        this.fdpStepWait = fdpStepWait;
        this.panel = panel;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p/>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    public void run() {
        running = true;
        float currentMovement = -100;
        try {
//            fdpStartWait = 1000;
            Thread.sleep(fdpStartWait);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < 1000 && running; i++) {
            try {
                Thread.sleep(fdpStepWait);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            fdp.step();
            if (currentMovement > 0 && (Math.abs(currentMovement - fdp.getCurrentMovement()) < STOP_CONDITION)) {
                System.out.println("Needed " + i + " steps for stable layout.");
                break;
            }
            currentMovement = fdp.getCurrentMovement();
//            System.out.println("Current movement: " + Math.abs(currentMovement-fdp.getCurrentMovement()));
            panel.repaint();
        }
//        System.out.println("No stable layout reached within time.");
        running = false;
    }

    public boolean isRunning() {
        return running;
    }

    public void setRunning(boolean running) {
        this.running = running;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -