Coverage Report - net.sf.jabref.wizard.integrity.gui.IntegrityMessagePanel
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegrityMessagePanel
45%
32/70
0%
0/14
2.222
IntegrityMessagePanel$IntegrityListRenderer
29%
5/17
0%
0/8
2.222
 
 1  
 /*
 2  
 Copyright (C) 2004 R. Nagel
 3  
 
 4  
 All programs in this directory and
 5  
 subdirectories are published under the GNU General Public License as
 6  
 described below.
 7  
 
 8  
 This program is free software; you can redistribute it and/or modify
 9  
 it under the terms of the GNU General Public License as published by
 10  
 the Free Software Foundation; either version 2 of the License, or (at
 11  
 your option) any later version.
 12  
 
 13  
 This program is distributed in the hope that it will be useful, but
 14  
 WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 16  
 General Public License for more details.
 17  
 
 18  
 You should have received a copy of the GNU General Public License
 19  
 along with this program; if not, write to the Free Software
 20  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 21  
 USA
 22  
 
 23  
 Further information about the GNU GPL is available at:
 24  
 http://www.gnu.org/copyleft/gpl.ja.html
 25  
 
 26  
 */
 27  
 
 28  
 // created by : r.nagel 09.12.2004
 29  
 //
 30  
 // function : shows the IntegrityMessages produced by IntegrityCheck
 31  
 //
 32  
 //     todo : several entries not supported
 33  
 //
 34  
 // modified :
 35  
 
 36  
 package net.sf.jabref.wizard.integrity.gui ;
 37  
 
 38  
 import java.awt.BorderLayout;
 39  
 import java.awt.Component;
 40  
 import java.awt.Dimension;
 41  
 import java.awt.event.ActionEvent;
 42  
 import java.awt.event.ActionListener;
 43  
 import java.awt.event.KeyEvent;
 44  
 import java.awt.event.KeyListener;
 45  
 
 46  
 import javax.swing.*;
 47  
 import javax.swing.event.ListSelectionEvent;
 48  
 import javax.swing.event.ListSelectionListener;
 49  
 
 50  
 import net.sf.jabref.*;
 51  
 import net.sf.jabref.undo.UndoableFieldChange;
 52  
 import net.sf.jabref.wizard.integrity.IntegrityCheck;
 53  
 import net.sf.jabref.wizard.integrity.IntegrityMessage;
 54  
 import net.sf.jabref.wizard.text.gui.HintListModel;
 55  
 
 56  
 public class IntegrityMessagePanel
 57  
     extends JPanel
 58  
     implements ListSelectionListener, KeyListener, ActionListener
 59  
 
 60  
 {
 61  
   private JList warnings ;
 62  
   private HintListModel warningData ;
 63  
 
 64  
   private IntegrityCheck validChecker ;
 65  
 
 66  
   private JTextField content  ;
 67  
   private JButton applyButton ;
 68  
   private JButton fixButton ;
 69  
   private BasePanel basePanel;
 70  
 
 71  
   public IntegrityMessagePanel(BasePanel basePanel)
 72  325535
   {
 73  325535
     this.basePanel = basePanel;
 74  325535
     validChecker = new IntegrityCheck() ; // errors, warnings, hints
 75  
 
 76  
   // JList --------------------------------------------------------------
 77  325535
     warningData = new HintListModel() ;
 78  325535
     warnings = new JList( warningData ) ;
 79  325535
     warnings.setCellRenderer( new IntegrityListRenderer() );
 80  325535
     warnings.addListSelectionListener(this);
 81  
 
 82  325535
     JScrollPane paneScrollPane = new JScrollPane( warnings ) ;
 83  325535
     paneScrollPane.setVerticalScrollBarPolicy(
 84  
         JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ) ;
 85  325535
     paneScrollPane.setPreferredSize( new Dimension( 540, 255 ) ) ;
 86  325535
     paneScrollPane.setMinimumSize( new Dimension( 10, 10 ) ) ;
 87  
 
 88  
   // Fix Panel ---------------------------------------------------------
 89  325535
     JPanel fixPanel = new JPanel() ;
 90  
 //    BoxLayout box = new BoxLayout(fixPanel, BoxLayout.LINE_AXIS) ;
 91  
 
 92  325535
     JLabel label1 = new JLabel(Globals.lang("Field_content")) ;
 93  
 
 94  325535
     content = new JTextField(40) ;
 95  325535
     content.addKeyListener(this);
 96  325535
     applyButton = new JButton(Globals.lang("Apply")) ;
 97  325535
     applyButton.addActionListener(this) ;
 98  325535
     applyButton.setEnabled(false);
 99  325535
     fixButton = new JButton(Globals.lang("Suggest")) ;
 100  325535
     fixButton.setEnabled(false);
 101  
 
 102  325535
     fixPanel.add(label1) ;
 103  325535
     fixPanel.add(content) ;
 104  325535
     fixPanel.add(applyButton) ;
 105  325535
     fixPanel.add(fixButton) ;
 106  
 
 107  
   // Main Panel --------------------------------------------------------
 108  325535
     this.setLayout( new BorderLayout() );
 109  325535
     this.add( paneScrollPane, BorderLayout.CENTER ) ;
 110  325535
     this.add( fixPanel, BorderLayout.SOUTH) ;
 111  325535
   }
 112  
 
 113  
   // ------------------------------------------------------------------------
 114  
 
 115  
   public void updateView( BibtexEntry entry )
 116  
   {
 117  0
     warningData.clear();
 118  0
     IntegrityMessage.setPrintMode( IntegrityMessage.SINLGE_MODE) ;
 119  0
     warningData.setData( validChecker.checkBibtexEntry( entry ) ) ;
 120  0
   }
 121  
 
 122  
   public void updateView( BibtexDatabase base )
 123  
   {
 124  41314
     warningData.clear();
 125  41314
     IntegrityMessage.setPrintMode( IntegrityMessage.FULL_MODE) ;
 126  41314
     warningData.setData( validChecker.checkBibtexDatabase( base ) ) ;
 127  41314
   }
 128  
 
 129  
 
 130  
   // ------------------------------------------------------------------------
 131  
   //This method is required by ListSelectionListener.
 132  
   public void valueChanged( ListSelectionEvent e )
 133  
   {
 134  0
     if ( e.getValueIsAdjusting() )
 135  
     {
 136  0
       Object obj = warnings.getSelectedValue() ;
 137  0
       String str = "" ;
 138  0
       if (obj != null)
 139  
       {
 140  0
         IntegrityMessage msg = (IntegrityMessage) obj ;
 141  0
         BibtexEntry entry = msg.getEntry() ;
 142  
 
 143  0
         if (entry != null)
 144  
         {
 145  0
           str = entry.getField(msg.getFieldName()) ;
 146  0
           basePanel.highlightEntry(entry);
 147  
   // make the "invalid" field visible  ....
 148  
   //          EntryEditor editor = basePanel.getCurrentEditor() ;
 149  
   //          editor.
 150  
         }
 151  
       }
 152  0
       content.setText(str);
 153  0
       applyButton.setEnabled(false);
 154  
     }
 155  0
   }
 156  
 
 157  
 // --------------------------------------------------------------------------
 158  
 // This methods are required by KeyListener
 159  
   public void keyPressed( KeyEvent e )
 160  
   {
 161  0
   }
 162  
 
 163  
   public void keyReleased( KeyEvent e )
 164  
   {
 165  0
     applyButton.setEnabled(true);
 166  0
     if (e.getKeyCode() == KeyEvent.VK_ENTER)
 167  
     {
 168  0
       applyButton.doClick();
 169  
     }
 170  0
   }
 171  
 
 172  
   public void keyTyped( KeyEvent e )
 173  
   {
 174  0
   }
 175  
 
 176  
   public void actionPerformed( ActionEvent e )
 177  
   {
 178  0
     Object obj = e.getSource() ;
 179  0
     if (obj == applyButton)
 180  
     {
 181  0
       Object data = warnings.getSelectedValue() ;
 182  0
       if (data != null)
 183  
       {
 184  0
         IntegrityMessage msg = (IntegrityMessage) data ;
 185  0
         BibtexEntry entry = msg.getEntry() ;
 186  
 
 187  0
         if (entry != null)
 188  
         {
 189  
 //          System.out.println("update") ;
 190  0
             String oldContent = entry.getField(msg.getFieldName());
 191  0
             UndoableFieldChange edit = new UndoableFieldChange(entry, msg.getFieldName(), oldContent,
 192  
                         content.getText());
 193  0
             entry.setField(msg.getFieldName(), content.getText());
 194  0
             basePanel.undoManager.addEdit(edit);
 195  0
             basePanel.markBaseChanged();
 196  0
             msg.setFixed(true);
 197  
 //          updateView(entry) ;
 198  0
           warningData.valueUpdated(warnings.getSelectedIndex()) ;
 199  
         }
 200  
       }
 201  
 
 202  0
       applyButton.setEnabled(false);
 203  
     }
 204  0
   }
 205  
   // ---------------------------------------------------------------------------
 206  
   // ---------------------------------------------------------------------------
 207  325535
   class IntegrityListRenderer extends DefaultListCellRenderer
 208  
   {
 209  325535
     final ImageIcon warnIcon = GUIGlobals.getImage("integrityWarn");
 210  325535
     final ImageIcon infoIcon = GUIGlobals.getImage("integrityInfo");
 211  325535
     final ImageIcon failIcon = GUIGlobals.getImage("integrityFail");
 212  325535
     final ImageIcon fixedIcon = GUIGlobals.getImage("complete");
 213  
 
 214  
     public Component getListCellRendererComponent(
 215  
         JList list,
 216  
         Object value, // value to display
 217  
         int index, // cell index
 218  
         boolean iss, // is the cell selected
 219  
         boolean chf ) // the list and the cell have the focus
 220  
     {
 221  0
       super.getListCellRendererComponent( list, value, index, iss, chf ) ;
 222  
 
 223  0
       if (value != null)
 224  
       {
 225  0
         IntegrityMessage msg = (IntegrityMessage) value ;
 226  0
         if (msg.getFixed())
 227  
         {
 228  0
           setIcon(fixedIcon) ;
 229  
         }
 230  
         else
 231  
         {
 232  0
           int id = msg.getType() ;
 233  0
           if ( id < 1000 )
 234  0
             setIcon( infoIcon ) ;
 235  0
           else if ( id < 2000 )
 236  0
             setIcon( warnIcon ) ;
 237  0
           else setIcon( failIcon ) ;
 238  
         }
 239  
       }
 240  0
       return this ;
 241  
     }
 242  
   }
 243  
 
 244  
 }