use of java.awt.HeadlessException in project JMRI by JMRI.
the class ReportContext method addScreenSize.
/**
* Provide screen - size information. This is based on the
* jmri.util.JmriJFrame calculation, but isn't refactored to there because
* we also want diagnostic info
*/
public void addScreenSize() {
try {
// Find screen size. This throws null-pointer exceptions on
// some Java installs, however, for unknown reasons, so be
// prepared to fall back.
JFrame dummy = new JFrame();
try {
Insets insets = dummy.getToolkit().getScreenInsets(dummy.getGraphicsConfiguration());
Dimension screen = dummy.getToolkit().getScreenSize();
addString("Screen size h:" + screen.height + ", w:" + screen.width + " Inset t:" + insets.top + ", b:" + insets.bottom + "; l:" + insets.left + ", r:" + insets.right);
} catch (NoSuchMethodError ex) {
Dimension screen = dummy.getToolkit().getScreenSize();
addString("Screen size h:" + screen.height + ", w:" + screen.width + " (No Inset method available)");
}
} catch (HeadlessException ex) {
// failed, fall back to standard method
addString("(Cannot sense screen size due to " + ex.toString() + ")");
}
try {
// Find screen resolution. Not expected to fail, but just in case....
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
addString("Screen resolution: " + dpi);
} catch (HeadlessException ex) {
addString("Screen resolution not available");
}
//Rectangle virtualBounds = new Rectangle();
try {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
addString("Environment max bounds: " + ge.getMaximumWindowBounds());
try {
GraphicsDevice[] gs = ge.getScreenDevices();
for (GraphicsDevice gd : gs) {
GraphicsConfiguration[] gc = gd.getConfigurations();
for (int i = 0; i < gc.length; i++) {
addString("bounds[" + i + "] = " + gc[i].getBounds());
// virtualBounds = virtualBounds.union(gc[i].getBounds());
}
addString("Device: " + gd.getIDstring() + " bounds = " + gd.getDefaultConfiguration().getBounds() + " " + gd.getDefaultConfiguration().toString());
}
} catch (HeadlessException ex) {
addString("Exception getting device bounds " + ex.getMessage());
}
} catch (HeadlessException ex) {
addString("Exception getting max window bounds " + ex.getMessage());
}
// various Linux window managers
try {
Insets jmriInsets = JmriInsets.getInsets();
addString("JmriInsets t:" + jmriInsets.top + ", b:" + jmriInsets.bottom + "; l:" + jmriInsets.left + ", r:" + jmriInsets.right);
} catch (Exception ex) {
addString("Exception getting JmriInsets" + ex.getMessage());
}
}
use of java.awt.HeadlessException in project JMRI by JMRI.
the class InputWindow method storeFile.
/**
* Save the contents of this input window to a file.
*
* @param fileChooser the chooser to select the file with
* @return true if successful; false otherwise
*/
protected boolean storeFile(JFileChooser fileChooser) {
boolean results = false;
File file = getFile(fileChooser);
if (file != null) {
try {
// check for possible overwrite
if (file.exists()) {
int selectedValue = JOptionPane.showConfirmDialog(null, "File " + file.getName() + " already exists, overwrite it?", "Overwrite file?", JOptionPane.OK_CANCEL_OPTION);
if (selectedValue != JOptionPane.OK_OPTION) {
// user clicked no to override
results = false;
return results;
}
}
StringBuilder fileData = new StringBuilder(area.getText());
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.append(fileData);
}
} catch (HeadlessException | IOException e) {
log.error("Unhandled problem in storeFile: " + e);
}
} else {
// If the file is null then the user has clicked cancel.
results = true;
}
return results;
}
use of java.awt.HeadlessException in project JMRI by JMRI.
the class RosterEntry method updateFile.
/**
* Write the contents of this RosterEntry back to a file, preserving all
* existing decoder CV content.
* <p>
* This writes the file back in place, with the same decoder-specific
* content.
*/
public void updateFile() {
LocoFile df = new LocoFile();
String fullFilename = LocoFile.getFileLocation() + getFileName();
// read in the content
try {
mRootElement = df.rootFromName(fullFilename);
} catch (JDOMException | IOException e) {
log.error("Exception while loading loco XML file: " + getFileName() + " exception: " + e);
}
try {
File f = new File(fullFilename);
// do backup
df.makeBackupFile(LocoFile.getFileLocation() + getFileName());
// and finally write the file
df.writeFile(f, mRootElement, this.store());
} catch (Exception e) {
log.error("error during locomotive file output", e);
try {
JOptionPane.showMessageDialog(null, ResourceBundle.getBundle("jmri.jmrit.roster.JmritRosterBundle").getString("ErrorSavingText") + "\n" + e.getMessage(), ResourceBundle.getBundle("jmri.jmrit.roster.JmritRosterBundle").getString("ErrorSavingTitle"), JOptionPane.ERROR_MESSAGE);
} catch (HeadlessException he) {
// silently ignore inability to display dialog
}
}
}
use of java.awt.HeadlessException in project processdash by dtuma.
the class WBSEditor method main.
public static void main(String[] args) {
args = maybeParseJnlpArgs(args);
if (isDumpAndExitMode())
System.setProperty("java.awt.headless", "true");
ExternalLocationMapper.getInstance().loadDefaultMappings();
RuntimeUtils.autoregisterPropagatedSystemProperties();
for (String prop : PROPS_TO_PROPAGATE) RuntimeUtils.addPropagatedSystemProperty(prop, null);
String[] locations = args;
boolean bottomUp = Boolean.getBoolean("teamdash.wbs.bottomUp");
boolean indivMode = Boolean.getBoolean("teamdash.wbs.indiv");
String indivInitials = System.getProperty("teamdash.wbs.indivInitials");
boolean showTeam = Boolean.getBoolean("teamdash.wbs.showTeamMemberList");
boolean readOnly = Boolean.getBoolean("teamdash.wbs.readOnly") || TeamServerSelector.isHistoricalModeEnabled();
String syncURL = System.getProperty("teamdash.wbs.syncURL");
String itemHref = System.getProperty("teamdash.wbs.showItem");
String owner = System.getProperty("teamdash.wbs.owner");
try {
createAndShowEditor(locations, bottomUp, indivMode, indivInitials, showTeam, syncURL, true, readOnly, itemHref, owner);
} catch (HeadlessException he) {
he.printStackTrace();
System.exit(1);
}
new Timer(DAY_MILLIS, new UsageLogAction()).start();
maybeNotifyOpened();
}
use of java.awt.HeadlessException in project Lucee by lucee.
the class Image method toBufferedImage.
// This method returns a buffered image with the contents of an image
public static BufferedImage toBufferedImage(java.awt.Image image) {
if (image instanceof BufferedImage) {
return (BufferedImage) image;
}
// This code ensures that all the pixels in the image are loaded
image = new ImageIcon(image).getImage();
// Determine if the image has transparent pixels; for this method's
boolean hasAlpha = hasAlpha(image);
// Create a buffered image with a format that's compatible with the screen
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// Determine the type of transparency of the new buffered image
int transparency = Transparency.OPAQUE;
if (hasAlpha) {
transparency = Transparency.BITMASK;
}
// Create the buffered image
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency);
} catch (HeadlessException e) {
// The system does not have a screen
}
if (bimage == null) {
// Create a buffered image using the default color model
int type = BufferedImage.TYPE_INT_RGB;
if (hasAlpha) {
type = BufferedImage.TYPE_INT_ARGB;
}
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
}
// Copy image to buffered image
Graphics g = bimage.createGraphics();
// Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose();
return bimage;
}
Aggregations