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

📄 configboxsub.java

📁 这是一个从音频信号里提取特征参量的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				// instantiate and place chack box on config panel		//		JCheckBox checkBox = new JCheckBox("", value2);		constrain(config_panel, checkBox, gridbag, 3, i,			  1,1,1,0,GridBagConstraints.EAST);		enteredData.add(checkBox);		blockType.add("boolean");	    }	    	    // add another pop up frame to set parameters for the class	    //	    else if (types.get(i).equals("class")) {				Vertex button;		if(cfgVertexFocus.max_subclass > cfgVertexFocus.subclass.size()) {		    String image_name = null;		    String image_association= null;	    		    // tells the program which transform it is looking to match		    //		    image_association = (String)values.get(i);		    		    // scans through the association until it 		    // finds the smallIcon key		    //		    for(int j=data.association.indexOf(image_association); 			j <= data.association.lastIndexOf(image_association);			j++) {			if(j != -1) {			    			    if(((String)(data.name.get(j))).			       equals("iconSmall")) {						// sets the image_name to the value 				// held in small icon				//				image_name = (String)data.values.get(j);			    }			}		    }		    		    // check to see if the file exists. If it does not exist,		    // use a default image.		    //		    if(image_name != null){			File image_file = new File(image_name);			if (image_file.exists() == false)			    image_name = "images_small/default.jpg";		    }		    else			image_name = "images_small/default.jpg";		    		    // create the icons for the config panel		    //		    ImageIcon icon = new ImageIcon(image_name);		    		    // create the button for the config panel		    //		    button = new Vertex(icon, ALGORITHM);		    		    // to simplify the creation, the data vectors will 		    // be trimmed to only include the transform we're		    // looking at and saved into these three vectors		    // for use in a bit		    //		    Vector labels2 = new Vector(5,5);		    Vector types2 = new Vector(5,5);		    Vector values2 = new Vector(5,5);		    		    for(int j=data.association.indexOf(image_association); 			j <= data.association.lastIndexOf(image_association);			j++) {			if(j != -1) {			    labels2.add(data.name.get(j));			    types2.add(data.type.get(j));			    values2.add(data.values.get(j));			}		    }		    	 		    // initialize the vertex to the default values for its type		    //		    button.initializeConfig(labels2, values2, types2,					    image_association, data);		   		    // add subclass button to the vector		    //		    cfgVertexFocus.subclass.add(button);		    		    // attach an action listener to the button		    //		    button.setActionCommand("class");		    button.addActionListener(this);		}		else {		    		    // bring back the saved button if all class button's have 		    // been previously saved		    //		    button = (Vertex)cfgVertexFocus.subclass.get(subclassIndex);		    if (button.actionAdded == false){			button.addActionListener(this);			button.actionAdded = true;		    }		    subclassIndex++;		}				// add the vertex to the button panel		//		constrain(config_panel,button, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(button);		blockType.add("Vertex");	    }	    	    // add another pop up frame to set parameters for the class	    //	    else if (types.get(i).equals("param")) {		String image_name = null;		String image_association= null;				// tells the program which transform it is looking to match		//		image_association = (String)values.get(i);		// scans through the association until it 		// finds the smallIcon key		//		for(int j=data.association.indexOf(image_association); 		    j <= data.association.lastIndexOf(image_association);		    j++) {		    if(j != -1) {						if(((String)(data.name.get(j))).			   equals("iconSmall")) {			    				// sets the image_name to the value 				// held in small icon				//			    image_name = (String)data.values.get(j);			}		    }		}		    		// check to see if the file exists. If it does not exist,		// use a default image.		//		if(image_name != null){		    File image_file = new File(image_name);		    if (image_file.exists() == false)			image_name = GUI_PATH + "/images_small/default.gif";		}		else {		    image_name = GUI_PATH + "/images_small/default.gif";		}		  		image_name = GUI_PATH+"/lib/images/isip_transform_builder/icons/algorithm_00.gif";		// create the icons for the config panel		//		ImageIcon icon = new ImageIcon(image_name);		    		// create the button for the config panel		//		buttonParam = new Vertex("Configure");		buttonParam.association = image_association;		// to simplify the creation, the data vectors will 		// be trimmed to only include the transform we're		// looking at and saved into these three vectors		// for use in a bit		//		Vector labels2 = new Vector(5,5);		Vector types2 = new Vector(5,5);		Vector values2 = new Vector(5,5);		    		for(int j=data.association.indexOf(image_association); 		    j <= data.association.lastIndexOf(image_association);		    j++) {		    if(j != -1) {			labels2.add(data.name.get(j));			types2.add(data.type.get(j));			values2.add(data.values.get(j));		    }		}				// initialize the vertex to the default values for its type		//		//button.initializeConfig(labels2, values2, types2,		//		    image_association, data);		   		// add subclass button to the vector		//		cfgVertexFocus.subclass.add(buttonParam);		    		enteredData.add(buttonParam);		blockType.add("Vertex");	    }    	    // do nothing if the type is image	    //	    else if (types.get(i).equals("image")) {	    }	    // take care of type vector	    //	    else if (types.get(i).equals("vector")) {		JTextField TextField = 		    new JTextField(((String)cfgVertexFocus.values.get(i)), 8);		TextField.setFont(newFont);		TextField.setForeground(Color.black);		constrain(config_panel,TextField, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(TextField);		blockType.add("vector");	    }	    	    // take care of type text	    //	    else if (types.get(i).equals("text")) {		JTextField TextField = 		    new JTextField(((String)cfgVertexFocus.values.get(i)), 8);		TextField.setFont(newFont);		TextField.setForeground(Color.black);		constrain(config_panel,TextField, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(TextField);		blockType.add("text");	    }	    	    // creation of input box for unsigned int	    //	    else if (types.get(i).equals("unsigned-integer")) {		JTextField TextField = 		    new JTextField(((String)cfgVertexFocus.values.get(i)), 8);		TextField.setFont(newFont);		TextField.setForeground(Color.black);		constrain(config_panel,TextField, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(TextField);		blockType.add("unsigned-integer");	    }	    // creation of input box for float	    //	    else if (types.get(i).equals("float")) {		JTextField TextField = 		    new JTextField(((String)cfgVertexFocus.values.get(i)), 8);		TextField.setFont(newFont);		TextField.setForeground(Color.black);		constrain(config_panel,TextField, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(TextField);		blockType.add("float");	    } 	    // creation of input box for double	    //	    else if (types.get(i).equals("double")) {		JTextField TextField = 		    new JTextField(((String)cfgVertexFocus.values.get(i)), 8);		TextField.setFont(newFont);		TextField.setForeground(Color.black);		constrain(config_panel,TextField, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(TextField);		blockType.add("double");	    } 	    // creation of input box for int	    //	     else if (types.get(i).equals("integer")) {		 JTextField TextField = 		     new JTextField(((String)cfgVertexFocus.values.get(i)), 8);		 TextField.setFont(newFont);		 TextField.setForeground(Color.black);		 constrain(config_panel,TextField, gridbag, 3, i,			   1, 1, 1, 0, GridBagConstraints.EAST);		 enteredData.add(TextField);		 blockType.add("integer");	     } 	    // !!! unexpected data type	    //	    else {		System.err.println();		System.err.println("---------------------------------------");		System.err.println("Error - Unexpected data type in file resource.txt: " + types.get(i));		System.err.println("---------------------------------------");		System.exit(0);	    }	    // check to see if the width of a JComboBox or JTextField	    // is wider than maxwidth and if it is, give that value to 	    // maxwidth	    //	    String type = (String)blockType.get(i);	    if((!type.equals("Vertex") &&		(!type.equals("image")) &&		(!type.equals("boolean")))) {				Dimension size = (Dimension)((JComponent)enteredData.					     get(i)).getPreferredSize();		int width = (int)size.getWidth();		int height = (int)size.getHeight();		if( width > maxwidth) {		    maxwidth = width;		    maxheight = height;		}	    }	}		// make all of the JComboBoxes and JTextFields be of equal length	//	for(int i = 0; i < blockType.size(); i++) {	    String type = (String)blockType.get(i);	    if((!type.equals("Vertex") &&		(!type.equals("image")) &&		(!type.equals("boolean")))) {		Dimension size = new Dimension(maxwidth, maxheight);		((JComponent)enteredData.get(i)).		    setPreferredSize(size);		((JComponent)enteredData.get(i)).		    setMinimumSize(size);	    }	}    }    // method: constrain    //    // arguments:    //    JPanel container      :  panel being added to    //    Component button      :  what is being added to the panel    //    GridBagLayout gridbag :  gridbag layout for config panel    //    int gridx             :  the x grid position of the constraint    //    int gridy             :  the y grid position of the constraint    //    int gridwidth         :  the number of gridspaces wide to constrain    //    int gridheight        :  the number of gridspaces tall to constrain    //    int weightx           :  the horizontal weighting of the constraint    //    int weighty           :  the vertical weighting of the constraint    //    int anchor            :  which side of the constraint to anchor to    //    // return  :  none    //    //  places all the proper input items onto the config panel     //  for configuring any transform    //     public void constrain(JPanel container,Component button, 			  GridBagLayout gridbag, int gridx,int gridy, 			  int gridwidth, int gridheight,			  int weightx, int weighty, int anchor){	GridBagConstraints c = new GridBagConstraints();	c.gridx = gridx;	c.gridy = gridy;	c.gridwidth = gridwidth;	c.gridheight = gridheight;	c.weightx = weightx;	c.weighty = weighty;	c.anchor = anchor;	gridbag.setConstraints(button, c);	container.add(button);    }    // method: validation    //    // arguments:  none    //    // return:  boolean     //    // checks to make sure that all configuration data has been input properly    // and if it has, make the changes to the referrign vertex     //     public boolean validation() {    	subparamInfo =  new Vector(5,5);		for(int i=0; i < labelReference.size(); i++) {	    	    if(blockType.get(i).equals("Vertex")) {		break;	    }	    	    if(blockType.get(i).equals("enum")) {				// set the vertex's value to match the newly selected one		//		subparamInfo.add((String)((JComboBox)enteredData.get(i)).				     getSelectedItem());	    }	}	for(int i=0; i < labelReference.size(); i++) {	    // code to use if the data is an enumerated type	    //	    if(blockType.get(i).equals("enum")) {				// set the vertex's value to match the newly selected one		//		cfgVertexFocus.values.set(i,			(String)((JComboBox)enteredData.get(i)).				     getSelectedItem());	    }	    // code to use if the data is a text field	    //	    if(blockType.get(i).equals("text")) {		String text =((JTextField)enteredData.get(i)).getText();		text = text.trim();		cfgVertexFocus.values.set(i,text);	    }	    // code to use if the data is a vector field	    //	    if(blockType.get(i).equals("vector")) {		String text =((JTextField)enteredData.get(i)).getText();		text = text.trim();		cfgVertexFocus.values.set(i,text);	    }	    // code to get information from a check box	    //	    if(blockType.get(i).equals("boolean")) {				boolean status = ((JCheckBox)enteredData.get(i)).isSelected();		String value = new String();		if(status){		    value = "true";		}		else {		    value = "false";		}		cfgVertexFocus.values.set(i,value);	    }	    	    // code to get information from a float variable	    //	    if(blockType.get(i).equals("float")) {		String text = ((JTextField)enteredData.get(i)).getText();		try {		    float value = Float.valueOf(text).floatValue();		    cfgVertexFocus.values.set(i, text);		}		catch (java.lang.NumberFormatException event) {		    JFrame frame = new JFrame("Warning");		    String warningMessage = new 			String("The value entered for " + 			       cfgVertexFocus.names.get(i) + 			       " is not a floating point number.");		    JOptionPane.showMessageDialog(frame, warningMessage);		    return false;		}	    }	    // code to get information from a double variable	    //	    if(blockType.get(i).equals("double")) {		String text = ((JTextField)enteredData.get(i)).getText();		try {		    double value = Double.valueOf(text).doubleValue();		    cfgVertexFocus.values.set(i, text);		}		catch (java.lang.NumberFormatException event) {		    JFrame frame = new JFrame("Warning");		    String warningMessage = new 			String("The value entered for " + 			       cfgVertexFocus.names.get(i) + 			       " is not a floating point number.");		    JOptionPane.showMessageDialog(frame, warningMessage);		    return false;		}	    }	    	    // code to get information from an unsigned integer variable	    //	    if(blockType.get(i).equals("unsigned-integer")) {		String text = ((JTextField)enteredData.get(i)).getText();		try {		    int value = Integer.valueOf(text).intValue();		    if (value >= 0) {			cfgVertexFocus.values.set(i, text);		    } else {			JFrame frame = new JFrame("Warning"); 			String warningMessage = new 			    String("The value entered for " + 				   cfgVertexFocus.names.get(i) + 				   " is not an unsigned integer.");			JOptionPane.showMessageDialog(frame,warningMessage);			return false;		    }		}		catch (java.lang.NumberFormatException event) {		    JFrame frame = new JFrame("Warning");		    String warningMessage = new 			String("The value entered for " + 			       cfgVertexFocus.names.get(i) + 			       " is not an unsigned integer.");		    JOptionPane.showMessageDialog(frame, warningMessage);		    return false;		}	    }	    // code to get information from an integer variable

⌨️ 快捷键说明

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