1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
package net.sf.jabref.wizard.integrity.gui ; |
37 | |
|
38 | |
import java.awt.BorderLayout; |
39 | |
import java.awt.Component; |
40 | |
import java.awt.Dimension; |
41 | |
import java.awt.event.ActionEvent; |
42 | |
import java.awt.event.ActionListener; |
43 | |
import java.awt.event.KeyEvent; |
44 | |
import java.awt.event.KeyListener; |
45 | |
|
46 | |
import javax.swing.*; |
47 | |
import javax.swing.event.ListSelectionEvent; |
48 | |
import javax.swing.event.ListSelectionListener; |
49 | |
|
50 | |
import net.sf.jabref.*; |
51 | |
import net.sf.jabref.undo.UndoableFieldChange; |
52 | |
import net.sf.jabref.wizard.integrity.IntegrityCheck; |
53 | |
import net.sf.jabref.wizard.integrity.IntegrityMessage; |
54 | |
import net.sf.jabref.wizard.text.gui.HintListModel; |
55 | |
|
56 | |
public class IntegrityMessagePanel |
57 | |
extends JPanel |
58 | |
implements ListSelectionListener, KeyListener, ActionListener |
59 | |
|
60 | |
{ |
61 | |
private JList warnings ; |
62 | |
private HintListModel warningData ; |
63 | |
|
64 | |
private IntegrityCheck validChecker ; |
65 | |
|
66 | |
private JTextField content ; |
67 | |
private JButton applyButton ; |
68 | |
private JButton fixButton ; |
69 | |
private BasePanel basePanel; |
70 | |
|
71 | |
public IntegrityMessagePanel(BasePanel basePanel) |
72 | 325535 | { |
73 | 325535 | this.basePanel = basePanel; |
74 | 325535 | validChecker = new IntegrityCheck() ; |
75 | |
|
76 | |
|
77 | 325535 | warningData = new HintListModel() ; |
78 | 325535 | warnings = new JList( warningData ) ; |
79 | 325535 | warnings.setCellRenderer( new IntegrityListRenderer() ); |
80 | 325535 | warnings.addListSelectionListener(this); |
81 | |
|
82 | 325535 | JScrollPane paneScrollPane = new JScrollPane( warnings ) ; |
83 | 325535 | paneScrollPane.setVerticalScrollBarPolicy( |
84 | |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ) ; |
85 | 325535 | paneScrollPane.setPreferredSize( new Dimension( 540, 255 ) ) ; |
86 | 325535 | paneScrollPane.setMinimumSize( new Dimension( 10, 10 ) ) ; |
87 | |
|
88 | |
|
89 | 325535 | JPanel fixPanel = new JPanel() ; |
90 | |
|
91 | |
|
92 | 325535 | JLabel label1 = new JLabel(Globals.lang("Field_content")) ; |
93 | |
|
94 | 325535 | content = new JTextField(40) ; |
95 | 325535 | content.addKeyListener(this); |
96 | 325535 | applyButton = new JButton(Globals.lang("Apply")) ; |
97 | 325535 | applyButton.addActionListener(this) ; |
98 | 325535 | applyButton.setEnabled(false); |
99 | 325535 | fixButton = new JButton(Globals.lang("Suggest")) ; |
100 | 325535 | fixButton.setEnabled(false); |
101 | |
|
102 | 325535 | fixPanel.add(label1) ; |
103 | 325535 | fixPanel.add(content) ; |
104 | 325535 | fixPanel.add(applyButton) ; |
105 | 325535 | fixPanel.add(fixButton) ; |
106 | |
|
107 | |
|
108 | 325535 | this.setLayout( new BorderLayout() ); |
109 | 325535 | this.add( paneScrollPane, BorderLayout.CENTER ) ; |
110 | 325535 | this.add( fixPanel, BorderLayout.SOUTH) ; |
111 | 325535 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
public void updateView( BibtexEntry entry ) |
116 | |
{ |
117 | 0 | warningData.clear(); |
118 | 0 | IntegrityMessage.setPrintMode( IntegrityMessage.SINLGE_MODE) ; |
119 | 0 | warningData.setData( validChecker.checkBibtexEntry( entry ) ) ; |
120 | 0 | } |
121 | |
|
122 | |
public void updateView( BibtexDatabase base ) |
123 | |
{ |
124 | 41314 | warningData.clear(); |
125 | 41314 | IntegrityMessage.setPrintMode( IntegrityMessage.FULL_MODE) ; |
126 | 41314 | warningData.setData( validChecker.checkBibtexDatabase( base ) ) ; |
127 | 41314 | } |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public void valueChanged( ListSelectionEvent e ) |
133 | |
{ |
134 | 0 | if ( e.getValueIsAdjusting() ) |
135 | |
{ |
136 | 0 | Object obj = warnings.getSelectedValue() ; |
137 | 0 | String str = "" ; |
138 | 0 | if (obj != null) |
139 | |
{ |
140 | 0 | IntegrityMessage msg = (IntegrityMessage) obj ; |
141 | 0 | BibtexEntry entry = msg.getEntry() ; |
142 | |
|
143 | 0 | if (entry != null) |
144 | |
{ |
145 | 0 | str = entry.getField(msg.getFieldName()) ; |
146 | 0 | basePanel.highlightEntry(entry); |
147 | |
|
148 | |
|
149 | |
|
150 | |
} |
151 | |
} |
152 | 0 | content.setText(str); |
153 | 0 | applyButton.setEnabled(false); |
154 | |
} |
155 | 0 | } |
156 | |
|
157 | |
|
158 | |
|
159 | |
public void keyPressed( KeyEvent e ) |
160 | |
{ |
161 | 0 | } |
162 | |
|
163 | |
public void keyReleased( KeyEvent e ) |
164 | |
{ |
165 | 0 | applyButton.setEnabled(true); |
166 | 0 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
167 | |
{ |
168 | 0 | applyButton.doClick(); |
169 | |
} |
170 | 0 | } |
171 | |
|
172 | |
public void keyTyped( KeyEvent e ) |
173 | |
{ |
174 | 0 | } |
175 | |
|
176 | |
public void actionPerformed( ActionEvent e ) |
177 | |
{ |
178 | 0 | Object obj = e.getSource() ; |
179 | 0 | if (obj == applyButton) |
180 | |
{ |
181 | 0 | Object data = warnings.getSelectedValue() ; |
182 | 0 | if (data != null) |
183 | |
{ |
184 | 0 | IntegrityMessage msg = (IntegrityMessage) data ; |
185 | 0 | BibtexEntry entry = msg.getEntry() ; |
186 | |
|
187 | 0 | if (entry != null) |
188 | |
{ |
189 | |
|
190 | 0 | String oldContent = entry.getField(msg.getFieldName()); |
191 | 0 | UndoableFieldChange edit = new UndoableFieldChange(entry, msg.getFieldName(), oldContent, |
192 | |
content.getText()); |
193 | 0 | entry.setField(msg.getFieldName(), content.getText()); |
194 | 0 | basePanel.undoManager.addEdit(edit); |
195 | 0 | basePanel.markBaseChanged(); |
196 | 0 | msg.setFixed(true); |
197 | |
|
198 | 0 | warningData.valueUpdated(warnings.getSelectedIndex()) ; |
199 | |
} |
200 | |
} |
201 | |
|
202 | 0 | applyButton.setEnabled(false); |
203 | |
} |
204 | 0 | } |
205 | |
|
206 | |
|
207 | 325535 | class IntegrityListRenderer extends DefaultListCellRenderer |
208 | |
{ |
209 | 325535 | final ImageIcon warnIcon = GUIGlobals.getImage("integrityWarn"); |
210 | 325535 | final ImageIcon infoIcon = GUIGlobals.getImage("integrityInfo"); |
211 | 325535 | final ImageIcon failIcon = GUIGlobals.getImage("integrityFail"); |
212 | 325535 | final ImageIcon fixedIcon = GUIGlobals.getImage("complete"); |
213 | |
|
214 | |
public Component getListCellRendererComponent( |
215 | |
JList list, |
216 | |
Object value, |
217 | |
int index, |
218 | |
boolean iss, |
219 | |
boolean chf ) |
220 | |
{ |
221 | 0 | super.getListCellRendererComponent( list, value, index, iss, chf ) ; |
222 | |
|
223 | 0 | if (value != null) |
224 | |
{ |
225 | 0 | IntegrityMessage msg = (IntegrityMessage) value ; |
226 | 0 | if (msg.getFixed()) |
227 | |
{ |
228 | 0 | setIcon(fixedIcon) ; |
229 | |
} |
230 | |
else |
231 | |
{ |
232 | 0 | int id = msg.getType() ; |
233 | 0 | if ( id < 1000 ) |
234 | 0 | setIcon( infoIcon ) ; |
235 | 0 | else if ( id < 2000 ) |
236 | 0 | setIcon( warnIcon ) ; |
237 | 0 | else setIcon( failIcon ) ; |
238 | |
} |
239 | |
} |
240 | 0 | return this ; |
241 | |
} |
242 | |
} |
243 | |
|
244 | |
} |