View | Details | Raw Unified | Return to bug 13672 | Differences between
and this patch

Collapse All | Expand All

(-)contexts_JDT.xml (+5 lines)
Lines 88-93 Link Here
88
    <context id="toggle_mark_occurrences_action_context">
88
    <context id="toggle_mark_occurrences_action_context">
89
        <description>Allows you to switch mark occurrences on and off.</description>
89
        <description>Allows you to switch mark occurrences on and off.</description>
90
    </context>
90
    </context>
91
    
92
    <context id="toggle_method_boundary_lines_action_context">
93
        <description>Allows you to toggle method boundary lines on and off.</description>
94
        <topic label="Java editor reference" href="reference/views/ref-java-editor.htm"/>
95
    </context>
91
96
92
    <context id="display_action_context">
97
    <context id="display_action_context">
93
        <description>This command evaluates the selected expression and shows the result in the Display view.</description>
98
        <description>This command evaluates the selected expression and shows the result in the Display view.</description>
(-)reference/preferences/java/ref-preferences-editor.htm (+18 lines)
Lines 127-132 Link Here
127
        </tr>
127
        </tr>
128
        <tr>
128
        <tr>
129
          <td valign="top">
129
          <td valign="top">
130
          Method boundary Lines
131
          </td>
132
          <td valign="top">
133
            <p>
134
              If enabled, the Java editor will show the Method boundary lines to indicate the beginning and end of a method.
135
            </p>
136
          </td>
137
          <td valign="top">
138
            <p>
139
              Off
140
            </p>
141
          </td>
142
        </tr>
143
        <tr>
144
          <td valign="top">
130
            Appearance color options
145
            Appearance color options
131
          </td>
146
          </td>
132
          <td valign="top">
147
          <td valign="top">
Lines 151-156 Link Here
151
              
166
              
152
              <dt>Source hover background</dt>
167
              <dt>Source hover background</dt>
153
              <dd>The background color for the source hover. The source hover shows the source code of the element under the mouse pointer.</dd>
168
              <dd>The background color for the source hover. The source hover shows the source code of the element under the mouse pointer.</dd>
169
              
170
              <dt>Method Boundary Lines</dt>
171
              <dd>The color of the method boundary lines</dd>
154
            </dl>
172
            </dl>
155
          </td>
173
          </td>
156
          <td valign="top">
174
          <td valign="top">
(-)reference/views/ref-java-editor.htm (+16 lines)
Lines 38-43 Link Here
38
      <tbody>
38
      <tbody>
39
        <tr>
39
        <tr>
40
        <td align="center" valign="top">
40
        <td align="center" valign="top">
41
            <p><img src="../../images/org.eclipse.jdt.ui/etool16/toggle_method_boundary.gif" alt="Toggle Method Boundary Lines"></p>
42
          </td>
43
          <td valign="top">
44
            <p>
45
              Toggle Method Boundary Lines
46
            </p>
47
          </td>
48
          <td valign="top">
49
            <p>
50
              This button shows the Method boundary lines in the Java Editor.
51
            </p>
52
          </td>
53
        </tr>
54
        
55
        <tr>
56
        <td align="center" valign="top">
41
            <p><img src="../../images/org.eclipse.jdt.ui/etool16/toggle_breadcrumb.gif" alt="Toggle Java Editor Breadcrumb"></p>
57
            <p><img src="../../images/org.eclipse.jdt.ui/etool16/toggle_breadcrumb.gif" alt="Toggle Java Editor Breadcrumb"></p>
42
          </td>
58
          </td>
43
          <td valign="top">
59
          <td valign="top">
(-)plugin.properties (+4 lines)
Lines 240-245 Link Here
240
toggleMarkOccurrences.tooltip= Toggle Mark Occurrences
240
toggleMarkOccurrences.tooltip= Toggle Mark Occurrences
241
toggleMarkOccurrences.description= Toggles mark occurrences in Java editors
241
toggleMarkOccurrences.description= Toggles mark occurrences in Java editors
242
242
243
toggleMethodBoundaryLines.label= Toggle Method Boundary Lines
244
toggleMethodBoundaryLines.tooltip= Toggle Method Boundary Lines
245
toggleMethodBoundaryLines.description= Toggles method boundary lines in Java editors
246
243
toggleBreadcrumb.label= Toggle Java Editor Breadcrumb
247
toggleBreadcrumb.label= Toggle Java Editor Breadcrumb
244
toggleBreadcrumb.tooltip= Toggle Java Editor Breadcrumb
248
toggleBreadcrumb.tooltip= Toggle Java Editor Breadcrumb
245
toggleBreadcrumb.description= Toggle the Java editor breadcrumb
249
toggleBreadcrumb.description= Toggle the Java editor breadcrumb
(-)plugin.xml (+19 lines)
Lines 1333-1338 Link Here
1333
               retarget="true"
1333
               retarget="true"
1334
               tooltip="%toggleBreadcrumb.tooltip">
1334
               tooltip="%toggleBreadcrumb.tooltip">
1335
         </action>
1335
         </action>
1336
         <action
1337
               allowLabelUpdate="true"
1338
               style="toggle"
1339
               toolbarPath="org.eclipse.ui.edit.text.actionSet.presentation/Presentation"
1340
               id="org.eclipse.jdt.ui.edit.text.java.toggleMethodBoundaryLines"
1341
               definitionId="org.eclipse.jdt.ui.edit.text.java.toggleMethodBoundaryLines"
1342
               disabledIcon="$nl$/icons/full/dtool16/toggle_method_boundary.gif"
1343
               icon="$nl$/icons/full/etool16/toggle_method_boundary.gif"
1344
               helpContextId="org.eclipse.jdt.ui.toggle_mark_occurrences_action_context"
1345
               label="%toggleMethodBoundaryLines.label"
1346
               retarget="true"
1347
               tooltip="%toggleMethodBoundaryLines.tooltip">
1348
         </action>
1336
      </actionSet>
1349
      </actionSet>
1337
   </extension>
1350
   </extension>
1338
1351
Lines 3557-3562 Link Here
3557
	        id="org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences">
3570
	        id="org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences">
3558
	  </command>
3571
	  </command>
3559
	  <command
3572
	  <command
3573
	        name="%toggleMethodBoundaryLines.label"
3574
	        description="%toggleMethodBoundaryLines.description"
3575
	        categoryId="org.eclipse.jdt.ui.category.source"
3576
	        id="org.eclipse.jdt.ui.edit.text.java.toggleMethodBoundaryLines">
3577
	  </command>
3578
	  <command
3560
	        name="%toggleBreadcrumb.label"
3579
	        name="%toggleBreadcrumb.label"
3561
	        description="%toggleBreadcrumb.description"
3580
	        description="%toggleBreadcrumb.description"
3562
	        categoryId="org.eclipse.jdt.ui.category.source"
3581
	        categoryId="org.eclipse.jdt.ui.category.source"
(-)ui/org/eclipse/jdt/internal/ui/IJavaHelpContextIds.java (+1 lines)
Lines 61-66 Link Here
61
61
62
	public static final String TOGGLE_PRESENTATION_ACTION= 								PREFIX + "toggle_presentation_action_context"; //$NON-NLS-1$
62
	public static final String TOGGLE_PRESENTATION_ACTION= 								PREFIX + "toggle_presentation_action_context"; //$NON-NLS-1$
63
	public static final String TOGGLE_MARK_OCCURRENCES_ACTION= 								PREFIX + "toggle_mark_occurrences_action_context"; //$NON-NLS-1$
63
	public static final String TOGGLE_MARK_OCCURRENCES_ACTION= 								PREFIX + "toggle_mark_occurrences_action_context"; //$NON-NLS-1$
64
	public static final String TOGGLE_METHOD_BOUNDARY_LINES_ACTION= PREFIX + "toggle_method_boundary_lines_action_context"; //$NON-NLS-1$
64
	public static final String TOGGLE_BREADCRUMB_ACTION= PREFIX + "toggle_breadcrumb_action_context"; //$NON-NLS-1$
65
	public static final String TOGGLE_BREADCRUMB_ACTION= PREFIX + "toggle_breadcrumb_action_context"; //$NON-NLS-1$
65
	public static final String TOGGLE_TEXTHOVER_ACTION= 									PREFIX + "toggle_texthover_action_context"; //$NON-NLS-1$
66
	public static final String TOGGLE_TEXTHOVER_ACTION= 									PREFIX + "toggle_texthover_action_context"; //$NON-NLS-1$
66
67
(-)ui/org/eclipse/jdt/internal/ui/IJavaThemeConstants.java (-1 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 29-34 Link Here
29
	public final String EDITOR_MATCHING_BRACKETS_COLOR= ID_PREFIX + PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
29
	public final String EDITOR_MATCHING_BRACKETS_COLOR= ID_PREFIX + PreferenceConstants.EDITOR_MATCHING_BRACKETS_COLOR;
30
30
31
	/**
31
	/**
32
	 * Theme constant for the color used to render method boundary lines.
33
	 */
34
	public final String METHOD_BOUNDARY_LINES_COLOR= ID_PREFIX + PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR;
35
36
	/**
32
	 * Theme constant for the color used to render multi-line comments.
37
	 * Theme constant for the color used to render multi-line comments.
33
	 */
38
	 */
34
	public final String EDITOR_MULTI_LINE_COMMENT_COLOR= ID_PREFIX + PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR;
39
	public final String EDITOR_MULTI_LINE_COMMENT_COLOR= ID_PREFIX + PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR;
(-)ui/org/eclipse/jdt/internal/ui/JavaUIPreferenceInitializer.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 125-130 Link Here
125
				findRGB(registry, IJavaThemeConstants.CODEASSIST_REPLACEMENT_BACKGROUND, new RGB(255, 255, 0)), fireEvent);
125
				findRGB(registry, IJavaThemeConstants.CODEASSIST_REPLACEMENT_BACKGROUND, new RGB(255, 255, 0)), fireEvent);
126
		setDefault(
126
		setDefault(
127
				store,
127
				store,
128
				PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR,
129
				findRGB(registry, IJavaThemeConstants.METHOD_BOUNDARY_LINES_COLOR, new RGB(192, 192, 192)), fireEvent);
130
		setDefault(
131
				store,
128
				PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND,
132
				PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND,
129
				findRGB(registry, IJavaThemeConstants.CODEASSIST_REPLACEMENT_FOREGROUND, new RGB(255, 0, 0)), fireEvent);
133
				findRGB(registry, IJavaThemeConstants.CODEASSIST_REPLACEMENT_FOREGROUND, new RGB(255, 0, 0)), fireEvent);
130
134
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/BasicJavaEditorActionContributor.java (+5 lines)
Lines 51-56 Link Here
51
	private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction;
51
	private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction;
52
	private ToggleBreadcrumbAction fToggleBreadcrumbAction;
52
	private ToggleBreadcrumbAction fToggleBreadcrumbAction;
53
53
54
	private ToggleMethodBoundaryLinesAction fToggleMethodBoundaryLinesAction;
55
54
	private RetargetTextEditorAction fGotoMatchingBracket;
56
	private RetargetTextEditorAction fGotoMatchingBracket;
55
	private RetargetTextEditorAction fShowOutline;
57
	private RetargetTextEditorAction fShowOutline;
56
	private RetargetTextEditorAction fOpenStructure;
58
	private RetargetTextEditorAction fOpenStructure;
Lines 80-85 Link Here
80
		fTogglePresentation= new TogglePresentationAction();
82
		fTogglePresentation= new TogglePresentationAction();
81
83
82
		fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction();
84
		fToggleMarkOccurrencesAction= new ToggleMarkOccurrencesAction();
85
		fToggleMethodBoundaryLinesAction= new ToggleMethodBoundaryLinesAction();
83
86
84
		fGotoMatchingBracket= new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
87
		fGotoMatchingBracket= new RetargetTextEditorAction(b, "GotoMatchingBracket."); //$NON-NLS-1$
85
		fGotoMatchingBracket.setActionDefinitionId(IJavaEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
88
		fGotoMatchingBracket.setActionDefinitionId(IJavaEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
Lines 129-134 Link Here
129
		bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
132
		bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
130
		bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
133
		bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
131
		bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_BREADCRUMB, fToggleBreadcrumbAction);
134
		bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_BREADCRUMB, fToggleBreadcrumbAction);
135
		bars.setGlobalActionHandler(IJavaEditorActionDefinitionIds.TOGGLE_METHOD_BOUNDARY_LINES, fToggleMethodBoundaryLinesAction);
132
	}
136
	}
133
137
134
	/*
138
	/*
Lines 179-184 Link Here
179
183
180
		fTogglePresentation.setEditor(textEditor);
184
		fTogglePresentation.setEditor(textEditor);
181
		fToggleMarkOccurrencesAction.setEditor(textEditor);
185
		fToggleMarkOccurrencesAction.setEditor(textEditor);
186
		fToggleMethodBoundaryLinesAction.setEditor(textEditor);
182
187
183
		fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
188
		fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
184
		fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
189
		fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE));
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/ConstructedJavaEditorMessages.properties (+3 lines)
Lines 46-51 Link Here
46
TogglePresentation.label=Show Source of Selected Element Only
46
TogglePresentation.label=Show Source of Selected Element Only
47
TogglePresentation.tooltip=Show Source of Selected Element Only
47
TogglePresentation.tooltip=Show Source of Selected Element Only
48
48
49
ToggleMethodBoundaryLinesAction.label=Toggle Method Boundary Lines
50
ToggleMethodBoundaryLinesAction.tooltip=Toggle Method Boundary Lines
51
49
ToggleMarkOccurrencesAction.label= Toggle Mark Occurrences
52
ToggleMarkOccurrencesAction.label= Toggle Mark Occurrences
50
ToggleMarkOccurrencesAction.tooltip= Toggle Mark Occurrences
53
ToggleMarkOccurrencesAction.tooltip= Toggle Mark Occurrences
51
54
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java (-1 / +51 lines)
Lines 30-35 Link Here
30
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.custom.ST;
31
import org.eclipse.swt.custom.ST;
32
import org.eclipse.swt.custom.StyledText;
32
import org.eclipse.swt.custom.StyledText;
33
import org.eclipse.swt.graphics.Color;
33
import org.eclipse.swt.graphics.Image;
34
import org.eclipse.swt.graphics.Image;
34
import org.eclipse.swt.graphics.Point;
35
import org.eclipse.swt.graphics.Point;
35
import org.eclipse.swt.layout.FillLayout;
36
import org.eclipse.swt.layout.FillLayout;
Lines 63-68 Link Here
63
import org.eclipse.jface.action.IMenuManager;
64
import org.eclipse.jface.action.IMenuManager;
64
import org.eclipse.jface.action.MenuManager;
65
import org.eclipse.jface.action.MenuManager;
65
import org.eclipse.jface.preference.IPreferenceStore;
66
import org.eclipse.jface.preference.IPreferenceStore;
67
import org.eclipse.jface.preference.PreferenceConverter;
66
import org.eclipse.jface.util.IPropertyChangeListener;
68
import org.eclipse.jface.util.IPropertyChangeListener;
67
import org.eclipse.jface.util.PropertyChangeEvent;
69
import org.eclipse.jface.util.PropertyChangeEvent;
68
import org.eclipse.jface.viewers.DoubleClickEvent;
70
import org.eclipse.jface.viewers.DoubleClickEvent;
Lines 1507-1513 Link Here
1507
	}
1509
	}
1508
1510
1509
1511
1510
1511
	/** Preference key for matching brackets */
1512
	/** Preference key for matching brackets */
1512
	protected final static String MATCHING_BRACKETS=  PreferenceConstants.EDITOR_MATCHING_BRACKETS;
1513
	protected final static String MATCHING_BRACKETS=  PreferenceConstants.EDITOR_MATCHING_BRACKETS;
1513
	/** Preference key for matching brackets color */
1514
	/** Preference key for matching brackets color */
Lines 1743-1748 Link Here
1743
	private long fErrorMessageTime;
1744
	private long fErrorMessageTime;
1744
1745
1745
	/**
1746
	/**
1747
	 * The method boundary lines capability provider.
1748
	 * 
1749
	 * @since 3.7
1750
	 */
1751
	private MethodBoundaryLinesProvider fMethodBoundaryLinesProvider;
1752
1753
	/**
1746
	 * Timeout for the error message.
1754
	 * Timeout for the error message.
1747
	 * 
1755
	 * 
1748
	 * @since 3.5
1756
	 * @since 3.5
Lines 2586-2591 Link Here
2586
			fProjectionSupport= null;
2594
			fProjectionSupport= null;
2587
		}
2595
		}
2588
2596
2597
		if (fMethodBoundaryLinesProvider != null) {
2598
			fMethodBoundaryLinesProvider.dispose();
2599
			fMethodBoundaryLinesProvider= null;
2600
		}
2601
2589
		// cancel possible running computation
2602
		// cancel possible running computation
2590
		fMarkOccurrenceAnnotations= false;
2603
		fMarkOccurrenceAnnotations= false;
2591
		uninstallOccurrencesFinder();
2604
		uninstallOccurrencesFinder();
Lines 2944-2949 Link Here
2944
				return;
2957
				return;
2945
			}
2958
			}
2946
2959
2960
			if (PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR.equals(property)) {
2961
				if (fMethodBoundaryLinesProvider != null) {
2962
					Color methodBoundaryColor= getSharedColors().getColor(PreferenceConverter.getColor(getPreferenceStore(), PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR));
2963
					fMethodBoundaryLinesProvider.setColor(methodBoundaryColor);
2964
				}
2965
			}
2966
2967
			if (PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES.equals(property)) {
2968
				if (!JavaPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES)) {
2969
					if (fMethodBoundaryLinesProvider != null) {
2970
						fMethodBoundaryLinesProvider.dispose();
2971
						fMethodBoundaryLinesProvider= null;
2972
					}
2973
				} else {
2974
					if (fMethodBoundaryLinesProvider == null) {
2975
						Color methodBoundaryColor= getSharedColors().getColor(PreferenceConverter.getColor(getPreferenceStore(), PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR));
2976
						fMethodBoundaryLinesProvider= new MethodBoundaryLinesProvider(this, (JavaSourceViewer)sourceViewer, getAnnotationAccess(), methodBoundaryColor);
2977
					}
2978
				}
2979
			}
2980
2947
		} finally {
2981
		} finally {
2948
			super.handlePreferenceStoreChanged(event);
2982
			super.handlePreferenceStoreChanged(event);
2949
		}
2983
		}
Lines 3063-3068 Link Here
3063
		if (fIsBreadcrumbVisible)
3097
		if (fIsBreadcrumbVisible)
3064
			showBreadcrumb();
3098
			showBreadcrumb();
3065
3099
3100
		if (JavaPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES)) {
3101
			Color methodBoundaryColor= getSharedColors().getColor(PreferenceConverter.getColor(getPreferenceStore(), PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR));
3102
			fMethodBoundaryLinesProvider= new MethodBoundaryLinesProvider(this, (JavaSourceViewer)getViewer(), getAnnotationAccess(), methodBoundaryColor);
3103
		}
3104
3066
		PlatformUI.getWorkbench().addWindowListener(fActivationListener);
3105
		PlatformUI.getWorkbench().addWindowListener(fActivationListener);
3067
	}
3106
	}
3068
3107
Lines 3352-3357 Link Here
3352
	}
3391
	}
3353
3392
3354
	/**
3393
	/**
3394
	 * Checks if the method boundary lines is enabled.
3395
	 * 
3396
	 * @return <code>true</code> if the method boundary lines preference is checked
3397
	 * @since 3.7
3398
	 */
3399
	protected boolean isShowingMethodBoundaryLines() {
3400
		IPreferenceStore store= getPreferenceStore();
3401
		return store != null && store.getBoolean(PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES);
3402
	}
3403
3404
	/**
3355
	 * @return true if editor breadcrumbs are enabled
3405
	 * @return true if editor breadcrumbs are enabled
3356
	 * @since 3.4
3406
	 * @since 3.4
3357
	 */
3407
	 */
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/MethodBoundaryLinesProvider.java (+609 lines)
Added Link Here
1
package org.eclipse.jdt.internal.ui.javaeditor;
2
3
import java.util.Iterator;
4
5
import org.eclipse.swt.custom.StyledText;
6
import org.eclipse.swt.graphics.Color;
7
import org.eclipse.swt.graphics.GC;
8
9
import org.eclipse.jface.text.BadLocationException;
10
import org.eclipse.jface.text.IDocument;
11
import org.eclipse.jface.text.IPainter;
12
import org.eclipse.jface.text.IRegion;
13
import org.eclipse.jface.text.Position;
14
import org.eclipse.jface.text.source.Annotation;
15
import org.eclipse.jface.text.source.AnnotationModel;
16
import org.eclipse.jface.text.source.AnnotationPainter;
17
import org.eclipse.jface.text.source.IAnnotationAccess;
18
import org.eclipse.jface.text.source.IAnnotationModel;
19
import org.eclipse.jface.text.source.IAnnotationModelExtension;
20
import org.eclipse.jface.text.source.ISourceViewer;
21
import org.eclipse.jface.text.source.ISourceViewerExtension2;
22
23
import org.eclipse.ui.texteditor.IDocumentProvider;
24
25
import org.eclipse.jdt.core.ElementChangedEvent;
26
import org.eclipse.jdt.core.IElementChangedListener;
27
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IJavaElementDelta;
29
import org.eclipse.jdt.core.IParent;
30
import org.eclipse.jdt.core.ISourceRange;
31
import org.eclipse.jdt.core.ISourceReference;
32
import org.eclipse.jdt.core.IType;
33
import org.eclipse.jdt.core.ITypeRoot;
34
import org.eclipse.jdt.core.JavaCore;
35
import org.eclipse.jdt.core.JavaModelException;
36
37
import org.eclipse.jdt.internal.ui.JavaPlugin;
38
39
/**
40
 * Draws lines that visually demarcate the boundary for methods and types.
41
 * 
42
 * @since 3.7
43
 */
44
class MethodBoundaryLinesProvider {
45
46
	/**
47
	 * Updates the annotation model to reflect the incoming element changes.
48
	 */
49
	private class ElementChangedListener implements IElementChangedListener {
50
51
		/*
52
		 * @see org.eclipse.jdt.core.IElementChangedListener#elementChanged(org.eclipse.jdt.core.ElementChangedEvent)
53
		 */
54
		public void elementChanged(ElementChangedEvent event) {
55
			IJavaElementDelta delta= findElement(fInput, event.getDelta());
56
			if (delta != null && (delta.getFlags() & (IJavaElementDelta.F_CHILDREN | IJavaElementDelta.F_CONTENT)) != 0) {
57
				//System.out.println("Element Changed: " + delta);
58
				//if (shouldIgnoreDelta(event.getDelta().getCompilationUnitAST(), delta))
59
				//	return;
60
				if ((delta.getFlags() & IJavaElementDelta.F_CHILDREN) != 0)
61
					updateAnnotationModel(delta.getAffectedChildren());
62
				else
63
					updateAnnotationPositions();
64
			}
65
		}
66
67
		/**
68
		 * Find the element in the java element delta that matches the target element.
69
		 * 
70
		 * @param target the target java element to be searched for in the delta
71
		 * @param delta the java element delta that is to be searched for the target element
72
		 * @return the delta that contains the java element matching the target element
73
		 */
74
		private IJavaElementDelta findElement(IJavaElement target, IJavaElementDelta delta) {
75
76
			if (delta == null || target == null)
77
				return null;
78
79
			IJavaElement element= delta.getElement();
80
81
			if (element.getElementType() > IJavaElement.CLASS_FILE)
82
				return null;
83
84
			if (target.equals(element))
85
				return delta;
86
87
			IJavaElementDelta[] children= delta.getAffectedChildren();
88
89
			for (int i= 0; i < children.length; i++) {
90
				IJavaElementDelta d= findElement(target, children[i]);
91
				if (d != null)
92
					return d;
93
			}
94
95
			return null;
96
		}
97
	}
98
99
	/**
100
	 * The annotation model that holds the annotations for method boundary lines.
101
	 */
102
	private class MethodBoundaryAnnotationModel extends AnnotationModel {
103
		private MethodBoundaryAnnotationModel() {
104
		}
105
106
		/**
107
		 * Sets the position for the annotation associated with a given element to the new position.
108
		 * If position is null then the annotation, if found, is removed from the model.
109
		 * 
110
		 * @param element the element whose corresponding annotation position is to be modified
111
		 * @param newPosition The new position for the concerned annotation
112
		 */
113
		public void modifyAnnotationForElement(IJavaElement element, Position newPosition) {
114
			MethodBoundaryAnnotation methodBoundaryAnnotation= (MethodBoundaryAnnotation)getAnnotationForElement(element);
115
			if (methodBoundaryAnnotation != null)
116
				modifyAnnotationPosition(methodBoundaryAnnotation, newPosition);
117
		}
118
119
		/**
120
		 * Searches and returns the annotation associated with given element.
121
		 * 
122
		 * @param element the element whose associated annotation we are looking for
123
		 * @return returns the associated annotation if found, else returns null
124
		 */
125
		public Object getAnnotationForElement(IJavaElement element) {
126
			Iterator iterator= getAnnotationIterator();
127
			while (iterator.hasNext()) {
128
				MethodBoundaryAnnotation methodBoundaryAnnotation= (MethodBoundaryAnnotation)iterator.next();
129
				if (element.equals(methodBoundaryAnnotation.getElement())) {
130
					return methodBoundaryAnnotation;
131
				}
132
			}
133
			return null;
134
		}
135
	}
136
137
	/**
138
	 * The drawing strategy for method boundary lines draws the lines that visual separate methods
139
	 * and types.
140
	 */
141
	private static class MethodBoundaryDrawingStrategy implements AnnotationPainter.IDrawingStrategy {
142
143
		/*
144
		 * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color)
145
		 */
146
		public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
147
			if (annotation instanceof MethodBoundaryAnnotation) {
148
				MethodBoundaryAnnotation methodBoundaryAnnotation= (MethodBoundaryAnnotation)annotation;
149
				if (gc != null) {
150
					int lineIndex= textWidget.getLineAtOffset(offset);
151
					int lineY= textWidget.getLinePixel(lineIndex);
152
					IJavaElement element= methodBoundaryAnnotation.getElement();
153
					if (element.getElementType() == IJavaElement.TYPE) {
154
						//System.out.println(methodBoundaryAnnotation.getElement().getElementName() + ":  Off-" + offset + "  Len-" + length + "  Width-" + 2);
155
						gc.setLineWidth(2);
156
						lineY++;
157
					} else {
158
						//System.out.println(methodBoundaryAnnotation.getElement().getElementName() + ":  Off-" + offset + "  Len-" + length + "  Width-" + 0);
159
						gc.setLineWidth(0);
160
					}
161
					Color defaultColor= gc.getForeground();
162
					gc.setForeground(color);
163
					gc.drawLine(2, lineY, textWidget.getClientArea().width, lineY);
164
					gc.setForeground(defaultColor);
165
				} else {
166
					//System.out.println("Clearing: " + methodBoundaryAnnotation.getElement().getElementName() + ":  " + offset + "  " + length);
167
					textWidget.redraw(2, textWidget.getLinePixel(textWidget.getLineAtOffset(offset)), textWidget.getClientArea().width, 2, true);
168
				}
169
			}
170
		}
171
	}
172
173
	/**
174
	 * Annotation for method boundary lines.
175
	 */
176
	private class MethodBoundaryAnnotation extends Annotation {
177
178
		/**
179
		 * The type for method boundary annotation.
180
		 */
181
		public static final String TYPE= "org.eclipse.separator"; //$NON-NLS-1$
182
183
		/**
184
		 * The java element associated with this annotation.
185
		 */
186
		private IJavaElement fElementToBeAnnotated;
187
188
		/**
189
		 * Creates a new method boundary annotation.
190
		 * 
191
		 * @param element the java element that this annotation is associated with
192
		 */
193
		public MethodBoundaryAnnotation(IJavaElement element) {
194
			super(TYPE, false, null);
195
			fElementToBeAnnotated= element;
196
		}
197
198
		/**
199
		 * Getter for the java element associated with this annotation.
200
		 * 
201
		 * @return returns the java element associated with this annotation
202
		 */
203
		public IJavaElement getElement() {
204
			return fElementToBeAnnotated;
205
		}
206
	}
207
208
	/**
209
	 * Paints the method boundary lines.
210
	 */
211
	private class MethodBoundaryAnnotationsPainter extends AnnotationPainter {
212
213
		/**
214
		 * Constructs a new <code>MethodSeparatorPainter</code>.
215
		 * 
216
		 * @param sourceViewer the source viewer for the painter
217
		 * @param access the annotation access
218
		 */
219
		public MethodBoundaryAnnotationsPainter(ISourceViewer sourceViewer, IAnnotationAccess access) {
220
			super(sourceViewer, access);
221
		}
222
223
		/**
224
		 * Retrieves the annotation model from the given source viewer.
225
		 * 
226
		 * @param sourceViewer the source viewer
227
		 * @return the source viewer's annotation model or <code>null</code> if none can be found
228
		 */
229
		protected IAnnotationModel findAnnotationModel(ISourceViewer sourceViewer) {
230
			if (sourceViewer != null && sourceViewer instanceof ISourceViewerExtension2)
231
				return ((IAnnotationModelExtension)(((ISourceViewerExtension2)sourceViewer).getVisualAnnotationModel())).getAnnotationModel(METHOD_BOUNDARY);
232
			return null;
233
		}
234
	}
235
236
	/**
237
	 * Key of the method boundary annotation model inside the visual annotation model. Also
238
	 * internally used as key for the drawing strategy.
239
	 */
240
	public final static Object METHOD_BOUNDARY= new Object();
241
	/**
242
	 * The source viewer associated with the editor.
243
	 */
244
	private JavaSourceViewer fViewer;
245
	/**
246
	 * The method boundary painter that paints the boundary lines.
247
	 */
248
	private MethodBoundaryAnnotationsPainter fPainter;
249
	
250
	/**
251
	 * The annotation access.
252
	 */
253
	private IAnnotationAccess fAnnotationAccess;
254
	/**
255
	 * The drawing strategy that is used for drawing the method boundary lines.
256
	 */
257
	private static AnnotationPainter.IDrawingStrategy fDrawingStrategy;
258
	/**
259
	 * The method boundary annotation model that holds the annotations and is connected to the
260
	 * document.
261
	 */
262
	private MethodBoundaryAnnotationModel fMethodBoundaryAnnotationModel;
263
	/**
264
	 * The listener that listens for element changes from the java model.
265
	 */
266
	private IElementChangedListener fElementListener;
267
	/**
268
	 * The java input element associated with the java editor.
269
	 */
270
	private IJavaElement fInput;
271
	/**
272
	 * The java editor.
273
	 */
274
	private JavaEditor fEditor;
275
	/**
276
	 * Constructs the <code>MethodBoundaryLinesProvider</code>.
277
	 * 
278
	 * @param editor the java editor
279
	 * @param viewer the source viewer associated with the editor
280
	 * @param annotationAccess the annotation access
281
	 * @param methodBoundaryColor the color to be used for drawing the method boundary lines
282
	 */
283
	public MethodBoundaryLinesProvider(JavaEditor editor, JavaSourceViewer viewer, IAnnotationAccess annotationAccess, Color methodBoundaryColor) {
284
		fEditor= editor;
285
		fViewer= viewer;
286
		fAnnotationAccess= annotationAccess;
287
		if (fPainter == null) {
288
			fPainter= new MethodBoundaryAnnotationsPainter(fViewer, fAnnotationAccess);
289
			fPainter.addDrawingStrategy(METHOD_BOUNDARY, getDrawingStrategy());
290
			fPainter.addAnnotationType(MethodBoundaryAnnotation.TYPE, METHOD_BOUNDARY);
291
			fPainter.setAnnotationTypeColor(MethodBoundaryAnnotation.TYPE, methodBoundaryColor);
292
			fViewer.addPainter(fPainter);
293
		}
294
295
		fInput= EditorUtility.getEditorInputJavaElement(fEditor, false);
296
		fMethodBoundaryAnnotationModel= new MethodBoundaryAnnotationModel();
297
		try {
298
			initializeModel(((IParent)fInput).getChildren());
299
		} catch (JavaModelException e) {
300
			JavaPlugin.log(e);
301
		}
302
		((IAnnotationModelExtension)(fViewer.getVisualAnnotationModel())).addAnnotationModel(METHOD_BOUNDARY, fMethodBoundaryAnnotationModel);
303
		if (fElementListener == null) {
304
			//System.out.println("New Listener Registered: " + fEditor.getContentDescription());
305
			fElementListener= new ElementChangedListener();
306
			JavaCore.addElementChangedListener(fElementListener);
307
		}
308
	}
309
310
	/**
311
	 * Initializes the annotation model with annotations based on the array of java elements.
312
	 * 
313
	 * @param elements the java elements for which the annotation model is to be initialized
314
	 */
315
	private void initializeModel(IJavaElement[] elements) {
316
		for (int i= 0; i < elements.length; i++) {
317
			int elementType= elements[i].getElementType();
318
			try {
319
				if (isElementOfTypeWeCanAnnotate(elements[i])) {
320
					if (isMethodOrType(elementType)) {
321
						fMethodBoundaryAnnotationModel.addAnnotation(new MethodBoundaryAnnotation(elements[i]), getAlignedFirstLineElementPosition(elements[i]));
322
					} else if (i != 0 && isMethodOrType(elements[i - 1].getElementType())) {
323
						fMethodBoundaryAnnotationModel.addAnnotation(new MethodBoundaryAnnotation(elements[i]), getAlignedFirstLineElementPosition(elements[i]));
324
					}
325
				}
326
				if (elements[i] instanceof IParent) {
327
					IJavaElement[] children= ((IParent)elements[i]).getChildren();
328
					if (children.length > 0)
329
						initializeModel(children);
330
				}
331
			} catch (JavaModelException e) {
332
				JavaPlugin.log(e);
333
			}
334
		}
335
	}
336
337
	/**
338
	 * Get the aligned position of the first line of the java element.
339
	 * 
340
	 * @param element the java element whose first line position is to be determined
341
	 * @return returns the position of the first line of the java element
342
	 */
343
	private Position getAlignedFirstLineElementPosition(IJavaElement element) {
344
		IDocument document= getDocument();
345
		try {
346
			ISourceRange sourceRange= ((ISourceReference)element).getSourceRange();
347
			IRegion elementFirstLineRegion= document.getLineInformationOfOffset(sourceRange.getOffset());
348
			return new Position(elementFirstLineRegion.getOffset(), elementFirstLineRegion.getLength());
349
		} catch (JavaModelException e) {
350
			JavaPlugin.log(e);
351
		} catch (BadLocationException e) {
352
			JavaPlugin.log(e);
353
		}
354
		return null;
355
	}
356
357
	/**
358
	 * Returns <code>true</code> if the element type is one of the types that we can annotate and it
359
	 * should not be of primary type. Types we can annotate are TYPE, METHOD, FIELD & INITIALIZER.
360
	 * 
361
	 * @param element the element whose type is to be checked
362
	 * @return <code>true</code> if element type matches any in our list
363
	 */
364
	private boolean isElementOfTypeWeCanAnnotate(IJavaElement element) {
365
		int elementType= element.getElementType();
366
		if (element instanceof ISourceReference && ((elementType == IJavaElement.TYPE && !isPrimaryType((IType)element))
367
				|| elementType == IJavaElement.METHOD || elementType == IJavaElement.FIELD
368
				|| elementType == IJavaElement.INITIALIZER)) {
369
			return true;
370
		}
371
		return false;
372
	}
373
374
	/**
375
	 * Returns <code>true</code> if <code>type</code> is not a top-level type, <code>false</code> if
376
	 * it is.
377
	 * 
378
	 * @param type the type to test
379
	 * @return <code>true</code> if <code>type</code> is an inner type
380
	 */
381
	private boolean isInnerType(IType type) {
382
		return type.getDeclaringType() != null;
383
	}
384
385
	/**
386
	 * Returns <code>true</code> if <code>element</code> is the primary type, <code>false</code> if
387
	 * it is not. This is based on {@link ITypeRoot#findPrimaryType()}.
388
	 * 
389
	 * @param element the <code>element</code> to be evaluated if it is the primary type
390
	 * @return <code>true</code> if it is the primary type
391
	 */
392
	private boolean isPrimaryType(IType element) {
393
		IType primaryType= ((ITypeRoot)fInput).findPrimaryType();
394
		if (primaryType != null && primaryType.equals(element))
395
			return true;
396
		return false;
397
	}
398
399
	/**
400
	 * Update the annotations in the method boundary annotation model with the
401
	 * {@link IJavaElementDelta} changes. Based on ({@link IJavaElementDelta#getKind()}, annotation
402
	 * corresponding to the element in the delta is added, removed or changed.
403
	 * 
404
	 * @param delta the java element deltas that contain the changes done to the Java model
405
	 */
406
	private void updateAnnotationModel(IJavaElementDelta[] delta) {
407
		for (int i= 0; i < delta.length; i++) {
408
			IJavaElement element= delta[i].getElement();
409
			if (isElementOfTypeWeCanAnnotate(element)) {
410
				int elementType= element.getElementType();
411
				int deltaKind= delta[i].getKind();
412
				if (deltaKind == IJavaElementDelta.REMOVED) {
413
					//System.out.println("Element 'Removed': " + element.getElementName());
414
					fMethodBoundaryAnnotationModel.modifyAnnotationForElement(element, null);
415
					updateAnnotationModelForDanglingElements(element.getParent());
416
417
				} else if (deltaKind == IJavaElementDelta.ADDED) {
418
					if (!isMethodOrType(elementType) && isElementAfterTypeOrMethod(element)) {
419
						//modifyAnnotationForNextElement(element, false);						
420
						addAnnotationForNewElementToModel(element);
421
						updateAnnotationModelForDanglingElements(element.getParent());
422
					} else if (isMethodOrType(elementType)) {
423
						//modifyAnnotationForNextElement(element, true);
424
						addAnnotationForNewElementToModel(element);
425
						updateAnnotationModelForDanglingElements(element.getParent());
426
					}
427
				} else if (deltaKind == IJavaElementDelta.CHANGED) {
428
					//System.out.println("Element 'Changed': " + element.getElementName());
429
					fMethodBoundaryAnnotationModel.modifyAnnotationForElement(element, getAlignedFirstLineElementPosition(element));
430
				}
431
			}
432
			if (element instanceof IParent) {
433
				updateAnnotationModel(delta[i].getAffectedChildren());
434
			}
435
		}
436
	}
437
438
	/**
439
	 * Return <code>true</code> if the given elementType is of type {@link IJavaElement#METHOD} or
440
	 * {@link IJavaElement#TYPE}.
441
	 * 
442
	 * @param elementType the element type to check against
443
	 * @return <code>true</code> if the given elementType is of type {@link IJavaElement#METHOD} or
444
	 *         {@link IJavaElement#TYPE}
445
	 */
446
	private boolean isMethodOrType(int elementType) {
447
		if (elementType == IJavaElement.METHOD || elementType == IJavaElement.TYPE)
448
			return true;
449
		return false;
450
	}
451
452
	/**
453
	 * For all the children of parentElement, it checks and updates if any does not have a required
454
	 * Method boundary.
455
	 * 
456
	 * @param parentElement the parent element whose children are checked for missing boundary lines
457
	 */
458
	private void updateAnnotationModelForDanglingElements(IJavaElement parentElement) {
459
		try {
460
			if (parentElement != null && parentElement.getElementType() == IJavaElement.TYPE && ((IType)parentElement).hasChildren()) {
461
				IJavaElement[] childrenElements= ((IType)parentElement).getChildren();
462
				for (int i= 0; i < childrenElements.length; i++) {
463
					int childElementType= childrenElements[i].getElementType();
464
					if (!isMethodOrType(childElementType)) {
465
						if (i == 0) {
466
							fMethodBoundaryAnnotationModel.modifyAnnotationForElement(childrenElements[i], null);
467
						} else {
468
							childElementType= childrenElements[i - 1].getElementType();
469
							if (isMethodOrType(childElementType) && isElementOfTypeWeCanAnnotate(childrenElements[i])
470
									&& fMethodBoundaryAnnotationModel.getAnnotationForElement(childrenElements[i]) == null) {
471
								fMethodBoundaryAnnotationModel.addAnnotation(new MethodBoundaryAnnotation(childrenElements[i]), getAlignedFirstLineElementPosition(childrenElements[i]));
472
							} else if (!isMethodOrType(childElementType)) {
473
								fMethodBoundaryAnnotationModel.modifyAnnotationForElement(childrenElements[i], null);
474
							}
475
						}
476
					}
477
				}
478
			}
479
		} catch (JavaModelException e) {
480
			JavaPlugin.log(e);
481
		}
482
	}
483
484
	/**
485
	 * Returns <code>true</code> if the given element is immediately preceded by an element of type
486
	 * IJavaElement.METHOD or TYPE in the source code.
487
	 * 
488
	 * @param element the element
489
	 * @return <code>true</code> if the given element is preceded by an IMethod or IType element
490
	 */
491
	private boolean isElementAfterTypeOrMethod(IJavaElement element) {
492
		try {
493
			IJavaElement parentElement= element.getParent();
494
			if (parentElement != null && parentElement.getElementType() == IJavaElement.TYPE && ((IType)parentElement).hasChildren()) {
495
				IJavaElement[] childrenElements= ((IType)parentElement).getChildren();
496
				for (int i= 0; i < childrenElements.length; i++) {
497
					if (childrenElements[i].equals(element)) {
498
						if (i == 0)
499
							return false;
500
						int childElementType= childrenElements[i - 1].getElementType();
501
						if (childElementType == IJavaElement.METHOD || (childElementType == IJavaElement.TYPE && isInnerType((IType)childrenElements[i - 1]))) {
502
							return true;
503
						}
504
					}
505
				}
506
			}
507
		} catch (JavaModelException e) {
508
			JavaPlugin.log(e);
509
		}
510
		return false;
511
	}
512
513
	/**
514
	 * For a new element added to the Java, create and add an annotation to the method boundary
515
	 * annotation model.
516
	 * 
517
	 * @param element the new element for which annotation is to be added to the annotation model
518
	 */
519
	private void addAnnotationForNewElementToModel(IJavaElement element) {
520
		//System.out.println("Element 'Added': " + element.getElementName());
521
		fMethodBoundaryAnnotationModel.addAnnotation(new MethodBoundaryAnnotation(element), getAlignedFirstLineElementPosition(element));
522
		if (element instanceof IParent) {
523
			try {
524
				IJavaElement[] children= ((IParent)element).getChildren();
525
				for (int i= 0; i < children.length; i++) {
526
					int elementType= children[i].getElementType();
527
					if (elementType == IJavaElement.METHOD || elementType == IJavaElement.TYPE) {
528
						addAnnotationForNewElementToModel(children[i]);
529
					}
530
				}
531
			} catch (JavaModelException e) {
532
				JavaPlugin.log(e);
533
			}
534
		}
535
	}
536
537
	/**
538
	 * Update the Positions in the annotation model for all the elements whose current source range
539
	 * in the document is different from the Position stored with the corresponding annotation.
540
	 */
541
	private void updateAnnotationPositions() {
542
		Iterator iterator= fMethodBoundaryAnnotationModel.getAnnotationIterator();
543
		while (iterator.hasNext()) {
544
			MethodBoundaryAnnotation methodBoundaryAnnotation= (MethodBoundaryAnnotation)iterator.next();
545
			Position existingPosition= fMethodBoundaryAnnotationModel.getPosition(methodBoundaryAnnotation);
546
			IJavaElement element= methodBoundaryAnnotation.getElement();
547
			if (element != null && ((ISourceReference)element).exists()) {
548
				Position newPosition= getAlignedFirstLineElementPosition(element);
549
				if (newPosition.getOffset() != existingPosition.getOffset() || newPosition.getLength() != existingPosition.getLength()) {
550
					fMethodBoundaryAnnotationModel.modifyAnnotationPosition(methodBoundaryAnnotation, newPosition);
551
				}
552
			}
553
		}
554
	}
555
556
	/**
557
	 * Gets the document associated with the Java editor.
558
	 * 
559
	 * @return returns the document
560
	 */
561
	private IDocument getDocument() {
562
		JavaEditor editor= fEditor;
563
		if (editor == null)
564
			return null;
565
566
		IDocumentProvider provider= editor.getDocumentProvider();
567
		if (provider == null)
568
			return null;
569
570
		return provider.getDocument(editor.getEditorInput());
571
	}
572
573
	/**
574
	 * Returns the drawing strategy to be used by the method boundary annotation painter.
575
	 * 
576
	 * @return the drawing strategy to be used by the method boundary annotation painter
577
	 */
578
	private AnnotationPainter.IDrawingStrategy getDrawingStrategy() {
579
		if (fDrawingStrategy == null)
580
			fDrawingStrategy= new MethodBoundaryDrawingStrategy();
581
		return fDrawingStrategy;
582
	}
583
584
	/**
585
	 * Disposes the method boundary lines provider and associated painter.
586
	 */
587
	public void dispose() {
588
		if (fPainter != null) {
589
			fViewer.removePainter(fPainter);
590
			fPainter.deactivate(true);
591
			fPainter.dispose();
592
			fPainter= null;
593
		}
594
		fMethodBoundaryAnnotationModel= null;
595
		JavaCore.removeElementChangedListener(fElementListener);
596
		fViewer= null;
597
		fEditor= null;
598
	}
599
600
	/**
601
	 * Sets the color for the method boundary lines.
602
	 * 
603
	 * @param methodBoundaryColor the color to be used for drawing the method boundary lines
604
	 */
605
	public void setColor(Color methodBoundaryColor) {
606
		fPainter.setAnnotationTypeColor(MethodBoundaryAnnotation.TYPE, methodBoundaryColor);
607
		fPainter.paint(IPainter.CONFIGURATION);
608
	}
609
}
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/ToggleMethodBoundaryLinesAction.java (+101 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.ui.javaeditor;
12
13
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.preference.IPreferenceStore;
16
import org.eclipse.jface.util.IPropertyChangeListener;
17
import org.eclipse.jface.util.PropertyChangeEvent;
18
19
import org.eclipse.ui.PlatformUI;
20
21
import org.eclipse.ui.texteditor.ITextEditor;
22
import org.eclipse.ui.texteditor.TextEditorAction;
23
24
import org.eclipse.jdt.ui.PreferenceConstants;
25
26
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27
import org.eclipse.jdt.internal.ui.JavaPlugin;
28
import org.eclipse.jdt.internal.ui.JavaPluginImages;
29
30
31
/**
32
 * A toolbar action which toggles the
33
 * {@linkplain org.eclipse.jdt.ui.PreferenceConstants#SHOW_METHOD_BOUNDARY_LINES preference}.
34
 * 
35
 * @since 3.7
36
 */
37
public class ToggleMethodBoundaryLinesAction extends TextEditorAction implements IPropertyChangeListener {
38
39
	private IPreferenceStore fStore;
40
41
	/**
42
	 * Constructs and updates the action.
43
	 */
44
	public ToggleMethodBoundaryLinesAction() {
45
		super(JavaEditorMessages.getBundleForConstructedKeys(), "ToggleMethodBoundaryLinesAction.", null, IAction.AS_CHECK_BOX); //$NON-NLS-1$
46
		JavaPluginImages.setToolImageDescriptors(this, "toggle_method_boundary.gif"); //$NON-NLS-1$
47
		PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.TOGGLE_METHOD_BOUNDARY_LINES_ACTION);
48
		update();
49
	}
50
51
	/*
52
	 * @see IAction#actionPerformed
53
	 */
54
	public void run() {
55
		fStore.setValue(PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES, isChecked());
56
	}
57
58
	/*
59
	 * @see TextEditorAction#update
60
	 */
61
	public void update() {
62
		ITextEditor editor= getTextEditor();
63
64
		boolean checked= false;
65
		if (editor instanceof JavaEditor)
66
			checked= ((JavaEditor)editor).isShowingMethodBoundaryLines();
67
68
		setChecked(checked);
69
		setEnabled(editor != null);
70
	}
71
72
	/*
73
	 * @see TextEditorAction#setEditor(ITextEditor)
74
	 */
75
	public void setEditor(ITextEditor editor) {
76
77
		super.setEditor(editor);
78
79
		if (editor != null) {
80
81
			if (fStore == null) {
82
				fStore= JavaPlugin.getDefault().getPreferenceStore();
83
				fStore.addPropertyChangeListener(this);
84
			}
85
86
		} else if (fStore != null) {
87
			fStore.removePropertyChangeListener(this);
88
			fStore= null;
89
		}
90
91
		update();
92
	}
93
94
	/*
95
	 * @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
96
	 */
97
	public void propertyChange(PropertyChangeEvent event) {
98
		if (event.getProperty().equals(PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES))
99
			setChecked(Boolean.valueOf(event.getNewValue().toString()).booleanValue());
100
	}
101
}
(-)ui/org/eclipse/jdt/internal/ui/preferences/JavaEditorAppearanceConfigurationBlock.java (+6 lines)
Lines 59-64 Link Here
59
			{PreferencesMessages.JavaEditorPreferencePage_backgroundForCompletionReplacement, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND, null },
59
			{PreferencesMessages.JavaEditorPreferencePage_backgroundForCompletionReplacement, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND, null },
60
			{PreferencesMessages.JavaEditorPreferencePage_foregroundForCompletionReplacement, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND, null },
60
			{PreferencesMessages.JavaEditorPreferencePage_foregroundForCompletionReplacement, PreferenceConstants.CODEASSIST_REPLACEMENT_FOREGROUND, null },
61
			{PreferencesMessages.JavaEditorPreferencePage_sourceHoverBackgroundColor, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT},
61
			{PreferencesMessages.JavaEditorPreferencePage_sourceHoverBackgroundColor, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR, PreferenceConstants.EDITOR_SOURCE_HOVER_BACKGROUND_COLOR_SYSTEM_DEFAULT},
62
			{ PreferencesMessages.JavaEditorPreferencePage_methodBoundaryLinesColor, PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR, null },
62
63
63
		};
64
		};
64
65
Lines 84-89 Link Here
84
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION));
85
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SUB_WORD_NAVIGATION));
85
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS));
86
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS));
86
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SHOW_SEGMENTS));
87
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_SHOW_SEGMENTS));
88
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES));
89
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.METHOD_BOUNDARY_LINES_COLOR));
87
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND));
90
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_PARAMETERS_BACKGROUND));
88
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND));
91
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_PARAMETERS_FOREGROUND));
89
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND));
92
		overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, PreferenceConstants.CODEASSIST_REPLACEMENT_BACKGROUND));
Lines 234-239 Link Here
234
		label= PreferencesMessages.JavaEditorPreferencePage_showJavaElementOnly;
237
		label= PreferencesMessages.JavaEditorPreferencePage_showJavaElementOnly;
235
		addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_SHOW_SEGMENTS, 0);
238
		addCheckBox(appearanceComposite, label, PreferenceConstants.EDITOR_SHOW_SEGMENTS, 0);
236
239
240
		label= PreferencesMessages.JavaEditorPreferencePage_ShowMethodBoundaryLines;
241
		addCheckBox(appearanceComposite, label, PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES, 0);
242
237
		Label l= new Label(appearanceComposite, SWT.LEFT );
243
		Label l= new Label(appearanceComposite, SWT.LEFT );
238
		gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
244
		gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
239
		gd.horizontalSpan= 2;
245
		gd.horizontalSpan= 2;
(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.java (+4 lines)
Lines 151-156 Link Here
151
	public static String JavaEditorPreferencePage_enable;
151
	public static String JavaEditorPreferencePage_enable;
152
	public static String JavaEditorPreferencePage_preview;
152
	public static String JavaEditorPreferencePage_preview;
153
	public static String JavaEditorPreferencePage_highlightMatchingBrackets;
153
	public static String JavaEditorPreferencePage_highlightMatchingBrackets;
154
155
	public static String JavaEditorPreferencePage_ShowMethodBoundaryLines;
154
	public static String JavaEditorPreferencePage_insertSingleProposalsAutomatically;
156
	public static String JavaEditorPreferencePage_insertSingleProposalsAutomatically;
155
	public static String JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext;
157
	public static String JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext;
156
	public static String JavaEditorPreferencePage_presentProposalsInAlphabeticalOrder;
158
	public static String JavaEditorPreferencePage_presentProposalsInAlphabeticalOrder;
Lines 178-183 Link Here
178
	public static String JavaEditorPreferencePage_empty_input;
180
	public static String JavaEditorPreferencePage_empty_input;
179
	public static String JavaEditorPreferencePage_invalid_input;
181
	public static String JavaEditorPreferencePage_invalid_input;
180
	public static String JavaEditorPreferencePage_matchingBracketsHighlightColor2;
182
	public static String JavaEditorPreferencePage_matchingBracketsHighlightColor2;
183
184
	public static String JavaEditorPreferencePage_methodBoundaryLinesColor;
181
	public static String JavaEditorPreferencePage_appearanceOptions;
185
	public static String JavaEditorPreferencePage_appearanceOptions;
182
	public static String JavaEditorPreferencePage_typing_tabTitle;
186
	public static String JavaEditorPreferencePage_typing_tabTitle;
183
	public static String JavaEditorPreferencePage_closeStrings;
187
	public static String JavaEditorPreferencePage_closeStrings;
(-)ui/org/eclipse/jdt/internal/ui/preferences/PreferencesMessages.properties (+2 lines)
Lines 131-136 Link Here
131
JavaEditorPreferencePage_enable=Enab&le
131
JavaEditorPreferencePage_enable=Enab&le
132
JavaEditorPreferencePage_preview=Previe&w:
132
JavaEditorPreferencePage_preview=Previe&w:
133
JavaEditorPreferencePage_highlightMatchingBrackets=Highlight &matching brackets
133
JavaEditorPreferencePage_highlightMatchingBrackets=Highlight &matching brackets
134
JavaEditorPreferencePage_ShowMethodBoundaryLines=Separator line &between types and method
134
JavaEditorPreferencePage_insertSingleProposalsAutomatically=Insert single &proposals automatically
135
JavaEditorPreferencePage_insertSingleProposalsAutomatically=Insert single &proposals automatically
135
JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext=Hide proposals not visible in the in&vocation context
136
JavaEditorPreferencePage_showOnlyProposalsVisibleInTheInvocationContext=Hide proposals not visible in the in&vocation context
136
JavaEditorPreferencePage_presentProposalsInAlphabeticalOrder=&Sort proposals
137
JavaEditorPreferencePage_presentProposalsInAlphabeticalOrder=&Sort proposals
Lines 160-165 Link Here
160
JavaEditorPreferencePage_empty_input=Empty input
161
JavaEditorPreferencePage_empty_input=Empty input
161
JavaEditorPreferencePage_invalid_input=''{0}'' is not a valid input.
162
JavaEditorPreferencePage_invalid_input=''{0}'' is not a valid input.
162
JavaEditorPreferencePage_matchingBracketsHighlightColor2=Matching brackets highlight
163
JavaEditorPreferencePage_matchingBracketsHighlightColor2=Matching brackets highlight
164
JavaEditorPreferencePage_methodBoundaryLinesColor= Separator line between types and method
163
JavaEditorPreferencePage_appearanceOptions=Appearance co&lor options:
165
JavaEditorPreferencePage_appearanceOptions=Appearance co&lor options:
164
166
165
JavaEditorPreferencePage_typing_tabTitle=T&yping
167
JavaEditorPreferencePage_typing_tabTitle=T&yping
(-)ui/org/eclipse/jdt/ui/PreferenceConstants.java (-1 / +23 lines)
Lines 2275-2285 Link Here
2275
	public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK= "browserLikeLinksKeyModifierMask"; //$NON-NLS-1$
2275
	public static final String EDITOR_BROWSER_LIKE_LINKS_KEY_MODIFIER_MASK= "browserLikeLinksKeyModifierMask"; //$NON-NLS-1$
2276
2276
2277
	/**
2277
	/**
2278
	 * A named preference that controls whether method boundary lines are shown in the editor.
2279
	 * <p>
2280
	 * Value is of type <code>Boolean</code>.
2281
	 * </p>
2282
	 * 
2283
	 * @since 3.7
2284
	 */
2285
	public static final String SHOW_METHOD_BOUNDARY_LINES= "showMethodBoundaryLines"; //$NON-NLS-1$
2286
2287
	/**
2288
	 * A named preference that holds the color used for method boundary lines.
2289
	 * <p>
2290
	 * Value is of type <code>String</code>. A RGB color value encoded as a string using class
2291
	 * <code>PreferenceConverter</code>
2292
	 * </p>
2293
	 * 
2294
	 * @since 3.7
2295
	 */
2296
	public static final String METHOD_BOUNDARY_LINES_COLOR= "methodBoundaryLinesColor"; //$NON-NLS-1$
2297
2298
	/**
2278
	 * A named preference that controls whether occurrences are marked in the editor.
2299
	 * A named preference that controls whether occurrences are marked in the editor.
2279
	 * <p>
2300
	 * <p>
2280
	 * Value is of type <code>Boolean</code>.
2301
	 * Value is of type <code>Boolean</code>.
2281
	 * </p>
2302
	 * </p>
2282
	 *
2303
	 * 
2283
	 * @since 3.0
2304
	 * @since 3.0
2284
	 */
2305
	 */
2285
	public static final String EDITOR_MARK_OCCURRENCES= "markOccurrences"; //$NON-NLS-1$
2306
	public static final String EDITOR_MARK_OCCURRENCES= "markOccurrences"; //$NON-NLS-1$
Lines 3707-3712 Link Here
3707
3728
3708
		// JavaEditorPreferencePage
3729
		// JavaEditorPreferencePage
3709
		store.setDefault(PreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
3730
		store.setDefault(PreferenceConstants.EDITOR_MATCHING_BRACKETS, true);
3731
		store.setDefault(PreferenceConstants.SHOW_METHOD_BOUNDARY_LINES, false);
3710
3732
3711
		store.setDefault(PreferenceConstants.EDITOR_CORRECTION_INDICATION, true);
3733
		store.setDefault(PreferenceConstants.EDITOR_CORRECTION_INDICATION, true);
3712
		store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true);
3734
		store.setDefault(PreferenceConstants.EDITOR_SYNC_OUTLINE_ON_CURSOR_MOVE, true);
(-)ui/org/eclipse/jdt/ui/actions/IJavaEditorActionDefinitionIds.java (-2 / +11 lines)
Lines 718-725 Link Here
718
	public static final String TOGGLE_MARK_OCCURRENCES= "org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences"; //$NON-NLS-1$
718
	public static final String TOGGLE_MARK_OCCURRENCES= "org.eclipse.jdt.ui.edit.text.java.toggleMarkOccurrences"; //$NON-NLS-1$
719
719
720
	/**
720
	/**
721
	 * Action definition id of toggle breadcrumb action
721
	 * Action definition id of toggle method boundary lines action (value:
722
	 * (value: <code>"org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"</code>).
722
	 * <code>"org.eclipse.jdt.ui.edit.text.java.toggleMethodBoundaryLines"</code>).
723
	 * 
724
	 * @since 3.7
725
	 */
726
	public static final String TOGGLE_METHOD_BOUNDARY_LINES= "org.eclipse.jdt.ui.edit.text.java.toggleMethodBoundaryLines"; //$NON-NLS-1$
727
728
	/**
729
	 * Action definition id of toggle breadcrumb action (value:
730
	 * <code>"org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"</code>).
731
	 * 
723
	 * @since 3.4
732
	 * @since 3.4
724
	 */
733
	 */
725
	public static final String TOGGLE_BREADCRUMB= "org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"; //$NON-NLS-1$
734
	public static final String TOGGLE_BREADCRUMB= "org.eclipse.jdt.ui.edit.text.java.toggleBreadcrumb"; //$NON-NLS-1$
(-)reference/ref-68.htm (-2 / +2 lines)
Lines 175-182 Link Here
175
<tr>
175
<tr>
176
<td align="center" valign="middle"><img src="../images/segment_edit.png" alt="Show source of selected element only image"></td>
176
<td align="center" valign="middle"><img src="../images/segment_edit.png" alt="Show source of selected element only image"></td>
177
<td>Show source of selected element only</td>
177
<td>Show source of selected element only</td>
178
<td>&nbsp;</td>
178
<td align="center" valign="middle"><img src="../images/toggle_method_boundary.gif" alt="Toggle Method Boundary Lines"></td>
179
<td>&nbsp;</td>
179
<td>Toggle Method Boundary Lines</td>
180
</tr>
180
</tr>
181
</tbody>
181
</tbody>
182
</table>
182
</table>

Return to bug 13672