diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..30d8837
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/actions/AddDataDisplayBoxAction.java b/src/actions/AddDataDisplayBoxAction.java
index ab99979..c058858 100644
--- a/src/actions/AddDataDisplayBoxAction.java
+++ b/src/actions/AddDataDisplayBoxAction.java
@@ -6,12 +6,18 @@
import paintcomponents.data.DataDisplayPaintComponent;
import ui.PaintPanel;
+/**
+ * This action adds a data display box (Data > Display > Add)
+ * @author chenzb
+ *
+ */
public class AddDataDisplayBoxAction extends PaintAction {
public AddDataDisplayBoxAction(PaintPanel panel) {
super(panel);
}
+
@Override
public boolean canPerformAction() {
return true;
diff --git a/src/actions/AddDataInputBoxAction.java b/src/actions/AddDataInputBoxAction.java
index 0b3f5a5..f4c3662 100644
--- a/src/actions/AddDataInputBoxAction.java
+++ b/src/actions/AddDataInputBoxAction.java
@@ -6,6 +6,11 @@
import paintcomponents.data.DataInputTextfieldPaintComponent;
import ui.PaintPanel;
+/**
+ * Add Data Input Box Action
+ * @author chenzb
+ *
+ */
public class AddDataInputBoxAction extends PaintAction {
public AddDataInputBoxAction(PaintPanel panel) {
diff --git a/src/actions/AddHaskellComponent.java b/src/actions/AddHaskellComponent.java
index cdd6286..41a2242 100644
--- a/src/actions/AddHaskellComponent.java
+++ b/src/actions/AddHaskellComponent.java
@@ -6,6 +6,11 @@
import paintcomponents.haskell.HaskellExpressionPaintComponent;
import ui.PaintPanel;
+/**
+ * Add a haskell expression component
+ * @author chenzb
+ *
+ */
public class AddHaskellComponent extends PaintAction {
public AddHaskellComponent(PaintPanel panel) {
diff --git a/src/actions/AddHaskellEvaluatorComponentAction.java b/src/actions/AddHaskellEvaluatorComponentAction.java
index 5206c08..13709fc 100644
--- a/src/actions/AddHaskellEvaluatorComponentAction.java
+++ b/src/actions/AddHaskellEvaluatorComponentAction.java
@@ -4,6 +4,11 @@
import paintcomponents.haskell.EvaluateHaskellPaintComponent;
import ui.PaintPanel;
+/**
+ * Haskell expression evaluator action
+ * @author chenzb
+ *
+ */
public class AddHaskellEvaluatorComponentAction extends PaintAction {
public AddHaskellEvaluatorComponentAction(PaintPanel panel) {
diff --git a/src/actions/AddLazyJavaClassAction.java b/src/actions/AddLazyJavaClassAction.java
index e545512..585604a 100644
--- a/src/actions/AddLazyJavaClassAction.java
+++ b/src/actions/AddLazyJavaClassAction.java
@@ -13,6 +13,11 @@
import ui.helper.ClassSearchFrame;
import ui.helper.ClassSearchFrameDelegateInterface;
+/**
+ * Add a lazily evaluated java class component
+ * @author chenzb
+ *
+ */
public class AddLazyJavaClassAction extends PaintAction {
public AddLazyJavaClassAction(PaintPanel panel) {
diff --git a/src/actions/AddLazyJavaConstructorAction.java b/src/actions/AddLazyJavaConstructorAction.java
index 84cc83e..a7c8d19 100644
--- a/src/actions/AddLazyJavaConstructorAction.java
+++ b/src/actions/AddLazyJavaConstructorAction.java
@@ -11,6 +11,11 @@
import paintcomponents.java.lazy.ClassPaintComponent;
import ui.PaintPanel;
+/**
+ * Add LazyJavaConstructorAction
+ * @author chenzb
+ *
+ */
public class AddLazyJavaConstructorAction extends PaintAction {
public AddLazyJavaConstructorAction(PaintPanel panel) {
diff --git a/src/actions/AddLazyJavaFieldsComponentAction.java b/src/actions/AddLazyJavaFieldsComponentAction.java
index 0f67cdc..53a6592 100644
--- a/src/actions/AddLazyJavaFieldsComponentAction.java
+++ b/src/actions/AddLazyJavaFieldsComponentAction.java
@@ -7,6 +7,11 @@
import paintcomponents.java.lazy.FieldsPaintComponent;
import ui.PaintPanel;
+/**
+ * Add a Java Fileds Component
+ * @author chenzb
+ *
+ */
public class AddLazyJavaFieldsComponentAction extends PaintAction {
public AddLazyJavaFieldsComponentAction(PaintPanel panel) {
diff --git a/src/actions/RemovePaintComponent.java b/src/actions/RemovePaintComponent.java
index 8ca868d..3841db4 100644
--- a/src/actions/RemovePaintComponent.java
+++ b/src/actions/RemovePaintComponent.java
@@ -29,6 +29,8 @@ public void performAction() {
for ( PaintComponent comp: panel.getSelectTool().getSelectedComponents()) {
comps.add(comp);
}
+
+
for( PaintComponent comp: comps ) comp.remove(panel);
//push action to the manager
@@ -45,6 +47,7 @@ public void redoAction() {
comp.remove(panel);
}
});
+
panel.repaint();
}
@@ -52,5 +55,8 @@ public void redoAction() {
public String locationString() {
// TODO Auto-generated method stub
return ActionsMenuBarTitles.Data().Remove().toString(); }
-
+
+ public String toString() {
+ return "Remove";
+ }
}
diff --git a/src/actions/edit/undoredo/SharedUndoRedoActionManager.java b/src/actions/edit/undoredo/SharedUndoRedoActionManager.java
index baceeae..bd59ce5 100644
--- a/src/actions/edit/undoredo/SharedUndoRedoActionManager.java
+++ b/src/actions/edit/undoredo/SharedUndoRedoActionManager.java
@@ -3,6 +3,13 @@
import java.util.Stack;
/**
+ *
+ * A manager for undo and redo in the program.
+ * Use getSharedInstance to retrieve such an instance.
+ *
+ * An undoable action should push an instance of the interface to this manger
+ * via pushUndoableAction method. Edit /Undo /Redo action should actively delgate this
+ * manager for the availability of undo and redoables.
*
* @author cs12wagn
* add to stack
diff --git a/src/actions/edit/undoredo/UndoRedoableInterface.java b/src/actions/edit/undoredo/UndoRedoableInterface.java
index fa6cea6..575fd36 100644
--- a/src/actions/edit/undoredo/UndoRedoableInterface.java
+++ b/src/actions/edit/undoredo/UndoRedoableInterface.java
@@ -1,5 +1,12 @@
package actions.edit.undoredo;
+/**
+ * An interface for implementing undo and redos.
+ *
+ * Each undoable action should push an instance of this interface to the undo redo manger.
+ * @author chenzb
+ *
+ */
public interface UndoRedoableInterface {
public void undoAction();
public void redoAction();
diff --git a/src/actions/menu/ActionsMenuBar.java b/src/actions/menu/ActionsMenuBar.java
index c7b4f9c..3b0dac6 100644
--- a/src/actions/menu/ActionsMenuBar.java
+++ b/src/actions/menu/ActionsMenuBar.java
@@ -29,6 +29,7 @@
import actions.PaintAction;
import actions.RemovePaintComponent;
import actions.UpdateDataDisplayBoxAction;
+import actions.singleinstanceoperations.SetLineSegmentWidthOperation;
import actions.singleinstanceoperations.SetPointSizeOperation;
import actions.singleinstanceoperations.UpdateFontSizeOperation;
import actions.ZoomInAction;
@@ -36,6 +37,13 @@
import actions.ZoomInAction;
import actions.ZoomOutAction;
+/**
+ * The main menubar.
+ *
+ * Individual actions should register itself in the constructor of this method.
+ * @author chenzb
+ *
+ */
public class ActionsMenuBar extends JMenuBar implements SelectionToolListener{
public ActionsMenuBar(PaintPanel panel){
@@ -78,6 +86,7 @@ public ActionsMenuBar(PaintPanel panel){
//edit
addAction(new UpdateFontSizeOperation(panel));
addAction(new SetPointSizeOperation(panel));
+ addAction(new SetLineSegmentWidthOperation(panel));
}
diff --git a/src/actions/menu/ActionsMenuBarTitles.java b/src/actions/menu/ActionsMenuBarTitles.java
index 390ed84..bee6950 100644
--- a/src/actions/menu/ActionsMenuBarTitles.java
+++ b/src/actions/menu/ActionsMenuBarTitles.java
@@ -1,5 +1,18 @@
package actions.menu;
+/**
+ * The menubar titles.
+ *
+ * A paint action's get location should use this class for creating menubar titles.
+ *
+ * For example ActionsMenuBarTitles.Edit().Undo().toString();
+ *
+ *
+ *
+ *
+ * @author chenzb
+ *
+ */
public class ActionsMenuBarTitles {
public String pending;
@@ -132,6 +145,11 @@ public ActionsMenuBarTitles Zoom_In() {
append("Zoom In");
return this;
}
+
+ public ActionsMenuBarTitles Line_Segment_Width() {
+ append("Line Segment Width...");
+ return this;
+ }
public ActionsMenuBarTitles Zoom_Out() {
append("Zoom Out");
diff --git a/src/actions/menu/PaintActionMenuItem.java b/src/actions/menu/PaintActionMenuItem.java
index 3b7e4b1..3d87048 100644
--- a/src/actions/menu/PaintActionMenuItem.java
+++ b/src/actions/menu/PaintActionMenuItem.java
@@ -4,6 +4,14 @@
import actions.PaintAction;
+/**
+ * An action menu item is a JMenuItme associated with an action.
+ *
+ * The associated paint action is invoked on a mouse click.
+ *
+ * @author chenzb
+ *
+ */
public class PaintActionMenuItem extends JMenuItem{
@@ -13,9 +21,10 @@ public class PaintActionMenuItem extends JMenuItem{
public PaintActionMenuItem(PaintAction associatedAction, ActionsMenuBar actionsMenuBar) {
this.setAssociatedAction(associatedAction);
this.actionsMenuBar = actionsMenuBar;
-
}
-
+ public PaintActionMenuItem(PaintAction associatedAction) {
+ this.setAssociatedAction(associatedAction);
+ }
public PaintAction getAssociatedAction() {
return associatedAction;
}
@@ -27,7 +36,7 @@ public void setAssociatedAction(PaintAction associatedAction) {
public void performAction() {
associatedAction.performAction();
//update menu bar status
- actionsMenuBar.updateEnableStatusForAllMenuItems();
-
+ if(actionsMenuBar != null)
+ actionsMenuBar.updateEnableStatusForAllMenuItems();
}
}
diff --git a/src/actions/singleinstanceoperations/SetLineSegmentWidthOperation.java b/src/actions/singleinstanceoperations/SetLineSegmentWidthOperation.java
new file mode 100644
index 0000000..6884cd2
--- /dev/null
+++ b/src/actions/singleinstanceoperations/SetLineSegmentWidthOperation.java
@@ -0,0 +1,45 @@
+package actions.singleinstanceoperations;
+
+import javax.sound.sampled.Line;
+
+import actions.menu.ActionsMenuBarTitles;
+import paintcomponents.LineSegment;
+import ui.PaintPanel;
+import ui.general.InputManager;
+import ui.general.InputManagerDelegate;
+
+/**
+ * A single instance operation responsible for setting the line width
+ * @author chenzb
+ *
+ */
+public class SetLineSegmentWidthOperation extends SingleInstanceOperation {
+
+ public SetLineSegmentWidthOperation(PaintPanel panel) {
+ super(panel);
+ }
+
+
+ @Override
+ public String locationString() {
+ return ActionsMenuBarTitles.Edit().Line_Segment_Width().toString();
+ }
+
+ @Override
+ protected void performActionOnInstance(LineSegment instance) {
+ InputManager.sharedInstance().askForDouble(panel, new InputManagerDelegate() {
+
+ @Override
+ public void didFinishInput(Double input) {
+ instance.setStrokeWidth(input);
+ }
+ });
+
+ }
+
+ @Override
+ protected Class getGenericClassType() {
+ return LineSegment.class;
+ }
+
+}
diff --git a/src/actions/singleinstanceoperations/SetPointSizeOperation.java b/src/actions/singleinstanceoperations/SetPointSizeOperation.java
index 0036577..2346d7f 100644
--- a/src/actions/singleinstanceoperations/SetPointSizeOperation.java
+++ b/src/actions/singleinstanceoperations/SetPointSizeOperation.java
@@ -6,6 +6,11 @@
import ui.general.InputManager;
import ui.general.InputManagerDelegate;
+/**
+ * A single instance operation responsible for setting the point size
+ * @author chenzb
+ *
+ */
public class SetPointSizeOperation extends SingleInstanceOperation {
public SetPointSizeOperation(PaintPanel panel) {
diff --git a/src/actions/singleinstanceoperations/SingleInstanceOperation.java b/src/actions/singleinstanceoperations/SingleInstanceOperation.java
index 946235b..90f7408 100644
--- a/src/actions/singleinstanceoperations/SingleInstanceOperation.java
+++ b/src/actions/singleinstanceoperations/SingleInstanceOperation.java
@@ -27,6 +27,10 @@ public SingleInstanceOperation(PaintPanel panel) {
super(panel);
}
+ /**
+ * The default behavior for a change method, only one component is selected
+ * and that component's type matchs the desired type
+ */
@Override
public boolean canPerformAction() {
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
@@ -41,6 +45,10 @@ public boolean canPerformAction() {
}
+ /**
+ * The implementation of this method delegates to the "PerformActionOnInstance"
+ *
+ */
@Override
public void performAction() {
// TODO Auto-generated method stub
@@ -50,6 +58,11 @@ public void performAction() {
panel.repaint();
}
+ /**
+ * This method is called when the action is triggered.
+ * Subclasses need to override this method to do appropriate operations
+ * @param instance
+ */
protected abstract void performActionOnInstance(T instance);
/**
diff --git a/src/actions/singleinstanceoperations/UpdateFontSizeOperation.java b/src/actions/singleinstanceoperations/UpdateFontSizeOperation.java
index 747b085..056ddf7 100644
--- a/src/actions/singleinstanceoperations/UpdateFontSizeOperation.java
+++ b/src/actions/singleinstanceoperations/UpdateFontSizeOperation.java
@@ -6,6 +6,11 @@
import ui.general.InputManager;
import ui.general.InputManagerDelegate;
+/**
+ * Single instance operaiton responsible for updating the font size
+ * @author chenzb
+ *
+ */
public class UpdateFontSizeOperation extends SingleInstanceOperation{
public UpdateFontSizeOperation(PaintPanel panel) {
diff --git a/src/classpathutil/ClassFinder.java b/src/classpathutil/ClassFinder.java
index b7b0033..0b58626 100644
--- a/src/classpathutil/ClassFinder.java
+++ b/src/classpathutil/ClassFinder.java
@@ -6,6 +6,12 @@
import java.util.jar.JarFile;
/**Take from
+ *
+ * This is a template class.
+ *
+ * Use ClassSearch instead.
+ *
+ * This class is copied from
*
* http://stackoverflow.com/questions/3222638/get-all-of-the-classes-in-the-classpath
*
diff --git a/src/paintcomponents/LineSegment.java b/src/paintcomponents/LineSegment.java
index d07fe29..dded59a 100644
--- a/src/paintcomponents/LineSegment.java
+++ b/src/paintcomponents/LineSegment.java
@@ -25,6 +25,22 @@ public class LineSegment extends PaintComponent {
private Stroke stroke;
private double strokeWidth;
+ /**
+ * @return the strokeWidth
+ */
+ public double getStrokeWidth() {
+ return strokeWidth;
+ }
+
+ /**
+ * @param strokeWidth the strokeWidth to set
+ */
+ public void setStrokeWidth(double strokeWidth) {
+ this.strokeWidth = strokeWidth;
+ this.stroke = new BasicStroke((float) strokeWidth);
+ }
+
+
/**
* @return the toPoint
*/
diff --git a/src/paintcomponents/PaintComponent.java b/src/paintcomponents/PaintComponent.java
index 7756ada..79caa3b 100644
--- a/src/paintcomponents/PaintComponent.java
+++ b/src/paintcomponents/PaintComponent.java
@@ -7,7 +7,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import painttools.tools.SelectTool;
+import painttools.tools.SelectToolInterface;
import ui.PaintPanel;
/**
@@ -119,7 +119,7 @@ public void paint(Graphics g) {
* @param selectTool
* TODO
*/
- public void select(SelectTool selectTool) {
+ public void select(SelectToolInterface selectTool) {
selected = true;
if (selectTool != null)
selectTool.getSelectedComponents().add(this);
@@ -134,7 +134,7 @@ public void select(SelectTool selectTool) {
* @param selectTool
* TODO
*/
- public void deselect(SelectTool selectTool) {
+ public void deselect(SelectToolInterface selectTool) {
selected = false;
if (selectTool != null)
selectTool.getSelectedComponents().remove(this);
@@ -146,7 +146,7 @@ public void deselect(SelectTool selectTool) {
* @param selectTool
* TODO
*/
- public void toggleSelect(SelectTool selectTool) {
+ public void toggleSelect(SelectToolInterface selectTool) {
if (isSelected()) {
deselect(selectTool);
} else {
diff --git a/src/paintcomponents/annotations/PaintComponentAnnotation.java b/src/paintcomponents/annotations/PaintComponentAnnotation.java
index 9d17651..8971274 100644
--- a/src/paintcomponents/annotations/PaintComponentAnnotation.java
+++ b/src/paintcomponents/annotations/PaintComponentAnnotation.java
@@ -7,7 +7,7 @@
/**
* Annotations is part of the paint panel that is attached to a particular paint component
* Annotations does not mainly impact the behavior of underlying paint components, but
- * extends the component to be more extensible
+ * extends the component to be more extensible, and usable by external actions
* @author chenzb
*
*/
diff --git a/src/paintcomponents/data/DataTextIOPaintComponent.java b/src/paintcomponents/data/DataTextIOPaintComponent.java
index 25379e9..19fcb71 100644
--- a/src/paintcomponents/data/DataTextIOPaintComponent.java
+++ b/src/paintcomponents/data/DataTextIOPaintComponent.java
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.stream.Collectors;
+import painttools.tools.SelectToolInterface;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -167,7 +168,7 @@ public boolean contains(int x, int y) {
}
@Override
- public void select(SelectTool selectTool) {
+ public void select(SelectToolInterface selectTool) {
int x = selectTool.getLastMouseEvent().getX();
int y = selectTool.getLastMouseEvent().getY();
// try to select every from and toPoints
@@ -189,7 +190,7 @@ public void select(SelectTool selectTool) {
}
@Override
- public void deselect(SelectTool selectTool) {
+ public void deselect(SelectToolInterface selectTool) {
int x = selectTool.getLastMouseEvent().getX();
int y = selectTool.getLastMouseEvent().getY();
diff --git a/src/paintcomponents/data/DataTextPaintComponent.java b/src/paintcomponents/data/DataTextPaintComponent.java
index a5b4bcb..e3bf41b 100644
--- a/src/paintcomponents/data/DataTextPaintComponent.java
+++ b/src/paintcomponents/data/DataTextPaintComponent.java
@@ -9,6 +9,8 @@
import paintcomponents.RectanglePaintComponent;
import paintcomponents.TextPaintComponent;
+import painttools.tools.SelectToolInterface;
+import settings.Defaults;
import painttools.tools.SelectTool;
import ui.PaintPanel;
@@ -61,7 +63,7 @@ public void translate(int i, int j) {
}
@Override
- public void select(SelectTool selectTool) {
+ public void select(SelectToolInterface selectTool) {
super.select(selectTool);
//pass in null to prevent current selection from being modified
//only causes changes in apperance
@@ -69,7 +71,7 @@ public void select(SelectTool selectTool) {
}
@Override
- public void deselect(SelectTool selectTool) {
+ public void deselect(SelectToolInterface selectTool) {
// TODO Auto-generated method stub
super.deselect(selectTool);
rect.deselect(null);
diff --git a/src/painttools/toolbar/ToolBar.java b/src/painttools/toolbar/ToolBar.java
index 7c853d6..01c184b 100644
--- a/src/painttools/toolbar/ToolBar.java
+++ b/src/painttools/toolbar/ToolBar.java
@@ -1,21 +1,18 @@
package painttools.toolbar;
-import java.awt.Button;
-import java.awt.Component;
-import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.BoxLayout;
-import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPanel;
-import javax.tools.Tool;
import painttools.tools.DotTool;
import painttools.tools.PaintTool;
import painttools.tools.SelectTool;
+import painttools.tools.SelectToolInterface;
+import painttools.tools.SmartTool;
import ui.PaintPanel;
public class ToolBar extends JPanel {
@@ -35,6 +32,7 @@ public ToolBar(PaintPanel panel) {
selectTool = new SelectTool(panel);
addTool(new DotTool());
addTool(selectTool);
+ addTool(new SmartTool(panel));
}
/**
@@ -73,7 +71,7 @@ private void select(PaintTool tool) {
}
}
- public SelectTool getSelectTool() {
+ public SelectToolInterface getSelectTool() {
return selectTool;
}
diff --git a/src/painttools/tools/MenuForPaintComponent.java b/src/painttools/tools/MenuForPaintComponent.java
new file mode 100644
index 0000000..51022a8
--- /dev/null
+++ b/src/painttools/tools/MenuForPaintComponent.java
@@ -0,0 +1,38 @@
+package painttools.tools;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JMenu;
+import javax.swing.JPopupMenu;
+
+import actions.PaintAction;
+import actions.RemovePaintComponent;
+import actions.menu.PaintActionMenuItem;
+import paintcomponents.PaintComponent;
+import paintcomponents.TextPaintComponent;
+import ui.PaintPanel;
+
+public class MenuForPaintComponent {
+ public static JPopupMenu getMenuForPaintComponent(PaintComponent comp, PaintPanel panel) {
+ JPopupMenu menu = new JPopupMenu();
+ if( comp instanceof TextPaintComponent )
+ addActionToMenu(menu, new RemovePaintComponent(panel));
+ return menu;
+
+ }
+ private static void addActionToMenu(JPopupMenu menu, PaintAction action) {
+ PaintActionMenuItem item = new PaintActionMenuItem(action);
+ item.setEnabled(action.canPerformAction());
+ item.setText(action.toString());
+ item.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ item.performAction();
+
+ }
+ });
+ menu.add(item);
+ }
+}
diff --git a/src/painttools/tools/SelectTool.java b/src/painttools/tools/SelectTool.java
index a8b2c32..32d2c55 100644
--- a/src/painttools/tools/SelectTool.java
+++ b/src/painttools/tools/SelectTool.java
@@ -12,7 +12,7 @@
import settings.Defaults;
import ui.PaintPanel;
-public class SelectTool extends PaintTool {
+public class SelectTool extends PaintTool implements SelectToolInterface{
private PaintPanel panel;
@@ -24,6 +24,7 @@ public class SelectTool extends PaintTool {
/**
* @return the lastMouseEvent
*/
+ @Override
public MouseEvent getLastMouseEvent() {
return lastMouseEvent;
}
@@ -35,13 +36,15 @@ public MouseEvent getLastMouseEvent() {
* @return
* @see java.util.ArrayList#add(java.lang.Object)
*/
+ @Override
public boolean addSelectionToolListener(SelectionToolListener e) {
return listeners.add(e);
}
- /**
- * @return the selectedComponents
+ /* (non-Javadoc)
+ * @see painttools.tools.SelectToolInterface#getSelectedComponents()
*/
+ @Override
public ArrayList getSelectedComponents() {
return selectedComponents;
}
@@ -57,12 +60,10 @@ public void mouseClicked(MouseEvent e) {
}
- /**
- * Selects a component, changes selection All listeners are informed. Panel
- * are repainted
- *
- * @param comp
+ /* (non-Javadoc)
+ * @see painttools.tools.SelectToolInterface#selectComponent(paintcomponents.PaintComponent)
*/
+ @Override
public void selectComponent(PaintComponent comp) {
comp.select(this);
for (SelectionToolListener selectionToolListener : listeners) {
@@ -71,12 +72,10 @@ public void selectComponent(PaintComponent comp) {
panel.repaint();
}
- /**
- * Deselect a component, changes selection All listeners are informed. Panel
- * are repainted
- *
- * @param comp
+ /* (non-Javadoc)
+ * @see painttools.tools.SelectToolInterface#deselectComponent(paintcomponents.PaintComponent)
*/
+ @Override
public void deselectComponent(PaintComponent comp) {
comp.deselect(this);
for (SelectionToolListener selectionToolListener : listeners) {
@@ -86,10 +85,10 @@ public void deselectComponent(PaintComponent comp) {
}
- /**
- * Deselect ALL components, changes selection All listeners are informed.
- * Panel are repainted
+ /* (non-Javadoc)
+ * @see painttools.tools.SelectToolInterface#clearSelection()
*/
+ @Override
public void clearSelection() {
// remove all selection
while(!selectedComponents.isEmpty()) {
@@ -246,7 +245,7 @@ public void mouseMoved(MouseEvent e) {
@Override
public void start(PaintPanel panel) {
this.panel = panel;
-
+ panel.setSelectTool(this);
}
@Override
diff --git a/src/painttools/tools/SelectToolInterface.java b/src/painttools/tools/SelectToolInterface.java
new file mode 100644
index 0000000..eed7e0c
--- /dev/null
+++ b/src/painttools/tools/SelectToolInterface.java
@@ -0,0 +1,41 @@
+package painttools.tools;
+
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+
+import paintcomponents.PaintComponent;
+
+public interface SelectToolInterface {
+
+ /**
+ * @return the selectedComponents
+ */
+ public abstract ArrayList getSelectedComponents();
+
+ /**
+ * Selects a component, changes selection All listeners are informed. Panel
+ * are repainted
+ *
+ * @param comp
+ */
+ public abstract void selectComponent(PaintComponent comp);
+
+ /**
+ * Deselect a component, changes selection All listeners are informed. Panel
+ * are repainted
+ *
+ * @param comp
+ */
+ public abstract void deselectComponent(PaintComponent comp);
+
+ /**
+ * Deselect ALL components, changes selection All listeners are informed.
+ * Panel are repainted
+ */
+ public abstract void clearSelection();
+
+ public abstract boolean addSelectionToolListener(SelectionToolListener e);
+
+ public abstract MouseEvent getLastMouseEvent();
+
+}
\ No newline at end of file
diff --git a/src/painttools/tools/SmartTool.java b/src/painttools/tools/SmartTool.java
new file mode 100644
index 0000000..247b79f
--- /dev/null
+++ b/src/painttools/tools/SmartTool.java
@@ -0,0 +1,138 @@
+package painttools.tools;
+
+import java.awt.Dimension;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+
+import javax.swing.JPopupMenu;
+
+import paintcomponents.PaintComponent;
+import ui.PaintPanel;
+
+public class SmartTool extends PaintTool implements SelectToolInterface{
+
+ private PaintPanel panel;
+ private MouseEvent lastMouseEvent;
+
+ public SmartTool(PaintPanel panel) {
+ super();
+ this.panel = panel;
+ selectedComponents = new ArrayList<>();
+ listeners = new ArrayList<>();
+
+ }
+
+ private ArrayList selectedComponents;
+ private ArrayList listeners;
+ @Override
+ public ArrayList getSelectedComponents() {
+ return selectedComponents;
+ }
+
+ @Override
+ public void selectComponent(PaintComponent comp) {
+ comp.select(this);
+ for (SelectionToolListener selectionToolListener : listeners) {
+ selectionToolListener.selectionChanged();
+ }
+ panel.repaint();
+ }
+
+ @Override
+ public void deselectComponent(PaintComponent comp) {
+ comp.deselect(this);
+ for (SelectionToolListener selectionToolListener : listeners) {
+ selectionToolListener.selectionChanged();
+ }
+ panel.repaint();
+ }
+
+ @Override
+ public void clearSelection() {
+ // remove all selection
+ while(!selectedComponents.isEmpty()) {
+ selectedComponents.get(0).deselect(this);
+ }
+
+ for (SelectionToolListener selectionToolListener : listeners) {
+ selectionToolListener.selectionChanged();
+ }
+ panel.repaint();
+ }
+
+ public boolean addSelectionToolListener(SelectionToolListener e) {
+ return listeners.add(e);
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ lastMouseEvent = e;
+ if(e.getButton() == MouseEvent.BUTTON3) {
+ PaintComponent comp = panel.componentUnderPoint(e.getX(), e.getY());
+ if( comp != null) {
+ selectComponent(comp);
+ JPopupMenu menu = MenuForPaintComponent.getMenuForPaintComponent(comp, panel);
+ //menu.setLocation(e.getPoint());
+ //menu.setPreferredSize(new Dimension(200,200));
+ menu.show(panel, e.getX(), e.getY());
+ //panel.add(menu);
+ panel.repaint();
+ }
+ }
+
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void start(PaintPanel panel) {
+ // TODO Auto-generated method stub
+ panel.setSelectTool(this);
+
+ }
+
+ @Override
+ public void reset() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public MouseEvent getLastMouseEvent() {
+ return lastMouseEvent;
+ }
+
+}
diff --git a/src/ui/PaintPanel.java b/src/ui/PaintPanel.java
index 62e5b0b..cb9f925 100644
--- a/src/ui/PaintPanel.java
+++ b/src/ui/PaintPanel.java
@@ -17,6 +17,7 @@
import painttools.toolbar.ToolBarListener;
import painttools.tools.PaintTool;
import painttools.tools.SelectTool;
+import painttools.tools.SelectToolInterface;
public class PaintPanel extends JPanel implements ToolBarListener {
@@ -31,7 +32,7 @@ enum State {
private PaintTool tool;
private PaintComponent tempComponent;
- private SelectTool selectTool;
+ private SelectToolInterface selectTool;
/**
* @return the tempComponent
@@ -204,7 +205,7 @@ public PaintComponent componentUnderPoint(int x, int y) {
*
* @return
*/
- public SelectTool getSelectTool() {
+ public SelectToolInterface getSelectTool() {
return selectTool;
}
@@ -213,7 +214,7 @@ public SelectTool getSelectTool() {
*
* @param selectTool
*/
- public void setSelectTool(SelectTool selectTool) {
+ public void setSelectTool(SelectToolInterface selectTool) {
this.selectTool = selectTool;
}