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

📄 modelpanel.java

📁 JavaExplorer是一个独立于平台的浏览器
💻 JAVA
字号:
/*
 * Created on 17 oct. 03
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package javaexplorer.gui.dialog;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javaexplorer.Launcher;
import javaexplorer.util.laf.LookAndFeelChooser;
import javaexplorer.util.laf.LookAndFeelModel;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JComboBox;

/**
 * @author veeb7280
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class ModelPanel extends JPanel implements ActionListener{

  private GridLayout gridLayout = new GridLayout();

  private JLabel jlblModelName = new JLabel();
  private JLabel jlblTreeListFont = new JLabel();
  private JLabel jlblMenuFont = new JLabel();
  private JLabel jlblDefaultFont = new JLabel();
  private JLabel jlblBackColor = new JLabel();
  private JLabel jlblMdiBackColor = new JLabel();
  private JLabel jlblTextAreaColor = new JLabel();


  private JComboBox jcbModel = new JComboBox();
  private JButton jbtTreeListFont = new JButton("Tree Font");
  private JButton jbtMenuFont = new JButton("Menu Font");
  private JButton jbtDefaultFont = new JButton("Default Font");
  private JButton jbtBackColor = new JButton("...");
  private JButton jbtMdiBackColor = new JButton("...");
  private JButton jbtTextAreaColor = new JButton("...");
  
  private JButton jbtSaveModel = new JButton("Save Model");
  private JButton jbtDeleteModel = new JButton("DeleteModel");
  
  private LookAndFeelChooser lfc = null;
  private JFrame _parent = null;
  private Launcher _launcher = null;


  public ModelPanel(Launcher launcher){    
    try{
      _launcher = launcher;      
      initGui();
    }catch( Exception e){
      javaexplorer.util.Log.addError(e);
    }
  }
  
  
  public void setParentFrame(JFrame jframe){
    _parent = jframe;
  }
  
  public void setLookAndFeelChooser(LookAndFeelChooser chooser){
    lfc = chooser.duplicate();
    refreshComboBox();
    jcbModel.setSelectedItem(lfc.getCurrentModel());
    applyModel(lfc.getCurrentModel()); 
  }
  
  public LookAndFeelChooser getLookAndFeelChooser(){
    return lfc;
  }  

  /*
  public static void main(String[] args) {
    javax.swing.JFrame frame = new javax.swing.JFrame("Test");
    ModelPanel mp = new ModelPanel(null);
    frame.getContentPane().setLayout(new java.awt.BorderLayout());
    frame.getContentPane().add(mp, java.awt.BorderLayout.CENTER); 
    frame.pack();
    frame.setVisible(true);
    
  }
  */
  
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    Object obj = e.getSource();
    
    if (obj == jbtTreeListFont) {
      FontChooser fc = new FontChooser(_parent, jbtTreeListFont.getFont());
      fc.setVisible(true);

      Font f = fc.getNewFont();

      if (f != null) {
        jbtTreeListFont.setFont(f);
        jbtTreeListFont.setText(f.getName());
      }
  }

  if (obj == jbtMenuFont) {
      FontChooser fc = new FontChooser(_parent, jbtMenuFont.getFont());
      fc.setVisible(true);

      Font f = fc.getNewFont();

      if (f != null) {
          jbtMenuFont.setFont(f);
          jbtMenuFont.setText(f.getName());
      }
  }

  if (obj == jbtDefaultFont) {
      FontChooser fc = new FontChooser(_parent, jbtDefaultFont.getFont());
      fc.setVisible(true);

      Font f = fc.getNewFont();

      if (f != null) {
          jbtDefaultFont.setFont(f);
          jbtDefaultFont.setText(f.getName());
      }
  }

  if (obj == jbtBackColor) {
      Color c = JColorChooser.showDialog(this, "Background color",
              jbtBackColor.getBackground());

      if (c != null) {
          jbtBackColor.setBackground(c);
      }
  }

  if (obj == jbtSaveModel) {
      //On sauvegarde le mod鑜e ayant les caract閞istiques
      //Trouv閑s
      lfc.add(createLookAndFeelModel());
      refreshComboBox();
      
  }
  if (obj == jbtDeleteModel) {
      //On supprime le mod鑜e ayant les caract閞istiques
      //Trouv閑s      
      lfc.remove(createLookAndFeelModel());
      if( lfc.length() == 0 ) lfc.add(new LookAndFeelModel());
      refreshComboBox();      
  }


  if (obj == jbtMdiBackColor) {
      Color c = JColorChooser.showDialog(this, "MDI Background color",
              jbtMdiBackColor.getBackground());

      if (c != null) {
          jbtMdiBackColor.setBackground(c);
      }
  }

  if (obj == jbtTextAreaColor) {
      Color c = JColorChooser.showDialog(this,
              "TextArea Background color",
              jbtTextAreaColor.getBackground());

      if (c != null) {
          jbtTextAreaColor.setBackground(c);
      }
  }
  
  if (obj == jcbModel) {
      String name = jcbModel.getEditor().getItem().toString();
      LookAndFeelModel model = lfc.getModel(name ); 
      if( model != null){
        applyModel(model);
      }
  }
  
}

  private void initGui() throws Exception{
    
    
    Font defaultFont = new Font("Dialog", 1, 10);
    
    gridLayout.setRows(8);
    gridLayout.setColumns(2);
    gridLayout.setHgap(10);
    
    setLayout(gridLayout);
    setBorder(BorderFactory.createLineBorder(Color.black));
    
    jcbModel.addActionListener(this);
    jbtTreeListFont.addActionListener(this);
    jbtMenuFont.addActionListener(this);
    jbtDefaultFont.addActionListener(this);
    jbtBackColor.addActionListener(this);
    jbtMdiBackColor.addActionListener(this);
    jbtTextAreaColor.addActionListener(this);
    jbtSaveModel.addActionListener(this);
    jbtDeleteModel.addActionListener(this);

    jlblModelName.setFont(defaultFont);
    jlblModelName.setText("L&F Model name");
    jlblTreeListFont.setFont(defaultFont);
    jlblTreeListFont.setText("Font for trees and lists");
    jlblMenuFont.setFont(defaultFont);
    jlblMenuFont.setText("Font for menus");
    jlblDefaultFont.setFont(defaultFont);
    jlblDefaultFont.setText("Default Font");
    jlblBackColor.setFont(defaultFont);
    jlblBackColor.setText("General Background color");
    jlblMdiBackColor.setFont(defaultFont);
    jlblMdiBackColor.setText("MDI Background color");
    jlblTextAreaColor.setFont(defaultFont);
    jlblTextAreaColor.setText("Text Area Background color");

    jcbModel.setEditable(true);
    
    jcbModel.setFont(defaultFont);
    jbtSaveModel.setFont(defaultFont);
    jbtDeleteModel.setFont(defaultFont);


    add(jlblModelName, null);
    add(jcbModel, null);
    
    add(jlblTreeListFont, null);
    add(jbtTreeListFont, null);
    
    add(jlblMenuFont, null);
    add(jbtMenuFont, null);
    
    add(jlblDefaultFont, null);
    add(jbtDefaultFont, null);
    
    add(jlblBackColor, null);
    add(jbtBackColor, null);
    
    add(jlblMdiBackColor, null);
    add(jbtMdiBackColor, null);
    
    add(jlblTextAreaColor, null);
    add(jbtTextAreaColor, null);

    add(jbtSaveModel, null);
    add(jbtDeleteModel, null);


  }


  private void refreshComboBox(){
    jcbModel.removeAllItems();
    for( int i = 0; i < lfc.length(); i++ ){
      jcbModel.addItem(lfc.getAt(i));
    }
  }
  
  /**
   * Creation d'un objet look and feel avec les valeurs voulues
   * @return LookAndFeelModel un modele
   */
  public LookAndFeelModel createLookAndFeelModel(){
    LookAndFeelModel model = new LookAndFeelModel();
    model.setModelName(jcbModel.getEditor().getItem().toString());
    
    model.setBackColor(jbtBackColor.getBackground());
    model.setMdiBackColor(jbtMdiBackColor.getBackground());
    model.setTextAreaColor(jbtTextAreaColor.getBackground());
    
    model.setTreeListFont(jbtTreeListFont.getFont());
    model.setMenuFont(jbtMenuFont.getFont());
    model.setDefaultFont(jbtDefaultFont.getFont());
    
    return model;
  }
  
  private void applyModel(LookAndFeelModel model){
    
    //applique les propri閠閟 du mod鑜e aux 閘閙ents de visualisation
    jbtBackColor.setBackground(model.getBackColor());
    jbtMdiBackColor.setBackground(model.getMdiBackColor());
    jbtTextAreaColor.setBackground(model.getTextAreaColor());
    
    jbtTreeListFont.setFont(model.getTreeListFont());
    jbtMenuFont.setFont(model.getMenuFont());
    jbtDefaultFont.setFont(model.getDefaultFont());
    
  }
  

}

⌨️ 快捷键说明

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