/*
* RemoteLRControlView.java
*/
package remotelrcontrol;
import java.util.List;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Arrays;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
/**
* The application's main frame.
*/
public class RemoteLRControlView extends FrameView {
public RemoteLRControlView(SingleFrameApplication app) {
super(app);
initComponents();
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
@Override
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}
public static void progressBarUpdater(int position, int maxLength){
int pos = (int)((double)(position/maxLength) * 100);
RemoteLRControlView.progressBar.setValue(pos);
}
public void showVideoConfigWindow(){
VideoDetectionPropsVew vdpv = new VideoDetectionPropsVew();
vdpv.setLocationRelativeTo(RemoteLRControlApp.getApplication().getMainFrame());
RemoteLRControlApp.getApplication().show(vdpv);
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = RemoteLRControlApp.getApplication().getMainFrame();
aboutBox = new RemoteLRControlAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
RemoteLRControlApp.getApplication().show(aboutBox);
}
@Action
public void showPreferencesWindow(){
if(prefsWindow == null){
prefsWindow = new RLRCPropertiesView();
prefsWindow.setLocationRelativeTo(RemoteLRControlApp.getApplication().getMainFrame());
}
RemoteLRControlApp.getApplication().show(prefsWindow);
}
@Action
public void showBTConfWindow(){
if(btConfWindow == null){
btConfWindow = new BTConfigView();
btConfWindow.setLocationRelativeTo(RemoteLRControlApp.getApplication().getMainFrame());
}
RemoteLRControlApp.getApplication().show(btConfWindow);
}
@Action
public void showLEJOSConfigureWindow(){
LEJOSConfigureView lcv = new LEJOSConfigureView();
lcv.setLocationRelativeTo(RemoteLRControlApp.getApplication().getMainFrame());
RemoteLRControlApp.getApplication().show(lcv);
}
@Action
public void showTrajCreationWindow(){
if(trajectoryDrawWindow == null){
trajectoryDrawWindow = new RCTrajectoryCreateView();
trajectoryDrawWindow.setLocationRelativeTo(RemoteLRControlApp.getApplication().getMainFrame());
}
RemoteLRControlApp.getApplication().show(trajectoryDrawWindow);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
mainPanel = new javax.swing.JPanel();
createTrajBtn = new javax.swing.JButton();
loadTrajBtn = new javax.swing.JButton();
startMoveBtn = new javax.swing.JButton();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
mainPanel.setName("mainPanel"); // NOI18N
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(remotelrcontrol.RemoteLRControlApp.class).getContext().getResourceMap(RemoteLRControlView.class);
createTrajBtn.setText(resourceMap.getString("createTrajBtn.text")); // NOI18N
createTrajBtn.setEnabled(false);
createTrajBtn.setName("createTrajBtn"); // NOI18N
createTrajBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
createTrajBtnMouseClicked(evt);
}
});
loadTrajBtn.setText(resourceMap.getString("loadTrajBtn.text")); // NOI18N
loadTrajBtn.setActionCommand(resourceMap.getString("loadTrajBtn.actionCommand")); // NOI18N
loadTrajBtn.setEnabled(false);
loadTrajBtn.setName("loadTrajBtn"); // NOI18N
loadTrajBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
loadTrajBtnMouseClicked(evt);
}
});
startMoveBtn.setText(resourceMap.getString("startMoveBtn.text")); // NOI18N
startMoveBtn.setEnabled(false);
startMoveBtn.setName("startMoveBtn"); // NOI18N
startMoveBtn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
startMoveBtnMouseClicked(evt);
}
});
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(loadTrajBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
.addComponent(createTrajBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
.addGap(69, 69, 69)
.addComponent(startMoveBtn)
.addGap(36, 36, 36))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(startMoveBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(createTrajBtn)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(loadTrajBtn)))
.addContainerGap(166, Short.MAX_VALUE))
);
menuBar.setName("menuBar"); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(remotelrcontrol.RemoteLRControlApp.class).getContext().getActionMap(RemoteLRControlView.class, this);
jMenuItem1.setAction(actionMap.get("showBTConfWindow")); // NOI18N
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
jMenuItem1.setName("jMenuItem1"); // NOI18N
fileMenu.add(jMenuItem1);
jMenuItem2.setAction(actionMap.get("showPreferencesWindow")); // NOI18N
jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
jMenuItem2.setName("jMenuItem2"); // NOI18N
fileMenu.add(jMenuItem2);
jMenuItem3.setAction(actionMap.get("showLEJOSConfigureWindow")); // NOI18N
jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
jMenuItem3.setName("jMenuItem3"); // NOI18N
fileMenu.add(jMenuItem3);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(statusMessageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 356, Short.MAX_VALUE)
.addComponent(statusAnimationLabel)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
.addContainerGap(179, Short.MAX_VALUE)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusMessageLabel)
.addComponent(statusAnimationLabel)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>//GEN-END:initComponents
private void createTrajBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createTrajBtnMouseClicked
if(createTrajBtn.isEnabled()){
if(btConfWindow != null){
if(Boolean.parseBoolean(RCProperties.config.getProperty("useVideoCamDetection".intern()))){
showVideoConfigWindow();
} else {
showTrajCreationWindow();
}
} else {
RCErrorDialogView errDialog = new RCErrorDialogView(RemoteLRControlApp.getApplication().getMainFrame(), true);
errDialog.setErrorText("You should enter Robot's MAC addresses before creation trajectories! (File\\Configure connections)");
RemoteLRControlApp.getApplication().show(errDialog);
}
}
}//GEN-LAST:event_createTrajBtnMouseClicked
private void loadTrajBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_loadTrajBtnMouseClicked
if(loadTrajBtn.isEnabled()){
JFileChooser openFileDialog = new JFileChooser();
openFileDialog.setDialogTitle("Open trajectory file");
openFileDialog.showOpenDialog(RemoteLRControlApp.getApplication().getMainFrame());
openFileDialog.setApproveButtonText("Open");
openFileDialog.setDragEnabled(true);
openFileDialog.setMultiSelectionEnabled(true);
//openFileDialog.setCurrentDirectory(new File(""));
//openFileDialog.setSelectedFile(new File(".generated"));
if(openFileDialog.getSelectedFiles() == null)
return;
List<File> coordFiles = Arrays.asList(openFileDialog.getSelectedFiles());
RCProperties.loadTrajectories(coordFiles);
}
}//GEN-LAST:event_loadTrajBtnMouseClicked
private void startMoveBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_startMoveBtnMouseClicked
if(startMoveBtn.isEnabled())
RemoteLRControlApp.mover.run();
}//GEN-LAST:event_startMoveBtnMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JButton createTrajBtn;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
public javax.swing.JButton loadTrajBtn;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
public static javax.swing.JProgressBar progressBar;
public javax.swing.JButton startMoveBtn;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration//GEN-END:variables
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
private JFrame prefsWindow;
private JFrame btConfWindow;
private RCTrajectoryCreateView trajectoryDrawWindow;
}