Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 138943
Collapse All | Expand All

(-)applemenu/src/org/netbeans/modules/applemenu/FontReferenceQueue.java (-134 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.Font;
45
import java.lang.ref.Reference;
46
import java.lang.ref.ReferenceQueue;
47
import java.lang.reflect.Field;
48
49
// #57664: Random crash on Mac OS X.  Apple JDK apparently has a bug in
50
// the native part of the font handling code.  Font instances seems to share
51
// native data structures which are released when the instances are finalized.
52
// Because the native data are shared, their premature release causes random
53
// JVM crashes.
54
//
55
// This evil hack forces Font.finalize() not to run.  The native font data
56
// are leaked but it's still better than total crash
57
58
class FontReferenceQueue extends ReferenceQueue {
59
    /**
60
     * Polls this queue to see if a reference object is available.  If one is
61
     * available without further delay then it is removed from the queue and
62
     * returned.  Otherwise this method immediately returns <tt>null</tt>.
63
     * 
64
     * @return  A reference object, if one was immediately available,
65
     *          otherwise <code>null</code>
66
     */
67
    public Reference poll() {
68
        Reference ref;
69
        
70
        for (;;) {
71
            ref = super.poll();
72
            if (ref == null)
73
                break;
74
            
75
            Object obj = ref.get();
76
            if (! (obj instanceof Font))
77
                break;
78
        }
79
        return ref;
80
    }
81
82
    /**
83
     * Removes the next reference object in this queue, blocking until either
84
     * one becomes available or the given timeout period expires.
85
     * 
86
     * <p> This method does not offer real-time guarantees: It schedules the
87
     * timeout as if by invoking the {@link Object#wait(long)} method.
88
     * 
89
     * @param  timeout  If positive, block for up <code>timeout</code>
90
     *                  milliseconds while waiting for a reference to be
91
     *                  added to this queue.  If zero, block indefinitely.
92
     * 
93
     * @return  A reference object, if one was available within the specified
94
     *          timeout period, otherwise <code>null</code>
95
     * 
96
     * @throws  IllegalArgumentException
97
     *          If the value of the timeout argument is negative
98
     * 
99
     * @throws  InterruptedException
100
     *          If the timeout wait is interrupted
101
     */
102
    public Reference remove(long timeout) throws IllegalArgumentException, InterruptedException {
103
        // timeout is not handled correctly, but good enough for our purposes
104
        
105
        Reference ref;
106
        
107
        for (;;) {
108
            ref = super.remove(timeout);
109
            if (ref == null)
110
                break;
111
            
112
            Object obj = ref.get();
113
            if (! (obj instanceof Font))
114
                break;
115
        }
116
        return ref;
117
    }
118
        
119
    static void install() {
120
        try {
121
            Class clzz = Class.forName("java.lang.ref.Finalizer");  // NOI18N
122
            Field fld = clzz.getDeclaredField("queue");  // NOI18N
123
            fld.setAccessible(true);
124
            fld.set(null, new FontReferenceQueue());
125
        } catch (NoClassDefFoundError ex) {
126
            // ex.printStackTrace();
127
        } catch (ClassNotFoundException ex) {
128
            // ex.printStackTrace();
129
        } catch (Exception ex) {
130
            // ex.printStackTrace();
131
        }
132
        
133
    }
134
}
(-)applemenu/src/org/netbeans/modules/applemenu/Install.java (-4 / +15 lines)
 Lines 44-49    Link Here 
44
import java.awt.AWTEvent;
44
import java.awt.AWTEvent;
45
import java.awt.Toolkit;
45
import java.awt.Toolkit;
46
import java.lang.reflect.*;
46
import java.lang.reflect.*;
47
import java.util.logging.Logger;
47
import org.openide.modules.ModuleInstall;
48
import org.openide.modules.ModuleInstall;
48
49
49
/** Module installer that installs an com.apple.eawt.ApplicationListener on
50
/** Module installer that installs an com.apple.eawt.ApplicationListener on
 Lines 55-65    Link Here 
55
public class Install extends ModuleInstall {
56
public class Install extends ModuleInstall {
56
    private CtrlClickHack listener;
57
    private CtrlClickHack listener;
57
58
58
    public void restored () {
59
    @Override
59
        listener = new CtrlClickHack();
60
    public void validate() throws IllegalStateException {
60
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK);
61
        Logger.getLogger(Install.class.getName()).warning("VALIDATE!!!!!!!!!!!!!!!!");
62
        System.out.println("VALIDATE!!!!!!!");
63
61
        if (System.getProperty("mrj.version") != null) { // NOI18N
64
        if (System.getProperty("mrj.version") != null) { // NOI18N
62
//            FontReferenceQueue.install();
63
            try {
65
            try {
64
                Class adapter = Class.forName("org.netbeans.modules.applemenu.NbApplicationAdapter");
66
                Class adapter = Class.forName("org.netbeans.modules.applemenu.NbApplicationAdapter");
65
                Method m = adapter.getDeclaredMethod("install", new Class[0] );
67
                Method m = adapter.getDeclaredMethod("install", new Class[0] );
 Lines 74-80    Link Here 
74
            }
76
            }
75
        }
77
        }
76
    }
78
    }
79
80
    @Override
81
    public void restored () {
82
        Logger.getLogger(Install.class.getName()).warning("RESTOREDE!!!!!!!!!!!!!!!!");
83
        System.out.println("RESTURED!!!!!!!");
84
        listener = new CtrlClickHack();
85
        Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.MOUSE_EVENT_MASK);
86
    }
77
    
87
    
88
    @Override
78
    public void uninstalled () {
89
    public void uninstalled () {
79
         if (listener != null) {
90
         if (listener != null) {
80
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
91
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
(-)applemenu/src/org/netbeans/modules/applemenu/NbApplicationAdapter.java (-2 / +7 lines)
 Lines 45-56    Link Here 
45
45
46
import java.beans.Beans;
46
import java.beans.Beans;
47
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionEvent;
48
import java.io.IOException;
48
import java.util.logging.Logger;
49
import javax.swing.Action;
49
import javax.swing.Action;
50
50
51
import org.openide.ErrorManager;
51
import org.openide.ErrorManager;
52
import org.openide.filesystems.*;
52
import org.openide.filesystems.*;
53
import org.openide.actions.*;
54
import org.openide.cookies.InstanceCookie;
53
import org.openide.cookies.InstanceCookie;
55
import org.openide.loaders.DataObject;
54
import org.openide.loaders.DataObject;
56
55
 Lines 77-82    Link Here 
77
    }
76
    }
78
77
79
    static void install() {
78
    static void install() {
79
        Logger.getLogger(NbApplicationAdapter.class.getName()).warning("INSTALLING!!!!!!!!!!!!!!!!");
80
        System.out.println("INSTALLING!!!!");
80
        //Thanks to Scott Kovatch from Apple for this fix - enabling the preferences menu
81
        //Thanks to Scott Kovatch from Apple for this fix - enabling the preferences menu
81
        //requires that Beans.isDesignTime() be false
82
        //requires that Beans.isDesignTime() be false
82
        boolean wasDesignTime = Beans.isDesignTime();
83
        boolean wasDesignTime = Beans.isDesignTime();
 Lines 105-113    Link Here 
105
    }
106
    }
106
    
107
    
107
    public void handleOpenApplication (ApplicationEvent e) {
108
    public void handleOpenApplication (ApplicationEvent e) {
109
        Logger.getLogger(NbApplicationAdapter.class.getName()).warning("handling open application!!!!!!!!!!!!!!!!");
110
        System.out.println("HANDLE OPEN");
108
    }
111
    }
109
    
112
    
110
    public void handleOpenFile (ApplicationEvent e) {
113
    public void handleOpenFile (ApplicationEvent e) {
114
        Logger.getLogger(NbApplicationAdapter.class.getName()).warning("Opening file " + e.getFilename());
115
        System.out.println("HANDLE OPEN FILE");
111
        e.setHandled(performAction (OPENFILE_ACTION, e.getFilename()));
116
        e.setHandled(performAction (OPENFILE_ACTION, e.getFilename()));
112
    }
117
    }
113
    
118
    

Return to bug 138943
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo