Advertisement
Guest User

Untitled

a guest
May 29th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 31.37 KB | None | 0 0
  1. /* Mark's Super Awesome Text Editor
  2. This is an Open Source Project Aimed at making
  3. a simple fully functional platform independant
  4. plain text editor
  5. -Mark Truitt 06/01/2010
  6.  */
  7.  
  8. //import statements
  9. import java.awt.*;
  10. import java.util.*;
  11. import java.awt.event.*;
  12. import javax.swing.*;
  13. import javax.swing.event.*;
  14. import javax.swing.undo.*;
  15. import javax.swing.text.*;
  16. import javax.swing.border.*;
  17. import java.io.*;
  18.  
  19. public class JavaText extends JFrame
  20. {
  21.         //Class Variable Declarations
  22.        
  23.         //Getting the Newline character from the system
  24.         public static String newline = System.getProperty("line.separator");
  25.         //Menus and Menubar declarations
  26.         JMenuBar menubar;
  27.         JMenu menu;
  28.         JMenu filemi;
  29.         JMenu langsmi;
  30.         JMenu optionmi;
  31.         JMenu editmi;
  32.         JPopupMenu rcEditMi;
  33.         //Menu Item Declarations
  34.         JMenuItem item;
  35.         JMenuItem savemi;
  36.         JMenuItem saveasmi;
  37.         JMenuItem newmi;
  38.         JMenuItem openmi;
  39.         JMenuItem exitmi;
  40.         JMenuItem undomi;
  41.         JMenuItem redomi;
  42.         JMenuItem cutmi;
  43.         JMenuItem copymi;
  44.         JMenuItem pastemi;
  45.         JMenuItem deletemi;
  46.         JMenuItem selectallmi;
  47.         JMenuItem foregmi;
  48.         JMenuItem backgmi;
  49.         JMenuItem aboutmi;
  50.         //Context Menu Item Declarations
  51.         JMenuItem rccutmi;
  52.         JMenuItem rccopymi;
  53.         JMenuItem rcpastemi;
  54.         JMenuItem rcselectallmi;
  55.            
  56.         JScrollPane scrollbar;
  57.         JTextArea textbox;
  58.         JFileChooser chooser;
  59.         FileReader inputfile;
  60.         BufferedReader filebuffer;
  61.         FileWriter output;
  62.             PrintWriter writer;
  63.             String txtfile = "newfile.txt";
  64.        
  65.         //Base Variables for Various Names and Strings
  66.        
  67.         //The MenuBar Elements
  68.         String sMenu;
  69.         String sLangs;
  70.         String sOptions;
  71.         String sEdit;
  72.         //The File Menu Elements
  73.         String sOpen;
  74.         String sNew;
  75.         String sSave;
  76.         String sSaveAs;
  77.         String sExit;
  78.         //The Edit Menu Elements
  79.         String sUndo;
  80.         String sRedo;
  81.         String sCut;
  82.         String sCopy;
  83.         String sPaste;
  84.         String sDelete;
  85.         String sSelectAll;
  86.         //The Options Menu Elements
  87.         String sForeG;
  88.         String sForeMsg;
  89.         String sBackG;
  90.         String sBackMsg;
  91.         String sAbout;
  92.         //Window Elements
  93.         String sGreet;
  94.         String sTitle;
  95.                
  96.         //Language Options Declarations
  97.        
  98.         public void en_Menus(){
  99.             //English variables
  100.             //The MenuBar Elements
  101.             sMenu = "File";
  102.             sLangs = "Languages";
  103.             sOptions = "Options";
  104.             sEdit = "Edit";
  105.             //The File Menu Elements
  106.             sOpen = "Open";
  107.             sSave = "Save";
  108.             sSaveAs = "Save As";
  109.             sNew = "New";
  110.             sExit = "Exit";
  111.             //The Edit Menu Elements
  112.             sUndo = "Undo";
  113.             sRedo = "Redo";
  114.             sCut = "Cut";
  115.             sCopy = "Copy";
  116.             sPaste = "Paste";
  117.             sDelete = "Delete";
  118.             sSelectAll = "Select All";
  119.             //The Options Menu Elements
  120.             sForeG = "Change Foreground";
  121.             sForeMsg = "Choose Foreground Color";
  122.             sBackG = "Change Background";
  123.             sBackMsg = "Choose Background Color";
  124.             sAbout = "About";
  125.             //Window Elements
  126.             sGreet = "Welcome";
  127.             sTitle = "Mark's Super Awesome Text Editor";
  128.         }
  129.        
  130.         public void jp_Menus(){
  131.             //Japanese aka 日本 variables
  132.             //The MenuBar Elements
  133.             sMenu = "\u30D5\u30A1\u30A4\u30EB";
  134.             sLangs = "\u8A00\u8A9E"; //言語
  135.             sOptions = "\u30AA\u30D7\u30B7\u30E7\u30F3"; //オプション
  136.             sEdit = "\u7DE8\u96C6"; //編集
  137.             //The File Menu Elements
  138.             sOpen = "\u30AA\u30FC\u30D7\u30F3";
  139.             sSave = " \u30BB\u30FC\u30D6";
  140.             sSaveAs = "\u5225\u540D\u3067\u4FDD\u5B58"; //別名で保存
  141.             sNew = "\u65B0\u3057\u3044"; //新しい
  142.             sExit = "\u51FA\u53E3"; //出口
  143.             //The Edit Menu Elements
  144.             sUndo = "Undo"; //元に戻す
  145.             sRedo = "Redo"; //やり直し
  146.             sCut = "\u30AB\u30C3\u30C8"; //カット
  147.             sCopy = "\u30B3\u30D4\u30FC"; //コピー
  148.             sPaste = "\u30D4\u30FC\u30B9\u30C8"; //ペースト
  149.             sDelete = "Delete"; //削除
  150.             sSelectAll = "\u3059\u3079\u3066\u9078\u629E"; //すべて選択
  151.             //The Options Menu Elements
  152.             sForeG = "\u5909\u66F4\u30D5\u30A9\u30A2\u30B0\u30E9\u30A6\u30F3\u30C9"; //変更フォアグラウンド
  153.             sForeMsg = "\u3092\u9078\u629E\u3057\u3066\u30D5\u30A9\u30A2\u30B0\u30E9\u30A6\u30F3\u30C9\u30AB\u30E9\u30FC";//を選択してフォアグラウンドカラー
  154.             sBackG = "\u80CC\u666F\u3092\u5909\u66F4"; //背景を変更
  155.             sBackMsg = "\u3092\u9078\u629E\u3057\u3066\u80CC\u666F\u8272";//を選択して背景色
  156.             sAbout = "About";
  157.             //Window Elements
  158.             sGreet = "\u3053\u3093\u306B\u3061\u306F";
  159.             sTitle = "\u30DE\u30EB\u30AF\u306E\u3081\u3063\u3061\u3083\u3059\u3054\u3044\u30C6\u30AD\u30B9\u30C8\u30A8\u30C7\u30A3\u30BF";
  160.         }
  161.        
  162.         public void fn_Menus(){
  163.             //Finnish aka Suomi
  164.             //The MenuBar Elements
  165.             sMenu = "Tiedosto";
  166.             sLangs = "Kielet";
  167.             sOptions = "Vaihtoehdot";
  168.             sEdit = "Muokata";
  169.             //The File Menu Elements
  170.             sOpen = "Avoinna";
  171.             sSave = "S\u00E4\u00E4st\u00E4\u00E4";
  172.             sSaveAs = "Tallenna nimell\u00E4";
  173.             sNew = "Uusi";
  174.             sExit = "Poistua";
  175.             //The Edit Menu Elements
  176.             sUndo = "Avata";
  177.             sRedo = "Tehd\u00E4 uudelleen";
  178.             sCut = "Leikkaus";
  179.             sCopy = "Kopio";
  180.             sPaste = "Tahna";
  181.             sDelete = "Poistaa";
  182.             sSelectAll = "Valitse kaikki";
  183.             //The Options Menu Elements
  184.             sForeG = "Muuta Tulosaineisto";
  185.             sForeMsg = "Valitse Edustav\u00E4ri";
  186.             sBackG = "Muuta taustaa";
  187.             sBackMsg = "Valitse Taustav\u00E4ri";
  188.             sAbout = "About";
  189.             //Window Elements
  190.             sGreet = "Tervetuloa";
  191.             sTitle = "Mark's Loistava Mahtava Kirjoitus Julkaisija";
  192.         }
  193.        
  194.         public void no_Menus(){
  195.             //Norwegian aka Norskepublic void en_Menus(){
  196.             sMenu = "Arkiv";
  197.             sLangs = "Spr\u00E5k";
  198.             sOptions = "Valg";
  199.             sEdit = "Rediger";
  200.             //The File Menu Elements
  201.             sOpen = "\u00C5pent";
  202.             sSave = "Lagre";
  203.             sSaveAs = "Lagre som";
  204.             sNew = "Ny";
  205.             sExit = "Avslutt";
  206.             //The Edit Menu Elements
  207.             sUndo = "Angre";
  208.             sRedo = "Gj\u00F8r om";
  209.             sCut = "Kutt";
  210.             sCopy = "Kopier";
  211.             sPaste = "Lim";
  212.             sDelete = "Slett";
  213.             sSelectAll = "Velg alle";
  214.             //The Options Menu Elements
  215.             sForeG = "Endre Forgrunn";
  216.             sForeMsg = "Velg Forgrunnsfarge";
  217.             sBackG = "Endre Bakgrunn";
  218.             sBackMsg = "Velg Bakgrunnsfarge";
  219.             sAbout = "About";
  220.             //Window Elements
  221.             sGreet = "Velkommen";
  222.             sTitle = "Mark's Super Awesome Tekst Editor";
  223.         }
  224.        
  225.         public void fp_Menus(){
  226.             //Filipino
  227.             sMenu = "File";
  228.             sLangs = "Wika";
  229.             sOptions = "Opsyon";
  230.             sEdit = "I-edit ang";
  231.             //The File Menu Elements
  232.             sOpen = "Bukas";
  233.             sSave = "Iligtas";
  234.             sSaveAs = "Iligtas Bilang";
  235.             sNew = "Bago";
  236.             sExit = "Labasan";
  237.             //The Edit Menu Elements
  238.             sUndo = "Magpawalang-bisa";
  239.             sRedo = "Gumawang muli";
  240.             sCut = "Hiwa";
  241.             sCopy = "Kopya";
  242.             sPaste = "Magdikit";
  243.             sDelete = "Alisin";
  244.             sSelectAll = "Piliin ang Lahat";
  245.             //The Options Menu Elements
  246.             sForeG = "Baguhin ang harapan";
  247.             sForeMsg = "Pumili ng Kulay ng harapan";
  248.             sBackG = "Baguhin ang likuran";
  249.             sBackMsg = "Pumili ng Kulay ng likuran";
  250.             sAbout = "About";
  251.             //Window Elements
  252.             sGreet = "Maligayang pagdating";
  253.             sTitle = "Mark's Magara Kasindak-sindak Teksto Editor";
  254.         }
  255.        
  256.         public void ko_Menus(){
  257.             //Korean aka 한국의
  258.             sMenu = "\uD30C\uC77C";
  259.             sLangs = "\uC5B8\uC5B4"; //언어
  260.             sOptions = "\uC635\uC158";//옵션
  261.             sEdit = "\uD3B8\uC9D1"; //편집
  262.             //The File Menu Elements
  263.             sOpen = "\uC5F4\uB9B0"; //열린
  264.             sSave = "\uC800\uC7A5";//저장
  265.             sSaveAs = "\uB2E4\uB978\uC774\uB984\uC73C\uB85C\uC800\uC7A5"; //다른이름으로 저장
  266.             sNew = "\uC0C8\uB85C\uC6B4"; //새로운
  267.             sExit = "\uCD9C\uAD6C"; //출구
  268.             //The Edit Menu Elements
  269.             sUndo = "Undo"; //취소
  270.             sRedo = "Redo"; //다시하다
  271.             sCut = "\uC808\uB2E8"; //절단
  272.             sCopy = "\uBCF5\uC0AC"; //복사
  273.             sPaste = "\uBD99\uC5EC\uB123\uAE30"; //붙여넣기
  274.             sDelete = "Delete"; //삭제
  275.             sSelectAll = "\uBAA8\uB450 \uC120\uD0DD"; //모두 선택
  276.             //The Options Menu Elements
  277.             sForeG = "\uAE00\uC790\uC0C9\uBCC0\uACBD"; //글자색 변경
  278.             sForeMsg = "\uC120\uD0DD\uC804\uACBD\uC0C9"; //선택 전경색
  279.             sBackG = "\uBCC0\uACBD \uBC30\uACBD"; //변경 배경
  280.             sBackMsg = "\uBC30\uACBD \uC0C9\uC0C1 \uC120\uD0DD"; //배경 색상 선택
  281.             sAbout = "About";
  282.             //Window Elements
  283.             sGreet = "\uD658\uC601";//환영
  284.             sTitle = "\uB9C8\uD06C\uC288\uD37C\uC2E0\uB09C\uB2E4\uD14D\uC2A4\uD2B8\uD3B8\uC9D1\uAE30";//마크 슈퍼 신 난다 텍스트 편집기
  285.         }
  286.        
  287.         public void ic_Menus(){
  288.             //Icelandic aka Íslenska
  289.             sMenu = "Skr\u00E1";
  290.             sLangs = "Tungum\u00E1l";
  291.             sOptions = "Options";
  292.             sEdit = "Breyta";
  293.             //The File Menu Elements
  294.             sOpen = "Opinn";
  295.             sSave = "Vista";
  296.             sSaveAs = "Vista eins";
  297.             sNew = "N\u00FD skr\u00E1";
  298.             sExit = "H\u00E6tta";
  299.             //The Edit Menu Elements
  300.             sUndo = "H\u00E6tta vi\u00F0";
  301.             sRedo = "Rautt";
  302.             sCut = "Cut";
  303.             sCopy = "Afrita";
  304.             sPaste = "Líma";
  305.             sDelete = "Ey\u00F0a";
  306.             sSelectAll = "Velja allt";
  307.             //The Options Menu Elements
  308.             sForeG = "Breyta Forgrunnur";
  309.             sForeMsg = "Veldu Forgrunnslitur";
  310.             sBackG = "Breyta Bakgrunnur";
  311.             sBackMsg = "Veldu Bakgrunnslit";
  312.             sAbout = "About";
  313.             //Window Elements
  314.             sGreet = "Velkomin";
  315.             sTitle = "Mark's Fr\u00E1b\u00E6r \u00D3gnvekjandi Texti Ritstj\u00F3ri";
  316.         }
  317.        
  318.         public void dn_Menus(){
  319.             //Danish aka Danske
  320.             //The MenuBar Elements
  321.             sMenu = "Fil";
  322.             sLangs = "Sprog";
  323.             sOptions = "Valg";
  324.             sEdit = "Rediger";
  325.             //The File Menu Elements
  326.             sOpen = "\u00C5bent";
  327.             sSave = "Gem";
  328.             sSaveAs = "Gem som";
  329.             sNew = "Nye";
  330.             sExit = "Udgang";
  331.             //The Edit Menu Elements
  332.             sUndo = "Fortryd";
  333.             sRedo = "Redo";
  334.             sCut = "Klip";
  335.             sCopy = "Kopier";
  336.             sPaste = "Inds\u00E6t";// \u00E6 = æ
  337.             sDelete = "Slet";
  338.             sSelectAll = "V\u00E6lg alle";
  339.             //The Options Menu Elements
  340.             sForeG = "Skift Forgrund";
  341.             sForeMsg = "V\u00E6lg Forgrundsfarve";
  342.             sBackG = "Skift Baggrund";
  343.             sBackMsg = "V\u00E6lg Baggrundsfarve";
  344.             sAbout = "Om";
  345.             //Window Elements
  346.             sGreet = "Velkommen";
  347.             sTitle = "Mark's Super Awesome Tekst Editor";
  348.         }
  349.        
  350.         public void sw_Menus(){
  351.             //Swedish aka Svensk
  352.             //The MenuBar Elements
  353.             sMenu = "Arkiv";
  354.             sLangs = "Spr\u00E5k";
  355.             sOptions = "Alternativ";
  356.             sEdit = "Redigera";
  357.             //The File Menu Elements
  358.             sOpen = "\u00D6ppet";
  359.             sSave = "Spara";
  360.             sSaveAs = "Spara som";
  361.             sNew = "Nya";
  362.             sExit = "Utg\u00E5ng";
  363.             //The Edit Menu Elements
  364.             sUndo = "\u00C5ngra";
  365.             sRedo = "G\u00F6r om";
  366.             sCut = "Klipp";
  367.             sCopy = "Kopiera";
  368.             sPaste = "Klistra in";
  369.             sDelete = "Ta bort";
  370.             sSelectAll = "Markera alla";
  371.             //The Options Menu Elements
  372.             sForeG = "\u00C4ndra F\u00F6rgrund";
  373.             sForeMsg = "V\u00E4lj F\u00F6rgrundsf\u00E4rg";
  374.             sBackG = "\u00C4ndra bakgrund";
  375.             sBackMsg = "V\u00E4lj bakgrundsf\u00E4rg";
  376.             sAbout = "Om";
  377.             //Window Elements
  378.             sGreet = "V\u00E4lkommen";
  379.             sTitle = "Mark Super Awesome Textredigerare";
  380.         }
  381.        
  382.         public void lol_Menus(){
  383.             //LolSpeak
  384.             sMenu = "MAH FILEZ";
  385.             sLangs = "LANGUAGEZ";
  386.             sOptions = "OPSHUNS";
  387.             sEdit = "EDITZ";
  388.             //The File Menu Elements
  389.             sOpen = "OPEN MAH FILE";
  390.             sSave = "SAVE MAH FILE";
  391.             sSaveAs = "SAVE MAH FILE AS";
  392.             sNew = "MAKES NEW FILE";
  393.             sExit = "EXIT APPLICASHUN";
  394.             //The Edit Menu Elements
  395.             sUndo = "UNDO DAT";
  396.             sRedo = "REDO DAT";
  397.             sCut = "CUT DAT";
  398.             sCopy = "COPY DAT";
  399.             sPaste = "PASTE DAT";
  400.             sDelete = "BALETE DAT";
  401.             sSelectAll = "SELECT EVRYTHIN";
  402.             //The Options Menu Elements
  403.             sForeG = "CHANGE FOREGROUND";
  404.             sForeMsg = "CHOOSE FOREGROUND COLOR";
  405.             sBackG = "CHANGE BACKGROUND";
  406.             sBackMsg = "CHOOSE BACKGROUND COLOR";
  407.             sAbout = "BOUT";
  408.             //Window Elements
  409.             sGreet = "OHAI, WELCOM 2 MAH TEXT EDITOR";
  410.             sTitle = "MARKZ SUPR AWSUM TEXT EDITOR";
  411.         }
  412.        
  413.         public void lt_Menus(){
  414.             //L337 or Leet
  415.             sMenu = "pH1L3";
  416.             sLangs = "L4|\\|9U493$";
  417.             sOptions = "0P710|\\|$";
  418.             sEdit = "3D17";
  419.             //The File Menu Elements
  420.             sOpen = "0P3|\\|";
  421.             sSave = "54\\/3";
  422.             sSaveAs = "54\\/3 4$";
  423.             sNew = "|\\|3\\/\\/";
  424.             sExit = "3><17";
  425.             //The Edit Menu Elements
  426.             sUndo = "U|\\|D0";
  427.             sRedo = "R3D0";
  428.             sCut = "(U7";
  429.             sCopy = "(0P'/";
  430.             sPaste = "P4$73";
  431.             sDelete = "D3L373";
  432.             sSelectAll = "53L3(7 4LL";
  433.             //The Options Menu Elements
  434.             sForeG = "(|-|4|\\|93 pH0r39r0U|\\|D";
  435.             sForeMsg = "(|-|00$3 pH0r39r0U|\\|D (0L0r";
  436.             sBackG = "(|-|4|\\|93 b4(|<9r0U|\\|D";
  437.             sBackMsg = "(|-|00$3 b4(|<9r0U|\\|D (0L0r";
  438.             sAbout = "4B0U7";
  439.             //Window Elements
  440.             sGreet = "\\/\\/3L(0/\\/\\3";
  441.             sTitle = "/\\/\\4r|<'$ 5UP3r 4\\/\\/3$0/\\/\\3 73><7 3D170r";
  442.         }
  443.        
  444.         private void contextMenu()
  445.         {
  446.             //Creates the Edit Menu
  447.             rcEditMi = new JPopupMenu();
  448.        
  449.             //Creates and adds the Cut button to the Edit Menu
  450.             rccutmi = new JMenuItem(sCut);
  451.             rccutmi.addActionListener(new ActionListener() {
  452.             public void actionPerformed(ActionEvent e) {
  453.                     textbox.cut();
  454.                     //selectAllText(textbox.getText().getlength());
  455.                 }
  456.             });
  457.             rcEditMi.add(rccutmi);
  458.            
  459.             //Creates and adds the Copy button to the Edit Menu
  460.             rccopymi = new JMenuItem(sCopy);
  461.             rccopymi.addActionListener(new ActionListener() {
  462.             public void actionPerformed(ActionEvent e) {
  463.                     textbox.copy();
  464.                     //selectAllText(textbox.getText().getlength());
  465.                 }
  466.             });
  467.             rcEditMi.add(rccopymi);
  468.            
  469.             //Creates and adds the Paste button to the Edit Menu
  470.             rcpastemi = new JMenuItem(sPaste);
  471.             rcpastemi.addActionListener(new ActionListener() {
  472.             public void actionPerformed(ActionEvent e) {
  473.                     textbox.paste();
  474.                     //selectAllText(textbox.getText().getlength());
  475.                 }
  476.             });
  477.             rcEditMi.add(rcpastemi);
  478.            
  479.             //Adds a Seperator to the Edit Menu
  480.             rcEditMi.addSeparator();
  481.            
  482.             //Creates and adds the Select All button to the Edit Menu
  483.             rcselectallmi = new JMenuItem(sSelectAll);
  484.             rcselectallmi.addActionListener(new ActionListener() {
  485.             public void actionPerformed(ActionEvent e) {
  486.                     textbox.selectAll();
  487.                     //selectAllText(textbox.getText().getlength());
  488.                 }
  489.             });
  490.             rcEditMi.add(rcselectallmi);
  491.        
  492.         }
  493.        
  494.         private void textArea()
  495.         {
  496.             //Sets up the text and scroll Area
  497.             textbox = new JTextArea();
  498.             textbox.setText(sGreet);
  499.             textbox.setLineWrap(true);
  500.             textbox.setCaretPosition(0);
  501.             textbox.setWrapStyleWord(true);
  502.             scrollbar = new JScrollPane(textbox);
  503.             textbox.setComponentPopupMenu(rcEditMi);
  504.         }
  505.        
  506.     //The Constructor for the Text Editor  
  507.     public JavaText()
  508.     {
  509.         //Setting The Initial Menu Language via User Prompt,
  510.        
  511.         //Creates an Object Array of Strings for Use in the User Prompt
  512.         Object[] langs = {new String("English"),new String("\u65e5\u672C"),new String("Suomi"),new String("Norske"),new String("Filipino"),new String("\uD55C\uAD6D\uC758"),new String("\u00CDslenska"),new String("Danske"),new String("svensk"),new String("Lolspeak"),new String("l337")};
  513.        
  514.         //The actual prompt itself
  515.         Object msg = JOptionPane.showInputDialog(null,"Please Select A Language Option","Choose Option", JOptionPane.QUESTION_MESSAGE,null,langs,null);
  516.         //Gets the frist character of the selected option and puts it into a char variable
  517.         char ch = (String.valueOf(msg)).charAt(0);
  518.        
  519.         //A switch statement that calls the apropriate function for what the user has chosen
  520.         switch(ch){
  521.         case '\u65e5': jp_Menus();
  522.             break;
  523.         case 'S': fn_Menus();
  524.             break;
  525.         case 'N': no_Menus();
  526.             break;
  527.         case 'F': fp_Menus();
  528.             break;
  529.         case '\uD55C': ko_Menus();
  530.             break;
  531.         case '\u00CD': ic_Menus();
  532.             break;
  533.         case 'D': dn_Menus();
  534.             break;
  535.         case 's': sw_Menus();
  536.             break;
  537.         case 'L': lol_Menus();
  538.             break;
  539.         case 'l': lt_Menus();
  540.             break;
  541.         default: en_Menus();
  542.             break;
  543.         }
  544.        
  545.         //Setting up the Menu Bar      
  546.         menubar = new JMenuBar();
  547.        
  548.         //File Menu
  549.         filemi = new JMenu(sMenu);
  550.         //filemi.addMnemonic('F');
  551.        
  552.         //Creates and adds the New Button to the File Menu
  553.         newmi = new JMenuItem(sNew);
  554.         newmi.addActionListener(new ActionListener() {
  555.             public void actionPerformed(ActionEvent e) {
  556.                 newFile();//Calls the newFile Function
  557.             }
  558.         });
  559.         //newmi.addMnemonic('N');
  560.         filemi.add(newmi);
  561.        
  562.         //Creates and adds the Open Button to the File Menu            
  563.         openmi = new JMenuItem(sOpen);
  564.         openmi.addActionListener(new ActionListener() {
  565.             public void actionPerformed(ActionEvent e) {
  566.                 openFile();//Calls the openFile Function
  567.             }
  568.         });
  569.         //openmi.addMnemonic('N');
  570.         filemi.add(openmi);
  571.        
  572.         //Adds a Seperator to the File Menu
  573.         filemi.addSeparator();
  574.        
  575.         //Creates and adds the Save Button to the File Menu
  576.         savemi = new JMenuItem(sSave);
  577.         savemi.addActionListener(new ActionListener() {
  578.             public void actionPerformed(ActionEvent e) {
  579.                 saveFile();
  580.             }
  581.         });
  582.         //savemi.addMnemonic('S');
  583.         filemi.add(savemi);
  584.        
  585.         //Creates and adds the Save As Button to the File Menu
  586.         saveasmi = new JMenuItem(sSaveAs);
  587.         saveasmi.addActionListener(new ActionListener() {
  588.             public void actionPerformed(ActionEvent e) {
  589.                 saveFileAs();
  590.             }
  591.         });
  592.         filemi.add(saveasmi);
  593.        
  594.         //Adds a Seperator to the File Menu
  595.         filemi.addSeparator();
  596.        
  597.         //Creates and adds the Exit Button to the File Menu
  598.         exitmi = new JMenuItem(sExit);
  599.         exitmi.addActionListener(new ActionListener() {
  600.             public void actionPerformed(ActionEvent e) {
  601.                 System.exit(0);
  602.             }
  603.         });
  604.         filemi.add(exitmi);
  605.        
  606.         //adds the file menu to the menu bar
  607.         menubar.add(filemi);
  608.        
  609.         //Creates the Edit Menu
  610.         editmi = new JMenu(sEdit);
  611.        
  612.         //Creates and adds the Undo button to the Edit Menu
  613.         undomi = new JMenuItem(sUndo);
  614.         //editmi.add(undomi);
  615.        
  616.         //Creates and adds the Redo button to the Edit Menu
  617.         redomi = new JMenuItem(sRedo);
  618.         //editmi.add(redomi);
  619.        
  620.         //Adds a Seperator to the Edit Menu
  621.         //editmi.addSeparator();
  622.        
  623.         //Creates and adds the Cut button to the Edit Menu
  624.         cutmi = new JMenuItem(sCut);
  625.         cutmi.addActionListener(new ActionListener() {
  626.             public void actionPerformed(ActionEvent e) {
  627.                 textbox.cut();
  628.                 //selectAllText(textbox.getText().getlength());
  629.             }
  630.         });
  631.         editmi.add(cutmi);
  632.        
  633.         //Creates and adds the Copy button to the Edit Menu
  634.         copymi = new JMenuItem(sCopy);
  635.         copymi.addActionListener(new ActionListener() {
  636.             public void actionPerformed(ActionEvent e) {
  637.                 textbox.copy();
  638.                 //selectAllText(textbox.getText().getlength());
  639.             }
  640.         });
  641.         editmi.add(copymi);
  642.        
  643.         //Creates and adds the Paste button to the Edit Menu
  644.         pastemi = new JMenuItem(sPaste);
  645.         pastemi.addActionListener(new ActionListener() {
  646.             public void actionPerformed(ActionEvent e) {
  647.                 textbox.paste();
  648.                 //selectAllText(textbox.getText().getlength());
  649.             }
  650.         });
  651.         editmi.add(pastemi);
  652.        
  653.         //Creates and adds the Delete button to the Edit Menu
  654.         deletemi = new JMenuItem(sDelete);
  655.         //editmi.add(deletemi);
  656.        
  657.         //Adds a Seperator to the Edit Menu
  658.         editmi.addSeparator();
  659.        
  660.         //Creates and adds the Select All button to the Edit Menu
  661.         selectallmi = new JMenuItem(sSelectAll);
  662.         selectallmi.addActionListener(new ActionListener() {
  663.             public void actionPerformed(ActionEvent e) {
  664.                 textbox.selectAll();
  665.                 //selectAllText(textbox.getText().getlength());
  666.             }
  667.         });
  668.         editmi.add(selectallmi);
  669.        
  670.         //Adds the edit menu to the Menubar
  671.         menubar.add(editmi);
  672.        
  673.         //Creates the Language Menu
  674.         langsmi = new JMenu(sLangs);
  675.        
  676.         //the English Button in the Language Menu
  677.         item = new JMenuItem("English");
  678.         item.addActionListener(new ActionListener() {
  679.             public void actionPerformed(ActionEvent e) {
  680.                 en_Menus();
  681.                 resetMenus();
  682.             }
  683.         });
  684.         langsmi.add(item);
  685.        
  686.         //the 日本 Button in the Language Menu
  687.         item = new JMenuItem("\u65e5\u672C");
  688.         item.addActionListener(new ActionListener() {
  689.             public void actionPerformed(ActionEvent e) {
  690.                 jp_Menus();
  691.                 resetMenus();
  692.             }
  693.         });
  694.         langsmi.add(item);
  695.        
  696.         //the Suomi Button in the Language Menu
  697.         item = new JMenuItem("Suomi");
  698.         item.addActionListener(new ActionListener() {
  699.             public void actionPerformed(ActionEvent e) {
  700.                 fn_Menus();
  701.                 resetMenus();
  702.             }
  703.         });
  704.         langsmi.add(item);
  705.        
  706.         //the Norske Button in the Language Menu
  707.         item = new JMenuItem("Norske");
  708.         item.addActionListener(new ActionListener() {
  709.             public void actionPerformed(ActionEvent e) {
  710.                 no_Menus();
  711.                 resetMenus();
  712.             }
  713.         });
  714.         langsmi.add(item);
  715.        
  716.         //the Filipino Button in the Language Menu
  717.         item = new JMenuItem("Filipino");
  718.         item.addActionListener(new ActionListener() {
  719.             public void actionPerformed(ActionEvent e) {
  720.                 fp_Menus();
  721.                 resetMenus();
  722.             }
  723.         });
  724.         langsmi.add(item);
  725.        
  726.         //the 한국의 Button in the Language Menu
  727.         item = new JMenuItem("\uD55C\uAD6D\uC758");
  728.         item.addActionListener(new ActionListener() {
  729.             public void actionPerformed(ActionEvent e) {
  730.                 ko_Menus();
  731.                 resetMenus();
  732.             }
  733.         });
  734.         langsmi.add(item);
  735.        
  736.         //the Íslenska Button in the Language Menu
  737.         item = new JMenuItem("\u00CDslenska");
  738.         item.addActionListener(new ActionListener() {
  739.             public void actionPerformed(ActionEvent e) {
  740.                 ic_Menus();
  741.                 resetMenus();
  742.             }
  743.         });
  744.         langsmi.add(item);
  745.        
  746.         //the Danske Button in the Language Menu
  747.         item = new JMenuItem("Danske");
  748.         item.addActionListener(new ActionListener() {
  749.             public void actionPerformed(ActionEvent e) {
  750.                 dn_Menus();
  751.                 resetMenus();
  752.             }
  753.         });
  754.         langsmi.add(item);
  755.        
  756.         //the Svensk Button in the Language Menu
  757.         item = new JMenuItem("Svensk");
  758.         item.addActionListener(new ActionListener() {
  759.             public void actionPerformed(ActionEvent e) {
  760.                 sw_Menus();
  761.                 resetMenus();
  762.             }
  763.         });
  764.         langsmi.add(item);
  765.        
  766.         //the Lolspeak Button in the Language Menu
  767.         item = new JMenuItem("Lolspeak");
  768.         item.addActionListener(new ActionListener() {
  769.             public void actionPerformed(ActionEvent e) {
  770.                 lol_Menus();
  771.                 resetMenus();
  772.             }
  773.         });
  774.         langsmi.add(item);
  775.        
  776.         //the L337 Button in the Language Menu
  777.         item = new JMenuItem("L337");
  778.         item.addActionListener(new ActionListener() {
  779.             public void actionPerformed(ActionEvent e) {
  780.                 lt_Menus();
  781.                 resetMenus();
  782.             }
  783.         });
  784.         langsmi.add(item);
  785.        
  786.         //adds the Language Menu to the menubar
  787.         menubar.add(langsmi);
  788.        
  789.         //Creates the Options Menu
  790.         optionmi = new JMenu(sOptions);
  791.        
  792.         //Creates and adds the Change Foreground Button to the Options Menu
  793.         foregmi = new JMenuItem(sForeG);
  794.         foregmi.addActionListener(new ActionListener() {
  795.             public void actionPerformed(ActionEvent e) {
  796.                 colorTools(e);
  797.             }
  798.         });
  799.         optionmi.add(foregmi);
  800.        
  801.         //Creates and adds the Change Background Button to the Options Menu
  802.         backgmi = new JMenuItem(sBackG);
  803.         backgmi.addActionListener(new ActionListener() {
  804.             public void actionPerformed(ActionEvent e) {
  805.                 colorTools(e);
  806.             }
  807.         });
  808.         optionmi.add(backgmi);
  809.        
  810.         //Adds a Separator to the Options Menu
  811.         //optionmi.addSeparator();
  812.        
  813.         //Creates and adds the About Button to the Options Menu
  814.         aboutmi  = new JMenuItem(sAbout);
  815.         backgmi.addActionListener(new ActionListener() {
  816.             public void actionPerformed(ActionEvent e) {
  817.                 aboutPopup();
  818.             }
  819.         });
  820.         //optionmi.add(aboutmi);
  821.        
  822.         /*Debug Tool
  823.         item = new JMenuItem("Debug");
  824.         item.addActionListener(new ActionListener() {
  825.             public void actionPerformed(ActionEvent e) {
  826.                 debugTools();
  827.             }
  828.         });
  829.         optionmi.add(item); */
  830.        
  831.         JPanel statusbar = new JPanel(new GridLayout(1, 1));
  832.         CaretListenerLabel caretListenerLabel = new CaretListenerLabel(" [Ln 1,Col 0]"+ newline);
  833.         statusbar.add(caretListenerLabel);
  834.        
  835.        
  836.        
  837.         //Adds The Options menu to the menubar
  838.         menubar.add(optionmi);
  839.        
  840.         contextMenu();
  841.         textArea();
  842.         textbox.addCaretListener(caretListenerLabel);
  843.        
  844.         //Sets up the Window
  845.         getContentPane().add(scrollbar, BorderLayout.CENTER);
  846.         getContentPane().add(statusbar, BorderLayout.PAGE_END);
  847.         //setContentPane(scrollbar);
  848.         setJMenuBar(menubar);
  849.         setLocationRelativeTo(null);
  850.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  851.         setTitle(sTitle);
  852.         setSize(500, 500);
  853.         setVisible(true);
  854.     }
  855.    
  856.     public int getLineAtCaret(JTextArea textArea)
  857.     {
  858.         int caretPosition = textArea.getCaretPosition();
  859.         Element root = textArea.getDocument().getDefaultRootElement();
  860.         return root.getElementIndex(caretPosition) + 1;
  861.     }
  862.    
  863.      public int getColumnAtCaret(JTextArea textArea)
  864.         {
  865.                 int caretPosition = textArea.getCaretPosition();
  866.                 Element root = textArea.getDocument().getDefaultRootElement();
  867.                 int lineNo = root.getElementIndex(caretPosition);
  868.                 Element line = root.getElement(lineNo);
  869.                 return caretPosition - line.getStartOffset();
  870.         }
  871.         public int countWords()
  872.     {
  873.         String bigString = textbox.getText();
  874.  
  875.         StringTokenizer t1 = new StringTokenizer(bigString," ");
  876.         int words = t1.countTokens();  
  877.        
  878.         return words;
  879.     }
  880.    
  881.     public int countSent()
  882.     {
  883.         String bigString = textbox.getText();
  884.  
  885.         StringTokenizer t1 = new StringTokenizer(bigString,".?!");
  886.         int sentences = t1.countTokens();
  887.        
  888.         return sentences - 1;
  889.     }
  890.     public class CaretListenerLabel extends JLabel implements CaretListener {
  891.         //Sets up the statusbar
  892.             public CaretListenerLabel(String label) { super(label); }
  893.             //this is the method that is called everytime the curser moves
  894.             public void caretUpdate(CaretEvent e) { ChangedCaret(e);}
  895.        
  896.         //updates the status bar
  897.         public void ChangedCaret(CaretEvent e) {
  898.             setText(" [Ln "+ getLineAtCaret(textbox) + " ,Col " + getColumnAtCaret(textbox) + "]"+ " Words: " + countWords() + " Sentences: " + countSent() + newline);
  899.             }
  900.         }
  901.  
  902.     //this function allows the program to take in commandline args
  903.     public void clOpen(String args)
  904.     {
  905.         if(args != null) {
  906.                     try{
  907.                         textbox.setText("");
  908.                         inputfile = new FileReader(args);
  909.                         txtfile = args;
  910.                         filebuffer = new BufferedReader(inputfile);
  911.                         String line = filebuffer.readLine();
  912.                         String reader = "";
  913.                         while((reader = filebuffer.readLine()) != null)
  914.                         {
  915.                             line += newline;
  916.                                         line += reader;
  917.                         }
  918.                        
  919.                         if (line != null)
  920.                                 {
  921.                                 textbox.setText(line);
  922.                                 }
  923.                     }
  924.                     catch(FileNotFoundException e){ txtfile = args; }
  925.                     catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
  926.                 }  
  927.     }
  928.  
  929.     private void openFile()
  930.     {
  931.         chooser = new JFileChooser(new File("."));
  932.             int returnVal = chooser.showOpenDialog(this);
  933.             if(returnVal == JFileChooser.APPROVE_OPTION)
  934.             {
  935.                 try{
  936.                     textbox.setText("");
  937.                     String text = chooser.getSelectedFile().getName();
  938.                     setTitle(text);
  939.                     inputfile = new FileReader(chooser.getSelectedFile());
  940.                     txtfile = chooser.getSelectedFile().getAbsolutePath();
  941.                     filebuffer = new BufferedReader(inputfile);
  942.                     String line = filebuffer.readLine();
  943.                     String reader = "";
  944.                     while((reader = filebuffer.readLine()) != null)
  945.                     {
  946.                         line += newline;
  947.                                 line += reader;
  948.                     }
  949.                        
  950.                     if (line != null)
  951.                             {
  952.                             textbox.setText(line);
  953.                             }
  954.                            
  955.                             inputfile.close();
  956.                             filebuffer.close();
  957.                            
  958.                 }
  959.                 catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
  960.                 catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
  961.                 /*finally
  962.                 {
  963.                     if(inputfile != null)
  964.                     inputfile.close();
  965.                     if(filebuffer !=null)
  966.                     filebuffer.close();
  967.                 } */
  968.             }
  969.     }
  970.    
  971.     private void saveFile()
  972.     {
  973.         try{
  974.             output = new FileWriter(txtfile);
  975.                 writer = new PrintWriter(output);
  976.                 writer.print(textbox.getText());
  977.                 writer.flush();
  978.                
  979.                 output.close();
  980.                 writer.close();
  981.                        
  982.             }
  983.             catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
  984.             catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
  985.             /*finally
  986.                 {
  987.                     if(output != null)
  988.                     output.close();
  989.                     if(writer !=null)
  990.                     writer.close();
  991.                 } */
  992.     }
  993.    
  994.     private void saveFileAs()
  995.     {
  996.         chooser = new JFileChooser(new File("."));
  997.             int returnVal = chooser.showSaveDialog(this);
  998.             if(returnVal == JFileChooser.APPROVE_OPTION)
  999.             {
  1000.                 try{
  1001.                 txtfile = chooser.getSelectedFile().getAbsolutePath();
  1002.                 output = new FileWriter(txtfile);
  1003.                     writer = new PrintWriter(output);
  1004.                     writer.print(textbox.getText());
  1005.                     writer.flush();
  1006.                    
  1007.                     output.close();
  1008.                     writer.close();
  1009.                 }
  1010.                 catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
  1011.             catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }  
  1012.             /*finally
  1013.                 {
  1014.                     if(output != null)
  1015.                     output.close();
  1016.                     if(writer !=null)
  1017.                     writer.close();
  1018.                 } */   
  1019.             }
  1020.            
  1021.     }
  1022.    
  1023.     private void newFile()
  1024.     {
  1025.         textbox.setText("");
  1026.         saveFileAs();
  1027.     }
  1028.    
  1029.     public void colorTools(ActionEvent event)
  1030.     {
  1031.         Color selectedColor;
  1032.        
  1033.         if(event.getActionCommand()== sForeG)
  1034.         {
  1035.             selectedColor = JColorChooser.showDialog(null,sForeMsg,textbox.getForeground());
  1036.             if(selectedColor != null)
  1037.             textbox.setForeground(selectedColor);
  1038.         }
  1039.        
  1040.         if(event.getActionCommand()== sBackG)
  1041.         {
  1042.             selectedColor = JColorChooser.showDialog(null,sBackMsg,textbox.getBackground());
  1043.             if(selectedColor != null)
  1044.             textbox.setBackground(selectedColor);
  1045.         }
  1046.     }
  1047.    
  1048.     public void resetMenus()
  1049.     {
  1050.             setTitle(sTitle);
  1051.             filemi.setText(sMenu);
  1052.             editmi.setText(sEdit);
  1053.             langsmi.setText(sLangs);
  1054.             optionmi.setText(sOptions);
  1055.             newmi.setText(sNew);
  1056.             openmi.setText(sOpen);
  1057.             savemi.setText(sSave);
  1058.             saveasmi.setText(sSaveAs);
  1059.             undomi.setText(sUndo);
  1060.             redomi.setText(sRedo);
  1061.             cutmi.setText(sCut);
  1062.             copymi.setText(sCopy);
  1063.             pastemi.setText(sPaste);
  1064.             deletemi.setText(sDelete);
  1065.             selectallmi.setText(sSelectAll);
  1066.             rccutmi.setText(sCut);
  1067.             rccopymi.setText(sCopy);
  1068.             rcpastemi.setText(sPaste);
  1069.             rcselectallmi.setText(sSelectAll);
  1070.             foregmi.setText(sForeG);
  1071.             backgmi.setText(sBackG);
  1072.             aboutmi.setText(sAbout);
  1073.             exitmi.setText(sExit);
  1074.        
  1075.     }
  1076.     public void aboutPopup()
  1077.     {
  1078.         //need something here, will put something here later ^.^
  1079.     }
  1080.     ///*a method to insert some debug options for when the program is running
  1081.     public void debugTools()
  1082.     {
  1083.         textbox.setText("\u65e5,S,N,F,\uD55C,\u00CD,L");
  1084.         txtfile = "debug.txt";
  1085.         saveFile();
  1086.         txtfile = "newfile.txt";
  1087.         textbox.setText(sGreet);
  1088.     }
  1089.     //*/
  1090.    
  1091.     /* Command Line Help function, to be called if the first arg is -h or --help
  1092.     public void helpCall()
  1093.     {
  1094.         System.out.println("The Correct Syntax is as Follows:");
  1095.         System.out.println("java -jar MultiLangEditor.jar <filename>");
  1096.     }
  1097.     */
  1098.    
  1099.     public static void main(String args[])
  1100.     {
  1101.         JavaText app = new JavaText();
  1102.         if(args.length > 0)
  1103.         {
  1104.              app.clOpen(args[0]);
  1105.         }
  1106.        
  1107.     }
  1108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement