⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 empty.java

📁 基于Junit的 功能和单元测试的的测试工具。只支持Swing.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.uispec4j.interception.toolkit;

import sun.awt.image.SunVolatileImage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.PaintEvent;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.*;
import java.awt.image.renderable.RenderableImage;
import java.awt.peer.*;
import java.text.AttributedCharacterIterator;
import java.util.HashMap;
import java.util.Map;

/**
 * Contains a set of empty peer class designed to keep the UISpec peer implementation clean.
 */
///CLOVER:OFF
public final class Empty {

  public static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
  public static final Dimension NULL_DIMENSION = new Dimension(50, 50);
  public static final Rectangle NULL_RECTANGLE = new Rectangle(50, 50);
  public static final GraphicsConfiguration NULL_GRAPHICS_CONFIGURATION = new DummyGraphicsConfiguration();
  public static final GraphicsDevice NULL_GRAPHICS_DEVICE = new DummyGraphicsDevice();
  public static final Graphics2D NULL_GRAPHICS_2D = new DummyGraphics2D();
  public static final ColorModel NULL_COLOR_MODEL = new DummyColorModel();
  public static final Point NULL_POINT = new Point(0, 0);
  public static final Image NULL_IMAGE = new DummyImage();
  public static final Font NULL_FONT = new JLabel().getFont();
  public static final FontMetrics NULL_FONT_METRICS;
  public static final VolatileImage NULL_VOLATILE_IMAGE = new DummyVolatileImage();
  public static final AffineTransform NULL_AFFINE_TRANSFORM = new AffineTransform();
  public static final int DEFAULT_HEIGHT = 50;
  public static final Paint NULL_PAINT = new DummyPaint();
  public static final PaintContext NULL_PAINT_CONTEXT = new DummyPaintContext();
  public static final ImageProducer NULL_IMAGE_PRODUCER = new DummyImageProducer();
  public static final Composite NULL_COMPOSITE = new DummyComposite();
  public static final CompositeContext NULL_COMPOSITE_CONTEXT = new DummyCompositeContext();
  public static final Stroke NULL_STROKE = new DummyStroke();
  public static final Icon NULL_ICON = new DummyIcon();

  public static final RobotPeer NULL_ROBOT = new DummyRobotPeer();
  public static final DummyLightweightPeer NULL_LIGHTWEIGHT_PEER = new DummyLightweightPeer();
  public static final DummyPanelPeer NULL_PANEL_PEER = new DummyPanelPeer();
  public static final DummyCanvasPeer NULL_CANVAS_PEER = new DummyCanvasPeer();

  static {
    NULL_FONT_METRICS = new DummyFontMetrics(NULL_FONT);
  }

  private Empty() {
  }

  static class WindowPeeer implements WindowPeer {
    public void toBack() {
    }

    public void updateAlwaysOnTop() {
    }

    public void updateFocusableWindowState() {
    }

    public boolean requestWindowFocus() {
      return false;
    }

    public void toFront() {
    }

    public void beginLayout() {
    }

    public void beginValidate() {
    }

    public void endLayout() {
    }

    public void endValidate() {
    }

    public Insets getInsets() {
      return NULL_INSETS;
    }

    public Insets insets() {
      return NULL_INSETS;
    }

    public boolean isPaintPending() {
      return false;
    }

    public void cancelPendingPaint(int x, int y, int w, int h) {
    }

    public void restack() {
    }

    public boolean isRestackSupported() {
      return false;
    }

    public boolean canDetermineObscurity() {
      return false;
    }

    public int checkImage(Image img, int w, int h, ImageObserver o) {
      return 0;
    }

    public void coalescePaintEvent(PaintEvent e) {
    }

    public void createBuffers(int numBuffers, BufferCapabilities caps)
      throws AWTException {
    }

    public Image createImage(ImageProducer producer) {
      return NULL_IMAGE;
    }

    public Image createImage(int width, int height) {
      return NULL_IMAGE;
    }

    public VolatileImage createVolatileImage(int width, int height) {
      return NULL_VOLATILE_IMAGE;
    }

    public void destroyBuffers() {
    }

    public void reparent(ContainerPeer newContainer) {
    }

    public boolean isReparentSupported() {
      return false;
    }

    public void layout() {
    }

    public Rectangle getBounds() {
      return NULL_RECTANGLE;
    }

    public void disable() {
    }

    public void dispose() {
    }

    public void enable() {
    }

    public void flip(BufferCapabilities.FlipContents flipAction) {
    }

    public Image getBackBuffer() {
      return NULL_IMAGE;
    }

    public ColorModel getColorModel() {
      return NULL_COLOR_MODEL;
    }

    public FontMetrics getFontMetrics(Font font) {
      return NULL_FONT_METRICS;
    }

    public Graphics getGraphics() {
      return NULL_GRAPHICS_2D;
    }

    public GraphicsConfiguration getGraphicsConfiguration() {
      return NULL_GRAPHICS_CONFIGURATION;
    }

    public Point getLocationOnScreen() {
      return NULL_POINT;
    }

    public Dimension getMinimumSize() {
      return NULL_DIMENSION;
    }

    public Dimension getPreferredSize() {
      return NULL_DIMENSION;
    }

    public Toolkit getToolkit() {
      return UISpecToolkit.instance();
    }

    public void handleEvent(AWTEvent e) {
    }

    public boolean handlesWheelScrolling() {
      return false;
    }

    public void hide() {
    }

    public boolean isFocusable() {
      return false;
    }

    public boolean isObscured() {
      return false;
    }

    public Dimension minimumSize() {
      return NULL_DIMENSION;
    }

    public void paint(Graphics g) {
    }

    public Dimension preferredSize() {
      return NULL_DIMENSION;
    }

    public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
      return false;
    }

    public void print(Graphics g) {
    }

    public void setBounds(int x, int y, int width, int height, int op) {
    }

    public void repaint(long tm, int x, int y, int width, int height) {
    }

    public boolean requestFocus(Component lightweightChild,
                                boolean temporary,
                                boolean focusedWindowChangeAllowed,
                                long time) {
      return false;
    }

    public void reshape(int x, int y, int width, int height) {
    }

    public void setBackground(Color c) {
    }

    public void setBounds(int x, int y, int width, int height) {
    }

    public void setEnabled(boolean b) {
    }

    public void setFont(Font f) {
    }

    public void setForeground(Color c) {
    }

    public void setVisible(boolean b) {
    }

    public void show() {
    }

    public void updateCursorImmediately() {
    }
  }

  static class FramePeer extends Empty.WindowPeeer implements java.awt.peer.FramePeer {
    public int getState() {
      return 0;
    }

    public void setState(int state) {
    }

    public void setResizable(boolean resizeable) {
    }

    public void setIconImage(Image im) {
    }

    public void setMenuBar(MenuBar mb) {
    }

    public void setMaximizedBounds(Rectangle bounds) {
    }

    public void setBoundsPrivate(int x, int y, int width, int height) {
    }

    public void setTitle(String title) {
    }
  }

  static class DialogPeer extends Empty.WindowPeeer implements java.awt.peer.DialogPeer {
    public void setResizable(boolean resizeable) {
    }

    public void setTitle(String title) {
    }
  }

  private static class DummyRobotPeer implements RobotPeer {

    public void keyPress(int keycode) {
    }

    public void keyRelease(int keycode) {
    }

    public void mousePress(int buttons) {
    }

    public void mouseRelease(int buttons) {
    }

    public void mouseWheel(int wheelAmt) {
    }

    public int getRGBPixel(int x, int y) {
      return 0;
    }

    public void mouseMove(int x, int y) {
    }

    public int[] getRGBPixels(Rectangle bounds) {
      return new int[0];
    }
  }

  static class DummyGraphicsConfiguration extends GraphicsConfiguration {
    public BufferedImage createCompatibleImage(int width, int height) {
      return new BufferedImage(width, height, 0);
    }

    public BufferedImage createCompatibleImage(int width, int height, int transparency) {
      return new BufferedImage(width, height, 0);
    }

    public VolatileImage createCompatibleVolatileImage(int width, int height) {
      return new SunVolatileImage(this, width, height);
    }

    public VolatileImage createCompatibleVolatileImage(int width, int height, int transparency) {
      return NULL_VOLATILE_IMAGE;
    }

    public Rectangle getBounds() {
      return NULL_RECTANGLE;
    }

    public ColorModel getColorModel() {
      return NULL_COLOR_MODEL;
    }

    public ColorModel getColorModel(int transparency) {
      return NULL_COLOR_MODEL;
    }

    public AffineTransform getDefaultTransform() {
      return NULL_AFFINE_TRANSFORM;
    }

    public GraphicsDevice getDevice() {
      return NULL_GRAPHICS_DEVICE;
    }

    public AffineTransform getNormalizingTransform() {
      return NULL_AFFINE_TRANSFORM;
    }
  }

  static class DummyColorModel extends ColorModel {
    public DummyColorModel(int bits) {
      super(bits);
    }

    public DummyColorModel() {
      super(128);
    }

    public int getAlpha(int pixel) {
      return 0;
    }

    public int getBlue(int pixel) {
      return 0;
    }

    public int getGreen(int pixel) {
      return 0;
    }

    public int getRed(int pixel) {
      return 0;
    }
  }

  private static class DummyImage extends Image {

    public void flush() {
    }

    public Graphics getGraphics() {
      return NULL_GRAPHICS_2D;
    }

    public int getHeight(ImageObserver observer) {
      return DEFAULT_HEIGHT;
    }

    public int getWidth(ImageObserver observer) {
      return DEFAULT_HEIGHT;
    }

    public ImageProducer getSource() {
      return NULL_IMAGE_PRODUCER;
    }

    public Object getProperty(String name, ImageObserver observer) {
      return "";
    }
  }

  private static class DummyVolatileImage extends VolatileImage {
    public static final ImageCapabilities CAPABILITIES = new ImageCapabilities(false);
    public static final BufferedImage IMAGE = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB);

    public BufferedImage getSnapshot() {
      return IMAGE;
    }

    public int getWidth() {
      return DEFAULT_HEIGHT;
    }

    public int getHeight() {
      return DEFAULT_HEIGHT;
    }

    public Graphics2D createGraphics() {
      return NULL_GRAPHICS_2D;
    }

    public int validate(GraphicsConfiguration gc) {
      return 0;
    }

    public boolean contentsLost() {
      return false;
    }

    public ImageCapabilities getCapabilities() {
      return CAPABILITIES;
    }

    public int getWidth(ImageObserver observer) {
      return DEFAULT_HEIGHT;
    }

    public int getHeight(ImageObserver observer) {
      return DEFAULT_HEIGHT;
    }

    public Object getProperty(String name, ImageObserver observer) {
      return "";
    }
  }

  private static class DummyFontMetrics extends FontMetrics {
    public static final int[] WIDTHS = new int[256];

    public DummyFontMetrics(Font font) {
      super(font);
    }

    public int[] getWidths() {
      return WIDTHS;
    }

    public int stringWidth(String str) {
      return 0;
    }
  }

  abstract static class DummyComponentPeer implements ComponentPeer {

    public void destroyBuffers() {
    }

    public void disable() {
    }

    public void dispose() {
    }

    public void enable() {
    }

    public void hide() {
    }

    public void updateCursorImmediately() {
    }

    public boolean canDetermineObscurity() {
      return false;
    }

    public boolean handlesWheelScrolling() {
      return false;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -