@Override protected void paintComponent(Graphics g) { int width = getWidth(), height = getHeight(); Graphics2D g2d = (Graphics2D) g.create(); if (alpha < 1.0f) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); } if (currentImage != null) { GraphicsConfiguration gc = getGraphicsConfiguration(); // If the GraphicsConfig changed, then change the hints being used if (gc.getClass() != graphicsConfigClass) { graphicsConfigClass = gc.getClass(); updateRenderingHints(graphicsConfigClass); } if (!renderingHints.isEmpty()) { g2d.setRenderingHints(renderingHints); } render(g2d, 0, 0, width, height); } else if (alpha >= 1.0f) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, width, height); } g2d.dispose(); } @Override
renderComponent.addPropertyChangeListener("preferredSize", propListener); renderComponent.addMouseListener(mouseListener); renderComponent.addMouseMotionListener(mouseListener); renderComponent.addKeyListener(keyListener); addKeyListener(keyListener); renderComponent.setBounds(getBounds()); setOpaque(true); setBackground(Color.BLACK);
public void run() { // // If the image changed size, resize the component to fit // if (width != imgWidth || height != imgHeight) { renderComponent.setPreferredSize(new Dimension(width, height)); imgWidth = width; imgHeight = height; } if (renderComponent.isVisible()) { renderComponent.paintImmediately(0, 0, renderComponent.getWidth(), renderComponent.getHeight()); } } });
/** * Gets the scaled Y position of the mouse event. */ private double getY(MouseEvent evt) { double scaleY = (double) imgHeight / (double) renderComponent.getHeight(); return (double) evt.getY() * scaleY; } /**
/** * Gets the scaled X position of the mouse event. */ private double getX(MouseEvent evt) { double scaleX = (double) imgWidth / (double) renderComponent.getWidth(); return (double) evt.getX() * scaleX; } /**
public void propertyChange(PropertyChangeEvent evt) { setPreferredSize(renderComponent.getPreferredSize()); scaleVideoOutput(); } };