View Javadoc
1 package net.sourceforge.pmd.swingui; 2 3 import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; 4 5 import javax.swing.ImageIcon; 6 import javax.swing.LookAndFeel; 7 import javax.swing.UIDefaults; 8 import java.awt.Color; 9 import java.awt.Font; 10 import java.io.BufferedInputStream; 11 import java.io.ByteArrayOutputStream; 12 import java.io.IOException; 13 import java.io.InputStream; 14 import java.util.Properties; 15 16 /*** 17 * 18 * @author Donald A. Leckie 19 * @since August 27, 2002 20 * @version $Revision: 1.19 $, $Date: 2003/05/28 18:08:32 $ 21 */ 22 public class PMDLookAndFeel extends WindowsLookAndFeel { 23 24 /*** 25 **************************************************************************** 26 * 27 * @return 28 */ 29 public String getDescription() { 30 return "Source Forge PMD look and feel"; 31 } 32 33 /*** 34 **************************************************************************** 35 * 36 * @return 37 */ 38 public String getID() { 39 return "SourceForgePMD"; 40 } 41 42 /*** 43 **************************************************************************** 44 * 45 * @return 46 */ 47 public String getName() { 48 return "SourceForgePMD"; 49 } 50 51 /*** 52 **************************************************************************** 53 * 54 * @return 55 */ 56 public boolean isNativeLookAndFeel() { 57 return false; 58 } 59 60 /*** 61 **************************************************************************** 62 * 63 * @return 64 */ 65 public boolean isSupportedLookAndFeel() { 66 return true; 67 } 68 69 /*** 70 **************************************************************************** 71 * 72 * @param table 73 */ 74 protected void initClassDefaults(UIDefaults table) { 75 super.initClassDefaults(table); 76 77 //String pkgName = "net.sourceforge.pmd.swingui"; 78 } 79 80 /*** 81 **************************************************************************** 82 * 83 * @param table 84 */ 85 protected void initSystemColorDefaults(UIDefaults table) { 86 super.initSystemColorDefaults(table); 87 88 Color darkBlue = Color.blue.darker(); 89 90 String[] defaultSystemColors = {"pmdBlue", String.valueOf(darkBlue.getRGB()), "pmdRed", String.valueOf(Color.red.getRGB()), "pmdGreen", "#336666", "pmdGray", "#F0F0F0", "pmdTreeBackground", "#F0F0F0", "pmdTableBackground", "#F0F0F0", "pmdMessageAreaBackground", "#F0F0F0", "pmdStatusAreaBackground", "#F0F0F0", "mediumGray", "#686868", "mediumDarkGray", "#434343", "paleGray", "#AAAAAA", "standardButtonBackground", "#686868", "standardButtonForeground", "#FFFFFF", "pmdTableHeaderBackground", "#686868", "pmdTableHeaderForeground", "#FFFFFF", "pmdEditingPanelBackground", String.valueOf(Color.lightGray.getRGB()), "disabledTextBackground", "#AAAAAA", }; 91 92 loadSystemColors(table, defaultSystemColors, isNativeLookAndFeel()); 93 } 94 95 /*** 96 **************************************************************************** 97 * 98 * @param table 99 */ 100 protected void initComponentDefaults(UIDefaults table) { 101 super.initComponentDefaults(table); 102 103 Class wlafClass = WindowsLookAndFeel.class; 104 Class plafClass = PMDLookAndFeel.class; 105 Object[] defaults = {"document", LookAndFeel.makeIcon(plafClass, "icons/document.gif"), "cancel", LookAndFeel.makeIcon(plafClass, "icons/cancel.gif"), "save", LookAndFeel.makeIcon(plafClass, "icons/save.gif"), "saveAs", LookAndFeel.makeIcon(plafClass, "icons/saveAs.gif"), "print", LookAndFeel.makeIcon(plafClass, "icons/print.gif"), "copy", LookAndFeel.makeIcon(plafClass, "icons/copy.gif"), "edit", LookAndFeel.makeIcon(plafClass, "icons/edit.gif"), "view", LookAndFeel.makeIcon(plafClass, "icons/view.gif"), "help", LookAndFeel.makeIcon(plafClass, "icons/help.gif"), "pmdLogo", LookAndFeel.makeIcon(plafClass, "icons/pmdLogo.gif"), "pmdLogoImage", getImageIcon("icons/pmdLogo.jpg"), "labelFont", new Font("Dialog", Font.BOLD, 12), "label14Font", new Font("Dialog", Font.BOLD, 14), "label16Font", new Font("Dialog", Font.BOLD, 16), "dataFont", new Font("Dialog", Font.PLAIN, 12), "codeFont", new Font("Monospaced", Font.PLAIN, 12), "tabFont", new Font("SansSerif", Font.BOLD, 12), "titleFont", new Font("SansSerif", Font.BOLD, 14), "buttonFont", new Font("SansSerif", Font.BOLD, 12), "messageFont", new Font("Dialog", Font.PLAIN, 12), "serif12Font", new Font("Serif", Font.PLAIN, 12), "serif14Font", new Font("Serif", Font.PLAIN, 14), "viewerProperties", loadViewerProperties(), 106 107 // These are all the icons defined in the WindowsLookAndFeel. We redefine them 108 // here because of the way they are defined in that class: in terms of the return 109 // value of getClass(). I.e., getClass() just returns the handle to the invoking 110 // class, which now is PMDLookAndFeel. That means that the icons are searched 111 // for in the PMD look and feel package, which is not where they really are. 112 // Since we've just called the superclass method, the icons have been installed 113 // incorrectly in the table. Reinstall them using the correct class. 114 115 "Tree.openIcon", LookAndFeel.makeIcon(wlafClass, "icons/TreeOpen.gif"), "Tree.closedIcon", LookAndFeel.makeIcon(wlafClass, "icons/TreeClosed.gif"), "Tree.leafIcon", LookAndFeel.makeIcon(wlafClass, "icons/TreeLeaf.gif"), 116 117 "FileChooser.newFolderIcon", LookAndFeel.makeIcon(wlafClass, "icons/NewFolder.gif"), "FileChooser.upFolderIcon", LookAndFeel.makeIcon(wlafClass, "icons/UpFolder.gif"), "FileChooser.homeFolderIcon", LookAndFeel.makeIcon(wlafClass, "icons/HomeFolder.gif"), "FileChooser.detailsViewIcon", LookAndFeel.makeIcon(wlafClass, "icons/DetailsView.gif"), "FileChooser.listViewIcon", LookAndFeel.makeIcon(wlafClass, "icons/ListView.gif"), 118 119 "FileView.directoryIcon", LookAndFeel.makeIcon(wlafClass, "icons/Directory.gif"), "FileView.fileIcon", LookAndFeel.makeIcon(wlafClass, "icons/File.gif"), "FileView.computerIcon", LookAndFeel.makeIcon(wlafClass, "icons/Computer.gif"), "FileView.hardDriveIcon", LookAndFeel.makeIcon(wlafClass, "icons/HardDrive.gif"), "FileView.floppyDriveIcon", LookAndFeel.makeIcon(wlafClass, "icons/FloppyDrive.gif"), }; 120 121 table.putDefaults(defaults); 122 } 123 124 /*** 125 **************************************************************************** 126 * 127 * @return 128 */ 129 private Properties loadViewerProperties() { 130 Properties properties = new Properties(); 131 132 try { 133 InputStream inputStream = getClass().getResourceAsStream("pmdViewer.properties"); 134 135 if (inputStream != null) { 136 properties.load(inputStream); 137 } 138 } catch (IOException exception) { 139 exception.printStackTrace(); 140 } 141 142 return properties; 143 } 144 145 /*** 146 ******************************************************************************* 147 * 148 * @param fileName 149 * 150 * @return 151 */ 152 protected static final ImageIcon getImageIcon(String fileName) { 153 final byte[][] buffer = new byte[1][]; 154 155 try { 156 InputStream resource = PMDLookAndFeel.class.getResourceAsStream(fileName); 157 158 if (resource == null) { 159 return null; 160 } 161 162 BufferedInputStream in; 163 ByteArrayOutputStream out; 164 int n; 165 166 in = new BufferedInputStream(resource); 167 out = new ByteArrayOutputStream(1024); 168 buffer[0] = new byte[1024]; 169 170 while ((n = in.read(buffer[0])) > 0) { 171 out.write(buffer[0], 0, n); 172 } 173 174 in.close(); 175 out.flush(); 176 buffer[0] = out.toByteArray(); 177 } catch (IOException ioe) { 178 return null; 179 } 180 181 if (buffer[0] == null) { 182 return null; 183 } 184 185 if (buffer[0].length == 0) { 186 return null; 187 } 188 189 return new ImageIcon(buffer[0]); 190 } 191 }

This page was automatically generated by Maven