Check if screen's DisplayMode is not null.

cusax-fix
Sebastien Vincent 17 years ago
parent b5b010db67
commit 96fe4b483e

@ -476,17 +476,17 @@ public ZrtpControl createZrtpControl()
{
return new ZrtpControlImpl();
}
/**
* Get available screens.
*
*
* @return screens
*/
public List<ScreenDevice> getAvailableScreenDevices()
{
List<ScreenDevice> ret = new ArrayList<ScreenDevice>();
ScreenDevice screens[] = ScreenDeviceImpl.getAvailableScreenDevice();
if(screens != null)
{
/* populates screen list */
@ -497,7 +497,7 @@ public List<ScreenDevice> getAvailableScreenDevices()
}
return ret;
}
/**
* Get default screen device.
*
@ -509,19 +509,20 @@ public ScreenDevice getDefaultScreenDevice()
ScreenDevice best = null;
int width = 0;
int height = 0;
for(ScreenDevice sc : screens)
{
java.awt.Dimension res = sc.getSize();
if(width < res.getSize().width || height < res.getSize().height)
if(res != null && (width < res.getSize().width ||
height < res.getSize().height))
{
width = res.width;
height = res.height;
best = sc;
}
}
return best;
}
}

@ -12,7 +12,7 @@
/**
* Implementation of <tt>ScreenDevice</tt>.
*
*
* @author Sebastien Vincent
*/
public class ScreenDeviceImpl implements ScreenDevice
@ -21,10 +21,10 @@ public class ScreenDeviceImpl implements ScreenDevice
* AWT <tt>GraphicsDevice</tt>.
*/
GraphicsDevice screen = null;
/**
* Returns all available <tt>ScreenDevice</tt> device.
*
*
* @return array of <tt>ScreenDevice</tt> device
*/
public static ScreenDevice[] getAvailableScreenDevice()
@ -33,7 +33,7 @@ public static ScreenDevice[] getAvailableScreenDevice()
GraphicsDevice devices[] = null;
GraphicsEnvironment ge = null;
int i = 0;
try
{
ge = GraphicsEnvironment.
@ -43,31 +43,31 @@ public static ScreenDevice[] getAvailableScreenDevice()
{
ge = null;
}
if(ge == null)
{
return null;
}
devices = ge.getScreenDevices();
if(devices == null || devices.length == 0)
{
return null;
}
screens = new ScreenDevice[devices.length];
for(GraphicsDevice dev : devices)
{
/* we know that GraphicsDevice type is TYPE_RASTER_SCREEN */
screens[i] = new ScreenDeviceImpl(dev);
i++;
}
return screens;
}
/**
* Constructor.
*
@ -77,17 +77,22 @@ protected ScreenDeviceImpl(GraphicsDevice screen)
{
this.screen = screen;
}
/**
* Get current resolution of <tt>ScreenDevice</tt> device.
*
*
* @return current resolution of the screen
*/
public Dimension getSize()
{
/* get current display resolution */
DisplayMode mode = screen.getDisplayMode();
return new Dimension(mode.getWidth(), mode.getHeight());
if(mode != null)
{
return new Dimension(mode.getWidth(), mode.getHeight());
}
return null;
}
}

Loading…
Cancel
Save