Debian Codegraph @

src/dr/app/bfe/XMLMerger.java

raw symbols SCIP
1 /*
2 * XMLMerger.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.bfe;
27
28 import javax.swing.*;
29 import javax.swing.event.ListSelectionEvent;
30 import javax.swing.event.ListSelectionListener;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33
34 /**
35 * Package: XMLMerger
36 * Description:
37 * <p/>
38 * <p/>
39 * Created by
40 *
41 * @author Alexander V. Alekseyenko ([email protected])
42 * Date: Apr 15, 2009
43 * Time: 2:42:38 AM
44 */
45 public class XMLMerger implements ActionListener, ListSelectionListener {
46
47 private JButton linkButton;
48 private JPanel panel;
49 private XMLViewer XMLViewer1;
50 private XMLViewer XMLViewer2;
51 private JList linkingList;
52 private JButton unlinkButton;
53 private JTextField linkingField;
54 private JFrame frame;
55
56 public XMLMerger() {
57
58 }
59
60 public XMLMerger(boolean standalone) {
61 XMLViewer1.getIdElementList().addListSelectionListener(this);
62 if (standalone) {
63 frame = new JFrame("XML Structure Viewer");
64 frame.setContentPane(panel);
65 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
66 frame.pack();
67 frame.setVisible(true);
68 }
69 }
70
71 public static void main(String[] args) {
72 XMLMerger z = new XMLMerger(true);
73 }
74
75 public void actionPerformed(ActionEvent e) {
76 if (e.getSource() == linkButton) {
77 String id1 = (String) XMLViewer1.getIdElementList().getSelectedValue();
78 String id2 = (String) XMLViewer2.getIdElementList().getSelectedValue();
79 String linkName = (String) linkingField.getSelectedText().trim();
80 if (linkName.equals("")) { // linking name must be non-empty
81 linkName = "" + id1;
82 }
83 if (id1 != null && id2 != null) {
84 //TODO: need to check if the id are already linked to something else
85 linkingList.updateUI();
86 }
87 } else if (e.getSource() == unlinkButton) {
88
89 }
90 }
91
92 public void valueChanged(ListSelectionEvent listSelectionEvent) {
93 if (listSelectionEvent.getSource() == linkingList) {
94 linkButton.setEnabled(false);
95 unlinkButton.setEnabled(true);
96 } else if (listSelectionEvent.getSource() == XMLViewer1.getIdElementList() || listSelectionEvent.getSource() == XMLViewer2.getIdElementList()) {
97 if (XMLViewer1.getIdElementList().getSelectedIndex() != -1 && XMLViewer2.getIdElementList().getSelectedIndex() != -1) {
98 linkButton.setEnabled(true);
99 }
100
101 }
102 }
103 }