public void setScale(double scale) { if (scale != this.scale) { this.scale = scale; display.setSize(Math.max((int)Math.ceil(getWidth() / scale), 0), Math.max((int)Math.ceil(getHeight() / scale), 0)); display.repaint(); } }
/** * Use this method to scale up or down (that is zoom in or out) * the entire application's display. * <p> For the main application window, a {@link org.apache.pivot.wtk.effects.ScaleDecorator} * cannot be used. This method (and related ones) must be used instead. * @see #scaleUp * @see #scaleDown * @see #getScale */ public void setScale(double scale) { if (scale != this.scale) { this.scale = scale; display.setSize(Math.max((int)Math.ceil(getWidth() / scale), 0), Math.max((int)Math.ceil(getHeight() / scale), 0)); display.repaint(); } }
@Override protected void processComponentEvent(ComponentEvent event) { super.processComponentEvent(event); switch (event.getID()) { case ComponentEvent.COMPONENT_RESIZED: { if (scale == 1) { display.setSize(Math.max(getWidth(), 0), Math.max(getHeight(), 0)); } else { display.setSize(Math.max((int)Math.ceil(getWidth() / scale), 0), Math.max((int)Math.ceil(getHeight() / scale), 0)); } break; } } }
@Override public void print(Graphics graphics) { // TODO: verify if/how we have to re-scale output in this case ... // Intersect the clip region with the bounds of this component // (for some reason, AWT does not do this automatically) graphics.clipRect(0, 0, getWidth(), getHeight()); java.awt.Rectangle clipBounds = graphics.getClipBounds(); if (clipBounds != null && !clipBounds.isEmpty()) { try { // When printing, there is no point in using offscreen buffers. paintDisplay((Graphics2D)graphics); } catch (RuntimeException exception) { System.err.println("Exception thrown during print(): " + exception); throw exception; } } }
@Override protected void processComponentEvent(ComponentEvent event) { super.processComponentEvent(event); switch (event.getID()) { case ComponentEvent.COMPONENT_RESIZED: { if (scale == 1) { display.setSize(Math.max(getWidth(), 0), Math.max(getHeight(), 0)); } else { display.setSize(Math.max((int)Math.ceil(getWidth() / scale), 0), Math.max((int)Math.ceil(getHeight() / scale), 0)); } break; } default: { break; } } }
@Override public void print(Graphics graphics) { // TODO: verify if/how we have to re-scale output in this case ... // Intersect the clip region with the bounds of this component // (for some reason, AWT does not do this automatically) graphics.clipRect(0, 0, getWidth(), getHeight()); java.awt.Rectangle clipBounds = graphics.getClipBounds(); if (clipBounds != null && !clipBounds.isEmpty()) { try { // When printing, there is no point in using offscreen buffers. paintDisplay((Graphics2D)graphics); } catch (RuntimeException exception) { System.err.println("Exception thrown during print(): " + exception); throw exception; } } }