package edu.jsu.leathrum.mathlets.shared; import javax.swing.*; import java.awt.event.*; import java.util.Locale; import java.util.ResourceBundle; import java.text.DecimalFormat; import java.util.PropertyResourceBundle; import java.util.MissingResourceException; abstract public class AMathlet extends JApplet { // abstract method: draw(), localinit(), localclear() // call setHandler() to set up field handling // register buttons with registerButtonAction() // some standard button actions with registerGraphButton(), registerClearButton() ButtonList bb = new ButtonList(); class ClearAction implements ActionWrapper { public void doThis() { clear(); draw(); } } class GraphAction implements ActionWrapper { public void doThis() { draw(); } } public void registerButtonAction(AbstractButton item, ActionWrapper act) { bb.registerButtonAction(item, act); } // must be called in localinit(), not constructor, because of getProperty() public void registerClearButton(JButton item) { item.setText(getProperty("clear")); bb.registerButtonAction(item, new ClearAction()); } // must be called in localinit(), not constructor, because of getProperty() public void registerGraphButton(JButton item) { item.setText(getProperty("graph")); bb.registerButtonAction(item, new GraphAction()); } KeyHandlerSequence kseq = new KeyHandlerSequence(); public void registerInputSet(InputSet item, ActionWrapper act) { kseq.registerKeyHandler(item, act); bb.registerButtonAction(item.getCheckBox(), act); } public void registerInputSet(InputSet item) { registerInputSet(item, new GraphAction()); } public abstract void draw(); public void jsDraw() { draw(); } final static int FIELDS = 10; static String[] fields = new String[FIELDS]; static FieldHandler[] handlers = new FieldHandler[FIELDS]; static int numfields = 0; public static void setHandler(String name, FieldHandler obj) { // static so that it can be called anywhere to register defaults while (numfields>=fields.length) { String[] tmp1 = new String[fields.length+2*FIELDS]; FieldHandler[] tmp2 = new FieldHandler[handlers.length+2*FIELDS]; for (int i=0; i-1) handlers[j].setField(value); } public void localclear() {} // often overridden to clear graph objects and such // but some applets don't need this method, so it isn't abstract public void clear() { for (int i=0; i-1) return handlers[j].getField(); else return ""; } private static Locale currentLocale = Locale.ENGLISH; public static Locale getLoc() { return currentLocale; } private static DecimalFormat nf = (DecimalFormat) DecimalFormat.getNumberInstance(currentLocale); public static DecimalFormat getNumberFormat() { return nf; } private static final int MAXFILES = 20; private static PropertyResourceBundle properties[] = new PropertyResourceBundle[MAXFILES]; private void checkForLocaleParams() { try { // parameters to determine locale checked here // get NullPointerExceptions from calls to getParameter() // when running as application rather than applet // if so, catch them, do nothing String lang = getParameter("language"); String ctry = getParameter("country"); if (lang != null) { if (ctry != null) currentLocale = new Locale(lang,ctry); else currentLocale = new Locale(lang); } } catch (NullPointerException e) {} // open ALL properties files, using locale info // MathletsB can override MathletsA, C can override B, etc. // and can skip filenames in the sequence // but no further down than MathletsT (based on MAXFILES value) int i = 0; for (int n=0; n