/* * Copyright (C) 2014 Vinu K.N * * This program 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 3 of the License, or * (at your option) any later version. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ package org.domainmath.gui.pkgview.doc; import java.io.File; import java.util.ArrayList; import javax.swing.DefaultListModel; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import org.domainmath.gui.MainFrame; import org.domainmath.gui.help.QuickHelpPanel; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; /** * * @author Vinu K.N */ public class IndexPanel extends javax.swing.JPanel { private final MainFrame frame; private final QuickHelpPanel quickHelpPanel; private final File xmlFile; private Packages j; private final DefaultListModel model; /** * Creates new form IndexPanel */ public IndexPanel(MainFrame frame,QuickHelpPanel quickHelpPanel,File xmlFile) { model = new DefaultListModel(); initComponents(); this.frame=frame; this.quickHelpPanel = quickHelpPanel; this.xmlFile=xmlFile; j=new Packages(); loadXML(); setContent(); jList1.setSelectedIndex(0); AutoCompleteDecorator.decorate(this.jList1, this.searchTextField, ObjectToStringConverter.DEFAULT_IMPLEMENTATION); } private void loadXML(){ JAXBContext jaxbContext; try { jaxbContext = JAXBContext.newInstance(Packages.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); j = (Packages) jaxbUnmarshaller.unmarshal(xmlFile); } catch (JAXBException ex) { } } private void setContent() { ArrayList<Package> pkg = j.getPkg(); for(Package p:pkg){ ArrayList<Function> functions = p.getFunctions(); for(Function f:functions){ ArrayList<String> list = f.getList(); for(String s:list){ model.addElement(s); } } } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); searchTextField = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); jList1 = new javax.swing.JList(); jLabel1.setText("Type any word :"); searchTextField.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { searchTextFieldActionPerformed(evt); } }); jList1.setModel(model); jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { jList1ValueChanged(evt); } }); jScrollPane1.setViewportView(jList1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(searchTextField) .addContainerGap()) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(searchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged if(evt.getValueIsAdjusting()){ quickHelpPanel.generate(jList1.getSelectedValue().toString()); } }//GEN-LAST:event_jList1ValueChanged private void searchTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchTextFieldActionPerformed quickHelpPanel.generate(jList1.getSelectedValue().toString()); }//GEN-LAST:event_searchTextFieldActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JList jList1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField searchTextField; // End of variables declaration//GEN-END:variables }