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