📄 debug.java
字号:
/* ==================================================================== * Copyright (c) 2001-2003 OYOAHA. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. The names "OYOAHA" must not be used to endorse or promote products * derived from this software without prior written permission. * For written permission, please contact email@oyoaha.com. * * 3. Products derived from this software may not be called "OYOAHA", * nor may "OYOAHA" appear in their name, without prior written * permission. * * 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 OYOAHA 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. */package com.oyoaha.swing.plaf.oyoaha;import java.io.*;import java.net.*;import java.util.*;import java.awt.*;import javax.swing.*;import java.awt.event.*;import javax.swing.plaf.*;import javax.swing.plaf.metal.*;public class Debug extends JFrame implements ActionListener{ private File openDirectory = new File(System.getProperty("user.dir")); private JFrame preview; private JFrame help; private File currentTheme; private MetalTheme currentMetalTheme; private boolean showHelp; private DebugOyoahaConsole debug; private JEditorPane text; public Debug() { debug = new DebugOyoahaConsole();//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- try { OyoahaLookAndFeel look = new DebugOyoahaLookAndFeel(debug); UIManager.setLookAndFeel(look); } catch(Exception e) { e.printStackTrace(); }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- JToolBar bar = new JToolBar(); bar.setFloatable(false); JButton btest = new JButton("Test"); JButton bopen = new JButton("Open a oyoaha theme"); JButton bhelp = new JButton("Help"); btest.setToolTipText("Test oyoaha lookandfeel"); bopen.setToolTipText("Open a oyoaha theme"); bhelp.setToolTipText("Show help"); btest.setName("test"); bopen.setName("open"); bhelp.setName("help"); btest.addActionListener(this); bopen.addActionListener(this); bhelp.addActionListener(this); btest.setVisible(false); bopen.setVisible(false); bhelp.setVisible(false); bar.add(btest); bar.add(bopen); bar.add(bhelp);//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- getContentPane().setLayout(new BorderLayout()); getContentPane().add(bar, BorderLayout.NORTH); getContentPane().add(new JLabel("(c) copyright 2000 oyoaha - http://www.oyoaha.com", SwingConstants.LEFT), BorderLayout.SOUTH); text = new JEditorPane("text/html", "<HTML><HEAD></HEAD><BODY></BODY></HTML>"); text.setEditable(false); JScrollPane scroll = new JScrollPane(text); scroll.setPreferredSize(new Dimension(630,400)); getContentPane().add(scroll, BorderLayout.CENTER); addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); pack(); Dimension d = getSize(); Dimension dim = getToolkit().getScreenSize(); setLocation((dim.width-d.width)/2, (dim.height-d.height)/2); super.setVisible(true);//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- help = new HelpFrame(); Icon icon = null; try { icon = new ImageIcon(getClass().getResource("rc/test.gif")); btest.setIcon(icon); } catch (Exception ex) { } try { icon = new ImageIcon(getClass().getResource("rc/open.gif")); bopen.setIcon(icon); } catch (Exception ex) { } try { icon = new ImageIcon(getClass().getResource("rc/help.gif")); bhelp.setIcon(icon); } catch (Exception ex) { } btest.setVisible(true); bopen.setVisible(true); bhelp.setVisible(true); pack(); d = getSize(); setBounds((dim.width-d.width)/2, (dim.height-d.height)/2, d.width, d.height); } public void actionPerformed(ActionEvent e) { String name = ((Component)e.getSource()).getName(); if(name.equals("test")) test(); else if(name.equals("open")) open(); else if(name.equals("help")) help.setVisible(true); } protected void open() { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ThemeFileFilter()); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); chooser.setCurrentDirectory(openDirectory); int result = chooser.showOpenDialog(null); if(result==JFileChooser.APPROVE_OPTION) { openDirectory = chooser.getCurrentDirectory(); File f = chooser.getSelectedFile(); if(f!=null && f.exists()) { currentTheme = f; if(f==null || !f.exists()) return; setTitle(f.getPath()); } } } public void setVisible(boolean _visible) { if(_visible) { try { MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme()); OyoahaLookAndFeel look = new DebugOyoahaLookAndFeel(debug); UIManager.setLookAndFeel(look); SwingUtilities.updateComponentTreeUI(this); SwingUtilities.updateComponentTreeUI(help); } catch(Exception e) { } if(showHelp) { help.setVisible(true); } text.setText(debug.getText()); } else { help.setVisible(false); } super.setVisible(_visible); } private void test() { if(preview==null) { try { if(currentMetalTheme!=null) { MetalLookAndFeel.setCurrentTheme(currentMetalTheme); } OyoahaLookAndFeel look = new DebugOyoahaLookAndFeel(debug); debug.setText(""); if(currentTheme!=null) look.setOyoahaTheme(currentTheme); UIManager.setLookAndFeel(look); } catch(Exception e) { } preview = new PreviewFrame(this); if(currentTheme!=null) preview.setTitle(currentTheme.getName()); else preview.setTitle("Use default theme"); preview.setVisible(true); } else { try { if(currentMetalTheme!=null) MetalLookAndFeel.setCurrentTheme(currentMetalTheme); OyoahaLookAndFeel look = new DebugOyoahaLookAndFeel(debug); debug.setText(""); if(currentTheme!=null) look.setOyoahaTheme(currentTheme); UIManager.setLookAndFeel(look); SwingUtilities.updateComponentTreeUI(preview); if(currentTheme!=null) preview.setTitle(currentTheme.getName()); else preview.setTitle("Use default theme"); preview.setVisible(true); } catch(Exception e) { } } }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --// MAIN//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- public static void main(String[] arg) { new Debug(); }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --// Inner Class...//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- class HelpFrame extends JFrame { HelpFrame() { super("help"); getContentPane().setLayout(new BorderLayout()); try { URL url = null; String path = null; try { path = "rc/index.html"; url = getClass().getResource(path); } catch (Exception ex1) { url = null; } if(url != null) { JEditorPane html = new JEditorPane(url); html.setEditable(false); //html.addHyperlinkListener(createHyperLinkListener()); JScrollPane scroller = new JScrollPane(); JViewport vp = scroller.getViewport(); vp.add(html); getContentPane().add(scroller, BorderLayout.CENTER); } } catch (Exception ex2) { } addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); showHelp = false; } }); JButton close = new JButton("close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); showHelp = false; } }); JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.RIGHT)); p.add(close); getContentPane().add(p, BorderLayout.SOUTH); pack(); Dimension dim = getToolkit().getScreenSize(); setBounds((dim.width-440)/2, (dim.height-380)/2, 440, 380); } public void setVisible(boolean _visible) { if(!showHelp && _visible) { showHelp = true; } super.setVisible(_visible); } } class PropertiesMetalTheme extends DefaultMetalTheme { private String name = "Custom Theme"; private ColorUIResource primary1; private ColorUIResource primary2; private ColorUIResource primary3; private ColorUIResource secondary1; private ColorUIResource secondary2; private ColorUIResource secondary3; private ColorUIResource black; private ColorUIResource white; protected FontUIResource controlFont; protected FontUIResource systemFont; protected FontUIResource userFont; protected FontUIResource smallFont; private File file; public PropertiesMetalTheme(File _file) { file = _file; initColors(); try { loadProperties(new FileInputStream(file)); } catch(Exception e) { } } public File getFile() { return file; } private void initColors() { primary1 = super.getPrimary1(); primary2 = super.getPrimary2(); primary3 = super.getPrimary3(); secondary1 = super.getSecondary1(); secondary2 = super.getSecondary2(); secondary3 = super.getSecondary3(); black = super.getBlack(); white = super.getWhite(); } private void loadProperties(InputStream stream) { Properties prop = new Properties(); try { prop.load(stream); } catch(IOException e) { } Object tempName = prop.get("name"); if (tempName != null) { name = tempName.toString(); } Object colorString = null; colorString = prop.get("primary1"); if (colorString != null) { primary1 = OyoahaThemeLoaderUtilities.readColor(colorString.toString()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -