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 219507
Collapse All | Expand All

(-)a/openide.util/src/org/openide/util/Utilities.java (-1 / +53 lines)
Lines 92-102 Link Here
92
import java.util.List;
92
import java.util.List;
93
import java.util.Locale;
93
import java.util.Locale;
94
import java.util.Map;
94
import java.util.Map;
95
import java.util.Map.Entry;
95
import java.util.NoSuchElementException;
96
import java.util.NoSuchElementException;
96
import java.util.Set;
97
import java.util.Set;
97
import java.util.StringTokenizer;
98
import java.util.StringTokenizer;
98
import java.util.TreeSet;
99
import java.util.TreeSet;
99
import java.util.Vector;
100
import java.util.Vector;
101
import java.util.WeakHashMap;
100
import java.util.logging.Level;
102
import java.util.logging.Level;
101
import java.util.logging.Logger;
103
import java.util.logging.Logger;
102
import javax.lang.model.SourceVersion;
104
import javax.lang.model.SourceVersion;
Lines 232-237 Link Here
232
234
233
    /** regular expression to with all changes */
235
    /** regular expression to with all changes */
234
    private static RE transExp;
236
    private static RE transExp;
237
    
238
    private static final Map<GraphicsConfiguration, Map<Rectangle, Long>> screenBoundsCache;
239
    static {
240
        final boolean cacheEnabled = !GraphicsEnvironment.isHeadless() && isUnix() && !isMac() && (System.getProperty("netbeans.screen.insetsCache", "true").equalsIgnoreCase("true")) ;
241
        
242
        if(cacheEnabled){
243
            screenBoundsCache = new WeakHashMap<GraphicsConfiguration, Map<Rectangle, Long>>();
244
        }
245
        else{
246
            screenBoundsCache = null;
247
        }
248
    }
235
249
236
    //
250
    //
237
    // Support for work with actions
251
    // Support for work with actions
Lines 2030-2037 Link Here
2030
2044
2031
    /**
2045
    /**
2032
     * Returns the usable area of the screen where applications can place its
2046
     * Returns the usable area of the screen where applications can place its
2033
     * windows.  The method subtracts from the screen the area of taskbars,
2047
     * windows. The method subtracts from the screen the area of taskbars,
2034
     * system menus and the like.
2048
     * system menus and the like.
2049
     * On certain platforms this methods uses a cache to avoid performance degradation due to repeated calls.
2050
     * This can be disabled by setting the property "-Dnetbeans.screen.insetsCache=false"
2035
     *
2051
     *
2036
     * @param gconf the GraphicsConfiguration of the monitor
2052
     * @param gconf the GraphicsConfiguration of the monitor
2037
     * @return the rectangle of the screen where one can place windows
2053
     * @return the rectangle of the screen where one can place windows
Lines 2042-2047 Link Here
2042
        if (gconf == null) {
2058
        if (gconf == null) {
2043
            gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
2059
            gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
2044
        }
2060
        }
2061
        if(screenBoundsCache == null){
2062
            return determineUsableScreenBounds(gconf);
2063
        }
2064
        
2065
        synchronized(screenBoundsCache){
2066
            Map<Rectangle, Long> cacheEntry = screenBoundsCache.get(gconf);
2067
            if(cacheEntry != null){
2068
                final long now = System.currentTimeMillis();
2069
                Entry<Rectangle, Long> entry = cacheEntry.entrySet().iterator().next();
2070
                if(entry.getValue() < now + 10000) { // cache hit, 10 seconds lifetime
2071
                    return new Rectangle(entry.getKey()); // return copy
2072
                }
2073
            }
2074
            
2075
            final Rectangle screenBounds = determineUsableScreenBounds(gconf);
2076
            cacheEntry = new HashMap<Rectangle, Long>(1);
2077
            cacheEntry.put(screenBounds, System.currentTimeMillis());
2078
            if(screenBoundsCache.size() > 20){ //maximum entries
2079
                screenBoundsCache.clear();
2080
            }
2081
            screenBoundsCache.put(gconf, cacheEntry);
2082
            return new Rectangle(screenBounds);
2083
        }
2084
    }
2085
    
2086
    /**
2087
     * Returns the usable area of the screen where applications can place its
2088
     * windows.  The method subtracts from the screen the area of taskbars,
2089
     * system menus and the like.
2090
     *
2091
     * @param gconf the GraphicsConfiguration of the monitor
2092
     * @return the rectangle of the screen where one can place windows
2093
     *
2094
     * @since 2.5
2095
     */
2096
    private static Rectangle determineUsableScreenBounds(GraphicsConfiguration gconf) {
2045
2097
2046
        Rectangle bounds = new Rectangle(gconf.getBounds());
2098
        Rectangle bounds = new Rectangle(gconf.getBounds());
2047
2099

Return to bug 219507