Package org.openscience.jchempaint.renderer.selection

Examples of org.openscience.jchempaint.renderer.selection.LogicalSelection


                        jcpPanel.getChemModel().setMoleculeSet(
                                chemModel.getMoleculeSet());
                        jcpPanel.getChemModel().setReactionSet(chemModel.getReactionSet());
                        jcpPanel.getRenderPanel().getRenderer()
                                .getRenderer2DModel().setSelection(
                                        new LogicalSelection(
                                                LogicalSelection.Type.NONE));

                        // the newly opened file should nicely fit the screen
                        jcpPanel.getRenderPanel().setFitToScreen(true);
View Full Code Here


                jcpPanel.get2DHub().removeBond(bondInRange);
            } else if(renderModel.getSelection()!=null && renderModel.getSelection().getConnectedAtomContainer()!=null){
                IChemObjectSelection selection = renderModel.getSelection();
                IAtomContainer selected = selection.getConnectedAtomContainer();
                jcpPanel.get2DHub().deleteFragment(selected);
                renderModel.setSelection(new LogicalSelection(
                        LogicalSelection.Type.NONE));
                jcpPanel.get2DHub().updateView();
            }
        } else if(type.indexOf("pasteTemplate")>-1){
            //if templates are shown, we extract the tab to show if any
            String templatetab="";
            if(type.indexOf("_")>-1){
                templatetab=type.substring(type.indexOf("_")+1);
            }
            TemplateBrowser templateBrowser = new TemplateBrowser(templatetab);
            if(templateBrowser.getChosenmolecule()!=null){
                scaleStructure(templateBrowser.getChosenmolecule());
                insertStructure(templateBrowser.getChosenmolecule(), renderModel);
                jcpPanel.getRenderPanel().setZoomWide(true);
                jcpPanel.get2DHub().getRenderer().getRenderer2DModel().setZoomFactor(1);
            }
        } else if ("paste".equals(type)) {
            handleSystemClipboard(sysClip);
            Transferable transfer = sysClip.getContents( null );
            ISimpleChemObjectReader reader = null;
            String content=null;
           
            if (supported(transfer, molFlavor) ) {
                StringBuffer sb = new StringBuffer();
              try {
                    //StringBufferInputStream sbis=null;
          //sbis = (StringBufferInputStream) transfer.getTransferData(molFlavor);

                    StringReader sbis=null;
          sbis = (StringReader) transfer.getTransferData(molFlavor);

               
                int x;
                    while((x=sbis.read())!=-1){
                        sb.append((char)x);
                    }
                    reader = new MDLReader(new StringReader(sb.toString()));
        } catch (UnsupportedFlavorException e1) {
          e1.printStackTrace();
        } catch (IOException e1) {
          e1.printStackTrace();
              } catch (Exception e1) {
                  reader = new RGroupQueryReader(new StringReader(sb.toString()));
                }

            } else if (supported(transfer, DataFlavor.stringFlavor) ) {
                try {
                    content = (String) transfer.getTransferData(DataFlavor.stringFlavor);
                    reader = new ReaderFactory().createReader(new StringReader(content));
                    //System.out.println(reader.getClass());
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }

            // if looks like CML - InputStream required. Reader throws error.
            if(content!=null && content.indexOf("cml")>-1) {
                reader = new CMLReader(new ByteArrayInputStream(content.getBytes()));
            }

            IAtomContainer toPaste = null;
            boolean rgrpQuery=false;
            if (reader != null) {
                IAtomContainer readMolecule =
                    chemModel.getBuilder().newInstance(IAtomContainer.class);
                try {
                    if (reader.accepts(IAtomContainer.class)) {
                        toPaste = (IAtomContainer) reader.read(readMolecule);
                    } else if (reader.accepts(ChemFile.class)) {
                        toPaste = readMolecule;
                        IChemFile file = (IChemFile) reader.read(new ChemFile());
                        for (IAtomContainer ac :
                            ChemFileManipulator.getAllAtomContainers(file)) {
                            toPaste.add(ac);

                        }
                  } else if (reader.accepts(RGroupQuery.class)) {
                rgrpQuery=true;
                    IRGroupQuery rgroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance()));
                chemModel = new ChemModel();
                RGroupHandler rgHandler =  new RGroupHandler(rgroupQuery, this.jcpPanel);
                this.jcpPanel.get2DHub().setRGroupHandler(rgHandler);
                chemModel.setMoleculeSet(rgHandler.getMoleculeSet(chemModel));
                rgHandler.layoutRgroup();
               
                  }

                } catch (CDKException e1) {
                    e1.printStackTrace();
                }
            }

            //Attempt SMILES or InChI if no reader is found for content.
            if(rgrpQuery!=true && toPaste == null &&
                    supported(transfer, DataFlavor.stringFlavor)) {
                try{
                    if (content.toLowerCase().indexOf("inchi")>-1 ) {
                        toPaste = InChITool.parseInChI(content);
                    }
                    else {   
                        SmilesParser sp = new SmilesParser(
                                DefaultChemObjectBuilder.getInstance());
                        toPaste = sp.parseSmiles(
                                ((String) transfer.getTransferData(
                                        DataFlavor.stringFlavor)).trim());
                        toPaste = new FixBondOrdersTool().kekuliseAromaticRings(toPaste);

                        IAtomContainerSet mols = ConnectivityChecker.partitionIntoMolecules(toPaste);
                        for(int i=0;i<mols.getAtomContainerCount();i++)
                        {
                            StructureDiagramGenerator sdg =
                                new StructureDiagramGenerator((IAtomContainer)mols.getAtomContainer(i));

                            sdg.setTemplateHandler(
                                    new TemplateHandler(toPaste.getBuilder())
                            );
                            sdg.generateCoordinates();
                        }
                        //SMILES parser sets valencies, unset
                        for(int i=0;i<toPaste.getAtomCount();i++){
                            toPaste.getAtom(i).setValency(null);
                        }
                    }
                } catch (Exception ex) {
                    jcpPanel.announceError(ex);
                    ex.printStackTrace();
                }
            }
           
            if (toPaste != null || rgrpQuery==true) {
                jcpPanel.getRenderPanel().setZoomWide(true);
                jcpPanel.get2DHub().getRenderer().getRenderer2DModel().setZoomFactor(1);
                if ( rgrpQuery==true) {
                  this.jcpPanel.setChemModel(chemModel);
                }
                else {
                  scaleStructure(toPaste);
                  insertStructure(toPaste, renderModel);
                }
            }
            else{
                JOptionPane.showMessageDialog(jcpPanel, GT.get("The content you tried to copy could not be read to any known format"), GT.get("Could not process content"), JOptionPane.WARNING_MESSAGE);
            }

        } else if (type.equals("cut")) {
            handleSystemClipboard(sysClip);
            IAtom atomInRange = null;
            IBond bondInRange = null;
            IChemObject object = getSource(e);
            logger.debug("Source of call: ", object);
            if (object instanceof IAtom) {
                atomInRange = (IAtom) object;
            } else {
                atomInRange = renderModel.getHighlightedAtom();
            }
            if (object instanceof IBond) {
                bondInRange = (IBond) object;
            } else {
                bondInRange = renderModel.getHighlightedBond();
            }
            IAtomContainer tocopyclone =
                jcpPanel.getChemModel().getBuilder().newInstance(IAtomContainer.class);
            if (atomInRange != null) {
                tocopyclone.addAtom(atomInRange);
                jcpPanel.get2DHub().removeAtom(atomInRange);
                renderModel.setHighlightedAtom(null);
            } else if (bondInRange != null) {
                tocopyclone.addBond(bondInRange);
                jcpPanel.get2DHub().removeBond(bondInRange);
            }else if(renderModel.getSelection()!=null && renderModel.getSelection().getConnectedAtomContainer()!=null){
                IChemObjectSelection selection = renderModel.getSelection();
                IAtomContainer selected = selection.getConnectedAtomContainer();
                tocopyclone.add(selected);
                jcpPanel.get2DHub().deleteFragment(selected);
                renderModel.setSelection(new LogicalSelection(
                        LogicalSelection.Type.NONE));
                jcpPanel.get2DHub().updateView();
            }
      if(tocopyclone.getAtomCount()>0 || tocopyclone.getBondCount()>0)
          addToClipboard(sysClip, tocopyclone);
     
        }else if (type.equals("selectAll")) {
            ControllerHub hub = jcpPanel.get2DHub();
            IChemObjectSelection allSelection =
                new LogicalSelection(LogicalSelection.Type.ALL);

            allSelection.select(hub.getIChemModel());
            renderModel.setSelection(allSelection);
            SelectSquareModule succusorModule = new SelectSquareModule(hub);
            succusorModule.setID("select");
            MoveModule newActiveModule = new MoveModule(hub, succusorModule);
            newActiveModule.setID("move");
View Full Code Here

          return;
        }
        jcpPanel.get2DHub().fireStructureChangedEvent();

        //We select the inserted structure
        IChemObjectSelection selection = new LogicalSelection(LogicalSelection.Type.ALL);
        selection.select(ChemModelManipulator.newChemModel(toPaste));
        renderModel.setSelection(selection);
        SelectSquareModule successorModule = new SelectSquareModule(jcpPanel.get2DHub());
        successorModule.setID("select");
        MoveModule newActiveModule = new MoveModule(jcpPanel.get2DHub(), successorModule);
        newActiveModule.setID("move");
View Full Code Here

   * @param model The chemmodel to use.
   */
  public void setChemModel(IChemModel model){
    renderPanel.setChemModel(model);
    //we need to do this to avoid npes later
    renderPanel.getRenderer().getRenderer2DModel().setSelection(new LogicalSelection(LogicalSelection.Type.NONE));
  }
View Full Code Here

                        jcpPanel.getChemModel().setMoleculeSet(
                                chemModel.getMoleculeSet());
                        jcpPanel.getChemModel().setReactionSet(chemModel.getReactionSet());
                        jcpPanel.getRenderPanel().getRenderer()
                                .getRenderer2DModel().setSelection(
                                        new LogicalSelection(
                                                LogicalSelection.Type.NONE));

                        // the newly opened file should nicely fit the screen
                        jcpPanel.getRenderPanel().setFitToScreen(true);
View Full Code Here

                jcpPanel.get2DHub().zap();
                jcpPanel.get2DHub().updateView();
                jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel()
                        .setZoomFactor(1);

                IChemObjectSelection selection = new LogicalSelection(
                        LogicalSelection.Type.NONE);
                jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel()
                        .setSelection(selection);

            }
View Full Code Here

        theJcpp.get2DHub().zap();
        theJcpp.get2DHub().updateView();
        theJcpp.getRenderPanel().getRenderer().getRenderer2DModel()
                .setZoomFactor(1);

        IChemObjectSelection selection = new LogicalSelection(
                LogicalSelection.Type.NONE);
        theJcpp.getRenderPanel().getRenderer().getRenderer2DModel()
                .setSelection(selection);
    }
View Full Code Here

    logger.debug("Undo triggered");
        if (jcpPanel.getRenderPanel().getUndoManager().canUndo()) {
            jcpPanel.getRenderPanel().getUndoManager().undo();
        }
        jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel()
          .setSelection(new LogicalSelection(LogicalSelection.Type.NONE));
        jcpPanel.updateUndoRedoControls();
        jcpPanel.updateStatusBar();
        JChemPaintRendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel();

        jcpPanel.get2DHub().updateView();
View Full Code Here

    logger.debug("Redo triggered");
    if (jcpPanel.getRenderPanel().getUndoManager().canRedo()) {
            jcpPanel.getRenderPanel().getUndoManager().redo();
        }
        jcpPanel.getRenderPanel().getRenderer().getRenderer2DModel()
          .setSelection(new LogicalSelection(LogicalSelection.Type.NONE));
    jcpPanel.updateUndoRedoControls();
    jcpPanel.updateStatusBar();
        JChemPaintRendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel();

    jcpPanel.get2DHub().updateView();
View Full Code Here

        IAtom closestAtom = null;
        IBond closestBond = null;
        IAtom highlitAtom = model.getHighlightedAtom();
        IBond highlitBond = model.getHighlightedBond();
        if(from.equals(startPoint)) {
          LogicalSelection lsel = null;
          boolean isAllSelected = false;
            if (sel.getClass().isAssignableFrom(LogicalSelection.class)) {
              lsel = (LogicalSelection)sel;
                isAllSelected = lsel.getType() == LogicalSelection.Type.ALL
                && sel.isFilled();
          }
          if (!isAllSelected && sel != null && sel.isFilled()) {
              bounds = BoundsCalculator.calculateBounds(sel.getConnectedAtomContainer());
              closestAtom = getClosestSelAtom(startPoint);
View Full Code Here

TOP

Related Classes of org.openscience.jchempaint.renderer.selection.LogicalSelection

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.