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

📄 swingxdemotp.java

📁 java实现浏览器等本地桌面的功能
💻 JAVA
字号:
/* * $Id: SwingXDemoTP.java,v 1.10 2005/06/16 14:10:41 kleopatra Exp $ * * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. */package org.jdesktop.demo.swingx_dev;import java.io.File;import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Vector;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.AbstractListModel;import javax.swing.DefaultComboBoxModel;import javax.swing.JFrame;import javax.swing.SwingUtilities;import javax.swing.UIManager;import org.jdesktop.demo.DemoPanel;import org.jdesktop.demo.MainWindow;import com.jgoodies.looks.LookUtils;import java.net.URL;import javax.swing.JEditorPane;/** * A JPanel that demonstrates the use of various SwingX components, intended for * developers, as some components may not work correctly or may be used in experimental * contexts. Each SwingX Component is shown in its own independent panel, and the user * can navigate between the different demos from a list. * * @author  rbair */public class SwingXDemoTP extends DemoPanel {    private Logger LOG = Logger.getLogger(SwingXDemoTP.class.getName());        /** A List of each component we're demonstrating--all of which are DemoPanel     * instances. */    private List<DemoPanel> demoPanels = new ArrayList<DemoPanel>();        /**     * Creates new form SwingXDemo     */    public SwingXDemoTP() {        demoPanels.add(new JXChooserDemoPanel());                initComponents();        descriptionPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);        infoTaskPane.setAnimated(false);        demoTaskPane.setAnimated(false);        howToTaskPane.setAnimated(false);                // JGoodies: next line is necessary if running in webstart        UIManager.put("ClassLoader", LookUtils.class.getClassLoader());                LinkedHashMap lnf = new LinkedHashMap();        lnf.put("Metal", "javax.swing.plaf.metal.MetalLookAndFeel");        lnf.put("Motif", "com.sun.java.swing.plaf.motif.MotifLookAndFeel");        lnf.put("Windows", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");        lnf.put("Ocean", "plasticxp");        lnf.put("{platform}", UIManager.getSystemLookAndFeelClassName());        lnf.put("{cross-platform}", UIManager.getCrossPlatformLookAndFeelClassName());                lnf.put("JGoodies Windows", "com.jgoodies.looks.windows.WindowsLookAndFeel");        lnf.put("JGoodies Plastic", "com.jgoodies.looks.plastic.PlasticLookAndFeel");        lnf.put("JGoodies Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");        lnf.put("JGoodies Plastic 3D", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel");        lnf.put("Kunststoff", "com.incors.plaf.kunststoff.KunststoffLookAndFeel");        lnf.put("Liquid", "com.birosoft.liquid.LiquidLookAndFeel");        lnf.put("Napkin", "napkin.NapkinLookAndFeel");        lnf.put("Substance", "org.jvnet.substance.SubstanceLookAndFeel");        lnfList.setModel(new MappedComboBoxModel(lnf));        lnfList.setSelectedItem("{platform}");        changePLAF();    }        private static Logger getLogger() { return Logger.getLogger(SwingXDemoTP.class.getName()); }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        java.awt.GridBagConstraints gridBagConstraints;        jSplitPane1 = new javax.swing.JSplitPane();        jXTitledPanel3 = new org.jdesktop.swingx.JXTitledPanel();        jScrollPane1 = new javax.swing.JScrollPane();        demoList = new javax.swing.JList();        jXTaskPaneContainer1 = new org.jdesktop.swingx.JXTaskPaneContainer();        infoTaskPane = new org.jdesktop.swingx.JXTaskPane();        jScrollPane3 = new javax.swing.JScrollPane();        descriptionPane = new org.jdesktop.swingx.JXEditorPane();        demoTaskPane = new org.jdesktop.swingx.JXTaskPane();        howToTaskPane = new org.jdesktop.swingx.JXTaskPane();        jScrollPane2 = new javax.swing.JScrollPane();        howToDisplay = new org.jdesktop.swingx.JXEditorPane();        jPanel1 = new javax.swing.JPanel();        jLabel1 = new javax.swing.JLabel();        lnfList = new javax.swing.JComboBox();        applyLnF = new javax.swing.JButton();        priorPLAF = new javax.swing.JButton();        nextPLAF = new javax.swing.JButton();        setLayout(new java.awt.GridBagLayout());        jSplitPane1.setBorder(null);        jSplitPane1.setDividerLocation(200);        jXTitledPanel3.getContentContainer().setLayout(new java.awt.BorderLayout());        jXTitledPanel3.setTitle("Table of Contents");        jScrollPane1.setBorder(null);        demoList.setModel(new AbstractListModel() {            public Object getElementAt(int index) {                return demoPanels.get(index).getName();            }            public int getSize() {                return demoPanels.size();            }        });        demoList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);        demoList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {                demoListValueChanged(evt);            }        });        jScrollPane1.setViewportView(demoList);        jXTitledPanel3.getContentContainer().add(jScrollPane1, java.awt.BorderLayout.CENTER);        jSplitPane1.setLeftComponent(jXTitledPanel3);        infoTaskPane.setTitle("Information");        descriptionPane.setContentType("text/html");        jScrollPane3.setViewportView(descriptionPane);        infoTaskPane.getContentPane().add(jScrollPane3);        jXTaskPaneContainer1.add(infoTaskPane);        demoTaskPane.setTitle("Demo");        jXTaskPaneContainer1.add(demoTaskPane);        howToTaskPane.setExpanded(false);        howToTaskPane.setTitle("How-To");        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);        howToDisplay.setEditable(false);        howToDisplay.setContentType("text/html");        jScrollPane2.setViewportView(howToDisplay);        howToTaskPane.getContentPane().add(jScrollPane2);        jXTaskPaneContainer1.add(howToTaskPane);        jSplitPane1.setRightComponent(jXTaskPaneContainer1);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 0;        gridBagConstraints.gridwidth = 2;        gridBagConstraints.gridheight = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;        gridBagConstraints.weightx = 1.0;        gridBagConstraints.weighty = 1.0;        gridBagConstraints.insets = new java.awt.Insets(12, 12, 17, 11);        add(jSplitPane1, gridBagConstraints);        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));        jLabel1.setText("Look and Feel:");        jPanel1.add(jLabel1);        jPanel1.add(lnfList);        applyLnF.setMnemonic('A');        applyLnF.setText("Apply");        applyLnF.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                applyLnFActionPerformed(evt);            }        });        jPanel1.add(applyLnF);        priorPLAF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/toolbarButtonGraphics/navigation/Back16.gif")));        priorPLAF.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                priorPLAFActionPerformed(evt);            }        });        jPanel1.add(priorPLAF);        nextPLAF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/toolbarButtonGraphics/navigation/Forward16.gif")));        nextPLAF.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                nextPLAFActionPerformed(evt);            }        });        jPanel1.add(nextPLAF);        gridBagConstraints = new java.awt.GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 2;        gridBagConstraints.gridwidth = 2;        gridBagConstraints.gridheight = 2;        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;        gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);        add(jPanel1, gridBagConstraints);    }    // </editor-fold>//GEN-END:initComponents        private void priorPLAFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_priorPLAFActionPerformed        int prior = lnfList.getSelectedIndex() - 1;        prior = ( prior < 0 ? lnfList.getItemCount() - 1 : prior );        lnfList.setSelectedIndex(prior);        changePLAF();    }//GEN-LAST:event_priorPLAFActionPerformed        private void nextPLAFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextPLAFActionPerformed        int next = lnfList.getSelectedIndex() + 1;        next = ( next == lnfList.getItemCount() ? 0 : next );        lnfList.setSelectedIndex(next);        changePLAF();    }//GEN-LAST:event_nextPLAFActionPerformed        private void applyLnFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyLnFActionPerformed        changePLAF();    }//GEN-LAST:event_applyLnFActionPerformed        private void changePLAF() {        MappedComboBoxModel map = (MappedComboBoxModel)lnfList.getModel();        final String newLNF = (String)map.getValueForSelection();        final JFrame frame = (JFrame)SwingUtilities.getWindowAncestor(this);                SwingUtilities.invokeLater( new Runnable() {            public void run() {                try {                    UIManager.setLookAndFeel(newLNF);                    if ( frame != null ) {                        SwingUtilities.updateComponentTreeUI(frame);                        LOG.info("Look and feel changed to " + newLNF);                    }                } catch ( Exception x ) {                    LOG.warning("Could not change look and feel to '" + newLNF + "': " + x.getMessage());                }            }        });    }        private void demoListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_demoListValueChanged        DemoPanel dp = demoPanels.get(demoList.getSelectedIndex());        descriptionPane.setText(dp.getHtmlDescription());                SwingUtilities.invokeLater( new Runnable() {            public void run() {                try {                    URL img = getClass().getResource("/org/jdesktop/demo/swingx/resources/duke_point.gif");                    if ( img == null ) System.out.println("No images");                    new javax.swing.ImageIcon(getClass().getResource("/org/jdesktop/demo/swingx/resources/duke_point.gif"));                    URL url = getClass().getResource("/org/jdesktop/demo/swingx_dev/resources/howto.html");                    if ( url == null )                        System.out.println("Can't find resource");                    System.out.println("URL " + url);                    howToDisplay.setPage(url);                } catch ( Exception e ) {                    e.printStackTrace();                    howToDisplay.setText("<html><body><p>Sorry! No how-to is available for this component.</p></body></html>");                }            }});            demoTaskPane.add(dp.getContent());            SwingUtilities.updateComponentTreeUI(dp.getContent());            demoTaskPane.revalidate();            demoTaskPane.repaint();                        // In the regular SwingX demo, the right component is a titled panel, and            // we just set contents on that panel--but that doesn't work if we also want            // to change the plaf dynamically--looks like a titled panel bug (PW 12/05/05)//        jSplitPane2.setRightComponent(dp.getContents());//        SwingUtilities.updateComponentTreeUI(dp.getContents());//        jSplitPane2.resetToPreferredSizes();                }//GEN-LAST:event_demoListValueChanged        /**     * @param args the command line arguments     */    public static void main(String args[])  {        try {            MainWindow.main(new String[]{"-d", SwingXDemoTP.class.getName()});        } catch ( Exception e ) {            SwingXDemoTP.getLogger().log(Level.WARNING, "Could not launch demo window and pluggable panel.", e);        }    }        public java.io.File getSourceRootDir() {        try {            LOG.info("Source root directory: " + getClass().getResource("/sources"));            return new File(getClass().getResource("/sources").toURI());        } catch (Exception e) {            LOG.log(Level.WARNING, "Could not determine source code root directory", e);            return null;        }    }        public javax.swing.Icon getIcon() {        return null;    }        public java.awt.Container getContent() {        return this;    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton applyLnF;    private javax.swing.JList demoList;    private org.jdesktop.swingx.JXTaskPane demoTaskPane;    private org.jdesktop.swingx.JXEditorPane descriptionPane;    private org.jdesktop.swingx.JXEditorPane howToDisplay;    private org.jdesktop.swingx.JXTaskPane howToTaskPane;    private org.jdesktop.swingx.JXTaskPane infoTaskPane;    private javax.swing.JLabel jLabel1;    private javax.swing.JPanel jPanel1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JScrollPane jScrollPane3;    private javax.swing.JSplitPane jSplitPane1;    private org.jdesktop.swingx.JXTaskPaneContainer jXTaskPaneContainer1;    private org.jdesktop.swingx.JXTitledPanel jXTitledPanel3;    private javax.swing.JComboBox lnfList;    private javax.swing.JButton nextPLAF;    private javax.swing.JButton priorPLAF;    // End of variables declaration//GEN-END:variables    class MappedComboBoxModel extends DefaultComboBoxModel {        private LinkedHashMap data;                MappedComboBoxModel(LinkedHashMap data) {            super(new Vector(data.keySet()));            this.data = data;        }                public Object getValueForSelection() {            return data.get(getSelectedItem());        }    }}

⌨️ 快捷键说明

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