Skip to content

Commit 6d27fb5

Browse files
author
Ultimate Pea
authored
Merge pull request #20 from UCSDOalads/updateClassSearchFramebyCG
Update class search frame by cg
2 parents 25e04da + d94efd0 commit 6d27fb5

20 files changed

Lines changed: 634 additions & 24 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.class
22
/bin/
3+
.DS_Store
4+
.settings
5+
.settings/*

.settings/org.eclipse.jdt.core.prefs

Lines changed: 0 additions & 11 deletions
This file was deleted.

TODOList.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
2. Edit Undo/Redo Operations
33
3. More usable SelectTools
44
4. Remove Functinoality
5-
5. Zooming and Scrolling
5+
5. Zooming and Scrolling and Moving Function
66
6. Data Point Connection Types
7-
7. Available Class Search
7+
7. Available Class Search
8+
8. Auto-Update Display Box Affected by Recent Changes
9+
9. Debug Undo Function
10+
10. Type Cast try (String) catch

src/actions/AddLazyJavaClassAction.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public void redoAction() {
5050
JOptionPane.showMessageDialog(panel,
5151
className + " :: Class Not Found");
5252
}
53-
54-
5553

5654
}
5755

src/actions/menu/ActionsMenuBar.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
import actions.PaintAction;
3030
import actions.RemovePaintComponent;
3131
import actions.UpdateDataDisplayBoxAction;
32+
import actions.singleinstanceoperations.SetPointSizeOperation;
33+
import actions.singleinstanceoperations.UpdateFontSizeOperation;
34+
import actions.ZoomInAction;
35+
import actions.ZoomOutAction;
3236
import actions.ZoomInAction;
3337
import actions.ZoomOutAction;
3438

@@ -71,6 +75,9 @@ public ActionsMenuBar(PaintPanel panel){
7175
// remove
7276
addAction(new RemovePaintComponent(panel));
7377

78+
//edit
79+
addAction(new UpdateFontSizeOperation(panel));
80+
addAction(new SetPointSizeOperation(panel));
7481

7582
}
7683

src/actions/menu/ActionsMenuBarTitles.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,21 @@ public ActionsMenuBarTitles Remove() {
113113
return this;
114114
}
115115

116-
public Object Open() {
116+
public ActionsMenuBarTitles Open() {
117117
append("Open...");
118118
return this;
119119
}
120120

121+
public ActionsMenuBarTitles Font_Size() {
122+
append("Font Size...");
123+
return this;
124+
}
125+
126+
public ActionsMenuBarTitles Point_Size() {
127+
append("Point Size...");
128+
return this;
129+
}
130+
121131
public ActionsMenuBarTitles Zoom_In() {
122132
append("Zoom In");
123133
return this;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package actions.singleinstanceoperations;
2+
3+
import actions.menu.ActionsMenuBarTitles;
4+
import paintcomponents.SimplePoint;
5+
import ui.PaintPanel;
6+
import ui.general.InputManager;
7+
import ui.general.InputManagerDelegate;
8+
9+
public class SetPointSizeOperation extends SingleInstanceOperation<SimplePoint> {
10+
11+
public SetPointSizeOperation(PaintPanel panel) {
12+
super(panel);
13+
}
14+
15+
16+
@Override
17+
public String locationString() {
18+
return ActionsMenuBarTitles.Edit().Point_Size().toString();
19+
}
20+
21+
@Override
22+
protected void performActionOnInstance(SimplePoint instance) {
23+
InputManager.sharedInstance().askForInt(panel, new InputManagerDelegate<Integer>() {
24+
25+
@Override
26+
public void didFinishInput(Integer input) {
27+
instance.setRadius(input);
28+
}
29+
});
30+
31+
}
32+
33+
34+
@Override
35+
protected Class<SimplePoint> getGenericClassType() {
36+
return SimplePoint.class;
37+
}
38+
39+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package actions.singleinstanceoperations;
2+
3+
import actions.PaintAction;
4+
import paintcomponents.PaintComponent;
5+
import ui.PaintPanel;
6+
7+
/**
8+
* Single Instance Operation defines operation on a single instance.
9+
*
10+
* i.e.,
11+
* 1.
12+
* One and Only One Instance must be selected to perform operaion.
13+
*
14+
* 2. The
15+
* operation only changes the instance itself but nothing else
16+
*
17+
*
18+
* After updating, the subclass do not need to call paintcomponent.repaint method
19+
*
20+
*
21+
* @author chenzb
22+
*
23+
*/
24+
public abstract class SingleInstanceOperation<T> extends PaintAction {
25+
26+
public SingleInstanceOperation(PaintPanel panel) {
27+
super(panel);
28+
}
29+
30+
@Override
31+
public boolean canPerformAction() {
32+
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
33+
return false;
34+
}
35+
PaintComponent paintComponent = panel.getSelectTool()
36+
.getSelectedComponents().get(0);
37+
38+
39+
//return if the object is kind of the desired class
40+
return getGenericClassType().isInstance(paintComponent);
41+
42+
}
43+
44+
@Override
45+
public void performAction() {
46+
// TODO Auto-generated method stub
47+
@SuppressWarnings("unchecked")
48+
T comp = (T) panel.getSelectTool().getSelectedComponents().get(0);
49+
performActionOnInstance(comp);
50+
panel.repaint();
51+
}
52+
53+
protected abstract void performActionOnInstance(T instance);
54+
55+
/**
56+
* Due to constraint in Java API, subclass MUST override this method
57+
*
58+
* with method body :: <code>return T.class;</code>
59+
* @return
60+
*/
61+
protected abstract Class<T> getGenericClassType();
62+
63+
64+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package actions.singleinstanceoperations;
2+
3+
import actions.menu.ActionsMenuBarTitles;
4+
import paintcomponents.TextPaintComponent;
5+
import ui.PaintPanel;
6+
import ui.general.InputManager;
7+
import ui.general.InputManagerDelegate;
8+
9+
public class UpdateFontSizeOperation extends SingleInstanceOperation<TextPaintComponent>{
10+
11+
public UpdateFontSizeOperation(PaintPanel panel) {
12+
super(panel);
13+
}
14+
15+
@Override
16+
protected void performActionOnInstance(TextPaintComponent instance) {
17+
InputManager.sharedInstance().askForFloat(panel, new InputManagerDelegate<Float>() {
18+
19+
@Override
20+
public void didFinishInput(Float input) {
21+
instance.setFontSize(input);
22+
panel.repaint();
23+
}
24+
});
25+
26+
}
27+
28+
@Override
29+
public String locationString() {
30+
return ActionsMenuBarTitles.Edit().Font_Size().toString();
31+
}
32+
33+
@Override
34+
protected Class<TextPaintComponent> getGenericClassType() {
35+
return TextPaintComponent.class;
36+
}
37+
38+
39+
40+
41+
42+
}

src/classpathutil/ClassSearch.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,36 @@ public static ClassSearch sharedInstance() {
1111
return sharedInstance;
1212
}
1313

14-
private ClassSearch() {
15-
}
14+
private ArrayList<String> allClasses;
1615

17-
public ArrayList<String> classesForName(String name) {
18-
ArrayList<String> result = new ArrayList<>();
16+
/**
17+
* Constructs a ClassSearch Instance
18+
* The method
19+
*/
20+
private ClassSearch() {
21+
//load classes
22+
23+
24+
allClasses = new ArrayList<>();
1925
ClassFinder.findClasses(new Visitor<String>() {
2026

2127
@Override
2228
public boolean visit(String t) {
23-
result.add(t);
24-
29+
allClasses.add(t);
2530
return true;
2631
}
2732
});
33+
34+
}
35+
36+
public ArrayList<String> classesForName(String name) {
37+
38+
ArrayList<String> result = new ArrayList<>();
39+
for (String string : allClasses) {
40+
if(string.contains(name)){
41+
result.add(string);
42+
}
43+
}
2844

2945
return sortAccordingToPrecedence(result, name);
3046
}

0 commit comments

Comments
 (0)