Skip to content

Commit

Permalink
Merge pull request #10 from gregcorbett/erase_button
Browse files Browse the repository at this point in the history
Add an 'Erase Arduino Program' Button
  • Loading branch information
gregcorbett committed Nov 8, 2018
2 parents 62857d3 + c72ed18 commit aa54d19
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/ardublock/ui/OpenblocksFrame.java
Expand Up @@ -32,6 +32,7 @@
import com.ardublock.ui.listener.OpenblocksFrameListener;
import com.ardublock.ui.listener.SaveAsButtonListener;
import com.ardublock.ui.listener.SaveButtonListener;
import com.ardublock.ui.listener.EraseButtonListener;

import edu.mit.blocks.controller.WorkspaceController;
import edu.mit.blocks.workspace.Workspace;
Expand Down Expand Up @@ -168,8 +169,13 @@ public void actionPerformed(ActionEvent e) {
}
}
});

JButton eraseProgramButton = new JButton(uiMessageBundle.getString("ardublock.ui.erase"));
eraseProgramButton.addActionListener(new EraseButtonListener(this, context));

JLabel versionLabel = new JLabel("v " + uiMessageBundle.getString("ardublock.ui.version"));

bottomPanel.add(eraseProgramButton);
bottomPanel.add(saveImageButton);
bottomPanel.add(websiteButton);
bottomPanel.add(versionLabel);
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/ardublock/ui/listener/EraseButtonListener.java
@@ -0,0 +1,50 @@
package com.ardublock.ui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;

import javax.swing.JFrame;

import com.ardublock.core.Context;
import com.ardublock.translator.AutoFormat;

import edu.mit.blocks.workspace.Workspace;

public class EraseButtonListener implements ActionListener
{
private JFrame parentFrame;
private Context context;
private Workspace workspace;
private ResourceBundle uiMessageBundle;

public EraseButtonListener(JFrame frame, Context context)
{
this.parentFrame = frame;
this.context = context;
workspace = context.getWorkspaceController().getWorkspace();
uiMessageBundle = ResourceBundle.getBundle("com/ardublock/block/ardublock");
}

public void actionPerformed(ActionEvent e)
{
AutoFormat formatter = new AutoFormat();
String codeOut = "void setup() {\n"
+ "// put your setup code here, to run once:\n\n"
+ "}\n\n"
+ "void loop() {\n"
+ "// put your main code here, to run repeatedly:\n\n"
+ "}";

if (context.isNeedAutoFormat)
{
codeOut = formatter.format(codeOut);
}

if (!context.isInArduino())
{
System.out.println(codeOut);
}
context.didGenerate(codeOut);
}
}
Expand Up @@ -430,6 +430,7 @@ ardublock.ui.save=Save
ardublock.ui.saveAs=Save As
ardublock.ui.load=Open
ardublock.ui.upload=Upload to Arduino
ardublock.ui.erase=Erase Arduino Program
ardublock.ui.clone=Clone
ardublock.ui.add_comment=Add Comment
ardublock.ui.delete_comment=Delete Comment
Expand Down

0 comments on commit aa54d19

Please sign in to comment.