001: /*
002: * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.X11;
027:
028: import java.awt.Color;
029: import java.awt.Font;
030: import java.awt.SystemColor;
031:
032: import javax.swing.*;
033: import javax.swing.plaf.*;
034: import javax.swing.border.*;
035: import javax.swing.text.DefaultEditorKit;
036:
037: import javax.swing.plaf.basic.BasicBorders;
038: import com.sun.java.swing.plaf.motif.*;
039: import sun.awt.X11.XComponentPeer;
040:
041: class XAWTLookAndFeel extends MotifLookAndFeel {
042:
043: /**
044: * Load the SystemColors into the defaults table. The keys
045: * for SystemColor defaults are the same as the names of
046: * the public fields in SystemColor. If the table is being
047: * created on a native Motif platform we use the SystemColor
048: * values, otherwise we create color objects whose values match
049: * the default CDE/Motif colors.
050: */
051: protected void initSystemColorDefaults(UIDefaults table) {
052: String[] defaultSystemColors = { "desktop", "#005C5C", /* Color of the desktop background */
053: "activeCaption", "#000080", /* Color for captions (title bars) when they are active. */
054: "activeCaptionText", "#FFFFFF", /* Text color for text in captions (title bars). */
055: "activeCaptionBorder", "#B24D7A", /* Border color for caption (title bar) window borders. */
056: "inactiveCaption", "#AEB2C3", /* Color for captions (title bars) when not active. */
057: "inactiveCaptionText", "#000000", /* Text color for text in inactive captions (title bars). */
058: "inactiveCaptionBorder", "#AEB2C3", /* Border color for inactive caption (title bar) window borders. */
059: "window", "#AEB2C3", /* Default color for the interior of windows */
060: "windowBorder", "#AEB2C3", /* ??? */
061: "windowText", "#000000", /* ??? */
062: "menu", "#AEB2C3", /* ??? */
063: "menuText", "#000000", /* ??? */
064: "text", "#FFF7E9", /* Text background color */
065: "textText", "#000000", /* Text foreground color */
066: "textHighlight", "#000000", /* Text background color when selected */
067: "textHighlightText", "#FFF7E9", /* Text color when selected */
068: "textInactiveText", "#808080", /* Text color when disabled */
069: "control", "#AEB2C3", /* Default color for controls (buttons, sliders, etc) */
070: "controlText", "#000000", /* Default color for text in controls */
071: "controlHighlight", "#DCDEE5", /* Highlight color for controls */
072: "controlLtHighlight", "#DCDEE5", /* Light highlight color for controls */
073: "controlShadow", "#63656F", /* Shadow color for controls */
074: "controlLightShadow", "#9397A5", /* Shadow color for controls */
075: "controlDkShadow", "#000000", /* Dark shadow color for controls */
076: "scrollbar", "#AEB2C3", /* Scrollbar ??? color. PENDING(jeff) foreground? background? ?*/
077: "info", "#FFF7E9", /* ??? */
078: "infoText", "#000000" /* ??? */
079: };
080:
081: loadSystemColors(table, defaultSystemColors, true);
082: }
083:
084: protected void initComponentDefaults(UIDefaults table) {
085: super .initComponentDefaults(table);
086:
087: FontUIResource dialogPlain12 = new FontUIResource(Font.DIALOG,
088: Font.PLAIN, 12);
089: FontUIResource sansSerifPlain12 = new FontUIResource(
090: Font.SANS_SERIF, Font.PLAIN, 12);
091: FontUIResource monospacedPlain12 = new FontUIResource(
092: Font.MONOSPACED, Font.PLAIN, 12);
093: ColorUIResource red = new ColorUIResource(Color.red);
094: ColorUIResource black = new ColorUIResource(Color.black);
095: ColorUIResource white = new ColorUIResource(Color.white);
096: ColorUIResource lightGray = new ColorUIResource(Color.lightGray);
097: ColorUIResource controlDarker = new ColorUIResource(
098: SystemColor.controlDkShadow);
099:
100: Color back = table.getColor("control");
101: Color colors[] = XComponentPeer.getSystemColors();
102: Color scrollBarBackground = colors[XComponentPeer.BACKGROUND_COLOR];
103: Color trackColor = new Color(MotifColorUtilities
104: .calculateSelectFromBackground(scrollBarBackground
105: .getRed(), scrollBarBackground.getGreen(),
106: scrollBarBackground.getBlue()));
107: Border loweredBevelBorder = new MotifBorders.BevelBorder(false,
108: table.getColor("controlShadow"), table
109: .getColor("controlLtHighlight"));
110:
111: Border raisedBevelBorder = new MotifBorders.BevelBorder(true,
112: table.getColor("controlShadow"), table
113: .getColor("controlLtHighlight"));
114:
115: Border marginBorder = new BasicBorders.MarginBorder();
116:
117: Border focusBorder = new MotifBorders.FocusBorder(table
118: .getColor("control"), table
119: .getColor("activeCaptionBorder"));
120:
121: Border focusBevelBorder = new BorderUIResource.CompoundBorderUIResource(
122: focusBorder, loweredBevelBorder);
123:
124: Border textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
125: focusBevelBorder, marginBorder);
126:
127: // *** Text
128:
129: Object fieldInputMap = new UIDefaults.LazyInputMap(
130: new Object[] { "COPY", DefaultEditorKit.copyAction,
131: "PASTE", DefaultEditorKit.pasteAction, "CUT",
132: DefaultEditorKit.cutAction, "control C",
133: DefaultEditorKit.copyAction, "control V",
134: DefaultEditorKit.pasteAction, "control X",
135: DefaultEditorKit.cutAction, "control INSERT",
136: DefaultEditorKit.copyAction, "shift INSERT",
137: DefaultEditorKit.pasteAction, "shift DELETE",
138: DefaultEditorKit.cutAction, "control F",
139: DefaultEditorKit.forwardAction, "control B",
140: DefaultEditorKit.backwardAction, "control D",
141: DefaultEditorKit.deleteNextCharAction,
142: "typed \010",
143: DefaultEditorKit.deletePrevCharAction,
144: "DELETE",
145: DefaultEditorKit.deleteNextCharAction, "RIGHT",
146: DefaultEditorKit.forwardAction, "LEFT",
147: DefaultEditorKit.backwardAction, "KP_RIGHT",
148: DefaultEditorKit.forwardAction, "KP_LEFT",
149: DefaultEditorKit.backwardAction, "shift LEFT",
150: DefaultEditorKit.selectionBackwardAction,
151: "shift RIGHT",
152: DefaultEditorKit.selectionForwardAction,
153: "control LEFT",
154: DefaultEditorKit.previousWordAction,
155: "control RIGHT",
156: DefaultEditorKit.nextWordAction,
157: "control shift LEFT",
158: DefaultEditorKit.selectionPreviousWordAction,
159: "control shift RIGHT",
160: DefaultEditorKit.selectionNextWordAction,
161: "control SLASH",
162: DefaultEditorKit.selectAllAction, "HOME",
163: DefaultEditorKit.beginLineAction, "END",
164: DefaultEditorKit.endLineAction, "shift HOME",
165: DefaultEditorKit.selectionBeginLineAction,
166: "shift END",
167: DefaultEditorKit.selectionEndLineAction,
168: "control BACK_SLASH", "unselect", "ENTER",
169: JTextField.notifyAction, "control shift O",
170: "toggle-componentOrientation" });
171:
172: Object passwordInputMap = new UIDefaults.LazyInputMap(
173: new Object[] { "COPY", DefaultEditorKit.copyAction,
174: "PASTE", DefaultEditorKit.pasteAction, "CUT",
175: DefaultEditorKit.cutAction, "control C",
176: DefaultEditorKit.copyAction, "control V",
177: DefaultEditorKit.pasteAction, "control X",
178: DefaultEditorKit.cutAction, "control INSERT",
179: DefaultEditorKit.copyAction, "shift INSERT",
180: DefaultEditorKit.pasteAction, "shift DELETE",
181: DefaultEditorKit.cutAction, "control F",
182: DefaultEditorKit.forwardAction, "control B",
183: DefaultEditorKit.backwardAction, "control D",
184: DefaultEditorKit.deleteNextCharAction,
185: "typed \010",
186: DefaultEditorKit.deletePrevCharAction,
187: "DELETE",
188: DefaultEditorKit.deleteNextCharAction, "RIGHT",
189: DefaultEditorKit.forwardAction, "LEFT",
190: DefaultEditorKit.backwardAction, "KP_RIGHT",
191: DefaultEditorKit.forwardAction, "KP_LEFT",
192: DefaultEditorKit.backwardAction, "shift LEFT",
193: DefaultEditorKit.selectionBackwardAction,
194: "shift RIGHT",
195: DefaultEditorKit.selectionForwardAction,
196: "control LEFT",
197: DefaultEditorKit.beginLineAction,
198: "control RIGHT",
199: DefaultEditorKit.endLineAction,
200: "control shift LEFT",
201: DefaultEditorKit.selectionBeginLineAction,
202: "control shift RIGHT",
203: DefaultEditorKit.selectionEndLineAction,
204: "control SLASH",
205: DefaultEditorKit.selectAllAction, "HOME",
206: DefaultEditorKit.beginLineAction, "END",
207: DefaultEditorKit.endLineAction, "shift HOME",
208: DefaultEditorKit.selectionBeginLineAction,
209: "shift END",
210: DefaultEditorKit.selectionEndLineAction,
211: "control BACK_SLASH", "unselect", "ENTER",
212: JTextField.notifyAction, "control shift O",
213: "toggle-componentOrientation" });
214:
215: Object multilineInputMap = new UIDefaults.LazyInputMap(
216: new Object[] { "COPY", DefaultEditorKit.copyAction,
217: "PASTE", DefaultEditorKit.pasteAction, "CUT",
218: DefaultEditorKit.cutAction, "control C",
219: DefaultEditorKit.copyAction, "control V",
220: DefaultEditorKit.pasteAction, "control X",
221: DefaultEditorKit.cutAction, "control INSERT",
222: DefaultEditorKit.copyAction, "shift INSERT",
223: DefaultEditorKit.pasteAction, "shift DELETE",
224: DefaultEditorKit.cutAction, "control F",
225: DefaultEditorKit.forwardAction, "control B",
226: DefaultEditorKit.backwardAction, "control D",
227: DefaultEditorKit.deleteNextCharAction,
228: "typed \010",
229: DefaultEditorKit.deletePrevCharAction,
230: "DELETE",
231: DefaultEditorKit.deleteNextCharAction, "RIGHT",
232: DefaultEditorKit.forwardAction, "LEFT",
233: DefaultEditorKit.backwardAction, "KP_RIGHT",
234: DefaultEditorKit.forwardAction, "KP_LEFT",
235: DefaultEditorKit.backwardAction, "shift LEFT",
236: DefaultEditorKit.selectionBackwardAction,
237: "shift RIGHT",
238: DefaultEditorKit.selectionForwardAction,
239: "control LEFT",
240: DefaultEditorKit.previousWordAction,
241: "control RIGHT",
242: DefaultEditorKit.nextWordAction,
243: "control shift LEFT",
244: DefaultEditorKit.selectionPreviousWordAction,
245: "control shift RIGHT",
246: DefaultEditorKit.selectionNextWordAction,
247: "control SLASH",
248: DefaultEditorKit.selectAllAction, "HOME",
249: DefaultEditorKit.beginLineAction, "END",
250: DefaultEditorKit.endLineAction, "shift HOME",
251: DefaultEditorKit.selectionBeginLineAction,
252: "shift END",
253: DefaultEditorKit.selectionEndLineAction,
254:
255: "control N", DefaultEditorKit.downAction,
256: "control P", DefaultEditorKit.upAction, "UP",
257: DefaultEditorKit.upAction, "DOWN",
258: DefaultEditorKit.downAction, "KP_UP",
259: DefaultEditorKit.upAction, "KP_DOWN",
260: DefaultEditorKit.downAction, "PAGE_UP",
261: DefaultEditorKit.pageUpAction, "PAGE_DOWN",
262: DefaultEditorKit.pageDownAction,
263: "shift PAGE_UP", "selection-page-up",
264: "shift PAGE_DOWN", "selection-page-down",
265: "ctrl shift PAGE_UP", "selection-page-left",
266: "ctrl shift PAGE_DOWN", "selection-page-right",
267: "shift UP", DefaultEditorKit.selectionUpAction,
268: "shift DOWN",
269: DefaultEditorKit.selectionDownAction,
270: "shift KP_UP",
271: DefaultEditorKit.selectionUpAction,
272: "shift KP_DOWN",
273: DefaultEditorKit.selectionDownAction, "ENTER",
274: DefaultEditorKit.insertBreakAction, "TAB",
275: DefaultEditorKit.insertTabAction,
276: "control BACK_SLASH", "unselect",
277: "control HOME", DefaultEditorKit.beginAction,
278: "control END", DefaultEditorKit.endAction,
279: "control shift HOME",
280: DefaultEditorKit.selectionBeginAction,
281: "control shift END",
282: DefaultEditorKit.selectionEndAction,
283: "control T", "next-link-action",
284: "control shift T", "previous-link-action",
285: "control SPACE", "activate-link-action",
286: "control shift O",
287: "toggle-componentOrientation" });
288:
289: Object sliderFocusInsets = new InsetsUIResource(0, 0, 0, 0);
290:
291: Object[] defaults = {
292:
293: "ScrollBar.background",
294: scrollBarBackground,
295: "ScrollBar.foreground",
296: table.get("control"),
297: "ScrollBar.track",
298: trackColor,
299: "ScrollBar.trackHighlight",
300: trackColor,
301: "ScrollBar.thumb",
302: scrollBarBackground,
303: "ScrollBar.thumbHighlight",
304: table.get("controlHighlight"),
305: "ScrollBar.thumbDarkShadow",
306: table.get("controlDkShadow"),
307: "ScrollBar.thumbShadow",
308: table.get("controlShadow"),
309: "ScrollBar.border",
310: loweredBevelBorder,
311: "ScrollBar.allowsAbsolutePositioning",
312: Boolean.TRUE,
313: "ScrollBar.defaultWidth",
314: Integer.valueOf(17),
315: "ScrollBar.focusInputMap",
316: new UIDefaults.LazyInputMap(new Object[] { "RIGHT",
317: "positiveUnitIncrement", "KP_RIGHT",
318: "positiveUnitIncrement", "DOWN",
319: "positiveUnitIncrement", "KP_DOWN",
320: "positiveUnitIncrement", "PAGE_DOWN",
321: "positiveBlockIncrement", "ctrl PAGE_DOWN",
322: "positiveBlockIncrement", "LEFT",
323: "negativeUnitIncrement", "KP_LEFT",
324: "negativeUnitIncrement", "UP",
325: "negativeUnitIncrement", "KP_UP",
326: "negativeUnitIncrement", "PAGE_UP",
327: "negativeBlockIncrement", "ctrl PAGE_UP",
328: "negativeBlockIncrement", "HOME", "minScroll",
329: "END", "maxScroll" }),
330:
331: "ScrollPane.font",
332: dialogPlain12,
333: "ScrollPane.background",
334: scrollBarBackground,
335: "ScrollPane.foreground",
336: table.get("controlText"),
337: "ScrollPane.border",
338: null,
339: "ScrollPane.viewportBorder",
340: loweredBevelBorder,
341: "ScrollPane.ancestorInputMap",
342: new UIDefaults.LazyInputMap(new Object[] { "RIGHT",
343: "unitScrollRight", "KP_RIGHT",
344: "unitScrollRight", "DOWN", "unitScrollDown",
345: "KP_DOWN", "unitScrollDown", "LEFT",
346: "unitScrollLeft", "KP_LEFT", "unitScrollLeft",
347: "UP", "unitScrollUp", "KP_UP", "unitScrollUp",
348: "PAGE_UP", "scrollUp", "PAGE_DOWN",
349: "scrollDown", "ctrl PAGE_UP", "scrollLeft",
350: "ctrl PAGE_DOWN", "scrollRight", "ctrl HOME",
351: "scrollHome", "ctrl END", "scrollEnd" }),
352:
353: "FormattedTextField.focusInputMap",
354: new UIDefaults.LazyInputMap(new Object[] { "ctrl C",
355: DefaultEditorKit.copyAction, "ctrl V",
356: DefaultEditorKit.pasteAction, "ctrl X",
357: DefaultEditorKit.cutAction, "COPY",
358: DefaultEditorKit.copyAction, "PASTE",
359: DefaultEditorKit.pasteAction, "CUT",
360: DefaultEditorKit.cutAction, "shift LEFT",
361: DefaultEditorKit.selectionBackwardAction,
362: "shift KP_LEFT",
363: DefaultEditorKit.selectionBackwardAction,
364: "shift RIGHT",
365: DefaultEditorKit.selectionForwardAction,
366: "shift KP_RIGHT",
367: DefaultEditorKit.selectionForwardAction,
368: "ctrl LEFT",
369: DefaultEditorKit.previousWordAction,
370: "ctrl KP_LEFT",
371: DefaultEditorKit.previousWordAction,
372: "ctrl RIGHT", DefaultEditorKit.nextWordAction,
373: "ctrl KP_RIGHT",
374: DefaultEditorKit.nextWordAction,
375: "ctrl shift LEFT",
376: DefaultEditorKit.selectionPreviousWordAction,
377: "ctrl shift KP_LEFT",
378: DefaultEditorKit.selectionPreviousWordAction,
379: "ctrl shift RIGHT",
380: DefaultEditorKit.selectionNextWordAction,
381: "ctrl shift KP_RIGHT",
382: DefaultEditorKit.selectionNextWordAction,
383: "ctrl A", DefaultEditorKit.selectAllAction,
384: "HOME", DefaultEditorKit.beginLineAction,
385: "END", DefaultEditorKit.endLineAction,
386: "shift HOME",
387: DefaultEditorKit.selectionBeginLineAction,
388: "shift END",
389: DefaultEditorKit.selectionEndLineAction,
390: "typed \010",
391: DefaultEditorKit.deletePrevCharAction,
392: "DELETE",
393: DefaultEditorKit.deleteNextCharAction, "RIGHT",
394: DefaultEditorKit.forwardAction, "LEFT",
395: DefaultEditorKit.backwardAction, "KP_RIGHT",
396: DefaultEditorKit.forwardAction, "KP_LEFT",
397: DefaultEditorKit.backwardAction, "ENTER",
398: JTextField.notifyAction, "ctrl BACK_SLASH",
399: "unselect", "control shift O",
400: "toggle-componentOrientation", "ESCAPE",
401: "reset-field-edit", "UP", "increment", "KP_UP",
402: "increment", "DOWN", "decrement", "KP_DOWN",
403: "decrement", }),
404:
405: "TextField.caretForeground", black,
406: "TextField.caretBlinkRate", Integer.valueOf(500),
407: "TextField.inactiveForeground",
408: table.get("textInactiveText"),
409: "TextField.selectionBackground",
410: table.get("textHighlight"),
411: "TextField.selectionForeground",
412: table.get("textHighlightText"), "TextField.background",
413: table.get("window"), "TextField.foreground",
414: table.get("textText"), "TextField.font",
415: sansSerifPlain12, "TextField.border", textFieldBorder,
416: "TextField.focusInputMap", fieldInputMap,
417:
418: "PasswordField.caretForeground", black,
419: "PasswordField.caretBlinkRate", Integer.valueOf(500),
420: "PasswordField.inactiveForeground",
421: table.get("textInactiveText"),
422: "PasswordField.selectionBackground",
423: table.get("textHighlight"),
424: "PasswordField.selectionForeground",
425: table.get("textHighlightText"),
426: "PasswordField.background", table.get("window"),
427: "PasswordField.foreground", table.get("textText"),
428: "PasswordField.font", sansSerifPlain12,
429: "PasswordField.border", textFieldBorder,
430: "PasswordField.focusInputMap", passwordInputMap,
431:
432: "TextArea.caretForeground", black,
433: "TextArea.caretBlinkRate", Integer.valueOf(500),
434: "TextArea.inactiveForeground",
435: table.get("textInactiveText"),
436: "TextArea.selectionBackground",
437: table.get("textHighlight"),
438: "TextArea.selectionForeground",
439: table.get("textHighlightText"), "TextArea.background",
440: table.get("window"), "TextArea.foreground",
441: table.get("textText"), "TextArea.font",
442: monospacedPlain12, "TextArea.border", marginBorder,
443: "TextArea.focusInputMap", multilineInputMap };
444:
445: table.putDefaults(defaults);
446: }
447: }
|