Back to index

wims  3.65+svn20090927
MainPanel.java
Go to the documentation of this file.
00001 /*
00002     WIMSchem Elements: Chemistry molecular diagram drawing tool.
00003     
00004     (c) 2007 Dr. Alex M. Clark
00005     
00006     Released as GNUware, under the Gnu Public License (GPL)
00007     
00008     See www.gnu.org for details.
00009 */
00010 
00011 package WIMSchem;
00012 
00013 import WIMSchem.ds.*;
00014 
00015 import java.io.*;
00016 import java.awt.*;
00017 import java.util.*;
00018 import java.awt.image.*;
00019 import java.awt.event.*;
00020 import java.awt.datatransfer.*;
00021 import javax.swing.*;
00022 
00023 /*
00024     Encapsulates the editing panel, provides menus and toolbars, and responds to various types
00025     of events.
00026     
00027     General description of WIMSchem: molecular sketching program, for preparing cheminformatic representations of molecules, and a
00028     few other miscellaneous useful tasks. Is generally intended for using in conjunction with various computational or presentation
00029     packages which do not themselves necessarily have a good editor for molecular connection graphs.
00030 */
00031 
00032 public class MainPanel extends JPanel implements ActionListener, MouseListener, WindowListener, KeyListener, ClipboardOwner, 
00033                                             TemplSelectListener, MolSelectListener
00034 {
00035     public String LICENSE= // (encoded in a string so that it appears in the final .jar file)
00036        "This program is free software; you can redistribute it and/or modify\n"+
00037        "it under the terms of the GNU General Public License as published by\n"+
00038        "the Free Software Foundation; either version 2 of the License, or\n"+
00039        "(at your option) any later version.\n\n"+
00040        "This program is distributed in the hope that it will be useful,\n"+
00041        "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"+
00042        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"+
00043        "GNU General Public License for more details.\n\n"+
00044        "You should have received a copy of the GNU General Public License\n"+
00045        "along with this program; if not, write to the Free Software\n"+
00046        "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\n\n"+
00047        "or see http://www.gnu.org for details.";
00048 
00049     public static String VERSION="0.1";
00050 
00051     public Properties loadProperties(String lang){//jm.evers                                                                               
00052         Properties P=new Properties();                                                                                                     
00053         try{                                                                                                                               
00054             InputStream in = getClass().getResourceAsStream("/lang/WIMSchemProperties_"+lang+".properties");                               
00055             P.load(in);in.close();                                                                                                         
00056             return P;                                                                                                                      
00057     }                                                                                                                                      
00058         catch (Exception e){ System.out.println("error reading /lang/WIMSchemProperties_"+lang+".properties\n"+e);}                        
00059         return null;                                                                                                                       
00060     } 
00061 
00062 
00063     MainWindow frameParent;
00064 
00065     ImageIcon mainIcon=null,mainLogo=null;
00066     public static boolean viewH;
00067     public static boolean viewC;
00068     static final int TOOL_CURSOR=0;
00069     static final int TOOL_ROTATOR=1;
00070     static final int TOOL_ERASOR=2;
00071     static final int TOOL_DIALOG=3;
00072     static final int TOOL_EDIT=4;
00073     static final int TOOL_SETATOM=5;
00074     static final int TOOL_SINGLE=6;
00075     static final int TOOL_DOUBLE=7;
00076     static final int TOOL_TRIPLE=8;
00077     static final int TOOL_ZERO=9;
00078     static final int TOOL_INCLINED=10;
00079     static final int TOOL_DECLINED=11;
00080     static final int TOOL_UNKNOWN=12;
00081     static final int TOOL_CHARGE=13;
00082     static final int TOOL_UNDO=14;
00083     static final int TOOL_REDO=15;
00084     static final int TOOL_TEMPLATE=16;
00085     static final int TOOL_CUT=17;
00086     static final int TOOL_COPY=18;
00087     static final int TOOL_PASTE=19;
00088     static final int TOOL_COUNT=20;
00089     public String[] TOOL_TIPS;
00090     public String[] IMAGE_TOOL={
00091        "Cursor","Rotator","Erasor","EDialog","AEdit","ASelect","BSingle","BDouble","BTriple","BZero","BInclined","BDeclined","BUnknown",
00092        "ACharge","Undo","Redo","Template","ECut","ECopy","EPaste"
00093     };
00094     
00095     // jm.evers
00096     public boolean[] selected_tools={true,true,true,true,true,true,true,true,true,true,
00097                                    true,true,true,true,true,true,true,true,true,true};
00098     // jm.evers
00099     public boolean[] selected_menus={true,true,true,true,true,true,true,true};
00100     
00101     public String[] my_atoms;
00102 
00103     // jm.evers
00104     public  String getToolTips( int p ){
00105        if(p>TOOL_COUNT){return "error";}
00106        TOOL_TIPS[0]=translation.getProperty("CURSOR_TIP");
00107        TOOL_TIPS[1]=translation.getProperty("ROTATOR_TIP");
00108        TOOL_TIPS[2]=translation.getProperty("ERASOR_TIP");
00109        TOOL_TIPS[3]=translation.getProperty("EDIT_DIALOG_TIP");
00110        TOOL_TIPS[4]=translation.getProperty("EDIT_ELEMENT_TIP");
00111        TOOL_TIPS[5]=translation.getProperty("PLACE_ELEMENT_TIP");
00112        TOOL_TIPS[6]=translation.getProperty("SINGLE_BOND_TIP");
00113        TOOL_TIPS[7]=translation.getProperty("DOUBLE_BOND_TIP");
00114        TOOL_TIPS[8]=translation.getProperty("TRIPLE_BOND_TIP");
00115        TOOL_TIPS[9]=translation.getProperty("ZERO_BOND_TIP");
00116        TOOL_TIPS[10]=translation.getProperty("INCLINED_BOND_TIP");
00117        TOOL_TIPS[11]=translation.getProperty("DECLINE_BOND_TIP");
00118        TOOL_TIPS[12]=translation.getProperty("SQUIGGLY_BOND_TIP");
00119        TOOL_TIPS[13]=translation.getProperty("CHARGE_TIP");
00120        TOOL_TIPS[14]=translation.getProperty("UNDO_TIP");
00121        TOOL_TIPS[15]=translation.getProperty("REDO_TIP");
00122        TOOL_TIPS[16]=translation.getProperty("TEMPLATE_TIP");
00123        TOOL_TIPS[17]=translation.getProperty("CUT_TIP");
00124        TOOL_TIPS[18]=translation.getProperty("COPY_TIP");
00125        TOOL_TIPS[19]=translation.getProperty("PASTE");
00126        return TOOL_TIPS[p];
00127     }
00128     
00129     AbstractButton[] toolButtons;
00130     ButtonGroup toolGroup;
00131     ImageIcon[] toolIcons;
00132     EditorPane editor;
00133     Templates templ;
00134     JCheckBoxMenuItem chkShowHydr,chkShowSter;
00135     
00136     boolean firstResize=true;
00137     String filename=null;
00138     String lastElement=null,typedElement="";
00139     Molecule lastTemplate=null;
00140     int templateIdx=-1;
00141     boolean streamMode=false,appletMode=false;
00142     String language="";
00143     Properties translation;
00144     boolean useLocalClipboard=false;
00145     String appletClipboard="";
00146     
00147 
00148     public MainPanel(String LoadFN,boolean StreamMode,boolean AppletMode,MainWindow FrameParent,String Language,Properties Translation, boolean[] Selected_Tools, boolean[] Selected_Menus , String[] My_Atoms , boolean ViewH, boolean ViewC){
00149        streamMode=StreamMode;
00150        appletMode=AppletMode;
00151        // jm.evers
00152        if(appletMode){
00153            viewH=ViewH;
00154            viewC=ViewC;
00155            selected_tools=Selected_Tools;
00156            selected_menus=Selected_Menus;
00157            my_atoms=My_Atoms;
00158            mainIcon=new ImageIcon(getClass().getResource("/images/wims_icon.gif"));
00159            mainLogo=new ImageIcon(getClass().getResource("/images/wims_logo.gif"));
00160            language=Language;
00161            translation=Translation;
00162            System.out.println("Hi, I\'m the applet version....language is :"+language);
00163        }
00164        else
00165        {// no language button yet...
00166            language="en";
00167            my_atoms=null;
00168            viewH=true;
00169            viewC=true;    
00170            mainIcon=new ImageIcon(getClass().getResource("/images/MainIcon.png"));
00171            mainLogo=new ImageIcon(getClass().getResource("/images/MainLogo.png"));
00172            translation=loadProperties("en");
00173            System.out.println("Hi, I\'m the standalone version....language is :"+language);
00174        }
00175        frameParent=FrameParent;
00176        useLocalClipboard=appletMode; 
00177        // applet mode always uses "local clipboard"; if the applet is signed, this will need to switch
00178        // to false if permission has been granted to use the system clipboard
00179        templ=new Templates(getClass());
00180        
00181        // toolbar
00182        TOOL_TIPS=new String[20];
00183        JToolBar tools=new JToolBar(JToolBar.VERTICAL);
00184        tools.setFloatable(!AppletMode);
00185        toolButtons=new AbstractButton[TOOL_COUNT];
00186        toolIcons=new ImageIcon[TOOL_COUNT];
00187        toolGroup=new ButtonGroup();
00188 
00189        // jm.evers
00190        for (int n=0;n<TOOL_COUNT;n++) 
00191        {
00192            toolIcons[n]=new ImageIcon(getClass().getResource("/images/"+IMAGE_TOOL[n]+".png"));
00193            if (selected_tools[n]) 
00194            {
00195               toolButtons[n]=new ToolButton(toolIcons[n]); 
00196               toolGroup.add(toolButtons[n]);
00197               tools.add(toolButtons[n]);
00198               toolButtons[n].addActionListener(this);
00199               toolButtons[n].setToolTipText(getToolTips(n));
00200            }
00201            /*else {toolButtons[n]=new JButton(toolIcons[n]);
00202            tools.add(toolButtons[n]);
00203            toolButtons[n].addActionListener(this);}*/
00204        }
00205        if(selected_tools[0]){toolGroup.setSelected(toolButtons[TOOL_CURSOR].getModel(),true);}
00206        if(selected_tools[5]){
00207            toolButtons[TOOL_SETATOM].addMouseListener(this);// tool 5
00208            toolButtons[TOOL_SETATOM].addKeyListener(this);
00209            SelectElement("C");
00210        }
00211        if(selected_tools[16]){toolButtons[TOOL_TEMPLATE].addMouseListener(this);}   
00212 
00213        // menu
00214        
00215        JMenuBar menubar=AppletMode ? MenuBarApplet() : MenuBarApplication();
00216 
00217        // molecule
00218        
00219        editor=new EditorPane();
00220        editor.SetMolSelectListener(this);
00221        JScrollPane scroll=new JScrollPane(editor);
00222 
00223        // overall layout
00224 
00225        if (!AppletMode)
00226        {
00227            setLayout(new BorderLayout());
00228            add(scroll,BorderLayout.CENTER);
00229            add(menubar,BorderLayout.NORTH);
00230            add(tools,BorderLayout.WEST);
00231        }
00232        else
00233        {
00234            // (!! add a little icon somewhere which does the About box...)
00235 
00236            JPanel p=new JPanel();
00237            p.setLayout(new BorderLayout());
00238            p.add(menubar,BorderLayout.NORTH);
00239            p.add(scroll,BorderLayout.CENTER);
00240            
00241            setLayout(new BorderLayout());
00242            add(tools,BorderLayout.WEST);
00243            add(p,BorderLayout.CENTER);
00244        }
00245        
00246        editor.grabFocus();
00247        
00248        editor.SetToolCursor();
00249        
00250        if (LoadFN!=null)
00251        {
00252            try
00253            {
00254               FileInputStream istr=new FileInputStream(LoadFN);
00255               Molecule frag=MoleculeStream.ReadUnknown(istr);
00256               editor.AddArbitraryFragment(frag);
00257               istr.close();
00258            }
00259            catch (IOException e) 
00260            {
00261               JOptionPane.showMessageDialog(null,e.toString(),"Open Failed",JOptionPane.ERROR_MESSAGE);
00262               return;
00263            }
00264 
00265            SetFilename(LoadFN);
00266            editor.NotifySaved();
00267        }
00268        if (streamMode) ReadStream();
00269        
00270        addKeyListener(this);
00271        editor.addKeyListener(this);
00272        if (frameParent!=null) frameParent.addWindowListener(this);
00273     }
00274     
00275     // builds and returns a menu bar suitable for the application-style invocation
00276     public JMenuBar MenuBarApplication()
00277     {
00278        JMenuBar menubar=new JMenuBar();
00279        JMenu menufile=new JMenu(translation.getProperty("File"));
00280        menufile.setMnemonic(KeyEvent.VK_F);
00281        menufile.add(MenuItem(translation.getProperty("New"),KeyEvent.VK_N,null,KeyStroke.getKeyStroke('N',InputEvent.CTRL_MASK)));
00282        menufile.add(MenuItem(translation.getProperty("New_Window"),KeyEvent.VK_W,null,KeyStroke.getKeyStroke('N',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00283        if (DataWindow.ALLOW) // (temporary)
00284            menufile.add(MenuItem(translation.getProperty("New_DataSheet"),KeyEvent.VK_D,null));
00285        menufile.add(MenuItem(translation.getProperty("Open"),KeyEvent.VK_O,null,KeyStroke.getKeyStroke('O',InputEvent.CTRL_MASK)));
00286        if (!streamMode) menufile.add(MenuItem(translation.getProperty("Save"),KeyEvent.VK_S,null,KeyStroke.getKeyStroke('S',InputEvent.CTRL_MASK)));
00287        menufile.add(MenuItem(translation.getProperty("Save_As"),KeyEvent.VK_A));
00288        JMenu menuexport=new JMenu(translation.getProperty("Export"));
00289        menuexport.setMnemonic(KeyEvent.VK_X);
00290        menuexport.add(MenuItem("Native2Javascript (wims)",KeyEvent.VK_M,null,KeyStroke.getKeyStroke('W',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00291        menuexport.add(MenuItem("MDLMol2Javascript (wims)",KeyEvent.VK_M,null,KeyStroke.getKeyStroke('V',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00292        menuexport.add(MenuItem(translation.getProperty("as_MDL_MOL"),KeyEvent.VK_M,null,KeyStroke.getKeyStroke('M',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00293        menuexport.add(MenuItem(translation.getProperty("as_CML_XML"),KeyEvent.VK_X,null,KeyStroke.getKeyStroke('X',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00294        menufile.add(menuexport);
00295 
00296        menufile.addSeparator();
00297        if (!streamMode) menufile.add(MenuItem(translation.getProperty("Quit"),KeyEvent.VK_Q,null,KeyStroke.getKeyStroke('Q',InputEvent.CTRL_MASK)));
00298        else menufile.add(MenuItem(translation.getProperty("Save_and_Quit"),KeyEvent.VK_Q,null,KeyStroke.getKeyStroke('Q',InputEvent.CTRL_MASK)));
00299        
00300        JMenu menuedit=new JMenu(translation.getProperty("Edit"));
00301        menuedit.setMnemonic(KeyEvent.VK_E);
00302        menuedit.add(MenuItem(translation.getProperty("Editttt"),KeyEvent.VK_E,toolIcons[TOOL_DIALOG],KeyStroke.getKeyStroke(' ',InputEvent.CTRL_MASK)));
00303        menuedit.add(MenuItem(translation.getProperty("Undo"),KeyEvent.VK_U,toolIcons[TOOL_UNDO],KeyStroke.getKeyStroke('Z',InputEvent.CTRL_MASK)));
00304        menuedit.add(MenuItem(translation.getProperty("Redo"),KeyEvent.VK_R,toolIcons[TOOL_REDO],KeyStroke.getKeyStroke('Z',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00305        menuedit.add(MenuItem(translation.getProperty("Cut"),KeyEvent.VK_X,toolIcons[TOOL_CUT],KeyStroke.getKeyStroke('X',InputEvent.CTRL_MASK)));
00306        menuedit.add(MenuItem(translation.getProperty("Copy"),KeyEvent.VK_C,toolIcons[TOOL_COPY],KeyStroke.getKeyStroke('C',InputEvent.CTRL_MASK)));
00307        menuedit.add(MenuItem(translation.getProperty("Paste"),KeyEvent.VK_V,toolIcons[TOOL_PASTE],KeyStroke.getKeyStroke('V',InputEvent.CTRL_MASK)));
00308        menuedit.addSeparator();
00309        menuedit.add(MenuItem(translation.getProperty("Select_All"),KeyEvent.VK_S,null,KeyStroke.getKeyStroke('A',InputEvent.CTRL_MASK)));
00310        menuedit.add(MenuItem(translation.getProperty("Next_Atom"),KeyEvent.VK_N,null,KeyStroke.getKeyStroke('E',InputEvent.CTRL_MASK)));
00311        menuedit.add(MenuItem(translation.getProperty("Previous_Atom"),KeyEvent.VK_P,null,KeyStroke.getKeyStroke('E',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00312        menuedit.add(MenuItem(translation.getProperty("Next_Group"),KeyEvent.VK_G,null,KeyStroke.getKeyStroke('G',InputEvent.CTRL_MASK)));
00313        menuedit.add(MenuItem(translation.getProperty("Previous_Group"),KeyEvent.VK_R,null,KeyStroke.getKeyStroke('G',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00314        menuedit.addSeparator();
00315        menuedit.add(MenuItem(translation.getProperty("Flip_Horizontal"),KeyEvent.VK_H,null,null));
00316        menuedit.add(MenuItem(translation.getProperty("Flip_Vertical"),KeyEvent.VK_V,null,null));
00317        menuedit.add(MenuItem(translation.getProperty("Rotate_P45"),KeyEvent.VK_4,null,null));
00318        menuedit.add(MenuItem(translation.getProperty("Rotate_M45"),KeyEvent.VK_5,null,null));
00319        menuedit.add(MenuItem(translation.getProperty("Rotate_P90"),KeyEvent.VK_9,null,null));
00320        menuedit.add(MenuItem(translation.getProperty("Rotate_M90"),KeyEvent.VK_0,null,null));
00321        menuedit.addSeparator();
00322        menuedit.add(MenuItem(translation.getProperty("Add_Temporary_Template"),KeyEvent.VK_T,null,null));
00323        menuedit.add(MenuItem(translation.getProperty("Normalise_Bond_Lengths"),KeyEvent.VK_N,null,null));
00324        
00325        JMenu menuview=new JMenu(translation.getProperty("View"));
00326        menuview.setMnemonic(KeyEvent.VK_V);
00327        menuview.add(MenuItem(translation.getProperty("Zoom_Full"),KeyEvent.VK_F,null,KeyStroke.getKeyStroke('0',InputEvent.CTRL_MASK)));
00328        menuview.add(MenuItem(translation.getProperty("Zoom_In"),KeyEvent.VK_I,null,KeyStroke.getKeyStroke('=',InputEvent.CTRL_MASK)));
00329        menuview.add(MenuItem(translation.getProperty("Zoom_Out"),KeyEvent.VK_O,null,KeyStroke.getKeyStroke('-',InputEvent.CTRL_MASK)));
00330        menuview.addSeparator();
00331        ButtonGroup showBG=new ButtonGroup();
00332        menuview.add(RadioMenuItem(translation.getProperty("Show_Elements"),KeyEvent.VK_E,true,showBG));
00333        menuview.add(RadioMenuItem(translation.getProperty("Show_All_Elements"),KeyEvent.VK_A,false,showBG));
00334        menuview.add(RadioMenuItem(translation.getProperty("Show_Indices"),KeyEvent.VK_I,false,showBG));
00335        menuview.add(RadioMenuItem(translation.getProperty("Show_Ring_ID"),KeyEvent.VK_R,false,showBG));
00336        menuview.add(RadioMenuItem(translation.getProperty("Show_CIP_Priority"),KeyEvent.VK_C,false,showBG));
00337        menuview.add(RadioMenuItem(translation.getProperty("Show_Mapping_Number"),KeyEvent.VK_M,false,showBG));
00338        
00339        JMenu menutool=new JMenu(translation.getProperty("Tool"));
00340        menutool.setMnemonic(KeyEvent.VK_T);
00341        menutool.add(MenuItem(translation.getProperty("Cursor"),KeyEvent.VK_C,toolIcons[TOOL_CURSOR],KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0)));
00342        menutool.add(MenuItem(translation.getProperty("Rotator"),KeyEvent.VK_R,toolIcons[TOOL_ROTATOR],KeyStroke.getKeyStroke('R',InputEvent.CTRL_MASK)));
00343        menutool.add(MenuItem(translation.getProperty("Erasor"),KeyEvent.VK_E,toolIcons[TOOL_ERASOR],KeyStroke.getKeyStroke('D',InputEvent.CTRL_MASK)));
00344        menutool.add(MenuItem(translation.getProperty("Edit_Atom"),KeyEvent.VK_A,toolIcons[TOOL_EDIT],KeyStroke.getKeyStroke(',',InputEvent.CTRL_MASK)));
00345        menutool.add(MenuItem(translation.getProperty("Set_Atom"),KeyEvent.VK_S,new ImageIcon(getClass().getResource("/images/ASelMenu.png")),KeyStroke.getKeyStroke('.',InputEvent.CTRL_MASK)));
00346        menutool.add(MenuItem(translation.getProperty("Single_Bond"),KeyEvent.VK_1,toolIcons[TOOL_SINGLE],KeyStroke.getKeyStroke('1',InputEvent.CTRL_MASK)));
00347        menutool.add(MenuItem(translation.getProperty("Double_Bond"),KeyEvent.VK_2,toolIcons[TOOL_DOUBLE],KeyStroke.getKeyStroke('2',InputEvent.CTRL_MASK)));
00348        menutool.add(MenuItem(translation.getProperty("Triple_Bond"),KeyEvent.VK_3,toolIcons[TOOL_TRIPLE],KeyStroke.getKeyStroke('3',InputEvent.CTRL_MASK)));
00349        menutool.add(MenuItem(translation.getProperty("Zero_Bond"),KeyEvent.VK_0,toolIcons[TOOL_ZERO],KeyStroke.getKeyStroke('0',InputEvent.CTRL_MASK)));
00350        menutool.add(MenuItem(translation.getProperty("Inclined_Bond"),KeyEvent.VK_I,toolIcons[TOOL_INCLINED]));
00351        menutool.add(MenuItem(translation.getProperty("Declined_Bond"),KeyEvent.VK_D,toolIcons[TOOL_DECLINED]));
00352        menutool.add(MenuItem(translation.getProperty("Unknown_Bond"),KeyEvent.VK_U,toolIcons[TOOL_UNKNOWN]));
00353        menutool.add(MenuItem(translation.getProperty("Charge"),KeyEvent.VK_H,toolIcons[TOOL_CHARGE],KeyStroke.getKeyStroke('H',InputEvent.CTRL_MASK)));
00354        menutool.add(MenuItem(translation.getProperty("Template_Tool"),KeyEvent.VK_T,toolIcons[TOOL_TEMPLATE],KeyStroke.getKeyStroke('T',InputEvent.CTRL_MASK)));
00355        menutool.add(MenuItem(translation.getProperty("Select_Template"),KeyEvent.VK_T,toolIcons[TOOL_TEMPLATE],KeyStroke.getKeyStroke('T',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00356        JMenu menuhydr=new JMenu(translation.getProperty("Hydrogen"));
00357        menuhydr.setMnemonic(KeyEvent.VK_Y);
00358        chkShowHydr=new JCheckBoxMenuItem(translation.getProperty("Show_Hydrogen"));
00359        chkShowHydr.setMnemonic(KeyEvent.VK_Y);
00360        chkShowHydr.setSelected(true);
00361        chkShowHydr.addActionListener(this);
00362        menuhydr.add(chkShowHydr);
00363        menuhydr.add(MenuItem(translation.getProperty("Set_Explicit"),KeyEvent.VK_E));
00364        menuhydr.add(MenuItem(translation.getProperty("Clear_Explicit"),KeyEvent.VK_X));
00365        menuhydr.add(MenuItem(translation.getProperty("Zero_Explicit"),KeyEvent.VK_Z));
00366        menuhydr.add(MenuItem(translation.getProperty("Create_Actual"),KeyEvent.VK_C));
00367        menuhydr.add(MenuItem(translation.getProperty("Delete_Actual"),KeyEvent.VK_D));
00368 
00369        JMenu menuster=new JMenu(translation.getProperty("Stereochemistry"));
00370        menuster.setMnemonic(KeyEvent.VK_S);
00371        chkShowSter=new JCheckBoxMenuItem(translation.getProperty("Show_Stereolabels"));
00372        chkShowSter.setMnemonic(KeyEvent.VK_L);
00373        chkShowSter.setSelected(false);
00374        chkShowSter.addActionListener(this);
00375        menuster.add(chkShowSter);
00376        menuster.add(MenuItem(translation.getProperty("Invert_Stereochemistry"),KeyEvent.VK_I));
00377        menuster.add(MenuItem(translation.getProperty("Set_RZ"),KeyEvent.VK_R));
00378        menuster.add(MenuItem(translation.getProperty("Set_SE"),KeyEvent.VK_S));
00379        menuster.add(MenuItem(translation.getProperty("Cycle_Wedges"),KeyEvent.VK_C));
00380        menuster.add(MenuItem(translation.getProperty("Remove_Wedges"),KeyEvent.VK_W));
00381 
00382        JMenu menuhelp=new JMenu(translation.getProperty("Help"));
00383        menuhelp.setMnemonic(KeyEvent.VK_H);
00384        menuhelp.add(MenuItem(translation.getProperty("About"),KeyEvent.VK_A));
00385 
00386        menubar.add(menufile);
00387        menubar.add(menuedit);
00388        menubar.add(menuview);
00389        menubar.add(menutool);
00390        menubar.add(menuhydr);
00391        menubar.add(menuster);
00392        menubar.add(Box.createHorizontalGlue());
00393        menubar.add(menuhelp);
00394        
00395        return menubar;
00396     }    
00397 
00399     // builds and returns a menu bar suitable for the applet-style invocation
00400     
00401    // menus={"MENU_BLOCK","MENU_SELECT","MENU_TRANSFORM","MENU_ZOOM","MENU_SHOW","MENU_HYDROGEN","MENU_STEREO","MENU_HELP"};
00402     public JMenuBar MenuBarApplet(){
00403        JMenuBar menubar=new JMenuBar();
00404        if(selected_menus[0]){
00405            AppletMenu menublock=new AppletMenu(translation.getProperty("Block"));
00406            menublock.setMnemonic(KeyEvent.VK_B);
00407            menublock.add(MenuItem(translation.getProperty("New"),KeyEvent.VK_N,null,KeyStroke.getKeyStroke('N',InputEvent.CTRL_MASK)));
00408            menublock.add(MenuItem(translation.getProperty("Editttt"),KeyEvent.VK_E,null,KeyStroke.getKeyStroke(' ',InputEvent.CTRL_MASK)));
00409            menublock.add(MenuItem(translation.getProperty("Undo"),KeyEvent.VK_U,null,KeyStroke.getKeyStroke('Z',InputEvent.CTRL_MASK)));
00410            menublock.add(MenuItem(translation.getProperty("Redo"),KeyEvent.VK_R,null,KeyStroke.getKeyStroke('Z',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00411            menublock.add(MenuItem(translation.getProperty("Cut"),KeyEvent.VK_X,null,KeyStroke.getKeyStroke('X',InputEvent.CTRL_MASK)));
00412            menublock.add(MenuItem(translation.getProperty("Copy"),KeyEvent.VK_C,null,KeyStroke.getKeyStroke('C',InputEvent.CTRL_MASK)));
00413            menublock.add(MenuItem(translation.getProperty("Paste"),KeyEvent.VK_V,null,KeyStroke.getKeyStroke('V',InputEvent.CTRL_MASK)));
00414            
00415            menubar.add(menublock);
00416        }
00417        if(selected_menus[1]){
00418            AppletMenu menuselect=new AppletMenu(translation.getProperty("Select"));
00419            menuselect.setMnemonic(KeyEvent.VK_S);
00420            menuselect.add(MenuItem(translation.getProperty("Select_All"),KeyEvent.VK_S,null,KeyStroke.getKeyStroke('A',InputEvent.CTRL_MASK)));
00421            menuselect.add(MenuItem(translation.getProperty("Next_Atom"),KeyEvent.VK_N,null,KeyStroke.getKeyStroke('E',InputEvent.CTRL_MASK)));
00422            menuselect.add(MenuItem(translation.getProperty("Previous_Atom"),KeyEvent.VK_P,null,KeyStroke.getKeyStroke('E',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00423            menuselect.add(MenuItem(translation.getProperty("Next_Group"),KeyEvent.VK_G,null,KeyStroke.getKeyStroke('G',InputEvent.CTRL_MASK)));
00424            menuselect.add(MenuItem(translation.getProperty("Previous_Group"),KeyEvent.VK_R,null,KeyStroke.getKeyStroke('G',InputEvent.CTRL_MASK+InputEvent.SHIFT_MASK)));
00425     
00426            menubar.add(menuselect);
00427        }
00428        
00429        
00430        if(selected_menus[2]){
00431            AppletMenu menutransform=new AppletMenu(translation.getProperty("Transform"));
00432            menutransform.setMnemonic(KeyEvent.VK_T);
00433            menutransform.add(MenuItem(translation.getProperty("Flip_Horizontal"),KeyEvent.VK_H,null,null));
00434            menutransform.add(MenuItem(translation.getProperty("Flip_Vertical"),KeyEvent.VK_V,null,null));
00435            menutransform.add(MenuItem(translation.getProperty("Rotate_P45"),KeyEvent.VK_4,null,null));
00436            menutransform.add(MenuItem(translation.getProperty("Rotate_M45"),KeyEvent.VK_5,null,null));
00437            menutransform.add(MenuItem(translation.getProperty("Rotate_P90"),KeyEvent.VK_9,null,null));
00438            menutransform.add(MenuItem(translation.getProperty("Rotate_M90"),KeyEvent.VK_0,null,null));
00439            menutransform.addSeparator();
00440            menutransform.add(MenuItem(translation.getProperty("Add_Temporary_Template"),KeyEvent.VK_T,null,null));
00441            menutransform.add(MenuItem(translation.getProperty("Normalise_Bond_Lengths"),KeyEvent.VK_N,null,null));
00442        menubar.add(menutransform);
00443        }
00444 
00445        if(selected_menus[3]){
00446            AppletMenu menuzoom=new AppletMenu(translation.getProperty("Zoom"));
00447            menuzoom.setMnemonic(KeyEvent.VK_Z);
00448            menuzoom.add(MenuItem(translation.getProperty("Zoom_Full"),KeyEvent.VK_F,null,KeyStroke.getKeyStroke('0',InputEvent.CTRL_MASK)));
00449            menuzoom.add(MenuItem(translation.getProperty("Zoom_In"),KeyEvent.VK_I,null,KeyStroke.getKeyStroke('=',InputEvent.CTRL_MASK)));
00450            menuzoom.add(MenuItem(translation.getProperty("Zoom_Out"),KeyEvent.VK_O,null,KeyStroke.getKeyStroke('-',InputEvent.CTRL_MASK)));
00451            menubar.add(menuzoom);
00452        }
00453 
00454        if(selected_menus[4]){      
00455            AppletMenu menushow=new AppletMenu(translation.getProperty("Show"));
00456            menushow.setMnemonic(KeyEvent.VK_O);
00457            ButtonGroup showBG=new ButtonGroup();
00458 //         if(viewC){
00459               menushow.add(RadioMenuItem(translation.getProperty("Show_Elements"),KeyEvent.VK_E,true,showBG));
00460               menushow.add(RadioMenuItem(translation.getProperty("Show_All_Elements"),KeyEvent.VK_A,false,showBG));
00461 //         }
00462            menushow.add(RadioMenuItem(translation.getProperty("Show_Indices"),KeyEvent.VK_I,false,showBG));
00463            menushow.add(RadioMenuItem(translation.getProperty("Show_Ring_ID"),KeyEvent.VK_R,false,showBG));
00464            menushow.add(RadioMenuItem(translation.getProperty("Show_CIP_Priority"),KeyEvent.VK_C,false,showBG));
00465            menushow.add(RadioMenuItem(translation.getProperty("Show_Mapping_Number"),KeyEvent.VK_M,false,showBG));
00466            menubar.add(menushow);
00467        }
00468 
00469        if(selected_menus[5]){      
00470            AppletMenu menuhydrogen=new AppletMenu(translation.getProperty("Hydrogen"));
00471            menuhydrogen.setMnemonic(KeyEvent.VK_H);
00472            // jm.evers : do not show checkbox in appletparam "viewH" is "no
00473            if(viewH){
00474               chkShowHydr=new JCheckBoxMenuItem(translation.getProperty("Show_Hydrogen"));
00475                chkShowHydr.setMnemonic(KeyEvent.VK_Y);
00476               chkShowHydr.setSelected(true);
00477                chkShowHydr.addActionListener(this);
00478               menuhydrogen.add(chkShowHydr);
00479            }
00480            menuhydrogen.add(MenuItem(translation.getProperty("Set_Explicit"),KeyEvent.VK_E));
00481            menuhydrogen.add(MenuItem(translation.getProperty("Clear_Explicit"),KeyEvent.VK_X));
00482            menuhydrogen.add(MenuItem(translation.getProperty("Zero_Explicit"),KeyEvent.VK_Z));
00483            menuhydrogen.add(MenuItem(translation.getProperty("Create_Actual"),KeyEvent.VK_C));
00484            menuhydrogen.add(MenuItem(translation.getProperty("Delete_Actual"),KeyEvent.VK_D));
00485        
00486            menubar.add(menuhydrogen);
00487        }
00488        
00489        if(selected_menus[6]){
00490            AppletMenu menustereo=new AppletMenu(translation.getProperty("Stereo"));
00491            menustereo.setMnemonic(KeyEvent.VK_E);
00492            chkShowSter=new JCheckBoxMenuItem(translation.getProperty("Show_Stereolabels"));
00493            chkShowSter.setMnemonic(KeyEvent.VK_L);
00494            chkShowSter.setSelected(false);
00495            chkShowSter.addActionListener(this);
00496            menustereo.add(chkShowSter);
00497            menustereo.add(MenuItem(translation.getProperty("Invert_Stereochemistry"),KeyEvent.VK_I));
00498            menustereo.add(MenuItem(translation.getProperty("Set_RZ"),KeyEvent.VK_R));
00499            menustereo.add(MenuItem(translation.getProperty("Set_SE"),KeyEvent.VK_S));
00500            menustereo.add(MenuItem(translation.getProperty("Cycle_Wedges"),KeyEvent.VK_C));
00501            menustereo.add(MenuItem(translation.getProperty("Remove_Wedges"),KeyEvent.VK_W));
00502        
00503            menubar.add(menustereo);
00504        }
00505 
00506        if(selected_menus[7]){
00507            AppletMenu menuhelp=new AppletMenu(translation.getProperty("Help"));
00508            menuhelp.setMnemonic(KeyEvent.VK_P);
00509            menuhelp.add(MenuItem(translation.getProperty("About"),KeyEvent.VK_A));
00510        
00511            menubar.add(menuhelp);
00512        }
00513        
00514        return menubar;
00515     }
00516     
00517     
00518     public Molecule MolData() {return editor.MolData();} // shallow copy, use with care
00519     public void SetMolecule(Molecule Mol) 
00520     {
00521        editor.Replace(Mol);
00522        editor.ScaleToFit();
00523        editor.NotifySaved();
00524     }
00525     public void AddMolecule(Molecule Mol) 
00526     {
00527        editor.AddArbitraryFragment(Mol);
00528        editor.ScaleToFit();
00529        editor.NotifySaved();
00530     }
00531     public void ScaleToFit() {editor.ScaleToFit();}
00532     
00533     JMenuItem MenuItem(String txt,int key) {return MenuItem(txt,key,null,null);}
00534     JMenuItem MenuItem(String txt,int key,Icon icon) {return MenuItem(txt,key,icon,null);}
00535     JMenuItem MenuItem(String txt,int key,Icon icon,KeyStroke accel)
00536     {
00537        JMenuItem mi=new JMenuItem(txt,key);
00538        mi.addActionListener(this);
00539        if (icon!=null) mi.setIcon(icon);
00540        if (accel!=null) mi.setAccelerator(accel);
00541        return mi;
00542     }
00543     JRadioButtonMenuItem RadioMenuItem(String txt,int key,boolean sel,ButtonGroup bg)
00544     {
00545        JRadioButtonMenuItem mi=new JRadioButtonMenuItem(txt,sel);
00546        mi.addActionListener(this);
00547        mi.setMnemonic(key);
00548        bg.add(mi);
00549        return mi;
00550     }
00551     
00552     void FileQuit()
00553     {
00554        if (!streamMode)
00555        {
00556            if (editor.IsDirty())
00557            {
00558               String opt[]={"Yes","No"};
00559               if (JOptionPane.showOptionDialog(null,translation.getProperty("Current_structure_has_been_modified"),translation.getProperty("Quit"),
00560                      JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00561            }
00562        }
00563        else
00564        {
00565            WriteStream();
00566        }
00567 
00568        if (frameParent!=null) frameParent.dispose(); 
00569 
00570        return;
00571     }
00572     void FileNew()
00573     {
00574        if (editor.MolData().NumAtoms()>0)
00575        {
00576            String opt[]={translation.getProperty("Yes"),translation.getProperty("No")};
00577            if (JOptionPane.showOptionDialog(null,translation.getProperty("Clear_current_structure_and_start_anew"),translation.getProperty("New"),
00578                   JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00579        }
00580        editor.Clear();
00581        filename=null;
00582        if (frameParent!=null) frameParent.setTitle("WIMSchem");
00583        editor.NotifySaved();
00584     }
00585     void FileNewWindow()
00586     {
00587        MainWindow mw=new MainWindow(null,false,translation);
00588        mw.setVisible(true);
00589     }
00590     void FileNewDataSheet()
00591     {
00592        DataWindow dw=new DataWindow(null);
00593        dw.setVisible(true);
00594     }
00595     void FileOpen()
00596     {
00597        JFileChooser chooser=new JFileChooser(System.getenv().get("PWD"));
00598        chooser.setDragEnabled(false);
00599        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
00600        chooser.setFileFilter(new FileExtFilter(translation.getProperty("Molecular_Structures"),".el;.mol;.sdf;*.xml"));
00601        chooser.setAccessory(new FileMolPreview(chooser));
00602        if (chooser.showOpenDialog(frameParent)!=JFileChooser.APPROVE_OPTION) return;
00603        
00604        boolean fresh=editor.IsEmpty();
00605        String newfn=chooser.getSelectedFile().getPath();
00606        boolean anything=editor.MolData().NumAtoms()>0;
00607        try
00608        {
00609            FileInputStream istr=new FileInputStream(newfn);
00610            if (!DataWindow.ALLOW && MoleculeStream.ExamineIsDatabase(istr)) 
00611            {  // !! this section is to be deprecated when DataSheet is fully functional
00612               istr.close();
00613               CatalogWindow cw=new CatalogWindow(newfn);
00614               cw.setVisible(true);
00615            }
00616            else if (DataSheetStream.ExamineIsXMLDS(istr) || DataSheetStream.ExamineIsMDLSDF(istr))
00617            {
00618               istr.close();
00619               DataWindow dw=new DataWindow(newfn);
00620               dw.setVisible(true);
00621            }
00622            else
00623            {
00624               Molecule frag=MoleculeStream.ReadUnknown(istr);
00625               editor.AddArbitraryFragment(frag);
00626               istr.close();
00627               if (fresh) SetFilename(newfn);
00628               if (!anything) editor.NotifySaved();
00629            }
00630        }
00631        catch (IOException e) 
00632        {
00633            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Open_Failed"),JOptionPane.ERROR_MESSAGE);
00634            //e.printStackTrace();
00635            return;
00636        }
00637     }
00638     
00639     void FileSave()
00640     {
00641        if (filename==null) {FileSaveAs(); return;}
00642        SaveCurrent();
00643     }
00644     
00645     void FileSaveAs()
00646     {
00647        JFileChooser chooser=new JFileChooser(System.getenv().get("PWD"));
00648        chooser.setDragEnabled(false);
00649        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
00650        chooser.setFileFilter(new FileExtFilter(translation.getProperty("WIMSchem_Files"),".el"));
00651        chooser.setAccessory(new FileMolPreview(chooser));
00652        if (chooser.showSaveDialog(frameParent)!=JFileChooser.APPROVE_OPTION) return;
00653     
00654        String fn=chooser.getSelectedFile().getPath();
00655        if (chooser.getSelectedFile().getName().indexOf('.')<0) fn=fn+".el";
00656     
00657        File newf=new File(fn);
00658        if (newf.exists())
00659        {
00660            String opt[]={translation.getProperty("Yes"),translation.getProperty("No")};
00661            if (JOptionPane.showOptionDialog(null,translation.getProperty("Overwrite_existing_file")+" ["+newf.getName()+"]?",translation.getProperty("Save_As"),
00662                   JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00663        }      
00664     
00665        SetFilename(fn);
00666        SaveCurrent();
00667     }
00668     
00669     void FileExportNative2JavaScript(){
00670        // jm.evers :test with export to more convinient wims usage...? make a Native Javascript string
00671        JFileChooser chooser=new JFileChooser(System.getenv().get("PWD"));
00672        chooser.setDragEnabled(false);
00673        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
00674        if (chooser.showSaveDialog(frameParent)!=JFileChooser.APPROVE_OPTION) return;
00675 
00676        String fn=chooser.getSelectedFile().getPath();
00677 
00678        File newf=new File(fn);
00679        if (newf.exists())
00680        {
00681            String opt[]={translation.getProperty("Yes"),translation.getProperty("No")};
00682            if (JOptionPane.showOptionDialog(null,translation.getProperty("Overwrite_existing_file")+" ["+newf.getName()+"]?",translation.getProperty("Export_MDL_MOL"),
00683                   JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00684        }      
00685 
00686        try
00687        {
00688            FileOutputStream ostr=new FileOutputStream(fn);
00689            MoleculeStream.WriteNative2JavaScript(ostr,editor.MolData());
00690            ostr.close();
00691        }
00692        catch (IOException e)
00693        {
00694            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Export_Failed"),JOptionPane.ERROR_MESSAGE);
00695        }
00696     }
00697     
00698     void FileExportMDLMol2JavaScript(){
00699        // jm.evers :test with export to more convinient wims usage...? make a MDLMol Javascript string
00700        JFileChooser chooser=new JFileChooser(System.getenv().get("PWD"));
00701        chooser.setDragEnabled(false);
00702        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
00703        if (chooser.showSaveDialog(frameParent)!=JFileChooser.APPROVE_OPTION) return;
00704 
00705        String fn=chooser.getSelectedFile().getPath();
00706 
00707        File newf=new File(fn);
00708        if (newf.exists())
00709        {
00710            String opt[]={translation.getProperty("Yes"),translation.getProperty("No")};
00711            if (JOptionPane.showOptionDialog(null,translation.getProperty("Overwrite_existing_file")+" ["+newf.getName()+"]?",translation.getProperty("Export_MDL_MOL"),
00712                   JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00713        }      
00714 
00715        try
00716        {
00717            FileOutputStream ostr=new FileOutputStream(fn);
00718            MoleculeStream.WriteMDLMol2JavaScript(ostr,editor.MolData());
00719            ostr.close();
00720        }
00721        catch (IOException e)
00722        {
00723            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Export_Failed"),JOptionPane.ERROR_MESSAGE);
00724        }
00725     }
00726     
00727 
00728 
00729     void FileExportMDLMOL(){
00730        JFileChooser chooser=new JFileChooser(System.getenv().get("PWD"));
00731        chooser.setDragEnabled(false);
00732        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
00733        chooser.setFileFilter(new FileExtFilter(translation.getProperty("MDL_MOL_Files"),".mol"));
00734        chooser.setAccessory(new FileMolPreview(chooser));
00735        if (chooser.showSaveDialog(frameParent)!=JFileChooser.APPROVE_OPTION) return;
00736 
00737        String fn=chooser.getSelectedFile().getPath();
00738        if (chooser.getSelectedFile().getName().indexOf('.')<0) fn=fn+".mol";
00739 
00740        File newf=new File(fn);
00741        if (newf.exists())
00742        {
00743            String opt[]={translation.getProperty("Yes"),translation.getProperty("No")};
00744            if (JOptionPane.showOptionDialog(null,translation.getProperty("Overwrite_existing_file")+" ["+newf.getName()+"]?",translation.getProperty("Export_MDL_MOL"),
00745                   JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00746        }      
00747 
00748        try
00749        {
00750            FileOutputStream ostr=new FileOutputStream(fn);
00751            MoleculeStream.WriteMDLMOL(ostr,editor.MolData());
00752            ostr.close();
00753        }
00754        catch (IOException e)
00755        {
00756            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Export_Failed"),JOptionPane.ERROR_MESSAGE);
00757        }
00758     }
00759 
00760     void FileExportCMLXML(){
00761        JFileChooser chooser=new JFileChooser(System.getenv().get("PWD"));
00762        chooser.setDragEnabled(false);
00763        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
00764        chooser.setFileFilter(new FileExtFilter(translation.getProperty("XML_Files"),".xml"));
00765        chooser.setAccessory(new FileMolPreview(chooser));
00766        if (chooser.showSaveDialog(frameParent)!=JFileChooser.APPROVE_OPTION) return;
00767 
00768        String fn=chooser.getSelectedFile().getPath();
00769        if (chooser.getSelectedFile().getName().indexOf('.')<0) fn=fn+".xml";
00770 
00771        File newf=new File(fn);
00772        if (newf.exists())
00773        {
00774            String opt[]={translation.getProperty("Yes"),translation.getProperty("No")};
00775            if (JOptionPane.showOptionDialog(null,translation.getProperty("Overwrite_existing_file")+" ["+newf.getName()+"]?",translation.getProperty("Export_CML_XML"),
00776                   JOptionPane.YES_NO_OPTION,JOptionPane.YES_NO_OPTION,null,opt,opt[0])!=JOptionPane.YES_OPTION) return;
00777        }      
00778 
00779        try
00780        {
00781            FileOutputStream ostr=new FileOutputStream(fn);
00782            MoleculeStream.WriteCMLXML(ostr,editor.MolData());
00783            ostr.close();
00784        }
00785        catch (IOException e)
00786        {
00787            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Export_Failed"),JOptionPane.ERROR_MESSAGE);
00788        }
00789     }
00790 
00791 
00792     void SetFilename(String fn){
00793        if (fn.length()==0) {filename=null; return;}
00794        filename=fn;
00795        
00796        if (!streamMode)
00797        {
00798           String chopfn=fn;
00799           int i=chopfn.lastIndexOf("/");
00800           if (i>=0) chopfn=chopfn.substring(i+1);
00801            if (frameParent!=null) frameParent.setTitle(chopfn+" - WIMSchem");
00802        } 
00803        else {if (frameParent!=null) frameParent.setTitle("WIMSchem");}
00804     }
00805     
00806     void SaveCurrent(){
00807        try
00808        {
00809            FileOutputStream ostr=new FileOutputStream(filename);
00810            MoleculeStream.WriteNative(ostr,editor.MolData());
00811            ostr.close();
00812            editor.NotifySaved();
00813        }
00814        catch (IOException e)
00815        {
00816            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Save_Failed"),JOptionPane.ERROR_MESSAGE);
00817        }
00818     }
00819     
00820     void ReadStream(){
00821        try
00822        {
00823            Molecule frag=MoleculeStream.ReadUnknown(System.in);
00824            editor.AddArbitraryFragment(frag);
00825        }
00826        catch (IOException e) 
00827        {
00828            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("stdin_Read_Failed"),JOptionPane.ERROR_MESSAGE);
00829            return;
00830        }
00831     }
00832     void WriteStream(){
00833        Molecule mol=editor.MolData();
00834        try
00835        {
00836            MoleculeStream.WriteMDLMOL(System.out,mol);
00837            MoleculeStream.WriteNative(System.out,mol);
00838        }
00839        catch (IOException e) 
00840        {
00841            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("stdout_Write_Failed"),JOptionPane.ERROR_MESSAGE);
00842        }
00843     }
00844     
00845     void TestMol(){
00846        Molecule mol=new Molecule();
00847        
00848        mol.AddAtom("N",0,0);
00849        mol.AddAtom("C",1.2,0);
00850        mol.AddAtom("O",2,0.8);
00851        mol.AddAtom("H",3,-0.8);
00852        mol.AddAtom("H",4,0);
00853        mol.AddBond(1,2,1);
00854        mol.AddBond(2,3,2);
00855        mol.AddBond(3,4,1);
00856        mol.AddBond(4,5,0);
00857        
00858        editor.Replace(mol);
00859     } 
00860     
00861     void EditCut(){
00862        Molecule frag=editor.SelectedSubgraph();
00863        try
00864        {
00865            StringWriter sw=new StringWriter();
00866            BufferedWriter bw=new BufferedWriter(sw);
00867            MoleculeStream.WriteMDLMOL(bw,frag);
00868            MoleculeStream.WriteNative(bw,frag);
00869            if (useLocalClipboard)
00870            {
00871               appletClipboard=sw.toString();
00872            }
00873            else
00874            {
00875               Clipboard clip=Toolkit.getDefaultToolkit().getSystemClipboard();
00876               clip.setContents(new StringSelection(sw.toString()),this);
00877            }
00878            editor.DeleteSelected(); // (keep this within the exception trap)
00879        }
00880        catch (IOException e) 
00881        {
00882            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Cut_Failed"),JOptionPane.ERROR_MESSAGE);
00883        }
00884     }
00885     
00886     void EditCopy(){
00887        Molecule frag=editor.SelectedSubgraph();
00888        try
00889        {
00890            StringWriter sw=new StringWriter();
00891            BufferedWriter bw=new BufferedWriter(sw);
00892            MoleculeStream.WriteMDLMOL(bw,frag);
00893            MoleculeStream.WriteNative(bw,frag);
00894            if (useLocalClipboard)
00895            {
00896               appletClipboard=sw.toString();
00897            }
00898            else
00899            {
00900               Clipboard clip=Toolkit.getDefaultToolkit().getSystemClipboard();
00901               clip.setContents(new StringSelection(sw.toString()),this);
00902            }
00903        }
00904        catch (IOException e) 
00905        {
00906            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Copy_Failed"),JOptionPane.ERROR_MESSAGE);
00907        }
00908     }
00909     
00910     void EditPaste(){
00911        try 
00912        {
00913            String cliptext=null;
00914            if (useLocalClipboard) cliptext=appletClipboard;
00915            else
00916            {
00917               Clipboard clip=Toolkit.getDefaultToolkit().getSystemClipboard();
00918               Transferable contents=clip.getContents(null);
00919               if (contents!=null && contents.isDataFlavorSupported(DataFlavor.stringFlavor))
00920               {
00921                   cliptext=(String)contents.getTransferData(DataFlavor.stringFlavor);
00922               }
00923            }
00924            
00925            if (cliptext!=null)
00926            {
00927               Molecule frag=MoleculeStream.ReadUnknown(new BufferedReader(new StringReader(cliptext)));
00928               if (frag!=null) editor.AddArbitraryFragment(frag);
00929            }
00930        }
00931        catch (UnsupportedFlavorException e) 
00932        {
00933            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Clipboard_Read_Failed"),JOptionPane.ERROR_MESSAGE);
00934        }
00935        catch (IOException e) 
00936        {
00937            JOptionPane.showMessageDialog(null,e.toString(),translation.getProperty("Paste_Failed"),JOptionPane.ERROR_MESSAGE);
00938        }
00939     }
00940 
00941     void SelectElement(String El){
00942        if (lastElement!=null) 
00943        {
00944            if (lastElement.compareTo(El)==0) return;
00945            toolIcons[TOOL_SETATOM]=new ImageIcon(getClass().getResource("/images/"+IMAGE_TOOL[TOOL_SETATOM]+".png"));
00946        }
00947 
00948        int w=toolIcons[TOOL_SETATOM].getImage().getWidth(null),h=toolIcons[TOOL_SETATOM].getImage().getHeight(null);
00949        BufferedImage img=new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
00950        Graphics2D g=(Graphics2D)img.getGraphics();
00951        g.setColor(new Color(0x00000000,true));
00952        g.fillRect(0,0,w,h);
00953        g.drawImage(toolIcons[TOOL_SETATOM].getImage(),0,0,null);
00954        
00955        Font font=new Font("SansSerif",Font.PLAIN,El.length()==1 ? 20 : 14);
00956        g.setFont(font);
00957        g.setColor(new Color(0,192,0));
00958        FontMetrics metrics=g.getFontMetrics();
00959        g.drawString(El,(w-metrics.stringWidth(El))/2-3,(h+metrics.getAscent())/2-2);
00960        
00961        toolButtons[TOOL_SETATOM].setIcon(new ImageIcon(img));
00962        
00963        lastElement=El;
00964     }
00965     
00966     void TemplateTool(){
00967        if (lastTemplate==null) {TemplateSelect(); return;}
00968        editor.SetToolTemplate(lastTemplate,templateIdx);
00969     }
00970     
00971     void TemplateSelect(){
00972        int heightFudge=appletMode ? 30 : 0; // !! unpleasant hack which stands in for being a non-signed applet; correct at some point
00973        TemplateSelector sel=new TemplateSelector(templ,this,heightFudge);
00974        Point pos=toolButtons[TOOL_TEMPLATE].getLocationOnScreen();
00975 
00976        Dimension ssz=Toolkit.getDefaultToolkit().getScreenSize();
00977        GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
00978        GraphicsConfiguration gc=ge.getScreenDevices()[0].getConfigurations()[0];
00979        ssz.width-=Toolkit.getDefaultToolkit().getScreenInsets(gc).right;
00980        ssz.height-=Toolkit.getDefaultToolkit().getScreenInsets(gc).bottom;
00981               
00982        if (pos.x+sel.getWidth()>ssz.width) pos.x=ssz.width-sel.getWidth();
00983        if (pos.y+sel.getHeight()>ssz.height) pos.y=ssz.height-sel.getHeight();
00984        sel.setLocation(pos);
00985        sel.setVisible(true);
00986     }
00987     
00988     void TemplateAddTo(){
00989        templ.AddTemplate(editor.SelectedSubgraph());
00990     }
00991     
00992     void EditDialog(){
00993        Molecule newMol=(new DialogEdit(frameParent,editor.MolData(),editor.SelectedIndices())).exec();
00994        if (newMol!=null) 
00995        {
00996            editor.CacheUndo();
00997            editor.Replace(newMol,false);
00998        }
00999     }
01000     
01001     void HelpAbout()
01002     {
01003        String msg="        WIMSchem v"+VERSION+"           \n"+
01004                  "                                        \n"+
01005                  "   Molecule drawing tool for WIMS       \n"+
01006                  "   [ the Interactive Education Server ] \n"+
01007                  "   http://wims.unice.fr/wims/wims.cgi?  \n"+
01008                  "   A slightly modified version of:      \n"+
01009                  "                                        \n"+
01010                  "      SketchEl  version1.19             \n"+
01011                  "    2005-2008 Dr. Alex M. Clark        \n"+
01012                  "   Released under the Gnu Public        \n"+
01013                  "   License (GPL), see www.gnu.org       \n"+
01014                  "   Home page and documentation:         \n"+
01015                  "   http://sketchel.sf.net               \n";
01016        JOptionPane.showMessageDialog(null,msg,translation.getProperty("About_WIMSchem"),JOptionPane.INFORMATION_MESSAGE,mainLogo);
01017     }
01018     
01019     // ------------------ event functions --------------------
01020 
01021     public void actionPerformed(ActionEvent e) 
01022     {
01023        String cmd=e.getActionCommand();
01024        
01025        int setsel=-1;
01026        
01027        if (cmd.equals(translation.getProperty("Quit")) || cmd.equals(translation.getProperty("Save_and_Quit"))) FileQuit();
01028        else if (cmd.equals(translation.getProperty("New"))) FileNew();
01029        else if (cmd.equals(translation.getProperty("New_Window"))) FileNewWindow();
01030        else if (cmd.equals(translation.getProperty("New_DataSheet"))) FileNewDataSheet();
01031        else if (cmd.equals(translation.getProperty("Open"))) FileOpen();
01032        else if (cmd.equals(translation.getProperty("Save"))) FileSave();
01033        else if (cmd.equals(translation.getProperty("Save_As"))) FileSaveAs();
01034        else if (cmd.equals(translation.getProperty("as_MDL_MOL"))) FileExportMDLMOL();
01035        else if (cmd.equals(translation.getProperty("as_CML_XML"))) FileExportCMLXML();
01036        else if (cmd.equals("Native2Javascript (wims)")) FileExportNative2JavaScript();
01037        else if (cmd.equals("MDLMol2Javascript (wims)")) FileExportMDLMol2JavaScript();
01038        else if (cmd.equals(translation.getProperty("Cursor")) || e.getSource()==toolButtons[TOOL_CURSOR]) {editor.SetToolCursor(); setsel=TOOL_CURSOR;}
01039        else if (cmd.equals(translation.getProperty("Rotator")) || e.getSource()==toolButtons[TOOL_ROTATOR]) {editor.SetToolRotator(); setsel=TOOL_ROTATOR;}
01040        else if (cmd.equals(translation.getProperty("Erasor")) || e.getSource()==toolButtons[TOOL_ERASOR]) {editor.SetToolErasor(); setsel=TOOL_ERASOR;}
01041        else if (cmd.equals(translation.getProperty("Editttt")) || e.getSource()==toolButtons[TOOL_DIALOG]) EditDialog();
01042        else if (cmd.equals(translation.getProperty("Select_All"))) editor.SelectAll();
01043        else if (cmd.equals(translation.getProperty("Next_Atom"))) editor.CycleSelection(true,false);
01044        else if (cmd.equals(translation.getProperty("Previous_Atom"))) editor.CycleSelection(false,false);
01045        else if (cmd.equals(translation.getProperty("Next_Group"))) editor.CycleSelection(true,true);
01046        else if (cmd.equals(translation.getProperty("Previous_Group"))) editor.CycleSelection(false,true);
01047        else if (cmd.equals(translation.getProperty("Edit_Atom")) || e.getSource()==toolButtons[TOOL_EDIT]) {editor.SetToolAtom(null); setsel=TOOL_EDIT;}
01048        else if (cmd.equals(translation.getProperty("Set_Atom")) || e.getSource()==toolButtons[TOOL_SETATOM]) {editor.SetToolAtom(lastElement); setsel=TOOL_SETATOM;}
01049        else if (cmd.equals(translation.getProperty("Single_Bond")) || e.getSource()==toolButtons[TOOL_SINGLE]) {editor.SetToolBond(1); setsel=TOOL_SINGLE;}
01050        else if (cmd.equals(translation.getProperty("Double_Bond")) || e.getSource()==toolButtons[TOOL_DOUBLE]) {editor.SetToolBond(2); setsel=TOOL_DOUBLE;}
01051        else if (cmd.equals(translation.getProperty("Triple_Bond")) || e.getSource()==toolButtons[TOOL_TRIPLE]) {editor.SetToolBond(3); setsel=TOOL_TRIPLE;}
01052        else if (cmd.equals(translation.getProperty("Zero_Bond")) || e.getSource()==toolButtons[TOOL_ZERO]) {editor.SetToolBond(0); setsel=TOOL_ZERO;}
01053        else if (cmd.equals(translation.getProperty("Inclined_Bond")) || e.getSource()==toolButtons[TOOL_INCLINED]) {editor.SetToolBond(-1); setsel=TOOL_INCLINED;}
01054        else if (cmd.equals(translation.getProperty("Declined_Bond")) || e.getSource()==toolButtons[TOOL_DECLINED]) {editor.SetToolBond(-2); setsel=TOOL_DECLINED;}
01055        else if (cmd.equals(translation.getProperty("Unknown_Bond")) || e.getSource()==toolButtons[TOOL_UNKNOWN]) {editor.SetToolBond(-3); setsel=TOOL_UNKNOWN;}
01056        else if (cmd.equals(translation.getProperty("Charge")) || e.getSource()==toolButtons[TOOL_CHARGE]) {editor.SetToolCharge(1); setsel=TOOL_CHARGE;}
01057        else if (cmd.equals(translation.getProperty("Undo")) || e.getSource()==toolButtons[TOOL_UNDO]) editor.Undo();
01058        else if (cmd.equals(translation.getProperty("Redo")) || e.getSource()==toolButtons[TOOL_REDO]) editor.Redo();
01059        else if (cmd.equals(translation.getProperty("Cut"))) EditCut();
01060        else if (cmd.equals(translation.getProperty("Copy"))) EditCopy();
01061        else if (cmd.equals(translation.getProperty("Paste"))) EditPaste();
01062        else if (cmd.equals(translation.getProperty("Flip_Horizontal"))) editor.FlipSelectedAtoms(false);
01063        else if (cmd.equals(translation.getProperty("Flip_Vertical"))) editor.FlipSelectedAtoms(true);
01064        else if (cmd.equals(translation.getProperty("Rotate_P45"))) editor.RotateSelectedAtoms(45);
01065        else if (cmd.equals(translation.getProperty("Rotate_M45"))) editor.RotateSelectedAtoms(-45);
01066        else if (cmd.equals(translation.getProperty("Rotate_P90"))) editor.RotateSelectedAtoms(90);
01067        else if (cmd.equals(translation.getProperty("Rotate_M90"))) editor.RotateSelectedAtoms(-90);
01068        else if (cmd.equals(translation.getProperty("Add_Temporary_Template"))) TemplateAddTo();
01069        else if (cmd.equals(translation.getProperty("Normalise_Bond_Lengths"))) editor.NormaliseBondLengths();
01070        else if (cmd.equals(translation.getProperty("Template_Tool")) || e.getSource()==toolButtons[TOOL_TEMPLATE]) {TemplateTool(); setsel=TOOL_TEMPLATE;}
01071        else if (cmd.equals(translation.getProperty("Select_Template"))) {TemplateSelect(); setsel=TOOL_TEMPLATE;}
01072        else if (cmd.equals(translation.getProperty("Zoom_Full"))) editor.ZoomFull();
01073        else if (cmd.equals(translation.getProperty("Zoom_In"))) editor.ZoomIn(1.5);
01074        else if (cmd.equals(translation.getProperty("Zoom_Out"))) editor.ZoomOut(1.5);
01075        else if (cmd.equals(translation.getProperty("Show_Elements"))) editor.SetShowMode(DrawMolecule.SHOW_ELEMENTS);
01076        else if (cmd.equals(translation.getProperty("Show_All_Elements"))) editor.SetShowMode(DrawMolecule.SHOW_ALL_ELEMENTS);
01077        else if (cmd.equals(translation.getProperty("Show_Indices"))) editor.SetShowMode(DrawMolecule.SHOW_INDEXES);
01078        else if (cmd.equals(translation.getProperty("Show_Ring_ID"))) editor.SetShowMode(DrawMolecule.SHOW_RINGID);
01079        else if (cmd.equals(translation.getProperty("Show_CIP_Priority"))) editor.SetShowMode(DrawMolecule.SHOW_PRIORITY);
01080        else if (cmd.equals(translation.getProperty("Show_Mapping_Number"))) editor.SetShowMode(DrawMolecule.SHOW_MAPNUM);
01081        else if (cmd.equals(translation.getProperty("Show_Hydrogen"))) editor.SetShowHydrogens(chkShowHydr.isSelected());
01082        else if (cmd.equals(translation.getProperty("Set_Explicit")))  editor.HydrogenSetExplicit(true);
01083        else if (cmd.equals(translation.getProperty("Clear_Explicit"))) editor.HydrogenSetExplicit(false);
01084        else if (cmd.equals(translation.getProperty("Zero_Explicit"))) editor.HydrogenSetExplicit(false,0);
01085        else if (cmd.equals(translation.getProperty("Create_Actual"))) editor.HydrogenCreateActual();
01086        else if (cmd.equals(translation.getProperty("Delete_Actual"))) editor.HydrogenDeleteActual();
01087        else if (cmd.equals(translation.getProperty("Show_Stereolabels"))) editor.SetShowStereolabels(chkShowSter.isSelected());
01088        else if (cmd.equals(translation.getProperty("Invert_Stereochemistry"))) editor.SetStereo(Molecule.STEREO_UNKNOWN);
01089        else if (cmd.equals(translation.getProperty("Set_RZ"))) editor.SetStereo(Molecule.STEREO_POS);
01090        else if (cmd.equals(translation.getProperty("Set_SE"))) editor.SetStereo(Molecule.STEREO_NEG);
01091        else if (cmd.equals(translation.getProperty("Cycle_Wedges"))) editor.CycleChiralWedges();
01092        else if (cmd.equals(translation.getProperty("Remove_Wedges"))) editor.RemoveChiralWedges();
01093        else if (cmd.equals(translation.getProperty("About"))) HelpAbout();
01094        else if (cmd.length()<=2) {SelectElement(cmd); editor.SetToolAtom(lastElement);}
01095        if (setsel!=-1) toolGroup.setSelected(toolButtons[setsel].getModel(),true);
01096     } 
01097     
01098     public void mouseClicked(MouseEvent e) {}
01099     public void mouseEntered(MouseEvent e) {}
01100     public void mouseExited(MouseEvent e) {}
01101     public void mousePressed(MouseEvent e){
01102        // jm.evers : setting atoms menulist according applet-params...or not
01103        if (e.getSource()==toolButtons[TOOL_SETATOM] && e.getButton()==MouseEvent.BUTTON3)
01104        {
01105            toolButtons[TOOL_SETATOM].setSelected(true);
01106            JPopupMenu popup=new JPopupMenu();
01107            if(my_atoms==null){
01108               popup.add(MenuItem("C",0));
01109                popup.add(MenuItem("H",0));
01110               popup.add(MenuItem("O",0));
01111                popup.add(MenuItem("N",0));
01112                popup.add(MenuItem("S",0));
01113                popup.add(MenuItem("P",0));
01114                popup.add(MenuItem("Li",0));
01115                popup.add(MenuItem("Na",0));
01116                popup.add(MenuItem("K",0));
01117                popup.add(MenuItem("Mg",0));
01118                popup.add(MenuItem("Ca",0));
01119               popup.add(MenuItem("Ti",0));
01120                popup.add(MenuItem("Zr",0));
01121                popup.add(MenuItem("Cr",0));
01122                popup.add(MenuItem("Mo",0));
01123                popup.add(MenuItem("Mn",0));
01124                popup.add(MenuItem("Fe",0));
01125                popup.add(MenuItem("Cu",0));
01126                popup.add(MenuItem("Zn",0));
01127                popup.add(MenuItem("Ag",0));
01128                popup.add(MenuItem("Hg",0));
01129                popup.add(MenuItem("Al",0));
01130                popup.add(MenuItem("Si",0));
01131                popup.add(MenuItem("F",0));
01132                popup.add(MenuItem("Cl",0));
01133                popup.add(MenuItem("Br",0));
01134                popup.add(MenuItem("I",0));
01135            }
01136            else
01137            {
01138               for(int p=0; p<my_atoms.length;p++){
01139                   popup.add(MenuItem(my_atoms[p],0));
01140               }
01141            }
01142            popup.show(toolButtons[TOOL_SETATOM],0,0);
01143        }
01144        if (e.getSource()==toolButtons[TOOL_TEMPLATE] && e.getButton()==MouseEvent.BUTTON3) 
01145        {
01146            toolGroup.setSelected(toolButtons[TOOL_TEMPLATE].getModel(),true);
01147            TemplateSelect();
01148        }
01149     }
01150     public void mouseReleased(MouseEvent e) {}   
01151     public void keyPressed(KeyEvent e) 
01152     {
01153        // keyboard arrow-nudges
01154        if (!e.isAltDown() && !e.isShiftDown() && !e.isControlDown() && !e.isMetaDown())
01155        {
01156            if (e.getKeyCode()==KeyEvent.VK_UP) {editor.NudgeSelectedAtoms(0,0.05); return;}
01157            if (e.getKeyCode()==KeyEvent.VK_DOWN) {editor.NudgeSelectedAtoms(0,-0.05); return;}
01158            if (e.getKeyCode()==KeyEvent.VK_LEFT) {editor.NudgeSelectedAtoms(-0.05,0); return;}
01159            if (e.getKeyCode()==KeyEvent.VK_RIGHT) {editor.NudgeSelectedAtoms(0.05,0); return;}
01160        }
01161     }
01162     public void keyReleased(KeyEvent e) {}
01163     public void keyTyped(KeyEvent e)
01164     {    
01165        // user typing in an element...
01166        char ch=e.getKeyChar();
01167        if (ch>='A' && ch<='Z') typedElement=""+ch;
01168        else if (typedElement.length()==1 && ch>='a' && ch<='z') typedElement=typedElement+ch;
01169        else if (typedElement.compareTo("R")==0 && ch>='0' && ch<='9') typedElement=typedElement+ch;
01170        else {typedElement=""; return;}
01171 
01172        String elset=null;
01173        if (typedElement.length()>=2 && typedElement.charAt(0)=='R' && typedElement.charAt(1)>='0' && typedElement.charAt(1)<='9') 
01174        {
01175            elset=typedElement;
01176        }
01177        else
01178        {
01179            for (int n=1;n<Molecule.ELEMENTS.length;n++) if (typedElement.compareTo(Molecule.ELEMENTS[n])==0) {elset=typedElement;}
01180        }
01181        if (elset!=null)
01182        {
01183            SelectElement(elset); 
01184            toolGroup.setSelected(toolButtons[TOOL_SETATOM].getModel(),true);
01185            editor.SetToolAtom(elset);
01186        }
01187     }
01188     
01189     public void TemplSelected(Molecule mol,int idx)
01190     {
01191        lastTemplate=mol;
01192        templateIdx=idx;
01193        editor.SetToolTemplate(mol,idx);
01194     }
01195     public void MolSelected(EditorPane source,int idx,boolean dblclick)
01196     {
01197        if (dblclick && idx!=0)
01198        {
01199            ArrayList<Integer> selidx=new ArrayList<Integer>();
01200            if (idx>0) selidx.add(idx);
01201            else {selidx.add(editor.MolData().BondFrom(-idx)); selidx.add(editor.MolData().BondTo(-idx));}
01202            Molecule newMol=(new DialogEdit(frameParent,editor.MolData(),selidx)).exec();
01203            if (newMol!=null) editor.Replace(newMol);
01204        }
01205     }
01206     public void DirtyChanged(boolean isdirty)
01207     {
01208        String str=frameParent==null ? "WIMSchem" : frameParent.getTitle();
01209        if (str.charAt(0)=='*') str=str.substring(1);
01210        if (isdirty) str="*"+str;
01211        if (frameParent!=null) frameParent.setTitle(str);
01212     }
01213     
01214     public void lostOwnership(Clipboard clipboard,Transferable contents) {} // don't care
01215     
01216     public void windowActivated(WindowEvent e) {}
01217     public void windowClosed(WindowEvent e) {}
01218     public void windowClosing(WindowEvent e) 
01219     {
01220        FileQuit();
01221     }
01222     public void windowDeactivated(WindowEvent e) {}
01223     public void windowDeiconified(WindowEvent e) {}
01224     public void windowIconified(WindowEvent e) {}
01225     public void windowOpened(WindowEvent e) 
01226     {
01227        if (firstResize)
01228        {
01229            editor.ScaleToFit();
01230            editor.repaint();
01231            firstResize=false;
01232        }
01233        editor.requestFocusInWindow();
01234     }
01235 }