package org.jpn.xucker.phonixSplit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.MessageBox;
import org.jpn.xucker.commons.swt.ui.FileDirChoicer;
public class PhonixSplit implements SelectionListener,QuestionControl{
/**
* @param shell
*/
private TabFolder tabfolder1;
private TabItem questionSelectTab;
private Combo combo1;
private Button questionStartButton;
private TabItem questionExecuteTab;
private TabItem resultTab;
private Table resultTable;
QuestionFolder questionFolder;
Shell shell;
private double version=0.1;
private String HOMEPAGE_URL="http://www.xucker.jpn.org/";
private String APP_NAME="App";
public PhonixSplit(Shell shell) {
this.shell=shell;
shell.setText("");
shell.setBounds(0,0,500,400);
RowLayout layout=new RowLayout();
shell.setLayout(layout);
tabfolder1=new TabFolder(shell,SWT.NULL);
RowData tabfolder1_data=new RowData();
tabfolder1_data.width=480;
tabfolder1_data.height=335;
tabfolder1.setLayoutData(tabfolder1_data);
tabfolder1.addSelectionListener(this);
questionSelectTab=new TabItem(tabfolder1,SWT.NULL);
questionSelectTab.setText("questionSelectTab");
Composite composite1=new Composite(tabfolder1,SWT.NULL);
RowLayout composite1_layout=new RowLayout();
composite1.setLayout(composite1_layout);
combo1=new Combo(composite1,SWT.NULL);
combo1.add("テスト");
combo1.select(0);
combo1.addSelectionListener(this);
RowData combo1_data=new RowData();
combo1.setLayoutData(combo1_data);
//問題開始
questionStartButton=new Button(composite1,SWT.NULL);
questionStartButton.setText("問題開始");
questionStartButton.addSelectionListener(this);
RowData questionStartButton_data=new RowData();
questionStartButton.setLayoutData(questionStartButton_data);
questionSelectTab.setControl(composite1);
questionExecuteTab=new TabItem(tabfolder1,SWT.NULL);
questionExecuteTab.setText("questionExecuteTab");
try {
questionFolder=new QuestionFolder(new FileReader(new File("c:\\tmp\\q.txt")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PhonixSplitCanvas canvas=new PhonixSplitCanvas(tabfolder1,SWT.NULL);
canvas.setButtonRectangle(new Rectangle(10,70,100,40));
RowLayout composite2_layout=new RowLayout();
canvas.setLayout(composite2_layout);
questionExecuteTab.setControl(canvas);
canvas.setQuestionControl(this);
canvas.init();
Font qFont=new Font(shell.getDisplay(),"MS 明朝",48,SWT.BOLD);
canvas.setQuestionFont(qFont);
resultTab=new TabItem(tabfolder1,SWT.NULL);
resultTab.setText("resultTab");
resultTable=new Table(tabfolder1,SWT.NULL);
resultTable.addSelectionListener(this);
RowData resultTable_data=new RowData();
resultTable.setLayoutData(resultTable_data);
TableColumn resultTable_column =new TableColumn(resultTable,SWT.NULL);
TableItem resultTable_item =new TableItem(resultTable,SWT.NULL);
resultTab.setControl(resultTable);
tabfolder1.setSelection(1);
}
public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display,SWT.CLOSE|SWT.MIN);
try {
PhonixSplit main=new PhonixSplit(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (!shell.isDisposed()) {
shell.close();
}
display.dispose();
//System.exit(0);
}
}
public void widgetSelected(SelectionEvent event) {
Object target=event.getSource();
if(target==null){
//maybe not happen.
System.out.println("target==null");
}
//null1
else if(target==tabfolder1){
do_tabfolder1();
}
//null1
else if(target==combo1){
do_combo1();
}
//問題開始
else if(target==questionStartButton){
do_questionStartButton();
}
//解答結果
else if(target==resultTable){
do_resultTable();
}
}
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
//null1
public void do_tabfolder1(){
System.out.println("tabfolder1");
}
//null1
public void do_combo1(){
System.out.println("combo1");
}
//問題開始
public void do_questionStartButton(){
System.out.println("questionStartButton");
}
//解答結果
public void do_resultTable(){
System.out.println("resultTable");
}
public void execHomepage(){
Program program=Program.findProgram("html");
if(program!=null){
program.execute(HOMEPAGE_URL);
}
}
public void execVersion() {
MessageBox box = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
box.setMessage(APP_NAME+" v" + version + "\r\n\r\n"
+ "License CPL or Apache2.0\r\n (c)アッキー 2004\r\n"
+ HOMEPAGE_URL);
//int result=box.open();
//never use result int,for PMD
box.open();
}
/* (non-Javadoc)
* @see org.jpn.xucker.phonixSplit.QuestionControl#getNextQuestion()
*/
public String getNextQuestion() {
String question
=questionFolder.nextQuestion();
return question;
}
/* (non-Javadoc)
* @see org.jpn.xucker.phonixSplit.QuestionControl#setResult(java.lang.String, boolean)
*/
public void setResult(String question, boolean result) {
Clipboard cp= new Clipboard(shell.getDisplay());
String datas[]={question};
Transfer[] transfers=new Transfer[1];
transfers[0]=TextTransfer.getInstance();
cp.setContents(datas,transfers);
System.out.println(question+","+result);
}
}
|