Commit c28b398e authored by Anian Bühler's avatar Anian Bühler
Browse files

added new autoLabel-rules

parent 388cbdd3
......@@ -243,11 +243,13 @@ public class BlockLabel implements MouseListener, MouseMotionListener, KeyListen
//added by letsgoING
//add local-Tag to local variables
//TODO: add other variable types?
generateLabelText(text);
/*
if(workspace.getEnv().getBlock(blockID).getGenusName().startsWith("local") && !(text.toUpperCase().startsWith("LO") || text.toUpperCase().startsWith("L_"))) {
workspace.getEnv().getBlock(blockID).setBlockLabel("loc_"+text);
}else {
workspace.getEnv().getBlock(blockID).setBlockLabel(text);
}
}*/
}
BlockConnector plug = workspace.getEnv().getBlock(blockID).getPlug();
......@@ -272,6 +274,45 @@ public class BlockLabel implements MouseListener, MouseMotionListener, KeyListen
}
}
}
protected void generateLabelText(String text) {
if(workspace.getEnv().getBlock(blockID).getGenusName().startsWith("local") && !(text.toUpperCase().startsWith("LO") || text.toUpperCase().startsWith("L_"))) {
workspace.getEnv().getBlock(blockID).setBlockLabel("loc_"+text);
}else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().startsWith("PSN")){
if(text.contains(".")) {
text = text.substring(0, text.indexOf("."));
}
if(text.contains(" ")) {
if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("CLIENT") || workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("BROKER")) {
text = text.substring(text.lastIndexOf(" ")+1, text.length());
}else {
text = text.substring(0, text.indexOf(" "));
}
}
if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("CLIENT")){
text = "Client "+text;
} else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("BROKER")){
text = "Broker "+ text;
} else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("HANDLE")){
text = text + " handleNetwork";
} else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("DATA_TO_SEND")){
text = text + " isDataToSend";
} else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("PUBLISH")){
text = text + " publish";
} else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("UNSUBSCRIBE")){
text = text + " unsubscribe";
} else if(workspace.getEnv().getBlock(blockID).getGenusName().toUpperCase().contains("SUBSCRIBE")){
text = text + " susbcribe";
}
workspace.getEnv().getBlock(blockID).setBlockLabel(text);
} else {
workspace.getEnv().getBlock(blockID).setBlockLabel(text);
}
}
protected void genusChanged(String genus) {
if (widget.hasSiblings()) {
......
package edu.mit.blocks.workspace;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Frame;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.event.ActionEvent;
......@@ -13,27 +11,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ResourceBundle;
import javax.print.DocFlavor.URL;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.html.HTMLEditorKit;
import edu.mit.blocks.renderable.RenderableBlock;
/**
......@@ -202,8 +183,15 @@ public class ContextMenu extends PopupMenu implements ActionListener {
String htmlResource ="/com/ardublock/reference/"+blockGenusName+".html";
String imageResource ="/com/ardublock/reference/"+blockGenusName+".png";
String fileNotFoundResource = "/com/ardublock/reference/404.png";
String tempPath = "";
//TODO: REMOVE PRINT AFTER BLOCKREFERENCE IS DONE
System.out.println("REMOVE PRINT in ContextMenue.java after BlockRef is done");
System.out.println("Blockname HTML: "+ blockGenusName + ".html");
System.out.println("Blockname Bild: "+ blockGenusName + ".png");
//get current .jar path for temp files
try {
tempPath = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8")).getParentFile().getPath();
......@@ -215,32 +203,40 @@ public class ContextMenu extends PopupMenu implements ActionListener {
//copy html to tmp file
try {
InputStream input = getClass().getResourceAsStream(htmlResource);
htmlFile = new File(tempPath +"/"+ blockGenusName + ".html");
OutputStream out = new FileOutputStream(htmlFile);
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.close();
htmlFile.deleteOnExit();
if(input != null) {
htmlFile = new File(tempPath +"/"+ blockGenusName + ".html");
OutputStream out = new FileOutputStream(htmlFile);
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.close();
htmlFile.deleteOnExit();
} else {
//TODO: use resources
System.out.println("Sorry, block was not found in reference.");
}
} catch (IOException ex) {
ex.printStackTrace();
}
//copy image to tmp file
try {
InputStream input = getClass().getResourceAsStream(imageResource);
imageFile = new File(tempPath +"/"+ blockGenusName+".png");
OutputStream out = new FileOutputStream(imageFile);
int read;
byte[] bytes = new byte[10000];
while ((read = input.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.close();
imageFile.deleteOnExit();
if(input != null) {
imageFile = new File(tempPath +"/"+ blockGenusName+".png");
OutputStream out = new FileOutputStream(imageFile);
int read;
byte[] bytes = new byte[10000];
while ((read = input.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.close();
imageFile.deleteOnExit();
} else {
//TODO: use resources
System.out.println("Sorry, image was not found in reference.");
}
} catch (IOException ex) {
ex.printStackTrace();
}
......@@ -254,6 +250,9 @@ public class ContextMenu extends PopupMenu implements ActionListener {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NullPointerException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
return;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment