diff --git a/.classpath b/.classpath index 42da157..fb50116 100644 --- a/.classpath +++ b/.classpath @@ -1,7 +1,6 @@ - diff --git a/README.md b/README.md index 1124d14..da63269 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ * [xdvrx1](https://github.com/xdvrx1) +* [Talha Tariq](https://github.com/TT-talhatariq) ## CONTACT diff --git a/SimpleJavaTextEditor.jar b/SimpleJavaTextEditor.jar index 6d6ffc7..f5d266a 100644 Binary files a/SimpleJavaTextEditor.jar and b/SimpleJavaTextEditor.jar differ diff --git a/icons/about.png b/bin/simplejavatexteditor/icons/about.png similarity index 100% rename from icons/about.png rename to bin/simplejavatexteditor/icons/about.png diff --git a/icons/about_me.png b/bin/simplejavatexteditor/icons/about_me.png similarity index 100% rename from icons/about_me.png rename to bin/simplejavatexteditor/icons/about_me.png diff --git a/icons/bold.png b/bin/simplejavatexteditor/icons/bold.png similarity index 100% rename from icons/bold.png rename to bin/simplejavatexteditor/icons/bold.png diff --git a/icons/clear.png b/bin/simplejavatexteditor/icons/clear.png similarity index 100% rename from icons/clear.png rename to bin/simplejavatexteditor/icons/clear.png diff --git a/icons/close.png b/bin/simplejavatexteditor/icons/close.png similarity index 100% rename from icons/close.png rename to bin/simplejavatexteditor/icons/close.png diff --git a/icons/copy.png b/bin/simplejavatexteditor/icons/copy.png similarity index 100% rename from icons/copy.png rename to bin/simplejavatexteditor/icons/copy.png diff --git a/icons/cut.png b/bin/simplejavatexteditor/icons/cut.png similarity index 100% rename from icons/cut.png rename to bin/simplejavatexteditor/icons/cut.png diff --git a/icons/italic.png b/bin/simplejavatexteditor/icons/italic.png similarity index 100% rename from icons/italic.png rename to bin/simplejavatexteditor/icons/italic.png diff --git a/icons/new.png b/bin/simplejavatexteditor/icons/new.png similarity index 100% rename from icons/new.png rename to bin/simplejavatexteditor/icons/new.png diff --git a/icons/open.png b/bin/simplejavatexteditor/icons/open.png similarity index 100% rename from icons/open.png rename to bin/simplejavatexteditor/icons/open.png diff --git a/icons/paste.png b/bin/simplejavatexteditor/icons/paste.png similarity index 100% rename from icons/paste.png rename to bin/simplejavatexteditor/icons/paste.png diff --git a/icons/save.png b/bin/simplejavatexteditor/icons/save.png similarity index 100% rename from icons/save.png rename to bin/simplejavatexteditor/icons/save.png diff --git a/icons/search.png b/bin/simplejavatexteditor/icons/search.png similarity index 100% rename from icons/search.png rename to bin/simplejavatexteditor/icons/search.png diff --git a/icons/selectall.png b/bin/simplejavatexteditor/icons/selectall.png similarity index 100% rename from icons/selectall.png rename to bin/simplejavatexteditor/icons/selectall.png diff --git a/icons/ste.png b/bin/simplejavatexteditor/icons/ste.png similarity index 100% rename from icons/ste.png rename to bin/simplejavatexteditor/icons/ste.png diff --git a/icons/wordwrap.png b/bin/simplejavatexteditor/icons/wordwrap.png similarity index 100% rename from icons/wordwrap.png rename to bin/simplejavatexteditor/icons/wordwrap.png diff --git a/src/simplejavatexteditor/AutoComplete.java b/src/simplejavatexteditor/AutoComplete.java index ecc99bd..f3806d0 100644 --- a/src/simplejavatexteditor/AutoComplete.java +++ b/src/simplejavatexteditor/AutoComplete.java @@ -63,8 +63,8 @@ public AutoComplete(UI ui, ArrayList al) { //Set the keywords words = al; kw = new SupportedKeywords(); - brackets = kw.getbrackets(); - bracketCompletions = kw.getbracketCompletions(); + brackets = kw.getBrackets(); + bracketCompletions = kw.getBracketCompletions(); //Access the editor this.ui = ui; diff --git a/src/simplejavatexteditor/Find.java b/src/simplejavatexteditor/Find.java index b5ef881..c820f76 100644 --- a/src/simplejavatexteditor/Find.java +++ b/src/simplejavatexteditor/Find.java @@ -111,14 +111,14 @@ public Find(JTextArea text) { } public void find() { - select_start = txt.getText().toLowerCase().indexOf(textF.getText().toLowerCase()); + select_start = txt.getText().indexOf(textF.getText().toLowerCase()); if(select_start == -1) { startIndex = 0; JOptionPane.showMessageDialog(null, "Could not find \"" + textF.getText() + "\"!"); return; } - if(select_start == txt.getText().toLowerCase().lastIndexOf(textF.getText().toLowerCase())) + if(select_start == txt.getText().lastIndexOf(textF.getText().toLowerCase())) { startIndex = 0; } @@ -147,12 +147,12 @@ public void findNext() { } try { - int select_start = txt.getText().toLowerCase().indexOf(selection.toLowerCase(), startIndex); + int select_start = txt.getText() .indexOf(selection , startIndex); int select_end = select_start+selection.length(); txt.select(select_start, select_end); startIndex = select_end+1; - if(select_start == txt.getText().toLowerCase().lastIndexOf(selection.toLowerCase())) + if(select_start == txt.getText().lastIndexOf(selection.toLowerCase())) { startIndex = 0; } @@ -175,7 +175,7 @@ public void replace() { } public void replaceAll() { - txt.setText(txt.getText().toLowerCase().replaceAll(textF.getText().toLowerCase(), textR.getText())); + txt.setText(txt.getText().replaceAll(textF.getText() , textR.getText())); } public void actionPerformed(ActionEvent e) { diff --git a/src/simplejavatexteditor/HighlightText.java b/src/simplejavatexteditor/HighlightText.java index 571f35a..4bd1556 100644 --- a/src/simplejavatexteditor/HighlightText.java +++ b/src/simplejavatexteditor/HighlightText.java @@ -13,14 +13,14 @@ public void highLight(JTextComponent textComp, String[] pattern) { removeHighlights(textComp); try { - Highlighter hilite = textComp.getHighlighter(); + Highlighter highlighter = textComp.getHighlighter(); Document doc = textComp.getDocument(); String text = doc.getText(0, doc.getLength()); for (int i = 0; i < pattern.length; i++) { int pos = 0; while ((pos = text.indexOf(pattern[i], pos)) >= 0) { - hilite.addHighlight(pos, pos + pattern[i].length(), this); + highlighter.addHighlight(pos, pos + pattern[i].length(), this); pos += pattern[i].length(); } } @@ -30,12 +30,12 @@ public void highLight(JTextComponent textComp, String[] pattern) { public void removeHighlights(JTextComponent textComp) { - Highlighter hilite = textComp.getHighlighter(); - Highlighter.Highlight[] hilites = hilite.getHighlights(); + Highlighter highlighter = textComp.getHighlighter(); + Highlighter.Highlight[] hilites = highlighter.getHighlights(); for (int i = 0; i < hilites.length; i++) { if (hilites[i].getPainter() instanceof HighlightText) { - hilite.removeHighlight(hilites[i]); + highlighter.removeHighlight(hilites[i]); } } } diff --git a/src/simplejavatexteditor/SimpleJavaTextEditor.java b/src/simplejavatexteditor/SimpleJavaTextEditor.java index dc4892b..6fb0ad9 100644 --- a/src/simplejavatexteditor/SimpleJavaTextEditor.java +++ b/src/simplejavatexteditor/SimpleJavaTextEditor.java @@ -19,19 +19,27 @@ package simplejavatexteditor; import javax.swing.JTextPane; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; public class SimpleJavaTextEditor extends JTextPane { private static final long serialVersionUID = 1L; public final static String AUTHOR_EMAIL = "hi@ph7.me"; public final static String NAME = "PHNotePad"; - public final static String EDITOR_EMAIL = "contact@achinthagunasekara.com"; + public final static String EDITOR_EMAIL = "contact@achinthagunasekara.com"; public final static double VERSION = 3.0; /** * @param args */ public static void main(String[] args) { + try { + UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { + e.printStackTrace(); + } + new UI().setVisible(true); } diff --git a/src/simplejavatexteditor/SupportedKeywords.java b/src/simplejavatexteditor/SupportedKeywords.java index a560841..6667723 100644 --- a/src/simplejavatexteditor/SupportedKeywords.java +++ b/src/simplejavatexteditor/SupportedKeywords.java @@ -45,14 +45,14 @@ public String[] getJavaKeywords() { public String[] getCppKeywords() { return cpp; } - public ArrayList getbracketCompletions() { + public ArrayList getBracketCompletions() { ArrayList al = new ArrayList<>(); for(String completion : bCompletions) { al.add(completion); } return al; } - public ArrayList getbrackets() { + public ArrayList getBrackets() { ArrayList al = new ArrayList<>(); for(String completion : brackets) { al.add(completion); diff --git a/src/simplejavatexteditor/UI.java b/src/simplejavatexteditor/UI.java index e356358..066d365 100644 --- a/src/simplejavatexteditor/UI.java +++ b/src/simplejavatexteditor/UI.java @@ -37,6 +37,7 @@ */ package simplejavatexteditor; +import java.lang.reflect.Method; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.DataFlavor; @@ -72,29 +73,29 @@ public class UI extends JFrame implements ActionListener { private final Action selectAllAction; //setup icons - Bold and Italic - private final ImageIcon boldIcon = new ImageIcon("icons/bold.png"); + private final ImageIcon boldIcon = new ImageIcon(UI.class.getResource("icons/bold.png")); private final ImageIcon italicIcon = new ImageIcon("icons/italic.png"); // setup icons - File Menu - private final ImageIcon newIcon = new ImageIcon("icons/new.png"); - private final ImageIcon openIcon = new ImageIcon("icons/open.png"); - private final ImageIcon saveIcon = new ImageIcon("icons/save.png"); - private final ImageIcon closeIcon = new ImageIcon("icons/close.png"); + private final ImageIcon newIcon = new ImageIcon(UI.class.getResource("icons/new.png")); + private final ImageIcon openIcon = new ImageIcon(UI.class.getResource("icons/open.png")); + private final ImageIcon saveIcon = new ImageIcon(UI.class.getResource("icons/save.png")); + private final ImageIcon closeIcon = new ImageIcon(UI.class.getResource("icons/close.png")); // setup icons - Edit Menu - private final ImageIcon clearIcon = new ImageIcon("icons/clear.png"); - private final ImageIcon cutIcon = new ImageIcon("icons/cut.png"); - private final ImageIcon copyIcon = new ImageIcon("icons/copy.png"); - private final ImageIcon pasteIcon = new ImageIcon("icons/paste.png"); - private final ImageIcon selectAllIcon = new ImageIcon("icons/selectall.png"); - private final ImageIcon wordwrapIcon = new ImageIcon("icons/wordwrap.png"); + private final ImageIcon clearIcon = new ImageIcon(UI.class.getResource("icons/clear.png")); + private final ImageIcon cutIcon = new ImageIcon(UI.class.getResource("icons/cut.png")); + private final ImageIcon copyIcon = new ImageIcon(UI.class.getResource("icons/copy.png")); + private final ImageIcon pasteIcon = new ImageIcon(UI.class.getResource("icons/paste.png")); + private final ImageIcon selectAllIcon = new ImageIcon(UI.class.getResource("icons/selectall.png")); + private final ImageIcon wordwrapIcon = new ImageIcon(UI.class.getResource("icons/wordwrap.png")); // setup icons - Search Menu - private final ImageIcon searchIcon = new ImageIcon("icons/search.png"); + private final ImageIcon searchIcon = new ImageIcon(UI.class.getResource("icons/search.png")); // setup icons - Help Menu - private final ImageIcon aboutMeIcon = new ImageIcon("icons/about_me.png"); - private final ImageIcon aboutIcon = new ImageIcon("icons/about.png"); + private final ImageIcon aboutMeIcon = new ImageIcon(UI.class.getResource("icons/about_me.png")); + private final ImageIcon aboutIcon = new ImageIcon(UI.class.getResource("icons/about.png")); private SupportedKeywords kw = new SupportedKeywords(); private HighlightText languageHighlighter = new HighlightText(Color.GRAY); @@ -104,7 +105,7 @@ public class UI extends JFrame implements ActionListener { public UI() { try { - ImageIcon image = new ImageIcon("icons/ste.png"); + ImageIcon image = new ImageIcon(UI.class.getResource("icons/ste.png")); super.setIconImage(image.getImage()); } catch (Exception ex) { ex.printStackTrace(); @@ -256,14 +257,10 @@ public void keyPressed(KeyEvent ke) { wordWrap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // If wrapping is false then after clicking on menuitem the word wrapping will be enabled - if (textArea.getLineWrap() == false) { - /* Setting word wrapping to true */ - textArea.setLineWrap(true); - } else { - // else if wrapping is true then after clicking on menuitem the word wrapping will be disabled - /* Setting word wrapping to false */ - textArea.setLineWrap(false); - } + /* Setting word wrapping to true */ + // else if wrapping is true then after clicking on menuitem the word wrapping will be disabled + /* Setting word wrapping to false */ + textArea.setLineWrap(!textArea.getLineWrap()); } }); @@ -369,9 +366,9 @@ public void actionPerformed(ActionEvent ev) { //GETTING ALL AVAILABLE FONT FOMILY NAMES String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); - for (int i = 0; i < fonts.length; i++) { + for (String font : fonts) { //Adding font family names to font[] array - fontType.addItem(fonts[i]); + fontType.addItem(font); } //Setting maximize size of the fontType ComboBox fontType.setMaximumSize(new Dimension(170, 30)); @@ -451,20 +448,20 @@ public void enableAutoComplete(File file) { for (int i = 0; i < list.length; i++) { if (file.getName().endsWith(list[i])) { switch (i) { - case 0: + case 0 -> { String[] jk = kw.getJavaKeywords(); arrayList = kw.setKeywords(jk); autocomplete = new AutoComplete(this, arrayList); textArea.getDocument().addDocumentListener(autocomplete); hasListener = true; - break; - case 1: + } + case 1 -> { String[] ck = kw.getCppKeywords(); arrayList = kw.setKeywords(ck); autocomplete = new AutoComplete(this, arrayList); textArea.getDocument().addDocumentListener(autocomplete); hasListener = true; - break; + } } } } @@ -506,13 +503,17 @@ else if (e.getSource() == newFile || e.getSource() == newButton) { } // If the source was the "open" option else if (e.getSource() == openFile || e.getSource() == openButton) { JFileChooser open = new JFileChooser(); // open up a file chooser (a dialog for the user to browse files to open) + if( !(textArea.getText().equals("")) ) { + saveFile(); + } + // if true does normal operation int option = open.showOpenDialog(this); // get the option that the user selected (approve or cancel) /* - * NOTE: because we are OPENing a file, we call showOpenDialog~ if - * the user clicked OK, we have "APPROVE_OPTION" so we want to open - * the file - */ + * NOTE: because we are OPENing a file, we call showOpenDialog~ if + * the user clicked OK, we have "APPROVE_OPTION" so we want to open + * the file + */ if (option == JFileChooser.APPROVE_OPTION) { FEdit.clear(textArea); // clear the TextArea before applying the file contents try { @@ -529,6 +530,7 @@ else if (e.getSource() == openFile || e.getSource() == openButton) { System.err.println(ex.getMessage()); } } + } // If the source of the event was the "save" option else if (e.getSource() == saveFile || e.getSource() == saveButton) { saveFile(); @@ -648,17 +650,17 @@ public void drop(DropTargetDropEvent e) { try { Transferable tr = e.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); - for (int i = 0; i < flavors.length; i++) { - if (flavors[i].isFlavorJavaFileListType()) { + for (DataFlavor flavor : flavors) { + if (flavor.isFlavorJavaFileListType()) { e.acceptDrop(e.getDropAction()); try { - String fileName = tr.getTransferData(flavors[i]).toString().replace("[", "").replace("]", ""); + String fileName = tr.getTransferData(flavor).toString().replace("[", "").replace("]", ""); // Allowed file filter extentions for drag and drop boolean extensionAllowed = false; - for (int j = 0; j < dragDropExtensionFilter.length; j++) { - if (fileName.endsWith(dragDropExtensionFilter[j])) { + for (String s : dragDropExtensionFilter) { + if (fileName.endsWith(s)) { extensionAllowed = true; break; } diff --git a/src/simplejavatexteditor/icons/about.png b/src/simplejavatexteditor/icons/about.png new file mode 100644 index 0000000..6ac43f1 Binary files /dev/null and b/src/simplejavatexteditor/icons/about.png differ diff --git a/src/simplejavatexteditor/icons/about_me.png b/src/simplejavatexteditor/icons/about_me.png new file mode 100644 index 0000000..76dfe2e Binary files /dev/null and b/src/simplejavatexteditor/icons/about_me.png differ diff --git a/src/simplejavatexteditor/icons/bold.png b/src/simplejavatexteditor/icons/bold.png new file mode 100644 index 0000000..f64840c Binary files /dev/null and b/src/simplejavatexteditor/icons/bold.png differ diff --git a/src/simplejavatexteditor/icons/clear.png b/src/simplejavatexteditor/icons/clear.png new file mode 100644 index 0000000..18d781a Binary files /dev/null and b/src/simplejavatexteditor/icons/clear.png differ diff --git a/src/simplejavatexteditor/icons/close.png b/src/simplejavatexteditor/icons/close.png new file mode 100644 index 0000000..7c51cef Binary files /dev/null and b/src/simplejavatexteditor/icons/close.png differ diff --git a/src/simplejavatexteditor/icons/copy.png b/src/simplejavatexteditor/icons/copy.png new file mode 100644 index 0000000..97df8a9 Binary files /dev/null and b/src/simplejavatexteditor/icons/copy.png differ diff --git a/src/simplejavatexteditor/icons/cut.png b/src/simplejavatexteditor/icons/cut.png new file mode 100644 index 0000000..d0631b1 Binary files /dev/null and b/src/simplejavatexteditor/icons/cut.png differ diff --git a/src/simplejavatexteditor/icons/italic.png b/src/simplejavatexteditor/icons/italic.png new file mode 100644 index 0000000..b09462d Binary files /dev/null and b/src/simplejavatexteditor/icons/italic.png differ diff --git a/src/simplejavatexteditor/icons/new.png b/src/simplejavatexteditor/icons/new.png new file mode 100644 index 0000000..b88d194 Binary files /dev/null and b/src/simplejavatexteditor/icons/new.png differ diff --git a/src/simplejavatexteditor/icons/open.png b/src/simplejavatexteditor/icons/open.png new file mode 100644 index 0000000..0c4d5b3 Binary files /dev/null and b/src/simplejavatexteditor/icons/open.png differ diff --git a/src/simplejavatexteditor/icons/paste.png b/src/simplejavatexteditor/icons/paste.png new file mode 100644 index 0000000..7e897ef Binary files /dev/null and b/src/simplejavatexteditor/icons/paste.png differ diff --git a/src/simplejavatexteditor/icons/save.png b/src/simplejavatexteditor/icons/save.png new file mode 100644 index 0000000..3cdafd5 Binary files /dev/null and b/src/simplejavatexteditor/icons/save.png differ diff --git a/src/simplejavatexteditor/icons/search.png b/src/simplejavatexteditor/icons/search.png new file mode 100644 index 0000000..8c6b951 Binary files /dev/null and b/src/simplejavatexteditor/icons/search.png differ diff --git a/src/simplejavatexteditor/icons/selectall.png b/src/simplejavatexteditor/icons/selectall.png new file mode 100644 index 0000000..6d217f2 Binary files /dev/null and b/src/simplejavatexteditor/icons/selectall.png differ diff --git a/src/simplejavatexteditor/icons/ste.png b/src/simplejavatexteditor/icons/ste.png new file mode 100644 index 0000000..c4fbfe2 Binary files /dev/null and b/src/simplejavatexteditor/icons/ste.png differ diff --git a/src/simplejavatexteditor/icons/wordwrap.png b/src/simplejavatexteditor/icons/wordwrap.png new file mode 100644 index 0000000..b48850b Binary files /dev/null and b/src/simplejavatexteditor/icons/wordwrap.png differ