home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / afc11 / JNotepad / src / JNotePad.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  7.8 KB  |  242 lines

  1. /*
  2. * (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. */
  4. import java.applet.*;
  5. import java.awt.*;
  6. import com.ms.ui.*;
  7. import com.ms.fx.*;
  8. import JNotePadFrame;
  9. import com.ms.ui.resource.*;
  10. import java.io.InputStream;
  11. /** 
  12.  * A text editor written in Java. A cross between Wordpad and Notepad
  13.  * with extra features, many of them user customizable. 
  14.  * <p>
  15.  * This is the main class which starts JNotepad and gets everything else
  16.  * running. This is a little different than traditional Java applets. This
  17.  * is because we want to use the AFC UIApplet class, but browsers don't 
  18.  * recognize this because they expect an Applet. Our solution is to use a
  19.  * AwtUIApplet wrapper. AwtUIApplet acts like an Applet object, so browsers
  20.  * can run it, and it supports AFC. Here we use a private UIApplet class, JNotePadImpl,
  21.  * to do all of the work necessary to run the applet, and wrap it inside
  22.  * the AwtUIApplet class JNotepad. We create a copy of JNotepadImpl and
  23.  * send it to the AwtUIApplet constructor. This gives us a UIApplet which
  24.  * will run in a browser. See UIApplet and AwtUIApplet for more detail.
  25.  * <p>
  26.  * (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  27.  * <p>
  28.  *
  29.  * @version     1.0, 7/9/97
  30.  */
  31. public class JNotePad extends AwtUIApplet{
  32. /**
  33.  *    Creates a new JNotepad object.
  34.  */
  35.     public JNotePad(){
  36.         super(new JNotePadImpl());
  37.     }
  38. /**
  39.  *    Program entry point. Creates an instance of the real JNotePad application
  40.  *    object, and runs it the same way as the system runs an applet.
  41.  * 
  42.  * @param args[] Array of command line arguments
  43.  */
  44.     public static void main(String args[]){
  45.         // set sFilename to filename to load into JNotepad        
  46.         JNotePadImpl theApp = new JNotePadImpl();
  47.         theApp.args=args;
  48.         if (args.length > 0){
  49.             theApp.sFilename = args[0];                
  50.             theApp.isApplet = false;
  51.         }
  52.         theApp.init();
  53.         theApp.start();
  54.     }
  55. /**
  56.  * 
  57.  */
  58.     private static Win32ResourceDecoder resources;
  59. /**
  60.  */
  61.     public static Win32ResourceDecoder getResources(){
  62.         if(resources==null){
  63.             try{
  64.                 WhereAmI here=new WhereAmI();
  65.                 Class cl=here.getClass();
  66.                 InputStream is = 
  67.                     com.ms.fx.FxToolkit.getSystemInterface().getResourceAsStream(cl, "jnotepad.res" );
  68.                 resources =new Win32ResourceDecoder( is );
  69.             }catch(Exception e)    {
  70.                 // no resource file
  71.                 UIMessageBox box = new UIMessageBox(new UIFrame(), 
  72.                     JNotePad.loadString(ResourceIDs.IDS_MSGINSTALLERR),
  73.                     JNotePad.loadString(ResourceIDs.IDS_MSGNORES),
  74.                     box.STOP, UIButtonBar.OK);
  75.                 box.doModal();
  76.                 return null;
  77.             }
  78.         }
  79.         return resources;
  80.     }
  81.     public static String loadString(int id){
  82.         Win32ResourceDecoder res=getResources();
  83.         try{
  84.             return res.getString(id);
  85.         }catch (Exception e){
  86.             return null;
  87.         }
  88.     }
  89.     public static UIMenuItem loadMenuItem(int stringID, 
  90.                                           int cmdID){
  91.         UIMenuItem mi=new UIMenuItem(loadString(stringID));
  92.         mi.setID(cmdID);
  93.         return mi;
  94.     }
  95.  
  96.     public static UIMenuItem loadMenuItem(int id){
  97.         return loadMenuItem(id,id);
  98.     }
  99. }
  100. /**
  101.  *    Class which implements JNotepad. 
  102.  */
  103.  class JNotePadImpl extends UIApplet {        
  104.     String sFilename;    
  105.     boolean isApplet;
  106.     String args[];
  107.     public JNotePadImpl(){
  108.         sFilename = null;
  109.         isApplet = false;
  110.     }
  111.     public void init(){
  112.         // we do nothing in the init() function
  113.     }
  114.     public void start(){
  115.         // Create Toplevel Window
  116.         JNotePadFrame frame = new JNotePadFrame("JNotePad", sFilename);
  117.         frame.show();        
  118.     }
  119. /** 
  120.  * getAppletInfo() returns information about the applet.
  121.  */
  122.     public String getAppletInfo(){
  123.         return "Name: JNotepad\r\n" +
  124.             "(C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.\r\n";
  125.     }    
  126. }
  127. interface ResourceIDs {
  128.     static final int ID_HELP_ABOUT=4020;
  129.     static final int ID_PROPERTIES=4005;
  130.     static final int ID_TIMEDATE=4014;
  131.     static final int ID_EMACS_CUT=-1;
  132.     static final int ID_EMACS_PASTE=-2;
  133.     static final int ID_FILE_NEW=4021;
  134.     static final int ID_FILE_OPEN=4022;
  135.     static final int ID_FILE_SAVE=4023;
  136.     static final int ID_FILE_SAVEAS=4024;
  137.     static final int ID_FILE_CLOSE=4003;
  138.     static final int ID_FILE_PRINT=-3;
  139.     static final int ID_FILE_EXIT=4007;
  140.     static final int ID_EDIT_FIND=4017;
  141.     static final int ID_EDIT_REPLACE=4019;
  142.     static final int ID_EDIT_CUT=1001;
  143.     static final int ID_EDIT_COPY=1002;
  144.     static final int ID_EDIT_PASTE=1003;
  145.     static final int ID_EDIT_DELETE=4012;
  146.     static final int ID_EDIT_UNDO=4026;
  147.     static final int ID_EDIT_REDO=4004;
  148.     static final int ID_EDIT_SELECT_ALL=4013;
  149.     static final int ID_WORDWRAPMENU=4006;
  150.     static final int ID_NOWORDWRAP=5000; // dynamically generated
  151.     static final int ID_WORDWRAP=5001;    // dynamically generated
  152.     static final int ID_WORDWRAP2=5002;    // dynamically generated
  153.     static final int ID_FONT=4001;
  154.     static final int ID_TEXTCOLOR=4002;
  155.     static final int ID_BGCOLOR=4011;
  156.     static final int ID_WINDOW_PREVIOUS=4027;
  157.     static final int ID_WINDOW_NEXT=4015;
  158.     //
  159.     // Context menu goo.
  160.     //
  161.     static final int ID_LAUNCH=3000;
  162.     //
  163.     // Strings
  164.     //
  165.     static final int IDS_NEW=101;
  166.     static final int IDS_OPEN=102;
  167.     static final int IDS_SAVE=103;
  168.     static final int IDS_CLOSE=104;
  169.     static final int IDS_UNDO=105;
  170.     static final int IDS_REDO=106;
  171.     static final int IDS_CUT=107;
  172.     static final int IDS_COPY=108;
  173.     static final int IDS_PASTE=109;
  174.     static final int IDS_DELETE=110;
  175.     static final int IDS_SELECT_ALL=121;
  176.     static final int IDS_FONT=111;
  177.     static final int IDS_TEXTCOLOR=112;
  178.     static final int IDS_BGCOLOR=113;
  179.     static final int IDS_LAUNCHSELLINK=114;
  180.     static final int IDS_FIND=115;
  181.     static final int IDS_REPLACE=116;
  182.     static final int IDS_WORDWRAPMENU = 117;
  183.     static final int IDS_NOWORDWRAP = 118;
  184.     static final int IDS_WORDWRAP = 119;
  185.     static final int IDS_WORDWRAP2 = 120;
  186.     // clipboard strings
  187.     static final int IDS_LOCALCLIPBOARD=124;
  188.     static final int IDS_CLIPBOARD=125;
  189.     static final int IDS_INVALIDCLIPBOARDDATA=126;
  190.     static final int IDS_EMPTYCLIPBOARD=127;
  191.     static final int IDS_CLIPBOARDIMG=128;
  192.     // misc strings
  193.     static final int IDS_FILEIMG=129;
  194.     static final int IDS_COLORCHOICEFGTIP=130;
  195.     static final int IDS_COLORCHOICEBGTIP=131;
  196.     static final int IDS_JNOTEPADICON=132;
  197.     static final int IDS_NEWFILETITLE=133;
  198.     static final int IDS_UNTITLEDFILE=239;
  199.     static final int IDS_FINDREPLACE=238;
  200.     // message box text
  201.     static final int IDS_MSGTITLE=122;
  202.     static final int IDS_MSGREADONLY=123;
  203.     static final int IDS_MSGNOSAVE=200;
  204.     static final int IDS_MSGFILENOTFOUND=202;
  205.     static final int IDS_MSGFILEREAD=203;
  206.     static final int IDS_MSGSAVEERR=204;
  207.     static final int IDS_MSGNODIALOG=206;
  208.     static final int IDS_MSGFINDTEXT=207;
  209.     static final int IDS_MSGSEARCHDONE=208;
  210.     static final int IDS_MSGNOMATCH=211;
  211.     static final int IDS_MSGREPLACEDONE=210;
  212.     static final int IDS_MSGMENULOAD=213;
  213.     static final int IDS_MSGMENUINIT=212;
  214.     static final int IDS_MSGINTERNALERR=214;
  215.     static final int IDS_MSGINSTALLERR=215;
  216.     static final int IDS_MSGNORES=216;
  217.     static final int IDS_MSGINIACCELERR=217;
  218.     static final int IDS_MSGINIFONTERR=218;
  219.     static final int IDS_MSGNOFEATURE=219;
  220.     static final int IDS_MSGNOFEATUREINIT=220;
  221.     static final int IDS_MSGINITOOLBARERR=221;
  222.     static final int IDS_MSGINITIMGERR=221;
  223.     static final int IDS_MSGINICOLORERR=222;
  224.     static final int IDS_MSGLAUNCH=223;
  225.     static final int IDS_MSGLAUNCHANNOC=224;
  226.     static final int IDS_MSGLAUNCHERR=225;
  227.     static final int IDS_MSGNOTRUNNABLE=226;
  228.     static final int IDS_MSGFILERUNERR=227;
  229.     static final int IDS_MSGRUNERROR=228;
  230.     static final int IDS_MSGNOSETTINGS=229;
  231.     static final int IDS_MSGSETTINGSERR=230;
  232.     static final int IDS_MSGSETTINGSSAVEERR=231;
  233.     static final int IDS_MSGSAVEFILE=232;
  234.     static final int IDS_MSGSAVECONFIRM=233;    
  235.     static final int IDS_MSGREPLACETEXT=236;
  236.     static final int IDS_MSGLOADFILE=237;
  237.     static final int IDS_MSGOKCANCEL=240;
  238.     static final int IDS_MSGLINKTO=241;
  239. }
  240. class WhereAmI{
  241.     public WhereAmI(){}
  242. }