Skip to content

Commit

Permalink
refactor(setNewActivatedEntryAndUpdateDisplay): issue #507
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfBarkow committed May 21, 2024
1 parent ef02f7c commit 3e587db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
36 changes: 13 additions & 23 deletions src/main/java/de/danielluedecke/zettelkasten/ZettelkastenView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ public void hyperlinkUpdate(HyperlinkEvent evt) {
}
});

// Initialize the JTable selection listeners.
// Init the JTable selection listeners.
JTable[] tables = new JTable[] { jTableLinks, jTableManLinks, jTableAuthors,
jTableTitles, jTableBookmarks, jTableAttachments };
for (JTable t : tables) {
Expand Down Expand Up @@ -3478,7 +3478,7 @@ public void updateZettelkasten(String updateBuildNr) {
}

/**
* This method toggles the highlight-setting for the keywords. When activated,
* This methoid toggles the highlight-setting for the keywords. When activated,
* the keywords of the current displayed entry are highlighted in the entry's
* content-text.
*/
Expand Down Expand Up @@ -5255,20 +5255,12 @@ private boolean addKeywords(String[] kws, boolean comesFromTextSelection) {
}

/**
* Adds the displayed entry to the bookmark list.
*/
@Action(enabledProperty = "entryBookmarked")
public void addToBookmark() {
Constants.zknlogger.log(Level.INFO, "Attempting to add the displayed entry to the bookmark list.");
Constants.zknlogger.log(Level.INFO, String.format("Displayed entry: %d", displayedZettel));

try {
addToBookmarks(new int[] { displayedZettel }, false);
Constants.zknlogger.log(Level.INFO, String.format("Entry %d added to bookmarks successfully.", displayedZettel));
} catch (Exception e) {
Constants.zknlogger.log(Level.SEVERE, "Error adding entry to bookmarks", e);
}
}
* Adds the displayed entry to the bookmark list.
*/
@Action(enabledProperty = "entryBookmarked")
public void addToBookmark() {
addToBookmarks(new int[] { displayedZettel }, false);
}

/**
* Adds one or more bookmarks to the bookmark-datafile.
Expand Down Expand Up @@ -5310,8 +5302,8 @@ private void addAttachments(String[] att) {
}

/**
* This method retrieves the selected authors(s) from the jTableAuthors and adds
* them to the author-textfield of the entry.
* Gets the selected author(s) from the jTableAuthors and
* adds them to the author-textfield of the entry.
*/
@Action(enabledProperty = "tableEntriesSelected")
public void addAuthorToList() {
Expand Down Expand Up @@ -7382,8 +7374,8 @@ public boolean addToLuhmann(int[] entries) {
}

/**
* This method gets the selected entries from the current activated tab in
* the tabbed pane and adds them to the current item's bookmarks.
* This method rerieves the selected entries from the current activated tab in
* the tabbedpane and adds them to the bookmarks of the current entry.
*/
@Action(enabledProperty = "tableEntriesSelected")
public void addBookmarks() {
Expand Down Expand Up @@ -8428,11 +8420,9 @@ public void setNewActivatedEntryAndUpdateDisplay(int entryNumber) {
*/
public void setNewActivatedEntryAndUpdateDisplay(int entryNumber, UpdateDisplayOptions options) {
if (data.activateEntry(entryNumber)) {
// Reset displayedZettel.
displayedZettel = -1;
updateDisplay(options);
} else {
// This should never happen.
// Log a warning if the entry number is invalid
Constants.zknlogger.log(Level.WARNING,
"setNewActivatedEntryAndUpdateDisplay was called with invalid entry number: {0}", entryNumber);
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/de/danielluedecke/zettelkasten/database/Daten.java
Original file line number Diff line number Diff line change
Expand Up @@ -5056,21 +5056,25 @@ public void historyFore() {
activatedEntryNumber = history[historyPosition];
}
}

/**
* This method sets the currently activated entry to the given number. If number
* is invalid, returns false without any change.
* Sets the currently activated entry to the given number.
* If the number is invalid, returns false without any change.
*
* @param entryNumber the number of the entry which should be activated
* @return success or not
* @param entryNumber the number of the entry to activate
* @return true if the entry was successfully activated, false otherwise
*/
public boolean activateEntry(int entryNumber) {
// Check if the entry exists and is not deleted
if (!zettelExists(entryNumber) || isDeleted(entryNumber)) {
return false;
}

// Set the activated entry number
activatedEntryNumber = entryNumber;
// Update history.

// Update history with the new activated entry
addToHistory();

return true;
}

Expand Down
27 changes: 27 additions & 0 deletions src/main/java/playground/ButtonClickExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package playground;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonClickExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Button Click Example");
JButton button = new JButton("Click Me");

// Add an event handler for the button click action
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// This is the event handler method
System.out.println("Button was clicked!");
}
});

frame.add(button);
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

0 comments on commit 3e587db

Please sign in to comment.