use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class JaretTable method preparePaint.
/**
* Calculate the layout of the table area rectangles.
*
* @param width width of the table
* @param height height of the table
*/
private void preparePaint(int width, int height) {
if (_drawHeader) {
_headerRect = new Rectangle(0, 0, width, _headerHeight);
} else {
_headerRect = new Rectangle(0, 0, 0, 0);
}
if (_autoFilterEnabled) {
// preferred height of the autofilters
int autoFilterHeight = getPreferredAutoFilterHeight();
_autoFilterRect = new Rectangle(0, _headerRect.y + _headerRect.height, _headerRect.width, autoFilterHeight);
_tableRect = new Rectangle(0, _autoFilterRect.y + _autoFilterRect.height, width, height - _autoFilterRect.height);
} else {
_tableRect = new Rectangle(0, _headerRect.y + _headerRect.height, width, height - _headerRect.height);
}
// do we have fixed cols? correct other rects and calc fixed col rect
if (_fixedColumns > 0) {
int fWidth = getFixedColumnsWidth();
_headerRect.x = _headerRect.x + fWidth;
_headerRect.width = _headerRect.width - fWidth;
if (_autoFilterEnabled) {
_autoFilterRect.x = _headerRect.x;
_autoFilterRect.width = _headerRect.width;
}
_tableRect.x = _headerRect.x;
_tableRect.width = _headerRect.width;
_fixedColRect = new Rectangle(0, _tableRect.y, fWidth, _tableRect.height);
} else {
_fixedColRect = new Rectangle(_tableRect.x, _tableRect.y, 0, _tableRect.height);
}
// do we have fixed rows? correct other rects nd setup the fixed row rect
if (_fixedRows > 0) {
int fHeight = getFixedRowsHeight();
if (_autoFilterEnabled) {
_fixedRowRect = new Rectangle(0, _autoFilterRect.y + _autoFilterRect.height, width, getFixedRowsHeight());
} else {
_fixedRowRect = new Rectangle(0, _headerRect.y + _headerRect.height, width, getFixedRowsHeight());
}
_tableRect.y = _tableRect.y + fHeight;
_tableRect.height = _tableRect.height - fHeight;
if (_fixedColumns > 0) {
_fixedColRect.y = _tableRect.y;
_fixedColRect.height = _tableRect.height;
}
} else {
// ensure fixed Row rect is available
_fixedRowRect = new Rectangle(_tableRect.x, _tableRect.y, _tableRect.width, 0);
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class JaretTable method startEditing.
/**
* Start editing of a specified cell if it is editable.
*
* @param row row
* @param col column
* @param typedKey key typed
*/
public void startEditing(IRow row, IColumn col, char typedKey) {
if (isEditing()) {
stopEditing(true);
}
if (!_model.isEditable(row, col)) {
return;
}
clearSelection();
if (row != null && col != null) {
_editor = getCellEditor(row, col);
if (_editor != null) {
_editorControl = _editor.getEditorControl(this, row, col, typedKey);
if (_editorControl != null) {
Rectangle bounds = getCellBounds(row, col);
// TODO borderwidth
bounds.x += 1;
bounds.width -= 1;
bounds.y += 1;
if (_editor.getPreferredHeight() == -1 || _editor.getPreferredHeight() < bounds.height) {
bounds.height -= 1;
} else {
bounds.height = _editor.getPreferredHeight();
}
_editorControl.setBounds(bounds);
_editorControl.setVisible(true);
_editorControl.forceFocus();
}
_editorRow = row;
} else {
// System.out.println("no cell editor found!");
}
}
if (_editorControl == null) {
stopEditing(true);
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class JaretTable method getToolTipText.
/**
* Supply tooltip text for a position in the table.
*
* @param x x coordinate
* @param y y coordinate
* @return tooltip text or <code>null</code>
*/
private String getToolTipText(int x, int y) {
IJaretTableCell cell = getCell(x, y);
if (cell != null) {
Rectangle bounds = getCellBounds(cell);
ICellRenderer renderer = getCellRenderer(cell.getRow(), cell.getColumn());
if (renderer != null) {
String tt = renderer.getTooltip(this, bounds, cell.getRow(), cell.getColumn(), x, y);
if (tt != null) {
return tt;
}
}
}
return null;
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class JaretTable method mousePressed.
/**
* Handle mouse pressed.
*
* @param x x coordinate
* @param y y coordinate
* @param popuptrigger true if the button pressed was the popup trigger
* @param stateMask statemask from the event
*/
private void mousePressed(int x, int y, boolean popuptrigger, int stateMask) {
// check for location over drag marker and start fill drag if necessary
if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
_isFillDrag = true;
_firstFillDragSelect = _selectedIdxRectangle;
return;
}
IRow row = rowByBottomBorder(y);
if (row != null && _rowResizeAllowed && (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR) && (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect.contains(x, y)))) {
_heightDraggedRowInfo = getRowInfo(row);
return;
} else {
IColumn col = colByRightBorder(x);
if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col) && (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
_widthDraggedColumn = getColInfo(col);
return;
}
}
// check header drag
if (_headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
_headerDragged = true;
return;
}
// handle mouse press for selection
boolean doSelect = true;
// check focus set
if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y)) || (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
setFocus(x, y);
doSelect = !handleEditorSingleClick(x, y);
}
// check hierarchy
if (_tableRect.contains(x, y) || (_fixedColumns > 0 && _fixedColRect.contains(x, y)) || (_fixedRows > 0 && _fixedRowRect.contains(x, y))) {
IRow xrow = rowForY(y);
IColumn xcol = colForX(x);
if (xrow != null && xcol != null && isHierarchyColumn(xrow, xcol)) {
Rectangle rect = getCellBounds(xrow, xcol);
IHierarchyRenderer hrenderer = (IHierarchyRenderer) getCellRenderer(xrow, xcol);
if (hrenderer.isInActiveArea(xrow, rect, x, y)) {
toggleExpanded(xrow);
}
}
}
// check header sorting clicks
IColumn xcol = colForX(x);
if (_allowSorting && _headerRect.contains(x, y) && _headerRenderer.isSortingClick(getHeaderDrawingArea(xcol), xcol, x, y)) {
_tvs.setSorting(xcol);
} else if (doSelect) {
// selection can be intercepted by editor clicks
handleSelection(x, y, stateMask, false);
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class JaretTable method handleVerticalScroll.
/**
* Handle a selection on the vertical scroll bar (a vertical scroll).
*
* @param event selection
*/
private void handleVerticalScroll(SelectionEvent event) {
int value = getVerticalBar().getSelection() + getFixedRowsHeight();
int rowidx = getRowIdxForAbsY(value);
int offset = value - getAbsBeginYForRowIdx(rowidx);
int oldFirstIdx = _firstRowIdx;
int oldPixelOffset = _firstRowPixelOffset;
int diff = _oldVerticalScroll - value;
if (Math.abs(diff) > _tableRect.height / 2 || _oldVerticalScroll == -1 || !_optimizeScrolling) {
update();
_firstRowIdx = rowidx;
_firstRowPixelOffset = offset;
// kill the cache
_rowInfoCache = null;
redraw();
} else {
Rectangle completeArea = new Rectangle(_fixedColRect.x, _tableRect.y, _fixedColRect.width + _tableRect.width, _tableRect.height);
if (diff > 0) {
scroll(0, completeArea.y + diff, 0, completeArea.y, getWidth(), completeArea.height - diff, false);
} else {
diff = -diff;
scroll(0, completeArea.y, 0, completeArea.y + diff, getWidth(), completeArea.height - diff, false);
}
_firstRowIdx = rowidx;
_firstRowPixelOffset = offset;
// kill the cache
_rowInfoCache = null;
}
_oldVerticalScroll = value;
firePropertyChange(PROPERTYNAME_FIRSTROWIDX, oldFirstIdx, _firstRowIdx);
firePropertyChange(PROPERTYNAME_FIRSTROWPIXELOFFSET, oldPixelOffset, _firstRowPixelOffset);
}
Aggregations