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

📄 configboxarc.java

📁 这是一个从音频信号里提取特征参量的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		// 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	//	labels = new Vector(5,5);	Vector types = new Vector(5,5);	Vector values = new Vector(5,5);	String transform = cfgVertexFocus.association;	int subclassIndex = 0;	for(int j=data.association.indexOf(transform); 	    j <= data.association.lastIndexOf(transform);	    j++) {	    if(j != -1) {		labels.add(data.name.get(j));		types.add(data.type.get(j));		values.add(data.values.get(j));	    }	}		// calculate the total number of subclasses	//	for(int i =0; i < types.size(); i++){	    if(types.get(i).equals("class"))		max_subclass++;	}		// maximum width of any JTextField or JComboBox	// will set all to this width once they have been added	//	int maxwidth = 0;	int maxheight = 0;		// run through these and add labels and input fields as appropriate	//	for(int i=0; i < labels.size(); i++) {	    // add a label for all labels except the images	    //	    if(types.get(i).equals("image") == false){		JLabel jlabel = new JLabel((String)labels.get(i));		jlabel.setForeground(Color.black);		constrain(config_panel,jlabel, gridbag, 0, i,			  1, 1, 1, 0, GridBagConstraints.WEST);		labelReference.add(jlabel);		jlabel.setFont(newFont);	    	    }	    else {			// keep data alligned so changing values is done easily		// while holding onto these image files		//		enteredData.add("image");		labelReference.add("image");		blockType.add("image");	    }	    	    // add a drop down list for the enumerated values with first	    // option from file being initially selected	    //	    if(types.get(i).equals("enum")){				// create a drop down list to allow selection from		//		JComboBox select = new JComboBox();		select.setFont(newFont);		select.setForeground(Color.black);		// retrieve and add all possible values to this list		//		Vector enum_values = (Vector)values.get(i);		for(int j=0; j < enum_values.size(); j++) {		    select.addItem(enum_values.get(j));		}				// add the combo box to the panel		//		constrain(config_panel,select, gridbag, 3, i,			  1, 1, 1, 0, GridBagConstraints.EAST);		enteredData.add(select);		blockType.add("enum");		Vertex selectedVertex = cfgVertexFocus;		select.setSelectedItem(selectedVertex.values.get(i));	    }	    	    // make a check box for a boolean type	    //	    else if (types.get(i).equals("boolean")){				// create the check box		//		String value = (String)(cfgVertexFocus.values.get(i));				// get the default value for the button		//		boolean value2;		if (value.equals( "true"))		    value2 = true;		else		    value2 = false;				// 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 = GUI_PATH + "/images_small/default.gif";		    }		    else {			image_name = GUI_PATH + "/images_small/default.gif";		    }		    // 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");	    }	    	    // do nothing if the type is image	    //	    else if (types.get(i).equals("image")) {	    }	    	    // 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");	    }	    // 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");	    }	    	    // 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")) {		if (!(labels.get(i).equals("signal_duration") && inputFlag)) {		    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");		}		else {		    //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("input")) &&		(!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("input")) &&		(!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() {	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";		}		digraph.tmpepi = "" + value;		//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();

⌨️ 快捷键说明

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