⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwin.java

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
              JOptionPane.showMessageDialog( this, about, "About",                                             JOptionPane.INFORMATION_MESSAGE,                                             js_icon );          }          else              JOptionPane.showMessageDialog( this, about, "About",                                             JOptionPane.INFORMATION_MESSAGE );      }      else if (command.equals( "Read" ) ) {          readLogFile();      }  }  //End of event Handler methods----------------------------------------------    private void disableRead()  {      read_btn.setEnabled(false);  }    // private void enableRead () {read_btn.setEnabled (true);}  public void enableRead()  {      read_btn.setEnabled(true);  }    /**   * selects the log file to be read   *///Bug: Method setCurrentDirectory of JFileChooser does not work completely.//     So, method rescanCurrentDirectory has to be called also to get the //     desired effect. We want the JFileChooser dialog to open up with a //     listing of files of the directory from which Jumpshot was executed  private void selectFile ()   {    if ( !isApplet ) { //Application - Read file from machine's memory        openAppFileDlg = new JFileChooser();        if ( openAppFileDlg != null ) {            openAppFileDlg.setDialogTitle( "Select Logfile" );	        File f = new File( (System.getProperties())                               .getProperty( "user.dir" ) );            openAppFileDlg.setCurrentDirectory( f );            openAppFileDlg.rescanCurrentDirectory();        }        else            selectFileMenuItem.setEnabled( false );        int r = openAppFileDlg.showOpenDialog( this );        if ( r == 0 ) {            String file;            File f = openAppFileDlg.getSelectedFile();            if ( f != null )                file = f.toString ();            else                file = null;	            if ( file != null ) {                logFileName = file;                logFileField.setText( logFileName );                readLogFile();            }        }        else            JOptionPane.showMessageDialog( this, "No file chosen" );    }    else { //Applet - Read file from host machine's memory         MainApplet top_applet = (MainApplet) parent;        openApltFileDlg = new ApltFileDlg( top_applet, "Select Logfile" );        openApltFileDlg.show();        if ( openApltFileDlg.getSelected() ) {            String file = openApltFileDlg.getFile();            if ( file != null ) {                logFileField.setText( file );                logFileName = top_applet.GetLogFileDirName() + "/" + file;                String prefix = top_applet.GetLogFilePathPrefix();                if ( prefix != null && prefix.length() > 0 )                    logFileName = prefix + "/" + logFileName ;                top_applet.showStatus( "Mainwin: After openApltFileDlg.show(), "                                     + "logFileName = " + logFileName + ",  "                                     + "file = " + file );                readLogFile();            }        }        else            JOptionPane.showMessageDialog( this, "No file chosen" );    }  }      /**     * reads a log file by creating a FrameReader instance      */    private void readLogFile()    {        // if ( ChkFileExist( logFileName ) ) {        if ( true ) {            // Clean up and free resources            freeMem();            // Spawn new thread, SwingWorker, to read the SLOG file header            readWorker = new SwingWorker()            {                public Object construct()                 {                    MainApplet top_applet;                    String serviceURLname;                    String locationURL;                    waitCursor();                    disableRead();                    reader_alive = true;                    if ( isApplet ) {                        top_applet = (MainApplet) parent;                        serviceURLname = top_applet.GetServiceURLname();                        locationURL    = serviceURLname;                    }                    else {                        serviceURLname = null;                        locationURL = "local filesystem";                    }                    /*                    top_applet.showStatus( "ServiceURLname = "                                         + top_applet.GetServiceURLname() );                    */                    try {                        return ( new SLOG_ProxyInputStream( serviceURLname,                                                            logFileName )                               );                    }                    catch ( NotBoundException err ) {                            new ErrorDialog( startwin,                                             "NotBoundException: ServiceURL = "                                           + serviceURLname );                        return null;                    }                    catch ( FileNotFoundException err ) {                            new ErrorDialog( startwin,                                             "FileNotFoundException: File = "                                           + logFileName + " at "                                           + locationURL );                        return null;                    }                    catch ( IOException err ) {                            new ErrorDialog( startwin,                                             "IOException: Reading file = "                                           + logFileName + " fails at "                                           + locationURL );                        return null;                    }                }                public void finished()                {                    reader_alive = false;                    slog = ( SLOG_ProxyInputStream ) get();                    if ( slog != null ) {                        //  The btn_names[] needs to be synchronized with                        //  SetIndexes() of StateGroupLabel class                         String[] btn_names = { "MPI-Process", "Thread",                                               "Processor" };                        frame_chooser = new ViewFrameChooser( slog, btn_names );                        frame_chooser.SetInitWindow( startwin );                        frame_chooser.pack();                        frame_chooser.setVisible( true );                    }                    normalCursor();                }            };            // Start the readWorker thread after the thread has been created.            // It is done to avoid race condition in SwingWorker2.             readWorker.start();        }    }    private boolean ChkFileExist( String filename )    {        InputStream in;        if ( isApplet ) {            URL url = null;            try { url = new URL( filename ); }            catch ( MalformedURLException e ) {                new ErrorDialog(this, "Mainwin: ChkFileExist(): Bad URL: "                                    + url + ", filename = " + filename );                return false;            }            try { in = url.openStream(); }            catch ( IOException e ) {                new ErrorDialog(this, "IO Error:" + e.getMessage ());                return false;            }        }        else {            try { in = new FileInputStream( filename ); }            catch ( FileNotFoundException e ) {                   new ErrorDialog( this, "file: " + filename + " not found." );                  return false;            }        }        return true;    }  /**   * Destructor   */  private void close ()  {    freeMem();     this.setVisible( false );    parent.setVisible( false );    //    System.runFinalization (); System.gc ();    if (!isChild && !isApplet) System.exit (0);  }    /**   * frees up the memory - reader and display   */  private void freeMem () {    if ( readWorker != null && reader_alive ) {        readWorker.interrupt();        readWorker = null;    }    // if ( disp != null ) disp.kill();    //    System.runFinalization (); System.gc ();    if ( frame_chooser != null ) frame_chooser = null;  }     /**   * sets the current cursor to DEFAULT_CURSOR   */  void normalCursor () {    ROUTINES.makeCursor (this, new Cursor (Cursor.DEFAULT_CURSOR));  }    /**   * sets the current cursor to WAIT_CURSOR   */  void waitCursor () {    ROUTINES.makeCursor (this, new Cursor (Cursor.WAIT_CURSOR));  }      /**   * method reads all the lines of text from the given file. All lines are   * stored in one string separated by '/n's.   */  private String readLines (InputStream file) {    if (file == null) return "";    BufferedReader in = new BufferedReader (new InputStreamReader (file));    String line, text = "";        try {      while ((line = in.readLine ()) != null) text += (line + "\n");      file.close ();    }    catch (IOException x)         {new ErrorDialog (this, "IO Error:" + x.getMessage ());}    return text;  }    private InputStream getFileIn (String name) {    InputStream in = null;        try {in = new FileInputStream (name);}    catch (FileNotFoundException e) {      new ErrorDialog (this, "file: " + name + " not found.");      return null;    }    return in;  }    private InputStream getUrlIn (String name) {    URL url = null;    InputStream in = null;        try {url = new URL (name);}    catch (MalformedURLException e) {      new ErrorDialog (this, "Mainwin: getUrlIn: Bad URL:" + url);      return null;    }       try {in = url.openStream ();}    catch (IOException e) {      new ErrorDialog (this, "IO Error:" + e.getMessage ());      return null;    }    return in;  }        private URL getURL(String filename)    {        URL url = null;        /*        if ( isApplet ) {            URL codeBase = ( (JApplet) parent ).getCodeBase();            try {                url = new URL( codeBase, filename );            } catch ( java.net.MalformedURLException e ) {                System.out.println("badly specified URL");                return null;            }        }        else           url = ClassLoader.getSystemResource( filename );        */        url = getClass().getResource( filename );        return url;    }    void delDisp () {    enableRead ();     //    disp = null;    //    System.runFinalization (); System.gc ();  }    /**   * Switch the between the Windows, Motif, Mac, and the Metal Look and Feel   */  private class ToggleUIListener implements ItemListener {    public void itemStateChanged(ItemEvent e) {      waitCursor ();      JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();      try {	if (   rb.isSelected()            && rb.getText().equals("Windows Style Look and Feel")) {	  UIManager.setLookAndFeel( "com.sun.java.swing.plaf"                                  + ".windows.WindowsLookAndFeel");	  makeUIChanges ();	} 	else if (   rb.isSelected()                 && rb.getText().equals("Macintosh Look and Feel")) {	  UIManager.setLookAndFeel( "com.sun.java.swing.plaf"                                  + ".mac.MacLookAndFeel" );	  makeUIChanges ();	} 	else if(rb.isSelected() && rb.getText().equals("Motif Look and Feel")) {	  UIManager.setLookAndFeel( "com.sun.java.swing.plaf"                                  + ".motif.MotifLookAndFeel" );	  makeUIChanges ();	} 	else if(rb.isSelected() && rb.getText().equals("Metal Look and Feel")) {	  UIManager.setLookAndFeel( "javax.swing.plaf"                                  + ".metal.MetalLookAndFeel" );	  makeUIChanges ();	}       }       catch (UnsupportedLookAndFeelException exc) {	// Error - unsupported L&F	rb.setEnabled(false);	new ErrorDialog (null, "Unsupported LookAndFeel: " + rb.getText()		             + ".\nLoading cross platform look and feel");		// Set L&F to Metal	try {	  metalMenuItem.setSelected(true);	  UIManager.setLookAndFeel( UIManager                                    .getCrossPlatformLookAndFeelClassName() );	  SwingUtilities.updateComponentTreeUI(startwin);	} catch (Exception exc2) {	  new ErrorDialog (null, "Could not load LookAndFeel: " + exc2);	}      }       catch (Exception exc) {	rb.setEnabled(false);	new ErrorDialog (null, "Could not load LookAndFeel: " + rb.getText());      }      normalCursor ();    }  }    private class DispListener implements ItemListener {    public void itemStateChanged(ItemEvent e) {      JRadioButtonMenuItem rb = (JRadioButtonMenuItem) e.getSource();      if ( rb.isSelected() && rb.getText().equals("Mountain Ranges") )           dtype = CONST.MTN_RANGES;      else if ( rb.isSelected() && rb.getText().equals("Time Lines") )           dtype = CONST.TIMELINES;    }  }  private void makeUIChanges(){    SwingUtilities.updateComponentTreeUI( this );    // setResizable (true); setSize (getMinimumSize ()); setResizable (false);    setSize( getPreferredSize() );    if ( !isApplet )         SwingUtilities.updateComponentTreeUI( (Component)openAppFileDlg );    else        SwingUtilities.updateComponentTreeUI( openApltFileDlg );        if ( btns_viewer != null )        SwingUtilities.updateComponentTreeUI( btns_viewer );    if ( tour_viewer != null )        SwingUtilities.updateComponentTreeUI( tour_viewer );    //  if (disp != null) disp.makeUIChanges ();}    protected void finalize() throws Throwable {super.finalize();}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -