项目:incubator-netbeans
文件:Utilities.java
/**
* Finds out the monitor where the user currently has the input focus.
* This method is usually used to help the client code to figure out on
* which monitor it should place newly created windows/frames/dialogs.
*
* @return the GraphicsConfiguration of the monitor which currently has the
* input focus
*/
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner != null) {
Window w = SwingUtilities.getwindowAncestor(focusOwner);
if (w != null) {
return w.getGraphicsConfiguration();
} else {
//#217737 - try to find the main window which Could be placed in secondary screen
for( Frame f : Frame.getFrames() ) {
if( "NbMainWindow".equals(f.getName())) { //NOI18N
return f.getGraphicsConfiguration();
}
}
}
}
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
private void drawbackingStoreImage(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
GraphicsConfiguration gc = g2d.getDeviceConfiguration();
if (vImg == null ||
vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
/* Create a new volatile image */
vImg = createVolatileImage(PANEL_WIDTH,PANEL_HEIGHT / 3);
}
Graphics vImgGraphics = vImg.createGraphics();
vImgGraphics.setColor(Color.WHITE);
vImgGraphics.fillRect(0,PANEL_WIDTH,PANEL_HEIGHT / 3);
drawInfo(vImgGraphics,PANEL_X,PANEL_Y,"Backbuffer",Color.magenta);
g.drawImage(vImg,PANEL_Y * 2,this);
}
项目:openjdk-jdk10
文件:PopupMenuLocation.java
public static void main(final String[] args) throws Exception {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] sds = ge.getScreenDevices();
for (GraphicsDevice sd : sds) {
GraphicsConfiguration gc = sd.getDefaultConfiguration();
Rectangle bounds = gc.getBounds();
Point point = new Point(bounds.x,bounds.y);
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
while (point.y < bounds.y + bounds.height - insets.bottom - SIZE) {
while (point.x
< bounds.x + bounds.width - insets.right - SIZE) {
test(point);
point.translate(bounds.width / 5,0);
}
point.setLocation(bounds.x,point.y + bounds.height / 5);
}
}
}
项目:jdk8u-jdk
文件:bug8071705.java
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {
GraphicsDevice correctDevice = null;
if (devices.length < 2) {
return correctDevice;
}
Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
int halfScreen = screenBounds.height/2;
for(int i = 0; i < devices.length; i++) {
if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
GraphicsConfiguration conf =
devices[i].getDefaultConfiguration();
Rectangle bounds = conf.getBounds();
if (bounds.y >= halfScreen) {
// found
correctDevice = devices[i];
break;
}
}
}
return correctDevice;
}
项目:jdk8u-jdk
文件:IncorrectAlphaConversionBicubic.java
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,int type) {
BufferedImage img = gc.createCompatibleImage(SIZE,SIZE,type);
Graphics2D g2d = img.createGraphics();
g2d.setColor(RGB);
g2d.fillRect(0,SIZE);
g2d.dispose();
final DataBuffer db = img.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
img.setaccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return img;
}
项目:incubator-netbeans
文件:BufferedCanvasComponent.java
private int updateOffscreenImage() {
// Update offscreen image reference
if (offscreenImage == null) offscreenImage = offscreenImageReference.get();
// Offscreen image not available
if (offscreenImage == null) return VolatileImage.IMAGE_INCOMPATIBLE;
// Buffered image is always valid
if (bufferType != BUFFER_VOLATILE_IMAGE) return VolatileImage.IMAGE_OK;
// Determine GraphicsConfiguration context
GraphicsConfiguration gConfiguration = getGraphicsConfiguration();
if (gConfiguration == null) return VolatileImage.IMAGE_INCOMPATIBLE;
// Return Volatile image state
return ((VolatileImage)offscreenImage).validate(gConfiguration);
}
项目:openjdk-jdk10
文件:VolatileSurfaceManager.java
/**
* Creates a software-based surface (of type BufImgSurfaceData).
* The software representation is only created when needed,which
* is only during some situation in which the hardware surface
* cannot be allocated. This allows apps to at least run,* albeit more slowly than they would otherwise.
*/
protected SurfaceData getBackupSurface() {
if (sdBackup == null) {
GraphicsConfiguration gc = vImg.getGraphicsConfig();
AffineTransform tx = gc.getDefaultTransform();
double scaleX = tx.getScaleX();
double scaleY = tx.getScaleY();
BufferedImage bImg = vImg.getBackupImage(scaleX,scaleY);
// Sabotage the acceleration capabilities of the BufImg surface
SunWritableRaster.stealTrackable(bImg
.getRaster()
.getDataBuffer()).setUntrackable();
sdBackup = BufImgSurfaceData.createData(bImg,scaleX,scaleY);
}
return sdBackup;
}
项目:jdk8u-jdk
文件:TransformSetGet.java
public static void main(final String[] args) {
final GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsConfiguration gc =
ge.getDefaultScreenDevice().getDefaultConfiguration();
final VolatileImage vi = gc.createCompatibleVolatileImage(200,200);
final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
sg2d.constrain(0,61,100,100);
final AffineTransform expected = sg2d.cloneTransform();
sg2d.setTransform(sg2d.getTransform());
final AffineTransform actual = sg2d.cloneTransform();
sg2d.dispose();
vi.flush();
if (!expected.equals(actual)) {
System.out.println("Expected = " + expected);
System.out.println("Actual = " + actual);
throw new RuntimeException("Wrong transform");
}
}
/**
* Creates an instance of the painter for particular peer.
*/
public static TranslucentwindowPainter createInstance(WWindowPeer peer) {
GraphicsConfiguration gc = peer.getGraphicsConfiguration();
if (!forceSW && gc instanceof AccelGraphicsConfig) {
String gcName = gc.getClass().getSimpleName();
AccelGraphicsConfig agc = (AccelGraphicsConfig)gc;
// this is a heuristic to check that we have a pcix board
// (those have higher transfer rate from gpu to cpu)
if ((agc.getContextCapabilities().getCaps() & CAPS_ps30) != 0 ||
forceOpt)
{
// we check for name to avoid loading classes unnecessarily if
// a pipeline isn't enabled
if (gcName.startsWith("D3D")) {
return new VIOptD3DWindowPainter(peer);
} else if (forceOpt && gcName.startsWith("WGL")) {
// on some boards (namely,ATI,even on pcix bus) ogl is
// very slow reading pixels back so for Now it is disabled
// unless forced
return new VIOptWGLWindowPainter(peer);
}
}
}
return new BIWindowPainter(peer);
}
private Point getUserLocation(GraphicsConfiguration gconf,OptionsPanel optionsPanel) {
final Rectangle screenBounds = Utilities.getUsableScreenBounds(gconf);
int x = NbPreferences.forModule(OptionsdisplayerImpl.class).getInt("OptionsX",Integer.MAX_VALUE);//NOI18N
int y = NbPreferences.forModule(OptionsdisplayerImpl.class).getInt("OptionsY",Integer.MAX_VALUE);//NOI18N
Dimension userSize = optionsPanel.getUserSize();
if (x > screenBounds.x + screenBounds.getWidth() || y > screenBounds.y + screenBounds.getHeight()
|| x + userSize.width > screenBounds.x + screenBounds.getWidth()
|| y + userSize.height > screenBounds.y + screenBounds.getHeight()
|| (x < screenBounds.x && screenBounds.x >= 0)
|| (x > screenBounds.x && screenBounds.x < 0)
|| (y < screenBounds.y && screenBounds.y >= 0)
|| (y > screenBounds.y && screenBounds.y < 0)){
return null;
} else {
return new Point(x,y);
}
}
public void show(Point location) {
Rectangle screenBounds = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
for (GraphicsDevice device : gds) {
GraphicsConfiguration gc = device.getDefaultConfiguration();
screenBounds = gc.getBounds();
if (screenBounds.contains(location)) {
break;
}
}
// showing the popup tooltip
cp = new TooltipContentPanel(master.getTextComponent());
Window w = SwingUtilities.windowForComponent(master.getTextComponent());
contentwindow = new JWindow(w);
contentwindow.add(cp);
contentwindow.pack();
Dimension dim = contentwindow.getSize();
if (location.y + dim.height + SCREEN_BORDER > screenBounds.y + screenBounds.height) {
dim.height = (screenBounds.y + screenBounds.height) - (location.y + SCREEN_BORDER);
}
if (location.x + dim.width + SCREEN_BORDER > screenBounds.x + screenBounds.width) {
dim.width = (screenBounds.x + screenBounds.width) - (location.x + SCREEN_BORDER);
}
contentwindow.setSize(dim);
contentwindow.setLocation(location.x,location.y - 1); // slight visual adjustment
contentwindow.setVisible(true);
Toolkit.getDefaultToolkit().addAWTEventListener(this,AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK);
w.addWindowFocusListener(this);
contentwindow.addWindowFocusListener(this);
}
项目:openjdk-jdk10
文件:bug8071705.java
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {
GraphicsDevice correctDevice = null;
if (devices.length < 2) {
return correctDevice;
}
Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
int halfScreen = screenBounds.height/2;
for(int i = 0; i < devices.length; i++) {
if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
GraphicsConfiguration conf =
devices[i].getDefaultConfiguration();
Rectangle bounds = conf.getBounds();
if (bounds.y >= halfScreen) {
// found
correctDevice = devices[i];
break;
}
}
}
return correctDevice;
}
项目:rapidminer
文件:FancyDropDownButton.java
@Override
public void actionPerformed(ActionEvent ae) {
jpopupmenu popup = getPopupMenu();
popup.addPopupMenuListener(popupMenuListener);
int popupPrefheight = (int) popup.getPreferredSize().getHeight();
int buttonY = mainButton.getLocationOnScreen().y;
boolean showOnTop = false;
GraphicsConfiguration graphicsConf = ApplicationFrame.getApplicationFrame().getGraphicsConfiguration();
if (graphicsConf != null) {
int windowHeight = (int) graphicsConf.getBounds().getHeight();
showOnTop = buttonY + mainButton.getHeight() + popupPrefheight > windowHeight;
}
if (showOnTop) {
popup.show(mainButton,-popupPrefheight);
} else {
popup.show(mainButton,mainButton.getHeight());
}
}
项目:BrainControl
文件:LevelScene.java
/**
* Constructor
*
* @param graphicsConfiguration
* @param renderer
* @param seed
* @param levelDifficulty
* @param type
* @param levelLength
* @param timeLimit
*/
public LevelScene(GraphicsConfiguration graphicsConfiguration,GameWorld renderer,long seed,int levelDifficulty,int type,int levelLength,int timeLimit,String ownLevelName)
{
this.graphicsConfiguration = graphicsConfiguration;
this.renderer = renderer;
this.levelSeed = seed;
this.levelDifficulty = levelDifficulty;
this.levelType = type;
this.levelLength = levelLength;
this.totalTime = timeLimit;
// Todo should these be initialized in an object constructor?
killedCreaturesTotal = 0;
killedCreaturesByFireBall = 0;
killedCreaturesByStomp = 0;
killedCreaturesByGrumpy = 0;
playersAtEnd = 0;
this.ownLevelName = ownLevelName;
}
项目:jdk8u-jdk
文件:SourceClippingBlitTest.java
static void initimage(GraphicsConfiguration gc,Image image) {
Graphics g = image.getGraphics();
g.setColor(Color.RED);
int w = image.getWidth(null);
int h = image.getHeight(null);
g.fillRect(0,w,h);
g.dispose();
// need to 'accelerate' the image
if (dstimage == null) {
dstimage =
gc.createCompatibleVolatileImage(TESTW,TESTH,Transparency.OPAQUE);
}
dstimage.validate(gc);
g = dstimage.getGraphics();
g.drawImage(image,null);
g.drawImage(image,null);
}
/**
* Creates an instance of the painter for particular peer.
*/
public static TranslucentwindowPainter createInstance(WWindowPeer peer) {
GraphicsConfiguration gc = peer.getGraphicsConfiguration();
if (!forceSW && gc instanceof AccelGraphicsConfig) {
String gcName = gc.getClass().getSimpleName();
AccelGraphicsConfig agc = (AccelGraphicsConfig)gc;
// this is a heuristic to check that we have a pcix board
// (those have higher transfer rate from gpu to cpu)
if ((agc.getContextCapabilities().getCaps() & CAPS_ps30) != 0 ||
forceOpt)
{
// we check for name to avoid loading classes unnecessarily if
// a pipeline isn't enabled
if (gcName.startsWith("D3D")) {
return new VIOptD3DWindowPainter(peer);
} else if (forceOpt && gcName.startsWith("WGL")) {
// on some boards (namely,even on pcix bus) ogl is
// very slow reading pixels back so for Now it is disabled
// unless forced
return new VIOptWGLWindowPainter(peer);
}
}
}
return new BIWindowPainter(peer);
}
private void initimages(int w,int h) {
if (images == null) {
images = new Image[6];
GraphicsConfiguration gc = getGraphicsConfiguration();
for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
VolatileImage vi =
gc.createCompatibleVolatileImage(w,h/images.length,i);
images[i-1] = vi;
vi.validate(gc);
String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination";
render(vi,i,s);
s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination";
images[i-1+3] = gc.createCompatibleImage(w,i);
render(images[i-1+3],s);
}
}
}
项目:jdk8u-jdk
文件:ImageCache.java
public boolean equals(GraphicsConfiguration config,int w,int h,Object[] args) {
if (this.w == w && this.h == h &&
((this.config != null && this.config.equals(config)) ||
(this.config == null && config == null))) {
if (this.args == null && args == null) {
return true;
}
if (this.args != null && args != null &&
this.args.length == args.length) {
for (int counter = args.length - 1; counter >= 0;
counter--) {
Object a1 = this.args[counter];
Object a2 = args[counter];
if ((a1 == null && a2 != null) ||
(a1 != null && !a1.equals(a2))) {
return false;
}
}
return true;
}
}
return false;
}
项目:openjdk-jdk10
文件:TransformedPaintTest.java
private void runtest() {
GraphicsConfiguration gc = GraphicsEnvironment.
getLocalGraphicsEnvironment().getDefaultScreenDevice().
getDefaultConfiguration();
if (gc.getColorModel().getPixelSize() < 16) {
System.out.println("8-bit desktop depth found,test passed");
return;
}
VolatileImage vi = gc.createCompatibleVolatileImage(R_WIDTH,R_HEIGHT);
BufferedImage bi = null;
do {
vi.validate(gc);
Graphics2D g = vi.createGraphics();
render(g,vi.getWidth(),vi.getHeight());
bi = vi.getSnapshot();
} while (vi.contentsLost());
checkBI(bi);
System.out.println("Test PASSED.");
}
public boolean isAccelerated() {
// Note that when img.getaccelerationPriority() gets set to 0
// we remove SurfaceDataProxy objects from the cache and the
// answer will be false.
GraphicsConfiguration tmpGc = gc;
if (tmpGc == null) {
tmpGc = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
if (tmpGc instanceof ProxiedGraphicsConfig) {
Object proxyKey =
((ProxiedGraphicsConfig) tmpGc).getProxyKey();
if (proxyKey != null) {
SurfaceDataProxy sdp =
(SurfaceDataProxy) getCacheData(proxyKey);
return (sdp != null && sdp.isAccelerated());
}
}
return false;
}
项目:openjdk-jdk10
文件:RSLAPITest.java
public static void main(String[] args) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
testGC(gc);
if (Failed) {
throw new RuntimeException("Test Failed. See err output for more");
}
System.out.println("Test PASSED.");
}
项目:litiengine
文件:ImageProcessing.java
public static BufferedImage getCompatibleImage(final int width,final int height) {
if (width == 0 && height == 0) {
return null;
}
final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = env.getDefaultScreenDevice();
final GraphicsConfiguration config = device.getDefaultConfiguration();
return config.createCompatibleImage(width,height,Transparency.TRANSLUCENT);
}
项目:jdk8u-jdk
文件:DrawCachedImageAndTransform.java
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(100,100);
Graphics2D g2d = vi.createGraphics();
g2d.scale(2,2);
BufferedImage img = new BufferedImage(50,50,BufferedImage.TYPE_INT_ARGB);
g2d.drawImage(img,10,25,Color.blue,null);
g2d.dispose();
}
项目:incubator-netbeans
文件:Utilities.java
/**
* Returns the usable area of the screen where applications can place its
* windows. The method subtracts from the screen the area of taskbars,* system menus and the like.
* On certain platforms this methods uses a cache to avoid performance degradation due to repeated calls.
* This can be disabled by setting the property "-Dnetbeans.screen.insetsCache=false"
* See issue http://netbeans.org/bugzilla/show_bug.cgi?id=219507
*
* @param gconf the GraphicsConfiguration of the monitor
* @return the rectangle of the screen where one can place windows
*
* @since 2.5
*/
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
if( gconf == null ) {
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
if( screenBoundsCache == null ) {
return calculateUsableScreenBounds( gconf );
}
synchronized( screenBoundsCache ) {
Map<Rectangle,Long> cacheEntry = screenBoundsCache.get( gconf );
if( cacheEntry != null ) {
final long Now = System.currentTimeMillis();
Entry<Rectangle,Long> entry = cacheEntry.entrySet().iterator().next();
if( entry.getValue() < Now + 10000 ) { // cache hit,10 seconds lifetime
return new Rectangle( entry.getKey() ); // return copy
}
}
final Rectangle screenBounds = calculateUsableScreenBounds( gconf );
cacheEntry = new HashMap<Rectangle,Long>( 1 );
cacheEntry.put( screenBounds,System.currentTimeMillis() );
if( screenBoundsCache.size() > 20 ) { //maximum entries
screenBoundsCache.clear();
}
screenBoundsCache.put( gconf,cacheEntry );
return new Rectangle( screenBounds );
}
}
项目:incubator-netbeans
文件:Utilities.java
/**
* Helps client code place components on the center of the screen. It
* handles multiple monitor configuration correctly
*
* @param gconf the GraphicsConfiguration of the monitor
* @param componentSize the size of the component
* @return bounds of the centered component
*/
private static Rectangle findCenterBounds(GraphicsConfiguration gconf,Dimension componentSize) {
if (gconf == null) {
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
Rectangle bounds = gconf.getBounds();
return new Rectangle(
bounds.x + ((bounds.width - componentSize.width) / 2),bounds.y + ((bounds.height - componentSize.height) / 2),componentSize.width,componentSize.height
);
}
项目:openjdk-jdk10
文件:normalizingTransformTest.java
public static void main(String[] args) {
GraphicsConfiguration gc =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
AffineTransform normTransform = gc.getnormalizingTransform();
int dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
int normDpiX = (int)(normTransform.getScaleX() * 72.0);
if (dpiX != normDpiX) {
throw new RuntimeException(
"Test Failed. Toolkit.getScreenResolution()=" + dpiX +
" GraphicsConfiguration.getnormalizingTransform()="+normDpiX);
}
System.out.println("Test PASSED. DPI="+normDpiX);
}
项目:jdk8u-jdk
文件:Permissions.java
public static void main(String[] args) {
MySecurityManager sm = MySecurityManager.install();
Toolkit toolkit = Toolkit.getDefaultToolkit();
sm.prepare("Toolkit.getSystemClipboard()");
toolkit.getSystemClipboard();
sm.assertChecked(AWTPermission.class,"accessClipboard");
sm.prepare("Toolkit.getSystemEventQueue()");
toolkit.getSystemEventQueue();
sm.assertChecked(AWTPermission.class,"accessEventQueue");
sm.prepare("Toolkit.getSystemSelection()");
toolkit.getSystemSelection();
//sm.assertChecked(AWTPermission.class,"accessClipboard");
sm.prepare("Window(Frame)");
new Window((Frame)null);
sm.assertChecked(AWTPermission.class,"showWindowWithoutWarningBanner");
sm.prepare("Window(Window)");
new Window((Window)null);
sm.assertChecked(AWTPermission.class,"showWindowWithoutWarningBanner");
sm.prepare("Window(Window,GraphicsConfiguration)");
new Window((Window)null,(GraphicsConfiguration)null);
sm.assertChecked(AWTPermission.class,"showWindowWithoutWarningBanner");
}
项目:incubator-netbeans
文件:ColumnSelectionPanel.java
public static void main(String[] args) {
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(16,16);
vi.validate(gc);
BufferedImage bi =
new BufferedImage(2,2,BufferedImage.TYPE_INT_RGB);
int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
data[0] = 0x0000007f;
data[1] = 0x0000007f;
data[2] = 0xff00007f;
data[3] = 0xff00007f;
Graphics2D g = vi.createGraphics();
g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
g.drawImage(bi,null);
bi = vi.getSnapshot();
if (bi.getRGB(0,0) != bi.getRGB(1,1)) {
throw new RuntimeException("Test Failed: color at 0x0 ="+
Integer.toHexString(bi.getRGB(0,0))+" differs from 1x1 ="+
Integer.toHexString(bi.getRGB(1,1)));
}
System.out.println("Test PASSED.");
}
项目:jdk8u-jdk
文件:ImageCache.java
项目:openjdk-jdk10
文件:IncorrectUnmanagedImageRotatedClip.java
private static void test(final BufferedImage bi) throws IOException {
GraphicsEnvironment ge = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice()
.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(500,200,TRANSLUCENT);
BufferedImage gold = gc.createCompatibleImage(500,TRANSLUCENT);
// draw to compatible Image
draw(bi,gold);
// draw to volatile image
int attempt = 0;
BufferedImage snapshot;
while (true) {
if (++attempt > 10) {
throw new RuntimeException("Too many attempts: " + attempt);
}
vi.validate(gc);
if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
continue;
}
draw(bi,vi);
snapshot = vi.getSnapshot();
if (vi.contentsLost()) {
continue;
}
break;
}
// validate images
for (int x = 0; x < gold.getWidth(); ++x) {
for (int y = 0; y < gold.getHeight(); ++y) {
if (gold.getRGB(x,y) != snapshot.getRGB(x,y)) {
ImageIO.write(gold,"png",new File("gold.png"));
ImageIO.write(snapshot,new File("bi.png"));
throw new RuntimeException("Test Failed.");
}
}
}
}
项目:incubator-netbeans
文件:DnDSupport.java
private BufferedImage createContentimage( JComponent c,Dimension contentSize ) {
GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
boolean opaque = c.isOpaque();
c.setopaque(true);
BufferedImage res = cfg.createCompatibleImage(contentSize.width,contentSize.height);
Graphics2D g = res.createGraphics();
g.setColor( c.getBackground() );
g.fillRect(0,contentSize.width,contentSize.height);
g.setComposite( AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.5f ));
c.paint(g);
c.setopaque(opaque);
return res;
}
项目:openjdk-jdk10
文件:InfiniteValidationLoopTest.java
private void runTest(Graphics g) {
int status = IMAGE_OK;
int count1 = 0;
do {
GraphicsConfiguration gc = getGraphicsConfiguration();
int count2 = 0;
while (vi == null || (status = vi.validate(gc)) != IMAGE_OK) {
if (++count2 > LOOP_THRESHOLD) {
System.err.println("Infinite loop detected: count2="+count2);
Failed = true;
return;
}
if (vi == null || status == IMAGE_INCOMPATIBLE) {
if (vi != null) { vi.flush(); vi = null; }
vi = gc.createCompatibleVolatileImage(100,100);
continue;
}
if (status == IMAGE_RESTORED) {
Graphics gg = vi.getGraphics();
gg.setColor(Color.green);
gg.fillRect(0,vi.getHeight());
break;
}
}
g.drawImage(vi,getInsets().left,getInsets().top,null);
if (++count1 > LOOP_THRESHOLD) {
System.err.println("Infinite loop detected: count1="+count1);
Failed = true;
return;
}
} while (vi.contentsLost());
}
/**
* Get the cached image for given keys
*
* @param config The graphics configuration,needed if cached image is a Volatile Image. Used as part of cache key
* @param w The image width,used as part of cache key
* @param h The image height,used as part of cache key
* @param args Other arguments to use as part of the cache key
* @return Returns the cached Image,or null there is no cached image for key
*/
public Image getimage(GraphicsConfiguration config,Object... args) {
lock.readLock().lock();
try {
PixelCountSoftReference ref = map.get(hash(config,h,args));
// check reference has not been lost and the key truly matches,in case of false positive hash match
if (ref != null && ref.equals(config,args)) {
return ref.get();
} else {
return null;
}
} finally {
lock.readLock().unlock();
}
}
项目:openjdk-jdk10
文件:ServiceDialog.java
/**
* Constructor for the "standard" print dialog (containing all relevant
* tabs)
*/
public ServiceDialog(GraphicsConfiguration gc,int x,int y,PrintService[] services,int defaultServiceIndex,DocFlavor flavor,PrintRequestAttributeSet attributes,Dialog dialog)
{
super(dialog,getMsg("dialog.printtitle"),true,gc);
initPrintDialog(x,y,services,defaultServiceIndex,flavor,attributes);
}
项目:rapidminer
文件:ToolbarHandlerBuffer.java
/**
* Creates a new instance of a VolatileSurfaceManager given any
* arbitrary SunVolatileImage. An optional context Object can be supplied
* as a way for the caller to pass pipeline-specific context data to
* the VolatileSurfaceManager (such as a backbuffer handle,for example).
*
* For Windows platforms,this method returns a Windows-specific
* VolatileSurfaceManager.
*/
public VolatileSurfaceManager createVolatileManager(SunVolatileImage vImg,Object context)
{
GraphicsConfiguration gc = vImg.getGraphicsConfig();
if (gc instanceof D3DGraphicsConfig) {
return new D3DVolatileSurfaceManager(vImg,context);
} else if (gc instanceof WGLGraphicsConfig) {
return new WGLVolatileSurfaceManager(vImg,context);
} else {
return new BufImgVolatileSurfaceManager(vImg,context);
}
}
项目:openjdk-jdk10
文件:ImageCache.java
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。