NotesView.java

Index Score
plugin.notes.gui
PCGen

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
EXITSProcedure exits
LOCLines of code
DECL_COMMENTSComments in declarations
LOGICAL_LINESNumber of statements
LINESNumber of lines in the source file
ELOCEffective lines of code
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
OPERATORSNumber of operators
UNIQUE_OPERANDSNumber of unique operands
LINE_COMMENTNumber of line comments
BLOCKSNumber of blocks
SIZESize of the file in bytes
PROGRAM_VOCABHalstead program vocabulary
FUNCTIONSNumber of function declarations
CYCLOMATICCyclomatic complexity
INTERFACE_COMPLEXITYInterface complexity
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
JAVA0145JAVA0145 Tab character used in source file
PARAMSNumber of formal parameter declarations
WHITESPACENumber of whitespace lines
COMPARISONSNumber of comparison operators
COMMENTSComment lines
DOC_COMMENTNumber of javadoc comment lines
LOOPSNumber of loops
JAVA0166JAVA0166 Generic exception caught
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0034JAVA0034 Missing braces in if statement
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0128JAVA0128 Public constructor in non-public class
NEST_DEPTHMaximum nesting depth
UNIQUE_OPERATORSNumber of unique operators
JAVA0237JAVA0237 Class implements Cloneable but does not have public clone method
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0043JAVA0043 Inner class does not use outer class
JAVA0123JAVA0123 Use all three components of for loop
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
/* * NotesView.java - the main view for the Notes plugin for GMGen * Copyright (C) 2003 Devon Jones * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Created on May 24, 2003 */ package plugin.notes.gui; import gmgen.GMGenSystem; import gmgen.GMGenSystemView; import gmgen.gui.ExtendedHTMLDocument; import gmgen.gui.ExtendedHTMLEditorKit; import gmgen.gui.ImageFileChooser; import gmgen.io.SimpleFileFilter; import gmgen.util.LogReceiver; import gmgen.util.LogUtilities; import gmgen.util.MiscUtilities; import pcgen.core.SettingsHandler; import pcgen.gui.panes.FlippingSplitPane; import pcgen.util.Logging; import plugin.notes.NotesPlugin; import javax.swing.*; import javax.swing.border.BevelBorder; import javax.swing.border.EtchedBorder; import javax.swing.event.*; import javax.swing.filechooser.FileFilter; import javax.swing.text.*; import javax.swing.text.html.HTML; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; import javax.swing.undo.UndoManager; import java.awt.Color; import java.awt.Component; import java.awt.Point; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.dnd.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.*; import java.text.SimpleDateFormat; import java.util.*; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; /** * This class is the main view for the Notes Plugin. Mostof the work is done * here and in the NotesTreeNode Class. * * @author soulcatcher * @since August 27, 2003 */ public class NotesView extends JPanel { /** Drop Target for the Edit Area */ protected DropTarget editAreaDT; /** Drop Target for the File Bar */ protected DropTarget filesBarDT; /** Drop Target for the Tree */ protected DropTarget treeDT; /** Insert OL Action for JTextPane */ protected ExtendedHTMLEditorKit.InsertListAction actionListOrdered = new ExtendedHTMLEditorKit.InsertListAction("InsertOLItem", HTML.Tag.OL); /** Insert UL Action for JTextPane */ protected ExtendedHTMLEditorKit.InsertListAction actionListUnordered = new ExtendedHTMLEditorKit.InsertListAction("InsertULItem", HTML.Tag.UL); // End of variables declaration//GEN-END:variables protected NotesPlugin plugin; /** Root node of tree */ protected NotesTreeNode root; /** Redo Action for JTextPane */ protected RedoAction redoAction = new RedoAction(); /** Data Directory */ protected String dataDir; /** Undo Action for JTextPane */ protected UndoAction undoAction = new UndoAction(); /** Undo Manager */ protected UndoManager undo = new UndoManager(); /** Image extensions that this supports */ // TODO: Move Image extensions to properties protected final String[] extsIMG = {"gif", "jpg", "jpeg", "png"}; private JButton boldButton; private JButton bulletButton; private JButton centerJustifyButton; private JButton colorButton; private JButton copyButton; private JButton cutButton; private JButton deleteButton; private JButton enumButton; private JButton exportButton; private JButton fileLeft; private JButton fileRight; private JButton imageButton; private JButton italicButton; private JButton leftJustifyButton; private JButton newButton; private JButton pasteButton; private JButton revertButton; private JButton rightJustifyButton; private JButton saveButton; private JButton underlineButton; private JComboBox sizeCB; private JPanel filePane; private JPanel jPanel1; private JPanel jPanel2; // Variables declaration - do not modify//GEN-BEGIN:variables private JScrollPane jScrollPane1; private JScrollPane jScrollPane2; private FlippingSplitPane jSplitPane1; private JTextPane editor; private JToolBar alignmentBar; private JToolBar clipboardBar; private JToolBar fileBar; private JToolBar filesBar; private JToolBar formatBar; private JTree notesTree; /** * Creates new form NotesView * *@param dataDir Data directory where notes will be stored. * @param plugin */ public NotesView(String dataDir, NotesPlugin plugin) { this.plugin = plugin; this.dataDir = dataDir; initComponents(); initEditingComponents(); initDnDComponents(); initTree(); initFileBar(new ArrayList<File>()); initLogging(); } /** * Searches a text component for a particular action. * *@param textComponent Text component to search for the action in *@param name name of the action to get *@return the action */ public Action getActionByName(JTextComponent textComponent, String name) { // TODO: This should be static in a GUIUtilities file for (Action a : textComponent.getActions()) { if (a.getValue(Action.NAME).equals(name)) { return a; } } return null; } /** * handle File->Open. Will open any .gmn files, and import them into your * notes structure */ public void handleOpen() { String sFile = SettingsHandler.getGMGenOption(NotesPlugin.LOG_NAME + ".LastFile", System.getProperty("user.dir")); File defaultFile = new File(sFile); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(defaultFile); for (FileFilter filter : plugin.getFileTypes()) { chooser.addChoosableFileFilter(filter); chooser.setFileFilter(filter); } chooser.setMultiSelectionEnabled(true); java.awt.Cursor saveCursor = MiscUtilities.setBusyCursor(GMGenSystem.inst); int option = chooser.showOpenDialog(GMGenSystem.inst); if (option == JFileChooser.APPROVE_OPTION) { for (File noteFile : chooser.getSelectedFiles()) { SettingsHandler.setGMGenOption(NotesPlugin.LOG_NAME + ".LastFile", noteFile.toString()); if (noteFile.toString().endsWith(".gmn")) { openGMN(noteFile); } } } MiscUtilities.setCursor(GMGenSystem.inst, saveCursor); refreshTree(); } /** * fills the 'edit' menu of the main menu * *@param editMenu The Edit Menu */ public void initEditMenu(JMenu editMenu) { JMenuItem paste = new JMenuItem("Paste"); paste.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pasteButtonActionPerformed(evt); } }); editMenu.insert(paste, 0); JMenuItem copy = new JMenuItem("Copy"); paste.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { copyButtonActionPerformed(evt); } }); editMenu.insert(copy, 0); JMenuItem cut = new JMenuItem("Cut"); paste.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cutButtonActionPerformed(evt); } }); editMenu.insert(cut, 0); editMenu.insertSeparator(0); editMenu.insert(redoAction, 0); editMenu.insert(undoAction, 0); } /** * Opens a .gmn file * *@param notesFile .gmn file to open */ public void openGMN(File notesFile) { try { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; if (node != root) { int choice = JOptionPane .showConfirmDialog( this, "Importing note " + notesFile.getName() + " into a node other then root, Continue?", "Importing to a node other then root", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } InputStream in = new BufferedInputStream(new FileInputStream(notesFile)); ZipInputStream zin = new ZipInputStream(in); ZipEntry e; ProgressMonitor pm = new ProgressMonitor(GMGenSystem.inst, "Reading Notes Export", "Reading", 1, 1000); int progress = 1; while ((e = zin.getNextEntry()) != null) { unzip(zin, e.getName(), node.getDir()); progress++; if (progress > 99) { progress = 99; } pm.setProgress(progress); } zin.close(); pm.close(); } } catch (IOException e) { JOptionPane.showMessageDialog(this, "Error Reading File" + notesFile.getName()); Logging.errorPrint("Error Reading File" + notesFile.getName()); Logging.errorPrint(e.getMessage(), e); } } /** refreshs the tree, and updates it's UI */ public void refreshTree() { root.refresh(); notesTree.updateUI(); } /** called when window is closed, saves everything in the tree */ public void windowClosed() { if (root.isTreeDirty()) { GMGenSystemView.getTabPane().setSelectedComponent(this); } root.checkSave(); } //Note Import/Export methods /** * Exports a node out to a gmn file. * *@param node node to export to file */ protected void exportFile(NotesTreeNode node) { JFileChooser fLoad = new JFileChooser(); String sFile = SettingsHandler.getGMGenOption(NotesPlugin.LOG_NAME + ".LastFile", ""); new File(sFile); String[] fileExt = new String[]{"gmn"}; SimpleFileFilter ff = new SimpleFileFilter(fileExt, "GMGen Notes Export"); fLoad.addChoosableFileFilter(ff); fLoad.setFileFilter(ff); int returnVal = fLoad.showSaveDialog(this); try { if (returnVal == JFileChooser.APPROVE_OPTION) { String fileName = fLoad.getSelectedFile().getName(); String dirName = fLoad.getSelectedFile().getParent(); String ext = ""; if (fileName.indexOf(".gmn") < 0) { ext = ".gmn"; } File expFile = new File(dirName + File.separator + fileName + ext); if (expFile.exists()) { int choice = JOptionPane.showConfirmDialog(this, "File Exists, Overwrite?", "File Exists", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (choice == JOptionPane.NO_OPTION) { return; } } SettingsHandler.setGMGenOption(NotesPlugin.LOG_NAME + ".LastFile", expFile.toString()); writeNotesFile(expFile, node); } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Error Writing File"); Logging.errorPrint("Error Writing to file: " + e.getMessage(), e); } } /** * gets the number of files in a directory so that you can have a progress * meter as we zip them into a gmn file. This function is recursive * *@param count File to count the children of *@return count of all files in this dir */ protected int fileCount(File count) { // TODO: Shouldn't this really be a static method in MiscUtils? int num = 0; for (File f : count.listFiles()) { if (f.isDirectory()) { num = num + fileCount(f); } else { num++; } } return num; } /** * Sets a border of an editing button to indicate that the function of the * button is active according to the text location of the cursor * *@param button Button to highlight */ protected void highlightButton(JButton button) { button.setBorder(new BevelBorder(BevelBorder.LOWERED)); } //Action methods /** * Performs an action of a particular name on the man editor. * *@param name name of the action to perform. *@param evt ActionEvent that sparked the calling of this function. */ protected void performTextPaneAction(String name, java.awt.event.ActionEvent evt) { Action action = getActionByName(editor, name); action.actionPerformed(evt); editor.grabFocus(); int cp = editor.getCaretPosition(); updateButtons(editor, cp); } /** * Sets a border of an editing button to indicate that the function of the * button is not active according to the text location of the cursor * *@param button button to set in standard mode */ protected void stdButton(JButton button) { button.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); } /** * Unzips one file from a zipinputstream * *@param zin Zip input stream *@param homeDir Directory to unzip the file to *@param entry Description of the Parameter *@exception IOException read or write error */ protected void unzip(ZipInputStream zin, String entry, File homeDir) throws IOException { // TODO: This function really should be in MiscUtils as a static File outFile = new File(homeDir.getPath() + File.separator + entry); File parentDir = outFile.getParentFile(); parentDir.mkdirs(); outFile.createNewFile(); FileOutputStream out = new FileOutputStream(outFile); byte[] b = new byte[512]; int len = 0; while ((len = zin.read(b)) != -1) { out.write(b, 0, len); } out.close(); } //Methods for dealing with button appearance /** * Updates Editing buttons based on the location of the cursor * *@param textPane text pane to update buttons base on *@param pos current text position */ protected void updateButtons(JTextPane textPane, int pos) { StyledDocument doc = textPane.getStyledDocument(); AttributeSet set = doc.getCharacterElement(pos - 1).getAttributes(); AttributeSet set1 = doc.getCharacterElement(pos).getAttributes(); if (StyleConstants.isBold(set) && StyleConstants.isBold(set1)) { highlightButton(boldButton); } else { stdButton(boldButton); } if (StyleConstants.isItalic(set) && StyleConstants.isItalic(set1)) { highlightButton(italicButton); } else { stdButton(italicButton); } if (StyleConstants.isUnderline(set) && StyleConstants.isUnderline(set1)) { highlightButton(underlineButton); } else { stdButton(underlineButton); } int align = StyleConstants.getAlignment(set); stdButton(leftJustifyButton); stdButton(rightJustifyButton); stdButton(centerJustifyButton); if (align == StyleConstants.ALIGN_LEFT) { highlightButton(leftJustifyButton); } else if (align == StyleConstants.ALIGN_RIGHT) { highlightButton(rightJustifyButton); } else if (align == StyleConstants.ALIGN_CENTER) { highlightButton(centerJustifyButton); } int fontSize = StyleConstants.getFontSize(set); for (int i = 0; i < sizeCB.getItemCount(); i++) { String value = (String) sizeCB.getItemAt(i); if (value.equals(Integer.toString(fontSize))) { sizeCB.setSelectedItem(value); break; } } } /** * Writes out a directory to a zipoutputstream * *@param out Zip output stream to write to *@param parentDir parent dir of whole structure to be written out *@param currentDir dir to be zipped up *@param pm progress meter that will display the progress *@param progress progress up to this dir *@return current progress *@exception IOException write or read failed for some reason */ protected int writeNotesDir(ZipOutputStream out, File parentDir, File currentDir, ProgressMonitor pm, int progress) throws IOException { byte[] buffer = new byte[4096]; int bytes_read; int returnValue = progress; for (File f : currentDir.listFiles()) { if (pm.isCanceled()) { return 0; } if (f.isDirectory()) { returnValue = writeNotesDir(out, parentDir, f, pm, returnValue); } else { FileInputStream in = new FileInputStream(f); try { String parentPath = parentDir.getParentFile().getAbsolutePath(); ZipEntry entry = new ZipEntry(f.getAbsolutePath().substring( parentPath.length() + 1)); out.putNextEntry(entry); while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } } finally { try { in.close(); } catch (IOException e) { //TODO: Should this really be ignored? } } returnValue++; } } pm.setProgress(returnValue); return returnValue; } /** * Writes out a GMN file * *@param exportFile file to export to *@param node node to export *@exception IOException file write failed for some reason */ protected void writeNotesFile(File exportFile, NotesTreeNode node) throws IOException { File dir = node.getDir(); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(exportFile)); int max = fileCount(dir); ProgressMonitor pm = new ProgressMonitor(GMGenSystem.inst, "Writing out Notes Export", "Writing", 0, max); try { writeNotesDir(out, dir, dir, pm, 0); } // Always close the streams, even if exceptions were thrown finally { try { out.close(); } catch (IOException e) { //TODO: Should this really be ignored? } } pm.close(); } //CoreUtility methods private File getCurrentDir() { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; return node.getDir(); } return null; } /** * obtains an Image for input using a custom JFileChooser dialog * *@param startDir Directory to open JFielChooser to *@param exts Extensions to search for *@param desc Description for files *@return File pointing to the selected image */ private File getImageFromChooser(String startDir, String[] exts, String desc) { ImageFileChooser jImageDialog = new ImageFileChooser(startDir); jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG); jImageDialog.setFileFilter(new SimpleFileFilter(exts, desc)); jImageDialog.setDialogTitle("Select an Image to Insert"); int optionSelected = JFileChooser.CANCEL_OPTION; optionSelected = jImageDialog.showDialog(this, "Insert"); if (optionSelected == JFileChooser.APPROVE_OPTION) { return jImageDialog.getSelectedFile(); } return null; } private void notesTreeNodesChanged() { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; try { node.rename((String) node.getUserObject()); } catch (Exception e) { System.out.println(e.getMessage()); } } } //GEN-LAST:event_italicButtonActionPerformed private void boldButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_boldButtonActionPerformed performTextPaneAction("font-bold", evt); } //GEN-LAST:event_rightJustifyButtonActionPerformed private void centerJustifyButtonActionPerformed( java.awt.event.ActionEvent evt) { //GEN-FIRST:event_centerJustifyButtonActionPerformed Action action = new StyledEditorKit.AlignmentAction("Align Centre", StyleConstants.ALIGN_CENTER); action.actionPerformed(evt); editor.grabFocus(); int cp = editor.getCaretPosition(); updateButtons(editor, cp); } //GEN-LAST:event_leftJustifyButtonActionPerformed private void colorButtonActionPerformed() { //GEN-FIRST:event_colorButtonActionPerformed AttributeSet as = editor.getCharacterAttributes(); SimpleAttributeSet sas = new SimpleAttributeSet(as); Color newColor = JColorChooser.showDialog(GMGenSystem.inst, "Choose Text Color", editor.getStyledDocument().getForeground(as)); if (newColor != null) { StyleConstants.setForeground(sas, newColor); editor.setCharacterAttributes(sas, true); } editor.repaint(); } //GEN-LAST:event_pasteButtonActionPerformed private void copyButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_copyButtonActionPerformed performTextPaneAction(DefaultEditorKit.copyAction, evt); } //GEN-LAST:event_copyButtonActionPerformed private void cutButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_cutButtonActionPerformed performTextPaneAction(DefaultEditorKit.cutAction, evt); } //GEN-LAST:event_cutButtonActionPerformed private void deleteButtonActionPerformed() { //GEN-FIRST:event_deleteButtonActionPerformed Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; node.delete(); } notesTree.updateUI(); } //GEN-LAST:event_newButtonActionPerformed private void editorCaretUpdate(CaretEvent evt) { //GEN-FIRST:event_editorCaretUpdate int dot = evt.getDot(); updateButtons(editor, dot); Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; if (node.isDirty()) { revertButton.setEnabled(true); } else { revertButton.setEnabled(false); } } } // Key Events private void editorKeyTyped(KeyEvent evt) { editor.getCaretPosition(); editor.getStyledDocument(); if (evt.getKeyChar() == KeyEvent.VK_BACK_SPACE) { handleBackspace(); } else if (evt.getKeyChar() == KeyEvent.VK_ENTER) { handleEnter(); } } //GEN-LAST:event_editorCaretUpdate // Edit Events private void editorUndoableEditHappened(UndoableEditEvent e) { undo.addEdit(e.getEdit()); undoAction.updateUndoState(); redoAction.updateRedoState(); } //GEN-END:initComponents private void exportButtonActionPerformed() { //GEN-FIRST:event_exportButtonActionPerformed Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; exportFile(node); } } //GEN-LAST:event_fileRightActionPerformed private void fileLeftActionPerformed() { //GEN-FIRST:event_fileLeftActionPerformed if (filesBar.getComponentCount() > 1) { Component c = filesBar.getComponent(filesBar.getComponentCount() - 1); filesBar.remove(c); filesBar.add(c, 0); } filesBar.updateUI(); } //GEN-LAST:event_imageButtonActionPerformed private void fileRightActionPerformed() { //GEN-FIRST:event_fileRightActionPerformed if (filesBar.getComponentCount() > 1) { Component c = filesBar.getComponent(0); filesBar.remove(c); filesBar.add(c); } filesBar.updateUI(); } //methods dealing with Key Events private void handleBackspace() { // TODO: This sucks, clean it up Element elem; int pos = editor.getCaretPosition(); ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument(); try { if (pos > 0) { if ((editor.getSelectedText()) != null) { ExtendedHTMLEditorKit.delete(editor); return; } int sOffset = htmlDoc.getParagraphElement(pos).getStartOffset(); if (sOffset == editor.getSelectionStart()) { boolean content = true; if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc .getParagraphElement(editor.getCaretPosition()), HTML.Tag.LI)) { elem = ExtendedHTMLEditorKit.getListItemParent(htmlDoc .getCharacterElement(editor .getCaretPosition())); content = false; int so = elem.getStartOffset(); int eo = elem.getEndOffset(); if ((so + 1) < eo) { char[] temp = editor.getText(so, eo - so).toCharArray(); for (int i = 0; i < temp.length; i++) { if (!Character.isWhitespace(temp[i])) { content = true; } } } if (!content) { elem.getParentElement(); ExtendedHTMLEditorKit.removeTag(editor, elem, true); editor.setCaretPosition(sOffset - 1); return; } editor.setCaretPosition(editor.getCaretPosition() - 1); editor.moveCaretPosition(editor.getCaretPosition() - 2); editor.replaceSelection(""); return; } } editor.replaceSelection(""); return; } } catch (BadLocationException ble) { Logging.errorPrint(ble.getMessage(), ble); } } private void handleEnter() { // TODO: this sucks. clean it up Element elem; int pos = editor.getCaretPosition(); int repos = -1; ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument(); try { if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc .getParagraphElement(editor.getCaretPosition()), HTML.Tag.UL) || ExtendedHTMLEditorKit.checkParentsTag(htmlDoc .getParagraphElement(editor.getCaretPosition()), HTML.Tag.OL)) { elem = ExtendedHTMLEditorKit.getListItemParent(htmlDoc .getCharacterElement(editor.getCaretPosition())); int so = elem.getStartOffset(); int eo = elem.getEndOffset(); char[] temp = editor.getText(so, eo - so).toCharArray(); boolean content = false; for (int i = 0; i < temp.length; i++) { if (!Character.isWhitespace(temp[i])) { content = true; } } if (content) { int end = -1; int j = temp.length; do { j--; if (Character.isLetterOrDigit(temp[j])) { end = j; } } while ((end == -1) && (j >= 0)); j = end; do { j++; if (!Character.isSpaceChar(temp[j])) { repos = j - end - 1; } } while ((repos == -1) && (j < temp.length)); if (repos == -1) { repos = 0; } } if ((elem.getStartOffset() == elem.getEndOffset()) || !content) { manageListElement(htmlDoc); } else { if ((editor.getCaretPosition() + 1) == elem.getEndOffset()) { ExtendedHTMLEditorKit.insertListElement(editor, ""); editor.setCaretPosition(pos - repos); } else { int caret = editor.getCaretPosition(); String tempString = editor.getText(caret, eo - caret); editor.select(caret, eo - 1); editor.replaceSelection(""); ExtendedHTMLEditorKit.insertListElement(editor, tempString); Element newLi = ExtendedHTMLEditorKit.getListItemParent(htmlDoc .getCharacterElement(editor .getCaretPosition())); editor.setCaretPosition(newLi.getEndOffset()); } } } } catch (BadLocationException ble) { Logging.errorPrint(ble.getMessage(), ble); } } //GEN-LAST:event_revertButtonActionPerformed private void imageButtonActionPerformed() { //GEN-FIRST:event_imageButtonActionPerformed try { insertLocalImage(null); } catch (Exception e) { Logging.errorPrint(e.getMessage(), e); } } /** * 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. */ private void initComponents() { //GEN-BEGIN:initComponents jSplitPane1 = new FlippingSplitPane(); jScrollPane1 = new JScrollPane(); notesTree = new JTree(); jPanel1 = new JPanel(); jScrollPane2 = new JScrollPane(); editor = new JTextPane(); jPanel2 = new JPanel(); fileBar = new JToolBar(); newButton = new JButton(); saveButton = new JButton(); exportButton = new JButton(); revertButton = new JButton(); deleteButton = new JButton(); clipboardBar = new JToolBar(); cutButton = new JButton(); copyButton = new JButton(); pasteButton = new JButton(); formatBar = new JToolBar(); sizeCB = new JComboBox(); boldButton = new JButton(); italicButton = new JButton(); underlineButton = new JButton(); colorButton = new JButton(); bulletButton = new JButton(); enumButton = new JButton(); imageButton = new JButton(); alignmentBar = new JToolBar(); leftJustifyButton = new JButton(); centerJustifyButton = new JButton(); rightJustifyButton = new JButton(); filePane = new JPanel(); fileLeft = new JButton(); fileRight = new JButton(); filesBar = new JToolBar(); setLayout(new java.awt.BorderLayout()); jSplitPane1.setDividerLocation(175); jSplitPane1.setDividerSize(5); jScrollPane1.setViewportView(notesTree); jSplitPane1.setLeftComponent(jScrollPane1); jPanel1.setLayout(new java.awt.BorderLayout()); editor.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent evt) { editorCaretUpdate(evt); } }); jScrollPane2.setViewportView(editor); jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER); jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0)); newButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_new-16.png"))); newButton.setToolTipText("New Node"); newButton.setBorder(new EtchedBorder()); newButton.setEnabled(false); newButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newButtonActionPerformed(); } }); fileBar.add(newButton); saveButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_save-16.png"))); saveButton.setToolTipText("Save Node"); saveButton.setBorder(new EtchedBorder()); saveButton.setEnabled(false); saveButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveButtonActionPerformed(); } }); fileBar.add(saveButton); exportButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_export-16.png"))); exportButton.setToolTipText("Export"); exportButton.setBorder(new EtchedBorder()); exportButton.setEnabled(false); exportButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exportButtonActionPerformed(); } }); fileBar.add(exportButton); revertButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_revert-16.png"))); revertButton.setToolTipText("Revert to Saved"); revertButton.setBorder(new EtchedBorder()); revertButton.setEnabled(false); revertButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { revertButtonActionPerformed(); } }); fileBar.add(revertButton); deleteButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_broken_image-16.png"))); deleteButton.setToolTipText("Delete Node"); deleteButton.setBorder(new EtchedBorder()); deleteButton.setEnabled(false); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(); } }); fileBar.add(deleteButton); jPanel2.add(fileBar); cutButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_cut-16.png"))); cutButton.setToolTipText("Cut"); cutButton.setBorder(new EtchedBorder()); cutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cutButtonActionPerformed(evt); } }); clipboardBar.add(cutButton); copyButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_copy-16.png"))); copyButton.setToolTipText("Copy"); copyButton.setBorder(new EtchedBorder()); copyButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { copyButtonActionPerformed(evt); } }); clipboardBar.add(copyButton); pasteButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_paste-16.png"))); pasteButton.setToolTipText("Paste"); pasteButton.setBorder(new EtchedBorder()); pasteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pasteButtonActionPerformed(evt); } }); clipboardBar.add(pasteButton); jPanel2.add(clipboardBar); sizeCB.setToolTipText("Size"); sizeCB.setBorder(new EtchedBorder()); sizeCB.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { sizeCBActionPerformed(evt); } }); formatBar.add(sizeCB); boldButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_text_bold-16.png"))); boldButton.setToolTipText("Bold"); boldButton.setBorder(new EtchedBorder()); boldButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { boldButtonActionPerformed(evt); } }); formatBar.add(boldButton); italicButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_text_italic-16.png"))); italicButton.setToolTipText("Italic"); italicButton.setBorder(new EtchedBorder()); italicButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { italicButtonActionPerformed(evt); } }); formatBar.add(italicButton); underlineButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_text_underline-16.png"))); underlineButton.setToolTipText("Underline"); underlineButton.setBorder(new EtchedBorder()); underlineButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { underlineButtonActionPerformed(evt); } }); formatBar.add(underlineButton); colorButton.setForeground(new java.awt.Color(0, 0, 0)); colorButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/menu-mode-RGB-alt.png"))); colorButton.setToolTipText("Color"); colorButton.setBorder(new EtchedBorder()); colorButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { colorButtonActionPerformed(); } }); formatBar.add(colorButton); bulletButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_list_bulet-16.png"))); bulletButton.setToolTipText("Bulleted List"); bulletButton.setAction(actionListUnordered); bulletButton.setBorder(new EtchedBorder()); formatBar.add(bulletButton); enumButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_list_enum-16.png"))); enumButton.setToolTipText("Numbered List"); enumButton.setAction(actionListOrdered); enumButton.setBorder(new EtchedBorder()); formatBar.add(enumButton); imageButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_insert_graphic-16.png"))); imageButton.setBorder(new EtchedBorder()); imageButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { imageButtonActionPerformed(); } }); formatBar.add(imageButton); jPanel2.add(formatBar); leftJustifyButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_text_align_left-16.png"))); leftJustifyButton.setToolTipText("Left Justify"); leftJustifyButton.setBorder(new EtchedBorder()); leftJustifyButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { leftJustifyButtonActionPerformed(evt); } }); alignmentBar.add(leftJustifyButton); centerJustifyButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_text_align_center-16.png"))); centerJustifyButton.setToolTipText("Center"); centerJustifyButton.setBorder(new EtchedBorder()); centerJustifyButton .addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { centerJustifyButtonActionPerformed(evt); } }); alignmentBar.add(centerJustifyButton); rightJustifyButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_text_align_right-16.png"))); rightJustifyButton.setToolTipText("Right Justify"); rightJustifyButton.setBorder(new EtchedBorder()); rightJustifyButton .addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rightJustifyButtonActionPerformed(evt); } }); alignmentBar.add(rightJustifyButton); jPanel2.add(alignmentBar); jPanel1.add(jPanel2, java.awt.BorderLayout.NORTH); filePane.setLayout(new BoxLayout(filePane, BoxLayout.X_AXIS)); fileLeft.setText("<"); fileLeft.setBorder(new EtchedBorder()); fileLeft.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fileLeftActionPerformed(); } }); filePane.add(fileLeft); fileRight.setText(">"); fileRight.setBorder(new EtchedBorder()); fileRight.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { fileRightActionPerformed(); } }); filePane.add(fileRight); filePane.add(filesBar); jPanel1.add(filePane, java.awt.BorderLayout.SOUTH); jSplitPane1.setRightComponent(jPanel1); add(jSplitPane1, java.awt.BorderLayout.CENTER); } private void initDnDComponents() { filesBarDT = new DropTarget(filesBar, new DropBarListener()); treeDT = new DropTarget(notesTree, new DropTreeListener()); } private void initEditingComponents() { bulletButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_list_bulet-16.png"))); bulletButton.setToolTipText("Bulleted List"); enumButton.setIcon(new ImageIcon(getClass().getResource( "/pcgen/gui/resource/stock_list_enum-16.png"))); enumButton.setToolTipText("Numbered List"); enumButton.setText(""); bulletButton.setText(""); Vector<String> fontVector = new Vector<String>(); fontVector.add("8"); fontVector.add("10"); fontVector.add("12"); fontVector.add("14"); fontVector.add("16"); fontVector.add("18"); fontVector.add("24"); fontVector.add("36"); fontVector.add("48"); DefaultComboBoxModel cbModel = new DefaultComboBoxModel(fontVector); sizeCB.setModel(cbModel); sizeCB.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); stdButton(boldButton); stdButton(italicButton); stdButton(underlineButton); stdButton(colorButton); stdButton(leftJustifyButton); stdButton(centerJustifyButton); stdButton(rightJustifyButton); stdButton(newButton); stdButton(saveButton); stdButton(deleteButton); stdButton(cutButton); stdButton(copyButton); stdButton(pasteButton); } private void initFileBar(List<File> files) { filePane.removeAll(); filesBar.removeAll(); if (files.size() > 0) { filePane.add(fileLeft); filePane.add(fileRight); filePane.add(filesBar); for (File f : files) { filesBar.add(new JIcon(f, plugin)); } } filePane.updateUI(); } private void initLogging() { LogUtilities.inst().addReceiver(new NotesLogReciever()); } //Initialization methods private void initTree() { File dir = new File(dataDir); dir.listFiles(); root = new NotesTreeNode(dir.getName(), dir, notesTree); TreeModel model = new DefaultTreeModel(root); notesTree.setModel(model); notesTree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { notesTreeActionPerformed(); } }); notesTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION); notesTree.setEditable(true); model.addTreeModelListener(new TreeModelListener() { public void treeNodesChanged(TreeModelEvent e) { notesTreeNodesChanged(); } public void treeNodesInserted(TreeModelEvent e) { // TODO: Method does nothing? } public void treeNodesRemoved(TreeModelEvent e) { // TODO: Method does nothing? } public void treeStructureChanged(TreeModelEvent e) { // TODO: Method does nothing? } }); } //Image insertion methods /** * Method for inserting an image from a file * *@param whatImage pointer to file *@exception IOException if the file can't be read *@exception BadLocationException if the file does not exist *@exception RuntimeException cause */ private void insertLocalImage(File whatImage) throws IOException, BadLocationException, RuntimeException { File image = whatImage; if (whatImage == null) { File dir = getCurrentDir(); File newImage = getImageFromChooser(dir.getPath(), extsIMG, "Image File"); //null possible if user cancelled if (newImage != null && newImage.exists()) { image = new File(dir.getAbsolutePath() + File.separator + newImage.getName()); if (!image.exists()) { MiscUtilities.copy(newImage, image); } } } if (image != null) { int caretPos = editor.getCaretPosition(); ExtendedHTMLEditorKit htmlKit = (ExtendedHTMLEditorKit) editor.getEditorKit(); ExtendedHTMLDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument(); htmlKit.insertHTML(htmlDoc, caretPos, "<IMG SRC=\"" + image + "\">", 0, 0, HTML.Tag.IMG); editor.setCaretPosition(caretPos + 1); } } //GEN-LAST:event_underlineButtonActionPerformed private void italicButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_italicButtonActionPerformed performTextPaneAction("font-italic", evt); } //GEN-LAST:event_centerJustifyButtonActionPerformed private void leftJustifyButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_leftJustifyButtonActionPerformed Action action = new StyledEditorKit.AlignmentAction("Left Justify", StyleConstants.ALIGN_LEFT); action.actionPerformed(evt); editor.grabFocus(); int cp = editor.getCaretPosition(); updateButtons(editor, cp); } private void manageListElement(ExtendedHTMLDocument htmlDoc) { Element h = ExtendedHTMLEditorKit.getListItemParent(htmlDoc .getCharacterElement(editor.getCaretPosition())); h.getParentElement(); ExtendedHTMLEditorKit.removeTag(editor, h, true); } //GEN-LAST:event_saveButtonActionPerformed private void newButtonActionPerformed() { //GEN-FIRST:event_newButtonActionPerformed Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; node.createChild(); } refreshTree(); } //Tree Events private void notesTreeActionPerformed() { // Add your handling code here: refreshTreeNodes(); } //GEN-LAST:event_boldButtonActionPerformed private void pasteButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_pasteButtonActionPerformed performTextPaneAction(DefaultEditorKit.pasteAction, evt); } //Gui methods private void refreshTreeNodes() { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; editor = node.getTextPane(); root.checkCache(); // TODO: Uh-oh -- never call gc manually without strong reason // Runtime.getRuntime().gc(); JViewport vp = new JViewport(); vp.setView(editor); jScrollPane2.setViewport(vp); editAreaDT = new DropTarget(editor, new DropEditorListener()); editor.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent evt) { editorCaretUpdate(evt); } }); editor.addKeyListener(new java.awt.event.KeyListener() { public void keyTyped(KeyEvent e) { editorKeyTyped(e); } public void keyPressed(KeyEvent e) { // TODO: Method does nothing? } public void keyReleased(KeyEvent e) { // TODO: Method does nothing? } }); editor.getStyledDocument().addUndoableEditListener( new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { editorUndoableEditHappened(evt); } }); if (node.isLeaf()) { deleteButton.setEnabled(true); } else { deleteButton.setEnabled(false); } if (node == root) { exportButton.setEnabled(false); } else { exportButton.setEnabled(true); } if (node.isDirty()) { revertButton.setEnabled(true); } else { revertButton.setEnabled(false); } initFileBar(node.getFiles()); saveButton.setEnabled(true); newButton.setEnabled(true); } else if (obj == null) { deleteButton.setEnabled(false); saveButton.setEnabled(false); revertButton.setEnabled(false); newButton.setEnabled(false); } } //GEN-LAST:event_exportButtonActionPerformed private void revertButtonActionPerformed() { //GEN-FIRST:event_revertButtonActionPerformed Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; node.revert(); refreshTreeNodes(); notesTree.updateUI(); } } //GEN-LAST:event_sizeCBActionPerformed private void rightJustifyButtonActionPerformed( java.awt.event.ActionEvent evt) { //GEN-FIRST:event_rightJustifyButtonActionPerformed Action action = new StyledEditorKit.AlignmentAction("Right Justify", StyleConstants.ALIGN_RIGHT); action.actionPerformed(evt); editor.grabFocus(); int cp = editor.getCaretPosition(); updateButtons(editor, cp); } //GEN-LAST:event_deleteButtonActionPerformed private void saveButtonActionPerformed() { //GEN-FIRST:event_saveButtonActionPerformed Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; node.save(); } revertButton.setEnabled(false); notesTree.updateUI(); } //GEN-LAST:event_fileLeftActionPerformed private void sizeCBActionPerformed(final ActionEvent evt) { //GEN-FIRST:event_sizeCBActionPerformed if (sizeCB.hasFocus()) { String fontS = (String) sizeCB.getSelectedItem(); performTextPaneAction("font-size-" + fontS, evt); } } //GEN-LAST:event_colorButtonActionPerformed private void underlineButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_underlineButtonActionPerformed performTextPaneAction("font-underline", evt); } /** * This is an abstract drop listener. Extend this to listen for drop events * for a particular Component */ public abstract class DropListener implements DropTargetListener { /** * Checks to see if dragEnter is supported for the actions on this event * Accepts only javaFileListFlavor data flavors * *@param dtde DropTargetDragEvent */ public void dragEnter(DropTargetDragEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(dtde.getDropAction()); } else { dtde.rejectDrag(); } } /** * Called when drag exit happens. override this id you need anythign to * happen * *@param dte DropTargetEvent */ public void dragExit(DropTargetEvent dte) { // TODO: Method does nothing? } /** * Accpets a drag over if the data flavor is javaFileListFlavor, otherwise * rejects it. * *@param dtde DropTargetDragEvent */ public void dragOver(DropTargetDragEvent dtde) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.acceptDrag(dtde.getDropAction()); } else { dtde.rejectDrag(); } } /** * implements a drop. you need to implements this in your class. * *@param dtde DropTargetDropEvent */ public abstract void drop(DropTargetDropEvent dtde); /** * Action has changed - we don't do anything, override if you need it to. * *@param dtde DropTargetDragEvent */ public void dropActionChanged(DropTargetDragEvent dtde) { // TODO: Method does nothing? } } /** * Drop listener for the File bar on the bottom of the Notes screen */ public class DropBarListener extends DropListener { /** * implements drop.if we accept it, pass the event to the currently selected * node * *@param dtde DropTargetDropEvent */ public void drop(DropTargetDropEvent dtde) { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.dropComplete(node.handleDropJavaFileList(dtde)); refreshTreeNodes(); } else { dtde.rejectDrop(); } } else { dtde.rejectDrop(); } } } /** * Drop listener for the Editor pane on the notes screen */ public class DropEditorListener extends DropListener { /** * Determines if a file passed in is an image or not (based on extension * *@param image File to check *@return true if image, false if not */ public boolean isImageFile(File image) { for (int i = 0; i < extsIMG.length; i++) { if (image.getName().endsWith(extsIMG[i])) { return true; } } return false; } /** * implements drop. if we accept it, pass the eventthe handler * *@param dtde Description of the Parameter */ public void drop(DropTargetDropEvent dtde) { Object obj = notesTree.getLastSelectedPathComponent(); if (obj instanceof NotesTreeNode) { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.dropComplete(handleDropJavaFileListAsImage(dtde)); refreshTreeNodes(); } else { dtde.rejectDrop(); } } else { dtde.rejectDrop(); } } /** * handles a drop. if the drop is an image, it will insert the image to the * proper place in the editor window. * *@param dtde DropTargetDropEvent *@return drop successful or not */ public boolean handleDropJavaFileListAsImage(DropTargetDropEvent dtde) { dtde.acceptDrop(dtde.getDropAction()); Transferable t = dtde.getTransferable(); try { List fileList = ((List) t .getTransferData(DataFlavor.javaFileListFlavor)); File dir = getCurrentDir(); for (int i = 0; i < fileList.size(); i++) { File newFile = (File) fileList.get(i); if (newFile.exists()) { File destFile = new File(dir.getAbsolutePath() + File.separator + newFile.getName()); if (!isImageFile(destFile) || !destFile.exists()) { MiscUtilities.copy(newFile, destFile); } editor.setCaretPosition(editor.viewToModel(dtde .getLocation())); handleImageDropInsertion(destFile); } } } catch (Exception e) { Logging.errorPrint(e.getMessage(), e); return false; } return true; } /** * Inserts a dropped image into the editor pane * *@param image File to insert */ public void handleImageDropInsertion(File image) { for (String s : extsIMG) { if (image.getName().endsWith(s)) { try { insertLocalImage(image); } catch (Exception e) { Logging.errorPrint(e.getMessage(), e); } break; } } } } /** * Drop listener for the Tree */ public class DropTreeListener extends DropListener { /** * implements drop.if we accept it, pass the event to the currently selected * node * *@param dtde Description of the Parameter */ public void drop(DropTargetDropEvent dtde) { Point p = dtde.getLocation(); TreePath path = notesTree.getPathForLocation(p.x, p.y); if (path == null) { dtde.rejectDrop(); return; } Object obj = path.getLastPathComponent(); if (obj instanceof NotesTreeNode) { NotesTreeNode node = (NotesTreeNode) obj; if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { dtde.dropComplete(node.handleDropJavaFileList(dtde)); refreshTreeNodes(); } else { dtde.rejectDrop(); } } else { dtde.rejectDrop(); } } } public class NotesLogReciever implements LogReceiver { NotesTreeNode log; public NotesLogReciever() { // Empty Constructor } /** * Logs a message associated with a specific owner. * * @param owner the owner of the message being logged. * @param message the message to log. *@since GMGen 3.3 */ public void logMessage(String owner, String message) { if (log == null) { log = getChildNode("Logs", root); } NotesTreeNode node = getChildNode(owner, log); SimpleDateFormat dateFmt = new SimpleDateFormat("MM-dd-yyyy hh.mm.ss a z"); node.appendText("<br>\n<b>" + dateFmt.format(Calendar.getInstance().getTime()) + "</b> " + message); } /** * Logs a message not associated with a specific owner. * * @param message the message to log. *@since GMGen 3.3 */ public void logMessage(String message) { logMessage("Misc", message); } private NotesTreeNode getChildNode(String name, NotesTreeNode parentNode) { Enumeration newNodes = parentNode.children(); for (; newNodes.hasMoreElements();) { NotesTreeNode node = (NotesTreeNode) newNodes.nextElement(); if (node.getUserObject().equals(NotesTreeNode.checkName(name))) { return node; } } return parentNode.createChild(name); } } /** * Action implementing Redo for editor */ protected class RedoAction extends AbstractAction { /** Constructor for the RedoAction object */ public RedoAction() { super("Redo"); setEnabled(false); } /** * Redo Action is preformed, run undo on the undo manager * *@param e Action Event */ public void actionPerformed(ActionEvent e) { try { undo.redo(); } catch (CannotRedoException ex) { Logging.errorPrint("Unable to redo: " + ex); } updateRedoState(); undoAction.updateUndoState(); } /** Update the current state of the redo labe */ protected void updateRedoState() { if (undo.canRedo()) { setEnabled(true); putValue(Action.NAME, undo.getRedoPresentationName()); } else { setEnabled(false); putValue(Action.NAME, "Redo"); } } } //Internal Classes /** * Action implementing Undo for editor */ protected class UndoAction extends AbstractAction { /** Constructor for the UndoAction object */ public UndoAction() { super("Undo"); setEnabled(false); } /** * Undo Action is preformed, run undo on the undo manager. * *@param e Action Event */ public void actionPerformed(ActionEvent e) { try { undo.undo(); } catch (CannotUndoException ex) { Logging.errorPrint("Unable to undo: " + ex.getMessage(), ex); } updateUndoState(); redoAction.updateRedoState(); } /** Update the current state of the undo label */ protected void updateUndoState() { if (undo.canUndo()) { setEnabled(true); putValue(Action.NAME, undo.getUndoPresentationName()); } else { setEnabled(false); putValue(Action.NAME, "Undo"); } } } }

The table below shows all metrics for NotesView.java.

MetricValueDescription
BLOCKS253.00Number of blocks
BLOCK_COMMENT20.00Number of block comment lines
COMMENTS336.00Comment lines
COMMENT_DENSITY 0.30Comment density
COMPARISONS101.00Number of comparison operators
CYCLOMATIC216.00Cyclomatic complexity
DECL_COMMENTS92.00Comments in declarations
DOC_COMMENT239.00Number of javadoc comment lines
ELOC1121.00Effective lines of code
EXEC_COMMENTS40.00Comments in executable code
EXITS300.00Procedure exits
FUNCTIONS107.00Number of function declarations
HALSTEAD_DIFFICULTY96.06Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY232.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 1.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 0.00JAVA0007 Should not declare public field
JAVA0008 0.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 0.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
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.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 1.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 4.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 1.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 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 2.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 1.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 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.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 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.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 0.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 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 1.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 1.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 2.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 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01455090.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 5.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.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 4.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 3.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
JAVA0237 2.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 0.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 1.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 3.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
LINES2307.00Number of lines in the source file
LINE_COMMENT77.00Number of line comments
LOC1670.00Lines of code
LOGICAL_LINES732.00Number of statements
LOOPS11.00Number of loops
NEST_DEPTH 8.00Maximum nesting depth
OPERANDS3121.00Number of operands
OPERATORS5702.00Number of operators
PARAMS94.00Number of formal parameter declarations
PROGRAM_LENGTH8823.00Halstead program length
PROGRAM_VOCAB983.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS138.00Number of return points from functions
SIZE55742.00Size of the file in bytes
UNIQUE_OPERANDS926.00Number of unique operands
UNIQUE_OPERATORS57.00Number of unique operators
WHITESPACE301.00Number of whitespace lines