Skip to content
Snippets Groups Projects
Splash.java 36.7 KiB
Newer Older
  • Learn to ignore specific revisions
  •     if(gcode_default != null)
        {
    
    tjc's avatar
    tjc committed
          String defS = (String)gcode_default.elementAt(0);
    
          if(defS.length() < 3)
          {
            try
            {
              int num = Integer.parseInt(defS);
              if(num > 0 && num <= gcodes.length)
                default_code = num-1;
              else
                System.err.println(defS+" is not a valid number");
            }
            catch(NumberFormatException nfe)
            {
              System.err.println(defS+" is not a valid number");
            }
          }
        }
        
    
    tjc's avatar
    tjc committed
        ButtonGroup gcodeGroup = new ButtonGroup();
    
        geneCode = new JCheckBoxMenuItem[gcodes.length];
        
    
    tjc's avatar
    tjc committed
        for(int i = 0; i< gcodes.length; i++)
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          if(gcodes[i].equals("-"))
            continue;
    
          int ind1; 
          while((ind1 = gcodes[i].indexOf("_")) > -1)
            gcodes[i] = gcodes[i].substring(0,ind1) + " " +
                        gcodes[i].substring(ind1+1,gcodes[i].length());
    
          String num = Integer.toString(i+1);
          final String gc_name = num+". "+gcodes[i];
    
          geneCode[i] = new JCheckBoxMenuItem(gc_name);
          gcodeGroup.add(geneCode[i]);
          final int menuNum = i;
          geneCode[i].setActionCommand(num);
    
    tjc's avatar
    tjc committed
    
    
          geneCode[i].addItemListener(new ItemListener()
    
    tjc's avatar
    tjc committed
          {
    
    tjc's avatar
    tjc committed
            public void itemStateChanged(ItemEvent event)
            {
    
              if(geneCode[menuNum].getState())
    
    tjc's avatar
    tjc committed
              {
                geneticCode = gc_name;
    
                String tab = "translation_table_"+geneCode[menuNum].getActionCommand();
                String startCodons = "start_codons_"+geneCode[menuNum].getActionCommand();
    
    tjc's avatar
    tjc committed
    
                StringVector options_file_table =
                             Options.getOptions().getOptionValues(tab);
    
                if(options_file_table != null)
                {
                  if(options_file_table.size() == 64) 
                  {
                    StringBuffer sbuff = new StringBuffer();
                    for(int i = 0; i < 64; ++i) 
                      sbuff.append(options_file_table.elementAt(i)+" ");
    
                    Options.getOptions().setGeneticCode(sbuff.toString());
                  }
                  else
                  {
                    StringVector table = Options.getOptions().getOptionValues("translation_table_1");
    
                    for(int i = 0; i < options_file_table.size(); ++i)
                    {
    
    tjc's avatar
    tjc committed
                      String cod_plus_aa = (String)options_file_table.elementAt(i);
    
    tjc's avatar
    tjc committed
    //                System.out.println(cod_plus_aa);
                      final int codon_index = Bases.getIndexOfBase(cod_plus_aa.charAt(0)) * 16 +
                                              Bases.getIndexOfBase(cod_plus_aa.charAt(1)) * 4 +
                                              Bases.getIndexOfBase(cod_plus_aa.charAt(2));
    
    //                System.out.println(cod_plus_aa.substring(3)+"  "+codon_index+"  "+
    //                                   table.elementAt(codon_index));
                      table.setElementAt(cod_plus_aa.substring(3), codon_index);
                    }
                    
                    StringBuffer sbuff = new StringBuffer();
                    for(int i = 0; i < 64; ++i)
                      sbuff.append(table.elementAt(i)+" ");
    
                    Options.getOptions().setGeneticCode(sbuff.toString());
                  }
    
                  options_file_table =
                             Options.getOptions().getOptionValues(startCodons);
    
                  if(options_file_table != null)
                  {
                    StringBuffer sbuff = new StringBuffer();
                    for(int i = 0; i < options_file_table.size(); ++i)
                      sbuff.append(options_file_table.elementAt(i)+" ");
                    
                    Options.getOptions().setProperty("start_codons",sbuff.toString());
                  }
                }
    
               
                AminoAcidSequence.setGeneCode();
     
    
    tjc's avatar
    tjc committed
                if(helix_canvas != null)
                  helix_canvas.repaint();
              }
            }
          });
    
          options_menu.add(geneCode[i]);
    
    tjc's avatar
    tjc committed
    
    
            geneCode[i].setState(true);
    
    tjc's avatar
    tjc committed
        }
    
    tjc's avatar
    tjc committed
      }
    
      /**
       * Set the Genetic Code number
       * @param geneticCodeValue
       */
      public void setTranslationTable(final String geneticCodeValue)
      {
    	for(int i=0;i<geneCode.length;i++)
    	{
    	  if(geneCode[i] == null)
    		continue;
    
    	  if( geneCode[i].getActionCommand().equals(geneticCodeValue) && 
    	     !geneCode[i].getState() )
    	  {  
    		int val = JOptionPane.showConfirmDialog(null, 
    		    		"Change translation table to:\n"+
    		    		geneCode[i].getText(), 
    			    	"Confirm Translation Table Change",
    		    		JOptionPane.OK_CANCEL_OPTION);
    		if(val == JOptionPane.CANCEL_OPTION)
    		  return;
    		logger4j.debug("SET GENETIC CODE translationTable="
    					+ geneticCodeValue);
    	    geneCode[i].setState(true);
    		break; 
    	  }
    	}
      }
      
    
    tjc's avatar
    tjc committed
      /**
       *  Make a new menu item in the given menu, with its label given the
       *  String and add the given ActionListener to it.
       */
      protected static void makeMenuItem(JMenu menu, String name,
                                         ActionListener listener) 
      {
        JMenuItem new_item = new JMenuItem(name);
        menu.add(new_item);
        new_item.addActionListener(listener);
        if(name.equals("Open ..."))
          new_item.setAccelerator(KeyStroke.getKeyStroke
    
                 (KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); // InputEvent.CTRL_MASK));
    
    tjc's avatar
    tjc committed
      }
    
      /**
       *  Return a Logger for warnings/errors/messages.
       **/
    
    tcarver's avatar
    tcarver committed
      protected static Logger getLogger() 
    
    tjc's avatar
    tjc committed
      {
        return logger;
      }
    
      /**
       *  Return the JComponent that the Splash screen is drawing on.
       **/
      public JComponent getCanvas() 
      {
        return helix_canvas;
      }
    
      /**
       *  Make the LogViewer visible.
       **/
      public static void showLog() 
      {
        logger.setVisible(true);
      }
    
      /**
       *  An InputStreamProgressListener used to update the error label with the
       *  current number of chars read.
       **/
      private final InputStreamProgressListener stream_progress_listener =
        new InputStreamProgressListener() {
          public void progressMade(final InputStreamProgressEvent event) 
          {
            final int char_count = event.getCharCount();
            if(char_count == -1) 
              getStatusLabel().setText("");
            else 
              getStatusLabel().setText("chars read so far: " + char_count);
          }
    
    
          public void progressMade(String progress)
          {
            getStatusLabel().setText(progress);
          }
    
    
    tjc's avatar
    tjc committed
        };
    }