Home » Eclipse Projects » GEF » Startup Performance
|
Re: Startup Performance [message #246234 is a reply to message #246221] |
Mon, 17 November 2008 15:00 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Iwan Birrer![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=iwanbirrer%40bluewin.ch) Messages: 6 Registered: July 2009 |
Junior Member |
|
|
This is a multi-part message in MIME format.
--------------090301050702020400080603
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
.... and the attachments.
- Iwan
--------------090301050702020400080603
Content-Type: text/plain;
name="EventListenerList.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EventListenerList.java"
package org.eclipse.draw2d;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* This class is intended for internal use only. TODO: If this is for internal
* use only, we should move it to the internal package.
*/
public final class EventListenerList {
private final Map listenersMap = new HashMap();
/**
* Adds a listener of type <i>c</i> to the list.
*
* @param c
* the class
* @param listener
* the listener
*/
public synchronized void addListener(Class c, Object listener) {
if (listener == null || c == null) {
throw new IllegalArgumentException();
}
List listeners = (List) listenersMap.get(c);
if (listeners == null) {
listeners = new ArrayList(2);
listenersMap.put(c, listeners);
}
listeners.add(listener);
}
/**
* Returns <code>true</code> if this list of listeners contains a listener
* of type <i>c</i>.
*
* @param c
* the type
* @return whether this list contains a listener of type <i>c</i>
*/
public synchronized boolean containsListener(Class c) {
return listenersMap.containsKey(c);
}
/**
* Returns an Iterator of all the listeners of type <i>c</i>.
*
* @param listenerType
* the type
* @return an Iterator of all the listeners of type <i>c</i>
*/
public synchronized Iterator getListeners(final Class listenerType) {
if (listenersMap.get(listenerType) != null) {
return new ArrayList(((List) listenersMap.get(listenerType)))
.iterator();
}
return Collections.EMPTY_LIST.iterator();
}
/**
* Removes the first <i>listener</i> of the specified type by identity.
*
* @param c
* the type
* @param listener
* the listener
*/
public synchronized void removeListener(Class c, Object listener) {
if (listener == null || c == null) {
throw new IllegalArgumentException();
}
List listeners = (List) listenersMap.get(c);
if (listeners != null) {
listeners.remove(listener);
}
}
}
--------------090301050702020400080603
Content-Type: text/plain;
name="EventListenerPerformance.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="EventListenerPerformance.java"
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");
}
}
--------------090301050702020400080603--
|
|
|
Re: Startup Performance [message #246246 is a reply to message #246234] |
Mon, 17 November 2008 15:48 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Anthony Hunter![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=ahunter.eclipse%40gmail.com) Messages: 446 Registered: July 2009 |
Senior Member |
|
|
Hi Iwan,
Can you cut and paste this entire thread into a Bugzilla?
Cheers...
Anthony
"Iwan Birrer" <iwanbirrer@bluewin.ch> wrote in message
news:gfs0tm$8j3$1@build.eclipse.org...
> ... and the attachments.
>
> - Iwan
>
------------------------------------------------------------ --------------------
> package org.eclipse.draw2d;
>
> import java.util.ArrayList;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.List;
> import java.util.Map;
>
> /**
> * This class is intended for internal use only. TODO: If this is for
> internal
> * use only, we should move it to the internal package.
> */
> public final class EventListenerList {
>
> private final Map listenersMap = new HashMap();
>
> /**
> * Adds a listener of type <i>c</i> to the list.
> *
> * @param c
> * the class
> * @param listener
> * the listener
> */
> public synchronized void addListener(Class c, Object listener) {
> if (listener == null || c == null) {
> throw new IllegalArgumentException();
> }
>
> List listeners = (List) listenersMap.get(c);
> if (listeners == null) {
> listeners = new ArrayList(2);
> listenersMap.put(c, listeners);
> }
>
> listeners.add(listener);
> }
>
> /**
> * Returns <code>true</code> if this list of listeners contains a listener
> * of type <i>c</i>.
> *
> * @param c
> * the type
> * @return whether this list contains a listener of type <i>c</i>
> */
> public synchronized boolean containsListener(Class c) {
> return listenersMap.containsKey(c);
> }
>
> /**
> * Returns an Iterator of all the listeners of type <i>c</i>.
> *
> * @param listenerType
> * the type
> * @return an Iterator of all the listeners of type <i>c</i>
> */
> public synchronized Iterator getListeners(final Class listenerType) {
> if (listenersMap.get(listenerType) != null) {
> return new ArrayList(((List) listenersMap.get(listenerType)))
> .iterator();
> }
> return Collections.EMPTY_LIST.iterator();
> }
>
> /**
> * Removes the first <i>listener</i> of the specified type by identity.
> *
> * @param c
> * the type
> * @param listener
> * the listener
> */
> public synchronized void removeListener(Class c, Object listener) {
> if (listener == null || c == null) {
> throw new IllegalArgumentException();
> }
>
> List listeners = (List) listenersMap.get(c);
> if (listeners != null) {
> listeners.remove(listener);
> }
> }
>
> }
>
------------------------------------------------------------ --------------------
> 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");
> }
> }
>
|
|
| | |
Goto Forum:
Current Time: Sat Aug 31 23:23:29 GMT 2024
Powered by FUDForum. Page generated in 0.03593 seconds
|