001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.window.messages;
020:
021: import java.awt.*;
022: import java.util.*;
023:
024: import javax.swing.*;
025:
026: import org.openharmonise.him.actions.messages.*;
027: import org.openharmonise.him.configuration.*;
028: import org.openharmonise.swing.FontManager;
029: import org.openharmonise.vfs.gui.*;
030:
031: /**
032: * @author Matthew Large
033: *
034: */
035: public class MessageWindow extends JPanel implements MessageListener {
036:
037: private JTextPane m_textarea = null;
038:
039: private HashMap m_typeIconMap = new HashMap();
040:
041: private JTabbedPane m_tabs = null;
042:
043: public MessageWindow(JTabbedPane tabs) {
044: this .m_tabs = tabs;
045:
046: MessageHandler.getInstance().addMessageListener(this );
047:
048: this .m_typeIconMap.put(MessageHandler.TYPE_CONFIRM, IconManager
049: .getInstance().getIcon("16-message-confirm.gif"));
050: this .m_typeIconMap.put(MessageHandler.TYPE_ERROR, IconManager
051: .getInstance().getIcon("16-message-error.gif"));
052: this .m_typeIconMap.put(MessageHandler.TYPE_INFORMATION,
053: IconManager.getInstance().getIcon(
054: "16-message-information.gif"));
055:
056: // String fontName = "Dialog";
057: // int fontSize = 11;
058: // Font font = new Font(fontName, Font.PLAIN, fontSize);
059:
060: m_textarea = new JTextPane();
061: this .m_textarea.setFont(FontManager.getInstance().getFont(
062: FontManager.FONT_RESOURCE_TITLE));
063: this .m_textarea.setEditable(false);
064: this .setBackground(Color.WHITE);
065: this .setBorder(BorderFactory.createLineBorder(Color.black));
066:
067: BorderLayout layout = new BorderLayout();
068: this .setLayout(layout);
069:
070: JToolBar toolBar = new JToolBar();
071: toolBar.setFloatable(false);
072:
073: ActionSetFilters filterButton = new ActionSetFilters();
074: toolBar.add(filterButton.getButton());
075: filterButton.setEnabled(true);
076:
077: toolBar.addSeparator();
078:
079: ActionClear clearButton = new ActionClear(this );
080: toolBar.add(clearButton.getButton());
081: clearButton.setEnabled(true);
082:
083: this .add(toolBar, BorderLayout.PAGE_START);
084:
085: m_textarea.replaceSelection("\n\n");
086: //m_textarea.setFont(new Font("Arial", Font.PLAIN, 12));
087: this .m_textarea.setFont(FontManager.getInstance().getFont(
088: FontManager.FONT_RESOURCE_TITLE));
089:
090: JScrollPane scroll = new JScrollPane(m_textarea,
091: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
092: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
093:
094: this .add(scroll);
095: this .setVisible(true);
096:
097: }
098:
099: public void clear() {
100: this .m_textarea.setEditable(true);
101: this .m_textarea.setText("");
102: m_textarea.setCaretPosition(0);
103: this .m_textarea.setEditable(false);
104: }
105:
106: public void appendToMessageWindow(String sMessageType,
107: String sMessage) {
108:
109: if (sMessageType.equals(MessageHandler.TYPE_ERROR)) {
110: for (int i = 0; i < this .m_tabs.getTabCount(); i++) {
111: if (this .m_tabs.getTitleAt(i).equals("Console")) {
112: this .m_tabs.setSelectedIndex(i);
113: break;
114: }
115: }
116: }
117:
118: this .m_textarea.setEditable(true);
119: m_textarea.setCaretPosition(0);
120: m_textarea.replaceSelection("\n");
121: m_textarea.replaceSelection("\n");
122: m_textarea.setCaretPosition(0);
123: m_textarea.replaceSelection(" " + sMessage);
124: m_textarea.setCaretPosition(0);
125: appendIconToMessageWindow((Icon) this .m_typeIconMap
126: .get(sMessageType));
127:
128: this .m_textarea.setEditable(false);
129: this .validateTree();
130: this .repaint();
131: }
132:
133: public void playSound(String sMessageType) {
134: /*if( sMessageType == this.MSG_ERROR ) {
135: this.auError.play();
136:
137: }*/
138: }
139:
140: public synchronized void appendToMessageWindow(String sMessage) {
141: this .m_textarea.setEditable(true);
142: m_textarea.replaceSelection(sMessage);
143: this .m_textarea.setEditable(false);
144: }
145:
146: public synchronized void appendIconToMessageWindow(Icon icon) {
147: this .m_textarea.setEditable(true);
148: m_textarea.insertIcon(icon);
149: this .m_textarea.setEditable(false);
150: }
151:
152: /* (non-Javadoc)
153: * @see com.simulacramedia.contentmanager.window.messages.MessageListener#messageEvent(com.simulacramedia.contentmanager.window.messages.MessageEvent)
154: */
155: public void messageEvent(MessageEvent me) {
156: if (me.getType().equals(MessageHandler.TYPE_CONFIRM)) {
157: String sValue = ConfigStore.getInstance().getPropertyValue(
158: "MSG_CONFIRM_REPORT");
159: if (sValue == null || sValue.equals("TRUE")) {
160: this .appendToMessageWindow(me.getType(), me
161: .getMessage());
162: }
163: } else if (me.getType().equals(MessageHandler.TYPE_INFORMATION)) {
164: String sValue = ConfigStore.getInstance().getPropertyValue(
165: "MSG_INFORMATION_REPORT");
166: if (sValue == null || sValue.equals("TRUE")) {
167: this .appendToMessageWindow(me.getType(), me
168: .getMessage());
169: }
170: } else if (me.getType().equals(MessageHandler.TYPE_ERROR)) {
171: String sValue = ConfigStore.getInstance().getPropertyValue(
172: "MSG_ERROR_REPORT");
173: if (sValue == null || sValue.equals("TRUE")) {
174: this.appendToMessageWindow(me.getType(), me
175: .getMessage());
176: }
177: }
178:
179: }
180:
181: }
|