6 package de.uni_hamburg.corpora.swing;
13 import java.io.IOException;
14 import java.net.MalformedURLException;
16 import java.nio.file.Paths;
17 import java.util.logging.Level;
18 import java.util.logging.Logger;
19 import javax.swing.JFileChooser;
20 import javax.swing.JFrame;
21 import javax.swing.JOptionPane;
22 import javax.xml.parsers.DocumentBuilder;
23 import javax.xml.parsers.DocumentBuilderFactory;
24 import javax.xml.parsers.ParserConfigurationException;
25 import javax.xml.transform.TransformerException;
26 import javax.xml.xpath.XPathExpressionException;
27 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
28 import org.w3c.dom.Document;
29 import org.xml.sax.SAXException;
38 String transcriptName;
52 @SuppressWarnings(
"unchecked")
54 private void initComponents() {
56 jPopupMenu1 =
new javax.swing.JPopupMenu();
57 jPopupMenu2 =
new javax.swing.JPopupMenu();
58 jPanel1 =
new javax.swing.JPanel();
59 jPanel2 =
new javax.swing.JPanel();
60 jLabel1 =
new javax.swing.JLabel();
61 firstVersion =
new javax.swing.JComboBox();
62 browseButton =
new javax.swing.JButton();
63 jPanel3 =
new javax.swing.JPanel();
64 jLabel2 =
new javax.swing.JLabel();
65 secondVersion =
new javax.swing.JComboBox();
66 browseButton2 =
new javax.swing.JButton();
67 jPanel4 =
new javax.swing.JPanel();
68 jScrollPane2 =
new javax.swing.JScrollPane();
69 firstVersionPane =
new javax.swing.JTextPane();
70 jLabel3 =
new javax.swing.JLabel();
71 compareButton =
new javax.swing.JButton();
72 mergeButton =
new javax.swing.JButton();
74 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
76 jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
"", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font(
"SansSerif", 1, 24)));
79 jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
"First Version of The Exb File", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font(
"SansSerif", 1, 14)));
81 jLabel1.setFont(
new java.awt.Font(
"Tahoma", 0, 14));
82 jLabel1.setText(
"File Path:");
84 firstVersion.setEditable(
true);
85 firstVersion.setFont(
new java.awt.Font(
"Times New Roman", 0, 14));
86 firstVersion.addActionListener(
new java.awt.event.ActionListener() {
87 public void actionPerformed(java.awt.event.ActionEvent evt) {
88 firstVersionActionPerformed(evt);
92 browseButton.setText(
"Browse");
93 browseButton.addActionListener(
new java.awt.event.ActionListener() {
94 public void actionPerformed(java.awt.event.ActionEvent evt) {
95 browseButtonActionPerformed(evt);
99 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
100 jPanel2.setLayout(jPanel2Layout);
101 jPanel2Layout.setHorizontalGroup(
102 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
103 .addGroup(jPanel2Layout.createSequentialGroup()
105 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
106 .addGroup(jPanel2Layout.createSequentialGroup()
107 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
108 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
109 .addComponent(firstVersion, 0, 702, Short.MAX_VALUE))
110 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
111 .addGap(0, 0, Short.MAX_VALUE)
112 .addComponent(browseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
115 jPanel2Layout.setVerticalGroup(
116 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117 .addGroup(jPanel2Layout.createSequentialGroup()
119 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
120 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
121 .addComponent(firstVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
122 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
123 .addComponent(browseButton)
124 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
127 jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
"Second Version of The Exb File", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font(
"SansSerif", 1, 14)));
129 jLabel2.setFont(
new java.awt.Font(
"Tahoma", 0, 14));
130 jLabel2.setText(
"File Path:");
132 secondVersion.setEditable(
true);
133 secondVersion.setFont(
new java.awt.Font(
"Times New Roman", 0, 14));
135 browseButton2.setText(
"Browse");
136 browseButton2.addActionListener(
new java.awt.event.ActionListener() {
137 public void actionPerformed(java.awt.event.ActionEvent evt) {
138 browseButton2ActionPerformed(evt);
142 javax.swing.GroupLayout jPanel3Layout =
new javax.swing.GroupLayout(jPanel3);
143 jPanel3.setLayout(jPanel3Layout);
144 jPanel3Layout.setHorizontalGroup(
145 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146 .addGroup(jPanel3Layout.createSequentialGroup()
148 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
149 .addGroup(jPanel3Layout.createSequentialGroup()
150 .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
151 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
152 .addComponent(secondVersion, 0, 702, Short.MAX_VALUE))
153 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
154 .addGap(0, 0, Short.MAX_VALUE)
155 .addComponent(browseButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
158 jPanel3Layout.setVerticalGroup(
159 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
160 .addGroup(jPanel3Layout.createSequentialGroup()
162 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
163 .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
164 .addComponent(secondVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
165 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
166 .addComponent(browseButton2)
167 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170 jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
"Differences Between Two Versions", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font(
"SansSerif", 1, 14)));
172 jScrollPane2.setViewportView(firstVersionPane);
174 javax.swing.GroupLayout jPanel4Layout =
new javax.swing.GroupLayout(jPanel4);
175 jPanel4.setLayout(jPanel4Layout);
176 jPanel4Layout.setHorizontalGroup(
177 jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178 .addGroup(jPanel4Layout.createSequentialGroup()
180 .addComponent(jScrollPane2)
183 jPanel4Layout.setVerticalGroup(
184 jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
185 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
187 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
191 jLabel3.setFont(
new java.awt.Font(
"SansSerif", 1, 24));
192 jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
193 jLabel3.setText(
"Merging of Exb Files");
195 compareButton.setText(
"Compare");
196 compareButton.addActionListener(
new java.awt.event.ActionListener() {
197 public void actionPerformed(java.awt.event.ActionEvent evt) {
198 compareButtonActionPerformed(evt);
202 mergeButton.setText(
"Merge");
203 mergeButton.addActionListener(
new java.awt.event.ActionListener() {
204 public void actionPerformed(java.awt.event.ActionEvent evt) {
205 mergeButtonActionPerformed(evt);
209 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
210 jPanel1.setLayout(jPanel1Layout);
211 jPanel1Layout.setHorizontalGroup(
212 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213 .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
214 .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
215 .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
216 .addGroup(jPanel1Layout.createSequentialGroup()
218 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
220 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
221 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
222 .addComponent(compareButton, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
223 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
224 .addComponent(mergeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
227 jPanel1Layout.setVerticalGroup(
228 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229 .addGroup(jPanel1Layout.createSequentialGroup()
231 .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
232 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
233 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
234 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
235 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
236 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
237 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
238 .addComponent(compareButton)
239 .addComponent(mergeButton))
241 .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
245 compareButton.getAccessibleContext().setAccessibleDescription(
"");
247 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
248 getContentPane().setLayout(layout);
249 layout.setHorizontalGroup(
250 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251 .addGroup(layout.createSequentialGroup()
252 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
255 layout.setVerticalGroup(
256 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257 .addGroup(layout.createSequentialGroup()
258 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
259 .addGap(0, 0, Short.MAX_VALUE))
265 private void compareButtonActionPerformed(java.awt.event.ActionEvent evt) {
266 String firstFilePath = (String) firstVersion.getSelectedItem();
267 String secondFilePath = (String) secondVersion.getSelectedItem();
270 URL secondURL = null;
272 firstURL = Paths.get(firstFilePath).toUri().toURL();
273 }
catch (MalformedURLException ex) {
274 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
277 secondURL = Paths.get(secondFilePath).toUri().toURL();
278 }
catch (MalformedURLException ex) {
279 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
283 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
284 DocumentBuilder db = null;
286 db = dbf.newDocumentBuilder();
287 }
catch (ParserConfigurationException ex) {
288 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
293 }
catch (SAXException ex) {
294 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
295 }
catch (IOException ex) {
296 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
297 }
catch (TransformerException ex) {
298 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
299 }
catch (ParserConfigurationException ex) {
300 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
301 }
catch (XPathExpressionException ex) {
302 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
304 if (doc.getElementsByTagName(
"transcription-name").getLength() > 0) {
305 transcriptName = doc.getElementsByTagName(
"transcription-name").item(0).getTextContent();
307 transcriptName =
"No Name Transcript";
309 Report mergeReport = null;
311 instance.
check(btFirst);
312 }
catch (JexmaraldaException ex) {
313 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
316 mergeReport = instance.
check(btSecond);
317 }
catch (JexmaraldaException ex) {
318 Logger.getLogger(
ExbMergerGUI.class.getName()).log(Level.SEVERE, null, ex);
323 private void firstVersionActionPerformed(java.awt.event.ActionEvent evt) {
327 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
328 JFileChooser chooser =
new JFileChooser();
330 if (evt.getSource() == browseButton) {
331 chooser =
new JFileChooser(
new File(System.getProperty(
"user.home")));
332 chooser.setDialogTitle(
"Select File Location");
333 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
335 if (chooser.showSaveDialog(
this) == JFileChooser.APPROVE_OPTION) {
336 filePath = chooser.getSelectedFile().getPath();
337 firstVersion.setSelectedItem(filePath);
342 private void browseButton2ActionPerformed(java.awt.event.ActionEvent evt) {
343 JFileChooser chooser =
new JFileChooser();
345 if (evt.getSource() == browseButton2) {
346 chooser =
new JFileChooser(
new File(System.getProperty(
"user.home")));
347 chooser.setDialogTitle(
"Select File Location");
348 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
350 if (chooser.showSaveDialog(
this) == JFileChooser.APPROVE_OPTION) {
351 filePath = chooser.getSelectedFile().getPath();
352 secondVersion.setSelectedItem(filePath);
357 private void mergeButtonActionPerformed(java.awt.event.ActionEvent evt) {
358 if (transcriptName != null) {
360 merge.setVisible(
true);
363 JOptionPane.showMessageDialog(null,
"Please compare two versions before merging them!");
370 public static void main(String args[]) {
377 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
378 if (
"Nimbus".equals(info.getName())) {
379 javax.swing.UIManager.setLookAndFeel(info.getClassName());
383 }
catch (ClassNotFoundException ex) {
384 java.util.logging.Logger.getLogger(
ExbMergerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
385 }
catch (InstantiationException ex) {
386 java.util.logging.Logger.getLogger(
ExbMergerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
387 }
catch (IllegalAccessException ex) {
388 java.util.logging.Logger.getLogger(
ExbMergerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
389 }
catch (javax.swing.UnsupportedLookAndFeelException ex) {
390 java.util.logging.Logger.getLogger(
ExbMergerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
395 java.awt.EventQueue.invokeLater(
new Runnable() {
403 private javax.swing.JButton browseButton;
404 private javax.swing.JButton browseButton2;
405 private javax.swing.JButton compareButton;
406 private javax.swing.JComboBox firstVersion;
407 private javax.swing.JTextPane firstVersionPane;
408 private javax.swing.JLabel jLabel1;
409 private javax.swing.JLabel jLabel2;
410 private javax.swing.JLabel jLabel3;
411 private javax.swing.JPanel jPanel1;
412 private javax.swing.JPanel jPanel2;
413 private javax.swing.JPanel jPanel3;
414 private javax.swing.JPanel jPanel4;
415 private javax.swing.JPopupMenu jPopupMenu1;
416 private javax.swing.JPopupMenu jPopupMenu2;
417 private javax.swing.JScrollPane jScrollPane2;
418 private javax.swing.JButton mergeButton;
419 private javax.swing.JComboBox secondVersion;
String toSaveableString()
Report check(CorpusData cd)
static void main(String args[])
static InputStream String2InputStream(String s)