use of org.eclipse.swt.events.ControlEvent in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method createTemplateTree.
/**
* Create the tree to display templates.
*
* @param parent the parent composite
*/
private void createTemplateTree(Composite parent) {
Composite treeComposite = new Composite(parent, SWT.NONE);
GridData data = new GridData(GridData.FILL_BOTH);
treeComposite.setLayoutData(data);
TreeColumnLayout columnLayout = new TreeColumnLayout();
treeComposite.setLayout(columnLayout);
fTemplatesTree = new Tree(treeComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
fTemplatesTree.setHeaderVisible(true);
fTemplatesTree.setLinesVisible(true);
PixelConverter pixelConverter = new PixelConverter(fTemplatesTree);
TreeColumn columnName = new TreeColumn(fTemplatesTree, SWT.NONE);
columnName.setText(TemplatesMessages.TemplatesPage_column_name);
int minWidth = fPreferenceStore.getInt(COLUMN_NAME_WIDTH_PREF_ID);
if (minWidth == 0) {
minWidth = pixelConverter.convertWidthInCharsToPixels(30);
}
columnLayout.setColumnData(columnName, new ColumnPixelData(minWidth, true));
columnName.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
int nameWidth = ((TreeColumn) e.getSource()).getWidth();
fPreferenceStore.setValue(COLUMN_NAME_WIDTH_PREF_ID, nameWidth);
}
});
TreeColumn columnDescription = new TreeColumn(fTemplatesTree, SWT.NONE);
columnDescription.setText(TemplatesMessages.TemplatesPage_column_description);
minWidth = fPreferenceStore.getInt(COLUMN_DESCRIPTION_WIDTH_PREF_ID);
if (minWidth == 0) {
minWidth = pixelConverter.convertWidthInCharsToPixels(45);
}
columnLayout.setColumnData(columnDescription, new ColumnPixelData(minWidth, false));
columnDescription.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
int descriptionWidth = ((TreeColumn) e.getSource()).getWidth();
fPreferenceStore.setValue(COLUMN_DESCRIPTION_WIDTH_PREF_ID, descriptionWidth);
}
});
createTreeViewer(fTemplatesTree);
}
use of org.eclipse.swt.events.ControlEvent in project eclipse.platform.text by eclipse.
the class AnnotationRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
fHitDetectionCursor = parentControl.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fCanvas = createCanvas(parentControl);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseListener = new MouseListener() {
@Override
public void mouseUp(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseClicked(lineNumber);
}
@Override
public void mouseDown(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
AnnotationRulerColumn.this.mouseDown(lineNumber);
}
@Override
public void mouseDoubleClick(MouseEvent event) {
int lineNumber;
if (isPropagatingMouseListener()) {
fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
lineNumber = fParentRuler.getLineOfLastMouseButtonActivity();
} else
lineNumber = fParentRuler.toDocumentLineNumber(event.y);
if (1 == event.button)
mouseDoubleClicked(lineNumber);
}
};
fCanvas.addMouseListener(fMouseListener);
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
handleMouseMove(e);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fLineListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
use of org.eclipse.swt.events.ControlEvent in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
fParentRuler = parentRuler;
fCachedTextViewer = parentRuler.getTextViewer();
fCachedTextWidget = fCachedTextViewer.getTextWidget();
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the line ruler
fCachedTextWidget.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fCachedTextWidget != null && fCachedTextWidget.getWordWrap()) {
postRedraw();
}
}
});
// track when StyledText is redrawn to check if some line height changed. In this case, the ruler must be redrawn
// to draw line number with well height.
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCanvas = new Canvas(parentControl, SWT.NO_FOCUS) {
@Override
public void addMouseListener(MouseListener listener) {
// see bug 40889, bug 230073 and AnnotationRulerColumn#isPropagatingMouseListener()
if (listener == fMouseHandler)
super.addMouseListener(listener);
else {
TypedListener typedListener = null;
if (listener != null)
typedListener = new TypedListener(listener);
addListener(SWT.MouseDoubleClick, typedListener);
}
}
};
fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
fCanvas.setForeground(fForeground);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fCachedTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
handleDispose();
fCachedTextViewer = null;
fCachedTextWidget = null;
}
});
fMouseHandler = new MouseHandler();
fCanvas.addMouseListener(fMouseHandler);
fCanvas.addMouseMoveListener(fMouseHandler);
fCanvas.addMouseWheelListener(fMouseHandler);
if (fCachedTextViewer != null) {
VisibleLinesTracker.track(fCachedTextViewer, lineHeightChangeHandler);
fCachedTextViewer.addTextListener(fInternalListener);
if (fFont == null) {
if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
fFont = fCachedTextWidget.getFont();
}
}
if (fFont != null)
fCanvas.setFont(fFont);
updateNumberOfDigits();
computeIndentations();
return fCanvas;
}
use of org.eclipse.swt.events.ControlEvent in project eclipse.platform.swt by eclipse.
the class MJ_Table method cout_visible_items_Snippet253.
@Test
public void cout_visible_items_Snippet253() {
final Shell shell = mkShell("Ensure correct item count is displayed in count. Try resizing shell to show 15 items, it should show 15. Gtk3 issues");
knownToBeBrokenGtk3("On gtk3, the measure is off, see bug 531884");
FillLayout layout = new FillLayout(SWT.VERTICAL);
shell.setLayout(layout);
final Table table = new Table(shell, SWT.NONE);
for (int i = 0; i < 32; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("Item " + (i + 1) + " is quite long");
}
final Button button = new Button(shell, SWT.PUSH);
Runnable fixCount = () -> {
Rectangle rect = table.getClientArea();
int itemHeight = table.getItemHeight();
int headerHeight = table.getHeaderHeight();
int visibleCount = (rect.height - headerHeight + itemHeight - 1) / itemHeight;
button.setText("Visible Items [" + visibleCount + "]");
};
button.setText("Visible Items []");
button.addListener(SWT.Selection, e -> {
fixCount.run();
});
shell.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
fixCount.run();
}
});
shell.addShellListener(new ShellAdapter() {
@Override
public void shellActivated(ShellEvent e) {
fixCount.run();
}
});
// setSize(..)_ affects bug/snippet behaviour.
// 820 => ~15 items or so, depending on your theme.
shell.setSize(1160, 820);
shell.open();
mainLoop(shell);
}
use of org.eclipse.swt.events.ControlEvent in project yamcs-studio by yamcs.
the class ClientsTableViewer method addFixedColumns.
private void addFixedColumns() {
TableViewerColumn idColumn = new TableViewerColumn(this, SWT.CENTER);
idColumn.getColumn().setText(COL_ID);
idColumn.getColumn().setWidth(30);
idColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return String.valueOf(client.getId());
}
});
TableViewerColumn userColumn = new TableViewerColumn(this, SWT.LEFT);
userColumn.getColumn().setText(COL_USER);
userColumn.getColumn().setWidth(100);
userColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return String.valueOf(client.getUsername());
}
});
TableViewerColumn applicationColumn = new TableViewerColumn(this, SWT.LEFT);
applicationColumn.getColumn().setText(COL_APPLICATION);
applicationColumn.getColumn().setWidth(100);
applicationColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getApplicationName();
}
});
TableViewerColumn instanceColumn = new TableViewerColumn(this, SWT.LEFT);
instanceColumn.getColumn().setText(COL_INSTANCE);
instanceColumn.getColumn().setWidth(100);
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getInstance();
}
});
TableViewerColumn processorColumn = new TableViewerColumn(this, SWT.LEFT);
processorColumn.getColumn().setText(COL_PROCESSOR);
processorColumn.getColumn().setWidth(100);
processorColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getProcessorName();
}
});
// prevent resize to 0
for (TableColumn column : getTable().getColumns()) {
column.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (column.getWidth() < 5) {
column.setWidth(5);
}
}
});
}
}
Aggregations