?? differentialwizard1.java
字號:
package cdt.projects.tree.wizards.diffdx;import javax.swing.*;import javax.swing.border.Border;import javax.swing.border.TitledBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import cdt.gui.HTMLTextPane;import cdt.projects.Project;import cdt.projects.tree.nodes.Hold;import cdt.projects.tree.nodes.Item;import cdt.projects.tree.nodes.Node;import cdt.projects.tree.nodes.Wizard;import cdt.wizard.WizardFrame;/** * Initiates a wizard to configure the differential diagnosises in an interactive case. */public class DifferentialWizard1 extends WizardFrame implements ActionListener { /** The parent frame to this wizard. */ private JFrame parent; /** * The {@link cdt.gui.HTMLTextPane HTMLTextPane} containing * the text of the differential diagnosis feedback. */ private HTMLTextPane diffDiagText; /** * The {@link cdt.gui.HTMLTextPane HTMLTextPane} containing * the text of the final diagnosis feedback. */ private HTMLTextPane finalDiagText; /** The JList containing the diagnoses. */ private JList diagnosesList; /** The name of the correct diagnosis. */ private int correctDiagnosis; /** Hashtable where the key is the diffDiag node, and the value is the finalDiag node. */ private HashMap diagnoses; /** JPanel containing the diagnosis information. */ private JPanel diagnosisPanel; /** * Creates the differential diagnosis wizard. * * @param parent The parent JFrame, in this case typically an instance of * {@link cdt.Frame1 Frame1}. */ public DifferentialWizard1(JFrame parent) { super(parent); this.parent = parent; this.diagnoses = new HashMap(); this.correctDiagnosis = -1; Hold diffDiagFolder = (Hold)this.data.get("diffDiagFolder"); Hold finalDiagFolder = (Hold)this.data.get("finalDiagFolder"); Enumeration enum = diffDiagFolder.children(); while(enum.hasMoreElements()) { Node diagNode = (Node)enum.nextElement(); Node finalDiagNode = null; if(diagNode instanceof Item) { finalDiagNode = Node.findChildNode(finalDiagFolder, diagNode.getName()); if(null == finalDiagNode) { finalDiagNode = new Item(diagNode.getName()); } this.diagnoses.put(diagNode, finalDiagNode); } } init(); } /** * Sets up the layout of this page. */ public void customize() { showPreviousButton(true); showFinishButton(true); showNextButton(false); setTitle("Differential Diagnosis Wizard"); Dimension dim; // Sets up a JList of the diagnoses Iterator iter = this.diagnoses.keySet().iterator(); DefaultListModel listModel = new DefaultListModel(); while(iter.hasNext()) { String diagnosisName = ((Node)iter.next()).getName(); listModel.addElement(diagnosisName); } this.diagnosesList = new JList(listModel); this.diagnosesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.diagnosesList.addListSelectionListener(new DiagnosisSelectionListener()); // Puts the list into a JScrollPane dim = new Dimension(120, 150); JScrollPane scrollPane = new JScrollPane(this.diagnosesList); scrollPane.setMaximumSize(dim); scrollPane.setPreferredSize(dim); scrollPane.setMinimumSize(dim); // Puts the diagnosis list's scrollpane in a JPanel with the [ + ] and [ - ] buttons JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS)); leftPanel.add(scrollPane); leftPanel.add(Box.createVerticalStrut(5)); JButton plus = new JButton("Add Diagnosis"); plus.addActionListener(this); dim = new Dimension(135, 30); plus.setMaximumSize(dim); plus.setMinimumSize(dim); plus.setPreferredSize(dim); JPanel temp = new JPanel(); temp.add(plus); leftPanel.add(temp); JButton minus = new JButton("Remove Diagnosis"); minus.addActionListener(this); temp = new JPanel(); dim = new Dimension(135, 30); minus.setMaximumSize(dim); minus.setMinimumSize(dim); minus.setPreferredSize(dim); temp.add(minus); leftPanel.add(temp); // Creates the HTMLTextPane for the Differential Diagnosis text this.diffDiagText = new HTMLTextPane(this.parent, ""); this.diffDiagText.setEditable(false); this.diffDiagText.setBackground(Color.lightGray); dim = new Dimension(360, 120); JScrollPane diffDiagScrollPane = new JScrollPane(this.diffDiagText); diffDiagScrollPane.setPreferredSize(dim); diffDiagScrollPane.setMinimumSize(dim); diffDiagScrollPane.setMaximumSize(dim); Border b = BorderFactory.createLineBorder(Color.darkGray); b = BorderFactory.createTitledBorder(b, "Differential Diagnosis Feedback"); ((TitledBorder)b).setTitleJustification(TitledBorder.CENTER); diffDiagScrollPane.setBorder(b); // Creates the HTMLTextPane for the Final Diagnosis text this.finalDiagText = new HTMLTextPane(this.parent, ""); this.finalDiagText.setEditable(false); this.finalDiagText.setBackground(Color.lightGray); dim = new Dimension(360, 120); JScrollPane finalDiagScrollPane = new JScrollPane(this.finalDiagText); finalDiagScrollPane.setPreferredSize(dim); finalDiagScrollPane.setMinimumSize(dim); finalDiagScrollPane.setMaximumSize(dim); b = BorderFactory.createLineBorder(Color.darkGray); b = BorderFactory.createTitledBorder(b, "Final Diagnosis Feedback"); ((TitledBorder)b).setTitleJustification(TitledBorder.CENTER); finalDiagScrollPane.setBorder(b); // Creates the panel containing the check box, and the two HTMLTextPanes this.diagnosisPanel = new JPanel(); this.diagnosisPanel.setLayout(new BoxLayout(this.diagnosisPanel, BoxLayout.Y_AXIS)); this.diagnosisPanel.add(diffDiagScrollPane); this.diagnosisPanel.add(finalDiagScrollPane); setupBorder(this.diagnosisPanel, "No Diagnosis Selected"); // Organizes the main panel JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS)); mainPanel.add(leftPanel); mainPanel.add(Box.createHorizontalStrut(5)); mainPanel.add(new JSeparator(JSeparator.VERTICAL)); mainPanel.add(Box.createHorizontalStrut(5)); mainPanel.add(this.diagnosisPanel); centerPanel.add(mainPanel); pack(); } /** * Sets up an HTMLEditorKit with the appropriate border. * * @param c The component to put the border onto. * @param title The title for the border. */ private void setupBorder(JComponent c, String title) { TitledBorder b = BorderFactory.createTitledBorder(title); b.setTitleJustification(TitledBorder.CENTER); c.setBorder(b); } /** * Moves to the next page in the wizard. */ public void nextAction() { } /** * A button has been pressed. */ public void actionPerformed(ActionEvent e) { // Adds a diagnosis if(e.getActionCommand().equals("Add Diagnosis")) { String name = JOptionPane.showInputDialog(this, "Please enter name of a new diagnosis."); if(null != name && false == name.equals("")) { // Makes sure this is a valid name boolean badName = false; if(name.endsWith(" **")) { cdt.ErrorD.ErrorDlg.ErrorMsg("Invalid diagnosis name."); badName = true; } else { Iterator iter = diagnoses.keySet().iterator(); boolean alreadyExists = false; while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(name)) { alreadyExists = true; break; } } if(alreadyExists) { cdt.ErrorD.ErrorDlg.ErrorMsg("There is already a diagnosis with this name."); badName = true; } } if(badName) { return; } // Disables any ChoiceSelectionListeners on the diagnosisList to prevent // unwanted behavior ListSelectionListener listListeners[] = diagnosesList.getListSelectionListeners(); for(int i = 0; i < listListeners.length; ++i) { if(listListeners[i] instanceof DiagnosisSelectionListener) { ((DiagnosisSelectionListener)listListeners[i]).setActive(false); } }// final int selectedIndex = this.diagnosesList.getSelectedIndex(); DefaultListModel listModel = (DefaultListModel)diagnosesList.getModel(); listModel.addElement(name); diagnosesList.setModel(listModel);// diagnosesList.setSelectedIndex(selectedIndex);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -