1 | |
package de.glossmaker.gui.gloss.main.tableview; |
2 | |
|
3 | |
import java.awt.Component; |
4 | |
import java.beans.PropertyChangeEvent; |
5 | |
import java.beans.PropertyChangeListener; |
6 | |
|
7 | |
import javax.swing.AbstractCellEditor; |
8 | |
import javax.swing.JScrollPane; |
9 | |
import javax.swing.JTable; |
10 | |
import javax.swing.JTextPane; |
11 | |
import javax.swing.border.Border; |
12 | |
import javax.swing.border.EmptyBorder; |
13 | |
import javax.swing.table.TableCellEditor; |
14 | |
|
15 | |
import de.glossmaker.common.document.LaTeXStyledDocument; |
16 | |
import de.glossmaker.gloss.datastructure.gui.Config; |
17 | |
import de.glossmaker.gloss.listener.EActionCommands; |
18 | |
import de.glossmaker.gloss.observer.GlossItemsChangePublisher; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
public class MultiLineCellEditor extends AbstractCellEditor implements TableCellEditor, PropertyChangeListener { |
26 | |
private static final long serialVersionUID = 1L; |
27 | |
protected static Border noFocusBorder; |
28 | 0 | private JScrollPane mScrollPane = null; |
29 | 0 | private JTextPane mTextPane = null; |
30 | |
|
31 | |
private LaTeXStyledDocument mDocument; |
32 | |
|
33 | |
public MultiLineCellEditor() { |
34 | 0 | super(); |
35 | 0 | mScrollPane = new JScrollPane(); |
36 | 0 | mScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
37 | 0 | mScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
38 | 0 | mTextPane = new JTextPane(); |
39 | 0 | noFocusBorder = new EmptyBorder(1, 2, 1, 2); |
40 | 0 | mTextPane.setOpaque(true); |
41 | 0 | mTextPane.setBorder(noFocusBorder); |
42 | 0 | mDocument = new LaTeXStyledDocument(Config.getInstance().isPrintBlankAndTabs()); |
43 | 0 | mTextPane.setDocument(mDocument); |
44 | 0 | mScrollPane.setViewportView(mTextPane); |
45 | 0 | GlossItemsChangePublisher.getInstance(null).addPropertyChangeListener(this); |
46 | 0 | } |
47 | |
|
48 | |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) |
49 | |
{ |
50 | 0 | mTextPane.setText(value.toString()); |
51 | 0 | return mScrollPane; |
52 | |
} |
53 | |
|
54 | |
public Object getCellEditorValue() |
55 | |
{ |
56 | 0 | return mTextPane.getText(); |
57 | |
} |
58 | |
|
59 | |
@Override |
60 | |
public void propertyChange(PropertyChangeEvent event) { |
61 | 0 | if (event.getPropertyName().equals(EActionCommands.SPECIAL_CHARS.toString())) { |
62 | 0 | mDocument.setShowSpecialCharacters((Boolean)event.getNewValue()); |
63 | 0 | mTextPane.setText(mDocument.getText()); |
64 | |
} |
65 | 0 | } |
66 | |
} |