📄 myjxtaview.java
字号:
JComboBox quickSearchContext = new JComboBox(new DefaultComboBoxModel(new Object[]{ new SearchContext(STRINGS.getString("label.pipe.name"), Searcher.PIPE), new SearchContext(STRINGS.getString("label.group.name"), Searcher.GROUP), new SearchContext(STRINGS.getString("label.share.name"), Searcher.SHARE) })); gbc.gridy++; gbc.gridwidth = GridBagConstraints.RELATIVE; gbc.gridheight = GridBagConstraints.REMAINDER; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.NONE; gb.setConstraints(quickSearchContext, gbc); p.add(quickSearchContext); JTextField quickSearch = new JTextField(25); quickSearch.addKeyListener(new QuickSearchKeyAdapter(quickSearchContext, this)); gbc.gridx++; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gb.setConstraints(quickSearch, gbc); p.add(quickSearch); m_navigationPane = new JTabbedPane(); m_navigationPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (m_menuManager != null) { m_menuManager.updateMenuStatus(); } } }); m_navigationPane.add(STRINGS.getString("label.network.jxta"), p); JPanel hp = new JPanel(); GridBagLayout hpgb = new GridBagLayout(); GridBagConstraints hpgbc = new GridBagConstraints(); hp.setLayout(hpgb); hp.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); hpgbc.gridx = 0; hpgbc.gridy = 0; hpgbc.gridwidth = GridBagConstraints.REMAINDER;// hpgbc.insets = new Insets(3, 3, 3, 3); hpgbc.anchor = GridBagConstraints.NORTHWEST; hpgbc.weightx = 1.0; hpgbc.weighty = 1.0; hpgbc.fill = GridBagConstraints.BOTH; hpgb.setConstraints(m_navigationPane, hpgbc); hp.add(m_navigationPane); return hp; } private JXTreeTable buildTree() { this.treeModel = new JxtaTreeModel(); JXTreeTable tt = new JXTreeTable(this.treeModel); tt.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tt.setRootVisible(false); tt.setShowsRootHandles(false); tt.setExpandsSelectedPaths(true); tt.setScrollsOnExpand(true); //extracted the renderer in an inner class tt.setTreeCellRenderer(new MyDefaultTreeCellRenderer()); Resources res = Resources.getInstance(); ImageIcon icon = res.getIconResource("TreeTable.PeerPresent"); if (icon != null) { Integer ip = res.getIntResource("TreeTable.padding"); tt.setRowHeight(icon.getIconHeight() + (ip != null ? ip.intValue() : 0) + 3); } // register listener (internal class PopupListener) - coconatty tt.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { process(me); } public void mouseReleased(MouseEvent me) { process(me); } /** * Invoked when the mouse has been clicked on a component. */ public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if ((e.getSource() == getTreeTable())) { JXTreeTable tt = getTreeTable(); TreePath path = tt.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } Object lastPath = path.getLastPathComponent(); if (lastPath instanceof GroupNode) { Group group = ((GroupNode) lastPath).getGroup(); if (e.getClickCount() >= 2) { if (group.isJoined()) { //resign group not implemented yet } else { new GroupJoinAction("", MyJXTAView.this).actionPerformed(new ActionEvent(this, 0, null)); } } } else if (lastPath instanceof PeerNode) { PeerNode node=(PeerNode)lastPath; if (e.getClickCount() >= 2) { getControl().getPluginContainer().triggerGlobalMyJxtaPopup(new ISelectableNode[]{node},e,getTreeTable());//, p_e, p_component) //new PeerChatAction("", MyJXTAView.this).actionPerformed(new ActionEvent(this, 0, null)); } } else if (lastPath instanceof ShareNode) { if (e.getClickCount() >= 2) { new ShareViewAction("", MyJXTAView.this).actionPerformed(new ActionEvent(this, 0, null)); } } } } private void process(MouseEvent me) { JXTreeTable tt = getTreeTable(); TreePath path = tt.getPathForLocation(me.getX(), me.getY()); if (me.isPopupTrigger() && me.getSource() == getTreeTable()) { tt.getTreeSelectionModel().setSelectionPath(path); displayTreePopup(tt, me.getX(), me.getY()); } } }); tt.setDragEnabled(true); tt.setTransferHandler(new MyTableTransferHandler()); tt.setDropTarget(new DropTarget(tt, new MyDropTargetListener())); return tt; } public JXTreeTable getTreeTable() { return this.tree; } //called by mouselistener to popup menu over tree //this could go in the listener methods, but kept separate at moment //in case we need to bring popup menu over other components than te JTree //this method can hopefully be used by both the PopupMenu and the MenuBar menus private void displayTreePopup(Component component, int x, int y) { // try to select tree nodes using right click as well // this doesn't work if right clicked on the node image... only on the text setActionMenuContext(); this.popup.show(component, x, y); } /** * Set the contextual menu for the popup dependening on the selected node * * @modified 2005-03-30 jamoore enable voice only if system property is set * @modified 2005-04-06 jamoore enable voice menu permanently * @modified 2005-04-24 jamoore add and enable video menu * @modified 2005-05-01 jamoore enable video only if system property is set */ public void setActionMenuContext() { //todo: sorry, but this one is a nightmare (nano) JMenu peer = (JMenu) this.popup.getComponent(0); JMenu group = (JMenu) this.popup.getComponent(1); JMenu share = (JMenu) this.popup.getComponent(2); JMenuItem export = (JMenuItem) this.popup.getComponent(4); JxtaNode jn = getJxtaNode(JxtaNode.class); GroupNode gn = (GroupNode) getJxtaNode(GroupNode.class); PeerNode pn = (PeerNode) getJxtaNode(PeerNode.class); Group g = gn != null ? gn.getGroup() : null; // xxx: might be nice to pull this in from an object (peer) PipeAdvertisement pa = g != null && g.getPeerGroup() != null ? PipeUtil.getAdv(g.getPeerGroup(), Dialog.getDialogNamer(OneToOneCommandDialog.class). getDialogName(g.getPeerGroup().getPeerName()), PipeService.UnicastSecureType, null, true) : null; boolean isMe = pn != null && pa != null && pa.getPipeID().equals(pn.getPeer().getPipeAdvertisement().getID()); boolean isJoined = g != null && g.isJoined(); Group pg = g != null ? g.getParentGroup() : null; boolean isParentJoined = pg == null || pg.isJoined(); ShareNode sn = (ShareNode) getJxtaNode(ShareNode.class); /** End temp section */ peer.setEnabled((isJoined || isParentJoined)); group.setEnabled(gn != null); share.setEnabled(isJoined || isParentJoined); export.setEnabled(pn != null || jn instanceof GroupNode); //todo: we should enable/disable the actions inside their own isEnabled action.... let em decide if they are //able to do something with the selection... peer.getItem(0).setEnabled(isJoined || isParentJoined); // search peer.getItem(1).setEnabled(pn != null && ! isMe); // chat peer.getItem(2).setEnabled(pn != null); peer.getItem(3).setEnabled(pn != null); peer.getItem(4).setEnabled(false); // add to friends peer.getItem(5).setEnabled(false); // remove from friends group.getItem(0).setEnabled(isJoined || isParentJoined); // search group.getItem(1).setEnabled(false); // chat group.getItem(2).setEnabled(isJoined); // create JMenuItem createGroupItem = group.getItem(2); createGroupItem.setEnabled(createGroupItem.getAction().isEnabled()); // leave group.getItem(3).setEnabled(!isJoined); // join JMenuItem leaveGroupItem = group.getItem(4); leaveGroupItem.setEnabled(leaveGroupItem.getAction().isEnabled()); // leave group.getItem(5).setEnabled(true); // manage share.getItem(0).setEnabled(isJoined || isParentJoined); // search share.getItem(1).setEnabled(true); // add share.getItem(2).setEnabled(sn != null); // view share.getItem(3).setEnabled(sn != null); // remove share.getItem(4).setEnabled(sn != null); // save// todo: re-enable as a plugin// share.getItem(5).setEnabled(sn != null &&// sn.toString().endsWith((UIConstants.NETBEAMS))); // beam } public Group getGroup() { GroupNode gn = (GroupNode) getJxtaNode(GroupNode.class); return gn != null ? gn.getGroup() : null; } public void setStatus(final String status) { // Write status info to the log regardless of the actual logger level LOG.log(Log4J.STATUS_LEVEL, status); EventQueue.invokeLater(new Runnable() { public void run() { getStatus().insertElementAt(status, 0); getStatus().setSelectedItem(status); int i = 0; while ((i = getStatus().getSize()) > STATUS_MAX) { getStatus().removeElementAt(i - 1); } } }); } private JPanel buildPlugins() { JPanel p = new JPanel(); GridBagLayout gb = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); p.setLayout(gb); p.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); this.plugins = new ClosableTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT); this.plugins.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { Object s = ce.getSource(); if (s instanceof JTabbedPane) { JTabbedPane tp = (JTabbedPane) s; Resources res = Resources.getInstance(); int i = tp.getSelectedIndex(); if (i > -1) { tp.setForegroundAt(i, res.getColorResource("TabPane.Selected")); } } } }); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = GridBagConstraints.REMAINDER;// gbc.insets = new Insets(3, 3, 3, 3); gbc.anchor = GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gb.setConstraints(this.plugins, gbc); p.add(this.plugins); //this is very primitive //but it ensures that the group chat of the current group navigation is visible final JTabbedPane plugins = getPlugins(); if (plugins != null) { m_navigationPane.addChangeListener(new SyncronizeTabPaneListener(plugins)); plugins.addChangeListener(new SyncronizeTabPaneListener(m_navigationPane)); } return p; } private JPanel buildFooter() { JPanel fp = new JPanel(); JPanel infoPanel = new JPanel(); fp.setLayout(new BoxLayout(fp, BoxLayout.X_AXIS)); fp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); this.status = new DefaultComboBoxModel(); JComboBox sb = new JComboBox();// sb.setFont(sb.getFont().deriveFont(8)); sb.setMaximumRowCount(STATUS_MAX); JPanel emptyPanel = new JPanel(); //not used rightn now, only to use the space emptyPanel.add(new Box.Filler(new Dimension(0, 0), new Dimension(800, 1), new Dimension(Short.MAX_VALUE, Short.MAX_VALUE))); infoPanel.add(Box.createHorizontalGlue());// infoPanel.add(new Box.Filler(new Dimension(0,0),new Dimension(200,1),new Dimension(1000,1000))); JLabel l = new JLabel(STRINGS.getString("label.badge.jxta"), JLabel.TRAILING); l.setFont(l.getFont().deriveFont(8)); l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); l.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent me) { String u = STRINGS.getString("uri.jxta"); try { ExecFactory.getExec().execDocument(new URL(u)); } catch (MalformedURLException mue) { if (LOG.isEnabledFor(Level.INFO)) { LOG.info("bad url: " + u); } } } }); infoPanel.add(l); infoPanel.add(Box.createRigidArea(new Dimension(7, 0))); ImageIcon i = Resources.getInstance().getIconResource("badge.sun");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -