Package sun.awt

Examples of sun.awt.AppContext


     *
     * @return ExecutorService for the {@code SwingWorkers}
     * @see #startAutoShutdownThread
     */
    private static synchronized ExecutorService getWorkersExecutorService() {
        final AppContext appContext = AppContext.getAppContext();
        Object obj = appContext.get(SwingWorker.class);
        if (obj == null) {
            //this creates non-daemon threads.
            ThreadFactory threadFactory =
                new ThreadFactory() {
                    final ThreadFactory defaultFactory =
                        Executors.defaultThreadFactory();
                    public Thread newThread(final Runnable r) {
                        Thread thread =
                            defaultFactory.newThread(r);
                        thread.setName("SwingWorker-"
                            + thread.getName());
                        return thread;
                    }
                };

            /*
             * We want a to have no more than MAX_WORKER_THREADS
             * running threads.
             *
             * We want a worker thread to wait no longer than 1 second
             * for new tasks before terminating.
             */
            obj = new ThreadPoolExecutor(0, MAX_WORKER_THREADS,
                                         1L, TimeUnit.SECONDS,
                                         new LinkedBlockingQueue<Runnable>(),
                                         threadFactory) {

                    private final ReentrantLock pauseLock = new ReentrantLock();
                    private final Condition unpaused = pauseLock.newCondition();
                    private boolean isPaused = false;
                    private final ReentrantLock executeLock = new ReentrantLock();
                   
                    @Override
                    public void execute(Runnable command) {
                        /*
                         * ThreadPoolExecutor first tries to run task
                         * in a corePool. If all threads are busy it
                         * tries to add task to the waiting queue. If it
                         * fails it run task in maximumPool.
                         *
                         * We want corePool to be 0 and
                         * maximumPool to be MAX_WORKER_THREADS
                         * We need to change the order of the execution.
                         * First try corePool then try maximumPool
                         * pool and only then store to the waiting
                         * queue. We can not do that because we would
                         * need access to the private methods.
                         *
                         * Instead we enlarge corePool to
                         * MAX_WORKER_THREADS before the execution and
                         * shrink it back to 0 after.
                         * It does pretty much what we need.
                         *
                         * While we changing the corePoolSize we need
                         * to stop running worker threads from accepting new
                         * tasks.
                         */
                       
                        //we need atomicity for the execute method.
                        executeLock.lock();
                        try {

                            pauseLock.lock();
                            try {
                                isPaused = true;
                            } finally {
                                pauseLock.unlock();
                            }
                           
                            setCorePoolSize(MAX_WORKER_THREADS);
                            super.execute(command);
                            setCorePoolSize(0);
                           
                            pauseLock.lock();
                            try {
                                isPaused = false;
                                unpaused.signalAll();
                            } finally {
                                pauseLock.unlock();
                            }
                        } finally {
                            executeLock.unlock();
                        }
                    }
                    @Override
                    protected void afterExecute(Runnable r, Throwable t) {
                        super.afterExecute(r, t);
                        pauseLock.lock();
                        try {
                            while(isPaused) {
                                unpaused.await();
                            }
                        } catch(InterruptedException ignore) {
                           
                        } finally {
                            pauseLock.unlock();
                        }
                    }
                };
            appContext.put(SwingWorker.class, obj);
        }
        return (ExecutorService)obj;
    }
View Full Code Here


    }
   
    private static final Object DO_SUBMIT_KEY = new Object(); // doSubmit
    private static AccumulativeRunnable<Runnable> getDoSubmit() {
        synchronized (DO_SUBMIT_KEY) {
            final AppContext appContext = AppContext.getAppContext();
            Object doSubmit = appContext.get(DO_SUBMIT_KEY);
            if (doSubmit == null) {
                doSubmit = new DoSubmitAccumulativeRunnable();
                appContext.put(DO_SUBMIT_KEY, doSubmit);
            }
            return (AccumulativeRunnable<Runnable>) doSubmit;
        }
    }
View Full Code Here

    // ********************************
    //        Create PLAF
    // ********************************
    public static ComponentUI createUI(JComponent b) {
        AppContext appContext = AppContext.getAppContext();
        BasicRadioButtonUI radioButtonUI =
                (BasicRadioButtonUI) appContext.get(BASIC_RADIO_BUTTON_UI_KEY);
        if (radioButtonUI == null) {
            radioButtonUI = new BasicRadioButtonUI();
            appContext.put(BASIC_RADIO_BUTTON_UI_KEY, radioButtonUI);
        }
        return radioButtonUI;
    }
View Full Code Here

    // ********************************
    //            Create PLAF
    // ********************************
    public static ComponentUI createUI(JComponent b) {
        AppContext appContext = AppContext.getAppContext();
        BasicCheckBoxUI checkboxUI =
                (BasicCheckBoxUI) appContext.get(BASIC_CHECK_BOX_UI_KEY);
        if (checkboxUI == null) {
            checkboxUI = new BasicCheckBoxUI();
            appContext.put(BASIC_CHECK_BOX_UI_KEY, checkboxUI);
        }
        return checkboxUI;
    }
View Full Code Here

     * @return the current theme
     * @see #setCurrentTheme
     * @since 1.5
     */
    public static MetalTheme getCurrentTheme() {
        AppContext context = AppContext.getAppContext();

  if ( cachedAppContext != context ) {
      currentTheme = (MetalTheme)context.get( "currentMetalTheme" );
            if (currentTheme == null) {
                // This will happen in two cases:
                // . When MetalLookAndFeel is first being initialized.
                // . When a new AppContext has been created that hasn't
                //   triggered UIManager to load a LAF. Rather than invoke
View Full Code Here

     * Called by NimbusLookAndFeel when the look and feel is being uninstalled.
     * Performs general cleanup of any app-context specific data.
     */
    static void uninitialize() {
        // get the appcontext that we've stored data in
        AppContext ctx = AppContext.getAppContext();
       
        // get the pcl stored in app context
        PropertyChangeListener pcl = (PropertyChangeListener)
                ctx.get("NimbusStyle.defaults.pcl");
       
        // if the pcl exists, uninstall it from the UIDefaults tables
        if (pcl != null) {
            UIManager.getDefaults().removePropertyChangeListener(pcl);
            UIManager.getLookAndFeelDefaults().removePropertyChangeListener(pcl);
        }
       
        // clear out the compiled defaults
        ctx.put("NimbusStyle.defaults", null);
    }
View Full Code Here

        // map on each call to this method where "values" was null. It turns
        // out this was happening a lot.
        // To remove this bottleneck, we store the compiled TreeMaps of defaults
        // in the appContext for reuse. It is nulled whenever the UIDefaults
        // changes and recomputed when necessary.
        final AppContext ctx = AppContext.getAppContext();
       
        // fetch the defaults from the app context. If null, then create and
        // store the compiled defaults
        Map<String, TreeMap<String, Object>> compiledDefaults =
                (Map<String, TreeMap<String, Object>>)
                    ctx.get("NimbusStyle.defaults");
       
        if (compiledDefaults == null) {
            // the entire UIDefaults tables are parsed and compiled into
            // this map of maps. The key of the compiledDefaults is the
            // prefix for each style, while the value is a map of
            // keys->values for that prefix.
            compiledDefaults = new HashMap<String, TreeMap<String, Object>>();
           
            // get all the defaults from UIManager.getDefaults() and put them
            // into the compiledDefaults
            compileDefaults(compiledDefaults, UIManager.getDefaults());

            // This second statement pulls defaults from the laf defaults
            UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
            compileDefaults(compiledDefaults, lafDefaults);
           
            // if it has not already been done, add a listener to both
            // UIManager.getDefaults() and UIManager.getLookAndFeelDefaults().
            PropertyChangeListener pcl = (PropertyChangeListener)
                    ctx.get("NimbusStyle.defaults.pcl");
           
            // if pcl is null, then it has not yet been registered with
            // the UIManager defaults for this app context
            if (pcl == null) {
                // create a PCL which will simply clear out the compiled
                // defaults from the app context, causing it to be recomputed
                // on subsequent passes
                pcl = new DefaultsListener();
                // add the PCL to both defaults tables that we pay attention
                // to, so that if the UIDefaults are updated, then the
                // precompiled defaults will be cleared from the app context
                // and recomputed on subsequent passes
                UIManager.getDefaults().addPropertyChangeListener(pcl);
                UIManager.getLookAndFeelDefaults().addPropertyChangeListener(pcl);
                // save the PCL to the app context as a marker indicating
                // that the PCL has been registered so we don't end up adding
                // more than one listener to the UIDefaults tables.
                ctx.put("NimbusStyle.defaults.pcl", pcl);
            }
           
            // store the defaults for reuse
            ctx.put("NimbusStyle.defaults", compiledDefaults);
        }
       
        TreeMap<String, Object> defaults = compiledDefaults.get(prefix);
       
        // inspect the client properties for the key "Nimbus.Overrides". If the
View Full Code Here

  setBumpColors( newTopColor, newShadowColor, newBackColor );
    }

    private static BumpBuffer createBuffer(GraphicsConfiguration gc,
                                           Color topColor, Color shadowColor, Color backColor) {
        AppContext context = AppContext.getAppContext();
        List<BumpBuffer> buffers = (List<BumpBuffer>) context.get(METAL_BUMPS);
        if (buffers == null) {
            buffers = new ArrayList<BumpBuffer>();
            context.put(METAL_BUMPS, buffers);
        }
        for (BumpBuffer buffer : buffers) {
            if (buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) {
                return buffer;
            }
View Full Code Here

    // ********************************
    //         Create PlAF
    // ********************************
    public static ComponentUI createUI(JComponent b) {
        AppContext appContext = AppContext.getAppContext();
        MetalCheckBoxUI checkboxUI =
                (MetalCheckBoxUI) appContext.get(METAL_CHECK_BOX_UI_KEY);
        if (checkboxUI == null) {
            checkboxUI = new MetalCheckBoxUI();
            appContext.put(METAL_CHECK_BOX_UI_KEY, checkboxUI);
        }
        return checkboxUI;
    }
View Full Code Here

        if (menuKeyListener == null) {
            menuKeyListener = new BasicMenuKeyListener();
        }
        popupMenu.addMenuKeyListener(menuKeyListener);

        AppContext context = AppContext.getAppContext();
        synchronized (MOUSE_GRABBER_KEY) {
            MouseGrabber mouseGrabber = (MouseGrabber)context.get(
                                                     MOUSE_GRABBER_KEY);  
            if (mouseGrabber == null) {   
                mouseGrabber = new MouseGrabber();  
                context.put(MOUSE_GRABBER_KEY, mouseGrabber);  
            }
        }
        synchronized (MENU_KEYBOARD_HELPER_KEY) {
            MenuKeyboardHelper helper =
                    (MenuKeyboardHelper)context.get(MENU_KEYBOARD_HELPER_KEY);
            if (helper == null) {
                helper = new MenuKeyboardHelper();
                context.put(MENU_KEYBOARD_HELPER_KEY, helper);
                MenuSelectionManager msm = MenuSelectionManager.defaultManager();
                msm.addChangeListener(helper);
            }
        }
    }
View Full Code Here

TOP

Related Classes of sun.awt.AppContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.