?? motionpanel.java
字號:
package cn.ac.siat.dswatcher;
import cn.ac.siat.dswatcher.toolkit.TimeTool;
import java.awt.*;
import java.awt.List;
import java.awt.image.BufferedImage;
import java.util.*;
import java.io.File;
import java.io.IOException;
import javax.swing.JPanel;
import javax.imageio.ImageIO;
/**
* <p>Title: Motion</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: CGCL</p>
*
* @author Disheng
* @version 1.0
*/
public class MotionPanel extends JPanel {
BorderLayout borderLayout1 = new BorderLayout();
public static ArrayList nodeList = new ArrayList();
public static HashMap nodeMap = new HashMap();
public static ArrayList processList = new ArrayList();
public static HashMap processMap = new HashMap();
public static ArrayList processRecordList = new ArrayList();
public static MotionPanel mp;
Dimension d;
public static int nodeNum = 0;
public static int processNum = 0;
BufferedImage img;
BufferedImage img2;
public static final int e = 26; //edge of squair (image:node)
public static final int margin = 30;
public static final int r = 15;
public MotionPanel() {
mp = this;
// this.setPreferredSize(new Dimension(600,450));
File f = new File("images/node.GIF");
try {
img = ImageIO.read(f);
} catch (IOException e) {
e.printStackTrace();
}
File f2 = new File("images/info.GIF");
try {
img2 = ImageIO.read(f2);
} catch (IOException e) {
e.printStackTrace();
}
}
public void update() {
repaint();
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(3f));
d = this.getSize();
int canvasWidth = (int) d.getWidth();
int canvasHeight = (int) d.getHeight();
g.setColor(Color.white);
g.fillRect(0, 0, canvasWidth, canvasHeight);
Set entrySet = LogViewerPlayer.allDisplayEdgeMap.entrySet();
Iterator itr = entrySet.iterator();
while (itr.hasNext()) {
Map.Entry entry = ((Map.Entry) itr.next());
Edge edge = ((Edge) entry.getValue());
g.setColor(edge.getColor());
// System.out.println("edge.getColor()="+edge.getColor());
// System.out.println("edge.getX1()="+edge.getX1());
// System.out.println("edge.getY1()="+edge.getY1());
// System.out.println("edge.getX2()="+edge.getX2());
// System.out.println("edge.getY2()="+edge.getY2());
g.drawLine(
edge.getX1(),
edge.getY1(),
edge.getX2(),
edge.getY2());
}
for (int i = 0; i < LogViewerPlayer.informationList.size(); i++) {
InfoTag ift = ((InfoTag) LogViewerPlayer.informationList.get(i));
int x = ift.getX();
int y = ift.getY();
g.drawImage(img2, x, y, 10, 10, null);
}
// g.setColor(Color.magenta);
Iterator it = nodeList.iterator();
// System.out.println("nodelist.length="+nodeList.size());
while (it.hasNext()) {
g.setColor(Color.blue);
String nodeName = ((String) it.next());
Node node = ((Node) nodeMap.get(nodeName));
double x = node.getX();
double y = node.getY();
g.drawImage(img, (int) x, (int) y, 25, 25, null);
g.drawString(node.getText(), (int) x, (int) y + 25 + 10);
ArrayList runPList = node.getRunningProcessList();
g.setColor(Color.green);
for(int i = 0;i < runPList.size(); i++)
{
String processName = (String) runPList.get(i);
int x1 = ((int) x+25 + i*20);
int y1 = (int)y;
g.fillOval(x1, y1, 10, 10);
g.drawString(processName, x1, y1);
}
}
if(LogViewerPlayer.end)
{
g.setColor(Color.black);
for(int i = 0;i < processRecordList.size();i++)
{
Process p = ((Process) processRecordList.get(i));
if (p.getS().empty()) {
g.drawString(p.getProcessName()+":"+ TimeTool.dateToString(p.getStartTime(),"yyyy-MM-dd HH:mm:ss"),10,10 + 30*i);
g.drawString("->"+TimeTool.dateToString(p.getEndTime(),"yyyy-MM-dd HH:mm:ss")+ "(Duration:"+p.getDuration()/1000+"s)",10,23 + 30*i);
}
else
{
g.drawString(p.getProcessName()+":"+ TimeTool.dateToString(p.getStartTime(),"yyyy-MM-dd HH:mm:ss"),10,10 + 30*i);
g.drawString("->"+"Unfinished" + "(Duration:-)",10,23 + 30*i);
}
}
}
g.dispose();
}
public void computeXY(Node node, int i) {
d = this.getSize();
double canvasWidth = d.getWidth();
double canvasHeight = d.getHeight();
double centerX = canvasWidth / 2;
double centerY = canvasHeight / 2;
double r = centerY - margin;
double x = centerX + r * Math.cos(2 * i * Math.PI / nodeNum) - e / 2;
double y = centerY + r * Math.sin(2 * i * Math.PI / nodeNum) - e / 2;
node.setX(x);
node.setY(y);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -