📄 jbrowse.java
字号:
/* * JBrowse.java - JBrowse GUI and Engine, v1.0.1 * * Copyright (c) 1999 George Latkiewicz (georgel@arvotek.net) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */import java.awt.*;import java.net.*;import javax.swing.*;import java.awt.event.*; // required for KeyListener and ActionListenerimport javax.swing.tree.*;import javax.swing.event.*;import javax.swing.border.*;import org.jext.event.*;import org.jext.gui.*;//=============================================================================/** * The class that defines the non-modal dialog window that provides the gui * for the JBrowse plugin. * @author George Latkiewicz * @version 1.0.1 - Nov. 16, 1999 */public class JBrowse extends JPanel // JFrame implements ActionListener, JextListener{ /* public class attributes */ public static final String VER_NUM = "1.0.1"; /* public instance attributes */ public JBrowseParser.Results results; /* private instance attributes */ private Frame frame; // passed by activator private PropertyAccessor props; // passed by activator private JBrowseParser parser; // passed by activator private UMLTree umlTree; // passed by activator private String fileName; // set on JBrowse.TreePane.init(), private UMLTree.Model treeModel; // set on JBrowse.TreePane.init() private UMLTree.Node root; private JButton parseBtn; private JButton resizeBtn; private JButton configBtn; // status bar JPanel statusPanel; JLabel classLabel, interfaceLabel, attributeLabel, methodLabel, errorLabel; JPanel topPanel; private TreePane treePane; private OptionDialog optionDialog; private Options options; private Options.Filter filterOpt; private Options.Display displayOpt; private ChangeListener optionListener; private boolean hasJavaFileExtension = false; JScrollPane scpTreePane; //------------------------------------------------------------------------- /** * This method creates a new instance of JBrowse GUI and Parsing engine. * @param */ public JBrowse(JBrowse.Activator activator) { // third option of false (i.e. non-modal) is the default for JDialog constructor// super(activator.getOwner(), "JBrowse", false);// super("JBrowse"); // for a JFrame frame = activator.getOwner(); // i.e. the associated editor view, if present props = activator.getPropertyAccessor(); parser = activator.getJBrowseParser(); umlTree = activator.getUMLTree(); if (props == null ) { return; } if (parser == null ) { return; } if (umlTree == null ) { return; }// if (frame != null) {// Image pluginIcon = org.gjt.sp.jedit.GUIUtilities.getPluginIcon();// if (pluginIcon != null) {// setIconImage( pluginIcon );// }// }// URL url = getClass().getResource("StructIcon.gif");// if (url != null) {// setIconImage( (new ImageIcon(url)).getImage() );// } treePane = new TreePane("jbrowse_tree"); // Add tree pane to center of content pane Container contentPane = this; contentPane.setLayout(new BorderLayout()); contentPane.add(BorderLayout.CENTER, treePane); // Connect to the optionPane's options optionDialog = new OptionDialog(frame, this, "JBrowse - Configure Options"); options = optionDialog.getOptions(); filterOpt = options.getFilterOptions(); displayOpt = options.getDisplayOptions(); treePane.init(); // Configure Parser parser.setOptions(options); parser.setRootNode(root); // create the ChangeListener for this JBrowse session, this // is the means by which this session is notified of any changes // to the current option values. optionListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { Object src = e.getSource(); if (src == options) { // Display or hide the status bar if (options.getShowStatusBar() ) { statusPanel.setVisible(true); } else { statusPanel.setVisible(false); } setPreferredSize(); } else if (src == filterOpt ) { // Reload the tree (if necessary) if ( root.getChildCount() > 0) { // there are nodes below the root, therefore need // to reload umlTree.display(treeModel, options, results); } } else if (src == displayOpt ) { // Update the display , if necessary (without reloading) if ( root.getChildCount(filterOpt) > 0) { // there are nodes below the root, therefore update // of the display is necessary// treeModel.updateVisibleChildren(root);// umlTree.updateVisible(options); umlTree.updateVisibleToggled(options); } } } // stateChanged(ChangeEvent): void } ; if (hasJavaFileExtension) { results = parser.parse(); showResults(results); } else { showResults(results); } // Determine size and position of the GUI/* Dimension screen = getToolkit().getScreenSize(); pack(); setPreferredSize(); setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2); show();*/ } // JBrowse(JBrowse.Activator): <init> private void parseNow() { // Set Wait Cursor setCursor(new Cursor(Cursor.WAIT_CURSOR)); umlTree.setModel(null); // set model to null to speed up results = parser.parse(); showResults(results); paintAll(getGraphics()); // Set Default Cursor setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } public void jextEventFired(JextEvent evt) { //evt.getWhat() == JextEvent.BATCH_MODE_UNSET || if ((!evt.getJextFrame().getBatchMode() && evt.getWhat() == JextEvent.TEXT_AREA_SELECTED)) parseNow(); } public Options.DisplayIro getDisplayOptions() { return displayOpt; } public ChangeListener getOptionListener() { return optionListener; } //------------------------------------------------------------------------- public void actionPerformed(ActionEvent evt) { Object source = evt.getSource(); if (source == parseBtn) { parseNow(); } else if (source == resizeBtn) { setPreferredSize(); } else if (source == configBtn) { optionDialog.reInit(); // check if first time, init as required // Determine size and position of the OptionDialog Dimension screen = getToolkit().getScreenSize(); Dimension optSize = optionDialog.getSize(); int treeX = getLocation().x; // ???1.1 for 1.2 replace getLocation().x with getX() int optY = (screen.height - optSize.height) / 2; if (treeX + getSize().width + 12 + optSize.width > screen.width ) { // i.e. won't fit at right so... if (treeX - optSize.width - 12 < 0 ) { // i.e. won't fit at left either so overlap at right end optionDialog.setLocation( screen.width - optSize.width - 2, optY); } else { // left of optionDialog.setLocation( treeX - optSize.width - 10, optY); } } else { // right of optionDialog.setLocation( treeX + getSize().width + 10, optY); } optionDialog.setVisible(true); optionDialog.paintAll(getGraphics()); // Repaint the JBrowse Dialog, required to eliminate // any contamination from the OptionDialog (really!) paintAll(getGraphics()); } } // actionPerformed(ActionEvent): void //------------------------------------------------------------------------- public void setPreferredSize() { topPanel.validate(); Dimension dFrame = getSize(); // current internal frame Dimension dViewCur = scpTreePane.getViewport().getSize(); Dimension dViewPref = scpTreePane.getViewport().getPreferredSize(); Dimension dTreePref = umlTree.getPreferredSize(); int newFrameWidth; // Set vertical scrollbar to visible, if it should be if (dViewCur.height < dViewPref.height) { scpTreePane.getVerticalScrollBar().setVisible(true); } // Set width to preferred width based on view and scroll bar if ( scpTreePane.getVerticalScrollBar().isVisible() ) { // i.e. 15 = scpTreePane.getVerticalScrollBar().getSize().width; newFrameWidth = dViewPref.width + 12 + 16; } else { newFrameWidth = dViewPref.width + 12; } // Adjust width for status panel, if visible if ( statusPanel.isVisible() ) { statusPanel.validate(); newFrameWidth = Math.max(newFrameWidth, statusPanel.getPreferredSize().width + 8); } // Adjust width for top panel dFrame.width = Math.max( newFrameWidth, topPanel.getPreferredSize().width + 8); setSize(dFrame); paintAll(getGraphics()); } // setPreferredSize(): void //------------------------------------------------------------------------- /** * This method should be called after every parse. It updates the text of * the status bar's labels to the results counts, displays the error * indicator (if appropriate) and then calls umlTree.display() to reload * the tree. */ public void showResults(JBrowseParser.Results results) { //System.out.println("showResults for options: " + options); umlTree.display(treeModel, options, results); if (results != null) { // Update Status Bar classLabel.setText( "" + results.getClassCount() ); interfaceLabel.setText( "" + results.getInterfaceCount() ); attributeLabel.setText( "" + (results.getObjAttrCount() + results.getPrimAttrCount() ) ); methodLabel.setText( "" + results.getMethodCount() ); // Update Parse Error Indicator
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -