Author: echatellier Date: 2009-09-09 13:44:02 +0200 (Wed, 09 Sep 2009) New Revision: 2658 Added: trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor_fr.properties trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob_fr.properties Modified: trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java trunk/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor.properties trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob.properties trunk/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java Log: Add alert UI i18n, improve alert manipulation. Modified: trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -45,10 +45,16 @@ /** serialVersionUID. */ private static final long serialVersionUID = -363052829182024180L; - + /** Current editor. */ protected Component editor; + /** + */ + public AlertCellEditor() { + //super(new JTextField()); + } + /* * @see javax.swing.CellEditor#getCellEditorValue() */ @@ -71,7 +77,7 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - + switch (column) { case 0: JComboBox combo = new JComboBox(); @@ -87,13 +93,19 @@ long duration = ((Long)value).longValue(); durationEditor.setDuration(duration); durationEditor.addPropertyChangeListener("duration", this); + durationEditor.setSize(100, 30); editor = durationEditor; break; - + default: break; } + // restore supercomponent properties + if (isSelected) { + editor.setBackground(table.getSelectionBackground()); + } + return editor; } Modified: trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -47,9 +47,8 @@ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - - super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - + + Component superComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); Component c = null; switch (column) { case 0: @@ -70,6 +69,9 @@ default: break; } + + // restore super properties + c.setBackground(superComponent.getBackground()); return c; } Modified: trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -37,6 +37,7 @@ import org.chorem.jtimer.data.TimerDataManager; import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TimerAlert.Type; import org.jdesktop.application.Action; import org.jdesktop.application.Application; import org.jdesktop.application.FrameView; @@ -54,17 +55,23 @@ /** serialVersionUID. */ private static final long serialVersionUID = 5606265095312928490L; - + + /** Task to manage alert on. */ protected TimerTask task; + /** List of cloned task alert list. */ protected List<TimerAlert> alerts; + /** Manager to commit alert modification. */ protected TimerDataManager timerDataManager; + /** Table to display alerts .*/ protected JTable alertTable; + /** Alert model for table. */ protected AlertTableModel alertModel; + /** Selected alert property. */ protected boolean selectedAlert; /** @@ -88,32 +95,42 @@ // rename frame to get proper position getFrame().setName("alertFrame"); + getFrame().setTitle(getResourceMap().getString("alert.title")); setComponent(getMainComponent()); } + /** + * Build main component. + * + * @return main component + */ protected JComponent getMainComponent() { JPanel panel = new JPanel(new GridBagLayout()); - JLabel label = new JLabel("Alerts list :"); - panel.add(label, new GridBagConstraints(0, 0, 3, 1, 1, 0, + JLabel label = new JLabel(getResourceMap().getString("alert.alertlist")); + panel.add(label, new GridBagConstraints(0, 0, 2, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets( 1, 1, 1, 1), 0, 0)); - alertTable = new JTable(); - alertModel = new AlertTableModel(alerts); - alertTable.setModel(alertModel); - alertTable.setRowHeight(30); + // get column labels + List<String> columnIdentifiers = new ArrayList<String>(); + columnIdentifiers.add(getResourceMap().getString("alert.type")); + columnIdentifiers.add(getResourceMap().getString("alert.duration")); + + alertModel = new AlertTableModel(alerts, columnIdentifiers); + alertTable = new JTable(alertModel); alertTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); alertTable.getColumnModel().getColumn(0).setCellEditor(new AlertCellEditor()); alertTable.getColumnModel().getColumn(1).setCellEditor(new AlertCellEditor()); alertTable.getColumnModel().getColumn(0).setCellRenderer(new AlertCellRenderer()); alertTable.getColumnModel().getColumn(1).setCellRenderer(new AlertCellRenderer()); + alertTable.setRowHeight(30); alertTable.getSelectionModel().addListSelectionListener(this); JScrollPane sp = new JScrollPane(alertTable); - panel.add(sp, new GridBagConstraints(0, 1, 3, 1, 1, 1, + panel.add(sp, new GridBagConstraints(0, 1, 2, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( 1, 1, 1, 1), 0, 0)); @@ -130,12 +147,18 @@ GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - JButton closeButton = new JButton(); - closeButton.setAction(getContext().getActionMap(this).get("close")); - panel.add(closeButton, new GridBagConstraints(2, 2, 1, 1, 1, 0, + JButton cancelButton = new JButton(); + cancelButton.setAction(getContext().getActionMap(this).get("cancel")); + panel.add(cancelButton, new GridBagConstraints(0, 3, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); + JButton saveButton = new JButton(); + saveButton.setAction(getContext().getActionMap(this).get("save")); + panel.add(saveButton, new GridBagConstraints(1, 3, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(1, 1, 1, 1), 0, 0)); + return panel; } @@ -162,6 +185,8 @@ @Action public void addAlert() { TimerAlert alert = new TimerAlert(); + // set default value, too hard to manage with null values :( + alert.setType(Type.REACH_DAILY_TIME); alerts.add(alert); alertModel.fireTableDataChanged(); } @@ -175,17 +200,26 @@ } @Action - public void close() { + public void save() { + + // filter null type alert (forbidden) task.setAlert(alerts); + timerDataManager.modifyAlert(task); getApplication().hide(this); } + @Action + public void cancel() { + getApplication().hide(this); + } + /* * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) */ @Override public void valueChanged(ListSelectionEvent e) { + // used to update remove button property setSelectedAlert(e.getFirstIndex() >= 0); } } Modified: trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -39,11 +39,21 @@ /** serialVersionUID. */ private static final long serialVersionUID = 4103529427954019924L; + /** Table column identifiers. */ + protected List<String> columnIdentifiers; + /** Edition alerts list. */ protected List<TimerAlert> alerts; - public AlertTableModel(List<TimerAlert> alerts) { + /** + * Contructor. + * + * @param alerts alerts list + * @param columnIdentifiers columns identifiers + */ + public AlertTableModel(List<TimerAlert> alerts, List<String> columnIdentifiers) { this.alerts = alerts; + this.columnIdentifiers = columnIdentifiers; } /* @@ -60,15 +70,7 @@ @Override public String getColumnName(int column) { - String columnName = ""; - switch (column) { - case 0: - columnName = "Type"; - break; - case 1: - columnName = "Duration"; - break; - } + String columnName = columnIdentifiers.get(column); return columnName; } Modified: trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -29,8 +29,6 @@ import java.awt.event.MouseListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.Date; import java.util.List; Modified: trunk/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -111,7 +111,7 @@ TimerDataManager dataManager) { super(parentApp); this.parentApp = parentApp; - + // init with False bWantToStop = Boolean.FALSE; @@ -377,13 +377,15 @@ for (TimerAlert alert : task.getAlerts()) { if (!alreadyTrownAlerts.contains(alert)) { if (alert.getType().equals(Type.REACH_DAILY_TIME) && TimerTaskHelper.getTotalTime(task, now) >= alert.getDuration()) { - String alertMessage = "Task '%s' has reached %s for current day !"; - displayAlert(String.format(alertMessage, task.getName(), DurationFormatUtils.formatDuration(alert.getDuration() * 1000, "HH:mm:ss"))); + //String alertMessage = "Task '%s' has reached %s for current day !"; + //displayAlert(String.format(alertMessage, task.getName(), DurationFormatUtils.formatDuration(alert.getDuration() * 1000, "HH:mm:ss"))); + displayAlert(task, Type.REACH_DAILY_TIME, alert.getDuration()); alreadyTrownAlerts.add(alert.clone()); } else if (alert.getType().equals(Type.REACH_TOTAL_TIME) && TimerTaskHelper.getAllTotalTime(task) >= alert.getDuration()) { - String alertMessage = "Task '%s' has reached %s !"; - displayAlert(String.format(alertMessage, task.getName(), DurationFormatUtils.formatDuration(alert.getDuration() * 1000, "HH:mm:ss"))); + //String alertMessage = "Task '%s' has reached %s !"; + //displayAlert(String.format(alertMessage, task.getName(), DurationFormatUtils.formatDuration(alert.getDuration() * 1000, "HH:mm:ss"))); + displayAlert(task, Type.REACH_TOTAL_TIME, alert.getDuration()); alreadyTrownAlerts.add(alert.clone()); } } @@ -402,10 +404,21 @@ * * @param alertMessage alert message */ - protected void displayAlert(final String alertMessage) { + protected void displayAlert(final TimerTask task, final Type alertType, final long alertDuration) { SwingUtilities.invokeLater(new Runnable() { public void run() { - JOptionPane.showMessageDialog(null, alertMessage, "Alert", JOptionPane.INFORMATION_MESSAGE, getResourceMap().getIcon("alertIcon")); + String alertMessage = null; + String formattedTime = DurationFormatUtils.formatDuration(alertDuration * 1000, "HH:mm:ss"); + if (Type.REACH_DAILY_TIME.equals(alertType)) { + alertMessage = getResourceMap().getString("alert.dailyAlertMessage", task.getName(), formattedTime); + } + else if (Type.REACH_TOTAL_TIME.equals(alertType)) { + alertMessage = getResourceMap().getString("alert.totalAlertMessage", task.getName(), formattedTime); + } + + JOptionPane.showMessageDialog(null, alertMessage, + getResourceMap().getString("alert.title"), JOptionPane.INFORMATION_MESSAGE, + getResourceMap().getIcon("alert.alertIcon")); } }); } Modified: trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor.properties 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor.properties 2009-09-09 11:44:02 UTC (rev 2658) @@ -1,3 +1,9 @@ +alert.title = ${Application.title} - Alerts +alert.alertlist = Alert list : +alert.type = Type +alert.duration = Duration + +# buttons addAlert.Action.text = Add addAlert.Action.shortDescription = Add @@ -4,5 +10,8 @@ removeAlert.Action.text = Remove removeAlert.shortDescription = Remove -close.Action.text = Close -close.Action.shortDescription = Close \ No newline at end of file +save.Action.text = Save +save.Action.shortDescription = Save + +cancel.Action.text = Cancel +cancel.Action.shortDescription = Cancel \ No newline at end of file Added: trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor_fr.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor_fr.properties (rev 0) +++ trunk/src/main/resources/org/chorem/jtimer/ui/alert/resources/AlertEditor_fr.properties 2009-09-09 11:44:02 UTC (rev 2658) @@ -0,0 +1,17 @@ +alert.title = ${Application.title} - Alertes +alert.alertlist = Listes des alertes : +alert.type = Type +alert.duration = Dur\u00E9e + +# Boutons +addAlert.Action.text = Ajouter +addAlert.Action.shortDescription = Ajouter une nouvelle alerte + +removeAlert.Action.text = Supprimer +removeAlert.shortDescription = Supprimer l'alerte + +save.Action.text = Sauver +save.Action.shortDescription = Sauver + +cancel.Action.text = Annuler +cancel.Action.shortDescription = Annuler \ No newline at end of file Modified: trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob.properties 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob.properties 2009-09-09 11:44:02 UTC (rev 2658) @@ -1 +1,6 @@ -alertIcon=bell48.png +alert.alertIcon=bell48.png + +# messages +alert.title = Alert +alert.dailyAlertMessage = Task '%s' has reached %s for current day ! +alert.totalAlertMessage = Task '%s' has reached %s ! Added: trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob_fr.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob_fr.properties (rev 0) +++ trunk/src/main/resources/org/chorem/jtimer/ui/tasks/resources/RunTaskJob_fr.properties 2009-09-09 11:44:02 UTC (rev 2658) @@ -0,0 +1,4 @@ +# messages +alert.title = Alerte +alert.dailyAlertMessage = La t\u00E2che '%s' a atteint %s pour ce jour ! +alert.totalAlertMessage = La t\u00E2che '%s' a atteint %s ! Modified: trunk/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java =================================================================== --- trunk/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java 2009-09-09 09:32:27 UTC (rev 2657) +++ trunk/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java 2009-09-09 11:44:02 UTC (rev 2658) @@ -49,8 +49,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { /** Class log */ - private static Log log = LogFactory - .getLog(GTimerIncrementalSaverTest.class); + private static Log log = LogFactory.getLog(GTimerIncrementalSaverTest.class); /** * Test que saveDirectory a une valeur attendue.