From: <gil...@us...> - 2009-02-05 12:37:23
|
Revision: 14067 http://cdk.svn.sourceforge.net/cdk/?rev=14067&view=rev Author: gilleain Date: 2009-02-05 12:37:19 +0000 (Thu, 05 Feb 2009) Log Message: ----------- Changes necessary to sync jchempaint with the merge of the maclean-jchempaint and jchempaint-primary cdk branches that was made to align bioclipse-jchempaint with swing-jchempaint. Simple, really. Modified Paths: -------------- jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/CleanupAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/EditAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/action/ModifyDisplaySettingsAction.java jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/ValidateFrame.java jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/RendererModelEditor.java Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/RenderPanel.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -49,16 +49,18 @@ import org.openscience.cdk.interfaces.IChemModel; import org.openscience.cdk.interfaces.IMolecularFormula; import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder; -import org.openscience.cdk.renderer.ISelection; -import org.openscience.cdk.renderer.IntermediateRenderer; +import org.openscience.cdk.renderer.Renderer; +import org.openscience.cdk.renderer.font.AWTFontManager; +import org.openscience.cdk.renderer.selection.ISelection; import org.openscience.cdk.renderer.visitor.SVGGenerator; +import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; import org.openscience.cdk.tools.manipulator.MolecularFormulaManipulator; public class RenderPanel extends JPanel implements IViewEventRelay { - private IntermediateRenderer renderer; + private Renderer renderer; private boolean isNewChemModel; @@ -80,7 +82,7 @@ } public void setFitToScreen(boolean fitToScreen) { - this.renderer.setFitToScreen(fitToScreen); + this.renderer.getRenderer2DModel().setFitToScreen(fitToScreen); } public IChemModel getChemModel() { @@ -97,12 +99,13 @@ private void setupMachinery(IChemModel chemModel, boolean fitToScreen) { // setup the Renderer and the controller 'model' - this.renderer = new IntermediateRenderer(); - this.renderer.setFitToScreen(fitToScreen); + this.renderer = new Renderer(new AWTFontManager()); + this.setFitToScreen(fitToScreen); this.controllerModel = new ControllerModel(); // connect the Renderer to the Hub - this.hub = new ControllerHub(controllerModel, renderer, chemModel, this); + this.hub = + new ControllerHub(controllerModel, renderer, chemModel, this); // connect mouse events from Panel to the Hub this.mouseEventRelay = new SwingMouseEventRelay(this.hub); @@ -120,7 +123,8 @@ IChemModel chemModel = this.hub.getIChemModel(); if (chemModel != null && chemModel.getMoleculeSet() != null) { SVGGenerator svgGenerator = new SVGGenerator(); - this.renderer.paint(svgGenerator, chemModel); + this.renderer.paintChemModel( + chemModel, svgGenerator, this.getBounds(), true); return svgGenerator.getResult(); } else { return "<svg></svg>"; @@ -148,11 +152,17 @@ RenderingHints.VALUE_ANTIALIAS_ON); this.paintChemModel(g, bounds); } + + private boolean isValidChemModel(IChemModel chemModel) { + return chemModel != null + && (chemModel.getMoleculeSet() != null + || chemModel.getReactionSet() != null); + } public void paintChemModel(Graphics2D g, Rectangle screenBounds) { IChemModel chemModel = this.hub.getIChemModel(); - if (chemModel != null && chemModel.getMoleculeSet() != null) { + if (isValidChemModel(chemModel)) { // determine the size the canvas needs to be in order to fit the model Rectangle diagramBounds = renderer.calculateScreenBounds(chemModel); @@ -180,10 +190,15 @@ || screenBounds.getMaxY() < diagramBounds.getMaxY(); } - private void paintChemModel(IChemModel chemModel, Graphics2D g, Rectangle bounds) { + private void paintChemModel( + IChemModel chemModel, Graphics2D g, Rectangle bounds) { // paint the chem model, and record that it is no longer new - renderer.paintChemModel(chemModel, g, bounds, isNewChemModel); + + renderer.paintChemModel(chemModel, + new AWTDrawVisitor(g), + bounds, + isNewChemModel); isNewChemModel = false; /* @@ -221,7 +236,7 @@ } private void paintFromCache(Graphics2D g) { - renderer.repaint(g); + renderer.repaint(new AWTDrawVisitor(g)); } public void updateView() { @@ -298,7 +313,7 @@ + implicitHs + " "+GT._("Hs implicit")+")")+" (mass "+mass+")</html>"; } - public IntermediateRenderer getRenderer() { + public Renderer getRenderer() { return renderer; } } Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/CleanupAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/CleanupAction.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/CleanupAction.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -46,7 +46,7 @@ import org.openscience.cdk.layout.StructureDiagramGenerator; import org.openscience.cdk.layout.TemplateHandler; import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder; -import org.openscience.cdk.renderer.LogicalSelection; +import org.openscience.cdk.renderer.selection.LogicalSelection; import org.openscience.cdk.renderer.selection.RectangleSelection; import org.openscience.cdk.renderer.selection.ShapeSelection; Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/CopyPasteAction.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -62,9 +62,9 @@ import org.openscience.cdk.io.ReaderFactory; import org.openscience.cdk.layout.StructureDiagramGenerator; import org.openscience.cdk.layout.TemplateHandler; -import org.openscience.cdk.renderer.ISelection; -import org.openscience.cdk.renderer.LogicalSelection; import org.openscience.cdk.renderer.RendererModel; +import org.openscience.cdk.renderer.selection.ISelection; +import org.openscience.cdk.renderer.selection.LogicalSelection; import org.openscience.cdk.smiles.SmilesGenerator; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.tools.manipulator.ChemFileManipulator; @@ -90,7 +90,8 @@ handleSystemClipboard(); logger.info(" type ", type); logger.debug(" source ", e.getSource()); - RendererModel renderModel = jcpPanel.get2DHub().getIJava2DRenderer().getRenderer2DModel(); + RendererModel renderModel = + jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); if ("copy".equals(type)) { IAtomContainer copy = renderModel.getSelection().getConnectedAtomContainer(); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/EditAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/EditAction.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/EditAction.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -44,9 +44,9 @@ import org.openscience.cdk.interfaces.IBond; import org.openscience.cdk.interfaces.IChemModel; import org.openscience.cdk.interfaces.IChemObject; -import org.openscience.cdk.renderer.ISelection; -import org.openscience.cdk.renderer.LogicalSelection; import org.openscience.cdk.renderer.RendererModel; +import org.openscience.cdk.renderer.selection.ISelection; +import org.openscience.cdk.renderer.selection.LogicalSelection; import org.openscience.cdk.renderer.selection.RectangleSelection; import org.openscience.cdk.renderer.selection.ShapeSelection; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; @@ -73,7 +73,8 @@ logger.debug("Event source: ", event.getSource().getClass().getName()); logger.debug(" IChemObject: ", getSource(event)); - RendererModel renderModel = jcpPanel.get2DHub().getIJava2DRenderer().getRenderer2DModel(); + RendererModel renderModel + = jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); IChemModel chemModel = jcpPanel.getChemModel(); if (type.equals("cut")) { org.openscience.cdk.interfaces.IAtom atomInRange = null; Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/action/ModifyDisplaySettingsAction.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/action/ModifyDisplaySettingsAction.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/action/ModifyDisplaySettingsAction.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -46,7 +46,8 @@ { //TODO test if renderer uses settings logger.debug("Modify display settings in mode"); - RendererModel renderModel = jcpPanel.get2DHub().getIJava2DRenderer().getRenderer2DModel(); + RendererModel renderModel = + jcpPanel.get2DHub().getRenderer().getRenderer2DModel(); ModifyRenderOptionsDialog frame = new ModifyRenderOptionsDialog(jcpPanel,renderModel); frame.setVisible(true); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/applet/JChemPaintAbstractApplet.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -186,53 +186,73 @@ @Override public void start() { - RendererModel rendererModel = theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel(); + RendererModel rendererModel = + theJcpp.get2DHub().getRenderer().getRenderer2DModel(); IChemModel chemModel = theJcpp.getChemModel(); - IControllerModel controllerModel = theJcpp.get2DHub().getController2DModel(); + IControllerModel controllerModel = + theJcpp.get2DHub().getController2DModel(); + //Parameter parsing goes here loadModelFromParam(); String atomNumbers=getParameter("atomNumbersVisible"); - if(atomNumbers!=null){ - if(atomNumbers.equals("true")) - theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel().setDrawNumbers(true); - } + if (atomNumbers != null) { + if (atomNumbers.equals("true")) + rendererModel.setDrawNumbers(true); + } + String background = getParameter("background"); - if(background!=null){ - if(background.indexOf("#")==0) - theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel().setBackColor(Color.decode(background)); - else - theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel().setBackColor(new Color(Integer.parseInt(background))); + if (background != null) { + if (background.indexOf("#") == 0) + rendererModel.setBackColor(Color.decode(background)); + else + rendererModel.setBackColor(new Color(Integer + .parseInt(background))); + } + + if (getParameter("compact") != null + && getParameter("compact").equals("true")) { + rendererModel.setIsCompact(true); } - if(getParameter("compact")!=null && getParameter("compact").equals("true")){ - theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel().setIsCompact(true); - } - if(getParameter("tooltips")!=null){ - StringTokenizer st=new StringTokenizer(getParameter("tooltips"),"|"); - IAtomContainer container = theJcpp.getChemModel().getBuilder().newAtomContainer(); - Iterator<IAtomContainer> containers = ChemModelManipulator.getAllAtomContainers(theJcpp.getChemModel()).iterator(); + + if (getParameter("tooltips") != null) { + StringTokenizer st = + new StringTokenizer(getParameter("tooltips"), "|"); + IAtomContainer container = + theJcpp.getChemModel().getBuilder().newAtomContainer(); + Iterator<IAtomContainer> containers = + ChemModelManipulator.getAllAtomContainers(chemModel).iterator(); + while (containers.hasNext()) { container.add(containers.next()); } - while(st.hasMoreTokens()){ - IAtom atom = container.getAtom(Integer.parseInt(st.nextToken())-1); - theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel().getToolTipTextMap().put(atom,st.nextToken()); + + while (st.hasMoreTokens()) { + IAtom atom = + container.getAtom(Integer.parseInt(st.nextToken()) - 1); + rendererModel.getToolTipTextMap().put(atom, st.nextToken()); } - theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel().setShowTooltip(true); + rendererModel.setShowTooltip(true); } - if(getParameter("impliciths")!=null && getParameter("impliciths").equals("false")){ + + if (getParameter("impliciths") != null + && getParameter("impliciths").equals("false")) { controllerModel.setAutoUpdateImplicitHydrogens(false); rendererModel.setShowImplicitHydrogens(false); rendererModel.setShowEndCarbons(false); - }else{ + } else { controllerModel.setAutoUpdateImplicitHydrogens(true); rendererModel.setShowImplicitHydrogens(true); - rendererModel.setShowEndCarbons(true); - if(chemModel!=null){ - List<IAtomContainer> atomContainers = ChemModelManipulator.getAllAtomContainers(chemModel); + rendererModel.setShowEndCarbons(true); + + if (chemModel != null) { + List<IAtomContainer> atomContainers = + ChemModelManipulator.getAllAtomContainers(chemModel); for(int i=0;i<atomContainers.size();i++) { try { - CDKHydrogenAdder.getInstance(atomContainers.get(i).getBuilder()).addImplicitHydrogens(atomContainers.get(i)); + CDKHydrogenAdder.getInstance( + atomContainers.get(i).getBuilder()) + .addImplicitHydrogens(atomContainers.get(i)); } catch (CDKException e) { //do nothing } @@ -386,10 +406,12 @@ * @param atom The atom number (starting with 0) */ public void selectAtom(int atom){ - RendererModel rendererModel = theJcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel(); + RendererModel rendererModel = + theJcpp.get2DHub().getRenderer().getRenderer2DModel(); IChemModel chemModel = theJcpp.getChemModel(); rendererModel.setExternalHighlightColor(Color.RED); - IAtomContainer ac=chemModel.getMoleculeSet().getBuilder().newAtomContainer(); + IAtomContainer ac = + chemModel.getMoleculeSet().getBuilder().newAtomContainer(); ac.addAtom(chemModel.getMoleculeSet().getMolecule(0).getAtom(atom)); rendererModel.setExternalSelectedPart(ac); getTheJcpp().repaint(); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/application/JChemPaint.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -35,8 +35,6 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -166,7 +164,7 @@ } public static void showInstance(File inFile, String type, JChemPaintPanel jcpPanel){ - if (!inFile.exists()) { + if (!inFile.exists()) { JOptionPane.showMessageDialog(jcpPanel, "File " + inFile.getPath() + " does not exist."); return; @@ -238,23 +236,16 @@ } } String error = null; - List<IChemModel> chemModels=new ArrayList<IChemModel>(); + ChemModel chemModel = null; + IChemFile chemFile = null; if (cor.accepts(IChemFile.class)) { // try to read a ChemFile try { - IChemFile chemFile = (IChemFile) cor + chemFile = (IChemFile) cor .read((IChemObject) new org.openscience.cdk.ChemFile()); if (chemFile == null) { error = "The object chemFile was empty unexpectedly!"; } - for (int i = 0; i < chemFile.getChemSequenceCount(); i++) { - org.openscience.cdk.interfaces.IChemSequence chemSequence = chemFile.getChemSequence(i); - int chemModelCount = chemSequence.getChemModelCount(); - for (int j = 0; j < chemModelCount; j++) { - org.openscience.cdk.interfaces.IChemModel chemModel = chemSequence.getChemModel(j); - chemModels.add(chemModel); - } - } } catch (Exception exception) { error = "Error while reading file: " + exception.getMessage(); exception.printStackTrace(); @@ -264,10 +255,13 @@ JOptionPane.showMessageDialog(jcpPanel, error); return; } - if (cor.accepts(IChemModel.class)) { + if (cor.accepts(ChemModel.class)) { // try to read a ChemModel try { - chemModels.add((IChemModel)cor.read((IChemObject) new ChemModel())); + chemModel = (ChemModel) cor.read((IChemObject) new ChemModel()); + if (chemModel == null) { + error = "The object chemModel was empty unexpectedly!"; + } } catch (Exception exception) { error = "Error while reading file: " + exception.getMessage(); exception.printStackTrace(); @@ -276,22 +270,23 @@ if (error != null) { JOptionPane.showMessageDialog(jcpPanel, error); } - for (IChemModel chemModel : chemModels) { - if(chemModel==null) - error = "Model is null. Cannot display anything."; - // check for bonds - if (ChemModelManipulator.getBondCount(chemModel) == 0) { - error = "Model does not have bonds. Cannot depict contents."; - } - // check for coordinates - JChemPaint.checkCoordinates(chemModel); - - chemModel.setID(inFile.getName()); - JChemPaintPanel p = showInstance(chemModel, inFile.getName()); - p.setCurrentWorkDirectory(inFile.getParentFile()); - p.setLastOpenedFile(inFile); - p.setIsAlreadyAFile(inFile); + + if (chemModel == null && chemFile != null) { + chemModel = (ChemModel) chemFile.getChemSequence(0).getChemModel(0); } + + + // check for bonds + if (ChemModelManipulator.getBondCount(chemModel) == 0) { + error = "Model does not have bonds. Cannot depict contents."; + } + // check for coordinates + JChemPaint.checkCoordinates(chemModel); + + JChemPaintPanel p = showInstance(chemModel, inFile.getName()); + p.setCurrentWorkDirectory(inFile.getParentFile()); + p.setLastOpenedFile(inFile); + p.setIsAlreadyAFile(inFile); } // TODO Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/ValidateFrame.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/ValidateFrame.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/ValidateFrame.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -77,7 +77,7 @@ public ValidateFrame(JChemPaintPanel jcpp) { super("Validation Results"); - rendererModel = jcpp.get2DHub().getIJava2DRenderer().getRenderer2DModel(); + rendererModel = jcpp.get2DHub().getRenderer().getRenderer2DModel(); getContentPane().setLayout(new BorderLayout()); JPanel southPanel = new JPanel(); Modified: jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/RendererModelEditor.java =================================================================== --- jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/RendererModelEditor.java 2009-02-05 12:26:27 UTC (rev 14066) +++ jchempaint/trunk/src/main/org/openscience/jchempaint/dialog/editor/RendererModelEditor.java 2009-02-05 12:37:19 UTC (rev 14067) @@ -65,7 +65,7 @@ private JCheckBox useAA; private JLabel fontName; private JButton chooseFontButton; - private Font currentFont; + private String currentFontName; private JLabel color; private JButton chooseColorButton; private Color currentColor; @@ -83,7 +83,7 @@ } private void constructPanel() { - currentFont = null; + currentFontName = ""; drawNumbers = new JCheckBox(); addField(GT._("Draw atom numbers"), drawNumbers); showAtomAtomMapping = new JCheckBox(); @@ -133,9 +133,9 @@ useAA.setSelected(model.getUseAntiAliasing()); showToolTip.setSelected(model.getShowTooltip()); showReactionBoxes.setSelected(model.getShowReactionBoxes()); - currentFont = model.getFont(); - if (currentFont != null) { - fontName.setText(currentFont.getFontName()); + currentFontName = model.getFontName(); + if (!currentFontName.equals("")) { + fontName.setText(currentFontName); } currentColor = model.getBackColor(); if (currentColor != null) { @@ -156,7 +156,7 @@ model.setUseAntiAliasing(useAA.isSelected()); model.setShowTooltip(showToolTip.isSelected()); model.setShowReactionBoxes(showReactionBoxes.isSelected()); - model.setFont(currentFont); + model.setFontName(currentFontName); model.setBackColor(currentColor); } @@ -165,10 +165,14 @@ */ public void actionPerformed(ActionEvent e) { if ("chooseFont".equals(e.getActionCommand())) { - Font newFont = JFontChooser.showDialog(this.frame, GT._("Choose a Font"), GT._("Carbon Dioxide"), currentFont); + Font newFont = JFontChooser.showDialog( + this.frame, + GT._("Choose a Font"), + GT._("Carbon Dioxide"), + new Font(currentFontName, Font.PLAIN, 12)); if (newFont != null) { - currentFont = newFont; - fontName.setText(currentFont.getFontName()); + currentFontName = newFont.getFontName(); + fontName.setText(currentFontName); } } if ("chooseColor".equals(e.getActionCommand())) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |