Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Text Editor like Notepad in java #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions Java/Java Text Editor/MyFileStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
public class MyFileStack {
private int size;
private Node top;
private Node forRetrieval = top;

private class Node {
String text;
Node next;

public Node(String text, Node next) {
super();
this.text = text;
this.next = next;
}

}

public boolean push(String text) {
if(this.toString().contains(text))
return false;
top = new Node(text, top);
size++;
return true;
}

public void pushAtFirst(String text) {
if (top == null) {
top = new Node(text, null);
size++;
return;
}
Node i = top;
if (top.next == null) {
top.next = new Node(text, null);
size++;
return;
}
while (i.next.next != null) {
i = i.next;
}
i.next = new Node(text, null);
}

public void removeAtFirst() {
if (top == null) {
return;
}
Node i = top;
if (top.next == null) {
return;
}
while (i.next.next != null) {
i = i.next;
}
i.next = null;
}

public String pop() {
if (top == null)
return "";
String text = top.text;
top = top.next;
size--;
return text;
}

public int size() {
return size;
}

public boolean isEmpty() {
return size == 0;
}

public String peek() {
if (top == null)
return "";
return top.text;
}

public void clear() {
top=forRetrieval=null;
}

public String nextData() {
if (forRetrieval == null)
return "";
String text = forRetrieval.text;
forRetrieval = forRetrieval.next;
return text;
}


@Override
public String toString() {
String buf="";
for (Node i = top; i != null; i = i.next) {
buf+=(i.text + " ");
}
return buf;
}


}
9 changes: 9 additions & 0 deletions Java/Java Text Editor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 19SW42-DSA-Project
A java text Editor
-------------------

I wanted to make a text editor using java using which we can open, modify or create new text files. So to record the information about which file is opened or what modifications have been done with a file, I needed a data structure in which I can store this kind of information.
As the text editor I am going to make has operation like undo/redo or open from history(the file(s) opened before opening of current file) options so this is clear that no data structure other than Stack could achieve this goal in an efficient manner.
As from stack we can undo very easily by popping recent activity and same goes for redo and open from history options. For that I have provided my own implementation of stacks.
Though it has some basic functionalities to interact with text files but we can say that some how it works same as the notepad which opens/edits/creates text files.
All functionalities that were thought to be part of this project i.e text editor. are fulfilled very well. Each operation is performing actions as it should do which includes cut, copy, paste, clear, new file ,save file, undo redo and closing operations.
Loading