?? differentialwizard1.java
字號:
// Adds a new diagnosis Item nodes to the diagnoses HashMap diagnoses.put(new Item(name), new Item(name)); // Re-enables any ChoiceSelectionListeners that were disabled during the // execution of this method. for(int i = 0; i < listListeners.length; ++i) { if(listListeners[i] instanceof DiagnosisSelectionListener) { ((DiagnosisSelectionListener)listListeners[i]).setActive(true); } } diagnosesList.setSelectedIndex(listModel.getSize()-1); } } // Removes a diagnosis else if(e.getActionCommand().equals("Remove Diagnosis")) { final int selectedIndex = this.diagnosesList.getSelectedIndex(); if(correctDiagnosis == selectedIndex) { correctDiagnosis = -1; } DefaultListModel listModel = new DefaultListModel(); ListModel oldList = diagnosesList.getModel(); for(int i = 0; i < oldList.getSize(); ++i) { if(i != selectedIndex) { listModel.addElement(oldList.getElementAt(i)); } else { Iterator iter = diagnoses.keySet().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(oldList.getElementAt(i))) { iter.remove(); break; } } } } diagnosesList.setModel(listModel); if(selectedIndex < correctDiagnosis) { correctDiagnosis -= 1; } if(selectedIndex < listModel.size()) { diagnosesList.setSelectedIndex(selectedIndex); } else { diffDiagText.setText(""); diffDiagText.setEditable(false); finalDiagText.setText(""); finalDiagText.setEditable(false); diffDiagText.setBackground(Color.lightGray); finalDiagText.setBackground(Color.lightGray); setupBorder(diagnosisPanel, "No Diagnosis Selected"); } } } /** * Saves whatever data is in the currently open {@link cdt.gui.HTMLTextPane HTMLTextPane's}. */ private final void saveDiagnosis() { final int selectedChoice = this.diagnosesList.getSelectedIndex(); if(-1 != selectedChoice) { String selectedDiagnosis = (String)diagnosesList.getModel().getElementAt(selectedChoice); if(selectedDiagnosis.endsWith(" **")) { selectedDiagnosis = selectedDiagnosis.substring(0, selectedDiagnosis.length()-3); } // Saves the text for the differential diagnosis. Iterator iter = diagnoses.keySet().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(selectedDiagnosis)) { n.setData(diffDiagText.getText()); break; } } // Saves the text for the final diagnosis iter = diagnoses.values().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(selectedDiagnosis)) { n.setData(finalDiagText.getText()); break; } } } } /** * Creates the differential diagnosis/final diagnosis and closes the wizard. */ public void finishAction() { saveDiagnosis(); Hold diffDiagFolder = (Hold)data.get("diffDiagFolder"); if(null != diffDiagFolder) { while(diffDiagFolder.getChildCount() > 0) { diffDiagFolder.remove(0); } Iterator iter = diagnoses.keySet().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); n.setFile(Node.foldername(n.getName()) + ".html"); diffDiagFolder.addNodeInto(n); } // Adds the wizard to the folder Wizard wiz = new Wizard(); wiz.setWizardType(Wizard.DIFFDX_WIZARD); wiz.setName("Modify differential diagnoses"); diffDiagFolder.addNodeInto(wiz); } Hold finalDiagFolder = (Hold)data.get("finalDiagFolder"); if(null != finalDiagFolder) { // Clears the finalDiagFolder of any files inside it while(finalDiagFolder.getChildCount() > 0) { finalDiagFolder.remove(0); } Iterator iter = diagnoses.values().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); n.setFile(Node.foldername(n.getName()) + ".html"); finalDiagFolder.addNodeInto(n); } Wizard wiz = new Wizard(); wiz.setWizardType(Wizard.DIFFDX_WIZARD); wiz.setName("Modify differential diagnoses"); finalDiagFolder.addNodeInto(wiz); } Project.currentProject.getTree().updateUI(); // Cleans up everything and closes the wizard super.finishAction(); } /** * Changes the text in the editor according to what choice is selected. */ private class DiagnosisSelectionListener implements ListSelectionListener { /** The currently 'selected' choice's index. */ private int currentSelection; /** Whether this listener is currently listening. */ private boolean isActive; /** * Creates a ChoiceSelectionListener that will affect a JTextComponent. */ public DiagnosisSelectionListener() { this.isActive = true; this.currentSelection = -1; } public boolean isActive() { return this.isActive; } public void setActive(boolean isActive) { this.isActive = isActive; } /** * Fired when an item in the registered list is selected. * * @param e The ListSelectionEvent that describes the selection. */ public synchronized void valueChanged(ListSelectionEvent e) { if(false == isActive() || e.getValueIsAdjusting()) { return; } final JList diagnosisList = (JList)e.getSource(); final int newIndex = diagnosisList.getSelectedIndex(); if(newIndex == this.currentSelection ) { // The selection hasn't changed, so don't do anything return; } else if(newIndex == -1) { this.currentSelection = -1; return; } String nextSelectedDiagnosis = (String)diagnosisList.getModel().getElementAt(newIndex); if(nextSelectedDiagnosis.endsWith(" **")) { nextSelectedDiagnosis = nextSelectedDiagnosis.substring(0, nextSelectedDiagnosis.length()-3); } // Saves the text from the previously selected answer if(-1 != this.currentSelection) { String selectedDiagnosis = (String)diagnosesList.getModel().getElementAt(this.currentSelection); if(selectedDiagnosis.endsWith(" **")) { selectedDiagnosis = selectedDiagnosis.substring(0, selectedDiagnosis.length()-3); } // Saves the text for the differential diagnosis. Iterator iter = diagnoses.keySet().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(selectedDiagnosis)) { n.setData(diffDiagText.getText()); break; } } // Saves the text for the final diagnosis iter = diagnoses.values().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(selectedDiagnosis)) { n.setData(finalDiagText.getText()); break; } } } // Makes sure that the answerText and the feedbackText are // editable when an answer is selected from the list if(false == diffDiagText.isEditable()) { diffDiagText.setEditable(true); diffDiagText.setBackground(UIManager.getColor("controlLtHighlight")); } if(false == finalDiagText.isEditable()) { finalDiagText.setEditable(true); finalDiagText.setBackground(UIManager.getColor("controlLtHighlight")); } // Switches the text in the answerText and feedbackText to the // text corresponding to the answer that was selected Iterator iter = diagnoses.keySet().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(nextSelectedDiagnosis)) { diffDiagText.setText(n.getData()); break; } } iter = diagnoses.values().iterator(); while(iter.hasNext()) { Node n = (Node)iter.next(); if(n.getName().equals(nextSelectedDiagnosis)) { finalDiagText.setText(n.getData()); break; } } if(nextSelectedDiagnosis.endsWith(" **")) { nextSelectedDiagnosis = nextSelectedDiagnosis.substring(0, (nextSelectedDiagnosis.length()-3)); } setupBorder(diagnosisPanel, nextSelectedDiagnosis); this.currentSelection = newIndex; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -