Class SwingMessageTable<D>

Type Parameters:
D - the type of document identifiers
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable

public class SwingMessageTable<D> extends JTable
Multi-line rendering for messages, to be included in a Swing based GUI.

Two graphical columns are supported, for the location and the (formatted and translated) message text. The kind is shown by background color.

Resorting of lines and columns is not supported, so a row number of the swing table always correspond to the index in the MessageTable.

Inspired by https://coderanch.com/t/341698/java/TableRenderer-multiple-lines-text

For "setLineWrap(true)": thanks to https://www.experts-exchange.com/questions/21475798/jtable-line-wrap.html

See Also:
  • Field Details

    • COLNUM_LOCATION

      protected static final int COLNUM_LOCATION
      Number of the message location column
      See Also:
    • COLNUM_TEXT

      protected static final int COLNUM_TEXT
      Number of the message text column
      See Also:
    • standardColor_warn

      public static final Color standardColor_warn
      Background color for warning messages
    • standardColor_error

      public static final Color standardColor_error
      Background color for error messages
    • standardColor_neutral

      public static final Color standardColor_neutral
      Background color for all other messages
    • standardColor_hint

      public static final Color standardColor_hint
      Background color for hint messages
    • colorWarn

      protected Color colorWarn
      Background color for warning messages
    • colorError

      protected Color colorError
      Background color for error messages
    • colorNeutral

      protected Color colorNeutral
      Background color for all other messages
    • colorHint

      protected Color colorHint
      Background color for hint messages
    • separatorColor

      protected Color separatorColor
      Background color for separator line.
    • separatorKey

      @Opt protected @Opt String separatorKey
      Message text which makes a bold horizontal line, nothing else.
    • translate

      protected Function<? super SimpleMessage<D>,String> translate
      Function used to translate the message text and its arguments. (Kind, location, cause, etc. do not need multi-lingual support.)
    • indentString

      protected String indentString
      The string prepended n times before the text to indicate the nesting of logg messages.
  • Constructor Details

    • SwingMessageTable

      public SwingMessageTable(MessageStore<SimpleMessage<D>>.TableModel model)
      Only constructor, needs an instance of a table model. After construction, setup() must be called for the completion of this instance configuration.
      Parameters:
      model - the table model to display
  • Method Details

    • setColorWarn

      public Color setColorWarn(Color nc)
      Set the color used to signal warning messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorError

      public Color setColorError(Color nc)
      Set the color used to signal error messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorHint

      public Color setColorHint(Color nc)
      Set the color used to signal hint messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setColorNeutral

      public Color setColorNeutral(Color nc)
      Set the color used to signal all other messages.
      Parameters:
      nc - the new color setting .
      Returns:
      the old color setting
    • setSeparatorKey

      @Opt public @Opt String setSeparatorKey(@Opt @Opt String separatorKey)
      Sets the message text which causes the message to be shown simply as one big grey separating block.
      Parameters:
      separatorKey - which will be shown as a separating block
      Returns:
      the old value
    • setTranslate

      public SwingMessageTable<D> setTranslate(Function<? super SimpleMessage<D>,String> fun)
      Set the function used to translate the message text and its arguments.
      Parameters:
      fun - the new function for translation
      Returns:
      this for method chaining
    • setIndentString

      public SwingMessageTable<D> setIndentString(String s)
      Set the string to visualize the indentation of messages.
      Parameters:
      s - the string to visualize the indentation of messages.
      Returns:
      this for method chaining
    • getMessageAt

      protected SimpleMessage<D> getMessageAt(int row)
      Get the message from the underlying message store at the given position.
      Parameters:
      row - the index position of the message
      Returns:
      the message at the given position in the message store
    • prepareRenderer

      public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
      Filters for separatorKey and draws a thick line instead. This method is called by the swing table package to modify a found table cell renderer, w.r.t selection state and/or enabled state, etc., and can be safely overridden, as done here.

      (Thanks to Robert Camick Table Row Rendering.)

      Overrides:
      prepareRenderer in class JTable
      Parameters:
      renderer - is prepared to show the contents of the normal table rows which are not separators.
      row - number in the current view. Is the same as in the TableModel as long as rows are not re-sorted.
      column - number in the current view. Is the same as in the TableModel as long as columns are not re-arranged.
    • setup

      public SwingMessageTable<D> setup()
      Completion of the configuration after construction. This method sets Swing attributes by method invocations. These are separate from the constructor to avoid "this-escapes" with future subclasses.

      ("Drag-and-Drop"/"DnD" is disabled since no handler is explicitly set.) (Column header is shown with no contents, to allow interactive change of column width.)

      Returns:
      this instance, for method chaining.
    • setwidth_minpref

      protected void setwidth_minpref(int colnum, int width)
      Sets minimal und preferred width of one particular column.
      Parameters:
      colnum - the number of the column
      width - the value for minimal and preferred width