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

📄 eventhandler.java

📁 这是一个从音频信号里提取特征参量的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    }	}	// did the user click on a vertex with the right mouse button?	//	if (e.getSource().getClass().getName().equals("Vertex")) {	    if(SwingUtilities.isRightMouseButton(e)) {		//System.out.println("vertex rm clicked");		vertexRMClicked(e);	    }	    if (SwingUtilities.isLeftMouseButton(e)) {	    		//System.out.println("vertex lm clicked");		vertexLMClicked(e);	    }	}		// repaint the work area	//	CData.work_area_d.repaint();    }    /**     * handle the event when left button of mouse is clicked     * on the work area     * @param e the mouse event     * @return void     */    public void workAreaLMClicked(MouseEvent e) {		// declare local variables	//	ImageIcon icon = null;	int type = CData.NONE_VERTEX;	String vertex_name;	vertex_name = CData.START_VERTEX_NAME;	Point location = e.getPoint();	//DiGraph curr_graph = getCurrGraph();	if ( CData.curr_graph_d == null ){	    curr_am_string_d = CData.AM_NONE;	    return;	}		// find the focus	//	curr_arc_focus_d = CData.curr_graph_d.findFocusGraphArc(location);	curr_vertex_focus_d = null;		if ( false ){	    	}	else {	    // insert a start node	    //	    if ( curr_am_string_d.equals(CData.AM_GRAMMAR_INSERT_START) ){		icon  = new ImageIcon(CData.START_IMAGE);		type = CData.START_VERTEX;		vertex_name = CData.START_VERTEX_NAME;		Vertex vertex = new Vertex(vertex_name, icon, type);		CData.work_area_d.insertVertex(vertex, location);		CData.curr_graph_d.insertVertex(vertex);		curr_vertex_focus_d = vertex;		curr_am_string_d = CData.AM_NONE;	    }	    // insert a stop node	    //	    if ( curr_am_string_d.equals(CData.AM_GRAMMAR_INSERT_STOP) ){		icon  = new ImageIcon(CData.TERM_IMAGE);		type = CData.TERM_VERTEX;		vertex_name = CData.TERM_VERTEX_NAME;		Vertex vertex = new Vertex(vertex_name, icon, type);		CData.work_area_d.insertVertex(vertex, location);		CData.curr_graph_d.insertVertex(vertex);		curr_vertex_focus_d = vertex;		curr_am_string_d = CData.AM_NONE;	    }	    // insert a normal node	    //	    if ( curr_am_string_d.equals(CData.AM_GRAMMAR_INSERT_NODE) ){		icon  = new ImageIcon(CData.NODE_IMAGE);		type = CData.NODE_VERTEX;		vertex_name = CData.NODE_VERTEX_NAME;		Vertex vertex = new Vertex(vertex_name, icon, type);		CData.work_area_d.insertVertex(vertex, location);		CData.curr_graph_d.insertVertex(vertex);		curr_vertex_focus_d = vertex;		curr_am_string_d = CData.AM_NONE;	    }	}    }    /**     * handle the event when left button of mouse is clicked     * on the work area     * @param e the mouse event     * @return void     */    public void workAreaRMClicked(MouseEvent e) {		// declare local variables	//	ImageIcon icon = null;	int type = CData.NONE_VERTEX;	String vertex_name;	vertex_name = CData.START_VERTEX_NAME;	Point location = e.getPoint();	if ( CData.curr_graph_d == null ){	    curr_am_string_d = CData.AM_NONE;	    return;	}	// find the focus	//	curr_arc_focus_d = CData.curr_graph_d.findFocusGraphArc(location);	if ( curr_arc_focus_d != null ){	    	    // repaint the work area	    //	    CData.work_area_d.repaint();	    System.out.println("arc selected");	    UIArcInfo dlg 		= new UIArcInfo( CData.main_frame_d, new String("Symbols"), 				  true, curr_arc_focus_d);		    Dimension dlgSize = dlg.getPreferredSize();	    Dimension frmSize = CData.main_frame_d.getSize();	    Point loc = CData.main_frame_d.getLocation();	    dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, 			    (frmSize.height - dlgSize.height) / 2 + loc.y);	    dlg.show();		}    }    /**     * handle the event when left button of mouse is clicked     * on the vertex     * @param e the mouse event     * @return void     */    public void vertexLMClicked(MouseEvent e) {		Vertex selected_vertex = (Vertex)e.getSource();	curr_arc_focus_d = null;	// insert an self arc	//	if ( curr_am_string_d.equals(CData.AM_GRAMMAR_INSERT_SELF_ARC) ){	    	    curr_vertex_focus_d = selected_vertex;	    GraphArc new_arc = new GraphArc();	    new_arc.from_d = curr_vertex_focus_d;	    new_arc.to_d = selected_vertex;	    CData.curr_graph_d.insertArc(new_arc);	    curr_am_string_d = CData.AM_NONE;	    curr_vertex_focus_d = null;	}	else {	    if ( curr_vertex_focus_d == selected_vertex ){		curr_vertex_focus_d = selected_vertex;		GraphArc new_arc = new GraphArc();		new_arc.from_d = curr_vertex_focus_d;		new_arc.to_d = selected_vertex;		CData.curr_graph_d.insertArc(new_arc);		curr_am_string_d = CData.AM_NONE;		curr_vertex_focus_d = null;	    }	    else if ( curr_vertex_focus_d == null ){		curr_vertex_focus_d = selected_vertex;	    }	    else {		GraphArc new_arc = new GraphArc();		new_arc.from_d = curr_vertex_focus_d;		new_arc.to_d = selected_vertex;		CData.curr_graph_d.insertArc(new_arc);		curr_am_string_d = CData.AM_NONE;		curr_vertex_focus_d = null;	    }	}	    }    /**     * handle the event when right button of mouse is clicked     * on the vertex     * @param e the mouse event     * @return void     */    public void vertexRMClicked(MouseEvent e) {	Vertex curr_vertex = (Vertex)e.getSource();	if ( curr_vertex.isStart() || curr_vertex.isTerm() ){	    return;	} 	UINodeInfo dlg 	    = new UINodeInfo( CData.main_frame_d, new String("Symbols"), true);		dlg.setVertex(curr_vertex);	dlg.level_symbols_d = (Vector)CData.getCurrLevel().symbols_d.clone();	Dimension dlgSize = dlg.getPreferredSize();	Dimension frmSize = CData.main_frame_d.getSize();	Point loc = CData.main_frame_d.getLocation();	dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, 			(frmSize.height - dlgSize.height) / 2 + loc.y);	dlg.setModal(true);	dlg.initAll();	dlg.show();		// set the vertex text	//	if (curr_vertex.name_d.length() > 5) {	    curr_vertex.setText(curr_vertex.name_d.substring(0, 5));	}	else {	    curr_vertex.setText(curr_vertex.name_d);	}    }    /**     * handle the event when mouse is clicked     *      * @param e the mouse event     * @return void     */    public void mouseMoved(MouseEvent e) {		// update the location of the mouse coordinates	//	mouse_x_d = e.getX();	mouse_y_d = e.getY();    }    /**     * handle the event when mouse is clicked     *      * @param e the mouse event     * @return void     */    public void mousePressed(MouseEvent e) {	/*	// did the user click on a vertex with the left mouse button?	//	if (e.getSource().getClass().getName().equals("Vertex")) {	    if (SwingUtilities.isLeftMouseButton(e)) {		if (curr_vertex_focus_d != null) {		    curr_vertex_focus_d.getModel().setSelected(false);		}		curr_vertex_focus_d = (Vertex)e.getSource();		curr_vertex_focus_d.getModel().setSelected(true);	    }	}	// repaint the work area	//	CData.work_area_d.repaint();	*/    }    /**     * handle the event when mouse is clicked     *      * @param e the mouse event     * @return void     */    public void mouseReleased(MouseEvent e) {	    }    /**     * handle the event when mouse is clicked     *      * @param e the mouse event     * @return void     */    public void mouseEntered(MouseEvent e) {	    }    /**     * handle the event when mouse is clicked     *      * @param e the mouse event     * @return void     */    public void mouseExited(MouseEvent e) {	    }    /**     * handle the event when mouse is dragged     *      * @param e the mouse event     * @return void     */    public void mouseDragged(MouseEvent e) {		// declare local variables	//	int xdelta = 0;	int ydelta = 0;	int newWidth = 0;	int newHeight = 0;	boolean forwardLink = false;	boolean reverseLink = false;	// did the user click on a vertex with the left mouse button?	//	if (e.getSource().getClass().getName().equals("Vertex")) {	    if (SwingUtilities.isLeftMouseButton(e)) {		curr_vertex_focus_d = (Vertex)e.getSource();		// determine the location and width of the vertex		//		Point loc = curr_vertex_focus_d.getLocation();		    		int vertexWidth = curr_vertex_focus_d.getVertexWidth();		int vertexHeight = curr_vertex_focus_d.getVertexHeight();		    		int xloc = (loc.x + e.getX() - (vertexWidth / 2));		int yloc = (loc.y + e.getY() - (vertexHeight / 2));		    		int xloc1 = loc.x + e.getX() + (vertexWidth / 2);		int yloc1 = loc.y + e.getY() + (vertexHeight / 2);		// make sure the user does not move the vertex out of		// the work area		//		if ((xloc >= 0) && (yloc >= 0)) {					    // determine the new width for the work area		    //		    if (xloc1 > CData.work_area_d.getWidth()) {						xdelta = xloc1 - CData.work_area_d.getWidth();			newWidth = CData.work_area_d.getWidth() + xdelta;		    }					    // determine the new height for the work area		    //		    if (yloc1 > CData.work_area_d.getHeight()) {                            			ydelta = yloc1 - CData.work_area_d.getHeight();			newHeight = CData.work_area_d.getHeight() + ydelta;		    }		    // update the scroll bars of the work area		    //		    if ((xloc1 >= CData.work_area_d.getWidth()) || 			(yloc1 >= CData.work_area_d.getHeight())) {			// scroll the work area to the new region			//			Rectangle rect = new Rectangle(xloc, yloc, 						       vertexWidth, 						       vertexHeight);			CData.work_area_d.scrollRectToVisible(rect);			    			// make sure that the width and does not			// decrease, i.e., it does not scroll back			//			if (newWidth <= CData.WORKAREA_WIDTH) {			    newWidth = CData.WORKAREA_WIDTH;			} else {			    CData.WORKAREA_WIDTH = newWidth;			}			    			// make sure that the height and does not			// decrease, i.e., it does not scroll back			//			if (newHeight <= CData.WORKAREA_HEIGHT) {			    newHeight = CData.WORKAREA_HEIGHT;			} else {			    CData.WORKAREA_HEIGHT = newHeight;			}			    			// update client's preferred size because the area 			// taken up by the work area has gotten larger			//			CData.work_area_d.			    setPreferredSize(new Dimension(newWidth, 							   newHeight));			    			// let the scroll pane know to update itself			// and its corresponding scroll bars			//			CData.work_area_d.revalidate();		    }					    // drag the vertex to the location the user specifies		    //			curr_vertex_focus_d.setLocation(xloc, yloc);		}				// repaint the work area		//		CData.work_area_d.repaint();	    }        }    }        }// end of the class

⌨️ 快捷键说明

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