Class TextEditor

  • All Implemented Interfaces:
    java.awt.event.WindowFocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.DocumentListener, javax.swing.RootPaneContainer, javax.swing.WindowConstants, ImageExportable, QueryListener, StatusHandler
    Direct Known Subclasses:
    Console.ConsoleFrame, DebugListenerTableau.DebugListenerFrame, SyntaxTextEditor, TextEditorForStringAttributes

    public class TextEditor
    extends TableauFrame
    implements javax.swing.event.DocumentListener, ImageExportable, java.awt.print.Printable, QueryListener
    A top-level window containing a simple text editor or viewer. You can access the public member text to set the text, get the text, or set the number of rows or columns. After creating this, it is necessary to call show() for it to appear.
    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Edward A. Lee, contributors: Christopher Brooks, Ben Leinfelder
    See Also:
    Serialized Form
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Yellow (eal)
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  TextEditor.ExportImageAction
      Export an image.
      • Nested classes/interfaces inherited from class javax.swing.JFrame

        javax.swing.JFrame.AccessibleJFrame
      • Nested classes/interfaces inherited from class java.awt.Frame

        java.awt.Frame.AccessibleAWTFrame
      • Nested classes/interfaces inherited from class java.awt.Window

        java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      TextEditor()
      Construct an empty text editor with no name.
      TextEditor​(java.lang.String title)
      Construct an empty text editor with the specified title.
      TextEditor​(java.lang.String title, javax.swing.text.Document document)
      Construct an empty text editor with the specified title and document.
      TextEditor​(java.lang.String title, javax.swing.text.Document document, Placeable placeable)
      Construct an empty text editor with the specified title and document and associated placeable.
      TextEditor​(java.lang.String title, javax.swing.text.Document document, PortablePlaceable portablePlaceable)
      Construct an empty text editor with the specified title and document and associated poratalbeplaceable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void _addMenus()
      Create an edit menu.
      protected boolean _clear()
      Clear the current contents.
      protected javax.swing.JMenuItem[] _createFileMenuItems()
      Create the items in the File menu's Export section This method adds a menu items to export images of the plot in GIF, PNG, and possibly PDF.
      protected void _find()
      Find and replace.
      protected void _help()
      Display more detailed information than given by _about().
      protected void _init​(java.lang.String title, javax.swing.text.Document document)
      Initializes an empty text editor with the specified title and document and associated placeable.
      protected void _print()
      Print the contents.
      protected void _redo()
      Redo the last undo action.
      protected boolean _saveAs()
      Query the user for a filename, save the model to that file, and open a new window to view the model.
      protected void _undo()
      Undo the last action.
      void adjustFileMenu()
      Allow subclasses to adjust the file menu after packing.
      void changed​(java.lang.String name)
      React to a change in the find-and-replace query.
      void changedUpdate​(javax.swing.event.DocumentEvent e)
      React to notification that an attribute or set of attributes changed.
      void dispose()
      Dispose of this frame.
      java.awt.image.BufferedImage exportImage()
      Create a BufferedImage and draw this plot to it.
      java.awt.image.BufferedImage exportImage​(java.awt.image.BufferedImage bufferedImage, java.awt.Rectangle rectangle, java.awt.RenderingHints hints, boolean transparent)
      Draw this plot onto the specified image at the position of the specified rectangle with the size of the specified rectangle.
      void exportImage​(java.io.OutputStream out, java.lang.String formatName)
      Export an image of the plot in the specified format.
      java.awt.Color getBackground()
      Get the background color.
      javax.swing.JScrollPane getScrollPane()
      Return the scroll pane, if there is one, and null if not.
      void insertUpdate​(javax.swing.event.DocumentEvent e)
      React to notification that there was an insert into the document.
      int print​(java.awt.Graphics graphics, java.awt.print.PageFormat format, int index)
      Print the text to a printer, which is represented by the specified graphics object.
      int print​(java.awt.Graphics graphics, java.awt.Rectangle drawRect)
      Print the text to a printer, which is represented by the specified graphics object.
      void removeUpdate​(javax.swing.event.DocumentEvent e)
      React to notification that there was a removal from the document.
      void scrollToEnd()
      Scroll as necessary so that the last line is visible.
      void setBackground​(java.awt.Color background)
      Set background color.
      void writeImage​(java.io.OutputStream stream, java.lang.String format)
      Write an image to the specified output stream in the specified format.
      • Methods inherited from class javax.swing.JFrame

        addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
      • Methods inherited from class java.awt.Frame

        addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
      • Methods inherited from class java.awt.Window

        addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, toBack, toFront
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.awt.MenuContainer

        getFont, postEvent
    • Field Detail

      • text

        public javax.swing.JTextArea text
        The text area.
      • _editMenu

        protected javax.swing.JMenu _editMenu
        The edit menu.
      • _exportGIFAction

        protected javax.swing.Action _exportGIFAction
        The export to GIF action.
      • _exportPNGAction

        protected javax.swing.Action _exportPNGAction
        The export to PNG action.
      • _scrollPane

        protected javax.swing.JScrollPane _scrollPane
        The scroll pane containing the text area.
    • Constructor Detail

      • TextEditor

        public TextEditor()
        Construct an empty text editor with no name. After constructing this, it is necessary to call setVisible(true) to make the frame appear.
      • TextEditor

        public TextEditor​(java.lang.String title)
        Construct an empty text editor with the specified title. After constructing this, it is necessary to call setVisible(true) to make the frame appear.
        Parameters:
        title - The title to put in the title bar.
      • TextEditor

        public TextEditor​(java.lang.String title,
                          javax.swing.text.Document document)
        Construct an empty text editor with the specified title and document. After constructing this, it is necessary to call setVisible(true) to make the frame appear.
        Parameters:
        title - The title to put in the title bar.
        document - The document containing text, or null if none.
      • TextEditor

        public TextEditor​(java.lang.String title,
                          javax.swing.text.Document document,
                          Placeable placeable)
        Construct an empty text editor with the specified title and document and associated placeable. After constructing this, it is necessary to call setVisible(true) to make the frame appear.
        Parameters:
        title - The title to put in the title bar.
        document - The document containing text, or null if none.
        placeable - The associated placeable.
      • TextEditor

        public TextEditor​(java.lang.String title,
                          javax.swing.text.Document document,
                          PortablePlaceable portablePlaceable)
        Construct an empty text editor with the specified title and document and associated poratalbeplaceable. After constructing this, it is necessary to call setVisible(true) to make the frame appear.
        Parameters:
        title - The title to put in the title bar.
        document - The document containing text, or null if none.
        portablePlaceable - The associated PortablePlaceable.
    • Method Detail

      • adjustFileMenu

        public void adjustFileMenu()
        Allow subclasses to adjust the file menu after packing. This has to be called after pack(). This base class does nothing.
      • changed

        public void changed​(java.lang.String name)
        React to a change in the find-and-replace query.
        Specified by:
        changed in interface QueryListener
        Parameters:
        name - The field that changed.
      • changedUpdate

        public void changedUpdate​(javax.swing.event.DocumentEvent e)
        React to notification that an attribute or set of attributes changed.
        Specified by:
        changedUpdate in interface javax.swing.event.DocumentListener
      • dispose

        public void dispose()
        Dispose of this frame. Override this dispose() method to unattach any listeners that may keep this model from getting garbage collected. This method invokes the dispose() method of the superclass, TableauFrame.
        Overrides:
        dispose in class TableauFrame
      • getBackground

        public java.awt.Color getBackground()
        Get the background color.
        Overrides:
        getBackground in class java.awt.Window
        Returns:
        The background color of the scroll pane. If _scrollPane is null, then null is returned.
        See Also:
        setBackground(Color)
      • getScrollPane

        public javax.swing.JScrollPane getScrollPane()
        Return the scroll pane, if there is one, and null if not.
        Returns:
        The scroll pane.
      • exportImage

        public java.awt.image.BufferedImage exportImage()
        Create a BufferedImage and draw this plot to it. The size of the returned image matches the current size of the plot. This method can be used, for example, by a servlet to produce an image, rather than requiring an applet to instantiate a PlotBox.
        Returns:
        An image filled by the plot.
      • exportImage

        public java.awt.image.BufferedImage exportImage​(java.awt.image.BufferedImage bufferedImage,
                                                        java.awt.Rectangle rectangle,
                                                        java.awt.RenderingHints hints,
                                                        boolean transparent)
        Draw this plot onto the specified image at the position of the specified rectangle with the size of the specified rectangle. The plot is rendered using anti-aliasing. This can be used to paint a number of different plots onto a single buffered image. This method can be used, for example, by a servlet to produce an image, rather than requiring an applet to instantiate a PlotBox.
        Parameters:
        bufferedImage - Image onto which the plot is drawn.
        rectangle - The size and position of the plot in the image.
        hints - Rendering hints for this plot.
        transparent - Indicator that the background of the plot should not be painted.
        Returns:
        The modified bufferedImage.
      • exportImage

        public void exportImage​(java.io.OutputStream out,
                                java.lang.String formatName)
        Export an image of the plot in the specified format. If the specified format is not supported, then pop up a message window apologizing.
        Parameters:
        out - An output stream to which to send the description.
        formatName - A format name, such as "gif" or "png".
      • insertUpdate

        public void insertUpdate​(javax.swing.event.DocumentEvent e)
        React to notification that there was an insert into the document.
        Specified by:
        insertUpdate in interface javax.swing.event.DocumentListener
      • print

        public int print​(java.awt.Graphics graphics,
                         java.awt.print.PageFormat format,
                         int index)
                  throws java.awt.print.PrinterException
        Print the text to a printer, which is represented by the specified graphics object.
        Specified by:
        print in interface java.awt.print.Printable
        Parameters:
        graphics - The context into which the page is drawn.
        format - The size and orientation of the page being drawn.
        index - The zero based index of the page to be drawn.
        Returns:
        PAGE_EXISTS if the page is rendered successfully, or NO_SUCH_PAGE if pageIndex specifies a non-existent page.
        Throws:
        java.awt.print.PrinterException - If the print job is terminated.
      • print

        public int print​(java.awt.Graphics graphics,
                         java.awt.Rectangle drawRect)
        Print the text to a printer, which is represented by the specified graphics object.
        Parameters:
        graphics - The context into which the page is drawn.
        drawRect - specification of the size.
        Returns:
        PAGE_EXISTS if the page is rendered successfully, or NO_SUCH_PAGE if pageIndex specifies a non-existent page.
      • removeUpdate

        public void removeUpdate​(javax.swing.event.DocumentEvent e)
        React to notification that there was a removal from the document.
        Specified by:
        removeUpdate in interface javax.swing.event.DocumentListener
      • scrollToEnd

        public void scrollToEnd()
        Scroll as necessary so that the last line is visible.
      • setBackground

        public void setBackground​(java.awt.Color background)
        Set background color. This overrides the base class to set the background of contained scroll pane and text area.
        Overrides:
        setBackground in class Top
        Parameters:
        background - The background color.
        See Also:
        getBackground()
      • writeImage

        public void writeImage​(java.io.OutputStream stream,
                               java.lang.String format)
                        throws java.awt.print.PrinterException,
                               java.io.IOException
        Write an image to the specified output stream in the specified format. Supported formats include at least "gif" and "png", standard image file formats. The image is a rendition of the current view of the model.
        Specified by:
        writeImage in interface ImageExportable
        Parameters:
        stream - The output stream to write to.
        format - The image format to generate.
        Throws:
        java.io.IOException - If writing to the stream fails.
        java.awt.print.PrinterException - If the specified format is not supported.
      • _addMenus

        protected void _addMenus()
        Create an edit menu.
        Overrides:
        _addMenus in class TableauFrame
      • _clear

        protected boolean _clear()
        Clear the current contents. First, check to see whether the contents have been modified, and if so, then prompt the user to save them. A return value of false indicates that the user has canceled the action.
        Overrides:
        _clear in class Top
        Returns:
        False if the user cancels the clear.
      • _createFileMenuItems

        protected javax.swing.JMenuItem[] _createFileMenuItems()
        Create the items in the File menu's Export section This method adds a menu items to export images of the plot in GIF, PNG, and possibly PDF.
        Overrides:
        _createFileMenuItems in class Top
        Returns:
        The items in the File menu.
      • _find

        protected void _find()
        Find and replace.
      • _help

        protected void _help()
        Display more detailed information than given by _about().
        Overrides:
        _help in class TableauFrame
        See Also:
        FileParameter
      • _init

        protected void _init​(java.lang.String title,
                             javax.swing.text.Document document)
        Initializes an empty text editor with the specified title and document and associated placeable. After constructing this, it is necessary to call setVisible(true) to make the frame appear.
        Parameters:
        title - The title to put in the title bar.
        document - The document containing text.
      • _print

        protected void _print()
        Print the contents.
        Overrides:
        _print in class Top
      • _redo

        protected void _redo()
        Redo the last undo action.
      • _saveAs

        protected boolean _saveAs()
        Query the user for a filename, save the model to that file, and open a new window to view the model. This overrides the base class to use the ".txt" extension.
        Overrides:
        _saveAs in class TableauFrame
        Returns:
        True if the save succeeds.
      • _undo

        protected void _undo()
        Undo the last action.