001: package org.dbbrowser.ui;
002:
003: import infrastructure.internationalization.InternationalizationManager;
004: import infrastructure.propertymanager.PropertyManager;
005: import java.awt.event.ActionEvent;
006: import java.awt.event.ActionListener;
007: import java.util.ArrayList;
008: import java.util.List;
009: import java.io.BufferedReader;
010: import java.io.FileReader;
011: import java.io.FileNotFoundException;
012: import java.io.IOException;
013: import org.dbbrowser.ui.panel.ButtonsPanel;
014: import org.dbbrowser.ui.widget.Button;
015: import javax.swing.*;
016:
017: public class AboutWindow implements ActionListener {
018: private static final long serialVersionUID = UIControllerForQueries.version;
019:
020: private static final String TITLE = InternationalizationManager
021: .getInstance().getMessage("dbbrowser-ui",
022: "dbbrowser-ui-dbbrowser-window-title-label", null);;
023:
024: private String ABOUT_TAB_LABEL = InternationalizationManager
025: .getInstance().getMessage("dbbrowser-ui",
026: "dbbrowser-ui-about-window-tab-label", null);
027: private String CREDITS_TAB_LABEL = InternationalizationManager
028: .getInstance().getMessage("dbbrowser-ui",
029: "dbbrowser-ui-credits-window-tab-label", null);
030: private String LICENSE_LABEL = InternationalizationManager
031: .getInstance().getMessage("dbbrowser-ui",
032: "dbbrowser-ui-license-window-tab-label", null);
033: private String CONTRIBUTORS_LABEL = InternationalizationManager
034: .getInstance().getMessage("dbbrowser-ui",
035: "dbbrowser-ui-contributors-window-tab-label", null);
036: private String OK_BUTTON_LABEL = InternationalizationManager
037: .getInstance()
038: .getMessage("dbbrowser-ui",
039: "dbbrowser-ui-license-window-ok-button-label", null);
040:
041: private String README_FILE_NAME = PropertyManager.getInstance()
042: .getProperty("dbbrowser-ui-about-window-readme-filename");
043: private String CREDITS_FILE_NAME = PropertyManager.getInstance()
044: .getProperty("dbbrowser-ui-about-window-credits-filename");
045: private String LICENSE_FILE_NAME = PropertyManager.getInstance()
046: .getProperty("dbbrowser-ui-about-window-license-filename");
047: private String CONTRIBUTORS_FILE_NAME = PropertyManager
048: .getInstance().getProperty(
049: "dbbrowser-ui-about-window-contributors-filename");
050:
051: private String ABOUT_TAB_ICON_FILE_NAME = PropertyManager
052: .getInstance().getProperty(
053: "dbbrowser-ui-about-window-about-tab-icon");
054: private String CREDITS_TAB_ICON_FILE_NAME = PropertyManager
055: .getInstance().getProperty(
056: "dbbrowser-ui-about-window-credits-tab-icon");
057: private String LICENSE_TAB_ICON_FILE_NAME = PropertyManager
058: .getInstance().getProperty(
059: "dbbrowser-ui-about-window-license-tab-icon");
060: private String CONTRIBUTORS_TAB_ICON_FILE_NAME = PropertyManager
061: .getInstance().getProperty(
062: "dbbrowser-ui-about-window-contributors-tab-icon");
063:
064: private String OK_BUTTON_ICON_FILE_NAME = PropertyManager
065: .getInstance()
066: .getProperty(
067: "dbbrowser-ui-view-record-window-update-record-icon");
068:
069: private JPanel mainPanel = new JPanel();
070: private JDialog dialog = null;
071: private JTextArea textAreaForData = null;
072: private JScrollPane panelForScrollPane = null;
073: private ButtonsPanel navigationButonsPanel = null;
074: private JTabbedPane tabbedPane = new JTabbedPane();
075:
076: public AboutWindow() {
077: initialize();
078: }
079:
080: public void show() {
081: this .dialog.setVisible(true);
082: }
083:
084: public void actionPerformed(ActionEvent e) {
085: this .dialog.pack();
086: this .dialog.dispose();
087: this .dialog = null;
088: }
089:
090: private void initialize() {
091: //Setup the tabbed pane
092: String dbbrowserReadmeFileContents = this
093: .readFromFile(README_FILE_NAME);
094: this .textAreaForData = new JTextArea(
095: dbbrowserReadmeFileContents);
096: this .textAreaForData.setLineWrap(true);
097: this .textAreaForData.setWrapStyleWord(true);
098: this .panelForScrollPane = new JScrollPane(textAreaForData);
099: this .tabbedPane.addTab(ABOUT_TAB_LABEL, new ImageIcon(
100: ABOUT_TAB_ICON_FILE_NAME), this .panelForScrollPane);
101:
102: String creditsFileContents = this
103: .readFromFile(CREDITS_FILE_NAME);
104: this .textAreaForData = new JTextArea(creditsFileContents);
105: this .textAreaForData.setLineWrap(true);
106: this .textAreaForData.setWrapStyleWord(true);
107: this .panelForScrollPane = new JScrollPane(textAreaForData);
108: this .tabbedPane.addTab(CREDITS_TAB_LABEL, new ImageIcon(
109: CREDITS_TAB_ICON_FILE_NAME), this .panelForScrollPane);
110:
111: String licenseFileContents = this
112: .readFromFile(LICENSE_FILE_NAME);
113: this .textAreaForData = new JTextArea(licenseFileContents);
114: this .textAreaForData.setLineWrap(true);
115: this .textAreaForData.setWrapStyleWord(true);
116: this .panelForScrollPane = new JScrollPane(textAreaForData);
117: this .tabbedPane.addTab(LICENSE_LABEL, new ImageIcon(
118: LICENSE_TAB_ICON_FILE_NAME), this .panelForScrollPane);
119:
120: //Contributors tab
121: String contributorsFileContents = this
122: .readFromFile(CONTRIBUTORS_FILE_NAME);
123: this .textAreaForData = new JTextArea(contributorsFileContents);
124: this .textAreaForData.setLineWrap(true);
125: this .textAreaForData.setWrapStyleWord(true);
126: this .panelForScrollPane = new JScrollPane(textAreaForData);
127: this .tabbedPane.addTab(CONTRIBUTORS_LABEL, new ImageIcon(
128: CONTRIBUTORS_TAB_ICON_FILE_NAME),
129: this .panelForScrollPane);
130:
131: //Setup the main panel
132: this .mainPanel.setLayout(new BoxLayout(this .mainPanel,
133: BoxLayout.PAGE_AXIS));
134: this .mainPanel.add(this .tabbedPane);
135:
136: //Build the list of buttons for the navigation buttons panel
137: List listOfNavigationButtons = new ArrayList();
138: Button okButton = new Button(OK_BUTTON_LABEL, this ,
139: OK_BUTTON_LABEL,
140: new ImageIcon(OK_BUTTON_ICON_FILE_NAME), Boolean.FALSE);
141: listOfNavigationButtons.add(okButton);
142:
143: //Setup the navigation panel
144: navigationButonsPanel = new ButtonsPanel(
145: listOfNavigationButtons);
146: this .mainPanel.add(navigationButonsPanel);
147:
148: //Setup the frame
149: this .dialog = new JDialog();
150: this .dialog.setTitle(TITLE);
151: this .dialog.setModal(true);
152: this .dialog.setSize(600, 400);
153: this .dialog.setLocationRelativeTo(null);
154: this .dialog.getContentPane().add(this .mainPanel);
155: }
156:
157: private String readFromFile(String filename) {
158: String fileContents = "";
159: StringBuffer buffer = new StringBuffer();
160: try {
161: BufferedReader reader = new BufferedReader(new FileReader(
162: filename));
163: String line = reader.readLine();
164: while (line != null) {
165: buffer.append(line + "\n");
166: line = reader.readLine();
167: }
168: reader.close();
169: fileContents = buffer.toString();
170: } catch (FileNotFoundException exc) {
171: //Cant do anything - show an error message
172: fileContents = exc.getMessage();
173: } catch (IOException exc) {
174: //Cant do anything - show an error message
175: fileContents = exc.getMessage();
176: }
177: return fileContents;
178: }
179: }
|