Skip to content

Commit

Permalink
Added getDontHireSubchoice for filtering of subchoice menus; applied to
Browse files Browse the repository at this point in the history
newly added OtherTreeSearch
  • Loading branch information
wmaddisn committed Mar 2, 2015
1 parent ac95978 commit 6c76a3a
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 25 deletions.
13 changes: 6 additions & 7 deletions .settings/org.eclipse.jdt.core.prefs
@@ -1,12 +1,11 @@
#Tue Mar 25 11:19:04 PDT 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.3
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
39 changes: 28 additions & 11 deletions Source/mesquite/lib/MenuOwner.java
Expand Up @@ -121,10 +121,10 @@ public abstract class MenuOwner implements Doomable { //EMBEDDED: extends Applet
rightBracket = "▶"; //byte[] bb = {(byte) 226, (byte)150, (byte)161}; new String(bb, "UTF-8");
}
else {*/
leftBracket = "«";//byte[] b = {(byte) 226, (byte)150, (byte)160}; new String(b, "UTF-8");
rightBracket = "»"; //byte[] bb = {(byte) 226, (byte)150, (byte)161}; new String(bb, "UTF-8");
leftBracket = "«";//byte[] b = {(byte) 226, (byte)150, (byte)160}; new String(b, "UTF-8");
rightBracket = "»"; //byte[] bb = {(byte) 226, (byte)150, (byte)161}; new String(bb, "UTF-8");
//}

}
/** The constructor in general is to be avoided, because modules are instantiated momentarily on startup to gather
information. The usual functions of a constructor are performed by startJob*/
Expand Down Expand Up @@ -698,7 +698,7 @@ else if (menuBar==null)
//else {
// if (MesquiteTrunk.isMacOSX()){
Menu spot = new Menu(leftBracket);
// spot.setFont(new Font ("SanSerif", Font.PLAIN, 12));
// spot.setFont(new Font ("SanSerif", Font.PLAIN, 12));
spot.add(new MenuItem("Menus between " + leftBracket + " " + rightBracket));
spot.add(new MenuItem(" refer to current window"));
menuBar.add(spot);
Expand Down Expand Up @@ -783,9 +783,10 @@ else if (menuBar==null)
if (menuBar!=null) {
for (int i=menuBar.getMenuCount()-1; i>=1; i--){ //leave first (file menu) in place
try{
if (menuEmpty(menuBar.getMenu(i))) {
if (menuEmpty(menuBar.getMenu(i)))
menuBar.remove(i);
}
else
removeEmptySubmenus(menuBar.getMenu(i));
}
catch (Exception e){
}
Expand All @@ -801,11 +802,27 @@ else if (menuBar==null)
e.printStackTrace();
}
}

public void removeEmptySubmenus(Menu parent){
for (int i=parent.getItemCount()-1; i>=0; i--){
try{
MenuItem item = parent.getItem(i);
if (item instanceof Menu){
if (menuEmpty((Menu)item))
parent.remove(i);
else
removeEmptySubmenus((Menu)item);
}
}
catch (Exception e){
}
}
}
/*-------------------------------------------------------------*/
public Vector getEmbeddedMenusVector(){
return embeddedMenusVector;
}

public void resetEmbeddedMenus(MesquiteWindow whichWindow){
if ((window != null && window.getShowInfoBar()) && (MesquiteTrunk.isMacOSX() || (whichWindow == null || !whichWindow.isLoneWindow()))) // && MesquiteTrunk.isMacOSX()) //these menus belong in the window, as long as an info bar is shown
embeddedMenusVector = composeEmbeddedMenuBar(whichWindow);
Expand Down Expand Up @@ -1385,7 +1402,7 @@ final boolean addListsToMenu(MesquiteMenuItemSpec mmi, Menu menu) {
int countPrimary2 = 0;
int countOthers2 = 0;
if (EmployerEmployee.useOtherChoices)
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModule( mbi.getHireSubchoice(), smbi))!=null) {
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModuleFilteredByNot( mbi.getHireSubchoice(), mbi.getDontHireSubchoice(), smbi))!=null) {
if (!smbi.getUserChooseable())
;
else if (smbi.isPrimary(mbi.getHireSubchoice()))
Expand All @@ -1400,7 +1417,7 @@ else if (smbi.isPrimary(mbi.getHireSubchoice()))
smbi = null;
countOthers2 =0;
count2 = 0;
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModule(mbi.getHireSubchoice(),smbi))!=null) {
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModuleFilteredByNot( mbi.getHireSubchoice(), mbi.getDontHireSubchoice(),smbi))!=null) {
int hiddenStatus2 = 0;
if (!smbi.getUserChooseable())
;
Expand Down Expand Up @@ -1650,7 +1667,7 @@ else if (mbi.getHireSubchoice()==null) { // potential employee hasn't indicated
zeroArray(secondaryItems2);
int countItems2 = 0;
// if (EmployerEmployee.useOtherChoices)
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModule( mbi.getHireSubchoice(), smbi))!=null) {
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModuleFilteredByNot( mbi.getHireSubchoice(), mbi.getDontHireSubchoice(), smbi))!=null) {
if (!smbi.getUserChooseable())
;
else if (smbi.isPrimary(mbi.getHireSubchoice()))
Expand All @@ -1665,7 +1682,7 @@ else if (smbi.isPrimary(mbi.getHireSubchoice()))
smbi = null;
countOthers2 =0;
count2 = 0;
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModule( mbi.getHireSubchoice(), smbi))!=null) {
while (count2++<128 && (smbi = MesquiteTrunk.mesquiteModulesInfoVector.findNextModuleFilteredByNot( mbi.getHireSubchoice(), mbi.getDontHireSubchoice(), smbi))!=null) {
boolean primary2 = smbi.isPrimary(mbi.getHireSubchoice());
int hiddenStatus2 = 0;
//TODO: this tokenization of the names for argument will not work if name of module includes ' -- must use full tokenization/detokenization
Expand Down
7 changes: 5 additions & 2 deletions Source/mesquite/lib/MesquiteModule.java
Expand Up @@ -68,7 +68,7 @@ public abstract class MesquiteModule extends EmployerEmployee implements Command
/*.................................................................................................................*/
/** returns build date of the Mesquite system (e.g., "22 September 2003") */
public final static String getBuildDate() {
return "28 February 2015";
return "1 March 2015";
}
/*.................................................................................................................*/
/** returns version of the Mesquite system */
Expand All @@ -90,7 +90,7 @@ public final static String getBuildLetter() {
public final static int getBuildNumber() {
//as of 26 Dec 08, build naming changed from letter + number to just number. Accordingly j105 became 473, based on
// highest build numbers of d51+e81+g97+h66+i69+j105 + 3 for a, b, c
return 693;
return 694;
}
//0.95.80 14 Mar 01 - first beta release
//0.96 2 April 01 beta - second beta release
Expand Down Expand Up @@ -2652,6 +2652,9 @@ public void processSingleXMLPreference (String tag, String flavor, String conten
module that the user requested as subemployee is passed as an argument.*/
public Class getHireSubchoice(){return null;}
/*.................................................................................................................*/
/** Returns duty Classes that module should NOT hire immediately upon hiring. */
public Class[] getDontHireSubchoice(){return null;}
/*.................................................................................................................*/
/** Called during Mesquite startup when the list of available modules is being constructed.*/
public void mesquiteStartup(){
}
Expand Down
18 changes: 17 additions & 1 deletion Source/mesquite/lib/MesquiteModuleInfo.java
Expand Up @@ -48,6 +48,7 @@ public class MesquiteModuleInfo implements Listable, CompatibilityChecker, Funct
Class mbClass;
Class dutyClass;
Class hireSubchoice;
Class[] dontHireSubchoice;
String directoryPath;
String splashURL;
String packageName;
Expand Down Expand Up @@ -99,6 +100,7 @@ public MesquiteModuleInfo (Class c, MesquiteModule mb, CommandChecker checker, S
this.mbClass = c;
isPrimaryChoice = mb.requestPrimaryChoice();
this.hireSubchoice = mb.getHireSubchoice();
this.dontHireSubchoice = mb.getDontHireSubchoice();
this.name = mb.getName(); //�
this.nameForMenuItem = mb.getNameForMenuItem(); //�
this.authors =mb.getAuthors();//�
Expand Down Expand Up @@ -393,10 +395,14 @@ public NexusBlockTest getNexusBlockTest(){
return nexusBlockTest;
}

/** returns the class of the module*/
/** returns the class of the employee desired*/
public Class getHireSubchoice() {
return hireSubchoice;
}
/** returns the classes that the employee shouldn't represent*/
public Class[] getDontHireSubchoice() {
return dontHireSubchoice;
}
/** Returns whether module is compatible with given object*/
public boolean isCompatible(Object obj, MesquiteProject project, EmployerEmployee prospectiveEmployer) {
return isCompatible(obj, project, prospectiveEmployer, null);
Expand Down Expand Up @@ -449,6 +455,16 @@ public boolean doesDuty (Class dutyClass) {
else
return false;
}
/** Returns whether module is instance of particular duty-defining class*/
public boolean doesADuty (Class[] dutyClasses) {
if (dutyClasses == null)
return false;
for (int i=0; i<dutyClasses.length; i++){
if (doesDuty(dutyClasses[i]))
return true;
}
return false;
}
public String getPackageName(){
return packageName;
}
Expand Down
62 changes: 58 additions & 4 deletions Source/mesquite/lib/ModulesInfoVector.java
Expand Up @@ -444,6 +444,48 @@ public MesquiteModuleInfo findModule(Class dutyClass, Object condition, Mesquite
return null;
}
/*........................................................................*/
/** Returns module information for first module found that is instance of dutyClass and satisfies given condition.
Returns null if none found.*/
public MesquiteModuleInfo findModuleFilteredByNot(Class dutyClass, Class[] notDutyClasses, Object condition, MesquiteProject project, EmployerEmployee prospectiveEmployer) {
int num = size();
// first, see if there is an available compatible default module
MesquiteModuleInfo mbi = findNextDefaultModuleFilteredByNot(dutyClass, notDutyClasses, -1, condition, project, prospectiveEmployer);
if (mbi!=null)
return mbi;

// Next, look among all of the modules to choose the first compatible one
for (int i=0; i<num; i++){
mbi = (MesquiteModuleInfo)elementAt(i);
if (mbi.doesDuty(dutyClass) && mbi.isCompatible(condition, project, prospectiveEmployer)){ //&& mbi.getUserChooseable()
return mbi;
}
}
return null;
}
/*........................................................................*/
/** Returns module information for next default module found, after the previousTH default, that is instance of dutyClass and satisfies given condition.
Returns null if none found.*/
public MesquiteModuleInfo findNextDefaultModuleFilteredByNot (Class dutyClass, Class[] notDutyClasses, int previous, Object condition, MesquiteProject project, EmployerEmployee prospectiveEmployer) {
int num = size();
MesquiteModuleInfo mbi;
String[] defaultModules = null;
boolean dutyClassFound = false;
// first, finding defaults
defaultModules =getDutyDefaults(dutyClass);
if (defaultModules==null || defaultModules.length == 0 || previous >= defaultModules.length-1)
return null;
if (previous<0)
previous = -1;
for (int i=previous+1; i<defaultModules.length; i++){

mbi = findModule(dutyClass, defaultModules[i]);
if (mbi !=null && mbi.doesDuty(dutyClass) && !mbi.doesADuty(notDutyClasses) && mbi.isCompatible(condition, project, prospectiveEmployer)){ //&& mbi.getUserChooseable()
return mbi;
}
}
return null;
}
/*........................................................................*/
/** Returns module information for next default module found, after the previousTH default, that is instance of dutyClass and satisfies given condition.
Returns null if none found.*/
public MesquiteModuleInfo findNextDefaultModule (Class dutyClass, int previous, Object condition, MesquiteProject project, EmployerEmployee prospectiveEmployer) {
Expand All @@ -467,6 +509,12 @@ public MesquiteModuleInfo findNextDefaultModule (Class dutyClass, int previous,
return null;
}
/*........................................................................*/
/** Returns module information for next module found, after previousModule, that is instance of dutyClass. However, also makes sure that the module found is NOT one of the notDutyClasses.
Returns null if none found. */
public MesquiteModuleInfo findNextModuleFilteredByNot (Class dutyClass, Class[] notDutyClasses, MesquiteModuleInfo previousModule) {
return findNextModule(dutyClass, notDutyClasses, previousModule, null, null, null);
}
/*........................................................................*/
/** Returns module information for next module found, after previousModule, that is instance of dutyClass.
Returns null if none found.*/
public MesquiteModuleInfo findNextModule (Class dutyClass, MesquiteModuleInfo previousModule) {
Expand All @@ -476,8 +524,14 @@ public MesquiteModuleInfo findNextModule (Class dutyClass, MesquiteModuleInfo pr
/** Returns module information for next module found, after previousModule, that is instance of dutyClass and satisfies given condition.
Returns null if none found.*/
public MesquiteModuleInfo findNextModule (Class dutyClass, MesquiteModuleInfo previousModule, Object condition, MesquiteProject project, EmployerEmployee prospectiveEmployer) {
return findNextModule(dutyClass, null, previousModule, condition, project, prospectiveEmployer);
}
/*........................................................................*/
/** Returns module information for next module found, after previousModule, that is instance of dutyClass and satisfies given condition. However, also makes sure that the module found is NOT one of the notDutyClasses
Returns null if none found. */
public MesquiteModuleInfo findNextModule (Class dutyClass, Class[] notDutyClasses, MesquiteModuleInfo previousModule, Object condition, MesquiteProject project, EmployerEmployee prospectiveEmployer) {
if (previousModule==null) {// no previous; find first module
return findModule(dutyClass, condition, project, prospectiveEmployer);
return findModuleFilteredByNot(dutyClass, notDutyClasses, condition, project, prospectiveEmployer);
}

boolean chooseNext = false;
Expand All @@ -489,7 +543,7 @@ public MesquiteModuleInfo findNextModule (Class dutyClass, MesquiteModuleInfo pr
if (defaultModules!=null && defaultModules.length>=1) { //check if there is a subsequent default
defaultsExist = true;
if (previousModule == null){
MesquiteModuleInfo fmbi =findNextDefaultModule(dutyClass, -1, condition, project, prospectiveEmployer);
MesquiteModuleInfo fmbi =findNextDefaultModuleFilteredByNot(dutyClass, notDutyClasses, -1, condition, project, prospectiveEmployer);
if (fmbi!=null)
return fmbi;
}
Expand All @@ -502,7 +556,7 @@ public MesquiteModuleInfo findNextModule (Class dutyClass, MesquiteModuleInfo pr
chooseNext = true;
}
else if (where<defaultModules.length-1){
MesquiteModuleInfo fmbi =findNextDefaultModule(dutyClass, where, condition, project, prospectiveEmployer);
MesquiteModuleInfo fmbi =findNextDefaultModuleFilteredByNot(dutyClass, notDutyClasses, where, condition, project, prospectiveEmployer);
if (fmbi!=null)
return fmbi;
}
Expand All @@ -515,7 +569,7 @@ else if (where<defaultModules.length-1){
for (int i=0; i<num; i++){ //next, go through non-defaults
mbi = (MesquiteModuleInfo)elementAt(i); //If there are defaults, don't choose if is default (otherwise defaults will be chosen more than once
if (chooseNext) {
if (mbi.doesDuty(dutyClass)){
if (mbi.doesDuty(dutyClass) && !mbi.doesADuty(notDutyClasses)){
if ((!defaultsExist || whichDefault(defaultModules, mbi)<0) && mbi.isCompatible(condition, project, prospectiveEmployer)) { //&& mbi.getUserChooseable()
return mbi;
}
Expand Down
44 changes: 44 additions & 0 deletions Source/mesquite/search/OtherTreeSearch/OtherTreeSearch.java
@@ -0,0 +1,44 @@
/* Mesquite source code. Copyright 1997 and onward, W. Maddison and D. Maddison.
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.search.OtherTreeSearch;
/*~~ */

import mesquite.lib.*;
import mesquite.lib.duties.TreeSearcher;
import mesquite.search.lib.*;

/* ======================================================================== */
public class OtherTreeSearch extends TreeSearch {
public String getName() {
return "Other Tree Inference";
}
public String getExplanation() {
return "Supplies trees resulting from other criteria.";
}
/*.................................................................................................................*/
public Class getHireSubchoice(){
return TreeSearcher.class;
}
/*.................................................................................................................*/
public Class[] getDontHireSubchoice(){
return new Class[]{LikelihoodAnalysis.class, DistanceAnalysis.class, ParsimonyAnalysis.class, BayesianAnalysis.class};
}
/*.................................................................................................................*/
/** returns whether this module is requesting to appear as a primary choice */
public boolean requestPrimaryChoice(){
return false;
}

}

0 comments on commit 6c76a3a

Please sign in to comment.