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

📄 mainwin.java

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    addWindowListener (new WindowAdapter () {      public void windowClosing (WindowEvent e) {close ();}    });  }    //End of setup methods---------------------------------------------------------    //Event Handler methods--------------------------------------------------------  //Only events from buttons are generated    /**   * Handles action events generated from buttons   */  public void actionPerformed (ActionEvent evt) {    String command = evt.getActionCommand ();    if (command.equals ("New Frame")) new Mainwin (parent, null, aplt, true);    else if (command.equals ("Select Logfile")) selectFile ();    else if (command.equals ("Exit")) close ();    else if (command.equals ("Manual")) helpDlg.setVisible (true);    else if (command.equals ("About")) {      URL icon_URL = ClassLoader.getSystemResource( "images/jumpshot.gif" );      if ( icon_URL != null ) {        ImageIcon js_icon = new ImageIcon( icon_URL );        JOptionPane.showMessageDialog (this, about, "About",                                       JOptionPane.INFORMATION_MESSAGE,                                        js_icon);      }      else        JOptionPane.showMessageDialog (this, about, "About",                                       JOptionPane.INFORMATION_MESSAGE);    }    else if (command.equals ("Display")) displayStuff ();  }  //End of event Handler methods-------------------------------------------------    private void displayStuff () {      if (mainTool != null) {      disableDisp ();       waitCursor ();      disp = new ClogDisplay (this);      normalCursor ();    }  }    private void disableDisp () {dispB.setEnabled (false);}    private void enableDisp () {dispB.setEnabled (true);}    /**   * selects the log file to be read   */  private void selectFile () {    if (!aplt) { //Application - Read file from machine's memory      Component comp; Class c = this.getClass ();            while (!(c.getName ().equals ("java.awt.Component"))) {	c = c.getSuperclass();      }                  int r = ((Integer)ROUTINES.invokeMethod 	       (openAppFileDlg, "showOpenDialog", (Component)this, c)).intValue ();      if (r == 0) {	String file;	File f = (File)ROUTINES.invokeMethod (openAppFileDlg, "getSelectedFile", null, null);	if (f != null) file = f.toString (); else file = null;		if (file != null) {	  logFileName = file;	  logFileField.setText (logFileName);	  readLogFile (logFileName);	}      }      else JOptionPane.showMessageDialog (this, "No file chosen");    } else { //Applet - Read file from host machine's memory       openApltFileDlg.show ();      if (openApltFileDlg.select) {	String file = openApltFileDlg.getFile ();	if (file != null) {	  logFileName = file;	  logFileField.setText (logFileName);	  readLogFile (logFileName);	}      }      else JOptionPane.showMessageDialog (this, "No file chosen");    }  }    /**   * reads a log file by creating a ClogReader instance    */  private void readLogFile (String inFile) {    //Clean up and free resources    freeMem ();        //Spawn new thread to read from clog file    readWorker = new SwingWorker() {      public Object construct() {	waitCursor ();	disableDisp ();	reader_alive = true;	return (new ClogReader ((JFrame)startwin, logFileName, aplt)).mainTool;      }      public void finished () {	reader_alive = false;	mainTool = (RecordHandler)get ();	normalCursor ();	if (mainTool != null) enableDisp ();	displayStuff ();      }    };    readWorker.start();  }      /**   * Destructor   */  private void close () {    freeMem ();     this.setVisible (false); this.dispose ();    //    System.runFinalization (); System.gc ();    if (!child && !aplt) 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 ();    mainTool = null;    //    System.runFinalization (); System.gc ();  }     /**   * 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 ErrorDiag (this, "IO Error:" + x.getMessage ());}    return text;  }    private InputStream getFileIn (String name) {    InputStream in = null;        try {in = new FileInputStream (name);}    catch (FileNotFoundException e) {      new ErrorDiag (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 ErrorDiag (this, "Bad URL:" + url);      return null;    }       try {in = url.openStream ();}    catch (IOException e) {      new ErrorDiag (this, "IO Error:" + e.getMessage ());      return null;    }    return in;  }      /**   * This method returns the path to data directory (..../jumpshot.../data/)    * in which data files including jumpshot.setup reside. This path is extracted    * from Java class path present in the set of system properties. Java class path    * contains a pointer to the classes directory having all the bytecode. From this    * classes path, distribution path (...jumpshot-1.0) is got to which data/   * is added to obtain data directory path   */  private String getDataPath () {    Properties s = System.getProperties ();        String classpath = s.getProperty ("java.class.path");        StringTokenizer tokens = new StringTokenizer (classpath, File.pathSeparator);        int ct = tokens.countTokens ();    for (int i = 0; i < ct; i++) {      String dir;      File f = new File (tokens.nextToken ());      try {dir = f.getCanonicalPath ();}      catch (IOException x) {	new ErrorDiag (this, "IO Exception:" + x.getMessage());	continue;      }      if (dir.endsWith (classDir1)) {        distributionDir = dir.substring (0, dir.lastIndexOf (classDir1));	return (distributionDir + dataDir + File.separator);      }      else if (dir.endsWith (classDir2)) {	distributionDir = dir.substring (0, dir.lastIndexOf (classDir2));	return (distributionDir + dataDir + File.separator);      }    }    new ErrorDiag (null, "Neither of " + classDir1 + " nor " + classDir2 + " could be found" +		   " in java.class.classpath");    return null;  }    /**   * Similar explanation as above method   */  private String getDataUrl () {    String url = (parent.getCodeBase ()).toString ();        int i = url.lastIndexOf (classDir1);    if (i == -1) distributionUrl = url;    else      distributionUrl = url.substring (0, i);        return (distributionUrl + dataDir + "/");     //Here front slash "/" is used because this is the specified character     //that is a file separator in url conventions  }    private ImageIcon loadImageIcon(String filename) {    if(!aplt) {      return new ImageIcon (distributionDir + filename);    }    else {      URL url = null;      try {url = new URL (distributionUrl + filename);}      catch (MalformedURLException e) {	new ErrorDiag (this, "Bad URL:" + url);	return null;      }      return new ImageIcon(url);    }  }    void delDisp () {    enableDisp (); 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("com.sun.java.swing.plaf.metal.MetalLookAndFeel");	  makeUIChanges ();	}       }       catch (UnsupportedLookAndFeelException exc) {	// Error - unsupported L&F	rb.setEnabled(false);	new ErrorDiag (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 ErrorDiag (null, "Could not load LookAndFeel: " + exc2);	}      }       catch (Exception exc) {	rb.setEnabled(false);	new ErrorDiag (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);    if (!aplt)       SwingUtilities.updateComponentTreeUI ((Component)openAppFileDlg);    else      SwingUtilities.updateComponentTreeUI (openApltFileDlg);        SwingUtilities.updateComponentTreeUI (helpDlg);    if (disp != null) disp.makeUIChanges ();  }    protected void finalize() throws Throwable {super.finalize();}}

⌨️ 快捷键说明

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