1/*
2 * Copyright (c) 2011, 2015, 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
26package com.apple.laf;
27
28import java.awt.*;
29
30import javax.swing.*;
31import javax.swing.plaf.ComponentUI;
32import javax.swing.plaf.basic.BasicTextAreaUI;
33import javax.swing.text.*;
34
35public class AquaTextAreaUI extends BasicTextAreaUI {
36    public static ComponentUI createUI(final JComponent c) {
37        return new AquaTextAreaUI();
38    }
39
40    public AquaTextAreaUI() {
41        super();
42    }
43
44    AquaFocusHandler handler;
45    @Override
46    protected void installListeners() {
47        super.installListeners();
48
49        final JTextComponent c = getComponent();
50        handler = new AquaFocusHandler();
51        c.addFocusListener(handler);
52        c.addPropertyChangeListener(handler);
53
54        AquaUtilControlSize.addSizePropertyListener(c);
55    }
56
57    @Override
58    protected void uninstallListeners() {
59        final JTextComponent c = getComponent();
60
61        AquaUtilControlSize.removeSizePropertyListener(c);
62
63        c.removeFocusListener(handler);
64        c.removePropertyChangeListener(handler);
65        handler = null;
66
67        super.uninstallListeners();
68    }
69
70    boolean oldDragState = false;
71    @Override
72    protected void installDefaults() {
73        if (!GraphicsEnvironment.isHeadless()) {
74            oldDragState = getComponent().getDragEnabled();
75            getComponent().setDragEnabled(true);
76        }
77        super.installDefaults();
78    }
79
80    @Override
81    protected void uninstallDefaults() {
82        if (!GraphicsEnvironment.isHeadless()) {
83            getComponent().setDragEnabled(oldDragState);
84        }
85        super.uninstallDefaults();
86    }
87
88    // Install a default keypress action which handles Cmd and Option keys
89    // properly
90    @Override
91    protected void installKeyboardActions() {
92        super.installKeyboardActions();
93        AquaKeyBindings bindings = AquaKeyBindings.instance();
94        bindings.setDefaultAction(getKeymapName());
95        final JTextComponent c = getComponent();
96        bindings.installAquaUpDownActions(c);
97    }
98
99    @Override
100    protected Caret createCaret() {
101        return new AquaCaret();
102    }
103
104    @Override
105    protected Highlighter createHighlighter() {
106        return new AquaHighlighter();
107    }
108}
109