📄 uisymboldialog.java
字号:
/* * @(#) UIMainFrame.java 1.10 10/09/02 * * Copyright ***, All Rights Reserved. * * This software is the proprietary information of ******** * Use is subject to license terms. * */// import java packages//import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.table.*;import javax.swing.event.*;import javax.swing.AbstractButton.*;import java.util.*;/** * This class is to display the symbol list for a certain level * @version 1.00 */public class UISymbolDialog extends JDialog implements ActionListener, ListSelectionListener, ChangeListener{ //----------------------------------------------------------------- // // static data members // //----------------------------------------------------------------- //----------------------------------------------------------------- // // instance data members // //----------------------------------------------------------------- // must init outside of the dialog // public Vector level_symbols_d = new Vector(); public String level_name_d = new String(); public String selected_string_d = new String(); // the main panel // JPanel jMainPane = new JPanel(); // four panels on the main pane // JPanel jTopPane = new JPanel(); JPanel jSymbolPane = new JPanel(); JPanel jCheckPane = new JPanel(); JPanel jBottomPane = new JPanel(); // components on the top pane // JLabel jLevelName = new JLabel(); // components on the symbol pane // LevelSymbolModel symbols_in_level_d = new LevelSymbolModel(); JTable jLevelSymbols = new JTable( symbols_in_level_d ); JScrollPane jScrollPane1 = new JScrollPane(); JPanel jTablePanel = new JPanel(); // components on the check pane // JCheckBox jCheckBoxNonSpeech = new JCheckBox(); JCheckBox jCheckBoxContextLess = new JCheckBox(); JCheckBox jCheckBoxDummy = new JCheckBox(); JCheckBox jCheckBoxSkip = new JCheckBox(); JCheckBox jCheckBoxExclude = new JCheckBox(); JCheckBox jCheckBoxST = new JCheckBox(); JPanel jSymbolPropPane = new JPanel(); // components on the bottom pane // JTextField jTextFieldAddedSymbol = new JTextField(); JButton jButtonAdd = new JButton(); JButton jButtonDelete = new JButton(); JButton jButtonApply = new JButton(); JButton jButtonOK = new JButton(); JButton jButtonCancel = new JButton(); GridBagLayout gridBagLayout1 = new GridBagLayout(); // borders // Border border2; Border border3; public UISymbolDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); } public UISymbolDialog() { this(null, "", false); } /** * init everything for a dialog * * @return void */ public void initAll(){ try { jbInit(); pack(); } catch(Exception ex) { ex.printStackTrace(); } } private void jbInit() throws Exception { // add the main panel // jMainPane.setPreferredSize(new Dimension(350, 400)); jMainPane.setLayout(gridBagLayout1); jTopPane.setPreferredSize(new Dimension(350, 50)); jSymbolPane.setPreferredSize(new Dimension(175, -1)); jCheckPane.setPreferredSize(new Dimension(175, -1)); jBottomPane.setPreferredSize(new Dimension(350, 50)); // add four panels // jMainPane.add(jTopPane, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0)); jMainPane.add(jSymbolPane, new GridBagConstraints(0, 1, 1, 1, 0.5, 0.65, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 5), 0, 0)); jMainPane.add(jCheckPane, new GridBagConstraints(1, 1, 1, 1, 0, 0.65, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 5), 0, 0)); jMainPane.add(jBottomPane, new GridBagConstraints(0, 2, 2, 1, 1.0, 0.1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 10, 0), 0, 0)); // add components on top panel // jTopPane.setLayout(new FlowLayout(FlowLayout.LEFT)); jTopPane.add(jLevelName); String curr_level_name = "Level Name: "; jLevelName.setText(curr_level_name + level_name_d); // add components on the symbol panel // jSymbolPane.setLayout(new BorderLayout()); jSymbolPane.add(jTablePanel); //jLevelSymbols.setPreferredSize(new Dimension(175, -1)); border3 = BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(Color.black,1),"Symbol Table"),BorderFactory.createEmptyBorder(1,1,1,1)); jTablePanel.setBorder(border3); jTablePanel.setLayout(new BorderLayout()); jTablePanel.add(jScrollPane1, null); jScrollPane1.getViewport().add(jLevelSymbols, null); // add components on the check panel // //jCheckPane.setLayout(new FlowLayout(FlowLayout.CENTER)); jCheckPane.setLayout(new BorderLayout()); border2 = BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(Color.black,1),"Symbol Type"),BorderFactory.createEmptyBorder(1,1,1,1)); jCheckPane.setBorder(border2); jCheckBoxNonSpeech.setText("non-speech"); jCheckBoxContextLess.setText("context-less "); jCheckBoxDummy.setText("dummy"); jCheckBoxSkip.setText("skip"); jCheckBoxExclude.setText("exclude"); jCheckBoxST.setText("attach statistical"); // add listener // jCheckBoxNonSpeech.addChangeListener(this); jCheckBoxContextLess.addChangeListener(this); jCheckBoxDummy.addChangeListener(this); jCheckBoxSkip.addChangeListener(this); jCheckBoxExclude.addChangeListener(this); jCheckBoxST.addChangeListener(this); Box b = Box.createVerticalBox(); b.setAlignmentX((float)0.5); b.setAlignmentY((float)0.5); //b.setPreferredSize(new Dimension(150, 200)); jCheckPane.add(b); b.add(jCheckBoxNonSpeech); b.add(jCheckBoxContextLess); b.add(jCheckBoxDummy); b.add(jCheckBoxSkip); b.add(jCheckBoxExclude); b.add(jCheckBoxST); // add components on the check panel // jBottomPane.setLayout(new FlowLayout(FlowLayout.CENTER)); jButtonAdd.setText("Add"); jButtonDelete.setText("Delete"); jButtonApply.setText("Apply"); jButtonOK.setText("OK"); jButtonCancel.setText("Cancel"); jBottomPane.add(jTextFieldAddedSymbol); jBottomPane.add(jButtonAdd); jBottomPane.add(jButtonDelete); jBottomPane.add(jButtonApply); jBottomPane.add(jButtonOK); jBottomPane.add(jButtonCancel); jButtonAdd.addActionListener(this); jButtonDelete.addActionListener(this); jButtonApply.addActionListener(this); jButtonOK.addActionListener(this); jButtonCancel.addActionListener(this); jTextFieldAddedSymbol.setPreferredSize(new Dimension(120, 24)); jButtonAdd.setPreferredSize(new Dimension(80, 24)); jButtonDelete.setPreferredSize(new Dimension(80, 24)); jButtonApply.setPreferredSize(new Dimension(80, 24)); jButtonOK.setPreferredSize(new Dimension(80, 24)); jButtonCancel.setPreferredSize(new Dimension(80, 24)); // add listener // ListSelectionModel model = jLevelSymbols.getSelectionModel(); model.addListSelectionListener(this); // add the main pain // getContentPane().add(jMainPane); } /** * handle the event when a button is clicked * * @param e the button event * @return void */ public void actionPerformed(ActionEvent e) { // decide which button is clicked // if(e.getSource() == jButtonAdd) { String added_text = jTextFieldAddedSymbol.getText(); if ( added_text.length() != 0){ if ( level_symbols_d.indexOf(added_text) < 0){ level_symbols_d.add( added_text ); symbols_in_level_d.fireTableDataChanged(); } } } if(e.getSource() == jButtonDelete) { int i = jLevelSymbols.getSelectedRow(); int j = jLevelSymbols.getSelectedColumn(); String selected_string = (String)jLevelSymbols.getValueAt(i , j); if ( selected_string != null){ level_symbols_d.remove( selected_string ); symbols_in_level_d.fireTableDataChanged(); } } if(e.getSource() == jButtonOK) { SearchLevel curr_level = CData.getCurrLevel(); curr_level.symbols_d = level_symbols_d; curr_level.level_name_d = level_name_d; dispose(); CData.symbol_dlg_d = null; } if(e.getSource() == jButtonApply) { SearchLevel curr_level = CData.getCurrLevel(); curr_level.symbols_d = level_symbols_d; curr_level.level_name_d = level_name_d; } if(e.getSource() == jButtonCancel) { dispose(); CData.symbol_dlg_d = null; } CData.getCurrLevel().sortSymbols(); } /** * handle the event on check boxes * * @param e the mouse event * @return void */ public void stateChanged(ChangeEvent e) { // if the user click on the symbol list // int i = jLevelSymbols.getSelectedRow(); int j = jLevelSymbols.getSelectedColumn(); int count = jLevelSymbols.getSelectedRowCount(); //if ( i >= 0 && j >= 0 ){ for (int end = i + count; i >= 0 && j >= 0 && i < end ; i++ ){ String selected_string = (String)jLevelSymbols.getValueAt(i,j); SearchLevel curr_level = CData.getCurrLevel(); // non-speech symbols // if ( (JCheckBox)e.getSource() == jCheckBoxNonSpeech ){ if ( curr_level.isNonSpeechSymbol(selected_string) ){ if ( !jCheckBoxNonSpeech.isSelected() ){ curr_level.non_speech_d.remove(selected_string); } } else { if ( jCheckBoxNonSpeech.isSelected() ){ curr_level.non_speech_d.add(selected_string); } } } // contextless symbols // if ( (JCheckBox)e.getSource() == jCheckBoxContextLess ){ if ( curr_level.isContextLessSymbol(selected_string) ){ if ( !jCheckBoxContextLess.isSelected() ){ curr_level.contextless_d.remove(selected_string); } } else { if ( jCheckBoxContextLess.isSelected() ){ curr_level.contextless_d.add(selected_string); } } } // skip symbols // if ( (JCheckBox)e.getSource() == jCheckBoxSkip ){ if ( curr_level.isSkipSymbol(selected_string) ){ if ( !jCheckBoxSkip.isSelected() ){ curr_level.skip_d.remove(selected_string); } } else { if ( jCheckBoxSkip.isSelected() ){ curr_level.skip_d.add(selected_string); } } } // exclude symbols // if ( (JCheckBox)e.getSource() == jCheckBoxExclude ){ if ( curr_level.isExcludeSymbol(selected_string) ){ if ( !jCheckBoxExclude.isSelected() ){ curr_level.exclude_d.remove(selected_string); } } else { if ( jCheckBoxExclude.isSelected() ){ curr_level.exclude_d.add(selected_string); } } } // dummy symbols // if ( (JCheckBox)e.getSource() == jCheckBoxDummy ){ if ( curr_level.isDummySymbol(selected_string) ){ if ( !jCheckBoxDummy.isSelected() ){ curr_level.dummy_d.remove(selected_string); } } else { if ( jCheckBoxDummy.isSelected() ){ curr_level.dummy_d.add(selected_string); } } } // ST symbols // if ( (JCheckBox)e.getSource() == jCheckBoxST ){ if ( curr_level.isSTSymbol(selected_string) ){ if ( !jCheckBoxST.isSelected() ){ curr_level.ST_d.remove(selected_string); } } else { if ( jCheckBoxST.isSelected() ){ curr_level.ST_d.add(selected_string); } } } } } /** * handle the event when a command is issued * * @param e the mouse event * @return void */ public void valueChanged(ListSelectionEvent e) { // if the user click on the symbol list // int i = jLevelSymbols.getSelectedRow(); int j = jLevelSymbols.getSelectedColumn(); if ( i >= 0 && j >= 0 ){ //for (int end = j + count; i >= 0 && j >= 0 && (j < end); j++ ){ String selected_string = (String)jLevelSymbols.getValueAt(i,j); SearchLevel curr_level = CData.getCurrLevel(); // non-speech symbols // if ( curr_level.isNonSpeechSymbol(selected_string) ){ jCheckBoxNonSpeech.setSelected(true); } else { jCheckBoxNonSpeech.setSelected(false); } // ContextLess symbols // if ( curr_level.isContextLessSymbol(selected_string) ){ jCheckBoxContextLess.setSelected(true); } else { jCheckBoxContextLess.setSelected(false); } // skip symbols // if ( curr_level.isSkipSymbol(selected_string) ){ jCheckBoxSkip.setSelected(true); } else { jCheckBoxSkip.setSelected(false); } // exclude symbols // if ( curr_level.isExcludeSymbol(selected_string) ){ jCheckBoxExclude.setSelected(true); } else { jCheckBoxExclude.setSelected(false); } // dummy symbols // if ( curr_level.isDummySymbol(selected_string) ){ jCheckBoxDummy.setSelected(true); } else { jCheckBoxDummy.setSelected(false); } // ST symbols // if ( curr_level.isSTSymbol(selected_string) ){ jCheckBoxST.setSelected(true); } else { jCheckBoxST.setSelected(false); } } } // define a inner class NodeSymbolModel // class LevelSymbolModel extends AbstractTableModel { final String[] columnNames = {"Symbol Name"}; public int getColumnCount() { return columnNames.length; } public int getRowCount() { return level_symbols_d.size(); } public String getColumnName(int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { return level_symbols_d.get(row); } public void setValueAt(Object aValue, int row, int col) { level_symbols_d.set(row, aValue.toString()); } public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } public boolean isCellEditable(int row, int col) { return false; } } // end of class LevelSymbolModel}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -