Search in sources :

Example 1 with ListContentProvider

use of org.eclipse.ecf.tutorial.scribbleshare.toolbox.ListContentProvider in project ecf by eclipse.

the class ScribbleView method createPartControl.

public void createPartControl(Composite parent) {
    Composite backgroundComposite = new Composite(parent, SWT.NONE);
    GridLayout backgroundGridLayout = new GridLayout(3, false);
    backgroundGridLayout.marginHeight = 0;
    backgroundGridLayout.marginBottom = 0;
    backgroundGridLayout.marginLeft = 0;
    backgroundGridLayout.marginRight = 0;
    backgroundGridLayout.marginWidth = 0;
    backgroundGridLayout.horizontalSpacing = 0;
    backgroundComposite.setLayout(backgroundGridLayout);
    backgroundComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    Composite paletteComposite = new Composite(backgroundComposite, SWT.NONE);
    backgroundGridLayout = new GridLayout();
    backgroundGridLayout.marginHeight = 0;
    backgroundGridLayout.marginBottom = 0;
    backgroundGridLayout.marginLeft = 0;
    backgroundGridLayout.marginRight = 0;
    backgroundGridLayout.marginWidth = 0;
    backgroundGridLayout.horizontalSpacing = 0;
    paletteComposite.setLayout(backgroundGridLayout);
    GridData toolboxGridData = new GridData(GridData.FILL_VERTICAL);
    toolboxGridData.widthHint = 60;
    paletteComposite.setLayoutData(toolboxGridData);
    final TableViewer toolbox = new TableViewer(paletteComposite, SWT.FLAT | SWT.FULL_SELECTION);
    toolboxGridData = new GridData(GridData.FILL_BOTH);
    toolbox.getTable().setLayoutData(toolboxGridData);
    toolbox.setLabelProvider(new ToolboxLabelProvider());
    toolbox.setContentProvider(new ListContentProvider());
    toolbox.setInput(createTools());
    toolbox.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            currentTool = (AbstractTool) ((StructuredSelection) toolbox.getSelection()).getFirstElement();
            // Apply the drawSettings to the currently selected tool.
            currentTool.setDrawSettings(drawSettings);
        }
    });
    // Create the UI widgets to modify the DrawSettings instance.
    createSettings(paletteComposite);
    Label separator = new Label(backgroundComposite, SWT.SEPARATOR | SWT.VERTICAL);
    separator.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    canvas = new Canvas(backgroundComposite, SWT.NONE);
    canvas.setLayoutData(new GridData(GridData.FILL_BOTH));
    display = parent.getDisplay();
    canvas.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            for (Iterator i = tools.iterator(); i.hasNext(); ) {
                AbstractTool at = (AbstractTool) i.next();
                at.draw(canvas);
            }
        }
    });
    Listener listener = new Listener() {

        public void handleEvent(Event event) {
            if (currentTool != null) {
                // Have the tool interpret the mouse events.
                currentTool.handleUIEvent(event, canvas);
                // other clients for rendering.
                if (currentTool.isComplete()) {
                    tools.add(currentTool);
                    sendTool(currentTool);
                    // Only do this once per Tool.
                    currentTool.setComplete(false);
                }
            /*else {
						if (currentTool instanceof Pencil) {
							tools.add(currentTool);
						}
					}*/
            }
        }
    };
    canvas.addListener(SWT.MouseDown, listener);
    canvas.addListener(SWT.MouseMove, listener);
    canvas.addListener(SWT.MouseUp, listener);
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) PaintListener(org.eclipse.swt.events.PaintListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Canvas(org.eclipse.swt.widgets.Canvas) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.eclipse.ecf.tutorial.scribbleshare.toolbox.ListContentProvider) GridData(org.eclipse.swt.layout.GridData) Iterator(java.util.Iterator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolboxLabelProvider(org.eclipse.ecf.tutorial.scribbleshare.toolbox.ToolboxLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractTool(org.eclipse.ecf.tutorial.scribbleshare.toolbox.AbstractTool)

Aggregations

Iterator (java.util.Iterator)1 AbstractTool (org.eclipse.ecf.tutorial.scribbleshare.toolbox.AbstractTool)1 ListContentProvider (org.eclipse.ecf.tutorial.scribbleshare.toolbox.ListContentProvider)1 ToolboxLabelProvider (org.eclipse.ecf.tutorial.scribbleshare.toolbox.ToolboxLabelProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Canvas (org.eclipse.swt.widgets.Canvas)1 Composite (org.eclipse.swt.widgets.Composite)1 Event (org.eclipse.swt.widgets.Event)1 Label (org.eclipse.swt.widgets.Label)1 Listener (org.eclipse.swt.widgets.Listener)1