Skip to content

Kent branch Add more functionality on right click popup menu #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop_smarttool
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/actions/RemovePaintComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.util.ArrayList;

import paintcomponents.PaintComponent;
import painttools.tools.SmartTool;
import ui.PaintPanel;
import actions.edit.undoredo.SharedUndoRedoActionManager;
import actions.edit.undoredo.UndoRedoableInterface;
import actions.menu.ActionsMenuBarTitles;
import actions.menu.ActionsPopupMenuTitles;

public class RemovePaintComponent extends PaintAction{

Expand All @@ -29,6 +31,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
Expand All @@ -45,12 +49,16 @@ public void redoAction() {
comp.remove(panel);
}
});

panel.repaint();
}

@Override
public String locationString() {
// TODO Auto-generated method stub
return ActionsMenuBarTitles.Data().Remove().toString(); }

if(panel.getSelectTool() instanceof SmartTool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach (using instanceof) is dangerous, Please Comment on these two lines on the reason for selection.

Instanceof makes code unmaintanable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a comment on the approach taken,
Include the following line:

//TODO RECONSIDER THIS DESIGN

return ActionsPopupMenuTitles.Remove().toString();
return ActionsMenuBarTitles.Data().Remove().toString();
}

}
32 changes: 32 additions & 0 deletions src/actions/add/AddConstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package actions.add;

import java.lang.reflect.Constructor;

import actions.menu.ActionsMenuBarTitles;
import actions.menu.ActionsPopupMenuTitles;
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
import ui.PaintPanel;

public class AddConstructor extends AddOperation<ClassConstructorPaintComponent> {

private Constructor constructor;

public AddConstructor(PaintPanel panel, Constructor constructor) {
super(panel);
// TODO Auto-generated constructor stub
this.constructor = constructor;
}

@Override
protected ClassConstructorPaintComponent getPaintComponentToAdd() {
// TODO Auto-generated method stub
return new ClassConstructorPaintComponent(constructor, 0, 0);
}

@Override
public String locationString() {
// TODO Auto-generated method stub
return ActionsPopupMenuTitles.Constructor().append(constructor.toString()).toString();
}

}
30 changes: 30 additions & 0 deletions src/actions/add/AddFields.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package actions.add;

import actions.menu.ActionsPopupMenuTitles;
import paintcomponents.PaintComponent;
import paintcomponents.java.lazy.FieldsPaintComponent;
import ui.PaintPanel;

public class AddFields extends AddOperation{

private Class displayingClass;

public AddFields(PaintPanel panel, Class displayingClass) {
super(panel);
// TODO Auto-generated constructor stub
this.displayingClass = displayingClass;
}

@Override
protected PaintComponent getPaintComponentToAdd() {
// TODO Auto-generated method stub
return new FieldsPaintComponent(displayingClass, 0, 0);
}

@Override
public String locationString() {
// TODO Auto-generated method stub
return ActionsPopupMenuTitles.Fields().toString();
}

}
32 changes: 32 additions & 0 deletions src/actions/add/AddMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package actions.add;

import java.lang.reflect.Method;

import actions.menu.ActionsPopupMenuTitles;
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
import paintcomponents.java.lazy.MethodPaintComponent;
import ui.PaintPanel;

public class AddMethod extends AddOperation<MethodPaintComponent> {

private Method method;

public AddMethod(PaintPanel panel, Method method) {
super(panel);
// TODO Auto-generated constructor stub
this.method = method;
}

@Override
protected MethodPaintComponent getPaintComponentToAdd() {
// TODO Auto-generated method stub
return new MethodPaintComponent(method, 0, 0);
}

@Override
public String locationString() {
// TODO Auto-generated method stub
return ActionsPopupMenuTitles.Method().append(method.toString()).toString();
}

}
37 changes: 37 additions & 0 deletions src/actions/add/AddOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package actions.add;

import paintcomponents.PaintComponent;
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
import ui.PaintPanel;
import actions.PaintAction;

/**
* Subcalss should override getPaintComponentToAdd to provide an adder should the action be performed
* @author cs12waft
*
* @param <T>
*/
public abstract class AddOperation<T extends PaintComponent> extends PaintAction {

public AddOperation(PaintPanel panel) {
super(panel);
}

@Override
public boolean canPerformAction() {
return true;
}

@Override
public void performAction() {
PaintComponent consComp = getPaintComponentToAdd();
consComp.translate(panel.getWidth() / 2, panel.getHeight() / 2);
panel.addPaintComponent(consComp);
panel.repaint();
}

protected abstract T getPaintComponentToAdd();



}
32 changes: 32 additions & 0 deletions src/actions/menu/ActionsPopupMenuTitles.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package actions.menu;

public class ActionsPopupMenuTitles {
public String pending;

public ActionsPopupMenuTitles(String string) {
pending = string;
}

@Override
public String toString() {
return pending;
}

public static ActionsPopupMenuTitles Remove(){
return new ActionsPopupMenuTitles("Remove");
}
public static ActionsPopupMenuTitles Constructor(){
return new ActionsPopupMenuTitles("Constructor");
}
public static ActionsPopupMenuTitles Method(){
return new ActionsPopupMenuTitles("Method");
}
public static ActionsPopupMenuTitles Fields(){
return new ActionsPopupMenuTitles("Fields");
}
public ActionsPopupMenuTitles append(String str) {
pending += "/" + str;
return this;
}

}
9 changes: 5 additions & 4 deletions src/actions/menu/PaintActionMenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,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;
}
Expand All @@ -27,7 +28,7 @@ public void setAssociatedAction(PaintAction associatedAction) {
public void performAction() {
associatedAction.performAction();
//update menu bar status
actionsMenuBar.updateEnableStatusForAllMenuItems();

if(actionsMenuBar != null)
actionsMenuBar.updateEnableStatusForAllMenuItems();
}
}
8 changes: 4 additions & 4 deletions src/paintcomponents/PaintComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/paintcomponents/data/DataTextIOPaintComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -166,7 +167,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
Expand All @@ -188,7 +189,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();

Expand Down
6 changes: 4 additions & 2 deletions src/paintcomponents/data/DataTextPaintComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import paintcomponents.RectanglePaintComponent;
import paintcomponents.TextPaintComponent;
import painttools.tools.SelectToolInterface;
import settings.Defaults;
import painttools.tools.SelectTool;
import ui.PaintPanel;

Expand Down Expand Up @@ -61,15 +63,15 @@ 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
rect.select(null);
}

@Override
public void deselect(SelectTool selectTool) {
public void deselect(SelectToolInterface selectTool) {
// TODO Auto-generated method stub
super.deselect(selectTool);
rect.deselect(null);
Expand Down
10 changes: 4 additions & 6 deletions src/painttools/toolbar/ToolBar.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -35,6 +32,7 @@ public ToolBar(PaintPanel panel) {
selectTool = new SelectTool(panel);
addTool(new DotTool());
addTool(selectTool);
addTool(new SmartTool(panel));
}

/**
Expand Down Expand Up @@ -73,7 +71,7 @@ private void select(PaintTool tool) {
}
}

public SelectTool getSelectTool() {
public SelectToolInterface getSelectTool() {
return selectTool;
}

Expand Down
Loading