home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 July & August
/
Pcwk78a98.iso
/
Micrsoft
/
VJ
/
VJ98
/
WIZARDS
/
TEMPLATE
/
AW1.TEM
< prev
next >
Wrap
Text File
|
1998-02-24
|
10KB
|
403 lines
//%FILENAME%.java
import wfc.app.*;
import wfc.core.*;
import wfc.ui.*;
///*awiz Menu
///*awiz Edit
import wfc.io.*;
///*end Edit
///*end Menu
/**
* ///#6010#
* ///#6020#
*/
public class %FILENAME% extends Form
{
///*awiz Menu
///*awiz Edit
private String m_sFileName = new String("");
private boolean m_bIsDirty = false;
private void edit1_onTextChanged(Object sender, Event e)
{
m_bIsDirty = true;
}
///*end Edit
public void newMenu_click(Object sender, Event e)
{
// ///#6170#
///*awiz Edit
if (canCloseCurrent(sender, e))
{
edit1.setText("");
m_sFileName = "";
m_bIsDirty = false;
}
///*end Edit
}
private void saveAsMenu_click(Object sender, Event e)
{
// ///#6180#
///*awiz Edit
doSaveAs(sender, e);
///*end Edit
}
private void saveMenu_click(Object sender, Event e)
{
// ///#6190#
///*awiz Edit
doSave(sender, e);
///*end Edit
}
private void openMenu_click(Object sender, Event e)
{
// ///#6200#
///*awiz Edit
if (! canCloseCurrent(sender, e))
{
return;
}
OpenFileDialog fOpenDlg = new OpenFileDialog ();
fOpenDlg.setFilter("///#5150#");
fOpenDlg.setOptions(OpenFileDialog.FILEMUSTEXIST|OpenFileDialog.PATHMUSTEXIST| OpenFileDialog.HIDEREADONLY);
fOpenDlg.setFilename ("///#5160#");
if (fOpenDlg.run ())
{
try
{
File fInputFile = File.open(fOpenDlg.getFilename());
long nLength = fInputFile.getLength();
edit1.setText (fInputFile.readStringCharsAnsi((int)nLength));
fInputFile.close ();
m_sFileName = fOpenDlg.getFilename();
}
catch (Exception excpt)
{
excpt.printStackTrace();
}
}
///*end Edit
}
public void wordWrapMenu_click(Object sender, Event e)
{
// ///#6030#
///*awiz Edit
boolean bWordWrap;
bWordWrap = ! edit1.getWordWrap ();
edit1.setWordWrap (bWordWrap);
wordWrapMenu.setChecked(bWordWrap);
if (bWordWrap)
{
edit1.setScrollBars(ScrollBars.VERTICAL);
}
else
{
edit1.setScrollBars(ScrollBars.BOTH);
}
///*end Edit
}
public void dateTimeMenu_click(Object sender, Event e)
{
// ///#6160#
///*awiz Edit
edit1.setSelectedText (Time.toString (Time.getNow()));
///*end Edit
}
public void pasteMenu_click(Object sender, Event e)
{
// ///#6040#
// ///#6050#
try
{
///*awiz Edit
DataObject myDObj = new DataObject (Clipboard.getClipboardData ());
edit1.setSelectedText ((String) myDObj.getData (String.class));
///*end Edit
}
catch (Exception ecx)
{
}
}
public void copyMenu_click(Object sender, Event e)
{
// ///#6060#
///*awiz Edit
Clipboard.setClipboardData (edit1.getSelectedText ());
///*end Edit
}
public void cutMenu_click(Object sender, Event e)
{
// ///#6070#
///*awiz Edit
Clipboard.setClipboardData (edit1.getSelectedText ());
edit1.setSelectedText ("");
///*end Edit
}
///*end Menu
///*awiz Edit
public void %FILENAME%_Resize(Object sender, Event e)
{
edit1.setSize (this.getClientSize ());
}
///*end Edit
///*awiz Menu
public void exitMenu_click(Object sender, Event e)
{
// ///#6150#
///*awiz Edit
if (canCloseCurrent(sender, e))
///*end Edit
Application.exit();
}
///*end Menu
public %FILENAME%()
{
///#6100#
initForm();
///#6110#
///*awiz Edit
edit1.setLocation (0,0);
edit1.setSize(this.getClientSize());
///*awiz Menu
wordWrapMenu.setChecked(edit1.getWordWrap ());
///*end Menu
///*end Edit
}
///*awiz Menu
///*awiz Edit
private boolean canCloseCurrent(Object sender, Event e)
{
boolean bRc = false;
if (! m_bIsDirty)
return true;
int iRc;
MessageBox mBox = new MessageBox();
String sText = new String ();
sText = "///#6210#";
if (m_sFileName.length() == 0)
sText = sText + "///#6220#";
else
sText = sText + m_sFileName;
sText = sText + "///#6230#";
iRc = mBox.show (sText, "JPad", MessageBox.DEFBUTTON1 |MessageBox.ICONEXCLAMATION | MessageBox.YESNOCANCEL);
switch (iRc){
case MessageBox.IDYES:
bRc = doSave(sender, e);
break;
case MessageBox.IDNO:
bRc = true;
break;
case MessageBox.IDCANCEL:
bRc = false;
break;
}
return bRc;
}
private boolean doSaveAs(Object sender, Event e)
{
boolean bRc = false;
SaveFileDialog fSaveDlg = new SaveFileDialog ();
fSaveDlg.setFilename (m_sFileName);
fSaveDlg.setFilter("///#5150#");
fSaveDlg.setOptions(OpenFileDialog.PATHMUSTEXIST| OpenFileDialog.HIDEREADONLY);
if (fSaveDlg.run ())
{
File fOutFile = File.create(fSaveDlg.getFilename());
fOutFile.writeStringCharsAnsi (edit1.getText ());
fOutFile.close ();
m_sFileName = fSaveDlg.getFilename();
m_bIsDirty = false;
bRc = true;
}
return bRc;
}
private boolean doSave(Object sender, Event e)
{
boolean bRc = false;
if (m_sFileName.length() == 0)
{
bRc = doSaveAs(sender, e);
}
else
{
File fOutFile = File.create(m_sFileName);
fOutFile.writeStringCharsAnsi (edit1.getText ());
fOutFile.close ();
m_bIsDirty = false;
bRc = true;
}
return bRc;
}
///*end Edit
///*end Menu
public static void main(String args[])
{
Application.run(new %FILENAME%());
}
///#6120#
Container components = new Container();
///*awiz Edit
Edit edit1 = new Edit();
///*end Edit
///*awiz Menu
MainMenu mainMenu1 = new MainMenu();
MenuItem fileMenu = new MenuItem();
MenuItem newMenu = new MenuItem();
MenuItem openMenu = new MenuItem();
MenuItem saveMenu = new MenuItem();
MenuItem seperator3Menu = new MenuItem();
MenuItem exitMenu = new MenuItem();
MenuItem editMenu = new MenuItem();
MenuItem cutMenu = new MenuItem();
MenuItem copyMenu = new MenuItem();
MenuItem pasteMenu = new MenuItem();
MenuItem separator1Menu = new MenuItem();
MenuItem dateTimeMenu = new MenuItem();
MenuItem separator2Menu = new MenuItem();
MenuItem wordWrapMenu = new MenuItem();
MenuItem helpMenu = new MenuItem();
MenuItem aboutMenu = new MenuItem();
MenuItem saveAsMenu = new MenuItem();
///*end Menu
///*awiz StatusBar
StatusBar statusBar1 = new StatusBar();
///*end StatusBar
private void initForm()
{
///*awiz Edit
edit1.setBackColor(Color.WINDOW);
edit1.setCursor(Cursor.IBEAM);
edit1.setLocation(new Point(85, 126));
edit1.setSize(new Point(121, 20));
edit1.setTabIndex(1);
edit1.setTabStop(true);
edit1.setText("");
edit1.setMultiline(true);
edit1.setScrollBars(ScrollBars.VERTICAL);
///*end Edit
///*awiz Menu
newMenu.setText("///#5010#");
newMenu.addOnClick(new EventHandler(this.newMenu_click));
openMenu.setText("///#5020#");
openMenu.addOnClick(new EventHandler(this.openMenu_click));
saveMenu.setText("///#5030#");
saveMenu.addOnClick(new EventHandler(this.saveMenu_click));
seperator3Menu.setText("///#5040#");
exitMenu.setText("///#5050#");
exitMenu.addOnClick(new EventHandler(this.exitMenu_click));
saveAsMenu.setText("///#5170#");
saveAsMenu.addOnClick(new EventHandler(this.saveAsMenu_click));
fileMenu.setMenuItems(new MenuItem[] {
newMenu,
openMenu,
saveMenu,
saveAsMenu,
seperator3Menu,
exitMenu});
fileMenu.setText("///#5060#");
cutMenu.setText("///#5070#");
cutMenu.addOnClick(new EventHandler(this.cutMenu_click));
copyMenu.setText("///#5080#");
copyMenu.addOnClick(new EventHandler(this.copyMenu_click));
pasteMenu.setText("///#5090#");
pasteMenu.addOnClick(new EventHandler(this.pasteMenu_click));
separator1Menu.setText("///#5040#");
dateTimeMenu.setText("///#5100#");
dateTimeMenu.addOnClick(new EventHandler(this.dateTimeMenu_click));
separator2Menu.setText("///#5040#");
wordWrapMenu.setText("///#5110#");
wordWrapMenu.addOnClick(new EventHandler(this.wordWrapMenu_click));
editMenu.setMenuItems(new MenuItem[] {
cutMenu,
copyMenu,
pasteMenu,
separator1Menu,
dateTimeMenu,
separator2Menu,
wordWrapMenu});
editMenu.setText("///#5120#");
aboutMenu.setText("///#5130#");
helpMenu.setMenuItems(new MenuItem[] {
aboutMenu});
helpMenu.setText("///#5140#");
mainMenu1.setMenuItems(new MenuItem[] {
fileMenu,
editMenu,
helpMenu});
/* @designTimeOnly mainMenu1.setLocation(new Point(100, 60)); */
///*end Menu
this.setBackColor(Color.CONTROL);
this.setLocation(new Point(298, 88));
this.setSize(new Point(300, 240));
this.setTabIndex(-1);
this.setTabStop(true);
this.setText("%FILENAME%");
this.setAutoScaleBaseSize(13);
this.setClientSize(new Point(292, 193));
///*awiz Menu
this.setMenu(mainMenu1);
///*end Menu
///*awiz Edit
this.addOnResize(new EventHandler(this.%FILENAME%_Resize));
///*end Edit
///*awiz StatusBar
statusBar1.setDock(ControlDock.BOTTOM);
statusBar1.setLocation(new Point(0, 153));
statusBar1.setSize(new Point(292, 20));
statusBar1.setTabIndex(3);
statusBar1.setTabStop(false);
statusBar1.setText("statusBar1");
statusBar1.setMode(StatusBarMode.NORMAL);
statusBar1.setPanels(new StatusBarPanel[] {});
statusBar1.setSimpleText("statusBar1");
statusBar1.setSizingGrip(false);
///*end StatusBar
this.setNewControls(new Control[] {
///*awiz StatusBar
statusBar1,
///*end StatusBar
///*awiz Edit
edit1
///*end Edit
});
}
///#6130#
public static class ClassInfo extends Form.ClassInfo
{
///#6140#
}
}