Container root = getRoot();
if (root == null) {
return null;
}
BufferStrategy bs = null;
if (TRY_FLIP) {
bs = createBufferStrategy(root,BufferCapabilities.FlipContents.
COPIED);
usingFlip = true;
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("createBufferStrategy: using flip strategy");
}
}
if (bs == null) {
bs = createBufferStrategy(root, null);
usingFlip = false;
}
if (!(bs instanceof SubRegionShowable)) {
// We do this for two reasons:
// 1. So that we know we can cast to SubRegionShowable and
// invoke show with the minimal region to update
// 2. To avoid the possibility of invoking client code
// on the toolkit thread.
bs = null;
}
return bs;
}
// Creates and returns a buffer strategy of the requested type. If
// there is a problem creating the buffer strategy this will
// eat the exception and return null.
private BufferStrategy createBufferStrategy(Container root,
BufferCapabilities.FlipContents type) {
BufferCapabilities caps = new BufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
type);
BufferStrategy bs = null;
if (root instanceof Applet) {
try {
getCreateBufferStrategyMethod().invoke(root, 2, caps);
bs = (BufferStrategy)getGetBufferStrategyMethod().
invoke(root);
} catch (InvocationTargetException ite) {
// Type is not supported
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "createBufferStratety failed",
ite);
}
} catch (IllegalArgumentException iae) {
assert false;
} catch (IllegalAccessException iae2) {
assert false;
}
}
else {
try {
((Window)root).createBufferStrategy(2, caps);
bs = ((Window)root).getBufferStrategy();
} catch (AWTException e) {
// Type not supported
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "createBufferStratety failed",
e);
}
}
}
return bs;
}
/**
* Cleans up and removes any references.
*/
public void dispose() {
Container root = getRoot();
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.log(Level.FINER, "disposed BufferInfo for: " + root);
}
if (root != null) {
root.removeComponentListener(this);
if (root instanceof Window) {
((Window)root).removeWindowListener(this);
}
BufferStrategy bs = getBufferStrategy(false);
if (bs != null) {
bs.dispose();
}
}
this.root = null;
weakBS = null;
}
// We mark the buffer as needing to be painted on a hide/iconify
// because the developer may have conditionalized painting based on
// visibility.
// Ideally we would also move to having the BufferStrategy being
// a SoftReference in Component here, but that requires changes to
// Component and the like.
public void componentHidden(ComponentEvent e) {
Container root = getRoot();
=9= |