Skip to content

Commit

Permalink
Implemented Run
Browse files Browse the repository at this point in the history
  • Loading branch information
leofds committed Mar 13, 2021
1 parent 8d946fe commit 5a54759
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import com.github.leofds.iotladdereditor.application.Mediator;
import com.github.leofds.iotladdereditor.ladder.config.Constants;
import com.github.leofds.iotladdereditor.view.event.BuildEvent;
import com.github.leofds.iotladdereditor.view.event.BuildRunEvent;
import com.github.leofds.iotladdereditor.view.event.Subject;

public class ContentPanel extends JPanel{
Expand All @@ -39,7 +39,7 @@ public ContentPanel() {
setBorder(new EmptyBorder(0,0,0,0));

Subject subject = Subject.getInstance();
new BuildEvent(subject);
new BuildRunEvent(subject);

LadderEditorPanel ladderEditorPanel = new LadderEditorPanel(new Dimension((int) (Constants.blockWidth*(Constants.colsNumber+2)),100));
ConsolePanel consolePanel = new ConsolePanel();
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/github/leofds/iotladdereditor/view/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public Menu() {
JMenuItem fileExit = new JMenuItem(Strings.exit());
JMenu menuProject = new JMenu(Strings.project());
JMenuItem projectBuild = new JMenuItem(Strings.build());
JMenuItem projectBuildRun = new JMenuItem(Strings.buildRun());
JMenuItem projectProprerties = new JMenuItem(Strings.properties());
JMenu menuHelp = new JMenu(Strings.help());
helpLang = new JMenu(Strings.language());
Expand Down Expand Up @@ -87,6 +88,7 @@ public Menu() {
fileSaveAs.addActionListener(getFileSaveAsAction());
fileExit.addActionListener(getFileExitAction());
projectBuild.addActionListener(getProjectBuild());
projectBuildRun.addActionListener(getProjectBuildRun());
projectProprerties.addActionListener(getProjectProperties());
helpAbout.addActionListener(getHelpAbout());

Expand Down Expand Up @@ -114,6 +116,10 @@ public Menu() {
projectBuild.getActionMap().put("evtBuild", (AbstractAction) getProjectBuild());
projectBuild.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK));

projectBuildRun.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK), "evtBuildRun");
projectBuildRun.getActionMap().put("evtBuildRun", (AbstractAction) getProjectBuildRun());
projectBuildRun.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK));

helpAbout.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0, true),"evtAbout");
helpAbout.getActionMap().put("evtAbout", (AbstractAction) getHelpAbout());
helpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0, true));
Expand All @@ -128,6 +134,7 @@ public Menu() {
menuFile.addSeparator();
menuFile.add(fileExit);
menuProject.add(projectBuild);
menuProject.add(projectBuildRun);
menuProject.addSeparator();
menuProject.add(projectProprerties);
menuHelp.add(helpLang);
Expand Down Expand Up @@ -215,6 +222,17 @@ public void actionPerformed(ActionEvent e) {
}
};
}

private AbstractAction getProjectBuildRun() {
return new AbstractAction() {
private static final long serialVersionUID = 1L;

@Override
public void actionPerformed(ActionEvent e) {
Subject.getInstance().notifyChange(SubMsg.BUILD_RUN);
}
};
}

private AbstractAction getHelpAbout() {
return new AbstractAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,11 @@ private void save() {
properties.setWifiSsid( textFieldSsid.getText() );
properties.setWifiPassword( textFieldPassword.getText() );
properties.setBrokerAddress( textFieldBrokerAddress.getText() );
properties.setBrokerPort( Integer.parseInt( textFieldBokerPort.getText() ) );
try {
properties.setBrokerPort( Integer.parseInt( textFieldBokerPort.getText() ) );
} catch (Exception e) {
properties.setBrokerPort( 1883 );
}
properties.setMqttClientID( textFieldClientID.getText() );
properties.setMqttUsername( textFieldUserUsername.getText() );
properties.setMqttPassword( textFieldUserPassword.getText() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@
******************************************************************************/
package com.github.leofds.iotladdereditor.view.event;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import com.github.leofds.iotladdereditor.application.Mediator;
import com.github.leofds.iotladdereditor.compiler.Compiler;
import com.github.leofds.iotladdereditor.view.event.Subject.SubMsg;

public class BuildEvent implements Observer {
public class BuildRunEvent implements Observer {

private Subject subject;

public BuildEvent(Subject subject) {
public BuildRunEvent(Subject subject) {
subject.addObserver(this);
this.subject = subject;
}
Expand All @@ -37,12 +40,32 @@ private void build() {
me.clearConsole();
Compiler.build(me.getProject());
}

private void buildRun() {
Mediator me = Mediator.getInstance();
build();
try {
switch(me.getProject().getLadderProgram().getProperties().getCodeOption()) {
case ESP32_ARDUINO_FREERTOS:
Desktop.getDesktop().open(new File("out/plc/plc.ino"));
break;
}
} catch (Exception e) {
e.printStackTrace();
me.outputConsoleMessage(e.getMessage());
}
}

@Override
public void update(Observable o, Object arg) {
if(subject instanceof Subject && arg instanceof SubMsg){
if(((SubMsg) arg) == SubMsg.BUILD) {
switch((SubMsg) arg) {
case BUILD:
build();
break;
case BUILD_RUN:
buildRun();
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Subject extends Observable{

public enum SubMsg{
BUILD,
BUILD_RUN,
};

private static Subject subject;
Expand Down

0 comments on commit 5a54759

Please sign in to comment.