001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: ReleaseInfoDialog.java,v 1.16 2005/12/04 13:46:04 jesper Exp $
023: package net.infonode.gui;
024:
025: import net.infonode.util.ReleaseInfo;
026:
027: import javax.swing.*;
028: import javax.swing.border.CompoundBorder;
029: import javax.swing.border.EmptyBorder;
030: import javax.swing.border.TitledBorder;
031: import java.awt.*;
032: import java.text.SimpleDateFormat;
033: import java.util.Date;
034: import java.util.TimeZone;
035:
036: public class ReleaseInfoDialog {
037: private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
038: "yyyy.MM.dd HH:mm:ss z");
039:
040: static {
041: DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
042: }
043:
044: public static void showDialog(ReleaseInfo info, String text) {
045: showDialog(new ReleaseInfo[] { info }, text == null ? null
046: : new String[] { text });
047: }
048:
049: public static void showDialog(ReleaseInfo[] info, String[] text) {
050: final JComponent message = constructMessage(info, text);
051: JScrollPane scrollPane = new JScrollPane(message,
052: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
053: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER) {
054: public Dimension getPreferredSize() {
055: Dimension d = message.getPreferredSize();
056: int height = (int) d.getHeight();
057: return new Dimension((int) d.getWidth() + 50,
058: height < 300 ? (int) super .getPreferredSize()
059: .getHeight() : 400);
060: }
061: };
062: message.setBorder(new EmptyBorder(10, 20, 10, 20));
063: scrollPane.getViewport().setBackground(Color.white);
064: JOptionPane.showMessageDialog(null, scrollPane,
065: "Product Release Information",
066: JOptionPane.INFORMATION_MESSAGE);
067: }
068:
069: private static JComponent constructMessage(ReleaseInfo[] info,
070: String[] text) {
071: Box box = new Box(BoxLayout.Y_AXIS);
072: for (int i = 0; i < info.length; i++) {
073: JLabel l = new JLabel(
074: "<html><body>"
075: + (text == null || text[i] == null ? ""
076: : text[i] + "<br>")
077: + "<table>"
078: + "<tr><td style='font-weight: bold;'>Product Name:</td><td>"
079: + info[i].getProductName()
080: + "</td></tr>"
081: + "<tr><td style='font-weight: bold;'>Version:</td><td>"
082: + info[i].getProductVersion().toString()
083: + "</td></tr>"
084: + "<tr><td style='font-weight: bold;'>Build Time:</td><td>"
085: + DATE_FORMAT.format(new Date(info[i]
086: .getBuildTime()))
087: + "</td></tr>"
088: + "<tr><td style='font-weight: bold;'>License:</td><td>"
089: + info[i].getLicense()
090: + "</td></tr>"
091: + "<tr><td style='font-weight: bold;'>Vendor:</td><td>"
092: + info[i].getProductVendor()
093: + "</td></tr>"
094: + "<tr><td style='font-weight: bold;'>Homepage:</td><td>"
095: + info[i].getHomepage() + "</td></tr>"
096: + "</table></body></html>");
097: l.setFont(l.getFont().deriveFont(Font.PLAIN));
098: l.setBorder(new CompoundBorder(new EmptyBorder(0, 0,
099: i == info.length - 1 ? 0 : 10, 0),
100: new TitledBorder(" " + info[i].getProductName()
101: + " ")));
102: box.add(l);
103: }
104: return box;
105: }
106: }
|