Author: pwang
Date: 2008-09-09 15:36:09 -0700 (Tue, 09 Sep 2008)
New Revision: 14869
Added:
csplugins/trunk/ucsd/pwang/SessionForWebPlugin/src/SessionForWebPlugin/SpeciesAssignmentDialog.java
Log:
Original creation
Added:
csplugins/trunk/ucsd/pwang/SessionForWebPlugin/src/SessionForWebPlugin/SpeciesAssignmentDialog.java
===================================================================
---
csplugins/trunk/ucsd/pwang/SessionForWebPlugin/src/SessionForWebPlugin/SpeciesAssignmentDialog.java
2008-09-09 22:15:16 UTC (rev 14868)
+++
csplugins/trunk/ucsd/pwang/SessionForWebPlugin/src/SessionForWebPlugin/SpeciesAssignmentDialog.java
2008-09-09 22:36:09 UTC (rev 14869)
@@ -0,0 +1,191 @@
+package SessionForWebPlugin;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.util.Map;
+
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import cytoscape.data.CyAttributes;
+import cytoscape.Cytoscape;
+import java.util.Set;
+
+
+public class SpeciesAssignmentDialog extends javax.swing.JDialog implements
ActionListener{
+
+ private boolean setAllNetwork = true;
+ private String[] networkIDs = null;
+
+ /** Creates new form SpeciesAssignmentDialog */
+ public SpeciesAssignmentDialog(javax.swing.JDialog parent, boolean modal) {
+ super(parent, modal);
+ this.setTitle("Assign species for all netwoks");
+ initComponents();
+ btnCancel.addActionListener(this);
+ btnOK.addActionListener(this);
+ }
+
+ public SpeciesAssignmentDialog(javax.swing.JDialog parent, boolean modal,
String[] networkIDs) {
+ super(parent, modal);
+ this.setTitle("Assign species for selected netwoks");
+ initComponents();
+ btnCancel.addActionListener(this);
+ btnOK.addActionListener(this);
+
+ setAllNetwork = false;
+ this.networkIDs = networkIDs;
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+ Object src = e.getSource();
+ if (src instanceof JButton) {
+ JButton btn = (JButton)src;
+ if (btn == btnCancel){
+ this.dispose();
+ }
+ if (btn == btnOK){
+ Object[] selectedItems = lstSpecies.getSelectedValues();
+ if (selectedItems.length == 0) {
+ return;
+ }
+ boolean selectOther = false;
+
+ String selectedSpecies = "";
+ for (int i=0; i< selectedItems.length; i++) {
+ System.out.println(selectedItems[i]);
+ if (selectedItems[i].toString() != "Other") {
+ if (selectedSpecies != "") {
+ selectedSpecies +=",";
+ }
+ selectedSpecies +=
selectedItems[i].toString();
+ }
+
+ if (selectedItems[i].toString() == "Other") {
+ selectOther = true;
+ }
+ }
+
+ if (selectOther) {
+ String inputValue =
JOptionPane.showInputDialog(this,"Please input new species \n(use coma
seperator if more than one species)", "Input New Species",
JOptionPane.PLAIN_MESSAGE);
+
+ if (selectedSpecies != "") {
+ selectedSpecies +=",";
+ }
+ selectedSpecies += inputValue;
+ }
+
+ this.dispose();
+
+ if (selectedSpecies == "") {
+ return;
+ }
+ if (setAllNetwork) {
+ setSpeciesForAllNetworks(selectedSpecies);
+ }
+ else {
+ setSpeciesForSelectedNetworks(selectedSpecies);
+ }
+ }
+ }
+ }
+
+
+ private void setSpeciesForAllNetworks(String pSpecies){
+ System.out.println("SelectedSpecies = " + pSpecies);
+
+ Map<String,String> theMap =
SessionForWebPlugin.networkTitleToIDMap();
+ CyAttributes cyAttrs = Cytoscape.getNetworkAttributes();
+
+ Object[] keys = theMap.keySet().toArray();
+ for (int i=0; i<keys.length; i++) {
+ String id = theMap.get(keys[i]);
+ System.out.println("key, id = "+ keys[i]+ ","+id);
+ cyAttrs.setAttribute(id, "species", pSpecies);
+
+ }
+ }
+
+
+ private void setSpeciesForSelectedNetworks(String pSpecies){
+ CyAttributes cyAttrs = Cytoscape.getNetworkAttributes();
+
+ for (int i=0; i<networkIDs.length; i++ ) {
+ cyAttrs.setAttribute(networkIDs[i], "species",
pSpecies);
+ }
+ }
+
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
+ private void initComponents() {
+ java.awt.GridBagConstraints gridBagConstraints;
+
+ lbTitle = new javax.swing.JLabel();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ lstSpecies = new javax.swing.JList();
+ pnlButton = new javax.swing.JPanel();
+ btnOK = new javax.swing.JButton();
+ btnCancel = new javax.swing.JButton();
+
+ getContentPane().setLayout(new java.awt.GridBagLayout());
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ lbTitle.setText("Assign selected species to networks");
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
+ getContentPane().add(lbTitle, gridBagConstraints);
+
+ lstSpecies.setModel(new javax.swing.AbstractListModel() {
+ String[] strings = { "Saccharomyces cerevisia", "Homo sapiens",
"Caenorhabditis elegans", "Drosophila melanogaste", "Plasmodium falciparum",
"Other" };
+ public int getSize() { return strings.length; }
+ public Object getElementAt(int i) { return strings[i]; }
+ });
+ jScrollPane1.setViewportView(lstSpecies);
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+ gridBagConstraints.weightx = 1.0;
+ gridBagConstraints.weighty = 1.0;
+ gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10);
+ getContentPane().add(jScrollPane1, gridBagConstraints);
+
+ btnOK.setText("OK");
+ pnlButton.add(btnOK);
+
+ btnCancel.setText("Cancel");
+ pnlButton.add(btnCancel);
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
+ getContentPane().add(pnlButton, gridBagConstraints);
+
+ pack();
+ }// </editor-fold>
+
+ // Variables declaration - do not modify
+ private javax.swing.JButton btnCancel;
+ private javax.swing.JButton btnOK;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JLabel lbTitle;
+ private javax.swing.JList lstSpecies;
+ private javax.swing.JPanel pnlButton;
+ // End of variables declaration
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ new SpeciesAssignmentDialog(new javax.swing.JDialog(),
true).setVisible(true);
+ }
+ });
+ }
+}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---