?? myjxtaview.java
字號:
if (net.jxta.logging.Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", use); } } catch (IOException ioe) { if (net.jxta.logging.Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", ioe); } } } boolean isValid = false; if (d != null) { isValid = handle(d, dtde); } dtde.dropComplete(isValid); if (!isValid) { dtde.rejectDrop(); } getTreeTable().getTreeSelectionModel().setSelectionPath(oldSelectionPath); oldSelectionPath = null; } public void dropActionChanged(DropTargetDragEvent dtde) { } private boolean handle(Object d, DropTargetDropEvent p_dtde) { boolean isValid = false; String s; if (d != null) { if (d instanceof Collection) { for (Object o : ((Collection) d)) { isValid = handle(o, p_dtde); } } else if (d instanceof String) { s = (String) d; Advertisement a = getAdvertisement(s); GroupNode gn = (GroupNode) getJxtaNode(GroupNode.class); Group g = gn != null ? gn.getGroup() : null; JxtaNode n = null; JXTreeTable treeTable = getTreeTable(); int row = treeTable.rowAtPoint(p_dtde.getLocation()); treeTable.getSelectionModel().setSelectionInterval(row, row); if (a != null && g != null) { // xxx: ?pub locally? if (a instanceof PipeAdvertisement) { PipeAdvertisement pa = (PipeAdvertisement) a; if (pa.getName().startsWith(OneToOneCommandDialog.DIALOG_NAME) && pa.getType().equals(PipeService.UnicastType)) { n = new PeerNode(new Peer(pa), g); } } else if (a instanceof PeerGroupAdvertisement) { n = new GroupNode(new Group(getControl(), (PeerGroupAdvertisement) a, g)); } } if (n != null) { addJxtaNode(n); isValid = true; } if (!isValid) { URI u = getURI(s); if (u != null) { getControl().getShareManager().share(u); } else { // xxx: share txt drop //String s = process((String)d); } isValid = true; } } else if (d instanceof java.io.File) { //under windows we may get a real file object //no string parsing needed, simply share it URI fileUri = ((java.io.File) d).toURI(); getControl().getShareManager().share(fileUri); isValid = true; } } return isValid; } private Advertisement getAdvertisement(String advertismentString) { Advertisement a = null; String c = process(advertismentString); if (c != null) { try { XMLElement element = (XMLElement) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, new ByteArrayInputStream(advertismentString.getBytes("UTF-8"))); a = AdvertisementFactory.newAdvertisement(element); } catch (Exception e) { if (net.jxta.logging.Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", e); } } } return a; } private URI getURI(String s) { URI u = null; if (s != null && s.trim().length() > 0) { try { u = new URI(s); } catch (URISyntaxException use) { if (net.jxta.logging.Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", use); } } } return u; } private String process(String d) { String s = null; String lc = d != null ? d.toLowerCase().trim() : null; if (lc != null && lc.trim().length() > 0) { if ((lc.startsWith(UIConstants.PROTOCOL_FILE) || lc.startsWith(UIConstants.PROTOCOL_HTTP)) && (lc.endsWith(DOT + Constants.JXTA_RESOURCE))) { URI u = getURI(d); if (u != null) { if (u.getScheme().equalsIgnoreCase(UIConstants.PROTOCOL_FILE)) { s = readFile(u); } else if (u.getScheme().equalsIgnoreCase(UIConstants.PROTOCOL_HTTP)) { s = readHTTP(u); } } else { s = d; } } else { s = d.trim(); } } return s; } private String readFile(URI u) { StringBuffer sb = new StringBuffer(); try { Object o = u.toURL().getContent(); Reader r = new BufferedReader(new InputStreamReader((InputStream) o)); for (int c = r.read(); c >= 0; c = r.read()) { sb.append((char) c); } } catch (IOException ioe) { if (net.jxta.logging.Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", ioe); } } return sb.toString().trim().length() > 0 ? sb.toString() : null; } private String readHTTP(URI u) { String s = null; try { s = (String) u.toURL().getContent(); } catch (IOException ioe) { if (net.jxta.logging.Logging.SHOW_SEVERE && LOG.isLoggable(Level.SEVERE)) { LOG.log(Level.SEVERE, "Caught unexpected Exception", ioe); } } return s; } } /* (non-Javadoc) * @see net.jxta.myjxta.View#createGroupNavigation(net.jxta.peergroup.PeerGroup) */ public void createGroupNavigation(Group group) { m_navigationPane.add(new SingleGroupNavigationPanel(this, group), group.getName()); m_navigationPane.setSelectedIndex(m_navigationPane.getComponentCount() - 1); } public void removeGroupNavigation(Group group) { Component comps[] = m_navigationPane.getComponents(); for (Component comp : comps) { if (comp instanceof SingleGroupNavigationPanel) { SingleGroupNavigationPanel singleGroupNavigationPanel = (SingleGroupNavigationPanel) comp; if (singleGroupNavigationPanel.getGroup().equals(group)) { singleGroupNavigationPanel.shutdown(); m_navigationPane.remove(singleGroupNavigationPanel); break; } } } } public void showMessageDialog(String p_message) { JOptionPane.showMessageDialog(split, p_message); } public Group findDeepestJoinedGroupAboveSelection() { if (tree == null) { return null; } Component selectedComponent = m_navigationPane.getSelectedComponent(); if (selectedComponent instanceof SingleGroupNavigationPanel) { return ((SingleGroupNavigationPanel) selectedComponent).getGroup(); } else { TreePath groupPath = findDeepestJoinedGroup(tree.getTreeSelectionModel().getSelectionPath()); if (groupPath != null) { return ((GroupNode) groupPath.getLastPathComponent()).getGroup(); } else { return null; } } } public SingleGroupNavigationPanel getNavigationForGroup(Group p_group) { int count = m_navigationPane.getComponentCount(); for (int i = 0; i < count; i++) { Component c = m_navigationPane.getComponent(i); if (c instanceof SingleGroupNavigationPanel) { SingleGroupNavigationPanel panel = ((SingleGroupNavigationPanel) c); if (panel.getGroup().equals(p_group)) { return panel; } } } return null; } public static TreePath findDeepestJoinedGroup(TreePath start) { if (start == null) { return null; } Object lastElement = start.getLastPathComponent(); if (lastElement instanceof GroupNode) { GroupNode groupNode = (GroupNode) lastElement; if (groupNode.getGroup().isJoined()) { return start; } else if (groupNode.getParent() instanceof GroupNode) { return findDeepestJoinedGroup(start.getParentPath()); } else { return null; } } else { return findDeepestJoinedGroup(start.getParentPath()); } } class InactiveNodeUpdater extends TimerTask { public void run() { getTreeModel().checkStatus(); } } public static class QuickSearchKeyAdapter extends KeyAdapter { private final View m_view; private final JComboBox m_contextCombo; public QuickSearchKeyAdapter(JComboBox p_contextCombo, View p_view) { m_contextCombo = p_contextCombo; m_view = p_view; } public void keyPressed(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_ENTER) { JTextField quickSearch = (JTextField) ke.getSource(); SearchContext c = (SearchContext) m_contextCombo.getModel().getSelectedItem(); String term = quickSearch.getText().trim(); Group g = m_view.getGroup(); if (term.length() == 0) { term = SearchModifier.WILDCARD; } while (g != null && !g.isJoined() && g.isVisible()) { g = g.getParentGroup(); } if (term.length() > 0 && c != null && g != null && SearchManager.getInstance().search(c.getContext(), g, m_view.getControl(), term)) { updateStatus(c, term); } } } private void updateStatus(SearchContext p_c, String p_term) { String status = null; switch (p_c.getContext()) { case Searcher.PIPE: status = STRINGS.getString("status.peer.discover"); break; case Searcher.GROUP: status = STRINGS.getString("status.group.discover"); break; case Searcher.SHARE: status = STRINGS.getString("status.share.discover"); break; default: } m_view.setStatus(status + ": " + p_term); } } public void popupRequested(PluginContainer.IPopupGenerator popupGenerator, ISelectableNode[] selectedNodes, MouseEvent triggerEvent) { if (!triggerEvent.isPopupTrigger()) return;// getTreeTable().getTreeSelectionModel().setSelectionPath(path); //set the context according to the current selection //this is only a temporal solution, we have to calculate the menus from selectedNodes setActionMenuContext(); //disable (and therefore hide) the group and share for now JMenu group = (JMenu) this.popup.getComponent(1); JMenu share = (JMenu) this.popup.getComponent(2); group.setEnabled(false); share.setEnabled(false); ArrayList<UIHelper.PopupConverterEntry> popupEntrys = new ArrayList<UIHelper.PopupConverterEntry>(); UIHelper.getPopupsFromPopupMenu(this.popup, null, popupEntrys); for (UIHelper.PopupConverterEntry popupConverterEntry : popupEntrys) { popupGenerator.addPopup(popupConverterEntry.path, 0, (AbstractAction) popupConverterEntry.m_action); } } private class SyncronizeTabPaneListener implements ChangeListener { private final JTabbedPane m_otherTabPane;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -