View.java

Index Score
org.gjt.sp.jedit
jEdit

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
DECL_COMMENTSComments in declarations
LINE_COMMENTNumber of line comments
JAVA0034JAVA0034 Missing braces in if statement
EXITSProcedure exits
LINESNumber of lines in the source file
CYCLOMATICCyclomatic complexity
ELOCEffective lines of code
LOCLines of code
LOGICAL_LINESNumber of statements
COMMENTSComment lines
SIZESize of the file in bytes
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
OPERANDSNumber of operands
DOC_COMMENTNumber of javadoc comment lines
UNIQUE_OPERANDSNumber of unique operands
FUNCTIONSNumber of function declarations
PROGRAM_VOCABHalstead program vocabulary
COMPARISONSNumber of comparison operators
INTERFACE_COMPLEXITYInterface complexity
BLOCKSNumber of blocks
RETURNSNumber of return points from functions
PARAMSNumber of formal parameter declarations
JAVA0145JAVA0145 Tab character used in source file
LOOPSNumber of loops
WHITESPACENumber of whitespace lines
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
EXEC_COMMENTSComments in executable code
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0007JAVA0007 Should not declare public field
JAVA0075JAVA0075 Method parameter hides field
JAVA0179JAVA0179 Local variable hides visible field
JAVA0143JAVA0143 Synchronized method
JAVA0039JAVA0039 Break statement with label
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0035JAVA0035 Missing braces in for statement
JAVA0032JAVA0032 Switch statement missing default
UNIQUE_OPERATORSNumber of unique operators
JAVA0150JAVA0150 java.lang.Error (or subclass) thrown
JAVA0068JAVA0068 Modifiers not declared in recommended order
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0262JAVA0262 Use of char in integer context
/* * View.java - jEdit view * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1998, 2004 Slava Pestov * * 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 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. */ package org.gjt.sp.jedit; //{{{ Imports import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Frame; import java.awt.Rectangle; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.io.StreamTokenizer; import java.io.StringReader; import java.net.Socket; import java.util.ArrayList; import java.util.List; import java.util.Stack; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.LayoutFocusTraversalPolicy; import javax.swing.SwingUtilities; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; import org.gjt.sp.jedit.bufferset.BufferSet; import org.gjt.sp.jedit.bufferset.BufferSetManager; import org.gjt.sp.jedit.gui.ActionBar; import org.gjt.sp.jedit.gui.DefaultInputHandler; import org.gjt.sp.jedit.gui.DockableWindowFactory; import org.gjt.sp.jedit.gui.DockableWindowManager; import org.gjt.sp.jedit.gui.HistoryModel; import org.gjt.sp.jedit.gui.IDockingFrameworkProvider; import org.gjt.sp.jedit.gui.InputHandler; import org.gjt.sp.jedit.gui.StatusBar; import org.gjt.sp.jedit.gui.ToolBarManager; import org.gjt.sp.jedit.gui.VariableGridLayout; import org.gjt.sp.jedit.gui.DockableWindowManager.DockingLayout; import org.gjt.sp.jedit.input.InputHandlerProvider; import org.gjt.sp.jedit.msg.BufferUpdate; import org.gjt.sp.jedit.msg.EditPaneUpdate; import org.gjt.sp.jedit.msg.PropertiesChanged; import org.gjt.sp.jedit.msg.SearchSettingsChanged; import org.gjt.sp.jedit.msg.ViewUpdate; import org.gjt.sp.jedit.options.GeneralOptionPane; import org.gjt.sp.jedit.search.CurrentBufferSet; import org.gjt.sp.jedit.search.SearchAndReplace; import org.gjt.sp.jedit.search.SearchBar; import org.gjt.sp.jedit.textarea.JEditTextArea; import org.gjt.sp.jedit.textarea.ScrollListener; import org.gjt.sp.jedit.textarea.TextArea; import org.gjt.sp.jedit.visitors.JEditVisitor; import org.gjt.sp.jedit.visitors.JEditVisitorAdapter; import org.gjt.sp.util.Log; import org.gjt.sp.util.StandardUtilities; //}}} /** * A <code>View</code> is jEdit's top-level frame window.<p> * * In a BeanShell script, you can obtain the current view instance from the * <code>view</code> variable.<p> * * The largest component it contains is an {@link EditPane} that in turn * contains a {@link org.gjt.sp.jedit.textarea.JEditTextArea} that displays a * {@link Buffer}. * A view can have more than one edit pane in a split window configuration. * A view also contains a menu bar, an optional toolbar and other window * decorations, as well as docked windows.<p> * * The <b>View</b> class performs two important operations * dealing with plugins: creating plugin menu items, and managing dockable * windows. * * <ul> * <li>When a view is being created, its initialization routine * iterates through the collection of loaded plugins and constructs the * <b>Plugins</b> menu using the properties as specified in the * {@link EditPlugin} class.</li> * <li>The view also creates and initializes a * {@link org.gjt.sp.jedit.gui.DockableWindowManager} * object. This object is * responsible for creating, closing and managing dockable windows.</li> * </ul> * * This class does not have a public constructor. * Views can be opened and closed using methods in the <code>jEdit</code> * class. * * @see org.gjt.sp.jedit.jEdit#newView(View) * @see org.gjt.sp.jedit.jEdit#newView(View,Buffer) * @see org.gjt.sp.jedit.jEdit#newView(View,Buffer,boolean) * @see org.gjt.sp.jedit.jEdit#closeView(View) * * @author Slava Pestov * @author John Gellene (API documentation) * @version $Id: View.java 13361 2008-08-18 04:36:58Z daleanson $ */ public class View extends JFrame implements EBComponent, InputHandlerProvider { //{{{ User interface //{{{ ToolBar-related constants public static final String VIEW_DOCKING_FRAMEWORK_PROPERTY = "view.docking.framework"; private static final String ORIGINAL_DOCKING_FRAMEWORK = "Original"; public static final String DOCKING_FRAMEWORK_PROVIDER_SERVICE = "org.gjt.sp.jedit.gui.DockingFrameworkProvider"; private static IDockingFrameworkProvider dockingFrameworkProvider = null; //{{{ Groups /** * The group of tool bars above the DockableWindowManager * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int TOP_GROUP = 0; /** * The group of tool bars below the DockableWindowManager * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int BOTTOM_GROUP = 1; public static final int DEFAULT_GROUP = TOP_GROUP; //}}} //{{{ Layers // Common layers /** * The highest possible layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int TOP_LAYER = Integer.MAX_VALUE; /** * The default layer for tool bars with no preference. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int DEFAULT_LAYER = 0; /** * The lowest possible layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int BOTTOM_LAYER = Integer.MIN_VALUE; // Layers for top group /** * Above system tool bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int ABOVE_SYSTEM_BAR_LAYER = 150; /** * System tool bar layer. * jEdit uses this for the main tool bar. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int SYSTEM_BAR_LAYER = 100; /** * Below system tool bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int BELOW_SYSTEM_BAR_LAYER = 75; /** * Search bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int SEARCH_BAR_LAYER = 75; /** * Below search bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.0pre7 */ public static final int BELOW_SEARCH_BAR_LAYER = 50; // Layers for bottom group /** * @deprecated Status bar no longer added as a tool bar. */ @Deprecated public static final int ABOVE_ACTION_BAR_LAYER = -50; /** * Action bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.2pre1 */ public static final int ACTION_BAR_LAYER = -75; /** * Status bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.2pre1 */ public static final int STATUS_BAR_LAYER = -100; /** * Status bar layer. * @see #addToolBar(int,int,java.awt.Component) * @since jEdit 4.2pre1 */ public static final int BELOW_STATUS_BAR_LAYER = -150; //}}} //}}} //{{{ getDockableWindowManager() method /** * Returns the dockable window manager associated with this view. * @since jEdit 2.6pre3 */ public DockableWindowManager getDockableWindowManager() { return dockableWindowManager; } //}}} static public String getDockingFrameworkName() { String framework = jEdit.getProperty( VIEW_DOCKING_FRAMEWORK_PROPERTY, ORIGINAL_DOCKING_FRAMEWORK); return framework; } static public IDockingFrameworkProvider getDockingFrameworkProvider() { if (dockingFrameworkProvider == null) { String framework = getDockingFrameworkName(); dockingFrameworkProvider = (IDockingFrameworkProvider) ServiceManager.getService( DOCKING_FRAMEWORK_PROVIDER_SERVICE, framework); } return dockingFrameworkProvider; } //{{{ getToolBar() method /** * Returns the view's tool bar. * @since jEdit 4.2pre1 */ public Container getToolBar() { return toolBar; } //}}} //{{{ addToolBar() method /** * Adds a tool bar to this view. * @param toolBar The tool bar */ public void addToolBar(Component toolBar) { addToolBar(DEFAULT_GROUP, DEFAULT_LAYER, toolBar); } //}}} //{{{ addToolBar() method /** * Adds a tool bar to this view. * @param group The tool bar group to add to * @param toolBar The tool bar * @see org.gjt.sp.jedit.gui.ToolBarManager * @since jEdit 4.0pre7 */ public void addToolBar(int group, Component toolBar) { addToolBar(group, DEFAULT_LAYER, toolBar); } //}}} //{{{ addToolBar() method /** * Adds a tool bar to this view. * @param group The tool bar group to add to * @param layer The layer of the group to add to * @param toolBar The tool bar * @see org.gjt.sp.jedit.gui.ToolBarManager * @since jEdit 4.0pre7 */ public void addToolBar(int group, int layer, Component toolBar) { toolBarManager.addToolBar(group, layer, toolBar); getRootPane().revalidate(); } //}}} //{{{ removeToolBar() method /** * Removes a tool bar from this view. * @param toolBar The tool bar */ public void removeToolBar(Component toolBar) { if (toolBarManager == null) return; if (toolBar == null) return; toolBarManager.removeToolBar(toolBar); getRootPane().revalidate(); } //}}} //{{{ showWaitCursor() method /** * Shows the wait cursor. This method and * {@link #hideWaitCursor()} are implemented using a reference * count of requests for wait cursors, so that nested calls work * correctly; however, you should be careful to use these methods in * tandem.<p> * * To ensure that {@link #hideWaitCursor()} is always called * after a {@link #showWaitCursor()}, use a * <code>try</code>/<code>finally</code> block, like this: * <pre>try *{ * view.showWaitCursor(); * // ... *} *finally *{ * view.hideWaitCursor(); *}</pre> */ public synchronized void showWaitCursor() { if(waitCount++ == 0) { Cursor cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR); setCursor(cursor); visit(new SetCursorVisitor(cursor)); } } //}}} //{{{ hideWaitCursor() method /** * Hides the wait cursor. */ public synchronized void hideWaitCursor() { if(waitCount > 0) waitCount--; if(waitCount == 0) { // still needed even though glass pane // has a wait cursor Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); setCursor(cursor); cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR); visit(new SetCursorVisitor(cursor)); } } //}}} //{{{ getSearchBar() method /** * Returns the search bar. * @since jEdit 2.4pre4 */ public final SearchBar getSearchBar() { return searchBar; } //}}} //{{{ getActionBar() method /** * Returns the action bar. * @since jEdit 4.2pre3 */ public final ActionBar getActionBar() { return actionBar; } //}}} //{{{ getStatus() method /** * Returns the status bar. The * {@link org.gjt.sp.jedit.gui.StatusBar#setMessage(String)} and * {@link org.gjt.sp.jedit.gui.StatusBar#setMessageAndClear(String)} methods can * be called on the return value of this method to display status * information to the user. * @since jEdit 3.2pre2 */ public StatusBar getStatus() { return status; } //}}} //{{{ quickIncrementalSearch() method /** * Quick search. * @since jEdit 4.0pre3 */ public void quickIncrementalSearch(boolean word) { if(searchBar == null) searchBar = new SearchBar(this,true); if(searchBar.getParent() == null) addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar); searchBar.setHyperSearch(false); JEditTextArea textArea = getTextArea(); if(word) { String text = textArea.getSelectedText(); if(text == null) { textArea.selectWord(); text = textArea.getSelectedText(); } else if(text.indexOf('\n') != -1) text = null; if(text != null && SearchAndReplace.getRegexp()) text = SearchAndReplace.escapeRegexp(text,false); searchBar.getField().setText(text); } searchBar.getField().requestFocus(); searchBar.getField().selectAll(); } //}}} //{{{ quickHyperSearch() method /** * Quick HyperSearch. * @since jEdit 4.0pre3 */ public void quickHyperSearch(boolean word) { JEditTextArea textArea = getTextArea(); if(word) { String text = textArea.getSelectedText(); if(text == null) { textArea.selectWord(); text = textArea.getSelectedText(); } if(text != null && text.indexOf('\n') == -1) { if(SearchAndReplace.getRegexp()) { text = SearchAndReplace.escapeRegexp( text,false); } HistoryModel.getModel("find").addItem(text); SearchAndReplace.setSearchString(text); SearchAndReplace.setSearchFileSet(new CurrentBufferSet()); SearchAndReplace.hyperSearch(this); return; } } if(searchBar == null) searchBar = new SearchBar(this,true); if(searchBar.getParent() == null) addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar); searchBar.setHyperSearch(true); searchBar.getField().setText(null); searchBar.getField().requestFocus(); searchBar.getField().selectAll(); } //}}} //{{{ actionBar() method /** * Shows the action bar if needed, and sends keyboard focus there. * @since jEdit 4.2pre1 */ public void actionBar() { if(actionBar == null) actionBar = new ActionBar(this,true); if(actionBar.getParent() == null) addToolBar(BOTTOM_GROUP,ACTION_BAR_LAYER,actionBar); actionBar.goToActionBar(); } //}}} //}}} //{{{ Input handling //{{{ getKeyEventInterceptor() method /** * Returns the listener that will handle all key events in this * view, if any. * @return the key event interceptor or null */ public KeyListener getKeyEventInterceptor() { return inputHandler.getKeyEventInterceptor(); } //}}} //{{{ setKeyEventInterceptor() method /** * Sets the listener that will handle all key events in this * view. For example, the complete word command uses this so * that all key events are passed to the word list popup while * it is visible. * @param listener The key event interceptor. */ public void setKeyEventInterceptor(KeyListener listener) { inputHandler.setKeyEventInterceptor(listener); } //}}} //{{{ getInputHandler() method /** * Returns the input handler. */ public InputHandler getInputHandler() { return inputHandler; } //}}} //{{{ setInputHandler() method /** * Sets the input handler. * @param inputHandler The new input handler */ public void setInputHandler(InputHandler inputHandler) { this.inputHandler = inputHandler; } //}}} //{{{ getMacroRecorder() method /** * Returns the macro recorder. */ public Macros.Recorder getMacroRecorder() { return recorder; } //}}} //{{{ setMacroRecorder() method /** * Sets the macro recorder. * @param recorder The macro recorder */ public void setMacroRecorder(Macros.Recorder recorder) { this.recorder = recorder; } //}}} //{{{ processKeyEvent() method /** * Forwards key events directly to the input handler. * This is slightly faster than using a KeyListener * because some Swing overhead is avoided. */ @Override public void processKeyEvent(KeyEvent evt) { inputHandler.processKeyEvent(evt,VIEW, false); if(!evt.isConsumed()) super.processKeyEvent(evt); } //}}} //{{{ processKeyEvent() method /** * Forwards key events directly to the input handler. * This is slightly faster than using a KeyListener * because some Swing overhead is avoided. */ public void processKeyEvent(KeyEvent evt, boolean calledFromTextArea) { processKeyEvent(evt,calledFromTextArea ? TEXT_AREA : VIEW); } //}}} //{{{ processKeyEvent() method public static final int VIEW = 0; public static final int TEXT_AREA = 1; public static final int ACTION_BAR = 2; /** * Forwards key events directly to the input handler. * This is slightly faster than using a KeyListener * because some Swing overhead is avoided. */ public void processKeyEvent(KeyEvent evt, int from) { processKeyEvent(evt,from,false); } /** * Forwards key events directly to the input handler. * This is slightly faster than using a KeyListener * because some Swing overhead is avoided. * @deprecated do not use, try {@link org.gjt.sp.jedit.gui.InputHandler#processKeyEvent(java.awt.event.KeyEvent, int, boolean)} */ @Deprecated public void processKeyEvent(KeyEvent evt, int from, boolean global) { inputHandler.processKeyEvent(evt, from, global); if(!evt.isConsumed()) super.processKeyEvent(evt); } //}}} //}}} //{{{ Buffers, edit panes, split panes //{{{ splitHorizontally() method /** * Splits the view horizontally. * @return the new editPane * @since jEdit 4.1pre2 */ public EditPane splitHorizontally() { return split(JSplitPane.VERTICAL_SPLIT); } //}}} //{{{ splitVertically() method /** * Splits the view vertically. * @return the new editPane * @since jEdit 4.1pre2 */ public EditPane splitVertically() { return split(JSplitPane.HORIZONTAL_SPLIT); } //}}} private Component mainContent = null; private void setMainContent(Component c) { if (mainContent != null) mainPanel.remove(mainContent); mainContent = c; mainPanel.add(mainContent, BorderLayout.CENTER); mainPanel.revalidate(); mainPanel.repaint(); } //{{{ split() method /** * Splits the view. * @param orientation the orientation {@link javax.swing.JSplitPane#HORIZONTAL_SPLIT} or * {@link javax.swing.JSplitPane#VERTICAL_SPLIT} * @return the new editPane * @since jEdit 4.1pre2 */ public EditPane split(int orientation) { PerspectiveManager.setPerspectiveDirty(true); editPane.saveCaretInfo(); EditPane oldEditPane = editPane; String action = jEdit.getProperty("editpane.bufferset.new"); BufferSetManager.NewBufferSetAction bufferSetAction = BufferSetManager.NewBufferSetAction.fromString(action); EditPane newEditPane; if (bufferSetAction == BufferSetManager.NewBufferSetAction.empty) newEditPane = createEditPane(null); else newEditPane = createEditPane(oldEditPane.getBuffer()); // setEditPane(newEditPane); newEditPane.loadCaretInfo(); JComponent oldParent = (JComponent)oldEditPane.getParent(); final JSplitPane newSplitPane = new JSplitPane(orientation, jEdit.getBooleanProperty("appearance.continuousLayout")); newSplitPane.setOneTouchExpandable(true); newSplitPane.setBorder(null); newSplitPane.setMinimumSize(new Dimension(0,0)); newSplitPane.setResizeWeight(0.5); int parentSize = orientation == JSplitPane.VERTICAL_SPLIT ? oldEditPane.getHeight() : oldEditPane.getWidth(); final int dividerPosition = (int)((parentSize - newSplitPane.getDividerSize()) * 0.5); newSplitPane.setDividerLocation(dividerPosition); if(oldParent instanceof JSplitPane) { JSplitPane oldSplitPane = (JSplitPane)oldParent; int dividerPos = oldSplitPane.getDividerLocation(); Component left = oldSplitPane.getLeftComponent(); if(left == oldEditPane) oldSplitPane.setLeftComponent(newSplitPane); else oldSplitPane.setRightComponent(newSplitPane); newSplitPane.setLeftComponent(oldEditPane); newSplitPane.setRightComponent(newEditPane); oldSplitPane.setDividerLocation(dividerPos); } else { splitPane = newSplitPane; newSplitPane.setLeftComponent(oldEditPane); newSplitPane.setRightComponent(newEditPane); setMainContent(newSplitPane); } SwingUtilities.invokeLater(new Runnable() { public void run() { newSplitPane.setDividerLocation(dividerPosition); } }); newEditPane.focusOnTextArea(); return newEditPane; } //}}} //{{{ unsplit() method /** * Unsplits the view. * @since jEdit 2.3pre2 */ public void unsplit() { if(splitPane != null) { lastSplitConfig = getSplitConfig(); PerspectiveManager.setPerspectiveDirty(true); EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { EditPane _editPane = editPanes[i]; if(editPane != _editPane) _editPane.close(); } setMainContent(editPane); splitPane = null; updateTitle(); editPane.focusOnTextArea(); } else getToolkit().beep(); } //}}} //{{{ unsplitCurrent() method /** * Removes the current split. * @since jEdit 2.3pre2 */ public void unsplitCurrent() { if(splitPane != null) { lastSplitConfig = getSplitConfig(); PerspectiveManager.setPerspectiveDirty(true); // find first split pane parenting current edit pane Component comp = editPane; while(!(comp instanceof JSplitPane) && comp != null) { comp = comp.getParent(); } // get rid of any edit pane that is a child // of the current edit pane's parent splitter EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { EditPane _editPane = editPanes[i]; if(GUIUtilities.isAncestorOf(comp,_editPane) && _editPane != editPane) _editPane.close(); } JComponent parent = comp == null ? null : (JComponent)comp.getParent(); if(parent instanceof JSplitPane) { JSplitPane parentSplit = (JSplitPane)parent; int pos = parentSplit.getDividerLocation(); if(parentSplit.getLeftComponent() == comp) parentSplit.setLeftComponent(editPane); else parentSplit.setRightComponent(editPane); parentSplit.setDividerLocation(pos); parent.revalidate(); } else { setMainContent(editPane); splitPane = null; } updateTitle(); editPane.focusOnTextArea(); } else getToolkit().beep(); } //}}} //{{{ resplit() method /** * Restore the split configuration as it was before unsplitting. * * @since jEdit 4.3pre1 */ public void resplit() { if(lastSplitConfig == null) getToolkit().beep(); else setSplitConfig(null,lastSplitConfig); } //}}} //{{{ getSplitConfig() method /** * Split configurations are recorded in a simple RPN "language". * @return The split configuration, describing where splitpanes * are, which buffers are open in each EditPane, etc. * */ public String getSplitConfig() { StringBuilder splitConfig = new StringBuilder(); if(splitPane != null) getSplitConfig(splitPane,splitConfig); else { appendToSplitConfig(splitConfig, editPane); } return splitConfig.toString(); } //}}} //{{{ setSplitConfig() method /** * sets the split configuration as per the splitConfig. * * @param buffer if null, checks all buffers to restore View's split config. * @param splitConfig the split config, as returned by getSplitConfig() */ public void setSplitConfig(Buffer buffer, String splitConfig) { try { Component comp = restoreSplitConfig(buffer,splitConfig); setMainContent(comp); } catch(IOException e) { // this should never throw an exception. throw new InternalError(); } } //}}} //{{{ nextTextArea() method /** * Moves keyboard focus to the next text area. * @since jEdit 2.7pre4 */ public void nextTextArea() { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { if(editPane == editPanes[i]) { if(i == editPanes.length - 1) editPanes[0].focusOnTextArea(); else editPanes[i+1].focusOnTextArea(); break; } } } //}}} //{{{ prevTextArea() method /** * Moves keyboard focus to the previous text area. * @since jEdit 2.7pre4 */ public void prevTextArea() { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { if(editPane == editPanes[i]) { if(i == 0) editPanes[editPanes.length - 1].focusOnTextArea(); else editPanes[i-1].focusOnTextArea(); break; } } } //}}} //{{{ getSplitPane() method /** * Returns the top-level split pane, if any. * @return the top JSplitPane if any. * @since jEdit 2.3pre2 */ public JSplitPane getSplitPane() { return splitPane; } //}}} //{{{ getBuffer() method /** * Returns the current edit pane's buffer. * @return the current edit pane's buffer, it can be null */ public Buffer getBuffer() { if(editPane == null) return null; else return editPane.getBuffer(); } //}}} //{{{ setBuffer() method /** * Sets the current edit pane's buffer. * @param buffer The buffer */ public void setBuffer(Buffer buffer) { setBuffer(buffer,false); } //}}} //{{{ setBuffer() method /** * Sets the current edit pane's buffer. * @param buffer The buffer * @param disableFileStatusCheck Disables file status checking * regardless of the state of the checkFileStatus property */ public void setBuffer(Buffer buffer, boolean disableFileStatusCheck) { setBuffer(buffer, disableFileStatusCheck, true); } //}}} //{{{ setBuffer() method /** * Sets the current edit pane's buffer. * @param buffer The buffer * @param disableFileStatusCheck Disables file status checking * regardless of the state of the checkFileStatus property * @param focus Whether the textarea should request focus * @since jEdit 4.3pre13 */ public void setBuffer(Buffer buffer, boolean disableFileStatusCheck, boolean focus) { editPane.setBuffer(buffer, focus); int check = jEdit.getIntegerProperty("checkFileStatus"); if(!disableFileStatusCheck && (check == GeneralOptionPane.checkFileStatus_all || check == GeneralOptionPane.checkFileStatus_operations || check == GeneralOptionPane.checkFileStatus_focusBuffer)) jEdit.checkBufferStatus(this, true); } //}}} //{{{ goToBuffer() method /** * If this buffer is open in one of the view's edit panes, sets focus * to that edit pane. Otherwise, opens the buffer in the currently * active edit pane. * @param buffer The buffer * @return the current edit pane * @since jEdit 4.2pre1 */ public EditPane goToBuffer(Buffer buffer) { return showBuffer(buffer, true); } //}}} //{{{ showBuffer() method /** * If this buffer is open in one of the view's edit panes, activates * that edit pane. Otherwise, opens the buffer in the currently * active edit pane. But the focus is not moved. * @param buffer The buffer to show * @return the current edit pane * @since jEdit 4.3pre13 */ public EditPane showBuffer(Buffer buffer) { return showBuffer(buffer, false); } //}}} //{{{ getTextArea() method /** * Returns the current edit pane's text area. * @return the current edit pane's text area, or <b>null</b> if there is no edit pane yet */ public JEditTextArea getTextArea() { if(editPane == null) return null; else return editPane.getTextArea(); } //}}} //{{{ getEditPane() method /** * Returns the current edit pane. * @return the current edit pane * @since jEdit 2.5pre2 */ public EditPane getEditPane() { return editPane; } //}}} //{{{ getEditPanes() method /** * Returns all edit panes. * @return an array of all edit panes in the view * @since jEdit 2.5pre2 */ public EditPane[] getEditPanes() { if(splitPane == null) { EditPane[] ep = { editPane }; return ep; } else { List<EditPane> vec = new ArrayList<EditPane>(); getEditPanes(vec,splitPane); EditPane[] ep = new EditPane[vec.size()]; vec.toArray(ep); return ep; } } //}}} //{{{ getViewConfig() method /** * @return a ViewConfig instance for the current view * @since jEdit 4.2pre1 */ public ViewConfig getViewConfig() { ViewConfig config = new ViewConfig(); config.plainView = isPlainView(); config.splitConfig = getSplitConfig(); config.extState = getExtendedState(); config.docking = dockableWindowManager.getDockingLayout(config); String prefix = config.plainView ? "plain-view" : "view"; switch (config.extState) { case Frame.MAXIMIZED_BOTH: case Frame.ICONIFIED: config.x = jEdit.getIntegerProperty(prefix + ".x",getX()); config.y = jEdit.getIntegerProperty(prefix + ".y",getY()); config.width = jEdit.getIntegerProperty(prefix + ".width",getWidth()); config.height = jEdit.getIntegerProperty(prefix + ".height",getHeight()); break; case Frame.MAXIMIZED_VERT: config.x = getX(); config.y = jEdit.getIntegerProperty(prefix + ".y",getY()); config.width = getWidth(); config.height = jEdit.getIntegerProperty(prefix + ".height",getHeight()); break; case Frame.MAXIMIZED_HORIZ: config.x = jEdit.getIntegerProperty(prefix + ".x",getX()); config.y = getY(); config.width = jEdit.getIntegerProperty(prefix + ".width",getWidth()); config.height = getHeight(); break; case Frame.NORMAL: default: config.x = getX(); config.y = getY(); config.width = getWidth(); config.height = getHeight(); break; } return config; } //}}} //}}} //{{{ isClosed() method /** * Returns true if this view has been closed with * {@link jEdit#closeView(View)}. * @return true if the view is closed */ public boolean isClosed() { return closed; } //}}} //{{{ isPlainView() method /** * Returns true if this is an auxilliary view with no dockable windows. * @return true if the view is plain * @since jEdit 4.1pre2 */ public boolean isPlainView() { return plainView; } //}}} //{{{ getNext() method /** * Returns the next view in the list. * @return the next view */ public View getNext() { return next; } //}}} //{{{ getPrev() method /** * Returns the previous view in the list. * @return the preview view */ public View getPrev() { return prev; } //}}} //{{{ handleMessage() method public void handleMessage(EBMessage msg) { if(msg instanceof PropertiesChanged) propertiesChanged(); else if(msg instanceof SearchSettingsChanged) { if(searchBar != null) searchBar.update(); } else if(msg instanceof BufferUpdate) handleBufferUpdate((BufferUpdate)msg); else if(msg instanceof EditPaneUpdate) handleEditPaneUpdate((EditPaneUpdate)msg); } //}}} //{{{ getMinimumSize() method @Override public Dimension getMinimumSize() { return new Dimension(0,0); } //}}} //{{{ setWaitSocket() method /** * This socket is closed when the buffer is closed. */ public void setWaitSocket(Socket waitSocket) { this.waitSocket = waitSocket; } //}}} //{{{ toString() method @Override public String toString() { return getClass().getName() + '[' + (jEdit.getActiveView() == this ? "active" : "inactive") + ']'; } //}}} //{{{ updateTitle() method /** * Updates the title bar. */ public void updateTitle() { List<Buffer> buffers = new ArrayList<Buffer>(); EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { Buffer buffer = editPanes[i].getBuffer(); if(!buffers.contains(buffer)) buffers.add(buffer); } StringBuilder title = new StringBuilder(); /* On Mac OS X, apps are not supposed to show their name in the title bar. */ if(!OperatingSystem.isMacOS()) title.append(jEdit.getProperty("view.title")); boolean unsavedChanges = false; for(int i = 0; i < buffers.size(); i++) { if(i != 0) title.append(", "); Buffer buffer = buffers.get(i); title.append((showFullPath && !buffer.isNewFile()) ? buffer.getPath() : buffer.getName()); if(buffer.isDirty()) { unsavedChanges = true; title.append(jEdit.getProperty("view.title.dirty")); } } setTitle(title.toString()); /* On MacOS X, the close box is shown in a different color if an app has unsaved changes. For details, see http://developer.apple.com/qa/qa2001/qa1146.html */ String WINDOW_MODIFIED = "windowModified"; getRootPane().putClientProperty(WINDOW_MODIFIED, unsavedChanges); } //}}} //{{{ getPrefixFocusOwner() method public Component getPrefixFocusOwner() { return prefixFocusOwner; } //}}} //{{{ setPrefixFocusOwner() method public void setPrefixFocusOwner(Component prefixFocusOwner) { this.prefixFocusOwner = prefixFocusOwner; } //}}} //{{{ visit() method /** * Visit the the editpanes and textareas of the view * @param visitor the visitor * @since jEdit 4.3pre13 */ public void visit(JEditVisitor visitor) { EditPane[] panes = getEditPanes(); for (int i = 0; i < panes.length; i++) { EditPane editPane = panes[i]; visitor.visit(editPane); visitor.visit(editPane.getTextArea()); } } //}}} //{{{ Package-private members View prev; View next; //{{{ View constructor View(Buffer buffer, ViewConfig config) { plainView = config.plainView; enableEvents(AWTEvent.KEY_EVENT_MASK); setIconImage(GUIUtilities.getEditorIcon()); mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); dockableWindowManager = getDockingFrameworkProvider().create(this, DockableWindowFactory.getInstance(), config); dockableWindowManager.setMainPanel(mainPanel); topToolBars = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS, 1)); bottomToolBars = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS, 1)); toolBarManager = new ToolBarManager(topToolBars, bottomToolBars); status = new StatusBar(this); inputHandler = new DefaultInputHandler(this,(DefaultInputHandler) jEdit.getInputHandler()); setSplitConfig(buffer,config.splitConfig); getContentPane().add(BorderLayout.CENTER,dockableWindowManager); dockableWindowManager.init(); // tool bar and status bar gets added in propertiesChanged() // depending in the 'tool bar alternate layout' setting. propertiesChanged(); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowHandler()); setFocusTraversalPolicy(new MyFocusTraversalPolicy()); EditBus.addToBus(this); GUIUtilities.addSizeSaver(this, null, plainView ? "plain-view" : "view"); } //}}} //{{{ close() method void close() { EditBus.send(new ViewUpdate(this,ViewUpdate.CLOSED)); closed = true; // save dockable window geometry, and close 'em dockableWindowManager.close(); EditBus.removeFromBus(this); dispose(); EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) editPanes[i].close(); // null some variables so that retaining references // to closed views won't hurt as much. toolBarManager = null; toolBar = null; searchBar = null; splitPane = null; inputHandler = null; recorder = null; getContentPane().removeAll(); // notify clients with -wait if(waitSocket != null) { try { waitSocket.getOutputStream().write('\0'); waitSocket.getOutputStream().flush(); waitSocket.getInputStream().close(); waitSocket.getOutputStream().close(); waitSocket.close(); } catch(IOException io) { //Log.log(Log.ERROR,this,io); } } } //}}} //}}} //{{{ Private members //{{{ Instance variables private boolean closed; private DockableWindowManager dockableWindowManager; private JPanel mainPanel; private JPanel topToolBars; private JPanel bottomToolBars; private ToolBarManager toolBarManager; private Container toolBar; private SearchBar searchBar; private ActionBar actionBar; private EditPane editPane; private JSplitPane splitPane; private String lastSplitConfig; private StatusBar status; private InputHandler inputHandler; private Macros.Recorder recorder; private Component prefixFocusOwner; private int waitCount; private boolean showFullPath; private boolean plainView; private Socket waitSocket; //}}} //{{{ getEditPanes() method private static void getEditPanes(List<EditPane> vec, Component comp) { if(comp instanceof EditPane) vec.add((EditPane) comp); else if(comp instanceof JSplitPane) { JSplitPane split = (JSplitPane)comp; getEditPanes(vec,split.getLeftComponent()); getEditPanes(vec,split.getRightComponent()); } } //}}} //{{{ showBuffer() method private EditPane showBuffer(Buffer buffer, boolean focus) { if(editPane.getBuffer() == buffer && editPane.getTextArea().getVisibleLines() > 1) { if (focus) editPane.focusOnTextArea(); return editPane; } EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { EditPane ep = editPanes[i]; if(ep.getBuffer() == buffer /* ignore zero-height splits, etc */ && ep.getTextArea().getVisibleLines() > 1) { setEditPane(ep); if (focus) ep.focusOnTextArea(); return ep; } } setBuffer(buffer,false, focus); return editPane; } //}}} //{{{ getSplitConfig() method /* * The split config is recorded in a simple RPN "language". */ private static void getSplitConfig(JSplitPane splitPane, StringBuilder splitConfig) { Component right = splitPane.getRightComponent(); appendToSplitConfig(splitConfig, right); splitConfig.append(' '); Component left = splitPane.getLeftComponent(); appendToSplitConfig(splitConfig, left); splitConfig.append(' '); splitConfig.append(splitPane.getDividerLocation()); splitConfig.append(' '); splitConfig.append(splitPane.getOrientation() == JSplitPane.VERTICAL_SPLIT ? "vertical" : "horizontal"); } //}}} //{{{ appendToSplitConfig() method /** * Append the Component to the split config. * The component must be a JSplitPane or an EditPane * * @param splitConfig the split config * @param component the component */ private static void appendToSplitConfig(StringBuilder splitConfig, Component component) { if(component instanceof JSplitPane) { // the component is a JSplitPane getSplitConfig((JSplitPane)component,splitConfig); } else { // the component is an editPane EditPane editPane = (EditPane) component; splitConfig.append('"'); splitConfig.append(StandardUtilities.charsToEscapes( editPane.getBuffer().getPath())); splitConfig.append("\" buffer"); BufferSet bufferSet = editPane.getBufferSet(); Buffer[] buffers = bufferSet.getAllBuffers(); BufferSetManager bufferSetManager = jEdit.getBufferSetManager(); for (Buffer buffer : buffers) { if (!buffer.isNewFile() && bufferSetManager.hasListeners(buffer)) { splitConfig.append(" \""); splitConfig.append(StandardUtilities.charsToEscapes( buffer.getPath())); splitConfig.append("\" buff"); } } splitConfig.append(" \""); splitConfig.append(bufferSet.getScope()); splitConfig.append("\" bufferset"); } } //}}} //{{{ restoreSplitConfig() method private Component restoreSplitConfig(Buffer buffer, String splitConfig) throws IOException // this is where checked exceptions piss me off. this method only uses // a StringReader which can never throw an exception... { if(buffer != null) { return editPane = createEditPane(buffer); } else if(splitConfig == null) { return editPane = createEditPane(jEdit.getFirstBuffer()); } Buffer[] buffers = jEdit.getBuffers(); Stack stack = new Stack(); // we create a stream tokenizer for parsing a simple // stack-based language StreamTokenizer st = new StreamTokenizer(new StringReader( splitConfig)); st.whitespaceChars(0,' '); /* all printable ASCII characters */ st.wordChars('#','~'); st.commentChar('!'); st.quoteChar('"'); st.eolIsSignificant(false); boolean continuousLayout = jEdit.getBooleanProperty("appearance.continuousLayout"); List<Buffer> editPaneBuffers = new ArrayList<Buffer>(); loop: while (true) { switch(st.nextToken()) { case StreamTokenizer.TT_EOF: break loop; case StreamTokenizer.TT_WORD: if(st.sval.equals("vertical") || st.sval.equals("horizontal")) { int orientation = st.sval.equals("vertical") ? JSplitPane.VERTICAL_SPLIT : JSplitPane.HORIZONTAL_SPLIT; int divider = ((Integer)stack.pop()) .intValue(); stack.push(splitPane = new JSplitPane( orientation, continuousLayout, (Component)stack.pop(), (Component)stack.pop())); splitPane.setOneTouchExpandable(true); splitPane.setBorder(null); splitPane.setMinimumSize( new Dimension(0,0)); splitPane.setDividerLocation(divider); } else if(st.sval.equals("buffer")) { Object obj = stack.pop(); if(obj instanceof Integer) { int index = ((Integer)obj).intValue(); if(index >= 0 && index < buffers.length) buffer = buffers[index]; } else if(obj instanceof String) { String path = (String)obj; buffer = jEdit.getBuffer(path); } if(buffer == null) buffer = jEdit.getFirstBuffer(); stack.push(editPane = createEditPane( buffer)); } else if (st.sval.equals("buff")) { String path = (String)stack.pop(); buffer = jEdit.getBuffer(path); if (buffer == null) { Log.log(Log.WARNING, this, "Error buffer " + path + " doesn't exists"); } else { editPaneBuffers.add(buffer); } } else if (st.sval.equals("bufferset")) { BufferSet.Scope scope = BufferSet.Scope.fromString((String) stack.pop()); BufferSetManager bufferSetManager = jEdit.getBufferSetManager(); switch (scope) { case view: editPane.setBufferSet(bufferSetManager.getViewBufferSet(this)); break; case editpane: editPane.setBufferSet(bufferSetManager.getEditPaneBufferSet(editPane)); break; case global: editPane.setBufferSet(bufferSetManager.getGlobalBufferSet()); break; } BufferSet bufferSet = editPane.getBufferSet(); for (Buffer buff : editPaneBuffers) { bufferSetManager.addBuffer(bufferSet, buff); } editPaneBuffers.clear(); } break; case StreamTokenizer.TT_NUMBER: stack.push((int)st.nval); break; case '"': stack.push(st.sval); break; } } updateGutterBorders(); return (Component)stack.peek(); } //}}} //{{{ propertiesChanged() method /** * Reloads various settings from the properties. */ private void propertiesChanged() { setJMenuBar(GUIUtilities.loadMenuBar("view.mbar")); loadToolBars(); showFullPath = jEdit.getBooleanProperty("view.showFullPath"); updateTitle(); status.propertiesChanged(); removeToolBar(status); getContentPane().remove(status); boolean showStatus = plainView ? jEdit.getBooleanProperty("view.status.plainview.visible") : jEdit.getBooleanProperty("view.status.visible"); if (jEdit.getBooleanProperty("view.toolbar.alternateLayout")) { getContentPane().add(BorderLayout.NORTH,topToolBars); getContentPane().add(BorderLayout.SOUTH,bottomToolBars); if (showStatus) addToolBar(BOTTOM_GROUP,STATUS_BAR_LAYER,status); } else { mainPanel.add(topToolBars, BorderLayout.NORTH); mainPanel.add(bottomToolBars, BorderLayout.SOUTH); if (showStatus) getContentPane().add(BorderLayout.SOUTH,status); } getRootPane().revalidate(); if (splitPane != null) GUIUtilities.initContinuousLayout(splitPane); //SwingUtilities.updateComponentTreeUI(getRootPane()); } //}}} //{{{ loadToolBars() method private void loadToolBars() { if(jEdit.getBooleanProperty("view.showToolbar") && !plainView) { if(toolBar != null) toolBarManager.removeToolBar(toolBar); toolBar = GUIUtilities.loadToolBar("view.toolbar"); addToolBar(TOP_GROUP, SYSTEM_BAR_LAYER, toolBar); } else if(toolBar != null) { removeToolBar(toolBar); toolBar = null; } if(searchBar != null) { searchBar.propertiesChanged(); removeToolBar(searchBar); } if(jEdit.getBooleanProperty("view.showSearchbar") && !plainView) { if(searchBar == null) searchBar = new SearchBar(this,false); addToolBar(TOP_GROUP,SEARCH_BAR_LAYER,searchBar); } } //}}} //{{{ createEditPane() method private EditPane createEditPane(Buffer buffer) { EditPane editPane = new EditPane(this,buffer); JEditTextArea textArea = editPane.getTextArea(); textArea.addFocusListener(new FocusHandler()); textArea.addCaretListener(new CaretHandler()); textArea.addScrollListener(new ScrollHandler()); EditBus.send(new EditPaneUpdate(editPane,EditPaneUpdate.CREATED)); return editPane; } //}}} //{{{ setEditPane() method private void setEditPane(EditPane editPane) { this.editPane = editPane; status.updateCaretStatus(); status.updateBufferStatus(); status.updateMiscStatus(); // repaint the gutter so that the border color // reflects the focus state updateGutterBorders(); EditBus.send(new ViewUpdate(this,ViewUpdate.EDIT_PANE_CHANGED)); } //}}} //{{{ handleBufferUpdate() method private void handleBufferUpdate(BufferUpdate msg) { Buffer buffer = msg.getBuffer(); if(msg.getWhat() == BufferUpdate.DIRTY_CHANGED || msg.getWhat() == BufferUpdate.LOADED) { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) { if(editPanes[i].getBuffer() == buffer) { updateTitle(); break; } } } } //}}} //{{{ handleEditPaneUpdate() method private void handleEditPaneUpdate(EditPaneUpdate msg) { EditPane editPane = msg.getEditPane(); if(editPane.getView() == this && msg.getWhat() == EditPaneUpdate.BUFFER_CHANGED && editPane.getBuffer().isLoaded()) { status.updateCaretStatus(); status.updateBufferStatus(); status.updateMiscStatus(); } } //}}} //{{{ updateGutterBorders() method /** * Updates the borders of all gutters in this view to reflect the * currently focused text area. * @since jEdit 2.6final */ private void updateGutterBorders() { EditPane[] editPanes = getEditPanes(); for(int i = 0; i < editPanes.length; i++) editPanes[i].getTextArea().getGutter().updateBorder(); } //}}} //}}} //{{{ Inner classes //{{{ CaretHandler class private class CaretHandler implements CaretListener { public void caretUpdate(CaretEvent evt) { if(evt.getSource() == getTextArea()) status.updateCaretStatus(); } } //}}} //{{{ FocusHandler class private class FocusHandler extends FocusAdapter { @Override public void focusGained(FocusEvent evt) { // walk up hierarchy, looking for an EditPane Component comp = (Component)evt.getSource(); while(!(comp instanceof EditPane)) { if(comp == null) return; comp = comp.getParent(); } if(comp != editPane) setEditPane((EditPane)comp); else updateGutterBorders(); } } //}}} //{{{ ScrollHandler class private class ScrollHandler implements ScrollListener { public void scrolledVertically(TextArea textArea) { if(getTextArea() == textArea) status.updateCaretStatus(); } public void scrolledHorizontally(TextArea textArea) {} } //}}} //{{{ WindowHandler class private class WindowHandler extends WindowAdapter { @Override public void windowActivated(WindowEvent evt) { boolean editPaneChanged = jEdit.getActiveViewInternal() != View.this; jEdit.setActiveView(View.this); // People have reported hangs with JDK 1.4; might be // caused by modal dialogs being displayed from // windowActivated() SwingUtilities.invokeLater(new Runnable() { public void run() { int check = jEdit.getIntegerProperty("checkFileStatus"); if(check == GeneralOptionPane.checkFileStatus_focus || check == GeneralOptionPane.checkFileStatus_all) jEdit.checkBufferStatus(View.this,false); else if(check == GeneralOptionPane.checkFileStatus_focusBuffer) jEdit.checkBufferStatus(View.this,true); } }); if (editPaneChanged) { EditBus.send(new ViewUpdate(View.this,ViewUpdate .ACTIVATED)); } } @Override public void windowClosing(WindowEvent evt) { jEdit.closeView(View.this); } } //}}} //{{{ ViewConfig class public static class ViewConfig { public int x, y, width, height, extState; public boolean plainView; public String splitConfig; public DockingLayout docking; public ViewConfig() { } public ViewConfig(boolean plainView) { this.plainView = plainView; String prefix = plainView ? "plain-view" : "view"; x = jEdit.getIntegerProperty(prefix + ".x",0); y = jEdit.getIntegerProperty(prefix + ".y",0); width = jEdit.getIntegerProperty(prefix + ".width",0); height = jEdit.getIntegerProperty(prefix + ".height",0); extState = jEdit.getIntegerProperty(prefix + ".extendedState",JFrame.NORMAL); } public ViewConfig(boolean plainView, String splitConfig, int x, int y, int width, int height, int extState) { this.plainView = plainView; this.splitConfig = splitConfig; this.x = x; this.y = y; this.width = width; this.height = height; this.extState = extState; } } //}}} public void adjust(View parent, ViewConfig config) { if(config.width != 0 && config.height != 0) { Rectangle desired = new Rectangle( config.x, config.y, config.width, config.height); if(OperatingSystem.isX11() && Debug.GEOMETRY_WORKAROUND) { new GUIUtilities.UnixWorkaround(this,"view",desired,config.extState); } else { setBounds(desired); setExtendedState(config.extState); } } else setLocationRelativeTo(parent); } //{{{ MyFocusTraversalPolicy class private static class MyFocusTraversalPolicy extends LayoutFocusTraversalPolicy { @Override public Component getDefaultComponent(Container focusCycleRoot) { return GUIUtilities.getView(focusCycleRoot).getTextArea(); } } //}}} //{{{ SetCursorVisitor class private static class SetCursorVisitor extends JEditVisitorAdapter { private final Cursor cursor; SetCursorVisitor(Cursor cursor) { this.cursor = cursor; } @Override public void visit(EditPane editPane) { editPane.setCursor(cursor); } }//}}} //}}} }

The table below shows all metrics for View.java.

MetricValueDescription
BLOCKS159.00Number of blocks
BLOCK_COMMENT31.00Number of block comment lines
COMMENTS554.00Comment lines
COMMENT_DENSITY 0.59Comment density
COMPARISONS117.00Number of comparison operators
CYCLOMATIC243.00Cyclomatic complexity
DECL_COMMENTS175.00Comments in declarations
DOC_COMMENT394.00Number of javadoc comment lines
ELOC940.00Effective lines of code
EXEC_COMMENTS21.00Comments in executable code
EXITS211.00Procedure exits
FUNCTIONS89.00Number of function declarations
HALSTEAD_DIFFICULTY100.34Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY173.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 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 8.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 2.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003461.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 1.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 2.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 4.00JAVA0075 Method parameter hides field
JAVA0076 1.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 0.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
JAVA010810.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 7.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 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA011614.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 8.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
JAVA0128 0.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 1.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 2.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01453330.00JAVA0145 Tab character used in source file
JAVA0150 1.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 0.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 2.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 3.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 2.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 0.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 5.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 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 8.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
LINES1987.00Number of lines in the source file
LINE_COMMENT129.00Number of line comments
LOC1197.00Lines of code
LOGICAL_LINES577.00Number of statements
LOOPS14.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS2381.00Number of operands
OPERATORS4474.00Number of operators
PARAMS71.00Number of formal parameter declarations
PROGRAM_LENGTH6855.00Halstead program length
PROGRAM_VOCAB759.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS102.00Number of return points from functions
SIZE50426.00Size of the file in bytes
UNIQUE_OPERANDS700.00Number of unique operands
UNIQUE_OPERATORS59.00Number of unique operators
WHITESPACE236.00Number of whitespace lines