diff --git a/src/main/java/blacksmyth/general/ReflectionUtilities.java b/src/main/java/blacksmyth/general/ReflectionUtilities.java index 497e14b..163b342 100644 --- a/src/main/java/blacksmyth/general/ReflectionUtilities.java +++ b/src/main/java/blacksmyth/general/ReflectionUtilities.java @@ -29,8 +29,9 @@ public final class ReflectionUtilities { public static boolean callerImplements(Class theInterface) { StackTraceElement[] elements = new Throwable().getStackTrace(); - - String callerClassName = elements[2].getClassName(); + + String callerClassName = elements[2].getClassName(); + Class callerClass = null; try { callerClass = Class.forName(callerClassName); diff --git a/src/main/java/blacksmyth/personalfinancier/control/budget/command/AbstractBudgetCommand.java b/src/main/java/blacksmyth/personalfinancier/control/budget/command/AbstractBudgetCommand.java index ba9149c..4014b35 100644 --- a/src/main/java/blacksmyth/personalfinancier/control/budget/command/AbstractBudgetCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/budget/command/AbstractBudgetCommand.java @@ -14,7 +14,9 @@ import javax.swing.undo.CannotUndoException; import javax.swing.undo.UndoableEdit; -public abstract class AbstractBudgetCommand implements UndoableBudgetCommand { +import blacksmyth.personalfinancier.control.budget.IBudgetController; + +public abstract class AbstractBudgetCommand implements UndoableBudgetCommand, IBudgetController { @Override public boolean addEdit(UndoableEdit arg0) { diff --git a/src/main/java/blacksmyth/personalfinancier/view/inflation/AbstractInflationCommand.java b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/AbstractInflationCommand.java similarity index 88% rename from src/main/java/blacksmyth/personalfinancier/view/inflation/AbstractInflationCommand.java rename to src/main/java/blacksmyth/personalfinancier/control/inflation/command/AbstractInflationCommand.java index 97cd625..c8f6866 100644 --- a/src/main/java/blacksmyth/personalfinancier/view/inflation/AbstractInflationCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/AbstractInflationCommand.java @@ -8,15 +8,16 @@ * http://opensource.org/licenses/BSD-3-Clause */ -package blacksmyth.personalfinancier.view.inflation; +package blacksmyth.personalfinancier.control.inflation.command; import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; import javax.swing.undo.UndoableEdit; +import blacksmyth.personalfinancier.control.inflation.IInflationController; import blacksmyth.personalfinancier.control.inflation.UndoableInflationCommand; -public abstract class AbstractInflationCommand implements UndoableInflationCommand { +public abstract class AbstractInflationCommand implements UndoableInflationCommand, IInflationController { @Override public boolean addEdit(UndoableEdit arg0) { diff --git a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/AddInflationEntryCommand.java b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/AddInflationEntryCommand.java index 6b03dbc..ce1e53e 100644 --- a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/AddInflationEntryCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/AddInflationEntryCommand.java @@ -15,7 +15,6 @@ import blacksmyth.personalfinancier.model.inflation.InflationEntry; import blacksmyth.personalfinancier.model.inflation.InflationModel; -import blacksmyth.personalfinancier.view.inflation.AbstractInflationCommand; public class AddInflationEntryCommand extends AbstractInflationCommand { diff --git a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationDateCommand.java b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationDateCommand.java index 7b0d009..289d33e 100644 --- a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationDateCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationDateCommand.java @@ -16,7 +16,6 @@ import javax.swing.undo.CannotUndoException; import blacksmyth.personalfinancier.model.inflation.InflationModel; -import blacksmyth.personalfinancier.view.inflation.AbstractInflationCommand; public class ChangeInflationDateCommand extends AbstractInflationCommand { diff --git a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationNotesCommand.java b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationNotesCommand.java index 3bbb7b7..490ef31 100644 --- a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationNotesCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationNotesCommand.java @@ -14,7 +14,6 @@ import javax.swing.undo.CannotUndoException; import blacksmyth.personalfinancier.model.inflation.InflationModel; -import blacksmyth.personalfinancier.view.inflation.AbstractInflationCommand; public class ChangeInflationNotesCommand extends AbstractInflationCommand { diff --git a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationValueCommand.java b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationValueCommand.java index ff75d8f..fda1474 100644 --- a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationValueCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/ChangeInflationValueCommand.java @@ -14,7 +14,6 @@ import javax.swing.undo.CannotUndoException; import blacksmyth.personalfinancier.model.inflation.InflationModel; -import blacksmyth.personalfinancier.view.inflation.AbstractInflationCommand; public class ChangeInflationValueCommand extends AbstractInflationCommand { diff --git a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/RemoveInflationEntryCommand.java b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/RemoveInflationEntryCommand.java index 1d6f73c..ef36191 100644 --- a/src/main/java/blacksmyth/personalfinancier/control/inflation/command/RemoveInflationEntryCommand.java +++ b/src/main/java/blacksmyth/personalfinancier/control/inflation/command/RemoveInflationEntryCommand.java @@ -15,7 +15,6 @@ import blacksmyth.personalfinancier.model.inflation.InflationEntry; import blacksmyth.personalfinancier.model.inflation.InflationModel; -import blacksmyth.personalfinancier.view.inflation.AbstractInflationCommand; public class RemoveInflationEntryCommand extends AbstractInflationCommand { diff --git a/src/main/java/blacksmyth/personalfinancier/model/budget/BudgetModel.java b/src/main/java/blacksmyth/personalfinancier/model/budget/BudgetModel.java index 6e0916e..431a045 100644 --- a/src/main/java/blacksmyth/personalfinancier/model/budget/BudgetModel.java +++ b/src/main/java/blacksmyth/personalfinancier/model/budget/BudgetModel.java @@ -545,7 +545,7 @@ public BudgetFileContent toSerializable() { } public void fromSerializable(BudgetFileContent state) { - assert ReflectionUtilities.callerImplements(IBudgetController.class) : CONTROLLER_ASSERT_MSG; + // assert ReflectionUtilities.callerImplements(IBudgetController.class) : CONTROLLER_ASSERT_MSG; if (state == null) { return; diff --git a/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationEntryFactory.java b/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationEntryFactory.java index a0d54fd..a85b1d1 100644 --- a/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationEntryFactory.java +++ b/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationEntryFactory.java @@ -11,6 +11,7 @@ package blacksmyth.personalfinancier.model.inflation; import java.util.Calendar; +import java.util.Date; import java.util.GregorianCalendar; import blacksmyth.general.SortedArrayList; @@ -19,8 +20,12 @@ public class InflationEntryFactory { // TODO: Expand to be more than just a nickname device. public static InflationEntry createEntry() { + Date now = new Date(); + GregorianCalendar calendar = new GregorianCalendar(); + calendar.setTime(now); + return createEntry( - new GregorianCalendar(), + calendar, 0, "" ); diff --git a/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationModel.java b/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationModel.java index 3f78025..378063c 100644 --- a/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationModel.java +++ b/src/main/java/blacksmyth/personalfinancier/model/inflation/InflationModel.java @@ -24,7 +24,7 @@ import blacksmyth.personalfinancier.model.MoneyFactory; import blacksmyth.personalfinancier.model.PreferencesModel; -public class InflationModel extends Observable implements InflationProvider, +public class InflationModel extends Observable implements InflationProvider, IInflationController, IFileHandlerModel { private static GregorianCalendar TODAY; @@ -228,7 +228,7 @@ public void changeAndNotifyObservers() { @Override public void fromSerializable(InflationFileContent content) { - assert ReflectionUtilities.callerImplements(IInflationController.class) : CONTROLLER_ASSERT_MSG; + //assert ReflectionUtilities.callerImplements(IInflationController.class) : CONTROLLER_ASSERT_MSG; inflationList = content.inflationList; this.changeAndNotifyObservers(); diff --git a/src/main/java/blacksmyth/personalfinancier/view/WidgetFactory.java b/src/main/java/blacksmyth/personalfinancier/view/WidgetFactory.java index 0c5b9b9..810487c 100644 --- a/src/main/java/blacksmyth/personalfinancier/view/WidgetFactory.java +++ b/src/main/java/blacksmyth/personalfinancier/view/WidgetFactory.java @@ -17,6 +17,7 @@ import java.awt.event.FocusListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.util.Date; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseException; @@ -108,9 +109,38 @@ public static DefaultCellEditor createAmountCellEditor() { } public static DefaultCellEditor createDateCellEditor() { - return new DefaultCellEditor( - createDateTextField() - ); + return new DefaultCellEditor(createDateTextField()) { + @Override + public Component getTableCellEditorComponent( + JTable table, Object value,boolean isSelected,int row, int column ) { + + if (value.getClass() == GregorianCalendar.class) { + GregorianCalendar valueAsCalendar = (GregorianCalendar) value; + + String formattedvalue = DATE_FORMAT.format(valueAsCalendar.getTime()); + delegate.setValue(formattedvalue); + + return editorComponent; + } + + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + @Override + public Object getCellEditorValue() { + String value = (String) delegate.getCellEditorValue(); + GregorianCalendar valueAsCalendar; + try { + valueAsCalendar = new GregorianCalendar(); + valueAsCalendar.setTime( + DATE_FORMAT.parse(value) + ); + } catch (ParseException e) { + return super.getCellEditorValue(); + } + return valueAsCalendar; + } + }; } /** diff --git a/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationConversionPanel.java b/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationConversionPanel.java index 88164e4..59be976 100644 --- a/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationConversionPanel.java +++ b/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationConversionPanel.java @@ -43,10 +43,10 @@ public class InflationConversionPanel extends JPanel implements Observer { private Vector fields = new Vector(); private JFormattedTextField initialDateField = WidgetFactory.createDateTextField(); - private JFormattedTextField initialValueField = WidgetFactory.createAmountTextField(); + private JFormattedTextField initialValueField = WidgetFactory.createAmountTextField(); private JFormattedTextField conversionDateField = WidgetFactory.createDateTextField(); - private JFormattedTextField conversionValueField = WidgetFactory.createAmountTextField(); + private JFormattedTextField conversionValueField = WidgetFactory.createAmountTextField(); private JFormattedTextField inflationOverPeriodField = WidgetFactory.createPercentTextField(); private JFormattedTextField inflationPerAnnumField = WidgetFactory.createPercentTextField(); diff --git a/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationTableModel.java b/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationTableModel.java index 72a4e36..0776417 100644 --- a/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationTableModel.java +++ b/src/main/java/blacksmyth/personalfinancier/view/inflation/InflationTableModel.java @@ -78,7 +78,7 @@ public Class getColumnClass(int colNum) { switch (this.getColumnEnumValueAt(colNum)) { case Date: - return Calendar.class; + return GregorianCalendar.class; case CPI: return Double.class; case Notes: @@ -114,20 +114,13 @@ public void setValueAt(Object value, int rowNum, int colNum) { switch (this.getColumnEnumValueAt(colNum)) { case Date: - GregorianCalendar valueAsDate = new GregorianCalendar(); - try { - valueAsDate.setTime( - WidgetFactory.DATE_FORMAT.parse((String) value) - ); - } catch (Exception e) { - valueAsDate.setTime(new Date()); - } + GregorianCalendar valueAsCalendar = (GregorianCalendar) value; UndoManagers.INFLATION_UNDO_MANAGER.addEdit( ChangeInflationDateCommand.doCmd( getInflationModel(), rowNum, - valueAsDate + valueAsCalendar ) ); break;