Fixes links on Log pages

This commit is contained in:
emmanue1 2015-03-29 21:54:54 +02:00
parent a2bf0c6387
commit 6683252152
4 changed files with 53 additions and 34 deletions

View File

@ -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))
}
}

View File

@ -81,6 +81,7 @@ abstract class SourcePage extends HyperlinkPage {
return max
}
@CompileStatic
int getTextAreaLineNumber(int sourceLineNumber) {
int textAreaLineNumber = 1
int greatestLowerSourceLineNumber = 0
@ -91,7 +92,7 @@ abstract class SourcePage extends HyperlinkPage {
if (sln <= sourceLineNumber) {
if (greatestLowerSourceLineNumber < sln) {
greatestLowerSourceLineNumber = sln
textAreaLineNumber = lineNumberMap[i]
textAreaLineNumber = i
}
}
}

View File

@ -119,44 +119,59 @@ 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))
}
Rectangle visible = textArea.visibleRect
visible.@x = r.@x - (visible.@width - r.@width) / 2 as int
visible.@y = r.@y - (visible.@height - r.@height) / 2 as int
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
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
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) {
}
}
}
protected void setCaretPositionAndCenter(int start, int end, Rectangle r) {
if (end != start) {
r = r.union(textArea.modelToView(end))
}
Rectangle visible = textArea.visibleRect
visible.@x = r.@x - (visible.@width - r.@width) / 2 as int
visible.@y = r.@y - (visible.@height - r.@height) / 2 as int
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
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 --- //
void copy() {
if (textArea.selectionStart == textArea.selectionEnd) {

View File

@ -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