本文整理匯總了Java中javax.swing.RepaintManager.currentManager方法的典型用法代碼示例。如果您正苦於以下問題:Java RepaintManager.currentManager方法的具體用法?Java RepaintManager.currentManager怎麽用?Java RepaintManager.currentManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.RepaintManager
的用法示例。
在下文中一共展示了RepaintManager.currentManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: print
import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
if (pageIndex >= getComponentCount()) {
mLastPage = -1;
return NO_SUCH_PAGE;
}
// We do the following trick to avoid going through the work twice,
// as we are called twice for each page, the first of which doesn't
// seem to be used.
if (mLastPage != pageIndex) {
mLastPage = pageIndex;
} else {
Component comp = getComponent(pageIndex);
RepaintManager mgr = RepaintManager.currentManager(comp);
boolean saved = mgr.isDoubleBufferingEnabled();
mgr.setDoubleBufferingEnabled(false);
mOkToPaint = true;
comp.print(graphics);
mOkToPaint = false;
mgr.setDoubleBufferingEnabled(saved);
}
return PAGE_EXISTS;
}
示例2: paint
import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
* Renders the wrapped component to the graphics context provided.
*
* @param g2 graphics context for rendering the JComponent
*/
public void paint(final Graphics2D g2) {
if (component.getBounds().isEmpty()) {
// The component has not been initialized yet.
return;
}
final PSwingRepaintManager manager = (PSwingRepaintManager) RepaintManager.currentManager(component);
manager.lockRepaint(component);
final RenderingHints oldHints = g2.getRenderingHints();
//Disable Fractional Metrics on Mac OS because when FRACTIONAL_METRICS are enabled on Mac OS, spurious ellipses
// are rendered on PSwing text components. Disabling the FRACTIONAL_METRICS rendering hint on Windows causes
// incorrect rendering of adjacent text PSwing nodes.
if (System.getProperty("os.name").startsWith( "Mac OS X" )) {
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
}
component.paint(g2);
g2.setRenderingHints(oldHints);
manager.unlockRepaint(component);
}
示例3: testUnlockRepaint
import javax.swing.RepaintManager; //導入方法依賴的package包/類
public void testUnlockRepaint() {
final PSwingCanvas canvas = new PSwingCanvas();
final RepaintManager currentManager = RepaintManager.currentManager(canvas);
assertNotNull(currentManager);
assertTrue(currentManager instanceof PSwingRepaintManager);
final PSwingRepaintManager repaintManager = (PSwingRepaintManager) currentManager;
repaintManager.lockRepaint(null);
repaintManager.lockRepaint(canvas);
repaintManager.unlockRepaint(null);
repaintManager.unlockRepaint(canvas);
// TODO: catch this array index out of bounds exception?
final JComponent notLocked = new JPanel();
try {
repaintManager.unlockRepaint(notLocked);
}
catch (final ArrayIndexOutOfBoundsException e) {
// expected
}
}
示例4: testAddInvalidComponent
import javax.swing.RepaintManager; //導入方法依賴的package包/類
public void testAddInvalidComponent() {
final PSwingCanvas canvas = new PSwingCanvas();
final RepaintManager currentManager = RepaintManager.currentManager(canvas);
assertNotNull(currentManager);
assertTrue(currentManager instanceof PSwingRepaintManager);
final PSwingRepaintManager repaintManager = (PSwingRepaintManager) currentManager;
// TODO: should check for null and throw IAE, or keep NPE?
try {
repaintManager.addInvalidComponent(null);
}
catch (final NullPointerException e) {
// expected
}
final JComponent component = new JPanel();
final JComponent child = new JPanel();
canvas.add(child);
repaintManager.addInvalidComponent(canvas);
repaintManager.addInvalidComponent(component);
repaintManager.addInvalidComponent(child);
// TODO: will need some additional work here for full test coverage
}
示例5: print
import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
if (pageIndex > 0) {
return NO_SUCH_PAGE;
}
else {
Graphics2D g2d = (Graphics2D) g;
RepaintManager currentManager = RepaintManager.currentManager(this);
currentManager.setDoubleBufferingEnabled(false);
Rectangle bounds = getContentBounds(Config.getInstance().getPrintPadding(), getGridElements());
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
AffineTransform t = g2d.getTransform();
double scale = Math.min(pageFormat.getImageableWidth() / bounds.width,
pageFormat.getImageableHeight() / bounds.height);
if (scale < 1) {
t.scale(scale, scale);
g2d.setTransform(t);
}
g2d.translate(-bounds.x, -bounds.y);
paint(g2d);
currentManager = RepaintManager.currentManager(this);
currentManager.setDoubleBufferingEnabled(true);
return PAGE_EXISTS;
}
}
示例6: paintImmediately
import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
* Immediately repaints the surface.
*
* <p/>It's possible to turn off double-buffering for just the repaint calls invoked directly on the non double
* buffered component. This can be done by overriding paintImmediately() (which is called as a result of repaint)
* and getting the current RepaintManager and turning off double buffering in the RepaintManager before calling
* super.paintImmediately(g).
*
* @param x The X coord to start painting at.
* @param y The Y coord to start painting at.
* @param w The width of the region to paint.
* @param h The height of the region to paint.
*/
public void paintImmediately(int x, int y, int w, int h)
{
RepaintManager repaintManager = null;
boolean save = true;
if (!isDoubleBuffered())
{
repaintManager = RepaintManager.currentManager(this);
save = repaintManager.isDoubleBufferingEnabled();
repaintManager.setDoubleBufferingEnabled(false);
}
super.paintImmediately(x, y, w, h);
if (repaintManager != null)
{
repaintManager.setDoubleBufferingEnabled(save);
}
}
示例7: paintWidget
import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
* Paints the component widget.
*/
@Override
protected final void paintWidget() {
RepaintManager rm = RepaintManager.currentManager(null);
boolean isDoubleBuffered = component instanceof JComponent && rm.isDoubleBufferingEnabled();
if (isDoubleBuffered) {
rm.setDoubleBufferingEnabled(false);
}
Graphics2D graphics = getGraphics();
Rectangle bounds = getClientArea();
AffineTransform previousTransform = graphics.getTransform();
graphics.translate(bounds.x, bounds.y);
//double zoomFactor = getScene().getZoomFactor();
//graphics.scale(1 / zoomFactor, 1 / zoomFactor);
if (componentVisible) {
componentWrapper.doPaint(graphics);
} else {
component.paint(graphics);
}
graphics.setTransform(previousTransform);
if (isDoubleBuffered) {
rm.setDoubleBufferingEnabled(true);
}
}
示例8: actionPerformed
import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
* Initial point of the next frame (invoked by the animation timer).
*
* @param e action event.
*/
@Override
public void actionPerformed(ActionEvent e) {
updatePhase();
RepaintManager manager = RepaintManager.currentManager(glassPane);
manager.markCompletelyDirty(glassPane);
manager.paintDirtyRegions();
}
示例9: print
import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public int print(java.awt.Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
// We have only one page, and 'page' is zero-based
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) g;
// User (0,0) is typically outside the imageable area, so we must
// translate by the X and Y values in the PageFormat to avoid clipping
g2d.translate(pf.getImageableX(), pf.getImageableY());
// Scale plots to paper size.
double scaleX = pf.getImageableWidth() / contentPane.getWidth();
double scaleY = pf.getImageableHeight() / contentPane.getHeight();
g2d.scale(scaleX, scaleY);
// Disable double buffering
RepaintManager currentManager = RepaintManager.currentManager(this);
currentManager.setDoubleBufferingEnabled(false);
// Now we perform our rendering
contentPane.printAll(g);
// Enable double buffering
currentManager.setDoubleBufferingEnabled(true);
// tell the caller that this page is part of the printed document
return PAGE_EXISTS;
}
示例10: addDirtyRegion
import javax.swing.RepaintManager; //導入方法依賴的package包/類
@Override
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) {
if (RepaintManager.currentManager(c) == this) {
testFuture.defaultCalled();
} else {
testFuture.delegateCalled();
}
super.addDirtyRegion(c, x, y, w, h);
}
示例11: testCurrentManager
import javax.swing.RepaintManager; //導入方法依賴的package包/類
public void testCurrentManager() {
RepaintManager currentManager = RepaintManager.currentManager(null);
assertNotNull(currentManager);
// TODO: this assertion is true when running this test case in isolation
// but since PSwingCanvas may have been instantiated elsewhere in the
// test suite
// may not be true when running this test case as part of a test suite
// assertFalse(currentManager instanceof PSwingRepaintManager);
final Component awtComponent = new Canvas();
currentManager = RepaintManager.currentManager(awtComponent);
assertNotNull(currentManager);
// assertFalse(currentManager instanceof PSwingRepaintManager);
final JComponent swingComponent = new JPanel();
currentManager = RepaintManager.currentManager(swingComponent);
assertNotNull(currentManager);
// assertFalse(currentManager instanceof PSwingRepaintManager);
final PSwingCanvas pswingCanvas = new PSwingCanvas();
currentManager = RepaintManager.currentManager(pswingCanvas);
assertNotNull(currentManager);
assertTrue(currentManager instanceof PSwingRepaintManager);
// once a PSwingCanvas has been instantiated,
// PSwingRepaintManager replaces RepaintManager everwhere
currentManager = RepaintManager.currentManager(awtComponent);
assertTrue(currentManager instanceof PSwingRepaintManager);
currentManager = RepaintManager.currentManager(swingComponent);
assertTrue(currentManager instanceof PSwingRepaintManager);
currentManager = RepaintManager.currentManager(pswingCanvas);
assertTrue(currentManager instanceof PSwingRepaintManager);
}
示例12: testLockRepaint
import javax.swing.RepaintManager; //導入方法依賴的package包/類
public void testLockRepaint() {
final PSwingCanvas canvas = new PSwingCanvas();
final RepaintManager currentManager = RepaintManager.currentManager(canvas);
assertNotNull(currentManager);
assertTrue(currentManager instanceof PSwingRepaintManager);
final PSwingRepaintManager repaintManager = (PSwingRepaintManager) currentManager;
// TODO: should lockRepaint allow null?
repaintManager.lockRepaint(null);
repaintManager.lockRepaint(canvas);
}
示例13: testIsPainting
import javax.swing.RepaintManager; //導入方法依賴的package包/類
public void testIsPainting() {
final PSwingCanvas canvas = new PSwingCanvas();
final RepaintManager currentManager = RepaintManager.currentManager(canvas);
assertNotNull(currentManager);
assertTrue(currentManager instanceof PSwingRepaintManager);
final PSwingRepaintManager repaintManager = (PSwingRepaintManager) currentManager;
repaintManager.lockRepaint(null);
repaintManager.lockRepaint(canvas);
final JComponent notLocked = new JPanel();
assertTrue(repaintManager.isPainting(null));
assertTrue(repaintManager.isPainting(canvas));
assertFalse(repaintManager.isPainting(notLocked));
}
示例14: testAddDirtyRegion
import javax.swing.RepaintManager; //導入方法依賴的package包/類
public void testAddDirtyRegion() {
final PSwingCanvas canvas = new PSwingCanvas();
final RepaintManager currentManager = RepaintManager.currentManager(canvas);
assertNotNull(currentManager);
assertTrue(currentManager instanceof PSwingRepaintManager);
final PSwingRepaintManager repaintManager = (PSwingRepaintManager) currentManager;
repaintManager.addDirtyRegion(canvas, 0, 0, canvas.getWidth(), canvas.getHeight());
final JComponent child = new JPanel();
canvas.add(child);
repaintManager.addDirtyRegion(child, 0, 0, child.getWidth(), child.getHeight());
// TODO: will need some additional work here for full test coverage
}
示例15: setAlpha
import javax.swing.RepaintManager; //導入方法依賴的package包/類
/**
* Set the alpha transparency level for this component. This automatically
* causes a repaint of the component.
*
* @param alpha must be a value between 0 and 1 inclusive.
*/
public void setAlpha(float alpha) {
if (alpha < 0 || alpha > 1) {
throw new IllegalArgumentException("Alpha must be between 0 and 1 inclusive");
}
if (this.alpha != alpha) {
float oldAlpha = this.alpha;
this.alpha = alpha;
if (alpha > 0f && alpha < 1f) {
if (oldAlpha == 1) {
//it used to be 1, but now is not. Save the oldOpaque
oldOpaque = isOpaque();
setOpaque(false);
}
//TODO this was quite the controversial choice, in automatically
//replacing the repaint manager. In retrospect, I'd probably
//opt for making this a manual choice. There really isn't a clear
//win, no matter the approach.
RepaintManager manager = RepaintManager.currentManager(this);
if (!manager.getClass().isAnnotationPresent(TranslucentRepaintManager.class)) {
RepaintManager.setCurrentManager(new RepaintManagerX());
}
} else if (alpha == 1) {
//restore the oldOpaque if it was true (since opaque is false now)
if (oldOpaque) {
setOpaque(true);
}
}
firePropertyChange("alpha", oldAlpha, alpha);
repaint();
}
}