import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
+import java.util.Locale;
import java.util.Properties;
import java.util.TreeSet;
private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
.toString();
+ /*
+ * a date formatter using a fixed (rather than the user's) locale;
+ * this ensures that date properties can be written and re-read successfully
+ * even if the user changes their locale setting
+ */
+ private static final DateFormat date_format = SimpleDateFormat
+ .getDateTimeInstance(SimpleDateFormat.LONG,
+ SimpleDateFormat.LONG, Locale.UK);
+
/**
* Initialises the Jalview Application Log
*/
{
setProperty(property, jalview.util.Format.getHexString(colour));
}
-
- public static final DateFormat date_format = SimpleDateFormat
- .getDateTimeInstance();
-
+
/**
- * store a date in a jalview property
+ * Stores a formatted date in a jalview property, using a fixed locale.
*
- * @param string
- * @param time
+ * @param propertyName
+ * @param date
+ * @return the formatted date string
*/
- public static void setDateProperty(String property, Date time)
+ public static String setDateProperty(String propertyName, Date date)
{
- setProperty(property, date_format.format(time));
+ String formatted = date_format.format(date);
+ setProperty(propertyName, formatted);
+ return formatted;
}
/**
- * read a date stored in a jalview property
+ * Reads a date stored in a Jalview property, parses it (using a fixed locale
+ * format) and returns as a Date, or null if parsing fails
*
- * @param property
- * @return valid date as stored by setDateProperty, or null
+ * @param propertyName
+ * @return
*
*/
- public static Date getDateProperty(String property)
+ public static Date getDateProperty(String propertyName)
{
- String val = getProperty(property);
+ String val = getProperty(propertyName);
if (val != null)
{
try
} catch (Exception ex)
{
System.err.println("Invalid or corrupt date in property '"
- + property + "' : value was '" + val + "'");
+ + propertyName + "' : value was '" + val + "'");
}
}
return null;
/**
* check if the news panel's container is visible
*/
+ @Override
public boolean isVisible()
{
if (parent == null)
xf.setContentPane(me);
xf.addWindowListener(new WindowAdapter()
{
+ @Override
public void windowClosing(WindowEvent e)
{
ActionEvent actionEvent = new ActionEvent(this,
exitAction.actionPerformed(actionEvent);
}
+ @Override
public void windowOpened(WindowEvent e)
{
}
}
if (lastDate != null)
{
- jalview.bin.Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
- lastDate);
- jalview.bin.Cache.log.debug("Saved last read date as "
- + jalview.bin.Cache.date_format.format(lastDate));
-
+ String formatted = Cache.setDateProperty(
+ "JALVIEW_NEWS_RSS_LASTMODIFIED", lastDate);
+ Cache.log.debug("Saved last read date as " + formatted);
}
}
}
listItems.addMouseListener(new java.awt.event.MouseAdapter()
{
+ @Override
public void mouseClicked(MouseEvent e)
{
listItems_mouseClicked(e);
}
textDescription.addHyperlinkListener(new HyperlinkListener()
{
+ @Override
public void hyperlinkUpdate(HyperlinkEvent e)
{
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
listItems.addListSelectionListener(new ListSelectionListener()
{
+ @Override
public void valueChanged(ListSelectionEvent e)
{
if (e.getValueIsAdjusting() == false)
_listItems = listItems;
}
+ @Override
public void actionPerformed(ActionEvent e)
{
Object o = _listItems.getSelectedValue();
}
}
+ @Override
public void update(Object o)
{
setEnabled(true);
lastread.set(1983, 01, 01);
while (lastread.before(today))
{
- Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED",
- lastread.getTime());
+ String formattedDate = Cache.setDateProperty(
+ "JALVIEW_NEWS_RSS_LASTMODIFIED", lastread.getTime());
BlogReader me = new BlogReader();
- System.out.println("Set last date to "
- + jalview.bin.Cache.date_format.format(lastread.getTime()));
+ System.out.println("Set last date to " + formattedDate);
if (me.isNewsNew())
{
Cache.log.debug("There is news to read.");
private final static Icon _icon = new ImageIcon(
Main.class.getResource("image/ComposeMail16.gif"));
+ @Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus)
{
private final static Icon _icon = new ImageIcon(
Main.class.getResource("image/ComposeMail16.gif"));
+ @Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus)
{
--- /dev/null
+package jalview.bin;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class CacheTest
+{
+ private Locale locale;
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpBeforeClass()
+ {
+ locale = Locale.getDefault();
+ }
+
+ @AfterClass(alwaysRun = true)
+ public void tearDownAfterClass()
+ {
+ Locale.setDefault(locale);
+ }
+
+ /**
+ * Test that saved date format does not vary with current locale
+ */
+ @Test(groups = "Functional")
+ public void testSetDateProperty()
+ {
+ Date now = new Date();
+ Locale.setDefault(Locale.FRENCH);
+ String formattedDate = Cache.setDateProperty("test", now);
+ Locale.setDefault(Locale.UK);
+ String formattedDate2 = Cache.setDateProperty("test", now);
+ assertEquals(formattedDate, formattedDate2);
+
+ // currently using Locale.UK to format dates:
+ assertEquals(
+ formattedDate2,
+ SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG,
+ SimpleDateFormat.LONG, Locale.UK).format(now));
+ }
+}
import java.io.File;
import java.util.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
* set news feed last read to a future time to ensure no
* 'unread' news item is displayed
*/
- String oneHourFromNow = Cache.date_format
- .format(System.currentTimeMillis() + 3600 * 1000);
- Cache.setProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
+ Date oneHourFromNow = new Date(System.currentTimeMillis() + 3600 * 1000);
+ Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
Jalview.main(new String[] {});
}
@AfterClass(alwaysRun = true)
public static void tearDownAfterClass() throws Exception
{
- jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
+ Desktop.instance.closeAll_actionPerformed(null);
}
int countDsAnn(jalview.viewmodel.AlignmentViewport avp)