Skip to content

Commit

Permalink
build feature added for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Geez14 committed Sep 2, 2024
1 parent 5aca82b commit 8a9ce6f
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
out/
.vscode/
.vscode/
build/
dump/
3 changes: 3 additions & 0 deletions FastNoteApp.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
REM Run the JAR file
java -jar FastNoteApp.jar
Binary file added FastNoteApp.jar
Binary file not shown.
16 changes: 10 additions & 6 deletions FastNoteApp.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

import java.awt.event.WindowAdapter;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import javax.swing.JFileChooser;
import java.awt.event.WindowAdapter;
import com.geez14.fastnote.FastNoteUI;
import com.geez14.fastnote.FastNoteComponentsEventHandler;
import com.geez14.fastnote.FileOperations;
import com.geez14.fastnote.FastNoteComponentsEventHandler;

/**
* The FastNoteApp class is the entry point for the FastNote application.
Expand All @@ -22,9 +19,14 @@ public class FastNoteApp {
static FastNoteUI ui;

public static void main(String[] args) {
// create UI
ui = new FastNoteUI();
FastNoteComponentsEventHandler handler = new FastNoteComponentsEventHandler(ui);

// setIcon
ui.setIconImage(new ImageIcon("assets/images/FastNote1.0.png").getImage());

// add window listener
ui.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
Expand All @@ -43,6 +45,8 @@ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
System.exit(0);
}
});

// add action listener
ui.getOpenItem().addActionListener(handler);
ui.getSaveItem().addActionListener(handler);
}
Expand Down
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
# A simple notepad application using java swing

## Features

1. Word Wraping
2. Open file
4. Read file
5. Save file
6. 3_Theme
3. Read file
4. Save file
5. 3_Theme
1. LightMode
2. DarkMode
3. HackerTheme
7. Line Number
6. Line Number

# For Windows, Linux
## Compile
```code
javac -d ./out FastNoteApp.java
javac --release 8 -d ./out FastNoteApp.java
```

## Build
```code
jar -cvfm FastNoteApp.jar MANIFEST.MF -C out .
```

## Run
```code
java -cp "./out" FastNoteApp
java -jar FastNoteApp.jar
```

## package info:
> **Supported by Java1.8 and +**
## Automation Windows
added build process automation.
added run code
```
!note you must be in the project directory to compile and build
.\build.bat
.\FastNoteApp.bat
```
> paste the FastNoteApp.jar and FastNoteApp.bat in a directory and add the environment variable to that path.
16 changes: 16 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
REM compile, build
echo "----------Compiling----------"
javac -d out FastNoteApp.java
if %errorlevel% neq 0 (
echo "Compile Failed"
) else (
echo "Compile Successful"
echo "-------Building FastNoteApp.jar-------"
jar cvfm FastNoteApp.jar MANIFEST.MF -C out .
if %errorlevel% neq 0 (
echo "Build Failed"
) else (
echo "Compile and Build Successful"
)
)
9 changes: 8 additions & 1 deletion com/geez14/fastnote/FastNoteComponentsEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package com.geez14.fastnote;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

public class FastNoteComponentsEventHandler implements ActionListener {
private FastNoteUI ui;
private JFileChooser fileChooser;

private FileNameExtensionFilter filter = new FileNameExtensionFilter("Text and Ascii Files", "js", "txt", "java", "c",
"cpp", "py", "html", "css", "xml", "json", "md", "csv", "tsv", "sql", "sh", "bat", "log", "yaml", "yml",
"properties", "ini", "cfg", "conf", "cnf", "config", "env", "envrc");

public FastNoteComponentsEventHandler(FastNoteUI ui) {
this.ui = ui;
fileChooser = new JFileChooser();
fileChooser.setFileFilter(filter);
}

@Override
Expand Down Expand Up @@ -47,6 +52,8 @@ public void actionPerformed(ActionEvent e) {
int result = fileChooser.showSaveDialog(ui);
if (result == JFileChooser.APPROVE_OPTION) {
FileOperations.writeFile(ui.getTextArea(), fileChooser.getSelectedFile());
ui.isSavedChange = true;
ui.setTitle("FastNote1.0(" + fileChooser.getSelectedFile().getName() + ")");
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions com/geez14/fastnote/FastNoteUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.text.AbstractDocument;
import javax.swing.text.Element;
import javax.swing.text.Utilities;

import theme.Theme;
import theme.ThemeInjector;
Expand All @@ -20,6 +22,7 @@

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.JScrollPane;
Expand Down Expand Up @@ -67,10 +70,10 @@ public FastNoteUI() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initMenueBar();
initTextArea();
setVisible(true);
}

void initTextArea() {

textArea.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Expand All @@ -80,7 +83,7 @@ public void keyPressed(KeyEvent e) {
// injecting color
JScrollPane scrollPane = new JScrollPane(textArea);
// // Create the line numbers area
lineNumbers = new JTextArea("0");
lineNumbers = new JTextArea("1");
lineNumbers.setBackground(Color.LIGHT_GRAY);
lineNumbers.setEditable(false);
lineNumbers.setFont(new Font("Calibri", Font.PLAIN, 16));
Expand All @@ -93,9 +96,9 @@ public String getText() {
// carterPosition is index of the cursor
int caretPosition = textArea.getDocument().getLength();
Element root = textArea.getDocument().getDefaultRootElement();
StringBuilder text = new StringBuilder("1"+System.lineSeparator());
StringBuilder text = new StringBuilder("1" + System.lineSeparator());
// iterate through the textArea and add line numbers
for (int i = 2; i < root.getElementIndex(caretPosition)+2 ; i++) {
for (int i = 2; i < root.getElementIndex(caretPosition) + 2; i++) {
text.append(i).append(System.lineSeparator());
}
return text.toString();
Expand All @@ -116,9 +119,11 @@ public void changedUpdate(DocumentEvent e) {
lineNumbers.setText(getText());
}
});

// add another listener for the textArea to makesure the buffer is not more than
// fixed size.
add(scrollPane, BorderLayout.CENTER);
currentTheme = defaultTheme[0];
SwingUtilities.invokeLater(() -> setVisible(true));
populateTheme();
}

Expand Down
39 changes: 39 additions & 0 deletions com/geez14/fastnote/TextFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.geez14.fastnote;

import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;

public class TextFilter {
// DocumentFilter to allow only ASCII characters
static class AsciiOnlyFilter extends DocumentFilter {
@Override
public void insertString(FilterBypass fb, int offset, String string, javax.swing.text.AttributeSet attr)
throws BadLocationException {
if (isAscii(string)) {
super.insertString(fb, offset, string, attr);
}
}

@Override
public void replace(FilterBypass fb, int offset, int length, String text, javax.swing.text.AttributeSet attrs)
throws BadLocationException {
if (isAscii(text)) {
super.replace(fb, offset, length, text, attrs);
}
}

@Override
public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
super.remove(fb, offset, length);
}

private boolean isAscii(String text) {
for (char c : text.toCharArray()) {
if (c > 127) {
return false;
}
}
return true;
}
}
}

0 comments on commit 8a9ce6f

Please sign in to comment.