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

📄 nimrodlookandfeel.java

📁 一个java漂亮外观的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *                 (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駉l) * * * Original author: Nilo J. Gonz醠ez *  * And these people improved the code: *   Fritz Elfert *   Eduardo  */ /** * The main class for the NimROD Look&Feel. * * To use this Look&Feel, simply include these two lines into your code:<br> * <code> * NimRODLookAndFeel NimRODLF = new NimRODLookAndFeel(); * UIManager.setLookAndFeel( NimRODLF); * </code> * You can change the default theme color in two ways. *  * You can create theme and change de colours with this lines:<br> *   <code> *   NimRODLookAndFeel NimRODLF = new NimRODLookAndFeel(); *   NimRODTheme nt = new NimRODTheme(); *   nt.setX( Color); *   .... *   nt.setX( Color); *   NimRODLF.setCurrentTheme( nt); *   UIManager.setLookAndFeel( NimRODLF); *   <code><br> * This way is good if you can change the sources and you want the program works *only* with NimRODLF.  * * If you don't have the sources you can change the theme color including same properties in your command line and the look and feel * will do its best... This couldn't work if the application changes the system properties, but, well, if you don't have the sources...<br> * For example:<br> *   <code>java -Dnimrodlf.selection=0x00cc00 XXX.YOUR.APP.XXX</code> will colour with green the selected widgets<br> *   <code>java java -Dnimrodlf.s1=0xdde8ee -Dnimrodlf.s2=0xb7daec -Dnimrodlf.s3=0x74bfe6 XXX.YOUR.APP.XXX</code> will colour with blue the background of the widgets<br> * The values are in the tipical HTML format (0xRRGGBB) with the red, green and blue values encoded in hexadecimal format.<br>  * These are the admited properties: * <ul>    * <li>nimrodlf.selection: this is the selection color</li> * <li>nimrodlf.background: this is the background color</li> * <li>nimrodlf.p1: this is the primary1 color (緿on't you understand? Patience?</li> * <li>nimrodlf.p2: this is the primary2 color</li> * <li>nimrodlf.p3: this is the primary3 color</li> * <li>nimrodlf.s1: this is the secondary1 color</li> * <li>nimrodlf.s2: this is the secondary2 color</li> * <li>nimrodlf.s3: this is the secondary3 color</li> * <li>nimrodlf.b: this is the black color</li> * <li>nimrodlf.w: this is the white color</li> * <li>nimrodlf.menuOpacity: this is the menu opacity</li> * <li>nimrodlf.frameOpacity: this is the frame opacity</li> * </ul> * 縋rimary color? 縎econdary? 縒hat the...? Cool. <a href='http://java.sun.com/products/jlf/ed1/dg/higg.htm#62001'>Here</a> you can learn what  * i'm talking about. Swing applications have only 8 colors, named PrimaryX, SecondaryX, White and Black, and <a href='http://java.sun.com/products/jlf/ed1/dg/higg.htm#62001'>here</a> * you hava a table with the who-is-who.<br> * You don't need to write all the values, you only must write those values you want to change. There are two shorthand properties, selection and background. * If you write nimrodlf.selection or nimrodlf.background the NimRODLF will calculate the colors around (darker and lighter) your choose.<br> * If nimrodlf.selection is writen, pX, sX, b and w are ignored.  * Ahh!! One more thing. 0xRRGGBB is equal #RRGGBB.  * @see NimRODTheme * @see http://java.sun.com/products/jlf/ed1/dg/higg.htm#62001 * @author Nilo J. Gonzalez  */ package com.nilo.plaf.nimrod;import java.awt.*;import java.awt.image.Kernel;import javax.swing.*;import javax.swing.plaf.*;import javax.swing.plaf.metal.*;import java.io.*;import java.util.*;public class NimRODLookAndFeel extends MetalLookAndFeel {  private static final long serialVersionUID = 7191199335214123414L;    String fichTheme = "";    protected static MetalTheme theme;    public NimRODLookAndFeel() {    super();        NimRODTheme nt = new NimRODTheme();        String p1, p2, p3, s1, s2, s3, selection, background, w, b, opMenu, opFrame;            // Vamos a ver si han puesto por linea de comandos un fichero de tema...        // Este codigo esta aqui gracias a Fritz Elfert, que descubrio que esto cascaba miserablemente    // cuando se usaba en un applet.    String nomFich = null;    try {      nomFich = System.getProperty( "nimrodlf.themeFile");    }     catch ( Exception ex) {      // If used in an applet, this could throw a SecurityException.    }        // ... o tenemos que tirar del fichero por defecto    nomFich = ( nomFich == null ? "NimRODThemeFile.theme" : nomFich);    try {      Properties props = new Properties();      InputStream res = null;            try {        res = new FileInputStream( nomFich);  // Primero, se carga el fichero      }      catch ( Exception ex) {        nomFich = ( nomFich.equals( "NimRODThemeFile.theme")? "/" + nomFich : nomFich);        res = this.getClass().getResourceAsStream( nomFich);   // Si no hay fichero, se busca en el classpath/jar      }            props.load( res);  // Si no esta en ningun sitio, esto dara una excepcion y cargara uno por defecto            selection = props.getProperty( "nimrodlf.selection");      background = props.getProperty( "nimrodlf.background");            p1 = props.getProperty( "nimrodlf.p1");      p2 = props.getProperty( "nimrodlf.p2");      p3 = props.getProperty( "nimrodlf.p3");            s1 = props.getProperty( "nimrodlf.s1");      s2 = props.getProperty( "nimrodlf.s2");      s3 = props.getProperty( "nimrodlf.s3");            w = props.getProperty( "nimrodlf.w");      b = props.getProperty( "nimrodlf.b");            opMenu = props.getProperty( "nimrodlf.menuOpacity");      opFrame = props.getProperty(  "nimrodlf.frameOpacity");              nt = NimRODUtils.iniCustomColors( nt, selection, background, p1, p2, p3, s1, s2, s3, w, b, opMenu, opFrame);            fichTheme = nomFich;    }    catch ( Exception ex) {    // Si no se puede leer el fichero o el fichero esta malamente,       nt = new NimRODTheme();  // no le hacemos ni caso.    }        try {      // Ahora vamos a ver si se expecifican los colores por linea de comandos.      selection = System.getProperty( "nimrodlf.selection");      background = System.getProperty( "nimrodlf.background");            p1 = System.getProperty( "nimrodlf.p1");      p2 = System.getProperty( "nimrodlf.p2");      p3 = System.getProperty( "nimrodlf.p3");            s1 = System.getProperty( "nimrodlf.s1");      s2 = System.getProperty( "nimrodlf.s2");      s3 = System.getProperty( "nimrodlf.s3");            w = System.getProperty( "nimrodlf.w");      b = System.getProperty( "nimrodlf.b");            opMenu = System.getProperty( "nimrodlf.menuOpacity");      opFrame = System.getProperty(  "nimrodlf.frameOpacity");              nt = NimRODUtils.iniCustomColors( nt, selection, background, p1, p2, p3, s1, s2, s3, w, b, opMenu, opFrame);    }    catch ( Exception ex ) {     // Este codigo esta aqui gracias a Fritz Elfert, que descubrio que esto cascaba miserablemente      // cuando se usaba en un applet. Un gran tipo Fritz...      if ( fichTheme.length() == 0 ) {        nt = new NimRODTheme();      }    }        setCurrentTheme( nt);        float[] elements = new float[NimRODUtils.MATRIX_FAT*NimRODUtils.MATRIX_FAT];    for ( int i = 0; i < elements.length; i++ ) {      elements[i] = 0.1f;    }    int mid = NimRODUtils.MATRIX_FAT/2+1;    elements[mid*mid] = .2f;        NimRODUtils.kernelFat = new Kernel( NimRODUtils.MATRIX_FAT,NimRODUtils.MATRIX_FAT, elements);        elements = new float[NimRODUtils.MATRIX_THIN*NimRODUtils.MATRIX_THIN];    for ( int i = 0; i < elements.length; i++ ) {      elements[i] = 0.1f;    }    mid = NimRODUtils.MATRIX_THIN/2+1;    elements[mid*mid] = .2f;        NimRODUtils.kernelThin = new Kernel( NimRODUtils.MATRIX_THIN,NimRODUtils.MATRIX_THIN, elements);  }      public String getID() {    return "NimROD";  }  public String getName() {    return "NimROD";  }  public String getDescription() {    return "Look and Feel NimROD, by Nilo J. Gonzalez 2005-2007";  }  public boolean isNativeLookAndFeel() {    return false;  }  public boolean isSupportedLookAndFeel() {    return true;  }    /**   * Este metodo devuelve false porque para dar bordes como es debido a la ventana principal hay que   * fusilarse la clase MetalRootPaneUI enterita porque la mayoria de sus metodos son privados...

⌨️ 快捷键说明

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