Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typify dirtyRegion map in UpdateListener and UpdateManager #238

Merged
merged 1 commit into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void setUp() throws Exception {
* .Rectangle, java.util.Map)
*/
@Override
public void notifyPainting(Rectangle damage, Map dirtyRegions) {
public void notifyPainting(Rectangle damage, Map<IFigure, Rectangle> dirtyRegions) {
lastDamaged = damage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void tearDown() throws Exception {
}

@Override
public void notifyPainting(Rectangle damage, Map dirtyRegions) {
public void notifyPainting(Rectangle damage, Map<IFigure, Rectangle> dirtyRegions) {
lastDamaged = damage;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -46,7 +46,7 @@ public void run() {
}

private Rectangle damage;
private Map dirtyRegions = new HashMap();
private Map<IFigure, Rectangle> dirtyRegions = new HashMap<>();

private GraphicsSource graphicsSource;
private List invalidFigures = new ArrayList();
Expand Down Expand Up @@ -103,7 +103,7 @@ public synchronized void addDirtyRegion(IFigure figure, int x, int y, int w, int
if (w == 0 || h == 0 || !figure.isShowing())
return;

Rectangle rect = (Rectangle) dirtyRegions.get(figure);
Rectangle rect = dirtyRegions.get(figure);
if (rect == null) {
rect = new Rectangle(x, y, w, h);
dirtyRegions.put(figure, rect);
Expand Down Expand Up @@ -266,15 +266,8 @@ protected void releaseGraphics(Graphics graphics) {
* regions.
*/
protected void repairDamage() {
Iterator keys = dirtyRegions.keySet().iterator();
Rectangle contribution;
IFigure figure;
IFigure walker;

while (keys.hasNext()) {
figure = (IFigure) keys.next();
walker = figure.getParent();
contribution = (Rectangle) dirtyRegions.get(figure);
dirtyRegions.forEach((figure, contribution) -> {
IFigure walker = figure.getParent();
// A figure can't paint beyond its own bounds
contribution.intersect(figure.getBounds());
while (!contribution.isEmpty() && walker != null) {
Expand All @@ -286,11 +279,11 @@ protected void repairDamage() {
damage = new Rectangle(contribution);
else
damage.union(contribution);
}
});

if (!dirtyRegions.isEmpty()) {
Map oldRegions = dirtyRegions;
dirtyRegions = new HashMap();
Map<IFigure, Rectangle> oldRegions = dirtyRegions;
dirtyRegions = new HashMap<>();
firePainting(damage, oldRegions);
}

Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/FigureCanvas.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -257,7 +257,7 @@ public Viewport getViewport() {
*/
private void hook() {
getLightweightSystem().getUpdateManager().addUpdateListener(new UpdateListener() {
public void notifyPainting(Rectangle damage, java.util.Map dirtyRegions) {
public void notifyPainting(Rectangle damage, java.util.Map<IFigure, Rectangle> dirtyRegions) {
}

public void notifyValidating() {
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/UpdateListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -31,7 +31,7 @@ public interface UpdateListener {
* @param damage The area being painted
* @param dirtyRegions a Map of figures to their dirty regions
*/
void notifyPainting(Rectangle damage, Map dirtyRegions);
void notifyPainting(Rectangle damage, Map<IFigure, Rectangle> dirtyRegions);

/**
* Notifies the listener that the listened to object is validating.
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/UpdateManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -117,7 +117,7 @@ public void dispose() {
* @param damage the damaged rectangle
* @param dirtyRegions map of dirty regions to figures
*/
protected void firePainting(Rectangle damage, Map dirtyRegions) {
protected void firePainting(Rectangle damage, Map<IFigure, Rectangle> dirtyRegions) {
UpdateListener localListeners[] = listeners;
for (int i = 0; i < localListeners.length; i++)
localListeners[i].notifyPainting(damage, dirtyRegions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* Copyright (c) 2000, 2023 IBM Corporation and others.
* 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
Expand Down Expand Up @@ -516,10 +516,8 @@ protected boolean isDirty() {

/** @see org.eclipse.draw2d.UpdateListener#notifyPainting(Rectangle, Map) */
@Override
public void notifyPainting(Rectangle damage, Map dirtyRegions) {
Iterator dirtyFigures = dirtyRegions.keySet().iterator();
while (dirtyFigures.hasNext()) {
IFigure current = (IFigure) dirtyFigures.next();
public void notifyPainting(Rectangle damage, Map<IFigure, Rectangle> dirtyRegions) {
for (IFigure current : dirtyRegions.keySet()) {
while (current != null) {
if (current == getSource()) {
setDirty(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2010 IBM Corporation and others.
* Copyright (c) 2004, 2023 IBM Corporation and others.
* 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
Expand All @@ -17,6 +17,7 @@

import org.eclipse.core.runtime.Assert;
import org.eclipse.draw2d.Cursors;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.UpdateListener;
import org.eclipse.draw2d.UpdateManager;
import org.eclipse.draw2d.geometry.Point;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class TextTool extends SelectionTool implements StyleProvider {
};
private UpdateListener updateListener = new UpdateListener() {
@Override
public void notifyPainting(Rectangle damage, Map dirtyRegions) {
public void notifyPainting(Rectangle damage, Map<IFigure, Rectangle> dirtyRegions) {
queueCaretRefresh(false);
}

Expand Down
Loading