01: package net.sourceforge.squirrel_sql.client.gui;
02:
03: /*
04: * Copyright (C) 2006 Rob Manning
05: * manningr@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import javax.swing.JTextPane;
22: import javax.swing.text.SimpleAttributeSet;
23: import javax.swing.text.StyleConstants;
24: import javax.swing.text.StyledDocument;
25:
26: import net.sourceforge.squirrel_sql.client.Version;
27: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
28: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
29:
30: /**
31: * A class that encapsulates the work of rendering the version and copyright.
32: * This is used in both the splash screen and the about dialog.
33: */
34: public class VersionPane extends JTextPane {
35:
36: private boolean _showWebsite = false;
37:
38: /** Logger for this class. */
39: private final static ILogger s_log = LoggerController
40: .createLogger(VersionPane.class);
41:
42: /**
43: * Constructor
44: * @param showWebsite whether or not to display the website. This is done
45: * in the about dialog but not in the splash screen.
46: */
47: public VersionPane(boolean showWebsite) {
48: _showWebsite = showWebsite;
49: init();
50: }
51:
52: /**
53: * Renders the content.
54: */
55: private void init() {
56: String content = getContent();
57: StyledDocument doc = getStyledDocument();
58: SimpleAttributeSet s = new SimpleAttributeSet();
59: StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);
60: StyleConstants.setBold(s, true);
61:
62: try {
63: doc.setParagraphAttributes(0, content.length(), s, false);
64: doc.insertString(0, content, s);
65: } catch (Exception e) {
66: s_log.error("init: Unexpected exception " + e.getMessage());
67: }
68: setOpaque(false);
69: }
70:
71: /**
72: * Constructs the text that gets rendered.
73: *
74: * @return version and copyright info ( and possibly website url )
75: */
76: private String getContent() {
77: StringBuffer text = new StringBuffer();
78: text.append(Version.getVersion());
79: text.append("\n");
80: text.append(Version.getCopyrightStatement());
81: if (_showWebsite) {
82: text.append("\n");
83: text.append(Version.getWebSite());
84: }
85: return text.toString();
86: }
87: }
|