001: package org.dbbrowser.ui;
002:
003: import infrastructure.internationalization.InternationalizationManager;
004: import infrastructure.propertymanager.PropertyManager;
005: import javax.swing.*;
006: import java.awt.*;
007: import java.awt.event.ActionListener;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ItemListener;
010: import java.awt.event.ItemEvent;
011: import java.util.List;
012: import java.util.ArrayList;
013: import java.io.BufferedReader;
014: import java.io.FileReader;
015: import java.io.FileNotFoundException;
016: import java.io.IOException;
017: import org.dbbrowser.ui.widget.Button;
018: import org.dbbrowser.ui.panel.ButtonsPanel;
019:
020: public class FirstRunMessageDialog implements ActionListener,
021: ItemListener {
022: private static final long serialVersionUID = UIControllerForQueries.version;
023:
024: private static final String TITLE = InternationalizationManager
025: .getInstance().getMessage("dbbrowser-ui",
026: "dbbrowser-ui-dbbrowser-window-title-label", null);;
027: private static final String OK_BUTTON_LABEL = InternationalizationManager
028: .getInstance()
029: .getMessage(
030: "dbbrowser-ui",
031: "dbbrowser-ui-first-run-message-dialog-ok-button-label",
032: null);;
033: private String OK_BUTTON_ICON_FILE_NAME = PropertyManager
034: .getInstance()
035: .getProperty(
036: "dbbrowser-ui-view-record-window-update-record-icon");
037:
038: private JDialog dialog = null;
039: private ButtonsPanel buttonPanel = null;
040: private JPanel mainPanel = new JPanel();
041:
042: public FirstRunMessageDialog() {
043: initialize();
044: }
045:
046: public void show() {
047: this .dialog.setVisible(true);
048: }
049:
050: public void actionPerformed(ActionEvent e) {
051: //Close the message dialog
052: this .dialog.pack();
053: this .dialog.setVisible(false);
054: this .dialog = null;
055: }
056:
057: private void initialize() {
058: //Set null layout manager
059: mainPanel.setLayout(null);
060:
061: //Add the title
062: String firstRunMessageTitle = InternationalizationManager
063: .getInstance().getMessage("dbbrowser-ui",
064: "dbbrowser-ui-first-run-message-dialog-title",
065: null);
066: JLabel firstRunMessageTitleLabel = new JLabel(
067: firstRunMessageTitle);
068: firstRunMessageTitleLabel.setForeground(Color.RED);
069: firstRunMessageTitleLabel.setBorder(BorderFactory
070: .createEtchedBorder());
071: firstRunMessageTitleLabel
072: .setHorizontalAlignment(SwingConstants.CENTER);
073: firstRunMessageTitleLabel.setBounds(0, 0, 600, 30);
074: mainPanel.add(firstRunMessageTitleLabel);
075:
076: //Setup the text area and the scrollpane
077: //Read the first run file and show it in the text area
078: String messageFileName = PropertyManager.getInstance()
079: .getProperty("dbbrowser-first-run-message-filename");
080: JTextPane editorPanel = null;
081: try {
082: BufferedReader reader = new BufferedReader(new FileReader(
083: messageFileName));
084: StringBuffer buffer = new StringBuffer();
085: String line = reader.readLine();
086: while (line != null) {
087: buffer.append(line + "\n");
088: line = reader.readLine();
089: }
090: reader.close();
091:
092: editorPanel = new JTextPane();
093: editorPanel.setText(buffer.toString());
094: JScrollPane pane = new JScrollPane(editorPanel);
095: pane.setBounds(0, 30, 590, 250);
096: mainPanel.add(pane);
097: } catch (FileNotFoundException exc) {
098: //Cant do anything - show an error message
099: editorPanel.setText(exc.getMessage());
100: } catch (IOException exc) {
101: //Cant do anything - show an error message
102: editorPanel.setText(exc.getMessage());
103: }
104:
105: //Set the check box
106: String checkBoxLabel = InternationalizationManager
107: .getInstance()
108: .getMessage(
109: "dbbrowser-ui",
110: "dbbrowser-ui-first-run-message-dialog-check-box-label",
111: null);
112: JCheckBox checkBox = new JCheckBox(checkBoxLabel);
113: checkBox.setBounds(190, 280, 300, 30);
114: checkBox.addItemListener(this );
115: mainPanel.add(checkBox);
116:
117: //Setup the dialog
118: this .dialog = new JDialog();
119: this .dialog.setTitle(TITLE);
120: this .dialog.setModal(true);
121: this .dialog.setSize(600, 400);
122: this .dialog
123: .setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
124: this .dialog.setResizable(false);
125: this .dialog.setLocationRelativeTo(null);
126: this .dialog.getContentPane().add(mainPanel);
127: }
128:
129: public void itemStateChanged(ItemEvent e) {
130: if (e.getStateChange() == ItemEvent.DESELECTED) {
131: //Remove the buttons from the panel
132: this .mainPanel.remove(buttonPanel);
133: this .mainPanel.updateUI();
134: }
135:
136: if (e.getStateChange() == ItemEvent.SELECTED) {
137: //Add the panel for the button
138: Button okButton = new Button(OK_BUTTON_LABEL, this ,
139: OK_BUTTON_LABEL, new ImageIcon(
140: OK_BUTTON_ICON_FILE_NAME), Boolean.TRUE);
141: List listOfButtons = new ArrayList();
142: listOfButtons.add(okButton);
143: buttonPanel = new ButtonsPanel(listOfButtons);
144: buttonPanel.setBounds(0, 320, 590, 50);
145: mainPanel.add(buttonPanel);
146: this.mainPanel.updateUI();
147: }
148: }
149: }
|