?? eimanager.java
字號:
package dian.ikeel.swt.first;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import java.util.ListIterator;
import dian.ikeel.yin.Shy;
import dian.ikeel.yin.Student;
import dian.ikeel.yin.*;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.text.Collator;
public class EIManager {
static int EDITABLECOLUMN = -1;
private static Shy shy;
private static Display display;
private Shell shell;
private Shell shell2;
private static Group group,searchgroup;
private static Table table;
private String[] headers = { "學號", "姓名", "年齡", "性別", "專業", "班級", "操作" };
private int[] Width={150,85,50,50,140,140,80};
private static int columnsize = 6;
private int rowHeight = 25;
private static int Itemcount = 10;
private static ListIterator<Student> curnode;
private Font font1,font2;
private static CommonData commondata;
private DoubleLinkList<Student> showlist=new DoubleLinkList<Student>();
private static Font font3;
private static EIManager tb3;
private Text searchtext;
private Button searchmethod;
private Combo drop,drop1;
private Button go;
private TableEditor editor;
private Button previouspage;
private Button nextpage;
private static int totalcount;
// private static int countperpage=8;
private static int pages;
private static int currentpage=1;
private Button delete;
private static int[] selecteditems;
private DoubleLinkList<Student> currentpagelist;
private Table table2;
private Group sysgroup,insertgroup;
private Button refresh;
public EIManager() {
this.shy=new Shy();
}
public static void main(String[] args) {
tb3=new EIManager();
{
tb3.init();
}
}
public void initShell() {
display = new Display();
//display.addListener(SWT.CLOSE, listener)
font1=new Font(display,"宋體",10,SWT.BOLD);
font2=new Font(display,"宋體",12, SWT.ITALIC);
font3=new Font(display,"宋體",12,SWT.BOLD );
shell = new Shell(display);
shell.setBounds(0, 0, 950, 600);
shell.setText("電信系學生信息管理系統(Designed By Ikeel)");
shell.setImage(new Image(null, "image/book.jpg"));
shell.setBackgroundImage(new Image(null, "image/13.jpg"));
shell.setBackgroundMode(SWT.MOD1);
searchgroup=new Group(shell, SWT.COLOR_BLUE);
group = new Group(shell, SWT.COLOR_DARK_MAGENTA);
searchgroup.setBounds(5,5,150,280);
searchgroup.setText("查詢信息");
group.setText("學生信息列表");
group.setBounds(160,5,725, 480);
// group.pack();
sysgroup=new Group(shell,SWT.COLOR_BLUE);
sysgroup.setText("版權申明");
sysgroup.setBounds(5, 290, 150, 150);
//insertgroup=new Group(group,SWT.COLOR_BLUE);
// insertgroup.setText("添加記錄");
// insertgroup.setBounds(15, 360, 650, 150);
}
public void initSysmanager()
{
final Font font4=new Font(display,"Arial",10,SWT.BOLD);
// drop1=new Combo(sysgroup,SWT.DROP_DOWN);
Label tip3=new Label(sysgroup,SWT.NONE);
tip3.setText("作者: Ikeel");
tip3.setBounds(5, 15, 105, 20);
tip3.setFont(font4);
Label tip4=new Label(sysgroup,SWT.NONE);
tip4.setText("Hust:SeedClass 2005");
tip4.setBounds(5, 40, 105, 20);
tip4.setFont(font4);
}
public void init()
{
tb3.preparedata();
tb3.initShell();
initControl();
open();
tb3.initTable();
}
public void initControl()
{
initSearchArea();
initTable();
//initTable2();
previouspage();
nextpage();
deleteSelected();
initSysmanager();
refreshButton();
bundCurrentpage();
}
public void initSearchArea()
{
final Font font4=new Font(display,"Arial",10,SWT.BOLD);
drop=new Combo(searchgroup,SWT.DROP_DOWN);
drop.setItems(new String[]{"按學號查詢","按姓名查詢","顯示所有"});
Label tip1=new Label(searchgroup,SWT.NONE);
tip1.setText("檢索方式:");
tip1.setBounds(5, 35, 105, 20);
tip1.setFont(font4);
drop.setBounds(5, 55, 105, 25);
drop.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
Label tip2=new Label(searchgroup,SWT.NONE);
tip2.setText("檢索內容:");
tip2.setBounds(5, 90, 105, 20);
tip2.setFont(font4);
searchtext=new Text(searchgroup,SWT.BORDER);
searchtext.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
searchtext.setBounds(5, 110, 105, 25);
searchtext.setEnabled(Boolean.TRUE);
go=new Button(searchgroup,SWT.PUSH);
go.setText("查詢");
go.setBounds(5, 150, 105, 25);
drop.addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event e)
{
if(Integer.valueOf(drop.getSelectionIndex())==2)
{
setShowlist(getCommondata().getStulist());
refresh();
}
else
searchtext.forceFocus();
}
}
);
go.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event) {
if(Integer.valueOf(drop.getSelectionIndex())==0)
{
setShowlist( tb3.getShy().findByID(searchtext.getText().trim()));
System.out.println("檢索到的條數"+ tb3.getShy().findByID(searchtext.getText().trim()).size());
}
else if(Integer.valueOf(drop.getSelectionIndex())==1)
{
setShowlist( tb3.getShy().findByName(searchtext.getText().trim()) ) ;
System.out.println("檢索到的條數"+ tb3.getShy().findByName(searchtext.getText().trim()).size());
}
refresh();
}
}
);
}
public void bundData(List<Student> list)
{
int k=0;
// curnode=getCurnode();
ListIterator<Student> itr=list.listIterator();
while (itr.hasNext()) {
// TableItem item = new TableItem(table, SWT.NONE);
if (k >= table.getItemCount())
return;
TableItem item = table.getItem(k);
Student stu = itr.next();
item.setText(stu.toStringArray());
k++;
}
while(k<table.getItemCount())
{
TableItem item = table.getItem(k);
//Student stu = itr.next();
item.setText(new String[]{"","","","","",""});
k++;
}
}
public void bundCurrentpage()
{
List<Student> curlist=new DoubleLinkList<Student>();
if(currentpage*getItemcount()<=getTotalcount())
{
System.out.println("當前Showlist:"+getShowlist().size());
curlist=getShowlist().subList((currentpage-1)*getItemcount(), currentpage*getItemcount());
}
else
curlist=getShowlist().subList((currentpage-1)*getItemcount(), getTotalcount());
bundData(curlist);
}
public void initTable2()
{
table2 = new Table(insertgroup, SWT.SINGLE
| SWT.FULL_SELECTION );
table2.setHeaderVisible(true);
//table.setSortColumn(column)
table2.setLinesVisible(true);
table2.setBounds(15,390,695, 50);
table2.setItemCount(1);
table2.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
table2.setFont(Display.getCurrent().getSystemFont());
table2.setHeaderVisible(Boolean.FALSE);
// table2.setLinesVisible(Boolean.TRUE);
table2.addListener(SWT.MeasureItem, new Listener() {
public void handleEvent(Event event) {
event.height =50;
}
});
}
public void previouspage()
{
{
previouspage = new Button(group, SWT.PUSH);
previouspage.setText("<<上一頁");
previouspage.setBounds(420, 360, 80, 25);
previouspage.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if(currentpage<=1)
{
return;
}
else
{
currentpage--;
bundCurrentpage();
}
}
});
}
}
private void nextpage()
{
{
nextpage = new Button(group, SWT.PUSH);
nextpage.setText("下一頁>>");
nextpage.setBounds(510, 360, 80, 25);
nextpage.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if(currentpage>=getPages())
{
// nextpage.setEnabled(Boolean.FALSE);
return;
}
else
{
// if(!(currentpage==getPages()-1))
currentpage++;
bundCurrentpage();
}
}
});
}
}
public void refreshButton()
{
refresh = new Button(group, SWT.PUSH);
refresh.setText("刷新列表");
refresh.setBounds(170, 360, 100, 25);
refresh.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setShowlist(CommonData.getInstance().getStulist());
refresh();
}
});
}
public void deleteSelected()
{
delete = new Button(group, SWT.PUSH);
delete.setText("刪除選中項");
delete.setBounds(50, 360, 100, 25);
delete.setVisible(Boolean.FALSE);
delete.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// TableItem[] selected =table.getSelection();
//int[] selectedindex= table.getSelectionIndices();
//table.remove(table.getSelectionIndices());
System.out.println("Selected :"+selecteditems.length);
for(int j=0;j<selecteditems.length;j++)
{
TableItem item=table.getItem(selecteditems[j]);
Student tmpstu = new Student();
if (item.getText(0).trim() == "")
continue;
else {
tmpstu.setUuid(Shy.findByID(
item.getText(0)).get(0)
.getUuid());
shy.deleteStudent(tmpstu);
}
}
setShowlist(CommonData.getInstance().getStulist());
refresh();
}
});
}
public void open() {
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
public void preparedata() {
commondata = CommonData.getInstance();
showlist=getCommondata().getStulist();
}
public void initTable() {
table = new Table(group, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE
| SWT.FULL_SELECTION | SWT.CHECK);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.setBounds(15,45,695, 290);
table.setItemCount(Itemcount);
table.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
table.setFont(Display.getCurrent().getSystemFont());
TableColumn[] columns=new TableColumn[headers.length];
for (int i = 0; i < headers.length; i++) {
columns[i] = new TableColumn(table, SWT.CENTER);
columns[i].setText(headers[i]);
columns[i].setResizable(Boolean.TRUE);
columns[i].setWidth(Width[i]);
}
table.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// TableItem[] selected =table.getSelection();
selecteditems= table.getSelectionIndices();
// table.remove(table.getSelectionIndices());
System.out.println("Selected :"+selecteditems.length);
/* for(int j=0;j<selectedindex.length;j++)
{
TableItem item=table.getItem(selectedindex[j]);
Student tmpstu = new Student();
if (item.getText(0).trim() == "")
continue;
else {
tmpstu.setUuid(Shy.findByID(
item.getText(0)).get(0)
.getUuid());
shy.deleteStudent(tmpstu);
}
}*/
// setShowlist(CommonData.getInstance().getStulist());
//refresh();
}
});
buidCellListener();
columns[0].addListener(SWT.Selection, new Listener()
{
public void handleEvent(Event e)
{
TableItem[] items=table.getItems();
Collator collator = Collator.getInstance(Locale.getDefault());
for (int i = 1; i < items.length; i++) {
String value1 = items[i].getText(0);
for (int j = 0; j < i; j++) {
String value2 = items[j].getText(0);
if (collator.compare(value1, value2) < 0) {
String[] values = { items[i].getText(0),
items[i].getText(1),items[i].getText(2),items[i].getText(3),items[i].getText(4),items[i].getText(5)};
items[i].dispose();
TableItem item = new TableItem(table, SWT.NONE, j);
item.setText(values);
items = table.getItems();
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -