Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Mark's Super Awesome Text Editor
- This is an Open Source Project Aimed at making
- a simple fully functional platform independant
- plain text editor
- -Mark Truitt 06/01/2010
- */
- //import statements
- import java.awt.*;
- import java.util.*;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.event.*;
- import javax.swing.undo.*;
- import javax.swing.text.*;
- import javax.swing.border.*;
- import java.io.*;
- public class JavaText extends JFrame
- {
- //Class Variable Declarations
- //Getting the Newline character from the system
- public static String newline = System.getProperty("line.separator");
- //Menus and Menubar declarations
- JMenuBar menubar;
- JMenu menu;
- JMenu filemi;
- JMenu langsmi;
- JMenu optionmi;
- JMenu editmi;
- JPopupMenu rcEditMi;
- //Menu Item Declarations
- JMenuItem item;
- JMenuItem savemi;
- JMenuItem saveasmi;
- JMenuItem newmi;
- JMenuItem openmi;
- JMenuItem exitmi;
- JMenuItem undomi;
- JMenuItem redomi;
- JMenuItem cutmi;
- JMenuItem copymi;
- JMenuItem pastemi;
- JMenuItem deletemi;
- JMenuItem selectallmi;
- JMenuItem foregmi;
- JMenuItem backgmi;
- JMenuItem aboutmi;
- //Context Menu Item Declarations
- JMenuItem rccutmi;
- JMenuItem rccopymi;
- JMenuItem rcpastemi;
- JMenuItem rcselectallmi;
- JScrollPane scrollbar;
- JTextArea textbox;
- JFileChooser chooser;
- FileReader inputfile;
- BufferedReader filebuffer;
- FileWriter output;
- PrintWriter writer;
- String txtfile = "newfile.txt";
- //Base Variables for Various Names and Strings
- //The MenuBar Elements
- String sMenu;
- String sLangs;
- String sOptions;
- String sEdit;
- //The File Menu Elements
- String sOpen;
- String sNew;
- String sSave;
- String sSaveAs;
- String sExit;
- //The Edit Menu Elements
- String sUndo;
- String sRedo;
- String sCut;
- String sCopy;
- String sPaste;
- String sDelete;
- String sSelectAll;
- //The Options Menu Elements
- String sForeG;
- String sForeMsg;
- String sBackG;
- String sBackMsg;
- String sAbout;
- //Window Elements
- String sGreet;
- String sTitle;
- //Language Options Declarations
- public void en_Menus(){
- //English variables
- //The MenuBar Elements
- sMenu = "File";
- sLangs = "Languages";
- sOptions = "Options";
- sEdit = "Edit";
- //The File Menu Elements
- sOpen = "Open";
- sSave = "Save";
- sSaveAs = "Save As";
- sNew = "New";
- sExit = "Exit";
- //The Edit Menu Elements
- sUndo = "Undo";
- sRedo = "Redo";
- sCut = "Cut";
- sCopy = "Copy";
- sPaste = "Paste";
- sDelete = "Delete";
- sSelectAll = "Select All";
- //The Options Menu Elements
- sForeG = "Change Foreground";
- sForeMsg = "Choose Foreground Color";
- sBackG = "Change Background";
- sBackMsg = "Choose Background Color";
- sAbout = "About";
- //Window Elements
- sGreet = "Welcome";
- sTitle = "Mark's Super Awesome Text Editor";
- }
- public void jp_Menus(){
- //Japanese aka 日本 variables
- //The MenuBar Elements
- sMenu = "\u30D5\u30A1\u30A4\u30EB";
- sLangs = "\u8A00\u8A9E"; //言語
- sOptions = "\u30AA\u30D7\u30B7\u30E7\u30F3"; //オプション
- sEdit = "\u7DE8\u96C6"; //編集
- //The File Menu Elements
- sOpen = "\u30AA\u30FC\u30D7\u30F3";
- sSave = " \u30BB\u30FC\u30D6";
- sSaveAs = "\u5225\u540D\u3067\u4FDD\u5B58"; //別名で保存
- sNew = "\u65B0\u3057\u3044"; //新しい
- sExit = "\u51FA\u53E3"; //出口
- //The Edit Menu Elements
- sUndo = "Undo"; //元に戻す
- sRedo = "Redo"; //やり直し
- sCut = "\u30AB\u30C3\u30C8"; //カット
- sCopy = "\u30B3\u30D4\u30FC"; //コピー
- sPaste = "\u30D4\u30FC\u30B9\u30C8"; //ペースト
- sDelete = "Delete"; //削除
- sSelectAll = "\u3059\u3079\u3066\u9078\u629E"; //すべて選択
- //The Options Menu Elements
- sForeG = "\u5909\u66F4\u30D5\u30A9\u30A2\u30B0\u30E9\u30A6\u30F3\u30C9"; //変更フォアグラウンド
- sForeMsg = "\u3092\u9078\u629E\u3057\u3066\u30D5\u30A9\u30A2\u30B0\u30E9\u30A6\u30F3\u30C9\u30AB\u30E9\u30FC";//を選択してフォアグラウンドカラー
- sBackG = "\u80CC\u666F\u3092\u5909\u66F4"; //背景を変更
- sBackMsg = "\u3092\u9078\u629E\u3057\u3066\u80CC\u666F\u8272";//を選択して背景色
- sAbout = "About";
- //Window Elements
- sGreet = "\u3053\u3093\u306B\u3061\u306F";
- sTitle = "\u30DE\u30EB\u30AF\u306E\u3081\u3063\u3061\u3083\u3059\u3054\u3044\u30C6\u30AD\u30B9\u30C8\u30A8\u30C7\u30A3\u30BF";
- }
- public void fn_Menus(){
- //Finnish aka Suomi
- //The MenuBar Elements
- sMenu = "Tiedosto";
- sLangs = "Kielet";
- sOptions = "Vaihtoehdot";
- sEdit = "Muokata";
- //The File Menu Elements
- sOpen = "Avoinna";
- sSave = "S\u00E4\u00E4st\u00E4\u00E4";
- sSaveAs = "Tallenna nimell\u00E4";
- sNew = "Uusi";
- sExit = "Poistua";
- //The Edit Menu Elements
- sUndo = "Avata";
- sRedo = "Tehd\u00E4 uudelleen";
- sCut = "Leikkaus";
- sCopy = "Kopio";
- sPaste = "Tahna";
- sDelete = "Poistaa";
- sSelectAll = "Valitse kaikki";
- //The Options Menu Elements
- sForeG = "Muuta Tulosaineisto";
- sForeMsg = "Valitse Edustav\u00E4ri";
- sBackG = "Muuta taustaa";
- sBackMsg = "Valitse Taustav\u00E4ri";
- sAbout = "About";
- //Window Elements
- sGreet = "Tervetuloa";
- sTitle = "Mark's Loistava Mahtava Kirjoitus Julkaisija";
- }
- public void no_Menus(){
- //Norwegian aka Norskepublic void en_Menus(){
- sMenu = "Arkiv";
- sLangs = "Spr\u00E5k";
- sOptions = "Valg";
- sEdit = "Rediger";
- //The File Menu Elements
- sOpen = "\u00C5pent";
- sSave = "Lagre";
- sSaveAs = "Lagre som";
- sNew = "Ny";
- sExit = "Avslutt";
- //The Edit Menu Elements
- sUndo = "Angre";
- sRedo = "Gj\u00F8r om";
- sCut = "Kutt";
- sCopy = "Kopier";
- sPaste = "Lim";
- sDelete = "Slett";
- sSelectAll = "Velg alle";
- //The Options Menu Elements
- sForeG = "Endre Forgrunn";
- sForeMsg = "Velg Forgrunnsfarge";
- sBackG = "Endre Bakgrunn";
- sBackMsg = "Velg Bakgrunnsfarge";
- sAbout = "About";
- //Window Elements
- sGreet = "Velkommen";
- sTitle = "Mark's Super Awesome Tekst Editor";
- }
- public void fp_Menus(){
- //Filipino
- sMenu = "File";
- sLangs = "Wika";
- sOptions = "Opsyon";
- sEdit = "I-edit ang";
- //The File Menu Elements
- sOpen = "Bukas";
- sSave = "Iligtas";
- sSaveAs = "Iligtas Bilang";
- sNew = "Bago";
- sExit = "Labasan";
- //The Edit Menu Elements
- sUndo = "Magpawalang-bisa";
- sRedo = "Gumawang muli";
- sCut = "Hiwa";
- sCopy = "Kopya";
- sPaste = "Magdikit";
- sDelete = "Alisin";
- sSelectAll = "Piliin ang Lahat";
- //The Options Menu Elements
- sForeG = "Baguhin ang harapan";
- sForeMsg = "Pumili ng Kulay ng harapan";
- sBackG = "Baguhin ang likuran";
- sBackMsg = "Pumili ng Kulay ng likuran";
- sAbout = "About";
- //Window Elements
- sGreet = "Maligayang pagdating";
- sTitle = "Mark's Magara Kasindak-sindak Teksto Editor";
- }
- public void ko_Menus(){
- //Korean aka 한국의
- sMenu = "\uD30C\uC77C";
- sLangs = "\uC5B8\uC5B4"; //언어
- sOptions = "\uC635\uC158";//옵션
- sEdit = "\uD3B8\uC9D1"; //편집
- //The File Menu Elements
- sOpen = "\uC5F4\uB9B0"; //열린
- sSave = "\uC800\uC7A5";//저장
- sSaveAs = "\uB2E4\uB978\uC774\uB984\uC73C\uB85C\uC800\uC7A5"; //다른이름으로 저장
- sNew = "\uC0C8\uB85C\uC6B4"; //새로운
- sExit = "\uCD9C\uAD6C"; //출구
- //The Edit Menu Elements
- sUndo = "Undo"; //취소
- sRedo = "Redo"; //다시하다
- sCut = "\uC808\uB2E8"; //절단
- sCopy = "\uBCF5\uC0AC"; //복사
- sPaste = "\uBD99\uC5EC\uB123\uAE30"; //붙여넣기
- sDelete = "Delete"; //삭제
- sSelectAll = "\uBAA8\uB450 \uC120\uD0DD"; //모두 선택
- //The Options Menu Elements
- sForeG = "\uAE00\uC790\uC0C9\uBCC0\uACBD"; //글자색 변경
- sForeMsg = "\uC120\uD0DD\uC804\uACBD\uC0C9"; //선택 전경색
- sBackG = "\uBCC0\uACBD \uBC30\uACBD"; //변경 배경
- sBackMsg = "\uBC30\uACBD \uC0C9\uC0C1 \uC120\uD0DD"; //배경 색상 선택
- sAbout = "About";
- //Window Elements
- sGreet = "\uD658\uC601";//환영
- sTitle = "\uB9C8\uD06C\uC288\uD37C\uC2E0\uB09C\uB2E4\uD14D\uC2A4\uD2B8\uD3B8\uC9D1\uAE30";//마크 슈퍼 신 난다 텍스트 편집기
- }
- public void ic_Menus(){
- //Icelandic aka Íslenska
- sMenu = "Skr\u00E1";
- sLangs = "Tungum\u00E1l";
- sOptions = "Options";
- sEdit = "Breyta";
- //The File Menu Elements
- sOpen = "Opinn";
- sSave = "Vista";
- sSaveAs = "Vista eins";
- sNew = "N\u00FD skr\u00E1";
- sExit = "H\u00E6tta";
- //The Edit Menu Elements
- sUndo = "H\u00E6tta vi\u00F0";
- sRedo = "Rautt";
- sCut = "Cut";
- sCopy = "Afrita";
- sPaste = "Líma";
- sDelete = "Ey\u00F0a";
- sSelectAll = "Velja allt";
- //The Options Menu Elements
- sForeG = "Breyta Forgrunnur";
- sForeMsg = "Veldu Forgrunnslitur";
- sBackG = "Breyta Bakgrunnur";
- sBackMsg = "Veldu Bakgrunnslit";
- sAbout = "About";
- //Window Elements
- sGreet = "Velkomin";
- sTitle = "Mark's Fr\u00E1b\u00E6r \u00D3gnvekjandi Texti Ritstj\u00F3ri";
- }
- public void dn_Menus(){
- //Danish aka Danske
- //The MenuBar Elements
- sMenu = "Fil";
- sLangs = "Sprog";
- sOptions = "Valg";
- sEdit = "Rediger";
- //The File Menu Elements
- sOpen = "\u00C5bent";
- sSave = "Gem";
- sSaveAs = "Gem som";
- sNew = "Nye";
- sExit = "Udgang";
- //The Edit Menu Elements
- sUndo = "Fortryd";
- sRedo = "Redo";
- sCut = "Klip";
- sCopy = "Kopier";
- sPaste = "Inds\u00E6t";// \u00E6 = æ
- sDelete = "Slet";
- sSelectAll = "V\u00E6lg alle";
- //The Options Menu Elements
- sForeG = "Skift Forgrund";
- sForeMsg = "V\u00E6lg Forgrundsfarve";
- sBackG = "Skift Baggrund";
- sBackMsg = "V\u00E6lg Baggrundsfarve";
- sAbout = "Om";
- //Window Elements
- sGreet = "Velkommen";
- sTitle = "Mark's Super Awesome Tekst Editor";
- }
- public void sw_Menus(){
- //Swedish aka Svensk
- //The MenuBar Elements
- sMenu = "Arkiv";
- sLangs = "Spr\u00E5k";
- sOptions = "Alternativ";
- sEdit = "Redigera";
- //The File Menu Elements
- sOpen = "\u00D6ppet";
- sSave = "Spara";
- sSaveAs = "Spara som";
- sNew = "Nya";
- sExit = "Utg\u00E5ng";
- //The Edit Menu Elements
- sUndo = "\u00C5ngra";
- sRedo = "G\u00F6r om";
- sCut = "Klipp";
- sCopy = "Kopiera";
- sPaste = "Klistra in";
- sDelete = "Ta bort";
- sSelectAll = "Markera alla";
- //The Options Menu Elements
- sForeG = "\u00C4ndra F\u00F6rgrund";
- sForeMsg = "V\u00E4lj F\u00F6rgrundsf\u00E4rg";
- sBackG = "\u00C4ndra bakgrund";
- sBackMsg = "V\u00E4lj bakgrundsf\u00E4rg";
- sAbout = "Om";
- //Window Elements
- sGreet = "V\u00E4lkommen";
- sTitle = "Mark Super Awesome Textredigerare";
- }
- public void lol_Menus(){
- //LolSpeak
- sMenu = "MAH FILEZ";
- sLangs = "LANGUAGEZ";
- sOptions = "OPSHUNS";
- sEdit = "EDITZ";
- //The File Menu Elements
- sOpen = "OPEN MAH FILE";
- sSave = "SAVE MAH FILE";
- sSaveAs = "SAVE MAH FILE AS";
- sNew = "MAKES NEW FILE";
- sExit = "EXIT APPLICASHUN";
- //The Edit Menu Elements
- sUndo = "UNDO DAT";
- sRedo = "REDO DAT";
- sCut = "CUT DAT";
- sCopy = "COPY DAT";
- sPaste = "PASTE DAT";
- sDelete = "BALETE DAT";
- sSelectAll = "SELECT EVRYTHIN";
- //The Options Menu Elements
- sForeG = "CHANGE FOREGROUND";
- sForeMsg = "CHOOSE FOREGROUND COLOR";
- sBackG = "CHANGE BACKGROUND";
- sBackMsg = "CHOOSE BACKGROUND COLOR";
- sAbout = "BOUT";
- //Window Elements
- sGreet = "OHAI, WELCOM 2 MAH TEXT EDITOR";
- sTitle = "MARKZ SUPR AWSUM TEXT EDITOR";
- }
- public void lt_Menus(){
- //L337 or Leet
- sMenu = "pH1L3";
- sLangs = "L4|\\|9U493$";
- sOptions = "0P710|\\|$";
- sEdit = "3D17";
- //The File Menu Elements
- sOpen = "0P3|\\|";
- sSave = "54\\/3";
- sSaveAs = "54\\/3 4$";
- sNew = "|\\|3\\/\\/";
- sExit = "3><17";
- //The Edit Menu Elements
- sUndo = "U|\\|D0";
- sRedo = "R3D0";
- sCut = "(U7";
- sCopy = "(0P'/";
- sPaste = "P4$73";
- sDelete = "D3L373";
- sSelectAll = "53L3(7 4LL";
- //The Options Menu Elements
- sForeG = "(|-|4|\\|93 pH0r39r0U|\\|D";
- sForeMsg = "(|-|00$3 pH0r39r0U|\\|D (0L0r";
- sBackG = "(|-|4|\\|93 b4(|<9r0U|\\|D";
- sBackMsg = "(|-|00$3 b4(|<9r0U|\\|D (0L0r";
- sAbout = "4B0U7";
- //Window Elements
- sGreet = "\\/\\/3L(0/\\/\\3";
- sTitle = "/\\/\\4r|<'$ 5UP3r 4\\/\\/3$0/\\/\\3 73><7 3D170r";
- }
- private void contextMenu()
- {
- //Creates the Edit Menu
- rcEditMi = new JPopupMenu();
- //Creates and adds the Cut button to the Edit Menu
- rccutmi = new JMenuItem(sCut);
- rccutmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.cut();
- //selectAllText(textbox.getText().getlength());
- }
- });
- rcEditMi.add(rccutmi);
- //Creates and adds the Copy button to the Edit Menu
- rccopymi = new JMenuItem(sCopy);
- rccopymi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.copy();
- //selectAllText(textbox.getText().getlength());
- }
- });
- rcEditMi.add(rccopymi);
- //Creates and adds the Paste button to the Edit Menu
- rcpastemi = new JMenuItem(sPaste);
- rcpastemi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.paste();
- //selectAllText(textbox.getText().getlength());
- }
- });
- rcEditMi.add(rcpastemi);
- //Adds a Seperator to the Edit Menu
- rcEditMi.addSeparator();
- //Creates and adds the Select All button to the Edit Menu
- rcselectallmi = new JMenuItem(sSelectAll);
- rcselectallmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.selectAll();
- //selectAllText(textbox.getText().getlength());
- }
- });
- rcEditMi.add(rcselectallmi);
- }
- private void textArea()
- {
- //Sets up the text and scroll Area
- textbox = new JTextArea();
- textbox.setText(sGreet);
- textbox.setLineWrap(true);
- textbox.setCaretPosition(0);
- textbox.setWrapStyleWord(true);
- scrollbar = new JScrollPane(textbox);
- textbox.setComponentPopupMenu(rcEditMi);
- }
- //The Constructor for the Text Editor
- public JavaText()
- {
- //Setting The Initial Menu Language via User Prompt,
- //Creates an Object Array of Strings for Use in the User Prompt
- 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")};
- //The actual prompt itself
- Object msg = JOptionPane.showInputDialog(null,"Please Select A Language Option","Choose Option", JOptionPane.QUESTION_MESSAGE,null,langs,null);
- //Gets the frist character of the selected option and puts it into a char variable
- char ch = (String.valueOf(msg)).charAt(0);
- //A switch statement that calls the apropriate function for what the user has chosen
- switch(ch){
- case '\u65e5': jp_Menus();
- break;
- case 'S': fn_Menus();
- break;
- case 'N': no_Menus();
- break;
- case 'F': fp_Menus();
- break;
- case '\uD55C': ko_Menus();
- break;
- case '\u00CD': ic_Menus();
- break;
- case 'D': dn_Menus();
- break;
- case 's': sw_Menus();
- break;
- case 'L': lol_Menus();
- break;
- case 'l': lt_Menus();
- break;
- default: en_Menus();
- break;
- }
- //Setting up the Menu Bar
- menubar = new JMenuBar();
- //File Menu
- filemi = new JMenu(sMenu);
- //filemi.addMnemonic('F');
- //Creates and adds the New Button to the File Menu
- newmi = new JMenuItem(sNew);
- newmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- newFile();//Calls the newFile Function
- }
- });
- //newmi.addMnemonic('N');
- filemi.add(newmi);
- //Creates and adds the Open Button to the File Menu
- openmi = new JMenuItem(sOpen);
- openmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- openFile();//Calls the openFile Function
- }
- });
- //openmi.addMnemonic('N');
- filemi.add(openmi);
- //Adds a Seperator to the File Menu
- filemi.addSeparator();
- //Creates and adds the Save Button to the File Menu
- savemi = new JMenuItem(sSave);
- savemi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- saveFile();
- }
- });
- //savemi.addMnemonic('S');
- filemi.add(savemi);
- //Creates and adds the Save As Button to the File Menu
- saveasmi = new JMenuItem(sSaveAs);
- saveasmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- saveFileAs();
- }
- });
- filemi.add(saveasmi);
- //Adds a Seperator to the File Menu
- filemi.addSeparator();
- //Creates and adds the Exit Button to the File Menu
- exitmi = new JMenuItem(sExit);
- exitmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- filemi.add(exitmi);
- //adds the file menu to the menu bar
- menubar.add(filemi);
- //Creates the Edit Menu
- editmi = new JMenu(sEdit);
- //Creates and adds the Undo button to the Edit Menu
- undomi = new JMenuItem(sUndo);
- //editmi.add(undomi);
- //Creates and adds the Redo button to the Edit Menu
- redomi = new JMenuItem(sRedo);
- //editmi.add(redomi);
- //Adds a Seperator to the Edit Menu
- //editmi.addSeparator();
- //Creates and adds the Cut button to the Edit Menu
- cutmi = new JMenuItem(sCut);
- cutmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.cut();
- //selectAllText(textbox.getText().getlength());
- }
- });
- editmi.add(cutmi);
- //Creates and adds the Copy button to the Edit Menu
- copymi = new JMenuItem(sCopy);
- copymi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.copy();
- //selectAllText(textbox.getText().getlength());
- }
- });
- editmi.add(copymi);
- //Creates and adds the Paste button to the Edit Menu
- pastemi = new JMenuItem(sPaste);
- pastemi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.paste();
- //selectAllText(textbox.getText().getlength());
- }
- });
- editmi.add(pastemi);
- //Creates and adds the Delete button to the Edit Menu
- deletemi = new JMenuItem(sDelete);
- //editmi.add(deletemi);
- //Adds a Seperator to the Edit Menu
- editmi.addSeparator();
- //Creates and adds the Select All button to the Edit Menu
- selectallmi = new JMenuItem(sSelectAll);
- selectallmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textbox.selectAll();
- //selectAllText(textbox.getText().getlength());
- }
- });
- editmi.add(selectallmi);
- //Adds the edit menu to the Menubar
- menubar.add(editmi);
- //Creates the Language Menu
- langsmi = new JMenu(sLangs);
- //the English Button in the Language Menu
- item = new JMenuItem("English");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- en_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the 日本 Button in the Language Menu
- item = new JMenuItem("\u65e5\u672C");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- jp_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Suomi Button in the Language Menu
- item = new JMenuItem("Suomi");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- fn_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Norske Button in the Language Menu
- item = new JMenuItem("Norske");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- no_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Filipino Button in the Language Menu
- item = new JMenuItem("Filipino");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- fp_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the 한국의 Button in the Language Menu
- item = new JMenuItem("\uD55C\uAD6D\uC758");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- ko_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Íslenska Button in the Language Menu
- item = new JMenuItem("\u00CDslenska");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- ic_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Danske Button in the Language Menu
- item = new JMenuItem("Danske");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- dn_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Svensk Button in the Language Menu
- item = new JMenuItem("Svensk");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- sw_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the Lolspeak Button in the Language Menu
- item = new JMenuItem("Lolspeak");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lol_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //the L337 Button in the Language Menu
- item = new JMenuItem("L337");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lt_Menus();
- resetMenus();
- }
- });
- langsmi.add(item);
- //adds the Language Menu to the menubar
- menubar.add(langsmi);
- //Creates the Options Menu
- optionmi = new JMenu(sOptions);
- //Creates and adds the Change Foreground Button to the Options Menu
- foregmi = new JMenuItem(sForeG);
- foregmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- colorTools(e);
- }
- });
- optionmi.add(foregmi);
- //Creates and adds the Change Background Button to the Options Menu
- backgmi = new JMenuItem(sBackG);
- backgmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- colorTools(e);
- }
- });
- optionmi.add(backgmi);
- //Adds a Separator to the Options Menu
- //optionmi.addSeparator();
- //Creates and adds the About Button to the Options Menu
- aboutmi = new JMenuItem(sAbout);
- backgmi.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- aboutPopup();
- }
- });
- //optionmi.add(aboutmi);
- /*Debug Tool
- item = new JMenuItem("Debug");
- item.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- debugTools();
- }
- });
- optionmi.add(item); */
- JPanel statusbar = new JPanel(new GridLayout(1, 1));
- CaretListenerLabel caretListenerLabel = new CaretListenerLabel(" [Ln 1,Col 0]"+ newline);
- statusbar.add(caretListenerLabel);
- //Adds The Options menu to the menubar
- menubar.add(optionmi);
- contextMenu();
- textArea();
- textbox.addCaretListener(caretListenerLabel);
- //Sets up the Window
- getContentPane().add(scrollbar, BorderLayout.CENTER);
- getContentPane().add(statusbar, BorderLayout.PAGE_END);
- //setContentPane(scrollbar);
- setJMenuBar(menubar);
- setLocationRelativeTo(null);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setTitle(sTitle);
- setSize(500, 500);
- setVisible(true);
- }
- public int getLineAtCaret(JTextArea textArea)
- {
- int caretPosition = textArea.getCaretPosition();
- Element root = textArea.getDocument().getDefaultRootElement();
- return root.getElementIndex(caretPosition) + 1;
- }
- public int getColumnAtCaret(JTextArea textArea)
- {
- int caretPosition = textArea.getCaretPosition();
- Element root = textArea.getDocument().getDefaultRootElement();
- int lineNo = root.getElementIndex(caretPosition);
- Element line = root.getElement(lineNo);
- return caretPosition - line.getStartOffset();
- }
- public int countWords()
- {
- String bigString = textbox.getText();
- StringTokenizer t1 = new StringTokenizer(bigString," ");
- int words = t1.countTokens();
- return words;
- }
- public int countSent()
- {
- String bigString = textbox.getText();
- StringTokenizer t1 = new StringTokenizer(bigString,".?!");
- int sentences = t1.countTokens();
- return sentences - 1;
- }
- public class CaretListenerLabel extends JLabel implements CaretListener {
- //Sets up the statusbar
- public CaretListenerLabel(String label) { super(label); }
- //this is the method that is called everytime the curser moves
- public void caretUpdate(CaretEvent e) { ChangedCaret(e);}
- //updates the status bar
- public void ChangedCaret(CaretEvent e) {
- setText(" [Ln "+ getLineAtCaret(textbox) + " ,Col " + getColumnAtCaret(textbox) + "]"+ " Words: " + countWords() + " Sentences: " + countSent() + newline);
- }
- }
- //this function allows the program to take in commandline args
- public void clOpen(String args)
- {
- if(args != null) {
- try{
- textbox.setText("");
- inputfile = new FileReader(args);
- txtfile = args;
- filebuffer = new BufferedReader(inputfile);
- String line = filebuffer.readLine();
- String reader = "";
- while((reader = filebuffer.readLine()) != null)
- {
- line += newline;
- line += reader;
- }
- if (line != null)
- {
- textbox.setText(line);
- }
- }
- catch(FileNotFoundException e){ txtfile = args; }
- catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- }
- }
- private void openFile()
- {
- chooser = new JFileChooser(new File("."));
- int returnVal = chooser.showOpenDialog(this);
- if(returnVal == JFileChooser.APPROVE_OPTION)
- {
- try{
- textbox.setText("");
- String text = chooser.getSelectedFile().getName();
- setTitle(text);
- inputfile = new FileReader(chooser.getSelectedFile());
- txtfile = chooser.getSelectedFile().getAbsolutePath();
- filebuffer = new BufferedReader(inputfile);
- String line = filebuffer.readLine();
- String reader = "";
- while((reader = filebuffer.readLine()) != null)
- {
- line += newline;
- line += reader;
- }
- if (line != null)
- {
- textbox.setText(line);
- }
- inputfile.close();
- filebuffer.close();
- }
- catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- /*finally
- {
- if(inputfile != null)
- inputfile.close();
- if(filebuffer !=null)
- filebuffer.close();
- } */
- }
- }
- private void saveFile()
- {
- try{
- output = new FileWriter(txtfile);
- writer = new PrintWriter(output);
- writer.print(textbox.getText());
- writer.flush();
- output.close();
- writer.close();
- }
- catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- /*finally
- {
- if(output != null)
- output.close();
- if(writer !=null)
- writer.close();
- } */
- }
- private void saveFileAs()
- {
- chooser = new JFileChooser(new File("."));
- int returnVal = chooser.showSaveDialog(this);
- if(returnVal == JFileChooser.APPROVE_OPTION)
- {
- try{
- txtfile = chooser.getSelectedFile().getAbsolutePath();
- output = new FileWriter(txtfile);
- writer = new PrintWriter(output);
- writer.print(textbox.getText());
- writer.flush();
- output.close();
- writer.close();
- }
- catch(FileNotFoundException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- catch(IOException e){ JOptionPane.showMessageDialog(null,"I appologise But there's been an Error", "Error", JOptionPane.ERROR_MESSAGE); }
- /*finally
- {
- if(output != null)
- output.close();
- if(writer !=null)
- writer.close();
- } */
- }
- }
- private void newFile()
- {
- textbox.setText("");
- saveFileAs();
- }
- public void colorTools(ActionEvent event)
- {
- Color selectedColor;
- if(event.getActionCommand()== sForeG)
- {
- selectedColor = JColorChooser.showDialog(null,sForeMsg,textbox.getForeground());
- if(selectedColor != null)
- textbox.setForeground(selectedColor);
- }
- if(event.getActionCommand()== sBackG)
- {
- selectedColor = JColorChooser.showDialog(null,sBackMsg,textbox.getBackground());
- if(selectedColor != null)
- textbox.setBackground(selectedColor);
- }
- }
- public void resetMenus()
- {
- setTitle(sTitle);
- filemi.setText(sMenu);
- editmi.setText(sEdit);
- langsmi.setText(sLangs);
- optionmi.setText(sOptions);
- newmi.setText(sNew);
- openmi.setText(sOpen);
- savemi.setText(sSave);
- saveasmi.setText(sSaveAs);
- undomi.setText(sUndo);
- redomi.setText(sRedo);
- cutmi.setText(sCut);
- copymi.setText(sCopy);
- pastemi.setText(sPaste);
- deletemi.setText(sDelete);
- selectallmi.setText(sSelectAll);
- rccutmi.setText(sCut);
- rccopymi.setText(sCopy);
- rcpastemi.setText(sPaste);
- rcselectallmi.setText(sSelectAll);
- foregmi.setText(sForeG);
- backgmi.setText(sBackG);
- aboutmi.setText(sAbout);
- exitmi.setText(sExit);
- }
- public void aboutPopup()
- {
- //need something here, will put something here later ^.^
- }
- ///*a method to insert some debug options for when the program is running
- public void debugTools()
- {
- textbox.setText("\u65e5,S,N,F,\uD55C,\u00CD,L");
- txtfile = "debug.txt";
- saveFile();
- txtfile = "newfile.txt";
- textbox.setText(sGreet);
- }
- //*/
- /* Command Line Help function, to be called if the first arg is -h or --help
- public void helpCall()
- {
- System.out.println("The Correct Syntax is as Follows:");
- System.out.println("java -jar MultiLangEditor.jar <filename>");
- }
- */
- public static void main(String args[])
- {
- JavaText app = new JavaText();
- if(args.length > 0)
- {
- app.clOpen(args[0]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement