home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 July & August / Pcwk78a98.iso / Micrsoft / VJ / VJ98 / WIZARDS / TEMPLATE / AW1.TEM < prev    next >
Text File  |  1998-02-24  |  10KB  |  403 lines

  1. //%FILENAME%.java
  2. import wfc.app.*;
  3. import wfc.core.*;
  4. import wfc.ui.*;
  5. ///*awiz Menu
  6. ///*awiz Edit
  7. import wfc.io.*;
  8. ///*end Edit
  9. ///*end Menu
  10.  
  11. /**
  12.  * ///#6010#
  13.  * ///#6020#
  14.  */ 
  15.  
  16.  
  17.  
  18. public class %FILENAME% extends Form
  19. {
  20. ///*awiz Menu
  21. ///*awiz Edit
  22.     private String m_sFileName = new String("");
  23.     private boolean m_bIsDirty = false;
  24.  
  25.     private void edit1_onTextChanged(Object sender, Event e)
  26.     {
  27.         m_bIsDirty = true;
  28.     }
  29.  
  30. ///*end Edit
  31.  
  32.     public void newMenu_click(Object sender, Event e)
  33.     {
  34.     // ///#6170#
  35. ///*awiz Edit
  36.         if (canCloseCurrent(sender,  e)) 
  37.         {
  38.             edit1.setText("");
  39.             m_sFileName = "";
  40.             m_bIsDirty = false;
  41.         }
  42. ///*end Edit
  43.     }
  44.     
  45.     private void saveAsMenu_click(Object sender, Event e)
  46.     {
  47.     // ///#6180#
  48. ///*awiz Edit
  49.         doSaveAs(sender, e);
  50. ///*end Edit
  51.     }
  52.  
  53.     private void saveMenu_click(Object sender, Event e)
  54.     {
  55.     // ///#6190#
  56. ///*awiz Edit
  57.         doSave(sender, e);
  58. ///*end Edit
  59.     }
  60.  
  61.     private void openMenu_click(Object sender, Event e)
  62.     {
  63.     // ///#6200#
  64. ///*awiz Edit
  65.         if (! canCloseCurrent(sender,  e)) 
  66.         {
  67.             return;
  68.         }
  69.  
  70.         OpenFileDialog fOpenDlg = new OpenFileDialog ();
  71.         fOpenDlg.setFilter("///#5150#");
  72.         fOpenDlg.setOptions(OpenFileDialog.FILEMUSTEXIST|OpenFileDialog.PATHMUSTEXIST| OpenFileDialog.HIDEREADONLY);
  73.         fOpenDlg.setFilename ("///#5160#");
  74.         if (fOpenDlg.run ()) 
  75.         {
  76.             try 
  77.             {
  78.                 File fInputFile = File.open(fOpenDlg.getFilename());
  79.                 long nLength = fInputFile.getLength();
  80.                 edit1.setText (fInputFile.readStringCharsAnsi((int)nLength));
  81.                 fInputFile.close ();
  82.                 m_sFileName = fOpenDlg.getFilename();
  83.             } 
  84.             catch (Exception excpt) 
  85.             {
  86.                 excpt.printStackTrace();
  87.             }
  88.         }
  89. ///*end Edit
  90.     }
  91.  
  92.     public void wordWrapMenu_click(Object sender, Event e)
  93.     {
  94.     // ///#6030#
  95. ///*awiz Edit
  96.         boolean bWordWrap;
  97.         bWordWrap = ! edit1.getWordWrap ();
  98.         edit1.setWordWrap (bWordWrap);
  99.         wordWrapMenu.setChecked(bWordWrap);
  100.         if (bWordWrap)
  101.         {
  102.             edit1.setScrollBars(ScrollBars.VERTICAL);
  103.         }
  104.         else
  105.         {
  106.             edit1.setScrollBars(ScrollBars.BOTH);
  107.         }
  108. ///*end Edit
  109.     }
  110.  
  111.     public void dateTimeMenu_click(Object sender, Event e)
  112.     {
  113.     // ///#6160#
  114. ///*awiz Edit
  115.         edit1.setSelectedText  (Time.toString (Time.getNow()));
  116. ///*end Edit
  117.     }
  118.  
  119.     public void pasteMenu_click(Object sender, Event e)
  120.     {
  121.     // ///#6040#
  122.         // ///#6050#
  123.         try 
  124.         {    
  125. ///*awiz Edit
  126.             DataObject myDObj = new DataObject (Clipboard.getClipboardData ());
  127.             edit1.setSelectedText ((String) myDObj.getData (String.class));            
  128. ///*end Edit
  129.         }
  130.         catch (Exception ecx)
  131.         {
  132.         }
  133.     }
  134.  
  135.     public void copyMenu_click(Object sender, Event e)
  136.     {
  137.     // ///#6060#
  138. ///*awiz Edit
  139.         Clipboard.setClipboardData (edit1.getSelectedText ());
  140. ///*end Edit
  141.     }
  142.  
  143.     public void cutMenu_click(Object sender, Event e)
  144.     {
  145.     // ///#6070#
  146. ///*awiz Edit
  147.         Clipboard.setClipboardData (edit1.getSelectedText ());
  148.         edit1.setSelectedText ("");
  149. ///*end Edit
  150.     }
  151.  
  152. ///*end Menu
  153. ///*awiz Edit
  154.     public void %FILENAME%_Resize(Object sender, Event e)
  155.     {
  156.         edit1.setSize (this.getClientSize ());
  157.     }
  158. ///*end Edit
  159.     
  160. ///*awiz Menu
  161.     public void exitMenu_click(Object sender, Event e)
  162.     {
  163.     // ///#6150#        
  164. ///*awiz Edit
  165.         if (canCloseCurrent(sender,  e)) 
  166. ///*end Edit
  167.             Application.exit();
  168.     }
  169. ///*end Menu
  170.  
  171.     public %FILENAME%()
  172.     {
  173.         ///#6100#
  174.         initForm();        
  175.  
  176.         ///#6110#
  177. ///*awiz Edit
  178.         edit1.setLocation (0,0);
  179.         edit1.setSize(this.getClientSize());
  180. ///*awiz Menu
  181.         wordWrapMenu.setChecked(edit1.getWordWrap ());
  182. ///*end Menu        
  183. ///*end Edit
  184.     }
  185.  
  186.  
  187. ///*awiz Menu        
  188. ///*awiz Edit
  189.     private boolean canCloseCurrent(Object sender, Event e)
  190.     {
  191.         boolean bRc = false;
  192.         if (! m_bIsDirty)
  193.             return true;
  194.  
  195.         int iRc;
  196.         MessageBox mBox = new MessageBox();
  197.         String sText = new String ();
  198.         sText = "///#6210#";
  199.         if (m_sFileName.length() == 0)
  200.             sText = sText + "///#6220#";
  201.         else
  202.             sText = sText + m_sFileName;
  203.         sText = sText + "///#6230#";
  204.         iRc = mBox.show (sText, "JPad", MessageBox.DEFBUTTON1 |MessageBox.ICONEXCLAMATION | MessageBox.YESNOCANCEL);
  205.         switch (iRc){
  206.         case MessageBox.IDYES:
  207.             bRc = doSave(sender, e);
  208.             break;
  209.         case MessageBox.IDNO:
  210.             bRc = true;
  211.             break;
  212.         case MessageBox.IDCANCEL:
  213.             bRc = false;
  214.             break;
  215.         }
  216.         return bRc;
  217.     }
  218.     
  219.     private boolean doSaveAs(Object sender, Event e)
  220.     {
  221.         boolean bRc = false;
  222.         SaveFileDialog fSaveDlg = new SaveFileDialog ();
  223.         fSaveDlg.setFilename (m_sFileName);
  224.         fSaveDlg.setFilter("///#5150#");
  225.         fSaveDlg.setOptions(OpenFileDialog.PATHMUSTEXIST| OpenFileDialog.HIDEREADONLY);
  226.         if (fSaveDlg.run ()) 
  227.         {
  228.             File fOutFile = File.create(fSaveDlg.getFilename());
  229.             fOutFile.writeStringCharsAnsi (edit1.getText ());
  230.             fOutFile.close ();
  231.             m_sFileName = fSaveDlg.getFilename();
  232.             m_bIsDirty = false;
  233.             bRc = true;
  234.         }
  235.         return bRc;
  236.     }
  237.  
  238.     private boolean doSave(Object sender, Event e)
  239.     {
  240.         boolean bRc = false;
  241.         
  242.         if (m_sFileName.length() == 0)
  243.         {
  244.             bRc = doSaveAs(sender,  e);
  245.         }
  246.         else
  247.         {
  248.             File fOutFile = File.create(m_sFileName);
  249.             fOutFile.writeStringCharsAnsi (edit1.getText ());
  250.             fOutFile.close ();
  251.             m_bIsDirty = false;
  252.             bRc = true;
  253.         }
  254.         return bRc;
  255.     }
  256.  
  257. ///*end Edit
  258. ///*end Menu        
  259.     
  260.  
  261.     public static void main(String args[])
  262.     {
  263.         Application.run(new %FILENAME%());
  264.     }
  265.  
  266.     ///#6120#
  267.  
  268.     Container components = new Container();
  269. ///*awiz Edit
  270.     Edit edit1 = new Edit();
  271. ///*end Edit
  272. ///*awiz Menu
  273.     MainMenu mainMenu1 = new MainMenu();
  274.     MenuItem fileMenu = new MenuItem();
  275.     MenuItem newMenu = new MenuItem();
  276.     MenuItem openMenu = new MenuItem();
  277.     MenuItem saveMenu = new MenuItem();
  278.     MenuItem seperator3Menu = new MenuItem();
  279.     MenuItem exitMenu = new MenuItem();
  280.     MenuItem editMenu = new MenuItem();
  281.     MenuItem cutMenu = new MenuItem();
  282.     MenuItem copyMenu = new MenuItem();
  283.     MenuItem pasteMenu = new MenuItem();
  284.     MenuItem separator1Menu = new MenuItem();
  285.     MenuItem dateTimeMenu = new MenuItem();
  286.     MenuItem separator2Menu = new MenuItem();
  287.     MenuItem wordWrapMenu = new MenuItem();
  288.     MenuItem helpMenu = new MenuItem();
  289.     MenuItem aboutMenu = new MenuItem();
  290.     MenuItem saveAsMenu = new MenuItem();
  291. ///*end Menu
  292. ///*awiz StatusBar
  293.     StatusBar statusBar1 = new StatusBar();
  294. ///*end StatusBar
  295.     private void initForm()
  296.     {
  297.  
  298. ///*awiz Edit
  299.         edit1.setBackColor(Color.WINDOW);
  300.         edit1.setCursor(Cursor.IBEAM);
  301.         edit1.setLocation(new Point(85, 126));
  302.         edit1.setSize(new Point(121, 20));
  303.         edit1.setTabIndex(1);
  304.         edit1.setTabStop(true);
  305.         edit1.setText("");
  306.         edit1.setMultiline(true);
  307.         edit1.setScrollBars(ScrollBars.VERTICAL);
  308. ///*end Edit
  309. ///*awiz Menu
  310.         newMenu.setText("///#5010#");
  311.         newMenu.addOnClick(new EventHandler(this.newMenu_click));
  312.         openMenu.setText("///#5020#");
  313.         openMenu.addOnClick(new EventHandler(this.openMenu_click));
  314.         saveMenu.setText("///#5030#");
  315.         saveMenu.addOnClick(new EventHandler(this.saveMenu_click));
  316.         seperator3Menu.setText("///#5040#");
  317.         exitMenu.setText("///#5050#");
  318.         exitMenu.addOnClick(new EventHandler(this.exitMenu_click));
  319.         saveAsMenu.setText("///#5170#");
  320.         saveAsMenu.addOnClick(new EventHandler(this.saveAsMenu_click));
  321.         fileMenu.setMenuItems(new MenuItem[] {
  322.             newMenu, 
  323.             openMenu, 
  324.             saveMenu, 
  325.             saveAsMenu, 
  326.             seperator3Menu, 
  327.             exitMenu});
  328.         fileMenu.setText("///#5060#");
  329.         cutMenu.setText("///#5070#");
  330.         cutMenu.addOnClick(new EventHandler(this.cutMenu_click));
  331.         copyMenu.setText("///#5080#");
  332.         copyMenu.addOnClick(new EventHandler(this.copyMenu_click));
  333.         pasteMenu.setText("///#5090#");
  334.         pasteMenu.addOnClick(new EventHandler(this.pasteMenu_click));
  335.         separator1Menu.setText("///#5040#");
  336.         dateTimeMenu.setText("///#5100#");
  337.         dateTimeMenu.addOnClick(new EventHandler(this.dateTimeMenu_click));
  338.         separator2Menu.setText("///#5040#");
  339.         wordWrapMenu.setText("///#5110#");
  340.         wordWrapMenu.addOnClick(new EventHandler(this.wordWrapMenu_click));
  341.         editMenu.setMenuItems(new MenuItem[] {
  342.             cutMenu, 
  343.             copyMenu, 
  344.             pasteMenu, 
  345.             separator1Menu, 
  346.             dateTimeMenu, 
  347.             separator2Menu, 
  348.             wordWrapMenu});
  349.         editMenu.setText("///#5120#");
  350.         aboutMenu.setText("///#5130#");
  351.         helpMenu.setMenuItems(new MenuItem[] {
  352.             aboutMenu});
  353.         helpMenu.setText("///#5140#");
  354.         mainMenu1.setMenuItems(new MenuItem[] {
  355.             fileMenu, 
  356.             editMenu, 
  357.             helpMenu});
  358.         /* @designTimeOnly mainMenu1.setLocation(new Point(100, 60)); */
  359. ///*end Menu
  360.         this.setBackColor(Color.CONTROL);
  361.         this.setLocation(new Point(298, 88));
  362.         this.setSize(new Point(300, 240));
  363.         this.setTabIndex(-1);
  364.         this.setTabStop(true);
  365.         this.setText("%FILENAME%");
  366.         this.setAutoScaleBaseSize(13);
  367.         this.setClientSize(new Point(292, 193));
  368. ///*awiz Menu
  369.         this.setMenu(mainMenu1);
  370. ///*end Menu
  371. ///*awiz Edit
  372.         this.addOnResize(new EventHandler(this.%FILENAME%_Resize));
  373. ///*end Edit
  374. ///*awiz StatusBar
  375.         statusBar1.setDock(ControlDock.BOTTOM);
  376.         statusBar1.setLocation(new Point(0, 153));
  377.         statusBar1.setSize(new Point(292, 20));
  378.         statusBar1.setTabIndex(3);
  379.         statusBar1.setTabStop(false);
  380.         statusBar1.setText("statusBar1");
  381.         statusBar1.setMode(StatusBarMode.NORMAL);
  382.         statusBar1.setPanels(new StatusBarPanel[] {});
  383.         statusBar1.setSimpleText("statusBar1");
  384.         statusBar1.setSizingGrip(false);
  385. ///*end StatusBar
  386.  
  387.         this.setNewControls(new Control[] {
  388. ///*awiz StatusBar
  389.             statusBar1, 
  390. ///*end StatusBar
  391. ///*awiz Edit
  392.             edit1
  393. ///*end Edit
  394.             });
  395.     }
  396.     ///#6130#
  397.  
  398.     public static class ClassInfo extends Form.ClassInfo
  399.     {
  400.         ///#6140#
  401.     }
  402. }
  403.