📄 mainwin.java
字号:
import java.awt.*;import java.util.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.rmi.*;import javax.swing.*;import javax.swing.border.*;/* This class supervises the reading and display of a slog file. It shows a Frame consisting of (New Frame), (Select File) and (Exit) buttons along with a text field showing the current filename. 1. The log file to be read is selected via FileDialog object (openAppFileDlg) 2. An instance of FrameReader class is created with this filename which traverses the log file and supervises the creation of data structures. 3. The data structures created reside in RecordHandler object which is returned. 4. This class (Mainwin) then takes the RecordHandler object along with the data structures creates an instance of FrameDisplay class which handles all drawing, printing, manipulation, etc.*/public class Mainwin extends JPanel implements ActionListener{ SLOG_ProxyInputStream slog = null; ViewFrameChooser frame_chooser; private SwingWorker readWorker; //Thread doing reading // Relative Path to the files for the GUI system's configuration private String configDefaultFile = "etc/jumpshot.conf"; private String colorDefaultFile = "share/jumpshot.colors"; private String tourDefaultFile = "doc/html/index.html"; private String buttonDefaultFile = "doc/jumpshot.def"; private String configFile = configDefaultFile; private String colorFile; private String tourHTMLFile; private String btnsDefnFile; //Directory to the sample logfiles private String logFileDir = "logfiles"; // private Object openAppFileDlg; private JFileChooser openAppFileDlg; private ApltFileDlg openApltFileDlg; private MyTextField logFileField; private JMenuItem metalMenuItem, selectFileMenuItem; String logFileName; Font frameFont; Color frameBColor, frameFColor; public Dimension dimPG; private HTMLviewer btns_viewer; private HTMLviewer tour_viewer; private JMenuBar menuBar; Mainwin startwin; //This boolean value tells us if this instance of Mainwin is a child or not //If it is a child then when u exit it only its descendents will be terminated //If however, u exit the father all children will also be exited private boolean isChild; Component parent; private String parent_superclass; private boolean isApplet; int dtype; private String about = "Jumpshot, the SLOG viewer, Version 3.0\n" + "Questions: mpi-maint@mcs.anl.gov"; private MyButton read_btn; private boolean reader_alive; public Mainwin( Component origin, boolean is_child, String filename, int frame_idx ) { parent = origin; parent_superclass = parent.getClass().getSuperclass().getName(); isApplet = parent_superclass.equals( "javax.swing.JApplet" ); isChild = is_child; startwin = this; logFileName = filename; slog = null; /* if ( frame_idx >= 0 ) slog_frame_idx = frame_idx; else slog_frame_idx = 0; */ if ( logFileName == null ) logFileName = new String( "No Name" ); setup(); } public boolean getIsApplet() { return isApplet; } //setup methods----------------------------------------------------------------- private void setup () { setupUI(); adjustFrameStuff(); setupData(); // setupDlgs(); setupPanels(); disableRead(); setupEventHandlers(); // setSize( getMinimumSize() ); setResizable( false ); setVisible(true); if ( ! logFileName.equals( "No Name" ) ) { readLogFile(); } } private void setupUI () { // Force SwingSet to come up in the Cross Platform L&F try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); // If you want the System L&F instead, comment out the above line and // uncomment the following: // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception exc) { new ErrorDialog (null, "Error loading L&F: " + exc); } } private void adjustFrameStuff () { if ( isChild ) ( (MainFrame)parent ).setTitle( "Jumpshot-3: Child" ); Dimension dimScreen = Toolkit.getDefaultToolkit().getScreenSize(); dimPG = new Dimension ((int)Math.rint (dimScreen.width * 0.75), (int)Math.rint (dimScreen.height * 0.7)); frameBColor = Color.lightGray; frameFColor = Color.black; frameFont = new Font ("Serif", Font.PLAIN, 10); } private void setupData(){ //Obtain the settings specified by the user. Properties settings = new Properties(); URL setup_URL, color_URL; boolean useDefaultSettings; InputStream setin, colorin; setup_URL = getURL( configFile ); if ( setup_URL != null ) { try { setin = setup_URL.openStream(); settings.load( setin ); setin.close(); } catch ( IOException err ) { new WarnDialog( this, "IO Error:" + err.getMessage() + " " + "in reading the setup file. Use default settings" ); useDefaultSettings = true; } useDefaultSettings = false; } else { new WarnDialog( this, "Cannot locate setup file " + configFile + ". " + "Use default settings." ); useDefaultSettings = true; } // Load the settings if possible if ( useDefaultSettings ) { colorFile = colorDefaultFile; tourHTMLFile = tourDefaultFile; btnsDefnFile = buttonDefaultFile; } else { colorFile = settings.getProperty( "COLORFILE", colorDefaultFile ); tourHTMLFile = settings.getProperty( "HTMLFILE", tourDefaultFile ); btnsDefnFile = settings.getProperty( "BUTTONFILE", buttonDefaultFile ); } color_URL = getURL( colorFile ); if ( color_URL == null ) { new ErrorDialog( this, "Cannot locate " + colorFile + ". Exiting!" ); close(); } colorin = null; try { colorin = color_URL.openStream(); } catch ( IOException err ) { new ErrorDialog( this, "IO Error:" + err.getMessage() + ". " + "Cannot open " + colorFile + ". Exiting!" ); close(); } ColorUtil.readColors( this, colorin ); reader_alive = false;} /*private void setupDlgs(){ URL init_URL = getURL( tourHTMLFile ); if ( init_URL != null ) tour_viewer = new HTMLviewer( init_URL ); else tour_viewer = null; URL btns_URL = getURL( btnsDefnFile ); if ( btns_URL != null ) btns_viewer = new HTMLviewer( btns_URL ); else btns_viewer = null;}*/ private void setupPanels(){ setLayout( new GridBagLayout() ); GridBagConstraints con = new GridBagConstraints(); con.anchor = GridBagConstraints.WEST; con.fill = GridBagConstraints.HORIZONTAL; add( setupMenuBar(), con ); con.fill = GridBagConstraints.NONE; //JPanels are used now. But, if the problem with using menus is solved //they should be used instead Border border1, border2 = BorderFactory.createLoweredBevelBorder(); //Logfile field JPanel pl = new JPanel( new FlowLayout() ); border1 = BorderFactory.createEmptyBorder( 4, 4, 2, 4 ); pl.setBorder( BorderFactory.createCompoundBorder( border1, border2 ) ); pl.add( new JLabel( "Logfile" ) ); logFileField = new MyTextField( logFileName, 35, false ); pl.add( logFileField ); con.gridy = 1; add( pl, con ); con.gridy = 2; con.gridx = 0; read_btn = new MyButton( "Read", "Reading the selected logfile", this ); add( read_btn, con );} private JMenuBar setupMenuBar () { menuBar = new JMenuBar(); //File Menu JMenu file = (JMenu) menuBar.add(new JMenu("File")); JMenuItem menuItem = file.add (new JMenuItem ("New Frame")); menuItem.addActionListener (this); menuItem.setHorizontalTextPosition (JButton.RIGHT); selectFileMenuItem = new JMenuItem ("Select Logfile"); file.add (selectFileMenuItem); selectFileMenuItem.addActionListener (this); selectFileMenuItem.setHorizontalTextPosition (JButton.RIGHT); menuItem = file.add (new JMenuItem ("Exit")); menuItem.addActionListener (this); menuItem.setHorizontalTextPosition (JButton.RIGHT); menuBar.add (file); //Display Menu JMenu dispM = (JMenu) menuBar.add(new JMenu("Display")); ButtonGroup dGroup = new ButtonGroup(); DispListener dispListener = new DispListener(); JRadioButtonMenuItem rbM; rbM = (JRadioButtonMenuItem) dispM.add(new JRadioButtonMenuItem("Time Lines")); dGroup.add(rbM); rbM.addItemListener(dispListener); rbM.setSelected (true); dtype = CONST.TIMELINES; //Setting dtype to time lines rbM = (JRadioButtonMenuItem) dispM.add(new JRadioButtonMenuItem("Mountain Ranges")); dGroup.add(rbM); rbM.addItemListener(dispListener); // disable the MountainRanges option rbM.setEnabled( false ); menuBar.add (dispM); // Sys Options Menu JMenu options = (JMenu) menuBar.add(new JMenu("System")); // Look and Feel Radio control ButtonGroup group = new ButtonGroup(); ToggleUIListener toggleUIListener = new ToggleUIListener(); JMenuItem windowsMenuItem, motifMenuItem, macMenuItem; windowsMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Windows Style Look and Feel")); windowsMenuItem.setSelected( UIManager.getLookAndFeel().getName().equals("Windows") ); group.add(windowsMenuItem); windowsMenuItem.addItemListener(toggleUIListener); motifMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Motif Look and Feel")); motifMenuItem.setSelected( UIManager.getLookAndFeel().getName().equals("CDE/Motif")); group.add(motifMenuItem); motifMenuItem.addItemListener(toggleUIListener); metalMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Metal Look and Feel")); metalMenuItem.setSelected( UIManager.getLookAndFeel().getName().equals("Metal")); metalMenuItem.setSelected(true); group.add(metalMenuItem); metalMenuItem.addItemListener(toggleUIListener); macMenuItem = (JRadioButtonMenuItem) options.add(new JRadioButtonMenuItem("Macintosh Look and Feel")); macMenuItem.setSelected( UIManager.getLookAndFeel().getName().equals("Macintosh")); group.add(macMenuItem); macMenuItem.addItemListener(toggleUIListener); // Tooltip checkbox options.add(new JSeparator()); JCheckBoxMenuItem cb = new JCheckBoxMenuItem ("Show ToolTips"); options.add(cb); cb.setSelected(true); cb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBoxMenuItem b = (JCheckBoxMenuItem)e.getSource(); if(b.isSelected()) { ToolTipManager.sharedInstance().setEnabled(true); } else { ToolTipManager.sharedInstance().setEnabled(false); } } }); //Help Menu JMenu helps = (JMenu) menuBar.add(new JMenu("Help")); menuItem = helps.add (new JMenuItem ("Manual")); menuItem.addActionListener (this); menuItem = helps.add (new JMenuItem ("Tour")); menuItem.addActionListener (this); menuItem = helps.add (new JMenuItem ("About")); menuItem.addActionListener (this); menuBar.add (helps); return menuBar; } private void setupEventHandlers() { this.enableEvents (AWTEvent.ACTION_EVENT_MASK); } //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 MainFrame( true, null, 0 ); else if ( command.equals( "Select Logfile" ) ) selectFile(); else if ( command.equals( "Exit" ) ) close(); else if ( command.equals( "Manual" ) ) { URL btns_URL = getURL( btnsDefnFile ); if ( btns_URL != null ) { btns_viewer = new HTMLviewer( btns_URL ); btns_viewer.setVisible( true ); } else new WarnDialog( this, "Cannot locate " + btnsDefnFile + "." ); } else if ( command.equals( "Tour" ) ) { URL init_URL = getURL( tourHTMLFile ); if ( init_URL != null ) { tour_viewer = new HTMLviewer( init_URL ); tour_viewer.setVisible( true ); } else new WarnDialog( this, "Cannot locate " + tourHTMLFile + "." ); } else if ( command.equals( "About" ) ) { URL icon_URL = getURL( "images/jumpshot.gif" ); if ( icon_URL != null ) { ImageIcon js_icon = new ImageIcon( icon_URL );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -