Package org.openscience.jchempaint.controller

Examples of org.openscience.jchempaint.controller.AddAtomModule


                IAtom normal = pseudo.getBuilder().newInstance(IPseudoAtom.class,pseudo);
                normal.setSymbol("C");
                jcpPanel.get2DHub().replaceAtom(normal,pseudo);
          }else {
            jcpPanel.get2DHub().convertToPseudoAtom(atom,label);
                AddAtomModule newActiveModule = new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE);
                if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule)
                    newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddBondDragModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
                else if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddAtomModule)
                    newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
                newActiveModule.setID(label);
                jcpPanel.get2DHub().setActiveDrawModule(newActiveModule);
                jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(true);
                jcpPanel.get2DHub().getController2DModel().setDrawElement(label);
                jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0);          }
        }
View Full Code Here


        }
        String s = event.getActionCommand();
        String symbol = s.substring(s.indexOf("@") + 1);
        if(symbol.equals("periodictable")){
            if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule)
                newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddBondDragModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
            else if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddAtomModule)
                newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
            else
                newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE);
            newActiveModule.setID(symbol);
            jcpPanel.get2DHub().setActiveDrawModule(newActiveModule);
            // open PeriodicTable panel
            PeriodicTableDialog dialog = new PeriodicTableDialog();
            dialog.setName("periodictabledialog");
            symbol=dialog.getChoosenSymbol();
            if(symbol.equals(""))
                return;
            jcpPanel.get2DHub().getController2DModel().setDrawElement(symbol);
            jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0);
            jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false);
        }else if(symbol.equals("enterelement")){
            newActiveModule=new EnterElementSwingModule(jcpPanel.get2DHub());
            newActiveModule.setID(symbol);
            jcpPanel.get2DHub().setActiveDrawModule(newActiveModule);
            if(atomsInRange!=null){
                String[] funcGroupsKeys=new String[0];
                symbol=EnterElementOrGroupDialog.showDialog(null,null, GT.get("Enter an element symbol:"), GT.get("Enter element"), funcGroupsKeys, "","");
                if(symbol!=null && symbol.length()>0){
                    if(Character.isLowerCase(symbol.toCharArray()[0]))
                        symbol=Character.toUpperCase(symbol.charAt(0))+symbol.substring(1);
                    IsotopeFactory ifa;
                    try {
                        ifa = XMLIsotopeFactory.getInstance(jcpPanel.getChemModel().getBuilder());
                        IIsotope iso=ifa.getMajorIsotope(symbol);
                        if(iso==null){
                            JOptionPane.showMessageDialog(jcpPanel, GT.get("No valid element symbol entered"), GT.get("Invalid symbol"), JOptionPane.WARNING_MESSAGE);
                            return;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                        return;
                    }
                }
            }
        }else{
            //it must be a symbol
            if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule)
                newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddBondDragModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
            else if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddAtomModule)
                newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
            else
                newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE);

            jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false);
            newActiveModule.setID(symbol);
            jcpPanel.get2DHub().getController2DModel().setDrawElement(symbol);
            jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(0);                 
View Full Code Here

    private static final long serialVersionUID = -4692219842740123315L;

    public void actionPerformed(ActionEvent event) {
        //first switch draw mode
        AddAtomModule newActiveModule = new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE);
        if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule)
            newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddBondDragModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
        else if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddAtomModule)
            newActiveModule=new AddAtomModule(jcpPanel.get2DHub(), ((AddAtomModule)jcpPanel.get2DHub().getActiveDrawModule()).getStereoForNewBond());
        logger.debug("About to change atom type of relevant atom!");
        IChemObject object = getSource(event);
        logger.debug("Source of call: ", object);
        Iterator<IAtom> atomsInRange = null;
    if (object == null){
      //this means the main menu was used
      if(jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().isFilled())
        atomsInRange=jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection().getConnectedAtomContainer().atoms().iterator();
    }else if (object instanceof IAtom)
    {
      List<IAtom> atoms = new ArrayList<IAtom>();
      atoms.add((IAtom) object);
      atomsInRange = atoms.iterator();
    } else
    {
      List<IAtom> atoms = new ArrayList<IAtom>();
      atoms.add(jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel().getHighlightedAtom());
      atomsInRange = atoms.iterator();
    }
    if(atomsInRange==null)
      return;
    while(atomsInRange.hasNext()){
            IAtom atom = atomsInRange.next();
            int isotopeNumber = 0;
            try {
                IIsotope isotope =
                    XMLIsotopeFactory.getInstance(
                                atom.getBuilder()).getMajorIsotope(
                                atom.getSymbol());
                isotopeNumber = isotope.getMassNumber();
            } catch (Exception exception) {
                logger.error("Error while configuring atom");
                logger.debug(exception);
            }
            // adapt for menu chosen
            if (type.equals("major")) {
                // that's the default
            } else if (type.equals("majorPlusOne")) {
                isotopeNumber += 1;
            } else if (type.equals("majorPlusTwo")) {
                isotopeNumber += 2;
            } else if (type.equals("majorPlusThree")) {
                isotopeNumber += 3;
            } else if (type.equals("majorMinusOne")) {
                isotopeNumber -= 1;
            } else if (type.equals("majorMinusTwo")) {
                isotopeNumber -= 2;
            } else if (type.equals("majorMinusThree")) {
                isotopeNumber -= 3;
            } else if (type.indexOf("specific")==0) {
              isotopeNumber = Integer.parseInt(type.substring(8));
      }
            jcpPanel.get2DHub().setMassNumber(atom,isotopeNumber);
            jcpPanel.get2DHub().updateView();
            newActiveModule.setID(atom.getSymbol());
            jcpPanel.get2DHub().getController2DModel().setDrawElement(atom.getSymbol());
            jcpPanel.get2DHub().getController2DModel().setDrawIsotopeNumber(isotopeNumber);
            jcpPanel.get2DHub().getController2DModel().setDrawPseudoAtom(false);
        }
        jcpPanel.get2DHub().setActiveDrawModule(newActiveModule);
View Full Code Here

TOP

Related Classes of org.openscience.jchempaint.controller.AddAtomModule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.