initial
This commit is contained in:
74
src/main/java/io/swtc/CCTVManager.java
Normal file
74
src/main/java/io/swtc/CCTVManager.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package io.swtc;
|
||||
|
||||
import com.github.sarxos.webcam.Webcam;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CCTVManager {
|
||||
public static void main(String[] args) {
|
||||
Display display = new Display();
|
||||
Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.ON_TOP);
|
||||
shell.setText("Dashboard");
|
||||
|
||||
List<Webcam> webcams = Webcam.getWebcams();
|
||||
int columnCount = webcams.size() > 3 ? 3 : Math.max(1, webcams.size());
|
||||
|
||||
GridLayout mainLayout = new GridLayout(columnCount, true);
|
||||
mainLayout.marginWidth = 20;
|
||||
mainLayout.marginHeight = 20;
|
||||
mainLayout.horizontalSpacing = 15;
|
||||
mainLayout.verticalSpacing = 15;
|
||||
shell.setLayout(mainLayout);
|
||||
|
||||
// Header (Spans across all columns)
|
||||
Label title = new Label(shell, SWT.NONE);
|
||||
title.setText("Connected Devices");
|
||||
title.setFont(new Font(display, "Segoe UI", 14, SWT.BOLD));
|
||||
GridData titleData = new GridData(SWT.FILL, SWT.CENTER, true, false, columnCount, 1);
|
||||
title.setLayoutData(titleData);
|
||||
|
||||
if (webcams.isEmpty()) {
|
||||
Label error = new Label(shell, SWT.NONE);
|
||||
error.setText("no available cameras!");
|
||||
} else {
|
||||
for (Webcam webcam : webcams) {
|
||||
createCameraCard(shell, display, webcam);
|
||||
}
|
||||
}
|
||||
|
||||
shell.pack();
|
||||
shell.open();
|
||||
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) {
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
display.dispose();
|
||||
}
|
||||
|
||||
private static void createCameraCard(Composite parent, Display display, Webcam webcam) {
|
||||
Group card = new Group(parent, SWT.NONE);
|
||||
card.setText(webcam.getName());
|
||||
card.setLayout(new GridLayout(1, false));
|
||||
card.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
Button btn = new Button(card, SWT.PUSH);
|
||||
btn.setText("View");
|
||||
btn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
||||
|
||||
btn.addListener(SWT.Selection, e -> {
|
||||
/**
|
||||
* This is where magic happens! We start the Window Here! As arguments, we give our display and webcam index!
|
||||
* */
|
||||
System.out.println("Starting: " + webcam.getName());
|
||||
CameraWindow window = new CameraWindow(display,webcam);
|
||||
window.open();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user