KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > planetamessenger > mos > forms > JMOSSendMessageDlg


1 /*
2     =========================================================================
3     Package forms - Implements the user interface MOS module
4
5     This module is developed and maintained by PlanetaMessenger.org.
6     Specs, New and updated versions can be found in
7     http://www.planetamessenger.org
8     If you want contact the Team please send a email to Project Manager
9     Leidson Campos Alves Ferreira at leidson@planetamessenger.org
10
11     Copyright (C) since 2001 by PlanetaMessenger.org
12
13     This program is free software; you can redistribute it and/or modify
14     it under the terms of the GNU General Public License as published by
15     the Free Software Foundation; either version 2 of the License, or
16     (at your option) any later version.
17
18     This program is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21     GNU General Public License for more details.
22
23     You should have received a copy of the GNU General Public License
24     along with this program; if not, write to the Free Software
25     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27     =========================================================================
28 */

29 /**
30  *
31  * $Id: JMOSSendMessageDlg.java,v 1.20 2007/01/28 17:39:20 popolony2k Exp $
32  * $Author: popolony2k $
33  * $Name: $
34  * $Revision: 1.20 $
35  * $State: Exp $
36  *
37  */

38
39 package org.planetamessenger.mos.forms;
40
41 import org.planetamessenger.mos.ui.*;
42 import org.planetamessenger.mos.engine.*;
43 import org.planetamessenger.plugin.*;
44 import javax.swing.*;
45
46
47 public class JMOSSendMessageDlg extends javax.swing.JFrame JavaDoc {
48
49   final int DEFAULT_WIDTH = 430;
50   final int DEFAULT_HEIGHT = 300;
51   JMessagePane messageTabs = null;
52   JButton sendButton = null;
53   JButton closeButton = null;
54   JButton closeTabButton = null;
55
56   
57
58   /**
59    * Create the SendMessage dialog object.
60    * @param bModal Flag for modal style;
61    */

62   public JMOSSendMessageDlg() {
63     
64     super();
65     initComponents();
66   }
67
68   /**
69    * Initializes all components from this
70    * window.
71    */

72   private void initComponents() {
73
74     java.awt.GridBagConstraints JavaDoc constraints = new java.awt.GridBagConstraints JavaDoc();
75     Box btnsPanel = Box.createHorizontalBox();
76
77     
78     messageTabs = new JMessagePane( this );
79     sendButton = new JButton();
80     closeButton = new JButton();
81     closeTabButton = new JButton();
82     
83     getContentPane().setLayout( new java.awt.GridBagLayout JavaDoc() );
84     setName( "SendMessageDialog" );
85     setResizable( true );
86         
87     addWindowListener( new java.awt.event.WindowAdapter JavaDoc() {
88       public void windowClosing( java.awt.event.WindowEvent JavaDoc evt ) {
89         closeDialog( evt );
90       }
91     } );
92
93     constraints.gridx = 0;
94     constraints.gridy = 0;
95     //constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
96
constraints.gridwidth = 1;
97     constraints.gridheight = 1;
98     constraints.weightx = 1.0;
99     constraints.weighty = 1.0;
100     constraints.fill = java.awt.GridBagConstraints.BOTH;
101     constraints.insets = new java.awt.Insets JavaDoc( 1, 8, 1, 1 );
102
103     messageTabs.setPreferredSize( new java.awt.Dimension JavaDoc( 350, 150 ) );
104     messageTabs.setFont( JSystemFonts.FONT );
105     getContentPane().add( messageTabs, constraints );
106     
107     //CloseTab button
108
constraints.gridx = 1;
109     constraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
110     constraints.fill = java.awt.GridBagConstraints.NONE;
111     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
112     constraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
113     constraints.insets = new java.awt.Insets JavaDoc( 1, 1, 1, 1 );
114     constraints.weightx = 0.0;
115     constraints.weighty = 0.0;
116     
117     closeTabButton.setFont( JSystemFonts.FONT );
118     closeTabButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_TAB_ICON ) );
119     closeTabButton.setEnabled( true );
120     closeTabButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.BUTTON_WIDTH_16, JResources.BUTTON_HEIGHT_16 ) );
121     closeTabButton.setMinimumSize( new java.awt.Dimension JavaDoc( JResources.BUTTON_WIDTH_16, JResources.BUTTON_HEIGHT_16 ) );
122     getContentPane().add( closeTabButton, constraints );
123
124     // Ok Button
125
sendButton.setFont( JSystemFonts.FONT );
126     sendButton.setIcon( JSharedObjects.getResources().getIcon( JResources.SEND_IM_ICON ) );
127     sendButton.setEnabled( false );
128     sendButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
129
130     // Close button
131
closeButton.setFont( JSystemFonts.FONT );
132     closeButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) );
133     closeButton.setPreferredSize( new java.awt.Dimension JavaDoc( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) );
134     
135     btnsPanel.add( javax.swing.Box.createHorizontalGlue() );
136     btnsPanel.add( closeButton );
137     btnsPanel.add( sendButton );
138     
139     constraints.gridy++;
140     constraints.gridx = 0;
141     constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142     constraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
143     constraints.weighty = 0.01;
144     
145     getContentPane().add( btnsPanel, constraints );
146     
147     // Add the listeners to send, close tab and close buttons
148
sendButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
149       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
150         sendButtonActionPerformed( evt );
151       }
152     } );
153
154     closeButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
155       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
156         closeButtonActionPerformed( evt );
157       }
158     } );
159     
160     closeTabButton.addActionListener( new java.awt.event.ActionListener JavaDoc() {
161       public void actionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
162         closeTabButtonActionPerformed( evt );
163       }
164     } );
165
166     updateLanguage();
167     
168     // Sets the initial dialog position
169
java.awt.Dimension JavaDoc screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
170     setSize( new java.awt.Dimension JavaDoc( DEFAULT_WIDTH, DEFAULT_HEIGHT ) );
171     setLocation( ( screenSize.width - getSize().width ) / 2, ( screenSize.height - getSize().height ) / 2 );
172     setIconImage( JSharedObjects.getResources().getIcon( JResources.APPLICATION_ICON ).getImage() );
173   }
174
175   /**
176    * Implements the onClick event of
177    * Send button.
178    * @param evt The button event object;
179    */

180   private void sendButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
181
182     JTabContent tabContent = messageTabs.getActiveItem();
183     
184     System.err.println( "JSendMessageDlg.sendButtonActionPerformed(" + tabContent.ownerItem.getUserId() + ") - triggered" );
185     
186     if( JSharedObjects.getPluginEngine().onSendMessage( tabContent.ownerItem, tabContent.messageEdit.getText() ) )
187       tabContent.addHistoryText();
188   }
189
190   /**
191    * Implements the onClick event of
192    * Cancel button.
193    * @param evt The button event object;
194    */

195   private void closeButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
196     
197     closeDialog( null );
198   }
199   
200   /**
201    * Implements the onClick event of Close Tab button.
202    * Close the current opened tab or the current dialog if there only one
203    * opened tab.
204    * @param evt The button event object;
205    */

206   private void closeTabButtonActionPerformed( java.awt.event.ActionEvent JavaDoc evt ) {
207
208     messageTabs.removeSelectedTab();
209   }
210
211   /**
212    * Implements the closeDialog event
213    * handler.
214    * @param evt The close window event object;
215    */

216   private void closeDialog( java.awt.event.WindowEvent JavaDoc evt ) {
217    
218     dispose();
219     messageTabs.removeAll();
220   }
221   
222   /**
223    * Update the language for all contact list items.
224    */

225   void updateLanguage() {
226
227     sendButton.setText( JSharedObjects.getLanguageManager().getStringEx( "SEND" ) );
228     closeButton.setText( JSharedObjects.getLanguageManager().getStringEx( "CLOSE" ) );
229     closeTabButton.setToolTipText( JSharedObjects.getLanguageManager().getStringEx( "CLOSE_TAB" ) );
230   }
231
232   /**
233    * Create a new tab into MessageDlg.
234    * @param ownerItem The owner item of the tab created;
235    */

236   public void newTab( JContactListItem ownerItem ) {
237
238     if( !isItemActive( ownerItem ) )
239       messageTabs.addTab( ownerItem );
240   }
241   
242   /**
243    * Set the message to this message dialog.
244    * @param item The contact that sent this message;
245    * @param strMsg The message that will
246    * be added into dialog;
247    */

248   public void setMessage( JContactListItem item, java.lang.String JavaDoc strMsg ) {
249
250     messageTabs.setText( item, strMsg );
251   }
252   
253   /**
254    * Check if Tab contain a specified item.
255    * @param item The item to check;
256    */

257   public boolean contains( JContactListItem item ) {
258     
259     return ( messageTabs.contains( item ) && isVisible() );
260   }
261   
262   /**
263    * Check if item is the active tab
264    * @param item The item to check;
265    */

266    public boolean isItemActive( JContactListItem item ) {
267    
268      return ( messageTabs.isItemActive( item ) && isVisible() );
269    }
270    
271    /**
272     * Returns the sendButton reference.
273     */

274    public javax.swing.JButton JavaDoc getSendButton() {
275
276      return sendButton;
277    }
278    
279    /**
280     * Returns the JMessagePane object.
281     */

282    public JMessagePane getTabbedMessagePane() {
283      
284      return messageTabs;
285    }
286 }
287
288 // JMOSSendMessageDlg class
Popular Tags