From 2aedcb765388459c9e43c77ee8db448159a86bcc Mon Sep 17 00:00:00 2001 From: Joel Moniz Date: Sat, 14 Jun 2014 15:32:04 +0530 Subject: [PATCH] "Last Updated" shows if "lastUpdated" field is present lastUpdate field is a Unix Timestamp in millisecs TODO: Add lastUpdated everywhere in contributions.txt, .properties file --- .../app/contrib/AvailableContribution.java | 12 ++++++++++-- app/src/processing/app/contrib/Contribution.java | 6 ++++++ .../processing/app/contrib/ContributionPanel.java | 11 +++++++++++ .../processing/app/contrib/LocalContribution.java | 9 ++++++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/contrib/AvailableContribution.java b/app/src/processing/app/contrib/AvailableContribution.java index f2d3efe65..639cbe9db 100644 --- a/app/src/processing/app/contrib/AvailableContribution.java +++ b/app/src/processing/app/contrib/AvailableContribution.java @@ -54,6 +54,13 @@ class AvailableContribution extends Contribution { version = PApplet.parseInt(versionStr, 0); } prettyVersion = params.get("prettyVersion"); + String lastUpdatedStr = params.get("lastUpdated"); + if (lastUpdatedStr != null) + try { + lastUpdated = Long.parseLong(lastUpdatedStr); + } catch (NumberFormatException e) { + lastUpdated = 0; + } } @@ -235,8 +242,8 @@ class AvailableContribution extends Contribution { version = Integer.parseInt(properties.get("version")); } catch (NumberFormatException e) { version = getVersion(); - System.err.println("The version number for the “" + name - + "” library is not set properly."); + System.err.println("The version number for the " + name + + " library is not set properly."); System.err .println("Please contact the library author to fix it according to the guidelines."); } @@ -256,6 +263,7 @@ class AvailableContribution extends Contribution { writer.println("paragraph=" + paragraph); writer.println("version=" + version); writer.println("prettyVersion=" + prettyVersion); + writer.println("lastUpdated=" + getLastUpdated()); writer.flush(); writer.close(); diff --git a/app/src/processing/app/contrib/Contribution.java b/app/src/processing/app/contrib/Contribution.java index 8367b98d3..9fc73c851 100644 --- a/app/src/processing/app/contrib/Contribution.java +++ b/app/src/processing/app/contrib/Contribution.java @@ -43,6 +43,7 @@ abstract public class Contribution { protected String paragraph; // protected int version; // 102 protected String prettyVersion; // "1.0.2" + protected long lastUpdated; // 1402805757 // "Sound" @@ -120,6 +121,11 @@ abstract public class Contribution { public String getPrettyVersion() { return prettyVersion; } + + // 1402805757 + public long getLastUpdated() { + return lastUpdated; + } abstract public ContributionType getType(); diff --git a/app/src/processing/app/contrib/ContributionPanel.java b/app/src/processing/app/contrib/ContributionPanel.java index e4d46c7ac..37b4fb6b3 100644 --- a/app/src/processing/app/contrib/ContributionPanel.java +++ b/app/src/processing/app/contrib/ContributionPanel.java @@ -28,6 +28,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.Date; +import java.text.DateFormat; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -373,6 +375,15 @@ class ContributionPanel extends JPanel { description.append("v" + version); } + long lastUpdatedUTC = contrib.getLastUpdated(); + if (lastUpdatedUTC != 0) { + DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); + Date lastUpdatedDate = new Date(lastUpdatedUTC); + if (version != null && !version.isEmpty()) + description.append(", "); + description.append("Last Updated on " + dateFormatter.format(lastUpdatedDate)); + } + description.append(""); //descriptionText.setText(description.toString()); descriptionBlock.setText(description.toString()); diff --git a/app/src/processing/app/contrib/LocalContribution.java b/app/src/processing/app/contrib/LocalContribution.java index 03a6e0f31..7b485cde4 100644 --- a/app/src/processing/app/contrib/LocalContribution.java +++ b/app/src/processing/app/contrib/LocalContribution.java @@ -1,4 +1,4 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* Part of the Processing project - http://processing.org @@ -74,6 +74,13 @@ public abstract class LocalContribution extends Contribution { System.err.println("Please contact the library author to fix it according to the guidelines."); } prettyVersion = properties.get("prettyVersion"); + try { + lastUpdated = Long.parseLong(properties.get("lastUpdated")); + } catch (NumberFormatException e) { + lastUpdated = 0; + System.err.println("The last updated timestamp for the “" + name + "” library is not set properly."); + System.err.println("Please contact the library author to fix it according to the guidelines."); + } } else { Base.log("No properties file at " + propertiesFile.getAbsolutePath());