Skip to content

Commit

Permalink
Fixes links on Log pages
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed Mar 29, 2015
1 parent a2bf0c6 commit 6683252
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ class ClassFilePage
void goToLineNumber(int lineNumber) {
int textAreaLineNumber = getTextAreaLineNumber(lineNumber)
if (textAreaLineNumber > 0) {
textArea.caretPosition = textArea.getLineStartOffset(textAreaLineNumber-1)
int start = textArea.getLineStartOffset(textAreaLineNumber-1)
int end = textArea.getLineEndOffset(textAreaLineNumber-1)
setCaretPositionAndCenter(new DocumentRange(start, end))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ abstract class SourcePage extends HyperlinkPage {
return max
}

@CompileStatic
int getTextAreaLineNumber(int sourceLineNumber) {
int textAreaLineNumber = 1
int greatestLowerSourceLineNumber = 0
Expand All @@ -91,7 +92,7 @@ abstract class SourcePage extends HyperlinkPage {
if (sln <= sourceLineNumber) {
if (greatestLowerSourceLineNumber < sln) {
greatestLowerSourceLineNumber = sln
textAreaLineNumber = lineNumberMap[i]
textAreaLineNumber = i
}
}
}
Expand Down
75 changes: 45 additions & 30 deletions services/src/main/groovy/jd/gui/view/component/TextPage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -119,42 +119,57 @@ class TextPage extends JPanel implements ContentCopyable, ContentSelectable, Lin
try {
Rectangle r = textArea.modelToView(start)

if (r) { // Visible
if (end != start) {
r = r.union(textArea.modelToView(end))
}
if (r) {
// Visible
setCaretPositionAndCenter(start, end, r)
} else {
// Not visible yet
SwingUtilities.invokeLater(new Runnable() {
void run() {
r = textArea.modelToView(start)
if (r) {
setCaretPositionAndCenter(start, end, r)
}
}
})
}
} catch (BadLocationException ignore) {
}
}
}

Rectangle visible = textArea.visibleRect
protected void setCaretPositionAndCenter(int start, int end, Rectangle r) {
if (end != start) {
r = r.union(textArea.modelToView(end))
}

visible.@x = r.@x - (visible.@width - r.@width) / 2 as int
visible.@y = r.@y - (visible.@height - r.@height) / 2 as int
Rectangle visible = textArea.visibleRect

Rectangle bounds = textArea.bounds
Insets i = textArea.insets
bounds.@x = i.left
bounds.@y = i.top
bounds.@width -= i.left + i.right
bounds.@height -= i.top + i.bottom
visible.@x = r.@x - (visible.@width - r.@width) / 2 as int
visible.@y = r.@y - (visible.@height - r.@height) / 2 as int

if (visible.@x < bounds.@x) {
visible.@x = bounds.@x
}
if (visible.@x + visible.@width > bounds.@x + bounds.@width) {
visible.@x = bounds.@x + bounds.@width - visible.@width
}
if (visible.@y < bounds.@y) {
visible.@y = bounds.@y
}
if (visible.@y + visible.@height > bounds.@y + bounds.@height) {
visible.@y = bounds.@y + bounds.@height - visible.@height
}
Rectangle bounds = textArea.bounds
Insets i = textArea.insets
bounds.@x = i.left
bounds.@y = i.top
bounds.@width -= i.left + i.right
bounds.@height -= i.top + i.bottom

textArea.scrollRectToVisible(visible)
textArea.caretPosition = start
}
} catch (BadLocationException ignore) {
}
if (visible.@x < bounds.@x) {
visible.@x = bounds.@x
}
if (visible.@x + visible.@width > bounds.@x + bounds.@width) {
visible.@x = bounds.@x + bounds.@width - visible.@width
}
if (visible.@y < bounds.@y) {
visible.@y = bounds.@y
}
if (visible.@y + visible.@height > bounds.@y + bounds.@height) {
visible.@y = bounds.@y + bounds.@height - visible.@height
}

textArea.scrollRectToVisible(visible)
textArea.caretPosition = start
}

// --- ContentCopyable --- //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ jd.gui.service.indexer.DirectoryIndexerProvider
jd.gui.service.indexer.ClassFileIndexerProvider
jd.gui.service.indexer.MetainfServiceFileIndexerProvider
jd.gui.service.indexer.TextFileIndexerProvider
jd.gui.service.indexer.XmlFileIndexerProvider
jd.gui.service.indexer.ZipFileIndexerProvider

0 comments on commit 6683252

Please sign in to comment.