]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/CleanResizeListener.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / internal / awt / CleanResizeListener.java
1 /*******************************************************************************
2  * Copyright (c) 2007 SAS Institute.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     SAS Institute - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.utils.ui.internal.awt;
12
13 import org.eclipse.swt.events.ControlAdapter;
14 import org.eclipse.swt.events.ControlEvent;
15 import org.eclipse.swt.graphics.GC;
16 import org.eclipse.swt.graphics.Rectangle;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Display;
19
20 public class CleanResizeListener extends ControlAdapter {
21
22     private Rectangle oldRect = null;
23
24     public void controlResized(ControlEvent e) {
25         assert e != null;
26         assert Display.getCurrent() != null; // On SWT event thread
27
28         // Prevent garbage from Swing lags during resize. Fill exposed areas
29         // with background color.
30         Composite composite = (Composite) e.widget;
31         // Rectangle newRect = composite.getBounds();
32         // newRect = composite.getDisplay().map(composite.getParent(), composite, newRect);
33         Rectangle newRect = composite.getClientArea();
34         if (oldRect != null) {
35             int heightDelta = newRect.height - oldRect.height;
36             int widthDelta = newRect.width - oldRect.width;
37             if ((heightDelta > 0) || (widthDelta > 0)) {
38                 GC gc = new GC(composite);
39                 try {
40                     gc.fillRectangle(newRect.x, oldRect.height, newRect.width, heightDelta);
41                     gc.fillRectangle(oldRect.width, newRect.y, widthDelta, newRect.height);
42                 } finally {
43                     gc.dispose();
44                 }
45             }
46         }
47         oldRect = newRect;
48     }
49
50 }