use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class RemotePairingWindow method _open.
private void _open() {
alreadyTested = false;
pairingManager = PairingManagerFactory.getSingleton();
PluginInterface piWebUI = getWebUI();
boolean showFTUX = piWebUI == null || !pairingManager.isEnabled();
if (skinnedDialog == null || skinnedDialog.isDisposed()) {
skinnedDialog = new SkinnedDialog("skin3_dlg_remotepairing", "shell", SWT.DIALOG_TRIM);
skin = skinnedDialog.getSkin();
soCodeArea = skin.getSkinObject("code-area");
control = soCodeArea.getControl();
soEnablePairing = (SWTSkinObjectButton) skin.getSkinObject("enable-pairing");
soEnablePairing.addSelectionListener(new ButtonListenerAdapter() {
// @see SWTSkinButtonUtility.ButtonListenerAdapter#pressed(SWTSkinButtonUtility, SWTSkinObject, int)
@Override
public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
skinObject.getControl().setEnabled(false);
if (!pairingManager.isEnabled()) {
// enabling will automatically get access code and trigger
// somethingChanged
pairingManager.setEnabled(true);
if (SHOW_SPEW) {
System.out.println("PAIR] SetEnabled");
}
} else {
// picked up
if (SHOW_SPEW) {
System.out.println("PAIR] AlreadyEnabled");
}
somethingChanged(pairingManager);
}
if (getWebUI() == null) {
installWebUI();
} else {
switchToCode();
}
}
});
soFTUX = skin.getSkinObject("pairing-ftux");
soCode = skin.getSkinObject("pairing-code");
soQR = (SWTSkinObjectImage) skin.getSkinObject("pairing-qr");
if (accessCode != null) {
setupQR(accessCode);
}
soStatusText = (SWTSkinObjectText) skin.getSkinObject("status-text");
soStatusText.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {
@Override
public boolean urlClicked(URLInfo urlInfo) {
if (urlInfo.url.equals("retry")) {
if (DEBUG) {
testPairingClass.inc();
}
alreadyTested = false;
testPairing(false);
return true;
}
return false;
}
});
pairingManager.addListener(this);
Font font = control.getFont();
GC gc = new GC(control);
fontCode = FontUtils.getFontWithHeight(font, gc, Constants.isWindows ? 20 : 18, SWT.BOLD);
gc.dispose();
control.setFont(fontCode);
control.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Color oldColor = e.gc.getForeground();
Rectangle printArea = ((Composite) e.widget).getClientArea();
printArea.y += 10;
printArea.height -= 20;
int fullWidth = printArea.width;
int fullHeight = printArea.height;
GCStringPrinter sp = new GCStringPrinter(e.gc, MessageText.getString("remote.pairing.accesscode"), printArea, false, false, SWT.NONE);
sp.calculateMetrics();
Point sizeAccess = sp.getCalculatedSize();
String drawAccessCode = accessCode == null ? " " : accessCode;
int numBoxes = drawAccessCode.length();
int boxSize = 25;
int boxSizeAndPadding = 30;
int allBoxesWidth = numBoxes * boxSizeAndPadding;
int textPadding = 15;
printArea.y = (fullHeight - boxSizeAndPadding - sizeAccess.y + textPadding) / 2;
sp.printString(e.gc, printArea, SWT.CENTER | SWT.TOP);
e.gc.setBackground(Colors.white);
e.gc.setForeground(Colors.blue);
int xStart = (fullWidth - allBoxesWidth) / 2;
int yStart = printArea.y + sizeAccess.y + textPadding;
for (int i = 0; i < numBoxes; i++) {
Rectangle r = new Rectangle(xStart + (i * boxSizeAndPadding), yStart, boxSize, boxSize);
e.gc.fillRectangle(r);
e.gc.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
e.gc.drawRectangle(r);
if (isCodeVisible()) {
e.gc.setForeground(oldColor);
GCStringPrinter.printString(e.gc, "" + drawAccessCode.charAt(i), r, false, false, SWT.CENTER);
}
}
}
});
soToClipboard = (SWTSkinObjectText) skin.getSkinObject("pair-clipboard");
soToClipboard.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {
@Override
public boolean urlClicked(URLInfo urlInfo) {
if (urlInfo.url.equals("new")) {
try {
accessCode = pairingManager.getReplacementAccessCode();
} catch (PairingException e) {
// ignore.. if error, lastErrorUpdates will trigger
}
control.redraw();
setupQR(accessCode);
String s = soToClipboard.getText();
int i = s.indexOf("|");
if (i > 0) {
soToClipboard.setText(s.substring(0, i - 1));
}
} else if (urlInfo.url.equals("clip")) {
ClipboardCopy.copyToClipBoard(accessCode);
}
return true;
}
});
SWTSkinButtonUtility btnToClipboard = new SWTSkinButtonUtility(soToClipboard);
btnToClipboard.addSelectionListener(new ButtonListenerAdapter() {
@Override
public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
}
});
skinnedDialog.addCloseListener(new SkinnedDialogClosedListener() {
@Override
public void skinDialogClosed(SkinnedDialog dialog) {
skinnedDialog = null;
pairingManager.removeListener(RemotePairingWindow.this);
Utils.disposeSWTObjects(new Object[] { fontCode });
if (pairingTest != null) {
pairingTest.cancel();
}
}
});
if (showFTUX) {
soFTUX.getControl().moveAbove(null);
}
}
setCodeVisible(false);
skinnedDialog.open();
if (showFTUX) {
switchToFTUX();
} else {
switchToCode();
}
}
use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class SWTBGImagePainter2 method main.
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display, SWT.DIALOG_TRIM);
shell.setLayout(new FillLayout());
Composite c = new Composite(shell, SWT.BORDER);
c.setLayout(new FillLayout());
c.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
e.gc.drawLine(0, 0, 100, 50);
}
});
Label lbl = new Label(c, SWT.NONE);
lbl.setText("text");
shell.open();
while (!shell.isDisposed()) {
if (display.readAndDispatch()) {
display.sleep();
}
}
}
use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class ProgressWindow method showDialog.
protected void showDialog(Shell _shell, CoreOperation _core_op) {
shell = _shell;
shell.setText(MessageText.getString("progress.window.title"));
final CoreOperationTask.ProgressCallback progress = _core_op == null ? null : _core_op.getTask().getProgressCallback();
Utils.setShellIcon(shell);
/*
shell.addListener(
SWT.Close,
new Listener()
{
public void
handleEvent(
org.eclipse.swt.widgets.Event event)
{
event.doit = false;
}
});
*/
GridLayout layout = new GridLayout();
layout.numColumns = 2;
shell.setLayout(layout);
shell.setBackground(Colors.white);
spinImages = ImageLoader.getInstance().getImages("working");
if (spinImages == null || spinImages.length == 0) {
new Label(shell, SWT.NULL);
} else {
final Rectangle spinBounds = spinImages[0].getBounds();
final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return (new Point(spinBounds.width, spinBounds.height));
}
};
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
e.gc.drawImage(spinImages[curSpinIndex], 0, 0);
if (progress != null && progress_bar != null) {
int p = progress.getProgress();
progress_bar.setSelection(p);
}
}
});
Utils.execSWTThreadLater(100, new AERunnable() {
@Override
public void runSupport() {
if (canvas == null || canvas.isDisposed()) {
return;
}
canvas.redraw();
// canvas.update();
if (curSpinIndex == spinImages.length - 1) {
curSpinIndex = 0;
} else {
curSpinIndex++;
}
Utils.execSWTThreadLater(100, this);
}
});
canvas.setBackground(Colors.white);
}
Label label = new Label(shell, SWT.NONE);
label.setText(MessageText.getString(resource));
GridData gridData = new GridData();
label.setLayoutData(gridData);
label.setBackground(Colors.white);
if (progress != null) {
progress_bar = new ProgressBar(shell, SWT.HORIZONTAL);
progress_bar.setMinimum(0);
progress_bar.setMaximum(1000);
progress_bar.setBackground(Colors.white);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
progress_bar.setLayoutData(gridData);
}
shell.pack();
Composite parent = shell.getParent();
if (parent != null) {
Utils.centerWindowRelativeTo(shell, parent);
} else {
Utils.centreWindow(shell);
}
shell.open();
}
use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class PieceGraphView method initialize.
// @see com.biglybt.ui.swt.views.AbstractIView#initialize(org.eclipse.swt.widgets.Composite)
private void initialize(Composite parent) {
blockColors = new Color[] { properties.getColor("color.pieceview.alldone"), properties.getColor("color.pieceview.notdone"), properties.getColor("color.pieceview.uploading"), properties.getColor("color.pieceview.downloading"), properties.getColor("color.pieceview.noavail"), properties.getColor("color.pieceview.havesome") };
compFindPEPiece = new Comparator() {
@Override
public int compare(Object arg0, Object arg1) {
int arg0no = (arg0 instanceof PEPiece) ? ((PEPiece) arg0).getPieceNumber() : ((Long) arg0).intValue();
int arg1no = (arg1 instanceof PEPiece) ? ((PEPiece) arg1).getPieceNumber() : ((Long) arg1).intValue();
return arg0no - arg1no;
}
};
canvas = new Canvas(parent, SWT.NO_BACKGROUND);
canvas.setLayout(new FillLayout());
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (img != null && !img.isDisposed()) {
Rectangle bounds = img.getBounds();
if (bounds.width >= e.width && bounds.height >= e.height) {
e.gc.drawImage(img, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
}
} else {
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
}
}
});
canvas.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
calcBlockSize();
}
});
}
use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class ViewQuickNotifications method initialize.
private void initialize(Composite parent) {
parent.setLayout(new GridLayout());
composite = new Composite(parent, SWT.BORDER);
GridData gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(composite, gridData);
GridLayout layout = new GridLayout(2, false);
layout.marginLeft = layout.marginRight = layout.marginTop = layout.marginBottom = 0;
composite.setLayout(layout);
// icon
notification_icon = new Label(composite, SWT.NONE);
gridData = new GridData();
gridData.widthHint = 20;
Utils.setLayoutData(notification_icon, gridData);
// text
notification_text = new Label(composite, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(notification_text, gridData);
MouseAdapter listener = new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES);
}
}
};
// text
more_text = new BufferedLabel(composite, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Utils.setLayoutData(more_text, gridData);
notification_text.setData("");
Control[] controls = { composite, notification_icon, notification_text, more_text.getControl() };
for (Control c : controls) {
c.addMouseListener(listener);
Messages.setLanguageTooltip(c, "label.click.to.view.tooltip");
}
notification_text.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
String text = (String) notification_text.getData();
int style = SWT.LEFT;
Rectangle bounds = notification_text.getBounds();
bounds.x = 4;
bounds.y = 0;
bounds.width -= 8;
GCStringPrinter sp = new GCStringPrinter(e.gc, text, bounds, true, true, style);
sp.calculateMetrics();
sp.printString();
}
});
}
Aggregations