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

📄 mainpanel.java

📁 Kohonen网络的学习过程可描述为:对于每一个网络的输入
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			nePanel.add(new JLabel("Neighbourhood function: "));
			stepRB = new JRadioButton("Step (bubble)",true);
			gaussianRB = new JRadioButton("Gaussian",false);
			neighborBG.add(stepRB);
			neighborBG.add(gaussianRB);
			nePanel.add(stepRB);
			nePanel.add(gaussianRB);
			ini3Panel.add(nePanel,"South");

			//ordering
			JPanel orderPanel = new JPanel();
			orderPanel.setLayout(new BorderLayout());
			JPanel leftoPanel = new JPanel();
			leftoPanel.setLayout(new GridLayout(3,1));
			JPanel rightoPanel = new JPanel();
			rightoPanel.setLayout(new GridLayout(3,1));
			Border orderTitled = BorderFactory.createTitledBorder(etched,"Training");
			orderPanel.setBorder(orderTitled);

			//steps
			JPanel stepsPanel = new JPanel();
			stepsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			stepsTF = new JTextField(5);
			stepsPanel.add(stepsTF);
			stepsPanel.add(new JLabel("Steps"));

			//lrate
			JPanel lratePanel = new JPanel();
			lratePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			lrateTF = new JTextField(5);
			lratePanel.add(lrateTF);
			lratePanel.add(new JLabel("Learning-rate"));

			//radius
			JPanel radiusPanel = new JPanel();
			radiusPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			radiusTF = new JTextField(5);
			radiusPanel.add(radiusTF);
			radiusPanel.add(new JLabel("Radius"));

			//learning-rate function type
			JPanel lrateTypePanel = new JPanel();
			lrateTypePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
			lrateTypeBG = new ButtonGroup();
			exponentialRB = new JRadioButton("Exponential",true);
			linearRB = new JRadioButton("Linear",false);
			inverseRB = new JRadioButton("Inverse time",false);
			lrateTypeBG.add(exponentialRB);
			lrateTypeBG.add(linearRB);
			lrateTypeBG.add(inverseRB);
			lrateTypePanel.add(exponentialRB);
			lrateTypePanel.add(linearRB);
			lrateTypePanel.add(inverseRB);

			lRateType.addElement(lrateTypeBG.getSelection().getActionCommand());

			//buttons
			JPanel buttonsPanel = new JPanel();
			buttonsPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
			prevB = new JButton("<");
			nextB = new JButton(">");
			addB = new JButton("+");
			delB = new JButton("-");
			currentL = new JLabel("1");
			totalL = new JLabel("1");
			buttonsPanel.add(currentL);
			buttonsPanel.add(new JLabel("/"));
			buttonsPanel.add(totalL);
			buttonsPanel.add(new JLabel(" "));
			buttonsPanel.add(prevB);
			buttonsPanel.add(addB);
			buttonsPanel.add(delB);
			buttonsPanel.add(nextB);

			leftoPanel.add(stepsPanel);
			leftoPanel.add(lratePanel);
			leftoPanel.add(radiusPanel);
			rightoPanel.add(new JLabel(" "));
			rightoPanel.add(lrateTypePanel);
			rightoPanel.add(buttonsPanel);
			orderPanel.add(leftoPanel,"West");
			orderPanel.add(rightoPanel,"Center");
			center.add(orderPanel,"Center");

			//output filename
			JPanel oNamePanel = new JPanel();
			oNamePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			oNamePanel.add(new JLabel("Identifier: "));
			outputNameTF = new JTextField(15);
			oNamePanel.add(outputNameTF);

			//ouput file
			JPanel oPanel = new JPanel();
			oPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			oPanel.add(new JLabel("Folder: "));
			outputTF = new JTextField(30);
			outputTF.setEditable(false);
			oPanel.add(outputTF);
			outputBrowse = new JButton("Browse");
			oPanel.add(outputBrowse);

			//output type
			JPanel oTypePanel = new JPanel();
			xmlCB = new JCheckBox("XML",false);
			svgCB = new JCheckBox("SVG",false);
			pdfCB = new JCheckBox("PDF",false);
			oTypePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
			oTypePanel.add(new JLabel("Type: "));
			oTypePanel.add(xmlCB);
			oTypePanel.add(svgCB);
			oTypePanel.add(pdfCB);

			//output
			JPanel outputPanel = new JPanel();
			outputPanel.setLayout(new BorderLayout());
			outputPanel.add(oNamePanel,"North");
			outputPanel.add(oPanel,"Center");
			outputPanel.add(oTypePanel,"South");
			Border outputTitled = BorderFactory.createTitledBorder(etched,"Output");
			outputPanel.setBorder(outputTitled);
			add(outputPanel,"South");

			//action listener
			inputBrowse.addActionListener(this);
			outputBrowse.addActionListener(this);
			prevB.addActionListener(this);
			nextB.addActionListener(this);
			addB.addActionListener(this);
			delB.addActionListener(this);
			pdfCB.addItemListener(this);
		}

		public void itemStateChanged(ItemEvent ie)
		{
			Object cache = ie.getSource();
			if(pdfCB==cache)
			{
				if(pdfCB.isSelected())
				{
					//popup the pdf settings dialog
					activatePdfSettings();
				}
			}
		}

		/*
		 * Action resolver.
		*/
		public void actionPerformed(ActionEvent e)
		{
			Object cache = e.getSource();

			if(inputBrowse==cache)
			{
				//open input browse window
				if(openFile==null)
				{
					openFile = new JFileChooser();
					openFile.setDialogTitle("Select a data file");
					openFile.setFileFilter(filter);
					openFile.setFileSelectionMode(JFileChooser.FILES_ONLY);
				}
				openFile.showDialog(parent,"Select");
				try
				{
					if(!openFile.getSelectedFile().getName().endsWith(".xml"))
					{
						inputTF.setText("");
						openFile.setSelectedFile(null);
					}
					else
					{
						inputTF.setText(openFile.getSelectedFile().getName());
					}
				}
				catch(NullPointerException npe){}
			}
			if(outputBrowse==cache)
			{
				//open output browse window
				if(saveFolder==null)
				{
					saveFolder = new JFileChooser();
					saveFolder.setDialogTitle("Select an output folder");
					saveFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				}
				saveFolder.showDialog(parent,"Select");
				try
				{
					outputTF.setText(saveFolder.getSelectedFile().getAbsolutePath());
				}
				catch(NullPointerException npe){}
			}
			if(addB==cache)
			{
				totalCounter++;
				totalL.setText(""+totalCounter);
				save();
				steps.setSize(totalCounter);
				lrate.setSize(totalCounter);
				radius.setSize(totalCounter);
				lRateType.setSize(totalCounter);
				steps.insertElementAt("",currentCounter);
				lrate.insertElementAt("",currentCounter);
				radius.insertElementAt("",currentCounter);
				lRateType.setElementAt("exponential",currentCounter);
				currentCounter++;
				present();
			}
			if(delB==cache)
			{
				if(totalCounter>=2)
				{
					totalCounter--;
					totalL.setText(""+totalCounter);
					steps.remove(currentCounter-1);
					lrate.remove(currentCounter-1);
					radius.remove(currentCounter-1);
					lRateType.remove(currentCounter-1);
					steps.setSize(totalCounter);
					lrate.setSize(totalCounter);
					radius.setSize(totalCounter);
					lRateType.setSize(totalCounter);
					if(currentCounter==(totalCounter+1))
					{
						currentCounter--;
					}
					present();
				}
			}
			if(nextB==cache)
			{
				if(currentCounter<totalCounter)
				{
					save();
					currentCounter++;
					present();
				}
			}
			if(prevB==cache)
			{
				if(currentCounter>1)
				{
					save();
					currentCounter--;
					present();
				}
			}
		}

		/*
		 * Saves the current values into Vectors.
		*/
		private void save()
		{
			String button = "";
			steps.setElementAt(stepsTF.getText(),currentCounter-1);
			lrate.setElementAt(lrateTF.getText(),currentCounter-1);
			radius.setElementAt(radiusTF.getText(),currentCounter-1);
			if(exponentialRB.isSelected())
			{
				button = "exponential";
			}
			else if(linearRB.isSelected())
			{
				button = "linear";
			}
			else //inverse
			{
			 	button = "inverse";
			}
			lRateType.setElementAt(button,currentCounter-1);
		}

		/*
		 * Presents the next or previous values.
		*/
		private void present()
		{
			String button = lRateType.elementAt(currentCounter-1).toString();
			stepsTF.setText(steps.elementAt(currentCounter-1).toString());
			lrateTF.setText(lrate.elementAt(currentCounter-1).toString());
			radiusTF.setText(radius.elementAt(currentCounter-1).toString());
			if(button.equals("exponential"))
			{
				exponentialRB.setSelected(true);
			}
			else if(button.equals("linear"))
			{
				linearRB.setSelected(true);
			}
			else //inverse
			{
				inverseRB.setSelected(true);
			}

			currentL.setText(""+currentCounter);
		}
	}

	/*********************************************************************************/

	/*
	 * Excecute Panel.
	*/
	private class ExecutePanel extends JPanel implements ActionListener
	{
		private JButton pButton;

		/*
		 * Main constructor.
		*/
		public ExecutePanel()
		{
			setLayout(new BorderLayout());
			Border etched = BorderFactory.createEtchedBorder();

			//Proceed button
			JPanel bPanel = new JPanel();
			bPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
			pButton = new JButton("Proceed");
			bPanel.add(pButton);
			add(bPanel,"South");

			//status text area
			textArea = new JTextArea("");
			JScrollPane tPanel = new JScrollPane(textArea);
			Border statusTitled = BorderFactory.createTitledBorder(etched,"Report");
			tPanel.setBorder(statusTitled);
			textArea.setEditable(false);
			textArea.setBackground(tPanel.getBackground());
			add(tPanel,"Center");

			//action listener
			pButton.addActionListener(this);
		}

		/*
		 * Action resolver.
		*/
		public void actionPerformed(ActionEvent e)
		{
			/* Proceed button */
			if(pButton==e.getSource())
			{
				if(instructionSettings)
				{
					area += "\n";
					area += "Constructing the map, please wait! \n";
					textArea.setText(area);

					/* Map creation */
					JSom sommi = new JSom(row);
					if(sommi.anyExceptions())
					{
						area += "\n";
						area += "An error has occured! Construction aborted! \n";
						textArea.setText(area);
					}
					else
					{
						area += "\n";
						area += "Map creation succesful! \n";
						textArea.setText(area);
					}
				}
			}
		}
	}

	/*********************************************************************************/

	/*
	 * FileFilter for Clusoe
	*/
	private class InputFileFilter extends FileFilter
	{

		/*
		 * Acception check.
		*/
		public boolean accept(File f)
		{
			if(f != null)
			{
			  if(f.isDirectory())
				{
					return true;
				}
			  if(f.isFile())
			  {
					String extension = getExtension(f);
			  	if(extension.equals("xml"))
			  	{
						return true;
			  	}
			  }
			}
			return false;
		}

		/*
		 * Returns human readable version of this filter.
		*/
		public String getDescription()
		{
			return "XML data Files (*.xml)";
		}

		/*
		 * Parses the extension from the file name.
		*/
		public String getExtension(File f)
		{
			if(f != null)
			{
				String filename = f.getName();
				int i = filename.lastIndexOf('.');
				if(i>0 && i<(filename.length()-1))
				{
					return filename.substring(i+1).toLowerCase();
				}
			}
			return "";
    }
	}

	/*********************************************************************************/

	/*
	 * PDF settings dialog.
	*/
	private class PdfSettingsDialog extends JDialog implements ActionListener
	{
		private JPanel mainP;
		private JButton closeB;

		/*
		 * Constructor.
		*/
		public PdfSettingsDialog(JFrame parent,Dimension screenSize)
		{
			super(parent,"PDF Paper Settings",true);
			setResizable(false);
			int width =275, height = 150;
			setSize(width,height);
			setLocation((screenSize.width-width)/2,(screenSize.height-height)/2);
			Border etched = BorderFactory.createEtchedBorder();

			//main panel
			mainP = new JPanel();
			mainP.setLayout(new GridLayout(1,2));
			getContentPane().add(mainP,"Center");

			//paper
			JPanel paperP = new JPanel();
			paperP.setLayout(new GridLayout(2,1));
			Border paperTitled = BorderFactory.createTitledBorder(etched,"Size");
			paperP.setBorder(paperTitled);
			JPanel paperP2 = new JPanel();
			paperP2.setLayout(new FlowLayout(FlowLayout.LEFT));
			paperP2.add(paperCB);
			paperP.add(paperP2);
			textL = new JLabel("(297mm x 210 mm)");
			JPanel paperP3 = new JPanel();
			paperP3.setLayout(new FlowLayout(FlowLayout.LEFT));
			paperP3.add(textL);
			paperP.add(paperP3);
			mainP.add(paperP);

			//orientation
			JPanel orienP = new JPanel();
			orienP.setLayout(new GridLayout(2,1));
			pdfBG = new ButtonGroup();
			pdfBG.add(portraitRB);
			pdfBG.add(landscapeRB);
			Border orienTitled = BorderFactory.createTitledBorder(etched,"Orientation");
			orienP.setBorder(orienTitled);
			JPanel orienP2 = new JPanel();
			orienP2.setLayout(new FlowLayout(FlowLayout.LEFT));
			orienP2.add(portraitRB);
			JPanel orienP3 = new JPanel();
			orienP3.setLayout(new FlowLayout(FlowLayout.LEFT));
			orienP3.add(landscapeRB);
			orienP.add(orienP2);
			orienP.add(orienP3);
			mainP.add(orienP);

			//close button panel
			JPanel buttonsP = new JPanel();
			buttonsP.setLayout(new FlowLayout(FlowLayout.CENTER));
			closeB = new JButton("Ok");
			buttonsP.add(closeB);
			getContentPane().add(buttonsP,"South");

			//action listeners
			closeB.addActionListener(this);
			portraitRB.addActionListener(this);
			landscapeRB.addActionListener(this);
			paperCB.addActionListener(this);
		}

		/*
		 * Actions.
		*/
		public void actionPerformed(ActionEvent ae)
		{
			Object cache = ae.getSource();
			if(closeB==cache)
			{
				setVisible(false);
			}
			if(portraitRB==cache)
			{
				if(((String)paperCB.getSelectedItem()).equals("A4"))
				{
					textL.setText("(297mm x 210mm)");
				}
				else //Letter
				{
					textL.setText("(279mm x 216mm)");
				}
			}
			if(landscapeRB==cache)
			{
				if(((String)paperCB.getSelectedItem()).equals("A4"))
				{
					textL.setText("(210mm x 297mm)");
				}
				else //Letter
				{
					textL.setText("(216mm x 279mm)");
				}
			}
			if(paperCB==cache)
			{
				if(((String)paperCB.getSelectedItem()).equals("A4"))
				{
					if(portraitRB.isSelected())
					{
						textL.setText("(297mm x 210mm)");
					}
					else
					{
						textL.setText("(210mm x 297mm)");
					}
				}
				else //Letter
				{
					if(portraitRB.isSelected())
					{
						textL.setText("(279mm x 216mm)");
					}
					else
					{
						textL.setText("(216mm x 279mm)");
					}
				}
			}
		}
	}

	/*********************************************************************************/

}

⌨️ 快捷键说明

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