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 11 Done #44

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 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
847990a
bug 4 is fixed
kenzzzzzzzzzz May 6, 2024
e25b565
Merge pull request #17 from nadanehad/Bug4Branch
kenzzzzzzzzzz May 6, 2024
5bff741
Merge branch 'master' of https://github.com/nadanehad/jMemorize into …
albertmaged May 6, 2024
3a6b290
Bug 13 Done
albertmaged May 6, 2024
82deb48
Merge pull request #18 from nadanehad/okaybutton_to_LocalVariableee
albertmaged May 6, 2024
7d75f7d
bug 5 is fixed
kenzzzzzzzzzz May 6, 2024
76e2411
Merge pull request #19 from nadanehad/Bug5Branch
kenzzzzzzzzzz May 6, 2024
022d034
Bug 14 Done
albertmaged May 6, 2024
5139347
Merge pull request #20 from nadanehad/m_stacktraceArea
albertmaged May 6, 2024
a2ad4a9
Bug 11 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
63 changes: 57 additions & 6 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 All @@ -46,7 +46,7 @@ public static List<Card> search(String text, int side, boolean matchCase, List<C
flipSide = flipSide.toLowerCase();
}

if (side == FRONT_SIDE || side == BOTH_SIDES)
if ((side == FRONT_SIDE || side == BOTH_SIDES) && frontSide.indexOf(text) > -1)
{
if (frontSide.indexOf(text) > -1)
{
Expand All @@ -55,7 +55,7 @@ public static List<Card> search(String text, int side, boolean matchCase, List<C
}
}

if (side == FLIP_SIDE || side == BOTH_SIDES)
if ((side == FLIP_SIDE || side == BOTH_SIDES) && flipSide.indexOf(text) > -1)
{
if (flipSide.indexOf(text) > -1)
{
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
}
});
}

}
3 changes: 2 additions & 1 deletion src/jmemorize/core/io/XmlBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ else if (out != null)
*
* Don't use this method directly. Use the {@link LessonProvider} instead.
*
* @param File xmlFile the file that containt the XML document which
* @param lesson xmlFile the file that containt the XML document which
* represents the lesson.
*/
public static void loadFromXMLFile(File xmlFile, Lesson lesson)
Expand Down Expand Up @@ -225,6 +225,7 @@ public static void loadFromXMLFile(File xmlFile, Lesson lesson)
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); // Disable DOCTYPE declaration
Document doc = factory.newDocumentBuilder().parse(in);

// there must be a root category
Expand Down
39 changes: 17 additions & 22 deletions src/jmemorize/gui/swing/GeneralTransferHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,21 @@ public boolean importData(JComponent comp, Transferable t)
{
try
{
Category targetCategory;
if (comp instanceof CategoryTree)
{
CategoryTree tree = (CategoryTree)comp;
targetCategory = tree.getSelectedCategory();
}
else if (comp instanceof CardTable)
{
CardTable table = (CardTable)comp;
targetCategory = table.getView().getCategory();
if (comp instanceof CategoryTree || comp instanceof CardTable) {
Category targetCategory = comp instanceof CategoryTree ?
((CategoryTree) comp).getSelectedCategory() :
((CardTable) comp).getView().getCategory();
}
else if (comp instanceof JTextPane)
{
JTextPane textPane = (JTextPane)comp;

if (t.isDataFlavorSupported(FORMATTED_TEXT_FLAVOR))
{
int start = textPane.getSelectionStart();
FormattedTextSection fText = (FormattedTextSection)t.getTransferData(
FORMATTED_TEXT_FLAVOR);

fText.getText().insertIntoDocument(textPane.getStyledDocument(), start);
}
else if (t.isDataFlavorSupported(DataFlavor.imageFlavor))
Expand All @@ -292,23 +286,23 @@ else if (t.isDataFlavorSupported(DataFlavor.imageFlavor))
{
String link = (String)t.getTransferData(DataFlavor.stringFlavor);
link = link.substring(0, link.indexOf('\n'));

String lower = link.toLowerCase();
if (lower.startsWith("http://"))
{
if (lower.endsWith(".jpg") ||
if (lower.endsWith(".jpg") ||
lower.endsWith(".gif") ||
lower.endsWith(".png") ||
lower.endsWith(".jpeg") ||
lower.endsWith(".png") ||
lower.endsWith(".jpeg") ||
lower.endsWith(".bmp"))
{
URL url = new URL(link);
ImageIcon icon = new ImageIcon(url);
icon.setDescription(link);

m_cardSidePanel.addImage(icon);
m_cardSidePanel.getTextPane().requestFocus();

return true;
}
}
Expand All @@ -318,17 +312,18 @@ else if (t.isDataFlavorSupported(DataFlavor.stringFlavor))
{
int start = textPane.getSelectionStart();
String text = (String)t.getTransferData(DataFlavor.stringFlavor);

textPane.getDocument().insertString(start, text, null);
}

return true;
}
else
{
return false;
}

}

Category targetCategory = null;
if (t.isDataFlavorSupported(CARDS_FLAVOR))
{
List<Card> cards = (List<Card>)t.getTransferData(CARDS_FLAVOR);
Expand Down
Loading