📄 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.Resources;import net.jxta.myjxta.util.objectmodel.JxtaNode;import net.jxta.myjxta.util.objectmodel.PeerNode;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 final class SingleGroupNavigationPanel extends JPanel implements PluginContainer.ISelectionProvider { private JTable m_groupNavigationTable = null; private static final boolean ENABLE_STATUS_CONTROLS = true; private SingleGroupTableModel m_groupTableModel = null; private final View m_view; private static final ResourceBundle STRINGS = Resources.getStrings(); private static final ImageIcon g_peerPresentIcon = Resources.getInstance().getIconResource("TreeTable.PeerPresent"); private static final ImageIcon g_peerAbsendIcon = Resources.getInstance().getIconResource("TreeTable.PeerAbsent"); private final JComboBox m_quickSearchContext; private final JTextField m_quickSearch; private final 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"); Group group = getGroup(); Group parentGroup = group.getParentGroup(); final GroupStatusControl parentGroupControl = new GroupStatusControl(parentGroup.getName(), iconConnected, iconNotConnected, iconIsRdv); parentGroupControl.setToolTipText("network connection state"); final GroupStatusControl ownGroupControl = new GroupStatusControl(group.getName(), iconConnected, iconNotConnected, iconIsRdv); ownGroupControl.setEnabled(true); MyGroupListener groupStatusControl = new MyGroupListener(group, parentGroupControl, ownGroupControl); group.addListener(groupStatusControl); parentGroup.addListener(groupStatusControl); groupStatusControl.updateControl(group, ownGroupControl); groupStatusControl.updateControl(parentGroup, parentGroupControl);// 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(parentGroupControl); //quick and dirty... remove this one after we have a better place to activate it parentGroupControl.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { pingAllNodes(); } } }); ownGroupControl.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(ownGroupControl); 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 final class GroupStatusControl extends JPanel { private final Icon m_edgeConnected; private final Icon m_edgeNotConnected; //private boolean m_active = false; private Icon m_activeIcon; private final ImageIcon m_isRdvIcon; private final String m_groupName; public void setEdgeConnected(boolean p_connected) { m_activeIcon = p_connected ? m_edgeConnected : m_edgeNotConnected; setToolTipText("Own peer a Edge peer for group " + m_groupName + " and " + (p_connected ? "IS " : "IS NOT ") + "connected"); invalidate(); repaint(); } public void setIsRdv() { m_activeIcon = m_isRdvIcon; setToolTipText("Own peer is a Rendezvous for group " + m_groupName); invalidate(); repaint(); } public GroupStatusControl(String groupName, ImageIcon p_edgeConnected, ImageIcon p_edgeNotConnected, ImageIcon p_isRdv) { m_edgeConnected = p_edgeConnected; m_edgeNotConnected = p_edgeNotConnected; m_isRdvIcon = p_isRdv; m_activeIcon = m_edgeNotConnected; m_groupName = groupName;// m_button=new JButton(m_edgeNotConnected);// m_button.setEnabled(false);// add(m_button); } public Dimension getPreferredSize() { return new Dimension(m_edgeConnected.getIconWidth(), m_edgeConnected.getIconHeight()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -