diff --git a/.idea/workspace.xml b/.idea/workspace.xml index da6aabd2..91e1bcea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -8,6 +8,9 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/_VisualDVM/Visual/Windows/ComparisonForm.java b/src/_VisualDVM/Visual/Windows/ComparisonForm.java index 6fbc93e5..e66217d4 100644 --- a/src/_VisualDVM/Visual/Windows/ComparisonForm.java +++ b/src/_VisualDVM/Visual/Windows/ComparisonForm.java @@ -12,11 +12,13 @@ import _VisualDVM.Utils; import com.github.difflib.text.DiffRow; import com.github.difflib.text.DiffRowGenerator; import javafx.util.Pair; -import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaHighlighter; import org.fife.ui.rtextarea.RTextScrollPane; import javax.swing.*; +import javax.swing.text.BadLocationException; import javax.swing.text.Highlighter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.List; import java.util.Vector; public abstract class ComparisonForm { @@ -40,10 +42,12 @@ public abstract class ComparisonForm { private JPanel content; private JPanel editorPanel; private JButton bCompare; + private JButton bPrevious; + private JButton bNext; private RTextScrollPane Scroll; //----- private boolean events_on = false;//относится только к мастеру, отвечает за скроллы. - private int current_diff_line = -1; + private int current_diff_num = -1; final String separator = "\u200B"; final char cseparator = '\u200B'; //невидимый пробел https://translated.turbopages.org/proxy_u/en-ru.ru.898e1daf-67e318c0-3fccff8a-74722d776562/https/stackoverflow.com/questions/17978720/invisible-characters-ascii @@ -51,6 +55,15 @@ public abstract class ComparisonForm { // protected Object ownScrollModel = null; protected Vector> diffs = new Vector<>(); //---<< + private void ShowCurrentDiff() { + try { + int diff_line = Body.getLineOfOffset(diffs.get(current_diff_num).getKey()); + Body.gotoLine_(diff_line); + } + catch (Exception ex){ + ex.printStackTrace(); + } + } public ComparisonForm(Class t_in, ComparisonForm slave_in) { //- Body = new BaseEditor(); @@ -95,6 +108,27 @@ public abstract class ComparisonForm { bClose.addActionListener(e -> { onClose(); }); + bPrevious.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (current_diff_num != CommonConstants.Nan) { + if (current_diff_num > 0) + current_diff_num--; + else + current_diff_num = diffs.size() - 1; + ShowCurrentDiff(); + } + } + }); + bNext.addActionListener(e -> { + if (current_diff_num != CommonConstants.Nan) { + if (current_diff_num < diffs.size() - 1) + current_diff_num++; + else + current_diff_num = 0; + ShowCurrentDiff(); + } + }); } public JPanel getContent() { return content; @@ -126,9 +160,6 @@ public abstract class ComparisonForm { applyObject(); showObject(); } - private void ShowCurrentDiff() { - // Body.gotoLine_(colors.get(current_diff_line).getKey()); - } private void getLines() { lines.clear(); visible_lines.clear(); @@ -144,13 +175,13 @@ public abstract class ComparisonForm { //предполагаем что оба объекта есть и мы можем получить с них текст. protected void Compare() throws Exception { events_on = false; - current_diff_line = CommonConstants.Nan; + current_diff_num = CommonConstants.Nan; + slave.current_diff_num =CommonConstants.Nan; //----------------------------------------------------------------------------------------------- Body.setText(""); slave.Body.setText(""); Body.getHighlighter().removeAllHighlights(); slave.Body.getHighlighter().removeAllHighlights(); - int d = 0; getLines(); slave.getLines(); //-------------------------------------------------------------------- @@ -217,6 +248,8 @@ public abstract class ComparisonForm { } } } + if (!diffs.isEmpty()) + current_diff_num=0; } public void colorDiffs() throws Exception{ Highlighter.HighlightPainter painter = isMaster()? SPFEditor.RedTextPainter: SPFEditor.GreenTextPainter; @@ -226,7 +259,8 @@ public abstract class ComparisonForm { } public void Show() throws Exception { events_on = false; - current_diff_line = CommonConstants.Nan; + current_diff_num = CommonConstants.Nan; + slave.current_diff_num =CommonConstants.Nan; //---------------------------------------------------------------------------------------------- Body.setText(""); slave.Body.setText("");