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