📄 main.java
字号:
{ 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(); Dimension d = new Dimension(440, 380); 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); } public void setVisible(boolean _visible) { if(!showHelp && _visible) { showHelp = true; } super.setVisible(_visible); } } protected void forceRepaintAfterDialog() { repaint(); } class PreviewFrame extends JFrame implements ActionListener { private JFrame parent; private JTabbedPane tabbedPane; private DemoPanel demo; private JColorChooser colorChooser; PreviewFrame(JFrame _parent) { parent = _parent; demo = new DemoPanel(); tabbedPane = demo.getTabbedPane(); //-------- JMenuBar menuBar = new JMenuBar(); menuBar.setOpaque(true); try { File file = new File(System.getProperty("user.dir"), "metal"); if(file.exists() && file.isDirectory()) { String list[] = file.list(); Vector themes = new Vector(); themes.addElement(new DefaultMetalTheme()); for(int i=0;i<list.length;i++) { if(list[i].endsWith(".theme")) themes.addElement(new OyoahaMetalTheme(new File(file, list[i]))); } JMenu themeMenu = new MetalThemeMenu("MetalTheme", themes); menuBar.add(themeMenu); } } catch (Exception e) { } JMenu tabbedPane = new JMenu("TabbedPane"); JMenuItem top = new JCheckBoxMenuItem("TabbedPane.top"); JMenuItem left = new JCheckBoxMenuItem("TabbedPane.left"); JMenuItem bottom = new JCheckBoxMenuItem("TabbedPane.bottom"); JMenuItem right = new JCheckBoxMenuItem("TabbedPane.right"); top.setName("top"); left.setName("left"); bottom.setName("bottom"); right.setName("right"); ButtonGroup group = new ButtonGroup(); group.add(top); group.add(bottom); group.add(left); group.add(right); top.setSelected(true); top.addActionListener(this); bottom.addActionListener(this); left.addActionListener(this); right.addActionListener(this); tabbedPane.add(top); tabbedPane.add(left); tabbedPane.add(bottom); tabbedPane.add(right); colorChooser = new JColorChooser(); menuBar.add(tabbedPane); JMenu dialog = new JMenu("OptionPane"); JMenuItem color = new JMenuItem("ColorChooser..."); JMenuItem file = new JMenuItem("FileChooser..."); JMenuItem info = new JMenuItem("Information Dialog..."); JMenuItem question = new JMenuItem("Question Dialog..."); JMenuItem warning = new JMenuItem("Warning Dialog..."); JMenuItem error = new JMenuItem("Error Dialog..."); color.setName("color"); file.setName("file"); info.setName("info"); question.setName("question"); warning.setName("warning"); error.setName("error"); color.addActionListener(this); file.addActionListener(this); info.addActionListener(this); question.addActionListener(this); warning.addActionListener(this); error.addActionListener(this); dialog.add(color); dialog.add(file); dialog.addSeparator(); dialog.add(info); dialog.add(question); dialog.add(warning); dialog.add(error); menuBar.add(dialog); setJMenuBar(menuBar); //-------- getContentPane().setLayout(new BorderLayout()); getContentPane().add(demo, BorderLayout.CENTER); addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent e) { setVisible(false); } }); JCheckBox enabledComponent = new JCheckBox("Disable components"); enabledComponent.addActionListener(this); JButton close = new JButton("close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.RIGHT)); p.add(enabledComponent); p.add(close); getContentPane().add(p, BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { Object o = e.getSource(); String name = ((Component)o).getName(); if (o instanceof JCheckBox) { demo.setEnabled(!((JCheckBox)o).isSelected()); } else if(o instanceof JCheckBoxMenuItem) { if(name.equalsIgnoreCase("top")) { tabbedPane.setTabPlacement(JTabbedPane.TOP); } else if(name.equalsIgnoreCase("left")) { tabbedPane.setTabPlacement(JTabbedPane.LEFT); } else if(name.equalsIgnoreCase("bottom")) { tabbedPane.setTabPlacement(JTabbedPane.BOTTOM); } else if(name.equalsIgnoreCase("right")) { tabbedPane.setTabPlacement(JTabbedPane.RIGHT); } pack(); } else { if(name.equalsIgnoreCase("color")) { Color tmp = JColorChooser.showDialog(this, "Color chooser", Color.pink); if(tmp!=null) { demo.setColor(tmp); } forceRepaintAfterDialog(); } else if(name.equalsIgnoreCase("file")) { JFileChooser fileChooser = new JFileChooser(); int result = fileChooser.showOpenDialog(this); if(result==JFileChooser.APPROVE_OPTION) { File tmp = fileChooser.getSelectedFile(); if(tmp==null || !tmp.exists() || tmp.isDirectory()) { return; } String tmpname = tmp.getName().toLowerCase(); if(tmpname.endsWith(".gif") || tmpname.endsWith(".jpeg") || tmpname.endsWith(".jpg")) { demo.openImage(tmp.getPath()); } } forceRepaintAfterDialog(); } else if(name.equalsIgnoreCase("question")) { JOptionPane.showMessageDialog(this, "This a question message", "question", JOptionPane.QUESTION_MESSAGE); } else if(name.equalsIgnoreCase("warning")) { JOptionPane.showMessageDialog(this, "This a warning message", "warning", JOptionPane.WARNING_MESSAGE); } else if(name.equalsIgnoreCase("error")) { JOptionPane.showMessageDialog(this, "This a error message", "error", JOptionPane.ERROR_MESSAGE); } else if(name.equalsIgnoreCase("info")) { JOptionPane.showMessageDialog(this, "This a information message", "information", JOptionPane.INFORMATION_MESSAGE); } } } public void setVisible(boolean _visible) { parent.setVisible(!_visible); if(_visible) { pack(); } if (_visible) { toFront(); demo.updateLnFInformation(); } super.setVisible(_visible); } public void pack() { super.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); } } class MetalThemeMenu extends JMenu implements ActionListener { protected Object[] themes; public MetalThemeMenu(String name, Vector themeArray) { super(name); themes = new Object[themeArray.size()]; themeArray.copyInto(themes); ButtonGroup group = new ButtonGroup(); for(int i = 0; i < themes.length; i++) { JRadioButtonMenuItem item = new JRadioButtonMenuItem(((MetalTheme)themes[i]).getName() ); group.add(item); add( item ); item.setActionCommand(i+""); item.addActionListener(this); if(i==0) { item.setSelected(true); } } } public void actionPerformed(ActionEvent e) { String numStr = e.getActionCommand(); currentMetalTheme = (MetalTheme)themes[Integer.parseInt(numStr)]; try { MetalLookAndFeel.setCurrentTheme(currentMetalTheme); OyoahaLookAndFeel look = new OyoahaLookAndFeel(); if(currentTheme!=null) look.setOyoahaTheme(currentTheme); UIManager.setLookAndFeel(look); SwingUtilities.updateComponentTreeUI(preview); preview.pack(); preview.setVisible(true); } catch(Exception ex) { } } } protected class ThemeFileFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File _file) { if(_file.isDirectory()) { return true; } String name = _file.getName(); if(name.endsWith(".zotm")) { return true; } return false; } public String getDescription() { return "OyoahaTheme"; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -