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

added to refrerence to context menu

parent 5c27a7e1
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ import javax.swing.KeyStroke; ...@@ -25,6 +25,7 @@ import javax.swing.KeyStroke;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import edu.mit.blocks.codeblockutil.CScrollPane.ScrollPolicy; import edu.mit.blocks.codeblockutil.CScrollPane.ScrollPolicy;
import edu.mit.blocks.workspace.Workspace;
/** /**
* The CHoverScrollPane is a swing-compatible widget that * The CHoverScrollPane is a swing-compatible widget that
...@@ -52,6 +53,12 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener { ...@@ -52,6 +53,12 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener {
private ScrollPolicy vpolicy; private ScrollPolicy vpolicy;
private ScrollPolicy hpolicy; private ScrollPolicy hpolicy;
private int thumbWidth; private int thumbWidth;
private Workspace workspace = null;
/**workspace zoom settings */
private static final double WORKSPACE_MIN_ZOOM = 0.6;
private static final double WORKSPACE_MAX_ZOOM = 3.0;
private static final double WORKSPACE_ZOOM_STEPSIZE = 0.1;
/** /**
* Constructs a custom CHoverScrollPane with the view port set to "view", * Constructs a custom CHoverScrollPane with the view port set to "view",
...@@ -110,6 +117,51 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener { ...@@ -110,6 +117,51 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener {
ScrollPolicy.HORIZONTAL_BAR_ALWAYS, ScrollPolicy.HORIZONTAL_BAR_ALWAYS,
thumbWidth, thumbColor, trackColor); thumbWidth, thumbColor, trackColor);
} }
//TODO TEST letsgoING
/**
* Constructs a custom CHoverScrollPane with the view port set to "view",
* with correponding vertical and horizontal bar policies (see
* javax.swing.JScrollPane for a description on the use of
* scroll bar policies). The thumb will have a girth equal to
* "thumbWidth" and an interior color of thumbColor. The background
* underneath the thumb will have a color equal to thumbBackground.
*
* @param view - the viewport
* @param verticalPolicy - the vertical scroll bar policy
* @param horizontalPolicy - the horizontal scroll bar policy
* @param thumbWidth - the width of the vertical scroll bar in pixels and
* the height of the horizotntal scroll bar in pixels
* @param thumbColor - the interior color of the thumb
* @param trackColor - the background color under the thumb
* @param workspace - current workspace to zoom with mousewheel
*
* @requires view != null
* @effects Creates a JScrollPane that displays the view component
* in a viewport whose view position can be controlled with
* a pair of scrollbars.
* -If the scrollbar policies are null, then it will use the default
* "ALWAYS" policy. That is, the scroll bars will always show.
* -If the thumbWidth is null or less than 0, then the scroll bars
* will not show.
* -If thumbColor is null, then thumbs will default on Color.black.
* -If trackColor is null, then the default grayed-out transparent color
* will be used as the background color.
*/
public CHoverScrollPane(
JComponent view,
ScrollPolicy verticalPolicy,
ScrollPolicy horizontalPolicy,
int thumbWidth,
Color thumbColor,
Color trackColor, Workspace workspace) {
this(view, verticalPolicy,
horizontalPolicy,
thumbWidth, thumbColor, trackColor);
this.workspace = workspace;
}
/** /**
* Constructs a custom CHoverScrollPane with the view port set to "view", * Constructs a custom CHoverScrollPane with the view port set to "view",
...@@ -277,6 +329,10 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener { ...@@ -277,6 +329,10 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener {
this.SCROLLINGUNIT = x; this.SCROLLINGUNIT = x;
this.verticalbar.setScrollingUnit(x); this.verticalbar.setScrollingUnit(x);
} }
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
/** /**
* @overrides CScrollPane.mouseWheelMoved * @overrides CScrollPane.mouseWheelMoved
...@@ -295,6 +351,23 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener { ...@@ -295,6 +351,23 @@ public class CHoverScrollPane extends CScrollPane implements KeyListener {
scrollviewport.getHorizontalScrollBar().getModel().getValue() scrollviewport.getHorizontalScrollBar().getModel().getValue()
+ e.getUnitsToScroll() * e.getScrollAmount() * SCROLLINGUNIT); + e.getUnitsToScroll() * e.getScrollAmount() * SCROLLINGUNIT);
horizontalbar.repaint(); horizontalbar.repaint();
}
//TODO: TEST ZOOM
else if(e.isControlDown()) {
if(workspace != null) {
if(e.isControlDown()) {
if(e.getUnitsToScroll() > 0) {
if(workspace.getCurrentWorkspaceZoom() > WORKSPACE_MIN_ZOOM) {
workspace.setWorkspaceZoom(workspace.getCurrentWorkspaceZoom()-WORKSPACE_ZOOM_STEPSIZE);
}
}
else {
if(workspace.getCurrentWorkspaceZoom() < WORKSPACE_MAX_ZOOM) {
workspace.setWorkspaceZoom(workspace.getCurrentWorkspaceZoom()+WORKSPACE_ZOOM_STEPSIZE);
}
}
}
}
} else { } else {
scrollviewport.getVerticalScrollBar().getModel().setValue( scrollviewport.getVerticalScrollBar().getModel().setValue(
scrollviewport.getVerticalScrollBar().getModel().getValue() scrollviewport.getVerticalScrollBar().getModel().getValue()
......
...@@ -7,7 +7,6 @@ import java.awt.event.MouseWheelListener; ...@@ -7,7 +7,6 @@ import java.awt.event.MouseWheelListener;
import javax.swing.BoundedRangeModel; import javax.swing.BoundedRangeModel;
import javax.swing.JLayeredPane; import javax.swing.JLayeredPane;
/** /**
* The CScrollPane is a swing-compatible widget that * The CScrollPane is a swing-compatible widget that
* allows clients of this CScrollPane to control the * allows clients of this CScrollPane to control the
...@@ -69,7 +68,6 @@ public abstract class CScrollPane extends JLayeredPane implements MouseWheelList ...@@ -69,7 +68,6 @@ public abstract class CScrollPane extends JLayeredPane implements MouseWheelList
* @effects set this.scrollingunit to x * @effects set this.scrollingunit to x
*/ */
abstract public void setScrollingUnit(int x); abstract public void setScrollingUnit(int x);
/** /**
* MouseWheelListener: Should move the viewport by same amount of wheel scroll * MouseWheelListener: Should move the viewport by same amount of wheel scroll
*/ */
......
...@@ -50,7 +50,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento { ...@@ -50,7 +50,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento {
/** serial version ID */ /** serial version ID */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final long serialVersionUID = 7458721329L; private static final long serialVersionUID = 7458721329L;
/** the collection of pages that this BlockCanvas stores */ /** the collection of pages that this BlockCanvas stores */
private List<Page> pages = new ArrayList<Page>(); private List<Page> pages = new ArrayList<Page>();
/** the collection of PageDivideres that this BlockCanvas stores */ /** the collection of PageDivideres that this BlockCanvas stores */
...@@ -63,6 +63,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento { ...@@ -63,6 +63,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento {
private final Workspace workspace; private final Workspace workspace;
private boolean collapsible = false; private boolean collapsible = false;
////////////////////////////// //////////////////////////////
//Constructor/Destructor // //Constructor/Destructor //
...@@ -77,7 +78,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento { ...@@ -77,7 +78,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento {
this.scrollPane = new CHoverScrollPane(canvas, this.scrollPane = new CHoverScrollPane(canvas,
ScrollPolicy.VERTICAL_BAR_ALWAYS, ScrollPolicy.VERTICAL_BAR_ALWAYS,
ScrollPolicy.HORIZONTAL_BAR_ALWAYS, ScrollPolicy.HORIZONTAL_BAR_ALWAYS,
18, CGraphite.blue, null); 18, CGraphite.blue, null, workspace);
scrollPane.setScrollingUnit(5); scrollPane.setScrollingUnit(5);
canvas.setLayout(null); canvas.setLayout(null);
canvas.setBackground(Color.gray); canvas.setBackground(Color.gray);
...@@ -566,6 +567,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento { ...@@ -566,6 +567,7 @@ public class BlockCanvas implements PageChangeListener, ISupportMemento {
private static final long serialVersionUID = 438974092314L; private static final long serialVersionUID = 438974092314L;
private Point p; private Point p;
public Canvas() { public Canvas() {
super(); super();
this.p = null; this.p = null;
......
package edu.mit.blocks.workspace; package edu.mit.blocks.workspace;
import java.awt.BorderLayout;
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;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
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;
/** /**
...@@ -31,10 +53,12 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -31,10 +53,12 @@ public class ContextMenu extends PopupMenu implements ActionListener {
private static boolean removeCommentMenuInit = false; private static boolean removeCommentMenuInit = false;
private final static String CLONE_BLOCK = "CLONE"; //heqichen private final static String CLONE_BLOCK = "CLONE"; //heqichen
private final static String CLONE_BLOCKS = "CLONEALL"; //letsgoING private final static String CLONE_BLOCKS = "CLONEALL"; //letsgoING
private static MenuItem cloneItem1 = null; //heqichen private final static String OPEN_REFERENCE = "OPEN_REFERENCE";
private static MenuItem cloneItem2 = null; //heqichen private static MenuItem cloneItem1 = null; //letsgoING
private static MenuItem cloneAllItem1 = null; //heqichen private static MenuItem cloneItem2 = null; //letsgoING
private static MenuItem cloneAllItem2 = null; //heqichen private static MenuItem cloneAllItem1 = null; //letsgoING
private static MenuItem cloneAllItem2 = null; //letsgoING
private static MenuItem refrenceItem = null; //letsgoING
//context menu for canvas plus //context menu for canvas plus
//menu items for canvas context menu //menu items for canvas context menu
private static ContextMenu canvasMenu = new ContextMenu(); private static ContextMenu canvasMenu = new ContextMenu();
...@@ -70,6 +94,11 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -70,6 +94,11 @@ public class ContextMenu extends PopupMenu implements ActionListener {
cloneAllItem1.addActionListener(rndBlockMenu); cloneAllItem1.addActionListener(rndBlockMenu);
addCommentMenu.add(cloneAllItem1); addCommentMenu.add(cloneAllItem1);
refrenceItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.reference"));
refrenceItem.setActionCommand(OPEN_REFERENCE);
refrenceItem.addActionListener(rndBlockMenu);
addCommentMenu.add(refrenceItem);
addCommentMenuInit = true; addCommentMenuInit = true;
} }
...@@ -97,6 +126,11 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -97,6 +126,11 @@ public class ContextMenu extends PopupMenu implements ActionListener {
cloneAllItem2.setActionCommand(CLONE_BLOCKS); cloneAllItem2.setActionCommand(CLONE_BLOCKS);
cloneAllItem2.addActionListener(rndBlockMenu); cloneAllItem2.addActionListener(rndBlockMenu);
removeCommentMenu.add(cloneAllItem2); removeCommentMenu.add(cloneAllItem2);
refrenceItem = new MenuItem(uiMessageBundle.getString("ardublock.ui.reference"));
refrenceItem.setActionCommand(OPEN_REFERENCE);
refrenceItem.addActionListener(rndBlockMenu);
removeCommentMenu.add(refrenceItem);
removeCommentMenuInit = true; removeCommentMenuInit = true;
} }
...@@ -148,6 +182,69 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -148,6 +182,69 @@ public class ContextMenu extends PopupMenu implements ActionListener {
} }
return null; return null;
} }
/**
* opens reference-file (html) for active block
* in standard browser
* @param blockGenusName = genus name of the active block
* added by letsgoING
*/
private void createReferenceWindow(String blockGenusName) {
//TODO: Test with reference files
String resourcePath = "/com/ardublock/reference/"+blockGenusName+".html";
System.out.println("TEST | Active Block: "+blockGenusName);
//TODO: call 404.html when there is no reference-file for active block
try {
Desktop.getDesktop().browse(getClass().getResource(resourcePath).toURI());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
/*
//get html path
String referenceText = "Block not found!";
Path path = null;
try {
path = Paths.get(getClass().getResource(resourcePath).toURI());
} catch (URISyntaxException e1 ) {
// TODO Auto-generated catch block
//e1.printStackTrace();
} catch (NullPointerException ne) {
//ne.printStackTrace();
}
if(path != null) {
try {
referenceText = new String(Files.readAllBytes(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//OPTION JFRAME
Frame frame = new JFrame("Block Reference");
JLabel label = new JLabel(referenceText);
frame.add(label);
frame.setLocationRelativeTo( null );
frame.pack();
frame.setVisible(true);
//OPTION DIALOG
JOptionPane.showMessageDialog(
null,
referenceText,
"Block-Referenz - "+((RenderableBlock) activeComponent).getBlock().getGenusName(), JOptionPane.INFORMATION_MESSAGE, null);
*/
return;
}
public void actionPerformed(ActionEvent a) { public void actionPerformed(ActionEvent a) {
if (a.getActionCommand() == ARRANGE_ALL_BLOCKS) { if (a.getActionCommand() == ARRANGE_ALL_BLOCKS) {
...@@ -177,5 +274,11 @@ public class ContextMenu extends PopupMenu implements ActionListener { ...@@ -177,5 +274,11 @@ public class ContextMenu extends PopupMenu implements ActionListener {
((RenderableBlock) activeComponent).cloneMe(false); ((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());
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment