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;
}
use of java.awt.HeadlessException in project eclipse.platform.releng by eclipse.
the class AwtScreenshot method main.
public static void main(String[] args) {
try {
System.setProperty("java.awt.headless", "false");
Robot robot = new Robot();
Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = robot.createScreenCapture(rect);
File file = new File(args[0]);
ImageIO.write(image, "png", file);
System.out.println("AWT screenshot saved to: " + file.getAbsolutePath());
} catch (HeadlessException e) {
e.printStackTrace();
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations