package com.topsun.posclient.common.ui.key;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.swt.SWT;
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.Shell;
public class SoftKey {
public static Map<String,Integer> getKeyBoard(){
Map<String,Integer> map = new LinkedHashMap<String,Integer> ();
map.put("ESC", (int) SWT.ESC);
map.put("F1", (int) SWT.F1);
map.put("F2", (int) SWT.F2);
map.put("F3", (int) SWT.F3);
map.put("F4", (int) SWT.F4);
map.put("F5", (int) SWT.F5);
map.put("F6", (int) SWT.F6);
map.put("F7", (int) SWT.F7);
map.put("F8", (int) SWT.F8);
map.put("F9", (int) SWT.F9);
map.put("F10", (int) SWT.F10);
map.put("F11", (int) SWT.F11);
map.put("F12", (int) SWT.F12);
return map;
}
public static List<Button> createBtnList(Composite parent){
List<Button> list =new ArrayList<Button>();
Map<String,Integer> map = getKeyBoard();
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(map.size(), false));
Iterator<String> it = map.keySet().iterator();
GridData data = new GridData();
data.widthHint = 40;
data.heightHint = 40;
while(it.hasNext()){
Button button = new Button(composite, SWT.None);
button.setText(it.next());
button.setLayoutData(data);
list.add(button);
}
return list;
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1,false));
shell.setSize(600,200);
createBtnList(shell);
// Button button = new Button(shell, SWT.NONE);
// button.setText("a");
shell.open();
while(!display.isDisposed()){
display.readAndDispatch();
}
}
}