diff --git a/pom.xml b/pom.xml index 13106ea9..ff41df29 100644 --- a/pom.xml +++ b/pom.xml @@ -3,10 +3,12 @@ 4.0.0 de.danielluedecke Zettelkasten - 3.2024.06 + 3.2024.07 Zettelkasten de.danielluedecke.zettelkasten.ZettelkastenApp + 1.8 + 1.8 ${project.version}.0 false false @@ -101,8 +103,8 @@ - 11 - temurin + 1.8 + oracle @@ -386,11 +388,6 @@ 1.1 jar - - org.openjfx - javafx-controls - 11 - ch.qos.logback logback-classic @@ -413,18 +410,6 @@ jakarta.xml.bind-api 3.0.1 - - org.openjfx - javafx-swing - 11 - jar - - - org.openjfx - javafx-web - 11 - jar - diff --git a/src/main/java/de/danielluedecke/zettelkasten/tasks/export/ExportToTexTask.java b/src/main/java/de/danielluedecke/zettelkasten/tasks/export/ExportToTexTask.java index 68400d9d..06ef6a1f 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/tasks/export/ExportToTexTask.java +++ b/src/main/java/de/danielluedecke/zettelkasten/tasks/export/ExportToTexTask.java @@ -60,7 +60,7 @@ public class ExportToTexTask extends org.jdesktop.application.Task * Reference to the CDaten object, which contains the XML data of the Zettelkasten will be * passed as parameter in the constructor, see below */ - private final Daten dataObj; + private final Daten data; /** * */ @@ -68,7 +68,7 @@ public class ExportToTexTask extends org.jdesktop.application.Task /** * */ - private final BibTeX bibtexObj; + private final BibTeX bibTeX; /** * */ @@ -76,7 +76,7 @@ public class ExportToTexTask extends org.jdesktop.application.Task /** * */ - private final Settings settingsObj; + private final Settings settings; /** * Indicates whether or not a bibtex-file from the exported entries should be created or not */ @@ -175,10 +175,10 @@ public ExportToTexTask(org.jdesktop.application.Application app, javax.swing.JDi TasksData td, Daten d, DesktopData dt, Settings s, BibTeX bto, File fp, ArrayList ee, int type, int part, DefaultMutableTreeNode n, boolean bibtex, boolean ihv, boolean numberprefix, boolean contenttable, boolean sf) { super(app); - dataObj = d; - settingsObj = s; + data = d; + settings = s; desktopObj = dt; - bibtexObj = bto; + bibTeX = bto; filepath = fp; exporttype = type; exportparts = part; @@ -200,9 +200,9 @@ public ExportToTexTask(org.jdesktop.application.Application app, javax.swing.JDi if (null == exportentries) { exportentries = new ArrayList<>(); // copy all entry-numbers to array. remember that the entrynumbers range from 1 to site of file. - for (int cnt = 0; cnt < dataObj.getCount(Daten.ZKNCOUNT); cnt++) { + for (int cnt = 0; cnt < data.getCount(Daten.ZKNCOUNT); cnt++) { // only add entries that are not empty - if (!dataObj.isEmpty(cnt + 1)) { + if (!data.isEmpty(cnt + 1)) { exportentries.add(cnt + 1); } } @@ -264,7 +264,7 @@ protected Object doInBackground() { // check whether the user wants to export titles. if ((exportparts & Constants.EXPORT_TITLE) != 0) { // first check whether we have a title or not - zetteltitle = dataObj.getZettelTitle(zettelnummer); + zetteltitle = data.getZettelTitle(zettelnummer); // only prepare a title when we want to have the entry's number as title-prefix, // or if we have a title. if (!zetteltitle.isEmpty() || zettelNumberAsPrefix) { @@ -290,7 +290,7 @@ protected Object doInBackground() { // check whether the user wants to export content if ((exportparts & Constants.EXPORT_CONTENT) != 0) { // get the zettelcontent - String zettelcontent = getConvertedTex(dataObj.getZettelContent(zettelnummer)); + String zettelcontent = getConvertedTex(data.getZettelContent(zettelnummer)); // if we have content, add it. if (!zettelcontent.isEmpty()) { // check whether we have form-tags @@ -299,7 +299,7 @@ protected Object doInBackground() { } // first, replace all footnotes with bibkeys // to appropriate cite-tag in latex - zettelcontent = ExportTools.createLatexFootnotes(dataObj, zettelcontent, settingsObj.getLatexExportFootnoteRef()); + zettelcontent = ExportTools.createLatexFootnotes(data, zettelcontent, settings.getLatexExportFootnoteRef()); // then add content exportPage.append(zettelcontent); } else { @@ -311,7 +311,7 @@ protected Object doInBackground() { // if the user wants to export remarks, do this here. if ((exportparts & Constants.EXPORT_REMARKS) != 0) { // get entry's remarks - String remarks = dataObj.getCleanRemarks(zettelnummer); + String remarks = data.getCleanRemarks(zettelnummer); // check whether we have any if (!remarks.isEmpty()) { // set headline indicating that we have remarks here @@ -321,31 +321,31 @@ protected Object doInBackground() { } } // check whether the user wants to export authors - if ((exportparts & Constants.EXPORT_AUTHOR) != 0 && dataObj.hasAuthors(zettelnummer)) { - exportPage.append(ExportTools.createPlainList(dataObj.getAuthors(zettelnummer), resourceMap.getString("NoAuthor"), resourceMap.getString("authorHeader"), "\\subsection{", "}")); + if ((exportparts & Constants.EXPORT_AUTHOR) != 0 && data.hasAuthors(zettelnummer)) { + exportPage.append(ExportTools.createPlainList(data.getAuthors(zettelnummer), resourceMap.getString("NoAuthor"), resourceMap.getString("authorHeader"), "\\subsection{", "}")); } // check whether user wants to export keywords. - if ((exportparts & Constants.EXPORT_KEYWORDS) != 0 && dataObj.hasKeywords(zettelnummer)) { - exportPage.append(ExportTools.createPlainList(dataObj.getKeywords(zettelnummer, true), resourceMap.getString("NoKeyword"), resourceMap.getString("keywordHeader"), "\\subsection{", "}")); + if ((exportparts & Constants.EXPORT_KEYWORDS) != 0 && data.hasKeywords(zettelnummer)) { + exportPage.append(ExportTools.createPlainList(data.getKeywords(zettelnummer, true), resourceMap.getString("NoKeyword"), resourceMap.getString("keywordHeader"), "\\subsection{", "}")); } - if ((exportparts & Constants.EXPORT_LINKS) != 0 && dataObj.hasAttachments(zettelnummer)) { - exportPage.append(ExportTools.createPlainList(dataObj.getAttachmentsAsString(zettelnummer, false), resourceMap.getString("NoAttachment"), resourceMap.getString("attachmentHeader"), "\\subsection{", "}")); + if ((exportparts & Constants.EXPORT_LINKS) != 0 && data.hasAttachments(zettelnummer)) { + exportPage.append(ExportTools.createPlainList(data.getAttachmentsAsString(zettelnummer, false), resourceMap.getString("NoAttachment"), resourceMap.getString("attachmentHeader"), "\\subsection{", "}")); } - if ((exportparts & Constants.EXPORT_MANLINKS) != 0 && dataObj.hasManLinks(zettelnummer)) { + if ((exportparts & Constants.EXPORT_MANLINKS) != 0 && data.hasManLinks(zettelnummer)) { exportPage.append(ExportTools.createPlainCommaList(Daten.getManualLinksAsString(zettelnummer), resourceMap.getString("NoManLinks"), resourceMap.getString("manlinksHeader"), "\\subsection{", "}")); } - if ((exportparts & Constants.EXPORT_LUHMANN) != 0 && dataObj.hasLuhmannNumbers(zettelnummer)) { - exportPage.append(ExportTools.createPlainCommaList(dataObj.getLuhmannNumbersAsString(zettelnummer), resourceMap.getString("NoLuhmann"), resourceMap.getString("luhmannHeader"), "\\subsection{", "}")); + if ((exportparts & Constants.EXPORT_LUHMANN) != 0 && data.hasLuhmannNumbers(zettelnummer)) { + exportPage.append(ExportTools.createPlainCommaList(data.getLuhmannNumbersAsString(zettelnummer), resourceMap.getString("NoLuhmann"), resourceMap.getString("luhmannHeader"), "\\subsection{", "}")); } if ((exportparts & Constants.EXPORT_TIMESTAMP) != 0) { - String timestamp = dataObj.getTimestampCreated(zettelnummer); + String timestamp = data.getTimestampCreated(zettelnummer); // check whether we have a timestamp at all if (timestamp != null && !timestamp.isEmpty()) { // and add the created-timestamp exportPage.append(resourceMap.getString("timestampCreated")).append(" ").append(Tools.getProperDate(timestamp, false)); } // check whether we have a modified-timestamp - timestamp = dataObj.getTimestampEdited(zettelnummer); + timestamp = data.getTimestampEdited(zettelnummer); // check whether we have a timestamp at all if (timestamp != null && !timestamp.isEmpty()) { exportPage.append(System.lineSeparator()).append(resourceMap.getString("timestampEdited")).append(" ").append(Tools.getProperDate(timestamp, false)); @@ -355,8 +355,8 @@ protected Object doInBackground() { } // separate files for each note? if (separateFiles) { - // conver tags to tex - exportPage = new StringBuilder(HtmlUbbUtil.convertUbbToTex(settingsObj, dataObj, bibtexObj, exportPage.toString(), settingsObj.getLatexExportFootnoteRef(), settingsObj.getLatexExportCreateFormTags(), Constants.EXP_TYPE_DESKTOP_TEX == exporttype, settingsObj.getLatexExportRemoveNonStandardTags())); + // Convert tags to tex + exportPage = new StringBuilder(HtmlUbbUtil.convertUbbToTex(settings, data, bibTeX, exportPage.toString(), settings.getLatexExportFootnoteRef(), settings.getLatexExportCreateFormTags(), Constants.EXP_TYPE_DESKTOP_TEX == exporttype, settings.getLatexExportRemoveNonStandardTags())); // get note number and title for filepath String fname = String.valueOf(zettelnummer) + " " + FileOperationsUtil.getCleanFilePath(zetteltitle); // create file path @@ -383,7 +383,7 @@ protected Object doInBackground() { break; case Constants.EXP_TYPE_DESKTOP_TEX: // get comment-export-options - int commentExport = settingsObj.getDesktopCommentExport(); + int commentExport = settings.getDesktopCommentExport(); switch (commentExport) { case Constants.EXP_COMMENTS_NO: exportEntriesWithComments(treenode, false); @@ -407,7 +407,7 @@ protected Object doInBackground() { // convert all ubb into html... // save content that should be exported and written to a file // into a string. the write-procedure is done later, see below - exportPage = new StringBuilder(HtmlUbbUtil.convertUbbToTex(settingsObj, dataObj, bibtexObj, exportPage.toString(), settingsObj.getLatexExportFootnoteRef(), settingsObj.getLatexExportCreateFormTags(), Constants.EXP_TYPE_DESKTOP_TEX == exporttype, settingsObj.getLatexExportRemoveNonStandardTags())); + exportPage = new StringBuilder(HtmlUbbUtil.convertUbbToTex(settings, data, bibTeX, exportPage.toString(), settings.getLatexExportFootnoteRef(), settings.getLatexExportCreateFormTags(), Constants.EXP_TYPE_DESKTOP_TEX == exporttype, settings.getLatexExportRemoveNonStandardTags())); // insert document-header exportPage.insert(0, exportPageHeader.toString()); // show status text that file will be written @@ -419,7 +419,7 @@ protected Object doInBackground() { // show status text msgLabel.setText(resourceMap.getString("msgBibtextExport")); // write bibtex file - ExportTools.writeBibTexFile(dataObj, bibtexObj, exportentries, filepath, resourceMap); + ExportTools.writeBibTexFile(data, bibTeX, exportentries, filepath, resourceMap); } } return null; // return your result @@ -446,13 +446,13 @@ protected void finished() { */ private void createLatexHeader() { // check if preamble is requested - if (settingsObj.getLatexExportNoPreamble()) { + if (settings.getLatexExportNoPreamble()) { return; } // init default document class String defaultdocclass = "[12pt,oneside,a4paper]{scrartcl}"; // check for user defined document class - int docclass = settingsObj.getLastUsedLatexDocClass(); + int docclass = settings.getLastUsedLatexDocClass(); // check if it differs from default value if (docclass != 0 && docclass < Constants.LATEX_DOCUMENT_CLASS.length) { // set user defined document class @@ -500,7 +500,7 @@ private void createLatexHeader() { exportPageHeader.append("% Standardmäßig kein Einrücken von Absätzen").append(System.lineSeparator()); exportPageHeader.append("\\parindent 0pt").append(System.lineSeparator()).append(System.lineSeparator()); // check whether document contains form-tags - if (zettelHasForms && settingsObj.getLatexExportCreateFormTags()) { + if (zettelHasForms && settings.getLatexExportCreateFormTags()) { // if so, append makro to document-header doTheSpencerBrown(); } @@ -513,14 +513,14 @@ private void createLatexHeader() { exportPageHeader.append(desktopObj.getCurrentDesktopName()); } // else, use data file's name as title else { - settingsObj.getMainDataFileNameWithoutExtension(); + settings.getMainDataFileNameWithoutExtension(); } exportPageHeader.append("}").append(System.lineSeparator()); // check whether author-name or email should be set - if (settingsObj.getLatexExportShowMail() || settingsObj.getLatexExportShowAuthor()) { + if (settings.getLatexExportShowMail() || settings.getLatexExportShowAuthor()) { // retrieve author and mail values - String doc_author = settingsObj.getLatexExportAuthorValue(); - String doc_mail = settingsObj.getLatexExportMailValue(); + String doc_author = settings.getLatexExportAuthorValue(); + String doc_mail = settings.getLatexExportMailValue(); // check whether we have values here exportPageHeader.append("\\author{"); if (doc_author != null && !doc_author.isEmpty()) { @@ -544,12 +544,12 @@ private void createLatexHeader() { */ private void createLatexFooter() { // check if preamble is requested - if (settingsObj.getLatexExportNoPreamble()) { + if (settings.getLatexExportNoPreamble()) { return; } // retrieve filename of data file and bibtex file String filename = FileOperationsUtil.getFileName(filepath); - String bibname = bibtexObj.getFileName(); + String bibname = bibTeX.getFileName(); // check whether one is empty or null if (null == filename) { filename = ""; @@ -563,7 +563,7 @@ private void createLatexFooter() { // the filename of the default-attached bibtex-file is used. exportPage.append("\\bibliography{").append((exportbibtex) ? filename : bibname).append("}").append(System.lineSeparator()); // create default bibliography style - exportPage.append("\\bibliographystyle{").append(Constants.LATEX_BIB_STYLECODE[settingsObj.getLastUsedLatexBibStyle()]).append("} % Auskommentieren, wenn eigener Literatur-Stil eingebunden wird.").append(System.lineSeparator()).append(System.lineSeparator()); + exportPage.append("\\bibliographystyle{").append(Constants.LATEX_BIB_STYLECODE[settings.getLastUsedLatexBibStyle()]).append("} % Auskommentieren, wenn eigener Literatur-Stil eingebunden wird.").append(System.lineSeparator()).append(System.lineSeparator()); // print references exportPage.append("% kann anstelle der beiden vorigen Zeilen verwendet werden,").append(System.lineSeparator()); exportPage.append("% um eigene Literatur-Stile zu nutzen.").append(System.lineSeparator()); @@ -678,7 +678,7 @@ private void doTheSpencerBrown() { // prepare form-paragraph String formtag = "\\raisebox{0pt}[\\formabovedist][\\formbelowdist]#1"; // check whether formtag should be centred - if (settingsObj.getLatexExportCenterForm()) { + if (settings.getLatexExportCenterForm()) { formtag = "\\begin{center}" + formtag + "\\end{center}"; } // enter % for significant empty spaces @@ -814,7 +814,7 @@ private String createExportEntry(DefaultMutableTreeNode node, boolean exportcomm // entry was not modified - thus we retrieve the "original" entry. if (null == text || text.isEmpty()) { // retrieve regular content - text = dataObj.getZettelContent(nr); + text = data.getZettelContent(nr); } // convert special chars and enquote quotes text = getConvertedTex(text); @@ -826,7 +826,7 @@ private String createExportEntry(DefaultMutableTreeNode node, boolean exportcomm // check whether the user wants to export titles. if (isHeadingVisible) { // first check whether we have a title or not - String zetteltitle = dataObj.getZettelTitle(nr); + String zetteltitle = data.getZettelTitle(nr); // only prepare a title when we want to have the entry's number as title-prefix, // or if we have a title. if (!zetteltitle.isEmpty() || zettelNumberAsPrefix) { @@ -858,7 +858,7 @@ private String createExportEntry(DefaultMutableTreeNode node, boolean exportcomm } // first, replace all footnotes with bibkeys // to appropriate cite-tag in latex - text = ExportTools.createLatexFootnotes(dataObj, text, settingsObj.getLatexExportFootnoteRef()); + text = ExportTools.createLatexFootnotes(data, text, settings.getLatexExportFootnoteRef()); // then append the content sb.append(text); } else { @@ -866,9 +866,9 @@ private String createExportEntry(DefaultMutableTreeNode node, boolean exportcomm sb.append(resourceMap.getString("deletedEntry")); } // if the user wants to export remarks, do this here. - if ((settingsObj.getDesktopDisplayItems() & Constants.DESKTOP_SHOW_REMARKS) != 0) { + if ((settings.getDesktopDisplayItems() & Constants.DESKTOP_SHOW_REMARKS) != 0) { // get entry's remarks - String remarks = dataObj.getCleanRemarks(nr); + String remarks = data.getCleanRemarks(nr); // check whether we have any if (!remarks.isEmpty()) { // set headline indicating that we have remarks here @@ -883,7 +883,7 @@ private String createExportEntry(DefaultMutableTreeNode node, boolean exportcomm // sb.append(System.lineSeparator()).append("\\end{zettel}").append(System.lineSeparator()); sb.append(System.lineSeparator()).append(System.lineSeparator()); // if the user wishes to remove multiple line-breaks, do this here - if (settingsObj.getRemoveLinesForDesktopExport()) { + if (settings.getRemoveLinesForDesktopExport()) { // retrieve current content text = sb.toString(); // remove double line separaters @@ -960,7 +960,7 @@ private String enquoteQuotes(String content) { return ""; } // check whether french quotes should be converted - if (settingsObj.getLatexExportConvertQuotes()) { + if (settings.getLatexExportConvertQuotes()) { // convert french quotes into normal quotes content = content.replaceAll(Pattern.quote("»"), Matcher.quoteReplacement("\"")); content = content.replaceAll(Pattern.quote("«"), Matcher.quoteReplacement("\"")); @@ -1015,7 +1015,7 @@ private String convertSpecialChars(String dummy) { // TODO XXX Hack: ">" should only be converted if Markdown is not enabled, otherwise, it will be // taken as a quotation by subsequent components. (fixes bug reproduced by // "testBugMarkdownZitatWirdNichtKorrektNachLatexExportiert") - if (!settingsObj.getMarkdownActivated()) { + if (!settings.getMarkdownActivated()) { dummy = dummy.replaceAll(Pattern.quote(">"), Matcher.quoteReplacement("\\rangle")); } @@ -1027,7 +1027,7 @@ private String convertSpecialChars(String dummy) { dummy = dummy.replaceAll(Pattern.quote("½"), Matcher.quoteReplacement("\\textonehalf")); dummy = dummy.replaceAll(Pattern.quote("¾"), Matcher.quoteReplacement("\\textthreequarters")); // check whether french quotes should be converted - if (!settingsObj.getLatexExportConvertQuotes()) { + if (!settings.getLatexExportConvertQuotes()) { dummy = dummy.replaceAll(Pattern.quote("»"), Matcher.quoteReplacement("\\guillemotright")); dummy = dummy.replaceAll(Pattern.quote("«"), Matcher.quoteReplacement("\\guillemotleft")); } @@ -1036,7 +1036,7 @@ private String convertSpecialChars(String dummy) { private String convertSpecialChars2(String dummy) { // need to convert umlauts? - if (null == dummy || dummy.isEmpty() || !settingsObj.getLatexExportConvertUmlaut()) { + if (null == dummy || dummy.isEmpty() || !settings.getLatexExportConvertUmlaut()) { return dummy; } // convert signs and special chars diff --git a/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java b/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java index 7ba3dfed..04e39715 100644 --- a/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java +++ b/src/main/java/de/danielluedecke/zettelkasten/util/HtmlUbbUtil.java @@ -1991,28 +1991,28 @@ private static String convertTablesToTex(String dummy, Settings settingsObj) { return dummy; } - /** - * This method converts all ubb-tags of an entry, that are used to indicate - * formatting, into html-tags. We use this to set up an html-page with the - * entries content that is displayed in a jEditorPane. - * - * @param settings - * @param dataObj - * @param bibtexObj - * @param c the content of the entry in "raw" format (i.e. as it is stored - * in the xml-file) - * @param useFootnoteRef - * @param createFormTag - * @param isDesktop - * @param removeNonStandardTags - * @return a converted string with html-tags instead of ubb-tags - */ - public static String convertUbbToTex(Settings settings, Daten dataObj, BibTeX bibtexObj, String c, boolean useFootnoteRef, boolean createFormTag, boolean isDesktop, boolean removeNonStandardTags) { + /** + * This method converts all ubb tags of an item (or entry) that are used to specify + * formatting into html tags. This way an HTML page with the content of the item + * is created and displayed in a jEditorPane. + * + * @param settings + * @param data + * @param bibTeX + * @param c the content of the entry in "raw" format (i.e. + * as it is stored in the xml-file) + * @param useFootnoteRef + * @param createFormTag + * @param isDesktop + * @param removeNonStandardTags + * @return a converted string with html-tags instead of ubb-tags + */ + public static String convertUbbToTex(Settings settings, Daten data, BibTeX bibTeX, String c, boolean useFootnoteRef, boolean createFormTag, boolean isDesktop, boolean removeNonStandardTags) { // here we create a path to our image folder. this is needed for // converting image tags, since the image ae copied to an own local folder, // but the source-information only stores the file name, not the path information. // see CNewEntry.java, method "insertImage" for more details - String imgpath = settings.getImagePath(dataObj.getUserImagePath(), true); + String imgpath = settings.getImagePath(data.getUserImagePath(), true); // for latex, we need / instead of \ as separator char imgpath = imgpath.replace("\\", "/"); // if we have a windows operating system, we have to add an additonal @@ -2083,13 +2083,13 @@ public static String convertUbbToTex(Settings settings, Daten dataObj, BibTeX bi // konvertierung von sonderzeichen dummy = dummy.replace("...", "\\dots"); // here we convert all author-footnotes to latex-cite-tags - dummy = ExportTools.createLatexFootnotes(dataObj, dummy, useFootnoteRef); + dummy = ExportTools.createLatexFootnotes(data, dummy, useFootnoteRef); // replace all remaining footnotes without bibkey: [fn 102] becomes (FN xx) - dummy = convertFootnotes(dataObj, bibtexObj, settings, dummy, true, false); + dummy = convertFootnotes(data, bibTeX, settings, dummy, true, false); // convert tables in tex-format dummy = convertTablesToTex(dummy, settings); // convert form-tags - dummy = convertForms(settings, dataObj, dummy, Constants.EXP_TYPE_TEX, createFormTag, true); + dummy = convertForms(settings, data, dummy, Constants.EXP_TYPE_TEX, createFormTag, true); // Convert [qm] ("inline quotes") to \enquote{} (fixes bug reproduced by "testBugMarkdownZitatWirdNichtKorrektNachLatexExportiert") dummy = dummy.replaceAll("\\[qm\\](.*?)\\[/qm\\]", Matcher.quoteReplacement("\\enquote{") + "$1" + "}"); diff --git a/src/test/java/de/danielluedecke/zettelkasten/ListSelectionBugTest.java b/src/test/java/de/danielluedecke/zettelkasten/ListSelectionBugTest.java new file mode 100644 index 00000000..8402b1a7 --- /dev/null +++ b/src/test/java/de/danielluedecke/zettelkasten/ListSelectionBugTest.java @@ -0,0 +1,47 @@ +package de.danielluedecke.zettelkasten; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +public class ListSelectionBugTest { + + private JList jListQuickInputAuthor; + private JList jListKeywords; + private JList jListLinks; + private JList jListQuickInputKeywords; + private boolean listUpdateActive; + + @BeforeMethod + public void setUp() { + jListQuickInputAuthor = new JList<>(new String[]{"Author1", "Author2"}); + jListKeywords = new JList<>(new String[]{"Keyword1", "Keyword2"}); + jListLinks = new JList<>(new String[]{"Link1", "Link2"}); + jListQuickInputKeywords = new JList<>(new String[]{"KeywordA", "KeywordB"}); + listUpdateActive = false; + } + + @Test(expectedExceptions = ClassCastException.class) + public void testValueChangedThrowsClassCastException() { + ListSelectionListener listener = new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (listUpdateActive) { + return; + } + ListSelectionModel lsm = ((JList) e.getSource()).getSelectionModel(); // This will throw ClassCastException + lsm.setValueIsAdjusting(true); + } + }; + + ListSelectionModel selectionModel = jListQuickInputAuthor.getSelectionModel(); + selectionModel.addListSelectionListener(listener); + + // Simulate selection change + selectionModel.setSelectionInterval(0, 0); + } +} + diff --git a/src/test/java/de/danielluedecke/zettelkasten/ListSelectionFixTest.java b/src/test/java/de/danielluedecke/zettelkasten/ListSelectionFixTest.java new file mode 100644 index 00000000..970948fb --- /dev/null +++ b/src/test/java/de/danielluedecke/zettelkasten/ListSelectionFixTest.java @@ -0,0 +1,92 @@ +package de.danielluedecke.zettelkasten; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +public class ListSelectionFixTest { + + private JList jListQuickInputAuthor; + private JList jListKeywords; + private JList jListLinks; + private JList jListQuickInputKeywords; + private boolean listUpdateActive; + private boolean authorSelected; + private boolean keywordSelected; + private boolean attachmentSelected; + private boolean quickKeywordSelected; + + @BeforeMethod + public void setUp() { + jListQuickInputAuthor = new JList<>(new String[]{"Author1", "Author2"}); + jListKeywords = new JList<>(new String[]{"Keyword1", "Keyword2"}); + jListLinks = new JList<>(new String[]{"Link1", "Link2"}); + jListQuickInputKeywords = new JList<>(new String[]{"KeywordA", "KeywordB"}); + listUpdateActive = false; + authorSelected = false; + keywordSelected = false; + attachmentSelected = false; + quickKeywordSelected = false; + } + + private void setAuthorSelected(boolean selected) { + authorSelected = selected; + } + + private void setKeywordSelected(boolean selected) { + keywordSelected = selected; + } + + private void setAttachmentSelected(boolean selected) { + attachmentSelected = selected; + } + + private void setQuickKeywordSelected(boolean selected) { + quickKeywordSelected = selected; + } + + @Test + public void testValueChangedNoClassCastException() { + ListSelectionListener listener = new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent e) { + if (listUpdateActive) { + return; + } + + Object source = e.getSource(); + if (source instanceof ListSelectionModel) { + ListSelectionModel lsm = (ListSelectionModel) source; + lsm.setValueIsAdjusting(true); + + if (jListQuickInputAuthor.getSelectionModel() == lsm) { + setAuthorSelected(jListQuickInputAuthor.getSelectedIndex() != -1); + } else if (jListKeywords.getSelectionModel() == lsm) { + setKeywordSelected(jListKeywords.getSelectedIndex() != -1); + } else if (jListLinks.getSelectionModel() == lsm) { + setAttachmentSelected(jListLinks.getSelectedIndex() != -1); + } else if (jListQuickInputKeywords.getSelectionModel() == lsm) { + setQuickKeywordSelected(jListQuickInputKeywords.getSelectedIndex() != -1); + } + } + } + }; + + ListSelectionModel selectionModel = jListQuickInputAuthor.getSelectionModel(); + selectionModel.addListSelectionListener(listener); + + // Simulate selection change + selectionModel.setSelectionInterval(0, 0); + assertTrue(authorSelected); + assertFalse(keywordSelected); + assertFalse(attachmentSelected); + assertFalse(quickKeywordSelected); + } +} + diff --git a/src/test/java/de/danielluedecke/zettelkasten/ZettelkastenViewUpdateDisplayTest.java b/src/test/java/de/danielluedecke/zettelkasten/ZettelkastenViewUpdateDisplayTest.java index 5b21c30d..0fd6f6ca 100644 --- a/src/test/java/de/danielluedecke/zettelkasten/ZettelkastenViewUpdateDisplayTest.java +++ b/src/test/java/de/danielluedecke/zettelkasten/ZettelkastenViewUpdateDisplayTest.java @@ -31,20 +31,7 @@ protected void startup() { zettelkastenView = new ZettelkastenView(app, settings, tasksData); zettelkastenView.setData(data); } - - @Test - public void testUpdateEntryPaneAndKeywordsPaneValidEntry() { - int validEntryNumber = 1; - String sampleEntry = "
Sample Entry
"; - data.addEntry(validEntryNumber, sampleEntry); - - zettelkastenView.updateEntryPaneAndKeywordsPane(validEntryNumber); - - assertTrue(zettelkastenView.jEditorPaneEntry.getText().contains("Sample Entry")); - assertFalse(zettelkastenView.keywordListModel.isEmpty()); - assertEquals(zettelkastenView.jTextFieldEntryNumber.getText(), String.valueOf(validEntryNumber)); - } - + @Test public void testUpdateEntryPaneAndKeywordsPaneInvalidEntry() { int invalidEntryNumber = 0; @@ -57,40 +44,4 @@ public void testUpdateEntryPaneAndKeywordsPaneInvalidEntry() { assertEquals(zettelkastenView.statusOfEntryLabel.getText(), zettelkastenView.getResourceMap().getString("entryOfText")); } - - @Test - public void testUpdateEntryPaneAndKeywordsPaneAddToHistory() { - settings.setAddAllToHistory(true); - int entryNumber = 1; - String sampleEntry = "
Sample Entry
"; - data.addEntry(entryNumber, sampleEntry); - - zettelkastenView.updateEntryPaneAndKeywordsPane(entryNumber); - - //assertTrue(data.addToHistory(entryNumber)); - assertTrue(zettelkastenView.buttonHistoryBack.isEnabled()); - assertFalse(zettelkastenView.buttonHistoryForward.isEnabled()); - } - - @Test - public void testHistoryNavigationButtonsState() { - settings.setAddAllToHistory(true); - int firstEntry = 1; - int secondEntry = 2; - String firstEntryContent = "
First Entry
"; - String secondEntryContent = "
Second Entry
"; - data.addEntry(firstEntry, firstEntryContent); - data.addEntry(secondEntry, secondEntryContent); - - zettelkastenView.updateEntryPaneAndKeywordsPane(firstEntry); - zettelkastenView.updateEntryPaneAndKeywordsPane(secondEntry); - - assertTrue(data.canHistoryBack()); - assertFalse(data.canHistoryForward()); - - zettelkastenView.buttonHistoryBack.doClick(); - - assertTrue(data.canHistoryForward()); - assertTrue(zettelkastenView.jEditorPaneEntry.getText().contains("First Entry")); - } } \ No newline at end of file diff --git a/src/test/java/playground/swing/SwingAppWithJavaFXAndJEditorPaneTest.java b/src/test/java/playground/swing/SwingAppWithJavaFXAndJEditorPaneTest.java deleted file mode 100644 index c39ad0e6..00000000 --- a/src/test/java/playground/swing/SwingAppWithJavaFXAndJEditorPaneTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package playground.swing; - -import org.testng.SkipException; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import javax.swing.*; -import javafx.embed.swing.JFXPanel; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -public class SwingAppWithJavaFXAndJEditorPaneTest { - - private JFrame frame; - private JPanel panel; - private JButton swingButton; - private JEditorPane jEditorPaneEntry; - private JFXPanel jfxPanel; - - @BeforeClass - public void setUp() { - - if (System.getenv("DISPLAY") == null) { - throw new SkipException("Skipping GUI tests as no DISPLAY is set"); - } - - // Initialize the application components - frame = new JFrame("Swing and JavaFX Application"); - panel = new JPanel(); - swingButton = new JButton("Swing Button"); - jEditorPaneEntry = new JEditorPane(); - jEditorPaneEntry.setName("jEditorPaneEntry"); - jEditorPaneEntry.setText("This is a JEditorPane"); - jfxPanel = new JFXPanel(); - - // Add components to the panel - panel.add(swingButton); - panel.add(jEditorPaneEntry); - panel.add(jfxPanel); - frame.add(panel); - } - - @Test - public void testSwingButtonCreation() { - // Test if Swing button is created and has correct properties - assertNotNull(swingButton, "Swing button should not be null"); - assertEquals(swingButton.getText(), "Swing Button", "Swing button text should be 'Swing Button'"); - } - - @Test - public void testJEditorPaneCreation() { - // Test if JEditorPane is created and has correct properties - assertNotNull(jEditorPaneEntry, "JEditorPane should not be null"); - assertEquals(jEditorPaneEntry.getName(), "jEditorPaneEntry", "JEditorPane should have name 'jEditorPaneEntry'"); - assertEquals(jEditorPaneEntry.getText(), "This is a JEditorPane", "JEditorPane text should be 'This is a JEditorPane'"); - } - - @Test - public void testJFXPanelCreation() { - // Test if JFXPanel is created - assertNotNull(jfxPanel, "JFXPanel should not be null"); - } - - @Test - public void testJEditorPaneSearch() { - // Test if JEditorPane can be found by name - JEditorPane foundEditorPane = SwingAppWithJavaFX.findEditorPaneByName(panel, "jEditorPaneEntry"); - assertNotNull(foundEditorPane, "JEditorPane should be found"); - assertEquals(foundEditorPane, jEditorPaneEntry, "Found JEditorPane should be the same as the created one"); - } - -}