use of org.eclipse.swt.events.PaintEvent in project eclipse-integration-commons by spring-projects.
the class DashboardMainPage method createFeedsSection.
private void createFeedsSection(Composite parent, final String title, FeedType feedType, String feedName) {
final Section section = new Section(parent, ExpandableComposite.TITLE_BAR) {
@Override
public void redraw() {
GridData compositeData = (GridData) feedsScrolled.getLayoutData();
compositeData.widthHint = getSize().x - 35;
compositeData.heightHint = getSize().y - 40;
compositeData.grabExcessHorizontalSpace = false;
compositeData.grabExcessVerticalSpace = false;
super.redraw();
}
};
form.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
GridData data = (GridData) section.getLayoutData();
data.heightHint = form.getSize().y - FEEDS_TEXT_WRAP_INDENT;
}
});
toolkit.adapt(section);
section.setTitleBarForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
section.setTitleBarBackground(toolkit.getColors().getColor(IFormColors.TB_BG));
section.setTitleBarBorderColor(toolkit.getColors().getColor(IFormColors.TB_BORDER));
section.setFont(FormFonts.getInstance().getBoldFont(getSite().getShell().getDisplay(), section.getFont()));
section.setText(title);
section.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).hint(300, 300).applyTo(section);
final Composite headerComposite = toolkit.createComposite(section, SWT.NONE);
RowLayout rowLayout = new RowLayout();
rowLayout.marginTop = 0;
rowLayout.marginBottom = 0;
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.createControl(headerComposite);
final PageBook pagebook = new PageBook(section, SWT.NONE);
toolkit.adapt(pagebook);
pagebook.setLayoutData(new GridLayout());
final Composite disclaimer = createDisclaimer(pagebook);
feedsScrolled = new ScrolledComposite(pagebook, SWT.V_SCROLL);
feedsScrolled.setExpandVertical(false);
feedsScrolled.setLayout(new GridLayout());
feedsScrolled.setAlwaysShowScrollBars(false);
GridDataFactory.fillDefaults().grab(true, false).applyTo(feedsScrolled);
toolkit.adapt(feedsScrolled);
feedsComposite = toolkit.createComposite(feedsScrolled);
feedsComposite.setLayout(new TableWrapLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(feedsComposite);
feedsScrolled.setContent(feedsComposite);
feedsComposite.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GridData data = (GridData) feedsComposite.getLayoutData();
data.widthHint = section.getSize().x - FEEDS_TEXT_WRAP_INDENT;
data.heightHint = form.getSize().y - 50;
}
});
section.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
GridData data = (GridData) feedsScrolled.getLayoutData();
data.heightHint = form.getSize().y - 50;
data.grabExcessVerticalSpace = false;
feedsScrolled.setSize(section.getSize().x - 40, form.getSize().y - 50);
for (Control feedControl : feedControls) {
if (!feedControl.isDisposed()) {
((TableWrapData) feedControl.getLayoutData()).maxWidth = section.getSize().x - FEEDS_TEXT_WRAP_INDENT;
// Point size = feedControl.computeSize(data.widthHint,
// 400);
// feedControl.setSize(size);
// feedControl.pack(true);
}
}
feedsComposite.pack();
}
});
feedControls = new HashSet<Control>();
final Map<String, String> springMap = new HashMap<String, String>();
String[] urls = ResourceProvider.getUrls(RESOURCE_DASHBOARD_FEEDS_BLOGS);
for (String url : urls) {
springMap.put(url, null);
}
getEditorSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
FeedsReader reader = new FeedsReader();
CachedFeedsManager manager = new CachedFeedsManager(title, springMap, reader);
try {
manager.readCachedFeeds(null);
Set<SyndEntry> entries = new HashSet<SyndEntry>();
for (SyndFeed entry : reader.getFeeds()) {
entries.addAll(entry.getEntries());
}
if (!getManagedForm().getForm().isDisposed()) {
displayFeeds(entries, feedsComposite, feedsScrolled, pagebook, disclaimer, section);
}
} catch (IllegalArgumentException e) {
StatusHandler.log(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "An unexpected error occurred while retrieving feed content from cache.", e));
} catch (FeedException e) {
StatusHandler.log(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "An unexpected error occurred while retrieving feed content from cache.", e));
}
}
});
refreshFeedsAction = new Action("Refresh Feeds", CommonImages.REFRESH) {
@Override
public void run() {
Map<String, String> springMap = getFeedsMap();
displayFeeds(feedsComposite, feedsScrolled, pagebook, disclaimer, springMap, title, section);
}
};
Action configureURLsAction = new Action("Configure URLs", StsUiImages.RSS_CONFIGURE) {
@Override
public void run() {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getSite().getShell(), URL_CONFIGURATION_ID, new String[] { URL_CONFIGURATION_ID }, null);
dialog.open();
}
};
section.setClient(pagebook);
section.setTextClient(headerComposite);
toolBarManager.add(configureURLsAction);
toolBarManager.add(refreshFeedsAction);
toolBarManager.update(true);
refreshFeedsAction.run();
}
use of org.eclipse.swt.events.PaintEvent in project webtools.sourceediting by eclipse.
the class AbstractSection method createPainter.
protected PaintListener createPainter() {
return new PaintListener() {
public void paintControl(PaintEvent e) {
// Rectangle bounds = composite.getClientArea();
GC gc = e.gc;
gc.setForeground(gc.getBackground());
gc.setBackground(getWidgetFactory().getColors().getColor(FormColors.TB_BG));
// gc.fillGradientRectangle(4 + bounds.width / 2, 0,
// bounds.width / 2 - 9, bounds.height, false);
gc.setForeground(getWidgetFactory().getColors().getColor(FormColors.TB_BORDER));
// gc.drawLine(bounds.width - 5, 0, bounds.width - 5,
// bounds.height);
}
};
}
use of org.eclipse.swt.events.PaintEvent in project yyl_example by Relucent.
the class HelloCanvasArrow method open.
public void open() {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setLayout(new FillLayout());
final Canvas canvas = new Canvas(shell, SWT.NONE);
canvas.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_ARROW));
canvas.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent arg0) {
}
public void mouseDown(MouseEvent e) {
p[0] = e.x;
p[1] = e.y;
b = true;
}
public void mouseUp(MouseEvent arg0) {
if (b) {
int[] tp = new int[4];
tp[0] = p[0];
tp[1] = p[0];
tp[2] = p[0];
tp[3] = p[3];
}
b = false;
}
});
canvas.addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
p[2] = e.x;
p[3] = e.y;
canvas.redraw();
}
});
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent paintevent) {
if (b) {
paintArrow(paintevent.gc, new Point(p[0], p[1]), new Point(p[2], p[3]));
}
}
});
shell.setText("test");
shell.setSize(300, 300);
shell.layout();
shell.open();
while (!shell.isDisposed()) if (!display.readAndDispatch())
display.sleep();
}
use of org.eclipse.swt.events.PaintEvent in project eclipse.themes.darker by jinmingjian.
the class CSSPropertyDarkerButtonBackgroundColorHandler method applyCSSProperty.
public boolean applyCSSProperty(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception {
final Widget widget = SWTElementHelpers.getWidget(element);
final Display display = widget.getDisplay();
final Color color = (Color) engine.convert(value, Color.class, display);
if (widget instanceof Button) {
final Button b = (Button) widget;
if ((b.getStyle() & SWT.PUSH) != 0) {
b.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
b.setBackground(color);
e.gc.setBackground(color);
e.gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
e.gc.fillRoundRectangle(0, 0, b.getBounds().width, b.getBounds().height, 2, 2);
// e.gc.drawRoundRectangle(0, 0,
// b.getBounds().width,
// b.getBounds().height,
// 2, 2);
e.gc.drawString(b.getText(), 5, 5);
}
});
return true;
}
}
return false;
}
use of org.eclipse.swt.events.PaintEvent in project uiautomatorviewer by yangzaiCN.
the class UiAutomatorViewer method createContents.
/**
* Create contents of the application window.
*
* @param parent
*/
@Override
protected Control createContents(Composite parent) {
UiAutomatorModel.createInstance(this);
Composite basePane = new Composite(parent, SWT.NONE);
basePane.setLayout(new GridLayout(2, false));
mScreenshotCanvas = new Canvas(basePane, SWT.NONE);
mScreenshotCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
UiAutomatorModel.getModel().toggleExploreMode();
}
});
mScreenshotCanvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
mScreenshotCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
mScreenshotCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (mCachedScaleImage != null) {
// shifting the image here, so that there's a border around screen shot
// this makes highlighting red rectangles on the screen shot edges more visible
e.gc.drawImage(mCachedScaleImage, IMG_BORDER, IMG_BORDER);
Rectangle rect = UiAutomatorModel.getModel().getCurrentDrawingRect();
if (rect != null) {
e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
if (UiAutomatorModel.getModel().isExploreMode()) {
// when we highlight nodes dynamically on mouse move,
// use dashed borders
e.gc.setLineStyle(SWT.LINE_DASH);
e.gc.setLineWidth(1);
} else {
// when highlighting nodes on tree node selection,
// use solid borders
e.gc.setLineStyle(SWT.LINE_SOLID);
e.gc.setLineWidth(2);
}
e.gc.drawRectangle(IMG_BORDER + getScaledSize(rect.x), IMG_BORDER + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height));
}
}
}
});
mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (UiAutomatorModel.getModel().isExploreMode()) {
UiAutomatorModel.getModel().updateSelectionForCoordinates(getInverseScaledSize(e.x - IMG_BORDER), getInverseScaledSize(e.y - IMG_BORDER));
}
}
});
mScreenshotCanvas.setBackgroundImage(ImageHelper.loadImageDescriptorFromResource("images/logo.png").createImage());
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.add(mOpenFilesAction);
toolBarManager.add(mExpandAllAction);
toolBarManager.add(mScreenshotAction);
toolBarManager.createControl(basePane);
mTreeViewer = new TreeViewer(basePane, SWT.BORDER);
Tree tree = mTreeViewer.getTree();
GridData gd_Tree = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
gd_Tree.widthHint = 350;
tree.setLayoutData(gd_Tree);
mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider());
// default LabelProvider uses toString() to generate text to display
mTreeViewer.setLabelProvider(new LabelProvider());
mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection().isEmpty()) {
UiAutomatorModel.getModel().setSelectedNode(null);
} else if (event.getSelection() instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object o = selection.toArray()[0];
if (o instanceof BasicTreeNode) {
UiAutomatorModel.getModel().setSelectedNode((BasicTreeNode) o);
}
}
}
});
// move focus so that it's not on tool bar (looks weird)
tree.setFocus();
Group grpNodeDetail = new Group(basePane, SWT.NONE);
grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL));
GridData gd_grpNodeDetail = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_grpNodeDetail.heightHint = FIXED_DETAIL_VIEW_HEIGHT;
gd_grpNodeDetail.minimumHeight = FIXED_DETAIL_VIEW_HEIGHT;
gd_grpNodeDetail.widthHint = FIXED_RHS_WIDTH;
gd_grpNodeDetail.minimumWidth = FIXED_RHS_WIDTH;
grpNodeDetail.setLayoutData(gd_grpNodeDetail);
grpNodeDetail.setText("Node Detail");
Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE);
tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
TableColumnLayout columnLayout = new TableColumnLayout();
tableContainer.setLayout(columnLayout);
mTableViewer = new TableViewer(tableContainer, SWT.BORDER | SWT.FULL_SELECTION);
Table table = mTableViewer.getTable();
table.setLinesVisible(true);
// use ArrayContentProvider here, it assumes the input to the TableViewer
// is an array, where each element represents a row in the table
mTableViewer.setContentProvider(new ArrayContentProvider());
TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE);
TableColumn tblclmnKey = tableViewerColumnKey.getColumn();
tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof AttributePair) {
// first column, shows the attribute name
return ((AttributePair) element).key;
}
return super.getText(element);
}
});
columnLayout.setColumnData(tblclmnKey, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE);
tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer));
TableColumn tblclmnValue = tableViewerColumnValue.getColumn();
columnLayout.setColumnData(tblclmnValue, new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true));
tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof AttributePair) {
// second column, shows the attribute value
return ((AttributePair) element).value;
}
return super.getText(element);
}
});
return basePane;
}
Aggregations