Author: echatellier Date: 2012-03-09 18:18:53 +0100 (Fri, 09 Mar 2012) New Revision: 2817 Url: http://chorem.org/repositories/revision/jtimer/2817 Log: Add current week and previous week buttons Added: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/date_current.png trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/date_previous.png Modified: trunk/README.txt trunk/src/main/java/org/chorem/jtimer/ui/report/ReportView.java trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView.properties trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView_fr.properties Modified: trunk/README.txt =================================================================== --- trunk/README.txt 2012-03-09 15:31:15 UTC (rev 2816) +++ trunk/README.txt 2012-03-09 17:18:53 UTC (rev 2817) @@ -24,3 +24,12 @@ jtimer (linux) jtimer.exe (windows) + + +Credits +------- + +Images "src/main/resources/org/chorem/jtimer/ui/report/resources/date_current.png" +and "src/main/resources/org/chorem/jtimer/ui/report/resources/date_previous.png" +are licensed under Creative Commons Attribution (by) and available at: +http://www.famfamfam.com/ Modified: trunk/src/main/java/org/chorem/jtimer/ui/report/ReportView.java =================================================================== --- trunk/src/main/java/org/chorem/jtimer/ui/report/ReportView.java 2012-03-09 15:31:15 UTC (rev 2816) +++ trunk/src/main/java/org/chorem/jtimer/ui/report/ReportView.java 2012-03-09 17:18:53 UTC (rev 2817) @@ -123,9 +123,6 @@ /** Report output */ protected JTextArea reportArea; - /** Send by mail button */ - protected JButton sendMailButton; - /** Can send mail property. */ protected boolean canSendMail; @@ -167,29 +164,6 @@ JPanel mainComponent = new JPanel(new GridBagLayout()); - // init dates - Calendar calendarBegin = Calendar.getInstance(); - int firstDayOfWeek = JTimer.config.getReportFirstDayOfWeek(); - if (firstDayOfWeek < 0 || firstDayOfWeek > 6) { - firstDayOfWeek = calendarBegin.getFirstDayOfWeek(); - } - calendarBegin.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); - calendarBegin.set(Calendar.HOUR, 0); - calendarBegin.set(Calendar.MINUTE, 0); - calendarBegin.set(Calendar.SECOND, 0); - calendarBegin.set(Calendar.MILLISECOND, 0); - - // calendar must be in current week by default - if (calendarBegin.getTime().after(new Date())) { - calendarBegin.add(Calendar.WEEK_OF_YEAR, -1); - } - - // get end of week - // take calendarBegin and add a week time - Calendar calendarEnd = (Calendar) calendarBegin.clone(); - calendarEnd.add(Calendar.WEEK_OF_YEAR, 1); - calendarEnd.add(Calendar.DAY_OF_YEAR, -1); // take the day before - // panel for options JPanel panelOption = new JPanel(new GridBagLayout()); panelOption.setBorder(BorderFactory.createTitledBorder(getResourceMap() @@ -202,9 +176,8 @@ new Insets(1, 1, 1, 1), 0, 0)); datePickerFrom = new JXDatePicker(); datePickerFrom.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED); - datePickerFrom.setDate(calendarBegin.getTime()); datePickerFrom.setFormats(DateFormat.getDateInstance(DateFormat.FULL)); - panelOption.add(datePickerFrom, new GridBagConstraints(1, 0, 3, 1, 1, + panelOption.add(datePickerFrom, new GridBagConstraints(1, 0, 2, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); @@ -215,13 +188,29 @@ new Insets(1, 1, 1, 1), 0, 0)); datePickerTo = new JXDatePicker(); datePickerTo.getMonthView().setDayForeground(Calendar.SUNDAY, Color.RED); - datePickerTo.setDate(calendarEnd.getTime()); datePickerTo.setFormats(DateFormat.getDateInstance(DateFormat.FULL)); - panelOption.add(datePickerTo, new GridBagConstraints(1, 1, 3, 1, 0, 0, + panelOption.add(datePickerTo, new GridBagConstraints(1, 1, 2, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - // Option for period regroupment + // set current week by default + currentWeek(); + + // action button to show current or previous week + JButton currentWeekButton = new JButton(); + currentWeekButton.setAction(getContext().getActionMap(this).get( + "currentWeek")); + panelOption.add(currentWeekButton, new GridBagConstraints(3, 0, 1, 1, 0, + 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(1, 1, 1, 1), 0, 0)); + JButton previousWeekButton = new JButton(); + previousWeekButton.setAction(getContext().getActionMap(this).get( + "previousWeek")); + panelOption.add(previousWeekButton, new GridBagConstraints(3, 1, 1, 1, 0, + 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(1, 1, 1, 1), 0, 0)); + + // Option for period grouping radioByDay = new JRadioButton( getResourceMap().getString("reportDaily"), true); radioByMonth = new JRadioButton(getResourceMap().getString( @@ -246,13 +235,13 @@ panelOption.add(radioByMonth, new GridBagConstraints(2, 2, 2, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - panelOption.add(radioByWeek, new GridBagConstraints(0, 3, 2, 1, 1, 0, + panelOption.add(radioByWeek, new GridBagConstraints(0, 3, 2, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - panelOption.add(radioByYear, new GridBagConstraints(2, 3, 2, 1, 1, 0, + panelOption.add(radioByYear, new GridBagConstraints(2, 3, 2, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - panelOption.add(radioByProject, new GridBagConstraints(0, 4, 4, 1, 1, + panelOption.add(radioByProject, new GridBagConstraints(0, 4, 4, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); @@ -260,7 +249,7 @@ checkIncludesAnnotations = new JCheckBox(getResourceMap().getString( "reportAnnotations")); panelOption.add(checkIncludesAnnotations, new GridBagConstraints(0, 5, - 4, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + 4, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); // panel form projects @@ -313,7 +302,7 @@ 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1, 1), 0, 0)); - sendMailButton = new JButton(); + JButton sendMailButton = new JButton(); sendMailButton.setAction(getContext().getActionMap(this) .get("sendMail")); mainComponent.add(sendMailButton, new GridBagConstraints(1, 2, 1, 1, 1, @@ -334,6 +323,60 @@ } /** + * Select current week in date pickers. + */ + @Action + public void currentWeek() { + fillPickerDates(0); + } + + /** + * Display previous week in date pickers. + */ + @Action + public void previousWeek() { + fillPickerDates(-1); + } + + /** + * 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) { + // init dates + Calendar calendarBegin = Calendar.getInstance(); + int firstDayOfWeek = JTimer.config.getReportFirstDayOfWeek(); + if (firstDayOfWeek < 0 || firstDayOfWeek > 6) { + firstDayOfWeek = calendarBegin.getFirstDayOfWeek(); + } + calendarBegin.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); + calendarBegin.set(Calendar.HOUR, 0); + calendarBegin.set(Calendar.MINUTE, 0); + calendarBegin.set(Calendar.SECOND, 0); + calendarBegin.set(Calendar.MILLISECOND, 0); + + // calendar must be in current week by default + if (calendarBegin.getTime().after(new Date())) { + calendarBegin.add(Calendar.WEEK_OF_YEAR, -1); + } + + // get end of week + // take calendarBegin and add a week time + Calendar calendarEnd = (Calendar) calendarBegin.clone(); + calendarEnd.add(Calendar.WEEK_OF_YEAR, 1); + calendarEnd.add(Calendar.DAY_OF_YEAR, -1); // take the day before + + // apply delai + calendarBegin.add(Calendar.WEEK_OF_YEAR, delay); + calendarEnd.add(Calendar.WEEK_OF_YEAR, delay); + + datePickerFrom.setDate(calendarBegin.getTime()); + datePickerTo.setDate(calendarEnd.getTime()); + } + + /** * Close action. */ @Action Modified: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView.properties 2012-03-09 15:31:15 UTC (rev 2816) +++ trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView.properties 2012-03-09 17:18:53 UTC (rev 2817) @@ -5,7 +5,7 @@ # $Id$ # $HeadURL$ # %% -# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric +# Copyright (C) 2007 - 2012 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 @@ -37,6 +37,12 @@ reportContent=Report reportProjectsList=Projects list +currentWeek.Action.icon = date_current.png +currentWeek.Action.shortDescription = Current week + +previousWeek.Action.icon = date_previous.png +previousWeek.Action.shortDescription = Previous week + showHiddenProjects.Action.text = Show hidden projects showHiddenProjects.Action.shortDescription = Show hidden projects Modified: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView_fr.properties =================================================================== --- trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView_fr.properties 2012-03-09 15:31:15 UTC (rev 2816) +++ trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/ReportView_fr.properties 2012-03-09 17:18:53 UTC (rev 2817) @@ -5,7 +5,7 @@ # $Id$ # $HeadURL$ # %% -# Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric +# Copyright (C) 2007 - 2012 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 @@ -37,6 +37,10 @@ reportContent=Rapport reportProjectsList=Liste des projets +currentWeek.Action.shortDescription = Semaine courante + +previousWeek.Action.shortDescription = Semaine pr\u00E9c\u00E9dente + showHiddenProjects.Action.text = Afficher les cach\u00E9s showHiddenProjects.Action.shortDescription = Afficher les cach\u00E9s Added: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/date_current.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/date_current.png ___________________________________________________________________ Added: svn:mime-type + image/png Added: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/date_previous.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/org/chorem/jtimer/ui/report/resources/date_previous.png ___________________________________________________________________ Added: svn:mime-type + image/png