📄 observationdescriptiondialog.java
字号:
/* jahmm package - v0.3.1 *//* * Copyright (c) 2004, Jean-Marc Francois. * * This file is part of Jahmm. * Jahmm is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Jahmm is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jahmm; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package be.ac.ulg.montefiore.run.jahmm.apps;import java.text.*;import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;/* * Observation type (integer or vector) and dimension. */public class ObservationDescriptionDialog extends JDialog implements ActionListener { final private JButton okButton; final private JButton cancelButton; final private JSpinner spinner; final private JComboBox typesComboBox; final private int[] types; final private String[] descriptions; private int type = -1; private int dimension; // Describes observations type : integer/vector and dimension public class ObservationDescription { final public int type; final public int dimension; public ObservationDescription(int type, int dimension) { this.type = type; this.dimension = dimension; } } public ObservationDescriptionDialog() { super(new JFrame(), "Select observations type", true); spinner = new JSpinner(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1)); types = new int[] { ObservationSequences.INTEGER, ObservationSequences.VECTOR }; descriptions = new String[types.length]; for (int i = 0; i < types.length; i++) descriptions[i] = ObservationSequences.describeType(types[i]); typesComboBox = new JComboBox(descriptions); JLabel messageLabel = new JLabel("Describe the observations properties:"); JLabel spinnerLabel = new JLabel("Max value/Vector dimension"); spinnerLabel.setHorizontalAlignment(SwingConstants.RIGHT); spinnerLabel.setLabelFor(spinner); JLabel typesLabel = new JLabel("Observations type"); typesLabel.setHorizontalAlignment(SwingConstants.RIGHT); typesLabel.setLabelFor(typesComboBox); JPanel mainPanel = new JPanel(new GridLayout(2,2)); mainPanel.add(typesLabel); mainPanel.add(typesComboBox); mainPanel.add(spinnerLabel); mainPanel.add(spinner); okButton = new JButton("Ok"); cancelButton = new JButton("Cancel"); okButton.addActionListener(this); cancelButton.addActionListener(this); JPanel buttonsPanel = new JPanel(new GridLayout(1,1)); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); getContentPane().add(messageLabel, BorderLayout.NORTH); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(buttonsPanel, BorderLayout.SOUTH); setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); setResizable(false); } public int type() { return type; } public int dimension() { return dimension; } public ObservationDescription describe() { return new ObservationDescription(type, dimension); } /** * Ok/Cancel button pressed. */ public void actionPerformed(ActionEvent e) { if (e.getSource().equals(okButton)) { try { spinner.commitEdit(); } catch(ParseException pe) { throw new RuntimeException("Internal error"); } type = Arrays.asList(descriptions). indexOf(typesComboBox.getSelectedItem()); dimension = (Integer) spinner.getValue(); } if (e.getSource().equals(cancelButton)) type = -1; setVisible(false); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -