]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/CleanResizeListener.java
Introduce WrapLayout to replace FlowLayout
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / internal / awt / CleanResizeListener.java
diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/CleanResizeListener.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/CleanResizeListener.java
new file mode 100644 (file)
index 0000000..c210158
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007 SAS Institute.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     SAS Institute - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.utils.ui.internal.awt;\r
+\r
+import org.eclipse.swt.events.ControlAdapter;\r
+import org.eclipse.swt.events.ControlEvent;\r
+import org.eclipse.swt.graphics.GC;\r
+import org.eclipse.swt.graphics.Rectangle;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Display;\r
+\r
+public class CleanResizeListener extends ControlAdapter {\r
+\r
+    private Rectangle oldRect = null;\r
+\r
+    public void controlResized(ControlEvent e) {\r
+        assert e != null;\r
+        assert Display.getCurrent() != null; // On SWT event thread\r
+\r
+        // Prevent garbage from Swing lags during resize. Fill exposed areas\r
+        // with background color.\r
+        Composite composite = (Composite) e.widget;\r
+        // Rectangle newRect = composite.getBounds();\r
+        // newRect = composite.getDisplay().map(composite.getParent(), composite, newRect);\r
+        Rectangle newRect = composite.getClientArea();\r
+        if (oldRect != null) {\r
+            int heightDelta = newRect.height - oldRect.height;\r
+            int widthDelta = newRect.width - oldRect.width;\r
+            if ((heightDelta > 0) || (widthDelta > 0)) {\r
+                GC gc = new GC(composite);\r
+                try {\r
+                    gc.fillRectangle(newRect.x, oldRect.height, newRect.width, heightDelta);\r
+                    gc.fillRectangle(oldRect.width, newRect.y, widthDelta, newRect.height);\r
+                } finally {\r
+                    gc.dispose();\r
+                }\r
+            }\r
+        }\r
+        oldRect = newRect;\r
+    }\r
+\r
+}\r