📄 fileinfoview.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: FileInfoView.java
package org.gudy.azureus2.ui.swt.views.file;
import com.aelitis.azureus.core.peermanager.piecepicker.PiecePicker;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.disk.*;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.peer.PEPeerManager;
import org.gudy.azureus2.core3.peer.PEPiece;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.ui.swt.components.Legend;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
import org.gudy.azureus2.ui.swt.mainwindow.SWTThread;
import org.gudy.azureus2.ui.swt.views.AbstractIView;
public class FileInfoView extends AbstractIView
{
private static final int BLOCK_FILLSIZE = 14;
private static final int BLOCK_SPACING = 2;
private static final int BLOCK_SIZE = 16;
private static final int BLOCKCOLOR_DONE = 0;
private static final int BLOCKCOLOR_SKIPPED = 1;
private static final int BLOCKCOLOR_ACTIVE = 2;
private static final int BLOCKCOLOR_NEEDED = 3;
private Composite fileInfoComposite;
private ScrolledComposite sc;
protected Canvas fileInfoCanvas;
private Color blockColors[];
private Label topLabel;
private int graphicsUpdate;
private int loopFactor;
private DiskManagerFileInfo file;
private Font font;
Image img;
public FileInfoView()
{
graphicsUpdate = COConfigurationManager.getIntParameter("Graphics Update") * 2;
loopFactor = 0;
font = null;
img = null;
blockColors = (new Color[] {
Colors.blues[9], Colors.white, Colors.red, Colors.green
});
}
public void dataSourceChanged(Object newDataSource)
{
if (newDataSource == null)
file = null;
else
if (newDataSource instanceof Object[])
file = (DiskManagerFileInfo)((Object[])(Object[])newDataSource)[0];
else
file = (DiskManagerFileInfo)newDataSource;
fillFileInfoSection();
}
public String getData()
{
return "FileView.BlockView.title";
}
public void initialize(Composite composite)
{
if (fileInfoComposite != null && !fileInfoComposite.isDisposed())
{
Logger.log(new LogEvent(LogIDs.GUI, 3, (new StringBuilder()).append("FileInfoView already initialized! Stack: ").append(Debug.getStackTrace(true, false)).toString()));
delete();
}
createFileInfoPanel(composite);
}
private Composite createFileInfoPanel(Composite parent)
{
fileInfoComposite = new Composite(parent, 0);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
fileInfoComposite.setLayout(layout);
GridData gridData = new GridData(4, 4, true, true);
fileInfoComposite.setLayoutData(gridData);
(new Label(fileInfoComposite, 0)).setLayoutData(new GridData());
topLabel = new Label(fileInfoComposite, 0);
gridData = new GridData(4, -1, false, false);
topLabel.setLayoutData(gridData);
sc = new ScrolledComposite(fileInfoComposite, 512);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
sc.setLayout(layout);
gridData = new GridData(4, 4, true, true, 2, 1);
sc.setLayoutData(gridData);
fileInfoCanvas = new Canvas(sc, 0x140000);
gridData = new GridData(4, -1, true, false);
fileInfoCanvas.setLayoutData(gridData);
fileInfoCanvas.addPaintListener(new PaintListener() {
final FileInfoView this$0;
public void paintControl(PaintEvent e)
{
if (e.width <= 0 || e.height <= 0)
return;
try
{
Rectangle bounds = img != null ? img.getBounds() : null;
if (bounds == null)
{
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
} else
{
if (e.x + e.width > bounds.width)
e.gc.fillRectangle(bounds.width, e.y, ((e.x + e.width) - bounds.width) + 1, e.height);
if (e.y + e.height > bounds.height)
e.gc.fillRectangle(e.x, bounds.height, e.width, ((e.y + e.height) - bounds.height) + 1);
int width = Math.min(e.width, bounds.width - e.x);
int height = Math.min(e.height, bounds.height - e.y);
e.gc.drawImage(img, e.x, e.y, width, height, e.x, e.y, width, height);
}
}
catch (Exception ex) { }
}
{
this$0 = FileInfoView.this;
super();
}
});
fileInfoCanvas.addMouseTrackListener(new MouseTrackAdapter() {
final FileInfoView this$0;
public void mouseHover(MouseEvent event)
{
showPieceDetails(event.x, event.y);
}
{
this$0 = FileInfoView.this;
super();
}
});
Listener doNothingListener = new Listener() {
final FileInfoView this$0;
public void handleEvent(Event event1)
{
}
{
this$0 = FileInfoView.this;
super();
}
};
fileInfoCanvas.addListener(1, doNothingListener);
fileInfoCanvas.addListener(11, new Listener() {
final FileInfoView this$0;
public void handleEvent(Event e)
{
SWTThread.getInstance().limitFrequencyAsyncExec(this, e.widget.getDisplay(), new AERunnable() {
final 4 this$1;
public void runSupport()
{
if (img != null)
{
int iOldColCount = img.getBounds().width / 16;
int iNewColCount = fileInfoCanvas.getClientArea().width / 16;
if (iOldColCount != iNewColCount)
refreshInfoCanvas();
}
}
{
this$1 = 4.this;
super();
}
});
}
{
this$0 = FileInfoView.this;
super();
}
});
sc.setContent(fileInfoCanvas);
Legend.createLegendComposite(fileInfoComposite, blockColors, new String[] {
"FileView.BlockView.Done", "FileView.BlockView.Skipped", "FileView.BlockView.Active", "FileView.BlockView.Outstanding"
}, new GridData(4, -1, true, false, 2, 1));
int iFontPixelsHeight = 10;
int iFontPointHeight = (iFontPixelsHeight * 72) / fileInfoCanvas.getDisplay().getDPI().y;
Font f = fileInfoCanvas.getFont();
FontData fontData[] = f.getFontData();
fontData[0].setHeight(iFontPointHeight);
font = new Font(fileInfoCanvas.getDisplay(), fontData);
return fileInfoComposite;
}
public void fillFileInfoSection()
{
topLabel.setText("");
refreshInfoCanvas();
}
public void refresh()
{
super.refresh();
if (loopFactor++ % graphicsUpdate == 0)
refreshInfoCanvas();
}
protected void showPieceDetails(int x, int y)
{
Rectangle bounds = fileInfoCanvas.getClientArea();
if (bounds.width <= 0 || bounds.height <= 0)
return;
if (file == null)
return;
DownloadManager download_manager = file.getDownloadManager();
if (download_manager == null)
return;
DiskManager disk_manager = download_manager.getDiskManager();
PEPeerManager peer_manager = download_manager.getPeerManager();
if (disk_manager == null || peer_manager == null)
return;
DiskManagerPiece dm_pieces[] = disk_manager.getPieces();
PEPiece pe_pieces[] = peer_manager.getPieces();
int first_piece = file.getFirstPieceNumber();
int num_pieces = file.getNbPieces();
int iNumCols = bounds.width / 16;
int x_block = x / 16;
int y_block = y / 16;
int piece_number = y_block * iNumCols + x_block + first_piece;
if (piece_number >= first_piece && piece_number < first_piece + num_pieces)
{
DiskManagerPiece dm_piece = dm_pieces[piece_number];
PEPiece pe_piece = pe_pieces[piece_number];
String text = (new StringBuilder()).append("Piece ").append(piece_number).append(": ").append(dm_piece.getString()).toString();
if (pe_piece != null)
text = (new StringBuilder()).append(text).append(", active: ").append(pe_piece.getString()).toString();
else
if (dm_piece.isNeeded() && !dm_piece.isDone())
text = (new StringBuilder()).append(text).append(", inactive: ").append(peer_manager.getPiecePicker().getPieceString(piece_number)).toString();
topLabel.setText(text);
} else
{
topLabel.setText("");
}
}
protected void refreshInfoCanvas()
{
Rectangle bounds;
DiskManager disk_manager;
PEPeerManager peer_manager;
int first_piece;
int num_pieces;
int iNumCols;
GC gcImg;
bounds = fileInfoCanvas.getClientArea();
if (bounds.width <= 0 || bounds.height <= 0)
return;
if (img != null && !img.isDisposed())
{
img.dispose();
img = null;
}
DownloadManager download_manager = file != null ? file.getDownloadManager() : null;
disk_manager = download_manager != null ? download_manager.getDiskManager() : null;
peer_manager = download_manager != null ? download_manager.getPeerManager() : null;
if (file == null || disk_manager == null || peer_manager == null)
{
GC gc = new GC(fileInfoCanvas);
gc.fillRectangle(bounds);
gc.dispose();
return;
}
first_piece = file.getFirstPieceNumber();
num_pieces = file.getNbPieces();
iNumCols = bounds.width / 16;
int iNeededHeight = ((num_pieces - 1) / iNumCols + 1) * 16;
if (sc.getMinHeight() != iNeededHeight)
{
sc.setMinHeight(iNeededHeight);
sc.layout(true, true);
bounds = fileInfoCanvas.getClientArea();
}
img = new Image(fileInfoCanvas.getDisplay(), bounds.width, iNeededHeight);
gcImg = new GC(img);
gcImg.setBackground(fileInfoCanvas.getBackground());
gcImg.fillRectangle(0, 0, bounds.width, bounds.height);
DiskManagerPiece dm_pieces[] = disk_manager.getPieces();
PEPiece pe_pieces[] = peer_manager.getPieces();
int iRow = 0;
int iCol = 0;
for (int i = first_piece; i < first_piece + num_pieces; i++)
{
DiskManagerPiece dm_piece = dm_pieces[i];
PEPiece pe_piece = pe_pieces[i];
int iXPos = iCol * 16;
int iYPos = iRow * 16;
int colorIndex;
if (dm_piece.isDone())
colorIndex = 0;
else
if (!dm_piece.isNeeded())
colorIndex = 1;
else
if (pe_piece != null)
colorIndex = 2;
else
colorIndex = 3;
gcImg.setBackground(blockColors[colorIndex]);
gcImg.fillRectangle(iXPos, iYPos, 14, 14);
if (++iCol >= iNumCols)
{
iCol = 0;
iRow++;
}
}
gcImg.dispose();
break MISSING_BLOCK_LABEL_495;
Exception e;
e;
Logger.log(new LogEvent(LogIDs.GUI, "drawing piece map", e));
gcImg.dispose();
break MISSING_BLOCK_LABEL_495;
Exception exception;
exception;
gcImg.dispose();
throw exception;
fileInfoCanvas.redraw();
return;
}
public Composite getComposite()
{
return fileInfoComposite;
}
public void delete()
{
if (img != null && !img.isDisposed())
{
img.dispose();
img = null;
}
if (font != null && !font.isDisposed())
{
font.dispose();
font = null;
}
SWTThread.getInstance().removeLimitedFrequencyOwner(this);
super.delete();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -