JOptionPane for Errors, general refactoring, deprecated class removed (CameraRenderer) moved into Swing now
modified: / SwingCCTVManager ; Error Pane, refactoring / WebcamCaptureLoop ; cleanup method for closing cameras reliably, and some MessageDialogs for error handling (just fails lol) / SwingCameraWindow ; refactor some legacy code into a "modern" lambda function , Message Dialog for error handling , and some g2d stuff (paintComponent) removed: - CameraRenderer.java ; Deprecated Component, was used for SWT GL Surfaces. We dont do that now! --- rattatwinko
This commit is contained in:
@@ -22,6 +22,7 @@ public class SwingCameraWindow {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// clean shit up
|
||||
frame.dispose();
|
||||
captureLoop.stop(); // be sure to call this! otherwise the camera will stay open!
|
||||
}
|
||||
});
|
||||
|
||||
@@ -30,18 +31,8 @@ public class SwingCameraWindow {
|
||||
this.frame.pack();
|
||||
this.frame.setSize(640, 480);
|
||||
|
||||
this.captureLoop = new WebcamCaptureLoop(webcam, (BufferedImage img) -> {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
cameraPanel.setImage(img);
|
||||
});
|
||||
});
|
||||
this.captureLoop = new WebcamCaptureLoop(webcam, (BufferedImage img) -> SwingUtilities.invokeLater(() -> cameraPanel.setImage(img)));
|
||||
|
||||
this.frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
captureLoop.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void open() {
|
||||
@@ -61,8 +52,9 @@ public class SwingCameraWindow {
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (currentImage != null) {
|
||||
// Draw the image scaled to the panel size
|
||||
g.drawImage(currentImage, 0, 0, getWidth(), getHeight(), null);
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g2.drawImage(currentImage, 0, 0, getWidth(), getHeight(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +67,12 @@ public class SwingCameraWindow {
|
||||
SwingCameraWindow window = new SwingCameraWindow(webcam);
|
||||
window.open();
|
||||
} else {
|
||||
System.err.println("No webcam found!");
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"No Webcam found!",
|
||||
"Error",
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user