Skip to content

Commit

Permalink
issues #7, #3: smaller fixes
Browse files Browse the repository at this point in the history
replaced faulty image
fixed freezing bug resulted from restructuring
updated help dialog size for german language
fixed wrong reconnection after unplugging cable
  • Loading branch information
boonto committed Aug 1, 2019
1 parent aba5ce5 commit 05cec59
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void connect() {
@Override
public void close() {
this.running = false;
this.fire(State.DISCOVER);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public SerialLoggingTask(IOraListener<byte[]> listener, CharSequence port, int s
@Override
protected void log() {
try {
LOG.info("TEST");
byte[] readBuffer = new byte[this.comPort.bytesAvailable()];
this.comPort.readBytes(readBuffer, readBuffer.length);
fire(readBuffer);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/de/fhg/iais/roberta/main/RobotDetectorHelper.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package de.fhg.iais.roberta.main;

import org.apache.commons.lang3.concurrent.ConcurrentUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

import de.fhg.iais.roberta.connection.IDetector;
import de.fhg.iais.roberta.connection.IRobot;
Expand Down Expand Up @@ -54,7 +58,7 @@ public List<IRobot> getDetectedRobots() {
List<IRobot> robots = new ArrayList<>(5);

// Check each detector future
for ( Map.Entry<IDetector, Future<List<IRobot>>> entry : this.futures.entrySet() ) {
for ( Entry<IDetector, Future<List<IRobot>>> entry : this.futures.entrySet() ) {
IDetector detector = entry.getKey();
Future<List<IRobot>> future = entry.getValue();

Expand Down Expand Up @@ -106,8 +110,11 @@ public void update(IRobot object) {
*/
public void reset() {
this.selectedRobot = null;
for ( Map.Entry<IDetector, Boolean> entry : this.ranOnce.entrySet() ) {
for ( Entry<IDetector, Boolean> entry : this.ranOnce.entrySet() ) {
entry.setValue(false);
}
for ( Entry<IDetector, Future<List<IRobot>>> entry : this.futures.entrySet() ) {
entry.setValue(ConcurrentUtils.constantFuture(Collections.emptyList()));
}
}
}
25 changes: 14 additions & 11 deletions src/main/java/de/fhg/iais/roberta/ui/main/HelpDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.fhg.iais.roberta.ui.main;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
Expand All @@ -19,6 +20,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.Border;

import de.fhg.iais.roberta.ui.OraButton;

Expand All @@ -28,6 +30,8 @@ class HelpDialog extends JDialog {
static final String CMD_SELECT_OTHER = "select_other";
static final String CMD_CLOSE_HELP = "close_help";

private static final Border BORDER = BorderFactory.createEmptyBorder(8, 10, 8, 10);

private final JPanel pnlGreet = new JPanel();
private final JLabel lblGreet = new JLabel();

Expand All @@ -46,16 +50,16 @@ class HelpDialog extends JDialog {
HelpDialog(Frame frame, ResourceBundle messages, ActionListener listener) {
super(frame);
// General
this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS));
this.setLayout(new BorderLayout());
this.setResizable(false);

JPanel jPanel = new JPanel();
this.add(jPanel);
this.add(jPanel, BorderLayout.PAGE_START);
jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.LINE_AXIS));

jPanel.add(this.pnlGreet);
this.pnlGreet.setLayout(new FlowLayout(FlowLayout.LEADING));
this.pnlGreet.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10));
this.pnlGreet.setBorder(BORDER);
this.pnlGreet.add(this.lblGreet);
this.lblGreet.setText(messages.getString("helpConnectionGreeting"));

Expand All @@ -67,20 +71,18 @@ class HelpDialog extends JDialog {
this.butClose.setActionCommand(CMD_CLOSE_HELP);
this.butClose.addActionListener(listener);

this.add(this.pnlInfo);
this.pnlInfo.setLayout(new FlowLayout(FlowLayout.LEADING));
this.pnlInfo.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10));
this.pnlInfo.add(this.txtAreaInfo);
this.pnlInfo.setPreferredSize(new Dimension(300, 70));
this.add(this.pnlInfo, BorderLayout.CENTER);
this.pnlInfo.setLayout(new BorderLayout());
this.pnlInfo.setBorder(BORDER);
this.pnlInfo.add(this.txtAreaInfo, BorderLayout.CENTER);
this.txtAreaInfo.setText(messages.getString("helpConnection"));
this.txtAreaInfo.setLineWrap(true);
this.txtAreaInfo.setWrapStyleWord(true);
this.txtAreaInfo.setColumns(20);
this.txtAreaInfo.setEditable(false);

this.add(this.pnlRobots);
this.add(this.pnlRobots, BorderLayout.PAGE_END);
this.pnlRobots.setLayout(new FlowLayout(FlowLayout.LEADING));
this.pnlRobots.setBorder(BorderFactory.createEmptyBorder(8, 10, 8, 10));
this.pnlRobots.setBorder(BORDER);
this.pnlRobots.add(this.butEv3);
this.butEv3.setActionCommand(CMD_SELECT_EV3);
this.butEv3.addActionListener(listener);
Expand All @@ -96,5 +98,6 @@ class HelpDialog extends JDialog {

this.setUndecorated(true);
this.pack();
this.pack();
}
}
7 changes: 5 additions & 2 deletions src/main/java/de/fhg/iais/roberta/ui/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class MainController implements IController, IOraListenable<IRobot> {
private IConnector<?> connector = null;

// Child controllers of the main controller, this includes other windows/JFrames that are launched from the main controller
private SerialMonitorController serialMonitorController = null;
private final SerialMonitorController serialMonitorController;
private final DeviceIdEditorController deviceIdEditorController;

private final HelpDialog helpDialog;
Expand All @@ -100,6 +100,8 @@ public MainController(ResourceBundle rb) {

this.mainView.setCustomAddresses(this.addresses.get());

this.serialMonitorController = new SerialMonitorController(this.rb);

this.helpDialog = new HelpDialog(this.mainView, rb, mainViewListener);

// Check for updates on startup
Expand Down Expand Up @@ -211,7 +213,6 @@ public void setConnector(IConnector<?> connector) {

// Serial monitor is only needed for serial supporting robots
if ( (connector.getRobot() instanceof Arduino) || (connector.getRobot() instanceof Microbit) ) {
this.serialMonitorController = new SerialMonitorController(this.rb);
this.serialMonitorController.setConnector(connector);
}
}
Expand All @@ -236,6 +237,7 @@ private void setDiscover() {
LOG.debug("setDiscover");
this.connected = false;
this.mainView.setDiscover();
this.serialMonitorController.setState(State.DISCOVER);
}

private void showAttentionPopup(String key, String... entries) {
Expand Down Expand Up @@ -285,6 +287,7 @@ public void actionPerformed(ActionEvent e) {
MainController.this.connector.connect();
break;
case CMD_DISCONNECT:
setDiscover(); // first!, order is important, otherwise ui thread does into deadlock
MainController.this.connector.close();
break;
case CMD_HELP:
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/de/fhg/iais/roberta/ui/main/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowListener;
import java.util.Collections;
import java.util.List;
import java.util.ResourceBundle;

Expand Down Expand Up @@ -598,7 +599,7 @@ void setDiscover() {
this.txtAreaInfo.setText(this.messages.getString("plugInInfo"));
((CardLayout) this.pnlGif.getLayout()).show(this.pnlGif, UiState.DISCOVERING.toString() + ConnectionType.WIRED);
this.hideArduinoMenu();
this.showTopEmpty();
this.showTopRobots(Collections.emptyList());
this.showCustomAddress();
}

Expand Down Expand Up @@ -639,7 +640,6 @@ void setNew(ConnectionType connectionType, String prefix, String token, String s
((CardLayout) this.pnlGif.getLayout()).show(this.pnlGif, UiState.CONNECTING.toString() + connectionType);

// dont show advanced options anymore
this.showCustomEmpty();
this.hideAdvancedOptions();
}

Expand Down Expand Up @@ -694,11 +694,6 @@ void showTopTokenServer() {
cl.show(this.pnlTopContainer, CARD_TOKEN_SERVER);
}

private void showTopEmpty() {
CardLayout cl = (CardLayout) this.pnlTopContainer.getLayout();
cl.show(this.pnlTopContainer, CARD_TOP_EMPTY);
}

// Custom
private void showCustomAddress() {
CardLayout cl = (CardLayout) this.pnlCustomContainer.getLayout();
Expand All @@ -710,11 +705,6 @@ void showCustomNaoLogin() {
cl.show(this.pnlCustomContainer, CARD_NAO_LOGIN);
}

private void showCustomEmpty() {
CardLayout cl = (CardLayout) this.pnlCustomContainer.getLayout();
cl.show(this.pnlCustomContainer, CARD_CUSTOM_EMPTY);
}

private void showAdvancedOptions() {
Dimension size = this.getSize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void setConnector(IConnector<?> connector) {
public void setState(State state) {
LOG.debug("setState: {}", state);
switch ( state ) {
case DISCOVER:
this.stopSerialLogging();
break;
case WAIT_UPLOAD:
this.stopSerialLogging();
break;
Expand Down
Binary file modified src/main/resources/images/connected_wireless.gif
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 05cec59

Please sign in to comment.