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
9 * SAS Institute - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.utils.ui.internal.awt;
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;
20 public class CleanResizeListener extends ControlAdapter {
22 private Rectangle oldRect = null;
24 public void controlResized(ControlEvent e) {
26 assert Display.getCurrent() != null; // On SWT event thread
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);
40 gc.fillRectangle(newRect.x, oldRect.height, newRect.width, heightDelta);
41 gc.fillRectangle(oldRect.width, newRect.y, widthDelta, newRect.height);