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

📄 processpanel.java

📁 这是一个演示分布式系统并行计算的GUI程序
💻 JAVA
字号:
package cn.ac.siat.dswatcher;import cn.ac.siat.dswatcher.toolkit.TimeTool;import java.awt.*;import java.awt.geom.Rectangle2D;import java.awt.geom.Point2D;import java.awt.event.MouseMotionListener;import java.awt.event.MouseEvent;import java.util.*;import javax.swing.JPanel;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2007</p> * <p>Company: CGCL</p> * author Disheng * version 1.0 */public class ProcessPanel extends JPanel {//    BorderLayout borderLayout = new BorderLayout();//    ProcessMPanel processPanel;    Dimension d;    int processHeight = 12;    public static int canvasWidth;    boolean mouseToolTip = false;    Point currentPoint = null;    Node currentPNode;    public ProcessPanel() {        init();        addMouseMotionListener(new MouseMotionHandler());    }    void init() {//        JScrollPane scrollPane1 = new JScrollPane();        //      this.setLayout(borderLayout);//        this.setBackground(Color.green);//        processPanel = new ProcessMPanel();        //      this.setPreferredSize(new Dimension(600, 450));        this.setMaximumSize(new Dimension(1000, 750));        this.setMinimumSize(new Dimension(80, 60));        //       scrollPane1.getViewport().add(processPanel, null);//        this.add(processPanel, BorderLayout.CENTER);    }    public void update() {        repaint();    }    public void paint(Graphics g) {        Graphics2D g2 = (Graphics2D) g;        g2.setStroke(new BasicStroke(2f));        d = this.getSize();        canvasWidth = (int) d.getWidth();        int canvasHeight = (int) d.getHeight();        g.setColor(Color.white);        g.fillRect(0, 0, canvasWidth, canvasHeight);        int processNum = MotionPanel.processList.size();        if (processNum != 0) {            int [] x = new int[processNum];            int [] y = new int[processNum];//            int aHeight = (canvasHeight -6) / processNum;            int rectWidth = canvasWidth - 40;            g.setColor(Color.blue);            g.drawString("Processes", canvasWidth / 2 - 10, 15);            for (int i = 0; i < processNum; i++) {                x[i] = 20;                y[i] = 15 + 15 + i * 25;            }            for (int i = 0; i < processNum; i++) {                String name = ((String) MotionPanel.processList.get(i));                g.setColor(Color.blue);                g.drawString(name, x[i], y[i] - 3);                g.setColor(Color.black);                g.drawRect(x[i], y[i], rectWidth, processHeight);            }            for (int i = 0; i < MotionPanel.processList.size(); i++) {                String processName = ((String) MotionPanel.processList.get(i));                ArrayList nodeList = ((ArrayList) MotionPanel.processMap.get(processName));                Iterator itr = nodeList.iterator();                int nodeX = x[i];                while (itr.hasNext()) {                    Node n = ((Node) itr.next());                    float proportion = n.getProcessProportion();                    float length = rectWidth * proportion;                    if (n.isProcessFinished()) {                        g.setColor(new Color(36, 142, 1));                        g.fillRect(nodeX, y[i], (int) length, 12);                        g.setColor(Color.black);                        g.drawRect(nodeX, y[i], (int) length, 12);                        g.setColor(Color.yellow);                        g.drawString(n.getText(), nodeX + 3, y[i] + 10);                        if(!LogViewerPlayer.end && n.contains(currentPoint))                        {                            currentPNode = n;                        }                    } else {                        g.setColor(Color.yellow);                        g.fillRect(nodeX, y[i], (int) length, 12);                        g.setColor(Color.black);                        g.drawRect(nodeX, y[i], (int) length, 12);                        g.setColor(Color.blue);                        g.drawString(n.getText(), nodeX + 2, y[i] + 10);                    }                    n.setX(nodeX);                    n.setY(y[i]);                    nodeX = nodeX + 1 + (int) length;                }            }            //paint mouseTooltip            if (mouseToolTip) {                g2.setStroke(new BasicStroke(1f));                int currentX = (int) currentPoint.getX();                int currentY = (int) currentPoint.getY();                int toolTipWidth = 152;                int toolTipHeight = 53;                g.setColor(new Color(0, 255, 255, 90));                g.fillRoundRect(currentX, currentY, toolTipWidth, toolTipHeight, 4, 2);                g.setColor(Color.black);                g.drawRoundRect(currentX, currentY, toolTipWidth, toolTipHeight, 4, 2);                Date startTime = currentPNode.getStart_time();//                System.out.println("--:"+currentPNode.getX()+":"+currentPNode.getY());                if (currentPNode.isProcessFinished()) {                    Date endTime = currentPNode.getEnd_time();                    long duration = currentPNode.runPeriodTime();                    g.setColor(Color.black);                    g.drawString("Start:" + TimeTool.dateToString(startTime, "yyyy-MM-dd HH:mm:ss"), currentX + 4, currentY + 17);                    g.drawString("End:" + TimeTool.dateToString(endTime, "yyyy-MM-dd HH:mm:ss"), currentX + 4, currentY + 30);                    g.drawString("Duration:" + duration / 1000 + "." + duration % 1000, currentX + 4, currentY + 43);                } else {                    long duration = LogViewerPlayer.currentTime - startTime.getTime();                    g.drawString("Start:" + TimeTool.dateToString(startTime, "yyyy-MM-dd HH:mm:ss"), currentX + 4, currentY + 17);                    g.drawString("End: -", currentX + 4, currentY + 30);                    g.drawString("Duration:" + duration / 1000 + "." + duration % 1000, currentX + 4, currentY + 43);                }            }        }        g.dispose();    }    /**     * Finds the first process_node containing a point.     *     * @param p a point     * @return the first square that contains p     */    public Node find(Point2D p) {        Set entrySet = MotionPanel.processMap.entrySet();        Iterator it = entrySet.iterator();        while (it.hasNext()) {            Map.Entry entry = ((Map.Entry) it.next());            ArrayList nodeList = ((ArrayList) entry.getValue());            for (int i = 0; i < nodeList.size(); i++) {                Node n = ((Node) nodeList.get(i));                if (n.contains(p)) {                    return n;                }            }        }        return null;    }    private class MouseMotionHandler            implements MouseMotionListener {        public void mouseMoved(MouseEvent event) {            // set the mouse cursor to cross hairs if it is inside            // a rectangle            currentPoint = event.getPoint();            currentPNode = find(currentPoint);            if (currentPNode == null) {                mouseToolTip = false;            } else {                mouseToolTip = true;            }            if (LogViewerPlayer.end) {                update();            }        }        public void mouseDragged(MouseEvent event) {        }    }}

⌨️ 快捷键说明

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