use of org.eclipse.swt.events.PaintListener in project translationstudio8 by heartsome.
the class InnerTag method init.
// 初始化组件。
private void init() {
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
tagRender.draw(e.gc, innerTagBean, 0, 0);
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
Control parent = getParent();
if (parent instanceof StyledText) {
StyledText text = (StyledText) parent;
Point size = getSize();
Point p = getLocation();
int offset = text.getOffsetAtLocation(p);
int mouseX = e.x;
if (mouseX > size.x / 2) {
text.setCaretOffset(offset + 1);
} else {
text.setCaretOffset(offset);
}
}
}
});
}
use of org.eclipse.swt.events.PaintListener in project translationstudio8 by heartsome.
the class CheckBoxCellEditor method activateCell.
/**
* As soon as the editor is activated, flip the current data value and commit it.<br/>
* The repaint will pick up the new value and flip the image.
*/
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) {
setCanonicalValue(originalCanonicalValue);
checked = !checked;
canvas = new Canvas(parent, SWT.NONE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent paintEvent) {
Rectangle bounds = canvas.getBounds();
Rectangle rect = new Rectangle(0, 0, bounds.width, bounds.height);
checkBoxCellPainter.paintIconImage(paintEvent.gc, rect, bounds.height / 2 - checkBoxCellPainter.getPreferredHeight(checked) / 2, checked);
}
});
canvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
checked = !checked;
canvas.redraw();
}
});
commit(MoveDirectionEnum.NONE, false);
return canvas;
}
use of org.eclipse.swt.events.PaintListener in project cubrid-manager by CUBRID.
the class CommonUITool method hackForYosemite.
/**
* Because the table has some problems of SWT library on Yosemite, all the table need add this patch.
* Fix for #64 Mac OSX yosemite didn't show all records while running a query on CUBRID manager.
*
* @param table
*/
public static void hackForYosemite(final Table table) {
if (!isYosemite() || table == null || table.isDisposed()) {
return;
}
if (table.getHeaderVisible()) {
table.setHeaderVisible(true);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (!table.isDisposed()) {
try {
Method getViewMethod = Control.class.getDeclaredMethod("contentView");
getViewMethod.setAccessible(true);
Object viewObject = getViewMethod.invoke(table);
Method tileMethod = viewObject.getClass().getMethod("tile");
tileMethod.invoke(viewObject);
} catch (NoSuchMethodException ex) {
LOGGER.error(ex.getMessage());
} catch (SecurityException ex) {
LOGGER.error(ex.getMessage());
} catch (IllegalAccessException ex) {
LOGGER.error(ex.getMessage());
} catch (IllegalArgumentException ex) {
LOGGER.error(ex.getMessage());
} catch (InvocationTargetException ex) {
LOGGER.error(ex.getMessage());
}
}
}
});
table.addPaintListener(new PaintListener() {
boolean isAdjusted = false;
public void paintControl(PaintEvent e) {
if (!table.isDisposed() && !isAdjusted) {
Rectangle bounds = table.getBounds();
table.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT));
table.setBounds(bounds);
isAdjusted = true;
}
}
});
}
}
use of org.eclipse.swt.events.PaintListener in project dbeaver by serge-rider.
the class ViewValuePanel method viewValue.
private void viewValue(boolean forceRefresh) {
if (valueSaving) {
return;
}
if (valueManager == null || valueEditor == null) {
forceRefresh = true;
}
if (forceRefresh) {
cleanupPanel();
// Create a new one
valueManager = previewController.getValueManager();
try {
valueEditor = valueManager.createEditor(previewController);
} catch (Throwable e) {
UIUtils.showErrorDialog(viewPlaceholder.getShell(), "Value preview", "Can't create value viewer", e);
return;
}
if (valueEditor != null) {
try {
valueEditor.createControl();
} catch (Exception e) {
log.error(e);
}
Control control = valueEditor.getControl();
if (control != null) {
UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
presentation.getController().lockActionsByFocus(control);
}
referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
if (referenceValueEditor.isReferenceValue()) {
GridLayout gl = new GridLayout(1, false);
viewPlaceholder.setLayout(gl);
valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
referenceValueEditor.createEditorSelector(viewPlaceholder);
} else {
viewPlaceholder.setLayout(new FillLayout());
}
} else {
final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
placeholder.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
Rectangle bounds = placeholder.getBounds();
String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
Point ext = e.gc.textExtent(message);
e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
}
});
referenceValueEditor = null;
}
viewPlaceholder.layout();
}
if (valueEditor instanceof BaseValueEditor) {
((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
}
if (valueEditor != null) {
try {
Object newValue = previewController.getValue();
if (newValue instanceof DBDValue) {
// Do not check for difference
valueEditor.primeEditorValue(newValue);
} else {
Object oldValue = null;
try {
if (previewController.getExecutionContext() != null) {
oldValue = valueEditor.extractEditorValue();
}
} catch (Throwable e) {
// Some error extracting current value
// This may happen if we were disconnected
}
if (!CommonUtils.equalObjects(oldValue, newValue)) {
valueEditor.primeEditorValue(newValue);
}
}
} catch (DBException e) {
log.error(e);
}
valueEditor.setDirty(false);
}
if (valueEditor instanceof BaseValueEditor) {
((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
}
}
use of org.eclipse.swt.events.PaintListener in project dbeaver by serge-rider.
the class ProgressEditorPart method createProgressPane.
private void createProgressPane(final Composite parent) {
progressCanvas = new Canvas(parent, SWT.NONE);
progressCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
e.gc.drawText("Connecting to datasource '" + getEditorInput().getDatabaseObject().getName() + "'...", 5, 5, true);
}
});
InitNodeService loadingService = new InitNodeService();
LoadingJob<IDatabaseEditorInput> loadJob = LoadingJob.createService(loadingService, new InitNodeVisualizer(loadingService));
loadJob.schedule();
}
Aggregations