доделано сравнение
This commit is contained in:
2025-03-26 02:43:58 +03:00
parent 2a30a42e77
commit fef75270a7
5 changed files with 63 additions and 10 deletions

View File

@@ -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<T> {
@@ -40,10 +42,12 @@ public abstract class ComparisonForm<T> {
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<T> {
// protected Object ownScrollModel = null;
protected Vector<Pair<Integer, Integer>> 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> t_in, ComparisonForm<T> slave_in) {
//-
Body = new BaseEditor();
@@ -95,6 +108,27 @@ public abstract class ComparisonForm<T> {
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<T> {
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<T> {
//предполагаем что оба объекта есть и мы можем получить с них текст.
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<T> {
}
}
}
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<T> {
}
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("");