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

📄 submainmenu.java

📁 这是一个从音频信号里提取特征参量的程序
💻 JAVA
字号:
// file: SubMainMenu.java
//

// import necessary java libraries
//
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.applet.*;

// class: SubMainMenu
//
// implement the menu driven system that drives the applet
//
// hierarchy: SubMainMenu
//
class SubMainMenu extends JPanel implements ActionListener, Constants {

    // ---------------------------------------------------    
    //
    // declare global variables
    //
    // ---------------------------------------------------    

    // creates a fram to manipulate the configuration options
    //
    public JFrame config = null;

    // textfields and labels for the connector properties
    //
    public JLabel nameLabel = null;
    public JTextField nameField = null;

    // declare a reference to the SubDiGraph
    //
    public SubDiGraph subdigraph = null;

    // menu that holds all functionality
    //
    public JMenu menu = null;
    public JMenu subMenu = null;
    public JMenu subSubMenu = null;
    public JMenuBar menuBar = null;
    public JMenuItem menuItem = null;
    
    // declare the layout manager
    //
    public GridBagLayout gridbag = new GridBagLayout();
    
    // ---------------------------------------------------        
    //
    // declare class constructors
    //
    // ---------------------------------------------------    
   
    // method: SubMainMenu
    //
    // arguments:
    //
    // returns  : none
    //
    // constructor initializes objects and containers
    //
    SubMainMenu(SubDiGraph sdg) {
	
	super();

	// set the default layout
	//
	setLayout(gridbag);

	// set the reference to vertex box
	//
	subdigraph = sdg;

	// initialize the menu bar
	//
	menuBar = new JMenuBar();

	// create the file menu
	//	
	menu = new JMenu(fileStr);
	menu.setFont(newFont);
	menuBar.add(menu);

	// add the menu items
	//
	menuItem = new JMenuItem(closeStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 
						       ActionEvent.ALT_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(closeStr);
	menu.add(menuItem);

	// create the edit menu
	//
	menu = new JMenu(editStr);
	menu.setFont(newFont);
	menuBar.add(menu);

	menuItem = new JMenuItem(cutStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, 
						       ActionEvent.CTRL_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(cutStr);
	menu.add(menuItem);

	menuItem = new JMenuItem(copyStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 
						       ActionEvent.CTRL_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(copyStr);
	menu.add(menuItem);

	menuItem = new JMenuItem(pasteStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 
						       ActionEvent.CTRL_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(pasteStr);
	menu.add(menuItem);

	menu.addSeparator();

	menuItem = new JMenuItem(insArcStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, 
						       ActionEvent.ALT_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(insArcStr);
	menu.add(menuItem);

	menu.addSeparator();

	menuItem = new JMenuItem(delArcStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, 
						       ActionEvent.ALT_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(delArcStr);
	menu.add(menuItem);

	menuItem = new JMenuItem(delBlkStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, 
						       ActionEvent.ALT_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(delBlkStr);
	menu.add(menuItem);

	menuItem = new JMenuItem(clearStr);
	menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, 
						       ActionEvent.ALT_MASK));
	menuItem.setFont(newFont);
	menuItem.addActionListener(this);
	menuItem.setActionCommand(clearStr);
	menu.add(menuItem);

	// create the algorithms menu
	//
	menu = new JMenu(algoStr);
	menu.setFont(newFont);
	menuBar.add(menu);

	int index = subdigraph.data.association.indexOf(TRANSFORM_TAG);
	Vector algorithms = (Vector)subdigraph.data.values.elementAt(index);
	for (int i=0; i < algorithms.size(); i++) {
	    String algo = (String)algorithms.elementAt(i);	
	    if(algo.equals("AudioFrontEnd")) {
		continue;
	    }   
	    menuItem = new JMenuItem(algo);
	    menuItem.setFont(newFont);
	    menuItem.addActionListener(this);
	    menuItem.setActionCommand(algo);
	    menu.add(menuItem);   
	}	    

	// set the dimensions of the menu
	//
	this.setSize(new Dimension(subdigraph.MAX_WIDTH, 30));
	this.setMinimumSize(new Dimension(subdigraph.MAX_WIDTH, 30));
	this.setMaximumSize(new Dimension(subdigraph.MAX_WIDTH, 30));
	this.setPreferredSize(new Dimension(subdigraph.MAX_WIDTH, 30));
    }
    
    // ---------------------------------------------------
    //
    // declare class methods
    //
    // ---------------------------------------------------
    
    // method: add_components
    //
    // arguments: none
    // return   : none
    //
    // adds components to the control panel
    //
    public void add_components () {
	
	constrain(this, menuBar, 0, 0, 
		  GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER,
		  GridBagConstraints.BOTH, GridBagConstraints.CENTER,
		  1, 1, 0, 0, 0, 0);
    }

    // method: actionPerformed
    //
    // arguments:
    //    ActionEvent e: action command that is fired
    //
    // return   : none
    //
    // method listens for actions taking place on text only menu items
    //
    public void actionPerformed(ActionEvent e) {

	// get the source of the action that just occured
	//
	String source = e.getActionCommand();

	if(source.equals(closeStr)) {

	    // close the application
	    //
	    subdigraph.closeContainer();

	} else if(source.equals(clearStr)) {

	    // clear out all existing memory
	    //
	    subdigraph.clearAllMemory();

	    // refresh the work area
	    //
	    subdigraph.subWorkArea.repaint();

	} else if (source.equals(cancelStr)) {

	    // remove the frame from the screen
	    //
	    config.setVisible(false);

	} else if(source.equals(delBlkStr)) {

	    // remove all children and parent edges
	    //
	    if (subdigraph.currVertexFocus != null) {
		if (subdigraph.currVertexFocus.getClass().getName().equals("Vertex")) {
		    subdigraph.removeVertex(subdigraph.currVertexFocus);
		}
	    }

	} else if(source.equals(cutStr)) {
	    subdigraph.cut();
	} else if(source.equals(copyStr)) {
	    subdigraph.copy();
	} else if(source.equals(pasteStr)) {
	    subdigraph.paste();
	} else if(source.equals(insArcStr)) {
	    subdigraph.enableArcInsertion = true;
	} else if(source.equals(delArcStr)) {
	    subdigraph.enableArcDeletion = true;
	} else {
	    subdigraph.createAlgorithm(e.getActionCommand());
	}
    }

    // method: constrain
    //
    // argument: 
    //     Container container: (input) container to place the component
    //     Component component: (input) the component to be constrained
    //     int grid_x: (input) horizontal position of component
    //     int grid_y: (input) vertical position of component
    //     int grid_width: (input) number of horizontal grid spots to take
    //     int grid_height: (input) number of vertical grid spots to take
    //     int fill: (input) directions to fill when component space is resized
    //     int anchor: (input) anchor position when component space is resized
    //     double weight_x: (input)relative amount of horizontal space 
    //                      component should take when its space is resized
    //     double weight_y: (input) relative amount of vertical space component
    //                      should take when its space is resized
    //     int top: (input) amount of inset space on top
    //     int left: (input) amount of inset space on left
    //     int bottom: (input) amount of inset space on bottom
    //     int right: (input) amount of inset space on right
    // 
    // returns: boolean flag indicating status
    //
    // this method creates the constraints of a component in a container
    // and then adds the component to the container.  it is based on 
    // code from "Java in a Nutshell" by David Flanagan. published by
    // O'Reilly and Associates incorporated.
    //
    public boolean constrain(Container container, Component component, 
			     int grid_x, int grid_y, int grid_width, 
			     int grid_height, int fill, int anchor, 
			     double weight_x, double weight_y, int top,
			     int left, int bottom, int right) {
	
	// set the constraints based on the input variables
	//
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = grid_x;
	c.gridy = grid_y;
	c.gridwidth = grid_width;
	c.gridheight = grid_height;
	c.fill = fill;
	c.anchor = anchor;
	c.weightx = weight_x;
	c.weighty = weight_y;
	
	// if any of the buffer insets are greater than zero, create a new
	// Insets object
	//
	if (top + bottom + left + right > 0)
	    c.insets = new Insets(top, left, bottom, right);
	
	// set the constraints of the component
	//
	((GridBagLayout) container.getLayout()).setConstraints(component, c);
	
	// add the component to the container
	//
	container.add(component);
	
	// exit gracefully
	//
	return true;
    }
}

//
// end of file

⌨️ 快捷键说明

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