All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.actelion.research.gui.editor.BondQueryFeatureDialogBuilder Maven / Gradle / Ivy

There is a newer version: 2024.11.2
Show newest version
/*
* Copyright (c) 1997 - 2016
* Actelion Pharmaceuticals Ltd.
* Gewerbestrasse 16
* CH-4123 Allschwil, Switzerland
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
*    list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
* 3. Neither the name of the the copyright holder nor the
*    names of its contributors may be used to endorse or promote products
*    derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

package com.actelion.research.gui.editor;

import com.actelion.research.chem.ExtendedMolecule;
import com.actelion.research.chem.Molecule;
import com.actelion.research.gui.generic.*;
import com.actelion.research.gui.hidpi.HiDPIHelper;

public class BondQueryFeatureDialogBuilder implements GenericEventListener {
	private GenericDialog       mDialog;
    private ExtendedMolecule	mMol;
	private int					mBond,mFirstSpanItem;
	private GenericCheckBox     mCBSingle,mCBDouble,mCBTriple,mCBQuadruple,mCBQuintuple,mCBDelocalized,
								mCBMetalLigand,mCBIsBridge,mCBMatchFormalOrder,mCBMatchStereo;
	private GenericComboBox     mComboBoxRing,mComboBoxRingSize,mComboBoxMinAtoms,mComboBoxMaxAtoms;
	private boolean             mOKSelected;

	public BondQueryFeatureDialogBuilder(GenericUIHelper dialogHelper, ExtendedMolecule mol, int bond) {
		mDialog = dialogHelper.createDialog((mol.isSelectedAtom(mol.getBondAtom(0, bond))
				&& mol.isSelectedAtom(mol.getBondAtom(1, bond))) ?
				"Bond Query Features (Multiple)" : "Bond Query Features", this);
		build(mol, bond);
		}

	/**
	 * @return true if OK was pressed and potential change was applied to molecule
	 */
	public boolean showDialog() {
		mOKSelected = false;
		mDialog.showDialog();
		return mOKSelected;
		}

	private void build(ExtendedMolecule mol, int bond) {
		mMol = mol;
		mBond = bond;

		int gap = HiDPIHelper.scale(8);
		int[] hLayout = {gap, GenericDialog.FILL, GenericDialog.PREFERRED, GenericDialog.PREFERRED, gap};
        int[] vLayout = {gap, GenericDialog.PREFERRED, gap, GenericDialog.PREFERRED, GenericDialog.PREFERRED,
					        GenericDialog.PREFERRED, GenericDialog.PREFERRED,
		                    GenericDialog.PREFERRED, GenericDialog.PREFERRED, GenericDialog.PREFERRED, gap,
					        GenericDialog.PREFERRED, gap, GenericDialog.PREFERRED, gap, GenericDialog.PREFERRED, gap,
		                    GenericDialog.PREFERRED, 2*gap,
					        GenericDialog.PREFERRED, gap/2, GenericDialog.PREFERRED, gap/2, GenericDialog.PREFERRED, 2*gap};
        mDialog.setLayout(hLayout, vLayout);

		mDialog.add(mDialog.createLabel("Desired Bond type(s):"), 1, 1, 3, 1);

		mCBSingle = mDialog.createCheckBox("Single");
		mDialog.add(mCBSingle,1,3,3,3);

		mCBDouble = mDialog.createCheckBox("Double");
		mDialog.add(mCBDouble,1,4,3,4);

		mCBTriple = mDialog.createCheckBox("Triple");
		mDialog.add(mCBTriple,1,5,3,5);

		mCBQuadruple = mDialog.createCheckBox("Quadruple");
		mDialog.add(mCBQuadruple,1,6,3,6);

		mCBQuintuple = mDialog.createCheckBox("Quintuple");
		mDialog.add(mCBQuintuple,1,7,3,7);

		mCBDelocalized = mDialog.createCheckBox("Delocalized");
		mDialog.add(mCBDelocalized,1,8,3,8);

		mCBMetalLigand = mDialog.createCheckBox("Coordinate (0-order)");
		mDialog.add(mCBMetalLigand,1,9,3,9);

		mComboBoxRing = mDialog.createComboBox();
		mComboBoxRing.addItem("any ring state");
		mComboBoxRing.addItem("is not in a ring");
		mComboBoxRing.addItem("is any ring bond");
		mComboBoxRing.addItem("is non-aromatic ring bond");
		mComboBoxRing.addItem("is aromatic bond");
		mComboBoxRing.addEventConsumer(this);
		mDialog.add(mComboBoxRing,1,11,3,11);

		mComboBoxRingSize = mDialog.createComboBox();
		mComboBoxRingSize.addItem("any ring size");
		mComboBoxRingSize.addItem("is in 3-membered ring");
		mComboBoxRingSize.addItem("is in 4-membered ring");
		mComboBoxRingSize.addItem("is in 5-membered ring");
		mComboBoxRingSize.addItem("is in 6-membered ring");
		mComboBoxRingSize.addItem("is in 7-membered ring");
		mDialog.add(mComboBoxRingSize, 1,13,3,13);

		mCBMatchFormalOrder = mDialog.createCheckBox("Match formal bond order");
		mCBMatchFormalOrder.setSelected((mol.getBondQueryFeatures(bond) & Molecule.cBondQFMatchFormalOrder) != 0);
		mCBMatchFormalOrder.addEventConsumer(this);
		mDialog.add(mCBMatchFormalOrder, 1,15,3,15);

		mCBMatchStereo = mDialog.createCheckBox("Match Stereo Configuration");
		mCBMatchStereo.setSelected((mol.getBondQueryFeatures(bond) & Molecule.cBondQFMatchStereo) != 0);
		mCBMatchStereo.addEventConsumer(this);
		mDialog.add(mCBMatchStereo, 1,17,3,17);

		mCBIsBridge = mDialog.createCheckBox("Is atom bridge between");
        mCBIsBridge.addEventConsumer(this);
		mDialog.add(mCBIsBridge,1,19,3,19);

        mComboBoxMinAtoms = mDialog.createComboBox();
        int itemCount = (1 << Molecule.cBondQFBridgeMinBits);
        for (int i=0; i> Molecule.cBondQFRingSizeShift;
		mComboBoxRingSize.setSelectedIndex((ringSize == 0) ? 0 : ringSize-2);

        if ((queryFeatures & Molecule.cBondQFBridge) != 0) {
            mCBIsBridge.setSelected(true);
            int minAtoms = (queryFeatures & Molecule.cBondQFBridgeMin) >> Molecule.cBondQFBridgeMinShift;
            int atomSpan = (queryFeatures & Molecule.cBondQFBridgeSpan) >> Molecule.cBondQFBridgeSpanShift;
            mComboBoxMinAtoms.setSelectedIndex(minAtoms);
            populateComboBoxMaxAtoms(minAtoms);
            mComboBoxMaxAtoms.setSelectedIndex(atomSpan);
            }
        else
	        mComboBoxMaxAtoms.setSelectedIndex(0);

        enableItems();
        }


    private int populateComboBoxMaxAtoms(int minAtoms) {
        mComboBoxMaxAtoms.removeAllItems();
        int itemCount = (1 << Molecule.cBondQFBridgeSpanBits);
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy