📄 singlegroupnavigationpanel.java
字号:
/** * Copyright (c) 2005 Frank Toennies * Redistributions in source code form must reproduce the above copyright and this condition. * The contents of this file are subject to the Sun Project JXTA License Version 1.1 (the "License"); * you may not use this file except in compliance with the License. * A copy of the License is available at http://www.jxta.org/jxta_license.html. * Please see the license information page for instructions on use of the license in source files. * * This software consists of voluntary contributions made by many individuals on behalf of Project JXTA. * For more information on Project JXTA, please see http://www.jxta.org. * */package net.jxta.myjxta.ui;import info.clearthought.layout.TableLayout;import net.jxta.myjxta.View;import net.jxta.myjxta.plugin.ISelectableNode;import net.jxta.myjxta.plugin.PluginContainer;import net.jxta.myjxta.plugin.SelectionNodeType;import net.jxta.myjxta.presence.PeerEntry;import net.jxta.myjxta.presence.PeerStatus;import net.jxta.myjxta.search.SearchContext;import net.jxta.myjxta.search.Searcher;import net.jxta.myjxta.ui.action.PeerPingAction;import net.jxta.myjxta.util.Group;import net.jxta.myjxta.util.GroupListener;import net.jxta.myjxta.util.JxtaNode;import net.jxta.myjxta.util.Peer;import net.jxta.myjxta.util.PeerNode;import net.jxta.myjxta.util.Resources;import net.jxta.rendezvous.RendezVousService;import javax.swing.*;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.table.DefaultTableCellRenderer;import java.awt.*;import java.awt.event.InputEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.EventObject;import java.util.ResourceBundle;/** * This Dialog Panel shows a information / navigation table of all known peers (the truth is:command dialog pipes) * inside the current jxta group. Each ro inside the table represents one pipe. A QuickSearch Textfield enables * the user to search for nodes and shares. next version of this panel will also support the listing * of shares inside the current group) * * @author Frank Toennies -- */public class SingleGroupNavigationPanel extends JPanel implements PluginContainer.ISelectionProvider { private JTable m_groupNavigationTable = null; private static boolean ENABLE_STATUS_CONTROLS = true; private SingleGroupTableModel m_groupTableModel = null; private View m_view; private static final ResourceBundle STRINGS = Resources.getStrings(); private static ImageIcon g_peerPresentIcon = Resources.getInstance().getIconResource("TreeTable.PeerPresent"); private static ImageIcon g_peerAbsendIcon = Resources.getInstance().getIconResource("TreeTable.PeerAbsent"); private JComboBox m_quickSearchContext; private JTextField m_quickSearch; private JScrollPane m_scrollPane; private JPanel m_infoPanel; /** * @param view * @param group */ public SingleGroupNavigationPanel(View view, Group group) { m_groupNavigationTable = new JTable(); m_view = view; m_view.getControl().getPluginContainer().registerSelectionProvider(this); m_groupNavigationTable.setDefaultRenderer(PeerEntry.class, new MyTableCellRenderer()); m_groupTableModel = new SingleGroupTableModel(group); m_groupNavigationTable.setModel(m_groupTableModel); int rowHeight = g_peerPresentIcon != null ? g_peerPresentIcon.getIconHeight() + 3 : 20; m_groupNavigationTable.setRowHeight(rowHeight); m_groupNavigationTable.setShowGrid(false); m_groupNavigationTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); m_groupNavigationTable.addMouseListener(new MyTableMouseListener()); m_groupNavigationTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { MenuManager.getInstance(m_view).updateMenuStatus(); } }); m_quickSearchContext = new JComboBox(new DefaultComboBoxModel(new Object[]{ new SearchContext(STRINGS.getString("label.pipe.name"), Searcher.PIPE),// new SearchContext(STRINGS.getString("label.share.name"),// Searcher.SHARE) })); m_quickSearch = new JTextField(25); m_quickSearch.addKeyListener(new MyJXTAView.QuickSearchKeyAdapter(m_quickSearchContext, m_view)); double size[][]; if (ENABLE_STATUS_CONTROLS) { m_infoPanel = createInfoPanel(); size = new double[][]{{0.00, 0.50, 0.50, 0.00}, //columns x {25, TableLayout.FILL, 25}}; //rows y //reserve 20 pixel above the table for some checkboxes (not there yet) } else { size = new double[][]{{0.00, 0.50, 0.50, 0.00}, //columns x {0, TableLayout.FILL, 25}}; //rows y //reserve 20 pixel above the table for some checkboxes (not there yet) } setLayout(new TableLayout(size)); JScrollPane sp = new JScrollPane(m_groupNavigationTable); m_scrollPane = sp; m_scrollPane.getViewport().setOpaque(false); sp.setBackground(m_groupNavigationTable.getBackground()); add(sp, "1, 1, 2, 1"); //cell 1,1 towards 2,1 (first one is column or X cord) add(m_quickSearchContext, "1,2"); //add the context combo to the outermost south west cell (row 3, column 1) add(m_quickSearch, "2,2"); //add the textfield right beside the combo if (ENABLE_STATUS_CONTROLS) { add(m_infoPanel, "0,0,2,0"); } } private PeerNode[] getAllPeerNodes() { return getTableModel().getAllPeerNodes(); } public void pingAllNodes() { final PeerNode[] nodes = getAllPeerNodes(); new PeerPingAction("not used", m_view) { protected PeerNode[] getNodes() { return nodes; } }.actionPerformed(null); } private JPanel createInfoPanel() { JPanel panel = new JPanel(); double size[][] = {{0.25, 0.25, TableLayout.FILL, 60}, //columns x {TableLayout.FILL}}; //rows y //reserve 20 pixel above the table for some checkboxes (not there yet) panel.setLayout(new TableLayout(size)); ImageIcon iconConnected = Resources.getInstance().getIconResource("GroupTable.connectedToRdv"); ImageIcon iconNotConnected = Resources.getInstance().getIconResource("GroupTable.notConnectedToRdv"); ImageIcon iconIsRdv = Resources.getInstance().getIconResource("GroupTable.isRdv"); final GroupStatusControl rdvConnectionControl = new GroupStatusControl("rdvConnection", iconConnected, iconNotConnected); rdvConnectionControl.setToolTipText("network connection state"); final GroupStatusControl isRdvControl = new GroupStatusControl("rdvConnection", iconIsRdv, iconConnected); isRdvControl.setEnabled(false); getGroup().addListener(new MyGroupListener(rdvConnectionControl, isRdvControl));// Group parentGroup = getGroup().getParentGroup();// GroupStatusControl parentGroupStatusControl=null;// if (parentGroup !=null){// parentGroupStatusControl=new GroupStatusControl("npgConnection",iconConnected,iconNotConnected);// parentGroupStatusControl.setActive(parentGroup.isConnected());// parentGroup.addListener(new MyGroupListener(parentGroupStatusControl,null));// } JPanel iconPanel = new JPanel(); iconPanel.add(rdvConnectionControl); //quick and dirty... remove this one after we have a better place to activate it rdvConnectionControl.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { pingAllNodes(); } } }); isRdvControl.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { int modifiers = e.getModifiersEx(); if (e.getClickCount() == 2 && (modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) { RendezVousService rendezVousService = m_groupTableModel.getGroup().getPeerGroup().getRendezVousService(); if (m_groupTableModel.getGroup().isOwnPeerRdv()) { rendezVousService.stopRendezVous(); } else { //hidden promote to rdv.... maybe not a good idea so dont advertise it too much... //may be removed at any time rendezVousService.startRendezVous(); } } } }); iconPanel.add(isRdvControl); panel.add(iconPanel, "3,0,3,0");//nano: not yet working (sometimes the wrong state is shown... maybe we are missing a rdv-connect event?)// JPanel parentGroupPanel=new JPanel();// parentGroupPanel.add(parentGroupStatusControl);// panel.add(parentGroupPanel,"0,0,0,0"); return panel; } private class GroupStatusControl extends JPanel { private Icon m_activeIcon; private Icon m_notActiveIcon; private boolean m_active = false; private ImageIcon m_disabledIcon; public void setActive(boolean p_active) { m_active = p_active; invalidate(); repaint(); } public GroupStatusControl(String identifier, ImageIcon p_active, ImageIcon p_notActive) { m_activeIcon = p_active; m_notActiveIcon = p_notActive; m_disabledIcon = new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon) p_active).getImage()));// m_button=new JButton(m_notActiveIcon);// m_button.setEnabled(false);// add(m_button); } public Dimension getPreferredSize() { return new Dimension(m_activeIcon.getIconWidth(), m_activeIcon.getIconHeight()); } protected void paintComponent(Graphics g) { super.paintComponent(g); if (isEnabled()) { if (m_active) { m_activeIcon.paintIcon(this, g, 0, 0); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -