soCodeArea = skin.getSkinObject("code-area");
control = soCodeArea.getControl();
soEnablePairing = (SWTSkinObjectButton) skin.getSkinObject("enable-pairing");
soEnablePairing.addSelectionListener(new ButtonListenerAdapter() {
// @see com.aelitis.azureus.ui.swt.skin.SWTSkinButtonUtility.ButtonListenerAdapter#pressed(com.aelitis.azureus.ui.swt.skin.SWTSkinButtonUtility, com.aelitis.azureus.ui.swt.skin.SWTSkinObject, int)
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 {
// fire something changed ourselves, so that accesscode gets
// 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");
soStatusText = (SWTSkinObjectText) skin.getSkinObject("status-text");
soStatusText.addUrlClickedListener(new SWTSkinObjectText_UrlClickedListener() {
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() {
public void paintControl(PaintEvent e) {
Color oldColor = e.gc.getForeground();
Rectangle printArea = ((Composite) e.widget).getClientArea();
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 == null ? 0 : drawAccessCode.length();
int boxSize = 25;
int boxSizeAndPadding = 30;
int allBoxesWidth = numBoxes * boxSizeAndPadding;
int textPadding = 15;
printArea.x = (fullWidth - (allBoxesWidth + sizeAccess.x + textPadding)) / 2;
printArea.width = sizeAccess.x;
sp.printString(e.gc, printArea, 0);
e.gc.setBackground(Colors.white);
e.gc.setForeground(Colors.blue);
int xStart = printArea.x + sizeAccess.x + textPadding;
int yStart = (fullHeight - boxSize) / 2;
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 (!hideCode) {
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() {
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();
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() {
public void pressed(SWTSkinButtonUtility buttonUtility,
SWTSkinObject skinObject, int stateMask) {
}
});