001: package org.dbbrowser.ui;
002:
003: import infrastructure.internationalization.InternationalizationManager;
004: import infrastructure.propertymanager.PropertyManager;
005: import infrastructure.logging.Log;
006: import javax.swing.*;
007: import java.awt.event.ActionListener;
008: import java.awt.event.ActionEvent;
009: import java.awt.*;
010: import java.util.List;
011: import java.util.ArrayList;
012: import org.dbbrowser.ui.widget.Button;
013: import org.dbbrowser.ui.panel.ButtonsPanel;
014: import org.dbbrowser.util.MailException;
015: import org.dbbrowser.util.MailManager;
016:
017: /**
018: * A window which can be used by the user to enter commnets/feedback. The user click on send to send the comment/feedback
019: */
020: public class CommentsFeedbackWindow implements ActionListener {
021: private static final String COMMENTS_FEEDBACK_ICON_FILENAME = PropertyManager
022: .getInstance()
023: .getProperty(
024: "dbbrowser-ui-dbbrowser-window-help-comments-feedback-menu-icon");
025:
026: private static final String COMMENTS_FEEDBACK_WINDOW_TITLE = InternationalizationManager
027: .getInstance()
028: .getMessage(
029: "dbbrowser-ui",
030: "dbbrowser-ui-dbbrowser-window-help-menu-comments-feedback-label",
031: null);
032: private static final String MESSAGE_NOT_SENT_ERROR_MESSAGE = InternationalizationManager
033: .getInstance()
034: .getMessage(
035: "dbbrowser-ui",
036: "dbbrowser-ui-comments-feedback-window-message-not-sent-label",
037: null);
038: private static final String COMMENTS_NOT_ENTERED_ERROR_MESSAGE = InternationalizationManager
039: .getInstance()
040: .getMessage(
041: "dbbrowser-ui",
042: "dbbrowser-ui-comments-feedback-window-comments-is-mandatory-in-comment-feedback-label",
043: null);
044: private static final String DESTINATION_ADDRESS_LABEL = InternationalizationManager
045: .getInstance()
046: .getMessage(
047: "dbbrowser-ui",
048: "dbbrowser-ui-comments-feedback-window-destination-email-label",
049: null);
050: private static final String EMAIL_ADDRESS_LABEL = InternationalizationManager
051: .getInstance()
052: .getMessage(
053: "dbbrowser-ui",
054: "dbbrowser-ui-comments-feedback-window-email-address-label",
055: null);
056: private static final String SUBJECT_LABEL = InternationalizationManager
057: .getInstance()
058: .getMessage(
059: "dbbrowser-ui",
060: "dbbrowser-ui-comments-feedback-window-subject-label",
061: null);
062: private static final String COMMENTS_FEEDBACK_LABEL = InternationalizationManager
063: .getInstance()
064: .getMessage(
065: "dbbrowser-ui",
066: "dbbrowser-ui-comments-feedback-window-comments-feedback-label",
067: null);
068: private static final String SEND_BUTTON_LABEL = InternationalizationManager
069: .getInstance()
070: .getMessage(
071: "dbbrowser-ui",
072: "dbbrowser-ui-comments-feedback-window-send-button-label",
073: null);
074:
075: private JFrame frame = new JFrame();
076: private JTextField textFieldForDestinationEmailAddress = null;
077: private JTextField textFieldForEmailAddress = null;
078: private JTextField textFieldForSubject = null;
079: private JTextArea textAreaForCommentsFeedback = null;
080:
081: /**
082: * Constructer
083: */
084: public CommentsFeedbackWindow() {
085: initialize();
086: }
087:
088: /**
089: * Show the UI
090: */
091: public void show() {
092: this .frame.show();
093: }
094:
095: public void actionPerformed(ActionEvent e) {
096: //Get the values entered by the user
097: String sendersEmailAddress = this .textFieldForEmailAddress
098: .getText();
099: String subject = this .textFieldForSubject.getText();
100: String comments = this .textAreaForCommentsFeedback.getText();
101:
102: //Only comments is mandatory
103: if ((comments != null) && (!"".equals(comments))) {
104: try {
105: Log.getInstance().debugMessage(
106: "Trying to send email...",
107: this .getClass().getName());
108: MailManager.sendEmail(sendersEmailAddress, subject,
109: comments);
110: Log.getInstance().debugMessage("Message sent",
111: this .getClass().getName());
112: this .frame.pack();
113: this .frame.dispose();
114: this .frame = null;
115: } catch (MailException exc) {
116: Log.getInstance().fatalMessage(
117: "Message not sent - " + exc.getMessage(),
118: this .getClass().getName());
119: JOptionPane.showMessageDialog(null,
120: MESSAGE_NOT_SENT_ERROR_MESSAGE + " - "
121: + exc.getMessage(),
122: COMMENTS_FEEDBACK_WINDOW_TITLE,
123: JOptionPane.ERROR_MESSAGE);
124: }
125: } else {
126: JOptionPane.showMessageDialog(null,
127: COMMENTS_NOT_ENTERED_ERROR_MESSAGE,
128: COMMENTS_FEEDBACK_WINDOW_TITLE,
129: JOptionPane.ERROR_MESSAGE);
130: }
131: }
132:
133: private void initialize() {
134: this .frame.setTitle(COMMENTS_FEEDBACK_WINDOW_TITLE);
135: this .frame.setSize(600, 400);
136: this .frame.setLocationRelativeTo(null);
137: this .frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
138: this .frame.setIconImage((new ImageIcon(
139: COMMENTS_FEEDBACK_ICON_FILENAME)).getImage());
140:
141: //Setup the widgets
142: JLabel labelForDestinationEmailAddress = new JLabel(
143: DESTINATION_ADDRESS_LABEL);
144: textFieldForDestinationEmailAddress = new JTextField(
145: "DBBrowser");
146: textFieldForDestinationEmailAddress.setEditable(false);
147: JLabel labelForEmailAddress = new JLabel(EMAIL_ADDRESS_LABEL);
148: textFieldForEmailAddress = new JTextField();
149: JLabel labelForSubject = new JLabel(SUBJECT_LABEL);
150: textFieldForSubject = new JTextField();
151: textAreaForCommentsFeedback = new JTextArea();
152:
153: //Add widgets to the panel
154: JPanel p = new JPanel(new GridLayout(3, 2));
155: p.add(labelForDestinationEmailAddress);
156: p.add(textFieldForDestinationEmailAddress);
157: p.add(labelForEmailAddress);
158: p.add(textFieldForEmailAddress);
159: p.add(labelForSubject);
160: p.add(textFieldForSubject);
161:
162: this .frame.getContentPane().setLayout(
163: new BoxLayout(this .frame.getContentPane(),
164: BoxLayout.PAGE_AXIS));
165: this .frame.getContentPane().add(p);
166:
167: JPanel panelForComments = new JPanel();
168: panelForComments.setPreferredSize(new Dimension(
169: panelForComments.getMinimumSize().width, 600));
170: panelForComments.setLayout(new BoxLayout(panelForComments,
171: BoxLayout.PAGE_AXIS));
172: this .textAreaForCommentsFeedback.setLineWrap(true);
173: JScrollPane paneForCommentsFeedback = new JScrollPane(
174: this .textAreaForCommentsFeedback);
175: paneForCommentsFeedback
176: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
177: panelForComments.add(paneForCommentsFeedback);
178: panelForComments.setBorder(BorderFactory
179: .createTitledBorder(COMMENTS_FEEDBACK_LABEL));
180: this .frame.getContentPane().add(panelForComments);
181:
182: Button buttonToSendMessage = new Button(SEND_BUTTON_LABEL,
183: this , SEND_BUTTON_LABEL, new ImageIcon(
184: COMMENTS_FEEDBACK_ICON_FILENAME), Boolean.TRUE);
185: List listOfButtons = new ArrayList();
186: listOfButtons.add(buttonToSendMessage);
187: ButtonsPanel buttonsPanel = new ButtonsPanel(listOfButtons);
188: this.frame.getContentPane().add(buttonsPanel);
189: }
190: }
|