use of org.eclipse.swt.events.PaintEvent 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.PaintEvent 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.PaintEvent 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.PaintEvent 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();
}
use of org.eclipse.swt.events.PaintEvent in project dbeaver by serge-rider.
the class DBeaverSplashHandler method initVisualization.
private void initVisualization() {
String progressRectString = null, messageRectString = null, foregroundColorString = null, versionCoordString = null, versionInfoSizeString = null, versionInfoColorString = null;
final IProduct product = Platform.getProduct();
if (product != null) {
progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
versionCoordString = product.getProperty("versionInfoCoord");
versionInfoSizeString = product.getProperty("versionInfoSize");
versionInfoColorString = product.getProperty("versionInfoColor");
}
setProgressRect(StringConverter.asRectangle(progressRectString, new Rectangle(275, 300, 280, 10)));
setMessageRect(StringConverter.asRectangle(messageRectString, new Rectangle(275, 275, 280, 25)));
final Point versionCoord = StringConverter.asPoint(versionCoordString, new Point(485, 215));
final int versionInfoSize = StringConverter.asInt(versionInfoSizeString, 22);
final RGB versionInfoRGB = StringConverter.asRGB(versionInfoColorString, new RGB(255, 255, 255));
int foregroundColorInteger = 0xD2D7FF;
try {
if (foregroundColorString != null) {
foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
}
} catch (Exception ex) {
// ignore
}
setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
normalFont = getContent().getFont();
//boldFont = UIUtils.makeBoldFont(normalFont);
FontData[] fontData = normalFont.getFontData();
fontData[0].setStyle(fontData[0].getStyle() | SWT.BOLD);
fontData[0].setHeight(versionInfoSize);
boldFont = new Font(normalFont.getDevice(), fontData[0]);
final Color versionColor = new Color(getContent().getDisplay(), versionInfoRGB);
getContent().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
String productVersion = "";
if (product != null) {
productVersion = GeneralUtils.getProductVersion().toString();
}
//String osVersion = Platform.getOS() + " " + Platform.getOSArch();
if (boldFont != null) {
e.gc.setFont(boldFont);
}
e.gc.setForeground(versionColor);
e.gc.drawText(productVersion, versionCoord.x, versionCoord.y, true);
//e.gc.drawText(osVersion, 115, 200, true);
e.gc.setFont(normalFont);
}
});
}
Aggregations