use of org.eclipse.swt.widgets.Canvas in project dbeaver by dbeaver.
the class EmptyPresentation method createPresentation.
@Override
public void createPresentation(@NotNull final IResultSetController controller, @NotNull Composite parent) {
super.createPresentation(controller, parent);
UIUtils.createHorizontalLine(parent);
placeholder = new Canvas(parent, SWT.NONE);
placeholder.setLayoutData(new GridData(GridData.FILL_BOTH));
placeholder.setBackground(controller.getDefaultBackground());
final Font normalFont = parent.getFont();
FontData[] fontData = normalFont.getFontData();
fontData[0].setStyle(fontData[0].getStyle() | SWT.BOLD);
fontData[0].setHeight(18);
final Font largeFont = new Font(normalFont.getDevice(), fontData[0]);
placeholder.addDisposeListener(e -> UIUtils.dispose(largeFont));
placeholder.addPaintListener(e -> {
if (controller.isRefreshInProgress()) {
return;
}
e.gc.setFont(largeFont);
e.gc.setForeground(UIStyles.getDefaultTextForeground());
// int fontSize = largeFont.getFontData()[0].getHeight();
String emptyDataMessage = controller.getDecorator().getEmptyDataMessage();
if (!CommonUtils.isEmpty(emptyDataMessage)) {
Point emSize = e.gc.textExtent(emptyDataMessage);
UIUtils.drawMessageOverControl(placeholder, e, emptyDataMessage, -emSize.y);
}
e.gc.setFont(normalFont);
String emptyDataDescription = controller.getDecorator().getEmptyDataDescription();
if (!CommonUtils.isEmpty(emptyDataDescription)) {
UIUtils.drawMessageOverControl(placeholder, e, emptyDataDescription, 10);
}
});
trackPresentationControl();
}
use of org.eclipse.swt.widgets.Canvas in project nebula.widgets.nattable by eclipse.
the class NatCombo method createTextControl.
/**
* Creates the Text control of this NatCombo, adding styles, look&feel
* and needed listeners for the control only.
*
* @param style
* The style for the Text Control to construct. Uses this style
* adding internal styles via ConfigRegistry.
*/
protected void createTextControl(int style) {
int widgetStyle = style | HorizontalAlignmentEnum.getSWTStyle(this.cellStyle);
this.text = new Text(this, widgetStyle);
this.text.setBackground(this.cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
this.text.setForeground(this.cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
this.text.setFont(this.cellStyle.getAttributeValue(CellStyleAttributes.FONT));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
this.text.setLayoutData(gridData);
this.text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
showDropdownControl();
int selectionIndex = getDropdownTable().getSelectionIndex();
if (selectionIndex < 0) {
select(0);
} else {
// only visualize the selection in the dropdown, do not
// perform a selection
getDropdownTable().select(selectionIndex);
}
// ensure the arrow key events do not have any further
// effect
event.doit = false;
} else if (!LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character)) {
if (NatCombo.this.freeEdit) {
// free value in text control will be used
if (!getDropdownTable().isDisposed()) {
getDropdownTable().deselectAll();
for (Map.Entry<String, Boolean> entry : NatCombo.this.selectionStateMap.entrySet()) {
entry.setValue(Boolean.FALSE);
}
}
} else {
showDropdownControl();
}
}
}
});
this.text.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (!NatCombo.this.freeEdit) {
if (getDropdownTable().isDisposed() || !getDropdownTable().isVisible()) {
showDropdownControl();
} else {
// if there is no free edit enabled, set the focus back
// to the dropdownlist so it handles key strokes itself
getDropdownTable().forceFocus();
}
}
}
});
this.text.addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
calculateBounds();
}
@Override
public void controlMoved(ControlEvent e) {
calculateBounds();
}
});
this.text.addFocusListener(new FocusListenerWrapper());
final Canvas iconCanvas = new Canvas(this, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle iconImageBounds = NatCombo.this.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() {
@Override
public void paintControl(PaintEvent event) {
GC gc = event.gc;
Rectangle iconCanvasBounds = iconCanvas.getBounds();
Rectangle iconImageBounds = NatCombo.this.iconImage.getBounds();
int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
gc.drawImage(NatCombo.this.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) {
if (NatCombo.this.dropdownShell != null && !NatCombo.this.dropdownShell.isDisposed()) {
if (NatCombo.this.dropdownShell.isVisible()) {
NatCombo.this.text.forceFocus();
hideDropdownControl();
} else {
showDropdownControl();
}
} else {
showDropdownControl();
}
}
});
}
use of org.eclipse.swt.widgets.Canvas in project jbosstools-hibernate by jbosstools.
the class DiagramContentOutlinePage method createControl.
/**
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
pageBook = new PageBook(parent, SWT.NONE);
outline = getViewer().createControl(pageBook);
overview = new Canvas(pageBook, SWT.NONE);
pageBook.showPage(outline);
configureOutlineViewer();
hookOutlineViewer();
initializeOutlineViewer();
}
use of org.eclipse.swt.widgets.Canvas in project core by jcryptool.
the class NewKeyComposite method initGUI.
private void initGUI() {
try {
GridLayout thisLayout = new GridLayout();
thisLayout.numColumns = 3;
this.setLayout(thisLayout);
// this.setSize(396, 100);
{
GridData canvas1LData = new GridData();
canvas1LData.widthHint = 48;
canvas1LData.heightHint = 48;
canvas1 = new Canvas(this, SWT.NONE);
canvas1.setLayoutData(canvas1LData);
canvas1.addPaintListener(new PaintListener() {
ImageDescriptor imgDescriptor = getKeyImageDescriptor();
public void paintControl(PaintEvent e) {
// $NON-NLS-1$
e.gc.drawImage(imgDescriptor.createImage(), 0, 0);
}
});
}
{
infoComposite = new Composite(this, SWT.NONE);
GridLayout infoCompositeLayout = new GridLayout();
infoCompositeLayout.makeColumnsEqualWidth = true;
infoCompositeLayout.verticalSpacing = 1;
infoCompositeLayout.marginHeight = 0;
GridData infoCompositeLData = new GridData();
infoCompositeLData.grabExcessHorizontalSpace = true;
infoCompositeLData.grabExcessVerticalSpace = true;
infoCompositeLData.horizontalAlignment = GridData.FILL;
infoCompositeLData.verticalAlignment = GridData.CENTER;
infoComposite.setLayoutData(infoCompositeLData);
infoComposite.setLayout(infoCompositeLayout);
{
labelInfo1 = new Label(infoComposite, SWT.NONE);
GridData labelInfo1LData = new GridData();
labelInfo1LData.grabExcessHorizontalSpace = true;
labelInfo1LData.horizontalAlignment = GridData.FILL;
labelInfo1.setLayoutData(labelInfo1LData);
// $NON-NLS-1$
setInfoLabelText();
// $NON-NLS-1$
labelInfo1.setFont(SWTResourceManager.getFont("Segoe UI", 9, 1, false, false));
}
{
labelOwner = new Label(infoComposite, SWT.NONE);
GridData labelOwnerLData = new GridData();
labelOwner.setLayoutData(labelOwnerLData);
// $NON-NLS-1$
labelOwner.setText(Messages.getString("NewKeyComposite.owner") + publicKeyAlias.getContactName());
}
{
labelType = new Label(infoComposite, SWT.NONE);
GridData labelTypeLData = new GridData();
labelType.setLayoutData(labelTypeLData);
labelType.setText(publicKeyAlias.getOperation());
}
}
{
GridData buttonDeleteLData = new GridData();
buttonDeleteLData.widthHint = 24;
buttonDeleteLData.heightHint = 24;
buttonDeleteLData.grabExcessVerticalSpace = true;
buttonDeleteLData.verticalAlignment = SWT.FILL;
buttonDelete = new Button(this, SWT.PUSH | SWT.CENTER);
buttonDelete.setLayoutData(buttonDeleteLData);
// $NON-NLS-1$
buttonDelete.setImage(KeyStorePlugin.getImageDescriptor("icons/16x16/cancel.png").createImage());
// $NON-NLS-1$
buttonDelete.setToolTipText(Messages.getString("NewKeyComposite.removeKeypairBtn"));
buttonDelete.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
removeKeyFromKeystore();
}
});
}
this.layout();
} catch (Exception ex) {
LogUtil.logError(IntegratorPlugin.PLUGIN_ID, ex);
}
}
use of org.eclipse.swt.widgets.Canvas in project tmdm-studio-se by Talend.
the class SWTResourceManager method fixCoolBarSize.
// ////////////////////////////
// CoolBar support
// ////////////////////////////
/**
* Fix the layout of the specified CoolBar
* @param bar CoolBar The CoolBar that shgoud be fixed
*/
public static void fixCoolBarSize(CoolBar bar) {
CoolItem[] items = bar.getItems();
// ensure that each item has control (at least empty one)
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
if (item.getControl() == null)
item.setControl(new Canvas(bar, SWT.NONE) {
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(20, 20);
}
});
}
// compute size for each item
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
Control control = item.getControl();
control.pack();
Point size = control.getSize();
item.setSize(item.computeSize(size.x, size.y));
}
}
Aggregations