Class FieldPanel

All Implemented Interfaces:
LayoutModelListener, IndexedScrollable, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ChangeListener

public class FieldPanel extends JPanel implements IndexedScrollable, LayoutModelListener, ChangeListener
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • showIndex

      public void showIndex(BigInteger layoutIndex, int verticalOffset)
      Description copied from interface: IndexedScrollable
      Makes the item at the given index be visible on the screen at the given vertical offset
      Specified by:
      showIndex in interface IndexedScrollable
      Parameters:
      layoutIndex - the index of the item to show
      verticalOffset - the number of pixels from the top of the screen to show the item
    • scrollView

      public void scrollView(int viewAmount)
    • scrollTo

      public void scrollTo(FieldLocation fieldLocation)
    • center

      public void center(FieldLocation location)
    • setFieldDescriptionProvider

      public void setFieldDescriptionProvider(FieldDescriptionProvider provider)
    • scrollLineDown

      public void scrollLineDown()
      Description copied from interface: IndexedScrollable
      Scrolls the displayed items down by the height of one line of text
      Specified by:
      scrollLineDown in interface IndexedScrollable
    • scrollLineUp

      public void scrollLineUp()
      Description copied from interface: IndexedScrollable
      Scrolls the displayed items up by the height of one line of text
      Specified by:
      scrollLineUp in interface IndexedScrollable
    • scrollPageDown

      public void scrollPageDown()
      Description copied from interface: IndexedScrollable
      Scrolls the displayed items down by the height of one screen of text
      Specified by:
      scrollPageDown in interface IndexedScrollable
    • scrollPageUp

      public void scrollPageUp()
      Description copied from interface: IndexedScrollable
      Scrolls the displayed items up by the height of one screen of text
      Specified by:
      scrollPageUp in interface IndexedScrollable
    • pageUp

      public void pageUp()
    • pageDown

      public void pageDown()
    • getHeight

      public int getHeight(BigInteger index)
      Description copied from interface: IndexedScrollable
      Returns the height of the n'th item.
      Specified by:
      getHeight in interface IndexedScrollable
      Parameters:
      index - the index of the time to get height for
      Returns:
      the height of the n'th item.
    • getIndexAfter

      public BigInteger getIndexAfter(BigInteger index)
      Description copied from interface: IndexedScrollable
      Returns the index of the next non-null item. Not all indexes have items. Some items span multiple indexes
      Specified by:
      getIndexAfter in interface IndexedScrollable
      Parameters:
      index - the index to start searching for the next non-null item
      Returns:
      the index of the next non-null item, or -1 if there is none
    • getIndexBefore

      public BigInteger getIndexBefore(BigInteger index)
      Description copied from interface: IndexedScrollable
      Returns the index of the previous non-null item. Not all indexes have items. Some items span multiple indexes
      Specified by:
      getIndexBefore in interface IndexedScrollable
      Parameters:
      index - the index to start searching backwards for the previous non-null item
      Returns:
      the index of the previous non-null item, or -1 if there is none
    • getIndexCount

      public BigInteger getIndexCount()
      Description copied from interface: IndexedScrollable
      Returns the number individually addressable items displayed.
      Specified by:
      getIndexCount in interface IndexedScrollable
      Returns:
      the number individually addressable items displayed
    • isUniformIndex

      public boolean isUniformIndex()
      Description copied from interface: IndexedScrollable
      Returns true if all the items are the same vertical size.
      Specified by:
      isUniformIndex in interface IndexedScrollable
      Returns:
      true if all the items are the same vertical size
    • cursorUp

      public void cursorUp()
    • cursorDown

      public void cursorDown()
    • cursorLeft

      public void cursorLeft()
    • cursorRight

      public void cursorRight()
    • tabRight

      public void tabRight()
    • tabLeft

      public void tabLeft()
    • cursorHome

      public void cursorHome()
      Moves the cursor to the beginning of the line.
    • cursorTopOfFile

      public void cursorTopOfFile()
    • cursorBottomOfFile

      public void cursorBottomOfFile()
    • cursorEnd

      public void cursorEnd()
      Moves the cursor to the end of the line.
    • getVisibleLayouts

      public List<AnchoredLayout> getVisibleLayouts()
    • isLocationVisible

      public boolean isLocationVisible(FieldLocation location)
      Returns true if the given field location is rendered on the screen; false if scrolled offscreen
      Parameters:
      location - the location
      Returns:
      true if the location is on the screen
    • getVisibleStartLayout

      public AnchoredLayout getVisibleStartLayout()
      Returns the first visible layout or null if there are no visible layouts
      Returns:
      the first visible layout
    • getVisibleEndLayout

      public AnchoredLayout getVisibleEndLayout()
      Returns the last visible layout or null if there are no visible layouts
      Returns:
      the last visible layout
    • repaint

      public void repaint()
      Overrides:
      repaint in class Component
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JPanel
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • stateChanged

      public void stateChanged(ChangeEvent e)
      Specified by:
      stateChanged in interface ChangeListener
    • setBounds

      public void setBounds(int x, int y, int width, int height)
      Overrides:
      setBounds in class Component
    • setBlinkCursor

      public void setBlinkCursor(Boolean blinkCursor)
    • enableSelection

      public void enableSelection(boolean b)
    • setHorizontalScrollingEnabled

      public void setHorizontalScrollingEnabled(boolean enabled)
    • getBackgroundColor

      public Color getBackgroundColor()
      Returns the default background color.
      Returns:
      the default background color.
      See Also:
    • getBackground

      public Color getBackground()
      Overrides:
      getBackground in class Component
    • setBackgroundColor

      public void setBackgroundColor(Color c)
      Sets the default background color
      Parameters:
      c - the color to use for the background.
    • getBackgroundColor

      public Color getBackgroundColor(BigInteger index)
    • setBackgroundColorModel

      public void setBackgroundColorModel(BackgroundColorModel model)
    • getForegroundColor

      public Color getForegroundColor()
      Returns the foreground color.
      Returns:
      the foreground color.
    • getSelectionColor

      public Color getSelectionColor()
      Returns the color used as the background for selected items.
      Returns:
      the color used as the background for selected items.
    • getHighlightColor

      public Color getHighlightColor()
      Returns the color color used as the background for highlighted items.
      Returns:
      the color color used as the background for highlighted items.
    • getFocusedCursorColor

      public Color getFocusedCursorColor()
      Returns the cursor color when this field panel is focused.
      Returns:
      the cursor color when this field panel is focused.
    • getNonFocusCursorColor

      public Color getNonFocusCursorColor()
      Returns the cursor color when this field panel is not focused.
      Returns:
      the cursor color when this field panel is not focused.
    • isFocused

      public boolean isFocused()
    • dispose

      public void dispose()
      Cleans up resources when this FieldPanel is no longer needed.
    • getCursorPoint

      public Point getCursorPoint()
      Returns the point in pixels of where the cursor is located.
      Returns:
      the point in pixels of where the cursor is located.
    • getCursorBounds

      public Rectangle getCursorBounds()
    • getCursorLocation

      public FieldLocation getCursorLocation()
    • getCurrentField

      public Field getCurrentField()
    • addIndexScrollListener

      public void addIndexScrollListener(IndexScrollListener listener)
      Description copied from interface: IndexedScrollable
      Adds a listener to be notified when the view is scrolled in any way.
      Specified by:
      addIndexScrollListener in interface IndexedScrollable
      Parameters:
      listener - the listener to be notified when the visible items change
    • removeIndexScrollListener

      public void removeIndexScrollListener(IndexScrollListener listener)
      Description copied from interface: IndexedScrollable
      Removes the given listener from those to be notified when the view changes.
      Specified by:
      removeIndexScrollListener in interface IndexedScrollable
      Parameters:
      listener - the listener to remove
    • addFieldSelectionListener

      public void addFieldSelectionListener(FieldSelectionListener listener)
    • removeFieldSelectionListener

      public void removeFieldSelectionListener(FieldSelectionListener listener)
    • addLiveFieldSelectionListener

      public void addLiveFieldSelectionListener(FieldSelectionListener listener)
      Adds a selection listener that will be notified while the selection is being created
      Parameters:
      listener - the listener to be notified
    • removeLiveFieldSelectionListener

      public void removeLiveFieldSelectionListener(FieldSelectionListener listener)
      Removes the selection listener from being notified when the selection is being created
      Parameters:
      listener - the listener to be removed from being notified
    • addHighlightListener

      public void addHighlightListener(FieldSelectionListener listener)
    • removeHighlightListener

      public void removeHighlightListener(FieldSelectionListener listener)
    • addFieldMouseListener

      public void addFieldMouseListener(FieldMouseListener listener)
    • removeFieldMouseListener

      public void removeFieldMouseListener(FieldMouseListener listener)
    • addFieldInputListener

      public void addFieldInputListener(FieldInputListener listener)
    • removeFieldInputListener

      public void removeFieldInputListener(FieldInputListener listener)
    • addFieldLocationListener

      public void addFieldLocationListener(FieldLocationListener listener)
    • removeFieldLocationListener

      public void removeFieldLocationListener(FieldLocationListener listener)
    • addLayoutListener

      public void addLayoutListener(LayoutListener listener)
    • removeLayoutListener

      public void removeLayoutListener(LayoutListener listener)
    • addViewListener

      public void addViewListener(ViewListener listener)
    • removeViewListener

      public void removeViewListener(ViewListener listener)
    • setHoverProvider

      public void setHoverProvider(HoverProvider hoverProvider)
      Add a new hover provider to be managed.
      Parameters:
      hoverProvider - the new hover provider to be managed.
    • getHoverHandler

      public HoverHandler getHoverHandler()
      Returns the class responsible for triggering popups for this field panel.
      Returns:
      the hover handler.
    • getFieldAt

      public Field getFieldAt(int x, int y, FieldLocation loc)
      Returns the Field at the given x,y coordinates. Note the x,y must currently be visible on the screen or else this method will return null.
      Parameters:
      x - the x mouse coordinate in the component.
      y - the y mouse coordinate in the component.
      loc - will be filled in with the FieldLocation for the given point. Values will be undefined if the Field return value is null.
      Returns:
      Field the Field object the point is over.
    • clearSelection

      public void clearSelection()
      Clears the selection;
    • clearHighlight

      public void clearHighlight()
      Clears the marked area highlight;
    • setFocusedCursorColor

      public void setFocusedCursorColor(Color color)
      Sets the cursor color for when this component has focus.
      Parameters:
      color - Color to use for the cursor when this component has keyboard focus.
    • setNonFocusCursorColor

      public void setNonFocusCursorColor(Color color)
      Sets the cursor color for when this component does not have focus.
      Parameters:
      color - Color to use for the cursor when this component does not have keyboard focus.
    • getSelection

      public FieldSelection getSelection()
      Returns the current selection.
      Returns:
      the current selection.
    • getHighlight

      public FieldSelection getHighlight()
      Returns the current highlight (marked area).
      Returns:
      the current highlight (marked area).
    • setSelection

      public void setSelection(FieldSelection sel)
      Sets the current selection.
      Parameters:
      sel - the selection to set.
    • setSelection

      public void setSelection(FieldSelection sel, EventTrigger trigger)
      Sets the current selection.
      Parameters:
      sel - the selection to set.
      trigger - the cause of the change
    • setHighlight

      public void setHighlight(FieldSelection sel)
      Sets the current highlight to the specified field selection.
      Parameters:
      sel - the selection to set as the highlight.
    • setCursorPosition

      public boolean setCursorPosition(BigInteger index, int fieldNum, int row, int col)
      Sets the cursorPosition to the given location.
      Parameters:
      index - the index of the Layout on which to place the cursor.
      fieldNum - the index of the field within its layout on which to place the cursor.
      row - the row within the field to place the cursor.
      col - the col within the row to place the cursor.
      Returns:
      true if the cursor changed
    • setCursorPosition

      public boolean setCursorPosition(BigInteger index, int fieldNum, int row, int col, EventTrigger trigger)
      Sets the cursorPosition to the given location with the given trigger.
      Parameters:
      index - the index of the Layout on which to place the cursor.
      fieldNum - the index of the field within its layout on which to place the cursor.
      row - the row within the field to place the cursor.
      col - the col within the row to place the cursor.
      trigger - a caller-specified event trigger.
      Returns:
      true if the cursor changed
    • setCursorOn

      public void setCursorOn(boolean cursorOn)
      Sets the cursor on or off. When the cursor is turned off, there is no visible cursor displayed on the screen.
      Parameters:
      cursorOn - true turns the cursor on, false turns it off.
    • isCursorOn

      public boolean isCursorOn()
      Returns the state of the cursor. True if on, false if off.
      Returns:
      the state of the cursor. True if on, false if off.
    • scrollToCursor

      public void scrollToCursor()
    • goTo

      public void goTo(BigInteger index, int fieldNum, int row, int col, boolean alwaysCenterCursor)
      Sets the cursor to the given Field location and attempts to show that location in the center of the screen.
      Parameters:
      index - the index of the line to go to.
      fieldNum - the field on the line to go to.
      row - the row in the field to go to.
      col - the column in the field to go to.
      alwaysCenterCursor - if true, centers cursor on screen. Otherwise, only centers cursor if cursor is offscreen.
    • goTo

      protected void goTo(BigInteger index, int fieldNum, int row, int col, boolean alwaysCenterCursor, EventTrigger trigger)
    • takeFocus

      public void takeFocus()
      Tell the panel to grab the keyboard input focus.
    • positionCursor

      public void positionCursor(int offset)
      Scrolls the view so that the cursor is at the given offset from the top of the screen
      Parameters:
      offset - the pixel distance from the top of the screen at which to scroll the display such that the cursor is at that offset.
    • isStartDragOK

      public boolean isStartDragOK()
    • setSelectionColor

      public void setSelectionColor(Color color)
      Sets the selection color
      Parameters:
      color - the color to use for selection.
    • setHighlightColor

      public void setHighlightColor(Color color)
      Sets the highlight color
      Parameters:
      color - the color to use for highlights.
    • getViewerPosition

      public ViewerPosition getViewerPosition()
      Returns a ViewerPosition object which contains the top of screen information. The ViewerPosition will have the index of the layout at the top of the screen and the yPos of that layout. For example, if the layout is completely displayed, yPos will be 0. If part of the layout is off the top off the screen, then yPos will have a negative value (indicating that it begins above the displayable part of the screen.
      Returns:
      the position
    • setViewerPosition

      public void setViewerPosition(BigInteger index, int xPos, int yPos)
      Scrolls the display to show the layout specified by index at the vertical position specified by yPos. Generally, the index will be layout at the top of the screen and the yPos will be <= 0, meaning the layout may be partially off the top of the screen.
      Parameters:
      index - the index of the layout to show at the top of the screen.
      xPos - the x position to set.
      yPos - the y position to set.
    • getLayoutModel

      public LayoutModel getLayoutModel()
    • setLayoutModel

      public void setLayoutModel(LayoutModel model)
      Sets the layout model for this field panel
      Parameters:
      model - the layout model to use.
    • dataChanged

      public void dataChanged(BigInteger start, BigInteger end)
      Description copied from interface: LayoutModelListener
      Called when the data at an index or range of indexes changes.
      Specified by:
      dataChanged in interface LayoutModelListener
      Parameters:
      start - the starting index for the region of data changes.
      end - the ending index (inclusive) for the region of data changes.
    • modelSizeChanged

      public void modelSizeChanged(IndexMapper indexMapper)
      Description copied from interface: LayoutModelListener
      Called whenever the number of indexes changed
      Specified by:
      modelSizeChanged in interface LayoutModelListener
      Parameters:
      indexMapper - Maps indexes from before the model size change to indexes after the model size changed.
    • paintComponent

      protected void paintComponent(Graphics g)
      Overrides:
      paintComponent in class JComponent
    • getOffset

      public int getOffset(FieldLocation location)
    • getCursorOffset

      public int getCursorOffset()
      Returns the offset of the cursor from the top of the screen
      Returns:
      the offset of the cursor from the top of the screen
    • getLayoutSelectionMap

      protected LayoutBackgroundColorManager getLayoutSelectionMap(BigInteger layoutIndex)
    • getPointForLocation

      public Point getPointForLocation(FieldLocation location)
    • getLocationForPoint

      public FieldLocation getLocationForPoint(int x, int y)
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class JPanel
    • mouseWheelMoved

      public void mouseWheelMoved(double preciseWheelRotation, boolean horizontal)
      Description copied from interface: IndexedScrollable
      Notify the scrollable that the mouse wheel was moved.
      Specified by:
      mouseWheelMoved in interface IndexedScrollable
      Parameters:
      preciseWheelRotation - the amount of rotation of the wheel
      horizontal - true if the rotation was horizontal, false for vertical