Skip to content
Snippets Groups Projects
Commit c28b398e authored by Anian Bühler's avatar Anian Bühler
Browse files

added new autoLabel-rules

parent 388cbdd3
Branches
No related tags found
No related merge requests found
...@@ -243,11 +243,13 @@ public class BlockLabel implements MouseListener, MouseMotionListener, KeyListen ...@@ -243,11 +243,13 @@ public class BlockLabel implements MouseListener, MouseMotionListener, KeyListen
//added by letsgoING //added by letsgoING
//add local-Tag to local variables //add local-Tag to local variables
//TODO: add other variable types? //TODO: add other variable types?
generateLabelText(text);
/*
if(workspace.getEnv().getBlock(blockID).getGenusName().startsWith("local") && !(text.toUpperCase().startsWith("LO") || text.toUpperCase().startsWith("L_"))) { if(workspace.getEnv().getBlock(blockID).getGenusName().startsWith("local") && !(text.toUpperCase().startsWith("LO") || text.toUpperCase().startsWith("L_"))) {
workspace.getEnv().getBlock(blockID).setBlockLabel("loc_"+text); workspace.getEnv().getBlock(blockID).setBlockLabel("loc_"+text);
}else { }else {
workspace.getEnv().getBlock(blockID).setBlockLabel(text); workspace.getEnv().getBlock(blockID).setBlockLabel(text);
} }*/
} }
BlockConnector plug = workspace.getEnv().getBlock(blockID).getPlug(); BlockConnector plug = workspace.getEnv().getBlock(blockID).getPlug();
...@@ -273,6 +275,45 @@ public class BlockLabel implements MouseListener, MouseMotionListener, KeyListen ...@@ -273,6 +275,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) { protected void genusChanged(String genus) {
if (widget.hasSiblings()) { if (widget.hasSiblings()) {
Block oldBlock = workspace.getEnv().getBlock(blockID); Block oldBlock = workspace.getEnv().getBlock(blockID);
......
package edu.mit.blocks.workspace; package edu.mit.blocks.workspace;
import java.awt.BorderLayout;
import java.awt.Desktop; import java.awt.Desktop;
import java.awt.Frame;
import java.awt.MenuItem; import java.awt.MenuItem;
import java.awt.PopupMenu; import java.awt.PopupMenu;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
...@@ -13,27 +11,10 @@ import java.io.IOException; ...@@ -13,27 +11,10 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLDecoder; 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 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; import edu.mit.blocks.renderable.RenderableBlock;
/** /**
...@@ -202,8 +183,15 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -202,8 +183,15 @@ public class ContextMenu extends PopupMenu implements ActionListener {
String htmlResource ="/com/ardublock/reference/"+blockGenusName+".html"; String htmlResource ="/com/ardublock/reference/"+blockGenusName+".html";
String imageResource ="/com/ardublock/reference/"+blockGenusName+".png"; String imageResource ="/com/ardublock/reference/"+blockGenusName+".png";
String fileNotFoundResource = "/com/ardublock/reference/404.png";
String tempPath = ""; 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 //get current .jar path for temp files
try { try {
tempPath = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8")).getParentFile().getPath(); tempPath = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8")).getParentFile().getPath();
...@@ -215,6 +203,7 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -215,6 +203,7 @@ public class ContextMenu extends PopupMenu implements ActionListener {
//copy html to tmp file //copy html to tmp file
try { try {
InputStream input = getClass().getResourceAsStream(htmlResource); InputStream input = getClass().getResourceAsStream(htmlResource);
if(input != null) {
htmlFile = new File(tempPath +"/"+ blockGenusName + ".html"); htmlFile = new File(tempPath +"/"+ blockGenusName + ".html");
OutputStream out = new FileOutputStream(htmlFile); OutputStream out = new FileOutputStream(htmlFile);
int read; int read;
...@@ -224,13 +213,17 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -224,13 +213,17 @@ public class ContextMenu extends PopupMenu implements ActionListener {
} }
out.close(); out.close();
htmlFile.deleteOnExit(); htmlFile.deleteOnExit();
} else {
//TODO: use resources
System.out.println("Sorry, block was not found in reference.");
}
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
//copy image to tmp file //copy image to tmp file
try { try {
InputStream input = getClass().getResourceAsStream(imageResource); InputStream input = getClass().getResourceAsStream(imageResource);
if(input != null) {
imageFile = new File(tempPath +"/"+ blockGenusName+".png"); imageFile = new File(tempPath +"/"+ blockGenusName+".png");
OutputStream out = new FileOutputStream(imageFile); OutputStream out = new FileOutputStream(imageFile);
int read; int read;
...@@ -240,7 +233,10 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -240,7 +233,10 @@ public class ContextMenu extends PopupMenu implements ActionListener {
} }
out.close(); out.close();
imageFile.deleteOnExit(); imageFile.deleteOnExit();
} else {
//TODO: use resources
System.out.println("Sorry, image was not found in reference.");
}
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
...@@ -254,6 +250,9 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -254,6 +250,9 @@ public class ContextMenu extends PopupMenu implements ActionListener {
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} catch (NullPointerException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
} }
} }
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment