From 6683252152c5109b5cac7f8521c7cc4be2363811 Mon Sep 17 00:00:00 2001 From: emmanue1 Date: Sun, 29 Mar 2015 21:54:54 +0200 Subject: [PATCH] Fixes links on Log pages --- .../gui/view/component/ClassFilePage.groovy | 4 +- .../jd/gui/view/component/SourcePage.groovy | 3 +- .../jd/gui/view/component/TextPage.groovy | 75 +++++++++++-------- .../META-INF/services/jd.gui.spi.Indexer | 1 + 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/services/src/main/groovy/jd/gui/view/component/ClassFilePage.groovy b/services/src/main/groovy/jd/gui/view/component/ClassFilePage.groovy index 1117cc19..88e5aa5f 100644 --- a/services/src/main/groovy/jd/gui/view/component/ClassFilePage.groovy +++ b/services/src/main/groovy/jd/gui/view/component/ClassFilePage.groovy @@ -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)) } } diff --git a/services/src/main/groovy/jd/gui/view/component/SourcePage.groovy b/services/src/main/groovy/jd/gui/view/component/SourcePage.groovy index b4f21d16..ca2cd3a5 100644 --- a/services/src/main/groovy/jd/gui/view/component/SourcePage.groovy +++ b/services/src/main/groovy/jd/gui/view/component/SourcePage.groovy @@ -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 } } } diff --git a/services/src/main/groovy/jd/gui/view/component/TextPage.groovy b/services/src/main/groovy/jd/gui/view/component/TextPage.groovy index 24482b10..dbc78562 100644 --- a/services/src/main/groovy/jd/gui/view/component/TextPage.groovy +++ b/services/src/main/groovy/jd/gui/view/component/TextPage.groovy @@ -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 --- // diff --git a/services/src/main/resources/META-INF/services/jd.gui.spi.Indexer b/services/src/main/resources/META-INF/services/jd.gui.spi.Indexer index c8d5c7c9..419f42de 100644 --- a/services/src/main/resources/META-INF/services/jd.gui.spi.Indexer +++ b/services/src/main/resources/META-INF/services/jd.gui.spi.Indexer @@ -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