annotate java-genomics-toolkit/gui/edu/unc/genomics/AssemblyManagerDialog.java @ 0:1daf3026d231

Upload alpha version
author timpalpant
date Mon, 13 Feb 2012 21:55:55 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
1 package edu.unc.genomics;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
2
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
3 import java.awt.BorderLayout;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
4 import java.awt.FlowLayout;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
5
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
6 import javax.swing.JButton;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
7 import javax.swing.JDialog;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
8 import javax.swing.JFileChooser;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
9 import javax.swing.JFrame;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
10 import javax.swing.JOptionPane;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
11 import javax.swing.JPanel;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
12 import javax.swing.JScrollPane;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
13 import javax.swing.JTable;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
14 import javax.swing.border.EmptyBorder;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
15
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
16 import org.apache.log4j.Logger;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
17
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
18 import java.awt.event.ActionListener;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
19 import java.awt.event.ActionEvent;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
20 import java.io.IOException;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
21 import java.nio.file.Path;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
22 import java.util.zip.DataFormatException;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
23
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
24 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
25 * View for AssemblyManager
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
26 *
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
27 * @author timpalpant
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
28 *
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
29 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
30 public class AssemblyManagerDialog extends JDialog {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
31
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
32 public static final int DEFAULT_WIDTH = 400;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
33 public static final int DEFAULT_HEIGHT = 500;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
34
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
35 private static final long serialVersionUID = -1461628562713621064L;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
36 private static final Logger log = Logger.getLogger(AssemblyManagerDialog.class);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
37
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
38 private final JPanel contentPanel = new JPanel();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
39 private final JFileChooser fcCustomAssembly = new JFileChooser();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
40 private final JTable assembliesTable = new JTable();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
41
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
42 private AssemblyTableModel model;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
43
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
44 /**
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
45 * Create the dialog.
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
46 */
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
47 public AssemblyManagerDialog(JFrame parent) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
48 super(parent, "Assembly Manager", true);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
49
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
50 setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
51 int centeredX = parent.getX() + (parent.getWidth()-getWidth()) / 2;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
52 int centeredY = parent.getY() + (parent.getHeight()-getHeight()) / 2;
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
53 setLocation(centeredX, centeredY);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
54
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
55 getContentPane().setLayout(new BorderLayout());
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
56 contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
57 getContentPane().add(contentPanel, BorderLayout.CENTER);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
58 contentPanel.setLayout(new BorderLayout(0, 0));
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
59
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
60 // Initialize the assemblies list
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
61 model = new AssemblyTableModel(AssemblyManager.getAvailableAssemblies());
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
62 assembliesTable.setModel(model);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
63 assembliesTable.setRowSelectionAllowed(true);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
64 JScrollPane scrollPane = new JScrollPane(assembliesTable);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
65 assembliesTable.setFillsViewportHeight(true);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
66 contentPanel.add(scrollPane);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
67
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
68 JPanel buttonPane = new JPanel();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
69 buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
70 getContentPane().add(buttonPane, BorderLayout.SOUTH);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
71
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
72 JButton removeAssemblyButton = new JButton("Remove");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
73 removeAssemblyButton.setActionCommand("RemoveAssembly");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
74 removeAssemblyButton.addActionListener(new ActionListener() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
75 public void actionPerformed(ActionEvent e) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
76 removeCustomAssembly();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
77 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
78 });
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
79 buttonPane.add(removeAssemblyButton);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
80
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
81 JButton loadAssemblyButton = new JButton("Load Custom Assembly");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
82 loadAssemblyButton.setActionCommand("LoadAssembly");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
83 loadAssemblyButton.addActionListener(new ActionListener() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
84 public void actionPerformed(ActionEvent e) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
85 loadCustomAssembly();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
86 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
87 });
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
88 buttonPane.add(loadAssemblyButton);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
89
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
90 JButton doneButton = new JButton("Done");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
91 doneButton.setActionCommand("Done");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
92 doneButton.addActionListener(new ActionListener() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
93 public void actionPerformed(ActionEvent e) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
94 closeDialog();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
95 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
96 });
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
97 buttonPane.add(doneButton);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
98 getRootPane().setDefaultButton(doneButton);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
99 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
100
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
101 private void removeCustomAssembly() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
102 for (int row : assembliesTable.getSelectedRows()) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
103 try {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
104 Assembly a = model.getRow(row);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
105 AssemblyManager.deleteAssembly(a);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
106 model.removeRow(row);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
107 } catch (IOException e) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
108 log.error("Error deleting Assembly");
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
109 e.printStackTrace();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
110 JOptionPane.showMessageDialog(this, "Error deleting assembly", "Assembly Manager Error", JOptionPane.ERROR_MESSAGE);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
111 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
112 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
113 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
114
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
115 private void loadCustomAssembly() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
116 int returnVal = fcCustomAssembly.showOpenDialog(this);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
117 if (returnVal == JFileChooser.APPROVE_OPTION) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
118 Path assemblyFile = fcCustomAssembly.getSelectedFile().toPath();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
119 try {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
120 Assembly a = AssemblyManager.loadCustomAssembly(assemblyFile);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
121 // Add it to the assemblies list model
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
122 model.addAssembly(a);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
123 } catch (IOException | DataFormatException e) {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
124 log.error("Error loading custom assembly: " + assemblyFile);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
125 e.printStackTrace();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
126 JOptionPane.showMessageDialog(this, "Error loading custom assembly", "Assembly Manager Error", JOptionPane.ERROR_MESSAGE);
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
127 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
128 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
129 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
130
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
131 private void closeDialog() {
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
132 this.dispose();
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
133 }
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
134
1daf3026d231 Upload alpha version
timpalpant
parents:
diff changeset
135 }