下面列出了org.eclipse.swt.widgets.Layout#org.eclipse.swt.graphics.Point 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Figure out if the click point is closer to the left/right edge of the cell.
* @param cellBounds of the table cell containing the click
* @param clickPt
* @param distanceFromEdge distance from the edge to qualify as <i>close</i> to the cell edge
*/
public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) {
if (distanceFromEdge < 0) {
distanceFromEdge = cellBounds.width / 2;
}
Rectangle left = new Rectangle(cellBounds.x, cellBounds.y, distanceFromEdge, cellBounds.height);
Rectangle right = new Rectangle(cellBounds.x + cellBounds.width - distanceFromEdge, cellBounds.y,
distanceFromEdge, cellBounds.height);
if (left.contains(clickPt)) {
return LEFT;
} else if (right.contains(clickPt)) {
return RIGHT;
} else {
return NONE;
}
}
/**
* {@inheritDoc}
*/
@Override
public Point computeSize(GC gc, int wHint, int hHint, Object value)
{
PShelfItem item = (PShelfItem)value;
if (item.getImage() == null)
return new Point(wHint,gc.getFontMetrics().getHeight() + (2*(margin+textMargin)));
int h = Math.max(item.getImage().getBounds().height,gc.getFontMetrics().getHeight() + (2*textMargin)) + (2*margin);
if (h % 2 != 0)
h ++;
return new Point(wHint,h);
}
private void treeDblClick( Event event ) {
StyledTextComp wScript = getStyledTextComp();
Point point = new Point( event.x, event.y );
TreeItem item = wTree.getItem( point );
// Qualification where the Click comes from
if ( item != null && item.getParentItem() != null ) {
if ( item.getParentItem().equals( wTreeClassesItem ) ) {
setActiveCtab( item.getText() );
} else if ( !item.getData().equals( "Snippit" ) ) {
int iStart = wScript.getCaretOffset();
int selCount = wScript.getSelectionCount(); // this selection
// will be replaced
// by wScript.insert
iStart = iStart - selCount; // when a selection is already there
// we need to subtract the position
if ( iStart < 0 ) {
iStart = 0; // just safety
}
String strInsert = (String) item.getData();
wScript.insert( strInsert );
wScript.setSelection( iStart, iStart + strInsert.length() );
}
}
}
public void mouseMove(NatTable natTable, MouseEvent event) {
if (event.x > natTable.getWidth()) {
return;
}
int selectedColumnPosition = natTable.getColumnPositionByX(event.x);
int selectedRowPosition = natTable.getRowPositionByY(event.y);
if (selectedColumnPosition > -1 && selectedRowPosition > -1) {
Point dragInCellPosition = new Point(selectedColumnPosition, selectedRowPosition);
if(lastDragInCellPosition == null || !dragInCellPosition.equals(lastDragInCellPosition)){
lastDragInCellPosition = dragInCellPosition;
fireSelectionCommand(natTable, selectedColumnPosition, selectedRowPosition, true, false);
}
}
}
/**
* @see org.eclipse.swt.widgets.Composite#computeSize(int, int, boolean)
*/
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget();
final Point computedSize = buttonRenderer.computeSize(this);
if (wHint != SWT.DEFAULT) {
computedSize.x = wHint;
}
if (hHint != SWT.DEFAULT) {
computedSize.y = hHint;
}
return computedSize;
}
/**
* @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
*/
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
checkWidget();
if (image == null && text == null) {
return super.computeSize(wHint, hHint, changed);
}
// Button
final Point buttonSize = computeButtonSize();
int width = buttonSize.x;
int height = buttonSize.y;
// Margin
width += 3 * MARGIN;
height += 3 * MARGIN;
return new Point(Math.max(width, wHint), Math.max(height, hHint));
}
private void onPaint(PaintEvent e) {
GC gc = e.gc;
Point s = getSize();
int w = s.x;
int h = s.y;
gc.setForeground(gradient1Color);
gc.setBackground(gradient2Color);
gc.fillGradientRectangle(0, 0, w, h - 1, true);
Rectangle imgsize = new Rectangle(0, 0, 0, 0);
if (image != null) {
imgsize = image.getBounds();
gc.drawImage(image, 12, 0);
}
gc.setForeground(bottomLineColor);
gc.drawLine(0, h - 1, w, h - 1);
gc.setFont(font);
gc.setForeground(writingColor);
Point textSize = gc.stringExtent(text);
int ty = (h - textSize.y) / 2;
gc.drawString(text, 22 + imgsize.width, TOP_SPACE + ty, true);
}
private static void paintImageAndText(VControl control, Event e) {
e.gc.setTextAntialias(SWT.ON);
if(control.foreground != null && !control.foreground.isDisposed()) {
e.gc.setForeground(control.foreground);
}
Rectangle ibounds = control.image.getBounds();
Point tsize = e.gc.textExtent(control.text);
int x = (int)getX(control, ibounds.width + tsize.x);
e.gc.drawImage(control.image, x, (int)getY(control, ibounds.height));
x += ibounds.width + 3;
e.gc.drawText(control.text, x, (int)getY(control, tsize.y), true);
}
/**
* Returns the initial location to use for the shell based upon the current selection in the viewer. Bottom is
* preferred to top, and right is preferred to left, therefore if possible the popup will be located below and to
* the right of the selection.
*
* @param initialSize
* the initial size of the shell, as returned by {@code getInitialSize}.
* @return the initial location of the shell
*/
@Override
protected Point getInitialLocation(final Point initialSize) {
if (null == anchor) {
return super.getInitialLocation(initialSize);
}
final Point point = anchor;
final Rectangle monitor = getShell().getMonitor().getClientArea();
if (monitor.width < point.x + initialSize.x) {
point.x = max(0, point.x - initialSize.x);
}
if (monitor.height < point.y + initialSize.y) {
point.y = max(0, point.y - initialSize.y);
}
return point;
}
@Override
protected Point onComputeSize(Composite composite, int wHint, int hHint,
boolean flushCache) {
// System.out.println("imageLabel.computeSize(" + wHint + "," + hHint +
// ")");
Point imgPrefSize = image.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// System.out.println("\tImage Width: " + imgPrefSize.x);
if (wHint != SWT.DEFAULT)
wHint = Math.max(0, wHint - imgPrefSize.x - hgap);
// System.out.println("\tReduced wHint: " + wHint);
Point textPrefSize = text.computeSize(wHint, hHint);
// System.out.println("\tImage Height: " + imgPrefSize.y);
// System.out.println("\tText Height: " + textPrefSize.y);
int height = Math.max(imgPrefSize.y, textPrefSize.y);
int width = imgPrefSize.x + hgap + textPrefSize.x;
// System.out.println("\t-> Result: " + width + "," + height);
return new Point(width, height);
}
public void updateDate2Composite() {
if (isBetweenDates()) {
date2Widget = new DateTime(widgetComp, SWT.CALENDAR);
date2Widget.addListener(SWT.Selection, e-> setDate2Selection());
time2Widget = new DateTime(widgetComp, SWT.TIME);
time2Widget.addListener(SWT.Selection, e-> setDate2Selection());
time2Widget.setHours(0);
time2Widget.setMinutes(0);
time2Widget.setSeconds(0);
} else {
if (date2Widget != null) {
date2Widget.dispose();
date2Widget = null;
time2Widget.dispose();
time2Widget = null;
}
}
widgetComp.layout(true, true);
final Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
getShell().setSize(newSize);
}
private void treeDblClick( Event event ) {
StyledTextComp wScript = getStyledTextComp();
Point point = new Point( event.x, event.y );
TreeItem item = wTree.getItem( point );
// Qualification where the Click comes from
if ( item != null && item.getParentItem() != null ) {
if ( item.getParentItem().equals( wTreeClassesItem ) ) {
setActiveCtab( item.getText() );
} else if ( !item.getData().equals( "Snippit" ) ) {
int iStart = wScript.getCaretOffset();
int selCount = wScript.getSelectionCount(); // this selection
// will be replaced
// by wScript.insert
iStart = iStart - selCount; // when a selection is already there
// we need to subtract the position
if ( iStart < 0 ) {
iStart = 0; // just safety
}
String strInsert = (String) item.getData();
wScript.insert( strInsert );
wScript.setSelection( iStart, iStart + strInsert.length() );
}
}
}
public EnterPrintDialog( Shell parent, int nrcols, int nrrows, int scale, double factorX, double factorY,
Rectangle m, double marginLeft, double marginRigth, double marginTop, double marginBottom, Image image ) {
super( parent, SWT.NONE );
props = PropsUI.getInstance();
this.nrcols = nrcols;
this.nrrows = nrrows;
this.scale = scale;
this.image = image;
this.factorx = factorX;
this.factory = factorY;
this.leftMargin = marginLeft;
this.rightMargin = marginRigth;
this.topMargin = marginTop;
this.bottomMargin = marginBottom;
page = new Point( m.width, m.height );
}
/**
* 替换 ;
*/
private void doReplace() {
CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion();
if (activeCellRegion == null) {
return;
}
StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
if(cellEditor != null){
StyledText text = cellEditor.getSegmentViewer().getTextWidget();
String sleText = text.getSelectionText();
String findStr = cmbFind.getText();
if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
findStr = findStr.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
findStr = findStr.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B");
findStr = findStr.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B");
}
if( sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase())){
Point p = text.getSelection();
text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText());
}
}
}
@Override
protected Point getInitialSize()
{
Point initialSize = super.getInitialSize();
try
{
int lastWidth = fDialogSettings.getInt(KEY_WIDTH);
// if (initialSize.x > lastWidth)
// lastWidth = initialSize.x;
int lastHeight = fDialogSettings.getInt(KEY_HEIGHT);
// if (initialSize.y > lastHeight)
// lastHeight = initialSize.y;
return new Point(lastWidth, lastHeight);
}
catch (NumberFormatException ex)
{
}
return initialSize;
}
@VisibleForTesting
void createAccountsPane(Composite accountArea) {
for (Account account : loginService.getAccounts()) {
Composite accountRow = new Composite(accountArea, SWT.NONE);
Label avatar = new Label(accountRow, SWT.NONE);
Composite secondColumn = new Composite(accountRow, SWT.NONE);
Label name = new Label(secondColumn, SWT.LEAD);
Label email = new Label(secondColumn, SWT.LEAD);
Label separator = new Label(accountArea, SWT.HORIZONTAL | SWT.SEPARATOR);
separator.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// <Avatar size> = 3 * <email label height>
Point emailSize = email.computeSize(SWT.DEFAULT, SWT.DEFAULT);
int avatarSize = emailSize.y * 3;
GridDataFactory.swtDefaults().hint(avatarSize, avatarSize).applyTo(avatar);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(accountRow);
GridLayoutFactory.fillDefaults().generateLayout(secondColumn);
if (account.getName() != null) {
name.setText(account.getName());
}
email.setText(account.getEmail()); // email is never null.
if (account.getAvatarUrl() != null) {
try {
imageLoader.loadImage(account.getAvatarUrl() + "=s" + avatarSize, avatar);
} catch (MalformedURLException ex) {
logger.log(Level.WARNING, "malformed avatar image URL", ex);
}
}
}
}
private void layout( )
{
GridData gd = (GridData) condition.getLayoutData( );
Point size = condition.computeSize( SWT.DEFAULT, SWT.DEFAULT );
if ( gd.widthHint < size.x )
gd.widthHint = size.x;
if ( gd.heightHint < size.y )
gd.heightHint = size.y;
condition.setLayoutData( gd );
condition.getShell( ).layout( );
if ( getButtonBar( ) != null )
condition.getShell( ).pack( );
}
private int getDayFromPoint(int x, int y){
int result = -1;
for (int i = 1; i <= 31; i++) {
Point p = getDayPoint(i);
Rectangle r = new Rectangle(p.x, p.y, colSize, rowSize);
if (r.contains(x, y)) {
result = i;
break;
}
}
return result;
}
/**
* {@inheritDoc}
*/
public Rectangle getTextBounds(GridItem item, boolean preferred) {
int x = leftMargin;
if (isTree()) {
x += getToggleIndent(item);
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
x += checkRenderer.getBounds().width + insideMargin;
}
Image image = item.getImage(getColumn());
if (image != null) {
x += image.getBounds().width + insideMargin;
}
Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);
GC gc = new GC(item.getParent());
gc.setFont(item.getFont(getColumn()));
Point size = gc.stringExtent(item.getText(getColumn()));
bounds.height = size.y;
if (preferred) {
bounds.width = size.x - 1;
} else {
bounds.width = getBounds().width - x - rightMargin;
}
gc.dispose();
return bounds;
}
void selectionChanged() {
Point selection= getSelection();
if (selection.equals(fLastSelection)) {
// leave caret position
} else if (selection.x == selection.y) { //empty range
fCaretPosition= selection.x;
} else if (fLastSelection.y == selection.y) {
fCaretPosition= selection.x; //same end -> assume caret at start
} else {
fCaretPosition= selection.y;
}
fLastSelection= selection;
}
public void preWindowOpen()
{
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(800, 600));
configurer.setShowFastViewBars(true);
configurer.setShowStatusLine(true);
configurer.setShowProgressIndicator(true);
configurer.setShowCoolBar(false);
// A DropTargetAdapter is need for editor DND support
final DropTargetListener dtl = new EditorAreaDropAdapter(
configurer.getWindow());
configurer.configureEditorAreaDropListener(dtl);
}
/**
* @return
*
* @since 3.1.1.1
*/
private String getToolTip(Point mousePos_RelativeToItem) {
List<MdiEntryVitalityImageSWT> vitalityImages = mdiEntry.getVitalityImages();
for (MdiEntryVitalityImageSWT vitalityImage : vitalityImages) {
if (vitalityImage == null) {
continue;
}
String indicatorToolTip = vitalityImage.getToolTip();
if (indicatorToolTip == null || !vitalityImage.isVisible()) {
continue;
}
Rectangle hitArea = vitalityImage.getHitArea();
if (hitArea == null) {
continue;
}
if (hitArea.contains(mousePos_RelativeToItem)) {
return indicatorToolTip;
}
}
if (mdiEntry.getViewTitleInfo() != null) {
String tt = (String) mdiEntry.getViewTitleInfo().getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT_TOOLTIP);
return tt;
}
return null;
}
/**
* Get the time in the entry for a given X point
*
* @param x
* the x point
* @return the time or {@code null} or {@code -1} if it is out of bounds
*/
public Long getTimeForPoint(int x) {
return UIThreadRunnable.syncExec((Result<@Nullable Long>) () -> {
Rectangle bounds = widget.getBounds();
Point p = new Point(x, bounds.y + bounds.height / 2);
if (!bounds.contains(p)) {
return null;
}
return widget.getTimeAtX(x);
});
}
/**
* Calculates the difference in size between the given page and the page
* container. A larger page results in a positive delta.
*
* @param page
* the page
* @return the size difference encoded as a
* <code>new Point(deltaWidth,deltaHeight)</code>
*/
private Point calculatePageSizeDelta(IWizardPage page) {
Control pageControl = page.getControl();
if (pageControl == null) {
// control not created yet
return new Point(0, 0);
}
Point contentSize = pageControl.computeSize(SWT.DEFAULT, SWT.DEFAULT,
true);
Rectangle rect = pageContainerLayout.getClientArea(pageContainer);
Point containerSize = new Point(rect.width, rect.height);
return new Point(Math.max(0, contentSize.x - containerSize.x), Math
.max(0, contentSize.y - containerSize.y));
}
public TabBarItem getItem(Point point)
{
int tabStartY = getBounds().height - barHeight - itemHeight;
if (point.y < tabStartY)
return null;
if (point.y > tabStartY + itemHeight - 1)
return null;
int totalWidth = horzMargin + (itemWidth * items.size()) + (itemSpacing * items.size()) - itemSpacing + horzMargin;
int x = horzMargin;
if ((getStyle() & SWT.RIGHT) != 0)
{
if (getBounds().width > totalWidth)
{
x += getBounds().width - totalWidth;
}
}
for (Iterator iterator = items.iterator(); iterator.hasNext();)
{
TabBarItem item = (TabBarItem)iterator.next();
if (point.x >= x && point.x < x + itemWidth)
{
return item;
}
x += itemWidth + itemSpacing;
}
return null;
}
/**
* Utility method which centers a text in a rectangle.
*
* @param gc
* @param text
* @param x
* @param y
* @param width
* @param height
*/
private void drawText(final GC gc, final String text, final int x, final int y, final int width, final int height) {
Point size = canvas.getSize();
Point extent = gc.textExtent(text);
gc.setClipping(x, y, width, height);
int xx = x + (width - extent.x) / 2;
int yy = y + height / 2 - extent.y / 2;
gc.drawText(text, xx, yy, true);
gc.setClipping(0, 0, size.x, size.y);
}
private void drawTopRight() {
Point pos= new Point(getSize().x, 0);
if ((fFlags & ABSTRACT) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_ABSTRACT, pos);
}
if ((fFlags & CONSTRUCTOR) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_CONSTRUCTOR, pos);
}
if ((fFlags & FINAL) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_FINAL, pos);
}
if ((fFlags & VOLATILE) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_VOLATILE, pos);
}
if ((fFlags & STATIC) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_STATIC, pos);
}
if ((fFlags & NATIVE) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_NATIVE, pos);
}
if ((fFlags & DEFAULT_METHOD) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_ANNOTATION_DEFAULT_METHOD, pos);
}
if ((fFlags & ANNOTATION_DEFAULT) != 0) {
addTopRightImage(JavaPluginImages.DESC_OVR_ANNOTATION_DEFAULT_METHOD, pos);
}
}
protected void printFooter() {
TextBundle textBundle = UiBundle.getInstance();
String text = textBundle.format("PageNumberText", page); //$NON-NLS-1$
Point point = gc.stringExtent(text);
gc.drawString(text,
clientArea.x + (clientArea.width - point.x)/2,
clientArea.y + clientArea.height + dpiY - point.y);
page++;
}
void onMouseDown(Event e) {
if (DEBUG)
System.out.println("Mouse down "); //$NON-NLS-1$
mouseClickHandled = false;
if (!_mouseDown(e)) {
// Stop handling as requested by the group renderer
mouseClickHandled = true;
return;
}
GalleryItem item = getItem(new Point(e.x, e.y));
if (e.button == 1) {
if (item == null) {
_deselectAll(true);
redraw();
mouseClickHandled = true;
lastSingleClick = null;
} else {
if ((e.stateMask & SWT.MOD1) > 0) {
onMouseHandleLeftMod1(e, item, true, false);
} else if ((e.stateMask & SWT.SHIFT) > 0) {
onMouseHandleLeftShift(e, item, true, false);
} else {
onMouseHandleLeft(e, item, true, false);
}
}
} else if (e.button == 3) {
onMouseHandleRight(e, item, true, false);
}
}
/**
* Draw the right part of the button
*
* @param buttonSize size of the button
*/
private void drawRightPart(final Point buttonSize) {
gc.setForeground(selectedBackgroundColor);
gc.setBackground(selectedBackgroundColor);
gc.setClipping(3, 3, buttonSize.x / 2, buttonSize.y - 1);
if (round) {
gc.fillRoundRectangle(2, 2, buttonSize.x, buttonSize.y, arc, arc);
} else {
gc.fillRectangle(2, 2, buttonSize.x, buttonSize.y);
}
gc.setForeground(selectedForegroundColor);
final Point textSize = gc.textExtent(textForSelect);
gc.drawString(textForSelect, (buttonSize.x / 2 - textSize.x) / 2 + arc, (buttonSize.y - textSize.y) / 2 + arc);
}