mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Memory work.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@9243 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
@ -1,13 +1,3 @@
|
||||
/**
|
||||
* $Revision: $
|
||||
* $Date: $
|
||||
*
|
||||
* Copyright (C) 2006 Jive Software. All rights reserved.
|
||||
*
|
||||
* This software is published under the terms of the GNU Lesser Public License (LGPL),
|
||||
* a copy of which is included in this distribution.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.spark.component.tabbedPane;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
@ -24,6 +14,7 @@ import java.awt.Window;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@ -102,34 +93,34 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
tabs = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)) {
|
||||
public Dimension getPreferredSize() {
|
||||
if (getParent() == null)
|
||||
return getPreferredSize();
|
||||
// calculate the preferred size based on the flow of components
|
||||
FlowLayout flow = (FlowLayout)getLayout();
|
||||
int w = getParent().getWidth();
|
||||
int h = flow.getVgap();
|
||||
int x = flow.getHgap();
|
||||
int rowH = 0;
|
||||
Dimension d;
|
||||
Component[] comps = getComponents();
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
if (comps[i].isVisible()) {
|
||||
d = comps[i].getPreferredSize();
|
||||
if (x + d.width > w && x > flow.getHgap()) {
|
||||
x = flow.getHgap();
|
||||
h += rowH;
|
||||
rowH = 0;
|
||||
h += flow.getVgap();
|
||||
public Dimension getPreferredSize() {
|
||||
if (getParent() == null)
|
||||
return getPreferredSize();
|
||||
// calculate the preferred size based on the flow of components
|
||||
FlowLayout flow = (FlowLayout)getLayout();
|
||||
int w = getParent().getWidth();
|
||||
int h = flow.getVgap();
|
||||
int x = flow.getHgap();
|
||||
int rowH = 0;
|
||||
Dimension d;
|
||||
Component[] comps = getComponents();
|
||||
for (int i = 0; i < comps.length; i++) {
|
||||
if (comps[i].isVisible()) {
|
||||
d = comps[i].getPreferredSize();
|
||||
if (x + d.width > w && x > flow.getHgap()) {
|
||||
x = flow.getHgap();
|
||||
h += rowH;
|
||||
rowH = 0;
|
||||
h += flow.getVgap();
|
||||
}
|
||||
rowH = Math.max(d.height, rowH);
|
||||
x += d.width + flow.getHgap();
|
||||
}
|
||||
}
|
||||
rowH = Math.max(d.height, rowH);
|
||||
x += d.width + flow.getHgap();
|
||||
h += rowH;
|
||||
return new Dimension(w, h);
|
||||
}
|
||||
}
|
||||
h += rowH;
|
||||
return new Dimension(w, h);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
final JPanel topPanel = new JPanel();
|
||||
@ -138,11 +129,15 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
|
||||
|
||||
// Add Tabs panel to top of panel.
|
||||
if (tabPlacement == JTabbedPane.TOP) {
|
||||
topPanel.add(tabs, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 0, 0), 0, 0));
|
||||
topPanel.add(tabs,
|
||||
new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(2, 0, 0, 0), 0, 0));
|
||||
add(topPanel, BorderLayout.NORTH);
|
||||
}
|
||||
else {
|
||||
topPanel.add(tabs, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 2, 0), 0, 0));
|
||||
topPanel.add(tabs,
|
||||
new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0, 0, 2, 0), 0, 0));
|
||||
add(topPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
@ -185,55 +180,55 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
|
||||
// Add Component to main panel
|
||||
mainPanel.add(Integer.toString(component.hashCode()), component);
|
||||
tab.addMouseListener(this);
|
||||
|
||||
boolean allowClosingThisTab = true;
|
||||
|
||||
boolean allowClosingThisTab = true;
|
||||
LocalPreferences pref = SettingsManager.getLocalPreferences();
|
||||
|
||||
|
||||
if (!pref.arePerisitedChatRoomsClosable()) {
|
||||
allowClosingThisTab = ConferenceUtils.isChatRoomClosable(component);
|
||||
allowClosingThisTab = ConferenceUtils.isChatRoomClosable(component);
|
||||
}
|
||||
//JOptionPane.showMessageDialog(this, "allowClosingThisTab:" + allowClosingThisTab);
|
||||
|
||||
|
||||
// Add Close Button
|
||||
if (isCloseButtonEnabled() && allowClosingThisTab) {
|
||||
final JLabel closeButton = new JLabel(closeInactiveButtonIcon);
|
||||
final JLabel closeButton = new JLabel(closeInactiveButtonIcon);
|
||||
tab.addComponent(closeButton);
|
||||
closeButton.addMouseListener(new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
if (Spark.isWindows()) {
|
||||
closeButton.setIcon(closeActiveButtonIcon);
|
||||
}
|
||||
|
||||
setCursor(HAND_CURSOR);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
if (Spark.isWindows()) {
|
||||
closeButton.setIcon(closeInactiveButtonIcon);
|
||||
}
|
||||
|
||||
setCursor(DEFAULT_CURSOR);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
final SwingWorker closeTimerThread = new SwingWorker() {
|
||||
public Object construct() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
public void mouseEntered(MouseEvent mouseEvent) {
|
||||
if (Spark.isWindows()) {
|
||||
closeButton.setIcon(closeActiveButtonIcon);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
return true;
|
||||
|
||||
setCursor(HAND_CURSOR);
|
||||
}
|
||||
|
||||
public void finished() {
|
||||
close(tab, component);
|
||||
public void mouseExited(MouseEvent mouseEvent) {
|
||||
if (Spark.isWindows()) {
|
||||
closeButton.setIcon(closeInactiveButtonIcon);
|
||||
}
|
||||
|
||||
setCursor(DEFAULT_CURSOR);
|
||||
}
|
||||
};
|
||||
closeTimerThread.start();
|
||||
}
|
||||
});
|
||||
|
||||
public void mousePressed(MouseEvent mouseEvent) {
|
||||
final SwingWorker closeTimerThread = new SwingWorker() {
|
||||
public Object construct() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void finished() {
|
||||
close(tab, component);
|
||||
}
|
||||
};
|
||||
closeTimerThread.start();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -368,7 +363,7 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
|
||||
// Close Tab
|
||||
mainPanel.remove(comp);
|
||||
tabs.remove(tab);
|
||||
|
||||
tabs.removeMouseListener(this);
|
||||
|
||||
tabs.invalidate();
|
||||
tabs.validate();
|
||||
|
||||
@ -10,6 +10,10 @@
|
||||
|
||||
package org.jivesoftware.spark.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JComponent;
|
||||
@ -19,10 +23,6 @@ import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.undo.UndoManager;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* This is implementation of ChatArea that should be used as the sendField
|
||||
* in any chat room implementation.
|
||||
@ -66,6 +66,15 @@ public class ChatInputEditor extends ChatArea implements DocumentListener {
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove dependices when no longer in use.
|
||||
*/
|
||||
public void close() {
|
||||
this.getDocument().removeDocumentListener(this);
|
||||
this.getDocument().removeUndoableEditListener(undoManager);
|
||||
this.removeMouseListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the Chat Editor, rendering it to the system default
|
||||
* color.
|
||||
|
||||
@ -27,26 +27,6 @@ import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
|
||||
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
@ -68,6 +48,26 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
|
||||
/**
|
||||
* The base implementation of all ChatRoom conversations. You would implement this class to have most types of Chat.
|
||||
*/
|
||||
@ -492,7 +492,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
private void checkForEnter(KeyEvent e) {
|
||||
final KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
|
||||
if (!keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK)) &&
|
||||
e.getKeyChar() == KeyEvent.VK_ENTER) {
|
||||
e.getKeyChar() == KeyEvent.VK_ENTER) {
|
||||
e.consume();
|
||||
sendMessage();
|
||||
getChatInputEditor().setText("");
|
||||
@ -644,6 +644,7 @@ public abstract class ChatRoom extends BackgroundPanel implements ActionListener
|
||||
packetIDList.clear();
|
||||
messageListeners.clear();
|
||||
fileDropListeners.clear();
|
||||
getChatInputEditor().close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -92,6 +92,8 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
|
||||
private long lastActivity;
|
||||
|
||||
private boolean active;
|
||||
|
||||
/**
|
||||
* Constructs a 1-to-1 ChatRoom.
|
||||
*
|
||||
@ -100,6 +102,7 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
* @param title the title of the room.
|
||||
*/
|
||||
public ChatRoomImpl(final String participantJID, String participantNickname, String title) {
|
||||
this.active = true;
|
||||
this.participantJID = participantJID;
|
||||
this.participantNickname = participantNickname;
|
||||
|
||||
@ -193,6 +196,11 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
|
||||
|
||||
public void closeChatRoom() {
|
||||
// If already closed, don't bother.
|
||||
if(!active){
|
||||
return;
|
||||
}
|
||||
|
||||
super.closeChatRoom();
|
||||
|
||||
// Send a cancel notification event on closing if listening.
|
||||
@ -206,7 +214,9 @@ public class ChatRoomImpl extends ChatRoom {
|
||||
SparkManager.getChatManager().removeChat(this);
|
||||
|
||||
SparkManager.getConnection().removePacketListener(this);
|
||||
typingTimerTask.cancel();
|
||||
TaskEngine.getInstance().cancelScheduledTask(typingTimerTask);
|
||||
typingTimerTask = null;
|
||||
active = false;
|
||||
}
|
||||
|
||||
public void sendMessage() {
|
||||
|
||||
Reference in New Issue
Block a user