use of org.eclipse.ecf.tutorial.scribbleshare.toolbox.AbstractTool in project ecf by eclipse.
the class ScribbleView method handleDrawLine.
/**
* This is called when a remote client calls <code>sendTool</code>.
*
* @param message
*/
public void handleDrawLine(byte[] message) {
ByteArrayInputStream bins = new ByteArrayInputStream(message);
// DataInputStream dins = new DataInputStream(bins);
try {
ObjectInputStream ois = new ObjectInputStream(bins);
AbstractTool tool = (AbstractTool) ois.readObject();
// Apply the tool to the local canvas.
tool.draw(canvas);
tools.add(tool);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.eclipse.ecf.tutorial.scribbleshare.toolbox.AbstractTool 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);
}
Aggregations