use of org.eclipse.swt.events.MouseEvent in project translationstudio8 by heartsome.
the class Grid method onMouseMove.
/**
* Mouse move event handler.
*
* @param e event
*/
private void onMouseMove(MouseEvent e) {
//tooltips - see bug 203364
if (inplaceTooltipCapture && (e.x < 0 || e.y < 0 || e.x >= getBounds().width || e.y >= getBounds().height)) {
setCapture(false);
inplaceTooltipCapture = false;
//a mouseexit event should occur immediately
return;
}
//if populated will be fired at end of method.
Event selectionEvent = null;
if ((e.stateMask & SWT.BUTTON1) == 0) {
handleHovering(e.x, e.y);
} else {
if (draggingColumn) {
handleColumnDragging(e.x);
return;
}
if (resizingColumn) {
handleColumnResizerDragging(e.x);
return;
}
if (resizingRow) {
handleRowResizerDragging(e.y);
return;
}
if (pushingColumn) {
handleColumnHeaderHoverWhilePushing(e.x, e.y);
return;
}
if (cellSelectionEnabled) {
if (!cellDragSelectionOccuring && cellSelectedOnLastMouseDown) {
cellDragSelectionOccuring = true;
//XXX: make this user definable
setCursor(getDisplay().getSystemCursor(SWT.CURSOR_CROSS));
cellDragCTRL = ((e.stateMask & SWT.MOD1) != 0);
if (cellDragCTRL) {
selectedCellsBeforeRangeSelect.clear();
selectedCellsBeforeRangeSelect.addAll(selectedCells);
}
}
if (!cellRowDragSelectionOccuring && cellRowSelectedOnLastMouseDown) {
cellRowDragSelectionOccuring = true;
setCursor(getDisplay().getSystemCursor(SWT.CURSOR_CROSS));
cellDragCTRL = ((e.stateMask & SWT.MOD1) != 0);
if (cellDragCTRL) {
selectedCellsBeforeRangeSelect.clear();
selectedCellsBeforeRangeSelect.addAll(selectedCells);
}
}
if (!cellColumnDragSelectionOccuring && cellColumnSelectedOnLastMouseDown) {
cellColumnDragSelectionOccuring = true;
setCursor(getDisplay().getSystemCursor(SWT.CURSOR_CROSS));
cellDragCTRL = ((e.stateMask & SWT.MOD1) != 0);
if (cellDragCTRL) {
selectedCellsBeforeRangeSelect.clear();
selectedCellsBeforeRangeSelect.addAll(selectedCells);
}
}
int ctrlFlag = (cellDragCTRL ? SWT.MOD1 : SWT.NONE);
if (cellDragSelectionOccuring && handleCellHover(e.x, e.y)) {
GridColumn intentColumn = hoveringColumn;
GridItem intentItem = hoveringItem;
if (hoveringItem == null) {
if (e.y > headerHeight) {
//then we must be hovering way to the bottom
intentItem = getPreviousVisibleItem(null);
} else {
intentItem = (GridItem) items.get(0);
}
}
if (hoveringColumn == null) {
if (e.x > rowHeaderWidth) {
//then we must be hovering way to the right
intentColumn = getVisibleColumn_DegradeLeft(intentItem, (GridColumn) displayOrderedColumns.get(displayOrderedColumns.size() - 1));
} else {
GridColumn firstCol = (GridColumn) displayOrderedColumns.get(0);
if (!firstCol.isVisible()) {
firstCol = getNextVisibleColumn(firstCol);
}
intentColumn = firstCol;
}
}
showColumn(intentColumn);
showItem(intentItem);
selectionEvent = updateCellSelection(new Point(indexOf(intentColumn), indexOf(intentItem)), ctrlFlag | SWT.MOD2, true, false);
}
if (cellRowDragSelectionOccuring && handleCellHover(e.x, e.y)) {
GridItem intentItem = hoveringItem;
if (hoveringItem == null) {
if (e.y > headerHeight) {
//then we must be hovering way to the bottom
intentItem = getPreviousVisibleItem(null);
} else {
if (getTopIndex() > 0) {
intentItem = getPreviousVisibleItem((GridItem) items.get(getTopIndex()));
} else {
intentItem = (GridItem) items.get(0);
}
}
}
Vector cells = new Vector();
getCells(intentItem, focusItem, cells);
showItem(intentItem);
selectionEvent = updateCellSelection(cells, ctrlFlag, true, false);
}
if (cellColumnDragSelectionOccuring && handleCellHover(e.x, e.y)) {
GridColumn intentCol = hoveringColumn;
if (intentCol == null) {
if (e.y < rowHeaderWidth) {
//TODO: get the first col to the left
} else {
//TODO: get the first col to the right
}
}
//temporary
if (intentCol == null)
return;
GridColumn iterCol = intentCol;
Vector newSelected = new Vector();
boolean decreasing = (displayOrderedColumns.indexOf(iterCol) > displayOrderedColumns.indexOf(focusColumn));
do {
getCells(iterCol, newSelected);
if (iterCol == focusColumn) {
break;
}
if (decreasing) {
iterCol = getPreviousVisibleColumn(iterCol);
} else {
iterCol = getNextVisibleColumn(iterCol);
}
} while (true);
selectionEvent = updateCellSelection(newSelected, ctrlFlag, true, false);
}
}
}
if (selectionEvent != null) {
selectionEvent.stateMask = e.stateMask;
selectionEvent.button = e.button;
selectionEvent.item = getItem(new Point(e.x, e.y));
selectionEvent.x = e.x;
selectionEvent.y = e.y;
notifyListeners(SWT.Selection, selectionEvent);
}
}
use of org.eclipse.swt.events.MouseEvent in project translationstudio8 by heartsome.
the class Grid method onMouseDoubleClick.
/**
* Mouse double click event handler.
*
* @param e event
*/
private void onMouseDoubleClick(MouseEvent e) {
if (e.button == 1) {
if (hoveringOnColumnResizer) {
columnBeingResized.pack();
columnBeingResized.fireResized();
for (int index = displayOrderedColumns.indexOf(columnBeingResized) + 1; index < displayOrderedColumns.size(); index++) {
GridColumn col = (GridColumn) displayOrderedColumns.get(index);
if (col.isVisible())
col.fireMoved();
}
resizingColumn = false;
handleHoverOnColumnResizer(e.x, e.y);
return;
} else if (rowsResizeable && hoveringOnRowResizer) {
List sel = Arrays.asList(getSelection());
if (sel.contains(rowBeingResized)) {
// so update all selected rows
for (int cnt = 0; cnt < sel.size(); cnt++) ((GridItem) sel.get(cnt)).pack();
redraw();
} else {
// otherwise only update the row the user double-clicked
rowBeingResized.pack();
}
resizingRow = false;
handleHoverOnRowResizer(e.x, e.y);
return;
}
GridItem item = getItem(new Point(e.x, e.y));
if (item != null) {
if (isListening(SWT.DefaultSelection)) {
Event newEvent = new Event();
newEvent.item = item;
notifyListeners(SWT.DefaultSelection, newEvent);
} else if (item.getItemCount() > 0) {
item.setExpanded(!item.isExpanded());
if (item.isExpanded()) {
item.fireEvent(SWT.Expand);
} else {
item.fireEvent(SWT.Collapse);
}
}
}
}
}
use of org.eclipse.swt.events.MouseEvent in project translationstudio8 by heartsome.
the class Grid method onMouseDown.
/**
* Mouse down event handler.
*
* @param e event
*/
private void onMouseDown(MouseEvent e) {
// forceFocus()
if ((getStyle() & SWT.NO_FOCUS) != SWT.NO_FOCUS) {
forceFocus();
}
hideToolTip();
//if populated will be fired at end of method.
Event selectionEvent = null;
cellSelectedOnLastMouseDown = false;
cellRowSelectedOnLastMouseDown = false;
cellColumnSelectedOnLastMouseDown = false;
if (hoveringOnColumnResizer) {
if (e.button == 1) {
resizingColumn = true;
resizingStartX = e.x;
resizingColumnStartWidth = columnBeingResized.getWidth();
}
return;
}
if (rowsResizeable && hoveringOnRowResizer) {
if (e.button == 1) {
resizingRow = true;
resizingStartY = e.y;
resizingRowStartHeight = rowBeingResized.getHeight();
}
return;
}
if (e.button == 1 && handleColumnHeaderPush(e.x, e.y)) {
return;
}
if (e.button == 1 && handleColumnGroupHeaderClick(e.x, e.y)) {
return;
}
if (e.button == 1 && handleColumnFooterPush(e.x, e.y)) {
return;
}
GridItem item = getItem(new Point(e.x, e.y));
if (e.button == 1 && item != null && handleCellClick(item, e.x, e.y)) {
return;
}
if (isListening(SWT.DragDetect)) {
if ((cellSelectionEnabled && hoveringOnSelectionDragArea) || (!cellSelectionEnabled && item != null && selectedItems.contains(item))) {
if (dragDetect(e)) {
return;
}
}
}
if (item != null) {
if (cellSelectionEnabled) {
GridColumn col = getColumn(new Point(e.x, e.y));
boolean isSelectedCell = false;
if (col != null)
isSelectedCell = selectedCells.contains(new Point(indexOf(col), indexOf(item)));
if (e.button == 1 || (e.button == 3 && col != null && !isSelectedCell)) {
if (col != null) {
selectionEvent = updateCellSelection(new Point(indexOf(col), indexOf(item)), e.stateMask, false, true);
cellSelectedOnLastMouseDown = (getCellSelectionCount() > 0);
if (e.stateMask != SWT.MOD2) {
focusColumn = col;
focusItem = item;
}
//showColumn(col);
showItem(item);
redraw();
} else if (rowHeaderVisible) {
if (e.x <= rowHeaderWidth) {
boolean shift = ((e.stateMask & SWT.MOD2) != 0);
boolean ctrl = false;
if (!shift) {
ctrl = ((e.stateMask & SWT.MOD1) != 0);
}
Vector cells = new Vector();
if (shift) {
getCells(item, focusItem, cells);
} else {
getCells(item, cells);
}
int newStateMask = SWT.NONE;
if (ctrl)
newStateMask = SWT.MOD1;
selectionEvent = updateCellSelection(cells, newStateMask, shift, ctrl);
cellRowSelectedOnLastMouseDown = (getCellSelectionCount() > 0);
if (!shift) {
//set focus back to the first visible column
focusColumn = getColumn(new Point(rowHeaderWidth + 1, e.y));
focusItem = item;
}
showItem(item);
redraw();
}
}
intendedFocusColumn = focusColumn;
}
} else {
if (e.button == 2 || e.button > 3) {
return;
}
if (e.button == 3 && selectionType == SWT.MULTI) {
if ((e.stateMask & SWT.MOD2) == SWT.MOD2) {
return;
}
if ((e.stateMask & SWT.MOD1) == SWT.MOD1) {
return;
}
if (selectedItems.contains(item)) {
return;
}
}
selectionEvent = updateSelection(item, e.stateMask);
focusItem = item;
showItem(item);
redraw();
}
} else if (e.button == 1 && rowHeaderVisible && e.x <= rowHeaderWidth && e.y < headerHeight) {
// Nothing to select
if (items.size() == 0) {
return;
}
if (cellSelectionEnabled) {
//click on the top left corner means select everything
selectionEvent = selectAllCellsInternal();
focusColumn = getColumn(new Point(rowHeaderWidth + 1, 1));
} else {
//click on the top left corner means select everything
selectionEvent = selectAllRowsInternal();
}
focusItem = getItem(getTopIndex());
} else if (cellSelectionEnabled && e.button == 1 && columnHeadersVisible && e.y <= headerHeight) {
//column cell selection
GridColumn col = getColumn(new Point(e.x, e.y));
if (col == null)
return;
if (getItemCount() == 0)
return;
Vector cells = new Vector();
GridColumnGroup group = col.getColumnGroup();
if (group != null && e.y < groupHeaderHeight) {
getCells(group, cells);
} else {
getCells(col, cells);
}
selectionEvent = updateCellSelection(cells, e.stateMask, false, true);
cellColumnSelectedOnLastMouseDown = (getCellSelectionCount() > 0);
GridItem newFocusItem = getItem(0);
while (newFocusItem != null && getSpanningColumn(newFocusItem, col) != null) {
newFocusItem = getNextVisibleItem(newFocusItem);
}
if (newFocusItem != null) {
focusColumn = col;
focusItem = newFocusItem;
}
showColumn(col);
redraw();
}
if (selectionEvent != null) {
selectionEvent.stateMask = e.stateMask;
selectionEvent.button = e.button;
selectionEvent.item = item;
selectionEvent.x = e.x;
selectionEvent.y = e.y;
notifyListeners(SWT.Selection, selectionEvent);
if (!cellSelectionEnabled) {
if (isListening(SWT.DragDetect)) {
dragDetect(e);
}
}
}
}
use of org.eclipse.swt.events.MouseEvent in project translationstudio8 by heartsome.
the class NatCombo method createTextControl.
private void createTextControl() {
text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
text.setLayoutData(gridData);
text.forceFocus();
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
showDropdownControl();
int selectionIndex = dropdownList.getSelectionIndex();
selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
if (selectionIndex < 0) {
selectionIndex = 0;
}
dropdownList.select(selectionIndex);
text.setText(dropdownList.getSelection()[0]);
}
}
});
iconImage = GUIHelper.getImage("down_2");
final Canvas iconCanvas = new Canvas(this, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle iconImageBounds = iconImage.getBounds();
return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
}
};
gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
iconCanvas.setLayoutData(gridData);
iconCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
Rectangle iconCanvasBounds = iconCanvas.getBounds();
Rectangle iconImageBounds = iconImage.getBounds();
int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
Color originalFg = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
gc.setForeground(originalFg);
}
});
iconCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showDropdownControl();
}
});
}
use of org.eclipse.swt.events.MouseEvent in project translationstudio8 by heartsome.
the class CatalogManagerDialog method initListener.
/**
* 给三个按钮添加事件 ;
*/
public void initListener() {
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AddOrEditCatalogDialog addDialog = new AddOrEditCatalogDialog(getShell(), root, adHandler, true);
// 如果是点击的确定按钮,那么更新数据
if (addDialog.open() == IDialogConstants.OK_ID) {
String[][] cataValue = getCatalogValue();
tableViewer.setInput(cataValue);
tableViewer.getTable().setSelection(cataValue.length - 1);
tableViewer.getTable().showSelection();
}
}
});
// <public publicId="-//W3C//DTD XMLSCHEMA 200102//EN" uri="xml/XMLSchema.dtd"/>
// <system systemId="xliff.dtd" uri="xliff/xliff.dtd"/>
// <uri name="http://www.heartsome.net.cn/2008/XLFExtension" uri="heartsome/XLFExtension.xsd"/>
// <nextCatalog catalog="docbook5.0/catalog.xml"/>
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (table.getSelectionCount() >= 1) {
boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle"), Messages.getString("dialogs.CatalogManagerDialog.msg1"));
if (!response) {
return;
}
TableItem[] selectItems = table.getSelection();
List<String> xpathList = new LinkedList<String>();
List<String[]> dataList = new LinkedList<String[]>();
for (int i = 0; i < selectItems.length; i++) {
String name = selectItems[i].getText(1);
String id = selectItems[i].getText(2);
String url = selectItems[i].getText(3);
StringBuffer xpathSB = new StringBuffer();
if ("public".equalsIgnoreCase(name)) {
xpathSB.append("/catalog/public[@publicId='" + id + "' and @uri='" + url + "']");
} else if ("system".equalsIgnoreCase(name)) {
xpathSB.append("/catalog/system[@systemId='" + id + "' and @uri='" + url + "']");
} else if ("uri".equalsIgnoreCase(name)) {
xpathSB.append("/catalog/uri[@name='" + id + "' and @uri='" + url + "']");
} else if ("nextCatalog".equalsIgnoreCase(name)) {
xpathSB.append("/catalog/nextCatalog[@catalog='" + url + "']");
}
xpathList.add(xpathSB.toString());
dataList.add(new String[] { name, id, url });
}
adHandler.deleteCatalog(catalogXmlLocation, xpathList, dataList);
// 更新列表
tableViewer.setInput(getCatalogValue());
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle2"), Messages.getString("dialogs.CatalogManagerDialog.msg2"));
}
}
});
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editCatalog();
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
editCatalog();
}
});
}
Aggregations