use of java.awt.GraphicsConfiguration in project opennars by opennars.
the class SCanvas method updateDoubleBuffer.
private final boolean updateDoubleBuffer() {
int w = getWidth();
int h = getHeight();
if ((w == 0) || (h == 0)) {
return false;
}
/*
* if image is already compatible and optimized for current system
* settings, simply return it
*/
if ((image != null) && /*(image.getColorModel().equals(gfx_config.getColorModel())) &&*/
(image.getWidth() == w) && (image.getHeight() == h)) {
// use existing image
} else {
// obtain the current system graphical settings
GraphicsConfiguration gfx_config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
image = gfx_config.createCompatibleImage(w, h);
}
return true;
}
use of java.awt.GraphicsConfiguration in project TrakEM2 by trakem2.
the class DisplayCanvas method render.
/**
* Adapted code from Wayne Meissner, for gstreamer-java org.gstreamer.swing.GstVideoComponent;
* Paints (and re-renders, if necessary) the volatile image onto the given Graphics object, which
* is that of the DisplayCanvas as provided to the paint(Graphics g) method.
*
* Expects clipRect in screen coordinates
*/
private void render(final Graphics g, final Displayable active, final Layer active_layer, final List<Layer> layers, final int c_alphas, final AffineTransform at, Rectangle clipRect) {
final Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHints(rhints);
do {
final ArrayList<Displayable> top;
final BufferedImage offscreen;
synchronized (offscreen_lock) {
offscreen = this.offscreen;
// will never be cleared, but may be swapped
top = this.al_top;
}
final GraphicsConfiguration gc = getGraphicsConfiguration();
// 5 images
display.getProject().getLoader().releaseToFit(getWidth() * getHeight() * 4 * 5);
// Protect volatile image while rendering it
synchronized (volatile_lock) {
if (invalid_volatile || null == volatileImage || volatileImage.validate(gc) != VolatileImage.IMAGE_OK) {
// clear clip, remade in full
clipRect = null;
renderVolatileImage(gc, offscreen, top, active, active_layer, layers, c_alphas, at, clipRect);
}
if (null != clipRect)
g2d.setClip(clipRect);
g2d.drawImage(volatileImage, 0, 0, null);
}
} while (volatileImage.contentsLost());
g2d.dispose();
// Flush all old offscreen images
synchronized (offscreen_lock) {
for (final BufferedImage bi : to_flush) {
bi.flush();
}
to_flush.clear();
}
}
use of java.awt.GraphicsConfiguration in project CCDD by nasa.
the class CcddJTableHandler method printTable.
/**
********************************************************************************************
* Output the table to the user-selected printer (or file)
*
* @param tableName
* table name; displayed at the top of each printed page
*
* @param fieldHandler
* data field handler; null if no data fields are associated with the table
*
* @param parent
* parent window for this table
*
* @param orientation
* page orientation; e.g., PageFormat.LANDSCAPE or PageFormat.PORTRAIT
********************************************************************************************
*/
protected void printTable(String tableName, CcddFieldHandler fieldHandler, Component parent, int orientation) {
try {
GraphicsConfiguration gc;
// Create a printer job
PrinterJob printerJob = PrinterJob.getPrinterJob();
// The native print dialog does not allow simple positioning on the screen relative to
// another component. However, the ServiceUI.printDialog() method, which calls
// PrinterJob.printDialog(), does allow setting the dialog's x and y coordinates. The
// dimensions of the print dialog must be known in order to center it over its parent,
// but the size is unknown until the dialog is instantiated. Therefore, a dummy dialog
// is created using the same call within ServiceUI.printDialog() and the dialog's size
// is taken from it. The dialog's x, y coordinates can then be determined
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
DocFlavor flavor = null;
PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
PrintService defaultService = printerJob.getPrintService();
// Get the dialog/frame that contains the table
Component comp = table.getTopLevelAncestor();
// Create a dummy dialog in order to obtain the print dialog's dimensions
ServiceDialog dialog = new ServiceDialog(comp.getGraphicsConfiguration(), 0, 0, services, 0, flavor, attributes, (Dialog) null);
Rectangle newDlgSize = dialog.getBounds();
dialog.dispose();
// Get the array of graphics devices (this accounts for multiple screens)
GraphicsDevice[] gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
// Check if more than one screen exists
if (gd.length > 1) {
// Get the graphics configuration for the screen on which the component resides
gc = gd[0].getDefaultConfiguration();
} else // Only one screen is present
{
// Get the component's graphics configuration
gc = comp.getGraphicsConfiguration();
}
// Now that the dialog's size is known the print dialog's position can be calculated so
// as to center it over calling component, adjusting the location so that the dialog
// appears fully on the screen in which the component resides
Dimension compSize = comp.getSize();
Point adjLocation = CcddDialogHandler.adjustDialogLocationForScreen(new Rectangle(comp.getX() + ((compSize.width - newDlgSize.width) / 2), comp.getY() + ((compSize.height - newDlgSize.height) / 2), newDlgSize.width, newDlgSize.height));
// selected printer
if (ServiceUI.printDialog(gc, adjLocation.x, adjLocation.y, services, defaultService, flavor, attributes) != null) {
// Set the page format
PageFormat pageFormat = new PageFormat();
pageFormat.setOrientation(orientation);
// Create a book object for the table and data fields (if applicable)
Book book = new Book();
// Determine the number of pages to print the table. The printable object is
// altered during the page counting process, so it cannot be reused when creating
// the page wrapper below
int tblPages = getNumberOfPages(getPrintable(JTable.PrintMode.FIT_WIDTH, new MessageFormat(tableName), new MessageFormat("page {0}")), pageFormat);
// Add the table to the book object
book.append(new PageWrapper(getPrintable(JTable.PrintMode.FIT_WIDTH, new MessageFormat(tableName), new MessageFormat("page {0}")), 0), pageFormat, tblPages);
// Check if data fields are provided
if (fieldHandler != null && !fieldHandler.getFieldInformation().isEmpty()) {
String fields = "";
// Step through each data field
for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
// Append the field name and value to the output string
fields += " " + fieldInfo.getFieldName() + ": " + fieldInfo.getValue() + "\n";
}
// Place the field information into a text area
JTextArea fldTxtArea = new JTextArea(fields);
// Get the printable object for the text area
Printable fldPrintable = fldTxtArea.getPrintable(new MessageFormat("Data Fields for " + tableName), new MessageFormat("page {0}"));
// Add the fields to the book object
book.append(new PageWrapper(fldPrintable, tblPages), pageFormat, getNumberOfPages(fldPrintable, pageFormat));
}
// Output the book object to the selected printer or file
printerJob.setPageable(book);
printerJob.print();
}
} catch (PrinterException pe) {
// Inform the user that printing failed
new CcddDialogHandler().showMessageDialog(parent, "<html><b>Table '" + tableName + "' printing failed; cause '" + pe.getMessage() + "'", "Print Fail", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
}
}
use of java.awt.GraphicsConfiguration in project freeplane by freeplane.
the class UITools method getValidFrameBounds.
public static Rectangle getValidFrameBounds(final Component frame, int win_x, int win_y, int win_width, int win_height) {
GraphicsConfiguration graphicsConfiguration = findGraphicsConfiguration(frame, win_x, win_y);
final Rectangle screenBounds = getScreenBounds(graphicsConfiguration);
int screenWidth = screenBounds.width;
if (win_width != -1)
win_width = Math.min(win_width, screenWidth);
else
win_width = screenWidth * 4 / 5;
int screenHeight = screenBounds.height;
if (win_height != -1)
win_height = Math.min(win_height, screenHeight);
else
win_height = screenHeight * 4 / 5;
if (win_x != -1) {
win_x = Math.min(screenWidth + screenBounds.x - win_width, win_x);
win_x = Math.max(screenBounds.x, win_x);
} else
win_x = screenBounds.x + (screenWidth - win_width) / 2;
if (win_y != -1) {
win_y = Math.max(screenBounds.y, win_y);
win_y = Math.min(screenHeight + screenBounds.y - win_height, win_y);
} else
win_y = screenBounds.y + (screenHeight - win_height) / 2;
final Rectangle frameBounds = new Rectangle(win_x, win_y, win_width, win_height);
return frameBounds;
}
use of java.awt.GraphicsConfiguration in project pivot by apache.
the class DesktopApplicationContext method getVirtualDesktopBounds.
/**
* Calculate the entire virtual desktop bounding rectangle
*/
private static Rectangle getVirtualDesktopBounds() {
Rectangle virtualBounds = new Rectangle();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (GraphicsDevice gd : ge.getScreenDevices()) {
for (GraphicsConfiguration gc : gd.getConfigurations()) {
virtualBounds = virtualBounds.union(gc.getBounds());
}
}
return virtualBounds;
}
Aggregations