⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myjxtaview.java

📁 jxta官方例程
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* *  Copyright (c) 2001 Sun Microsystems, Inc.  All rights *  reserved. * *  Redistribution and use in source and binary forms, with or withouta *  modification, are permitted provided that the following conditions *  are met:addjxt * *  1. Redistributions of sourcec code must retain the above copyright *  notice, this list of conditions and the following disclaimer. * *  2. Redistributions in binary form must reproduce the above copyright *  notice, this list of conditions and the following discalimer in *  the documentation and/or other materials provided with the *  distribution.c * *  3. The end-user documentation included with the redistribution, *  if any, must include the following acknowledgment: *  "This product includes softgetware developed by the *  Sun Microsystems, Inc. for Project JXTA." *  Alternately, this acknowledgment may appear in the software itself, *  if and wherever such third-party acknowledgments normally appear. * *  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" *  must not be used to endorse or promote products derived from this *  software without prior written permission. For written *  permission, please contact Project JXTA at http://www.jxta.org. * *  5. Products derived from this software may not be called "JXTA",s *  nor may "JXTA" appear in their name, without prior written *  permission of Sun. * *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *  SUCH DAMAGE. *  ===================================================tre================= * *  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/>. * * *  $Id: MyJXTAView.java,v 1.104 2006/09/04 21:39:22 nano Exp $ */package net.jxta.myjxta.ui;import net.jxta.document.Advertisement;import net.jxta.document.AdvertisementFactory;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocumentFactory;import net.jxta.document.XMLElement;import net.jxta.ext.config.Configurator;import net.jxta.myjxta.MyJXTA;import net.jxta.myjxta.View;import net.jxta.myjxta.dialog.Dialog;import net.jxta.myjxta.dialog.DialogMessage;import net.jxta.myjxta.dialog.OneToOneCommandDialog;import net.jxta.myjxta.dialog.util.Text;import net.jxta.myjxta.plugin.ISelectableNode;import net.jxta.myjxta.plugin.PluginContainer;import net.jxta.myjxta.plugin.PluginPanel;import net.jxta.myjxta.search.SearchContext;import net.jxta.myjxta.search.SearchManager;import net.jxta.myjxta.search.SearchModifier;import net.jxta.myjxta.search.Searcher;import net.jxta.myjxta.ui.action.ExitAction;import net.jxta.myjxta.ui.action.GroupJoinAction;import net.jxta.myjxta.ui.action.ShareViewAction;import net.jxta.myjxta.ui.model.JxtaTreeModel;import net.jxta.myjxta.util.ConfigData;import net.jxta.myjxta.util.Constants;import net.jxta.myjxta.util.Env;import net.jxta.myjxta.util.Group;import net.jxta.myjxta.util.GroupNode;import net.jxta.myjxta.util.JxtaNode;import net.jxta.myjxta.util.Log4J;import net.jxta.myjxta.util.Peer;import net.jxta.myjxta.util.PeerNode;import net.jxta.myjxta.util.PipeUtil;import net.jxta.myjxta.util.Prefs;import net.jxta.myjxta.util.Resources;import net.jxta.myjxta.util.ShareNode;import net.jxta.myjxta.util.exec.ExecFactory;import net.jxta.myjxta.util.preferences.MyPreferencePanel;import net.jxta.pipe.PipeService;import net.jxta.protocol.PeerGroupAdvertisement;import net.jxta.protocol.PipeAdvertisement;import org.apache.log4j.Level;import org.apache.log4j.Logger;import org.jdesktop.swingx.JXFrame;import org.jdesktop.swingx.JXTreeTable;import javax.swing.*;import javax.swing.border.EmptyBorder;import javax.swing.border.EtchedBorder;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;import java.awt.*;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.datatransfer.UnsupportedFlavorException;import java.awt.dnd.DnDConstants;import java.awt.dnd.DropTarget;import java.awt.dnd.DropTargetDragEvent;import java.awt.dnd.DropTargetDropEvent;import java.awt.dnd.DropTargetEvent;import java.awt.dnd.DropTargetListener;import java.awt.event.ActionEvent;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.io.BufferedReader;import java.io.ByteArrayInputStream;import java.io.File;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.Reader;import java.lang.reflect.InvocationTargetException;import java.net.MalformedURLException;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;import java.util.List;import java.util.ResourceBundle;import java.util.TimerTask;/** * @author james todd [gonzo at jxta dot org] * @author joe leach [coconatty at jxta dot org] * @version $Id: MyJXTAView.java,v 1.104 2006/09/04 21:39:22 nano Exp $ * @modified 2005-03-26 jamoore add general PlugInPanel type to removeDialog * @modified 2005-03-27 jamoore add vojxta to menus * @modified 2005-04-06 Frank Toennies [nano at jxta dot org]  fixed resize and tree renderer issues, some code refactoring * @modified 2005-03-27 jamoore add vojxta add/remove dialog support * @modified 2005-04-24 jamoore add vijxta add/remove dialog support * @modified 2005-05-01 jamoore enable video only if system property is set */public final class MyJXTAView        extends JXFrame        implements View, PluginContainer.IPopupProvider {// ------------------------------ FIELDS ------------------------------    static final Logger LOG = Logger.getLogger(MyJXTAView.class);    private static final int STATUS_MAX = 15;    private static final String DOT = ".";    private static final ResourceBundle STRINGS = Resources.getStrings();    private MyJXTA myjxta = null;    private JSplitPane split = null;    private JXTreeTable tree = null;    private JxtaTreeModel treeModel = null;    private JDialog searchDialog = null;    private JTabbedPane search = null;    private JDialog shareDialog = null;    private JTabbedPane share = null;    private JTabbedPane plugins = null;    private JTabbedPane m_navigationPane = null;    private DefaultComboBoxModel status = null;    private Action exitAction = null;    private JPopupMenu popup = null; // coconatty    private final Object lock = new Object();    private Dimension m_preferredSize = new Dimension(600, 375);    private ConfigData config = null;    private MenuManager m_menuManager;// --------------------------- CONSTRUCTORS ---------------------------    /**     * Default Constructor     *     * @param p_myjxta     */    public MyJXTAView(MyJXTA p_myjxta) {        super(MyJXTA.NAME);        setControl(p_myjxta);        initialize();    }    private void initialize() {        ui();        pack();        // start the timer that updates the tree        // myjxta.startTimer( new InactiveNodeUpdater(),        //   Env.TREE_UPDATE_PERIOD);    }    private void ui() {        Resources res = Resources.getInstance();        ImageIcon icon = res.getIconResource("Application.Icon");        if (icon != null) {            setIconImage(icon.getImage());        }        buildActions();        buildMenu();        buildUI();    }    private void buildActions() {        this.exitAction = new ExitAction(STRINGS.getString("menu.exit"), this.getControl());    }    private void buildMenu() {        m_menuManager = MenuManager.getInstance(this);        setJMenuBar(m_menuManager.getMenuBar());        //todo: why is it necessary to add the popup menu to the content pane?        getContentPane().add(this.popup =                buildPopupMenu(m_menuManager.getActionMenu().getMenuComponents()));    }    //set up popup menu, and add mouse listener (see internal class popuplistener)    private JPopupMenu buildPopupMenu(Component[] c) {        JPopupMenu jp = new JPopupMenu();        for (int i = 0; i < c.length; i++) {            jp.add(c[i]);        }        return jp;    }    private void buildUI() {        GridBagLayout gb = new GridBagLayout();        GridBagConstraints gbc = new GridBagConstraints();        getContentPane().setLayout(gb);        ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));        //sp.setViewportBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));        gbc.gridx = 0;        gbc.gridy = 0;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.insets = new Insets(3, 3, 3, 3);        gbc.anchor = GridBagConstraints.NORTHWEST;        gbc.weightx = 1.0;        gbc.weighty = 1.0;        gbc.fill = GridBagConstraints.BOTH;        JPanel newLeftComponent = buildNavigation();        JPanel newRightComponent = buildPlugins();        this.split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,                newLeftComponent, newRightComponent);//        this.split.setDividerLocation(0.3);        this.split.setResizeWeight(0.15);        this.split.setOneTouchExpandable(true);        this.split.setDividerSize(8);        gb.setConstraints(this.split, gbc);        getContentPane().add(this.split);        gbc.gridx = 0;        gbc.gridy++;        gbc.anchor = GridBagConstraints.LINE_START;        gbc.weightx = 0.0;        gbc.weighty = 0.0;        gbc.fill = GridBagConstraints.HORIZONTAL;        JPanel fp = buildFooter();        gb.setConstraints(fp, gbc);        getContentPane().add(fp);        addComponentListener(new ComponentAdapter() {            public void componentMoved(ComponentEvent we) {                componentResized(we);            }            public void componentResized(ComponentEvent we) {//                Rectangle b = getBounds();                MyJXTA myJXTA = MyJXTAView.this.getControl();                //nano: myJXTA can be null during the initial setup, so prevent the NPE here                if (myJXTA != null) {                    // todo: persist app size, location, etc//                    p.putInt(Prefs.UI_WIDTH, b.width);//                    p.putInt(Prefs.UI_HEIGHT, b.height);//                    p.putInt(Prefs.UI_X, b.x);//                    p.putInt(Prefs.UI_Y, b.y);                }            }        });        addWindowListener(new WindowAdapter() {            public void windowClosing(WindowEvent we) {                MyJXTAView.this.getExitAction().actionPerformed(null);            }        });        addFocusListener(new FocusListener() {            public void focusGained(FocusEvent fe) {                toFront();            }            public void focusLost(FocusEvent fe) {                // Do nothing            }        });    }    private JPanel buildNavigation() {        JPanel p = new JPanel();        GridBagLayout gb = new GridBagLayout();        GridBagConstraints gbc = new GridBagConstraints();        p.setLayout(gb);        JScrollPane sp = new JScrollPane(this.tree = buildTree());        tree.getSelectionModel().addListSelectionListener(new ListSelectionListener() {            public void valueChanged(ListSelectionEvent arg0) {                m_menuManager.updateMenuStatus();            }        });        tree.getSelectionModel().addListSelectionListener(new ListSelectionListener() {            public void valueChanged(ListSelectionEvent e) {                m_menuManager.updateMenuStatus();            }        });        gbc.gridx = 0;        gbc.gridy = 0;        gbc.gridwidth = GridBagConstraints.REMAINDER;        gbc.gridheight = GridBagConstraints.RELATIVE;        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(sp, gbc);        p.add(sp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -