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

📄 main.java

📁 java 开源,Swing外观:JGoodies look & feel. ... JGoodies look&feels让你的Swing 应用程序与applets看起来更漂亮.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ==================================================================== * 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.metal.*;import com.oyoaha.swing.plaf.oyoaha.editor.*;public class Main extends JFrame implements ActionListener{  protected File openDirectory = new File(System.getProperty("user.dir"));  protected JFrame preview;  protected JFrame help;  protected JFrame compress;  protected static File currentTheme;  protected static MetalTheme currentMetalTheme;  protected boolean showHelp;  protected boolean showCompress;    protected JTextArea text;  protected JCheckBox brollover;  public Main()  {    if(currentTheme==null)    {      File tmp = new File(System.getProperty("user.dir"), "gradient.otm");      if(tmp.exists())      {        currentTheme = tmp;      }    }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --    try    {      OyoahaLookAndFeel look = new OyoahaLookAndFeel();      UIManager.setLookAndFeel(look);    }    catch(Exception e)    {    }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --    //JToolBar bar = new JToolBar();    //bar.setFloatable(false);    JButton btest = new JButton("Test");    JButton bopen = new JButton("Select a oyoaha theme");    JButton bcompactor = new JButton("Compress");    JButton bhelp = new JButton("Help");    brollover = new JCheckBox("Enabled rollover effect");    brollover.setToolTipText("Enabled rollover effect for button, checkbox, scrollbar...");    brollover.setSelected(true);    btest.setToolTipText("Test oyoaha lookandfeel");    bopen.setToolTipText("Select a oyoaha theme");    bcompactor.setToolTipText("Utility to remove unused features from the oyoaha lookandfeel jar file");    bhelp.setToolTipText("Show help");    btest.setName("test");    bopen.setName("open");    bcompactor.setName("compress");    bhelp.setName("help");    btest.addActionListener(this);    bopen.addActionListener(this);    bcompactor.addActionListener(this);    bhelp.addActionListener(this);    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/compress.gif"));      bcompactor.setIcon(icon);    }    catch (Exception ex)    {    }    try    {      icon = new ImageIcon(getClass().getResource("rc/help.gif"));      bhelp.setIcon(icon);    }    catch (Exception ex)    {    }    JPanel bar = new JPanel();    bar.setLayout(new GridLayout(4,1));    btest.setHorizontalAlignment(SwingConstants.LEFT);    bopen.setHorizontalAlignment(SwingConstants.LEFT);    bcompactor.setHorizontalAlignment(SwingConstants.LEFT);    bhelp.setHorizontalAlignment(SwingConstants.LEFT);    bar.add(btest);    bar.add(bopen);    bar.add(bcompactor);    bar.add(bhelp);//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --    getContentPane().setLayout(new BorderLayout());    getContentPane().add(bar, BorderLayout.CENTER);    getContentPane().add(brollover, BorderLayout.SOUTH);    addWindowListener (new WindowAdapter()    {      public void windowClosing(WindowEvent e)      {        System.exit(0);      }    });    pack();        Dimension dim = getToolkit().getScreenSize();    Dimension d = getSize();        if (d.width>dim.width)    {            d.width = dim.width;    }    if (d.height>dim.height)    {        d.height = dim.height;    }    setBounds((dim.width-d.width)/2, (dim.height-d.height)/2, d.width, d.height);    if(currentTheme==null)    {      super.setVisible(true);    }    else    {      help = null;      compress = null;      test();    }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --    compress = new OyoahaCompactorFrame(false);    help = new HelpFrame();  }  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("compress"))    {        if(compress!=null)        compress.setVisible(true);    }        else    if (name.equals("help"))    {        if(help!=null)        help.setVisible(true);    }      }  protected void open()  {    JFileChooser chooser = new JFileChooser();    chooser.setFileFilter(new ThemeFileFilter());    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);    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;        setTitle(f.getPath());      }    }  }  public void setVisible(boolean _visible)  {    if(_visible)    {      try      {        MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());        OyoahaLookAndFeel look = new OyoahaLookAndFeel();        UIManager.setLookAndFeel(look);        SwingUtilities.updateComponentTreeUI(this);                if(help!=null)        SwingUtilities.updateComponentTreeUI(help);                if(compress!=null)        SwingUtilities.updateComponentTreeUI(compress);      }      catch(Exception e)      {      }      if(help!=null && showHelp)      {        help.setVisible(true);      }            if (compress!=null && showCompress)      {        compress.setVisible(true);      }    }    else    {      if(help!=null)      {        help.setVisible(false);      }            if (compress!=null)      {        showCompress = compress.isVisible();        compress.setVisible(false);      }    }    super.setVisible(_visible);        if (_visible)    {        toFront();    }  }  private void test()  {    if(preview==null)    {      try      {        if(currentMetalTheme!=null)        {          MetalLookAndFeel.setCurrentTheme(currentMetalTheme);        }        OyoahaLookAndFeel look = new OyoahaLookAndFeel(brollover.isSelected());                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);      super.setVisible(false);      preview.toFront();    }    else    {      try      {        if (currentMetalTheme!=null)        {            MetalLookAndFeel.setCurrentTheme(currentMetalTheme);        }                OyoahaLookAndFeel look = new OyoahaLookAndFeel(brollover.isSelected());        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);        super.setVisible(false);        preview.toFront();      }      catch(Exception e)      {      }    }  }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --// MAIN//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  public static void main(String[] arg)  {    if(arg.length>0)    {      File f = new File(arg[0]);      if(f.exists() && f.isFile())      {        if(f.getName().endsWith(".theme"))        currentMetalTheme = new OyoahaMetalTheme(f);        else        currentTheme = f;      }    }    new Main();  }//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --// 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)

⌨️ 快捷键说明

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