jas-plotter-2.2.10/0000755000265600020320000000000014746176464013352 5ustar andreasadminjas-plotter-2.2.10/pom.xml0000644000265600020320000000425113035754550014655 0ustar andreasadmin 4.0.0 global org.freehep 22.0 org.freehep jas-plotter 2.2.10 JAS(2) Plotter JAS(2) Plotter freehep-maven2-public Maven FreeHEP http://srs.slac.stanford.edu/nexus/content/groups/freehep-maven2-public/ freehep-site FreeHep Maven2 centreal site repository dav:http://srs.slac.stanford.edu/nexus/content/sites/freehep-site/jas-plotter http://java.freehep.org/svn/repos/freehep/list/freehep/tags/jas-plotter-2.2.10 scm:svn:svn://svn.freehep.org/svn/freehep/tags/jas-plotter-2.2.10 scm:svn:svn://svn.freehep.org/svn/freehep/tags/jas-plotter-2.2.10 org.freehep freehep-graphicsbase 2.2.1 test junit junit test maven-surefire-plugin 2.14 true jas-plotter-2.2.10/src/0000755000265600020320000000000014746176422014133 5ustar andreasadminjas-plotter-2.2.10/src/main/0000755000265600020320000000000014746176463015064 5ustar andreasadminjas-plotter-2.2.10/src/main/java/0000755000265600020320000000000014746176465016007 5ustar andreasadminjas-plotter-2.2.10/src/main/java/jas/0000755000265600020320000000000014746176455016563 5ustar andreasadminjas-plotter-2.2.10/src/main/java/jas/util/0000755000265600020320000000000014746176455017540 5ustar andreasadminjas-plotter-2.2.10/src/main/java/jas/util/ImageException.java0000644000265600020320000000036310631354456023272 0ustar andreasadminpackage jas.util; /** * An Exception to be thrown in case of problems loading an image. * @see JASIcon */ public class ImageException extends Exception { ImageException() { super(); } ImageException(String message) { super(message); } } jas-plotter-2.2.10/src/main/java/jas/util/PropertySite.java0000644000265600020320000000011210631354456023032 0ustar andreasadminpackage jas.util; public interface PropertySite { void callEnable(); } jas-plotter-2.2.10/src/main/java/jas/util/CommandProcessor.java0000644000265600020320000001451010631357137023645 0ustar andreasadminpackage jas.util; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Observable; /** * A CommandProcessor represents a collection of CommandTargets. The CommandProcessor is Observable, * and is normally Observed by the CommandTargetManager. When the CommandProcessor calls * its notifyObservers method, the CommandTargetManager prompts each CommandSource currently * attached to CommandTargets within the CommandProcessor to update their enabled/disabled status. * * Typically applications provide their own CommandProcessor(s) which extend this base class * and which can handle a set of commands. By default CommandProcessor's acceptCommand method * uses reflection to search for methods in the subClass which correspond to specific commands, * although subclasses could also override the acceptCommand method to implement a different * scheme. The default scheme looks for methods of type: *
 *            public void onXXX()
 * 
* to handle the command XXX. Also *
 *            public void enableXXX(JASState state)
 * 
* to determine if the command is active or not. * @dependency jas.util.CommandProcessor$SimpleTarget creates * @dependency jas.util.CommandProcessor$BooleanTarget creates */ public class CommandProcessor extends Observable { protected String translate(String command) { if (command.endsWith("...")) command = command.substring(0,command.length()-3); for (int i=command.indexOf(" "); i >= 0; i=command.indexOf(" ")) command = command.substring(0,i)+command.substring(i+1); return command; } protected void setChanged() { super.setChanged(); notifyObservers(); } protected void setManager(CommandTargetManager m) { } /** * The CommandTargetManager called acceptCommand to find out if this CommandProcessor * can respond to the specified command. If it can it returns a CommandTarget for the command, * otherwise it returns null. * */ protected CommandTarget acceptCommand(String command) { String t = translate(command); String c = "on"+t; String e = "enable"+t; Method mc,me; try { mc = this.getClass().getMethod(c,noArg); try { me = this.getClass().getMethod(e,simpleEnableArg); } catch (NoSuchMethodException x) { me = null; } try // Support for RadioMenuItem { if (me == null) me = this.getClass().getMethod(e,booleanEnableArg); } catch (NoSuchMethodException x) { me = null; } return new SimpleTarget(mc,me); } catch (NoSuchMethodException x) { } try { mc = this.getClass().getMethod(c,boolArg); try { me = this.getClass().getMethod(e,booleanEnableArg); } catch (NoSuchMethodException x) { me = null; } return new BooleanTarget(mc,me); } catch (NoSuchMethodException x) { } return null; } protected void invoke(Method method,Object[] args) throws IllegalAccessException,InvocationTargetException { method.invoke(this,args); } protected void invokeEnable(Method method,Object[] args) throws IllegalAccessException,InvocationTargetException { invoke(method,args); } protected void invokeCommand(Method method,Object[] args) throws IllegalAccessException,InvocationTargetException { invoke(method,args); } protected void invokeCommand(SimpleTarget t) { try { t.doCommand(); } catch (CommandInvocationException x) { System.err.println("Error during command invocation: "+x.getTargetException()); } } protected void invokeCommand(BooleanTarget t, boolean arg) { try { t.doCommand(arg); } catch (CommandInvocationException x) { System.err.println("Error during command invocation: "+x.getTargetException()); } } private static final Class noArg[] = {}; private static final Object noArgs[] = {}; private static final Class boolArg[] = {java.lang.Boolean.TYPE}; private static final Class simpleEnableArg[] = {JASState.class}; private static final Class booleanEnableArg[] = {JASCheckboxState.class}; /** * A SimpleTarget is an implementation of CommandTarget which implements its * */ protected class SimpleTarget implements SimpleCommandTarget { SimpleTarget(Method command, Method enable) { m_command = command; m_enable = enable; } public void invoke() { CommandProcessor.this.invokeCommand(this); } public void doCommand() throws CommandInvocationException { try { invokeCommand(m_command,noArgs); } catch (IllegalAccessException x) { throw new RuntimeException("IllegalAccessException during command invocation"); } catch (InvocationTargetException x) { throw new CommandInvocationException(x.getTargetException()); } } public void enable(JASState state) { if (m_enable == null) state.setEnabled(true); else { try { Object[] args = { state }; invokeEnable(m_enable, args); } catch (IllegalAccessException x) { state.setEnabled(false); } catch (InvocationTargetException x) { state.setEnabled(false); } } } public CommandProcessor getProcessor() { return CommandProcessor.this; } private Method m_command; private Method m_enable; } protected class BooleanTarget implements BooleanCommandTarget { BooleanTarget(Method command, Method enable) { m_command = command; m_enable = enable; } public void invoke(boolean arg) { CommandProcessor.this.invokeCommand(this,arg); } public void enable(JASState state) { if (m_enable == null) state.setEnabled(true); else { try { Object[] args = { (JASCheckboxState) state }; invokeEnable(m_enable, args); } catch (IllegalAccessException x) { state.setEnabled(false); } catch (InvocationTargetException x) { state.setEnabled(false); } } } public void doCommand(boolean arg) throws CommandInvocationException { try { Object[] args = { new Boolean(arg) }; invokeCommand(m_command,args); } catch (IllegalAccessException x) { throw new RuntimeException("IllegalAccessException during command invocation"); } catch (InvocationTargetException x) { throw new CommandInvocationException(x.getTargetException()); } } public CommandProcessor getProcessor() { return CommandProcessor.this; } private Method m_command; private Method m_enable; } } jas-plotter-2.2.10/src/main/java/jas/util/PropertyDialog.java0000644000265600020320000000473310631357137023341 0ustar andreasadminpackage jas.util; import java.awt.Frame; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class PropertyDialog extends JASDialog implements PropertySite, ChangeListener { protected PropertyDialog(Frame f,String title,Object bean) { super(f,title,true,OK_BUTTON|APPLY_BUTTON|CANCEL_BUTTON|HELP_BUTTON); m_tab_manager = new JTabbedPane(); m_tab_manager.addChangeListener(this); setContentPane(m_tab_manager); m_currentPage = null; m_bean = bean; } protected void addPage(final String name, final PropertyPage p, final boolean select) { m_tab_manager.addTab(name,p); p.setPropertySite(this); if (select) m_tab_manager.setSelectedComponent(p); } public void stateChanged(ChangeEvent evt) { if (m_suppressChangeEvents) return; // don't receive change events that this method creates if (m_currentPage == null || m_currentPage.hasValidInput()) // notification of invalid input is the responsibility of the field binding { doDataExchange(true); if (m_currentPage != null) m_currentPage.deactivate(); m_currentPage = (PropertyPage) m_tab_manager.getSelectedComponent(); m_currentPage.activate(); doDataExchange(false); setHelpTopic(m_currentPage.getHelpTopic()); super.callEnable(); } else { m_suppressChangeEvents = true; // ignore change event from the call below m_tab_manager.setSelectedComponent(m_currentPage); // return to page that was not valid m_suppressChangeEvents = false; // allow change events again } } private void doDataExchange(boolean set) { // guaranteed by this point to be valid input if (m_currentPage != null) m_currentPage.doDataExchange(set,m_bean); } public void enableApply(JASState state) { state.setEnabled(m_currentPage.hasChanged()); } public void callEnable() { super.callEnable(); } public void onApply() { if (m_currentPage.hasValidInput()) // notification of invalid input is the responsibility of the field binding { doDataExchange(true); doDataExchange(false); // In case other values change super.onApply(); super.callEnable(); } } public void onOK() { if (m_currentPage.hasValidInput()) { doDataExchange(true); m_currentPage.deactivate(); super.onOK(); } } public void onCancel() { m_currentPage.deactivate(); super.onCancel(); } private Object m_bean; private JTabbedPane m_tab_manager; private PropertyPage m_currentPage; private boolean m_suppressChangeEvents = false; } jas-plotter-2.2.10/src/main/java/jas/util/Debug.java0000644000265600020320000000470010631357137021415 0ustar andreasadminpackage jas.util; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; public class Debug { public static void init() { if (debugInitialized) return; try { theStdOutFile = new File(theStdOutFileName); theStdErrFile = new File(theStdErrFileName); PrintStream outFile = new PrintStream( new BufferedOutputStream( new FileOutputStream(theStdOutFile))); PrintStream errFile = new PrintStream( new BufferedOutputStream( new FileOutputStream(theStdErrFile))); theFileOutWriter = new PrintWriter(outFile, true); theFileErrWriter = new PrintWriter(errFile, true); } catch (IOException eh) { System.out.println("IOException initializing Debug system!"); eh.printStackTrace(); } debugInitialized = true; } public static void setFileOutput() { redirectToFile = true; } public static void setNormalOutput() { redirectToFile = false; } public static void pushFileOutput() { oldRedirectValue = redirectToFile; redirectToFile = true; } public static void pushNormalOutput() { oldRedirectValue = redirectToFile; redirectToFile = false; } public static void popOutput() { redirectToFile = oldRedirectValue; } public static void say(String s) { init(); if (redirectToFile) { theFileOutWriter.println(s); } else { theConsoleOutWriter.println(s); } } public static void complain(String s) { init(); if (redirectToFile) { theFileErrWriter.println(s); } else { theConsoleErrWriter.println(s); } } public static void debugSay(String s) { if (debugMode) { say(s); } } public static void debugComplain(String s) { if (debugMode) { complain(s); } } private static File theStdOutFile; private static File theStdErrFile; private static final PrintWriter theConsoleOutWriter = new PrintWriter(System.out, true); private static final PrintWriter theConsoleErrWriter = new PrintWriter(System.err, true); private static PrintWriter theFileOutWriter; private static PrintWriter theFileErrWriter; private static final String theStdOutFileName = "stdout.txt"; private static final String theStdErrFileName = "stderr.txt"; private static final boolean debugMode = true; private static boolean debugInitialized = false; private static boolean redirectToFile = false; private static boolean oldRedirectValue = false; } jas-plotter-2.2.10/src/main/java/jas/util/NestedRuntimeException.java0000644000265600020320000000265410631354456025043 0ustar andreasadminpackage jas.util; public class NestedRuntimeException extends RuntimeException implements HasNestedException { private Throwable detail; /** * Create a nested exception with the specified string */ public NestedRuntimeException(Throwable ex) { super(); detail = ex; } /** * Create a remote exception with the specified string, and the * exception specified. */ public NestedRuntimeException(String s, Throwable ex) { super(s); detail = ex; } public Throwable getNestedException() { return detail; } /** * Produce the message, include the message from the nested * exception if there is one. */ public String getMessage() { return NestedException.formatNestedException(this); } /** * Return just the super classes message */ public String getSimpleMessage() { return super.getMessage(); } public void printStackTrace() { super.printStackTrace(); if (detail != null) { System.err.println("Nested Exception is:"); detail.printStackTrace(); } } public void printStackTrace(java.io.PrintStream s) { super.printStackTrace(s); if (detail != null) { s.println("Nested Exception is:"); detail.printStackTrace(s); } } public void printStackTrace(java.io.PrintWriter s) { super.printStackTrace(s); if (detail != null) { s.println("Nested Exception is:"); detail.printStackTrace(s); } } } jas-plotter-2.2.10/src/main/java/jas/util/ErrorBox.java0000644000265600020320000001350510631357137022134 0ustar andreasadminpackage jas.util; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.PrintWriter; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.UIManager; /** * This class is used to show the user that an error has occurred. * If the error is in the form of a Throwable (normally an * Exception, but possibly an Error) then that object can be passed * to the error box so that the user can be notified of the exact * error. Invoke doModal() on the object to show the error. * @see java.lang.Throwable * @see java.lang.Exception * @see java.lang.Error * @author Tony Johnson * @author Jonas Gifford */ public class ErrorBox extends JASDialog { /** * Opens an ErrorBox with no help button and no displayed Throwable. * @param parent the parent JFrame * @param message a String to display as a message */ public ErrorBox(JFrame parent, String message) { this(parent, message, null, null); } /** * Opens an ErrorBox that has a Help button that opens the specified topic. Help books * are accessible throught static constants in the Application class. * @see Application * @param parent the parent JFrame * @param message a String to display as a message * @param helpTopic the help topic (as specified in the .oht topics file for the specified book) */ public ErrorBox(JFrame parent, String message, String helpTopic) { this(parent, message, null, helpTopic); } /** * Opens an ErrorBox that displays a Throwable, but has no help button. Book objects * are accessible through static constants in the Application class. * @see Application * @param parent the parent JFrame * @param message a String to display as a message * @param throwable the Error or Exception that was generated */ public ErrorBox(JFrame parent, String message, Throwable throwable) { this(parent,message,throwable,null); } /** * Opens an ErrorBox that displays a Throwable and has a Help button * that opens the specified topic. Book objects are available through * the Application class. * @see Application * @param parent the parent JFrame * @param message a String to display as a message * @param throwable the Error or Exception that was generated * @param helpTopic the help topic (XML target) */ public ErrorBox(JFrame parent, String message, Throwable throwable, String helpTopic) { super(parent, "Error...", true, OK_BUTTON | (throwable != null ? APPLY_BUTTON | CANCEL_BUTTON : 0) | (helpTopic != null ? HELP_BUTTON : 0)); if (helpTopic != null) setHelpTopic(helpTopic); init(message, throwable,parent); } private void init(String m, Throwable t,JFrame parent) { setApplyLabel("Details"); setApplyMnemonic('D'); setCancelLabel("Traceback"); setCancelMnemonic('T'); JPanel p = new JPanel(); p.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon"))); p.add(new JLabel(m)); getContentPane().add(p,BorderLayout.NORTH); m_frame = parent; m_throw = t; m_details = (t != null); pack(); getToolkit().beep(); } /** Inherited from JASDialog; do not call. */ final protected void enableApply(JASState state) { state.setEnabled(m_details); } /** Inherited from JASDialog; do not call. */ final protected void onCancel() { // We used to use a JASDialog here, but it needs a Frame as its parent. // This cannot be fixed while maintaining JDK 1.1 compatibility, so instead // we swicthed to using a JOptionPane. JTextArea ta = new JTextArea(); PrintWriter pw = new PrintWriter(new DocumentOutputStream(ta.getDocument())); m_throw.printStackTrace(pw); pw.close(); ta.setEditable(false); ta.addMouseListener(new PopupListener(new PopupMenu(ta))); JScrollPane scroll = new JScrollPane(ta); scroll.setPreferredSize(new Dimension(500,300)); JOptionPane.showMessageDialog(this,scroll,"Traceback...",JOptionPane.PLAIN_MESSAGE); } /** Inherited from JASDialog; do not call. */ final protected void onApply() { JTextArea text = new JTextArea(m_throw.toString()); text.setEditable(false); text.addMouseListener(new PopupListener(new PopupMenu(text))); JScrollPane scroll = new JScrollPane(); scroll.setViewportView(text); getContentPane().add(scroll,BorderLayout.CENTER); pack(); m_details = false; callEnable(); } private static class PopupMenu extends OnScreenPopupMenu implements ActionListener { private JTextArea parent; JMenuItem copy = new JMenuItem("Copy",'C'); JMenuItem select = new JMenuItem("Select All",'S'); PopupMenu(JTextArea parent) { this.parent = parent; copy.addActionListener(this); select.addActionListener(this); add(copy); add(select); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == select) parent.selectAll(); else if (source == copy) parent.copy(); } } private static class PopupListener extends MouseAdapter { private JPopupMenu menu; PopupListener(JPopupMenu menu) { this.menu = menu; } public void mouseReleased(MouseEvent me) { maybePopup(me); } public void mousePressed(MouseEvent me) { maybePopup(me); } private void maybePopup(MouseEvent me) { if (menu.isPopupTrigger(me)) menu.show(me.getComponent(),me.getX(),me.getY()); } } private Throwable m_throw; private boolean m_details; private JFrame m_frame; }jas-plotter-2.2.10/src/main/java/jas/util/HasNextPages.java0000644000265600020320000000243710631354456022727 0ustar andreasadminpackage jas.util; /** * A JASWizardPage that implements this interface will have one or more subsequent * pages. When a page that implements this interface is showing in a JASWizard, * the "Next" button will be enabled. A sensible wizard page would implement this * interface, or the Finishable interface, or both. If you implement neither then * neither the "Next" nor "Finish" button will enable on the wizard, and you page * will be a "dead end". * @author Jonas Gifford * @see JASWizardPage * @see JASWizard * @see Finishable */ public interface HasNextPages { /** * Returns an array of all possible next pages. There could, of course, be just * one element in this array. This method will be called before the wizard * shows on the screen. The wizard needs to know all of the possible pages so that * it can size itself to fit them all. * @return an array of all possible subsequent pages */ public abstract JASWizardPage[] getNextWizardPages(); /** * This method is called when the user clicks on the "Next" button. You must * return a page that was in the array returned by getNextWizardPages. * @return a JASWizardPage that was included in the array returned by getNextWizardPages */ public abstract JASWizardPage getNext(); } jas-plotter-2.2.10/src/main/java/jas/util/JTextFieldBinding.java0000644000265600020320000000557410631357137023676 0ustar andreasadminpackage jas.util; import java.lang.reflect.Constructor; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; public class JTextFieldBinding extends FieldBinding implements DocumentListener { protected JTextFieldBinding(JTextField field, byte flags) { this(field); m_flags = flags; } protected JTextFieldBinding(JTextField field) { m_field = field; field.getDocument().addDocumentListener(this); } void set(Object value) { String x = setValue(value); if (!m_oldVal.equals(x)) { m_field.setText(x); m_oldVal = x; } } protected String setValue(Object value) { String x; if (value == null) x = ""; else if (value instanceof String) x = (String) value; else x = value.toString(); return x; } protected Object getValue(String value, Class type) throws UnsupportedType { if (type.isPrimitive()) { if (type == Double.TYPE ) return new Double(value); if (type == Integer.TYPE) return new Integer(value); throw new UnsupportedType(m_field,type); } else { Class[] strarg = { value.getClass() }; try { Constructor c = type.getConstructor(strarg); Object[] args = { value }; return c.newInstance(args); } catch (Exception xx) { throw new UnsupportedType(m_field,type); } } } Object get(Class type) throws UnsupportedType { return getValue(m_field.getText(),type); } public void changedUpdate(DocumentEvent e) { update(); } public void insertUpdate(DocumentEvent e) { update(); } public void removeUpdate(DocumentEvent e) { update(); } private void update() { String x = m_field.getText(); if (!x.equals(m_oldVal)) setChanged(); notifyObservers(); } protected void reset() { super.reset(); m_oldVal = m_field.getText(); } boolean hasValidInput() { final String value = m_field.getText(); if ((m_flags & MUST_BE_NUMBER) != 0) { try { double d = (m_flags & MUST_BE_INTEGER_FLAG) != 0 ? (double) Integer.parseInt(value) : Double.valueOf(value).doubleValue(); if ((m_flags & MUST_BE_POSITIVE) != 0 && d <= 0.0) { JOptionPane.showMessageDialog(m_field, value.concat(" is invalid input; value must be positive."), "Error", JOptionPane.ERROR_MESSAGE); return false; } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(m_field, value +" is invalid input; value must be a"+ ((m_flags & MUST_BE_INTEGER) != 0 ? "n integer." : " number."), "Error", JOptionPane.ERROR_MESSAGE); return false; } } return true; } private String m_oldVal = ""; private JTextField m_field; private byte m_flags = 0; public static final byte MUST_BE_NUMBER = 1; private static final byte MUST_BE_INTEGER_FLAG = 2; public static final byte MUST_BE_INTEGER = MUST_BE_INTEGER_FLAG | MUST_BE_NUMBER; public static final byte MUST_BE_POSITIVE = 4; } jas-plotter-2.2.10/src/main/java/jas/util/JASDialog.java0000644000265600020320000003222210631357137022124 0ustar andreasadminpackage jas.util; import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dialog; import java.awt.Frame; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowEvent; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; /** * JASDialog extends the built in java dialog to provide a number of extra features * * To make components visible on this dialog, add them to the content pane. * @see JASDialog#getContentPane() * @author Tony Johnson */ public class JASDialog extends JDialog implements MouseListener, DocumentListener { /** Include this in your flags to include an OK button. */ public final static int OK_BUTTON = 1; /** Include this in your flags to include an Apply button. */ public final static int APPLY_BUTTON = 2; /** Include this in your flags to include a Cancel button. */ public final static int CANCEL_BUTTON = 4; /** Include this in your flags to include a Help button. */ public final static int HELP_BUTTON = 8; public static JASDialog create(Frame frame, String title) { return create(frame, title, true, OK_BUTTON | CANCEL_BUTTON); } public static JASDialog create(Frame frame, String title, boolean modal) { return create(frame, title, modal, OK_BUTTON | CANCEL_BUTTON); } public static JASDialog create(Component c,String t,boolean modal,int flags) { Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class,c); if (w instanceof Frame ) return new JASDialog((Frame) w,t,modal,flags); else if (w instanceof Dialog) return new JASDialog((Dialog) w,t,modal,flags); else throw new RuntimeException("No dialog parent found"); } /** * Creates a modal dialog with OK and Cancel buttons. * @param frame the parent frame * @param title the title for the dialog box */ public JASDialog(Frame frame, String title) { this(frame, title, true, OK_BUTTON | CANCEL_BUTTON); } /** * Creates a dialog with OK and Cancel buttons. * @param frame the parent frame * @param title the title for the dialog box * @param modal whether the dialog box is modal */ public JASDialog(Frame frame, String title, boolean modal) { this(frame, title, modal, OK_BUTTON | CANCEL_BUTTON); } /** * Creates a dialog box with any combination of buttons. Use bitwise * logic to specify the appropriate flags in the flags * parameter. For example,
* JASDialog.OK_BUTTON | JASDialog.CANCEL_BUTTON | JASDialog.HELP_BUTTON
* when passed as the flags parameter will create a button * that has an OK button, a Cancel button, and a Help button. * @param dlg the parent Dialog * @param title the title for the dialog box * @param modal whether the dialog box is modal * @param flags option flags */ public JASDialog(Frame f,String t,boolean modal,int flags) { super(f,t,modal); init(f,flags); } /** * Creates a modal dialog with OK and Cancel buttons. * @param frame the parent frame * @param title the title for the dialog box */ public JASDialog(Dialog dlg, String title) { this(dlg, title, true, OK_BUTTON | CANCEL_BUTTON); } /** * Creates a dialog with OK and Cancel buttons. * @param dlg the parent Dialog * @param title the title for the dialog box * @param modal whether the dialog box is modal */ public JASDialog(Dialog dlg, String title, boolean modal) { this(dlg, title, modal, OK_BUTTON | CANCEL_BUTTON); } /** * Creates a dialog box with any combination of buttons. Use bitwise * logic to specify the appropriate flags in the flags * parameter. For example,
* JASDialog.OK_BUTTON | JASDialog.CANCEL_BUTTON | JASDialog.HELP_BUTTON
* when passed as the flags parameter will create a button * that has an OK button, a Cancel button, and a Help button. * @param dlg the parent Dialog * @param title the title for the dialog box * @param modal whether the dialog box is modal * @param flags option flags */ public JASDialog(Dialog dlg,String t,boolean modal,int flags) { super(dlg,t,modal); init(dlg,flags); } private void init(Window w, int flags) { m_window = w; m_flags = flags; ActionListener l = new ActionEventHandler(); m_ok = new JButton("OK"); m_ok.addActionListener(l); m_ok.setMnemonic('O'); m_apply = new JButton("Apply"); m_apply.setMnemonic('A'); m_apply.addActionListener(l); m_cancel = new JButton("Cancel"); m_cancel.setMnemonic('C'); m_cancel.addActionListener(l); m_help = new JButton("Help"); m_help.setMnemonic('H'); m_help.addActionListener(l); m_buttonPanel = new JPanel(); super.getContentPane().add(m_buttonPanel,BorderLayout.SOUTH); enableEvents(AWTEvent.WINDOW_EVENT_MASK); JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); super.getContentPane().add(p,BorderLayout.CENTER); m_contentPane = p; } /** * Causes a default pack(), but also places the dialog in the center * of the parent frame. * @see java.awt.Window#pack() */ public void pack() { defaultPack(); setLocationRelativeTo(m_window); } /** Causes default pack; does not move dialog. */ public void defaultPack() { if (m_buttonPanel.getComponentCount() == 0) { if ((m_flags & OK_BUTTON) !=0) m_buttonPanel.add(m_ok); if ((m_flags & APPLY_BUTTON) !=0) m_buttonPanel.add(m_apply); if ((m_flags & CANCEL_BUTTON) !=0) m_buttonPanel.add(m_cancel); if ((m_flags & HELP_BUTTON) !=0) m_buttonPanel.add(m_help); } super.pack(); } /** This method is public as an implementation side effect; do not call or override. */ public void processEvent(AWTEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) onCancel(); super.processEvent(e); } /** * Forces a modal display of the dialog box * @return true if the OK button was pushed, otherwise false */ public boolean doModal() { m_result = false; setModal(true); show(); return m_result; } public void show() { callEnable(); if (isModal() && app != null) app.modalDialogOpening(this); super.show(); if (isModal() && app != null) app.modalDialogClosing(this); } /** * Set the label on the OK button. Allows for * customized button labels. */ public void setOKLabel(String label) { m_ok.setText(label); } /** * Sets the mnnemonic (or keyboard shortcut) for the * OK button. If you have changed the label * using setOKLabel(String) the default * mnemonic ('O') may not be appropriate, so use * this method to set a better one. * @param mnemonic the new key shortcut to use * @see JASDialog#setOKLabel(String) */ public void setOKMnemonic(char mnemonic) { m_ok.setMnemonic(mnemonic); } /** * Set the label on the Cancel button. Allows for * customized button labels. */ public void setCancelLabel(String label) { m_cancel.setText(label); } /** * Sets the mnnemonic (or keyboard shortcut) for the * Cancel button. If you have changed the label * using setCancelLabel(String) the default * mnemonic ('C') may not be appropriate, so use * this method to set a better one. * @param mnemonic the new key shortcut to use * @see JASDialog#setCancelLabel(String) */ public void setCancelMnemonic(char mnemonic) { m_cancel.setMnemonic(mnemonic); } /** * Set the label on the Apply button. Allows for * customized button labels. */ public void setApplyLabel(String label) { m_apply.setText(label); } /** * Sets the mnnemonic (or keyboard shortcut) for the * Apply button. If you have changed the label * using setApplyLabel(String) the default * mnemonic ('A') may not be appropriate, so use * this method to set a better one. * @param mnemonic the new key shortcut to use * @see JASDialog#setApplyLabel(String) */ public void setApplyMnemonic(char mnemonic) { m_apply.setMnemonic(mnemonic); } /** * Called when the OK button is pushed. Override to provide customized * functionality for derived dialog boxes. */ protected void onOK() { m_result = true; dispose(); } /** * Called when the Cancel button is pushed. Override to provide customized * functionality for derived dialog boxes. */ protected void onCancel() { dispose(); } /** * Called when the Apply button is pushed. Override to provide customized * functionality for derived dialog boxes. */ protected void onApply() { } /** Forces the dialog to re-evaluate button enabling. */ protected void callEnable() { if (m_ok != null) { enableOK(new ButtonState(m_ok)); getRootPane().setDefaultButton(m_ok); } if (m_apply != null) enableApply(new ButtonState(m_apply)); if (m_help != null) enableHelp(new ButtonState(m_help)); } /** * Override to customize when OK is enabled. OK is enabled by * default. */ protected void enableOK(JASState state) { } /** * Override to customize when Help is enabled. By default, Help * is enabled if both a help book and help topic have been set. * @see JASDialog#setHelpTopic(String) */ protected void enableHelp(JASState state) { state.setEnabled(m_helpTopic != null); } /** * Override to customize when Apply is enabled. By default, * Apply is disenabled. */ protected void enableApply(JASState state) { state.setEnabled(false); } /** * Returns the content pane for the JASDialog, which is the * panel (not including the buttons) where components can be * added. Add components to this container to have them appear * in the dialog. */ public Container getContentPane() { return m_contentPane; } /** * Sets the content pane. The buttons are not members of this * content pane. */ public void setContentPane(Container c) { m_contentPane = c; super.getContentPane().add(m_contentPane,BorderLayout.CENTER); } /** * Sets the name for the help topic that the Help button opens. * Note: This is now being used to set the XML target for JavaHelp. */ public final void setHelpTopic(String topic) { m_flags |= HELP_BUTTON; m_helpTopic = topic; } private void onHelp() { Application.getApplication().showHelpTopic(m_helpTopic,this); } private class ActionEventHandler implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == m_ok) onOK(); else if (source == m_apply) onApply(); else if (source == m_cancel) onCancel(); else if (source == m_help) onHelp(); } } private class ButtonState implements JASState { ButtonState(JButton b) { m_button = b; } public void setEnabled(boolean state) { m_button.setEnabled(state); } private JButton m_button; } /** * Does nothing by default. To use this class as a MouseListener, * override only the method(s) you need. */ public void mouseClicked(MouseEvent e){} /** * Does nothing by default. To use this class as a MouseListener, * override only the method(s) you need. */ public void mousePressed(MouseEvent e){} /** * Does nothing by default. To use this class as a MouseListener, * override only the method(s) you need. */ public void mouseReleased(MouseEvent e){} /** * Does nothing by default. To use this class as a MouseListener, * override only the method(s) you need. */ public void mouseEntered(MouseEvent e){} /** * Does nothing by default. To use this class as a MouseListener, * override only the method(s) you need. */ public void mouseExited(MouseEvent e){} // Implements DocumentListener as a convenience to subclasses so // that they only need to overload the desired functions /** * Calls callEnable() by default. To use this class * as a DocumentListener, override only the method(s) you need. * @see JASDialog#callEnable() */ public void insertUpdate(DocumentEvent e){callEnable();} /** * Calls callEnable() by default. To use this class * as a DocumentListener, override only the method(s) you need. * @see JASDialog#callEnable() */ public void removeUpdate(DocumentEvent e){callEnable();} /** * Calls callEnable() by default. To use this class * as a DocumentListener, override only the method(s) you need. * @see JASDialog#callEnable() */ public void changedUpdate(DocumentEvent e){callEnable();} private Application app = Application.getApplication(); private String m_helpTopic = null; private int m_flags; private JPanel m_buttonPanel; private JButton m_ok; private JButton m_cancel; private JButton m_apply; private JButton m_help; private boolean m_result; private Window m_window; private Container m_contentPane; } jas-plotter-2.2.10/src/main/java/jas/util/IndentPrintWriter.java0000644000265600020320000000317010631357137024022 0ustar andreasadminpackage jas.util; import java.io.PrintWriter; import java.io.Writer; /** * A PrintWriter that keeps track of an indentation level * and indents the output appropriately. * * Warning: Only print and println methods taking strings have been overriden, * print, println methods taking other arguments may not be indented properly. */ public class IndentPrintWriter extends PrintWriter { public IndentPrintWriter(Writer w) { super(w); } public void println(String s) { if (!indented) doIndent(); super.println(s); indented = false; } public void print(String s) { if (!indented) doIndent(); super.print(s); } public void println() { super.println(); indented = false; } private void doIndent() { for (int i=0; ijava.awt.Color. */ public final static Color[] BASIC_COLORS = { Color.black, Color.darkGray, Color.gray, Color.lightGray, Color.blue, Color.cyan, Color.green, Color.magenta, Color.red, Color.pink, Color.orange, Color.yellow, Color.white }; /** * An array containing the names of colors defined as constants in * java.awt.Color. * * @see #BASIC_COLORS */ public final static String[] BASIC_COLOR_NAMES = { "black", "dark gray", "gray", "light gray", "blue", "cyan", "green", "magenta", "red", "pink", "orange", "yellow", "white" }; // all hail to Crayola /** * An array containing an expanded selection of colors. */ public final static Color[] EXTENDED_COLORS = { Color.black, new Color(0.1f, 0.1f, 0.1f), new Color(0.2f, 0.2f, 0.2f), new Color(0.3f, 0.3f, 0.3f), new Color(0.4f, 0.4f, 0.4f), new Color(0.5f, 0.5f, 0.5f), new Color(0.6f, 0.6f, 0.6f), new Color(0.7f, 0.7f, 0.7f), new Color(0.8f, 0.8f, 0.8f), new Color(0.9f, 0.9f, 0.9f), Color.white, Color.red, new Color(255, 136, 28), new Color(120, 62, 27), new Color(0, 125, 32), new Color(11, 157, 150), Color.blue, new Color(109, 0, 168), new Color(168, 0, 126), Color.pink, Color.orange, Color.yellow, Color.green, Color.cyan, new Color(164, 207, 255), new Color(225, 170, 255), new Color(255, 170, 210) }; /** * An array containing names of the expanded selection of colors. * * @see #EXTENDED_COLORS */ public final static String[] EXTENDED_COLOR_NAMES = { "black", "grey 10%", "grey 20%", "grey 30%", "grey 40%", "grey 50%", "grey 60%", "grey 70%", "grey 80%", "grey 90%", "white", "red", "orange", "brown", "green", "turquoise", "blue", "purple", "magenta", "pink", "light orange", "yellow", "light green", "cyan", "sky blue", "violet", "light magenta" }; // inner classes private class ColorMenuItem extends JRadioButtonMenuItem implements Icon { ColorMenuItem(Color c, String s) { super(s); setIcon(this); color = c; group.add(this); } public void fireActionPerformed(ActionEvent e) { colorModel.setSelectedColor(color); } void setSelectedColor(Color c) { this.setSelected(c == color); } public int getIconHeight() { return size; } public int getIconWidth() { return size; } public void paintIcon(Component p1, Graphics g, int x, int y) { Color save = g.getColor(); g.setColor(color == null ? getBackground() : color); g.fill3DRect(x,y,size,size,true); g.setColor(save); } private Color color; } private final static int size = 12; private class OtherColorMenuItem extends JMenuItem { OtherColorMenuItem() { super("Other..."); } public void fireActionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(this,"Choose color...",colorModel.getSelectedColor()); if (c != null) colorModel.setSelectedColor(c); } } } jas-plotter-2.2.10/src/main/java/jas/util/BooleanCommandTarget.java0000644000265600020320000000060410631354456024414 0ustar andreasadminpackage jas.util; /** * A boolean command target is a CommandTarget which corresponds to a command which * may have an on/off state associated with it. * @see SimpleCommandTarget * @see CommandTarget */ public interface BooleanCommandTarget extends CommandTarget { /** * Called when the on/off state changes (i.e. when the comamnd is invoked) */ void invoke(boolean onOff); } jas-plotter-2.2.10/src/main/java/jas/util/SciFormatPanel.java0000644000265600020320000000646010631357137023243 0ustar andreasadminpackage jas.util; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; /**Creates a jpanel that allows users to set the parameters used by ScientificFormat * objects for number formatting. The panel allows the setting of significant digits, * max width of number and formatting styles. * * @author Paul Spence * @version 03/20/2000 */ public class SciFormatPanel extends JPanel implements ActionListener { public SciFormatPanel(ScientificFormat s) { f=s; createPanel(); } private ScientificFormat f; private JLabel WidthLabel; private JLabel SigLabel; private JPanel DisplayStyle; private JRadioButton PureSci; private JRadioButton StandardSci; private SpinBox widthdigits; private SpinBox sigdigits; private void createPanel() { JPanel DisplayOptions = new JPanel(new FlowLayout(FlowLayout.CENTER)); SigLabel = new JLabel("Significant Digits"); WidthLabel = new JLabel("Maximum Digits"); sigdigits = new SpinBox(f.getSigDigits(),1,15); widthdigits = new SpinBox(f.getMaxWidth(),1,100); sigdigits.setValue(f.getSigDigits()); widthdigits.setValue(f.getMaxWidth()); sigdigits.addActionListener(new MySpinBoxListener()); widthdigits.addActionListener(new MySpinBoxListener()); if(f.getScientificNotationStyle()){ widthdigits.setEnabled(false); WidthLabel.setEnabled(false); } DisplayOptions.add(SigLabel); DisplayOptions.add(sigdigits); DisplayOptions.add(WidthLabel); DisplayOptions.add(widthdigits); JPanel Style = new JPanel(new FlowLayout(FlowLayout.CENTER)); PureSci = new JRadioButton("Use Pure Scientific Notation", f.getScientificNotationStyle()); PureSci.setActionCommand("PureSci"); PureSci.addActionListener(this); StandardSci = new JRadioButton("Use Standard Scientific Notation", !(f.getScientificNotationStyle())); StandardSci.setActionCommand("StandSci"); StandardSci.addActionListener(this); Style.add(PureSci); Style.add(StandardSci); final ButtonGroup group = new ButtonGroup(); group.add(PureSci); group.add(StandardSci); DisplayStyle = new JPanel(); DisplayStyle.setLayout(new GridLayout(2,1)); DisplayStyle.add(DisplayOptions); DisplayStyle.add(Style); } /**Sets the ScientificFormat objects parameters according to the SciFormatPanels values. * To be called when 'ok' or 'apply' buttons int the panels' parent container is * selected. */ public void updateSciFormat(){ f.setMaxWidth(widthdigits.getValue()); f.setSigDigits(sigdigits.getValue()); f.setScientificNotationStyle(PureSci.isSelected()); } /**Get the DisplayStyle panel */ public JPanel getPanel(){ return DisplayStyle; } public void actionPerformed(ActionEvent e) { if (e.getActionCommand() == "StandSci") { WidthLabel.setEnabled(true); widthdigits.setEnabled(true); }else if (e.getActionCommand() == "PureSci") { WidthLabel.setEnabled(false); widthdigits.setEnabled(false); } } class MySpinBoxListener implements ActionListener{ public void actionPerformed(ActionEvent evt){ if( (widthdigits.getValue() < sigdigits.getValue()) ){ widthdigits.setValue(sigdigits.getValue()); } } } } jas-plotter-2.2.10/src/main/java/jas/util/JASCheckboxMenuItem.java0000644000265600020320000000402210631357137024114 0ustar andreasadminpackage jas.util; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Observable; import java.util.Observer; import javax.swing.JCheckBoxMenuItem; public class JASCheckboxMenuItem extends JCheckBoxMenuItem implements Observer,ActionListener,JASCheckboxState, CommandSource { public JASCheckboxMenuItem() { super(); setEnabled(false); Application.getApplication().getCommandManager().add(this); addActionListener(this); } public JASCheckboxMenuItem(String s, char mnemonic) { super(s); setMnemonic(mnemonic); setEnabled(false); Application.getApplication().getCommandManager().add(this); // register with CommandTargetManager addActionListener(this); } public void actionPerformed(ActionEvent evt) { m_target.invoke(getState()); } public void setCheckbox(boolean state) { setState(state); } public boolean setTarget(CommandTarget t) { if (t instanceof BooleanCommandTarget) { m_target = (BooleanCommandTarget) t; m_target.enable(this); return true; } else return false; } public void clearTarget() { m_target = null; setEnabled(false); } public CommandTarget getTarget() { return m_target; } public String getCommand() { return getText(); } public void update(Observable o, Object arg) { m_target.enable(this); } public void setEnabled(boolean state) { if (correspondingToolBarFloating) { //We need to do this since when the menu is refreshed calling setEnabled //wipes out the previous setting, which we might have adjusted based on whether //the user has undocked the corresponding toolbar IF this JASCheckboxMenuItem //controls the visibility of a toolbar. (Yes, this is a bit ugly but when we //move to JDK 1.2 this issue will go away.) super.setEnabled(false); } else { super.setEnabled(state); } } public void setCorrespondingToolBarFloating(boolean state) { correspondingToolBarFloating = state; } private boolean correspondingToolBarFloating = false; private BooleanCommandTarget m_target = null; } jas-plotter-2.2.10/src/main/java/jas/util/ColorListener.java0000644000265600020320000000013010631354456023145 0ustar andreasadminpackage jas.util; public interface ColorListener { void colorChanged(ColorEvent c); } jas-plotter-2.2.10/src/main/java/jas/util/SplashScreen.java0000644000265600020320000000413010631357137022756 0ustar andreasadminpackage jas.util; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JWindow; import javax.swing.SwingUtilities; import javax.swing.border.BevelBorder; public class SplashScreen extends JWindow { private JProgressBar progress; // SplashScreen's constructor public SplashScreen(ImageIcon CoolPicture, String message, String title) { // Create a JPanel so we can use a BevelBorder JPanel PanelForBorder=new JPanel(new BorderLayout()); PanelForBorder.setLayout(new BorderLayout()); PanelForBorder.add(new JLabel(CoolPicture),BorderLayout.CENTER); PanelForBorder.add(new JLabel(title,JLabel.CENTER),BorderLayout.NORTH); progress = new JProgressBar(0,80); progress.setStringPainted(true); progress.setString(message); PanelForBorder.add(progress,BorderLayout.SOUTH); PanelForBorder.setBorder(new BevelBorder(BevelBorder.RAISED)); getContentPane().add(PanelForBorder); } public void setVisible(boolean show) { if (show) { pack(); // Plonk it on center of screen Dimension WindowSize=getSize(), ScreenSize=Toolkit.getDefaultToolkit().getScreenSize(); setBounds((ScreenSize.width-WindowSize.width)/2, (ScreenSize.height-WindowSize.height)/2,WindowSize.width, WindowSize.height); } super.setVisible(show); } public void showStatus(String CurrentStatus, int percent) { if (isVisible()) { SwingUtilities.invokeLater(new UpdateStatus(CurrentStatus,percent)); } } public void close() { if (isVisible()) { SwingUtilities.invokeLater(new CloseSplashScreen()); } } private class UpdateStatus implements Runnable { public UpdateStatus(String status, int pc) { message = status; value = pc; } public void run() { progress.setValue(value); progress.setString(message); } private String message; private int value; } private class CloseSplashScreen implements Runnable { public void run() { setVisible(false); dispose(); } } } jas-plotter-2.2.10/src/main/java/jas/util/DateChooser.java0000644000265600020320000002745610631357137022604 0ustar andreasadminpackage jas.util; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.Insets; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import java.text.Format; import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.Vector; import javax.swing.AbstractListModel; import javax.swing.ComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.plaf.basic.BasicComboBoxRenderer; interface DateListener { void dateChanged(); } class DateModel { DateModel(Calendar date) { this.date = date; } DateModel(Date date) { this.date = Calendar.getInstance(); this.date.setTime(date); } synchronized void addDateListener(DateListener l) { listeners.addElement(l); } synchronized void removeDateListener(DateListener l) { listeners.removeElement(l); } synchronized void fireDateChanged() { Enumeration e = listeners.elements(); while (e.hasMoreElements()) { DateListener l = (DateListener) e.nextElement(); l.dateChanged(); } } void set(int field,int value) { date.set(field,value); fireDateChanged(); } void roll(int field, boolean up) { date.roll(field,up); fireDateChanged(); } void add(int field, int delta) { date.add(field,delta); fireDateChanged(); } int get(int field) { return date.get(field); } Calendar getCalendar() { return date; } int getDaysInMonth() { return( date.getActualMaximum( Calendar.DAY_OF_MONTH ) ); } Date getTime() { return date.getTime(); } private Vector listeners = new Vector(); private Calendar date; } class AbstractDateComboModel extends AbstractListModel implements ComboBoxModel, DateListener { AbstractDateComboModel(DateModel model, int field) { this.model = model; this.field = field; model.addDateListener(this); } public void dateChanged() { fireContentsChanged(this,0,100); } public Object getElementAt(int index) { return element[index]; } public int getSize() { return model.getCalendar().getMaximum(field)+1; } public Object getSelectedItem() { int i = model.get(field); return element[i]; } public void setSelectedItem(Object value) { int i = ((Integer) value).intValue(); model.set(field,i); } DateModel model; int field; static Integer[] element; static { element = new Integer[100]; for (int i=0; i= 12) i -= 12; return element[i]; } public void setSelectedItem(Object value) { int ampm = model.get(Calendar.AM_PM); int i = ((Integer) value).intValue(); if (ampm > 0) i += 12; model.set(field,i); } } class DateMinuteModel extends AbstractDateComboModel { DateMinuteModel(DateModel model) { super(model,Calendar.MINUTE); } } class DateSecondModel extends AbstractDateComboModel { DateSecondModel(DateModel model) { super(model,Calendar.SECOND); } } class DateAMPMModel extends AbstractDateComboModel { DateAMPMModel(DateModel model) { super(model,Calendar.AM_PM); } public void setSelectedItem(Object value) { int hour = model.get(Calendar.HOUR_OF_DAY); int i = ((Integer) value).intValue(); if (i == 0 && hour >= 12) hour -= 12; if (i == 1 && hour < 12) hour += 12; model.set(Calendar.HOUR_OF_DAY,hour); } } class MinuteCellRenderer extends BasicComboBoxRenderer { public Component getListCellRendererComponent (JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { String s =f.format(value); return super.getListCellRendererComponent (list,s,index,isSelected,cellHasFocus); } private static Format f = new DecimalFormat("00"); } class HourCellRenderer extends BasicComboBoxRenderer { HourCellRenderer() { setHorizontalAlignment(SwingConstants.RIGHT); } public Component getListCellRendererComponent (JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { int i = ((Integer) value).intValue(); if (i==0) i = 12; String s = String.valueOf(i); return super.getListCellRendererComponent (list,s,index,isSelected,cellHasFocus); } } class AMPMCellRenderer extends BasicComboBoxRenderer { public Component getListCellRendererComponent (JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { int i = ((Integer) value).intValue(); return super.getListCellRendererComponent (list,ampm[i],index,isSelected,cellHasFocus); } private static String[] ampm = { "AM" , "PM" }; } class DateYearModel extends AbstractDateComboModel { DateYearModel(DateModel model,int offset) { super(model,Calendar.YEAR); this.offset = offset; } public int getSize() { return element.length; } public Object getSelectedItem() { int i = model.get(field); return element[i-offset]; } public void setSelectedItem(Object value) { int i = ((Integer) value).intValue(); model.set(field,i+offset); } private int offset; } class YearCellRenderer extends BasicComboBoxRenderer { YearCellRenderer(int offset) { this.offset = offset; } public Component getListCellRendererComponent (JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { int i = ((Integer) value).intValue(); return super.getListCellRendererComponent (list,String.valueOf(i+offset),index,isSelected,cellHasFocus); } private static int offset; } class CalendarHeader extends JComponent { CalendarHeader(DateModel model) { this.model = model; int offset = 1950; setLayout(new FlowLayout()); JComboBox day = new JComboBox(new DateDayModel(model)); JComboBox month = new JComboBox(new DateMonthModel(model)); JComboBox year = new JComboBox(new DateYearModel(model,offset)); month.setRenderer(new MonthCellRenderer()); year.setRenderer(new YearCellRenderer(offset)); JButton down = new JButton("<"); JButton up = new JButton(">"); down.addActionListener(new RollListener(-1)); up.addActionListener(new RollListener(+1)); add(down); add(day); add(month); add(year); add(up); } private DateModel model; private class RollListener implements ActionListener { RollListener(int delta) { this.delta = delta; } public void actionPerformed(ActionEvent evt) { model.add(Calendar.MONTH,delta); } private int delta; } } class TimeHeader extends JComponent { TimeHeader(DateModel model) { this.model = model; setLayout(new FlowLayout()); JComboBox hour = new JComboBox(new DateHourModel(model)); JComboBox minute = new JComboBox(new DateMinuteModel(model)); JComboBox second = new JComboBox(new DateSecondModel(model)); JComboBox ampm = new JComboBox(new DateAMPMModel(model)); hour.setRenderer(new HourCellRenderer()); minute.setRenderer(new MinuteCellRenderer()); second.setRenderer(new MinuteCellRenderer()); ampm.setRenderer(new AMPMCellRenderer()); add(hour); add(minute); add(second); add(ampm); } private DateModel model; } class CalendarPane extends JComponent implements DateListener, ActionListener { CalendarPane(DateModel model) { this.model = model; model.addDateListener(this); setLayout(null); Insets insets = new Insets(1,1,1,1); days = new JButton[31]; for (int i=0; i<31; i++) { days[i] = new JButton(String.valueOf(i+1)); days[i].addActionListener(this); //days[i].setMargin(insets); add(days[i]); } fg = days[30].getForeground(); bg = days[30].getBackground(); buttonSize = days[30].getPreferredSize(); panelSize = new Dimension(buttonSize.width*7,buttonSize.height*7); hidden = new Point(buttonSize.width*10,buttonSize.height*10); for (int i=0; i<31; i++) days[i].setSize(buttonSize); for (int i=0; i<7; i++) { JLabel l = new JLabel(labels[i],SwingConstants.CENTER); add(l); l.setLocation(i*buttonSize.width,0); l.setSize(buttonSize); } layoutCalendar(); } public Dimension getPreferredSize() { return panelSize; } public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); int day = Integer.valueOf(s).intValue(); model.set(Calendar.DAY_OF_MONTH,day); } public void dateChanged() { layoutCalendar(); } void layoutCalendar() { Calendar selected = model.getCalendar(); int day = selected.get(Calendar.DAY_OF_MONTH)-1; if (selectedButton != days[day]) { if (selectedButton != null) { selectedButton.setForeground(fg); selectedButton.setBackground(bg); selectedButton.repaint(); } selectedButton = days[day]; selectedButton.setForeground(UIManager.getColor("textHighlightText")); selectedButton.setBackground(UIManager.getColor("textHighlight")); selectedButton.repaint(); } Calendar date = (Calendar) selected.clone(); date.set(Calendar.DAY_OF_MONTH,1); int i=0; for (; i>")); m_next.setMnemonic('N'); buttons.add(m_finish = new JButton("Finish")); m_finish.setMnemonic('F'); m_wizardPagePanel.setBorder(new javax.swing.border.EtchedBorder()); m_contentPane.add(BorderLayout.CENTER, m_wizardPagePanel); m_contentPane.add(BorderLayout.SOUTH, buttons); pack(); final Dimension mySize = getSize(); final Dimension parentSize = parent.getSize(); final Point position = parent.getLocation(); position.translate((parentSize.width-mySize.width)/2, (parentSize.height-mySize.height)/2); setLocation(position); m_layout.first(m_wizardPagePanel); (m_currentPage = m_firstPage = firstPage).doEnable(); m_cancel.addActionListener(this); m_help.addActionListener(this); m_prev.addActionListener(this); m_next.addActionListener(this); m_finish.addActionListener(this); m_currentPageHasAmbiguousDefault = m_currentPage.isFinishable() && m_currentPage.hasNextPages(); // setDefaultButton(); m_help.setEnabled(firstPage instanceof HasHelpPage); setResizable(false); enableEvents(java.awt.AWTEvent.WINDOW_EVENT_MASK); firstPage.beforeShowing(); Application app = Application.getApplication(); if (app != null) app.modalDialogOpening(this); show(); if (app != null) app.modalDialogClosing(this); } void setNextEnabled(final boolean b) { m_next.setEnabled(b && m_currentPage.hasNextPages()); } void setFinishEnabled(final boolean b) { m_finish.setEnabled(b && m_currentPage.isFinishable()); } void doPrevEnabled() { m_prev.setEnabled(m_currentPage.getPrev() != null); } private void onHelp() { setToWaitCursor(); HasHelpPage h = ((HasHelpPage) m_currentPage); Application.getApplication().showHelpTopic(h.getHelpTopic(),this); setToDefaultCursor(); } private void setToCurrentPage(final JASWizardPage page) { m_currentPage = page; m_currentPageHasAmbiguousDefault = m_currentPage.isFinishable() && m_currentPage.hasNextPages(); page.doEnable(); if (! m_currentPageHasAmbiguousDefault) setDefaultButton(); m_help.setEnabled(page instanceof HasHelpPage); page.beforeShowing(); m_layout.show(m_wizardPagePanel, page.toString()); } private void onPrev() { setToWaitCursor(); try { setToCurrentPage(m_currentPage.getPrev()); } catch (Throwable t) { handleError("Error during wizard processing",t); } finally { setToDefaultCursor(); } } private void onNext() { setToWaitCursor(); try { final JASWizardPage newPage = ((HasNextPages) m_currentPage).getNext(); if (newPage != null) { // Make sure this page was already added to the current (soon to be previous) page, // if not add it now. if (!m_wizardPagePanel.isAncestorOf(newPage)) { newPage.addTo(m_wizardPagePanel, this, m_currentPage); newPage.invalidate(); validate(); } setToCurrentPage(newPage); } } catch (Throwable t) { handleError("Error during wizard processing",t); } finally { setToDefaultCursor(); } } void setDefaultButton() { if (m_currentPageHasAmbiguousDefault && m_next.isEnabled()) m_rootPane.setDefaultButton(m_next); else if (m_currentPageHasAmbiguousDefault && m_finish.isEnabled()) m_rootPane.setDefaultButton(m_finish); else m_rootPane.setDefaultButton(m_currentPage.hasNextPages() ? m_next : m_finish); } /** * Closes the wizard. Invoked by dispose() in JASWizardPage. * @see JASWizardPage * @see JASWizardPage#dispose() */ public void dispose() { m_firstPage.clear(); /* * References in it and all pages linked to * it are set to null. */ JASWizardPage.pageNumber = 0; // next time the pages start at zero, so that the number doesn't get too big if (getCursor() == m_wait) m_frame.setCursor(m_wait); super.dispose(); } private void onFinish() { setToWaitCursor(); try { ((Finishable) m_currentPage).onFinish(); } catch (Throwable t) { handleError("Error during wizard processing",t); } finally { setToDefaultCursor(); } } private void onCancel() { setToWaitCursor(); try { m_firstPage.doCancel(); dispose(); } catch (Throwable t) { handleError("Error during wizard processing",t); } finally { setToDefaultCursor(); } } void setToWaitCursor() { // should set it on frame too, but doesn't work with modal dialog setCursor(m_wait); } void setToDefaultCursor() { setCursor(m_default); m_frame.setCursor(m_default); } /** Public as an implementation side effect; do not call. */ public void actionPerformed(final ActionEvent e) { final Object source = e.getSource(); if (source == m_cancel) onCancel(); else if (source == m_help) onHelp(); else if (source == m_prev) onPrev(); else if (source == m_next) onNext(); else if (source == m_finish) onFinish(); } /** Public as an implementation side effect; do not call. */ public void processWindowEvent(final WindowEvent e) { // super.processWindowEvent(e); final int id = e.getID(); if (id == WindowEvent.WINDOW_CLOSING) onCancel(); else if (id == WindowEvent.WINDOW_ACTIVATED) setDefaultButton(); } protected void handleError(String message, Throwable t) { Application app = Application.getApplication(); if (app != null) app.error("Error during wizard processing",t); else t.printStackTrace(); } private final JFrame m_frame; private final Cursor m_default = Cursor.getDefaultCursor(), m_wait = new Cursor(Cursor.WAIT_CURSOR); private boolean m_currentPageHasAmbiguousDefault; final private JRootPane m_rootPane; final private java.awt.Container m_contentPane; final private JPanel m_wizardPagePanel; final private JASWizardPage m_firstPage; private JASWizardPage m_currentPage; final private JButton m_cancel, m_help, m_prev, m_next, m_finish; final private CardLayout m_layout; } jas-plotter-2.2.10/src/main/java/jas/util/NestedException.java0000644000265600020320000000327210631354456023474 0ustar andreasadminpackage jas.util; public class NestedException extends Exception implements HasNestedException { private Throwable detail; /** * Create a remote exception */ public NestedException() {} /** * Create a remote exception with the specified string */ public NestedException(String s) { super(s); } /** * Create a remote exception with the specified string, and the * exception specified. */ public NestedException(String s, Throwable ex) { super(s); detail = ex; } public Throwable getNestedException() { return detail; } /** * Produce the message, include the message from the nested * exception if there is one. */ public String getMessage() { return formatNestedException(this); } /** * Return just the super classes message */ public String getSimpleMessage() { return super.getMessage(); } public static String formatNestedException(HasNestedException t) { Throwable nest = t.getNestedException(); if (nest == null) return t.getSimpleMessage(); else return t.getSimpleMessage() + "; nested exception is: \n\t" + nest.toString(); } public void printStackTrace() { super.printStackTrace(); if (detail != null) { System.err.println("Nested Exception is:"); detail.printStackTrace(); } } public void printStackTrace(java.io.PrintStream s) { super.printStackTrace(s); if (detail != null) { s.println("Nested Exception is:"); detail.printStackTrace(s); } } public void printStackTrace(java.io.PrintWriter s) { super.printStackTrace(s); if (detail != null) { s.println("Nested Exception is:"); detail.printStackTrace(s); } } } jas-plotter-2.2.10/src/main/java/jas/util/xml/0000755000265600020320000000000014746176465020341 5ustar andreasadminjas-plotter-2.2.10/src/main/java/jas/util/xml/parserwrappers/0000755000265600020320000000000014746176450023413 5ustar andreasadminjas-plotter-2.2.10/src/main/java/jas/util/xml/parserwrappers/XMLErrorHandler.java0000644000265600020320000000211210631357137027212 0ustar andreasadmin/* * XMLErrorHandler.java * * Created on March 31, 2002, 12:08 AM */ package jas.util.xml.parserwrappers; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; /** * * @author tonyj */ class XMLErrorHandler implements ErrorHandler { private int level = 0; private String fileName; XMLErrorHandler(String fileName) { this.fileName = fileName; } int getLevel() { return level; } public void warning(SAXParseException exception) { //System.err.println(fileName+": Warning at line "+exception.getLineNumber()+": "+exception); if (level < 1) level = 1; } public void error(SAXParseException exception) { System.err.println(fileName+": Error at line "+exception.getLineNumber()+": "+exception); if (level < 2) level = 2; } public void fatalError(SAXParseException exception) throws SAXException { System.err.println(fileName+": Fatal error at line "+exception.getLineNumber()+": "+exception); if (level < 3) level = 3; throw exception; } } jas-plotter-2.2.10/src/main/java/jas/util/xml/parserwrappers/JAXPDOMParser.java0000644000265600020320000000507510631357137026534 0ustar andreasadmin/* * JAXPDomParser.java * * Created on March 30, 2002, 11:51 PM */ package jas.util.xml.parserwrappers; import jas.util.xml.JASDOMParser; import java.io.IOException; import java.io.Reader; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * * @author tonyj */ public class JAXPDOMParser extends JASDOMParser { /** * Create a DOM document by reading an XML file * @param in A reader set up to read an XML file * @param fileName The name of the file being read (used in error messages) * @return Document The resulting DOM * @exception XMLException thrown if there is an error reading the XML */ public Document parse(Reader in, String fileName) throws JASXMLException { return parse(in,fileName,null); } /** * Create a DOM document by reading an XML file with an explicit entity resolver. * An entity resolver is typically used to specify where to find the DTD for the XML * document. * @param in A reader set up to read an XML file * @param fileName The name of the file being read (used in error messages) * @param resolver An entity resolver to use when reading the XML file * @return Document The resulting DOM * @exception XMLException thrown if there is an error reading the XML */ public Document parse(Reader in, String fileName, EntityResolver resolver) throws JASXMLException { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); DocumentBuilder parser = factory.newDocumentBuilder(); XMLErrorHandler errorHandler = new XMLErrorHandler(fileName); parser.setErrorHandler(errorHandler); if (resolver != null) parser.setEntityResolver(resolver); InputSource is = new InputSource(in); is.setSystemId("file:/"); Document doc = parser.parse(is); if (errorHandler.getLevel() > 1) throw new SAXException("Error during XML file parsing"); return doc; } catch (SAXException x) { throw new JASDOMParser.JASXMLException("Syntax error parsing XML file",x); } catch (IOException x) { throw new JASDOMParser.JASXMLException("IO error parsing XML file",x); } catch (ParserConfigurationException x) { throw new JASDOMParser.JASXMLException("Can not create XML parser",x); } } } jas-plotter-2.2.10/src/main/java/jas/util/xml/ClassPathEntityResolver.java0000644000265600020320000000153610631357137025774 0ustar andreasadminpackage jas.util.xml; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; /** * An implementation of an EntityResolver which can be used to locate * DTD files located on the current java class path */ public class ClassPathEntityResolver implements EntityResolver { /** * Constructor * @param DTDName The DTDName to resolve * @oaram root A Class in the same package as the DTD */ public ClassPathEntityResolver(String DTDName, Class root) { this.name = DTDName; this.root = root; } /** * Implementation of resolveEntity method */ public InputSource resolveEntity(String publicId, String systemId) { if (systemId.endsWith(name)) { return new InputSource(root.getResourceAsStream(name)); } else { // use the default behaviour return null; } } private String name; private Class root; } jas-plotter-2.2.10/src/main/java/jas/util/xml/XMLWriter.java0000644000265600020320000003075010631357137023030 0ustar andreasadminpackage jas.util.xml; import jas.util.IndentPrintWriter; import java.io.IOException; import java.io.Writer; import java.util.Enumeration; import java.util.Hashtable; import java.util.Stack; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** * A class that makes it easy to write XML documents. * * @author Tony Johnson * @author Mark Donszelmann * @version $Id: XMLWriter.java 11553 2007-06-05 22:06:23Z duns $ */ public class XMLWriter { public XMLWriter(Writer w, String indentString) { writer = new IndentPrintWriter(w); writer.setIndentString(indentString); } public XMLWriter(Writer w) { this(w, " "); // By popular demand of Babar } /** * closes the writer */ public void close() throws IOException { closeDoc(); writer.close(); } /** * Opens the document with an xml header */ public void openDoc() { openDoc("1.0", "", false); } /** * Opens the document with an xml header */ public void openDoc(String version, String encoding, boolean standalone) { String indentString = writer.getIndentString(); writer.setIndentString(indentString); closed = false; if (!XMLCharacterProperties.validVersionNum(version)) throw new RuntimeException("Invalid version number: "+version); writer.print(""); writer.setIndentString(indentString); } /** * Writes a reference to a DTD */ public void referToDTD(String name, String pid, String ref) { if (dtdName != null) { throw new RuntimeException("ReferToDTD cannot be called twice"); } dtdName = name; writer.println(""); } /** * Writes a reference to a DTD */ public void referToDTD(String name, String system) { if (dtdName != null) { throw new RuntimeException("ReferToDTD cannot be called twice"); } dtdName = name; writer.println(""); } /** * Closes the document, and checks if you closed all the tags */ public void closeDoc() { if (!closed) { if (!openTags.isEmpty()) { StringBuffer sb = new StringBuffer("Not all tags were closed before closing XML document:\n"); while (!openTags.isEmpty()) { sb.append(" \n"); } throw new RuntimeException(sb.toString()); } closed = true; } } /** * Print a comment */ public void printComment(String comment) { if (comment.indexOf("--") >= 0) throw new RuntimeException("'--' sequence not allowed in comment"); writer.print(""); } /** * Prints character data, while escaping < and > */ public void print(String text) { writer.print(normalizeText(text)); } /** * Prints character data, while escaping < and > */ public void println(String text) { print(text); writer.println(); } public void println() { writer.println(); } public void print(double d) { print(String.valueOf(d)); } /** * Prints a new XML tag and increases the identation level */ public void openTag(String namespace, String name) { openTag(namespace+":"+name); } /** * Prints a new XML tag and increases the identation level */ public void openTag(String name) { checkNameValid(name); if (openTags.isEmpty() && dtdName != null && !dtdName.equals(name)) { throw new RuntimeException("First tag: '"+name+"' not equal to DTD id: '"+dtdName+"'"); } writer.print("<"+name); printAttributes(name.length()); writer.println(">"); writer.indent(); openTags.push(name); } /** * Closes the current XML tag and decreases the indentation level */ public void closeTag() { if (openTags.isEmpty()) { writer.close(); throw new RuntimeException("No open tags"); } Object name = openTags.pop(); writer.outdent(); writer.print(""); } /** * Prints an empty XML tag. */ public void printTag(String namespace, String name) { printTag(namespace+":"+name); } /** * Prints an empty XML tag. */ public void printTag(String name) { checkNameValid(name); writer.print("<"+name); printAttributes(name.length()); writer.println("/>"); } /** * Sets an attribute which will be included in the next tag * printed by openTag or printTag */ public void setAttribute(String name, String value) { if ((name != null) && (value != null)) { attributes.put(name,value); } } public void setAttribute(String namespace, String name, String value) { if ((namespace != null) && (name != null)) { attributes.put(namespace+":"+name, value); } } public void setAttribute(String name, double value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, float value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, int value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, long value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, short value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, boolean value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, byte value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String name, char value) { setAttribute(name, String.valueOf(value)); } public void setAttribute(String ns, String name, double value) { setAttribute(ns+":"+name, String.valueOf(value)); } public void setAttribute(String ns, String name, int value) { setAttribute(ns+":"+name, String.valueOf(value)); } public void setAttribute(String ns, String name, boolean value) { setAttribute(ns+":"+name, String.valueOf(value)); } protected void printAttributes(int tagLength) { int width = tagLength + 1; boolean extraIndent = false; Enumeration e = attributes.keys(); while (e.hasMoreElements()) { String key = e.nextElement().toString(); checkNameValid(key); String value = normalize(attributes.get(key).toString()); int length = key.length() + value.length() + 3; if (width > 0 && width + length + 2*writer.getIndent() > 60) { width = 0; writer.println(); if (!extraIndent) { writer.indent(); extraIndent = true; } } else { width += length; writer.print(' '); } writer.print(key); writer.print("=\""); writer.print(value); writer.print("\""); } attributes.clear(); if (extraIndent) writer.outdent(); } /** * Prints a DOM node, recursively. * No support for a document node */ public void print(Node node) { if ( node == null ) return; int type = node.getNodeType(); switch ( type ) { // print document case Node.DOCUMENT_NODE: throw new RuntimeException("No support for printing nodes of type Document"); // print element with attributes case Node.ELEMENT_NODE: NamedNodeMap attributes = node.getAttributes(); for ( int i = 0; i < attributes.getLength(); i++ ) { Node attr = attributes.item(i); setAttribute(attr.getNodeName(), attr.getNodeValue()); } NodeList children = node.getChildNodes(); if ( children == null ) { printTag(node.getNodeName()); } else { openTag(node.getNodeName()); int len = children.getLength(); for ( int i = 0; i < len; i++ ) { print(children.item(i)); } closeTag(); } break; // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: writer.print('&'); writer.print(node.getNodeName()); writer.print(';'); break; // print cdata sections case Node.CDATA_SECTION_NODE: writer.print(""); break; // print text case Node.TEXT_NODE: print(node.getNodeValue()); break; // print processing instruction case Node.PROCESSING_INSTRUCTION_NODE: writer.print(" 0 ) { writer.print(' '); writer.print(data); } writer.print("?>"); break; } } // print(Node) /** Normalizes the given string for an Attribute value*/ public static String normalize(String s) { StringBuffer str = new StringBuffer(); int len = (s != null) ? s.length() : 0; for (int i = 0; i < len; i++) { char ch = s.charAt(i); switch (ch) { case '<': { str.append("<"); break; } case '>': { str.append(">"); break; } case '&': { str.append("&"); break; } case '"': { str.append("""); break; } case '\r': case '\n': { str.append("&#"); str.append(Integer.toString(ch)); str.append(';'); break; } default: { if (ch > 0x00FF) { String hex = "0000"+Integer.toHexString(ch); str.append("&#x"); str.append(hex.substring(hex.length()-4)); str.append(';'); } else { str.append(ch); } } } } return str.toString(); } // normalize(String):String /** Normalizes the given string for Text */ public static String normalizeText(String s) { StringBuffer str = new StringBuffer(); int len = (s != null) ? s.length() : 0; for (int i = 0; i < len; i++) { char ch = s.charAt(i); switch (ch) { case '<': { str.append("<"); break; } case '>': { str.append(">"); break; } case '&': { str.append("&"); break; } default: { if (ch > 0x00FF) { String hex = "0000"+Integer.toHexString(ch); str.append("&#x"); str.append(hex.substring(hex.length()-4)); str.append(';'); } else { str.append(ch); } } } } return str.toString(); } protected void checkNameValid(String s) { if (!XMLCharacterProperties.validName(s)) throw new RuntimeException("Invalid name: "+s); } protected boolean closed = true; private String dtdName = null; private Hashtable attributes = new Hashtable(); private Stack openTags = new Stack(); protected IndentPrintWriter writer; } jas-plotter-2.2.10/src/main/java/jas/util/xml/HasXMLRepresentation.java0000644000265600020320000000031110631354456025201 0ustar andreasadminpackage jas.util.xml; /** * An interface to be implemented by Objects which can * provide their own XML representation */ public interface HasXMLRepresentation { void writeAsXML(XMLWriter pw); } jas-plotter-2.2.10/src/main/java/jas/util/xml/JASDOMParser.java0000644000265600020320000000414610631357137023325 0ustar andreasadminpackage jas.util.xml; import jas.util.NestedException; import jas.util.NestedRuntimeException; import java.io.Reader; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; /** * Ideally wouldnt need this interface, except that the DOM specification * only specifies how to extract information from a DOM, not how to create * a DOM from an XML file. The JASDOMParser interface is meant to make up * for that deficiency. */ public abstract class JASDOMParser { /** * Create a DOM document by reading an XML file * @param in A reader set up to read an XML file * @param fileName The name of the file being read (used in error messages) * @return Document The resulting DOM * @exception XMLException thrown if there is an error reading the XML */ public abstract Document parse(Reader in, String fileName) throws JASXMLException; /** * Create a DOM document by reading an XML file with an explicit entity resolver. * An entity resolver is typically used to specify where to find the DTD for the XML * document. * @param in A reader set up to read an XML file * @param fileName The name of the file being read (used in error messages) * @param resolver An entity resolver to use when reading the XML file * @return Document The resulting DOM * @exception XMLException thrown if there is an error reading the XML */ public abstract Document parse(Reader in, String fileName, EntityResolver resolver) throws JASXMLException; /** * An exception that gets thrown if there is an error reading an XML file. */ public static class JASXMLException extends NestedException { public JASXMLException(String message) { super(message,null); } public JASXMLException(String message, Throwable detail) { super(message,detail); } } /** * Creates a default instance of a JASDOMParser * @return A JASDOMParser */ public static JASDOMParser instance() { try { return (JASDOMParser) Class.forName("jas.util.xml.parserwrappers.JAXPDOMParser").newInstance(); } catch (Throwable x) { throw new NestedRuntimeException("Unable to create default JASDomParser",x); } } } jas-plotter-2.2.10/src/main/java/jas/util/xml/XMLNodeTraverser.java0000644000265600020320000000575610631357137024347 0ustar andreasadminpackage jas.util.xml; import jas.util.ColorConverter; import java.awt.Color; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Text; /** * Utility class for traversing XML DOM trees */ public abstract class XMLNodeTraverser { public void traverse(Node node) throws BadXMLException { if (node instanceof Element) { handleElementAttributes((Element) node); } for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) { handleSubNode(n,n.getNodeName()); } } protected void handleSubNode(Node node, String name) throws BadXMLException { int type = node.getNodeType(); switch (type) { case Node.ELEMENT_NODE: handleElement((Element) node,name); break; case Node.TEXT_NODE: handleTextNode((Text) node,name); break; default: handleOtherNode(node,name); } } protected void handleElementAttributes(Element node) throws BadXMLException { NamedNodeMap nnm = node.getAttributes(); for (int i=0; i