This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 6af93110296a6304d2c7c61d203e1357234a1493 Author: Eric Chatellier <chatellier@codelutin.com> Date: Wed Aug 3 10:36:56 2016 +0200 Format code and imports --- pom.xml | 5 +- src/main/assembly/bin.xml | 2 +- src/main/config/checkstyle.xml | 249 -------------- src/main/java/org/chorem/jtimer/JTimer.java | 371 ++++++++++----------- src/main/java/org/chorem/jtimer/JTimerActions.java | 8 +- src/main/java/org/chorem/jtimer/JTimerConfig.java | 78 ++--- src/main/java/org/chorem/jtimer/JTimerFactory.java | 8 +- .../org/chorem/jtimer/data/DataEventListener.java | 4 +- .../chorem/jtimer/data/DataViolationException.java | 11 +- .../java/org/chorem/jtimer/data/TimerCore.java | 27 +- .../org/chorem/jtimer/data/TimerDataManager.java | 108 +++--- .../jtimer/data/VetoableDataEventListener.java | 10 +- .../org/chorem/jtimer/entities/TimerAlert.java | 21 +- .../org/chorem/jtimer/entities/TimerProject.java | 8 +- .../java/org/chorem/jtimer/entities/TimerTask.java | 4 +- .../chorem/jtimer/entities/TimerTaskHelper.java | 10 +- .../org/chorem/jtimer/io/DataLockingException.java | 6 +- .../chorem/jtimer/io/GTimerIncrementalSaver.java | 17 +- .../java/org/chorem/jtimer/io/GTimerTimeUtil.java | 14 +- src/main/java/org/chorem/jtimer/io/Saver.java | 16 +- .../jtimer/plugin/timebundle/TimeBundleHelper.java | 3 - .../jtimer/plugin/timebundle/TimeBundleSaver.java | 4 +- .../plugin/timebundle/TimeBundleVetoable.java | 19 +- .../jtimer/plugin/timebundle/TimerSyncEditor.java | 30 +- .../plugin/timebundle/TimerSyncTableModel.java | 10 +- .../java/org/chorem/jtimer/system/SystemInfo.java | 6 +- .../chorem/jtimer/system/SystemInfoFactory.java | 9 +- .../jtimer/system/macos/MacOSSystemInfo.java | 6 +- .../chorem/jtimer/system/unix/UnixSystemInfo.java | 13 +- .../java/org/chorem/jtimer/system/unix/X11.java | 29 +- .../java/org/chorem/jtimer/system/unix/Xss.java | 23 +- .../org/chorem/jtimer/system/win32/Kernel32.java | 6 +- .../org/chorem/jtimer/system/win32/User32.java | 14 +- .../jtimer/system/win32/Win32SystemInfo.java | 10 +- src/main/java/org/chorem/jtimer/ui/HelpFrame.java | 50 ++- .../java/org/chorem/jtimer/ui/NewTaskView.java | 35 +- src/main/java/org/chorem/jtimer/ui/StatusBar.java | 23 +- .../java/org/chorem/jtimer/ui/TimerTaskEditor.java | 154 ++++----- .../chorem/jtimer/ui/alert/AlertCellEditor.java | 69 ++-- .../chorem/jtimer/ui/alert/AlertCellRenderer.java | 47 ++- .../org/chorem/jtimer/ui/alert/AlertEditor.java | 64 ++-- .../chorem/jtimer/ui/alert/AlertTableModel.java | 67 ++-- .../chorem/jtimer/ui/report/ReportGenerator.java | 76 ++--- .../org/chorem/jtimer/ui/report/ReportUtils.java | 90 +++-- .../org/chorem/jtimer/ui/report/ReportView.java | 93 +++--- .../chorem/jtimer/ui/systray/SystrayManager.java | 31 +- .../org/chorem/jtimer/ui/tasks/IdleDialog.java | 75 ++--- .../chorem/jtimer/ui/tasks/RefreshTreeTask.java | 14 +- .../org/chorem/jtimer/ui/tasks/RunTaskJob.java | 81 +++-- .../jtimer/ui/tree/CheckBoxTreeCellComponent.java | 28 +- .../jtimer/ui/tree/CheckBoxTreeCellEditor.java | 40 ++- .../jtimer/ui/tree/CheckBoxTreeCellRenderer.java | 20 +- .../jtimer/ui/tree/ProjectsAndTasksTree.java | 2 +- .../org/chorem/jtimer/ui/tree/TaskTreeModel.java | 61 +--- .../ui/treetable/ProjectsAndTasksCellRenderer.java | 21 +- .../jtimer/ui/treetable/ProjectsAndTasksModel.java | 147 ++++---- .../ProjectsAndTasksRunningCellRenderer.java | 41 +-- .../jtimer/ui/treetable/ProjectsAndTasksTable.java | 45 ++- .../ui/treetable/dnd/TimerTaskTranferable.java | 14 +- .../ui/treetable/dnd/TimerTaskTransferHandler.java | 35 +- .../org/chorem/jtimer/ui/widget/DialogView.java | 15 +- .../chorem/jtimer/ui/widget/DurationEditor.java | 15 +- .../chorem/jtimer/ui/widget/JPopupTrayIcon.java | 15 +- .../chorem/jtimer/ui/widget/WindowProperty2.java | 10 +- .../org/chorem/jtimer/utils/DailySortedMap.java | 17 +- src/main/resources/log4j2.xml | 4 +- .../java/org/chorem/jtimer/AbstractJTimerTest.java | 76 ++--- .../java/org/chorem/jtimer/JTimerFactoryTest.java | 10 +- .../org/chorem/jtimer/data/CommonVetoableTest.java | 28 +- .../chorem/jtimer/data/TimerDataManagerTest.java | 32 +- .../org/chorem/jtimer/entities/TimerAlertTest.java | 26 +- .../chorem/jtimer/entities/TimerProjectTest.java | 10 +- .../org/chorem/jtimer/entities/TimerTaskTest.java | 26 +- .../org/chorem/jtimer/io/AbstractSaverTest.java | 43 ++- .../jtimer/io/GTimerIncrementalSaverTest.java | 53 ++- .../plugin/timebundle/TImeBundleSaverTest.java | 2 +- .../plugin/timebundle/TimeBundleHelperTest.java | 2 - .../jtimer/system/SystemInfoFactoryTest.java | 4 +- .../jtimer/ui/report/ReportGeneratorTest.java | 114 +++---- .../chorem/jtimer/ui/report/ReportUtilsTest.java | 52 +-- .../jtimer/ui/widget/DurationEditorTest.java | 4 +- .../chorem/jtimer/utils/DailySortedMapTest.java | 118 +++---- 82 files changed, 1451 insertions(+), 1807 deletions(-) diff --git a/pom.xml b/pom.xml index ad6f2ba..2c9240a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -98,7 +99,7 @@ <!-- jnlp configuration --> <jnlpFileName>jTimer.jnlp</jnlpFileName> <ciViewId>JTimer</ciViewId> - + <javaVersion>1.8</javaVersion> <signatureArtifactId>java18</signatureArtifactId> <signatureVersion>1.0</signatureVersion> diff --git a/src/main/assembly/bin.xml b/src/main/assembly/bin.xml index c3f7fa1..aafc9a2 100644 --- a/src/main/assembly/bin.xml +++ b/src/main/assembly/bin.xml @@ -22,7 +22,7 @@ --> <assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>bin</id> <formats> <format>zip</format> diff --git a/src/main/config/checkstyle.xml b/src/main/config/checkstyle.xml deleted file mode 100644 index 1b5877e..0000000 --- a/src/main/config/checkstyle.xml +++ /dev/null @@ -1,249 +0,0 @@ -<?xml version="1.0"?> -<!-- - #%L - jTimer - %% - Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - %% - 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 3 of the - License, 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. - - You should have received a copy of the GNU General Public - License along with this program. If not, see - <http://www.gnu.org/licenses/gpl-3.0.html>. - #L% - --> - -<!DOCTYPE module PUBLIC - "-//Puppy Crawl//DTD Check Configuration 1.3//EN" - "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> - -<module name="Checker"> - <!-- - If you set the basedir property below, then all reported file - names will be relative to the specified directory. See - http://checkstyle.sourceforge.net/5.x/config.html#Checker - - <property name="basedir" value="${basedir}"/> - --> - - <property name="severity" value="error"/> - - <!-- <module name="SuppressionFilter"> - <property name="file" value="checkstyle_suppression.xml"/> - </module> --> - - <module name="JavadocPackage"> - <property name="allowLegacy" value="false"/> - </module> - - <!-- <module name="Translation"> - <property name="severity" value="${translation.severity}"/> - </module> --> - - <module name="FileTabCharacter"> - <property name="eachLine" value="false"/> - </module> - - <module name="FileLength"> - <property name="fileExtensions" value="java"/> - </module> - - <module name="NewlineAtEndOfFile"/> - - <!-- <module name="Header"> - <property name="headerFile" value="checkstyle_header.xml"/> - <property name="fileExtensions" value="java"/> - <property name="id" value="header"/> - </module> --> - - <module name="RegexpSingleline"> - <property name="severity" value="info" /> - <property name="format" value="^[^\*]*\s+$"/> - <property name="minimum" value="0"/> - <property name="maximum" value="0"/> - </module> - - <module name="TreeWalker"> - <property name="cacheFile" value="target/cachefile"/> - <property name="tabWidth" value="4" /> - - <module name="AvoidStarImport"/> - <module name="ConstantName"/> - <module name="EmptyBlock"/> - <module name="EmptyForIteratorPad"/> - <module name="EqualsHashCode"/> - <module name="OneStatementPerLine"/> - - <!-- module name="IllegalCatch"/ - <module name="ImportControl"> - <property name="file" value="checkstyle_import.xml"/> - </module> --> - <module name="IllegalImport"/> - <module name="IllegalInstantiation"/> - <module name="IllegalThrows"/> - <module name="InnerAssignment"/> - <module name="JavadocType"> - <property name="authorFormat" value="\S"/> - </module> - <module name="JavadocMethod"> - <property name="allowUndeclaredRTE" value="true"/> - <property name="allowThrowsTagsForSubclasses" value="true"/> - <property name="allowMissingPropertyJavadoc" value="true"/> - </module> - <module name="JavadocVariable"/> - <module name="JavadocStyle"> - <property name="scope" value="public"/> - </module> - - <module name="LeftCurly"> - <property name="option" value="eol"/> - <property name="tokens" value="CLASS_DEF"/> - <property name="tokens" value="CTOR_DEF"/> - <property name="tokens" value="INTERFACE_DEF"/> - <property name="tokens" value="METHOD_DEF"/> - </module> - <module name="LeftCurly"> - <property name="option" value="eol"/> - <property name="tokens" value="LITERAL_CATCH"/> - <property name="tokens" value="LITERAL_DO"/> - <property name="tokens" value="LITERAL_ELSE"/> - <property name="tokens" value="LITERAL_FINALLY"/> - <property name="tokens" value="LITERAL_FOR"/> - <property name="tokens" value="LITERAL_IF"/> - <property name="tokens" value="LITERAL_SWITCH"/> - <property name="tokens" value="LITERAL_SYNCHRONIZED"/> - <property name="tokens" value="LITERAL_TRY"/> - <property name="tokens" value="LITERAL_WHILE"/> - </module> - - <module name="OuterTypeNumber"/> - <module name="LineLength"> - <property name="ignorePattern" value="^ *\* *[^ ]+$"/> - </module> - <module name="MethodCount"> - <property name="maxTotal" value="30"/> - </module> - - <module name="LocalFinalVariableName"/> - <module name="LocalVariableName"/> - <module name="MemberName"> - <property name="format" value="^[a-z][a-zA-Z0-9]*$"/> - </module> - <module name="MethodLength"/> - <module name="MethodName"/> - <module name="MethodParamPad"/> - <module name="ModifierOrder"/> - <module name="NeedBraces"/> - <module name="NoWhitespaceAfter"> - <property name="tokens" value="BNOT"/> - <property name="tokens" value="DEC"/> - <property name="tokens" value="DOT"/> - <property name="tokens" value="INC"/> - <property name="tokens" value="LNOT"/> - <property name="tokens" value="UNARY_MINUS"/> - <property name="tokens" value="UNARY_PLUS"/> - </module> - - <module name="NoWhitespaceBefore"/> - <module name="NoWhitespaceBefore"> - <property name="tokens" value="DOT"/> - <property name="allowLineBreaks" value="true"/> - </module> - - <module name="OperatorWrap"/> - <module name="OperatorWrap"> - <property name="tokens" value="ASSIGN"/> - <property name="tokens" value="DIV_ASSIGN"/> - <property name="tokens" value="PLUS_ASSIGN"/> - <property name="tokens" value="MINUS_ASSIGN"/> - <property name="tokens" value="STAR_ASSIGN"/> - <property name="tokens" value="MOD_ASSIGN"/> - <property name="tokens" value="SR_ASSIGN"/> - <property name="tokens" value="BSR_ASSIGN"/> - <property name="tokens" value="SL_ASSIGN"/> - <property name="tokens" value="BXOR_ASSIGN"/> - <property name="tokens" value="BOR_ASSIGN"/> - <property name="tokens" value="BAND_ASSIGN"/> - <property name="option" value="eol"/> - </module> - <module name="PackageName"/> - <module name="ParameterName"> - <property name="format" value="^[a-z][a-zA-Z0-9]*$"/> - </module> - <module name="ParameterNumber"> - <property name="id" value="paramNum"/> - </module> - <module name="ParenPad"/> - <module name="TypecastParenPad"/> - <module name="RedundantImport"/> - <module name="RedundantModifier"> - <property name="severity" value="warning" /> - </module> - <module name="RightCurly"> - <property name="option" value="same"/> - </module> - <module name="SimplifyBooleanExpression"/> - <module name="SimplifyBooleanReturn"/> - <module name="StaticVariableName"> - <property name="format" value="^[a-z][a-zA-Z0-9]*$"/> - </module> - <module name="TypeName"/> - <module name="UnusedImports"/> - <module name="UpperEll"/> - <module name="VisibilityModifier"> - <property name="protectedAllowed" value="true"/> - </module> - <module name="WhitespaceAfter"> - <property name="tokens" value="COMMA, SEMI"/> - </module> - <module name="WhitespaceAround"/> - <module name="GenericWhitespace"/> - <module name="FinalClass"/> - <module name="MissingSwitchDefault"/> - <module name="MagicNumber"> - <property name="severity" value="warning" /> - <property name="ignoreNumbers" value="-1,0,1, 1"/> - </module> - <module name="Indentation"> - <property name="severity" value="warning" /> - <property name="basicOffset" value="4"/> - <property name="braceAdjustment" value="0"/> - <property name="caseIndent" value="0"/> - </module> - <module name="ArrayTrailingComma"/> - <!--<module name="FinalLocalVariable"/> --> - <module name="EqualsAvoidNull"/> - <module name="ParameterAssignment"/> - - <!-- Generates quite a few errors --> - <module name="CyclomaticComplexity"> - <property name="severity" value="ignore"/> - </module> - - <module name="NestedForDepth"> - <property name="max" value="2"/> - </module> - <module name="NestedIfDepth"> - <property name="max" value="3"/> - </module> - <module name="NestedTryDepth"/> - <module name="ExplicitInitialization"/> - <module name="AnnotationUseStyle"/> - <module name="MissingDeprecated"/> - <module name="MissingOverride"> - <property name="javaFiveCompatibility" value="true"/> - </module> - <module name="PackageAnnotation"/> - <module name="SuppressWarnings"/> - <module name="OuterTypeFilename"/> - <module name="HideUtilityClassConstructor"/> - </module> -</module> diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index 48faf5e..509aafd 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -22,42 +22,6 @@ package org.chorem.jtimer; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Optional; -import java.util.Timer; - -import javax.swing.ButtonGroup; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JRadioButtonMenuItem; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JToolBar; -import javax.swing.KeyStroke; -import javax.swing.ListSelectionModel; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.TreePath; - import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; @@ -67,6 +31,7 @@ import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.plugin.timebundle.TimerSyncEditor; import org.chorem.jtimer.system.SystemInfo; import org.chorem.jtimer.system.SystemInfoFactory; import org.chorem.jtimer.ui.HelpFrame; @@ -75,7 +40,6 @@ import org.chorem.jtimer.ui.StatusBar; import org.chorem.jtimer.ui.TimerTaskEditor; import org.chorem.jtimer.ui.alert.AlertEditor; import org.chorem.jtimer.ui.report.ReportView; -import org.chorem.jtimer.plugin.timebundle.TimerSyncEditor; import org.chorem.jtimer.ui.systray.SystrayManager; import org.chorem.jtimer.ui.tasks.IdleDialog; import org.chorem.jtimer.ui.tasks.RefreshTreeTask; @@ -90,14 +54,49 @@ import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.Task; import org.jdesktop.application.TaskMonitor; +import javax.swing.ButtonGroup; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JScrollPane; +import javax.swing.JSeparator; +import javax.swing.JToolBar; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.TreePath; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.File; +import java.io.IOException; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.Timer; + /** * Main jTimer application window. - * + * * Respect JSR-296 - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -136,7 +135,7 @@ public class JTimer extends SingleFrameApplication implements /** Single non running task selection. */ protected boolean selectedSingleStoppedTask; - + /** Multiples tasks selection (at least 1). */ protected boolean selectedTasks; @@ -154,7 +153,7 @@ public class JTimer extends SingleFrameApplication implements /** * Main. launch UI - * + * * @param args args */ public static void main(String[] args) { @@ -173,7 +172,7 @@ public class JTimer extends SingleFrameApplication implements /** * Initialize application. Called before UI build. - * + * * @param args args * @see Application#initialize(String[]) */ @@ -208,7 +207,7 @@ public class JTimer extends SingleFrameApplication implements /** * Load configuration. - * + * * @param args args to parse command line options */ protected static void loadConfiguration(String[] args) { @@ -226,7 +225,7 @@ public class JTimer extends SingleFrameApplication implements */ protected static void migrateConfiguration() { // add file migration for configuration file created before version 1.4 - File homeDir = new File(System.getProperty("user.home"), ".jtimer"); + File homeDir = new File(System.getProperty("user.home"), ".jtimer"); File oldFile = new File(homeDir, "JTimer.properties"); File newFile = new File(config.appConfig.getUserConfigDirectory(), config.appConfig.getConfigFileName()); if (oldFile.isFile() && !newFile.isFile()) { @@ -245,9 +244,9 @@ public class JTimer extends SingleFrameApplication implements /** * startup. - * + * * Create frame menu bar. Create main component. - * + * * @see Application#startup() */ @Override @@ -263,9 +262,9 @@ public class JTimer extends SingleFrameApplication implements /** * Create main component. - * + * * Toolbar on top. Tree middle. Status bar on bottom. - * + * * @return The component */ protected JComponent createMainComponent() { @@ -296,7 +295,7 @@ public class JTimer extends SingleFrameApplication implements /** * Create complex tree table. - * + * * @return ProjectsAndTaskTable instance */ protected ProjectsAndTasksTable createTreeTable() { @@ -328,12 +327,12 @@ public class JTimer extends SingleFrameApplication implements /** * Create toolbar. - * + * * @return tool bar builded */ protected JComponent createToolBar() { - String[] toolbarActionNames = { "startTask", "stopAllTasks", "newProject", - "newTask", "---", "addAnnotation", "editAlert" }; + String[] toolbarActionNames = {"startTask", "stopAllTasks", "newProject", + "newTask", "---", "addAnnotation", "editAlert"}; JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); for (String actionName : toolbarActionNames) { @@ -358,37 +357,37 @@ public class JTimer extends SingleFrameApplication implements /** * Create application menu bar. - * + * * @return menu bar */ protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); - String[] projectMenuActionNames = { "newProject", "editProject", + String[] projectMenuActionNames = {"newProject", "editProject", "closeProject", "deleteProject", "---", "quit"}; if (JTimerFactory.getSynchronizer() != null) { projectMenuActionNames = ArrayUtils.add(projectMenuActionNames, 2, "editSync"); } menuBar.add(createMenu("projectMenu", projectMenuActionNames)); - String[] taskMenuActionNames = { "newTask", "editTask", "closeTask", + String[] taskMenuActionNames = {"newTask", "editTask", "closeTask", "deleteTask", "---", "startTask", "stopAllTasks", "---", "addAnnotation", "editAlert", "increment1Task", "increment5Task", "increment30Task", "decrement1Task", - "decrement5Task", "decrement30Task", "setToZero", "mergeTasks" }; + "decrement5Task", "decrement30Task", "setToZero", "mergeTasks"}; if (JTimerFactory.getSynchronizer() != null) { taskMenuActionNames = ArrayUtils.add(taskMenuActionNames, 2, "editSync"); } menuBar.add(createMenu("taskMenu", taskMenuActionNames)); - String[] reportMenuActionNames = { "makeReport" }; + String[] reportMenuActionNames = {"makeReport"}; menuBar.add(createMenu("reportMenu", reportMenuActionNames)); JMenu optionmMenu = createOptionMenu(); menuBar.add(optionmMenu); - String[] helpMenuActionNames = { "about" }; + String[] helpMenuActionNames = {"about"}; menuBar.add(createMenu("helpMenu", helpMenuActionNames)); return menuBar; @@ -396,7 +395,7 @@ public class JTimer extends SingleFrameApplication implements /** * Create option dynamic menu. - * + * * @return option menu */ protected JMenu createOptionMenu() { @@ -416,14 +415,14 @@ public class JTimer extends SingleFrameApplication implements closeToSysItem.setSelected(config.isCloseToSystray()); closeToSysItem.setIcon(null); menu.add(closeToSysItem); - + // report first day of week JMenu reportFDoW = new JMenu(); reportFDoW.setName("optionReportFirstDayMenu"); Calendar calendar = Calendar.getInstance(); ButtonGroup bg = new ButtonGroup(); // affiche la liste des jours dans l'ordre de la locale utilisateur - for (int day = calendar.getFirstDayOfWeek() ; day < calendar.getFirstDayOfWeek() + 7 ; day++) { + for (int day = calendar.getFirstDayOfWeek(); day < calendar.getFirstDayOfWeek() + 7; day++) { int realDay = (day - 1) % 7 + 1; JRadioButtonMenuItem fdowItem = new JRadioButtonMenuItem(); fdowItem.setAction(getAction("isReportFirstDayOfWeek" + realDay)); @@ -433,13 +432,13 @@ public class JTimer extends SingleFrameApplication implements bg.add(fdowItem); } menu.add(reportFDoW); - + return menu; } /** * Create single menu. - * + * * @param menuName menu name * @param actionNames associated actions * @return menu @@ -453,9 +452,9 @@ public class JTimer extends SingleFrameApplication implements /** * Add saf action to an existing menu. - * + * * Menu have to be a JMenu or JPopupMenu. - * + * * @param menu parent menu * @param actionNames action names */ @@ -483,7 +482,7 @@ public class JTimer extends SingleFrameApplication implements /** * Ready. Called when UI is ready and displayed. - * + * * @see Application#ready() */ @Override @@ -513,9 +512,9 @@ public class JTimer extends SingleFrameApplication implements /** * Called on application shutdown. - * + * * Save context. - * + * * @see SingleFrameApplication#shutdown() */ @Override @@ -550,12 +549,12 @@ public class JTimer extends SingleFrameApplication implements // task,firstTime,period timer.schedule(refreshTreeTask, date.getTime(), // at date 1000 * 60 * 60 * 24 // every day - ); + ); } /** * Display a popup error message. - * + * * @param errorMessageKey saf error message key */ public void displayErrorMessage(String errorMessageKey) { @@ -574,7 +573,7 @@ public class JTimer extends SingleFrameApplication implements /** * New project action. - * + * * Ask user for project name */ @Action @@ -605,7 +604,7 @@ public class JTimer extends SingleFrameApplication implements /** * Edit project - * + * * Enabled when a project is selected */ @Action(enabledProperty = "selectedSingleProject") @@ -614,8 +613,8 @@ public class JTimer extends SingleFrameApplication implements 0); String newProjectName = (String) JOptionPane.showInputDialog(getMainFrame(), resourceMap - .getString("input.editProjectMessage"), resourceMap - .getString("input.editProjectTitle"), + .getString("input.editProjectMessage"), resourceMap + .getString("input.editProjectTitle"), JOptionPane.INFORMATION_MESSAGE, null, null, project.getName()); if (newProjectName != null) { @@ -633,7 +632,7 @@ public class JTimer extends SingleFrameApplication implements /** * Create new task action. - * + * * Enabled when a project or a task is selected */ @Action(enabledProperty = "selectedSingleElement") @@ -648,7 +647,7 @@ public class JTimer extends SingleFrameApplication implements /** * Auto select task after creation. - * + * * @param task task to select */ public void selectTask(TimerTask task) { @@ -657,7 +656,7 @@ public class JTimer extends SingleFrameApplication implements /** * Edit task. - * + * * Enabled when a task is selected */ @Action(enabledProperty = "selectedSingleTask") @@ -673,7 +672,7 @@ public class JTimer extends SingleFrameApplication implements * Update task. * Enabled when a task is selected */ - @Action(enabledProperty = "selectedSingleElement") + @Action(enabledProperty = "selectedSingleElement") public void editSync() { TimerTask task = projectsAndTasksTable.getSelectedElements().get(0); @@ -683,9 +682,9 @@ public class JTimer extends SingleFrameApplication implements /** * Start selected task in tree. - * + * * If it not already been running - * + * * @return TimerTask scheduled for start * @see Task */ @@ -707,7 +706,7 @@ public class JTimer extends SingleFrameApplication implements /** * Start task pointed by taskPath. - * + * * @param taskPath task path to start (from root to task) */ public void startTask(String taskPath) { @@ -726,10 +725,10 @@ public class JTimer extends SingleFrameApplication implements } } } - + /** * Called by task job manager when task as been started. - * + * * @param task started task */ public void startedTask(TimerTask task) { @@ -739,7 +738,7 @@ public class JTimer extends SingleFrameApplication implements /** * Return job that manage running task. - * + * * @param task timer task to get job * @return job or null */ @@ -759,12 +758,12 @@ public class JTimer extends SingleFrameApplication implements /** * Stop all running task in tree. - * + * * Verify if it has been started */ @Action(enabledProperty = "singleRunningTask") public void stopAllTasks() { - + TaskMonitor tm = getContext().getTaskMonitor(); for (Task<?, ?> t : tm.getTasks()) { // task @@ -776,10 +775,10 @@ public class JTimer extends SingleFrameApplication implements /** * Stop a task. - * + * * Delegate method. Called by idle detect ? * Called by delete method too. - * + * * @param task task to stop */ public void stopTask(TimerTask task) { @@ -788,7 +787,7 @@ public class JTimer extends SingleFrameApplication implements if (rtt != null) { rtt.wantToStop(); core.getData().stopTask(task); - + // re-enable/disable buttons setSingleRunningTask(false); setSelectedSingleStoppedTask(true); @@ -827,14 +826,14 @@ public class JTimer extends SingleFrameApplication implements if (projects.size() == 1) { TimerProject firstOne = projects.get(0); confirm = JOptionPane.showConfirmDialog(getMainFrame(), - resourceMap.getString("input.deleteProjectMessage", firstOne.getName()), - resourceMap.getString("input.deleteProjectTitle"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + resourceMap.getString("input.deleteProjectMessage", firstOne.getName()), + resourceMap.getString("input.deleteProjectTitle"), + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } else { confirm = JOptionPane.showConfirmDialog(getMainFrame(), - resourceMap.getString("input.deleteProjectsMessage", projects.size()), - resourceMap.getString("input.deleteProjectTitle"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + resourceMap.getString("input.deleteProjectsMessage", projects.size()), + resourceMap.getString("input.deleteProjectTitle"), + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } if (confirm == JOptionPane.YES_OPTION) { // approved @@ -861,14 +860,14 @@ public class JTimer extends SingleFrameApplication implements if (tasks.size() == 1) { TimerTask firstOne = tasks.get(0); confirm = JOptionPane.showConfirmDialog(getMainFrame(), - resourceMap.getString("input.deleteTaskMessage", firstOne.getName()), - resourceMap.getString("input.deleteTaskTitle"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + resourceMap.getString("input.deleteTaskMessage", firstOne.getName()), + resourceMap.getString("input.deleteTaskTitle"), + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } else { confirm = JOptionPane.showConfirmDialog(getMainFrame(), - resourceMap.getString("input.deleteTasksMessage", tasks.size()), - resourceMap.getString("input.deleteTaskTitle"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + resourceMap.getString("input.deleteTasksMessage", tasks.size()), + resourceMap.getString("input.deleteTaskTitle"), + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); } if (confirm == JOptionPane.YES_OPTION) { // approved @@ -885,7 +884,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change show closed option. - * + * * @param event action event */ @Action @@ -898,7 +897,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change close to systray option. - * + * * @param event action event */ @Action @@ -1014,9 +1013,9 @@ public class JTimer extends SingleFrameApplication implements /** * Increment task time. - * + * * To decrement, set negative increment:) - * + * * @param increment increment in ms */ protected void incrementTaskTime(long increment) { @@ -1135,7 +1134,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected project. - * + * * @return selected project property */ public boolean isSelectedSingleProject() { @@ -1144,7 +1143,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected project property. - * + * * @param selectedSingleProject selected project property */ public void setSelectedSingleProject(boolean selectedSingleProject) { @@ -1156,7 +1155,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected task. - * + * * @return selected task property */ public boolean isSelectedSingleTask() { @@ -1165,7 +1164,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected task property. - * + * * @param selectedSingleTask selected task property */ public void setSelectedSingleTask(boolean selectedSingleTask) { @@ -1176,7 +1175,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected task or project. - * + * * @return selected task or project property */ public boolean isSelectedSingleElement() { @@ -1185,7 +1184,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected task or project property. - * + * * @param selectedSingleElement selected task or project property */ public void setSelectedSingleElement(boolean selectedSingleElement) { @@ -1197,7 +1196,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is running task. - * + * * @return the singleRunningTask */ public boolean isSingleRunningTask() { @@ -1206,7 +1205,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected running task property. - * + * * @param singleRunningTask running task property */ public void setSingleRunningTask(boolean singleRunningTask) { @@ -1217,7 +1216,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected non running task. - * + * * @return selected non running task */ public boolean isSelectedSingleStoppedTask() { @@ -1226,7 +1225,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected non running task property. - * + * * @param selectedSingleStoppedTask selected non running task */ public void setSelectedSingleStoppedTask(boolean selectedSingleStoppedTask) { @@ -1238,7 +1237,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected multiples projects. - * + * * @return selected multiples projects */ public boolean isSelectedMultiplesProjects() { @@ -1247,7 +1246,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected multiples projects property. - * + * * @param selectedMultiplesProjects selected multiples projects */ public void setSelectedMultiplesProjects(boolean selectedMultiplesProjects) { @@ -1259,7 +1258,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected multiples tasks. - * + * * @return selected multiples tasks */ public boolean isSelectedMultiplesTasks() { @@ -1268,7 +1267,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected multiples tasks property. - * + * * @param selectedMultiplesTasks selected multiples tasks */ public void setSelectedMultiplesTasks(boolean selectedMultiplesTasks) { @@ -1280,7 +1279,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected multiples elements. - * + * * @return selected multiples elements */ public boolean isSelectedMultiplesElements() { @@ -1289,7 +1288,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected multiples elements property. - * + * * @param selectedMultiplesElements selected multiples elements */ public void setSelectedMultiplesElements(boolean selectedMultiplesElements) { @@ -1301,7 +1300,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected tasks property. - * + * * @param selectedTasks selected tasks property */ public void setSelectedTasks(boolean selectedTasks) { @@ -1312,7 +1311,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected task property. - * + * * @return selected tasks property */ public boolean isSelectedTasks() { @@ -1321,7 +1320,7 @@ public class JTimer extends SingleFrameApplication implements /** * Change selected projects property. - * + * * @param selectedProjects selected projects property */ public void setSelectedProjects(boolean selectedProjects) { @@ -1332,7 +1331,7 @@ public class JTimer extends SingleFrameApplication implements /** * Is selected task property. - * + * * @return selected tasks property */ public boolean isSelectedProjects() { @@ -1386,9 +1385,9 @@ public class JTimer extends SingleFrameApplication implements /** * Get action for named component. - * + * * Util method. - * + * * @param actionName action name * @return swing action */ @@ -1434,85 +1433,85 @@ public class JTimer extends SingleFrameApplication implements if (log.isDebugEnabled()) { log.debug("Mouse clicked (" + e.getClickCount() - + " clics), source = " - + e.getSource().getClass().getName()); + + " clics), source = " + + e.getSource().getClass().getName()); } switch (e.getButton()) { - // clic gauche - case MouseEvent.BUTTON1: - // clic sur l'arbre des projets - if (e.getSource() == projectsAndTasksTable) { - // demarre la tache lors d'un double clic dessus - if (e.getClickCount() == 2) { - - if (isSelectedSingleStoppedTask()) { // can only launch non running tasks - Task<?, ?> appTask = startTask(); - if (appTask != null) { - getContext().getTaskService().execute(appTask); + // clic gauche + case MouseEvent.BUTTON1: + // clic sur l'arbre des projets + if (e.getSource() == projectsAndTasksTable) { + // demarre la tache lors d'un double clic dessus + if (e.getClickCount() == 2) { + + if (isSelectedSingleStoppedTask()) { // can only launch non running tasks + Task<?, ?> appTask = startTask(); + if (appTask != null) { + getContext().getTaskService().execute(appTask); + } + } else if (isSelectedSingleTask()) { + TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); + stopTask(task); + } else { + if (log.isDebugEnabled()) { + log.debug("Non selected non running task to launch"); + } } - } else if (isSelectedSingleTask()) { - TimerTask task = projectsAndTasksTable.getSelectedTasks().get(0); - stopTask(task); } else { if (log.isDebugEnabled()) { - log.debug("Non selected non running task to launch"); + log.debug("Single clic on tree, do nothing"); } } - } else { - if (log.isDebugEnabled()) { - log.debug("Single clic on tree, do nothing"); - } } - } - break; + break; - // gestion du clic droit - case MouseEvent.BUTTON3: + // gestion du clic droit + case MouseEvent.BUTTON3: - // force task selection on rigth clic - TreePath path = projectsAndTasksTable.getPathForLocation(e.getX(), - e.getY()); - int selectedRow = projectsAndTasksTable.getRowForPath(path); - projectsAndTasksTable.getSelectionModel().setSelectionInterval( - selectedRow, selectedRow); + // force task selection on rigth clic + TreePath path = projectsAndTasksTable.getPathForLocation(e.getX(), + e.getY()); + int selectedRow = projectsAndTasksTable.getRowForPath(path); + projectsAndTasksTable.getSelectionModel().setSelectionInterval( + selectedRow, selectedRow); - // fix item selection - JPopupMenu menu = new JPopupMenu(); + // fix item selection + JPopupMenu menu = new JPopupMenu(); - String[] actionNames = null; + String[] actionNames = null; - // construct menu in function of selection - if (isSelectedSingleProject()) { - actionNames = new String[] { "newTask", "---", "newProject", - "editProject", "closeProject", "deleteProject" }; - if (JTimerFactory.getSynchronizer() != null) { - actionNames = ArrayUtils.add(actionNames, 4, "editSync"); + // construct menu in function of selection + if (isSelectedSingleProject()) { + actionNames = new String[]{"newTask", "---", "newProject", + "editProject", "closeProject", "deleteProject"}; + if (JTimerFactory.getSynchronizer() != null) { + actionNames = ArrayUtils.add(actionNames, 4, "editSync"); + } } - } - if (isSelectedSingleTask()) { - actionNames = new String[] { "startTask", "---", - "newTask", "editTask", "closeTask", "deleteTask", - "---", "addAnnotation", "editAlert", "increment1Task", - "increment5Task", "increment30Task", "decrement1Task", - "decrement5Task", "decrement30Task", "setToZero" }; - if (JTimerFactory.getSynchronizer() != null) { - actionNames = ArrayUtils.add(actionNames, 4, "editSync"); + if (isSelectedSingleTask()) { + actionNames = new String[]{"startTask", "---", + "newTask", "editTask", "closeTask", "deleteTask", + "---", "addAnnotation", "editAlert", "increment1Task", + "increment5Task", "increment30Task", "decrement1Task", + "decrement5Task", "decrement30Task", "setToZero"}; + if (JTimerFactory.getSynchronizer() != null) { + actionNames = ArrayUtils.add(actionNames, 4, "editSync"); + } } - } - if (isSelectedMultiplesTasks()) { - actionNames = new String[] { "mergeTasks" }; - } + if (isSelectedMultiplesTasks()) { + actionNames = new String[]{"mergeTasks"}; + } - // case, right clic, but nothing selected - if (actionNames != null) { - addActionToMenu(menu, actionNames); + // case, right clic, but nothing selected + if (actionNames != null) { + addActionToMenu(menu, actionNames); - menu.show(e.getComponent(), e.getX(), e.getY()); - } + menu.show(e.getComponent(), e.getX(), e.getY()); + } } } diff --git a/src/main/java/org/chorem/jtimer/JTimerActions.java b/src/main/java/org/chorem/jtimer/JTimerActions.java index e9df9a2..cc9da2d 100644 --- a/src/main/java/org/chorem/jtimer/JTimerActions.java +++ b/src/main/java/org/chorem/jtimer/JTimerActions.java @@ -28,10 +28,10 @@ import org.nuiton.config.ApplicationConfig.Action.Step; /** * JTimer actions class run from command line. - * + * * @author chatellier * @version $Revision: 2825 $ - * + * * Last update : $Date: 2012-03-15 11:41:39 +0100 (jeu. 15 mars 2012) $ * By : $Author: echatellier $ */ @@ -48,7 +48,7 @@ public class JTimerActions { displayVersion(); System.out.println(); for (JTimerAction a : JTimerAction.values()) { - for (int index = 0 ; index < a.aliases.length ; index++) { + for (int index = 0; index < a.aliases.length; index++) { System.out.print(a.aliases[index]); if (index != a.aliases.length - 1) { System.out.print(", "); @@ -64,7 +64,7 @@ public class JTimerActions { displayVersion(); System.exit(0); } - + protected void displayVersion() { System.out.println("jTimer " + config.getOption("application.version")); System.out.println(config.getOption("application.website")); diff --git a/src/main/java/org/chorem/jtimer/JTimerConfig.java b/src/main/java/org/chorem/jtimer/JTimerConfig.java index 778b5cd..3c687ce 100644 --- a/src/main/java/org/chorem/jtimer/JTimerConfig.java +++ b/src/main/java/org/chorem/jtimer/JTimerConfig.java @@ -22,6 +22,13 @@ package org.chorem.jtimer; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.config.ApplicationConfig; +import org.nuiton.config.ArgumentsParserException; +import org.yaml.snakeyaml.Yaml; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -34,19 +41,12 @@ import java.nio.file.Path; import java.util.Map; import java.util.TreeMap; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.config.ApplicationConfig; -import org.nuiton.config.ArgumentsParserException; -import org.yaml.snakeyaml.Yaml; - /** * JTimer configuration. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -96,7 +96,7 @@ public class JTimerConfig { /** * Run command line actions for step. - * + * * @param step action step */ public void doAction(int step) { @@ -111,7 +111,7 @@ public class JTimerConfig { /** * Get IO class implementation. - * + * * @return IO save class */ public Class<?> getIOSaverClass() { @@ -130,7 +130,7 @@ public class JTimerConfig { /** * Get jtimer data directory. - * + * * @since 1.5 * @return jtimer 1.5 data directory */ @@ -140,7 +140,7 @@ public class JTimerConfig { /** * Get jtimer backup directory. - * + * * @since 1.5 * @return jtimer 1.5 backup directory */ @@ -150,7 +150,7 @@ public class JTimerConfig { /** * Get gtimer data directory. - * + * * @since 1.5 * @return jtimer < 1.5 data directory */ @@ -160,7 +160,7 @@ public class JTimerConfig { /** * Get gtimer backup directory. - * + * * @since 1.5 * @return jtimer < 1.5 backup directory */ @@ -170,7 +170,7 @@ public class JTimerConfig { /** * Return auto save delay in seconds. - * + * * @return auto save delay */ public long getIOSaverAutoSaveDelay() { @@ -187,7 +187,7 @@ public class JTimerConfig { /** * Return user idle time threshold in seconds. - * + * * @return idle time threshold */ public long getIdleTime() { @@ -196,7 +196,7 @@ public class JTimerConfig { /** * Show closed project on main ui tree. - * + * * @return show closed project */ public boolean isShowClosed() { @@ -205,7 +205,7 @@ public class JTimerConfig { /** * Set show closed option. - * + * * @param showClosed show closed */ public void setShowClosed(boolean showClosed) { @@ -215,7 +215,7 @@ public class JTimerConfig { /** * Get task template from configuration. - * + * * @return task template as map */ public Map<String, Object> getTaskTemplates() { @@ -234,7 +234,7 @@ public class JTimerConfig { result.put(name, r); } } - } catch (DirectoryIteratorException|IOException ex) { + } catch (DirectoryIteratorException | IOException ex) { if (log.isErrorEnabled()) { log.error("Can't create backup", ex); } @@ -246,7 +246,7 @@ public class JTimerConfig { /** * Get close to systray option. - * + * * @return close to systray */ public boolean isCloseToSystray() { @@ -255,7 +255,7 @@ public class JTimerConfig { /** * Set close to systray option - * + * * @param closeToSystray close to systray */ public void setCloseToSystray(boolean closeToSystray) { @@ -266,7 +266,7 @@ public class JTimerConfig { /** * Return first day of week. * Default to {@code -1} (no preference). - * + * * @return first day of week in report */ public int getReportFirstDayOfWeek() { @@ -275,7 +275,7 @@ public class JTimerConfig { /** * Report first day of week. - * + * * @param firstDayOfWeek first day of week */ public void setReportFirstDayOfWeek(int firstDayOfWeek) { @@ -312,20 +312,20 @@ public class JTimerConfig { this.defaultValue = defaultValue; } } - + protected enum JTimerAction { - HELP("Show help", JTimerActions.class.getName() + "#help", "--help", "-h"), - VERSION("Display application version", JTimerActions.class.getName() + "#version", "--version", "-v"), - START("Start task", JTimerActions.class.getName() + "#start", "--start", "-s"); - - protected String description; - protected String action; - protected String[] aliases; - - JTimerAction(String description, String action, String... aliases) { - this.description = description; - this.action = action; - this.aliases = aliases; - } + HELP("Show help", JTimerActions.class.getName() + "#help", "--help", "-h"), + VERSION("Display application version", JTimerActions.class.getName() + "#version", "--version", "-v"), + START("Start task", JTimerActions.class.getName() + "#start", "--start", "-s"); + + protected String description; + protected String action; + protected String[] aliases; + + JTimerAction(String description, String action, String... aliases) { + this.description = description; + this.action = action; + this.aliases = aliases; + } } } diff --git a/src/main/java/org/chorem/jtimer/JTimerFactory.java b/src/main/java/org/chorem/jtimer/JTimerFactory.java index 5689b49..2444718 100644 --- a/src/main/java/org/chorem/jtimer/JTimerFactory.java +++ b/src/main/java/org/chorem/jtimer/JTimerFactory.java @@ -29,10 +29,10 @@ import org.chorem.jtimer.plugin.timebundle.TimeBundleSynchronizer; /** * JTimer config class. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -56,7 +56,7 @@ public class JTimerFactory { /** * Get saver manager. - * + * * @return saver manager */ public static Saver getFileSaver() { @@ -96,7 +96,7 @@ public class JTimerFactory { /** * Get synchronizer manager */ - public static TimeBundleSynchronizer getSynchronizer(){ + public static TimeBundleSynchronizer getSynchronizer() { if (synchronizer == null) { Class<?> synchronizerClass = JTimer.config.getIOSynchronizerClass(); diff --git a/src/main/java/org/chorem/jtimer/data/DataEventListener.java b/src/main/java/org/chorem/jtimer/data/DataEventListener.java index bcc126e..3bd3013 100644 --- a/src/main/java/org/chorem/jtimer/data/DataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/DataEventListener.java @@ -32,10 +32,10 @@ import java.util.List; /** * Data event listener. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ By : $Author$ */ public interface DataEventListener extends EventListener { diff --git a/src/main/java/org/chorem/jtimer/data/DataViolationException.java b/src/main/java/org/chorem/jtimer/data/DataViolationException.java index a3e0044..a12469b 100644 --- a/src/main/java/org/chorem/jtimer/data/DataViolationException.java +++ b/src/main/java/org/chorem/jtimer/data/DataViolationException.java @@ -27,7 +27,7 @@ package org.chorem.jtimer.data; * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -43,7 +43,7 @@ public class DataViolationException extends RuntimeException { /** * Constructor with text message. - * + * * @param message text message * @param exceptionKey exception key */ @@ -54,20 +54,19 @@ public class DataViolationException extends RuntimeException { /** * Constructor with text message and cause. - * + * * @param message text message * @param exceptionKey exception key * @param cause parent cause */ - public DataViolationException(String message, String exceptionKey, - Throwable cause) { + public DataViolationException(String message, String exceptionKey, Throwable cause) { super(message, cause); this.exceptionKey = exceptionKey; } /** * Get exception key. - * + * * @return the exceptionKey */ public String getExceptionKey() { diff --git a/src/main/java/org/chorem/jtimer/data/TimerCore.java b/src/main/java/org/chorem/jtimer/data/TimerCore.java index fe5465b..d103856 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerCore.java +++ b/src/main/java/org/chorem/jtimer/data/TimerCore.java @@ -22,12 +22,6 @@ package org.chorem.jtimer.data; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,12 +34,19 @@ import org.chorem.jtimer.plugin.timebundle.TimeBundleSaver; import org.chorem.jtimer.plugin.timebundle.TimeBundleSynchronizer; import org.chorem.jtimer.plugin.timebundle.TimeBundleVetoable; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + /** * TimerCore - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -83,7 +84,7 @@ public class TimerCore { // add commmon vetoable CommonVetoable commonVetoable = new CommonVetoable(data); data.addVetoableDataEventListener(commonVetoable); - + // init saver implementation saver = JTimerFactory.getFileSaver(); if (saver != null) { @@ -104,8 +105,8 @@ public class TimerCore { /** * Migrate file structure for jtimer 1.5 directories changes. - * - * @throws IOException + * + * @throws IOException */ protected void migrateDirectoryStructure() throws IOException { File newDataDirectory = JTimer.config.getDataDirectory(); @@ -139,7 +140,7 @@ public class TimerCore { /** * Init Load and launch synchronization. - * + * * @return true if init has gone successfully */ public boolean init() { @@ -169,7 +170,7 @@ public class TimerCore { /** * Get data. - * + * * @return timer data */ public TimerDataManager getData() { diff --git a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java index b8bd106..921c3bd 100644 --- a/src/main/java/org/chorem/jtimer/data/TimerDataManager.java +++ b/src/main/java/org/chorem/jtimer/data/TimerDataManager.java @@ -22,6 +22,13 @@ package org.chorem.jtimer.data; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; + import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -32,21 +39,13 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; - /** * Gere les donnees. Des objets peuvent s'enregistrer pour etre notifies des * changements de donnees. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date: 2008-06-19 10:17:31 +0200 (jeu., 19 juin 2008)$ * By : $Author$ */ @@ -54,7 +53,7 @@ public class TimerDataManager { /** log. */ private static Log log = LogFactory.getLog(TimerDataManager.class); - + /** Project list. */ protected List<TimerProject> projectList; @@ -79,7 +78,7 @@ public class TimerDataManager { /** * Add listener. - * + * * @param listener listener */ public void addDataEventListener(DataEventListener listener) { @@ -88,7 +87,7 @@ public class TimerDataManager { /** * Remove listener. - * + * * @param listener listener */ public void removeDataEventListener(DataEventListener listener) { @@ -97,7 +96,7 @@ public class TimerDataManager { /** * Add vetoable listener. - * + * * @param listener listener */ public void addVetoableDataEventListener( @@ -107,7 +106,7 @@ public class TimerDataManager { /** * Remove vetoable listener. - * + * * @param listener listener */ public void removeVetoableDataEventListener( @@ -117,7 +116,7 @@ public class TimerDataManager { /** * Add single project. - * + * * @param project a project */ public void addProject(TimerProject project) { @@ -137,7 +136,7 @@ public class TimerDataManager { /** * Add single task. - * + * * @param parent parent task * @param task task to add * @param taskTemplate task template to apply for subtasks @@ -155,7 +154,7 @@ public class TimerDataManager { for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.addTask(task); } - + if (taskTemplate != null) { Object subTasks = JTimer.config.getTaskTemplates().get(taskTemplate); createSubTasks(subTasks, task); @@ -164,13 +163,13 @@ public class TimerDataManager { /** * Recursive method to apply tempate to current task. - * + * * @param subTasks template to apply * @param task current subtask */ protected void createSubTasks(Object subTasks, TimerTask task) { if (subTasks != null && subTasks instanceof Map) { - Map<String, Object> realSubTasks = (Map<String, Object>)subTasks; + Map<String, Object> realSubTasks = (Map<String, Object>) subTasks; for (Map.Entry<String, Object> entry : realSubTasks.entrySet()) { String name = entry.getKey(); Object newSubTasks = entry.getValue(); @@ -179,14 +178,14 @@ public class TimerDataManager { // Fix creation date newTask.setCreationDate(new Date()); - + task.addTask(newTask); // send notification for (DataEventListener dataEventListener : dataEventListeners) { dataEventListener.addTask(newTask); } - + createSubTasks(newSubTasks, newTask); } } @@ -194,7 +193,7 @@ public class TimerDataManager { /** * Add many projects. - * + * * @param projects project collection */ public void addAllProjects(Collection<TimerProject> projects) { @@ -211,9 +210,9 @@ public class TimerDataManager { /** * Get projects list. - * + * * synchronized to prevent manipulation during save. - * + * * @return list of projects */ public List<TimerProject> getProjectsList() { @@ -222,13 +221,13 @@ public class TimerDataManager { /** * Change time for the given date. - * + * * @param task the task to change time * @param date date to change time * @param value new time in ms */ public void changeTaskTime(TimerTask task, Date date, - long value) { + long value) { // fire vetoable event for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { @@ -245,7 +244,7 @@ public class TimerDataManager { /** * Start task. - * + * * @param task task to start */ public void startTask(TimerTask task) { @@ -257,7 +256,7 @@ public class TimerDataManager { /** * Stop task. - * + * * @param task task to stop */ public void stopTask(TimerTask task) { @@ -269,7 +268,7 @@ public class TimerDataManager { /** * Delete task. - * + * * @param task task to delete */ public void deleteTask(TimerTask task) { @@ -290,7 +289,7 @@ public class TimerDataManager { /** * Delete project. - * + * * @param project project to delete */ public void deleteProject(TimerProject project) { @@ -310,7 +309,7 @@ public class TimerDataManager { /** * Close project. - * + * * @param project project to close */ public void changeProjectCloseState(TimerProject project) { @@ -343,7 +342,7 @@ public class TimerDataManager { /** * Close task. - * + * * @param task task to close */ public void changeTaskCloseState(TimerTask task) { @@ -363,7 +362,7 @@ public class TimerDataManager { /** * Edit project. - * + * * @param project project to edit * @param newProjectName new project name * @@ -371,7 +370,7 @@ public class TimerDataManager { */ @Deprecated public void editProject(TimerProject project, - String newProjectName) { + String newProjectName) { // fire vetoable event TimerProject newProject = project.clone(); @@ -390,7 +389,7 @@ public class TimerDataManager { /** * Edit task. - * + * * @param task task to edit * @param newTaskName new task name * @@ -443,7 +442,7 @@ public class TimerDataManager { /** * Move task. - * + * * @param destination task to move to * @param tasksToMove tasks to move */ @@ -478,17 +477,17 @@ public class TimerDataManager { /** * Merge tasks. - * + * * @param destinationTask task where task will be merged * @param otherTasks task to merge in first task */ public void mergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - + // fire vetoable event for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { vetoableDataEventListener.checkMergeTasks(destinationTask, otherTasks); } - + // send pre notification Iterator<DataEventListener> itDataEventListener = dataEventListeners .iterator(); @@ -509,7 +508,7 @@ public class TimerDataManager { /** * Merge two task together. - * + * * @param destinationTask task where task will be merged * @param otherTask task to merge in first task */ @@ -541,16 +540,15 @@ public class TimerDataManager { } // just move moveTask(destinationTask, Collections.singleton(otherTaskSubTask)); - } - else { + } else { // task must be merged if (log.isDebugEnabled()) { log.debug("Sub-merging of " + sameTaskNameTask.getName() + " and " + otherTaskSubTask.getName()); } - + // recursive merge mergeTwoTasks(sameTaskNameTask, otherTaskSubTask); - + // TODO possible bug here, task times may not be saved } } @@ -563,12 +561,12 @@ public class TimerDataManager { } // copy annotations - for (Entry<Date, String> note : otherTask.getAllDaysAnnotations().entrySet()) { + for (Entry<Date, String> note : otherTask.getAllDaysAnnotations().entrySet()) { Date noteKey = note.getKey(); while (destinationTask.getAllDaysAnnotations().containsKey(noteKey)) { // les deux taches ont des notes au meme moments // on ne deplace à la prochaine seconde - + if (log.isDebugEnabled()) { log.debug("Annotation collision detected, try next second"); } @@ -590,18 +588,18 @@ public class TimerDataManager { /** * Add annotation on task for specified calendar, and send event. - * + * * @param task task * @param date day of annotation * @param annotation annotation */ public void addAnnotation(TimerTask task, Date date, - String annotation) { + String annotation) { // fire vetoable event for (VetoableDataEventListener vetoableDataEventListener : vetoableDataEventListeners) { vetoableDataEventListener.checkSetAnnotation(task, date, - annotation); + annotation); } task.addAnnotation(date, annotation); @@ -614,7 +612,7 @@ public class TimerDataManager { /** * Notify alert modification. - * + * * @param task task where alert has been modified */ public void modifyAlert(TimerTask task) { @@ -628,14 +626,14 @@ public class TimerDataManager { /** * Return the corresponding task for path. - * + * * @param taskPath task path to find * @return corresponding task for path */ public TimerTask getTaskForPath(String taskPath) { - + String[] paths = taskPath.split("/"); - + // make sure can't select only project if (paths.length <= 1) { throw new IllegalArgumentException("Can't parse argument '" + taskPath + "' as task"); @@ -646,7 +644,7 @@ public class TimerDataManager { /** * Find task in tasks collections. - * + * * @param tasks task collection * @param paths task path to find * @return found task diff --git a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java index d86787c..831205c 100644 --- a/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java +++ b/src/main/java/org/chorem/jtimer/data/VetoableDataEventListener.java @@ -22,20 +22,20 @@ package org.chorem.jtimer.data; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; + import java.util.Collection; import java.util.Date; import java.util.EventListener; import java.util.List; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; - /** * Vetoable Data event listener. - * + * * @author chorlet * @version $Revision$ - * + * * Last update : $Date$ By : $Author$ */ public interface VetoableDataEventListener extends EventListener { diff --git a/src/main/java/org/chorem/jtimer/entities/TimerAlert.java b/src/main/java/org/chorem/jtimer/entities/TimerAlert.java index 6eb2a7b..697cd82 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerAlert.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerAlert.java @@ -26,10 +26,10 @@ import java.io.Serializable; /** * Alert. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -61,7 +61,7 @@ public class TimerAlert implements Serializable, Cloneable { /** * Constructor. - * + * * @param type type * @param duration duration (ms) */ @@ -73,7 +73,7 @@ public class TimerAlert implements Serializable, Cloneable { /** * Get alert type. - * + * * @return the type */ public Type getType() { @@ -82,7 +82,7 @@ public class TimerAlert implements Serializable, Cloneable { /** * Set alert type. - * + * * @param type the type to set */ public void setType(Type type) { @@ -91,7 +91,7 @@ public class TimerAlert implements Serializable, Cloneable { /** * Get duration. - * + * * @return the duration in seconds */ public long getDuration() { @@ -100,7 +100,7 @@ public class TimerAlert implements Serializable, Cloneable { /** * Set duration. - * + * * @param duration the duration to set (in seconds) */ public void setDuration(long duration) { @@ -111,7 +111,7 @@ public class TimerAlert implements Serializable, Cloneable { public TimerAlert clone() { TimerAlert clone; try { - clone = (TimerAlert)super.clone(); + clone = (TimerAlert) super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException("Can't clone", e); } @@ -132,12 +132,11 @@ public class TimerAlert implements Serializable, Cloneable { if (obj instanceof TimerAlert) { TimerAlert other = (TimerAlert) obj; - + result = duration == other.duration; if (type != null) { result &= type.equals(other.type); - } - else { + } else { result &= other.type == null; } } diff --git a/src/main/java/org/chorem/jtimer/entities/TimerProject.java b/src/main/java/org/chorem/jtimer/entities/TimerProject.java index ad64ff6..8e2ee2c 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerProject.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerProject.java @@ -24,10 +24,10 @@ package org.chorem.jtimer.entities; /** * Represent a project. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -44,7 +44,7 @@ public class TimerProject extends TimerTask { /** * Constructor with name. - * + * * @param name project name */ public TimerProject(String name) { @@ -53,7 +53,7 @@ public class TimerProject extends TimerTask { /** * Clone project. - * + * * @return project copy */ @Override diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index 0043d52..01c805c 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -22,6 +22,8 @@ package org.chorem.jtimer.entities; +import org.chorem.jtimer.utils.DailySortedMap; + import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -30,8 +32,6 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.UUID; -import org.chorem.jtimer.utils.DailySortedMap; - /** * Represents a task. * diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java index e6f8eb2..37e8ef1 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTaskHelper.java @@ -232,10 +232,9 @@ public class TimerTaskHelper { SortedMap<Date, String> annotations = new TreeMap<>(); - task.getAllDaysAnnotations().keySet().stream().filter(day -> day.compareTo(beginCal.getTime()) >= 0 - && day.compareTo(endCal.getTime()) < 0).forEach(day -> - annotations.put(day, task.getAllDaysAnnotations().get(day)) - ); + task.getAllDaysAnnotations().keySet().stream() + .filter(day -> day.compareTo(beginCal.getTime()) >= 0 && day.compareTo(endCal.getTime()) < 0) + .forEach(day -> annotations.put(day, task.getAllDaysAnnotations().get(day))); return annotations; } @@ -276,8 +275,7 @@ public class TimerTaskHelper { Calendar endCal = (Calendar) beginCal.clone(); endCal.add(Calendar.DAY_OF_YEAR, 1); - for (Iterator<Date> iterator = task.getAllDaysAnnotations().keySet() - .iterator(); iterator.hasNext();) { + for (Iterator<Date> iterator = task.getAllDaysAnnotations().keySet().iterator(); iterator.hasNext(); ) { Date day = iterator.next(); if (day.compareTo(beginCal.getTime()) >= 0 && day.compareTo(endCal.getTime()) < 0) { diff --git a/src/main/java/org/chorem/jtimer/io/DataLockingException.java b/src/main/java/org/chorem/jtimer/io/DataLockingException.java index 0e08de1..adf184b 100644 --- a/src/main/java/org/chorem/jtimer/io/DataLockingException.java +++ b/src/main/java/org/chorem/jtimer/io/DataLockingException.java @@ -27,7 +27,7 @@ package org.chorem.jtimer.io; * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -38,7 +38,7 @@ public class DataLockingException extends Exception { /** * Constructor with text message. - * + * * @param message text message */ public DataLockingException(String message) { @@ -47,7 +47,7 @@ public class DataLockingException extends Exception { /** * Constructor with text message and cause. - * + * * @param message text message * @param cause parent cause */ diff --git a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java index 449b32b..3d4a5d6 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerIncrementalSaver.java @@ -822,7 +822,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, Files.delete(file); } } - } catch (DirectoryIteratorException|IOException ex) { + } catch (DirectoryIteratorException | IOException ex) { if (log.isErrorEnabled()) { log.error("Can't create backup", ex); } @@ -940,8 +940,7 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, * @param associatedToProject associated project number * @param taskPrefixName task prefix name */ - protected void saveTask(TimerTask task, int associatedToProject, - String taskPrefixName) { + protected void saveTask(TimerTask task, int associatedToProject, String taskPrefixName) { // check project number if (associatedToProject < 0) { @@ -1096,12 +1095,12 @@ public class GTimerIncrementalSaver extends AbstractSaver implements Saver, long duration = alert.getDuration() / 1000; switch (type) { - case REACH_DAILY_TIME: - out.write("reachdailytime " + duration + "\n"); - break; - case REACH_TOTAL_TIME: - out.write("reachtotaltime " + duration + "\n"); - break; + case REACH_DAILY_TIME: + out.write("reachdailytime " + duration + "\n"); + break; + case REACH_TOTAL_TIME: + out.write("reachtotaltime " + duration + "\n"); + break; } } diff --git a/src/main/java/org/chorem/jtimer/io/GTimerTimeUtil.java b/src/main/java/org/chorem/jtimer/io/GTimerTimeUtil.java index feb8937..64f0bff 100644 --- a/src/main/java/org/chorem/jtimer/io/GTimerTimeUtil.java +++ b/src/main/java/org/chorem/jtimer/io/GTimerTimeUtil.java @@ -22,20 +22,20 @@ package org.chorem.jtimer.io; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - /** * Util class to manipulate gTimer date format. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ By : $Author$ */ public class GTimerTimeUtil { @@ -55,7 +55,7 @@ public class GTimerTimeUtil { /** * Convert a yyyyMMdd date string to Calendar. - * + * * @param dateAsString yyyyMMdd sting to convert * @return {@link Date} * @throws IllegalArgumentException @@ -92,7 +92,7 @@ public class GTimerTimeUtil { /** * Convert a calendar to yyyyMMdd date string. - * + * * @param date date to convert * @return a string yyyyMMdd date * @throws IllegalArgumentException diff --git a/src/main/java/org/chorem/jtimer/io/Saver.java b/src/main/java/org/chorem/jtimer/io/Saver.java index 7c54c59..eac4514 100644 --- a/src/main/java/org/chorem/jtimer/io/Saver.java +++ b/src/main/java/org/chorem/jtimer/io/Saver.java @@ -22,18 +22,18 @@ package org.chorem.jtimer.io; -import java.util.Collection; - import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.VetoableDataEventListener; import org.chorem.jtimer.entities.TimerProject; +import java.util.Collection; + /** * Common interface for jtimer data savers. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -41,28 +41,28 @@ public interface Saver extends DataEventListener, VetoableDataEventListener { /** * Set auto save delay (in milliseconds). - * + * * @param autoSaveDelay delay in milliseconds */ void setAutoSaveDelay(long autoSaveDelay); /** * Try to lock current saver directory. - * + * * @throws DataLockingException if can't obtain lock */ void lock() throws DataLockingException; /** * Try to unlock current saver directory. - * + * * @throws DataLockingException if there is no lock */ void unlock() throws DataLockingException; /** * Load a project list. - * + * * @return a collection of projects */ Collection<TimerProject> load(); diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java index 00d0e54..7b3d9ba 100644 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java +++ b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelper.java @@ -25,13 +25,10 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; -import org.apache.commons.lang3.time.DurationFormatUtils; import org.chorem.jtimer.entities.TimerSync; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; -import java.time.LocalDate; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java index 862fc50..47e0d41 100644 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java +++ b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleSaver.java @@ -208,8 +208,8 @@ public class TimeBundleSaver implements DataEventListener { public void postMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { otherTasks.forEach(task -> { task.getSyncs().forEach(sync -> { - boolean urlExists = destinationTask.getSyncs().stream() // - .anyMatch(timerSync -> timerSync.getUrl().equals(sync.getUrl())); + boolean urlExists = destinationTask.getSyncs().stream() + .anyMatch(timerSync -> timerSync.getUrl().equals(sync.getUrl())); if (!urlExists) { destinationTask.getSyncs().add(sync); } diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java index b4f34e5..8a2c323 100644 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java +++ b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimeBundleVetoable.java @@ -21,9 +21,6 @@ */ package org.chorem.jtimer.plugin.timebundle; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.data.VetoableDataEventListener; import org.chorem.jtimer.entities.TimerSync; @@ -38,8 +35,6 @@ import java.util.stream.Collectors; */ public class TimeBundleVetoable implements VetoableDataEventListener { - private static Log log = LogFactory.getLog(TimeBundleVetoable.class); - /** * Merge project violation key. */ @@ -47,13 +42,13 @@ public class TimeBundleVetoable implements VetoableDataEventListener { @Override public void checkMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { - Set<String> allUrls = otherTasks.stream() // - .flatMap(t -> t.getSyncs().stream()) // - .map(TimerSync::getUrl) // - .collect(Collectors.toSet()); - Set<String> destUrls = destinationTask.getSyncs().stream() // - .map(TimerSync::getUrl) // - .collect(Collectors.toSet()); + Set<String> allUrls = otherTasks.stream() + .flatMap(t -> t.getSyncs().stream()) + .map(TimerSync::getUrl) + .collect(Collectors.toSet()); + Set<String> destUrls = destinationTask.getSyncs().stream() + .map(TimerSync::getUrl) + .collect(Collectors.toSet()); if (!allUrls.equals(destUrls)) { throw new DataViolationException("Can't merge tasks", INVALID_SYNC_LIST_VIOLATION); } diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java index 4ece14f..ad70964 100644 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java +++ b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncEditor.java @@ -21,18 +21,6 @@ */ package org.chorem.jtimer.plugin.timebundle; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.table.TableColumnModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.TimerCore; @@ -42,6 +30,19 @@ import org.chorem.jtimer.entities.TimerTask; import org.jdesktop.application.Application; import org.jdesktop.application.FrameView; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.TableColumnModel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + /** * UI to modify Synchronization Info of a task. */ @@ -119,7 +120,7 @@ public class TimerSyncEditor extends FrameView implements ActionListener { configComponent.setLayout(new BorderLayout(5, 5)); JPanel urlPanel = new JPanel(); - urlPanel.setLayout(new BorderLayout(5,5)); + urlPanel.setLayout(new BorderLayout(5, 5)); urlJTable = new JTable(new TimerSyncTableModel(this, task)); //try to have coherent width of columns @@ -215,8 +216,7 @@ public class TimerSyncEditor extends FrameView implements ActionListener { if ("addURL".equals(actionCommand)) { model.add(new TimerSync("")); - } - else if ("deleteURL".equals(actionCommand)) { + } else if ("deleteURL".equals(actionCommand)) { TimerSync timerSync = model.getValueAt(urlJTable.getSelectedRow()); model.remove(timerSync); } diff --git a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java index 94f100e..286d30f 100644 --- a/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java +++ b/src/main/java/org/chorem/jtimer/plugin/timebundle/TimerSyncTableModel.java @@ -43,11 +43,11 @@ public class TimerSyncTableModel extends AbstractTableModel { public TimerSyncTableModel(View view, TimerTask task) { timerSyncList = new ArrayList<>(task.getSyncs()); - columnHeaders = new String[] { - view.getResourceMap().getString("syncURLHeader"), - view.getResourceMap().getString("activeHeader"), - view.getResourceMap().getString("withAnnotationsHeader"), - view.getResourceMap().getString("lastSyncHeader") + columnHeaders = new String[]{ + view.getResourceMap().getString("syncURLHeader"), + view.getResourceMap().getString("activeHeader"), + view.getResourceMap().getString("withAnnotationsHeader"), + view.getResourceMap().getString("lastSyncHeader") }; } diff --git a/src/main/java/org/chorem/jtimer/system/SystemInfo.java b/src/main/java/org/chorem/jtimer/system/SystemInfo.java index a69b83e..f094b59 100644 --- a/src/main/java/org/chorem/jtimer/system/SystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/SystemInfo.java @@ -24,10 +24,10 @@ package org.chorem.jtimer.system; /** * System info interface for all systems. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -40,7 +40,7 @@ public interface SystemInfo { /** * Get system idle time in milliseconds. - * + * * @return system idle time in milliseconds */ long getIdleTime(); diff --git a/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java b/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java index 53881c8..281b365 100644 --- a/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java +++ b/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java @@ -22,22 +22,21 @@ package org.chorem.jtimer.system; +import com.sun.jna.Platform; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.system.macos.MacOSSystemInfo; import org.chorem.jtimer.system.unix.UnixSystemInfo; import org.chorem.jtimer.system.win32.Win32SystemInfo; -import com.sun.jna.Platform; - import java.util.Optional; /** * Build system info determined from system. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -58,7 +57,7 @@ public class SystemInfoFactory { /** * Return system info depending on system. - * + * * @return SystemInfo instance * @see SystemInfo */ diff --git a/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java b/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java index 2c6035f..fa6c657 100644 --- a/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java @@ -26,13 +26,13 @@ import org.chorem.jtimer.system.SystemInfo; /** * MacOSSystemInfo - * + * * Source : http://ochafik.free.fr/blog/?p=98#comment-17694 - * + * * @author chatellier * @version $Revision$ * @since 1.3.2 - * + * * Last update : $Date$ * By : $Author: chatellier $ */ diff --git a/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java b/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java index a0b90d4..dcd563e 100644 --- a/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java @@ -22,23 +22,22 @@ package org.chorem.jtimer.system.unix; +import com.sun.jna.ptr.IntByReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.system.SystemInfo; -import com.sun.jna.ptr.IntByReference; - import java.awt.Toolkit; /** * Linux system info. - * + * * Based on * http://java.net/projects/jdic/sources/svn/content/trunk/src/incubator/system... source code. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -89,7 +88,7 @@ public class UnixSystemInfo implements SystemInfo { /** * Get idle time via Xss. - * + * * @return idle time */ protected long getXssIdleTime() { @@ -141,7 +140,7 @@ public class UnixSystemInfo implements SystemInfo { idleTime = screenSaverInfo.idle.longValue(); } } - + // free resources X11.INSTANCE.XFree(screenSaverInfo.getPointer()); } diff --git a/src/main/java/org/chorem/jtimer/system/unix/X11.java b/src/main/java/org/chorem/jtimer/system/unix/X11.java index bdf7a3b..fb66ded 100644 --- a/src/main/java/org/chorem/jtimer/system/unix/X11.java +++ b/src/main/java/org/chorem/jtimer/system/unix/X11.java @@ -23,20 +23,25 @@ import com.sun.jna.PointerType; /** Definition (incomplete) of the X library. */ public interface X11 extends Library { - class Drawable extends NativeLong { - private static final long serialVersionUID = 1L; - } - class Window extends Drawable { - private static final long serialVersionUID = 1L; - } + class Drawable extends NativeLong { + private static final long serialVersionUID = 1L; + } - class Display extends PointerType { } + class Window extends Drawable { + private static final long serialVersionUID = 1L; + } - X11 INSTANCE = (X11)Native.loadLibrary("X11", X11.class); + class Display extends PointerType { + } - Display XOpenDisplay(String name); - Window XDefaultRootWindow(Display display); - int XFree(Pointer data); - int XCloseDisplay(Display display); + X11 INSTANCE = (X11) Native.loadLibrary("X11", X11.class); + + Display XOpenDisplay(String name); + + Window XDefaultRootWindow(Display display); + + int XFree(Pointer data); + + int XCloseDisplay(Display display); } diff --git a/src/main/java/org/chorem/jtimer/system/unix/Xss.java b/src/main/java/org/chorem/jtimer/system/unix/Xss.java index 7a156e6..44c10c6 100644 --- a/src/main/java/org/chorem/jtimer/system/unix/Xss.java +++ b/src/main/java/org/chorem/jtimer/system/unix/Xss.java @@ -22,23 +22,23 @@ package org.chorem.jtimer.system.unix; -import java.util.Arrays; -import java.util.List; - import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Structure; import com.sun.jna.ptr.IntByReference; +import java.util.Arrays; +import java.util.List; + /** * libXss JNA interface. - * + * * Incomplete definition. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -57,6 +57,7 @@ public interface Xss extends Library { public NativeLong til_or_since; /* time til or since screen saver */ public NativeLong idle; /* total time since last user input */ public NativeLong eventMask; /* currently selected events for this client */ + @Override protected List<?> getFieldOrder() { return Arrays.asList("window", "state", "kind", "til_or_since", "idle", "eventMask"); @@ -65,13 +66,13 @@ public interface Xss extends Library { /** * Information sur l'activation de l'ecran de veille de X11. - * + * * @param display display * @param event_base event_base * @param error_base error_base - * + * * @return true if XScreenSaver extension is loaded - * + * * @see IntByReference */ boolean XScreenSaverQueryExtension(X11.Display display, @@ -79,14 +80,14 @@ public interface Xss extends Library { /** * XScreenSaverAllocInfo. - * + * * @return XScreenSaverInfo instance */ XScreenSaverInfo XScreenSaverAllocInfo(); /** * XScreenSaverQueryInfo. - * + * * @param display * @param drawable * @param infos diff --git a/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java b/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java index 3e7a4ea..1ccc619 100644 --- a/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java +++ b/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java @@ -27,10 +27,10 @@ import com.sun.jna.win32.W32APIOptions; /** * Win kernel32 JNA Interface. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -42,7 +42,7 @@ public interface Kernel32 extends StdCallLibrary { /** * Retrieves the number of milliseconds that have elapsed since the system * was started. - * + * * @see "http://msdn2.microsoft.com/en-us/library/ms724408.aspx" * @return number of milliseconds that have elapsed since the system was * started. diff --git a/src/main/java/org/chorem/jtimer/system/win32/User32.java b/src/main/java/org/chorem/jtimer/system/win32/User32.java index 70d6500..6361181 100644 --- a/src/main/java/org/chorem/jtimer/system/win32/User32.java +++ b/src/main/java/org/chorem/jtimer/system/win32/User32.java @@ -21,24 +21,24 @@ */ package org.chorem.jtimer.system.win32; -import java.util.Arrays; -import java.util.List; - import com.sun.jna.Native; import com.sun.jna.Structure; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; +import java.util.Arrays; +import java.util.List; + /** * Win User32 JNA Interface. - * + * * TODO it not the same code as jna's User32 class. - * + * * @author chatellier * @version $Revision$ * * @see <a href="http://msdn.microsoft.com/en-us/library/ms646272">Windows API</a> - * + * * Last update : $Date$ * By : $Author$ */ @@ -64,7 +64,7 @@ public interface User32 extends StdCallLibrary { /** * Retrieves the time of the last input event. - * + * * @param result time of the last input event, in milliseconds * @return boolean flag */ diff --git a/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java b/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java index bc38335..ea19f42 100644 --- a/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java @@ -26,12 +26,12 @@ import org.chorem.jtimer.system.SystemInfo; /** * Win32 System info. - * + * * From http://ochafik.free.fr/blog/?p=98 - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -42,7 +42,7 @@ public class Win32SystemInfo implements SystemInfo { /** * Constructor. - * + * * Package visibility */ public Win32SystemInfo() { @@ -52,7 +52,7 @@ public class Win32SystemInfo implements SystemInfo { /** * Get the amount of milliseconds that have elapsed since the last input * event (mouse or keyboard) - * + * * @return idle time in milliseconds */ public int getIdleTimeMillisWin32() { diff --git a/src/main/java/org/chorem/jtimer/ui/HelpFrame.java b/src/main/java/org/chorem/jtimer/ui/HelpFrame.java index 44c3009..7e17ff7 100644 --- a/src/main/java/org/chorem/jtimer/ui/HelpFrame.java +++ b/src/main/java/org/chorem/jtimer/ui/HelpFrame.java @@ -22,15 +22,11 @@ package org.chorem.jtimer.ui; -import java.awt.Color; -import java.awt.Component; -import java.awt.Desktop; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.application.Action; +import org.jdesktop.application.Application; +import org.jdesktop.application.FrameView; import javax.swing.Icon; import javax.swing.JButton; @@ -42,19 +38,22 @@ import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.application.Action; -import org.jdesktop.application.Application; -import org.jdesktop.application.FrameView; +import java.awt.Color; +import java.awt.Component; +import java.awt.Desktop; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; /** * Help window. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ By : $Author$ */ public class HelpFrame extends FrameView implements HyperlinkListener { @@ -64,9 +63,9 @@ public class HelpFrame extends FrameView implements HyperlinkListener { /** * Constructor. - * + * * Build UI. - * + * * @param application parent application */ public HelpFrame(Application application) { @@ -84,7 +83,7 @@ public class HelpFrame extends FrameView implements HyperlinkListener { /** * Get UI main component. - * + * * @return view's main component */ protected JComponent getMainComponent() { @@ -109,14 +108,14 @@ public class HelpFrame extends FrameView implements HyperlinkListener { mainComponent.add(tabPanel, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( - 0, 5, 5, 5), 0, 0)); + 0, 5, 5, 5), 0, 0)); // ok button JButton closeButton = new JButton(); closeButton.setAction(getContext().getActionMap(this).get("closeView")); mainComponent.add(closeButton, new GridBagConstraints(0, 2, 1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, - 5, 5, 5), 20, 0)); + 5, 5, 5), 20, 0)); // fix resizing getFrame().setResizable(false); @@ -129,7 +128,7 @@ public class HelpFrame extends FrameView implements HyperlinkListener { /** * Build license tab. - * + * * @return license tab component */ protected Component getLicenseTab() { @@ -144,7 +143,7 @@ public class HelpFrame extends FrameView implements HyperlinkListener { /** * Build about tab. - * + * * @return about tab component */ protected Component getAboutTab() { @@ -164,9 +163,6 @@ public class HelpFrame extends FrameView implements HyperlinkListener { getApplication().hide(this); } - /* - * @see javax.swing.event.HyperlinkListener#hyperlinkUpdate(javax.swing.event.HyperlinkEvent) - */ @Override public void hyperlinkUpdate(HyperlinkEvent he) { if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED diff --git a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java index 17be9cd..effb754 100644 --- a/src/main/java/org/chorem/jtimer/ui/NewTaskView.java +++ b/src/main/java/org/chorem/jtimer/ui/NewTaskView.java @@ -21,13 +21,13 @@ */ package org.chorem.jtimer.ui; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.util.Date; -import java.util.Map; -import java.util.Set; +import org.apache.commons.lang3.StringUtils; +import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.data.DataViolationException; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.ui.widget.DialogView; +import org.jdesktop.application.Action; import javax.swing.ActionMap; import javax.swing.DefaultComboBoxModel; @@ -39,14 +39,13 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.KeyStroke; - -import org.apache.commons.lang3.StringUtils; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.data.DataViolationException; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.ui.widget.DialogView; -import org.jdesktop.application.Action; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.util.Date; +import java.util.Map; +import java.util.Set; /** * New task panel used to ask for: @@ -54,7 +53,7 @@ import org.jdesktop.application.Action; * <li>Task name</li> * <li>Task template (if available)</li> * </ul> - * + * * @author Eric Chatellier */ public class NewTaskView extends DialogView { @@ -135,7 +134,7 @@ public class NewTaskView extends DialogView { // default escape getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE"); getRootPane().getActionMap().put("ESCAPE", cancelButton.getAction()); - + panel.add(buttonPanel, new GridBagConstraints(0, 4, 2, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); @@ -145,7 +144,7 @@ public class NewTaskView extends DialogView { @Action public void valid() { String taskName = newTaskField.getText(); - String taskTemplate = (String)newTaskTemplateBox.getSelectedItem(); + String taskTemplate = (String) newTaskTemplateBox.getSelectedItem(); getApplication().hide(this); diff --git a/src/main/java/org/chorem/jtimer/ui/StatusBar.java b/src/main/java/org/chorem/jtimer/ui/StatusBar.java index 193bcfd..9cfd4b7 100644 --- a/src/main/java/org/chorem/jtimer/ui/StatusBar.java +++ b/src/main/java/org/chorem/jtimer/ui/StatusBar.java @@ -22,13 +22,6 @@ package org.chorem.jtimer.ui; -import java.awt.GridLayout; -import java.util.Collection; -import java.util.Date; -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; import org.apache.commons.lang3.time.DurationFormatUtils; import org.chorem.jtimer.data.DataEventListener; import org.chorem.jtimer.data.TimerDataManager; @@ -40,12 +33,20 @@ import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; import org.jdesktop.application.ResourceMap; +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import java.awt.GridLayout; +import java.util.Collection; +import java.util.Date; + /** * StatusBar. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date: 2008-06-17 10:50:40 +0200 (mar., 17 juin 2008) * $ By : $Author$ */ @@ -73,7 +74,7 @@ public class StatusBar extends JPanel implements DataEventListener { /** * Constucteur. - * + * * @param application parent application * @param dataManager data manager */ @@ -167,7 +168,7 @@ public class StatusBar extends JPanel implements DataEventListener { /** * Start and stop task common code. - * + * * @param task task * @param start start(true) or stop (false) */ diff --git a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java index 7c54d41..74e7d64 100644 --- a/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/TimerTaskEditor.java @@ -22,18 +22,19 @@ package org.chorem.jtimer.ui; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.util.Calendar; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.stream.Collectors; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.data.DataViolationException; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.data.TimerDataManager; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TimerTaskHelper; +import org.chorem.jtimer.ui.widget.DialogView; +import org.jdesktop.application.Action; +import org.jdesktop.swingx.JXMonthView; +import org.jdesktop.swingx.calendar.DateSelectionModel; + import javax.swing.ActionMap; import javax.swing.JButton; import javax.swing.JComponent; @@ -51,22 +52,22 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.data.DataViolationException; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.data.TimerDataManager; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; -import org.chorem.jtimer.ui.widget.DialogView; -import org.jdesktop.application.Action; -import org.jdesktop.swingx.JXMonthView; -import org.jdesktop.swingx.calendar.DateSelectionModel; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.stream.Collectors; /** * JTimer task editor - * + * * @author sch */ public class TimerTaskEditor extends DialogView { @@ -113,26 +114,26 @@ public class TimerTaskEditor extends DialogView { /** did the modified annotation ? */ protected boolean isAnnotationChanged; - /** + /** * days modified: You can modify any number of days before you apply changes, * this set keep track of days modified (for time, annotations or title). */ protected Set<Date> dateChanged = new HashSet<>(); - /** + /** * days where annotation were modified: You can modify any number of days before you apply changes, * this set keep track of days where annotations were modified. */ protected Set<Date> annotationChanged = new HashSet<>(); - /** + /** * selected monthview day: should never be null */ protected Calendar selectedDay; /** * TimerTaskEditor - * + * * @param parent * @param task * @param core @@ -186,7 +187,7 @@ public class TimerTaskEditor extends DialogView { /** * Create command panel. - * + * * @return command panel */ protected JPanel createCommandPanel() { @@ -211,7 +212,7 @@ public class TimerTaskEditor extends DialogView { /** * Create main content. - * + * * @return content panel */ protected JPanel createContentPanel() { @@ -235,7 +236,7 @@ public class TimerTaskEditor extends DialogView { /** * Create edition panel. - * + * * @return edition panel */ protected JPanel createEditionPanel() { @@ -300,7 +301,7 @@ public class TimerTaskEditor extends DialogView { /** * Create JXMonthView. - * + * * @return month view component */ protected JXMonthView createJXMonthView() { @@ -319,7 +320,7 @@ public class TimerTaskEditor extends DialogView { // selected day monthView.setSelectionDate(yesterdayCalendar.getTime()); - + // set sunday red monthView.setDayForeground(Calendar.SUNDAY, Color.RED); @@ -335,7 +336,7 @@ public class TimerTaskEditor extends DialogView { /** * Create three spinners panel. - * + * * @return spinner panel */ protected JPanel createSpinnersPanel() { @@ -377,9 +378,8 @@ public class TimerTaskEditor extends DialogView { @Override public void stateChanged(ChangeEvent e) { if (e.getSource() == spinnerM) { - int value = ((SpinnerNumberModel) spinnerM.getModel()) - .getNumber().intValue(); - + int value = ((SpinnerNumberModel) spinnerM.getModel()).getNumber().intValue(); + if (value >= 60) { if (spinnerH.getNextValue() != null) { spinnerM.setValue(value - 60); @@ -387,7 +387,7 @@ public class TimerTaskEditor extends DialogView { } else { spinnerM.setValue(value - 1); } - + } else if (value < 0) { if (spinnerH.getPreviousValue() != null) { spinnerM.setValue(value + 60); @@ -396,33 +396,30 @@ public class TimerTaskEditor extends DialogView { spinnerM.setValue(0); } } - + } else if (e.getSource() == spinnerS) { - int value = ((SpinnerNumberModel) spinnerS.getModel()) - .getNumber().intValue(); - - if (value >= 60) { - if (spinnerM.getNextValue() != null) { - spinnerS.setValue(value - 60); - spinnerM.setValue(spinnerM.getNextValue()); - } else { - spinnerS.setValue(value - 1); - } - - } else if (value < 0) { - int hour = ((SpinnerNumberModel) spinnerH.getModel()) - .getNumber().intValue(); - - int minute = ((SpinnerNumberModel) spinnerM.getModel()) - .getNumber().intValue(); - - if (hour != 0 || minute != 0) { - spinnerS.setValue(value + 60); - spinnerM.setValue(spinnerM.getPreviousValue()); - } else { - spinnerS.setValue(0); - } - } + int value = ((SpinnerNumberModel) spinnerS.getModel()).getNumber().intValue(); + + if (value >= 60) { + if (spinnerM.getNextValue() != null) { + spinnerS.setValue(value - 60); + spinnerM.setValue(spinnerM.getNextValue()); + } else { + spinnerS.setValue(value - 1); + } + + } else if (value < 0) { + int hour = ((SpinnerNumberModel) spinnerH.getModel()).getNumber().intValue(); + + int minute = ((SpinnerNumberModel) spinnerM.getModel()).getNumber().intValue(); + + if (hour != 0 || minute != 0) { + spinnerS.setValue(value + 60); + spinnerM.setValue(spinnerM.getPreviousValue()); + } else { + spinnerS.setValue(0); + } + } } updateTask(); @@ -448,7 +445,7 @@ public class TimerTaskEditor extends DialogView { /** * Monthview selected day. - * + * * @return monthview selected day */ public Calendar getSelectedDay() { @@ -472,14 +469,14 @@ public class TimerTaskEditor extends DialogView { /** * update spinners and annotation textarea according to selected day. - * + * * @param date task date */ protected void displayTask(Date date) { - + selectedDay = Calendar.getInstance(); selectedDay.setTime(date); - + if (log.isDebugEnabled()) { log.debug("Displaying information on: " + date); } @@ -492,7 +489,7 @@ public class TimerTaskEditor extends DialogView { Calendar cal = Calendar.getInstance(); // FIXME me, not use a calendar here ! cal.setTimeInMillis(time - cal.get(Calendar.ZONE_OFFSET)); - + spinnerH.setValue(cal.get(Calendar.HOUR_OF_DAY)); spinnerM.setValue(cal.get(Calendar.MINUTE)); spinnerS.setValue(cal.get(Calendar.SECOND)); @@ -524,7 +521,7 @@ public class TimerTaskEditor extends DialogView { /** * update tasktime according to selected date on jxmonthview - * + * * @param issuer of change */ protected void updateTask(TextChangeListener issuer) { @@ -599,20 +596,17 @@ public class TimerTaskEditor extends DialogView { if (log.isDebugEnabled()) { log.debug("Applying changes on: " + date); } - + // time - dataManager.changeTaskTime(task, date, cloneTask - .getTime(date)); - + dataManager.changeTaskTime(task, date, cloneTask.getTime(date)); + // annotation if (annotationChanged.contains(date)) { TimerTaskHelper.removeAnnotation(task, date); - - Map<Date, String> annotations = TimerTaskHelper - .getAnnotationMap(cloneTask, date); + + Map<Date, String> annotations = TimerTaskHelper.getAnnotationMap(cloneTask, date); for (Date date2 : annotations.keySet()) { - dataManager.addAnnotation(task, date2, - annotations.get(date2)); + dataManager.addAnnotation(task, date2, annotations.get(date2)); } } } diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java index e2271e2..de3b211 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellEditor.java @@ -22,26 +22,25 @@ package org.chorem.jtimer.ui.alert; -import java.awt.Component; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; +import org.chorem.jtimer.entities.TimerAlert.Type; +import org.chorem.jtimer.ui.widget.DurationEditor; import javax.swing.AbstractCellEditor; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.table.TableCellEditor; - -import org.chorem.jtimer.entities.TimerAlert.Type; -import org.chorem.jtimer.ui.widget.DurationEditor; +import java.awt.Component; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; /** * Tree cell editor for alerts table. * * @author chatellier * @version $Revision: 1.0 $ - * + * * Last update : $Date: 6 juil. 2009 $ * By : $Author: chatellier $ */ @@ -58,39 +57,37 @@ public class AlertCellEditor extends AbstractCellEditor implements TableCellEdit Object value = null; if (editor instanceof JComboBox) { - value = ((JComboBox<?>)editor).getSelectedItem(); - } - else if (editor instanceof DurationEditor) { - value = ((DurationEditor)editor).getDuration(); + value = ((JComboBox<?>) editor).getSelectedItem(); + } else if (editor instanceof DurationEditor) { + value = ((DurationEditor) editor).getDuration(); } return value; } @Override - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, int row, int column) { - + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + switch (column) { - case 0: - JComboBox<Type> combo = new JComboBox<>(); - combo.addItem(Type.REACH_DAILY_TIME); - combo.addItem(Type.REACH_TOTAL_TIME); - combo.setSelectedItem(value); - combo.addItemListener(this); - editor = combo; - break; - - case 1: - DurationEditor durationEditor = new DurationEditor(9999); - long duration = (Long) value; - durationEditor.setDuration(duration); - durationEditor.addPropertyChangeListener("duration", this); - durationEditor.setSize(100, 30); - editor = durationEditor; - break; - - default: - break; + case 0: + JComboBox<Type> combo = new JComboBox<>(); + combo.addItem(Type.REACH_DAILY_TIME); + combo.addItem(Type.REACH_TOTAL_TIME); + combo.setSelectedItem(value); + combo.addItemListener(this); + editor = combo; + break; + + case 1: + DurationEditor durationEditor = new DurationEditor(9999); + long duration = (Long) value; + durationEditor.setDuration(duration); + durationEditor.addPropertyChangeListener("duration", this); + durationEditor.setSize(100, 30); + editor = durationEditor; + break; + + default: + break; } // restore super component properties diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java index 2e1103c..b08aed3 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertCellRenderer.java @@ -22,21 +22,20 @@ package org.chorem.jtimer.ui.alert; -import java.awt.Component; +import org.chorem.jtimer.entities.TimerAlert.Type; +import org.chorem.jtimer.ui.widget.DurationEditor; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; - -import org.chorem.jtimer.entities.TimerAlert.Type; -import org.chorem.jtimer.ui.widget.DurationEditor; +import java.awt.Component; /** * Tree cell editor for alerts table. * * @author chatellier * @version $Revision: 1.0 $ - * + * * Last update : $Date: 6 juil. 2009 $ * By : $Author: chatellier $ */ @@ -46,31 +45,31 @@ public class AlertCellRenderer extends DefaultTableCellRenderer { private static final long serialVersionUID = -363052829182024180L; @Override - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, + int row, int column) { Component superComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); Component c = null; switch (column) { - case 0: - JComboBox<Type> combo = new JComboBox<>(); - combo.addItem(Type.REACH_DAILY_TIME); - combo.addItem(Type.REACH_TOTAL_TIME); - combo.setSelectedItem(value); - c = combo; - break; + case 0: + JComboBox<Type> combo = new JComboBox<>(); + combo.addItem(Type.REACH_DAILY_TIME); + combo.addItem(Type.REACH_TOTAL_TIME); + combo.setSelectedItem(value); + c = combo; + break; - case 1: - DurationEditor durationEditor = new DurationEditor(9999); - long duration = (Long) value; - durationEditor.setDuration(duration); - c = durationEditor; - break; - - default: - break; + case 1: + DurationEditor durationEditor = new DurationEditor(9999); + long duration = (Long) value; + durationEditor.setDuration(duration); + c = durationEditor; + break; + + default: + break; } - + // restore super properties if (c != null) { c.setBackground(superComponent.getBackground()); diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java index 4a905bc..d6e139a 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertEditor.java @@ -22,12 +22,13 @@ package org.chorem.jtimer.ui.alert; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; +import org.chorem.jtimer.data.TimerDataManager; +import org.chorem.jtimer.entities.TimerAlert; +import org.chorem.jtimer.entities.TimerAlert.Type; +import org.chorem.jtimer.entities.TimerTask; +import org.jdesktop.application.Action; +import org.jdesktop.application.Application; +import org.jdesktop.application.FrameView; import javax.swing.JButton; import javax.swing.JComponent; @@ -38,26 +39,24 @@ import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; - -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; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; /** * Alert editor dialog. * * @author chatellier * @version $Revision: 1.0 $ - * + * * Last update : $Date: 6 juil. 2009 $ * By : $Author: chatellier $ */ public class AlertEditor extends FrameView implements ListSelectionListener { - + /** Task to manage alert on. */ protected TimerTask task; @@ -78,13 +77,12 @@ public class AlertEditor extends FrameView implements ListSelectionListener { /** * Constructor. - * + * * @param application parent * @param task task - * @param timerDataManager + * @param timerDataManager */ - public AlertEditor(Application application, - TimerDataManager timerDataManager, TimerTask task) { + public AlertEditor(Application application, TimerDataManager timerDataManager, TimerTask task) { super(application); this.task = task; this.timerDataManager = timerDataManager; @@ -101,7 +99,7 @@ public class AlertEditor extends FrameView implements ListSelectionListener { /** * Build main component. - * + * * @return main component */ protected JComponent getMainComponent() { @@ -110,14 +108,13 @@ public class AlertEditor extends FrameView implements ListSelectionListener { 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)); + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); // get column labels List<String> columnIdentifiers = new ArrayList<>(); 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); @@ -130,40 +127,35 @@ public class AlertEditor extends FrameView implements ListSelectionListener { JScrollPane sp = new JScrollPane(alertTable); panel.add(sp, new GridBagConstraints(0, 1, 2, 1, 1, 1, - GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets( - 1, 1, 1, 1), 0, 0)); + GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 1, 1, 1), 0, 0)); JButton addButton = new JButton(); addButton.setAction(getContext().getActionMap(this).get("addAlert")); panel.add(addButton, new GridBagConstraints(0, 2, 1, 1, 1, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(1, 1, 1, 1), 0, 0)); + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); JButton removeButton = new JButton(); removeButton.setAction(getContext().getActionMap(this).get( "removeAlert")); panel.add(removeButton, new GridBagConstraints(1, 2, 1, 1, 1, 0, - GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, - new Insets(1, 1, 1, 1), 0, 0)); + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 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)); + 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)); + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); return panel; } /** * Is selected alert. - * + * * @return selected alert property */ public boolean isSelectedAlert() { @@ -172,7 +164,7 @@ public class AlertEditor extends FrameView implements ListSelectionListener { /** * Change selected alert property. - * + * * @param selectedAlert selected alert property */ public void setSelectedAlert(boolean selectedAlert) { diff --git a/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java b/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java index ddf617d..b3b8d30 100644 --- a/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java +++ b/src/main/java/org/chorem/jtimer/ui/alert/AlertTableModel.java @@ -22,19 +22,18 @@ package org.chorem.jtimer.ui.alert; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; +import javax.swing.table.AbstractTableModel; +import java.util.List; + /** * Table model for alerts. * * @author chatellier * @version $Revision: 1.0 $ - * + * * Last update : $Date: 6 juil. 2009 $ * By : $Author: chatellier $ */ @@ -42,16 +41,16 @@ public class AlertTableModel extends AbstractTableModel { /** serialVersionUID. */ private static final long serialVersionUID = 4103529427954019924L; - + /** Table column identifiers. */ protected List<String> columnIdentifiers; - + /** Edition alerts list. */ protected List<TimerAlert> alerts; /** * Contructor. - * + * * @param alerts alerts list * @param columnIdentifiers columns identifiers */ @@ -67,7 +66,7 @@ public class AlertTableModel extends AbstractTableModel { @Override public String getColumnName(int column) { - + String columnName = columnIdentifiers.get(column); return columnName; } @@ -81,22 +80,22 @@ public class AlertTableModel extends AbstractTableModel { public Object getValueAt(int rowIndex, int columnIndex) { TimerAlert alert = alerts.get(rowIndex); - + Object result = null; - + switch (columnIndex) { - case 0: - result = alert.getType(); - break; - - case 1: - result = alert.getDuration() / 1000; - break; - - default: - break; + case 0: + result = alert.getType(); + break; + + case 1: + result = alert.getDuration() / 1000; + break; + + default: + break; } - + return result; } @@ -105,18 +104,18 @@ public class AlertTableModel extends AbstractTableModel { TimerAlert alert = alerts.get(rowIndex); switch (columnIndex) { - case 0: - Type type = (Type)value; - alert.setType(type); - break; - - case 1: - long duration = (Long) value; - alert.setDuration(duration * 1000); - break; - - default: - break; + case 0: + Type type = (Type) value; + alert.setType(type); + break; + + case 1: + long duration = (Long) value; + alert.setDuration(duration * 1000); + break; + + default: + break; } } diff --git a/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java b/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java index 86c5dfa..9987a1c 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java +++ b/src/main/java/org/chorem/jtimer/ui/report/ReportGenerator.java @@ -22,6 +22,15 @@ package org.chorem.jtimer.ui.report; +import freemarker.cache.ClassTemplateLoader; +import freemarker.ext.beans.BeansWrapper; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.entities.TimerProject; + import java.io.IOException; import java.io.StringWriter; import java.io.Writer; @@ -31,22 +40,12 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.entities.TimerProject; - -import freemarker.cache.ClassTemplateLoader; -import freemarker.ext.beans.BeansWrapper; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; - /** * Report generator class (process code). * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -67,7 +66,7 @@ public class ReportGenerator { /** * Constructor. - * + * * Init freemarker. */ public ReportGenerator() { @@ -77,7 +76,7 @@ public class ReportGenerator { // needed to overwrite "Defaults to default system encoding." // fix encoding issue on some systems freemarkerConfiguration.setEncoding(Locale.getDefault(), "UTF-8"); - + // specific template loader to get template from jars (classpath) ClassTemplateLoader templateLoader = new ClassTemplateLoader(ReportGenerator.class, "/ftl"); freemarkerConfiguration.setTemplateLoader(templateLoader); @@ -87,7 +86,7 @@ public class ReportGenerator { /** * Make report. - * + * * @param reportType type, (daily, weekly...) * @param projects projects sub set * @param begin begin date @@ -99,30 +98,30 @@ public class ReportGenerator { * * @return report text */ - public String getReportText(Type reportType, List<TimerProject> projects, - Date begin, Date end, boolean includeTime, boolean includeAnnotate, boolean includeAnnotateTime, - boolean includeIntermediateTotalTime) { + public String getReportText(Type reportType, List<TimerProject> projects, Date begin, Date end, boolean includeTime, + boolean includeAnnotate, boolean includeAnnotateTime, + boolean includeIntermediateTotalTime) { Template template = null; String content = null; try { switch (reportType) { - case BY_DAY_REPORT: - template = freemarkerConfiguration.getTemplate("reportByDay.ftl"); - break; - case BY_WEEK_REPORT: - template = freemarkerConfiguration.getTemplate("reportByWeek.ftl"); - break; - case BY_MONTH_REPORT: - template = freemarkerConfiguration.getTemplate("reportByMonth.ftl"); - break; - case BY_YEAR_REPORT: - template = freemarkerConfiguration.getTemplate("reportByYear.ftl"); - break; - case BY_PROJECT_REPORT: - template = freemarkerConfiguration.getTemplate("reportByProject.ftl"); - break; + case BY_DAY_REPORT: + template = freemarkerConfiguration.getTemplate("reportByDay.ftl"); + break; + case BY_WEEK_REPORT: + template = freemarkerConfiguration.getTemplate("reportByWeek.ftl"); + break; + case BY_MONTH_REPORT: + template = freemarkerConfiguration.getTemplate("reportByMonth.ftl"); + break; + case BY_YEAR_REPORT: + template = freemarkerConfiguration.getTemplate("reportByYear.ftl"); + break; + case BY_PROJECT_REPORT: + template = freemarkerConfiguration.getTemplate("reportByProject.ftl"); + break; } content = getReportContent(template, projects, begin, end, includeTime, @@ -138,7 +137,7 @@ public class ReportGenerator { /** * Get report content with freemarker template execution. - * + * * @param projects projects sub set * @param begin begin date * @param end end date @@ -149,16 +148,15 @@ public class ReportGenerator { * @param includeIntermediateTotalTime include middle man total time * * @return string content - * + * * @throws IOException if i/o exception occurs * @throws TemplateException if freemarker template exception occurs - * + * * @see Template */ - protected String getReportContent(Template template, - List<TimerProject> projects, Date begin, Date end, - boolean includeTime, boolean includeAnnotate, boolean includeAnnotateTime, - boolean includeIntermediateTotalTime) throws TemplateException, IOException { + protected String getReportContent(Template template, List<TimerProject> projects, Date begin, Date end, + boolean includeTime, boolean includeAnnotate, boolean includeAnnotateTime, + boolean includeIntermediateTotalTime) throws TemplateException, IOException { // Create the root hash Map<String, Object> root = new HashMap<>(); diff --git a/src/main/java/org/chorem/jtimer/ui/report/ReportUtils.java b/src/main/java/org/chorem/jtimer/ui/report/ReportUtils.java index 47bbcc3..e16a564 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/ReportUtils.java +++ b/src/main/java/org/chorem/jtimer/ui/report/ReportUtils.java @@ -22,6 +22,10 @@ package org.chorem.jtimer.ui.report; +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TimerTaskHelper; + import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -29,16 +33,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.time.DurationFormatUtils; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; - /** * Report utility class for use in freemarker context. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -46,7 +46,7 @@ public class ReportUtils { /** * Get date list, between to date (1 day interval). - * + * * @param begin begin date * @param end end date * @return dates list @@ -59,7 +59,7 @@ public class ReportUtils { /** * Get date list, between to date (1 week interval). - * + * * @param begin begin date * @param end end date * @return dates list @@ -72,7 +72,7 @@ public class ReportUtils { /** * Get date list, between to date (1 month interval). - * + * * @param begin begin date * @param end end date * @return dates list @@ -85,7 +85,7 @@ public class ReportUtils { /** * Get date list, between to date (1 year interval). - * + * * @param begin begin date * @param end end date * @return dates list @@ -98,7 +98,7 @@ public class ReportUtils { /** * Get date list, between to date. - * + * * @param begin begin date * @param end end date * @param calendarField calendar field to increment @@ -132,7 +132,7 @@ public class ReportUtils { /** * Get task proper time for a day. - * + * * @param task task * @param day day * @return duration in seconds @@ -147,7 +147,7 @@ public class ReportUtils { * Get task proper time for a week. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the week <code>week</code>. Thus you can get weekly task time from tuesday to wednesday. - * + * * @param task task * @param week week * @param fromDay from day (inclusive) @@ -155,7 +155,7 @@ public class ReportUtils { * @return duration in seconds */ public long getWeeklyTaskTime(TimerTask task, Date week, Date fromDay, - Date toDay) { + Date toDay) { long result = 0; Calendar beginPeriodDate = Calendar.getInstance(); @@ -173,7 +173,7 @@ public class ReportUtils { if ((fromDay == null || fromDay.compareTo(loopPeriodDate.getTime()) <= 0) && (toDay == null || toDay.compareTo(loopPeriodDate - .getTime()) >= 0)) { + .getTime()) >= 0)) { result += task.getTime(loopPeriodDate.getTime()); } loopPeriodDate.add(Calendar.DAY_OF_YEAR, 1); @@ -186,15 +186,14 @@ public class ReportUtils { * Get task proper time for a month. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the month <code>month</code>. Thus you can get monthly task time from third day to twelfth day. - * + * * @param task task * @param month month * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return duration in seconds */ - public long getMonthlyTaskTime(TimerTask task, Date month, Date fromDay, - Date toDay) { + public long getMonthlyTaskTime(TimerTask task, Date month, Date fromDay, Date toDay) { long result = 0; Calendar beginPeriodDate = Calendar.getInstance(); @@ -211,7 +210,7 @@ public class ReportUtils { if ((fromDay == null || fromDay.compareTo(loopPeriodDate.getTime()) <= 0) && (toDay == null || toDay.compareTo(loopPeriodDate - .getTime()) >= 0)) { + .getTime()) >= 0)) { result += task.getTime(loopPeriodDate.getTime()); } @@ -225,15 +224,14 @@ public class ReportUtils { * Get task proper time for a year. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the year <code>year</code>. Thus you can get yearly task time from 03/01 to 31/07. - * + * * @param task task * @param year year * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return duration in seconds */ - public long getYearlyTaskTime(TimerTask task, Date year, Date fromDay, - Date toDay) { + public long getYearlyTaskTime(TimerTask task, Date year, Date fromDay, Date toDay) { long result = 0; Calendar beginPeriodDate = Calendar.getInstance(); @@ -250,8 +248,7 @@ public class ReportUtils { while (loopPeriodDate.compareTo(endPeriodDate) <= 0) { if ((fromDay == null || fromDay.compareTo(loopPeriodDate.getTime()) <= 0) - && (toDay == null || toDay.compareTo(loopPeriodDate - .getTime()) >= 0)) { + && (toDay == null || toDay.compareTo(loopPeriodDate.getTime()) >= 0)) { result += task.getTime(loopPeriodDate.getTime()); } @@ -263,7 +260,7 @@ public class ReportUtils { /** * Get task total time (including subtask) for a day. - * + * * @param task task * @param day day * @return duration in seconds @@ -278,15 +275,14 @@ public class ReportUtils { * Get task total time (including subtask) for a week. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the week <code>week</code>. Thus you can get weekly task time from tuesday to wednesday. - * + * * @param task task * @param week week * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return duration in seconds */ - public long getWeeklyTotalTaskTime(TimerTask task, Date week, Date fromDay, - Date toDay) { + public long getWeeklyTotalTaskTime(TimerTask task, Date week, Date fromDay, Date toDay) { long result = 0; Calendar beginPeriodDate = Calendar.getInstance(); @@ -303,8 +299,7 @@ public class ReportUtils { while (loopPeriodDate.compareTo(endPeriodDate) <= 0) { if ((fromDay == null || fromDay.compareTo(loopPeriodDate.getTime()) <= 0) - && (toDay == null || toDay.compareTo(loopPeriodDate - .getTime()) >= 0)) { + && (toDay == null || toDay.compareTo(loopPeriodDate.getTime()) >= 0)) { result += TimerTaskHelper.getTotalTime(task, loopPeriodDate.getTime()); } loopPeriodDate.add(Calendar.DAY_OF_YEAR, 1); @@ -317,15 +312,14 @@ public class ReportUtils { * Get task total time (including subtask) for a month. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the month <code>month</code>. Thus you can get monthly task time from third day to twelfth day. - * + * * @param task task * @param month month * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return duration in seconds */ - public long getMonthlyTotalTaskTime(TimerTask task, Date month, - Date fromDay, Date toDay) { + public long getMonthlyTotalTaskTime(TimerTask task, Date month, Date fromDay, Date toDay) { long result = 0; Calendar beginPeriodDate = Calendar.getInstance(); @@ -341,8 +335,7 @@ public class ReportUtils { while (loopPeriodDate.compareTo(endPeriodDate) <= 0) { if ((fromDay == null || fromDay.compareTo(loopPeriodDate.getTime()) <= 0) - && (toDay == null || toDay.compareTo(loopPeriodDate - .getTime()) >= 0)) { + && (toDay == null || toDay.compareTo(loopPeriodDate.getTime()) >= 0)) { result += TimerTaskHelper.getTotalTime(task, loopPeriodDate.getTime()); } @@ -356,15 +349,14 @@ public class ReportUtils { * Get task total time (including subtask) for a year. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the year <code>year</code>. Thus you can get yearly task time from 03/01 to 31/07. - * + * * @param task task * @param year year * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return duration in seconds */ - public long getYearlyTotalTaskTime(TimerTask task, Date year, Date fromDay, - Date toDay) { + public long getYearlyTotalTaskTime(TimerTask task, Date year, Date fromDay, Date toDay) { long result = 0; Calendar beginPeriodDate = Calendar.getInstance(); @@ -381,8 +373,7 @@ public class ReportUtils { while (loopPeriodDate.compareTo(endPeriodDate) <= 0) { if ((fromDay == null || fromDay.compareTo(loopPeriodDate.getTime()) <= 0) - && (toDay == null || toDay.compareTo(loopPeriodDate - .getTime()) >= 0)) { + && (toDay == null || toDay.compareTo(loopPeriodDate.getTime()) >= 0)) { result += TimerTaskHelper.getTotalTime(task, loopPeriodDate.getTime()); } @@ -394,7 +385,7 @@ public class ReportUtils { /** * Format duration in 00:00:00 format. - * + * * @param duration duration in seconds * @return formated duration */ @@ -405,7 +396,7 @@ public class ReportUtils { /** * Get task annotations for a day. - * + * * @param task task * @param day day * @return annotations of the day @@ -421,15 +412,14 @@ public class ReportUtils { * Get task annotations for a week. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the week <code>week</code>. Thus you can get weekly task annotations from tuesday to wednesday. - * + * * @param task task * @param week week * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return annotations of the week */ - public Map<Date, String> getWeeklyTaskAnnotation(TimerTask task, Date week, - Date fromDay, Date toDay) { + public Map<Date, String> getWeeklyTaskAnnotation(TimerTask task, Date week, Date fromDay, Date toDay) { Calendar beginPeriodDate = Calendar.getInstance(); beginPeriodDate.setTime(week); @@ -447,15 +437,14 @@ public class ReportUtils { * Get task annotations for a month. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the month <code>month</code>. Thus you can get monthly task annotations from third day to twelfth day. - * + * * @param task task * @param month month * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return annotations of the month */ - public Map<Date, String> getMonthlyTaskAnnotation(TimerTask task, Date month, - Date fromDay, Date toDay) { + public Map<Date, String> getMonthlyTaskAnnotation(TimerTask task, Date month, Date fromDay, Date toDay) { Calendar beginPeriodDate = Calendar.getInstance(); beginPeriodDate.setTime(month); @@ -472,15 +461,14 @@ public class ReportUtils { * Get task annotations for a year. * <code>fromDay</code> and <code>toDay</code> allows you to define lower and upper bound * in the year <code>year</code>. Thus you can get yearly task annotations from 03/01 to 31/07. - * + * * @param task task * @param year year * @param fromDay from day (inclusive) * @param toDay to day (inclusive) * @return annotations of the year */ - public Map<Date, String> getYearlyTaskAnnotation(TimerTask task, Date year, - Date fromDay, Date toDay) { + public Map<Date, String> getYearlyTaskAnnotation(TimerTask task, Date year, Date fromDay, Date toDay) { Calendar beginPeriodDate = Calendar.getInstance(); beginPeriodDate.setTime(year); @@ -526,7 +514,7 @@ public class ReportUtils { /** * Return task subtasks ordered by name. - * + * * @param task task to get subtasks * @return subtask ordered by name * @since 1.4.0 diff --git a/src/main/java/org/chorem/jtimer/ui/report/ReportView.java b/src/main/java/org/chorem/jtimer/ui/report/ReportView.java index 62ec1e8..fb07019 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/ReportView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/ReportView.java @@ -22,6 +22,37 @@ package org.chorem.jtimer.ui.report; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.ui.report.ReportGenerator.Type; +import org.chorem.jtimer.ui.tree.CheckBoxTreeCellEditor; +import org.chorem.jtimer.ui.tree.CheckBoxTreeCellRenderer; +import org.chorem.jtimer.ui.tree.TaskTreeModel; +import org.jdesktop.application.Action; +import org.jdesktop.application.Application; +import org.jdesktop.application.FrameView; +import org.jdesktop.swingx.JXDatePicker; +import org.jdesktop.swingx.JXTaskPane; +import org.jdesktop.swingx.JXTaskPaneContainer; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTextArea; +import javax.swing.JTree; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import java.awt.Color; import java.awt.Desktop; import java.awt.Dimension; @@ -43,44 +74,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; -import javax.swing.JTree; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.ui.report.ReportGenerator.Type; -import org.chorem.jtimer.ui.tree.CheckBoxTreeCellEditor; -import org.chorem.jtimer.ui.tree.CheckBoxTreeCellRenderer; -import org.chorem.jtimer.ui.tree.TaskTreeModel; -import org.jdesktop.application.Action; -import org.jdesktop.application.Application; -import org.jdesktop.application.FrameView; -import org.jdesktop.swingx.JXDatePicker; -import org.jdesktop.swingx.JXTaskPane; -import org.jdesktop.swingx.JXTaskPaneContainer; - /** * Reports UI. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -120,10 +119,10 @@ public class ReportView extends FrameView implements DocumentListener { /** Project tree (with checkbox) */ protected JTree projectsTree; - + /** Show hidden project box. */ protected JCheckBox showHiddenProjectBox; - + /** Report process generator */ protected ReportGenerator reportGenerator; @@ -135,7 +134,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Reposts constructor. - * + * * @param application parent reference * @param core core reference */ @@ -164,7 +163,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Get main view component. - * + * * TODO use less complicated UI (no gbl) * @return main component */ @@ -334,7 +333,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Fill picker date with predefined week selection (from current) * and apply a delay (-1 = previous week). - * + * * @param delay delay to add to current week */ protected void fillPickerDates(int delay) { @@ -387,7 +386,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Make report. - * + * * Set content in {@link #reportArea} text area. */ @Action @@ -426,7 +425,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Get project list without project and task unselected in tree. - * + * * @param projects original project list * @param uncheckedTaskList unselected task list * @return selected project list @@ -455,13 +454,13 @@ public class ReportView extends FrameView implements DocumentListener { /** * Get tasks list without tasks unselected in tree. - * + * * @param tasks original project list * @param uncheckedTaskList unselected task list * @return selected project list */ protected List<TimerTask> getSelectedTasks(List<? extends TimerTask> tasks, - Collection<TimerTask> uncheckedTaskList) { + Collection<TimerTask> uncheckedTaskList) { List<TimerTask> currentTask = new ArrayList<>(); for (TimerTask task : tasks) { @@ -496,7 +495,7 @@ public class ReportView extends FrameView implements DocumentListener { */ @Action public void showHiddenProjects() { - TaskTreeModel model = (TaskTreeModel)projectsTree.getModel(); + TaskTreeModel model = (TaskTreeModel) projectsTree.getModel(); model.setShowClosed(showHiddenProjectBox.isSelected()); } @@ -532,7 +531,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Can send mail ? - * + * * @return true if can send mail */ public boolean isSendMailEnabled() { @@ -541,7 +540,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Change can send mail property. - * + * * @param enabled can send mail */ public void setSendMailEnabled(boolean enabled) { @@ -567,7 +566,7 @@ public class ReportView extends FrameView implements DocumentListener { /** * Document content changed. - * + * * Update can send mail property. */ protected void documentChanged() { diff --git a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java index 5de58e3..6a80d4f 100644 --- a/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java +++ b/src/main/java/org/chorem/jtimer/ui/systray/SystrayManager.java @@ -22,6 +22,18 @@ package org.chorem.jtimer.ui.systray; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.JTimer; +import org.chorem.jtimer.data.DataEventListener; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.ui.widget.JPopupTrayIcon; +import org.jdesktop.application.ApplicationContext; +import org.jdesktop.application.ResourceManager; +import org.jdesktop.application.ResourceMap; + +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; import java.awt.AWTException; import java.awt.EventQueue; import java.awt.Image; @@ -33,24 +45,13 @@ import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; -import javax.swing.JMenuItem; -import javax.swing.JPopupMenu; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.JTimer; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.ui.widget.JPopupTrayIcon; -import org.jdesktop.application.ApplicationContext; -import org.jdesktop.application.ResourceManager; -import org.jdesktop.application.ResourceMap; /** * Factory to get correct working systray implementation. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -95,7 +96,7 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat /** * Default constructor. - * + * * @param parent parent */ public SystrayManager(JTimer parent) { @@ -166,7 +167,7 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat /** * Tray icon installation is make into a thread, put un AWT event * queue. - * + * * @see EventQueue#invokeLater(Runnable) */ @Override @@ -204,7 +205,7 @@ public class SystrayManager extends WindowAdapter implements ActionListener, Dat /** * Common code for start or stop task. - * + * * @param task task * @param start start(true) or stop(false) task */ diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java b/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java index c9c6881..728c370 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/IdleDialog.java @@ -22,26 +22,6 @@ package org.chorem.jtimer.ui.tasks; -import java.awt.BorderLayout; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.GridLayout; -import java.awt.Insets; -import java.util.Timer; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JToggleButton; -import javax.swing.SwingConstants; -import javax.swing.WindowConstants; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; - import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -59,11 +39,30 @@ import org.jdesktop.application.SingleFrameApplication; import org.jdesktop.application.Task; import org.jdesktop.application.TaskMonitor; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSeparator; +import javax.swing.JToggleButton; +import javax.swing.SwingConstants; +import javax.swing.WindowConstants; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; +import java.awt.BorderLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.Insets; +import java.util.Timer; + /** * Modal idle dialog showed to user when idle has been detected. - * + * * Composed of an unique blocking show method. - * + * * Also composed of three resume option : * <ul> * <li>Stop task</li> @@ -71,10 +70,10 @@ import org.jdesktop.application.TaskMonitor; * <li>Resume (without idle time summed)</li> * <li>Set time to another task</li> * </ul> - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -144,9 +143,9 @@ public class IdleDialog extends JDialog { /** * IdleDialog constructor. - * + * * Protected to force use of show static method. - * + * * @param application parent application * @param core timer core */ @@ -182,7 +181,7 @@ public class IdleDialog extends JDialog { /** * Build main component UI. - * + * * @return component ui. */ private JComponent getMainComponent() { @@ -230,7 +229,7 @@ public class IdleDialog extends JDialog { /** * Build option panel with a GridLayout for all button to get same size. - * + * * @return option panel */ protected JPanel getOptionPanel() { @@ -253,19 +252,19 @@ public class IdleDialog extends JDialog { resumeButton.setHorizontalTextPosition(SwingConstants.CENTER); resumeButton.setVerticalTextPosition(SwingConstants.BOTTOM); optionPanel.add(resumeButton); - + assignButton = new JToggleButton(); assignButton.setAction(application.getContext().getActionMap(this).get("chooseAssignOption")); assignButton.setHorizontalTextPosition(SwingConstants.CENTER); assignButton.setVerticalTextPosition(SwingConstants.BOTTOM); optionPanel.add(assignButton); - + return optionPanel; } /** * Build assign panel. - * + * * @return assign panel */ protected JPanel getAssignPanel() { @@ -274,7 +273,7 @@ public class IdleDialog extends JDialog { // separator panel.add(new JSeparator(), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 5), 0, 0)); - + // label JLabel labelIdle = new JLabel(); labelIdle.setText(resourceMap.getString("assignIdleTimeTo")); @@ -291,7 +290,7 @@ public class IdleDialog extends JDialog { projectsTree.addTreeSelectionListener(e -> { TreePath path = e.getPath(); if (path.getPathCount() > 2) { - assignSelectedTask = (TimerTask)path.getLastPathComponent(); + assignSelectedTask = (TimerTask) path.getLastPathComponent(); } else { assignSelectedTask = null; } @@ -306,14 +305,14 @@ public class IdleDialog extends JDialog { assignValidButton.setAction(application.getContext().getActionMap(this).get("validAssignOption")); panel.add(assignValidButton, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0)); - + return panel; } public boolean isSelectedTask() { return selectedTask; } - + public void setSelectedTask(boolean selectedTask) { boolean oldValue = this.selectedTask; this.selectedTask = selectedTask; @@ -322,7 +321,7 @@ public class IdleDialog extends JDialog { /** * Init dialog idleDialog instance. - * + * * @param parent parent reference * @param core core reference */ @@ -416,7 +415,7 @@ public class IdleDialog extends JDialog { // schedule timer updateIdleTime = new UpdateIdleTime(); timer.schedule(updateIdleTime, 0, 1000 * 60 /* every minutes */); - + reset(); } else { updateIdleTime.cancel(); @@ -428,7 +427,7 @@ public class IdleDialog extends JDialog { /** * Called function on idle detect. - * + * * This function is thread safe and show only one dialog even if * function is called multiples times. * diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java b/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java index 3cde04a..226eb74 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/RefreshTreeTask.java @@ -22,9 +22,6 @@ package org.chorem.jtimer.ui.tasks; -import java.util.Date; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.TimerCore; @@ -32,12 +29,15 @@ import org.chorem.jtimer.data.TimerDataManager; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; +import java.util.Date; +import java.util.List; + /** * Task used to refresh tree at midnight. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -51,7 +51,7 @@ public class RefreshTreeTask extends java.util.TimerTask { /** * Constructor with core. - * + * * @param core core */ public RefreshTreeTask(TimerCore core) { @@ -76,7 +76,7 @@ public class RefreshTreeTask extends java.util.TimerTask { /** * Refresh task list. - * + * * @param tasks tasks list */ protected void refreshTasks(List<TimerTask> tasks) { diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java b/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java index 3602a32..72e4228 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java @@ -22,16 +22,6 @@ package org.chorem.jtimer.ui.tasks; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; @@ -47,14 +37,23 @@ import org.chorem.jtimer.system.SystemInfoFactory; import org.chorem.jtimer.ui.tasks.IdleDialog.IdleOption; import org.jdesktop.application.Task; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; + /** * RunTaskJob. - * + * * Notify every second the core controler. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -86,15 +85,15 @@ public class RunTaskJob extends Task<Void, Void> { /** * Constructor. - * + * * Take the task to manage - * + * * @param parentApp parent application * @param managedTask task * @param dataManager data */ public RunTaskJob(JTimer parentApp, TimerTask managedTask, - TimerDataManager dataManager) { + TimerDataManager dataManager) { super(parentApp); this.parentApp = parentApp; @@ -115,10 +114,10 @@ public class RunTaskJob extends Task<Void, Void> { /** * Check for already thrown alerts. - * + * * Used to not fired again already fired alerts during previous * timing. - * + * * @param task current task */ protected void checkAlreadyThrownAlerts(TimerTask task) { @@ -128,11 +127,11 @@ public class RunTaskJob extends Task<Void, Void> { for (TimerAlert alert : task.getAlerts()) { if (alert.getType().equals(Type.REACH_DAILY_TIME) && TimerTaskHelper.getTotalTime(task, now) > alert - .getDuration()) { + .getDuration()) { alreadyThrownAlerts.add(alert.clone()); } else if (alert.getType().equals(Type.REACH_TOTAL_TIME) && TimerTaskHelper.getAllTotalTime(task) > alert - .getDuration()) { + .getDuration()) { alreadyThrownAlerts.add(alert.clone()); } } @@ -147,7 +146,7 @@ public class RunTaskJob extends Task<Void, Void> { /** * Task getter. - * + * * @return managed task */ public TimerTask getTask() { @@ -212,21 +211,21 @@ public class RunTaskJob extends Task<Void, Void> { delta = lastUserActivity.get() - oldUserActivity; switch (option) { - case REVERT: - // just stop the task - ((JTimer) getApplication()).stopTask(managedTask); - break; - - case CONTINUE: - // readd delta since oldUserActivity - addTaskDelta(managedTask, oldUserActivity - userIdleTime, delta + userIdleTime); - break; - - case ASSIGN: - // readd delta since oldUserActivity to another task - TimerTask otherTask = IdleDialog.assignSelectedTask; - addTaskDelta(otherTask, oldUserActivity - userIdleTime, delta + userIdleTime); - break; + case REVERT: + // just stop the task + ((JTimer) getApplication()).stopTask(managedTask); + break; + + case CONTINUE: + // readd delta since oldUserActivity + addTaskDelta(managedTask, oldUserActivity - userIdleTime, delta + userIdleTime); + break; + + case ASSIGN: + // readd delta since oldUserActivity to another task + TimerTask otherTask = IdleDialog.assignSelectedTask; + addTaskDelta(otherTask, oldUserActivity - userIdleTime, delta + userIdleTime); + break; } } @@ -243,7 +242,7 @@ public class RunTaskJob extends Task<Void, Void> { /** * Add task delta. - * + * * @param task task to apply delta * @param from time when delta was notified * @param delta delta to add @@ -295,7 +294,7 @@ public class RunTaskJob extends Task<Void, Void> { /** * Check for alert to be fired. - * + * * @param task */ protected void checkTaskAlerts(TimerTask task) { @@ -328,13 +327,13 @@ public class RunTaskJob extends Task<Void, Void> { /** * Display alert message without breaking UI. - * + * * @param task task * @param alertType alert type * @param alertDuration alert duration */ protected void displayAlert(final TimerTask task, final Type alertType, - final long alertDuration) { + final long alertDuration) { SwingUtilities.invokeLater(() -> { String alertMessage = null; String formattedTime = DurationFormatUtils.formatDuration( @@ -367,7 +366,7 @@ public class RunTaskJob extends Task<Void, Void> { /** * Tell if task is trying to stop. - * + * * @return stopping flag */ public boolean isStopping() { diff --git a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java index 38629cc..b0065f8 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellComponent.java @@ -22,22 +22,21 @@ package org.chorem.jtimer.ui.tree; -import java.awt.Color; -import java.awt.Component; -import java.util.Set; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerTask; import javax.swing.JCheckBox; import javax.swing.JTree; - -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerTask; +import java.awt.Color; +import java.awt.Component; +import java.util.Set; /** * JCheckBox tree node cell component. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -48,22 +47,21 @@ public abstract class CheckBoxTreeCellComponent extends JCheckBox { /** Timer core. */ protected TimerCore core; - + /** Parent tree. */ protected JTree parentTree; /** Unchecked task set. */ protected Set<TimerTask> uncheckedTaskSet; - + /** * Constructor. - * + * * @param core core reference * @param parentTree tree reference * @param uncheckedTaskList common unselected tasks list */ - protected CheckBoxTreeCellComponent(TimerCore core, JTree parentTree, - Set<TimerTask> uncheckedTaskList) { + protected CheckBoxTreeCellComponent(TimerCore core, JTree parentTree, Set<TimerTask> uncheckedTaskList) { this.core = core; this.parentTree = parentTree; this.uncheckedTaskSet = uncheckedTaskList; @@ -71,7 +69,7 @@ public abstract class CheckBoxTreeCellComponent extends JCheckBox { /** * Generic check box component. - * + * * @param tree tree * @param value value * @param selected selected @@ -80,8 +78,8 @@ public abstract class CheckBoxTreeCellComponent extends JCheckBox { * @param row row * @return check box component */ - protected Component getCheckBoxComponent(JTree tree, Object value, - boolean selected, boolean expanded, boolean leaf, int row) { + protected Component getCheckBoxComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, + int row) { // if this is a task if (value instanceof TimerTask) { diff --git a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java index 885038b..9fb838b 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellEditor.java @@ -22,13 +22,11 @@ package org.chorem.jtimer.ui.tree; -import java.awt.Component; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EventObject; -import java.util.Set; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; import javax.swing.JCheckBox; import javax.swing.JTree; @@ -36,19 +34,20 @@ import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.tree.TreeCellEditor; import javax.swing.tree.TreePath; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; +import java.awt.Component; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.EventObject; +import java.util.Set; /** * JCheckBox tree node cell editor. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -66,13 +65,12 @@ public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements /** * Constructor. - * + * * @param core core * @param parentTree tree * @param uncheckedTaskList common unselected tasks list */ - public CheckBoxTreeCellEditor(TimerCore core, JTree parentTree, - Set<TimerTask> uncheckedTaskList) { + public CheckBoxTreeCellEditor(TimerCore core, JTree parentTree, Set<TimerTask> uncheckedTaskList) { super(core, parentTree, uncheckedTaskList); addItemListener(this); @@ -80,8 +78,8 @@ public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements } @Override - public Component getTreeCellEditorComponent(JTree tree, Object value, - boolean selected, boolean expanded, boolean leaf, int row) { + public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row) { return getCheckBoxComponent(tree, value, selected, expanded, leaf, row); } @@ -115,7 +113,7 @@ public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements /** * Cell selection. - * + * * False, can click without select. */ @Override @@ -162,7 +160,7 @@ public class CheckBoxTreeCellEditor extends CheckBoxTreeCellComponent implements /** * Recursive update task sub task. - * + * * @param treePath current tree path * @param select select (true) or deselect */ diff --git a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java index cec3f89..a588b8b 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/CheckBoxTreeCellRenderer.java @@ -22,21 +22,20 @@ package org.chorem.jtimer.ui.tree; -import java.awt.Component; -import java.util.Set; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerTask; import javax.swing.JTree; import javax.swing.tree.TreeCellRenderer; - -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerTask; +import java.awt.Component; +import java.util.Set; /** * JCheckBox tree node cell renderer. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -48,20 +47,19 @@ public class CheckBoxTreeCellRenderer extends CheckBoxTreeCellComponent /** * Constructor. - * + * * @param core core * @param parentTree tree * @param uncheckedTaskList common unselected tasks list */ public CheckBoxTreeCellRenderer(TimerCore core, JTree parentTree, - Set<TimerTask> uncheckedTaskList) { + Set<TimerTask> uncheckedTaskList) { super(core, parentTree, uncheckedTaskList); } @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, - boolean selected, boolean expanded, boolean leaf, int row, - boolean hasFocus) { + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row, boolean hasFocus) { Component c = getCheckBoxComponent(tree, value, selected, expanded, leaf, row); // fix a strange bug where checkbox does have a "gray" background diff --git a/src/main/java/org/chorem/jtimer/ui/tree/ProjectsAndTasksTree.java b/src/main/java/org/chorem/jtimer/ui/tree/ProjectsAndTasksTree.java index d81f057..b172c25 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/ProjectsAndTasksTree.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/ProjectsAndTasksTree.java @@ -51,7 +51,7 @@ public class ProjectsAndTasksTree extends JTree { public void setSelectedTask(TimerTask task) { // compute task tree path List<TimerTask> components = TimerTaskHelper.getPathFromParent(task); - components.add(0, (TimerTask)getModel().getRoot()); + components.add(0, (TimerTask) getModel().getRoot()); // select tree path in reverse order (from root to leaf) TreePath path = new TreePath(components.toArray()); diff --git a/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java b/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java index 78c6e87..41b3160 100644 --- a/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java +++ b/src/main/java/org/chorem/jtimer/ui/tree/TaskTreeModel.java @@ -22,14 +22,6 @@ package org.chorem.jtimer.ui.tree; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import javax.swing.event.TreeModelListener; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.data.TimerCore; @@ -37,12 +29,19 @@ import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; import org.jdesktop.swingx.tree.TreeModelSupport; +import javax.swing.event.TreeModelListener; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + /** * Timer task tree model. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -52,7 +51,7 @@ public class TaskTreeModel implements TreeModel { private static Log log = LogFactory.getLog(TaskTreeModel.class); protected TreeModelSupport modelSupport; - + /** Timer core. */ protected TimerCore core; @@ -61,10 +60,10 @@ public class TaskTreeModel implements TreeModel { /** Show closed tasks. */ protected boolean showClosed; - + /** * Constructor. - * + * * @param core core * @param rootName root node name */ @@ -74,18 +73,12 @@ public class TaskTreeModel implements TreeModel { modelSupport = new TreeModelSupport(this); } - /* - * @see javax.swing.tree.DefaultTreeModel#getChild(java.lang.Object, int) - */ @Override public Object getChild(Object parent, int index) { TimerTask child = getChildrenFor(parent).get(index); return child; } - /* - * @see javax.swing.tree.DefaultTreeModel#getChildCount(java.lang.Object) - */ @Override public int getChildCount(Object parent) { int count = getChildrenFor(parent).size(); @@ -95,7 +88,7 @@ public class TaskTreeModel implements TreeModel { /** * Recupere la sous liste: data.getProjectsList() si parent = root * getSubTasks() sinon - * + * * @param parent parent to task sublist * @return children */ @@ -105,11 +98,11 @@ public class TaskTreeModel implements TreeModel { return result; } - + /** * Recupere la sous liste: data.getProjectsList() si parent = root * getSubTasks() sinon - * + * * @param parent parent to task sublist * @return filtered list */ @@ -128,8 +121,8 @@ public class TaskTreeModel implements TreeModel { // filter list, if only show closed if (!showClosed) { result = result.stream() - .filter(task -> !task.isClosed()) - .collect(Collectors.toList()); + .filter(task -> !task.isClosed()) + .collect(Collectors.toList()); } // Since sort is not supported by the table, do a manual sorting. @@ -138,58 +131,40 @@ public class TaskTreeModel implements TreeModel { return result; } - /* - * @see javax.swing.tree.DefaultTreeModel#getIndexOfChild(java.lang.Object, java.lang.Object) - */ @Override public int getIndexOfChild(Object parent, Object child) { int count = getChildrenFor(parent).indexOf(parent); return count; } - /* - * @see javax.swing.tree.DefaultTreeModel#isLeaf(java.lang.Object) - */ @Override public boolean isLeaf(Object node) { return getChildCount(node) == 0; } - /* - * @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener) - */ @Override public void addTreeModelListener(TreeModelListener l) { modelSupport.addTreeModelListener(l); } - /* - * @see javax.swing.tree.TreeModel#getRoot() - */ @Override public Object getRoot() { return root; } - /* - * @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener) - */ @Override public void removeTreeModelListener(TreeModelListener l) { modelSupport.removeTreeModelListener(l); } - /* - * @see javax.swing.tree.TreeModel#valueForPathChanged(javax.swing.tree.TreePath, java.lang.Object) - */ @Override public void valueForPathChanged(TreePath path, Object newValue) { } - + /** * Show closed. - * + * * @param closed closed value */ public void setShowClosed(boolean closed) { diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksCellRenderer.java index 33718fd..8435257 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksCellRenderer.java @@ -22,20 +22,19 @@ package org.chorem.jtimer.ui.treetable; -import java.awt.Color; -import java.awt.Component; +import org.chorem.jtimer.entities.TimerTask; import javax.swing.JTree; import javax.swing.tree.DefaultTreeCellRenderer; - -import org.chorem.jtimer.entities.TimerTask; +import java.awt.Color; +import java.awt.Component; /** * Gere l'affichage des noeuds de l'arbre. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -44,13 +43,9 @@ public class ProjectsAndTasksCellRenderer extends DefaultTreeCellRenderer { /** serialVersionUID. */ private static final long serialVersionUID = 1383276150996517529L; - /* - * @see org.jdesktop.swingx.renderer.DefaultTreeRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) - */ @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, - boolean selected, boolean expanded, boolean leaf, int row, - boolean hasFocus) { + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row, boolean hasFocus) { Object localValue = value; @@ -66,7 +61,7 @@ public class ProjectsAndTasksCellRenderer extends DefaultTreeCellRenderer { // le toString() suivit du setName() super.getTreeCellRendererComponent(tree, localValue, selected, expanded, leaf, row, hasFocus); - + setIcon(null); // if this is a task diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java index 1fa7b7f..fd49d60 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksModel.java @@ -22,16 +22,6 @@ package org.chorem.jtimer.ui.treetable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.swing.SwingUtilities; -import javax.swing.table.TableColumn; -import javax.swing.tree.TreePath; import org.apache.commons.lang3.time.DurationFormatUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,12 +33,23 @@ import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; import org.jdesktop.swingx.treetable.AbstractTreeTableModel; +import javax.swing.SwingUtilities; +import javax.swing.table.TableColumn; +import javax.swing.tree.TreePath; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + /** * Cette classe gere l'affichage d'une liste de project dans l'arbre/table - * + * * Cela permet au programme principal de manipuler la liste et d'oublier la * gestion de l'arbre... - * + * * Le modele de cet arbre utilise directement des TimerTask au lieu des TreeTableNode * qui ne servent a rien et qui complique tout. Par contre, les tâches étant * les mêmes instances que celle manipulées par le programme, il doit mettre @@ -57,13 +58,13 @@ import org.jdesktop.swingx.treetable.AbstractTreeTableModel; * <li>Nom : cas de renommage avec changement d'ordre * <li>Sous tache : pour supprimer une tache qui disparaitrait directement du modèle * </ul> - * + * * Voir cet article pour la non utilisation des TreeNode : * http://www.javalobby.org/forums/thread.jspa?threadID=16052&tstart=0 - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date: 2008-06-13 11:05:57 +0200 (ven., 13 juin 2008) * $ By : $Author$ */ @@ -97,20 +98,20 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements /** * Constructor. - * + * * @param projectsAndTaskTable table * @param core timer core * @param columnIdentifiers column identifiers */ - public ProjectsAndTasksModel(ProjectsAndTasksTable projectsAndTaskTable, - TimerCore core, List<String> columnIdentifiers) { + public ProjectsAndTasksModel(ProjectsAndTasksTable projectsAndTaskTable, TimerCore core, + List<String> columnIdentifiers) { super(new TimerProject("root")); // remember this.projectsAndTaskTable = projectsAndTaskTable; this.dataManager = core.getData(); this.columnIdentifiers = columnIdentifiers; - + taskNameCache = new HashMap<>(); subTasksCache = new HashMap<>(); } @@ -135,17 +136,17 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements TimerTask task = (TimerTask) object; switch (column) { - case 0: - value = task.getName(); - break; - case 1: - long duration = TimerTaskHelper.getTotalTime(task, new Date()); - value = DurationFormatUtils.formatDuration(duration, "HH:mm:ss"); - break; - case 2: - long totalDuration = TimerTaskHelper.getAllTotalTime(task); - value = DurationFormatUtils.formatDuration(totalDuration, "HH:mm:ss"); - break; + case 0: + value = task.getName(); + break; + case 1: + long duration = TimerTaskHelper.getTotalTime(task, new Date()); + value = DurationFormatUtils.formatDuration(duration, "HH:mm:ss"); + break; + case 2: + long totalDuration = TimerTaskHelper.getAllTotalTime(task); + value = DurationFormatUtils.formatDuration(totalDuration, "HH:mm:ss"); + break; } } else { // means that it's tree root @@ -181,7 +182,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements /** * Recupere la sous liste: data.getProjectsList() si parent = root * getSubTasks() sinon (cache results). - * + * * @param parent parent to task sublist * @return filtered list */ @@ -192,7 +193,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements /** * Recupere la sous liste: data.getProjectsList() si parent = root * getSubTasks() sinon. - * + * * @param parent parent to task sublist * @param noCache disable use of cached result and result caching * @return filtered list @@ -221,13 +222,13 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements // Since sort is not supported by the table, do a manual sorting. result = TimerTaskHelper.sortTask(result); - + if (!noCache) { // cache tasks name for (TimerTask task : result) { taskNameCache.put(task, task.getName()); } - + subTasksCache.put(parent, result); } } @@ -249,7 +250,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements /** * Notification de changement de donnees. - * + * * @param task task to update * @param operation operation */ @@ -261,14 +262,13 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements /** * Recursively try to update node. - * + * * @param task the task to update * @param path current path * @param operation operation (add, modify, delete) * @return <tt>true</tt> if children have been found and updated in current recursion */ - protected synchronized boolean updateChildren(TimerTask task, TreePath path, - int operation) { + protected synchronized boolean updateChildren(TimerTask task, TreePath path, int operation) { TimerTask pathLastComponent = (TimerTask) path.getLastPathComponent(); boolean updated = false; @@ -284,44 +284,44 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements // this update only node, not all path... switch (operation) { - case OPERATION_ADD: { - subTasksCache.remove(pathLastComponent); // force child recache - int newIndex = getIndexOfChild(pathLastComponent, taskUO); - modelSupport.fireChildAdded(path, newIndex, taskUO); - // expand path - projectsAndTaskTable.expandPath(path); - break; - } - case OPERATION_DELETE: { - // before cache invalidate (use index of himself) - modelSupport.fireChildRemoved(path, childIndex, taskUO); - subTasksCache.get(pathLastComponent).remove(taskUO); // not in cache anymore - taskNameCache.remove(taskUO); // not in cache anymore - break; - } - case OPERATION_MODIFY: { - String cacheName = taskNameCache.get(taskUO); - if (cacheName.equals(task.getName())) { - // not name modification (time...) - modelSupport.fireChildChanged(path, childIndex, taskUO); - } else { + case OPERATION_ADD: { subTasksCache.remove(pathLastComponent); // force child recache int newIndex = getIndexOfChild(pathLastComponent, taskUO); - if (newIndex != childIndex) { - // name modification (order DO change) - modelSupport.fireChildRemoved(path, childIndex, taskUO); - modelSupport.fireChildAdded(path, newIndex, taskUO); - } else { - // name modification (order DO NOT change) + modelSupport.fireChildAdded(path, newIndex, taskUO); + // expand path + projectsAndTaskTable.expandPath(path); + break; + } + case OPERATION_DELETE: { + // before cache invalidate (use index of himself) + modelSupport.fireChildRemoved(path, childIndex, taskUO); + subTasksCache.get(pathLastComponent).remove(taskUO); // not in cache anymore + taskNameCache.remove(taskUO); // not in cache anymore + break; + } + case OPERATION_MODIFY: { + String cacheName = taskNameCache.get(taskUO); + if (cacheName.equals(task.getName())) { + // not name modification (time...) modelSupport.fireChildChanged(path, childIndex, taskUO); + } else { + subTasksCache.remove(pathLastComponent); // force child recache + int newIndex = getIndexOfChild(pathLastComponent, taskUO); + if (newIndex != childIndex) { + // name modification (order DO change) + modelSupport.fireChildRemoved(path, childIndex, taskUO); + modelSupport.fireChildAdded(path, newIndex, taskUO); + } else { + // name modification (order DO NOT change) + modelSupport.fireChildChanged(path, childIndex, taskUO); + } } + break; } - break; - } - default: - if (log.isErrorEnabled()) { - log.error("Unknow operation : " + operation); - } + default: + if (log.isErrorEnabled()) { + log.error("Unknow operation : " + operation); + } } updated = true; @@ -423,7 +423,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements /** * Change closed task property. - * + * * @param showClosedTask closed task property */ public void setShowClosed(boolean showClosedTask) { @@ -443,8 +443,7 @@ public class ProjectsAndTasksModel extends AbstractTreeTableModel implements } @Override - public void postMergeTasks(TimerTask destinationTask, - List<TimerTask> otherTasks) { + public void postMergeTasks(TimerTask destinationTask, List<TimerTask> otherTasks) { notifyTaskChanged(destinationTask, OPERATION_MODIFY); for (TimerTask otherTask : otherTasks) { diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java index 905fa9d..93149c2 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksRunningCellRenderer.java @@ -22,6 +22,15 @@ package org.chorem.jtimer.ui.treetable; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.data.DataEventListener; +import org.chorem.jtimer.data.TimerCore; +import org.chorem.jtimer.entities.TimerTask; +import org.jdesktop.swingx.JXTreeTable; + +import javax.swing.ImageIcon; +import javax.swing.JTree; import java.awt.Component; import java.awt.Image; import java.awt.Rectangle; @@ -32,24 +41,14 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import javax.swing.ImageIcon; -import javax.swing.JTree; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.data.DataEventListener; -import org.chorem.jtimer.data.TimerCore; -import org.chorem.jtimer.entities.TimerTask; -import org.jdesktop.swingx.JXTreeTable; - /** * Gere l'affichage des noeuds de l'arbre. - * + * * Comme une icone quand la taches est lancee... - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -75,7 +74,7 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen /** * Constructor. - * + * * @param treeTable Tree table reference for image observer * @param core TimerCore */ @@ -95,13 +94,9 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen core.getData().addDataEventListener(this); } - /* - * @see org.jdesktop.swingx.renderer.DefaultTreeRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) - */ @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, - boolean selected, boolean expanded, boolean leaf, int row, - boolean hasFocus) { + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row, boolean hasFocus) { // le fait en 2 temps car sinon, on voit de temps en temps // le toString() suivit du setName() @@ -140,12 +135,8 @@ public class ProjectsAndTasksRunningCellRenderer extends ProjectsAndTasksCellRen rows.remove(row); } - /* - * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int) - */ @Override - public boolean imageUpdate(Image img, int flags, int x, int y, int w, - int h) { + public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) { if ((flags & (FRAMEBITS | ALLBITS)) != 0) { for (Integer row : rows) { Rectangle rowBounds = treeTable.getCellRect(row, 0, true); diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java index 6cc9a11..319d4fb 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/ProjectsAndTasksTable.java @@ -22,17 +22,6 @@ package org.chorem.jtimer.ui.treetable; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.KeyStroke; -import javax.swing.tree.TreePath; - import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; @@ -44,16 +33,26 @@ import org.jdesktop.application.ResourceManager; import org.jdesktop.application.ResourceMap; import org.jdesktop.swingx.JXTreeTable; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.KeyStroke; +import javax.swing.tree.TreePath; +import java.awt.Color; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + /** * ProjectAndTaskTable. - * + * * Just redefine JXTreeTable setting up a specific model - * + * * @see org.jdesktop.swingx.JXTreeTable - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -70,7 +69,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** * Constructor. - * + * * @param application application * @param core timer core */ @@ -136,7 +135,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { } } }; - + getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put( KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), action.getValue(Action.NAME)); @@ -146,9 +145,9 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** * Change show closed task property. - * + * * @param closed new closed state - * + * * @see ProjectsAndTasksModel#setShowClosed(boolean) */ public void setShowClosed(boolean closed) { @@ -157,7 +156,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** * Get tasks corresponding to selected rows - * + * * @return tasks list (never <tt>null</tt>) */ public List<TimerTask> getSelectedTasks() { @@ -189,7 +188,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** * Get tasks or projects corresponding to selected rows - * + * * @return project or task list (never <tt>null</tt>) */ public List<TimerTask> getSelectedElements() { @@ -221,7 +220,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { /** * Get projects corresponding to selected rows. - * + * * @return projects list (never <tt>null</tt>) */ public List<TimerProject> getSelectedProjects() { @@ -260,7 +259,7 @@ public class ProjectsAndTasksTable extends JXTreeTable { public void setSelectedTask(TimerTask task) { // compute task tree path List<TimerTask> components = TimerTaskHelper.getPathFromParent(task); - components.add(0, (TimerTask)treeTableModel.getRoot()); + components.add(0, (TimerTask) treeTableModel.getRoot()); // select tree path in reverse order (from root to leaf) TreePath path = new TreePath(components.toArray()); diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTranferable.java b/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTranferable.java index 01032ca..c63808b 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTranferable.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTranferable.java @@ -22,22 +22,22 @@ package org.chorem.jtimer.ui.treetable.dnd; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.entities.TimerTask; + import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.entities.TimerTask; - /** * Represent transfered data. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ By : $Author$ */ public class TimerTaskTranferable implements Transferable { @@ -96,7 +96,7 @@ public class TimerTaskTranferable implements Transferable { @Override public DataFlavor[] getTransferDataFlavors() { - return new DataFlavor[] { myData }; + return new DataFlavor[]{myData}; } @Override diff --git a/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java b/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java index cb4ad67..3da3ba3 100644 --- a/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java +++ b/src/main/java/org/chorem/jtimer/ui/treetable/dnd/TimerTaskTransferHandler.java @@ -22,17 +22,6 @@ package org.chorem.jtimer.ui.treetable.dnd; -import java.awt.datatransfer.DataFlavor; -import java.awt.datatransfer.Transferable; -import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.TransferHandler; - import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,12 +35,22 @@ import org.jdesktop.application.ApplicationContext; import org.jdesktop.application.ResourceManager; import org.jdesktop.application.ResourceMap; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.TransferHandler; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + /** * Transfer handler used to transfer tasks in table. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ By : $Author$ */ public class TimerTaskTransferHandler extends TransferHandler { @@ -70,12 +69,12 @@ public class TimerTaskTransferHandler extends TransferHandler { /** * Constructor. - * + * * @param application * @param dataManager data manager */ public TimerTaskTransferHandler(Application application, - TimerDataManager dataManager) { + TimerDataManager dataManager) { this.dataManager = dataManager; // init resources map @@ -122,10 +121,10 @@ public class TimerTaskTransferHandler extends TransferHandler { String message; if (movedTasks.size() == 1) { message = resourceMap.getString("move.task.message", - movedTasks.get(0).getName(), destinationTask.getName()); + movedTasks.get(0).getName(), destinationTask.getName()); } else { message = resourceMap.getString("move.tasks.message", - movedTasks.size(), destinationTask.getName()); + movedTasks.size(), destinationTask.getName()); } int answer = JOptionPane.showConfirmDialog(component, message, title, JOptionPane.YES_NO_OPTION, @@ -148,7 +147,7 @@ public class TimerTaskTransferHandler extends TransferHandler { /** * Get selected task in tree, and build Transferable object for it. - * + * * @param cp component * @return transferable instance for selected task */ diff --git a/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java b/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java index 0c7c687..1f918d1 100644 --- a/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java +++ b/src/main/java/org/chorem/jtimer/ui/widget/DialogView.java @@ -21,18 +21,17 @@ */ package org.chorem.jtimer.ui.widget; -import static org.jdesktop.application.Application.KEY_APPLICATION_ICON; -import static org.jdesktop.application.Application.KEY_APPLICATION_TITLE; - -import java.awt.Frame; -import java.awt.Image; +import org.jdesktop.application.Application; +import org.jdesktop.application.ResourceMap; +import org.jdesktop.application.View; import javax.swing.JDialog; import javax.swing.JRootPane; +import java.awt.Frame; +import java.awt.Image; -import org.jdesktop.application.Application; -import org.jdesktop.application.ResourceMap; -import org.jdesktop.application.View; +import static org.jdesktop.application.Application.KEY_APPLICATION_ICON; +import static org.jdesktop.application.Application.KEY_APPLICATION_TITLE; /** * Another implementation of FrameView, but using a dialog to use modal state and non visible diff --git a/src/main/java/org/chorem/jtimer/ui/widget/DurationEditor.java b/src/main/java/org/chorem/jtimer/ui/widget/DurationEditor.java index 3e9c11a..9fa54c0 100644 --- a/src/main/java/org/chorem/jtimer/ui/widget/DurationEditor.java +++ b/src/main/java/org/chorem/jtimer/ui/widget/DurationEditor.java @@ -22,23 +22,22 @@ package org.chorem.jtimer.ui.widget; -import java.awt.FlowLayout; - import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import java.awt.FlowLayout; /** * Duration editor. - * + * * Graphical editor to set hh/mm/ss duration. * * @author chatellier * @version $Revision: 1.0 $ - * + * * Last update : $Date: 2 juil. 2009 $ * By : $Author: chatellier $ */ @@ -70,7 +69,7 @@ public class DurationEditor extends JPanel implements ChangeListener { /** * Constructor. - * + * * Default hours set to 24. */ public DurationEditor() { @@ -79,7 +78,7 @@ public class DurationEditor extends JPanel implements ChangeListener { /** * Constructor. - * + * * @param maxHourValue max hour value */ public DurationEditor(int maxHourValue) { @@ -167,7 +166,7 @@ public class DurationEditor extends JPanel implements ChangeListener { /** * Get duration in seconds - * + * * @return duration in seconds */ public long getDuration() { @@ -184,7 +183,7 @@ public class DurationEditor extends JPanel implements ChangeListener { /** * Set duration. - * + * * @param duration */ public void setDuration(long duration) { diff --git a/src/main/java/org/chorem/jtimer/ui/widget/JPopupTrayIcon.java b/src/main/java/org/chorem/jtimer/ui/widget/JPopupTrayIcon.java index 2b110b3..f34d235 100644 --- a/src/main/java/org/chorem/jtimer/ui/widget/JPopupTrayIcon.java +++ b/src/main/java/org/chorem/jtimer/ui/widget/JPopupTrayIcon.java @@ -22,6 +22,12 @@ package org.chorem.jtimer.ui.widget; +import javax.swing.JDialog; +import javax.swing.JPopupMenu; +import javax.swing.JWindow; +import javax.swing.RootPaneContainer; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; import java.awt.Dimension; import java.awt.Frame; import java.awt.GraphicsEnvironment; @@ -32,18 +38,11 @@ import java.awt.Window; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import javax.swing.JDialog; -import javax.swing.JPopupMenu; -import javax.swing.JWindow; -import javax.swing.RootPaneContainer; -import javax.swing.event.PopupMenuEvent; -import javax.swing.event.PopupMenuListener; - /** * JPopupMenu compatible TrayIcon based on Alexander Potochkin's JXTrayIcon * (http://weblogs.java.net/blog/alexfromsun/archive/2008/02/jtrayicon_updat.htm...) * but uses a JWindow instead of a JDialog to workaround some bugs on linux. - * + * * @author Michael Bien * @author Chatellier Eric */ diff --git a/src/main/java/org/chorem/jtimer/ui/widget/WindowProperty2.java b/src/main/java/org/chorem/jtimer/ui/widget/WindowProperty2.java index e6c8bcf..4eacab3 100644 --- a/src/main/java/org/chorem/jtimer/ui/widget/WindowProperty2.java +++ b/src/main/java/org/chorem/jtimer/ui/widget/WindowProperty2.java @@ -22,19 +22,19 @@ package org.chorem.jtimer.ui.widget; +import org.jdesktop.application.session.WindowProperty; + import java.awt.Component; import java.awt.Frame; -import org.jdesktop.application.session.WindowProperty; - /** * Code from http://kenai.com/jira/browse/BSAF-74. - * + * * Force jtimer to always start in not iconified mode. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ diff --git a/src/main/java/org/chorem/jtimer/utils/DailySortedMap.java b/src/main/java/org/chorem/jtimer/utils/DailySortedMap.java index a7111ac..c02c67e 100644 --- a/src/main/java/org/chorem/jtimer/utils/DailySortedMap.java +++ b/src/main/java/org/chorem/jtimer/utils/DailySortedMap.java @@ -35,13 +35,13 @@ import java.util.TreeMap; * * @see java.util.SortedMap * @param <T> values type - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ - * + * * @deprecated since 1.5, this class can now be replaced by TreeMap<LocalDate, Long> */ @Deprecated @@ -60,7 +60,7 @@ public class DailySortedMap<T> extends TreeMap<Date, T> { /** * Constructs a new, empty tree map, ordered according to * the given comparator. - * + * * @param comparator comparator */ public DailySortedMap(Comparator<? super Date> comparator) { @@ -70,7 +70,7 @@ public class DailySortedMap<T> extends TreeMap<Date, T> { /** * Constructs a new tree map containing the same mappings * as the given map, ordered according to the natural ordering of its keys. - * + * * @param m init map */ public DailySortedMap(Map<? extends Date, ? extends T> m) { @@ -80,7 +80,7 @@ public class DailySortedMap<T> extends TreeMap<Date, T> { /** * Constructs a new tree map containing the same mappings and * using the same ordering as the specified sorted map. - * + * * @param m init map */ public DailySortedMap(SortedMap<Date, ? extends T> m) { @@ -244,8 +244,7 @@ public class DailySortedMap<T> extends TreeMap<Date, T> { * {@inheritDoc} */ @Override - public NavigableMap<Date, T> subMap(Date fromKey, boolean fromInclusive, - Date toKey, boolean toInclusive) { + public NavigableMap<Date, T> subMap(Date fromKey, boolean fromInclusive, Date toKey, boolean toInclusive) { Date fromDayKey = getDayDate(fromKey); Date toDayKey = getDayDate(toKey); NavigableMap<Date, T> result = super.subMap(fromDayKey, fromInclusive, @@ -286,7 +285,7 @@ public class DailySortedMap<T> extends TreeMap<Date, T> { /** * Get date at 0h00:00.000. - * + * * @param date date to convert * @return day date */ diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index d82c2d6..64922ec 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -24,7 +24,7 @@ <Appenders> <Console name="Console" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{yyyy/MM/dd HH:mm:ss} %5p (%c:%L) - %m%n" /> + <PatternLayout pattern="%d{yyyy/MM/dd HH:mm:ss} %5p (%c:%L) - %m%n"/> </Console> </Appenders> @@ -33,7 +33,7 @@ <Logger name="org.chorem.jtimer.plugin.timebundle" level="debug"/> <Root level="warn"> - <AppenderRef ref="Console" /> + <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration> diff --git a/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java b/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java index 551be0c..2c61b9c 100644 --- a/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java +++ b/src/test/java/org/chorem/jtimer/AbstractJTimerTest.java @@ -22,13 +22,6 @@ package org.chorem.jtimer; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Collection; -import java.util.Locale; -import java.util.Properties; - import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.HiddenFileFilter; import org.apache.commons.logging.Log; @@ -39,14 +32,21 @@ import org.chorem.jtimer.io.Saver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Collection; +import java.util.Locale; +import java.util.Properties; + /** * Surcharge la factory du code principal. - * + * * Redefinie les propriétés de test. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -63,7 +63,7 @@ public abstract class AbstractJTimerTest { /** * Return specific temp dir. - * + * * @return system temp dir */ public static String getTempDirPath() { @@ -78,7 +78,7 @@ public abstract class AbstractJTimerTest { /** * Redefinit les proprietes utilisées pour les tests. - * + * * @throws IOException */ protected void initDataDirectory() throws IOException { @@ -116,7 +116,7 @@ public abstract class AbstractJTimerTest { /** * Delete data directory defined in saver. - * + * * @throws IOException */ protected void deleteDataDirectory() throws IOException { @@ -129,7 +129,7 @@ public abstract class AbstractJTimerTest { /** * Before each test, set up test data directory. - * + * * @throws IOException */ @BeforeMethod @@ -147,7 +147,7 @@ public abstract class AbstractJTimerTest { /** * After each test, remove test data directory. - * + * * @throws IOException */ @AfterMethod @@ -161,13 +161,13 @@ public abstract class AbstractJTimerTest { /** * Get A specific task with is path in tree. - * + * * @param tasks tasks list to search into * @param path path to search * @return found task, or <tt>null</tt> if not found */ public static TimerTask findTask(Collection<? extends TimerTask> tasks, - String path) { + String path) { String[] paths = path.split("/"); String current = paths[0]; @@ -188,16 +188,16 @@ public abstract class AbstractJTimerTest { return foundTask; } - + /** * Get a specific project in project list. - * + * * @param projects projects list * @param path path to search * @return found project, or <tt>null</tt> if not found */ public static TimerProject findProject(Collection<TimerProject> projects, - String path) { + String path) { TimerProject foundProject = null; for (TimerProject project : projects) { @@ -208,41 +208,41 @@ public abstract class AbstractJTimerTest { return foundProject; } - + /** * Get projects count. - * + * * @param projects projects collection * @return project count */ protected static int getProjectsCount(Collection<TimerProject> projects) { return projects.size(); } - + /** * Get task count. - * + * * @param projects projects collection * @return task count */ protected static int getTasksCount(Collection<TimerProject> projects) { int tasksCount = 0; - + for (TimerProject project : projects) { tasksCount += getRecursiveTasksCount(project.getSubTasks()); } return tasksCount; } - + /** * Get task count. - * + * * @param tasks tasks collection * @return task count */ protected static int getRecursiveTasksCount(Collection<TimerTask> tasks) { int tasksCount = 0; - + for (TimerTask task : tasks) { tasksCount++; // count me tasksCount += getRecursiveTasksCount(task.getSubTasks()); @@ -252,59 +252,59 @@ public abstract class AbstractJTimerTest { /** * Get annotations count. - * + * * @param projects projects collection * @return annotations count */ protected static int getAnnotationsCount(Collection<TimerProject> projects) { int annotationsCount = 0; - + for (TimerProject project : projects) { annotationsCount += getRecursiveAnnotationsCount(project.getSubTasks()); } return annotationsCount; } - + /** * Get annotations count. - * + * * @param tasks tasks collection * @return annotations count */ protected static int getRecursiveAnnotationsCount(Collection<TimerTask> tasks) { int annotationsCount = 0; - + for (TimerTask task : tasks) { annotationsCount += task.getAllDaysAnnotations().size(); annotationsCount += getRecursiveAnnotationsCount(task.getSubTasks()); } return annotationsCount; } - + /** * Get alert count. - * + * * @param projects projects collection * @return annotations count */ protected static int getAlertsCount(Collection<TimerProject> projects) { int annotationsCount = 0; - + for (TimerProject project : projects) { annotationsCount += getRecursiveAlertsCount(project.getSubTasks()); } return annotationsCount; } - + /** * Get alert count. - * + * * @param tasks tasks collection * @return annotations count */ protected static int getRecursiveAlertsCount(Collection<TimerTask> tasks) { int annotationsCount = 0; - + for (TimerTask task : tasks) { annotationsCount += task.getAlerts().size(); annotationsCount += getRecursiveAlertsCount(task.getSubTasks()); diff --git a/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java b/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java index f591ee0..6c47f43 100644 --- a/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java +++ b/src/test/java/org/chorem/jtimer/JTimerFactoryTest.java @@ -22,8 +22,6 @@ package org.chorem.jtimer; -import java.util.Map; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.io.GTimerIncrementalSaver; @@ -31,12 +29,14 @@ import org.chorem.jtimer.io.Saver; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.Map; + /** * Test for JTimerFactory. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -71,9 +71,9 @@ public class JTimerFactoryTest extends AbstractJTimerTest { @Test public void testJsonTaskTemplates() { Map<String, Object> templates = JTimer.config.getTaskTemplates(); - Map<String, Object> p1Tpl = (Map<String, Object>)templates.get("project1"); + Map<String, Object> p1Tpl = (Map<String, Object>) templates.get("project1"); Assert.assertNotNull(p1Tpl); - Map<String, Object> p2Tpl = (Map<String, Object>)templates.get("project2"); + Map<String, Object> p2Tpl = (Map<String, Object>) templates.get("project2"); Assert.assertNotNull(p2Tpl); Object p3Tpl = templates.get("project3"); Assert.assertNull(p3Tpl); diff --git a/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java b/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java index e5fe15e..3982376 100644 --- a/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java +++ b/src/test/java/org/chorem/jtimer/data/CommonVetoableTest.java @@ -22,25 +22,25 @@ package org.chorem.jtimer.data; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - import org.chorem.jtimer.AbstractJTimerTest; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; + /** * Test that all forbidden operation by {@link CommonVetoable} throws * excepted exception. - * + * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -64,7 +64,7 @@ public class CommonVetoableTest extends AbstractJTimerTest { project.setCreationDate(new Date()); dataManager.addProject(project); } - + /** * Test create task with already existing name. */ @@ -86,7 +86,7 @@ public class CommonVetoableTest extends AbstractJTimerTest { newTask.setCreationDate(new Date()); dataManager.addTask(task1, newTask, null); } - + /** * Test single task move, trying to move projects into tasks. */ @@ -110,7 +110,7 @@ public class CommonVetoableTest extends AbstractJTimerTest { // move task dataManager.moveTask(task2, Collections.singleton(task1)); } - + /** * Test single task move, into another task where name already exists. */ @@ -130,7 +130,7 @@ public class CommonVetoableTest extends AbstractJTimerTest { Assert.assertNotNull(task1); Assert.assertNotNull(task2); - + // rename tank before move // (task jTimer/Add workspace support exists !) dataManager.editTask(task1, "Add workspace support"); @@ -138,7 +138,7 @@ public class CommonVetoableTest extends AbstractJTimerTest { // move task dataManager.moveTask(task2, Collections.singleton(task1)); } - + /** * Test multiples tasks move move into one task to move. */ @@ -173,7 +173,7 @@ public class CommonVetoableTest extends AbstractJTimerTest { dataManager.moveTask(task1, tasksToMove); } - + /** * Merge two projects and tasks. */ diff --git a/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java b/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java index 106c6a3..4eb816c 100644 --- a/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java +++ b/src/test/java/org/chorem/jtimer/data/TimerDataManagerTest.java @@ -22,28 +22,28 @@ package org.chorem.jtimer.data; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - import org.chorem.jtimer.AbstractJTimerTest; import org.chorem.jtimer.entities.TimerAlert; +import org.chorem.jtimer.entities.TimerAlert.Type; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; -import org.chorem.jtimer.entities.TimerAlert.Type; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; + /** * Test class for TimerDataManager. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -301,7 +301,7 @@ public class TimerDataManagerTest extends AbstractJTimerTest { Assert.assertNull(task2a); Assert.assertNotNull(task3a); } - + /** * Test multiples tasks move. */ @@ -447,7 +447,7 @@ public class TimerDataManagerTest extends AbstractJTimerTest { /** * Merge two tasks together. - * + * * In both task subtask, there is a name conflict (same subtask name). */ @Test @@ -497,7 +497,7 @@ public class TimerDataManagerTest extends AbstractJTimerTest { /** * Test add alert. - * + * * Alert reloading was buggy when multiple alert types were defined. * (i.e. two alert type REACH_DAILY_TIME) */ @@ -613,24 +613,24 @@ public class TimerDataManagerTest extends AbstractJTimerTest { //core.init(); core.load(); - + TimerTask task = dataManager.getTaskForPath("jTimer/Unit tests/UI tests"); Assert.assertEquals(task.getName(), "UI tests"); task = dataManager.getTaskForPath("jTimer/Unit tests/fake"); Assert.assertNull(task); } - + /** * Test to find task by path. */ - @Test(expectedExceptions=IllegalArgumentException.class) + @Test(expectedExceptions = IllegalArgumentException.class) public void testGetTaskForPathProject() { TimerCore core = new TimerCore(); TimerDataManager dataManager = core.getData(); //core.init(); core.load(); - + TimerTask task = dataManager.getTaskForPath("jTimer"); Assert.assertNotNull(task); } diff --git a/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java b/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java index 20a7454..83c0b1f 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerAlertTest.java @@ -22,22 +22,22 @@ package org.chorem.jtimer.entities; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.chorem.jtimer.AbstractJTimerTest; import org.chorem.jtimer.entities.TimerAlert.Type; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * Test class for TimerAlert. * * @author chatellier * @version $Revision: 2607 $ - * + * * Last update : $Date: 2009-06-18 17:19:19 +0200 (jeu. 18 juin 2009) $ * By : $Author: echatellier $ */ @@ -54,7 +54,7 @@ public class TimerAlertTest extends AbstractJTimerTest { Assert.assertEquals(alert.getDuration(), 8); Assert.assertEquals(alert.getType(), Type.REACH_DAILY_TIME); } - + /** * Test task clone(); */ @@ -63,10 +63,10 @@ public class TimerAlertTest extends AbstractJTimerTest { TimerAlert alert = new TimerAlert(Type.REACH_DAILY_TIME, 8); TimerAlert alertClone = alert.clone(); - + Assert.assertEquals(alertClone.getDuration(), 8); Assert.assertEquals(alertClone.getType(), Type.REACH_DAILY_TIME); - + // not origin modification alertClone.setDuration(16); Assert.assertEquals(alert.getDuration(), 8); @@ -77,10 +77,10 @@ public class TimerAlertTest extends AbstractJTimerTest { */ @Test public void testEquals() { - + TimerAlert alert = new TimerAlert(Type.REACH_DAILY_TIME, 8); TimerAlert alert2 = new TimerAlert(Type.REACH_TOTAL_TIME, 8); - + Assert.assertFalse(alert.equals(alert2)); alert.setType(Type.REACH_TOTAL_TIME); Assert.assertEquals(alert, alert2); @@ -108,7 +108,7 @@ public class TimerAlertTest extends AbstractJTimerTest { alertList.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); alertList.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); alertList.add(new TimerAlert(Type.REACH_DAILY_TIME, 7)); - + Assert.assertEquals(alertList.size(), 3); Assert.assertTrue(alertList.contains(new TimerAlert(Type.REACH_DAILY_TIME, 7))); } @@ -122,7 +122,7 @@ public class TimerAlertTest extends AbstractJTimerTest { alertSet.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); alertSet.add(new TimerAlert(Type.REACH_DAILY_TIME, 8)); alertSet.add(new TimerAlert(Type.REACH_DAILY_TIME, 7)); - + // 2 => due to hashcode Assert.assertEquals(alertSet.size(), 2); Assert.assertTrue(alertSet.contains(new TimerAlert(Type.REACH_DAILY_TIME, 7))); diff --git a/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java b/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java index 1c0ffb3..98124ff 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerProjectTest.java @@ -31,7 +31,7 @@ import org.testng.annotations.Test; * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -48,18 +48,18 @@ public class TimerProjectTest extends AbstractJTimerTest { Assert.assertEquals("test", project.getName()); } - + /** * Test project clone() */ @Test public void testClone() { - + TimerProject project = new TimerProject(); project.setName("name1"); - + TimerProject project2 = project.clone(); - + Assert.assertEquals("name1", project2.getName()); Assert.assertEquals(project, project2); } diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java index 87cc0e1..b717624 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerTaskTest.java @@ -22,19 +22,19 @@ package org.chorem.jtimer.entities; -import java.util.Date; - import org.chorem.jtimer.AbstractJTimerTest; import org.chorem.jtimer.utils.DailySortedMap; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.Date; + /** * Test class for TimerTask. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -51,7 +51,7 @@ public class TimerTaskTest extends AbstractJTimerTest { Assert.assertEquals("test", task.getName()); } - + /** * Test task clone(); */ @@ -60,7 +60,7 @@ public class TimerTaskTest extends AbstractJTimerTest { TimerTask task = new TimerTask(); task.setName("test"); - + TimerTask clonedTask = task.clone(); Assert.assertTrue(clonedTask.allDaysTimes instanceof DailySortedMap<?>, "Clone put invalid type for map"); @@ -72,23 +72,23 @@ public class TimerTaskTest extends AbstractJTimerTest { */ @Test public void testSubtasks() { - + TimerTask task = new TimerTask(); task.setName("test"); - + TimerTask subtask = new TimerTask(); subtask.setName("subtest"); subtask.setCreationDate(new Date()); task.addTask(subtask); - + TimerTask clonedTask = task.clone(); - + // subtask copied Assert.assertEquals(1, clonedTask.getSubTasks().size()); - + // subtask modification Assert.assertEquals("subtest", clonedTask.getSubTasks().get(0).getName()); - + // clone removal, not modify first clonedTask.getSubTasks().clear(); Assert.assertEquals(0, clonedTask.getSubTasks().size()); @@ -102,9 +102,9 @@ public class TimerTaskTest extends AbstractJTimerTest { public void testCloneLists() { TimerTask task = new TimerTask(); task.setName("test"); - + TimerTask clonedTask = task.clone(); - + task.setClosed(true); task.addTask(new TimerTask()); task.setName("new name"); diff --git a/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java b/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java index c387b13..f4ef310 100644 --- a/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/AbstractSaverTest.java @@ -22,21 +22,21 @@ package org.chorem.jtimer.io; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - import org.apache.commons.io.FileUtils; import org.chorem.jtimer.AbstractJTimerTest; import org.testng.Assert; import org.testng.annotations.Test; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + /** * Test for AbstractSaver. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -44,61 +44,58 @@ public class AbstractSaverTest extends AbstractJTimerTest { /** * Test that backup create a backup file. - * + * * @throws IOException */ @Test public void makeBackupFileTest() throws IOException { File file = File.createTempFile("test", ".test"); - AbstractSaver saver = new GTimerIncrementalSaver(); - + File backupFile = BackupUtils.makeBackupFile(file); - + Assert.assertNotNull(backupFile); Assert.assertTrue(backupFile.isFile()); } - + /** * Test that restore restore backup file. - * - * @throws IOException + * + * @throws IOException */ @Test public void restoreBackupFileTest() throws IOException { File file = File.createTempFile("test", ".test"); FileUtils.writeStringToFile(file, "oldcontent", StandardCharsets.UTF_8); - - AbstractSaver saver = new GTimerIncrementalSaver(); + File backupFile = BackupUtils.makeBackupFile(file); - + Assert.assertNotNull(backupFile); Assert.assertTrue(backupFile.isFile()); - + FileUtils.writeStringToFile(file, "newcontent", StandardCharsets.UTF_8); Assert.assertEquals(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "newcontent"); Assert.assertEquals(FileUtils.readFileToString(backupFile, StandardCharsets.UTF_8), "oldcontent"); boolean result = BackupUtils.restoreBackupFile(backupFile); Assert.assertTrue(result); - + Assert.assertFalse(backupFile.isFile()); Assert.assertEquals(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "oldcontent"); } - + /** * Test that delete really delete file. - * - * @throws IOException + * + * @throws IOException */ @Test public void deleteBackupFile() throws IOException { File file = File.createTempFile("test", ".test"); - - AbstractSaver saver = new GTimerIncrementalSaver(); + File backupFile = BackupUtils.makeBackupFile(file); BackupUtils.deleteBackupFile(backupFile); - + Assert.assertFalse(backupFile.isFile()); } } diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java index a4c8a19..559be60 100644 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java @@ -22,10 +22,18 @@ package org.chorem.jtimer.io; +import org.apache.commons.io.FileUtils; +import org.chorem.jtimer.AbstractJTimerTest; +import org.chorem.jtimer.entities.TimerAlert; +import org.chorem.jtimer.entities.TimerProject; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TimerTaskHelper; +import org.testng.Assert; +import org.testng.annotations.Test; + import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; - import java.util.Calendar; import java.util.Collection; import java.util.Date; @@ -34,22 +42,13 @@ import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; -import org.apache.commons.io.FileUtils; -import org.chorem.jtimer.AbstractJTimerTest; -import org.chorem.jtimer.entities.TimerSync; -import org.chorem.jtimer.entities.TimerAlert; -import org.chorem.jtimer.entities.TimerProject; -import org.chorem.jtimer.entities.TimerTask; -import org.chorem.jtimer.entities.TimerTaskHelper; -import org.testng.Assert; -import org.testng.annotations.Test; /** * Test for JTimerFactory. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -79,7 +78,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { /** * Test data loading. - * + * * Test that 5 projects are loaded (39 tasks, etc...) */ @Test @@ -107,8 +106,8 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { /** * Test project loading. - * - * @throws IOException + * + * @throws IOException */ @Test public void getProjectFromFileTest() throws IOException { @@ -144,13 +143,13 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { /** * Test task loading. - * + * * Test: * name * times * parent - * - * @throws IOException + * + * @throws IOException */ @Test public void parseTaskFromFileTest() throws IOException { @@ -231,8 +230,8 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { /** * Test annotation loading. - * - * @throws IOException + * + * @throws IOException */ @Test public void parseAnnotationsTest() throws IOException { @@ -258,7 +257,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { .firstKey()); Assert.assertEquals("Very hard work", task.getAllDaysAnnotations().get( task.getAllDaysAnnotations().firstKey())); - + // second ann date = new Date(); date.setTime(1228950002 * 1000L); @@ -278,8 +277,8 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { /** * Test alert loading. - * - * @throws IOException + * + * @throws IOException */ @Test public void parseAlertsTest() throws IOException { @@ -314,12 +313,12 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { } }*/ } - + /** * Test que les taches sans projets parent (autorisé par gtimer) sont bien * chargé par jtimer dans un projet nommé "No project". - * - * @throws IOException + * + * @throws IOException */ @Test public void defaultProjectTest() throws IOException { @@ -327,13 +326,13 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { //FIXME testSaver.lock();*/ GTimerIncrementalSaver gsaver = (GTimerIncrementalSaver) testSaver; - + // task to get annotation Collection<TimerProject> projects = gsaver.load(); TimerProject project1 = findProject(projects, "No project"); Assert.assertNotNull(project1); - + TimerTask task1 = findTask(projects, "No project/Test no parent project"); Assert.assertNotNull(task1); Assert.assertEquals(TimerTaskHelper.getAllTotalTime(task1), 9644000); diff --git a/src/test/java/org/chorem/jtimer/plugin/timebundle/TImeBundleSaverTest.java b/src/test/java/org/chorem/jtimer/plugin/timebundle/TImeBundleSaverTest.java index 4dac2cf..733ec82 100644 --- a/src/test/java/org/chorem/jtimer/plugin/timebundle/TImeBundleSaverTest.java +++ b/src/test/java/org/chorem/jtimer/plugin/timebundle/TImeBundleSaverTest.java @@ -29,7 +29,7 @@ public class TImeBundleSaverTest extends AbstractJTimerTest { * @throws IOException */ @Test - public void parseSyncInfoTest() throws IOException{ + public void parseSyncInfoTest() throws IOException { TimerTask task = new TimerTask(); task.setNumber(41); diff --git a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java b/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java index fc0d91a..c7538b7 100644 --- a/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java +++ b/src/test/java/org/chorem/jtimer/plugin/timebundle/TimeBundleHelperTest.java @@ -31,8 +31,6 @@ import org.chorem.jtimer.entities.TimerTask; import org.testng.Assert; import org.testng.annotations.Test; -import java.time.LocalDate; -import java.time.ZoneId; import java.util.Calendar; import java.util.Date; diff --git a/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java b/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java index 40187ae..52d785c 100644 --- a/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java +++ b/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java @@ -36,7 +36,7 @@ import java.util.Optional; * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -47,7 +47,7 @@ public class SystemInfoFactoryTest extends AbstractJTimerTest { /** * Test to get system info. - * + * * Could return a valid system info, on linux * windows, or fail if none is available. */ diff --git a/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java b/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java index 415646e..992c615 100644 --- a/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java +++ b/src/test/java/org/chorem/jtimer/ui/report/ReportGeneratorTest.java @@ -22,13 +22,6 @@ package org.chorem.jtimer.ui.report; -import java.text.DateFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.AbstractJTimerTest; @@ -36,12 +29,19 @@ import org.chorem.jtimer.entities.TimerProject; import org.testng.Assert; import org.testng.annotations.Test; +import java.text.DateFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + /** * Test for ReportGenerator class. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -49,20 +49,20 @@ public class ReportGeneratorTest extends AbstractJTimerTest { /** Class log */ private static Log log = LogFactory.getLog(ReportGeneratorTest.class); - + protected static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); /** * Test report generation. - * - * @throws ParseException + * + * @throws ParseException */ @Test public void getReportTextDaily() throws ParseException { /*try { FIXME saver.lock();*/ - + Date d1 = df.parse("January 1, 2008"); Date d2 = df.parse("December 31, 2008"); List<TimerProject> projects = new ArrayList<>(); @@ -70,7 +70,7 @@ public class ReportGeneratorTest extends AbstractJTimerTest { ReportGenerator generator = new ReportGenerator(); String content = generator.getReportText(ReportGenerator.Type.BY_DAY_REPORT, projects, d1, d2, false, false, false, false); - + if (log.isDebugEnabled()) { log.debug("Daily report = " + content); } @@ -79,16 +79,16 @@ public class ReportGeneratorTest extends AbstractJTimerTest { Assert.assertFalse(content.indexOf("IsisFish") > 0); Assert.assertFalse(content.indexOf("jRST") > 0); Assert.assertTrue(content.indexOf("Topia") > 0); - + // no present task Assert.assertFalse(content.indexOf("Add webservice") > 0); Assert.assertFalse(content.indexOf("Add workspace support") > 0); - + // present task Assert.assertTrue(content.indexOf("Add service layer") > 0); Assert.assertTrue(content.indexOf("Calendar to date") > 0); Assert.assertTrue(content.indexOf("Tree tests") > 0); - + // no annotations Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); Assert.assertFalse(content.indexOf("Not easy work") > 0); @@ -105,8 +105,8 @@ public class ReportGeneratorTest extends AbstractJTimerTest { /** * Test report generation with annotation time. - * - * @throws ParseException + * + * @throws ParseException */ @Test public void getReportTextDailyAnnotationTime() throws ParseException { @@ -143,15 +143,15 @@ public class ReportGeneratorTest extends AbstractJTimerTest { /** * Test report generation. - * - * @throws ParseException + * + * @throws ParseException */ @Test public void getReportTextWeekly() throws ParseException { /*try { FIXME saver.lock();*/ - + Date d1 = df.parse("November 1, 2008"); Date d2 = df.parse("March 31, 2009"); List<TimerProject> projects = new ArrayList<>(); @@ -159,22 +159,22 @@ public class ReportGeneratorTest extends AbstractJTimerTest { ReportGenerator generator = new ReportGenerator(); String content = generator.getReportText(ReportGenerator.Type.BY_WEEK_REPORT, projects, d1, d2, true, true, false, false); - + if (log.isDebugEnabled()) { log.debug("Weekly report = " + content); } - + Assert.assertNotNull(content); Assert.assertTrue(content.indexOf("jTimer") > 0); Assert.assertTrue(content.indexOf("Topia") > 0); - + // no present task Assert.assertFalse(content.indexOf("Add service layer") > 0); - + // present task Assert.assertTrue(content.indexOf("Add webservice") > 0); Assert.assertTrue(content.indexOf("Add workspace support") > 0); - + // with annotations Assert.assertTrue(content.indexOf("* Test task and subtask time") > 0); Assert.assertTrue(content.indexOf("* Not easy work") > 0); @@ -187,18 +187,18 @@ public class ReportGeneratorTest extends AbstractJTimerTest { } }*/ } - + /** * Test report generation with annotation time. - * - * @throws ParseException + * + * @throws ParseException */ @Test public void getReportTextMonthlyAnnotationTime() throws ParseException { /*try { FIXME saver.lock();*/ - + Date d1 = df.parse("November 1, 2008"); Date d2 = df.parse("March 31, 2009"); List<TimerProject> projects = new ArrayList<>(); @@ -206,13 +206,13 @@ public class ReportGeneratorTest extends AbstractJTimerTest { ReportGenerator generator = new ReportGenerator(); String content = generator.getReportText(ReportGenerator.Type.BY_MONTH_REPORT, projects, d1, d2, true, true, true, false); - + if (log.isDebugEnabled()) { log.debug("Monthly report = " + content); } - + Assert.assertNotNull(content); - + // no annotations Assert.assertTrue(content.indexOf("* 2/3/09 2:10 PM : Test task and subtask time") > 0); Assert.assertTrue(content.indexOf("* 12/11/08 12:00 AM : Not easy work") > 0); @@ -225,17 +225,17 @@ public class ReportGeneratorTest extends AbstractJTimerTest { } }*/ } - + /** * Test report generation. - * @throws ParseException + * @throws ParseException */ @Test public void getReportTextMonthly() throws ParseException { /*try { FIXME saver.lock();*/ - + Date d1 = df.parse("November 1, 2008"); Date d2 = df.parse("March 31, 2009"); List<TimerProject> projects = new ArrayList<>(); @@ -243,22 +243,22 @@ public class ReportGeneratorTest extends AbstractJTimerTest { ReportGenerator generator = new ReportGenerator(); String content = generator.getReportText(ReportGenerator.Type.BY_MONTH_REPORT, projects, d1, d2, true, false, false, false); - + if (log.isDebugEnabled()) { log.debug("Monthly report = " + content); } - + Assert.assertNotNull(content); Assert.assertTrue(content.indexOf("Chorem") > 0); Assert.assertTrue(content.indexOf("Topia") > 0); - + // no present task Assert.assertFalse(content.indexOf("Add service layer") > 0); - + // present task Assert.assertTrue(content.indexOf("Add webservice") > 0); Assert.assertTrue(content.indexOf("Add workspace support") > 0); - + // no annotations Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); Assert.assertFalse(content.indexOf("Not easy work") > 0); @@ -271,17 +271,17 @@ public class ReportGeneratorTest extends AbstractJTimerTest { } }*/ } - + /** * Test report generation. - * @throws ParseException + * @throws ParseException */ @Test public void getReportTextYearly() throws ParseException { /*try { FIXME saver.lock();*/ - + Date d1 = df.parse("January 1, 2008"); Date d2 = df.parse("December 31, 2008"); List<TimerProject> projects = new ArrayList<>(); @@ -289,23 +289,23 @@ public class ReportGeneratorTest extends AbstractJTimerTest { ReportGenerator generator = new ReportGenerator(); String content = generator.getReportText(ReportGenerator.Type.BY_YEAR_REPORT, projects, d1, d2, false, false, false, false); - + if (log.isDebugEnabled()) { log.debug("Yearly report = " + content); } - + Assert.assertNotNull(content); Assert.assertFalse(content.indexOf("Chorem") > 0); Assert.assertTrue(content.indexOf("Topia") > 0); - + // no present task Assert.assertFalse(content.indexOf("Add webservice") > 0); Assert.assertFalse(content.indexOf("Add workspace support") > 0); - + // present task Assert.assertTrue(content.indexOf("Add service layer") > 0); Assert.assertTrue(content.indexOf("Calendar to date") > 0); - + // no annotations Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); Assert.assertFalse(content.indexOf("Not easy work") > 0); @@ -318,17 +318,17 @@ public class ReportGeneratorTest extends AbstractJTimerTest { } }*/ } - + /** * Test report generation. - * @throws ParseException + * @throws ParseException */ @Test public void getReportTextByProject() throws ParseException { /*try { FIXME saver.lock();*/ - + Date d1 = df.parse("January 1, 2008"); Date d2 = df.parse("December 31, 2008"); List<TimerProject> projects = new ArrayList<>(); @@ -336,23 +336,23 @@ public class ReportGeneratorTest extends AbstractJTimerTest { ReportGenerator generator = new ReportGenerator(); String content = generator.getReportText(ReportGenerator.Type.BY_PROJECT_REPORT, projects, d1, d2, true, true, false, false); - + if (log.isDebugEnabled()) { log.debug("Project report = " + content); } - + Assert.assertNotNull(content); Assert.assertFalse(content.indexOf("Chorem") > 0); Assert.assertTrue(content.indexOf("Topia") > 0); - + // no present task Assert.assertFalse(content.indexOf("Add webservice") > 0); Assert.assertFalse(content.indexOf("Add workspace support") > 0); - + // present task Assert.assertTrue(content.indexOf("Add service layer") > 0); Assert.assertTrue(content.indexOf("Calendar to date") > 0); - + // test annotations Assert.assertFalse(content.indexOf("Test task and subtask time") > 0); Assert.assertTrue(content.indexOf("* Not easy work") > 0); diff --git a/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java b/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java index e7613f3..7fc5441 100644 --- a/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java +++ b/src/test/java/org/chorem/jtimer/ui/report/ReportUtilsTest.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2008 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,12 +22,6 @@ package org.chorem.jtimer.ui.report; -import java.text.DateFormat; -import java.text.ParseException; -import java.util.Date; -import java.util.List; -import java.util.Locale; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.AbstractJTimerTest; @@ -35,12 +29,18 @@ import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.text.DateFormat; +import java.text.ParseException; +import java.util.Date; +import java.util.List; +import java.util.Locale; + /** * Test for ReportUtils class. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -61,10 +61,10 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 day interval). - * + * * Test qu'il y a bien 46 jours entre date102008 et date112008. - * - * @throws ParseException + * + * @throws ParseException */ @Test public void testGetDailyDates() throws ParseException { @@ -84,8 +84,8 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 day interval). - * - * @throws ParseException + * + * @throws ParseException */ @Test public void testGetDailyDates2() throws ParseException { @@ -105,8 +105,8 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 day interval). - * - * @throws ParseException + * + * @throws ParseException */ @Test public void testGetDailyDates3() throws ParseException { @@ -126,9 +126,9 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 week interval). - * + * * Test qu'il y a bien 46 jours entre date102008 et date112008. - * @throws ParseException + * @throws ParseException */ @Test public void testGetWeeklyDates() throws ParseException { @@ -148,7 +148,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 week interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetWeeklyDates2() throws ParseException { @@ -168,7 +168,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 week interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetWeeklyDates3() throws ParseException { @@ -188,9 +188,9 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 month interval). - * + * * 16 mois. - * @throws ParseException + * @throws ParseException */ @Test public void testGetMonthlyDates() throws ParseException { @@ -211,7 +211,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 month interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetMonthlyDates2() throws ParseException { @@ -232,7 +232,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 month interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetMonthlyDates4() throws ParseException { @@ -253,7 +253,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 year interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetYearlyDates() throws ParseException { @@ -275,7 +275,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 year interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetYearlyDates2() throws ParseException { @@ -297,7 +297,7 @@ public class ReportUtilsTest extends AbstractJTimerTest { /** * Get date list, between to date (1 year interval). - * @throws ParseException + * @throws ParseException */ @Test public void testGetYearlyDates3() throws ParseException { diff --git a/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java b/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java index 3b33756..747f73e 100644 --- a/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java +++ b/src/test/java/org/chorem/jtimer/ui/widget/DurationEditorTest.java @@ -29,7 +29,7 @@ import javax.swing.JFrame; * * @author chatellier * @version $Revision: 1.0 $ - * + * * Last update : $Date: 2 juil. 2009 $ * By : $Author: chatellier $ */ @@ -37,7 +37,7 @@ public class DurationEditorTest { /** * Show duration editor test. - * + * * TODO add ui test framework */ public void showDurationEditorTest() { diff --git a/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java b/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java index e936584..888e01f 100644 --- a/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java +++ b/src/test/java/org/chorem/jtimer/utils/DailySortedMapTest.java @@ -22,26 +22,26 @@ package org.chorem.jtimer.utils; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + import java.text.DateFormat; import java.text.ParseException; import java.util.Date; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.SortedMap; import java.util.TreeMap; -import java.util.Map.Entry; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; /** * Test for DailySortedMap class. * * @author chatellier * @version $Revision$ - * + * * Last update : $Date$ * By : $Author$ */ @@ -68,7 +68,7 @@ public class DailySortedMapTest { /** * Test le constructeur avec comparateur. - * @throws ParseException + * @throws ParseException */ @Test public void testConsctuctorComparator() throws ParseException { @@ -90,7 +90,7 @@ public class DailySortedMapTest { /** * Test du constructeur avec une sorted map. - * @throws ParseException + * @throws ParseException */ @Test public void testConstructorMap() throws ParseException { @@ -114,7 +114,7 @@ public class DailySortedMapTest { /** * Test du constructeur avec une map. - * @throws ParseException + * @throws ParseException */ @Test public void testConstructorSortedMap() throws ParseException { @@ -138,7 +138,7 @@ public class DailySortedMapTest { /** * Test ceilingEntry. - * @throws ParseException + * @throws ParseException */ @Test public void ceilingEntryTest() throws ParseException { @@ -147,10 +147,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Entry<Date, Long> entry = map.ceilingEntry(d2); Assert.assertEquals(entry.getKey(), d3); @@ -159,7 +159,7 @@ public class DailySortedMapTest { /** * Test ceilingKey. - * @throws ParseException + * @throws ParseException */ @Test public void ceilingKeyTest() throws ParseException { @@ -168,10 +168,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Date d = map.ceilingKey(d2); Assert.assertEquals(d, d3); @@ -179,7 +179,7 @@ public class DailySortedMapTest { /** * Test containsKey. - * @throws ParseException + * @throws ParseException */ @Test public void containsKeyTest() throws ParseException { @@ -202,7 +202,7 @@ public class DailySortedMapTest { /** * Test floorEntry. - * @throws ParseException + * @throws ParseException */ @Test public void floorEntryTest() throws ParseException { @@ -211,10 +211,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Entry<Date, Long> entry = map.floorEntry(d2); Assert.assertEquals(entry.getKey(), d1); @@ -223,7 +223,7 @@ public class DailySortedMapTest { /** * Test floorKey. - * @throws ParseException + * @throws ParseException */ @Test public void floorKeyTest() throws ParseException { @@ -232,10 +232,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Date d = map.floorKey(d2); Assert.assertEquals(d, d1); @@ -243,7 +243,7 @@ public class DailySortedMapTest { /** * Test get(). - * @throws ParseException + * @throws ParseException */ @Test public void getTest() throws ParseException { @@ -262,14 +262,14 @@ public class DailySortedMapTest { Date d4 = df.parse("December 30, 2008, 18:48:00 GMT"); Assert.assertEquals(map.get(d4).longValue(), 1l); - + // non date object Assert.assertNull(map.get("test false")); } /** * Test headMap. - * @throws ParseException + * @throws ParseException */ @Test public void headMapTest() throws ParseException { @@ -278,11 +278,11 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d2, 34l); map.put(d3, 13l); - + SortedMap<Date, Long> newMap = map.headMap(df.parse("June 12, 2009, 18:44:59 GMT")); Assert.assertEquals(newMap.size(), 1); @@ -290,7 +290,7 @@ public class DailySortedMapTest { /** * Test headMap. - * @throws ParseException + * @throws ParseException */ @Test public void headMapBooleanTest() throws ParseException { @@ -299,11 +299,11 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d2, 34l); map.put(d3, 13l); - + SortedMap<Date, Long> newMap = map.headMap(df.parse("June 12, 2009, 18:44:59 GMT"), true); Assert.assertEquals(newMap.size(), 2); @@ -311,7 +311,7 @@ public class DailySortedMapTest { /** * Test higherEntry. - * @throws ParseException + * @throws ParseException */ @Test public void higherEntryTest() throws ParseException { @@ -320,10 +320,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Entry<Date, Long> entry = map.higherEntry(df.parse("June 12, 2009, 18:44:59 GMT")); Assert.assertEquals(entry.getKey(), d3); @@ -332,7 +332,7 @@ public class DailySortedMapTest { /** * Test higherKey. - * @throws ParseException + * @throws ParseException */ @Test public void higherKeyTest() throws ParseException { @@ -341,10 +341,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Date d = map.higherKey(df.parse("June 12, 2009, 18:44:59 GMT")); Assert.assertEquals(d, d3); @@ -352,7 +352,7 @@ public class DailySortedMapTest { /** * Test lowerEntry. - * @throws ParseException + * @throws ParseException */ @Test public void lowerEntryTest() throws ParseException { @@ -361,10 +361,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Entry<Date, Long> entry = map.lowerEntry(df.parse("June 12, 2009, 18:44:59 GMT")); Assert.assertEquals(entry.getKey(), d1); @@ -373,7 +373,7 @@ public class DailySortedMapTest { /** * Test lowerKey. - * @throws ParseException + * @throws ParseException */ @Test public void lowerKeyTest() throws ParseException { @@ -382,10 +382,10 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); //Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d3, 13l); - + Date d = map.lowerKey(df.parse("June 12, 2009, 18:44:59 GMT")); Assert.assertEquals(d, d1); @@ -393,7 +393,7 @@ public class DailySortedMapTest { /** * Test put(). - * @throws ParseException + * @throws ParseException */ @Test public void putTest() throws ParseException { @@ -424,7 +424,7 @@ public class DailySortedMapTest { /** * Test putAll(). - * @throws ParseException + * @throws ParseException */ @Test public void putAllTest() throws ParseException { @@ -452,7 +452,7 @@ public class DailySortedMapTest { /** * Test subMap. - * @throws ParseException + * @throws ParseException */ @Test public void subMapTest() throws ParseException { @@ -461,11 +461,11 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d2, 3l); map.put(d3, 13l); - + SortedMap<Date, Long> newMap = map.subMap(df.parse("May 1, 2009, 11:02:33 GMT"), df.parse("October 11, 2009, 18:44:59 GMT")); @@ -474,7 +474,7 @@ public class DailySortedMapTest { /** * Test subMap. - * @throws ParseException + * @throws ParseException */ @Test public void subMapBooleanTest() throws ParseException { @@ -483,20 +483,20 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d2, 3l); map.put(d3, 13l); - + SortedMap<Date, Long> newMap = map.subMap(df.parse("May 09, 2009, 15:45:00 GMT"), true, - df.parse("December 07, 2009, 17:56:12 GMT") , false); + df.parse("December 07, 2009, 17:56:12 GMT"), false); Assert.assertEquals(newMap.size(), 2); } - + /** * Test tailMap. - * @throws ParseException + * @throws ParseException */ @Test public void tailMapTest() throws ParseException { @@ -505,19 +505,19 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d2, 3l); map.put(d3, 13l); - + SortedMap<Date, Long> newMap = map.tailMap(df.parse("July 15, 2009, 15:10:00 GMT")); Assert.assertEquals(newMap.size(), 1); } - + /** * Test tailMap. - * @throws ParseException + * @throws ParseException */ @Test public void tailMapBooleanTest() throws ParseException { @@ -526,11 +526,11 @@ public class DailySortedMapTest { Date d1 = df.parse("May 09, 2009, 12:00:00 GMT"); Date d2 = df.parse("June 12, 2009, 12:00:00 GMT"); Date d3 = df.parse("December 07, 2009, 12:00:00 GMT"); - + map.put(d1, 3l); map.put(d2, 3l); map.put(d3, 13l); - + SortedMap<Date, Long> newMap = map.tailMap(df.parse("December 07, 2009, 13:58:00 GMT"), false); Assert.assertEquals(newMap.size(), 0); -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.