コード例 #1
0
ファイル: CatalogWindow.cs プロジェクト: carlhuth/GenXSource
        override public void  Run()
        {
            try
            {
                long pos = 0, nextpos;
                while (!zap)
                {
                    lock (mutex)
                    {
                        nextpos = MoleculeStream.FindNextPosition(istr, pos);
                    }
                    if (nextpos < 0)
                    {
                        break;
                    }

                    filepos.Add(pos);
                    pos = nextpos;

                    // inform the main window that is has work to do!
                    //UPGRADE_ISSUE: Method 'java.awt.EventQueue.invokeLater' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtEventQueue'"
                    //EventQueue.invokeLater(new AnonymousClassRunnable(this));
                    Synch synchDelegate = new Synch(wnd.Synchronize);
                    synchDelegate(filepos.Count);
                }
            }
            catch (System.IO.IOException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                SupportClass.OptionPaneSupport.ShowMessageDialog(null, e.ToString(), "Catalog Load Failed", (int)System.Windows.Forms.MessageBoxIcon.Error);
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
コード例 #2
0
ファイル: CatalogWindow.cs プロジェクト: carlhuth/GenXSource
 public virtual Molecule Get(int N)
 {
     try
     {
         lock (mutex)
         {
             return(MoleculeStream.FetchFromPosition(istr, filepos[N]));
         }
     }
     catch (System.IO.IOException e)
     {
         return(null);
     }
 }
コード例 #3
0
ファイル: FileMolPreview.cs プロジェクト: carlhuth/GenXSource
        public virtual void  propertyChange(System.Object event_sender, SupportClass.PropertyChangingEventArgs ev)
        {
            bool update = false;

            System.String prop = ev.PropertyName;

            if ("directoryChanged".Equals(prop))
            // changed directory, do nothing much
            {
                file   = null;
                update = true;
            }
            else if ("SelectedFilesChangedProperty".Equals(prop))
            // file just got selected
            {
                file   = (System.IO.FileInfo)ev.NewValue;
                update = true;
            }

            if (update)
            {
                thumbnail = null;
                Molecule mol = null;
                if (file != null && System.IO.File.Exists(file.FullName))
                {
                    try
                    {
                        //UPGRADE_TODO: Constructor 'java.io.FileInputStream.FileInputStream' was converted to 'System.IO.FileStream.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileInputStreamFileInputStream_javaioFile'"
                        System.IO.FileStream istr = new System.IO.FileStream(file.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        mol = MoleculeStream.ReadUnknown(istr);
                        istr.Close();
                    }
                    catch (System.IO.IOException)
                    {
                        mol = null;
                    }
                }
                if (mol == null)
                {
                    mol = new Molecule();
                }
                Replace(mol);
                ScaleToFit();
                if (Visible)
                {
                    //UPGRADE_TODO: Method 'java.awt.Component.repaint' was converted to 'System.Windows.Forms.Control.Refresh' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtComponentrepaint'"
                    Refresh();
                }
            }
        }
コード例 #4
0
        public Templates()
        {
            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            List <String> list = new List <String>();

            // read the list of molecules from the directory file, then create each one of them
            Assembly assembly = Assembly.GetExecutingAssembly();

            string[] resources = assembly.GetManifestResourceNames();

            try
            {
                // Build the string of resources.
                foreach (string resource in resources)
                {
                    if (resource.StartsWith("Genetibase.Chem.NuGenSChem.templ."))
                    {
                        list.Add(resource);
                    }
                }
            }
            catch (IOException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.Console.Out.WriteLine("Failed to obtain list of templates:\n" + e.ToString());
                return;
            }

            try
            {
                for (int n = 0; n < list.Count; n++)
                {
                    Stream   istr = assembly.GetManifestResourceStream(list[n]);
                    Molecule mol  = MoleculeStream.ReadNative(istr);
                    templ.Add(mol);
                    istr.Close();
                }
            }
            catch (System.IO.IOException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                System.Console.Out.WriteLine("Failed to obtain particular template:\n" + e.ToString());
                return;
            }

            // sort the molecules by an index of "complexity" (smaller molecules first, carbon-only favoured)

            int[] complex = new int[templ.Count];
            for (int n = 0; n < templ.Count; n++)
            {
                Molecule mol = templ[n];
                complex[n] = mol.NumAtoms() * 100;
                bool nonCH = false;
                for (int i = 1; i <= mol.NumAtoms(); i++)
                {
                    if (String.CompareOrdinal(mol.AtomElement(i), "C") != 0 && String.CompareOrdinal(mol.AtomElement(i), "H") != 0)
                    {
                        nonCH = true;
                    }
                }
                if (!nonCH)
                {
                    complex[n] -= 1000;
                }
                for (int i = 1; i <= mol.NumBonds(); i++)
                {
                    complex[n] = complex[n] + mol.BondOrder(i);
                }
            }

            int p = 0;

            while (p < templ.Count - 1)
            {
                if (complex[p] > complex[p + 1])
                {
                    int      i   = complex[p]; complex[p] = complex[p + 1]; complex[p + 1] = i;
                    Molecule mol = templ[p]; templ[p] = templ[p + 1]; templ[p + 1] = mol;
                    if (p > 0)
                    {
                        p--;
                    }
                }
                else
                {
                    p++;
                }
            }
        }