Skip to content

Commit

Permalink
Refactored createNodes() and reload() methods, combining them into up…
Browse files Browse the repository at this point in the history
…dateTreeNodeList().
  • Loading branch information
billmaya committed Oct 11, 2018
1 parent 899ec35 commit ee9f808
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/com/storytron/swat/verbeditor/VerbTree.java
Expand Up @@ -272,7 +272,7 @@ else if (useCatMenu)

public void init(Deikto tdk){
dk=tdk;
createNodes(); // this method populates the tree with the verbs
updateTreeNodeList(); // this method populates the tree with the verbs
}

/**
Expand Down Expand Up @@ -738,10 +738,8 @@ private void deleteNodeSub(String nodeName, Enumeration children) {
}
}
}
// **********************************************************************
private void createNodes() {
// [change-ld] replaced code with call to a recursive function
// to generate nodes an arbitrary number of levels deep

private void updateTreeNodeList() {

root.removeAllChildren();
createNodeChildren(root, dk.categories);
Expand All @@ -751,6 +749,7 @@ private void createNodes() {

// Generate nodes an arbitrary number of levels deep
private void createNodeChildren(VerbTreeNode root, Category source) {

ArrayList<String> verbNames;
int numVerbs = 0;
for (Category child: source.getChildren()) {
Expand All @@ -770,16 +769,6 @@ private void createNodeChildren(VerbTreeNode root, Category source) {
}
}
}

public void reload() { // TODO Should I refactor this, combining somehow with createNodes() above?
root.removeAllChildren();

// [change-ld] replaced code with call to a recursive function
// to generate nodes an arbitrary number of levels deep
createNodeChildren(root, dk.categories);

treeModel.reload();
}

private void addNewVerb() {
int i=0;
Expand Down Expand Up @@ -854,7 +843,8 @@ private int findLinearVerbIndex(int pos,VerbTreeNode catN){
} else
return ((VerbTreeNode)catN.getChildAt(0)).getVerb().getReference().getIndex()+pos;
}
private void addVerb(int pos,VerbTreeNode catN,Verb verbObj){
private void addVerb(int pos,VerbTreeNode catN,Verb verbObj) {

try {
dk.addVerb(findLinearVerbIndex(pos,catN),verbObj);
} catch (LimitException e) { throw new RuntimeException(e); }
Expand All @@ -867,11 +857,13 @@ private void addVerb(int pos,VerbTreeNode catN,Verb verbObj){
checkAddVerbAction();
showAndSelect(verb);
}
private void addVerb(int pos,Verb verbObj){
private void addVerb(int pos,Verb verbObj) {

addVerb(pos,findCategoryNode(verbObj.getCategory()),verbObj);
}

private void duplicateVerb(){
private void duplicateVerb() {

final Verb oldVerb = selectedVerb;
final Verb newVerb = selectedVerb.clone(false);

Expand Down Expand Up @@ -961,6 +953,7 @@ public void myUndo() {
};
}
private void deleteVerb(Verb mVerb) {

boolean reloadOptions=ve.getRole()!=null && ve.getRole().getRole().getOptionIndex(mVerb.getLabel())>=0;

// remove the verb tree node
Expand All @@ -976,7 +969,7 @@ else if (reloadOptions) {
validate();
}

private VerbTreeNode findCategoryNode(String category){
private VerbTreeNode findCategoryNode(String category) {
return findCategoryNode(root,category);
}
private VerbTreeNode findCategoryNode(VerbTreeNode n,String category){
Expand All @@ -990,7 +983,7 @@ else if (n.isCategory()) {
return null;
}

private VerbTreeNode findVerbNode(Verb verb){
private VerbTreeNode findVerbNode(Verb verb) {
VerbTreeNode cat=findCategoryNode(verb.getCategory());
if (cat==null) return null;

Expand Down Expand Up @@ -1023,15 +1016,19 @@ public void myUndo() {
};
}
private void addCategory(Category cat) {

addCategory(dk.categories.getChildren().size(),cat);
}

private void addCategory(int index,Category cat) {

cat.setParent(dk,index,dk.categories);
reload();
updateTreeNodeList();
showAndSelect(findCategoryNode(cat.getName()));
}

private void renameSelectedCategory(String zLabel){
private void renameSelectedCategory(String zLabel) {

final Category cat = selectedCat;
final String oldLabel = cat.getName();

Expand Down Expand Up @@ -1061,7 +1058,9 @@ public String getUndoPresentationName() {
};
}
}

private void renameCategory(Category cat,String zLabel) {

// Alter all references to this verb label in all options
for (Verb zVerb: dk.getVerbs())
if (zVerb.getCategory().equalsIgnoreCase(cat.getName()))
Expand All @@ -1071,7 +1070,8 @@ private void renameCategory(Category cat,String zLabel) {
validate();
}

private void renameSelectedVerb(String zLabel){
private void renameSelectedVerb(String zLabel) {

final Verb verb = selectedVerb;
final String oldLabel = verb.getLabel();
if (zLabel==null || zLabel.equals(oldLabel)) return;
Expand Down Expand Up @@ -1102,6 +1102,7 @@ public String getUndoPresentationName() {
}

private void renameVerb(Verb mVerb,String newLabel) {

renameNode(false, mVerb.getLabel(), newLabel);
mVerb.setLabel(newLabel);
if (ve.getVerb()==mVerb)
Expand All @@ -1112,6 +1113,7 @@ private void renameVerb(Verb mVerb,String newLabel) {
}

private void deleteSelectedCategory() {

if (!selectedCat.hasAnyVerbs(dk)) {
final Category cat = selectedCat;
final int index = cat.getParent().getIndex(cat);
Expand All @@ -1129,6 +1131,7 @@ public void myUndo() {
}
}
private void deleteCategory(Category mCat) {

// remove the catgory from the category tree
String catName = mCat.getName();
mCat.getParent().removeChild(mCat);
Expand Down

0 comments on commit ee9f808

Please sign in to comment.