EntryEditor.java

Index Score
net.sf.jabref
JabRef

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
JAVA0034JAVA0034 Missing braces in if statement
EXITSProcedure exits
SIZESize of the file in bytes
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
OPERANDSNumber of operands
LOGICAL_LINESNumber of statements
CYCLOMATICCyclomatic complexity
PROGRAM_VOCABHalstead program vocabulary
ELOCEffective lines of code
LINESNumber of lines in the source file
LOCLines of code
COMPARISONSNumber of comparison operators
JAVA0128JAVA0128 Public constructor in non-public class
FUNCTIONSNumber of function declarations
BLOCKSNumber of blocks
RETURNSNumber of return points from functions
WHITESPACENumber of whitespace lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
INTERFACE_COMPLEXITYInterface complexity
JAVA0237JAVA0237 Class implements Cloneable but does not have public clone method
DECL_COMMENTSComments in declarations
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
COMMENTSComment lines
JAVA0170JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0166JAVA0166 Generic exception caught
JAVA0096JAVA0096 Field in nested class hides outer field
PARAMSNumber of formal parameter declarations
JAVA0267JAVA0267 Use of System.err
LOOPSNumber of loops
JAVA0035JAVA0035 Missing braces in for statement
JAVA0008JAVA0008 Empty catch block
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0071JAVA0071 Strings compared with ==
JAVA0177JAVA0177 Variable declaration missing initializer
UNIQUE_OPERATORSNumber of unique operators
JAVA0007JAVA0007 Should not declare public field
JAVA0143JAVA0143 Synchronized method
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0234JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0179JAVA0179 Local variable hides visible field
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0075JAVA0075 Method parameter hides field
BLOCK_COMMENTNumber of block comment lines
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
NEST_DEPTHMaximum nesting depth
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0145JAVA0145 Tab character used in source file
/* * Copyright (C) 2003 Morten O. Alver, Nizar N. Batada * * All programs in this directory and subdirectories are published under the GNU * General Public License as described below. * * 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 2 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, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA * * Further information about the GNU GPL is available at: * http://www.gnu.org/copyleft/gpl.ja.html * */ package net.sf.jabref; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTarget; import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.VetoableChangeListener; import java.io.File; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.logging.Logger; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.JTextComponent; import net.sf.jabref.export.LatexFieldFormatter; import net.sf.jabref.external.ExternalFilePanel; import net.sf.jabref.external.WriteXMPEntryEditorAction; import net.sf.jabref.journals.JournalAbbreviations; import net.sf.jabref.gui.AutoCompleter; import net.sf.jabref.gui.date.DatePickerButton; import net.sf.jabref.imports.BibtexParser; import net.sf.jabref.labelPattern.LabelPatternUtil; import net.sf.jabref.undo.NamedCompound; import net.sf.jabref.undo.UndoableFieldChange; import net.sf.jabref.undo.UndoableKeyChange; import net.sf.jabref.undo.UndoableRemoveEntry; /** * GUI component that allows editing of the fields of a BibtexEntry (i.e. the * one that shows up, when you double click on an entry in the table) * * It hosts the tabs (required, general, optional) and the buttons to the left. * * EntryEditor also registers itself as a VetoableChangeListener, receiving * events whenever a field of the entry changes, enabling the text fields to * update themselves if the change is made from somewhere else. */ public class EntryEditor extends JPanel implements VetoableChangeListener { // A reference to the entry this object works on. private BibtexEntry entry; BibtexEntryType type; // The action concerned with closing the window. CloseAction closeAction; // The action that deletes the current entry, and closes the editor. DeleteAction deleteAction = new DeleteAction(); // The action concerned with copying the BibTeX key to the clipboard. CopyKeyAction copyKeyAction; // The action concerned with copying the BibTeX key to the clipboard. AbstractAction nextEntryAction = new NextEntryAction(); // Actions for switching to next/previous entry. AbstractAction prevEntryAction = new PrevEntryAction(); // The action concerned with storing a field value. public StoreFieldAction storeFieldAction; // The actions concerned with switching the panels. SwitchLeftAction switchLeftAction = new SwitchLeftAction(); SwitchRightAction switchRightAction = new SwitchRightAction(); // The action which generates a bibtexkey for this entry. public GenerateKeyAction generateKeyAction; public AbstractAction writeXmp; SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(); JPanel mainPanel = new JPanel(); JPanel srcPanel = new JPanel(); EntryEditorTab genPan, optPan, reqPan, absPan; JTextField bibtexKey; FieldTextField tf; JTextArea source; JToolBar tlb; JTabbedPane tabbed = new JTabbedPane(); // JTabbedPane.RIGHT); JLabel lab; TypeLabel typeLabel; JabRefFrame frame; BasePanel panel; EntryEditor ths = this; HashSet<FieldContentSelector> contentSelectors = new HashSet<FieldContentSelector>(); Logger logger = Logger.getLogger(EntryEditor.class.getName()); boolean updateSource = true; // This can be set to false to stop the // source List<Object> tabs = new ArrayList<Object>(); // text area from gettin updated. This is used in cases where the source // couldn't be parsed, and the user is given the option to edit it. boolean lastSourceAccepted = true; // This indicates whether the last // attempt // at parsing the source was successful. It is used to determine whether the // dialog should close; it should stay open if the user received an error // message about the source, whatever he or she chose to do about it. String lastSourceStringAccepted = null; // This is used to prevent double // fields. // These values can be used to calculate the preferred height for the form. // reqW starts at 1 because it needs room for the bibtex key field. private int sourceIndex = -1; // The index the source panel has in tabbed. JabRefPreferences prefs; HelpAction helpAction; UndoAction undoAction = new UndoAction(); RedoAction redoAction = new RedoAction(); TabListener tabListener = new TabListener(); public EntryEditor(JabRefFrame frame_, BasePanel panel_, BibtexEntry entry_) { frame = frame_; panel = panel_; entry = entry_; prefs = Globals.prefs; type = entry.getType(); entry.addPropertyChangeListener(this); helpAction = new HelpAction(frame.helpDiag, GUIGlobals.entryEditorHelp, "Help"); closeAction = new CloseAction(); copyKeyAction = new CopyKeyAction(); generateKeyAction = new GenerateKeyAction(frame); storeFieldAction = new StoreFieldAction(); writeXmp = new WriteXMPEntryEditorAction(panel_, this); BorderLayout bl = new BorderLayout(); setLayout(bl); setupToolBar(); setupFieldPanels(); setupSourcePanel(); add(tabbed, BorderLayout.CENTER); tabbed.addChangeListener(tabListener); if (prefs.getBoolean("showSource") && prefs.getBoolean("defaultShowSource")) tabbed.setSelectedIndex(sourceIndex); updateAllFields(); } private void setupFieldPanels() { tabbed.removeAll(); tabs.clear(); String[] fields = entry.getRequiredFields(); List<String> fieldList = null; if (fields != null) fieldList = java.util.Arrays.asList(fields); reqPan = new EntryEditorTab(frame, panel, fieldList, this, true, Globals.lang("Required fields")); tabbed.addTab(Globals.lang("Required fields"), GUIGlobals.getImage("required"), reqPan .getPane(), Globals.lang("Show required fields")); tabs.add(reqPan); if ((entry.getOptionalFields() != null) && (entry.getOptionalFields().length >= 1)) { optPan = new EntryEditorTab(frame, panel, java.util.Arrays.asList(entry.getOptionalFields()), this, false, Globals.lang("Optional fields")); tabbed.addTab(Globals.lang("Optional fields"), GUIGlobals.getImage("optional"), optPan .getPane(), Globals.lang("Show optional fields")); tabs.add(optPan); } EntryEditorTabList tabList = Globals.prefs.getEntryEditorTabList(); for (int i = 0; i < tabList.getTabCount(); i++) { EntryEditorTab newTab = new EntryEditorTab(frame, panel, tabList.getTabFields(i), this, false, tabList.getTabName(i)); tabbed.addTab(tabList.getTabName(i), GUIGlobals.getImage("general"), newTab.getPane()); tabs.add(newTab); } srcPanel.setName(Globals.lang("BibTeX source")); if (Globals.prefs.getBoolean("showSource")) { tabbed.addTab(Globals.lang("BibTeX source"), GUIGlobals.getImage("source"), srcPanel, Globals.lang("Show/edit BibTeX source")); tabs.add(srcPanel); } sourceIndex = tabs.size() - 1; // Set the sourceIndex variable. srcPanel.setFocusCycleRoot(true); } public BibtexEntryType getType() { return type; } public BibtexEntry getEntry() { return entry; } public BibtexDatabase getDatabase(){ return panel.getDatabase(); } private void setupToolBar() { tlb = new JToolBar(JToolBar.VERTICAL); tlb.setMargin(new Insets(0, 0, 0, 2)); // The toolbar carries all the key bindings that are valid for the whole // window. ActionMap am = tlb.getActionMap(); InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(prefs.getKey("Close entry editor"), "close"); am.put("close", closeAction); im.put(prefs.getKey("Entry editor, store field"), "store"); am.put("store", storeFieldAction); im.put(prefs.getKey("Autogenerate BibTeX keys"), "generateKey"); am.put("generateKey", generateKeyAction); im.put(prefs.getKey("Entry editor, previous entry"), "prev"); am.put("prev", prevEntryAction); im.put(prefs.getKey("Entry editor, next entry"), "next"); am.put("next", nextEntryAction); im.put(prefs.getKey("Undo"), "undo"); am.put("undo", undoAction); im.put(prefs.getKey("Redo"), "redo"); am.put("redo", redoAction); im.put(prefs.getKey("Help"), "help"); am.put("help", helpAction); tlb.setFloatable(false); // Create type-label typeLabel = new TypeLabel(entry.getType().getName()); // Add actions (and thus buttons) tlb.add(closeAction); tlb.add(typeLabel); tlb.addSeparator(); tlb.add(generateKeyAction); tlb.add(writeXmp); tlb.addSeparator(); tlb.add(deleteAction); tlb.add(prevEntryAction); tlb.add(nextEntryAction); tlb.addSeparator(); tlb.add(helpAction); Component[] comps = tlb.getComponents(); for (int i = 0; i < comps.length; i++) ((JComponent) comps[i]).setOpaque(false); add(tlb, BorderLayout.WEST); } /** * Rebuild the field tabs. This is called e.g. when a new content selector * has been added. */ public void rebuildPanels() { // Remove change listener, because the rebuilding causes meaningless // events and trouble: tabbed.removeChangeListener(tabListener); setupFieldPanels(); // Add the change listener again: tabbed.addChangeListener(tabListener); revalidate(); repaint(); } /** * getExtra checks the field name against BibtexFields.getFieldExtras(name). * If the name has an entry, the proper component to be shown is created and * returned. Otherwise, null is returned. In addition, e.g. listeners can be * added to the field editor, even if no component is returned. * * @param string * Field name * @return Component to show, or null if none. */ public JComponent getExtra(String string, final FieldEditor ed) { // fieldName and parameter string identically ???? final String fieldName = ed.getFieldName(); String s = BibtexFields.getFieldExtras(string); // timestamp or a other field with datepicker command if ((fieldName.equals(Globals.prefs.get("timeStampField"))) || ((s != null) && s.equals("datepicker"))) { // double click AND datefield => insert the current date (today) ((JTextArea) ed).addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) // double click { String date = Util.easyDateFormat(); ed.setText(date); } } }); // insert a datepicker, if the extras field contains this command if ((s != null) && s.equals("datepicker")) { DatePickerButton datePicker = new DatePickerButton(ed); return datePicker.getDatePicker(); } } if ((s != null) && s.equals("external")) { // Add external viewer listener for "pdf" and "url" fields. ((JComponent) ed).addMouseListener(new ExternalViewerListener()); return null; } else if ((s != null) && s.equals("journalNames")) { // Add controls for switching between abbreviated and full journal // names. // If this field also has a FieldContentSelector, we need to combine // these. JPanel controls = new JPanel(); controls.setLayout(new BorderLayout()); if (panel.metaData.getData(Globals.SELECTOR_META_PREFIX + ed.getFieldName()) != null) { FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, ed, panel.metaData, storeFieldAction, false, ", "); contentSelectors.add(ws); controls.add(ws, BorderLayout.NORTH); } controls.add(JournalAbbreviations.getNameSwitcher(this, ed, panel.undoManager), BorderLayout.SOUTH); return controls; } else if (panel.metaData.getData(Globals.SELECTOR_META_PREFIX + ed.getFieldName()) != null) { FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, ed, panel.metaData, storeFieldAction, false, (ed.getFieldName().equals("author") ? " and " : ", ")); contentSelectors.add(ws); return ws; } else if ((s != null) && s.equals("browse")) { JButton but = new JButton(Globals.lang("Browse")); ((JComponent) ed).addMouseListener(new ExternalViewerListener()); // but.setBackground(GUIGlobals.lightGray); but.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String dir = ed.getText(); if (dir.equals("")) dir = prefs.get(fieldName + Globals.FILETYPE_PREFS_EXT, ""); String chosenFile = Globals.getNewFile(frame, new File(dir), "." + fieldName, JFileChooser.OPEN_DIALOG, false); if (chosenFile != null) { File newFile = new File(chosenFile); // chooser.getSelectedFile(); ed.setText(newFile.getPath()); prefs.put(fieldName + Globals.FILETYPE_PREFS_EXT, newFile.getPath()); updateField(ed); } } }); return but; // } else if ((s != null) && s.equals("browsePdf")) { } else if ((s != null) && (s.equals("browseDoc") || s.equals("browseDocZip"))) { final String ext = "." + fieldName.toLowerCase(); final OpenFileFilter off; if (s.equals("browseDocZip")) off = new OpenFileFilter(new String[] { ext, ext + ".gz", ext + ".bz2" }); else off = new OpenFileFilter(new String[] { ext }); ExternalFilePanel pan = new ExternalFilePanel(frame, panel.metaData(), this, fieldName, off, ed); return pan; } /* * else if ((s != null) && s.equals("browsePs")) { ExternalFilePanel pan = * new ExternalFilePanel(frame, this, "ps", off, ed); return pan; } */ else if ((s != null) && s.equals("url")) { ((JComponent) ed).setDropTarget(new DropTarget((Component) ed, DnDConstants.ACTION_NONE, new SimpleUrlDragDrop(ed, storeFieldAction))); return null; } else if ((s != null) && (s.equals("setOwner"))) { JButton button = new JButton(Globals.lang("Auto")); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ed.setText(Globals.prefs.get("defaultOwner")); storeFieldAction.actionPerformed(new ActionEvent(ed, 0, "")); } }); return button; } else return null; } private void setupSourcePanel() { source = new JTextArea();/* { private boolean antialias = Globals.prefs.getBoolean("antialias"); public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; if (antialias) g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); super.paint(g2); } };*/ //DefaultFormBuilder builder = new DefaultFormBuilder // (srcPanel, new FormLayout( "fill:pref:grow", "fill:pref:grow")); source.setEditable(true); // prefs.getBoolean("enableSourceEditing")); source.setLineWrap(true); source.setTabSize(GUIGlobals.INDENT); source.addFocusListener(new FieldEditorFocusListener()); // Add the global focus listener, so a menu item can see if this field // was focused when // an action was called. source.addFocusListener(Globals.focusListener); source.setFont(new Font("Monospaced", Font.PLAIN, Globals.prefs.getInt("fontSize"))); setupJTextComponent(source); updateSource(); JScrollPane sp = new JScrollPane(source, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); //builder.append(sp); srcPanel.setLayout(new BorderLayout()); srcPanel.add(sp, BorderLayout.CENTER); } public void updateSource() { if (updateSource) { StringWriter sw = new StringWriter(200); try { entry.write(sw, new net.sf.jabref.export.LatexFieldFormatter(), false); String srcString = sw.getBuffer().toString(); source.setText(srcString); lastSourceStringAccepted = srcString; } catch (IOException ex) { source.setText(ex.getMessage() + "\n\n" + Globals.lang("Correct the entry, and " + "reopen editor to display/edit source.")); source.setEditable(false); } } } /** * NOTE: This method is only used for the source panel, not for the * other tabs. Look at EntryEditorTab for the setup of text components * in the other tabs. */ public void setupJTextComponent(JTextComponent ta) { // Set up key bindings and focus listener for the FieldEditor. InputMap im = ta.getInputMap(JComponent.WHEN_FOCUSED); ActionMap am = ta.getActionMap(); // im.put(KeyStroke.getKeyStroke(GUIGlobals.closeKey), "close"); // am.put("close", closeAction); im.put(prefs.getKey("Entry editor, store field"), "store"); am.put("store", storeFieldAction); im.put(prefs.getKey("Entry editor, next panel"), "right"); im.put(prefs.getKey("Entry editor, next panel 2"), "right"); am.put("right", switchRightAction); im.put(prefs.getKey("Entry editor, previous panel"), "left"); im.put(prefs.getKey("Entry editor, previous panel 2"), "left"); am.put("left", switchLeftAction); im.put(prefs.getKey("Help"), "help"); am.put("help", helpAction); im.put(prefs.getKey("Save database"), "save"); am.put("save", saveDatabaseAction); im.put(Globals.prefs.getKey("Next tab"), "nexttab"); am.put("nexttab", frame.nextTab); im.put(Globals.prefs.getKey("Previous tab"), "prevtab"); am.put("prevtab", frame.prevTab); try { HashSet<AWTKeyStroke> keys = new HashSet<AWTKeyStroke>(ta .getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB")); ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys); keys = new HashSet<AWTKeyStroke>(ta .getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); keys.clear(); keys.add(KeyStroke.getKeyStroke("shift pressed TAB")); ta.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys); } catch (Throwable t) { System.err.println(t); } ta.addFocusListener(new FieldListener()); } public void requestFocus() { activateVisible(); } private void activateVisible() { Object activeTab = tabs.get(tabbed.getSelectedIndex()); if (activeTab instanceof EntryEditorTab) ((EntryEditorTab) activeTab).activate(); else new FocusRequester(source); // ((JComponent)activeTab).requestFocus(); } /** * Reports the enabled status of the editor, as set by setEnabled() */ public boolean isEnabled() { return source.isEnabled(); } /** * Sets the enabled status of all text fields of the entry editor. */ public void setEnabled(boolean enabled) { for (Iterator<Object> i = tabs.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof EntryEditorTab) { ((EntryEditorTab) o).setEnabled(enabled); } } source.setEnabled(enabled); } /** * Centers the given row, and highlights it. * * @param row * an <code>int</code> value */ private void scrollTo(int row) { panel.mainTable.setRowSelectionInterval(row, row); panel.mainTable.ensureVisible(row); } /** * Makes sure the current edit is stored. */ public void storeCurrentEdit() { Component comp = Globals.focusListener.getFocused(); if ((comp == source) || ((comp instanceof FieldEditor) && this.isAncestorOf(comp))) { storeFieldAction.actionPerformed(new ActionEvent(comp, 0, "")); } } /** * Returns the index of the active (visible) panel. * * @return an <code>int</code> value */ public int getVisiblePanel() { return tabbed.getSelectedIndex(); } /** Returns the name of the currently selected component. */ public String getVisiblePanelName() { return tabbed.getSelectedComponent().getName(); } /** * Sets the panel with the given index visible. * * @param i * an <code>int</code> value */ public void setVisiblePanel(int i) { tabbed.setSelectedIndex(Math.min(i, tabbed.getTabCount() - 1)); } public void setVisiblePanel(String name) { for (int i = 0; i < tabbed.getTabCount(); ++i) { if (name.equals(tabbed.getComponent(i).getName())) { tabbed.setSelectedIndex(i); return; } } if (tabbed.getTabCount() > 0) tabbed.setSelectedIndex(0); } /** * Updates this editor to show the given entry, regardless of type * correspondence. * * @param be * a <code>BibtexEntry</code> value */ public synchronized void switchTo(BibtexEntry be) { if (entry == be) return; storeCurrentEdit(); // Remove this instance as property listener for the entry: entry.removePropertyChangeListener(this); // Register as property listener for the new entry: be.addPropertyChangeListener(this); entry = be; updateAllFields(); validateAllFields(); updateSource(); panel.showing = be; } /** * Returns false if the contents of the source panel has not been validated, * true othervise. */ public boolean lastSourceAccepted() { if (tabbed.getSelectedComponent() == srcPanel) storeSource(false); return lastSourceAccepted; } /* * public boolean storeSourceIfNeeded() { if (tabbed.getSelectedIndex() == * sourceIndex) return storeSource(); else return true; } */ public boolean storeSource(boolean showError) { // Store edited bibtex code. BibtexParser bp = new BibtexParser(new java.io.StringReader(source.getText())); try { BibtexDatabase db = bp.parse().getDatabase(); if (db.getEntryCount() > 1) throw new Exception("More than one entry found."); if (db.getEntryCount() < 1) throw new Exception("No entries found."); NamedCompound compound = new NamedCompound(Globals.lang("source edit")); BibtexEntry nu = db.getEntryById(db.getKeySet().iterator().next()); String id = entry.getId(); String // oldKey = entry.getCiteKey(), newKey = nu.getCiteKey(); boolean anyChanged = false; boolean duplicateWarning = false; boolean emptyWarning = newKey == null || newKey.equals(""); if (panel.database.setCiteKeyForEntry(id, newKey)) { duplicateWarning = true; // First, remove fields that the user have removed. } for (String field : entry.getAllFields()){ if (BibtexFields.isDisplayableField(field.toString())) { if (nu.getField(field.toString()) == null) { compound.addEdit(new UndoableFieldChange(entry, field.toString(), entry .getField(field.toString()), null)); entry.clearField(field.toString()); anyChanged = true; } } } // Then set all fields that have been set by the user. for (String field : nu.getAllFields()){ if (entry.getField(field.toString()) != nu.getField(field.toString())) { String toSet = nu.getField(field.toString()); // Test if the field is legally set. (new LatexFieldFormatter()).format(toSet, field.toString()); compound.addEdit(new UndoableFieldChange(entry, field.toString(), entry .getField(field.toString()), toSet)); entry.setField(field.toString(), toSet); anyChanged = true; } } compound.end(); if (!anyChanged) return true; panel.undoManager.addEdit(compound); /* * if (((oldKey == null) && (newKey != null)) || ((oldKey != null) && * (newKey == null)) || ((oldKey != null) && (newKey != null) && * !oldKey.equals(newKey))) { } */ if (duplicateWarning) { warnDuplicateBibtexkey(); } else if (emptyWarning && showError) { warnEmptyBibtexkey(); } else { panel.output(Globals.lang("Stored entry") + "."); } lastSourceStringAccepted = source.getText(); updateAllFields(); lastSourceAccepted = true; updateSource = true; // TODO: does updating work properly after source stored? // panel.tableModel.remap(); // panel.entryTable.repaint(); // panel.refreshTable(); panel.markBaseChanged(); return true; } catch (Throwable ex) { // ex.printStackTrace(); // The source couldn't be parsed, so the user is given an // error message, and the choice to keep or revert the contents // of the source text field. updateSource = false; lastSourceAccepted = false; tabbed.setSelectedComponent(srcPanel); if (showError) { Object[] options = { Globals.lang("Edit"), Globals.lang("Revert to original source") }; int answer = JOptionPane.showOptionDialog(frame, Globals.lang("Error") + ": " + ex.getMessage(), Globals.lang("Problem with parsing entry"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); if (answer != 0) { updateSource = true; updateSource(); } } return false; } } public void setField(String fieldName, String newFieldData) { for (Iterator<Object> i = tabs.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof EntryEditorTab) { ((EntryEditorTab) o).updateField(fieldName, newFieldData); } } } /** * Sets all the text areas according to the shown entry. */ public void updateAllFields() { for (Iterator<Object> i = tabs.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof EntryEditorTab) { ((EntryEditorTab) o).setEntry(entry); } } } /** * Removes the "invalid field" color from all text areas. */ public void validateAllFields() { for (Iterator<Object> i = tabs.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof EntryEditorTab) { ((EntryEditorTab) o).validateAllFields(); } } } public void updateAllContentSelectors() { if (contentSelectors.size() > 0) { for (Iterator<FieldContentSelector> i = contentSelectors.iterator(); i.hasNext();) i.next().rebuildComboBox(); } } /* * Update the JTextArea when a field has changed. * * (non-Javadoc) * * @see java.beans.VetoableChangeListener#vetoableChange(java.beans.PropertyChangeEvent) */ public void vetoableChange(PropertyChangeEvent e) { String newValue = ((e.getNewValue() != null) ? e.getNewValue().toString() : ""); setField(e.getPropertyName(), newValue); } public void updateField(final Object source) { storeFieldAction.actionPerformed(new ActionEvent(source, 0, "")); } private class TypeLabel extends JPanel { private String label; public TypeLabel(String type) { label = type; addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { boolean ctrlClick = prefs.getBoolean("ctrlClick"); if ((e.getButton() == MouseEvent.BUTTON3) || (ctrlClick && (e.getButton() == MouseEvent.BUTTON1) && e.isControlDown())) { JPopupMenu typeMenu = new JPopupMenu(); // typeMenu.addSeparator(); for (String s: BibtexEntryType.ALL_TYPES.keySet()) typeMenu.add(new ChangeTypeAction(BibtexEntryType.getType(s), panel)); typeMenu.show(ths, e.getX(), e.getY()); } } }); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(GUIGlobals.validFieldColor); g2.setFont(GUIGlobals.typeNameFont); FontMetrics fm = g2.getFontMetrics(); int width = fm.stringWidth(label); //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.rotate(-Math.PI / 2, 0, 0); g2.drawString(label, -width - 7, 28); } } class FieldListener extends FocusAdapter { /* * Focus listener that fires the storeFieldAction when a FieldTextArea * loses focus. */ public void focusGained(FocusEvent e) { } public void focusLost(FocusEvent e) { // Util.pr("Lost focus "+e.getSource().toString().substring(0,30)); if (!e.isTemporary()) updateField(e.getSource()); } } class TabListener implements ChangeListener { public void stateChanged(ChangeEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { activateVisible(); } }); // After the initial event train has finished, we tell the editor // tab to update all // its fields. This makes sure they are updated even if the tab we // just left contained one // or more of the same fields as this one: SwingUtilities.invokeLater(new Runnable() { public void run() { Object activeTab = tabs.get(tabbed.getSelectedIndex()); if (activeTab instanceof EntryEditorTab) ((EntryEditorTab) activeTab).updateAll(); } }); } } class DeleteAction extends AbstractAction { public DeleteAction() { super(Globals.lang("Delete"), GUIGlobals.getImage("delete")); putValue(SHORT_DESCRIPTION, Globals.lang("Delete entry")); } public void actionPerformed(ActionEvent e) { // Show confirmation dialog if not disabled: boolean goOn = panel.showDeleteConfirmationDialog(1); if (!goOn) return; panel.entryEditorClosing(EntryEditor.this); panel.database.removeEntry(entry.getId()); panel.markBaseChanged(); panel.undoManager.addEdit(new UndoableRemoveEntry(panel.database, entry, panel)); panel.output(Globals.lang("Deleted") + " " + Globals.lang("entry")); } } class CloseAction extends AbstractAction { public CloseAction() { super(Globals.lang("Close window"), GUIGlobals.getImage("close")); putValue(SHORT_DESCRIPTION, Globals.lang("Close window")); } public void actionPerformed(ActionEvent e) { if (tabbed.getSelectedComponent() == srcPanel) { updateField(source); if (lastSourceAccepted) panel.entryEditorClosing(EntryEditor.this); } else panel.entryEditorClosing(EntryEditor.this); } } class CopyKeyAction extends AbstractAction { public CopyKeyAction() { super("Copy BibTeX key to clipboard"); putValue(SHORT_DESCRIPTION, "Copy BibTeX key to clipboard (Ctrl-K)"); // putValue(MNEMONIC_KEY, GUIGlobals.copyKeyCode); } public void actionPerformed(ActionEvent e) { String s = (entry.getField(BibtexFields.KEY_FIELD)); StringSelection ss = new StringSelection(s); if (s != null) Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, ss); } } public class StoreFieldAction extends AbstractAction { public StoreFieldAction() { super("Store field value"); putValue(SHORT_DESCRIPTION, "Store field value"); } public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof FieldTextField) { // Storage from bibtex key field. FieldTextField fe = (FieldTextField) e.getSource(); String oldValue = entry.getCiteKey(); String newValue = fe.getText(); if (newValue.equals("")) newValue = null; if (((oldValue == null) && (newValue == null)) || ((oldValue != null) && (newValue != null) && oldValue.equals(newValue))) return; // No change. // Make sure the key is legal: String cleaned = Util.checkLegalKey(newValue); if ((cleaned != null) && !cleaned.equals(newValue)) { JOptionPane.showMessageDialog(frame, Globals.lang("Invalid BibTeX key"), Globals.lang("Error setting field"), JOptionPane.ERROR_MESSAGE); fe.setBackground(GUIGlobals.invalidFieldBackground); return; } else { fe.setBackground(/* * fe.getTextComponent().hasFocus() ? * GUIGlobals.activeEditor : */ GUIGlobals.validFieldBackground); } boolean isDuplicate = panel.database.setCiteKeyForEntry(entry.getId(), newValue); if (newValue != null) { if (isDuplicate) warnDuplicateBibtexkey(); else panel.output(Globals.lang("BibTeX key is unique.")); } else { // key is null/empty warnEmptyBibtexkey(); } // Add an UndoableKeyChange to the baseframe's undoManager. panel.undoManager.addEdit(new UndoableKeyChange(panel.database, entry.getId(), oldValue, newValue)); if ((newValue != null) && (newValue.length() > 0)) // fe.setLabelColor(GUIGlobals.validFieldColor); fe.setBackground(GUIGlobals.validFieldBackground); else // fe.setLabelColor(GUIGlobals.nullFieldColor); fe.setBackground(GUIGlobals.validFieldBackground); updateSource(); panel.markBaseChanged(); } else if (e.getSource() instanceof FieldEditor) { String toSet = null; FieldEditor fe = (FieldEditor) e.getSource(); boolean set; // Trim the whitespace off this value String currentText = fe.getText(); String trim = currentText.trim(); if (trim.length() > 0) { toSet = trim; } // We check if the field has changed, since we don't want to // mark the base as changed unless we have a real change. if (toSet == null) { if (entry.getField(fe.getFieldName()) == null) set = false; else set = true; } else { if ((entry.getField(fe.getFieldName()) != null) && toSet.equals(entry.getField(fe.getFieldName()).toString())) set = false; else set = true; } if (set) { try { // The following statement attempts to write the // new contents into a StringWriter, and this will // cause an IOException if the field is not // properly formatted. If that happens, the field // is not stored and the textarea turns red. if (toSet != null) (new LatexFieldFormatter()).format(toSet, fe.getFieldName()); String oldValue = entry.getField(fe.getFieldName()); if (toSet != null) entry.setField(fe.getFieldName(), toSet); else entry.clearField(fe.getFieldName()); if ((toSet != null) && (toSet.length() > 0)) // fe.setLabelColor(GUIGlobals.validFieldColor); fe.setBackground(GUIGlobals.validFieldBackground); else // fe.setLabelColor(GUIGlobals.nullFieldColor); fe.setBackground(GUIGlobals.validFieldBackground); // See if we need to update an AutoCompleter instance: AutoCompleter aComp = panel.getAutoCompleter(fe.getFieldName()); if (aComp != null) aComp.addAll(toSet); // Add an UndoableFieldChange to the baseframe's // undoManager. panel.undoManager.addEdit(new UndoableFieldChange(entry, fe.getFieldName(), oldValue, toSet)); updateSource(); panel.markBaseChanged(); // TODO: is this a safe solution to keep selection on // entry? SwingUtilities.invokeLater(new Runnable() { public void run() { panel.highlightEntry(entry); } }); } catch (IllegalArgumentException ex) { JOptionPane.showMessageDialog(frame, Globals.lang("Error") + ": " + ex.getMessage(), Globals .lang("Error setting field"), JOptionPane.ERROR_MESSAGE); fe.setBackground(GUIGlobals.invalidFieldBackground); } } else { // set == false // We set the field and label color. fe.setBackground(GUIGlobals.validFieldBackground); } } else if ((source.isEditable()) && (!source.getText().equals(lastSourceStringAccepted))) { boolean accepted = storeSource(true); if (accepted) { } } } } class SwitchLeftAction extends AbstractAction { public SwitchLeftAction() { super("Switch to the panel to the left"); } public void actionPerformed(ActionEvent e) { // System.out.println("switch left"); int i = tabbed.getSelectedIndex(); tabbed.setSelectedIndex(((i > 0) ? (i - 1) : (tabbed.getTabCount() - 1))); activateVisible(); } } class SwitchRightAction extends AbstractAction { public SwitchRightAction() { super("Switch to the panel to the right"); } public void actionPerformed(ActionEvent e) { // System.out.println("switch right"); int i = tabbed.getSelectedIndex(); tabbed.setSelectedIndex((i < (tabbed.getTabCount() - 1)) ? (i + 1) : 0); activateVisible(); } } class NextEntryAction extends AbstractAction { public NextEntryAction() { super(Globals.lang("Next entry"), GUIGlobals.getImage("down")); putValue(SHORT_DESCRIPTION, Globals.lang("Next entry")); } public void actionPerformed(ActionEvent e) { int thisRow = panel.mainTable.findEntry(entry); int newRow = -1; if ((thisRow + 1) < panel.database.getEntryCount()) newRow = thisRow + 1; else if (thisRow > 0) newRow = 0; else return; // newRow is still -1, so we can assume the database has // only one entry. scrollTo(newRow); panel.mainTable.setRowSelectionInterval(newRow, newRow); } } class PrevEntryAction extends AbstractAction { public PrevEntryAction() { super(Globals.lang("Previous entry"), GUIGlobals.getImage("up")); putValue(SHORT_DESCRIPTION, Globals.lang("Previous entry")); } public void actionPerformed(ActionEvent e) { int thisRow = panel.mainTable.findEntry(entry); int newRow = -1; if ((thisRow - 1) >= 0) newRow = thisRow - 1; else if (thisRow != (panel.database.getEntryCount() - 1)) newRow = panel.database.getEntryCount() - 1; else return; // newRow is still -1, so we can assume the database has // only one entry. // id = panel.tableModel.getIdForRow(newRow); // switchTo(id); scrollTo(newRow); panel.mainTable.setRowSelectionInterval(newRow, newRow); } } class GenerateKeyAction extends AbstractAction { JabRefFrame parent; BibtexEntry selectedEntry; public GenerateKeyAction(JabRefFrame parentFrame) { super(Globals.lang("Generate BibTeX key"), GUIGlobals.getImage("makeKey")); parent = parentFrame; // selectedEntry = newEntry ; putValue(SHORT_DESCRIPTION, Globals.lang("Generate BibTeX key")); // putValue(MNEMONIC_KEY, GUIGlobals.showGenKeyCode); } public void actionPerformed(ActionEvent e) { // 1. get Bitexentry for selected index (already have) // 2. run the LabelMaker by it try { // Store the current edit in case this action is called during the // editing of a field: storeCurrentEdit(); // this updates the table automatically, on close, but not // within the tab Object oldValue = entry.getField(BibtexFields.KEY_FIELD); // entry = frame.labelMaker.applyRule(entry, panel.database) ; LabelPatternUtil.makeLabel(prefs.getKeyPattern(), panel.database, entry); // Store undo information: panel.undoManager.addEdit(new UndoableKeyChange(panel.database, entry.getId(), (String) oldValue, entry.getField(BibtexFields.KEY_FIELD))); // here we update the field String bibtexKeyData = entry.getField(BibtexFields.KEY_FIELD); // set the field named for "bibtexkey" setField(BibtexFields.KEY_FIELD, bibtexKeyData); updateSource(); panel.markBaseChanged(); } catch (Throwable t) { System.err.println("error setting key: " + t); } } } class UndoAction extends AbstractAction { public UndoAction() { super("Undo", GUIGlobals.getImage("undo")); putValue(SHORT_DESCRIPTION, "Undo"); } public void actionPerformed(ActionEvent e) { try { panel.runCommand("undo"); } catch (Throwable ex) { } } } class RedoAction extends AbstractAction { public RedoAction() { super("Undo", GUIGlobals.getImage("redo")); putValue(SHORT_DESCRIPTION, "Redo"); } public void actionPerformed(ActionEvent e) { try { panel.runCommand("redo"); } catch (Throwable ex) { } } } class SaveDatabaseAction extends AbstractAction { public SaveDatabaseAction() { super("Save database"); } public void actionPerformed(ActionEvent e) { Object activeTab = tabs.get(tabbed.getSelectedIndex()); if (activeTab instanceof EntryEditorTab) { // Normal panel. EntryEditorTab fp = (EntryEditorTab) activeTab; updateField(fp.getActive()); } else // Source panel. updateField(activeTab); try { panel.runCommand("save"); } catch (Throwable ex) { } } } class ExternalViewerListener extends MouseAdapter { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { FieldTextArea tf = (FieldTextArea) evt.getSource(); if (tf.getText().equals("")) return; tf.selectAll(); String link = tf.getText(); // get selected ? String // getSelectedText() try { Util.openExternalViewer(panel.metaData(), link, tf.getFieldName()); } catch (IOException ex) { System.err.println("Error opening file."); } } } } class ChangeTypeAction extends AbstractAction { BibtexEntryType type; BasePanel panel; public ChangeTypeAction(BibtexEntryType type, BasePanel bp) { super(type.getName()); this.type = type; panel = bp; } public void actionPerformed(ActionEvent evt) { panel.changeType(entry, type); } } private void warnDuplicateBibtexkey() { panel.output(Globals.lang("Warning") + ": " + Globals.lang("Duplicate BibTeX key.")); if (prefs.getBoolean("dialogWarningForDuplicateKey")) { // JZTODO lyrics CheckBoxMessage jcb = new CheckBoxMessage(Globals.lang("Warning") + ": " + Globals.lang("Duplicate BibTeX key. Grouping may not work for this entry."), Globals.lang("Disable this warning dialog"), false); JOptionPane.showMessageDialog(frame, jcb, Globals.lang("Warning"), JOptionPane.WARNING_MESSAGE); if (jcb.isSelected()) prefs.putBoolean("dialogWarningForDuplicateKey", false); } } private void warnEmptyBibtexkey() { // JZTODO lyrics panel.output(Globals.lang("Warning") + ": " + Globals.lang("Empty BibTeX key.")); if (prefs.getBoolean("dialogWarningForEmptyKey")) { // JZTODO lyrics CheckBoxMessage jcb = new CheckBoxMessage(Globals.lang("Warning") + ": " + Globals.lang("Empty BibTeX key. Grouping may not work for this entry."), Globals .lang("Disable this warning dialog"), false); JOptionPane.showMessageDialog(frame, jcb, Globals.lang("Warning"), JOptionPane.WARNING_MESSAGE); if (jcb.isSelected()) prefs.putBoolean("dialogWarningForEmptyKey", false); } } }

The table below shows all metrics for EntryEditor.java.

MetricValueDescription
BLOCKS147.00Number of blocks
BLOCK_COMMENT61.00Number of block comment lines
COMMENTS252.00Comment lines
COMMENT_DENSITY 0.34Comment density
COMPARISONS124.00Number of comparison operators
CYCLOMATIC196.00Cyclomatic complexity
DECL_COMMENTS32.00Comments in declarations
DOC_COMMENT73.00Number of javadoc comment lines
ELOC745.00Effective lines of code
EXEC_COMMENTS71.00Comments in executable code
EXITS201.00Procedure exits
FUNCTIONS71.00Number of function declarations
HALSTEAD_DIFFICULTY83.23Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY136.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 3.00JAVA0007 Should not declare public field
JAVA0008 3.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 1.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003446.00JAVA0034 Missing braces in if statement
JAVA0035 2.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 1.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 1.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 2.00JAVA0096 Field in nested class hides outer field
JAVA0098 2.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 2.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 3.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 3.00JAVA0116 Missing javadoc: field 'field'
JAVA011724.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 1.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA012813.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 1.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145 1.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 6.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 6.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 2.00JAVA0177 Variable declaration missing initializer
JAVA0179 1.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA023415.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA023713.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 5.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 3.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1401.00Number of lines in the source file
LINE_COMMENT118.00Number of line comments
LOC889.00Lines of code
LOGICAL_LINES500.00Number of statements
LOOPS 8.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS2435.00Number of operands
OPERATORS4468.00Number of operators
PARAMS42.00Number of formal parameter declarations
PROGRAM_LENGTH6903.00Halstead program length
PROGRAM_VOCAB797.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS94.00Number of return points from functions
SIZE51258.00Size of the file in bytes
UNIQUE_OPERANDS746.00Number of unique operands
UNIQUE_OPERATORS51.00Number of unique operators
WHITESPACE260.00Number of whitespace lines