📄 gcstringprinter.java
字号:
h = Math.max(h, textExtent.y);
}
return new Point(w, h);
}
if (!nodraw)
gc.drawText(s, x, y, true);
textExtent = gc.textExtent(s);
if (hitAreas != null)
hitAreas.add(new Rectangle(x, y, textExtent.x, textExtent.y));
return textExtent;
}
public static void main(String args[])
{
Display display = Display.getDefault();
Shell shell = new Shell(display, 1264);
ImageLoader imageLoader = ImageLoader.getInstance();
Image images[] = {
imageLoader.getImage("azureus32"), imageLoader.getImage("azureus64"), imageLoader.getImage("azureus"), imageLoader.getImage("azureus128")
};
String text = "Apple <A HREF=\"aa\">Banana</a>, Cow <A HREF=\"ss\">Dug Ergo</a>, Flip Only. test of the string printer averlongwordthisisyesindeed";
shell.setSize(500, 500);
GridLayout gridLayout = new GridLayout(2, false);
shell.setLayout(gridLayout);
Composite cButtons = new Composite(shell, 0);
GridData gridData = new GridData(0, 4, false, true);
cButtons.setLayoutData(gridData);
Canvas cPaint = new Canvas(shell, 0x20000000);
gridData = new GridData(4, 4, true, true);
cPaint.setLayoutData(gridData);
cButtons.setLayout(new RowLayout(512));
Listener l = new Listener(cPaint) {
final Canvas val$cPaint;
public void handleEvent(Event event)
{
cPaint.redraw();
}
{
cPaint = canvas;
Object();
}
};
Text txtText = new Text(cButtons, 2114);
txtText.setText("Apple <A HREF=\"aa\">Banana</a>, Cow <A HREF=\"ss\">Dug Ergo</a>, Flip Only. test of the string printer averlongwordthisisyesindeed");
txtText.addListener(24, l);
txtText.setLayoutData(new RowData(100, 200));
txtText.addKeyListener(new KeyListener(txtText) {
final Text val$txtText;
public void keyReleased(KeyEvent keyevent)
{
}
public void keyPressed(KeyEvent e)
{
if (e.keyCode == 97 && e.stateMask == 0x40000)
txtText.selectAll();
}
{
txtText = text;
Object();
}
});
Button btnSkipClip = new Button(cButtons, 32);
btnSkipClip.setText("Skip Clip");
btnSkipClip.setSelection(true);
btnSkipClip.addListener(13, l);
Button btnFullOnly = new Button(cButtons, 32);
btnFullOnly.setText("Full Lines Only");
btnFullOnly.setSelection(true);
btnFullOnly.addListener(13, l);
Combo cboVAlign = new Combo(cButtons, 8);
cboVAlign.add("Top");
cboVAlign.add("Bottom");
cboVAlign.add("None");
cboVAlign.addListener(13, l);
cboVAlign.select(0);
Combo cboHAlign = new Combo(cButtons, 8);
cboHAlign.add("Left");
cboHAlign.add("Center");
cboHAlign.add("Right");
cboHAlign.add("None");
cboHAlign.addListener(13, l);
cboHAlign.select(0);
Button btnWrap = new Button(cButtons, 32);
btnWrap.setText("Wrap");
btnWrap.setSelection(true);
btnWrap.addListener(13, l);
Label lblInfo = new Label(shell, 64);
lblInfo.setText("Welcome");
Listener l2 = new Listener(cPaint, display, shell, lblInfo, btnWrap, cboVAlign, cboHAlign, txtText, btnSkipClip, btnFullOnly, images) {
URLInfo lastHitInfo;
final Canvas val$cPaint;
final Display val$display;
final Shell val$shell;
final Label val$lblInfo;
final Button val$btnWrap;
final Combo val$cboVAlign;
final Combo val$cboHAlign;
final Text val$txtText;
final Button val$btnSkipClip;
final Button val$btnFullOnly;
final Image val$images[];
public void handleEvent(Event event)
{
GC gc;
boolean ourGC;
gc = event.gc;
ourGC = gc == null;
if (ourGC)
gc = new GC(cPaint);
GCStringPrinter sp;
Color colorURL;
Color colorURL2;
URLInfo hitUrl;
String url1;
String url2;
sp = buildSP(gc);
colorURL = gc.getDevice().getSystemColor(3);
colorURL2 = gc.getDevice().getSystemColor(12);
if (event.type != 5)
break MISSING_BLOCK_LABEL_197;
Point pt = cPaint.toControl(display.getCursorLocation());
hitUrl = sp.getHitUrl(pt.x, pt.y);
url1 = hitUrl != null && hitUrl.url != null ? hitUrl.url : "";
url2 = lastHitInfo != null && lastHitInfo.url != null ? lastHitInfo.url : "";
if (url1.equals(url2))
{
if (ourGC)
gc.dispose();
return;
}
cPaint.redraw();
lastHitInfo = hitUrl;
if (ourGC)
gc.dispose();
return;
Rectangle bounds = cPaint.getClientArea();
Color colorBox = gc.getDevice().getSystemColor(7);
Color colorText = gc.getDevice().getSystemColor(2);
gc.setForeground(colorText);
Point pt = cPaint.toControl(display.getCursorLocation());
sp.setUrlColor(colorURL);
URLInfo hitUrl = sp.getHitUrl(pt.x, pt.y);
if (hitUrl != null)
{
shell.setCursor(shell.getDisplay().getSystemCursor(21));
hitUrl.urlColor = colorURL2;
} else
{
shell.setCursor(null);
}
boolean fit = sp.printString();
lblInfo.setText(fit ? "fit" : "no fit");
bounds.width--;
bounds.height--;
gc.setForeground(colorBox);
gc.drawRectangle(bounds);
if (ourGC)
gc.dispose();
break MISSING_BLOCK_LABEL_417;
Throwable t;
t;
t.printStackTrace();
if (ourGC)
gc.dispose();
break MISSING_BLOCK_LABEL_417;
Exception exception;
exception;
if (ourGC)
gc.dispose();
throw exception;
}
private GCStringPrinter buildSP(GC gc)
{
Rectangle bounds = cPaint.getClientArea();
int style = btnWrap.getSelection() ? 64 : 0;
if (cboVAlign.getSelectionIndex() == 0)
style |= 0x80;
else
if (cboVAlign.getSelectionIndex() == 1)
style |= 0x400;
if (cboHAlign.getSelectionIndex() == 0)
style |= 0x4000;
else
if (cboHAlign.getSelectionIndex() == 1)
style |= 0x1000000;
else
if (cboHAlign.getSelectionIndex() == 2)
style |= 0x20000;
String text = txtText.getText();
text = text.replaceAll("\r\n", "\n");
GCStringPrinter sp = new GCStringPrinter(gc, text, bounds, btnSkipClip.getSelection(), btnFullOnly.getSelection(), style);
sp.setImages(images);
sp.calculateMetrics();
return sp;
}
{
cPaint = canvas;
display = display1;
shell = shell1;
lblInfo = label;
btnWrap = button;
cboVAlign = combo;
cboHAlign = combo1;
txtText = text;
btnSkipClip = button1;
btnFullOnly = button2;
images = aimage;
Object();
lastHitInfo = null;
}
};
cPaint.addListener(9, l2);
cPaint.addListener(5, l2);
shell.open();
do
{
if (shell.isDisposed())
break;
if (!display.readAndDispatch())
display.sleep();
} while (true);
}
public GCStringPrinter(GC gc, String string, Rectangle printArea, boolean skipClip, boolean fullLinesOnly, int swtFlags)
{
this.gc = gc;
this.string = string;
this.printArea = printArea;
this.swtFlags = swtFlags;
printFlags = 0;
if (skipClip)
printFlags |= 1;
if (fullLinesOnly)
printFlags |= 2;
}
public GCStringPrinter(GC gc, String string, Rectangle printArea, int printFlags, int swtFlags)
{
this.gc = gc;
this.string = string;
this.printArea = printArea;
this.swtFlags = swtFlags;
this.printFlags = printFlags;
}
public boolean printString()
{
return _printString();
}
public boolean printString(int printFlags)
{
int oldPrintFlags = this.printFlags;
printFlags |= printFlags;
boolean b = _printString();
this.printFlags = oldPrintFlags;
return b;
}
public void calculateMetrics()
{
int oldPrintFlags = printFlags;
printFlags |= 4;
_printString();
printFlags = oldPrintFlags;
}
public void printString(GC gc, Rectangle rectangle, int swtFlags)
{
this.gc = gc;
int printFlags = this.printFlags;
if (printArea.width == rectangle.width)
printFlags |= 8;
printArea = rectangle;
this.swtFlags = swtFlags;
printString(printFlags);
}
public Point getCalculatedSize()
{
return size;
}
public Color getUrlColor()
{
return urlColor;
}
public void setUrlColor(Color urlColor)
{
this.urlColor = urlColor;
}
public URLInfo getHitUrl(int x, int y)
{
if (listUrlInfo == null || listUrlInfo.size() == 0)
return null;
Iterator iter = listUrlInfo.iterator();
URLInfo urlInfo;
label0:
do
if (iter.hasNext())
{
urlInfo = (URLInfo)iter.next();
if (urlInfo.hitAreas == null)
continue;
Iterator iter2 = urlInfo.hitAreas.iterator();
Rectangle r;
do
{
if (!iter2.hasNext())
continue label0;
r = (Rectangle)iter2.next();
} while (!r.contains(x, y));
break;
} else
{
return null;
}
while (true);
return urlInfo;
}
public URLInfo[] getHitUrlInfo()
{
if (listUrlInfo == null)
return new URLInfo[0];
else
return (URLInfo[])(URLInfo[])listUrlInfo.toArray(new URLInfo[0]);
}
public boolean hasHitUrl()
{
return listUrlInfo != null && listUrlInfo.size() > 0;
}
public boolean isCutoff()
{
return cutoff;
}
public void setImages(Image images[])
{
this.images = images;
}
public float[] getImageScales()
{
return imageScales;
}
public void setImageScales(float imageScales[])
{
this.imageScales = imageScales;
}
public String getText()
{
return string;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -