Added facility for setting whether the chat text entry field should
request keyboard focus. Expanded imports. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@778 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,21 +1,38 @@
|
|||||||
//
|
//
|
||||||
// $Id: ChatPanel.java,v 1.7 2001/10/18 23:55:37 mdb Exp $
|
// $Id: ChatPanel.java,v 1.8 2001/12/14 04:33:53 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.micasa.client;
|
package com.threerings.micasa.client;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.text.*;
|
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import com.samskivert.swing.*;
|
import javax.swing.JButton;
|
||||||
import com.threerings.crowd.chat.*;
|
import javax.swing.JComboBox;
|
||||||
import com.threerings.crowd.client.*;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JTextPane;
|
||||||
|
import javax.swing.event.AncestorEvent;
|
||||||
|
import javax.swing.event.AncestorListener;
|
||||||
|
import javax.swing.text.BadLocationException;
|
||||||
|
import javax.swing.text.Document;
|
||||||
|
import javax.swing.text.Style;
|
||||||
|
import javax.swing.text.StyleConstants;
|
||||||
|
import javax.swing.text.StyleContext;
|
||||||
|
|
||||||
|
import com.samskivert.swing.GroupLayout;
|
||||||
|
import com.samskivert.swing.HGroupLayout;
|
||||||
|
import com.samskivert.swing.VGroupLayout;
|
||||||
|
|
||||||
|
import com.threerings.crowd.chat.ChatCodes;
|
||||||
|
import com.threerings.crowd.chat.ChatDirector;
|
||||||
|
import com.threerings.crowd.chat.ChatDisplay;
|
||||||
|
import com.threerings.crowd.client.OccupantObserver;
|
||||||
|
import com.threerings.crowd.client.PlaceView;
|
||||||
import com.threerings.crowd.data.OccupantInfo;
|
import com.threerings.crowd.data.OccupantInfo;
|
||||||
import com.threerings.crowd.data.PlaceObject;
|
import com.threerings.crowd.data.PlaceObject;
|
||||||
import com.threerings.crowd.util.CrowdContext;
|
import com.threerings.crowd.util.CrowdContext;
|
||||||
@@ -68,14 +85,26 @@ public class ChatPanel
|
|||||||
epanel.add(_send, GroupLayout.FIXED);
|
epanel.add(_send, GroupLayout.FIXED);
|
||||||
add(epanel, GroupLayout.FIXED);
|
add(epanel, GroupLayout.FIXED);
|
||||||
|
|
||||||
// focus the chat input field by default
|
// listen to ancestor events to request focus when added
|
||||||
_entry.requestFocus();
|
addAncestorListener(new AncestorListener() {
|
||||||
|
public void ancestorAdded (AncestorEvent e) {
|
||||||
|
if (_focus) {
|
||||||
|
_entry.requestFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void ancestorMoved (AncestorEvent e) {
|
||||||
|
// don't care
|
||||||
|
}
|
||||||
|
public void ancestorRemoved (AncestorEvent e) {
|
||||||
|
// don't care
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For appliations where the chat box has extremely limited space, the
|
* For applications where the chat box has extremely limited space,
|
||||||
* send button can be removed to leave more space for the text input
|
* the send button can be removed to leave more space for the text
|
||||||
* box.
|
* input box.
|
||||||
*/
|
*/
|
||||||
public void removeSendButton ()
|
public void removeSendButton ()
|
||||||
{
|
{
|
||||||
@@ -85,6 +114,17 @@ public class ChatPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the chat box text entry field requests the keyboard
|
||||||
|
* focus when the panel receives {@link
|
||||||
|
* AncestorListener#ancestorAdded} or {@link PlaceView#willEnterPlace}
|
||||||
|
* events.
|
||||||
|
*/
|
||||||
|
public void setRequestFocus (boolean focus)
|
||||||
|
{
|
||||||
|
_focus = focus;
|
||||||
|
}
|
||||||
|
|
||||||
protected void createStyles (JTextPane text)
|
protected void createStyles (JTextPane text)
|
||||||
{
|
{
|
||||||
StyleContext sctx = StyleContext.getDefaultStyleContext();
|
StyleContext sctx = StyleContext.getDefaultStyleContext();
|
||||||
@@ -253,7 +293,9 @@ public class ChatPanel
|
|||||||
// we can chat
|
// we can chat
|
||||||
_entry.setEnabled(true);
|
_entry.setEnabled(true);
|
||||||
_send.setEnabled(true);
|
_send.setEnabled(true);
|
||||||
_entry.requestFocus();
|
if (_focus) {
|
||||||
|
_entry.requestFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void didLeavePlace (PlaceObject place)
|
public void didLeavePlace (PlaceObject place)
|
||||||
@@ -276,6 +318,8 @@ public class ChatPanel
|
|||||||
protected CrowdContext _ctx;
|
protected CrowdContext _ctx;
|
||||||
protected ChatDirector _chatdtr;
|
protected ChatDirector _chatdtr;
|
||||||
|
|
||||||
|
protected boolean _focus = true;
|
||||||
|
|
||||||
protected JComboBox _roombox;
|
protected JComboBox _roombox;
|
||||||
protected JTextPane _text;
|
protected JTextPane _text;
|
||||||
protected JButton _send;
|
protected JButton _send;
|
||||||
|
|||||||
Reference in New Issue
Block a user