1 /*
2  * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.apple.laf;
27 
28 import java.awt.*;
29 import java.awt.event.FocusListener;
30 
31 import javax.swing.*;
32 import javax.swing.plaf.ComponentUI;
33 import javax.swing.plaf.basic.BasicEditorPaneUI;
34 import javax.swing.text.*;
35 
36 public class AquaEditorPaneUI extends BasicEditorPaneUI {
createUI(final JComponent c)37     public static ComponentUI createUI(final JComponent c){
38         return new AquaEditorPaneUI();
39     }
40 
41     boolean oldDragState = false;
installDefaults()42     protected void installDefaults(){
43         super.installDefaults();
44         if(!GraphicsEnvironment.isHeadless()){
45             oldDragState = getComponent().getDragEnabled();
46             getComponent().setDragEnabled(true);
47         }
48     }
49 
uninstallDefaults()50     protected void uninstallDefaults(){
51         if(!GraphicsEnvironment.isHeadless()){
52             getComponent().setDragEnabled(oldDragState);
53         }
54         super.uninstallDefaults();
55     }
56 
57     FocusListener focusListener;
installListeners()58     protected void installListeners(){
59         super.installListeners();
60         focusListener = createFocusListener();
61         getComponent().addFocusListener(focusListener);
62     }
63 
installKeyboardActions()64     protected void installKeyboardActions() {
65         super.installKeyboardActions();
66         AquaKeyBindings bindings = AquaKeyBindings.instance();
67         bindings.setDefaultAction(getKeymapName());
68         final JTextComponent c = getComponent();
69         bindings.installAquaUpDownActions(c);
70     }
71 
uninstallListeners()72     protected void uninstallListeners(){
73         getComponent().removeFocusListener(focusListener);
74         super.uninstallListeners();
75     }
76 
createFocusListener()77     protected FocusListener createFocusListener(){
78         return new AquaFocusHandler();
79     }
80 
createCaret()81     protected Caret createCaret(){
82         final Window owningWindow = SwingUtilities.getWindowAncestor(getComponent());
83         final AquaCaret returnValue = new AquaCaret(owningWindow, getComponent());
84         return returnValue;
85     }
86 
createHighlighter()87     protected Highlighter createHighlighter(){
88         return new AquaHighlighter();
89     }
90 }
91