Skip to content

Commit

Permalink
added webcampanel and icons
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 23, 2023
1 parent e4c118b commit c916313
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 16 deletions.
30 changes: 21 additions & 9 deletions src/main/java/com/marginallyclever/ro3/apps/RO3Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.marginallyclever.ro3.apps.logpanel.LogPanel;
import com.marginallyclever.ro3.apps.nodedetailview.NodeDetailView;
import com.marginallyclever.ro3.apps.nodetreeview.NodeTreeView;
import com.marginallyclever.ro3.apps.webcampanel.WebCamPanel;
import com.marginallyclever.ro3.render.OpenGLPanel;
import com.marginallyclever.ro3.render.Viewport;
import com.marginallyclever.robotoverlord.RobotOverlord;
Expand All @@ -31,24 +32,26 @@
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Objects;
import java.util.prefs.Preferences;

public class RO3Frame extends JFrame {
private static final Logger logger = LoggerFactory.getLogger(RO3Frame.class);
private final List<DockingPanel> windows = new ArrayList<>();
private final JFileChooser fileChooser;
private final OpenGLPanel renderPanel;
private final LogPanel logPanel;
private final EditorPanel editPanel;
private final List<DockingPanel> windows = new ArrayList<>();
private final JFileChooser fileChooser;
private final WebCamPanel webCamPanel;

public RO3Frame() {
super("Robot Overlord 3");
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setLookAndFeel();
logPanel = new LogPanel();
editPanel = new EditorPanel();
renderPanel = new Viewport();
fileChooser = new JFileChooser();
webCamPanel = new WebCamPanel();

initDocking();
createLayout();
Expand Down Expand Up @@ -82,14 +85,15 @@ private void initDocking() {
}

private void addQuitHandler() {
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
// when someone tries to close the app, confirm it.
@Override
public void windowClosing(WindowEvent e) {
if(confirmClose()) {
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
super.windowClosing(e);
if(confirmClose()) {
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
super.windowClosing(e);
}
});

Expand Down Expand Up @@ -148,13 +152,17 @@ private JMenu buildFileMenu() {
menuFile.add(new JMenuItem(new LoadScene(loadRecentMenu,null,fileChooser)));
menuFile.add(loadRecentMenu);
menuFile.add(new JMenuItem(new ImportScene(fileChooser)));

// TODO save vs save-as
menuFile.add(new JMenuItem(new SaveScene(loadRecentMenu,fileChooser)));
menuFile.add(new JMenuItem(new ExportScene()));

menuFile.add(new JSeparator());
menuFile.add(new JMenuItem(new AbstractAction("Quit") {
{
putValue(Action.NAME, "Quit");
putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK));
putValue(Action.SMALL_ICON, new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-stop-16.png"))));
putValue(Action.SHORT_DESCRIPTION, "Quit the application.");
}
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if(confirmClose()) {
Expand Down Expand Up @@ -221,6 +229,10 @@ private void createLayout() {
aboutView.add(new AboutPanel(), BorderLayout.CENTER);
windows.add(aboutView);

DockingPanel webcamView = new DockingPanel("1331fbb0-ceda-4c67-b343-6539d4f939a1","USB Camera");
webcamView.add(webCamPanel, BorderLayout.CENTER);
windows.add(webcamView);

// now that the main frame is set up with the defaults, we can restore the layout
AppState.setPersistFile(new File("ro3.layout"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Objects;

/**
* <p>Export the scene and all the assets used to a single file for sharing on another computer.
Expand All @@ -18,7 +19,9 @@ public class ExportScene extends AbstractAction {
private static final JFileChooser chooser = new JFileChooser();

public ExportScene() {
super("Export Scene");
super();
putValue(Action.NAME,"Export Scene");
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-export-16.png"))));
putValue(SHORT_DESCRIPTION,"Export the scene and all the assets used to a single file.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.InvalidParameterException;
import java.util.Objects;

/**
* Load a Scene into the existing Scene.
Expand All @@ -24,8 +25,10 @@ public class ImportScene extends AbstractAction {
private final JFileChooser chooser;

public ImportScene(JFileChooser chooser) {
super("Import Scene");
super();
this.chooser = chooser;
putValue(Action.NAME,"Import Scene");
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-import-16.png"))));
putValue(SHORT_DESCRIPTION,"Load a Scene into the existing Scene.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.InvalidParameterException;
import java.util.Objects;

/**
* Load a scene from a file. Completely replaces the current Scene.
Expand Down Expand Up @@ -48,6 +49,7 @@ public LoadScene(RecentFilesMenu menu, String filePath,JFileChooser chooser) {
this.menu = menu;
this.filePath = filePath;
putValue(Action.NAME,filePath==null || filePath.isEmpty() ? "Load Scene" : filePath);
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-load-16.png"))));
putValue(SHORT_DESCRIPTION,"Load a scene from a file. Completely replaces the current Scene.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Reset the scene to a new empty scene.
Expand All @@ -19,6 +20,7 @@ public class NewScene extends AbstractAction {
public NewScene() {
super();
putValue(Action.NAME,"New");
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-new-16.png"))));
putValue(SHORT_DESCRIPTION,"Reset the scene to a new empty scene.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class RemoveNode extends AbstractAction {
private final NodeTreeView nodeTreeView;
public RemoveNode(NodeTreeView nodeTreeView) {
super();
this.nodeTreeView = nodeTreeView;
putValue(Action.NAME,"Remove");
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-delete-16.png"))));
putValue(SHORT_DESCRIPTION,"Remove the selected node(s).");
this.nodeTreeView = nodeTreeView;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Objects;

/**
* Save the entire scene to a file.
Expand All @@ -22,9 +23,11 @@ public class SaveScene extends AbstractAction {
private final RecentFilesMenu menu;

public SaveScene(RecentFilesMenu menu,JFileChooser chooser) {
super("Save Scene");
super();
this.chooser = chooser;
this.menu = menu;
putValue(Action.NAME,"Save Scene");
putValue(Action.SMALL_ICON,new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-save-16.png"))));
putValue(SHORT_DESCRIPTION,"Save to a file.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.marginallyclever.ro3.apps.webcampanel;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;

import javax.swing.*;
import java.awt.*;

public class WebCamPanel extends JPanel {
private final Webcam webcam;
private final WebcamPanel panel;

public WebCamPanel() {
super(new BorderLayout());
setName("webcam");

webcam = Webcam.getDefault();
Dimension size = WebcamResolution.QVGA.getSize();
webcam.setViewSize(size);

panel = new WebcamPanel(webcam, size, false);
panel.setFPSDisplayed(true);
add(panel, BorderLayout.CENTER);
panel.start();
panel.pause();
}

@Override
public void addNotify() {
super.addNotify();
panel.resume();
}

@Override
public void removeNotify() {
super.removeNotify();
panel.pause();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<html><body>
<html>
<body style="padding:10px 10px 10px 10px">
<h1>Hello, World!</h1>
<p>Welcome to Robot Overlord 3.</p>
<p><a href="">Read the friendly manual</a></p>
<p><a href="https://mcr.dozuki.com/c/Robot_Overlord_3">Read the friendly manual</a></p>
<p><a href="https://discord.gg/VQ82jNvDBP">Discord</a>: join us!</p>
<p><a href="https://github.com/marginallyclever/robot-overlord-app">Github.com</a>: read the source</p>
<p>Created by <a href="https://marginallyclever.com">Marginally Clever Robots</a></p>
</body></html>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c916313

Please sign in to comment.