📄 vivaldipanel.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: VivaldiPanel.java
package org.gudy.azureus2.ui.swt.views.stats;
import com.aelitis.azureus.core.dht.control.DHTControlContact;
import com.aelitis.azureus.core.dht.netcoords.vivaldi.ver1.VivaldiPosition;
import com.aelitis.azureus.core.dht.netcoords.vivaldi.ver1.impl.HeightCoordinatesImpl;
import com.aelitis.azureus.core.dht.transport.DHTTransportContact;
import com.aelitis.azureus.ui.swt.utils.ColorCache;
import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.internat.MessageText;
public class VivaldiPanel
{
private class Scale
{
int width;
int height;
float minX;
float maxX;
float minY;
float maxY;
double rotation;
float saveMinX;
float saveMaxX;
float saveMinY;
float saveMaxY;
double saveRotation;
final VivaldiPanel this$0;
public int getX(float x, float y)
{
return (int)(((((double)x * Math.cos(rotation) + (double)y * Math.sin(rotation)) - (double)minX) / (double)(maxX - minX)) * (double)width);
}
public int getY(float x, float y)
{
return (int)((((double)y * Math.cos(rotation) - (double)x * Math.sin(rotation) - (double)minY) / (double)(maxY - minY)) * (double)height);
}
private Scale()
{
this$0 = VivaldiPanel.this;
super();
minX = -1000F;
maxX = 1000F;
minY = -1000F;
maxY = 1000F;
rotation = 0.0D;
}
}
private static final int ALPHA_FOCUS = 255;
private static final int ALPHA_NOFOCUS = 150;
Display display;
Composite parent;
Canvas canvas;
Scale scale;
private boolean mouseLeftDown;
private boolean mouseRightDown;
private int xDown;
private int yDown;
private boolean antiAliasingAvailable;
private List lastContacts;
private DHTTransportContact lastSelf;
private Image img;
private int alpha;
private boolean autoAlpha;
public VivaldiPanel(Composite parent)
{
mouseLeftDown = false;
mouseRightDown = false;
antiAliasingAvailable = true;
alpha = 255;
autoAlpha = false;
this.parent = parent;
display = parent.getDisplay();
canvas = new Canvas(parent, 0x40000);
scale = new Scale();
canvas.addPaintListener(new PaintListener() {
final VivaldiPanel this$0;
public void paintControl(PaintEvent e)
{
if (img != null && !img.isDisposed())
{
Rectangle bounds = img.getBounds();
if (bounds.width >= e.width && bounds.height >= e.height)
{
if (alpha != 255)
try
{
e.gc.setAlpha(alpha);
}
catch (Exception ex) { }
e.gc.drawImage(img, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
}
} else
{
e.gc.setBackground(display.getSystemColor(22));
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
e.gc.drawText(MessageText.getString("VivaldiView.notAvailable"), 10, 10, true);
}
}
{
this$0 = VivaldiPanel.this;
super();
}
});
canvas.addMouseListener(new MouseAdapter() {
final VivaldiPanel this$0;
public void mouseDown(MouseEvent event)
{
if (event.button == 1)
mouseLeftDown = true;
if (event.button == 3)
mouseRightDown = true;
xDown = event.x;
yDown = event.y;
scale.saveMinX = scale.minX;
scale.saveMaxX = scale.maxX;
scale.saveMinY = scale.minY;
scale.saveMaxY = scale.maxY;
scale.saveRotation = scale.rotation;
}
public void mouseUp(MouseEvent event)
{
if (event.button == 1)
mouseLeftDown = false;
if (event.button == 3)
mouseRightDown = false;
refreshContacts(lastContacts, lastSelf);
}
{
this$0 = VivaldiPanel.this;
super();
}
});
canvas.addListener(1, new Listener() {
final VivaldiPanel this$0;
public void handleEvent(Event event1)
{
}
{
this$0 = VivaldiPanel.this;
super();
}
});
canvas.addListener(37, new Listener() {
final VivaldiPanel this$0;
public void handleEvent(Event event)
{
scale.saveMinX = scale.minX;
scale.saveMaxX = scale.maxX;
scale.saveMinY = scale.minY;
scale.saveMaxY = scale.maxY;
int deltaY = event.count * 5;
float scaleFactor = 1.0F - (float)deltaY / 300F;
if (scaleFactor <= 0.0F)
scaleFactor = 0.01F;
float moveFactor = 1.0F - 1.0F / scaleFactor;
float centerX = (scale.saveMinX + scale.saveMaxX) / 2.0F;
scale.minX = scale.saveMinX + moveFactor * (centerX - scale.saveMinX);
scale.maxX = scale.saveMaxX - moveFactor * (scale.saveMaxX - centerX);
float centerY = (scale.saveMinY + scale.saveMaxY) / 2.0F;
scale.minY = scale.saveMinY + moveFactor * (centerY - scale.saveMinY);
scale.maxY = scale.saveMaxY - moveFactor * (scale.saveMaxY - centerY);
refreshContacts(lastContacts, lastSelf);
}
{
this$0 = VivaldiPanel.this;
super();
}
});
canvas.addMouseMoveListener(new MouseMoveListener() {
final VivaldiPanel this$0;
public void mouseMove(MouseEvent event)
{
if (mouseLeftDown)
{
int deltaX = event.x - xDown;
int deltaY = event.y - yDown;
int width = scale.width;
int height = scale.height;
float ratioX = (scale.saveMaxX - scale.saveMinX) / (float)width;
float ratioY = (scale.saveMaxY - scale.saveMinY) / (float)height;
float realDeltaX = (float)deltaX * ratioX;
float realDeltaY = (float)deltaY * ratioY;
scale.minX = scale.saveMinX - realDeltaX;
scale.maxX = scale.saveMaxX - realDeltaX;
scale.minY = scale.saveMinY - realDeltaY;
scale.maxY = scale.saveMaxY - realDeltaY;
refreshContacts(lastContacts, lastSelf);
}
if (mouseRightDown)
{
int deltaX = event.x - xDown;
scale.rotation = scale.saveRotation - (double)((float)deltaX / 100F);
int deltaY = event.y - yDown;
float scaleFactor = 1.0F - (float)deltaY / 300F;
if (scaleFactor <= 0.0F)
scaleFactor = 0.01F;
float moveFactor = 1.0F - 1.0F / scaleFactor;
float centerX = (scale.saveMinX + scale.saveMaxX) / 2.0F;
scale.minX = scale.saveMinX + moveFactor * (centerX - scale.saveMinX);
scale.maxX = scale.saveMaxX - moveFactor * (scale.saveMaxX - centerX);
float centerY = (scale.saveMinY + scale.saveMaxY) / 2.0F;
scale.minY = scale.saveMinY + moveFactor * (centerY - scale.saveMinY);
scale.maxY = scale.saveMaxY - moveFactor * (scale.saveMaxY - centerY);
refreshContacts(lastContacts, lastSelf);
}
}
{
this$0 = VivaldiPanel.this;
super();
}
});
canvas.addMouseTrackListener(new MouseTrackListener() {
final VivaldiPanel this$0;
public void mouseHover(MouseEvent mouseevent)
{
}
public void mouseExit(MouseEvent e)
{
if (autoAlpha)
setAlpha(150);
}
public void mouseEnter(MouseEvent e)
{
if (autoAlpha)
setAlpha(255);
}
{
this$0 = VivaldiPanel.this;
super();
}
});
}
public void setLayoutData(Object data)
{
canvas.setLayoutData(data);
}
public void refreshContacts(List contacts, DHTTransportContact self)
{
if (contacts == null || self == null)
return;
lastContacts = contacts;
lastSelf = self;
if (canvas.isDisposed())
return;
Rectangle size = canvas.getBounds();
if (size.isEmpty())
return;
scale.width = size.width;
scale.height = size.height;
Color white = ColorCache.getColor(display, 255, 255, 255);
Color blue = ColorCache.getColor(display, 66, 87, 104);
if (img != null && !img.isDisposed())
img.dispose();
img = new Image(display, size);
GC gc = new GC(img);
gc.setForeground(white);
gc.setBackground(white);
gc.fillRectangle(size);
if (SWT.getVersion() < 3138 || !antiAliasingAvailable);
gc.setForeground(blue);
gc.setBackground(white);
com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition _ownPosition = self.getNetworkPosition((byte)1);
if (_ownPosition == null)
return;
VivaldiPosition ownPosition = (VivaldiPosition)_ownPosition;
float ownErrorEstimate = ownPosition.getErrorEstimate();
HeightCoordinatesImpl ownCoords = (HeightCoordinatesImpl)ownPosition.getCoordinates();
gc.drawText((new StringBuilder()).append("Our error: ").append(ownErrorEstimate).toString(), 10, 10);
Color black = ColorCache.getColor(display, 0, 0, 0);
gc.setBackground(black);
Iterator iter = contacts.iterator();
do
{
if (!iter.hasNext())
break;
DHTControlContact contact = (DHTControlContact)iter.next();
com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition _position = contact.getTransportContact().getNetworkPosition((byte)1);
if (_position != null)
{
VivaldiPosition position = (VivaldiPosition)_position;
HeightCoordinatesImpl coord = (HeightCoordinatesImpl)position.getCoordinates();
if (coord.isValid())
draw(gc, coord.getX(), coord.getY(), coord.getH(), contact, (int)ownCoords.distance(coord), position.getErrorEstimate());
}
} while (true);
Color red = ColorCache.getColor(display, 255, 0, 0);
gc.setForeground(red);
drawSelf(gc, ownCoords.getX(), ownCoords.getY(), ownCoords.getH(), ownErrorEstimate);
gc.dispose();
canvas.redraw();
}
public void refresh(List vivaldiPositions)
{
if (canvas.isDisposed())
return;
Rectangle size = canvas.getBounds();
scale.width = size.width;
scale.height = size.height;
if (img != null && !img.isDisposed())
img.dispose();
img = new Image(display, size);
GC gc = new GC(img);
Color white = ColorCache.getColor(display, 255, 255, 255);
gc.setForeground(white);
gc.setBackground(white);
gc.fillRectangle(size);
Color blue = ColorCache.getColor(display, 66, 87, 104);
gc.setForeground(blue);
gc.setBackground(blue);
Color drawColor;
for (Iterator iter = vivaldiPositions.iterator(); iter.hasNext(); drawColor.dispose())
{
VivaldiPosition position = (VivaldiPosition)iter.next();
HeightCoordinatesImpl coord = (HeightCoordinatesImpl)position.getCoordinates();
float error = position.getErrorEstimate() - 0.1F;
if (error < 0.0F)
error = 0.0F;
if (error > 1.0F)
error = 1.0F;
int blueComponent = (int)(255F - error * 255F);
int redComponent = (int)(255F * error);
drawColor = new Color(display, redComponent, 50, blueComponent);
gc.setForeground(drawColor);
draw(gc, coord.getX(), coord.getY(), coord.getH());
}
gc.dispose();
canvas.redraw();
}
private void draw(GC gc, float x, float y, float h)
{
int x0 = scale.getX(x, y);
int y0 = scale.getY(x, y);
gc.fillRectangle(x0 - 1, y0 - 1, 3, 3);
gc.drawLine(x0, y0, x0, (int)((float)y0 - (200F * h) / (scale.maxY - scale.minY)));
}
private void draw(GC gc, float x, float y, float h, DHTControlContact contact, int distance, float error)
{
if (x == 0.0F && y == 0.0F)
return;
if (error > 1.0F)
error = 1.0F;
int errDisplay = (int)(100F * error);
int x0 = scale.getX(x, y);
int y0 = scale.getY(x, y);
gc.fillRectangle(x0 - 1, y0 - 1, 3, 3);
String text = (new StringBuilder()).append(distance).append(" ms \nerr:").append(errDisplay).append("%").toString();
int lineReturn = text.indexOf("\n");
int xOffset = (gc.getFontMetrics().getAverageCharWidth() * (lineReturn == -1 ? text.length() : lineReturn)) / 2;
gc.drawText(text, x0 - xOffset, y0, true);
}
private void drawSelf(GC gc, float x, float y, float h, float errorEstimate)
{
int x0 = scale.getX(x, y);
int y0 = scale.getY(x, y);
gc.drawLine(x0 - 15, y0, x0 + 15, y0);
gc.drawLine(x0, y0 - 15, x0, y0 + 15);
}
public int getAlpha()
{
return alpha;
}
public void setAlpha(int alpha)
{
this.alpha = alpha;
if (canvas != null && !canvas.isDisposed())
canvas.redraw();
}
public void setAutoAlpha(boolean autoAlpha)
{
this.autoAlpha = autoAlpha;
if (autoAlpha)
setAlpha(canvas.getDisplay().getCursorControl() != canvas ? 150 : 255);
}
public void delete()
{
if (img != null && !img.isDisposed())
img.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -