/** * Check whether this applet is an Exercise * * @return true if the Exercise has assignments, this will happen when * either {@link #getExerciseResult()} or * {@link #getExerciseFraction()} are called with user defined Tools * present in the applet or if the ExerciseBuilderDialog was used to * create the Exercise. */ @Override public boolean isExercise() { Exercise ex = kernel.getExercise(); return !ex.isEmpty(); }
/** * Returns XML representation of given macros and/or exercise in the kernel, * including header. * * @param macros * list of macros * @return XML representation of given macros in the kernel. */ public String getFullMacroXML(ArrayList<Macro> macros) { StringBuilder sb = new StringBuilder(); addXMLHeader(sb); addGeoGebraHeader(sb, true, null, app.getVersion()); // save construction sb.append(kernel.getMacroXML(macros)); sb.append(kernel.getExercise().getExerciseXML()); sb.append("</geogebra>"); return sb.toString(); }
/** * If there are Macros or an Exercise present in the current file this can * be used to check if parts of the construction are equivalent to the * Macros in the file. <br> * It will return the overall Fraction of the Exercise.<br> * This is the sum of all the Fractions in the Assignment or 1 if one of the * Assignments has a fraction of 100 and no negative fractions are present. * Use {@link #getExerciseResult()} to get the fractions of each Assignment. * If you don't want that a standard exercise (using all the Macros in the * Construction and setting each fraction to 100) will be created, check if * this is a Exercise with {@link #isExercise()} first. <br> * * @return the overall fraction of the Exercise * */ @Override public double getExerciseFraction() { Exercise ex = kernel.getExercise(); ex.checkExercise(); return ex.getFraction(); }
/** * Tells conidition listeners that their condition is removed and calls * super.remove() */ @Override public void doRemove() { if (condListenersShowObject != null) { // copy conditionListeners into array Object[] geos = condListenersShowObject.toArray(); condListenersShowObject.clear(); // tell all condition listeners for (int i = 0; i < geos.length; i++) { GeoElement geo = (GeoElement) geos[i]; geo.removeCondition(this); kernel.notifyUpdate(geo); } } if (kernel.hasExercise()) { kernel.getExercise().notifyUpdate(); } super.doRemove(); }
private void initExercise(LinkedHashMap<String, String> attrs) { if (exercise == null) { exercise = kernel.getExercise(); exercise.reset();
/** * @return XML for or macros and/or Exercise or empty string if there are * none */ public String getMacroXMLorEmpty() { if (!kernel.hasMacros() && kernel.getExercise().isEmpty()) { return ""; } ArrayList<Macro> macros = kernel.getAllMacros(); return getXMLio().getFullMacroXML(macros); }
/** * Will delete all Macros and add all macros in order * * @param macros * the Macros to be added */ public void addMacros(Object[] macros) { // update order of macros: // remove all macros from kernel and add them again in new order Kernel kernel = app.getKernel(); // since all Macros are removed and added back, the Assignments have // also be added again so: // keeping "pointers" on the Assignments in the Exercise to put them // in Place afterwards (the Exercise checks if they are still valid) Exercise ex = app.getKernel().getExercise(); ArrayList<Assignment> assignments = new ArrayList<>( ex.getParts()); kernel.removeAllMacros(); for (Object obj : macros) { kernel.addMacro((Macro) obj); } for (Assignment assignment : assignments) { ex.addAssignment(assignment); } }
/** * Removes all macros from the kernel. */ public void removeAllMacros() { if (macroManager != null) { getApplication().removeMacroCommands(); macroManager.removeAllMacros(); } // Also remove all Assignments if (hasExercise()) { getExercise().removeAllAssignments(); } app.dispatchEvent(new Event(EventType.REMOVE_MACRO, null, null)); }
/** * Removes a macro from the kernel. */ public void removeMacro(Macro macro) { if (macroManager != null) { macroManager.removeMacro(macro); } // Also remove Assignments using this macro from Exercise if (hasExercise()) { Exercise ex = getExercise(); if (!ex.isEmpty() && ex.usesMacro(macro)) { ex.removeAssignment(macro); } } app.dispatchEvent(new Event(EventType.REMOVE_MACRO, null, macro.getCommandName())); }
StringBuilder sb = new StringBuilder(); newTool.getXML(sb); Exercise ex = app.getKernel().getExercise(); GeoAssignment assignment = ex.getAssignment(macro); int assignmentIndex = ex.getParts().indexOf(assignment);
@Override public JSONObject getExerciseResult() { Exercise ex = kernel.getExercise(); ex.checkExercise(); JSONObject result = new JSONObject(); ArrayList<Assignment> parts = ex.getParts(); try { for (Assignment part : parts) { JSONObject partresult = new JSONObject(); result.put(part.getDisplayName(), partresult); partresult.put("result", part.getResult().name()); String hint = part.getHint(); hint = hint == null ? "" : hint; partresult.put("hint", hint); partresult.put("fraction", part.getFraction()); } } catch (Exception e) { // how? } return result; }