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

📄 nimrodmain.java

📁 NimROD L&F是一个具有多种主题的Swing皮肤
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      public void actionPerformed( ActionEvent ev) {
        JOptionPane.showMessageDialog( NimRODMain.this, "Eggs aren't supposed to be green.", "Inane warning", JOptionPane.ERROR_MESSAGE);
      }});
    bots.add( b);
    
    b = new JButton( UIManager.getIcon( "OptionPane.informationIcon"));
    b.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent ev) {
        JOptionPane.showMessageDialog( NimRODMain.this, "Eggs aren't supposed to be green.", "Inane warning", JOptionPane.INFORMATION_MESSAGE);
      }});
    bots.add( b);
    
    b = new JButton( UIManager.getIcon( "OptionPane.warningIcon"));
    b.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent ev) {
        JOptionPane.showMessageDialog( NimRODMain.this, "Eggs aren't supposed to be green.", "Inane warning", JOptionPane.WARNING_MESSAGE);
      }});
    bots.add( b);
    
    b = new JButton( UIManager.getIcon( "OptionPane.questionIcon"));
    b.addActionListener( new ActionListener() {
      public void actionPerformed( ActionEvent ev) {
        JOptionPane.showMessageDialog( NimRODMain.this, "Eggs aren't supposed to be green.", "Inane warning", JOptionPane.QUESTION_MESSAGE);
      }});
    bots.add( b);
    
    pView1 = new JPanel( new BorderLayout());
    pView1.add( fondo, BorderLayout.CENTER);
    pView1.add( bots, BorderLayout.SOUTH);
  }
  
  private void hazPreview2() {
    pView2 = new JPanel( new BorderLayout( 10,10));
    
    DefaultMutableTreeNode root = new DefaultMutableTreeNode( "Raiz");
    root.add( new DefaultMutableTreeNode( "Alfa"));
    root.add( new DefaultMutableTreeNode( "Beta"));
    root.add( new DefaultMutableTreeNode( "Gamma"));
    
    DefaultMutableTreeNode next = new DefaultMutableTreeNode( "Iota");
    root.add( next);
    
    next.add( new DefaultMutableTreeNode( "Iota-Alfa"));
    next.add( new DefaultMutableTreeNode( "Iota-Beta"));
    next.add( new DefaultMutableTreeNode( "Iota-Gamma"));
    
    next = new DefaultMutableTreeNode( "Kappa");
    root.add( next);
    
    next.add( new DefaultMutableTreeNode( "Kappa-Alfa"));
    next.add( new DefaultMutableTreeNode( "Kappa-Beta"));
    next.add( new DefaultMutableTreeNode( "Kappa-Gamma"));
    
    next = new DefaultMutableTreeNode( "Xi");
    root.add( next);
    
    next.add( new DefaultMutableTreeNode( "Xi-Alfa"));
    next.add( new DefaultMutableTreeNode( "Xi-Beta"));
    next.add( new DefaultMutableTreeNode( "Xi-Gamma"));
    
    DefaultMutableTreeNode renext = new DefaultMutableTreeNode( "Rho");
    next.add( renext);
    
    renext.add( new DefaultMutableTreeNode( "Rho-Alfa"));
    renext.add( new DefaultMutableTreeNode( "Rho-Beta"));
    renext.add( new DefaultMutableTreeNode( "Rho-Gamma"));
    
    JTree arb = new JTree( root);
    JScrollPane treeView = new JScrollPane( arb);
    
    JTable tabla = new JTable( 15, 4);
    JScrollPane scrPan = new JScrollPane( tabla);
    
    pView2.add( treeView, BorderLayout.WEST);
    pView2.add( scrPan, BorderLayout.CENTER);
  }
  
  private void hazPreview3() {
    pView3 = new JPanel( new BorderLayout( 0, 10));
    
    JPanel p1 = new JPanel( new GridLayout( 2,3, 5,1));
    p1.add( new JLabel( "JTextField"));
    p1.add( new JLabel( "JTextField disabled"));
    p1.add( new JLabel( "JPasswordField"));
    p1.add( new JTextField( 15));
    JTextField tf = new JTextField( "Disabled");
    tf.setEnabled( false);
    p1.add( tf);
    p1.add( new JPasswordField( 15));
    
    JTextArea text = new JTextArea( "e\nasd\nasd\nads\nasd\nasdaaaaaaaaaaaaaaaaaa\n\n\n\n\n\n\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae\nasd\nasd\nads\nasd\nasdaaaaa\naaaaaaa\naaaaaaaaa\naaaaaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaaaaaaaaa\naaaaaaaaaaaa\naaaaa");
    JScrollPane scrPan = new JScrollPane( text);
    scrPan.setPreferredSize( new Dimension( 300,320));
    
    pView3.add( p1, BorderLayout.NORTH);
    pView3.add( scrPan, BorderLayout.CENTER);
  }
  
  private void hazPreview4() {
    pView4 = new JPanel( new BorderLayout(3,3));
    
    desktop = new JDesktopPane();
    desktop.setBorder( BorderFactory.createEtchedBorder());
    
    JButton bAdd = new JButton( "Add InternalFrame");
    bAdd.addActionListener( new MiFL());
    pView4.add( bAdd, BorderLayout.NORTH);
    pView4.add( desktop, BorderLayout.CENTER);
    
    JPanel pp = new JPanel(new BorderLayout());
    pp.add( new JLabel( "If you like the icons, here they are..."), BorderLayout.NORTH);
    pp.add( new JTextField( "http://www.kde-look.org/content/show.php/Alien+OSX?content=53829"), BorderLayout.CENTER);
    
    pView4.add( pp, BorderLayout.SOUTH);
  }
  
  private void hazPreview5() {
    JProgressBar pb1 = new JProgressBar( 0, 100);
    pb1.setValue( 0);
    pb1.setString( "Doing something...");
    pb1.setStringPainted( true);
    pb1.setIndeterminate( true);
    
    JProgressBar pb2 = new JProgressBar( 0, 100);
    pb2.setValue( 0);
    pb2.setString( "Doing something too...");
    pb2.setStringPainted( true);
    pb2.setIndeterminate( true);
    pb2.setOrientation( JProgressBar.VERTICAL);
    
    pb3 = new JProgressBar( 0, 100);
    pb3.setValue( 50);
    pb3.setStringPainted( true);
    
    pb4 = new JProgressBar( 0, 100);
    pb4.setValue( 50);
    pb4.setStringPainted( true);
    pb4.setOrientation( JProgressBar.VERTICAL);
    
    SpinnerModel spModel = new SpinnerNumberModel( 50,0,100,1);
    sp = new JSpinner( spModel);
    sp.addChangeListener( new ChangeListener() {
      public void stateChanged( ChangeEvent e) {
        pb4.setValue( ((Integer)sp.getValue()).intValue());
        pb3.setValue( ((Integer)sp.getValue()).intValue());
      }
    });
    
    JPanel pp = new JPanel();
    pp.add( sp);
    
    pView5 = new JPanel( new BorderLayout());
    pView5.add( pp, BorderLayout.CENTER);
    pView5.add( pb1, BorderLayout.SOUTH);
    pView5.add( pb2, BorderLayout.EAST);
    pView5.add( pb3, BorderLayout.NORTH);
    pView5.add( pb4, BorderLayout.WEST);
  }
  
  class MiTL implements ActionListener {
    public void actionPerformed( ActionEvent ev) {
      if ( ev.getActionCommand().equals( "Top") ) {
        tabPan.setTabPlacement( JTabbedPane.TOP);
      }
      else if ( ev.getActionCommand().equals( "Bottom") ) {
        tabPan.setTabPlacement( JTabbedPane.BOTTOM);
      }
      else if ( ev.getActionCommand().equals( "Right") ) {
        tabPan.setTabPlacement( JTabbedPane.RIGHT);
      }
      else if ( ev.getActionCommand().equals( "Left") ) {
        tabPan.setTabPlacement( JTabbedPane.LEFT);
      }
    }
  }
  
  class MiWL extends WindowAdapter {
    public void windowClosing( WindowEvent ev) {
      System.exit( 0);
    }
  }
  
  int index = 0;
  ImageIcon lIcon[] = { NimRODUtils.loadRes( "/com/nilo/plaf/nimrod/icons/tools.png"),
                        NimRODUtils.loadRes( "/com/nilo/plaf/nimrod/icons/folder_picture.png"),
                        NimRODUtils.loadRes( "/com/nilo/plaf/nimrod/icons/network_local.png"),
                        NimRODUtils.loadRes( "/com/nilo/plaf/nimrod/icons/news.png"),
                        null
                        };
  
  private Icon nextIcon() {
    if ( index >= lIcon.length ) {
      index = 0;
    }
    
    return lIcon[index++];
  }
  
  class MiFL implements ActionListener {
    public void actionPerformed( ActionEvent ev) {
      JInternalFrame jif = new JInternalFrame( "The Long Titled Internal Frame, n� " + pos / 5, true, true, true, true);
      
      jif.setVisible( true);
      jif.setFrameIcon( nextIcon());
      
      jif.setIconifiable( true);
      jif.setMaximizable( true);
      jif.setClosable( true);
      
      JButton but = new JButton( "Change Icon");
      but.addActionListener( new dummy( jif));
      jif.getContentPane().add( new JLabel( "Another InternalFrame"));
      jif.getContentPane().add( but, BorderLayout.SOUTH);
      
      jif.setLocation( new Point( pos, pos));
      
      pos += 5;
      jif.pack();
      desktop.add( jif);
      
      try {
        jif.setSelected( true);
      }
      catch ( PropertyVetoException e) {}
    }
  }
  
  class dummy implements ActionListener {
    JInternalFrame jif;
    
    public dummy( JInternalFrame jif) {
      this.jif = jif;
    }
    
    public void actionPerformed( ActionEvent ev) {
      jif.setFrameIcon( nextIcon());
    }
  }
  
  class MiAL implements ActionListener {
    public void actionPerformed( ActionEvent ev) {
      if ( ev.getActionCommand().equals( "Open") ) {
        JFileChooser fc = new JFileChooser();
        fc.setCurrentDirectory( new File( "."));
        if ( fc.showOpenDialog( NimRODMain.this) != JFileChooser.APPROVE_OPTION ) {
          return;
        }
        String nomFich = fc.getSelectedFile().getPath();
        tNomFich.setText( nomFich);
        
        Properties props = new Properties();
        try {
          props.load( new FileInputStream( nomFich));//this.getClass().getResourceAsStream( nomFich));
        }
        catch ( Exception ex) {
          ex.printStackTrace();
          return;
        }
        
        nt = NimRODUtils.iniCustomColors( nt, props.getProperty( "nimrodlf.selection"), 
                                     props.getProperty( "nimrodlf.background"),
                                     props.getProperty( "nimrodlf.p1"),
                                     props.getProperty( "nimrodlf.p2"),
                                     props.getProperty( "nimrodlf.p3"),                                  
                                     props.getProperty( "nimrodlf.s1"),
                                     props.getProperty( "nimrodlf.s2"),
                                     props.getProperty( "nimrodlf.s3"),
                                     props.getProperty( "nimrodlf.w"),
                                     props.getProperty( "nimrodlf.b"),
                                     props.getProperty( "nimrodlf.menuOpacity"),
                                     props.getProperty( "nimrodlf.frameOpacity"));
        
        cambiaTema();
      }
      else if ( ev.getActionCommand().equals( "Save") ) {
        JFileChooser fc = new JFileChooser();
        
        String nomFich = tNomFich.getText();
        if ( nomFich.equals( "") ) {
          fc.setCurrentDirectory( new File ( "."));
          fc.setSelectedFile( new File( "NimRODThemeFile.theme"));
        }
        else {
          File fich = new File( nomFich);
          //fc.setCurrentDirectory( fich.getName());
          fc.setSelectedFile( fich);
        }

        if ( fc.showSaveDialog( NimRODMain.this) != JFileChooser.APPROVE_OPTION ) {
          return;
        }
        nomFich = fc.getSelectedFile().getPath();
        tNomFich.setText( nomFich);
        
        try {
          FileOutputStream f = new FileOutputStream( nomFich);
          f.write( nt.toString().getBytes());
          f.close();
        }
        catch ( IOException ex) {
          JOptionPane.showMessageDialog( NimRODMain.this, "No se puede guardar el fichero");
        }
      }
      else if ( ev.getActionCommand().equals( "Test") ) {
        nt = new NimRODTheme();
        
        nt.setBlack( bB.getBackground());
        nt.setWhite( bW.getBackground());
        nt.setPrimary1( bP1.getBackground());
        nt.setPrimary2( bP2.getBackground());
        nt.setPrimary3( bP3.getBackground());
        nt.setSecondary1( bS1.getBackground());
        nt.setSecondary2( bS2.getBackground());
        nt.setSecondary3( bS3.getBackground());
        nt.setMenuOpacity( sMenuOpacidad.getValue());
        nt.setFrameOpacity( sFrameOpacidad.getValue());

        cambiaTema();
      }
    }
    
    protected void cambiaTema() { 
      NimRODLookAndFeel.setCurrentTheme( nt);
      try {
        UIManager.setLookAndFeel( nf);
      }
      catch ( Exception ex) {
        ex.printStackTrace();
      }
      
      SwingUtilities.updateComponentTreeUI( NimRODMain.this);
      
      hazPaleta();
    }
  }
  
  class MiML extends MouseAdapter {
    public void mouseClicked( MouseEvent ev) {
      if ( ev.getComponent() == bP1 ) {
        bP1.setBackground( getColor( bP1.getBackground(), "Primary 1"));
      }
      else if ( ev.getComponent() == bP2 ) {
        bP2.setBackground( getColor( bP2.getBackground(), "Primary 2"));
      }
      else if ( ev.getComponent() == bP3 ) {
        bP3.setBackground( getColor( bP3.getBackground(), "Primary 3"));
      }
      else if ( ev.getComponent() == bSelection ) {
        Color col = getColor( bSelection.getBackground(), "Selection");
        
        int r = col.getRed();
        int g = col.getGreen();
        int b = col.getBlue();
        
        bP1.setBackground( new Color( (r>20 ? r-20 : 0), (g>20 ? g-20 : 0), (b>20 ? b-20 : 0)));
        bP2.setBackground( new Color( (r>10 ? r-10 : 0), (g>10 ? g-10 : 0), (b>10 ? b-10 : 0)));
        bP3.setBackground( col);
        bSelection.setBackground( col);
      }
      else if ( ev.getComponent() == bS1 ) {
        bS1.setBackground( getColor( bS1.getBackground(), "Secondary 1"));
      }
      else if ( ev.getComponent() == bS2 ) {
        bS2.setBackground( getColor( bS2.getBackground(), "Secondary 2"));
      }
      else if ( ev.getComponent() == bS3 ) {
        bS3.setBackground( getColor( bS3.getBackground(), "Secondary 3"));
      }
      else if ( ev.getComponent() == bBackground ) {
        Color col = getColor( bBackground.getBackground(), "Background");
        
        int r = col.getRed();
        int g = col.getGreen();
        int b = col.getBlue();
        
        bS1.setBackground( new Color( (r>20 ? r-20 : 0), (g>20 ? g-20 : 0), (b>20 ? b-20 : 0)));
        bS2.setBackground( new Color( (r>10 ? r-10 : 0), (g>10 ? g-10 : 0), (b>10 ? b-10 : 0)));
        bS3.setBackground( col);
        bBackground.setBackground( col);
      }
      else if ( ev.getComponent() == bW ) {
        bW.setBackground( getColor( bW.getBackground(), "White"));
      }
      else if ( ev.getComponent() == bB ) {
        bB.setBackground( getColor( bB.getBackground(), "Black"));
      }
    }
    
    protected Color getColor( Color col, String cad) {
      Color ret = JColorChooser.showDialog( NimRODMain.this, cad, col);
      if ( ret == null ) {
        ret = col;
      }
      
      return ret;
    }
  }
  
  public static void main( String[] args) {
    try {
      nf = new NimRODLookAndFeel();
      nt = new NimRODTheme();
      NimRODLookAndFeel.setCurrentTheme( nt);

      UIManager.setLookAndFeel( nf);
    } 
    catch ( Exception ex) {
      System.out.println( ex);
    }
    
    JFrame.setDefaultLookAndFeelDecorated( true);
    new NimRODMain();
  }
}

⌨️ 快捷键说明

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