|  1 |     | 
   package de.glossmaker.gui.gloss.main.tableview;  | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
   import javax.swing.*;  | 
  |  6 |     | 
   import javax.swing.table.TableCellRenderer;  | 
  |  7 |     | 
   import javax.swing.border.*;  | 
  |  8 |     | 
     | 
  |  9 |     | 
   import de.glossmaker.common.document.LaTeXStyledDocument;  | 
  |  10 |     | 
   import de.glossmaker.gloss.datastructure.gui.Config;  | 
  |  11 |     | 
   import de.glossmaker.gloss.listener.EActionCommands;  | 
  |  12 |     | 
   import de.glossmaker.gloss.observer.GlossItemsChangePublisher;  | 
  |  13 |     | 
     | 
  |  14 |     | 
   import java.awt.Component;  | 
  |  15 |     | 
   import java.awt.Color;  | 
  |  16 |     | 
   import java.beans.PropertyChangeEvent;  | 
  |  17 |     | 
   import java.beans.PropertyChangeListener;  | 
  |  18 |     | 
     | 
  |  19 |     | 
   import java.io.Serializable;  | 
  |  20 |     | 
     | 
  |  21 |     | 
     | 
  |  22 |     | 
     | 
  |  23 |     | 
     | 
  |  24 |     | 
     | 
  |  25 |     | 
     | 
  |  26 |     | 
     | 
  |  27 |     | 
     | 
  |  28 |     | 
     | 
  |  29 |     | 
   @SuppressWarnings("serial") | 
  |  30 |     | 
   public class MultiLineCellRenderer extends JTextPane implements TableCellRenderer,   | 
  |  31 |     | 
   Serializable, PropertyChangeListener { | 
  |  32 |     | 
     | 
  |  33 |     | 
     protected static Border noFocusBorder;   | 
  |  34 |     | 
         | 
  |  35 |     | 
     private Color unselectedForeground;   | 
  |  36 |     | 
     private Color unselectedBackground;  | 
  |  37 |     | 
     | 
  |  38 |     | 
     private LaTeXStyledDocument mDocument;   | 
  |  39 |     | 
     | 
  |  40 |     | 
     public MultiLineCellRenderer() { | 
  |  41 |    0 |        super();  | 
  |  42 |    0 |        mDocument = new LaTeXStyledDocument(Config.getInstance().isPrintBlankAndTabs());  | 
  |  43 |    0 |        setDocument(mDocument);  | 
  |  44 |    0 |        noFocusBorder = new EmptyBorder(1, 2, 1, 2);  | 
  |  45 |    0 |        setOpaque(true);  | 
  |  46 |    0 |        setBorder(noFocusBorder);  | 
  |  47 |    0 |        GlossItemsChangePublisher.getInstance(null).addPropertyChangeListener(this);  | 
  |  48 |    0 |      }  | 
  |  49 |     | 
     | 
  |  50 |     | 
     public void setForeground(Color c) { | 
  |  51 |    0 |        super.setForeground(c);   | 
  |  52 |    0 |        unselectedForeground = c;   | 
  |  53 |    0 |      }  | 
  |  54 |     | 
         | 
  |  55 |     | 
     public void setBackground(Color c) { | 
  |  56 |    0 |        super.setBackground(c);   | 
  |  57 |    0 |        unselectedBackground = c;   | 
  |  58 |    0 |      }  | 
  |  59 |     | 
     | 
  |  60 |     | 
     public void updateUI() { | 
  |  61 |    0 |        super.updateUI();   | 
  |  62 |    0 |        setForeground(null);  | 
  |  63 |    0 |        setBackground(null);  | 
  |  64 |    0 |      }  | 
  |  65 |     | 
         | 
  |  66 |     | 
     public Component getTableCellRendererComponent(JTable table, Object value,  | 
  |  67 |     | 
                                                    boolean isSelected, boolean hasFocus,   | 
  |  68 |     | 
                                                    int row, int column) { | 
  |  69 |     | 
     | 
  |  70 |    0 |        if (isSelected) { | 
  |  71 |    0 |          super.setForeground(table.getSelectionForeground());  | 
  |  72 |    0 |          super.setBackground(table.getSelectionBackground());  | 
  |  73 |     | 
       }  | 
  |  74 |     | 
       else { | 
  |  75 |    0 |          super.setForeground((unselectedForeground != null) ? unselectedForeground   | 
  |  76 |     | 
                             : table.getForeground());  | 
  |  77 |    0 |          super.setBackground((unselectedBackground != null) ? unselectedBackground   | 
  |  78 |     | 
                             : table.getBackground());  | 
  |  79 |     | 
       }  | 
  |  80 |     | 
             | 
  |  81 |    0 |        setFont(table.getFont());  | 
  |  82 |     | 
     | 
  |  83 |    0 |        if (hasFocus) { | 
  |  84 |    0 |          setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") ); | 
  |  85 |    0 |          if (table.isCellEditable(row, column)) { | 
  |  86 |    0 |            super.setForeground( UIManager.getColor("Table.focusCellForeground") ); | 
  |  87 |    0 |            super.setBackground( UIManager.getColor("Table.focusCellBackground") ); | 
  |  88 |     | 
         }  | 
  |  89 |     | 
       } else { | 
  |  90 |    0 |          setBorder(noFocusBorder);  | 
  |  91 |     | 
       }  | 
  |  92 |     | 
     | 
  |  93 |    0 |        setValue(value);   | 
  |  94 |     | 
             | 
  |  95 |    0 |        return this;  | 
  |  96 |     | 
     }  | 
  |  97 |     | 
         | 
  |  98 |     | 
     protected void setValue(Object value) { | 
  |  99 |    0 |        setText((value == null) ? "" : value.toString());  | 
  |  100 |    0 |      }  | 
  |  101 |     | 
     | 
  |  102 |     | 
     @Override  | 
  |  103 |     | 
           public void propertyChange(PropertyChangeEvent event) { | 
  |  104 |    0 |                    if (event.getPropertyName().equals(EActionCommands.SPECIAL_CHARS.toString())) { | 
  |  105 |    0 |                            mDocument.setShowSpecialCharacters((Boolean)event.getNewValue());  | 
  |  106 |    0 |                            setText(mDocument.getText());  | 
  |  107 |    0 |                            updateUI();  | 
  |  108 |     | 
                   }  | 
  |  109 |    0 |            }  | 
  |  110 |     | 
     | 
  |  111 |     | 
       | 
  |  112 |     | 
       | 
  |  113 |     | 
     | 
  |  114 |     | 
     | 
  |  115 |     | 
     | 
  |  116 |     | 
   }  | 
  |  117 |     | 
     | 
  |  118 |     | 
     |