This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 90371
Collapse All | Expand All

(-)a/applemenu/src/org/netbeans/modules/applemenu/CtrlClickHack.java (-27 / +54 lines)
Lines 43-85 Link Here
43
43
44
import java.awt.AWTEvent;
44
import java.awt.AWTEvent;
45
import java.awt.event.AWTEventListener;
45
import java.awt.event.AWTEventListener;
46
import java.awt.event.FocusEvent;
46
import java.awt.event.InputEvent;
47
import java.awt.event.InputEvent;
47
import java.awt.event.MouseEvent;
48
import java.awt.event.MouseEvent;
49
import java.lang.ref.Reference;
50
import java.lang.ref.WeakReference;
48
import java.lang.reflect.Field;
51
import java.lang.reflect.Field;
49
import java.lang.reflect.Method;
52
import java.lang.reflect.Method;
53
import javax.swing.text.JTextComponent;
50
54
51
/**
55
/**
52
 * hack for issue #67799, on macosx with single button mouse,
56
 * hack for issue #67799, on macosx with single button mouse,
53
 * make Ctrl-Click work as right click on multiselections
57
 * make Ctrl-Click work as right click on multiselections
54
 * @author ttran
58
 *
59
 * Also handles issue #90371 - on Macintosh, JTextComponents
60
 * are never sent focus lost events, resulting in multiple
61
 * blinking caret.s
62
 * 
63
 * @author ttran, tboudreau
55
 */
64
 */
56
public class CtrlClickHack implements AWTEventListener {
65
public class CtrlClickHack implements AWTEventListener {
57
66
    private Reference<JTextComponent> lastFocusedTextComponent = null;
58
    /** Creates a new instance of CtrlClickHack */
67
    public void eventDispatched(AWTEvent e) {
59
    public CtrlClickHack() {
68
        if (!(e instanceof MouseEvent) && !(e instanceof FocusEvent)) {
69
            return;
70
        }
71
        if (e instanceof MouseEvent) {
72
            MouseEvent evt = (MouseEvent) e;
73
            if (evt.getModifiers() != (InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK)) {
74
                return;
75
            }
76
            try {
77
                Field f1 = InputEvent.class.getDeclaredField("modifiers");
78
                Field f2 = MouseEvent.class.getDeclaredField("button");
79
                Method m = MouseEvent.class.getDeclaredMethod("setNewModifiers", new Class[] {});
80
                f1.setAccessible(true);
81
                f1.setInt(evt, InputEvent.BUTTON3_MASK);
82
                f2.setAccessible(true);
83
                f2.setInt(evt, MouseEvent.BUTTON3);
84
                m.setAccessible(true);
85
                m.invoke(evt, new Object[] {});
86
            } catch (Exception ex) {
87
                ex.printStackTrace();
88
            }
89
        } else {
90
            System.err.println("Handling focus event");
91
            FocusEvent fe = (FocusEvent) e;
92
            if (fe.getID() == FocusEvent.FOCUS_GAINED) {
93
                if (fe.getOppositeComponent() instanceof JTextComponent) {
94
                    JTextComponent jtc = (JTextComponent) fe.getOppositeComponent();
95
                    jtc.getCaret().setVisible(false);
96
                } else {
97
                    JTextComponent jtc = lastFocusedTextComponent == null ? null :
98
                        lastFocusedTextComponent.get();
99
                    if (jtc != null) {
100
                        jtc.getCaret().setVisible(false);
101
                    }
102
                }
103
                if (fe.getComponent() instanceof JTextComponent) {
104
                    JTextComponent jtc = (JTextComponent) fe.getComponent();
105
                    lastFocusedTextComponent = new WeakReference<JTextComponent>(jtc);
106
                    jtc.getCaret().setVisible(true);
107
                }
108
            }
109
        }
60
    }
110
    }
61
111
62
    public void eventDispatched(AWTEvent e) {
63
        if (! (e instanceof MouseEvent)) {
64
            return;
65
        }
66
        MouseEvent evt = (MouseEvent) e;
67
        if (evt.getModifiers() != (InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK)) {
68
            return;
69
        }
70
        try {
71
            Field f1 = InputEvent.class.getDeclaredField("modifiers");
72
            Field f2 = MouseEvent.class.getDeclaredField("button");
73
            Method m = MouseEvent.class.getDeclaredMethod("setNewModifiers", new Class[] {});
74
            f1.setAccessible(true);
75
            f1.setInt(evt, InputEvent.BUTTON3_MASK);
76
            f2.setAccessible(true);
77
            f2.setInt(evt, MouseEvent.BUTTON3);
78
            m.setAccessible(true);
79
            m.invoke(evt, new Object[] {});
80
        } catch (Exception ex) {
81
            ex.printStackTrace();
82
        }
83
    }
84
    
85
}
112
}
(-)a/applemenu/src/org/netbeans/modules/applemenu/Install.java (-2 / +4 lines)
Lines 55-63 Link Here
55
public class Install extends ModuleInstall {
55
public class Install extends ModuleInstall {
56
    private CtrlClickHack listener;
56
    private CtrlClickHack listener;
57
57
58
    @Override
58
    public void restored () {
59
    public void restored () {
59
        listener = new CtrlClickHack();
60
        listener = new CtrlClickHack();
60
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK);
61
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
61
        if (System.getProperty("mrj.version") != null) { // NOI18N
62
        if (System.getProperty("mrj.version") != null) { // NOI18N
62
//            FontReferenceQueue.install();
63
//            FontReferenceQueue.install();
63
            try {
64
            try {
Lines 74-80 Link Here
74
            }
75
            }
75
        }
76
        }
76
    }
77
    }
77
    
78
79
    @Override
78
    public void uninstalled () {
80
    public void uninstalled () {
79
         if (listener != null) {
81
         if (listener != null) {
80
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
82
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
(-)a/applemenu/src/org/netbeans/modules/applemenu/MinimizeWindowAction.java (-64 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.applemenu;
43
44
import java.awt.Frame;
45
import java.awt.event.ActionEvent;
46
import javax.swing.AbstractAction;
47
import org.openide.windows.WindowManager;
48
49
/**
50
 * JDK on Mac ignores Meta-M shortcut to minimize the main window, so we need 
51
 * to define our own shortcut and assign shortcut to it.
52
 * 
53
 * @author S. Aubrecht
54
 */
55
public class MinimizeWindowAction extends AbstractAction {
56
57
    public MinimizeWindowAction() {
58
    }
59
    
60
    public void actionPerformed(ActionEvent arg0) {
61
        WindowManager.getDefault().getMainWindow().setExtendedState(Frame.ICONIFIED);
62
    }
63
64
}

Return to bug 90371