1 | package com.framsticks.gui.controls; |
---|
2 | |
---|
3 | import java.awt.Dimension; |
---|
4 | import java.awt.event.ActionEvent; |
---|
5 | import java.awt.event.ActionListener; |
---|
6 | |
---|
7 | import javax.swing.JButton; |
---|
8 | import javax.swing.JCheckBox; |
---|
9 | import javax.swing.JPanel; |
---|
10 | import javax.swing.JScrollPane; |
---|
11 | import javax.swing.JTable; |
---|
12 | |
---|
13 | import com.framsticks.gui.Gui; |
---|
14 | import com.framsticks.params.Param; |
---|
15 | import com.framsticks.util.swing.TooltipConstructor; |
---|
16 | |
---|
17 | @SuppressWarnings("serial") |
---|
18 | public abstract class HistoryControl extends Control { |
---|
19 | |
---|
20 | protected final JPanel controlRow; |
---|
21 | protected final JButton mainButton; |
---|
22 | protected final JCheckBox foldingCheckbox; |
---|
23 | protected final JButton clearButton; |
---|
24 | |
---|
25 | protected final JScrollPane resultsScrollPane; |
---|
26 | protected final JTable resultsTable; |
---|
27 | |
---|
28 | public HistoryControl(Param param) { |
---|
29 | super(param); |
---|
30 | |
---|
31 | this.setToolTipText(new TooltipConstructor() |
---|
32 | .append("name", param.getName()) |
---|
33 | .append("id", param.getId()) |
---|
34 | .append("help", param.getHelp()) |
---|
35 | .build()); |
---|
36 | |
---|
37 | controlRow = new JPanel(); |
---|
38 | controlRow.setName("control_row"); |
---|
39 | |
---|
40 | mainButton = new JButton(); |
---|
41 | |
---|
42 | mainButton.setMaximumSize(new Dimension(Integer.MAX_VALUE, LINE_HEIGHT)); |
---|
43 | |
---|
44 | clearButton = new JButton("Clear"); |
---|
45 | clearButton.setName("clear"); |
---|
46 | |
---|
47 | foldingCheckbox = new JCheckBox("Fold"); |
---|
48 | foldingCheckbox.setName("folding"); |
---|
49 | foldingCheckbox.setSelected(true); |
---|
50 | |
---|
51 | foldingCheckbox.addActionListener(new ActionListener() { |
---|
52 | @Override |
---|
53 | public void actionPerformed(ActionEvent e) { |
---|
54 | updateFoldState(); |
---|
55 | } |
---|
56 | }); |
---|
57 | |
---|
58 | |
---|
59 | clearButton.addActionListener(new ActionListener() { |
---|
60 | @Override |
---|
61 | public void actionPerformed(ActionEvent e) { |
---|
62 | clearTable(); |
---|
63 | } |
---|
64 | }); |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | Gui.layoutInRow(controlRow, mainButton, foldingCheckbox, clearButton); |
---|
69 | |
---|
70 | resultsTable = new JTable(); |
---|
71 | resultsScrollPane = new JScrollPane(resultsTable); |
---|
72 | resultsTable.setShowGrid(false); |
---|
73 | |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | public boolean isFolded() { |
---|
78 | return foldingCheckbox.isSelected(); |
---|
79 | } |
---|
80 | |
---|
81 | protected void updateFoldState() { |
---|
82 | int lines = isFolded() ? 1 : 5; |
---|
83 | int height = lines * LINE_HEIGHT; |
---|
84 | // resultsTable.getTableHeader().setVisible(!isFolded()); |
---|
85 | resultsScrollPane.setColumnHeaderView(!isFolded() ? resultsTable.getTableHeader() : null); |
---|
86 | resultsScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, height)); |
---|
87 | resultsScrollPane.setPreferredSize(new Dimension(0, height)); |
---|
88 | if (owner != null) { |
---|
89 | refreshTable(); |
---|
90 | } |
---|
91 | this.revalidate(); |
---|
92 | // foldingButton.setText(isFolded ? "Unfold" : "Fold"); |
---|
93 | } |
---|
94 | |
---|
95 | protected abstract void refreshTable(); |
---|
96 | |
---|
97 | protected abstract void clearTable(); |
---|
98 | |
---|
99 | } |
---|