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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| package fr.wedia.util.swt;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class TestSWT {
private static FontRegistry fontRegistry;
public static void main(String[] args) {
Display display = new Display();
fontRegistry = new FontRegistry(display);
try {
test(display);
}
finally {
display.dispose();
}
}
private static Font getFont(String key) {
if ( !fontRegistry.hasValueFor(key) ) {
String[] fontdata = key.split("-");
String name = fontdata[0].trim();
int style = SWT.NORMAL;
int height = Integer.parseInt(fontdata[1].trim());
String _style = null;
if ( fontdata.length>2 ) {
_style = fontdata[2].trim().toUpperCase();
}
else {
_style = "NORMAL";
}
if ( _style.startsWith("ITALIC") || _style.endsWith("ITALIC") ) {
style = SWT.ITALIC;
}
if ( _style.startsWith("BOLD") || _style.endsWith("BOLD") ) {
style |= SWT.BOLD;
}
if ( (style & SWT.ITALIC)==SWT.ITALIC ) {
if ( (style & SWT.BOLD)==SWT.BOLD ) {
_style = "BOLDITALIC";
}
else {
_style = "ITALIC";
}
} else if ( (style & SWT.BOLD)==SWT.BOLD ) {
_style = "BOLD";
} else {
_style = "NORMAL";
}
String _height = Integer.toString(height);
key = name + "-" + _height+ "-" + _style ;
if ( !fontRegistry.hasValueFor(key) ) {
fontRegistry.put(key, new FontData[]{new FontData(name, height, style)});
}
}
return fontRegistry.get(key);
}
private static void test(Display display) {
WizardDialog dialog = new WizardDialog(null, new MyWizard());
dialog.create();
dialog.open();
}
private static class MyWizard extends Wizard {
@Override
public void addPages() {
super.addPages();
addPage(new MyPage());
}
@Override
public boolean performFinish() {
return true;
}
}
private static class MyPage extends WizardPage {
protected MyPage() {
super("page");
}
public void createControl(final Composite parent) {
final Composite comp = new Composite(parent, SWT.NONE);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(comp);
GridLayoutFactory.fillDefaults().spacing(LayoutConstants.getSpacing()).numColumns(3).equalWidth(false).applyTo(comp);
Label labelTitre = new Label(comp,SWT.NONE);
labelTitre.setText("Informations concernants les numéros de configuration");
labelTitre.setFont(TestSWT.getFont("Arial-14"));
GridData titreGD = new GridData(SWT.FILL, SWT.CENTER, true, false);
titreGD.horizontalSpan = 4;
titreGD.heightHint = 40;
final ScrolledComposite scrolledComposite = new ScrolledComposite (comp, SWT.V_SCROLL);
GridDataFactory.fillDefaults().align(SWT.FILL,SWT.FILL).grab(false, false).hint(SWT.DEFAULT, 0).applyTo(scrolledComposite);
labelTitre.setLayoutData(titreGD);
final Group groupTT = new Group(scrolledComposite,SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL,SWT.FILL).grab(false, false).applyTo(groupTT);
scrolledComposite.setContent(groupTT);
Group groupOM = new Group(comp,SWT.NONE);
Group groupOT = new Group(comp,SWT.NONE);
GridLayout gridTT = new GridLayout(2,false);
groupTT.setLayout(gridTT);
Label labelTTtitre = new Label(groupTT,SWT.NONE);
labelTTtitre.setText("Renommer les Tests Type");
labelTTtitre.setFont(TestSWT.getFont("Arial-10"));
GridData ttGridData = new GridData(GridData.FILL_HORIZONTAL);
ttGridData.horizontalSpan = 2;
labelTTtitre.setLayoutData(ttGridData);
/*listMat = MyWizard.one.getListTableChecked();
//String name = MyWizard.one.getName();
java.util.List<String> nameMatSansAff = new ArrayList<String>();
for(int i = 0; i<listMat.size(); i++){
String[] nameMat = listMat.get(i).split(name);
nameMatSansAff.add(nameMat[0]);
}*/
/*java.util.List<String> nameTestType = new ArrayList<String>();
for(int i = 0; i<nameMatSansAff.size(); i++){
String[] nameTT = nameMatSansAff.get(i).split("_");
boolean exist = false;
for(int t = 0; t<nameTT.length; t++){
for(int j = 0; j<nameTestType.size(); j++){
if(nameTT[t].equals(nameTestType.get(j))){
exist = true;
}
}
if(!exist){
nameTestType.add(nameTT[t]);
}
}
}*/
for(int i=0; i<500; i++){
Label labelTT = new Label(groupTT,SWT.NONE);
labelTT.setText("toto"+i);
labelTT.setFont(TestSWT.getFont("Arial-9"));
Text textTT = new Text(groupTT,SWT.BORDER);
textTT.setText("");
GridData textGD = new GridData(GridData.FILL_HORIZONTAL);
textGD.widthHint = 100;
textTT.setLayoutData(textGD);
}
scrolledComposite.setMinSize(groupTT.computeSize(SWT.DEFAULT, SWT.DEFAULT));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
comp.getShell().addShellListener(new ShellAdapter() {
public void shellActivated(ShellEvent e) {
comp.getShell().layout(true,true);
}
});
for(int i=0; i<6; i++) {
Button button=new Button(comp, SWT.PUSH);
button.setText("button "+i);
button.setFont(TestSWT.getFont("Arial-15-BOLD"));
GridDataFactory.fillDefaults().align(SWT.CENTER,SWT.CENTER).grab(false, false).applyTo(button);
}
comp.getShell().addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
((GridData)scrolledComposite.getLayoutData()).heightHint=
Math.max(0, comp.getShell().getSize().y/5);
System.out.println(((GridData)scrolledComposite.getLayoutData()).heightHint);
parent.layout(true,true);
}
});
setControl(comp);
}
}
} |