diff --git a/src/main/java/edu/mit/blocks/workspace/ContextMenu.java b/src/main/java/edu/mit/blocks/workspace/ContextMenu.java index 0e3ef73a6558921c185a67a324193ee16cf6ac47..49049dce870f4f0d5cc5fe410dfcc7bbe2a8bf2e 100644 --- a/src/main/java/edu/mit/blocks/workspace/ContextMenu.java +++ b/src/main/java/edu/mit/blocks/workspace/ContextMenu.java @@ -81,11 +81,6 @@ public class ContextMenu extends PopupMenu implements ActionListener { cloneAllItem1.addActionListener(rndBlockMenu); addCommentMenu.add(cloneAllItem1); - refrenceItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.reference")); - refrenceItem.setActionCommand(OPEN_REFERENCE); - refrenceItem.addActionListener(rndBlockMenu); - addCommentMenu.add(refrenceItem); - addCommentMenuInit = true; } @@ -113,11 +108,6 @@ public class ContextMenu extends PopupMenu implements ActionListener { cloneAllItem2.setActionCommand(CLONE_BLOCKS); cloneAllItem2.addActionListener(rndBlockMenu); removeCommentMenu.add(cloneAllItem2); - - refrenceItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.reference")); - refrenceItem.setActionCommand(OPEN_REFERENCE); - refrenceItem.addActionListener(rndBlockMenu); - removeCommentMenu.add(refrenceItem); removeCommentMenuInit = true; } @@ -170,93 +160,6 @@ public class ContextMenu extends PopupMenu implements ActionListener { return null; } - /** - * opens reference-file (html) for active block - * in standard browser - * @param blockGenusName = genus name of the active block - * added by letsgoING - * @throws URISyntaxException - */ - private void createReferenceWindow(String blockGenusName) { - File htmlFile = null; - File imageFile = null; - - 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(); - } catch (UnsupportedEncodingException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - //copy html to tmp file - try { - InputStream input = getClass().getResourceAsStream(htmlResource); - 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); - 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(); - } - - //open file in standard browser - if (htmlFile != null && !htmlFile.exists() && imageFile != null && !imageFile.exists()) { - throw new RuntimeException("Error: File " + htmlFile + "or " + imageFile + " not found!"); - }else { - try { - Desktop.getDesktop().browse(htmlFile.toURI()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NullPointerException e) { - // TODO Auto-generated catch block - //e.printStackTrace(); - } - } - return; - } public void actionPerformed(ActionEvent a) { if (a.getActionCommand() == ARRANGE_ALL_BLOCKS) { @@ -286,11 +189,5 @@ public class ContextMenu extends PopupMenu implements ActionListener { ((RenderableBlock) activeComponent).cloneMe(false); } } - else if (a.getActionCommand() == OPEN_REFERENCE) { - //notify the renderableblock componenet that lauched the conetxt menu - if (activeComponent != null && activeComponent instanceof RenderableBlock) { - createReferenceWindow(((RenderableBlock) activeComponent).getBlock().getGenusName()); - } - } } }