/plugins/JDiffPlugin/tags/jdiffplugin-1_7_0/jdiff/DiffGlobalVirtualOverview.java

# · Java · 215 lines · 24 code · 13 blank · 178 comment · 0 complexity · 98d90a9eb2b6bda698448a7a8a7d3c5c MD5 · raw file

  1. /*
  2. * DiffGlobalVirtualOverview.java
  3. * Copyright (c) 2000, 2001, 2002 Andre Kaplan
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package jdiff;
  20. import java.awt.Color;
  21. import java.awt.Graphics;
  22. import java.awt.Rectangle;
  23. import jdiff.util.Diff;
  24. import org.gjt.sp.jedit.textarea.DisplayManager;
  25. import org.gjt.sp.jedit.textarea.JEditTextArea;
  26. import org.gjt.sp.util.Log;
  27. public class DiffGlobalVirtualOverview extends DiffOverview
  28. {
  29. public DiffGlobalVirtualOverview(
  30. Diff.change edits,
  31. int lineCount0,
  32. int lineCount1,
  33. JEditTextArea textArea0,
  34. JEditTextArea textArea1
  35. ) {
  36. super(edits, lineCount0, lineCount1, textArea0, textArea1);
  37. }
  38. public void paint(Graphics gfx) {
  39. /*DisplayManager foldVisibilityManager0 = this.textArea0.getDisplayManager();
  40. DisplayManager foldVisibilityManager1 = this.textArea1.getDisplayManager();
  41. int virtualLineCount0 = foldVisibilityManager0.getScrollLineCount();
  42. int virtualLineCount1 = foldVisibilityManager1.getScrollLineCount();
  43. int lineCount0 = this.textArea0.getLineCount();
  44. int lineCount1 = this.textArea1.getLineCount();
  45. Rectangle size = getBounds();
  46. gfx.setColor(getBackground());
  47. gfx.fillRect(0, 0, size.width, size.height);
  48. Rectangle inner = new Rectangle(4, 4, size.width - 8, size.height - 8);
  49. int lines = Math.max(virtualLineCount0, virtualLineCount1);
  50. double pxlPerLine = ((double) inner.height) / lines;
  51. Rectangle left = new Rectangle(
  52. inner.x,
  53. inner.y,
  54. inner.width / 3,
  55. Math.max(1, (int) Math.round(pxlPerLine * virtualLineCount0))
  56. );
  57. Rectangle right = new Rectangle(
  58. inner.x + (inner.width - left.width),
  59. inner.y,
  60. left.width,
  61. Math.max(1, (int) Math.round(pxlPerLine * virtualLineCount1))
  62. );
  63. Rectangle cursor = new Rectangle(
  64. inner.x + inner.width / 2 - 1, inner.y, 2, 0
  65. );
  66. Color leftColor = JDiffPlugin.overviewInvalidColor;
  67. Color rightColor = JDiffPlugin.overviewInvalidColor;
  68. gfx.setColor(Color.black);
  69. gfx.drawRect(left.x - 1, left.y - 1, left.width + 1, left.height + 1);
  70. gfx.drawRect(right.x - 1, right.y - 1, right.width + 1, right.height + 1);
  71. gfx.setColor(Color.white);
  72. gfx.fillRect(left.x, left.y, left.width, left.height);
  73. gfx.fillRect(right.x, right.y, right.width, right.height);
  74. Diff.change hunk = this.edits;
  75. int virtualLeftHeight = 0;
  76. int virtualRightHeight = 0;
  77. int virtualLeftOffset = 0;
  78. int virtualRightOffset = 0;
  79. for (; hunk != null; hunk = hunk.link) {
  80. // Log.log(Log.DEBUG, this, "hunk.line0: " + hunk.line0);
  81. // Log.log(Log.DEBUG, this, "hunk.deleted: " + hunk.deleted);
  82. // Log.log(Log.DEBUG, this, "lineCount0: " + lineCount0);
  83. // Log.log(Log.DEBUG, this, "hunk.line1: " + hunk.line1);
  84. // Log.log(Log.DEBUG, this, "hunk.inserted: " + hunk.inserted);
  85. // Log.log(Log.DEBUG, this, "lineCount1: " + lineCount1);
  86. if (hunk.inserted == 0 && hunk.deleted != 0) { // DELETE
  87. leftColor = JDiffPlugin.overviewDeletedColor;
  88. rightColor = JDiffPlugin.overviewInvalidColor;
  89. } else if (hunk.inserted != 0 && hunk.deleted == 0) { // INSERT
  90. leftColor = JDiffPlugin.overviewInvalidColor;
  91. rightColor = JDiffPlugin.overviewInsertedColor;
  92. } else { // CHANGE
  93. leftColor = JDiffPlugin.overviewChangedColor;
  94. rightColor = JDiffPlugin.overviewChangedColor;
  95. }
  96. virtualLeftHeight = 0;
  97. if (hunk.line0 >= lineCount0) {
  98. virtualLeftOffset = foldVisibilityManager0.getScrollLineCount();
  99. } else {
  100. virtualLeftOffset = foldVisibilityManager0.physicalToVirtual(hunk.line0);
  101. if (hunk.deleted != 0) {
  102. virtualLeftHeight = 1 + (
  103. foldVisibilityManager0.physicalToVirtual(hunk.line0 + hunk.deleted - 1)
  104. - virtualLeftOffset
  105. );
  106. }
  107. }
  108. virtualRightHeight = 0;
  109. if (hunk.line1 >= lineCount1) {
  110. virtualRightOffset = foldVisibilityManager1.getVirtualLineCount();
  111. } else {
  112. virtualRightOffset = foldVisibilityManager1.physicalToVirtual(hunk.line1);
  113. if (hunk.inserted != 0) {
  114. virtualRightHeight = 1 + (
  115. foldVisibilityManager1.physicalToVirtual(hunk.line1 + hunk.inserted - 1)
  116. - virtualRightOffset
  117. );
  118. }
  119. }
  120. left.y = inner.y + (int) Math.round(virtualLeftOffset * pxlPerLine);
  121. right.y = inner.y + (int) Math.round(virtualRightOffset * pxlPerLine);
  122. left.height = Math.max(1, (int) Math.round(virtualLeftHeight * pxlPerLine));
  123. right.height = Math.max(1, (int) Math.round(virtualRightHeight * pxlPerLine));
  124. gfx.setColor(leftColor);
  125. gfx.fillRect(left.x, left.y, left.width, left.height);
  126. gfx.setColor(rightColor);
  127. gfx.fillRect(right.x, right.y, right.width, right.height);
  128. gfx.setColor(Color.black);
  129. gfx.drawLine(left.x + left.width + 1, left.y, right.x - 1, right.y);
  130. }
  131. // Display the textArea cursor
  132. this.paintCursor(gfx);*/
  133. }
  134. public void paintCursor(Graphics gfx) {
  135. /*int virtualLineCount0 = this.textArea0.getVirtualLineCount();
  136. int virtualLineCount1 = this.textArea1.getVirtualLineCount();
  137. Rectangle size = getBounds();
  138. Rectangle inner = new Rectangle(4, 4, size.width - 8, size.height - 8);
  139. int lines = Math.max(virtualLineCount0, virtualLineCount1);
  140. double pxlPerLine = ((double) inner.height) / lines;
  141. int screenFirstLine0 = this.textArea0.getPhysicalLineOfScreenLine(0);
  142. int screenLastLine0 = -1;
  143. for (int i = this.textArea0.getVisibleLines() - 1; i >= 0; i--) {
  144. screenLastLine0 = this.textArea0.getPhysicalLineOfScreenLine(i);
  145. if (screenLastLine0 != -1) { break; }
  146. }
  147. int screenFirstLine1 = this.textArea1.getPhysicalLineOfScreenLine(0);
  148. int screenLastLine1 = -1;
  149. for (int i = this.textArea1.getVisibleLines() - 1; i >= 0; i--) {
  150. screenLastLine1 = this.textArea1.getPhysicalLineOfScreenLine(i);
  151. if (screenLastLine1 != -1) { break; }
  152. }
  153. int virtualFirstLine0 = this.textArea0.physicalToVirtual(screenFirstLine0);
  154. int virtualLastLine0 = this.textArea0.physicalToVirtual(screenLastLine0);
  155. Rectangle leftCursor = new Rectangle(
  156. inner.x, inner.y + ((int) Math.round(pxlPerLine * virtualFirstLine0)),
  157. inner.width / 3,
  158. Math.max(1, (int) Math.round(pxlPerLine * Math.min(virtualLineCount0, virtualLastLine0 - virtualFirstLine0 + 1)))
  159. );
  160. int virtualFirstLine1 = this.textArea1.physicalToVirtual(screenFirstLine1);
  161. int virtualLastLine1 = this.textArea1.physicalToVirtual(screenLastLine1);
  162. Rectangle rightCursor = new Rectangle(
  163. inner.x + (inner.width - leftCursor.width),
  164. inner.y + ((int) Math.round(pxlPerLine * virtualFirstLine1)),
  165. leftCursor.width,
  166. Math.max(1, (int) Math.round(pxlPerLine * Math.min(virtualLineCount1, virtualLastLine1 - virtualFirstLine1 + 1)))
  167. );
  168. gfx.setColor(JDiffPlugin.leftCursorColor);
  169. gfx.drawRect(leftCursor.x, leftCursor.y, leftCursor.width - 1, leftCursor.height - 1);
  170. gfx.setColor(JDiffPlugin.rightCursorColor);
  171. gfx.drawRect(rightCursor.x, rightCursor.y, rightCursor.width - 1, rightCursor.height - 1);*/
  172. }
  173. }