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