@@ -129,16 +129,34 @@ private int displayDensityImpl() {
129129
130130
131131 private int displayDensityImpl (int display ) {
132- if (display > 0 && display <= displayDevices .length ) {
133- GraphicsConfiguration graphicsConfig =
134- displayDevices [display - 1 ].getDefaultConfiguration ();
132+ GraphicsConfiguration graphicsConfig = null ;
133+
134+ if (display == -1 ) { // the default display
135+ GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment ();
136+ graphicsConfig = ge .getDefaultScreenDevice ().getDefaultConfiguration ();
137+
138+ } else if (display == SPAN ) {
139+ // walk through all displays, go with lowest common denominator
140+ for (int i = 0 ; i < displayDevices .length ; i ++) {
141+ if (displayDensityImpl (i ) == 1 ) {
142+ return 1 ;
143+ }
144+ }
145+ return 2 ; // everyone is density 2
146+
147+ } else if (display <= displayDevices .length ) {
148+ graphicsConfig = displayDevices [display - 1 ].getDefaultConfiguration ();
149+ }
150+
151+ if (graphicsConfig == null ) {
152+ System .err .println ("Display " + display + " does not exist, " +
153+ "returning 1 for displayDensity(" + display + ")" );
154+ return 1 ; // not the end of the world, so don't throw a RuntimeException
155+
156+ } else {
135157 AffineTransform tx = graphicsConfig .getDefaultTransform ();
136158 return (int ) Math .round (tx .getScaleX ());
137159 }
138-
139- System .err .println ("Display " + display + " does not exist, " +
140- "returning 1 for displayDensity(" + display + ")" );
141- return 1 ; // not the end of the world, so don't throw a RuntimeException
142160 }
143161
144162
0 commit comments