?? sdimgr.java
字號:
package net.csksoft.TigerBox;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.*;
import java.io.*;
import java.nio.*;
import java.util.*;
import java.nio.channels.*;
import java.lang.reflect.*;
import com.cloudgarden.resource.*;
public class SDIMgr implements DisposeListener{
public static Shell current_shell;
public static SDIMgr current_mgr;
protected Menu mainMenu;
protected CoolbarMgr coolbarmgr;
protected CoolBar coolbar;
protected Sash SashBar;
protected StyledText main_editor;
protected Text output;
protected ConsoleThread ct;
protected String m_strFilename ="";
protected boolean m_bIsChg = false;
protected boolean m_bSaved = false;
protected String m_compiler_class = "";
public LinkedList<String> cmdBuff = new LinkedList<String>();
protected void UpdateTitle()
{
current_shell.setText("TigerBox BY CSK-" + m_strFilename + ((m_bIsChg)?"*":""));
}
public void Output(String str,boolean cls)
{
if (cls)
{
output.setText("");
}
output.setSelection(output.getCharCount());
output.insert(str+ "\r\n");
}
public static int MessageBox(String text,String title,int nStyle)
{
MessageBox msgbox = new MessageBox(current_shell,nStyle );
msgbox.setMessage( text);
msgbox.setText(title);
return msgbox.open();
}
protected void OnExportTree()
{
if (m_bIsChg || !m_bSaved)
{
if (MessageBox( "Current file has been changed\nSave it now","?",SWT.YES|SWT.NO )==SWT.NO)
{
if (!m_bSaved)
{
MessageBox("You should save this file first","Error",SWT.YES);
return;
}
}else
{
OnSaveDocument(false);
}
}
if (!m_bIsChg && m_bSaved )
{
FileDialog fdialog = new FileDialog(current_shell,SWT.SAVE);
fdialog.setFilterExtensions(new String [] {"*.bmp","*.jpg"});
fdialog.setFilterNames(new String [] {"Bmp File","JPG File"});
String strfilePath = fdialog.open();
int img_format=0;
if (strfilePath!=null)
{
if(strfilePath.toLowerCase().substring(strfilePath.length()-3).equals("bmp")) img_format=0;
if(strfilePath.toLowerCase().substring(strfilePath.length()-3).equals("jpg")) img_format=1;
// if(strfilePath.toLowerCase().substring(strfilePath.length()-3).equals("png")) img_format=2;
try{
if (XTiger.parsersys.Main.exportToTree(m_strFilename,strfilePath,img_format))
{
// Output("<Tree Saved>",false);
}
else
{
// Output("<NOTHING DONE>",false);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}else
{
return ;
}
}
else
{
Output("<Compile Aborted>",false);
}
}
protected void OnCompile()
{
if (m_bIsChg || !m_bSaved)
{
if (MessageBox( "Current file has been changed\nSave it now","?",SWT.YES|SWT.NO )==SWT.NO)
{
if (!m_bSaved)
{
MessageBox("You should save this file first","Error",SWT.YES);
return;
}
}else
{
OnSaveDocument(false);
}
}
if (!m_bIsChg && m_bSaved )
{
String [] str = new String[1];
str[0]=this.m_strFilename;
Output("=======Start Compiler======",true);
try{
Class [] argc = new Class[1];
argc[0] = str.getClass();
Method MainMethod;
Class destClass;
destClass = Class.forName(m_compiler_class);
MainMethod =destClass.getMethod("main", argc);
Object[] inArgs = new Object[1];
inArgs[0] = str;
MainMethod.invoke(destClass, inArgs);
System.out.println("\n---------- FINISHED -----------");
}
catch (ClassNotFoundException e)
{
//TODO
System.out.println("\n----------Invoke Error-----------");
System.out.println("Cannot Load Class:"+m_compiler_class);
}
catch (NoSuchMethodException e)
{
System.out.println("\n----------Invoke Error-----------");
System.out.println("Cannot Find Method \"Main\"");
}
catch (IllegalAccessException e)
{
System.out.println("\n----------Invoke Error-----------");
System.out.println("invoke Method \"Main\" error:IllegalAccessException");
}
catch (IllegalArgumentException e)
{
System.out.println("\n----------Invoke Error-----------");
System.out.println("invoke Method \"Main\" error:IllegalArgumentException");
}
catch(Exception e)
{
System.out.println("\n----------Unexpected Error-----------");
e.printStackTrace(System.out);
}
}
else
{
Output("<Compile Aborted>",false);
}
}
protected void OnNewDocument()
{
if (OnCloseDocument()==SWT.CANCEL) return;
m_strFilename = "untitled.tig";
main_editor.setText("");
m_bIsChg =false;
m_bSaved = false;
Output("<New Document>",false);
m_bIsChg =false;
this.UpdateTitle();
}
protected void OnOpenDocument()
{
if (OnCloseDocument()==SWT.CANCEL) return;
m_strFilename = "untitled.tig";
main_editor.setText("");
m_bSaved = false;
m_bIsChg =false;
FileDialog fdialog = new FileDialog(current_shell,SWT.OPEN);
fdialog.setFilterExtensions(new String [] {"*.tig","*.*"});
fdialog.setFilterNames(new String [] {"Tiger Language Source","All files"});
String strfilePath = fdialog.open();
if (strfilePath!=null)
{
this.m_strFilename = strfilePath;
}else
{
this.UpdateTitle();
return ;
}
try
{
FileInputStream inputstream = new FileInputStream(m_strFilename);
FileChannel fileData =inputstream.getChannel();
byte[] buffer= new byte[(int)fileData.size()];
inputstream.read(buffer);
String strBuff=new String(buffer,"GBK");
main_editor.setText(strBuff);
m_bSaved = true;
fileData.close();
inputstream.close();
}
catch(Exception e)
{
MessageBox( "Can not open file:"+m_strFilename,"Failed",SWT.OK );
}
finally{
try{
}
catch(Exception e)
{
}
}
m_bIsChg =false;
Output("<Open:" +m_strFilename + ">",false);
this.UpdateTitle();
}
protected int OnCloseDocument()
{
if (this.m_bIsChg)
{
int ans;
ans = MessageBox("Save?","Current File will be LOST",SWT.YES | SWT.NO | SWT.CANCEL);
if (ans==SWT.YES)
{
OnSaveDocument(false);
}
return ans;
}
return SWT.YES;
}
protected void OnSaveDocument(boolean bAs)
{
if (bAs || !m_bSaved)
{
FileDialog fdialog = new FileDialog(current_shell,SWT.SAVE);
fdialog.setFilterExtensions(new String [] {"*.tig","*.*"});
fdialog.setFilterNames(new String [] {"Tiger Language Source","All files"});
fdialog.setFileName(this.m_strFilename);
String strfilePath = fdialog.open();
if (strfilePath!=null)
{
this.m_strFilename = strfilePath;
}else
{
return ;
}
}
m_bIsChg = false;
m_bSaved = true;
try
{
byte[] bufferData = main_editor.getText().getBytes("GBK");
FileOutputStream inputstream = new FileOutputStream(m_strFilename);
FileChannel fileData =inputstream.getChannel();
ByteBuffer reader= ByteBuffer.allocate(bufferData.length);
reader.put(bufferData);
reader.flip();
fileData.write(reader);
reader.clear();
fileData.close();
inputstream.close();
}
catch(Exception e)
{
MessageBox( "Can not save file:"+m_strFilename,"Failed",SWT.OK );
}
finally{
try{
}
catch(Exception e)
{
}
}
UpdateTitle();
Output("<Saved to:"+m_strFilename+">",false);
}
public SDIMgr(Shell myShell)
{
current_shell = myShell;
current_mgr = this;
myShell.addDisposeListener(this);
myShell.addShellListener(new myShellListener());
OnInitSDI();
try
{
ct = new ConsoleThread(this);
System.setOut(new PrintStream(ct.getOut(), true));
System.setErr(new PrintStream(ct.getOut(), true));
}
catch(Exception e)
{
}
ct.setRun(true);
ct.start();
}
protected void LoadConf()
{
try
{
FileInputStream inputstream = new FileInputStream("etc/conf");
FileChannel fileData =inputstream.getChannel();
MappedByteBuffer reader=fileData.map(FileChannel.MapMode.READ_ONLY, 0, fileData.size());
byte[] buffer= new byte[(int)fileData.size()];
reader.get(buffer);
String strBuff=new String(buffer,"GBK");
m_compiler_class = strBuff;
}
catch(Exception e)
{
Output("Error,cannot load configure file",true);
e.printStackTrace();
}
}
protected void OnInitSDI()
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -