< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m

Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion


  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 #import "CSystemColors.h"
  27 
  28 #import "java_awt_SystemColor.h"
  29 #import "sun_lwawt_macosx_LWCToolkit.h"
  30 
  31 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  32 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
  33 
  34 #import "ThreadUtilities.h"

  35 
  36 NSColor **sColors = nil;
  37 NSColor **appleColors = nil;
  38 
  39 @implementation CSystemColors
  40 
  41 + (void)initialize {
  42     JNIEnv *env = [ThreadUtilities getJNIEnv];
  43 JNF_COCOA_ENTER(env);
  44     [CSystemColors reloadColors];
  45     [[NSNotificationCenter defaultCenter] addObserver:[CSystemColors class] selector:@selector(systemColorsDidChange:) name:NSSystemColorsDidChangeNotification object:nil];
  46 JNF_COCOA_EXIT(env);
  47 }
  48 
  49 static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
  50 static JNF_STATIC_MEMBER_CACHE(jm_systemColorsChanged, jc_LWCToolkit, "systemColorsChanged", "()V");
  51 
  52 + (void)systemColorsDidChange:(NSNotification *)notification {
  53     AWT_ASSERT_APPKIT_THREAD;
  54 
  55     [CSystemColors reloadColors];
  56 
  57     // Call LWCToolkit with the news. LWCToolkit makes certain to do its duties
  58     // from a new thread.
  59     JNIEnv* env = [ThreadUtilities getJNIEnv];
  60     JNFCallStaticVoidMethod(env, jm_systemColorsChanged); // AWT_THREADING Safe (event)




  61 }
  62 
  63 
  64 + (void)reloadColors {
  65     // NOTE: <rdar://problem/3447825> was filed to make this code even lazier. Each
  66     //  color below could be set lazily when it was first accessed. This way the
  67     //  arrays would be sparse, and filled in as SystemColors were used.
  68     int i;
  69     if (sColors == nil) {
  70         sColors = (NSColor**)malloc(sizeof(NSColor*) * java_awt_SystemColor_NUM_COLORS);
  71     } else {
  72         for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
  73             if (sColors[i] != NULL) [sColors[i] release];
  74         }
  75     }
  76 
  77     sColors[java_awt_SystemColor_DESKTOP] =                    [NSColor greenColor];
  78     sColors[java_awt_SystemColor_ACTIVE_CAPTION] =            [NSColor whiteColor];
  79     sColors[java_awt_SystemColor_ACTIVE_CAPTION_TEXT] =        [NSColor blackColor];
  80     sColors[java_awt_SystemColor_ACTIVE_CAPTION_BORDER] =    [NSColor whiteColor];




  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 #import "CSystemColors.h"
  27 
  28 #import "java_awt_SystemColor.h"
  29 #import "sun_lwawt_macosx_LWCToolkit.h"
  30 

  31 #import <JavaRuntimeSupport/JavaRuntimeSupport.h>
  32 
  33 #import "ThreadUtilities.h"
  34 #import "JNIUtilities.h"
  35 
  36 NSColor **sColors = nil;
  37 NSColor **appleColors = nil;
  38 
  39 @implementation CSystemColors
  40 
  41 + (void)initialize {
  42     JNIEnv *env = [ThreadUtilities getJNIEnv];
  43 JNI_COCOA_ENTER(env);
  44     [CSystemColors reloadColors];
  45     [[NSNotificationCenter defaultCenter] addObserver:[CSystemColors class] selector:@selector(systemColorsDidChange:) name:NSSystemColorsDidChangeNotification object:nil];
  46 JNI_COCOA_EXIT(env);
  47 }
  48 


  49 
  50 + (void)systemColorsDidChange:(NSNotification *)notification {
  51     AWT_ASSERT_APPKIT_THREAD;
  52 
  53     [CSystemColors reloadColors];
  54 
  55     // Call LWCToolkit with the news. LWCToolkit makes certain to do its duties
  56     // from a new thread.
  57     JNIEnv* env = [ThreadUtilities getJNIEnv];
  58     DECLARE_CLASS(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit");
  59     DECLARE_STATIC_METHOD(jm_systemColorsChanged, jc_LWCToolkit, "systemColorsChanged", "()V");
  60     (*env)->CallStaticVoidMethod(env, jc_LWCToolkit, jm_systemColorsChanged); // AWT_THREADING Safe (event)
  61     CHECK_EXCEPTION();
  62 
  63 }
  64 
  65 
  66 + (void)reloadColors {
  67     // NOTE: <rdar://problem/3447825> was filed to make this code even lazier. Each
  68     //  color below could be set lazily when it was first accessed. This way the
  69     //  arrays would be sparse, and filled in as SystemColors were used.
  70     int i;
  71     if (sColors == nil) {
  72         sColors = (NSColor**)malloc(sizeof(NSColor*) * java_awt_SystemColor_NUM_COLORS);
  73     } else {
  74         for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
  75             if (sColors[i] != NULL) [sColors[i] release];
  76         }
  77     }
  78 
  79     sColors[java_awt_SystemColor_DESKTOP] =                    [NSColor greenColor];
  80     sColors[java_awt_SystemColor_ACTIVE_CAPTION] =            [NSColor whiteColor];
  81     sColors[java_awt_SystemColor_ACTIVE_CAPTION_TEXT] =        [NSColor blackColor];
  82     sColors[java_awt_SystemColor_ACTIVE_CAPTION_BORDER] =    [NSColor whiteColor];


< prev index next >