versions) {
setSize(new Dimension(500, 300));
Container cnt = getContentPane();
cnt.setLayout(new BoxLayout(cnt, BoxLayout.PAGE_AXIS));
JEditorPane changesText = new JEditorPane();
changesText.setEditable(false);
changesText.setFont(UIManager.getFont("TextField.font"));
String changesStr = "";
SimpleDateFormat serverFormatter = new SimpleDateFormat("MM/dd/yyyy");
DateFormat formatter;
String customFormat = translate("customDateFormat");
if (customFormat.equals("default")) {
formatter = DateFormat.getDateInstance();
} else {
formatter = new SimpleDateFormat(customFormat);
}
boolean first = true;
for (Version v : versions) {
if (!first) {
changesStr += "
";
}
first = false;
changesStr += "" + translate("version") + " " + v.versionName + "
";
String releaseDate = v.releaseDate;
try {
Date date = serverFormatter.parse(releaseDate);
releaseDate = formatter.format(date);
} catch (ParseException ex) {
Logger.getLogger(NewVersionDialog.class.getName()).log(Level.SEVERE, null, ex);
}
changesStr += translate("releasedate") + " " + releaseDate;
if (!v.changes.isEmpty()) {
changesStr += "
";
changesStr += "";
for (String type : v.changes.keySet()) {
changesStr += type + ":" + "
";
for (String ch : v.changes.get(type)) {
changesStr += " - " + ch + "
";
}
}
changesStr += "";
}
}
latestVersion = null;
if (!versions.isEmpty()) {
latestVersion = versions.get(0);
}
changesText.setContentType("text/html");
changesText.setText("" + changesStr + "");
JLabel newAvailableLabel = new JLabel("" + translate("newversionavailable") + " " + latestVersion.appName + " " + translate("version") + " " + latestVersion.versionName + "", SwingConstants.CENTER);
newAvailableLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
cnt.add(newAvailableLabel);
JLabel changeslogLabel = new JLabel("" + translate("changeslog") + "");
changeslogLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
cnt.add(changeslogLabel);
JScrollPane span = new JScrollPane(changesText);
span.setAlignmentX(JLabel.CENTER_ALIGNMENT);
cnt.add(span);
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton buttonOk = new JButton(translate("button.ok"));
buttonOk.setActionCommand(ACTION_OK);
buttonOk.addActionListener(this);
JButton buttonCancel = new JButton(translate("button.cancel"));
buttonCancel.setActionCommand(ACTION_CANCEL);
buttonCancel.addActionListener(this);
buttonsPanel.add(buttonOk);
buttonsPanel.add(buttonCancel);
buttonsPanel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
JLabel downloadNowLabel = new JLabel("" + translate("downloadnow") + "", SwingConstants.CENTER);
downloadNowLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
cnt.add(downloadNowLabel);
cnt.add(buttonsPanel);
setResizable(false);
setTitle(translate("dialog.title"));
this.getRootPane().setDefaultButton(buttonOk);
View.centerScreen(this);
setModalityType(ModalityType.APPLICATION_MODAL);
changesText.setCaretPosition(0);
View.setWindowIcon(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == ACTION_OK) {
String url;
if (latestVersion.updateLink != null) {
url = latestVersion.updateLink;
} else {
url = ApplicationInfo.updatePage;
}
if (View.navigateUrl(url)) {
Main.exit();
} else {
View.showMessageDialog(null, translate("newvermessage").replace("%oldAppName%", ApplicationInfo.SHORT_APPLICATION_NAME).replace("%newAppName%", latestVersion.appName).replace("%projectPage%", ApplicationInfo.PROJECT_PAGE), translate("newversion"), JOptionPane.INFORMATION_MESSAGE);
}
}
setVisible(false);
}
}