?? nimrodmain.java
字號:
/*
* (C) Copyright 2005 Nilo J. Gonzalez
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser Gereral Public Licence as published by the Free
* Software Foundation; either version 2 of the Licence, or (at your opinion) any
* later version.
*
* This library is distributed in the hope that it will be usefull, but WITHOUT ANY
* WARRANTY; without even the implied warranty of merchantability or fitness for a
* particular purpose. See the GNU Lesser General Public Licence for more details.
*
* You should have received a copy of the GNU Lesser General Public Licence along
* with this library; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, Ma 02111-1307 USA.
*
* http://www.gnu.org/licenses/lgpl.html (English)
* http://gugs.sindominio.net/gnu-gpl/lgpl-es.html (Espa?ol)
*
*
* Original author: Nilo J. Gonz?lez
*/
/**
*
*/
package com.nilo.plaf.nimrod;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyVetoException;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.io.*;
import java.util.*;
/**
* This is only a facility to create themes and is poorly coded... Just works.
* @author Nilo J. Gonzalez
*/
public class NimRODMain extends JFrame {
private static final long serialVersionUID = 1L;
public static NimRODLookAndFeel nf;
public static NimRODTheme nt;
private JPanel bP1, bP2, bP3, bS1, bS2, bS3, bB, bW;
private JPanel bSelection, bBackground;
private JButton bOpen, bSave, bPrueba;
private JTextField tNomFich;
private JSlider sMenuOpacidad, sFrameOpacidad;
private JProgressBar pb3, pb4;
private JSpinner sp;
private JToolBar toolBar;
private JDesktopPane desktop;
private JPanel pConfig, pView1, pView2, pView3, pView4, pView5;
private JMenuBar menuBar;
private JTabbedPane tabPan;
private static int pos = 0;
NimRODMain() {
super( "NimROD Look&Feel Theme Configuration");
menuBar = new JMenuBar();
hazMenuBar();
setJMenuBar( menuBar);
hazConfig();
hazPreview1();
hazPreview2();
hazPreview3();
hazPreview4();
hazPreview5();
hazToolBar();
tabPan = new JTabbedPane();
tabPan.add( "Config", pConfig);
tabPan.add( "Preview 1", pView1);
tabPan.add( "Preview 2", pView2);
tabPan.add( "Preview 3", pView3);
tabPan.add( "Preview 4", pView4);
tabPan.add( "Preview 5", pView5);
getContentPane().add( toolBar, BorderLayout.PAGE_START);
getContentPane().add( tabPan, BorderLayout.CENTER);
addWindowListener( new MiWL());
setSize( 390,470);
setVisible( true);
}
private void hazToolBar() {
toolBar = new JToolBar( "ToolBar, you know...");
toolBar.add( new JButton( UIManager.getIcon( "FileView.floppyDriveIcon")));
toolBar.add( new JButton( UIManager.getIcon( "Tree.closedIcon")));
toolBar.addSeparator();
toolBar.add( new JToggleButton( UIManager.getIcon( "Tree.openIcon")));
}
private void hazMenuBar() {
JMenu menuTabs = new JMenu( "Tabs");
menuBar.add( menuTabs);
JMenuItem menuItem = new JMenuItem( "Top");
menuItem.addActionListener( new MiTL());
menuTabs.add( menuItem);
menuItem = new JMenuItem( "Bottom");
menuItem.addActionListener( new MiTL());
menuTabs.add( menuItem);
menuItem = new JMenuItem( "Left");
menuItem.addActionListener( new MiTL());
menuTabs.add( menuItem);
menuItem = new JMenuItem( "Right");
menuItem.addActionListener( new MiTL());
menuTabs.add( menuItem);
JMenu menuOtro = new JMenu( "Menu");
menuBar.add( menuOtro);
menuItem = new JMenuItem( "One item");
menuItem.setMnemonic( KeyEvent.VK_O);
menuOtro.add( menuItem);
menuItem = new JMenuItem( "Not enabled");
menuItem.setMnemonic( KeyEvent.VK_E);
menuItem.setEnabled( false);
menuOtro.add( menuItem);
menuItem = new JMenuItem( "Other item");
menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_4, ActionEvent.ALT_MASK));
menuOtro.add( menuItem);
menuItem = new JMenuItem( "Other Not enabled");
menuItem.setEnabled( false);
menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_5, ActionEvent.ALT_MASK));
menuOtro.add( menuItem);
ButtonGroup group = new ButtonGroup();
JRadioButtonMenuItem rbMi = new JRadioButtonMenuItem( "Cats", true);
rbMi.setMnemonic( KeyEvent.VK_G);
group.add( rbMi);
menuOtro.add( rbMi);
rbMi = new JRadioButtonMenuItem( "Dogs");
rbMi.setMnemonic( KeyEvent.VK_P);
rbMi.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_P, ActionEvent.CTRL_MASK));
group.add( rbMi);
menuOtro.add( rbMi);
rbMi = new JRadioButtonMenuItem( "Birds", true);
rbMi.setEnabled( false);
rbMi.setMnemonic( KeyEvent.VK_E);
group.add( rbMi);
menuOtro.add( rbMi);
rbMi = new JRadioButtonMenuItem( "Elephants");
rbMi.setEnabled( false);
rbMi.setMnemonic( KeyEvent.VK_V);
rbMi.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_V, ActionEvent.CTRL_MASK));
group.add( rbMi);
menuOtro.add( rbMi);
menuOtro.addSeparator();
JCheckBoxMenuItem cbMi = new JCheckBoxMenuItem( "Eat", true);
cbMi.setMnemonic( KeyEvent.VK_C);
menuOtro.add( cbMi);
cbMi = new JCheckBoxMenuItem( "Drink", false);
cbMi.setMnemonic( KeyEvent.VK_B);
cbMi.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_B, ActionEvent.CTRL_MASK));
menuOtro.add( cbMi);
cbMi = new JCheckBoxMenuItem( "Walk", true);
cbMi.setEnabled( false);
cbMi.setMnemonic( KeyEvent.VK_R);
menuOtro.add( cbMi);
cbMi = new JCheckBoxMenuItem( "Look", false);
cbMi.setEnabled( false);
cbMi.setMnemonic( KeyEvent.VK_M);
cbMi.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_M, ActionEvent.CTRL_MASK));
menuOtro.add( cbMi);
menuOtro.addSeparator();
JMenu submenu = new JMenu( "A submenu");
submenu.setMnemonic( KeyEvent.VK_S);
menuItem = new JMenuItem( "An item in the submenu");
menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_2, ActionEvent.ALT_MASK));
submenu.add( menuItem);
menuItem = new JMenuItem( "Another item");
submenu.add( menuItem);
menuItem = new JMenuItem( "Not enabled");
menuItem.setEnabled( false);
submenu.add( menuItem);
menuItem = new JMenuItem( "Not enabled, too");
menuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_3, ActionEvent.ALT_MASK));
menuItem.setEnabled( false);
submenu.add( menuItem);
menuOtro.add( submenu);
JMenu masMenus = new JMenu( "Not enabled");
masMenus.setEnabled( false);
menuBar.add( masMenus);
}
private void hazConfig() {
// Para abrir y guardar
tNomFich = new JTextField( 20);
tNomFich.setEditable( false);
bOpen = new JButton( "Open");
bOpen.addActionListener( new MiAL());
bOpen.setToolTipText( "Open theme files");
bSave = new JButton( "Save");
bSave.setToolTipText( "Save theme files");
bSave.addActionListener( new MiAL());
JPanel pAlto = new JPanel( new FlowLayout());
pAlto.add( tNomFich);
pAlto.add( bOpen);
pAlto.add( bSave);
MiML ml = new MiML();
// Para los colores de seleccion
bSelection = hazPanel( ml);
bP1 = hazPanel( ml);
bP2 = hazPanel( ml);
bP3 = hazPanel( ml);
JPanel pSel = new JPanel( new GridLayout( 1,5, 3,3));
pSel.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Selection"));
pSel.add( bSelection);
pSel.add( new JLabel());
pSel.add( bP1);
pSel.add( bP2);
pSel.add( bP3);
// Para los colores de fondo
bBackground = hazPanel( ml);
bS1 = hazPanel( ml);
bS2 = hazPanel( ml);
bS3 = hazPanel( ml);
JPanel pFon = new JPanel( new GridLayout( 1,5, 3,3));
pFon.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Background"));
pFon.add( bBackground);
pFon.add( new JLabel());
pFon.add( bS1);
pFon.add( bS2);
pFon.add( bS3);
bB = hazPanel( ml);
bW = hazPanel( ml);
JPanel pBW = new JPanel( new GridLayout( 1,2, 3,3));
pBW.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Black & White"));
pBW.add( bB);
pBW.add( bW);
bPrueba = new JButton( "Test");
bPrueba.setToolTipText( "Test current selection");
bPrueba.addActionListener( new MiAL());
JPanel pMenuOp = new JPanel();
pMenuOp.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Menu Opacity"));
sMenuOpacidad = new JSlider( SwingConstants.HORIZONTAL, 0, 255, nt.getMenuOpacity());
pMenuOp.add( sMenuOpacidad);
JPanel pFrameOp = new JPanel();
pFrameOp.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), "Internal Frame Opacity"));
sFrameOpacidad = new JSlider( SwingConstants.HORIZONTAL, 0, 255, nt.getFrameOpacity());
pFrameOp.add( sFrameOpacidad);
hazPaleta();
pConfig = new JPanel( new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets( 5,5,5,5);
c.gridwidth = 2;
c.gridx = 0; c.gridy = 0;
pConfig.add( pAlto, c);
c.gridwidth = 1;
c.gridx = 0; c.gridy = 1;
pConfig.add( pSel, c);
c.gridx = 1; c.gridy = 1;
pConfig.add( pBW, c);
c.gridx = 0; c.gridy = 2;
pConfig.add( pFon, c);
c.fill = GridBagConstraints.BOTH;
c.gridx = 1; c.gridy = 2;
pConfig.add( bPrueba, c);
c.gridwidth = 2;
c.gridx = 0; c.gridy = 3;
pConfig.add( pMenuOp, c);
c.gridy = 4;
pConfig.add( pFrameOp, c);
}
private JPanel hazPanel( MouseAdapter ml) {
JPanel pan = new JPanel();
pan.setPreferredSize( new Dimension( 40,40));
pan.addMouseListener( ml);
pan.setBorder( BorderFactory.createEtchedBorder());
return pan;
}
private void hazPaleta() {
bSelection.setBackground( nt.getPrimary3());
bP1.setBackground( nt.getPrimary1());
bP2.setBackground( nt.getPrimary2());
bP3.setBackground( nt.getPrimary3());
bBackground.setBackground( nt.getSecondary3());
bS1.setBackground( nt.getSecondary1());
bS2.setBackground( nt.getSecondary2());
bS3.setBackground( nt.getSecondary3());
bB.setBackground( nt.getBlack());
bW.setBackground( nt.getWhite());
sMenuOpacidad.setValue( nt.getMenuOpacity());
sFrameOpacidad.setValue( nt.getFrameOpacity());
}
private void hazPreview1() {
JPanel fondo = new JPanel();
fondo.setLayout( new BoxLayout( fondo, BoxLayout.X_AXIS));
JPanel p1 = new JPanel();
p1.setLayout( new BoxLayout( p1, BoxLayout.Y_AXIS));
p1.add( new JCheckBox( "Checkbox 1"));
JCheckBox cbi = new JCheckBox( "Checkbox 2");
cbi.setEnabled( false);
p1.add( cbi);
p1.add( new JRadioButton( "Radio 1"));
JRadioButton rbi = new JRadioButton( "Radio 2");
rbi.setEnabled( false);
p1.add( rbi);
p1.add( new JButton( "Button 1"));
p1.add( new JToggleButton( "ToggleButton"));
JButton bi = new JButton( "Inactive");
bi.setEnabled( false);
p1.add( bi);
p1.add( Box.createVerticalGlue());
Vector v = new Vector();
for ( int i = 0; i < 30; i++) {
v.add( "Option " + i);
}
JPanel p2 = new JPanel();
p2.setLayout( new BoxLayout( p2, BoxLayout.Y_AXIS));
JComboBox cb = new JComboBox( v);
cb.setMaximumSize( new Dimension( 400, cb.getPreferredSize().height));
p2.add( cb);
p2.add( Box.createRigidArea( new Dimension( 10,10)));
JComboBox cb2 = new JComboBox( v);
cb2.setMaximumSize( new Dimension( 400, cb.getPreferredSize().height));
cb2.setEditable( true);
p2.add( cb2);
p2.add( Box.createRigidArea( new Dimension( 10,10)));
JComboBox cb3 = new JComboBox();
cb3.addItem( "Option 1");
cb3.addItem( "Option 2");
cb3.addItem( "Option 3");
cb3.addItem( "Option 4");
cb3.setMaximumRowCount( 7);
cb3.setMaximumSize( new Dimension( 400, cb.getPreferredSize().height));
cb3.setEditable( true);
p2.add( cb3);
p2.add( Box.createRigidArea( new Dimension( 10,10)));
JList list = new JList( v);
JScrollPane scrPan = new JScrollPane( list);
scrPan.setPreferredSize( new Dimension( 200,80));
p2.add( scrPan);
fondo.add( p1);
fondo.add( p2);
JPanel bots = new JPanel( new FlowLayout());
JButton b = new JButton( UIManager.getIcon( "OptionPane.errorIcon"));
b.addActionListener( new ActionListener() {
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -