Skip to content

Commit

Permalink
updating the listener
Browse files Browse the repository at this point in the history
now the keypressed has been changed to keyreleased event for the safety reason while saving the data.
  • Loading branch information
fgroupindonesia committed Jun 4, 2024
1 parent 3b6b795 commit 5e5ed02
Show file tree
Hide file tree
Showing 36 changed files with 291 additions and 87 deletions.
2 changes: 1 addition & 1 deletion build/built-jar.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Thu, 16 May 2024 17:53:00 +0700
#Tue, 04 Jun 2024 15:09:19 +0700


D\:\\project-2024\\java\\SNotepad=
Binary file added build/classes/raw/Entry.class
Binary file not shown.
Binary file modified build/classes/snotepad/CustomPanel2$1.class
Binary file not shown.
Binary file modified build/classes/snotepad/CustomPanel2$2.class
Binary file not shown.
Binary file modified build/classes/snotepad/CustomPanel2$EditorPane.class
Binary file not shown.
Binary file modified build/classes/snotepad/CustomPanel2.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$10.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$11.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$12.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$13.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$14.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$15.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$16.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$17.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$18.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$19.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$20.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$21.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$22.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$23.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$24.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$25.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$26.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$27.class
Binary file not shown.
Binary file added build/classes/snotepad/MainFrame$28.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$8.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame$9.class
Binary file not shown.
Binary file modified build/classes/snotepad/MainFrame.class
Binary file not shown.
Binary file modified build/classes/snotepad/helper/APICall.class
Binary file not shown.
4 changes: 3 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ dist.jar=${dist.dir}/SNotepad.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.gson-2.10.1.jar=C:\\Users\\pc-i3 gen4\\Downloads\\source\\java\\gson\\gson-2.10.1.jar
file.reference.jna-5.6.0.jar=C:\\Users\\pc-i3 gen4\\Downloads\\source\\java\\jna\\jna-5.6.0.jar
file.reference.jna-platform-5.6.0.jar=C:\\Users\\pc-i3 gen4\\Downloads\\source\\java\\jna\\jna-platform-5.6.0.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.jna-5.6.0.jar}:\
${file.reference.jna-platform-5.6.0.jar}
${file.reference.jna-platform-5.6.0.jar}:\
${file.reference.gson-2.10.1.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down
39 changes: 39 additions & 0 deletions src/raw/Entry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

package raw;

/**
*
* @author pc-i3 gen4
*/
public class Entry {
private String url;
private String origin_url;

/**
* @return the url
*/
public String getUrl() {
return url;
}

/**
* @param url the url to set
*/
public void setUrl(String url) {
this.url = url;
}

/**
* @return the origin_url
*/
public String getOrigin_url() {
return origin_url;
}

/**
* @param origin_url the origin_url to set
*/
public void setOrigin_url(String origin_url) {
this.origin_url = origin_url;
}
}
1 change: 1 addition & 0 deletions src/snotepad/CustomPanel2.form
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</Properties>
<Events>
<EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="jTextAreaKeyPressed"/>
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="jTextAreaKeyReleased"/>
</Events>
</Component>
</SubComponents>
Expand Down
80 changes: 39 additions & 41 deletions src/snotepad/CustomPanel2.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class CustomPanel2 extends javax.swing.JPanel {
private File fileObject;
private String fileName;
private String completeLocation;
private StringBuffer stb = new StringBuffer();
private JTabbedPane tabbedPanel;
private JMenuItem menuLock;
private JMenuItem menuSave;
Expand All @@ -42,18 +41,13 @@ public void setSavedStatus(boolean b) {
addMark();
}

public void changeTitleOfTab(String newName) {
tabbedPanel.setTitleAt(nomer, newName);
public void decreaseIndexNum() {
nomer--;
}

public void appendText(String n) {

stb.append(n);
this.setOriginalText(stb.toString());

setSavedStatus(false);
public void changeTitleOfTab(String newName) {

addMark();
tabbedPanel.setTitleAt(nomer, newName);
}

int fontSize;
Expand All @@ -76,6 +70,10 @@ public boolean isSaved() {
return saved;
}

public String getTitle() {
return tabbedPanel.getTitleAt(nomer);
}

private void addMark() {
String title = tabbedPanel.getTitleAt(nomer);

Expand All @@ -91,12 +89,6 @@ private void addMark() {

}

public void clear() {
stb = new StringBuffer();
this.setOriginalText(stb.toString());

}

public void lock() {
// this will automatically toggle
locked = !locked;
Expand All @@ -106,12 +98,11 @@ public void lock() {
jTextArea.setEnabled(!locked);
}

public void setNewOriginalText(String n){
this.clear();
this.appendText(n);
public void setNewOriginalText(String n) {
this.refreshRender();
this.setOriginalText(n);
}

public void refreshRender() {
if (isLockOrNot()) {
jTextArea.setText(this.getCodeText());
Expand Down Expand Up @@ -198,6 +189,10 @@ public CustomPanel2() {
applyDropable();
}

public void setTabbedPanel(JTabbedPane jtb2) {
tabbedPanel = jtb2;
}

public CustomPanel2(JTabbedPane jtb, int nomerX,
JMenuItem menuLockNa, JMenuItem menuSaveNa,
JButton btnSaveNa) {
Expand All @@ -207,7 +202,7 @@ public CustomPanel2(JTabbedPane jtb, int nomerX,
menuLock = menuLockNa;
menuSave = menuSaveNa;
btn_save = btnSaveNa;

applyDropable();
}

Expand All @@ -225,7 +220,9 @@ public synchronized void drop(DropTargetDropEvent evt) {
if (!files.isEmpty()) {
File file = files.get(0);
// clear the notepad first
clear();

setOriginalText("");

readFileContent(file);

// to make the cursor at the beginning of the content
Expand Down Expand Up @@ -261,6 +258,9 @@ private void initComponents() {
public void keyPressed(java.awt.event.KeyEvent evt) {
jTextAreaKeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
jTextAreaKeyReleased(evt);
}
});
jScrollPane1.setViewportView(jTextArea);

Expand Down Expand Up @@ -292,16 +292,21 @@ private void jTextAreaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event

this.lock();

} else {
}

}//GEN-LAST:event_jTextAreaKeyPressed

// toggle the save button
private void jTextAreaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextAreaKeyReleased

// toggle the save button
menuSave.setEnabled(true);
btn_save.setEnabled(true);
this.appendText(jTextArea.getText());

}

}//GEN-LAST:event_jTextAreaKeyPressed
this.setOriginalText(jTextArea.getText());
setSavedStatus(false);
addMark();

}//GEN-LAST:event_jTextAreaKeyReleased

private boolean isBackSpace(KeyEvent evt) {
boolean t = false;
Expand Down Expand Up @@ -334,18 +339,20 @@ private void readFileContent(File file) {

BufferedReader reader = new BufferedReader(new FileReader(file));

StringBuffer stb = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
appendText(line);
appendText("\n");
stb.append(line);
stb.append("\n");
}

setOriginalText(stb.toString());
this.jTextArea.setText(getOriginalText());

} catch (Exception e) {
System.err.println("Error when reading file content...");
}

}

public boolean isEmptyEditor() {
Expand All @@ -356,14 +363,6 @@ public boolean isEmptyEditor() {
return false;
}

private void backspace() {
// deleting one char from the original text
stb = new StringBuffer();
this.appendText(
getOriginalText().substring(0, getOriginalText().length() - 1));

}

void highlightText() {

this.jTextArea.requestFocus();
Expand All @@ -382,9 +381,8 @@ void highlightText() {

void pasteText() {

this.jTextArea.requestFocus();
this.jTextArea.requestFocus();


try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
Expand Down
6 changes: 6 additions & 0 deletions src/snotepad/MainFrame.form
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,13 @@
<EmptyBorder bottom="1" left="8" right="1" top="1"/>
</Border>
</Property>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="label_statusMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Center"/>
Expand Down
Loading

0 comments on commit 5e5ed02

Please sign in to comment.