Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 209892 Details for
Bug 369357
[jface] Zooming does not work when custom anchors used.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Example showing zooming not working properly when custom anchors used.
ZoomingGraphJFaceExample.java (text/plain), 6.15 KB, created by
Erdal Karaca
on 2012-01-23 03:11:01 EST
(
hide
)
Description:
Example showing zooming not working properly when custom anchors used.
Filename:
MIME Type:
Creator:
Erdal Karaca
Created:
2012-01-23 03:11:01 EST
Size:
6.15 KB
patch
obsolete
>/******************************************************************************* > * Copyright (c) 2012 Erdal Karaca. All rights reserved. This program and > * the accompanying materials are made available under the terms of the Eclipse > * Public License v1.0 which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * <p/> > * Contributors: Erdal Karaca - initial implementation based on snippet 9 > *******************************************************************************/ >package org.eclipse.zest.examples.jface; > >import java.util.Arrays; > >import org.eclipse.draw2d.AbstractConnectionAnchor; >import org.eclipse.draw2d.Connection; >import org.eclipse.draw2d.IFigure; >import org.eclipse.draw2d.RelativeBendpoint; >import org.eclipse.draw2d.geometry.Dimension; >import org.eclipse.draw2d.geometry.Point; >import org.eclipse.draw2d.geometry.Rectangle; >import org.eclipse.jface.action.MenuManager; >import org.eclipse.jface.viewers.ISelectionChangedListener; >import org.eclipse.jface.viewers.ITreeContentProvider; >import org.eclipse.jface.viewers.LabelProvider; >import org.eclipse.jface.viewers.SelectionChangedEvent; >import org.eclipse.jface.viewers.Viewer; >import org.eclipse.swt.SWT; >import org.eclipse.swt.events.SelectionAdapter; >import org.eclipse.swt.events.SelectionEvent; >import org.eclipse.swt.graphics.Image; >import org.eclipse.swt.layout.FillLayout; >import org.eclipse.swt.widgets.Button; >import org.eclipse.swt.widgets.Composite; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Menu; >import org.eclipse.swt.widgets.Shell; >import org.eclipse.zest.core.viewers.AbstractZoomableViewer; >import org.eclipse.zest.core.viewers.GraphViewer; >import org.eclipse.zest.core.viewers.ISelfStyleProvider; >import org.eclipse.zest.core.viewers.IZoomableWorkbenchPart; >import org.eclipse.zest.core.viewers.ZoomContributionViewItem; >import org.eclipse.zest.core.widgets.GraphConnection; >import org.eclipse.zest.core.widgets.GraphNode; >import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; > >/** > * Shows the zooming functionality. > */ >public class ZoomingGraphJFaceExample { > > private static class MyCustomAnchor extends AbstractConnectionAnchor { > public static int LEFT = 0; > public static int RIGHT = 1; > private int style; > > public MyCustomAnchor(int style, IFigure nodeFigure) { > super(nodeFigure); > this.style = style; > } > > public Point getLocation(Point arg0) { > Rectangle bounds = getOwner().getBounds(); > int w = bounds.width; > int h = bounds.height; > int x = bounds.x; > int y = bounds.y; > > return (style & RIGHT) != 0 ? new Point(x + w, y + h / 2) > : new Point(x, y + h / 2); > } > } > > static class MyContentProvider implements ITreeContentProvider { > > private static final String n1 = "First", n2 = "Second", n3 = "Third", > n4 = "Fourth"; > > public Object[] getElements(Object inputElement) { > return new String[] { n1 }; > } > > public void dispose() { > } > > public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { > } > > public Object[] getChildren(Object parentElement) { > if (parentElement.equals(n1)) { > return new Object[] { n2, n3 }; > } > if (parentElement.equals(n2)) { > return new Object[] { n4 }; > } > return null; > } > > public Object getParent(Object element) { > if (element.equals(n2)) { > return n1; > } else if (element.equals(n3)) { > return n1; > } else if (element.equals(n4)) { > return new Object[] { n2 }; > } > return null; > } > > public boolean hasChildren(Object element) { > return element.equals("First") || element.equals("Second"); > } > } > > static class MyLabelProvider extends LabelProvider implements > ISelfStyleProvider { > final Image image = Display.getDefault().getSystemImage( > SWT.ICON_WARNING); > > public Image getImage(Object element) { > if (element instanceof String) { > return image; > } > return null; > } > > public String getText(Object element) { > if (element instanceof String) { > return element.toString(); > } > return null; > } > > public void selfStyleConnection(Object element, > GraphConnection connection) { > Connection conn = connection.getConnectionFigure(); > conn.setSourceAnchor(new MyCustomAnchor(MyCustomAnchor.RIGHT, > connection.getSource().getFigure())); > conn.setTargetAnchor(new MyCustomAnchor(MyCustomAnchor.LEFT, > connection.getDestination().getFigure())); > RelativeBendpoint bp1 = new RelativeBendpoint(conn); > bp1.setWeight(1); > bp1.setRelativeDimensions(new Dimension(0, 0), > new Dimension(-80, 0)); > conn.getConnectionRouter().setConstraint(conn, > Arrays.asList(new Object[] { bp1 })); > } > > public void selfStyleNode(Object element, GraphNode node) { > } > } > > private static class ExtGraphViewer extends GraphViewer implements > IZoomableWorkbenchPart { > public ExtGraphViewer(Composite composite, int style) { > super(composite, style); > } > > public AbstractZoomableViewer getZoomableViewer() { > return this; > } > } > > static ExtGraphViewer viewer = null; > > public static void main(String[] args) { > Display d = new Display(); > Shell shell = new Shell(d); > shell.setLayout(new FillLayout(SWT.VERTICAL)); > shell.setSize(400, 400); > Button button = new Button(shell, SWT.PUSH); > button.setText("Reload"); > button.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > viewer.setInput(new Object()); > } > }); > viewer = new ExtGraphViewer(shell, SWT.NONE); > viewer.setContentProvider(new MyContentProvider()); > viewer.setLabelProvider(new MyLabelProvider()); > viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm()); > viewer.addSelectionChangedListener(new ISelectionChangedListener() { > public void selectionChanged(SelectionChangedEvent event) { > System.out.println("Selection changed: " > + (event.getSelection())); > } > }); > viewer.setInput(new Object()); > > MenuManager tbm = new MenuManager(); > Menu menu = tbm.createContextMenu(viewer.getControl()); > viewer.getControl().setMenu(menu); > ZoomContributionViewItem toolbarZoomContributionViewItem = new ZoomContributionViewItem( > viewer); > tbm.add(toolbarZoomContributionViewItem); > > shell.open(); > while (!shell.isDisposed()) { > while (!d.readAndDispatch()) { > d.sleep(); > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 369357
: 209892