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

📄 logviewerplayer.java

📁 这是一个演示分布式系统并行计算的GUI程序
💻 JAVA
字号:
package cn.ac.siat.dswatcher;

import cn.ac.siat.dswatcher.toolkit.TimeTool;

import javax.swing.*;
import javax.swing.Timer;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Date;
import java.util.*;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * Author: Disheng
 * Date: 2007-2-8
 * Time: 13:45:17
 * Institution: CGCL/ChinaGrid
 * Description: To change this template use File | Settings | File Templates.
 */
public class LogViewerPlayer extends Thread implements ActionListener {
    public static long currentTime;
    static long lastTime;
    static int index; // used to record the indexes of the playing frames.
    public static Map allDisplayEdgeMap = new HashMap(100);
    public static List informationList = new ArrayList(100);       //used to record the positions of info.gif
    MotionPanel mPanel;
    ProcessPanel pPanel;
    TimePanel timePanel;
    public static boolean end = false;
    static int delay = 200;

    public LogViewerPlayer(MotionPanel mPanel, ProcessPanel pPanel, TimePanel timePanel) {
        this.mPanel = mPanel;
        this.pPanel = pPanel;
        this.timePanel = timePanel;
    }

    public void run() {
        index = 0;
        ControlMenu.timer = new Timer(delay, this);
        ControlMenu.timer.setInitialDelay(delay * LogViewerPanel.frameList.size());
        ControlMenu.timer.setCoalesce(true);
        ControlMenu.timer.start();
        ControlMenu.frozen = false;
    }

    public void actionPerformed(ActionEvent e) {
        currentTime += delay;
        //refresh the colors of all the displaying edges
        Set entrySet = allDisplayEdgeMap.entrySet();
        Iterator it = entrySet.iterator();
        while (it.hasNext()) {
            Map.Entry entry = ((Map.Entry) it.next());
            Edge edge = ((Edge) entry.getValue());
            Color color = edge.getColor();
            int blue = color.getBlue();
            if (blue < 210) {
                color = new Color(255, blue + 20, blue + 20);
                edge.setColor(color);
            }
        }

        for (int i = 0; i < LogViewerPlayer.informationList.size(); i++) {
            InfoTag ift = ((InfoTag) LogViewerPlayer.informationList.get(i));
            int x = ift.getX();
            int y = ift.getY();
            int startX = ift.getStartX();
            int startY = ift.getStartY();
            int tx = ift.getTerminationX();
            int ty = ift.getTerminationY();
            int x1 = x + (tx - startX) / 8;
            int y1 = y + (ty - startY) / 8;
            if (Math.abs(x1 - tx) >= Math.abs(tx - startX) / 8) {
                ift.setX(x1);
                ift.setY(y1);
            } else {
                ift.setX(tx + MotionPanel.r * (startX - tx) / ift.getLength());
                ift.setY(ty + MotionPanel.r * (startY - ty) / ift.getLength());
            }

        }

        // add new edge
        //   System.out.println("index="+index);
        //   System.out.println("LogViewerPanel.frameList.size()="+LogViewerPanel.frameList.size());

        if (index < LogViewerPanel.frameList.size()) {
            PlayFrame pf = ((PlayFrame) LogViewerPanel.frameList.get(index));
            long time = pf.getTimestamp();
            while (time <= currentTime) {

                Node from = pf.getFrom();
                Node to = pf.getTo();
                if (from != null && to != null) {
                    int x1 = (int) from.getX() + 13;
                    int y1 = (int) from.getY() + 13;
                    int x2 = (int) to.getX() + 13;
                    int y2 = (int) to.getY() + 13;
                    Color c = new Color(255, 0, 0);
                    Edge edge = new Edge(c, x1, y1, x2, y2);
                    Graphics2D g = ((Graphics2D) mPanel.getGraphics());
                    g.setStroke(new BasicStroke(3f));
                    g.setColor(Color.yellow);
                    g.drawLine(x1, y1, x2, y2);
                    g.setColor(Color.green);
                    g.drawLine(x1, y1, x2, y2);
                    g.setColor(Color.cyan);
                    g.drawLine(x1, y1, x2, y2);
                    g.setColor(Color.blue);
                    g.drawLine(x1, y1, x2, y2);
                    allDisplayEdgeMap.put(from + "-" + to, edge);
                    double length = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
                    informationList.add(new InfoTag(x1, y1, x1, y1, x2, y2, (int) length));


                    String processName = pf.getProcessName();
                    ArrayList list = ((ArrayList) MotionPanel.processMap.get(processName));
                    float newProcessProportion = 1;
                    for (int i = 0; i < list.size(); i++) {
                        Node n1 = ((Node) list.get(i));
                        if (n1.getText().equals(from.getText())) {
                            newProcessProportion = n1.getProcessProportion() / 2;
                            n1.setProcessProportion(newProcessProportion);
                            break;
                            }
                        }

                    Node n = new Node(to.getText(), "", Color.green,newProcessProportion);
                    //Notice: this n above is used for ProcessPanel, not MotionPanel. So, x and y are not from to.getX/Y()
                    n.setStart_time(new Date(time));
                    for(int i = 0;i < MotionPanel.processRecordList.size(); i++)
                    {
                        Process p = ((Process) MotionPanel.processRecordList.get(i));
                        if(p.getProcessName().equals(processName))
                        {
                            p.getS().push(new Integer(0));
                            break;
                        }
                    }

                    list.add(n);
                    to.getRunningProcessList().add(processName);
                } else if (from == null) {
               //     int x2 = (int) to.getX() + 13;
              //      int y2 = (int) to.getY() + 13;
                    String processName = pf.getProcessName();
                    Process p = new Process(processName,new Date(time),null);
                    p.getS().push(new Integer(0));
                    MotionPanel.processRecordList.add(p);
                    ArrayList list = ((ArrayList) MotionPanel.processMap.get(processName));
                    Node n = new Node(to.getText(), "", Color.green, 1);


                    n.setStart_time(new Date(time));
                    list.add(n);
                    to.getRunningProcessList().add(processName);
                } else // to == null
                {
                    String processName = pf.getProcessName();
                    from.getRunningProcessList().remove(processName);
                    for(int i = 0;i < MotionPanel.processRecordList.size(); i++)
                    {
                        Process p = ((Process) MotionPanel.processRecordList.get(i));
                        if(p.getProcessName().equals(processName))
                        {
                            if(!p.getS().empty())
                            {
                                p.getS().pop();
                                if(p.getS().empty())
                                   p.setEndTime(new Date(time));
                            }
                            break;
                        }
                    }

                    ArrayList list = ((ArrayList) MotionPanel.processMap.get(processName));
                    for (int i = 0; i < list.size(); i++) {
                        Node n1 = ((Node) list.get(i));
                        if (n1.getText().equals(from.getText()) && !n1.isProcessFinished()) {
                            n1.setProcessFinished(true);
                            n1.setEnd_time(new Date(time));
                            break;
                            }
                        }
                }
                index++;
                if (index >= LogViewerPanel.frameList.size()) {
                    break;
                }
                pf = ((PlayFrame) LogViewerPanel.frameList.get(index));
                time = pf.getTimestamp();

            }

        } else {
            end = true;
            System.out.println("...");

            ControlMenu.timer.stop();
        }
        //paint


        mPanel.update();
        pPanel.update();
        //    System.out.println("currentTime="+currentTime);

        if (currentTime / 1000 != lastTime / 1000) {
            lastTime = currentTime;
            String currentTime_S = TimeTool.dateToString(new Date(currentTime), "yyyy-MM-dd HH:mm:ss");
            timePanel.setTime(currentTime_S);
            timePanel.update();
        }

    }

}

⌨️ 快捷键说明

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