📄 timelinedisplayer.java
字号:
return; } g.setColor(Color.black); int x = mouseX; int y = mouseY; int w = mouseDragX - mouseX; int h = mouseDragY - mouseY; if(w < 0) { x += w; w = -w; } if(h < 0) { y += h; h = -h; } g.drawRect(x, y, w, h); } Color bundleLineColor = new Color(200,200,200); Color bundleSelectedLineColor = new Color(0,0,0); Color bundleHiliteColor = new Color(230,230,230); Color bundleNameColor = new Color(100,100,100); Color bundleEventColor = new Color(0, 0, 0); Color bundleTextColor = new Color(0,0,0); Color bgColor = new Color(255,255,255); int hiliteHeight = 12; void paintNearest(Graphics g) { FWEvent fwe = getNearest(mouseX, mouseY); if(fwe != null) { setToolTipText(fwe.toString()); g.setColor(Color.black); g.drawArc(fwe.x - 10, fwe.y - 11, 16, 16, 0, 360); } else { setToolTipText(null); } } FWEvent getNearest(int x, int y) { double bestDist = Double.MAX_VALUE; FWEvent bestEvent = null; for(Iterator itb = bundleToServiceEvents.keySet().iterator(); itb.hasNext();) { Bundle b = (Bundle)itb.next(); Map serviceEvents = (Map)bundleToServiceEvents.get(b); for(Iterator it = serviceEvents.keySet().iterator(); it.hasNext(); ) { Long key = (Long)it.next(); FWEvent fwe = (FWEvent)serviceEvents.get(key); double dx = x - fwe.x; double dy = y - fwe.y; double dist2 = dx * dx + dy * dy; if(dist2 <= bestDist) { bestDist = dist2; bestEvent = fwe; } } } for(Iterator it = bundleEvents.keySet().iterator(); it.hasNext(); ) { Long key = (Long)it.next(); FWEvent fwe = (FWEvent)bundleEvents.get(key); int dx = x - fwe.x; int dy = y - fwe.y; int dist2 = dx * dx + dy * dy; if(dist2 <= bestDist) { bestDist = dist2; bestEvent = fwe; } } return bestEvent; } void paintServices(Graphics g, Bundle b, long first, int offsetX, int offsetY, double kx, double ky) { Map serviceEvents = (Map)bundleToServiceEvents.get(b); if(serviceEvents == null) { return; } for(Iterator it = serviceEvents.keySet().iterator(); it.hasNext(); ) { Long key = (Long)it.next(); FWEvent fwe = (FWEvent)serviceEvents.get(key); long time = fwe.getTime(); ServiceReference sr = fwe.getServiceReference(); Bundle b2 = sr.getBundle(); if(b2 != null && b.getBundleId() == b2.getBundleId()) { int y = (int)(b.getBundleId() * ky) + offsetY; int x = (int)((time - first) * kx) + offsetX; g.setColor(Color.black); fwe.setPos(x, y + 3); g.drawLine(fwe.x, fwe.y, fwe.x, fwe.y - 3); } } } void paintBundles(Graphics g) { Bundle[] bundles = getBundleArray(); if(bundleEvents.size() == 0) { return; } Dimension size = getSize(); int offsetY = 10; int offsetX = 10; long first = ((FWEvent)bundleEvents.get(bundleEvents.firstKey())).getTime(); long last = ((FWEvent)bundleEvents.get(bundleEvents.lastKey())).getTime(); if(last == first) { last = first + 1; } long diff = last - first; double ky = (size.height - offsetY * 2) / (double)bundles.length; double kx = (size.width - offsetX * 2) / (double)diff; int bundleH = (int)((size.height - offsetY/2) / bundles.length); Point viewPoint = scroll.getViewport().getViewPosition(); int detailLevel = 0; if(bundleH < 12) { detailLevel = 0; } else if(bundleH < 20) { detailLevel = 1; } else { detailLevel = 2; } int imageSize = 12; Font font = getSizedFont((bundleH - 10) / 40.0); hiliteBundle = null; hiliteBundleIx = -1; for(int i = 0; i < bundles.length; i++) { Bundle b = bundles[i]; int y = (int)(b.getBundleId() * ky + offsetY); if(mouseY > y - bundleH/2 && mouseY < y + bundleH/2) { hiliteBundle = b; hiliteBundleIx = i; g.setColor(bundleHiliteColor); g.fillRect(offsetX, y, size.width - offsetX, hiliteHeight); } if(bundleSelModel.isSelected(b.getBundleId())) { g.setColor(bundleSelectedLineColor); } else { g.setColor(bundleLineColor); } g.drawLine(offsetX, y, size.width - offsetX, y); g.setFont(font); g.setColor(bundleNameColor); g.drawString(Util.getBundleName(b), offsetX, y + font.getSize() + 1); paintServices(g, b, first, offsetX, offsetY, kx, ky); } for(Iterator it = bundleEvents.keySet().iterator(); it.hasNext(); ) { Long key = (Long)it.next(); FWEvent fwe = (FWEvent)bundleEvents.get(key); long time = fwe.getTime(); int y = (int)(fwe.getBundle().getBundleId() * ky) + offsetY; int x = (int)((time - first) * kx) + offsetX; fwe.setPos(x, y); g.setColor(bundleEventColor); ImageIcon icon = desktop.getBundleEventIcon(fwe.getType()); if(icon != null) { if(imageSize == -1) { g.drawImage(icon.getImage(), x, y, null); } else { g.drawImage(icon.getImage(), x-10, y-11, 16, 16, null); } } else { g.drawLine(x, y, x, y-3); String s = Util.bundleEventName(fwe.getType()); g.drawString(s, x, y); } } } } } static int idCount = 0; class FWEvent implements Comparable { long time; int id; BundleEvent bundleEvent; Bundle bundle; ServiceReference sr; int eventType; int x = -1; int y = -1; FWEvent ref; public FWEvent(Bundle b, FWEvent ref) { this.id = idCount++; this.time = System.currentTimeMillis(); this.bundle = b; this.ref = ref; } public FWEvent(Bundle b, int eventType) { this.id = idCount++; this.time = System.currentTimeMillis(); this.bundle = b; this.eventType = eventType; } public FWEvent(ServiceReference sr, int eventType) { this.id = idCount++; this.time = System.currentTimeMillis(); this.sr = sr; this.eventType = eventType; } public void setPos(int x, int y) { this.x = x; this.y = y; } public Bundle getBundle() { return bundle; } public ServiceReference getServiceReference() { return sr; } public int getType() { return eventType; } public boolean isBundle() { return bundle != null && ref == null; } public boolean isSR() { return sr != null; } public boolean isRef() { return ref != null; } public long getTime() { return time; } public int getId() { return id; } public int compareTo(Object other) { FWEvent e = (FWEvent)other; return (int)(id - e.id); } public void paint(Graphics2D g, int x, int y) { } public String toString() { return toString(false); } public String toString(boolean bCoord) { StringBuffer sb = new StringBuffer(); if(isBundle()) { sb.append(Util.getBundleName(getBundle())); sb.append(" "); sb.append(Util.bundleEventName(getType())); } else if(isSR()) { sb.append("#" + getServiceReference().getProperty(Constants.SERVICE_ID)); String[] sl = (String[])getServiceReference().getProperty(Constants.OBJECTCLASS); sb.append(" "); for(int i = 0; i < sl.length; i++) { sb.append(sl[i]); if(i < sl.length - 1) { sb.append("/"); } } sb.append(" "); sb.append(Util.serviceEventName(getType())); } sb.append(" " + (new Date(time)).toString()); if(bCoord) { sb.append(" (" + x + ", " + y + ")"); } return sb.toString(); } } Font[] fonts = null; Font getSizedFont(double size) { int min = 5; int max = 19; if(fonts == null) { fonts = new Font[10]; for(int i = 0; i < fonts.length; i++) { double k = (double)i / fonts.length; fonts[i] = new Font("dialog", Font.PLAIN, (int)(min + k * (max - min))); } } int n = (int)(size * (fonts.length - 1)); n = Math.max(0, Math.min(n, fonts.length - 1)); return fonts[n]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -