use of java.awt.DisplayMode in project TeachingInSimulation by ScOrPiOzzy.
the class SettingDialog method initResolution.
private void initResolution() {
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice sd = g.getDefaultScreenDevice();
DisplayMode[] modes = sd.getDisplayModes();
List<Resolution> resolutions = new ArrayList<Resolution>();
for (DisplayMode mode : modes) {
int width = mode.getWidth();
int height = mode.getHeight();
if (mode.getRefreshRate() != 60 || mode.getBitDepth() != 32) {
continue;
}
if (width == 1366 && height == 768) {
resolutions.add(new Resolution(width, height));
} else if (width == 1600 && height == 900) {
resolutions.add(new Resolution(width, height));
} else if (width == 1920 && height == 1080) {
resolutions.add(new Resolution(width, height));
}
}
resolutions.sort(new Comparator<Resolution>() {
@Override
public int compare(Resolution o1, Resolution o2) {
int width1 = o1.getWidth();
int width2 = o2.getWidth();
if (width1 == width2) {
return 0;
}
return width1 > width2 ? 1 : -1;
}
});
resolution.getItems().addAll(resolutions);
Preferences prefs = Preferences.userRoot().node(SettingConsts.REG_APP_PATH);
// 分辨率
int width = prefs.getInt(SettingConsts.RESOLUTION_WIDTH, 1366);
if (width < 1366) {
width = 1366;
}
int height = prefs.getInt(SettingConsts.RESOLUTION_HEIGHT, 768);
if (height < 768) {
height = 768;
}
resolution.getSelectionModel().select(new Resolution(width, height));
boolean fullscreen = prefs.getBoolean(SettingConsts.SCREEN_MODE, false);
full.setSelected(fullscreen);
}
use of java.awt.DisplayMode in project TeachingInSimulation by ScOrPiOzzy.
the class TestReslution2 method display.
private void display() {
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice sd = g.getDefaultScreenDevice();
DisplayMode[] dm = sd.getDisplayModes();
List<String> resolution = new ArrayList<>();
for (int i = 0; i < dm.length; i++) {
String res = String.format("%sx%s", dm[i].getWidth(), dm[i].getHeight());
if (resolution.indexOf(res) == -1) {
resolution.add(res);
}
}
resolution.forEach(System.out::println);
}
use of java.awt.DisplayMode in project TeachingInSimulation by ScOrPiOzzy.
the class TestReslution2 method doSnap.
protected void doSnap(final ImageView iv) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
Robot robot = null;
try {
robot = new Robot(gs[gs.length - 1]);
} catch (AWTException e) {
e.printStackTrace();
return;
}
DisplayMode mode = gs[0].getDisplayMode();
Rectangle bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
final BufferedImage bi = robot.createScreenCapture(bounds);
Platform.runLater(new Runnable() {
@Override
public void run() {
Image im = SwingFXUtils.toFXImage(bi, null);
iv.setImage(im);
}
});
}
use of java.awt.DisplayMode in project lionengine by b3dgs.
the class ScreenFullAwt method initFullscreen.
/**
* Prepare fullscreen mode.
*
* @param output The output resolution
* @param depth The bit depth color.
* @throws LionEngineException If unsupported resolution.
*/
private void initFullscreen(Resolution output, int depth) {
final java.awt.Window window = new java.awt.Window(frame, conf);
window.setBackground(Color.BLACK);
window.setIgnoreRepaint(true);
window.setPreferredSize(new Dimension(output.getWidth(), output.getHeight()));
dev.setFullScreenWindow(window);
final DisplayMode disp = isSupported(new DisplayMode(output.getWidth(), output.getHeight(), depth, output.getRate()));
if (disp == null) {
throw new LionEngineException(ScreenFullAwt.ERROR_UNSUPPORTED_FULLSCREEN + formatResolution(output, depth) + getSupportedResolutions());
}
if (!dev.isDisplayChangeSupported()) {
throw new LionEngineException(ScreenFullAwt.ERROR_SWITCH);
}
dev.setDisplayMode(disp);
window.validate();
ToolsAwt.createBufferStrategy(window, conf);
buf = window.getBufferStrategy();
// Set input listeners
componentForKeyboard = frame;
componentForMouse = window;
componentForCursor = window;
frame.validate();
}
use of java.awt.DisplayMode in project lionengine by b3dgs.
the class ScreenFullAwt method getSupportedResolutions.
/**
* Get the supported resolution information.
*
* @return The supported resolutions.
*/
private String getSupportedResolutions() {
final StringBuilder builder = new StringBuilder(Constant.HUNDRED);
int i = 0;
for (final DisplayMode display : dev.getDisplayModes()) {
final StringBuilder widthSpace = new StringBuilder();
final int width = display.getWidth();
if (width < Constant.THOUSAND) {
widthSpace.append(Constant.SPACE);
}
final StringBuilder heightSpace = new StringBuilder();
final int height = display.getHeight();
if (height < Constant.THOUSAND) {
heightSpace.append(System.lineSeparator());
}
final StringBuilder freqSpace = new StringBuilder();
final int freq = display.getRefreshRate();
if (freq < Constant.HUNDRED) {
freqSpace.append(Constant.SPACE);
}
builder.append("Supported display mode:").append(System.lineSeparator()).append('[').append(widthSpace).append(width).append(Constant.STAR).append(heightSpace).append(height).append(Constant.STAR).append(display.getBitDepth()).append(Constant.SPACE).append(Constant.AT).append(freqSpace).append(freq).append(Constant.UNIT_RATE).append(']').append(Constant.SPACE);
i++;
final int linesPerDisplay = 5;
if (i % linesPerDisplay == 0) {
builder.append(System.lineSeparator());
}
}
return builder.toString();
}
Aggregations