1 | |
package org.homeunix.thecave.buddi.plugin.api; |
2 | |
|
3 | |
import java.awt.Color; |
4 | |
import java.awt.Component; |
5 | |
import java.awt.Dimension; |
6 | |
import java.awt.Graphics; |
7 | |
import java.awt.event.ActionEvent; |
8 | |
import java.awt.event.ActionListener; |
9 | |
|
10 | |
import javax.swing.Icon; |
11 | |
import javax.swing.JButton; |
12 | |
import javax.swing.JLabel; |
13 | |
import javax.swing.JPanel; |
14 | |
|
15 | |
import org.homeunix.thecave.buddi.model.Document; |
16 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
17 | |
import org.homeunix.thecave.buddi.view.MainFrame; |
18 | |
|
19 | |
import ca.digitalcave.moss.application.document.DocumentChangeEvent; |
20 | |
import ca.digitalcave.moss.application.document.DocumentChangeListener; |
21 | |
import ca.digitalcave.moss.application.plugin.MossPlugin; |
22 | |
import ca.digitalcave.moss.swing.MossPanel; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public abstract class BuddiPanelPlugin extends MossPanel implements MossPlugin { |
29 | |
private static final long serialVersionUID = 0L; |
30 | |
private MainFrame parentFrame; |
31 | |
protected Document document; |
32 | |
private DocumentChangeListener listener; |
33 | |
|
34 | |
private CloseTabButton tabButton; |
35 | |
|
36 | |
public abstract String getTabLabelKey(); |
37 | |
|
38 | |
public abstract boolean isSingleton(); |
39 | |
|
40 | |
public abstract boolean isStartedAutomatically(); |
41 | |
|
42 | |
public abstract boolean isPersisted(); |
43 | |
|
44 | |
public abstract void initPanel(); |
45 | |
|
46 | |
public abstract void updatePanel(); |
47 | |
|
48 | |
@Override |
49 | |
public void init() { |
50 | 0 | super.init(); |
51 | 0 | tabButton = new CloseTabButton(this, TextFormatter.getTranslation(getTabLabelKey())); |
52 | 0 | initPanel(); |
53 | 0 | } |
54 | |
|
55 | |
@Override |
56 | |
public void updateContent() { |
57 | 0 | super.updateContent(); |
58 | 0 | updatePanel(); |
59 | 0 | } |
60 | |
|
61 | |
public void close() { |
62 | 0 | parentFrame.removePanel(this); |
63 | |
|
64 | |
|
65 | |
|
66 | 0 | } |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public MainFrame getParentFrame() { |
77 | 0 | return parentFrame; |
78 | |
} |
79 | |
|
80 | |
public void setParentFrame(MainFrame parentFrame) { |
81 | 0 | this.parentFrame = parentFrame; |
82 | 0 | listener = new DocumentChangeListener() { |
83 | |
|
84 | |
public void documentChange(DocumentChangeEvent arg0) { |
85 | 0 | updatePanel(); |
86 | 0 | } |
87 | |
}; |
88 | 0 | this.document = (Document) parentFrame.getDocument(); |
89 | 0 | parentFrame.getDocument().addDocumentChangeListener(listener); |
90 | 0 | updateContent(); |
91 | 0 | } |
92 | |
|
93 | |
public boolean wasInUse() { |
94 | |
|
95 | |
|
96 | 0 | return false; |
97 | |
} |
98 | |
|
99 | |
public JPanel getTabComponent(){ |
100 | 0 | return tabButton; |
101 | |
} |
102 | |
|
103 | 0 | class CloseIcon implements Icon { |
104 | |
|
105 | |
public void paintIcon(Component c, Graphics g, int x, int y) { |
106 | 0 | g.setColor(Color.RED); |
107 | 0 | g.drawLine(4, 4, getIconWidth() - 5, getIconHeight() - 5); |
108 | 0 | g.drawLine(getIconWidth() - 5, 4, 4, getIconHeight() - 5); |
109 | 0 | } |
110 | |
|
111 | |
public int getIconWidth() { |
112 | 0 | return 13; |
113 | |
} |
114 | |
|
115 | |
public int getIconHeight() { |
116 | 0 | return 13; |
117 | |
} |
118 | |
} |
119 | |
|
120 | 0 | class CloseTabButton extends JPanel implements ActionListener { |
121 | |
private static final long serialVersionUID = 0L; |
122 | |
|
123 | |
BuddiPanelPlugin plugin; |
124 | |
|
125 | 0 | private CloseTabButton(BuddiPanelPlugin plugin, String title) { |
126 | 0 | this.plugin = plugin; |
127 | 0 | setOpaque(false); |
128 | 0 | add(new JLabel(title,JLabel.LEFT)); |
129 | 0 | Icon closeIcon = new CloseIcon(); |
130 | 0 | JButton btClose = new JButton(closeIcon); |
131 | 0 | btClose.setPreferredSize(new Dimension( |
132 | |
closeIcon.getIconWidth(), closeIcon.getIconHeight())); |
133 | 0 | add(btClose); |
134 | 0 | btClose.addActionListener(this); |
135 | 0 | } |
136 | |
|
137 | |
public void actionPerformed(ActionEvent e) { |
138 | |
|
139 | 0 | } |
140 | |
} |
141 | |
} |