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 118061 Details for
Bug 255534
Optimize startup performance by replacing EventListenerList implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Executable gef snippet to profile initialization times
EventListenerPerformance.java (text/x-java), 8.86 KB, created by
Iwan Birrer
on 2008-11-17 11:29:36 EST
(
hide
)
Description:
Executable gef snippet to profile initialization times
Filename:
MIME Type:
Creator:
Iwan Birrer
Created:
2008-11-17 11:29:36 EST
Size:
8.86 KB
patch
obsolete
>package ch.there.diagramxy; > >import java.util.ArrayList; >import java.util.Collections; >import java.util.HashSet; >import java.util.List; >import java.util.Set; > >import org.eclipse.draw2d.ColorConstants; >import org.eclipse.draw2d.Figure; >import org.eclipse.draw2d.FreeformLayer; >import org.eclipse.draw2d.FreeformLayout; >import org.eclipse.draw2d.Graphics; >import org.eclipse.draw2d.IFigure; >import org.eclipse.draw2d.LineBorder; >import org.eclipse.draw2d.PolylineConnection; >import org.eclipse.draw2d.RectangleFigure; >import org.eclipse.draw2d.XYLayout; >import org.eclipse.draw2d.geometry.Rectangle; >import org.eclipse.gef.EditPart; >import org.eclipse.gef.EditPartFactory; >import org.eclipse.gef.editparts.AbstractConnectionEditPart; >import org.eclipse.gef.editparts.AbstractGraphicalEditPart; >import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; >import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; >import org.eclipse.swt.layout.FillLayout; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Shell; > >public class EventListenerPerformance { > > // Edit parts =========================== > > static class DiagramEditPart extends AbstractGraphicalEditPart { > > public DiagramEditPart(Diagram diagram) { > setModel(diagram); > } > > private Diagram getDiagram() { > return (Diagram) getModel(); > } > > @Override > protected IFigure createFigure() { > FreeformLayer layer = new FreeformLayer(); > layer.setLayoutManager(new FreeformLayout()); > layer.setBorder(new LineBorder(1)); > return layer; > } > > @Override > protected void createEditPolicies() { > } > > @Override > protected List<Line> getModelChildren() { > return new ArrayList<Line>(getDiagram().getLines()); > } > } > > static class LineEditPart extends AbstractGraphicalEditPart { > > public LineEditPart(Line line) { > setModel(line); > } > > @Override > protected IFigure createFigure() { > FreeformLayer layer = new FreeformLayer(); > layer.setLayoutManager(new FreeformLayout()); > return layer; > } > > private Line getLine() { > return (Line) getModel(); > } > > @Override > protected void createEditPolicies() { > > } > > @Override > protected List<Point> getModelChildren() { > return getLine().getPoints(); > } > } > > static class PointEditPart extends AbstractGraphicalEditPart { > > public PointEditPart(Point point) { > setModel(point); > } > > @Override > protected IFigure createFigure() { > RectangleFigure fig = new RectangleFigure(); > return fig; > } > > private Point getPoint() { > return (Point) getModel(); > } > > @Override > protected void refreshVisuals() { > RectangleFigure figure = (RectangleFigure) getFigure(); > figure.setPreferredSize(3, 3); > LineEditPart parent = (LineEditPart) getParent(); > parent.setLayoutConstraint(this, figure, new Rectangle(getPoint() > .getX(), getPoint().getY(), -1, -1)); > } > > @Override > protected void createEditPolicies() { > } > > @Override > public List<Connection> getModelSourceConnections() { > Connection connection = getPoint().getSourceConnection(); > if (connection == null) { > return Collections.emptyList(); > } > List<Connection> list = new ArrayList<Connection>(1); > list.add(connection); > return list; > } > > @Override > public List<Connection> getModelTargetConnections() { > Connection connection = getPoint().getTargetConnection(); > if (connection == null) { > return Collections.emptyList(); > } > List<Connection> list = new ArrayList<Connection>(1); > list.add(connection); > return list; > } > } > > static class ConnectionEditPart extends AbstractConnectionEditPart { > > public ConnectionEditPart(Connection connection) { > setModel(connection); > } > > @Override > protected IFigure createFigure() { > PolylineConnection connection = (PolylineConnection) super > .createFigure(); > return connection; > } > > @Override > protected void createEditPolicies() { > } > } > > // Edit Part Factory ========================================== > > static class DiagramEditPartFactory implements EditPartFactory { > > private int editPartCount = 0; > > @Override > public EditPart createEditPart(EditPart context, Object model) { > editPartCount++; > if (model instanceof Diagram) { > return new DiagramEditPart((Diagram) model); > } else if (model instanceof Line) { > return new LineEditPart((Line) model); > } else if (model instanceof Point) { > return new PointEditPart((Point) model); > } else if (model instanceof Connection) { > return new ConnectionEditPart((Connection) model); > } > return null; > } > > /** > * Clears the edit part count. > * > * @return the previous value of {@link #editPartCount}. > */ > int clearEditPartCount() { > int oldValue = editPartCount; > this.editPartCount = 0; > return oldValue; > } > } > > // Figures ==================================================== > > static class LineFigure extends Figure { > private final RectangleFigure rectangle; > > public LineFigure() { > setLayoutManager(new XYLayout()); > rectangle = new RectangleFigure(); > add(rectangle); > } > > @Override > protected void paintFigure(Graphics graphics) { > setConstraint(rectangle, new Rectangle(0, 0, 10, 10)); > rectangle.invalidate(); > } > } > > static class PointFigure extends Figure { > private final RectangleFigure rectangle; > > public PointFigure() { > setLayoutManager(new XYLayout()); > rectangle = new RectangleFigure(); > add(rectangle); > } > > @Override > protected void paintFigure(Graphics graphics) { > setConstraint(rectangle, new Rectangle(0, 0, 3, 3)); > rectangle.invalidate(); > } > } > > // Model ====================================================== > > static class Diagram { > private final Set<Line> lines = new HashSet<Line>(); > > public void addLine(Line line) { > lines.add(line); > } > > public void removeLine(Line line) { > lines.remove(line); > } > > public Set<Line> getLines() { > return lines; > } > } > > static public class Line { > private final List<Point> points; > > public Line(List<Point> points) { > this.points = Collections.unmodifiableList(new ArrayList<Point>( > points)); > } > > public List<Point> getPoints() { > return points; > } > } > > static class Point { > private int x; > private int y; > private Connection sourceConnection; > private Connection targetConnection; > > public Point(int x, int y) { > this.x = x; > this.y = y; > } > > public int getX() { > return x; > } > > public void setX(int x) { > this.x = x; > } > > public int getY() { > return y; > } > > public void setY(int y) { > this.y = y; > } > > public Connection getSourceConnection() { > return sourceConnection; > } > > public void setSourceConnection(Connection sourceConnection) { > this.sourceConnection = sourceConnection; > } > > public Connection getTargetConnection() { > return targetConnection; > } > > public void setTargetConnection(Connection targetConnection) { > this.targetConnection = targetConnection; > } > } > > static class Connection { > private final Point source, target; > > public Connection(Point source, Point target) { > if (source == null || target == null) { > throw new IllegalArgumentException("null not allowed"); > } > > this.source = source; > this.target = target; > > this.source.setSourceConnection(this); > this.target.setTargetConnection(this); > } > > public Point getSource() { > return source; > } > > public Point getTarget() { > return target; > } > } > > // Main ============================================================= > > public static void main(String[] args) { > Display display = new Display(); > Shell shell = new Shell(display); > > ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer(); > viewer.createControl(shell); > shell.setLayout(new FillLayout()); > viewer.setRootEditPart(new ScalableFreeformRootEditPart()); > viewer.getControl().setBackground(ColorConstants.white); > > DiagramEditPartFactory editPartFactory = new DiagramEditPartFactory(); > viewer.setEditPartFactory(editPartFactory); > > setContents(viewer, editPartFactory, 10, 100); > setContents(viewer, editPartFactory, 50, 100); > setContents(viewer, editPartFactory, 100, 100); > setContents(viewer, editPartFactory, 200, 100); > > shell.open(); > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) > display.sleep(); > } > display.dispose(); > } > > private static void setContents(ScrollingGraphicalViewer viewer, > DiagramEditPartFactory editPartFactory, int lineCount, > int pointCount) { > viewer.setContents(null); > Diagram diagram = new Diagram(); > for (int i = 0; i < lineCount; i++) { > List<Point> points = new ArrayList<Point>(); > Point lastPoint = null; > for (int j = 0; j < pointCount; j++) { > Point point = new Point(j * 20, i * 12 + j * 10); > if (lastPoint != null) { > new Connection(lastPoint, point); > } > points.add(point); > lastPoint = point; > } > diagram.addLine(new Line(points)); > } > Diagram model = diagram; > long start = System.currentTimeMillis(); > viewer.setContents(model); > System.out.println(editPartFactory.clearEditPartCount() > + " edit parts: " + (System.currentTimeMillis() - start) > + " ms"); > } >}
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 255534
:
118060
| 118061 |
159408