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

Bug 13 Done #43

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
42ce8a7
bug 16 is done
nadanehad May 6, 2024
db6ece9
Merge pull request #1 from nadanehad/BugNo16
nadanehad May 6, 2024
9967fea
adding search history feature
kenzzzzzzzzzz May 6, 2024
03f7f25
bug 17 is done
nadanehad May 6, 2024
f38da6f
Merge pull request #3 from nadanehad/SearchHistoryBranch
kenzzzzzzzzzz May 6, 2024
b5918ce
adding search by category feature
kenzzzzzzzzzz May 6, 2024
2edd282
Merge pull request #4 from nadanehad/SearchByCategoryBranch
kenzzzzzzzzzz May 6, 2024
398432c
Merge branch 'master' of https://github.com/nadanehad/jMemorize into …
nadanehad May 6, 2024
b631146
bug number 18 is fixed
nadanehad May 6, 2024
1070520
Merge pull request #2 from nadanehad/bugNumber17
nadanehad May 6, 2024
21a81b0
Merge branch 'master' of https://github.com/nadanehad/jMemorize into …
nadanehad May 6, 2024
bf79ea0
bug number 19 is fixed
nadanehad May 6, 2024
16d20d9
bug number 20 is fixed
nadanehad May 6, 2024
95edf07
Feature 4 Done
albertmaged May 6, 2024
f2f845c
Feature 4 Done
albertmaged May 6, 2024
b409cda
Merge pull request #7 from nadanehad/bugNumber20
nadanehad May 6, 2024
7b95447
Merge pull request #8 from nadanehad/CalculateRemainingDays
albertmaged May 6, 2024
7d674cd
change in setDateExpired method
nadanehad May 6, 2024
17439ac
adding Search Result Sorting Description feature
kenzzzzzzzzzz May 6, 2024
3b14a02
Merge branch 'master' of https://github.com/nadanehad/jMemorize into …
nadanehad May 6, 2024
5420e8c
Merge pull request #9 from nadanehad/SortBranch
kenzzzzzzzzzz May 6, 2024
7e2e29a
Merge branch 'master' of https://github.com/nadanehad/jMemorize into …
nadanehad May 6, 2024
85d4c62
Enhance the toString method in card class
nadanehad May 6, 2024
60cf9b6
Merge pull request #10 from nadanehad/feature5
nadanehad May 6, 2024
2ad95ef
bug 12 Done
albertmaged May 6, 2024
f4c8780
Merge pull request #12 from nadanehad/okaybutton_to_LocalVariable
albertmaged May 6, 2024
14aacb8
Merge pull request #11 from nadanehad/feature6
nadanehad May 6, 2024
4ce7b62
bug 1 is fixed
kenzzzzzzzzzz May 6, 2024
9157787
Merge pull request #13 from nadanehad/Bug1Branch
kenzzzzzzzzzz May 6, 2024
434d0d7
bug 2 is fixed
kenzzzzzzzzzz May 6, 2024
f21eb07
Merge pull request #14 from nadanehad/Bug2Branch
kenzzzzzzzzzz May 6, 2024
dc74347
Bug 15 Completed
albertmaged May 6, 2024
20646e3
Merge pull request #15 from nadanehad/m_okayButton
albertmaged May 6, 2024
67b0928
bug 3 is fixed
kenzzzzzzzzzz May 6, 2024
1ce993e
Merge pull request #16 from nadanehad/Bug3Branch
kenzzzzzzzzzz May 6, 2024
9e1bc09
Bug 13 Done
albertmaged May 6, 2024
ae4be07
Bug 13 Done
albertmaged May 6, 2024
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/checkstyle_all_4_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/libraries/lib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions checkstyle_config/checkstyle_config.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="checkstyle-all-4.3" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions jMemorize.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>
22 changes: 13 additions & 9 deletions src/jmemorize/core/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Date;
import java.util.List;
import java.util.Objects;

import jmemorize.core.CardSide.CardSideObserver;

Expand Down Expand Up @@ -233,11 +234,14 @@ public Date getDateExpired()
/**
* @param date can be <code>null</code>.
*/
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 <code>null</code>.
*/
Expand All @@ -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");
}

/**
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions src/jmemorize/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
59 changes: 55 additions & 4 deletions src/jmemorize/core/SearchTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/
package jmemorize.core;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.*;

/**
* @author djemili
Expand All @@ -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<String> searchHistory = new ArrayList<>();


public static List<Card> search(String text, int side, boolean matchCase, List<Card> cards)
{
List<Card> foundCards = new LinkedList<Card>();
Expand Down Expand Up @@ -87,4 +87,55 @@ public static List<Integer> search(String text, String searchtext,
return positions;
}


public static void addToSearchHistory(String query) {
searchHistory.add(query);
}

public static List<String> getSearchHistory() {
return searchHistory;
}

public static List<Card> searchWithinCategory(String text, int side, boolean matchCase, Category category) {
List<Card> foundCards = new LinkedList<Card>();
List<Card> 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<Card> foundCards) {
// Sort by relevance criteria
Collections.sort(foundCards, new Comparator<Card>() {
@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
}
});
}

}
69 changes: 33 additions & 36 deletions src/jmemorize/gui/swing/actions/file/AbstractExportAction.java
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 <code>null</code> 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)
{
Expand All @@ -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();
}
Loading