blob: c6f8c77e80d31731fd526d7707cdb50301d27644 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*******************************************************************************
* Copyright (c) 2008-2010 Sonatype, Inc.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.m2e.core.wizards;
import java.util.HashSet;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Control;
/**
* Group of controls with the same width
*
* @author Eugene Kuleshov
*/
public class WidthGroup extends ControlAdapter {
private final HashSet<Control> controls = new HashSet<Control>();
public void controlResized(ControlEvent e) {
int maxWidth = 0;
for(Control c : this.controls) {
int width = c.getSize().x;
if(width > maxWidth) {
maxWidth = width;
}
}
if(maxWidth > 0) {
for(Control c : this.controls) {
GridData gd = (GridData) c.getLayoutData();
gd.widthHint = maxWidth;
c.getParent().layout();
}
}
}
public void addControl(Control control) {
controls.add(control);
control.getParent().layout();
}
}
|