use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class TypeColunmCellRenderer method getTextBounds.
/**
* {@inheritDoc}
*/
public Rectangle getTextBounds(GridItem item, boolean preferred) {
int x = leftMargin;
Image image = item.getImage(getColumn());
if (image != null) {
x += image.getBounds().width + 3;
}
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;
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class GridCopyEnable method clearSelection.
void clearSelection() {
int start = selection.x;
int end = selection.y;
selection.x = selection.y = caretOffset;
selectionAnchor = -1;
// redraw old selection, if any
if (end - start > 0 && gridTable.getItems().length != 0) {
if (layout == null && focusItemIndex != -1 && focusItemIndex != -1) {
GridItem item = gridTable.getItem(focusItemIndex);
GridColumn col = gridTable.getColumn(focusColIndex);
GridCellRenderer gcr = col.getCellRenderer();
if (gcr != null && gcr instanceof XGridCellRenderer) {
GC gc = new GC(gcr.getDisplay());
layout = ((XGridCellRenderer) gcr).getTextLayout(gc, item, focusColIndex, true, false);
gc.dispose();
}
if (layout == null) {
return;
}
}
Rectangle rect = layout.getBounds(start, end);
gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class GridCopyEnable method handleVerticalScroll.
void handleVerticalScroll(Event event) {
GridVisibleRange visibleR = gridTable.getVisibleRange();
GridItem[] items = visibleR.getItems();
boolean itemFlg = false;
for (GridItem item : items) {
if (focusItem == item) {
itemFlg = true;
}
}
boolean columnFlg = false;
GridColumn[] columns = visibleR.getColumns();
if (columns.length - 1 >= focusColIndex) {
columnFlg = true;
}
if (!itemFlg || !columnFlg) {
defaultCaret.setVisible(false);
return;
}
defaultCaret.setVisible(true);
GridColumn col = gridTable.getColumn(focusColIndex);
GridCellRenderer gcr = col.getCellRenderer();
int colIndex = gcr.getColumn();
if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
return;
}
XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
Rectangle cellBounds = focusItem.getBounds(colIndex);
GC gc = new GC(Display.getDefault());
TextLayout layout = null;
try {
layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
if (layout == null) {
gc.dispose();
return;
}
Point point = layout.getLocation(caretOffset, false);
coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
} finally {
if (layout != null) {
layout.dispose();
}
if (gc != null) {
gc.dispose();
}
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class InputDialog method setErrorMessage.
/**
* Sets or clears the error message. If not <code>null</code>, the OK button is disabled.
* @param errorMessage
* the error message, or <code>null</code> to clear
* @since 3.0
*/
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
if (errorMessageText != null && !errorMessageText.isDisposed()) {
String msg = errorMessageText.getText();
msg = msg == null ? "" : msg;
//$NON-NLS-1$
errorMessageText.setText(errorMessage == null ? "" : errorMessage);
// Disable the error message text control if there is no error, or
// no error text (empty or whitespace only). Hide it also to avoid
// color change.
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=130281
boolean hasError = errorMessage != null && (StringConverter.removeWhiteSpaces(errorMessage)).length() > 0;
errorMessageText.setEnabled(hasError);
errorMessageText.setVisible(hasError);
errorMessageText.getParent().update();
String msg2 = errorMessageText.getText();
if (!msg.equals(msg2) && initLocation != null && initSize != null) {
Point p = getShell().computeSize(initSize.x, SWT.DEFAULT);
getShell().setBounds(getConstrainedShellBounds(new Rectangle(initLocation.x, initLocation.y, initSize.x, p.y)));
}
// Access the ok button by id, in case clients have overridden button creation.
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
Control button = getButton(IDialogConstants.OK_ID);
if (button != null) {
button.setEnabled(errorMessage == null);
}
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class HorizontalRowSelectionModel method getSelections.
public List<Rectangle> getSelections() {
List<Rectangle> selectionRectangles = new ArrayList<Rectangle>();
selectionsLock.readLock().lock();
try {
int width = selectionLayer.getColumnCount();
for (int selectedRow : selectedRows) {
if (selectedRow > -1) {
selectionRectangles.add(new Rectangle(0, selectedRow, width, 1));
}
}
} finally {
selectionsLock.readLock().unlock();
}
return selectionRectangles;
}
Aggregations