KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > messages > MessageWindow


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.messages;
20
21 import java.awt.*;
22 import java.util.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.him.actions.messages.*;
27 import org.openharmonise.him.configuration.*;
28 import org.openharmonise.swing.FontManager;
29 import org.openharmonise.vfs.gui.*;
30
31
32 /**
33  * @author Matthew Large
34  *
35  */

36 public class MessageWindow extends JPanel implements MessageListener {
37     
38     private JTextPane m_textarea = null;
39     
40     private HashMap m_typeIconMap = new HashMap();
41     
42     private JTabbedPane m_tabs = null;
43     
44     public MessageWindow(JTabbedPane tabs) {
45         this.m_tabs = tabs;
46         
47         MessageHandler.getInstance().addMessageListener(this);
48         
49         this.m_typeIconMap.put(MessageHandler.TYPE_CONFIRM, IconManager.getInstance().getIcon("16-message-confirm.gif"));
50         this.m_typeIconMap.put(MessageHandler.TYPE_ERROR, IconManager.getInstance().getIcon("16-message-error.gif"));
51         this.m_typeIconMap.put(MessageHandler.TYPE_INFORMATION, IconManager.getInstance().getIcon("16-message-information.gif"));
52
53 // String fontName = "Dialog";
54
// int fontSize = 11;
55
// Font font = new Font(fontName, Font.PLAIN, fontSize);
56

57         m_textarea = new JTextPane();
58         this.m_textarea.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) );
59         this.m_textarea.setEditable(false);
60         this.setBackground(Color.WHITE);
61         this.setBorder(BorderFactory.createLineBorder(Color.black));
62
63         BorderLayout layout = new BorderLayout();
64         this.setLayout(layout);
65         
66         JToolBar toolBar = new JToolBar();
67         toolBar.setFloatable(false);
68
69         ActionSetFilters filterButton = new ActionSetFilters();
70         toolBar.add(filterButton.getButton());
71         filterButton.setEnabled(true);
72         
73         toolBar.addSeparator();
74
75         ActionClear clearButton = new ActionClear(this);
76         toolBar.add(clearButton.getButton());
77         clearButton.setEnabled(true);
78         
79         this.add(toolBar, BorderLayout.PAGE_START);
80         
81         m_textarea.replaceSelection("\n\n");
82         //m_textarea.setFont(new Font("Arial", Font.PLAIN, 12));
83
this.m_textarea.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) );
84         
85         JScrollPane scroll = new JScrollPane(m_textarea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
86         
87         this.add(scroll);
88         this.setVisible(true);
89         
90     }
91     
92     public void clear() {
93         this.m_textarea.setEditable(true);
94         this.m_textarea.setText("");
95         m_textarea.setCaretPosition(0);
96         this.m_textarea.setEditable(false);
97     }
98
99     public void appendToMessageWindow(String JavaDoc sMessageType, String JavaDoc sMessage) {
100
101         if(sMessageType.equals(MessageHandler.TYPE_ERROR)) {
102             for(int i=0; i<this.m_tabs.getTabCount(); i++) {
103                 if(this.m_tabs.getTitleAt(i).equals("Console")) {
104                     this.m_tabs.setSelectedIndex(i);
105                     break;
106                 }
107             }
108         }
109
110         this.m_textarea.setEditable(true);
111         m_textarea.setCaretPosition(0);
112         m_textarea.replaceSelection("\n");
113         m_textarea.replaceSelection("\n");
114         m_textarea.setCaretPosition(0);
115         m_textarea.replaceSelection(" " + sMessage);
116         m_textarea.setCaretPosition(0);
117         appendIconToMessageWindow( (Icon) this.m_typeIconMap.get(sMessageType) );
118
119         this.m_textarea.setEditable(false);
120         this.validateTree();
121         this.repaint();
122     }
123
124     public void playSound(String JavaDoc sMessageType) {
125         /*if( sMessageType == this.MSG_ERROR ) {
126           this.auError.play();
127
128         }*/

129     }
130
131     public synchronized void appendToMessageWindow(String JavaDoc sMessage) {
132         this.m_textarea.setEditable(true);
133         m_textarea.replaceSelection(sMessage);
134         this.m_textarea.setEditable(false);
135     }
136
137     public synchronized void appendIconToMessageWindow(Icon icon) {
138         this.m_textarea.setEditable(true);
139       m_textarea.insertIcon(icon);
140       this.m_textarea.setEditable(false);
141     }
142
143     /* (non-Javadoc)
144      * @see com.simulacramedia.contentmanager.window.messages.MessageListener#messageEvent(com.simulacramedia.contentmanager.window.messages.MessageEvent)
145      */

146     public void messageEvent(MessageEvent me) {
147         if(me.getType().equals(MessageHandler.TYPE_CONFIRM)) {
148             String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("MSG_CONFIRM_REPORT");
149             if(sValue==null || sValue.equals("TRUE")) {
150                 this.appendToMessageWindow(me.getType(), me.getMessage());
151             }
152         } else if(me.getType().equals(MessageHandler.TYPE_INFORMATION)) {
153             String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("MSG_INFORMATION_REPORT");
154             if(sValue==null || sValue.equals("TRUE")) {
155                 this.appendToMessageWindow(me.getType(), me.getMessage());
156             }
157         } else if(me.getType().equals(MessageHandler.TYPE_ERROR)) {
158             String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("MSG_ERROR_REPORT");
159             if(sValue==null || sValue.equals("TRUE")) {
160                 this.appendToMessageWindow(me.getType(), me.getMessage());
161             }
162         }
163         
164     }
165
166 }
167
Popular Tags