001/* % [{ 002% (C) Copyright 2008 Nicolas Carranza and individual contributors. 003% See the jpen-copyright.txt file in the jpen distribution for a full 004% listing of individual contributors. 005% 006% This file is part of jpen. 007% 008% jpen is free software: you can redistribute it and/or modify 009% it under the terms of the GNU Lesser General Public License as published by 010% the Free Software Foundation, either version 3 of the License, or 011% (at your option) any later version. 012% 013% jpen is distributed in the hope that it will be useful, 014% but WITHOUT ANY WARRANTY; without even the implied warranty of 015% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016% GNU Lesser General Public License for more details. 017% 018% You should have received a copy of the GNU Lesser General Public License 019% along with jpen. If not, see <http://www.gnu.org/licenses/>. 020% }] */ 021package jpen.provider; 022 023import java.awt.DisplayMode; 024import java.awt.geom.AffineTransform; 025import java.awt.geom.Rectangle2D; 026import java.awt.GraphicsConfiguration; 027import java.awt.GraphicsDevice; 028import java.awt.GraphicsEnvironment; 029import java.util.logging.Level; 030import java.util.logging.Logger; 031import jpen.PLevel; 032 033public final class VirtualScreenBounds{ 034 static final Logger L=Logger.getLogger(VirtualScreenBounds.class.getName()); 035 private static VirtualScreenBounds INSTANCE; 036 private final Rectangle2D.Float r=new Rectangle2D.Float(); 037 038 { 039 // first time calc is expensive... I do it once in a background thread 040 new Thread(){ 041 { 042 setName("jpen-VirtualScreenBounds"); 043 setDaemon(true); 044 } 045 @Override 046 public void run(){ 047 reset(); 048 L.fine("first calculation done."); 049 } 050 }.start(); 051 } 052 053 private VirtualScreenBounds(){} 054 055 public static VirtualScreenBounds getInstance(){ 056 if(INSTANCE==null) 057 INSTANCE=new VirtualScreenBounds(); 058 return INSTANCE; 059 } 060 061 public synchronized void reset(){ 062 r.x=r.y=r.width=r.height=0; 063 calc(r); 064 } 065 066 static void calc(Rectangle2D r){ 067 for (GraphicsDevice gd: GraphicsEnvironment. 068 getLocalGraphicsEnvironment().getScreenDevices()){ 069 GraphicsConfiguration graphicsConfiguration=gd.getDefaultConfiguration(); 070 r.add(graphicsConfiguration.getBounds()); 071 } 072 } 073 074 public float getLevelRangeMult(PLevel.Type type) { 075 switch(type){ 076 case X: 077 return r.width; 078 case Y: 079 return r.height; 080 default: 081 return 1f; 082 } 083 } 084 085 public float getLevelRangeOffset(PLevel.Type type){ 086 switch(type){ 087 case X: 088 return r.x; 089 case Y: 090 return r.y; 091 default: 092 return 0f; 093 } 094 } 095}