bufferstats
Class BufferStatsPlugin

java.lang.Object
  extended by org.gjt.sp.jedit.EditPlugin
      extended by org.gjt.sp.jedit.EBPlugin
          extended by bufferstats.BufferStatsPlugin
All Implemented Interfaces:
org.gjt.sp.jedit.EBComponent

public class BufferStatsPlugin
extends org.gjt.sp.jedit.EBPlugin

The BufferStatsPlugin uses the EditBus to track Buffers as they are opened/loaded, saved, and activated. Buffers begin to be tracked as soon as the plugin is loaded.

Normally, the intention would be for the plugin to be activated at startup. If plugin loading is deferred, you can use the monitorOpenBuffers() to track currently open buffers.

To get usage statistics for a Buffer, several calls are available. Assume you have initialized a variable called plugin for the BufferStatsPlugin instance, and a variable called buffer for the buffer you want information on.

The plugin can also return sorted arrays of open buffers, based on usage.

The plugin is currently shipped with several macros useful for closing unused buffers based on certain rules. See the plugin HTML documentation for details.

Note that "activation" for a Buffer may not be as expected, as some Buffer-management plugins cause Buffers to briefly activate when one switches between them. That is, if using keyboard shortcuts to page through open Buffers, a Buffer will briefly become active even if it is not the one you settle on. BufferStatsPlugin will report the activation count, and time, based on the EditBus messages related to Buffer changing. Because of this, depending on what question you are asking, you may want to use the total time a Buffer was active, rather than the count of times it was active.

Version:
0.1
Author:
Patrick Wright

Nested Class Summary
 
Nested classes/interfaces inherited from class org.gjt.sp.jedit.EditPlugin
org.gjt.sp.jedit.EditPlugin.Broken, org.gjt.sp.jedit.EditPlugin.Deferred, org.gjt.sp.jedit.EditPlugin.JAR
 
Field Summary
static java.lang.String MENU
          Standard EditPlugin field, plugin menu option prefix
static java.lang.String NAME
          Standard EditPlugin field, plugin name
static java.lang.String OPTION_PREFIX
          Standard EditPlugin field, plugin options prefix
static java.lang.String PROPERTY_PREFIX
          Standard EditPlugin field, plugin property option prefix
 
Constructor Summary
BufferStatsPlugin()
          Constructor for the BufferStatsPlugin object
 
Method Summary
 long activatedTime(org.gjt.sp.jedit.Buffer buffer)
          Returns the time, in milliseconds, that the Buffer has been the user's active Buffer, since it was opened.
 int countActivated(org.gjt.sp.jedit.Buffer buffer)
          Returns the number of times the Buffer instance has been made the active Buffer.
 void handleMessage(org.gjt.sp.jedit.EBMessage message)
          Implementation of EBComponent.handleMessage()--in this case, to listen to messages relating to Buffer opening, closing, etc.
 org.gjt.sp.jedit.Buffer[] listBuffersByActivationFrequency()
          Returns an array of open Buffers sorted by the number of times they have been made active since opened, from most to least active.
 org.gjt.sp.jedit.Buffer[] listBuffersByActivationOrder()
          Returns an array of open Buffers sorted by the timestamp of their last activation, from most to least active.
 org.gjt.sp.jedit.Buffer[] listBuffersByActivationQuantity()
          Returns an array of open Buffers sorted by the amount of time they have been the active buffer, from most to least active.
 long longestActivatedTime()
          Returns the time in milliseconds the most-active Buffer has been activate.
 void monitorOpenBuffers()
          Loads list of open Buffers in JEdit and starts to track their usage.
 int mostActivatedCount()
          Returns the number of times the most-often activated Buffer has been activated
 void start()
          Standard EBPlugin start() method.
 void stop()
          Standard EBPlugin stop() method.
 long whenLastActivated(org.gjt.sp.jedit.Buffer buffer)
          Returns the long timestamp (see System.currentTimeMillis) since the Buffer was last made the active Buffer (active EditPane) in JEdit.
 long whenLoaded(org.gjt.sp.jedit.Buffer buffer)
          Returns the long timestamp (see System.currentTimeMillis) since the Buffer was loaded/opened.
 
Methods inherited from class org.gjt.sp.jedit.EditPlugin
createBrowserMenuItems, createMenuItems, createMenuItems, createOptionPanes, getClassName, getJAR, getPluginJAR
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME

public static final java.lang.String NAME
Standard EditPlugin field, plugin name

See Also:
Constant Field Values

MENU

public static final java.lang.String MENU
Standard EditPlugin field, plugin menu option prefix

See Also:
Constant Field Values

PROPERTY_PREFIX

public static final java.lang.String PROPERTY_PREFIX
Standard EditPlugin field, plugin property option prefix

See Also:
Constant Field Values

OPTION_PREFIX

public static final java.lang.String OPTION_PREFIX
Standard EditPlugin field, plugin options prefix

See Also:
Constant Field Values
Constructor Detail

BufferStatsPlugin

public BufferStatsPlugin()
Constructor for the BufferStatsPlugin object

Method Detail

start

public void start()
Standard EBPlugin start() method.

Overrides:
start in class org.gjt.sp.jedit.EditPlugin

stop

public void stop()
Standard EBPlugin stop() method.

Overrides:
stop in class org.gjt.sp.jedit.EditPlugin

monitorOpenBuffers

public void monitorOpenBuffers()
Loads list of open Buffers in JEdit and starts to track their usage. Call this to get the Plugin started if plugin activation is deferred.


listBuffersByActivationFrequency

public org.gjt.sp.jedit.Buffer[] listBuffersByActivationFrequency()
Returns an array of open Buffers sorted by the number of times they have been made active since opened, from most to least active.

Returns:
See desc.

listBuffersByActivationOrder

public org.gjt.sp.jedit.Buffer[] listBuffersByActivationOrder()
Returns an array of open Buffers sorted by the timestamp of their last activation, from most to least active.

Returns:
See desc.

listBuffersByActivationQuantity

public org.gjt.sp.jedit.Buffer[] listBuffersByActivationQuantity()
Returns an array of open Buffers sorted by the amount of time they have been the active buffer, from most to least active.

Returns:
See desc.

whenLoaded

public long whenLoaded(org.gjt.sp.jedit.Buffer buffer)
Returns the long timestamp (see System.currentTimeMillis) since the Buffer was loaded/opened.

Parameters:
buffer - A Buffer instance you want to check.
Returns:
long representing when, in milliseconds, the buffer was loaded. Returns 0 if the Buffer is not being tracked.

whenLastActivated

public long whenLastActivated(org.gjt.sp.jedit.Buffer buffer)
Returns the long timestamp (see System.currentTimeMillis) since the Buffer was last made the active Buffer (active EditPane) in JEdit.

Parameters:
buffer - A Buffer instance you want to check.
Returns:
long representing the last date/time, in milliseconds, the buffer was activated. Returns 0 if the Buffer is not being tracked.

countActivated

public int countActivated(org.gjt.sp.jedit.Buffer buffer)
Returns the number of times the Buffer instance has been made the active Buffer. Buffers are always considered "active" on load, so this will be at least 1 unless the Buffer is not known.

Parameters:
buffer - A Buffer instance you want to check.
Returns:
See desc; returns 0 if the Buffer is not known.

mostActivatedCount

public int mostActivatedCount()
Returns the number of times the most-often activated Buffer has been activated

Returns:
See desc; returns 0 if the Buffer is not known.

activatedTime

public long activatedTime(org.gjt.sp.jedit.Buffer buffer)
Returns the time, in milliseconds, that the Buffer has been the user's active Buffer, since it was opened. This grows culmulatively as the user switches between buffers.

Parameters:
buffer - The Buffer instance to check.
Returns:
See desc, return 0 if buffer is not known.

longestActivatedTime

public long longestActivatedTime()
Returns the time in milliseconds the most-active Buffer has been activate. This is the Buffer the user had active for the longest time regardless of how often they switched between buffers.

Returns:
See desc.

handleMessage

public void handleMessage(org.gjt.sp.jedit.EBMessage message)
Implementation of EBComponent.handleMessage()--in this case, to listen to messages relating to Buffer opening, closing, etc.

Specified by:
handleMessage in interface org.gjt.sp.jedit.EBComponent
Overrides:
handleMessage in class org.gjt.sp.jedit.EBPlugin
Parameters:
message - The EBMessage sent on the EditBus.