jas-plotter-2.2.10/ 0000755 0002656 0002032 00000000000 14746176464 013352 5 ustar andreas admin jas-plotter-2.2.10/pom.xml 0000644 0002656 0002032 00000004251 13035754550 014655 0 ustar andreas admin
* 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.java 0000644 0002656 0002032 00000004733 10631357137 023341 0 ustar andreas admin package 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.java 0000644 0002656 0002032 00000004700 10631357137 021415 0 ustar andreas admin package 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.java 0000644 0002656 0002032 00000002654 10631354456 025043 0 ustar andreas admin package 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.java 0000644 0002656 0002032 00000013505 10631357137 022134 0 ustar andreas admin package 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.java 0000644 0002656 0002032 00000002437 10631354456 022727 0 ustar andreas admin package 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.java 0000644 0002656 0002032 00000005574 10631357137 023676 0 ustar andreas admin package 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.java 0000644 0002656 0002032 00000032222 10631357137 022124 0 ustar andreas admin package 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
* flags
* parameter. For example,JASDialog.OK_BUTTON | JASDialog.CANCEL_BUTTON | JASDialog.HELP_BUTTON
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
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.java 0000644 0002656 0002032 00000003170 10631357137 024022 0 ustar andreas admin package 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; i