From: <dal...@us...> - 2013-08-13 23:44:35
|
Revision: 23119 http://jedit.svn.sourceforge.net/jedit/?rev=23119&view=rev Author: daleanson Date: 2013-08-13 23:44:26 +0000 (Tue, 13 Aug 2013) Log Message: ----------- moved blame component from svn plugin to common controls Modified Paths: -------------- plugins/CommonControls/trunk/build.xml plugins/CommonControls/trunk/docs/blame.html plugins/CommonControls/trunk/docs/users-guide.xml Added Paths: ----------- plugins/CommonControls/trunk/common/gui/blame/ plugins/CommonControls/trunk/common/gui/blame/BasicBlamePaneUI.java plugins/CommonControls/trunk/common/gui/blame/BlameModel.java plugins/CommonControls/trunk/common/gui/blame/BlamePane.java plugins/CommonControls/trunk/common/gui/blame/BlamePaneUI.java Modified: plugins/CommonControls/trunk/build.xml =================================================================== --- plugins/CommonControls/trunk/build.xml 2013-08-13 23:04:36 UTC (rev 23118) +++ plugins/CommonControls/trunk/build.xml 2013-08-13 23:44:26 UTC (rev 23119) @@ -45,7 +45,7 @@ <selector id="packageFiles"> <or> <filename name="**/*.props"/> - <filename name="*.html"/> + <filename name="**/*.html"/> <filename name="**/*.gif"/> <filename name="**/*.png"/> </or> Added: plugins/CommonControls/trunk/common/gui/blame/BasicBlamePaneUI.java =================================================================== --- plugins/CommonControls/trunk/common/gui/blame/BasicBlamePaneUI.java (rev 0) +++ plugins/CommonControls/trunk/common/gui/blame/BasicBlamePaneUI.java 2013-08-13 23:44:26 UTC (rev 23119) @@ -0,0 +1,163 @@ +/* +* Copyright (c) 2008, Dale Anson +* +* 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 common.gui.blame; + +import java.awt.*; +import java.awt.event.*; + +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.plaf.ComponentUI; + +import org.gjt.sp.jedit.jEdit; + +/** + * UI for the BlamePane to be displayed left of the right scroll bar of the + * main text area. + */ +public class BasicBlamePaneUI extends BlamePaneUI implements ChangeListener, MouseListener { + + private BlamePane blamePane; + private BlameRendererPane blameRendererPane; + private int pixelsPerLine = 12; // default, this will be calculated later + + public static ComponentUI createUI( JComponent c ) { + return new BasicBlamePaneUI(); + } + + public void installUI( JComponent c ) { + blamePane = ( BlamePane ) c; + blamePane.setLayout( createLayoutManager() ); + installDefaults(); + installComponents(); + installListeners(); + + } + + public void uninstallUI( JComponent c ) { + c.setLayout( null ); + uninstallListeners(); + uninstallComponents(); + uninstallDefaults(); + } + + public void installDefaults() {} + + public void installComponents() { + blameRendererPane = new BlameRendererPane(); + blamePane.add( blameRendererPane, BorderLayout.CENTER ); + } + + public void installListeners() { + blamePane.addChangeListener( this ); + blamePane.addMouseListener( this ); + } + + public void uninstallDefaults() {} + + public void uninstallComponents() { + blamePane.remove( blameRendererPane ); + } + + public void uninstallListeners() { + blamePane.removeChangeListener( this ); + } + + protected LayoutManager createLayoutManager() { + return new BorderLayout(); + } + + public void stateChanged( ChangeEvent event ) { + blameRendererPane.repaint(); + } + + /** + * On mouse click on the BlamePane, move the cursor in the text area to the + * corresponding line. This makes line highlight (if turned on) line up + * nicely with the appropriate line in the BlamePane. + */ + public void mouseClicked( MouseEvent e ) { + BlameModel model = blamePane.getModel(); + if ( model == null ) { + return ; + } + int line_number = ( e.getY() / pixelsPerLine ) + model.getTextArea().getFirstPhysicalLine(); + model.getTextArea().setCaretPosition( model.getTextArea().getLineStartOffset( line_number ), false ); + } + + public void mouseEntered( MouseEvent e ) {} + public void mouseExited( MouseEvent e ) {} + public void mousePressed( MouseEvent e ) {} + public void mouseReleased( MouseEvent e ) {} + + public class BlameRendererPane extends JPanel { + public BlameRendererPane( ) { + // need a model and some blame + BlameModel model = blamePane.getModel(); + if ( model == null ) { + throw new IllegalArgumentException( "blame model is null" ); + } + if ( model.getBlame() == null ) { + throw new IllegalArgumentException( "no blame found in model" ); + } + + // calculate the proper width by finding the widest line of the blame + int max_width = 0; + FontMetrics fm = model.getTextArea().getPainter().getFontMetrics(); + for ( String line : model.getBlame() ) { + int width = fm.stringWidth( line ); + max_width = width > max_width ? width : max_width; + } + Dimension dim = getPreferredSize(); + dim.width = max_width + 3; // 3 extra pixels just to give some separation from the text area + setPreferredSize( dim ); + } + + public void paintComponent( Graphics gfx ) { + super.paintComponent( gfx ); + + // paint the background + Rectangle size = getBounds(); + gfx.setColor( getBackground() ); + gfx.fillRect( 0, 0, size.width, size.height ); + + // get the visible lines, draw the corresponding blame lines + BlameModel model = blamePane.getModel(); + pixelsPerLine = model.getTextArea().getPainter().getFontMetrics().getHeight(); + int firstLine = model.getTextArea().getFirstPhysicalLine(); + int lastLine = model.getTextArea().getLastPhysicalLine(); + int caretLine = model.getTextArea().getCaretLine(); + Color foreground = jEdit.getColorProperty( "view.fgColor", Color.BLACK ); + Color highlight = jEdit.getColorProperty( "view.lineHighlightColor", Color.WHITE ); + gfx.setColor( foreground ); + java.util.List<String> blame = model.getBlame(); + int descent = gfx.getFontMetrics().getDescent(); + for ( int i = firstLine; i <= lastLine; i++ ) { + if ( i == caretLine ) { + gfx.setColor( highlight ); + gfx.fillRect( 0, ( i - firstLine ) * pixelsPerLine, size.width, pixelsPerLine ); + gfx.setColor( foreground ); + } + if ( i >= 0 && i < blame.size() ) { + gfx.drawString( blame.get( i ), 3, ( ( i - firstLine + 1 ) * pixelsPerLine ) - descent ); + } + } + } + } +} \ No newline at end of file Added: plugins/CommonControls/trunk/common/gui/blame/BlameModel.java =================================================================== --- plugins/CommonControls/trunk/common/gui/blame/BlameModel.java (rev 0) +++ plugins/CommonControls/trunk/common/gui/blame/BlameModel.java 2013-08-13 23:44:26 UTC (rev 23119) @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2008, Dale Anson +* +* 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 common.gui.blame; + +import java.util.List; +import org.gjt.sp.jedit.textarea.JEditTextArea; + +/** + * Simple data model to transport necessary data for the SVN "blame" command. + */ +public class BlameModel { + + /** + * Blame is actually attached to a Buffer, but is displayed in a JEditTextArea, + * so need a reference to the text area. + */ + private JEditTextArea textArea = null; + + /** + * The lines of blame returned from the SVN "blame" command. There is one + * entry in the list per line in the file. + */ + private List<String> blame = null; + + /** + * My "blame" command will check if the local working file has been modified, + * if it has, this field will be set to true; + */ + private boolean outOfDate = false; + + public BlameModel() { + + } + + public BlameModel(JEditTextArea textarea, List<String> blame) { + this.textArea = textarea; + this.blame = blame; + } + + public void setTextArea(JEditTextArea textarea) { + textArea = textarea; + } + + public JEditTextArea getTextArea() { + return textArea; + } + + public void setBlame(List<String> blame) { + this.blame = blame; + } + + public List<String> getBlame() { + return blame; + } + + public void setOutOfDate(boolean b) { + outOfDate = b; + } + + public boolean outOfDate() { + return outOfDate; + } +} \ No newline at end of file Added: plugins/CommonControls/trunk/common/gui/blame/BlamePane.java =================================================================== --- plugins/CommonControls/trunk/common/gui/blame/BlamePane.java (rev 0) +++ plugins/CommonControls/trunk/common/gui/blame/BlamePane.java 2013-08-13 23:44:26 UTC (rev 23119) @@ -0,0 +1,192 @@ +/* +* Copyright (c) 2008, Dale Anson +* +* 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 common.gui.blame; + +import java.util.*; + +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.*; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.gjt.sp.jedit.EditBus; +import org.gjt.sp.jedit.EBComponent; +import org.gjt.sp.jedit.EBMessage; +import org.gjt.sp.jedit.GUIUtilities; +import org.gjt.sp.jedit.View; +import org.gjt.sp.jedit.textarea.JEditTextArea; +import org.gjt.sp.jedit.msg.EditPaneUpdate; +import org.gjt.sp.jedit.msg.BufferChanging; +import org.gjt.sp.jedit.buffer.JEditBuffer; +import org.gjt.sp.jedit.jEdit; + +public class BlamePane extends JComponent implements CaretListener, EBComponent { + + private static final String uiClassID = "BlamePaneUI"; + private Set<ChangeListener> changeListeners = new HashSet<ChangeListener>(); + private BlameModel model = null; + + public BlamePane() { + this( null ); + } + + public BlamePane( BlameModel model ) { + this.model = model; + updateUI(); + EditBus.addToBus( this ); + } + + public void updateUI() { + if ( UIManager.get( getUIClassID() ) != null ) { + setUI( ( BlamePaneUI ) UIManager.getUI( this ) ); + } + else { + setUI( new BasicBlamePaneUI() ); + } + } + + public BlamePaneUI getUI() { + return ( BlamePaneUI ) ui; + } + + public String getUIClassID() { + return uiClassID; + } + + public void caretUpdate( final CaretEvent e ) { + if ( e.getSource() instanceof JEditTextArea ) { + fireStateChanged(); + } + } + + public void addChangeListener( ChangeListener cl ) { + if ( cl != null ) { + changeListeners.add( cl ); + } + } + + public void removeChangeListener( ChangeListener cl ) { + if ( cl != null ) { + changeListeners.remove( cl ); + } + } + + public void fireStateChanged() { + if ( changeListeners.size() > 0 ) { + ChangeEvent event = new ChangeEvent( this ); + for ( ChangeListener cl : changeListeners ) { + cl.stateChanged( event ); + } + } + } + + /** + * Model is a list of strings, one per line in the source file. Each string + * in the model provides the blame information about that line, probably just + * author and revision. This list is provided by the i.p.s.command.Blame command. + */ + public void setModel( BlameModel model ) { + this.model = model; + updateUI(); + } + + /** + * @return the model + */ + public BlameModel getModel() { + return model; + } + + /** + * A panel with a button to close out this blame pane. + */ + public JPanel getCloser( final View view ) { + final JPanel panel = new JPanel( new FlowLayout( FlowLayout.RIGHT, 16, 0 ) ); + JButton button = new JButton( jEdit.getProperty( "ips.Close_blame", "Close blame" ), GUIUtilities.loadIcon( "10x10/actions/close.png" ) ); + button.setBorder( null ); + panel.add( button ); + button.addActionListener( + new ActionListener() { + public void actionPerformed( ActionEvent ae ) { + Runnable runner = new Runnable(){ + public void run() { + // clean up the text area by removing the closer and blame pane, + // remove the stored props from the buffer, refresh the view. + getUI().uninstallUI( BlamePane.this ); + JEditTextArea textarea = view.getEditPane().getTextArea(); + textarea.removeCaretListener( BlamePane.this ); + textarea.removeTopComponent( panel ); + textarea.removeLeftOfScrollBar( BlamePane.this ); + textarea.getBuffer().unsetProperty( "_old_blame_" ); + textarea.getBuffer().unsetProperty( "_old_closer_" ); + view.invalidate(); + view.validate(); + } + }; + SwingUtilities.invokeLater(runner); + } + } + ); + return panel; + } + + public void handleMessage( EBMessage msg ) { + if ( msg instanceof EditPaneUpdate ) { + EditPaneUpdate epu = ( EditPaneUpdate ) msg; + if ( EditPaneUpdate.BUFFER_CHANGING.equals( epu.getWhat() ) ) { + // remove the blame components from the text area + JEditTextArea textArea = epu.getEditPane().getTextArea(); + JEditBuffer buffer = textArea.getBuffer(); + if ( buffer == null || epu instanceof BufferChanging && buffer.equals( ( ( BufferChanging ) epu ).getBuffer() ) ) { + return ; // same buffer, nothing to do + } + Object old_blame = buffer.getProperty( "_old_blame_" ); + if ( old_blame != null ) { + textArea.removeLeftOfScrollBar( ( JComponent ) old_blame ); + } + Object old_closer = buffer.getProperty( "_old_closer_" ); + if ( old_closer != null ) { + textArea.removeTopComponent( ( JComponent ) old_closer ); + } + epu.getEditPane().getView().invalidate(); + epu.getEditPane().getView().validate(); + + } + else if ( EditPaneUpdate.BUFFER_CHANGED.equals( epu.getWhat() ) ) { + // check if the new buffer has stored blame parts, if so, add + // them to the text area + JEditTextArea textArea = epu.getEditPane().getTextArea(); + JEditBuffer buffer = textArea.getBuffer(); + Object old_blame = buffer.getProperty( "_old_blame_" ); + Object old_closer = buffer.getProperty( "_old_closer_" ); + if ( old_blame != null && old_closer != null ) { + textArea.addLeftOfScrollBar( ( JComponent ) old_blame ); + textArea.addTopComponent( ( JComponent ) old_closer ); + epu.getEditPane().getView().invalidate(); + epu.getEditPane().getView().validate(); + } + } + } + } +} \ No newline at end of file Added: plugins/CommonControls/trunk/common/gui/blame/BlamePaneUI.java =================================================================== --- plugins/CommonControls/trunk/common/gui/blame/BlamePaneUI.java (rev 0) +++ plugins/CommonControls/trunk/common/gui/blame/BlamePaneUI.java 2013-08-13 23:44:26 UTC (rev 23119) @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2008, Dale Anson + * + * 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 common.gui.blame; + +import javax.swing.plaf.ComponentUI; + +public abstract class BlamePaneUI extends ComponentUI { +} Modified: plugins/CommonControls/trunk/docs/blame.html =================================================================== --- plugins/CommonControls/trunk/docs/blame.html 2013-08-13 23:04:36 UTC (rev 23118) +++ plugins/CommonControls/trunk/docs/blame.html 2013-08-13 23:44:26 UTC (rev 23119) @@ -7,7 +7,7 @@ The intent of this component is to show the results of the svn or git "blame" commands. Here is what this component looks like when used by the SVN Plugin: <br> -<img src="./doc-files/example.png"> +<img src="blame.png"> <br> <br> This component provides both the list on the right side of the text area and the Modified: plugins/CommonControls/trunk/docs/users-guide.xml =================================================================== --- plugins/CommonControls/trunk/docs/users-guide.xml 2013-08-13 23:04:36 UTC (rev 23118) +++ plugins/CommonControls/trunk/docs/users-guide.xml 2013-08-13 23:44:26 UTC (rev 23119) @@ -492,8 +492,8 @@ <para>This component shows the "blame" panel on the right side of the text area. This is used by the SVN Plugin and the Git Plugin.</para> - <para><ulink url="javadoc/common/gui/blame/package-summary.html">See details in the javadoc.</ulink></para> - + <para><ulink url="docs/blame.html">See details here.</ulink></para> + <para></para> </sect1> <sect1 id="AtomicOutputStream"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |