📄 tabframe.java
字号:
/* Copyright (C) 2003 Adam Olsen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother;import java.awt.*;import java.awt.event.*;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Hashtable;import java.util.Locale;import java.util.ResourceBundle;import javax.swing.border.*;import javax.swing.*;import org.jivesoftware.smack.packet.Presence;import org.jivesoftware.smackx.muc.*;import com.valhalla.gui.DialogTracker;import com.valhalla.gui.Standard;import com.valhalla.jbother.groupchat.ChatRoomPanel;import com.valhalla.jbother.groupchat.GroupChatBookmarks;import com.valhalla.jbother.plugins.events.ExitingEvent;import com.valhalla.jbother.jabber.BuddyStatus;import com.valhalla.pluginmanager.PluginChain;import com.valhalla.settings.Settings;import net.infonode.tabbedpanel.*;import net.infonode.tabbedpanel.titledtab.*;import net.infonode.util.*;import net.infonode.tabbedpanel.theme.*;import net.infonode.gui.colorprovider.*;import net.infonode.gui.hover.*;/** * Contains all of the groupchat windows in tabs * * @author Adam Olsen * @author Andrey Zakirov * @version 1.1 */public class TabFrame extends JFrame { private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault()); private JPanel container = new JPanel(new BorderLayout()); private TabbedPanel tabPane = new TabbedPanel(); private TabListener tabListener = null; private JMenuBar menuBar = new JMenuBar(); private JMenu optionMenu = new JMenu(resources.getString("options")); private JMenuItem newItem = new JMenuItem(resources.getString("joinRoom")), leaveItem = new JMenuItem(resources.getString("leaveAll")), closeItem = new JMenuItem(resources.getString("closeButton")); private Hashtable queueCounts = new Hashtable(); private GCTabHandler switchListener = new GCTabHandler(); private WindowAdapter windowListener = null; private TabFocusListener tabFocusListener = null; private CloseMenu close = new CloseMenu(); private TabFrame thisPointer = this; private JSplitPane pane; private static boolean tabListenerAdded = false; private MyFocusListener focusListener = new MyFocusListener(); private javax.swing.Timer focusTimer = new javax.swing.Timer( 50, focusListener ); //private ShapedGradientTheme theme = new ShapedGradientTheme(); //private SmallFlatTheme theme = new SmallFlatTheme(); private ShapedGradientTheme theme = new ShapedGradientTheme(0f, 0f, new FixedColorProvider(new Color(150, 150, 150)),null); /** * Constructor sets the frame up and adds a listener to the JTabPane so that * if a tab is changed the title of this frame reflects the topic and the * name of the room in the tab */ public TabFrame() { super("JBother"); setIconImage(Standard.getImage("frameicon.png")); setContentPane(container); container.add(tabPane, BorderLayout.CENTER); // add the tab switch listener so the title of the frame reflects the // current tab tabListener = new TabAdapter() { public void tabSelected(TabStateChangedEvent e) { if( tabPane.getSelectedTab() == null) return; if (tabPane.getSelectedTab().getContentComponent() != null) { final TabFramePanel panel = (TabFramePanel) tabPane.getSelectedTab().getContentComponent(); setTitle(panel.getWindowTitle()); focusComponent( panel.getInputComponent() ); clearTab(panel); } } }; tabFocusListener = new TabFocusListener(); optionMenu.add(newItem); optionMenu.add(leaveItem); addListeners(); menuBar.add(optionMenu); windowListener = new WindowAdapter() { public void windowClosing(WindowEvent e) { saveStates(); closeHandler(); } }; // if they press the close button, we wanna handle leaving of the rooms addWindowListener(windowListener); setPreferredLocation(); pack(); String stringWidth = Settings.getInstance().getProperty( "chatFrameWidth"); String stringHeight = Settings.getInstance().getProperty( "chatFrameHeight"); if (stringWidth == null) stringWidth = "635"; if (stringHeight == null) stringHeight = "450"; setSize(new Dimension(Integer.parseInt(stringWidth), Integer .parseInt(stringHeight))); DialogTracker.addDialog(this, true, false); addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { saveStates(); } }); com.valhalla.Logger.debug("TabFrame is being created"); addComponentListener(new MoveListener()); addTabListeners(); } class TabFocusListener implements FocusListener { public void focusLost(FocusEvent e) { } public void focusGained(FocusEvent e) { final TabFramePanel panel = (TabFramePanel) tabPane.getSelectedTab().getContentComponent(); if (panel != null) { focusComponent( panel.getInputComponent() ); } if (panel instanceof ConversationPanel) { (((ConversationPanel) panel).getBuddy()).sendNotDisplayedID(); } } } private void focusComponent( Component comp ) { focusListener.setComponent( comp ); if( !focusTimer.isRunning() ) focusTimer.start(); else focusTimer.restart(); } class MyFocusListener implements ActionListener { private Component comp = null; public void setComponent( Component comp ) { this.comp = comp; } public void actionPerformed( ActionEvent e ) { SwingUtilities.invokeLater( new Runnable() { public void run() { if( comp != null ) comp.requestFocus(); } } ); focusTimer.stop(); } } private void addTabListeners() { tabPane.addTabListener(tabListener); tabPane.addFocusListener(tabFocusListener); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addKeyEventPostProcessor(switchListener); Direction d = Direction.DOWN; String dSetting = Settings.getInstance().getProperty( "tabOrientation", "Down" ); if( dSetting.equals( "Up" ) ) d = Direction.UP; else if( dSetting.equals( "Right" ) ) d = Direction.RIGHT; else if( dSetting.equals( "Left" ) ) d = Direction.LEFT; tabPane.getProperties().setTabAreaOrientation(d); tabPane.getProperties().setAutoSelectTab(true); tabPane.getProperties().setTabReorderEnabled(true); tabPane.getProperties().setTabLayoutPolicy(TabLayoutPolicy.COMPRESSION); tabPane.getProperties().setTabDropDownListVisiblePolicy(TabDropDownListVisiblePolicy.MORE_THAN_ONE_TAB); tabPane.getProperties().addSuperObject(theme.getTabbedPanelProperties()); } public void removeTabListeners() { tabPane.removeTabListener(tabListener); tabPane.removeFocusListener(tabFocusListener); KeyboardFocusManager.getCurrentKeyboardFocusManager() .removeKeyEventPostProcessor(switchListener); } public void dockBuddyList(final BuddyList list) { container.remove(tabPane); pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); pane.add(list); pane.add(tabPane); container.add(pane, BorderLayout.CENTER); removeWindowListener(windowListener); windowListener = new WindowAdapter() { public void windowClosing(WindowEvent e) { saveStates(); ExitingEvent event = new ExitingEvent(list); PluginChain.fireEvent(event); if (event.getExit()) { closeHandler(); list.quitHandler(); } } }; addWindowListener(windowListener); String divLocString = Settings.getInstance().getProperty( "dockedBuddyListDivLocation"); int divLoc = 150; try { if (divLocString != null) { divLoc = Integer.parseInt(divLocString); } } catch (NumberFormatException ex) { } addComponentListener(new MoveListener()); pane.setDividerLocation(divLoc); pane.addPropertyChangeListener("lastDividerLocation", new DividerListener()); validate(); } class MoveListener extends ComponentAdapter { public void componentMoved(ComponentEvent e) { saveStates(); } } public void undock() { container.remove(tabPane); removeTabListeners(); TabFrame frame = new TabFrame(); frame.setTabPane(tabPane); BuddyList.getInstance().setTabFrame(frame); frame.setVisible(true); dispose(); if (tabPane.getTabCount() > 0 && tabPane.getTabAt(0) != null) tabPane.setSelectedTab(tabPane.getTabAt(0)); } private void setTabPane(TabbedPanel pane) { try { remove(this.tabPane); } catch (Exception e) { } this.tabPane = pane; com.valhalla.Logger.debug("Setting tab pane"); addTabListeners(); getContentPane().add(pane, BorderLayout.CENTER); validate(); } /** * Listens for the user to move the divider, and saves it's location * * @author Adam Olsen * @version 1.0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -