Class DataTool

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, AppFrame, Hidable, Tool

public class DataTool extends OSPFrame implements Tool, PropertyChangeListener
This provides a GUI for analyzing OSP Data objects.
Version:
1.0
Author:
Douglas Brown
See Also:
  • Field Details

    • loadClass

      public static boolean loadClass
    • dim

      protected static Dimension dim
    • defaultButtonHeight

      protected static final int defaultButtonHeight
      See Also:
    • buttonHeight

      protected static int buttonHeight
    • SPACE

      protected static final String SPACE
      See Also:
    • delimiters

      protected static String[] delimiters
    • helpFrame

      protected static TextFrame helpFrame
    • helpName

      protected static String helpName
    • helpBase

      protected static String helpBase
    • loadMultipleTracksInSingleTab

      protected static boolean loadMultipleTracksInSingleTab
    • askToLoadMultipleTracksInSingleTab

      protected static boolean askToLoadMultipleTracksInSingleTab
    • tabbedPane

      protected JTabbedPane tabbedPane
    • useChooser

      protected boolean useChooser
    • contentPane

      protected JPanel contentPane
    • support

      protected PropertyChangeSupport support
    • control

      protected XMLControlElement control
    • addableData

      protected Data addableData
    • controlContainsData

      protected boolean controlContainsData
    • emptyMenubar

      protected JMenuBar emptyMenubar
    • emptyFileMenu

      protected JMenu emptyFileMenu
    • emptyNewTabItem

      protected JMenuItem emptyNewTabItem
    • emptyOpenItem

      protected JMenuItem emptyOpenItem
    • emptyExitItem

      protected JMenuItem emptyExitItem
    • emptyEditMenu

      protected JMenu emptyEditMenu
    • emptyPasteMenu

      protected JMenuItem emptyPasteMenu
    • emptyPasteTabItem

      protected JMenuItem emptyPasteTabItem
    • fileMenu

      protected JMenu fileMenu
    • newTabItem

      protected JMenuItem newTabItem
    • openItem

      protected JMenuItem openItem
    • importItem

      protected JMenuItem importItem
    • exportItem

      protected JMenuItem exportItem
    • saveItem

      protected JMenuItem saveItem
    • saveAsItem

      protected JMenuItem saveAsItem
    • closeItem

      protected JMenuItem closeItem
    • closeAllItem

      protected JMenuItem closeAllItem
    • printItem

      protected JMenuItem printItem
    • exitItem

      protected JMenuItem exitItem
    • editMenu

      protected JMenu editMenu
    • undoItem

      protected JMenuItem undoItem
    • redoItem

      protected JMenuItem redoItem
    • copyMenu

      protected JMenu copyMenu
    • copyImageItem

      protected JMenuItem copyImageItem
    • copyTabItem

      protected JMenuItem copyTabItem
    • copyDataMenu

      protected JMenu copyDataMenu
    • setDelimiterMenu

      protected JMenu setDelimiterMenu
    • copyDataAsFormattedItem

      protected JMenuItem copyDataAsFormattedItem
    • copyDataRawItem

      protected JMenuItem copyDataRawItem
    • pasteMenu

      protected JMenu pasteMenu
    • pasteTabItem

      protected JMenuItem pasteTabItem
    • pasteColumnsItem

      protected JMenuItem pasteColumnsItem
    • displayMenu

      protected JMenu displayMenu
    • languageMenu

      protected JMenu languageMenu
    • languageItems

      protected JMenuItem[] languageItems
    • fontSizeMenu

      protected JMenu fontSizeMenu
    • defaultFontSizeItem

      protected JMenuItem defaultFontSizeItem
    • fontSizeGroup

      protected ButtonGroup fontSizeGroup
    • helpMenu

      protected JMenu helpMenu
    • helpItem

      protected JMenuItem helpItem
    • logItem

      protected JMenuItem logItem
    • aboutItem

      protected JMenuItem aboutItem
    • dataBuilder

      protected DataBuilder dataBuilder
    • exitOnClose

      protected boolean exitOnClose
    • saveChangesOnClose

      protected boolean saveChangesOnClose
    • fitBuilder

      protected FitBuilder fitBuilder
    • isLoading

      protected boolean isLoading
    • loadDataFunctionsButton

      protected JButton loadDataFunctionsButton
    • saveDataFunctionsButton

      protected JButton saveDataFunctionsButton
    • slopeExtended

      protected boolean slopeExtended
    • myPopupFontLevel

      protected int myPopupFontLevel
    • myCopyMenuFontLevel

      protected int myCopyMenuFontLevel
    • NEW_LINE

      public static String NEW_LINE
  • Constructor Details

    • DataTool

      public DataTool()
      Constructs a blank DataTool.
    • DataTool

      public DataTool(String fileName)
      Constructs a DataTool and opens the specified xml file.
      Parameters:
      fileName - the name of the xml file
    • DataTool

      public DataTool(XMLControl control)
      Constructs a DataTool and loads data from an xml control.
      Parameters:
      control - the xml control
    • DataTool

      public DataTool(Data data)
      Constructs a DataTool and loads the specified data object.
      Parameters:
      data - the data
    • DataTool

      protected DataTool(String title, String name)
      Constructs a DataTool with title and name.
      Parameters:
      title -
      name -
  • Method Details

    • getTool

      public static DataTool getTool()
    • getTool

      public static DataTool getTool(boolean forceNew)
      Gets the shared DataTool.
      Returns:
      the shared DataTool
    • main

      public static void main(String[] args)
      Main entry point when used as application.
      Parameters:
      args - args[0] may be a data or xml file name
    • loadDatasetURL

      public void loadDatasetURL(String path)
      Replace any open tabs with a single tab loaded with the given path. JavaScript only?
      Parameters:
      path -
    • loadDatasetURI

      public void loadDatasetURI(String relpath)
      Replace any open tabs with a single tab loaded with the given path. JavaScript only?
      Parameters:
      relpath -
    • getMainFrame

      public OSPFrame getMainFrame()
      Gets the main OSPFrame when DataTool is a stand alone application.
      Returns:
      OSPFrame
    • getMainFrameSize

      public int[] getMainFrameSize()
      Gets the DataTool frame size.
    • setSaveChangesOnClose

      public void setSaveChangesOnClose(boolean save)
      Sets the saveChangesOnClose flag.
      Parameters:
      save - true to save changes when exiting
    • addTabs

      public void addTabs(XMLControl control, Consumer<ArrayList<DataToolTab>> whenDone)
      Adds tabs loaded with data from an xml control.
      Parameters:
      control - the xml control
      whenDone -
    • createTabs

      public ArrayList<DataToolTab> createTabs(Data source)
      Creates a tab for each Data object returned by DataTool.getDataList(source). The tab names will be those of the Data objects in the list if they define a getName() method.
      Parameters:
      source - the source Data
      Returns:
      a list of new tabs
    • createTab

      protected DataToolTab createTab(Data data)
      Creates a tab for the specified Data object. The tab name will be that of the Data object if it defines a getName() method.
      Parameters:
      data - the Data
      Returns:
      the new tab
    • removeTab

      public DataToolTab removeTab(int index, boolean saveChanges)
      Removes the tab at the specified index.
      Parameters:
      index - the tab number
      saveChanges -
      Returns:
      the removed tab, or null if none removed
    • removeTab

      public DataToolTab removeTab(DataToolTab tab)
      Removes a specified tab.
      Parameters:
      tab - the tab
      Returns:
      the removed tab, or null if none removed
    • loadData

      public ArrayList<DataToolTab> loadData(Data data)
      Loads a Data object into existing tabs and/or newly created tabs as needed.
      Parameters:
      data - the Data
      Returns:
      a list of the loaded tabs
    • loadData

      public DataToolTab loadData(Data... data)
      Loads multiple Data objects into a single existing or newly created tab.
      Parameters:
      data - one or more Data objects
      Returns:
      the loaded tab
    • getTab

      public DataToolTab getTab(Data data)
      Returns the tab associated with the specified Data object. May return null.
      Parameters:
      data - the Data
      Returns:
      the tab
    • getTab

      public DataToolTab getTab(int index)
      Returns the tab at the specified index. May return null.
      Parameters:
      index - the tab index
      Returns:
      the tab
    • getTabCount

      public int getTabCount()
      Returns the tab count.
      Returns:
      the number of tabs
    • getTabs

      public List<DataToolTab> getTabs()
      Returns a list of all open tabs.
      Returns:
      a list of DataToolTabs
    • open

      public void open(File file)
      Opens an xml or data file specified by name.
      Parameters:
      fileName - the file name
    • loadDataset

      public void loadDataset(String content, String title)
      Loads content into DataDataTool.
      Parameters:
      content - the xml or CVS dataset
    • send

      public void send(Job job, Tool replyTo)
      Sends a job to this tool and specifies a tool to reply to.
      Specified by:
      send in interface Tool
      Parameters:
      job - the Job
      replyTo - the tool to notify when the job is complete (may be null)
    • setUseChooser

      public void setUseChooser(boolean useChooser)
      Sets the useChooser flag.
      Parameters:
      useChooser - true to load datasets with a chooser
    • isUseChooser

      public boolean isUseChooser()
      Gets the useChooser flag.
      Returns:
      true if loading datasets with a chooser
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Listens for property changes "function"
      Specified by:
      propertyChange in interface PropertyChangeListener
      Parameters:
      e - the event
    • containsDuplicateValues

      protected static boolean containsDuplicateValues(double[] values)
      Determines if an array contains any duplicate or Double.NaN values.
      Parameters:
      values - the array
      Returns:
      true if at least one duplicate is found
    • getIndex

      protected static int getIndex(double value, double[] array, int ignoreIndex)
      Gets the first array index at which the specified value is found.
      Parameters:
      value - the value to find
      array - the array to search
      ignoreIndex - an array index to ignore
      Returns:
      the index, or -1 if not found
    • getRowArray

      protected static double[] getRowArray(int rowCount)
      Returns an array of row numbers.
      Parameters:
      rowCount - length of the array
      Returns:
      the array
    • parseStrings

      protected static String[] parseStrings(String text, String delimiter)
      Parses a String into tokens separated by a specified delimiter. A token may be "".
      Parameters:
      text - the text to parse
      delimiter - the delimiter
      Returns:
      an array of String tokens
    • parseDoubles

      protected static double[] parseDoubles(String text, String delimiter)
      Parses a String into doubles separated by a specified delimiter. Unparsable strings are set to Double.NaN.
      Parameters:
      text - the text to parse
      delimiter - the delimiter
      Returns:
      an array of doubles
    • parseDoubles

      protected static double[] parseDoubles(String[] strings, String delimiter)
      Parses a String array into doubles. Unparsable strings are set to Double.NaN.
      Parameters:
      strings - the String array to parse
      delimiter - the delimiter that was used to parse the strings
      Returns:
      an array of doubles
    • parseStrings

      protected static String[][] parseStrings(String text, String rowDelimiter, String colDelimiter)
      Parses a String into tokens separated by specified row and column delimiters. NOTE: This method WILL check for European comma decimal point
      Parameters:
      text - the text to parse
      rowDelimiter - the column delimiter
      colDelimiter - the column delimiter
      Returns:
      a 2D array of String tokens
    • parseDoubles

      protected static double[][] parseDoubles(String text, String rowDelimiter, String colDelimiter)
      Parses a String into doubles separated by specified row and column delimiters. NOTE: This method is not set to parse European comma decimal points (but could be)
      Parameters:
      text - the text to parse
      rowDelimiter - the column delimiter
      colDelimiter - the column delimiter
      Returns:
      a 2D array of doubles
    • parseData

      public static DatasetManager[] parseData(String dataString, String fileName)
      Parses character-delimited data from a string. This attempts to extract the following information from the string: 1. A title to be used for the tab name 2. One or more columns of double data values 3. Column names for the data columns
      Parameters:
      dataString - the data string
      fileName - name of file containing the data string (may be null)
      Returns:
      DatasetManager[] with parsed data, or null if none found
    • readFirstLine

      protected String readFirstLine(Reader in)
    • setupDelimiterMenu

      protected void setupDelimiterMenu(JMenu menu)
    • getUniqueTabName

      protected String getUniqueTabName(String proposed)
      Gets a unique name.
      Parameters:
      proposed - the proposed name
      Returns:
      the unique name
    • createDatasetFromYPoints

      public static Dataset createDatasetFromYPoints(Dataset xColumn, Dataset yColumn)
      Constructs a dataset from independent xColumn and yColumn datasets.
      Parameters:
      xColumn - the dataset containing data for the x column
      yColumn - the dataset containing data for the y column
      Returns:
      the x-y dataset
    • getDatasets

      public static ArrayList<Dataset> getDatasets(Data source)
      Gets a list of Datasets from a self-contained source Data object.
      Parameters:
      source - the self-contained Data
      Returns:
      a list of Datasets
    • getAllDatasets

      public static ArrayList<Dataset> getAllDatasets(Data source)
      Gets a list of all Datasets from any Data object.
      Parameters:
      source - a self-contained or container Data object
      Returns:
      a list of all Datasets
    • getSelfContainedData

      protected static ArrayList<Data> getSelfContainedData(Data container)
      Gets a list of self-contained Data objects.
      Parameters:
      container - the container Data
      Returns:
      a list of self-contained Data objects
    • getDataColumns

      protected static ArrayList<DataColumn> getDataColumns(Data source)
      Gets a list of DataColumns from a self-contained Data object.
      Parameters:
      source - a self-contained Data object
      Returns:
      a list of DataColumns
    • getAllDataColumns

      protected static ArrayList<DataColumn> getAllDataColumns(Data source)
      Gets a list of all DataColumns from any Data object.
      Parameters:
      source - a self-contained or container Data object
      Returns:
      a list of all DataColumns
    • copyDataset

      public static Dataset copyDataset(Dataset source, Dataset target, boolean includeDataAndID)
      Copies a dataset. If includeDataAndID is false, only the name and display properties are copied.
      Parameters:
      source - the source dataset
      target - the target dataset (may be null)
      includeDataAndID - true to copy data and ID
      Returns:
      the copy
    • insert

      protected static double[] insert(double input, double[] array, int trend)
      Inserts a specified value into an array.
      Parameters:
      input - the value to insert
      array - the array into which the value is inserted
      trend - positive if array is ascending, negative if descending, 0 if neither
      Returns:
      an array containing the inserted value
    • addTab

      public void addTab(DataToolTab tab)
      Adds a tab. The tab should be named before calling this method.
      Parameters:
      tab - a DataToolTab
    • saveChangesAt

      protected boolean saveChangesAt(int i)
      Offers to save changes to the tab at the specified index.
      Parameters:
      i - the tab index
      Returns:
      true unless canceled by the user
    • getSelectedTab

      public DataToolTab getSelectedTab()
      Gets the currently selected DataToolTab, if any.
      Returns:
      the selected tab
    • setSelectedTab

      public void setSelectedTab(DataToolTab tab)
      Selects a DataToolTab.
      Parameters:
      tab - the tab to select
    • clearData

      public void clearData()
      Clears data by removing all tabs.
      Overrides:
      clearData in class OSPFrame
    • setFontLevel

      public void setFontLevel(int level)
      Sets the font level.
      Overrides:
      setFontLevel in class OSPFrame
      Parameters:
      level - the level
    • setVisible

      public void setVisible(boolean vis)
      Description copied from class: OSPFrame
      Shows or hides this component depending on the value of parameter b and the keepHidden flag. OSP Applets often keep windows hidden.
      Overrides:
      setVisible in class OSPFrame
    • getFitBuilder

      public FitBuilder getFitBuilder()
      Gets the fit builder.
      Returns:
      the fit builder
    • write

      protected static String write(String text, String fileName)
      Writes text to a file with the specified name.
      Parameters:
      text - the text
      fileName - the file name
      Returns:
      the path of the saved document or null if failed
    • write

      protected static void write(String text, Writer out)
      Writes text to a Writer.
      Parameters:
      text - the text
      out - the Writer
    • open

      protected void open()
      Opens an xml or data file selected with a chooser.
    • save

      protected String save(String fileName)
      Saves the current tab to the specified file.
      Parameters:
      fileName - the file name
      Returns:
      the name of the saved file, or null if not saved
    • save

      protected String save(DataToolTab tab, String fileName)
      Saves a tab to the specified file.
      Parameters:
      tab - the tab
      fileName - the file name
      Returns:
      the name of the saved file, or null if not saved
    • saveAs

      protected String saveAs()
      Saves the current tab to a file selected with a chooser.
      Returns:
      the name of the saved file, or null if not saved
    • getTabIndex

      protected int getTabIndex(Data data)
      Returns the index of the tab containing the specified Data object.
      Parameters:
      data - the Data
      Returns:
      the index, or -1 if not found
    • getTabIndex

      protected int getTabIndex(DataToolTab tab)
      Returns the index of a specified tab.
      Parameters:
      tab - the tab
      Returns:
      the index, or -1 if not found
    • removeAllButTab

      protected boolean removeAllButTab(int index)
      Removes all tabs except the specified index.
      Parameters:
      index - the tab number
      Returns:
      true if tabs removed
    • removeAllTabs

      protected boolean removeAllTabs()
      Removes all tabs.
      Returns:
      true if all tabs removed
    • refreshTabTitles

      protected void refreshTabTitles()
    • refreshMenubar

      protected void refreshMenubar()
    • getDataBuilder

      protected FunctionTool getDataBuilder()
      Gets the data builder for defining custom data functions.
      Returns:
      the data builder
    • refreshDataBuilder

      protected void refreshDataBuilder()
      Refreshes the data builder.
    • showHelp

      protected static void showHelp()
      Shows the DataTool help.
    • setDefaultCloseOperation

      public void setDefaultCloseOperation(int operation)
      Overrides OSPFrame method. This converts EXIT_ON_CLOSE to DO_NOTHING_ON_CLOSE and sets the exitOnClose flag.
      Specified by:
      setDefaultCloseOperation in interface AppFrame
      Overrides:
      setDefaultCloseOperation in class OSPFrame
      Parameters:
      operation - the operation
      See Also:
    • dispose

      public void dispose()
      Description copied from class: OSPFrame
      Disposes all resources.
      Overrides:
      dispose in class OSPFrame
    • finalize

      public void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • createGUI

      protected void createGUI()
      Creates the GUI.
    • pasteTab

      protected void pasteTab(Object source)
    • copyTab

      protected void copyTab()
    • cloneTab

      protected void cloneTab(int index, boolean editable)
    • pasteAction

      protected void pasteAction(String dataString, Object source)
    • addColumnsFromPaste

      protected void addColumnsFromPaste()
      add columns, possibly asynchronously
    • refreshGUI

      protected void refreshGUI()
      Refreshes the GUI.
      Overrides:
      refreshGUI in class OSPFrame
    • refreshDecimalSeparators

      public void refreshDecimalSeparators()
      Refreshes decimal separators in all tabs.
    • hasPastableData

      protected boolean hasPastableData()
      Determines if the clipboard has pastable data.
      Returns:
      true if data is pastable
    • hasPastableColumns

      protected boolean hasPastableColumns(DataToolTab tab)
      Determines if the clipboard has columns that are pastable into a specified tab.
      Parameters:
      tab - the tab
      Returns:
      true if clipboard has pastable columns
    • showAboutDialog

      protected void showAboutDialog()
      Shows the about dialog.
    • setMultipleTabPolicy

      protected void setMultipleTabPolicy(String dataString)
    • createButton

      protected static JButton createButton(String text)
      Creates a button with a specified text.
      Parameters:
      text - the button text
      Returns:
      the button
    • createButton

      protected static JButton createButton(String text, boolean allowBorder)