diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/libraries/checkstyle_all_4_3.xml b/.idea/libraries/checkstyle_all_4_3.xml
new file mode 100644
index 0000000..60dafeb
--- /dev/null
+++ b/.idea/libraries/checkstyle_all_4_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml
new file mode 100644
index 0000000..f97f788
--- /dev/null
+++ b/.idea/libraries/lib.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..6f29fee
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..9121378
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/checkstyle_config/checkstyle_config.iml b/checkstyle_config/checkstyle_config.iml
new file mode 100644
index 0000000..e97b9cb
--- /dev/null
+++ b/checkstyle_config/checkstyle_config.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/checkstyle_config/src/jmemorize/checks/ExceptionLoggedCheck.java b/checkstyle_config/src/jmemorize/checks/ExceptionLoggedCheck.java
index 0958386..7f1e545 100644
--- a/checkstyle_config/src/jmemorize/checks/ExceptionLoggedCheck.java
+++ b/checkstyle_config/src/jmemorize/checks/ExceptionLoggedCheck.java
@@ -83,7 +83,7 @@ public void visitToken(DetailAST ast)
} else if (ast.getType() == TokenTypes.LITERAL_ASSERT &&
catchDepth == 1) {
DetailAST childAst = ast.findFirstToken(TokenTypes.EXPR);
- if (childAst != null || childAst.getNumberOfChildren() == 1) {
+ if (childAst != null && childAst.getNumberOfChildren() == 1) {
DetailAST grandchildAst = childAst.findFirstToken(TokenTypes.LITERAL_FALSE);
if (grandchildAst != null) {
hasAssert = true;
diff --git a/jMemorize.iml b/jMemorize.iml
new file mode 100644
index 0000000..fb8e866
--- /dev/null
+++ b/jMemorize.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/jmemorize/core/Card.java b/src/jmemorize/core/Card.java
index d6cf17e..46c252f 100644
--- a/src/jmemorize/core/Card.java
+++ b/src/jmemorize/core/Card.java
@@ -20,6 +20,7 @@
import java.util.Date;
import java.util.List;
+import java.util.Objects;
import jmemorize.core.CardSide.CardSideObserver;
@@ -233,11 +234,14 @@ public Date getDateExpired()
/**
* @param date can be null.
*/
- public void setDateExpired(Date date) // CHECK should this throw a event?
- {
+ public void setDateExpired(Date date) throws IllegalArgumentException {
+ if (date.before(m_dateCreated)) {
+ throw new IllegalArgumentException("Expiration date cannot be before the creation date of the card.");
+ }
m_dateExpired = cloneDate(date);
}
+
/**
* @return the creation date. Is never null.
*/
@@ -248,10 +252,7 @@ public Date getDateCreated()
public void setDateCreated(Date date)
{
- if (date == null)
- throw new NullPointerException();
-
- m_dateCreated = cloneDate(date);
+ m_dateCreated = Objects.requireNonNull(date, "Date cannot be null");
}
/**
@@ -441,9 +442,12 @@ public Card cloneWithoutProgress()
/**
* @see java.lang.Object#toString()
*/
- public String toString()
- {
- return "("+m_frontSide+"/"+m_backSide+")";
+ public String toString() {
+ if (m_dateExpired != null) {
+ return "(" + m_frontSide + "/" + m_backSide + " - Expires: " + m_dateExpired + ")";
+ } else {
+ return "(" + m_frontSide + "/" + m_backSide + ")";
+ }
}
private void attachCardSideObservers()
diff --git a/src/jmemorize/core/Main.java b/src/jmemorize/core/Main.java
index 2c6f185..23016d1 100644
--- a/src/jmemorize/core/Main.java
+++ b/src/jmemorize/core/Main.java
@@ -27,11 +27,7 @@
import java.io.StringWriter;
import java.net.URL;
import java.nio.channels.FileChannel;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Observable;
-import java.util.Properties;
+import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
@@ -445,7 +441,7 @@ public static Logger getLogger()
// we have more information about the exception there.
public static void logThrowable(String msg, Throwable t)
{
- if (t != null && m_lastLoggedThrowable != t)
+ if (t != null && !Objects.equals(m_lastLoggedThrowable, t))
{
m_lastLoggedThrowable = t;
logger.severe(msg);
diff --git a/src/jmemorize/core/SearchTool.java b/src/jmemorize/core/SearchTool.java
index 39c8256..77092fa 100644
--- a/src/jmemorize/core/SearchTool.java
+++ b/src/jmemorize/core/SearchTool.java
@@ -18,9 +18,7 @@
*/
package jmemorize.core;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
/**
* @author djemili
@@ -30,7 +28,9 @@ public class SearchTool
public final static int FRONT_SIDE = 0;
public final static int FLIP_SIDE = 1;
public final static int BOTH_SIDES = 2;
-
+ private static List searchHistory = new ArrayList<>();
+
+
public static List search(String text, int side, boolean matchCase, List cards)
{
List foundCards = new LinkedList();
@@ -87,4 +87,55 @@ public static List search(String text, String searchtext,
return positions;
}
+
+ public static void addToSearchHistory(String query) {
+ searchHistory.add(query);
+ }
+
+ public static List getSearchHistory() {
+ return searchHistory;
+ }
+
+ public static List searchWithinCategory(String text, int side, boolean matchCase, Category category) {
+ List foundCards = new LinkedList();
+ List cards = category.getCards(); // Assuming Category class has a method to get cards
+
+ for (Card card : cards) {
+ String frontSide = card.getFrontSide().getText().getUnformatted();
+ String flipSide = card.getBackSide().getText().getUnformatted();
+
+ if (!matchCase) {
+ text = text.toLowerCase();
+ frontSide = frontSide.toLowerCase();
+ flipSide = flipSide.toLowerCase();
+ }
+
+ if (side == FRONT_SIDE || side == BOTH_SIDES) {
+ if (frontSide.indexOf(text) > -1) {
+ foundCards.add(card);
+ continue;
+ }
+ }
+
+ if (side == FLIP_SIDE || side == BOTH_SIDES) {
+ if (flipSide.indexOf(text) > -1) {
+ foundCards.add(card);
+ }
+ }
+ }
+ return foundCards;
+ }
+
+ public static void sortByRelevance(List foundCards) {
+ // Sort by relevance criteria
+ Collections.sort(foundCards, new Comparator() {
+ @Override
+ public int compare(Card card1, Card card2) {
+ // Implement comparison logic based on relevance
+ // Return -1 if card1 is more relevant, 1 if card2 is more relevant, 0 if equal
+ return 0; // Placeholder, implement actual logic
+ }
+ });
+ }
+
}
diff --git a/src/jmemorize/gui/swing/actions/file/AbstractExportAction.java b/src/jmemorize/gui/swing/actions/file/AbstractExportAction.java
index 3063332..01fb207 100644
--- a/src/jmemorize/gui/swing/actions/file/AbstractExportAction.java
+++ b/src/jmemorize/gui/swing/actions/file/AbstractExportAction.java
@@ -1,7 +1,7 @@
/*
* jMemorize - Learning made easy (and fun) - A Leitner flashcards tool
* Copyright(C) 2004-2008 Riad Djemili and contributors
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
@@ -41,81 +41,78 @@ public abstract class AbstractExportAction extends AbstractSessionDisabledAction
/**
* Displays a Save As or Export dialog, and to confirm overwrites,
* and to attach specified file extension.
- *
+ *
* @return the file path or null if the dialog was cancelled.
- *
+ *
* @author Perry (elsapo)
* @author djemili
*/
- public static File showSaveDialog(JFrame frame, ExtensionFileFilter fileFilter)
- {
+ public static File showSaveDialog(JFrame frame, ExtensionFileFilter fileFilter) {
JFileChooser chooser = new JFileChooser();
-
- try
- {
+
+ try {
chooser.setCurrentDirectory(Settings.loadLastDirectory());
- }
- catch (Exception ioe)
- {
+ } catch (Exception ioe) {
Main.logThrowable("Could not load last directory", ioe);
chooser.setCurrentDirectory(null);
- }
-
+ }
+
chooser.setFileFilter(fileFilter);
-
+ File file = null;
+ boolean confirmed = false;
// Loop so we can prompt again if they choose not to overwrite
- while (true)
- {
+ while (!confirmed) {
// Do the actual Save As prompt
int choice = chooser.showSaveDialog(frame);
if (choice != JFileChooser.APPROVE_OPTION)
- return null;
+ break;
- File file = chooser.getSelectedFile();
+ file = chooser.getSelectedFile();
// Attach desired extension, if supplied
String extension = fileFilter.getExtension();
- if (extension.length() > 0 && !file.getName().endsWith(extension))
- {
+ if (extension.length() > 0 && !file.getName().endsWith(extension)) {
file = new File(file.getAbsolutePath() + '.' + extension);
chooser.setSelectedFile(file);
}
-
- if (file.exists())
- {
+
+ if (file.exists()) {
// Prompt to confirm they actually want to overwrite existing file
String text = Localization.get("MainFrame.CONFIRM_OVERWRITE");
String title = Localization.get("MainFrame.CONFIRM_OVERWRITE_TITLE");
-
- int act = JOptionPane.showConfirmDialog(frame,
- text + " " + file.toString(),
- title,
- JOptionPane.YES_NO_OPTION);
-
+
+ int act = JOptionPane.showConfirmDialog(frame,
+ text + " " + file.toString(),
+ title,
+ JOptionPane.YES_NO_OPTION);
+
if (act == JOptionPane.NO_OPTION)
continue;
}
-
+ confirmed = true;
+ }
+
+ if (confirmed) {
Settings.storeLastDirectory(file);
return file;
+ } else {
+ return null;
}
}
-
-
/* (non-Javadoc)
* @see java.awt.event.ActionListener
*/
public void actionPerformed(ActionEvent event)
{
Main main = Main.getInstance();
-
- File file = null;
+
+ File file = null;
try
{
file = showSaveDialog(main.getFrame(), getFileFilter());
if (file != null)
doExport(main.getLesson(), file);
-
+
}
catch (IOException e)
{
@@ -128,7 +125,7 @@ public void actionPerformed(ActionEvent event)
new ErrorDialog(main.getFrame(), msg, e).setVisible(true);
}
}
-
+
abstract protected void doExport(Lesson lesson, File file) throws IOException;
abstract protected ExtensionFileFilter getFileFilter();
}
diff --git a/src/jmemorize/gui/swing/dialogs/ErrorDialog.java b/src/jmemorize/gui/swing/dialogs/ErrorDialog.java
index 12a25c1..1b1053a 100644
--- a/src/jmemorize/gui/swing/dialogs/ErrorDialog.java
+++ b/src/jmemorize/gui/swing/dialogs/ErrorDialog.java
@@ -169,7 +169,7 @@ private JPanel buildMainPanel()
private JPanel buildButtonBar()
{
// buttons
- m_okayButton = new JButton(Localization.get(LC.OKAY));
+ JButton okayButton = new JButton(Localization.get(LC.OKAY));
m_okayButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
@@ -181,11 +181,12 @@ public void actionPerformed(ActionEvent evt)
m_moreButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
+
extendDialog();
}
});
-
- m_copyButton = new JButton("Copy to clipboard");
+
+ JButton copyButton = new JButton("Copy to clipboard");
m_copyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{
diff --git a/src/jmemorize/gui/swing/frames/EditCardFrame.java b/src/jmemorize/gui/swing/frames/EditCardFrame.java
index e2273f9..a28b965 100644
--- a/src/jmemorize/gui/swing/frames/EditCardFrame.java
+++ b/src/jmemorize/gui/swing/frames/EditCardFrame.java
@@ -437,11 +437,9 @@ private boolean isChanged()
if (!ImageRepository.equals(m_cardPanel.getFrontImages(), frontSide.getImages()))
return true;
-
- if (!ImageRepository.equals(m_cardPanel.getBackImages(), backSide.getImages()))
- return true;
- return false;
+ return ImageRepository.equals(m_cardPanel.getBackImages(), backSide.getImages());
+
}
private void updatePanel()
diff --git a/src/jmemorize/gui/swing/panels/AxisConfiguration.java b/src/jmemorize/gui/swing/panels/AxisConfiguration.java
new file mode 100644
index 0000000..8893981
--- /dev/null
+++ b/src/jmemorize/gui/swing/panels/AxisConfiguration.java
@@ -0,0 +1,21 @@
+package jmemorize.gui.swing.panels;
+import org.jfree.chart.axis.CategoryAxis;
+import org.jfree.chart.axis.ValueAxis;
+
+public class AxisConfiguration {
+ private final CategoryAxis domainAxis;
+ private final ValueAxis rangeAxis;
+
+ public AxisConfiguration(CategoryAxis domainAxis, ValueAxis rangeAxis) {
+ this.domainAxis = domainAxis;
+ this.rangeAxis = rangeAxis;
+ }
+
+ public CategoryAxis getDomainAxis() {
+ return domainAxis;
+ }
+
+ public ValueAxis getRangeAxis() {
+ return rangeAxis;
+ }
+}
diff --git a/src/jmemorize/gui/swing/panels/CardSidePanel.java b/src/jmemorize/gui/swing/panels/CardSidePanel.java
index fe9ae6e..266ed72 100644
--- a/src/jmemorize/gui/swing/panels/CardSidePanel.java
+++ b/src/jmemorize/gui/swing/panels/CardSidePanel.java
@@ -262,7 +262,6 @@ private enum Mode {TEXT, IMAGE, TEXT_AND_IMAGE};
private List m_imageObservers = new LinkedList();
private CardFont m_cardFont;
- private JButton m_prevImageButton;
private JButton m_nextImageButton;
private JButton m_textModeButton;
@@ -601,7 +600,7 @@ private void buildImageBar()
m_imageLabel.setHorizontalAlignment(StyleConstants.ALIGN_LEFT);
m_imageBar.add(m_imageLabel);
- m_prevImageButton = new JButton(loadIcon("arrow_left.png")); //$NON-NLS-1$
+ JButton m_prevImageButton = new JButton(loadIcon("arrow_left.png")); //$NON-NLS-1$
m_prevImageButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
diff --git a/src/jmemorize/gui/swing/panels/DeckChartPanel.java b/src/jmemorize/gui/swing/panels/DeckChartPanel.java
index 065c2c5..e731569 100644
--- a/src/jmemorize/gui/swing/panels/DeckChartPanel.java
+++ b/src/jmemorize/gui/swing/panels/DeckChartPanel.java
@@ -113,9 +113,9 @@ private class MyBarRenderer extends StackedBarRenderer3D
m_boldFont = getBaseItemLabelFont().deriveFont(Font.BOLD);
}
- public void drawItem(Graphics2D g, CategoryItemRendererState state,
- Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis,
- ValueAxis rangeAxis, CategoryDataset data, int row, int column, int pass)
+ public void drawItem(Graphics2D g, CategoryItemRendererState state,
+ Rectangle2D dataArea, CategoryPlot plot, AxisConfiguration axisConfig,
+ CategoryDataset data, int row, int column, int pass)
{
if (column - 1 == m_deck && m_category.getCards(m_deck).size() > 0)
{
@@ -131,8 +131,8 @@ public void drawItem(Graphics2D g, CategoryItemRendererState state,
}
// domainAxis.setCategoryMargin(0.2 + (0.011 * getMinNumDecks()));
-
- super.drawItem(g, state, dataArea, plot, domainAxis, rangeAxis,
+
+ super.drawItem(g, state, dataArea, plot, axisConfig.getDomainAxis(), axisConfig.getRangeAxis(),
data, row, column, pass);
}
@@ -164,11 +164,9 @@ protected void drawStackVertical(List values, Comparable category,
Object[] pair = (Object[]) it.next();
double thisValue = ((Double)pair[1]).doubleValue();
double delta = thisValue - lastValue;
-
- if( pair[0] != null)
- {
- if (delta == 0.0)
- it.remove();
+
+ if (pair[0] != null && delta == 0.0) {
+ it.remove();
}
lastValue = thisValue;
diff --git a/src/jmemorize/gui/swing/panels/ThinkQuiz.java b/src/jmemorize/gui/swing/panels/ThinkQuiz.java
index 736bde8..71ee4d0 100644
--- a/src/jmemorize/gui/swing/panels/ThinkQuiz.java
+++ b/src/jmemorize/gui/swing/panels/ThinkQuiz.java
@@ -33,28 +33,22 @@
public class ThinkQuiz implements Quiz
{
private CardSidePanel m_answerPanel = new CardSidePanel();
-
- private CardSide m_answerCardSide;
- public ThinkQuiz()
- {
+
+ public ThinkQuiz() {
m_answerPanel.setEditable(false);
}
- /* (non-Javadoc)
- * @see jmemorize.gui.swing.Quiz
- */
- public void showQuestion(CardSide answerCardSide)
- {
- m_answerCardSide = answerCardSide;
-
+ public void showQuestion(CardSide answerCardSide) {
+ CardSide m_answerCardSide = answerCardSide; // Declaring m_answerCardSide as a local variable
m_answerPanel.setText(m_answerCardSide.getText());
-
+
ImageRepository repo = ImageRepository.getInstance();
List images = repo.toImageIcons(m_answerCardSide.getImages());
m_answerPanel.setImages(images);
}
+
/* (non-Javadoc)
* @see jmemorize.gui.swing.Quiz
*/