001: package org.acm.seguin.pmd.swingui;
002:
003: import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
004:
005: import javax.swing.ImageIcon;
006: import javax.swing.LookAndFeel;
007: import javax.swing.UIDefaults;
008: import java.awt.Color;
009: import java.awt.Font;
010: import java.io.BufferedInputStream;
011: import java.io.ByteArrayOutputStream;
012: import java.io.IOException;
013: import java.io.InputStream;
014: import java.util.Properties;
015:
016: /**
017: *
018: * @author Donald A. Leckie
019: * @since August 27, 2002
020: * @version $Revision: 1.4 $, $Date: 2003/09/21 20:51:41 $
021: */
022: public class PMDLookAndFeel extends WindowsLookAndFeel {
023:
024: /**
025: ****************************************************************************
026: *
027: * @return
028: */
029: public String getDescription() {
030: return "Source Forge PMD look and feel";
031: }
032:
033: /**
034: ****************************************************************************
035: *
036: * @return
037: */
038: public String getID() {
039: return "SourceForgePMD";
040: }
041:
042: /**
043: ****************************************************************************
044: *
045: * @return
046: */
047: public String getName() {
048: return "SourceForgePMD";
049: }
050:
051: /**
052: ****************************************************************************
053: *
054: * @return
055: */
056: public boolean isNativeLookAndFeel() {
057: return false;
058: }
059:
060: /**
061: ****************************************************************************
062: *
063: * @return
064: */
065: public boolean isSupportedLookAndFeel() {
066: return true;
067: }
068:
069: /**
070: ****************************************************************************
071: *
072: * @param table
073: */
074: protected void initClassDefaults(UIDefaults table) {
075: super .initClassDefaults(table);
076: }
077:
078: /**
079: ****************************************************************************
080: *
081: * @param table
082: */
083: protected void initSystemColorDefaults(UIDefaults table) {
084: super .initSystemColorDefaults(table);
085:
086: Color darkBlue = Color.blue.darker();
087:
088: String[] defaultSystemColors = { "pmdBlue",
089: String.valueOf(darkBlue.getRGB()), "pmdRed",
090: String.valueOf(Color.red.getRGB()), "pmdGreen",
091: "#336666", "pmdGray", "#F0F0F0", "pmdTreeBackground",
092: "#F0F0F0", "pmdTableBackground", "#F0F0F0",
093: "pmdMessageAreaBackground", "#F0F0F0",
094: "pmdStatusAreaBackground", "#F0F0F0", "mediumGray",
095: "#686868", "mediumDarkGray", "#434343", "paleGray",
096: "#AAAAAA", "standardButtonBackground", "#686868",
097: "standardButtonForeground", "#FFFFFF",
098: "pmdTableHeaderBackground", "#686868",
099: "pmdTableHeaderForeground", "#FFFFFF",
100: "pmdEditingPanelBackground",
101: String.valueOf(Color.lightGray.getRGB()),
102: "disabledTextBackground", "#AAAAAA", };
103:
104: loadSystemColors(table, defaultSystemColors,
105: isNativeLookAndFeel());
106: }
107:
108: /**
109: ****************************************************************************
110: *
111: * @param table
112: */
113: protected void initComponentDefaults(UIDefaults table) {
114: super .initComponentDefaults(table);
115:
116: Class wlafClass = WindowsLookAndFeel.class;
117: Class plafClass = PMDLookAndFeel.class;
118: Object[] defaults = {
119: "document",
120: LookAndFeel.makeIcon(plafClass, "icons/Document.gif"),
121: "cancel",
122: LookAndFeel.makeIcon(plafClass, "icons/cancel.gif"),
123: "save",
124: LookAndFeel.makeIcon(plafClass, "icons/Save.gif"),
125: "saveAs",
126: LookAndFeel.makeIcon(plafClass, "icons/SaveAs.gif"),
127: "print",
128: LookAndFeel.makeIcon(plafClass, "icons/Print.gif"),
129: "copy",
130: LookAndFeel.makeIcon(plafClass, "icons/Copy.gif"),
131: "edit",
132: LookAndFeel.makeIcon(plafClass, "icons/edit.gif"),
133: "view",
134: LookAndFeel.makeIcon(plafClass, "icons/View.gif"),
135: "help",
136: LookAndFeel.makeIcon(plafClass, "icons/help.gif"),
137: "pmdLogo",
138: LookAndFeel.makeIcon(plafClass, "icons/pmdLogo.gif"),
139: "pmdLogoImage",
140: getImageIcon("icons/pmdLogo.jpg"),
141: "labelFont",
142: new Font("Dialog", Font.BOLD, 12),
143: "label14Font",
144: new Font("Dialog", Font.BOLD, 14),
145: "label16Font",
146: new Font("Dialog", Font.BOLD, 16),
147: "dataFont",
148: new Font("Dialog", Font.PLAIN, 12),
149: "codeFont",
150: new Font("Monospaced", Font.PLAIN, 12),
151: "tabFont",
152: new Font("SansSerif", Font.BOLD, 12),
153: "titleFont",
154: new Font("SansSerif", Font.BOLD, 14),
155: "buttonFont",
156: new Font("SansSerif", Font.BOLD, 12),
157: "messageFont",
158: new Font("Dialog", Font.PLAIN, 12),
159: "serif12Font",
160: new Font("Serif", Font.PLAIN, 12),
161: "serif14Font",
162: new Font("Serif", Font.PLAIN, 14),
163: "viewerProperties",
164: loadViewerProperties(),
165:
166: // These are all the icons defined in the WindowsLookAndFeel. We redefine them
167: // here because of the way they are defined in that class: in terms of the return
168: // value of getClass(). I.e., getClass() just returns the handle to the invoking
169: // class, which now is PMDLookAndFeel. That means that the icons are searched
170: // for in the PMD look and feel package, which is not where they really are.
171: // Since we've just called the superclass method, the icons have been installed
172: // incorrectly in the table. Reinstall them using the correct class.
173:
174: "Tree.openIcon",
175: LookAndFeel.makeIcon(wlafClass, "icons/TreeOpen.gif"),
176: "Tree.closedIcon",
177: LookAndFeel.makeIcon(wlafClass, "icons/TreeClosed.gif"),
178: "Tree.leafIcon",
179: LookAndFeel.makeIcon(wlafClass, "icons/TreeLeaf.gif"),
180:
181: "FileChooser.newFolderIcon",
182: LookAndFeel.makeIcon(wlafClass, "icons/NewFolder.gif"),
183: "FileChooser.upFolderIcon",
184: LookAndFeel.makeIcon(wlafClass, "icons/UpFolder.gif"),
185: "FileChooser.homeFolderIcon",
186: LookAndFeel.makeIcon(wlafClass, "icons/HomeFolder.gif"),
187: "FileChooser.detailsViewIcon",
188: LookAndFeel
189: .makeIcon(wlafClass, "icons/DetailsView.gif"),
190: "FileChooser.listViewIcon",
191: LookAndFeel.makeIcon(wlafClass, "icons/ListView.gif"),
192:
193: "FileView.directoryIcon",
194: LookAndFeel.makeIcon(wlafClass, "icons/Directory.gif"),
195: "FileView.fileIcon",
196: LookAndFeel.makeIcon(wlafClass, "icons/File.gif"),
197: "FileView.computerIcon",
198: LookAndFeel.makeIcon(wlafClass, "icons/Computer.gif"),
199: "FileView.hardDriveIcon",
200: LookAndFeel.makeIcon(wlafClass, "icons/HardDrive.gif"),
201: "FileView.floppyDriveIcon",
202: LookAndFeel
203: .makeIcon(wlafClass, "icons/FloppyDrive.gif"), };
204:
205: table.putDefaults(defaults);
206: }
207:
208: /**
209: ****************************************************************************
210: *
211: * @return
212: */
213: private Properties loadViewerProperties() {
214: Properties properties = new Properties();
215:
216: try {
217: InputStream inputStream = getClass().getResourceAsStream(
218: "pmdViewer.properties");
219:
220: if (inputStream != null) {
221: properties.load(inputStream);
222: }
223: } catch (IOException exception) {
224: exception.printStackTrace();
225: }
226:
227: return properties;
228: }
229:
230: /**
231: *******************************************************************************
232: *
233: * @param fileName
234: *
235: * @return
236: */
237: protected static final ImageIcon getImageIcon(String fileName) {
238: final byte[][] buffer = new byte[1][];
239:
240: try {
241: InputStream resource = PMDLookAndFeel.class
242: .getResourceAsStream(fileName);
243:
244: if (resource == null) {
245: return null;
246: }
247:
248: BufferedInputStream in;
249: ByteArrayOutputStream out;
250: int n;
251:
252: in = new BufferedInputStream(resource);
253: out = new ByteArrayOutputStream(1024);
254: buffer[0] = new byte[1024];
255:
256: while ((n = in.read(buffer[0])) >= 0) {
257: out.write(buffer[0], 0, n);
258: }
259:
260: in.close();
261: out.flush();
262: buffer[0] = out.toByteArray();
263: } catch (IOException ioe) {
264: return null;
265: }
266:
267: if (buffer[0] == null) {
268: return null;
269: }
270:
271: if (buffer[0].length == 0) {
272: return null;
273: }
274:
275: return new ImageIcon(buffer[0]);
276: }
277: }
|