diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..99cb56d
Binary files /dev/null and b/.DS_Store differ
diff --git a/checkstyle_config/.DS_Store b/checkstyle_config/.DS_Store
new file mode 100644
index 0000000..0791dae
Binary files /dev/null and b/checkstyle_config/.DS_Store differ
diff --git a/resource/.DS_Store b/resource/.DS_Store
new file mode 100644
index 0000000..836ff65
Binary files /dev/null and b/resource/.DS_Store differ
diff --git a/src/jmemorize/core/Card.java b/src/jmemorize/core/Card.java
index d6cf17e..019f6b1 100644
--- a/src/jmemorize/core/Card.java
+++ b/src/jmemorize/core/Card.java
@@ -17,6 +17,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package jmemorize.core;
+/* eman */
import java.util.Date;
import java.util.List;
@@ -29,66 +30,60 @@
* @author djemili
* @version $Id: Card.java 1048 2008-01-21 21:40:00Z djemili $
*/
-public class Card implements Events, Cloneable
-{
- public static final long ONE_DAY = 1000 * 60 * 60 * 24;
+public class Card implements Events, Cloneable {
+ public static final long ONE_DAY = 1000 * 60 * 60 * 24;
public static final boolean CLONE_DATES = Main.isDevel();
private Category m_category;
- private int m_level;
+ private int m_level;
// content
private CardSide m_frontSide = new CardSide();
- private CardSide m_backSide = new CardSide();
-
+ private CardSide m_backSide = new CardSide();
+
// dates
- private Date m_dateTested;
- private Date m_dateExpired;
- private Date m_dateCreated;
- private Date m_dateModified;
- private Date m_dateTouched; //this date is used internaly to order cards
+ private Date m_dateTested;
+ private Date m_dateExpired;
+ private Date m_dateCreated;
+ private Date m_dateModified;
+ private Date m_dateTouched; // this date is used internaly to order cards
// stats
- private int m_testsTotal;
- private int m_testsHit; //succesfull learn repetitions
- private int m_frontHitsCorrect;
- private int m_backHitsCorrect;
+ private int m_testsTotal;
+ private int m_testsHit; // succesfull learn repetitions
+ private int m_frontHitsCorrect;
+ private int m_backHitsCorrect;
/**
* Assumes formatted front- and backsides
*/
- public Card(String front, String back)
- {
+ public Card(String front, String back) {
this(FormattedText.formatted(front), FormattedText.formatted(back));
}
-
- public Card(FormattedText front, FormattedText back)
- {
+
+ public Card(FormattedText front, FormattedText back) {
this(new Date(), front, back);
}
-
+
/**
* The card sides are given in a formatted state.
*/
- public Card(Date created, String front, String back)
- {
+ public Card(Date created, String front, String back) {
this(created, FormattedText.formatted(front), FormattedText.formatted(back));
}
-
- public Card(Date created, FormattedText front, FormattedText back)
- {
+
+ public Card(Date created, FormattedText front, FormattedText back) {
this(created, new CardSide(front), new CardSide(back));
}
-
- public Card(Date created, CardSide frontSide, CardSide backSide)
- {
+
+ public Card(Date created, CardSide frontSide, CardSide backSide) {
m_dateCreated = cloneDate(created);
m_dateModified = cloneDate(created);
m_dateTouched = cloneDate(created);
m_frontSide = frontSide;
m_backSide = backSide;
-
+
attachCardSideObservers();
}
@@ -97,51 +92,47 @@ public Card(Date created, CardSide frontSide, CardSide backSide)
*
* @throws IllegalArgumentException If frontSide or backSide has no text.
*/
- public void setSides(String front, String back)
- {
+ public void setSides(String front, String back) {
FormattedText frontSide = FormattedText.unformatted(front);
FormattedText backSide = FormattedText.unformatted(back);
-
+
setSides(frontSide, backSide);
}
-
+
/**
* @throws IllegalArgumentException If front or back has no text.
*/
- public void setSides(FormattedText front, FormattedText back)
- throws IllegalArgumentException
- {
- if (front.equals(m_frontSide.getText()) &&
- back.equals(m_backSide.getText()))
- {
+ public void setSides(FormattedText front, FormattedText back)
+ throws IllegalArgumentException {
+ if (front.equals(m_frontSide.getText()) &&
+ back.equals(m_backSide.getText())) {
return;
}
-
+
m_frontSide.setText(front);
m_backSide.setText(back);
-
- if (m_category != null)
- {
+
+ if (m_category != null) {
m_dateModified = new Date();
m_category.fireCardEvent(EDITED_EVENT, this, getCategory(), m_level);
}
}
-
+
/**
* Get the number of times a specific card side was already learned in its
* deck.
*
* @param frontside true if it should deliver the fronside
- * value, false if it should deliver the backside value.
+ * value, false if it should deliver the backside
+ * value.
*
* @return the amount of times that the specified side was learned in this
- * deck.
+ * deck.
*/
- public int getLearnedAmount(boolean frontside)
- {
+ public int getLearnedAmount(boolean frontside) {
// TODO move to CardSide class
-
- return frontside ? m_frontHitsCorrect : m_backHitsCorrect;
+
+ return frontside ? m_frontHitsCorrect : m_backHitsCorrect;
}
/**
@@ -149,26 +140,22 @@ public int getLearnedAmount(boolean frontside)
* deck.
*
* @param frontside true if it should deliver the fronside
- * value, false if it should deliver the backside value.
+ * value, false if it should deliver the backside
+ * value.
*
- * @param amount the amount of times that the specified side was learned in
- * this deck.
+ * @param amount the amount of times that the specified side was learned in
+ * this deck.
*/
- public void setLearnedAmount(boolean frontside, int amount)
- {
-// TODO move to CardSide class
-
- if (frontside)
- {
+ public void setLearnedAmount(boolean frontside, int amount) {
+ // TODO move to CardSide class
+
+ if (frontside) {
m_frontHitsCorrect = amount;
- }
- else
- {
+ } else {
m_backHitsCorrect = amount;
}
- if (m_category != null)
- {
+ if (m_category != null) {
m_category.fireCardEvent(DECK_EVENT, this, getCategory(), m_level);
}
}
@@ -178,12 +165,12 @@ public void setLearnedAmount(boolean frontside, int amount)
* its deck by one.
*
* @param frontside true if it should deliver the fronside
- * value, false if it should deliver the backside value.
+ * value, false if it should deliver the backside
+ * value.
*/
- public void incrementLearnedAmount(boolean frontside)
- {
-// TODO move to CardSide class
-
+ public void incrementLearnedAmount(boolean frontside) {
+ // TODO move to CardSide class
+
setLearnedAmount(frontside, getLearnedAmount(frontside) + 1);
}
@@ -191,33 +178,28 @@ public void incrementLearnedAmount(boolean frontside)
* Resets the amount of times that the card sides were learned in this deck
* to 0.
*/
- public void resetLearnedAmount()
- {
+ public void resetLearnedAmount() {
setLearnedAmount(true, 0);
setLearnedAmount(false, 0);
}
- public CardSide getFrontSide()
- {
+ public CardSide getFrontSide() {
return m_frontSide;
}
- public CardSide getBackSide()
- {
+ public CardSide getBackSide() {
return m_backSide;
}
-
+
/**
* @return the date that this card appeared the last time in a test and was
- * either passed or failed (skip doesn't count).
+ * either passed or failed (skip doesn't count).
*/
- public Date getDateTested()
- {
+ public Date getDateTested() {
return cloneDate(m_dateTested);
}
- public void setDateTested(Date date)
- {
+ public void setDateTested(Date date) {
m_dateTested = cloneDate(date);
m_dateTouched = cloneDate(date);
}
@@ -225,8 +207,7 @@ public void setDateTested(Date date)
/**
* @return can be null.
*/
- public Date getDateExpired()
- {
+ public Date getDateExpired() {
return cloneDate(m_dateExpired);
}
@@ -241,101 +222,88 @@ public void setDateExpired(Date date) // CHECK should this throw a event?
/**
* @return the creation date. Is never null.
*/
- public Date getDateCreated()
- {
+ public Date getDateCreated() {
return cloneDate(m_dateCreated);
}
- public void setDateCreated(Date date)
- {
- if (date == null)
+ public void setDateCreated(Date date) {
+ if (date == null)
throw new NullPointerException();
-
+
m_dateCreated = cloneDate(date);
}
-
+
/**
* @return the modification date. Is never null.
*/
- public Date getDateModified()
- {
+ public Date getDateModified() {
return m_dateModified;
}
/**
* @param date must be equal or after the creation date.
*/
- public void setDateModified(Date date)
- {
+ public void setDateModified(Date date) {
if (date.before(m_dateCreated))
throw new IllegalArgumentException(
- "Modification date can't be before creation date.");
-
+ "Modification date can't be before creation date.");
+
m_dateModified = date;
}
/**
* @return DateTouched is the date that this card was learned, skipped,
- * reset or created the last time. This value is used to sort cards by a
- * global value that is unique for all categories and decks.
+ * reset or created the last time. This value is used to sort cards by a
+ * global value that is unique for all categories and decks.
*/
- public Date getDateTouched()
- {
+ public Date getDateTouched() {
return cloneDate(m_dateTouched);
}
- public void setDateTouched(Date date)
- {
+ public void setDateTouched(Date date) {
m_dateTouched = cloneDate(date);
}
/**
* @return Number of times this card has been tested.
*/
- public int getTestsTotal()
- {
+ public int getTestsTotal() {
return m_testsTotal;
}
/**
* @return Number of times this card has been tested succesfully.
*/
- public int getTestsPassed()
- {
+ public int getTestsPassed() {
return m_testsHit;
}
/**
* @return The percentage of times that this card has passed learn tests in
- * comparison to failed tests.
+ * comparison to failed tests.
*/
- public int getPassRatio()
- {
- return (int)Math.round(100.0 * m_testsHit / m_testsTotal);
+ public int getPassRatio() {
+ return (int) Math.round(100.0 * m_testsHit / m_testsTotal);
}
- public void incStats(int hit, int total)
- {
+ public void incStats(int hit, int total) {
m_testsTotal += total;
m_testsHit += hit;
}
- public void resetStats()
- {
+ public void resetStats() {
m_testsTotal = 0;
m_testsHit = 0;
-
+
m_frontHitsCorrect = 0;
m_backHitsCorrect = 0;
}
- public Category getCategory()
- {
+ public Category getCategory() {
return m_category;
}
- protected void setCategory(Category category)
- {
+ protected void setCategory(Category category) {
m_category = category;
}
@@ -345,21 +313,19 @@ protected void setCategory(Category category)
*
* @return True if the card has expired.
*/
- public boolean isExpired()
- {
+ public boolean isExpired() {
Date now = Main.getNow();
- return m_dateExpired != null &&
- (m_dateExpired.before(now) || m_dateExpired.equals(now));
+ return m_dateExpired != null &&
+ (m_dateExpired.before(now) || m_dateExpired.equals(now));
}
/**
- * A card is learned when it was learned/repeated succesfully and its learn
+ * A card is learned when it was learned/repeated succesfully and its learn
* time hasnt expired.
*
* @return True if the card is learned.
*/
- public boolean isLearned()
- {
+ public boolean isLearned() {
return m_dateExpired != null && m_dateExpired.after(Main.getNow());
}
@@ -369,70 +335,61 @@ public boolean isLearned()
*
* @return True if the card is unlearned.
*/
- public boolean isUnlearned()
- {
+ public boolean isUnlearned() {
return m_dateExpired == null;
}
/**
* @return Returns the level.
*/
- public int getLevel()
- {
+ public int getLevel() {
return m_level;
}
/**
* @param level The level to set.
*/
- protected void setLevel(int level)
- {
+ protected void setLevel(int level) {
m_level = level;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#clone()
*/
- public Object clone()
- {
+ public Object clone() {
Card card = null;
- try
- {
- card = (Card)super.clone();
- card.m_frontSide = (CardSide)m_frontSide.clone();
- card.m_backSide = (CardSide)m_backSide.clone();
-
+ try {
+ card = (Card) super.clone();
+ card.m_frontSide = (CardSide) m_frontSide.clone();
+ card.m_backSide = (CardSide) m_backSide.clone();
+
card.m_dateCreated = cloneDate(m_dateCreated);
card.m_dateExpired = cloneDate(m_dateExpired);
card.m_dateModified = cloneDate(m_dateModified);
card.m_dateTested = cloneDate(m_dateTested);
card.m_dateTouched = cloneDate(m_dateTouched);
-
+
card.m_category = null; // don't clone category
- }
- catch (CloneNotSupportedException e)
- {
+ } catch (CloneNotSupportedException e) {
assert false;
}
-
+
return card;
}
-
+
/**
* Clones the card without copying its user-dependent progress stats.
*
* This includes the following data: Fronside, Flipside, Creation date.
* Setting the right category needs to be handled from the out side.
*/
- public Card cloneWithoutProgress()
- {
- try
- {
- return new Card(m_dateCreated,
- (CardSide)m_frontSide.clone(), (CardSide)m_backSide.clone());
- }
- catch (CloneNotSupportedException e)
- {
+ public Card cloneWithoutProgress() {
+ try {
+ return new Card(m_dateCreated,
+ (CardSide) m_frontSide.clone(), (CardSide) m_backSide.clone());
+ } catch (CloneNotSupportedException e) {
assert false;
return null; // satisfy compiler
}
@@ -441,45 +398,38 @@ public Card cloneWithoutProgress()
/**
* @see java.lang.Object#toString()
*/
- public String toString()
- {
- return "("+m_frontSide+"/"+m_backSide+")";
+ public String toString() {
+ return "(" + m_frontSide + "/" + m_backSide + ")";
}
-
- private void attachCardSideObservers()
- {
+
+ private void attachCardSideObservers() {
CardSideObserver observer = new CardSideObserver() {
- public void onImagesChanged(CardSide cardSide, List imageIDs)
- {
- if (m_category != null)
- {
+ public void onImagesChanged(CardSide cardSide, List imageIDs) {
+ if (m_category != null) {
m_dateModified = new Date();
m_category.fireCardEvent(EDITED_EVENT, Card.this, getCategory(), m_level);
}
}
- public void onTextChanged(CardSide cardSide, FormattedText text)
- {
+ public void onTextChanged(CardSide cardSide, FormattedText text) {
// already handled by set sides
// TODO handle event notfying here
}
};
-
+
m_frontSide.addObserver(observer);
m_backSide.addObserver(observer);
}
/**
* @return clone of given date or null if given date was
- * null.
+ * null.
*/
- private Date cloneDate(Date date)
- {
- if (CLONE_DATES)
- {
- return date == null ? null : (Date)date.clone();
+ private Date cloneDate(Date date) {
+ if (CLONE_DATES) {
+ return date == null ? null : (Date) date.clone();
}
-
+
return date;
}
}
diff --git a/src/jmemorize/core/Main.java b/src/jmemorize/core/Main.java
index 2c6f185..cba2a3c 100644
--- a/src/jmemorize/core/Main.java
+++ b/src/jmemorize/core/Main.java
@@ -17,7 +17,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package jmemorize.core;
-
+/*its me again 'noureen' last commit */
+/*my name is noureeeen */
+/*Basmala */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -54,408 +56,366 @@
*
* @author djemili
*/
-public class Main extends Observable implements LearnSessionProvider,
- LessonProvider, CategoryObserver
-{
- public interface ProgramEndObserver
- {
+public class Main extends Observable implements LearnSessionProvider,
+ LessonProvider, CategoryObserver {
+ public interface ProgramEndObserver {
/**
- * This method is notified when the program ends.
+ * This method is notified when the program ends.
*/
public void onProgramEnd();
}
-
- public static final Properties PROPERTIES = new Properties();
- public static final Preferences USER_PREFS =
- Preferences.userRoot().node("de/riad/jmemorize"); //$NON-NLS-1$
- private static final String PROPERTIES_PATH =
- "/resource/jMemorize.properties"; //$NON-NLS-1$
+ public static final Properties PROPERTIES = new Properties();
+ public static final Preferences USER_PREFS = Preferences.userRoot().node("de/riad/jmemorize"); //$NON-NLS-1$
+
+ private static final String PROPERTIES_PATH = "/resource/jMemorize.properties"; //$NON-NLS-1$
+
+ public static final File STATS_FILE = new File(System.getProperty("user.home") + "/.jmemorize-stats.xml"); //$NON-NLS-1$ //$NON-NLS-2$
- public static final File STATS_FILE =
- new File(System.getProperty("user.home")+"/.jmemorize-stats.xml"); //$NON-NLS-1$ //$NON-NLS-2$
+ private RecentItems m_recentFiles = new RecentItems(5, USER_PREFS.node("recent.files")); //$NON-NLS-1$
- private RecentItems m_recentFiles =
- new RecentItems(5, USER_PREFS.node("recent.files")); //$NON-NLS-1$
+ private static Main m_instance;
- private static Main m_instance;
-
- private MainFrame m_frame;
- private Lesson m_lesson;
- private LearnSettings m_learnSettings;
- private LearnHistory m_globalLearnHistory;
- private int m_runningSessions = 0;
+ private MainFrame m_frame;
+ private Lesson m_lesson;
+ private LearnSettings m_learnSettings;
+ private LearnHistory m_globalLearnHistory;
+ private int m_runningSessions = 0;
// observers
- private List m_lessonObservers =
- new LinkedList();
- private List m_learnSessionObservers =
- new LinkedList();
- private List m_programEndObservers =
- new LinkedList();
-
+ private List m_lessonObservers = new LinkedList();
+ private List m_learnSessionObservers = new LinkedList();
+ private List m_programEndObservers = new LinkedList();
+
// simple logging support
- private static final Logger logger = Logger.getLogger("jmemorize");
- private static Throwable m_lastLoggedThrowable;
-
+ private static final Logger logger = Logger.getLogger("jmemorize");
+ private static Throwable m_lastLoggedThrowable;
+
/**
* @return the singleton instance of Main.
*/
- public static Main getInstance()
- {
- if (m_instance == null)
- {
+ public static Main getInstance() {
+ if (m_instance == null) {
m_instance = new Main();
}
-
+
return m_instance;
}
-
- public static Date getNow()
- {
+
+ public static Date getNow() {
return new Date();
}
-
- public static Date getTomorrow()
- {
+
+ public static Date getTomorrow() {
return new Date(new Date().getTime() + Card.ONE_DAY);
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LessonProvider
*/
- public void createNewLesson()
- {
+ public void createNewLesson() {
ImageRepository.getInstance().clear();
setLesson(new Lesson(false));
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jmemorize.core.LessonProvider
*/
- public void setLesson(Lesson lesson)
- {
+ public void setLesson(Lesson lesson) {
Lesson oldLesson = m_lesson;
m_lesson = lesson;
-
- if (oldLesson != null)
- {
+
+ if (oldLesson != null) {
fireLessonClosed(oldLesson);
}
-
+
if (m_frame != null) // TODO remove call
{
m_frame.setLesson(m_lesson);
}
-
+
fireLessonLoaded(m_lesson);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LessonProvider
*/
- public void loadLesson(File file) throws IOException
- {
- try
- {
+ public void loadLesson(File file) throws IOException {
+ try {
ImageRepository.getInstance().clear();
-
+
Lesson lesson = new Lesson(false);
XmlBuilder.loadFromXMLFile(file, lesson);
lesson.setFile(file);
lesson.setCanSave(false);
m_recentFiles.push(file.getAbsolutePath());
-
+
setLesson(lesson);
- //startExpirationTimer(); TODO expiration timer
- }
- catch (Exception e)
- {
+ // startExpirationTimer(); TODO expiration timer
+ } catch (Exception e) {
m_recentFiles.remove(file.getAbsolutePath());
logThrowable("Error loading lesson", e);
throw new IOException(e.getMessage());
}
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LessonProvider
*/
- public void saveLesson(Lesson lesson, File file) throws IOException
- {
- try
- {
- File tempFile = new File(file.getAbsolutePath()+"~"); //$NON-NLS-1$
+ public void saveLesson(Lesson lesson, File file) throws IOException {
+ try {
+ File tempFile = new File(file.getAbsolutePath() + "~"); //$NON-NLS-1$
XmlBuilder.saveAsXMLFile(tempFile, lesson);
-
+
file.delete();
copyFile(tempFile, file);
-
+
lesson.setFile(file); // note: sets file only if no exception
lesson.setCanSave(false);
m_recentFiles.push(file.getAbsolutePath());
-
- for (LessonObserver observer : m_lessonObservers)
- {
+
+ for (LessonObserver observer : m_lessonObservers) {
observer.lessonSaved(lesson);
}
- }
- catch (Throwable t)
- {
+ } catch (Throwable t) {
throw new IOException(t.getMessage());
}
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LessonProvider
*/
- public Lesson getLesson()
- {
+ public Lesson getLesson() {
return m_lesson;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LessonProvider
*/
- public RecentItems getRecentLessonFiles()
- {
+ public RecentItems getRecentLessonFiles() {
return m_recentFiles;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jmemorize.core.LessonProvider
*/
- public void addLessonObserver(LessonObserver observer)
- {
+ public void addLessonObserver(LessonObserver observer) {
m_lessonObservers.add(observer);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jmemorize.core.LessonProvider
*/
- public void removeLessonObserver(LessonObserver observer)
- {
+ public void removeLessonObserver(LessonObserver observer) {
m_lessonObservers.remove(observer);
}
-
+
/**
* Adds a ProgramEndObserver that will be fired when this program closes.
*
* @param observer
*/
- public void addProgramEndObserver(ProgramEndObserver observer)
- {
+ public void addProgramEndObserver(ProgramEndObserver observer) {
m_programEndObservers.add(observer);
}
-
+
/**
* @see #addProgramEndObserver(jmemorize.core.Main.ProgramEndObserver)
*/
- public void removeProgramEndObserver(ProgramEndObserver observer)
- {
+ public void removeProgramEndObserver(ProgramEndObserver observer) {
m_programEndObservers.remove(observer);
}
-
+
/**
* Notifies all program end observers and exists the application.
*/
- public void exit()
- {
- for (ProgramEndObserver observer : m_programEndObservers)
- {
+ public void exit() {
+ for (ProgramEndObserver observer : m_programEndObservers) {
observer.onProgramEnd();
}
-
+
System.exit(0);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LearnSessionProvider
*/
- public void startLearnSession(LearnSettings settings, List selectedCards,
- Category category,boolean learnUnlearned, boolean learnExpired)
- {
- LearnSession session = new DefaultLearnSession(category, settings,
- selectedCards, learnUnlearned, learnExpired, this);
-
+ public void startLearnSession(LearnSettings settings, List selectedCards,
+ Category category, boolean learnUnlearned, boolean learnExpired) {
+ LearnSession session = new DefaultLearnSession(category, settings,
+ selectedCards, learnUnlearned, learnExpired, this);
+
m_runningSessions++;
-
- for (LearnSessionObserver observer : m_learnSessionObservers)
- {
+
+ for (LearnSessionObserver observer : m_learnSessionObservers) {
observer.sessionStarted(session);
}
-
+
// this needs to be called after notifying the observers so that they
// don't miss the first card
session.startLearning();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LearnSessionProvider
*/
- public void sessionEnded(LearnSession session)
- {
+ public void sessionEnded(LearnSession session) {
m_runningSessions--;
-
- if (session.isRelevant())
- {
+
+ if (session.isRelevant()) {
LearnHistory history = m_lesson.getLearnHistory();
history.addSummary(
- session.getStart(),
- session.getEnd(),
- session.getPassedCards().size(),
- session.getFailedCards().size(),
- session.getSkippedCards().size(),
- session.getRelearnedCards().size());
+ session.getStart(),
+ session.getEnd(),
+ session.getPassedCards().size(),
+ session.getFailedCards().size(),
+ session.getSkippedCards().size(),
+ session.getRelearnedCards().size());
}
-
- for (LearnSessionObserver observer : m_learnSessionObservers)
- {
+
+ for (LearnSessionObserver observer : m_learnSessionObservers) {
observer.sessionEnded(session);
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LearnSessionProvider
*/
- public boolean isSessionRunning()
- {
+ public boolean isSessionRunning() {
return m_runningSessions > 0;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LearnSessionProvider
*/
- public void addLearnSessionObserver(LearnSessionObserver observer)
- {
+ public void addLearnSessionObserver(LearnSessionObserver observer) {
m_learnSessionObservers.add(observer);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.LearnSessionProvider
*/
- public void removeLearnSessionObserver(LearnSessionObserver observer)
- {
+ public void removeLearnSessionObserver(LearnSessionObserver observer) {
m_learnSessionObservers.remove(observer);
}
/**
* @return the main frame.
*/
- public MainFrame getFrame()
- {
+ public MainFrame getFrame() {
return m_frame;
}
/**
* @return currently loaded learn strategy.
*/
- public LearnSettings getLearnSettings()
- {
+ public LearnSettings getLearnSettings() {
return m_learnSettings;
}
-
+
/**
* @return the statistics for jMemorize.
*/
- public LearnHistory getGlobalLearnHistory()
- {
+ public LearnHistory getGlobalLearnHistory() {
return m_globalLearnHistory;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.CategoryObserver
*/
- public void onCardEvent(int type, Card card, Category category, int deck)
- {
+ public void onCardEvent(int type, Card card, Category category, int deck) {
fireLessonModified(m_lesson);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* Declared in jmemorize.core.CategoryObserver
*/
- public void onCategoryEvent(int type, Category category)
- {
- fireLessonModified(m_lesson);
+ public void onCategoryEvent(int type, Category category) {
+ fireLessonModified(m_lesson);
}
- public Main()
- {
+ public Main() {
InputStream propertyStream = null;
-
- try
- {
+
+ try {
// TODO - make this adjustable
// Note that the limit might not be enough for finer.
Handler fh = new FileHandler("%t/jmemorize%g.log", 10000, 3);
- fh.setLevel(Level.WARNING);
+ fh.setLevel(Level.WARNING);
fh.setFormatter(new SimpleFormatter());
logger.addHandler(fh);
URL resource = getClass().getResource(PROPERTIES_PATH);
-
-// PROPERTIES.load(resource.openStream());
-
- if (resource != null)
- {
+
+ // PROPERTIES.load(resource.openStream());
+
+ if (resource != null) {
propertyStream = resource.openStream();
PROPERTIES.load(propertyStream);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
e.printStackTrace();
logThrowable("Initialization problem", e);
- }
- finally
- {
- try
- {
+ } finally {
+ try {
if (propertyStream != null)
propertyStream.close();
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
e.printStackTrace();
logThrowable("Initialization problem", e);
}
}
}
-
+
/**
* @return true if this is the devel version running.
- * false if it is the release version. This can be used for
- * new and expiremental features.
+ * false if it is the release version. This can be used for
+ * new and expiremental features.
*/
- public static boolean isDevel()
- {
+ public static boolean isDevel() {
String property = PROPERTIES.getProperty("project.release"); //$NON-NLS-1$
return !Boolean.valueOf(property).booleanValue();
}
-
+
/*
* Logging utilities
*/
- public static Logger getLogger()
- {
+ public static Logger getLogger() {
return logger;
}
-
+
// note that we cache the throwable so that we only log it the first time.
// This allows us to put a catch all call to this function in ErrorDialog.
// Ideally, exceptions should be logged where they are first caught, because
// we have more information about the exception there.
- public static void logThrowable(String msg, Throwable t)
- {
- if (t != null && m_lastLoggedThrowable != t)
- {
+ public static void logThrowable(String msg, Throwable t) {
+ if (t != null && m_lastLoggedThrowable != t) {
m_lastLoggedThrowable = t;
logger.severe(msg);
-
+
// TODO, consider writing these to the log file only once?
- String java = System.getProperty("java.version");
- String os = System.getProperty("os.name");
+ String java = System.getProperty("java.version");
+ String os = System.getProperty("os.name");
String version = Main.PROPERTIES.getProperty("project.version");
String buildId = Main.PROPERTIES.getProperty("buildId");
- String txt = "Ver "+ version +" ("+ buildId +") - Java "+ java +" , OS "+ os;
+ String txt = "Ver " + version + " (" + buildId + ") - Java " + java + " , OS " + os;
logger.severe(txt);
StringWriter strWriter = new StringWriter();
@@ -465,78 +425,63 @@ public static void logThrowable(String msg, Throwable t)
}
}
- public static void clearLastThrowable()
- {
+ public static void clearLastThrowable() {
m_lastLoggedThrowable = null;
}
-
- private static void copyFile(File in, File out) throws IOException
- {
+
+ private static void copyFile(File in, File out) throws IOException {
FileChannel sourceChannel = null;
FileChannel destinationChannel = null;
- try
- {
+ try {
sourceChannel = new FileInputStream(in).getChannel();
destinationChannel = new FileOutputStream(out).getChannel();
-
+
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
- }
- finally
- {
+ } finally {
if (sourceChannel != null)
sourceChannel.close();
-
+
if (destinationChannel != null)
destinationChannel.close();
}
}
- private void run(File file)
- {
+ private void run(File file) {
createNewLesson();
startStats();
-
+
m_frame = new MainFrame();
m_learnSettings = Settings.loadStrategy(m_frame);
m_frame.setVisible(true);
-
- if (file != null)
- {
+
+ if (file != null) {
m_frame.loadLesson(file);
}
}
- private void startStats()
- {
+ private void startStats() {
m_globalLearnHistory = new LearnHistory(STATS_FILE);
}
-
- private void fireLessonLoaded(Lesson lesson)
- {
+
+ private void fireLessonLoaded(Lesson lesson) {
lesson.getRootCategory().addObserver(this);
-
- for (LessonObserver observer : m_lessonObservers)
- {
+
+ for (LessonObserver observer : m_lessonObservers) {
observer.lessonLoaded(lesson);
}
}
-
- private void fireLessonClosed(Lesson lesson)
- {
+
+ private void fireLessonClosed(Lesson lesson) {
lesson.getRootCategory().removeObserver(this);
-
- for (LessonObserver observer : m_lessonObservers)
- {
+
+ for (LessonObserver observer : m_lessonObservers) {
observer.lessonClosed(lesson);
}
}
- private void fireLessonModified(Lesson lesson)
- {
- if (lesson.canSave())
- {
- for (LessonObserver observer : m_lessonObservers)
- {
+ private void fireLessonModified(Lesson lesson) {
+ if (lesson.canSave()) {
+ for (LessonObserver observer : m_lessonObservers) {
observer.lessonModified(lesson);
}
}
@@ -545,9 +490,8 @@ private void fireLessonModified(Lesson lesson)
/**
* @param args the command line arguments
*/
- public static void main(String args[])
- {
+ public static void main(String args[]) {
File file = args.length >= 1 ? new File(args[0]) : null;
- Main.getInstance().run(file);
+ Main.getInstance().run(file);
}
}
diff --git a/src/jmemorize/gui/swing/widgets/ExtentProgressBar.java b/src/jmemorize/gui/swing/widgets/ExtentProgressBar.java
index edb77e3..a3386a9 100644
--- a/src/jmemorize/gui/swing/widgets/ExtentProgressBar.java
+++ b/src/jmemorize/gui/swing/widgets/ExtentProgressBar.java
@@ -15,49 +15,62 @@
/**
* @author bret5 Copyright(C) 2007 bret5
*
- * This class extends JProgressBar in order to show two values for progress,
- * which are presumably related so that they can be shown on a stacked bar.
+ * This class extends JProgressBar in order to show two values for
+ * progress,
+ * which are presumably related so that they can be shown on a stacked
+ * bar.
*
- * The underlying data object, the BoundedRangeModel, already has a data member,
- * extent, representing the length of an inner range, so all we have to do is
- * expose methods for adjusting the value of extent and implement a paint method
- * which paints the inner range in a separate color.
+ * The underlying data object, the BoundedRangeModel, already has a data
+ * member,
+ * extent, representing the length of an inner range, so all we have to
+ * do is
+ * expose methods for adjusting the value of extent and implement a
+ * paint method
+ * which paints the inner range in a separate color.
*
- * The drawback to this painting implementation is that if isStringPainted, then
- * the rectangle representing the extent paints over the text. - Workaround - if
- * you want the the text to be visible through the extent rectangle, set the
- * extentForeground to a partially transparent color. See the included main for
- * an example.
+ * The drawback to this painting implementation is that if
+ * isStringPainted, then
+ * the rectangle representing the extent paints over the text. -
+ * Workaround - if
+ * you want the the text to be visible through the extent rectangle, set
+ * the
+ * extentForeground to a partially transparent color. See the included
+ * main for
+ * an example.
*
- * TODO - fixing this requires fully implementing paint (background, both
- * rectangles, and the text in three colors).
+ * TODO - fixing this requires fully implementing paint (background,
+ * both
+ * rectangles, and the text in three colors).
*
- * 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) any later version.
+ * 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) any later version.
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
*
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
- * Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass
+ * Ave, Cambridge, MA 02139, USA.
*/
-public class ExtentProgressBar extends JProgressBar
-{
+public class ExtentProgressBar extends JProgressBar {
private Color extentForeground;
- public void setExtent(int n)
- {
+ public void setExtent(int n) {
getModel().setExtent(n);
repaint();
}
- public int getExtent()
- {
+ public int getExtent() {
return getModel().getExtent();
}
@@ -66,8 +79,7 @@ public int getExtent()
*
* @param fg
*/
- public void setExtentForeground(Color fg)
- {
+ public void setExtentForeground(Color fg) {
extentForeground = fg;
}
@@ -76,13 +88,11 @@ public void setExtentForeground(Color fg)
*
* @return the color used to paint the extent value
*/
- public Color getExtentForeground()
- {
+ public Color getExtentForeground() {
return extentForeground;
}
- protected void paintComponent(Graphics g)
- {
+ protected void paintComponent(Graphics g) {
// first use the superclass to paint the bar
super.paintComponent(g);
Insets insets = getInsets();
@@ -100,19 +110,16 @@ protected void paintComponent(Graphics g)
int y, w, h = 0;
int barHeight = getHeight() - (insets.top + insets.bottom);
int barWidth = getWidth() - (insets.left + insets.right);
- if (getOrientation() == HORIZONTAL)
- {
+ if (getOrientation() == HORIZONTAL) {
y = getY() + insets.top;
- x += (int)(barWidth * (value / outerRange));
- w = (int)(barWidth * (extent / outerRange));
+ x += (int) (barWidth * (value / outerRange));
+ w = (int) (barWidth * (extent / outerRange));
h = barHeight;
- }
- else
- {
+ } else {
// Vertical bars start at the bottom and go up
y = getY() + barHeight;
- y -= (int)(barHeight * (value / outerRange));
- h = (int)(barHeight * (extent / outerRange));
+ y -= (int) (barHeight * (value / outerRange));
+ h = (int) (barHeight * (extent / outerRange));
y -= h;
w = barWidth;
}
@@ -147,46 +154,47 @@ private static void createAndShowGUI()
frame.getContentPane().add(bar);
frame.addKeyListener(new KeyAdapter()
+ /* BUG#2 FIXED SALMA */
{
public void keyPressed(KeyEvent arg0)
{
switch (arg0.getKeyCode())
{
- case KeyEvent.VK_LEFT:
- bar.setValue(bar.getValue() - 1);
- break;
- case KeyEvent.VK_RIGHT:
- bar.setValue(bar.getValue() + 1);
- break;
- case KeyEvent.VK_UP:
- bar.setExtent(bar.getExtent() + 1);
- break;
- case KeyEvent.VK_DOWN:
- bar.setExtent(bar.getExtent() - 1);
- break;
- case KeyEvent.VK_1:
- bar.setOrientation(JProgressBar.HORIZONTAL);
- break;
- case KeyEvent.VK_2:
- bar.setOrientation(JProgressBar.VERTICAL);
- break;
- }
- }
- });
+ case KeyEvent.VK_LEFT:
+ bar.setValue(bar.getValue() - 1);
+ break;
+ case KeyEvent.VK_RIGHT:
+ bar.setValue(bar.getValue() + 1);
+ break;
+ case KeyEvent.VK_UP:
+ bar.setExtent(bar.getExtent() + 1);
+ break;
+ case KeyEvent.VK_DOWN:
+ bar.setExtent(bar.getExtent() - 1);
+ break;
+ case KeyEvent.VK_1:
+ bar.setOrientation(JProgressBar.HORIZONTAL);
+ break;
+ case KeyEvent.VK_2:
+ bar.setOrientation(JProgressBar.VERTICAL);
+ break;
+ default:
+ //the default case here }
+ System.out.println("Unrecognized key code: " + arg0.getKeyCode()); }
+
+ }
+ };
// Display the window.
frame.pack();
frame.setVisible(true);
}
- public static void main(String[] args)
- {
+ public static void main(String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
createAndShowGUI();
}
});