++
сравнение
This commit is contained in:
@@ -3,7 +3,7 @@ import Common.Utils.Vector_;
|
||||
|
||||
import java.util.Vector;
|
||||
public class Constants {
|
||||
public static final int version = 1226;
|
||||
public static final int version = 1227;
|
||||
public static final int planner_version = 24;
|
||||
public static final int testingMaxKernels = 64;
|
||||
//--
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Passes.Pass;
|
||||
import Common.Utils.Vector_;
|
||||
import com.github.difflib.text.DiffRow;
|
||||
import com.github.difflib.text.DiffRowGenerator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
public class TestPass extends Pass {
|
||||
@@ -52,5 +55,23 @@ public class TestPass extends Pass {
|
||||
System.out.println("Square of " + num + " is " + square);
|
||||
})
|
||||
).join();
|
||||
System.out.println("DONE");
|
||||
//----
|
||||
|
||||
DiffRowGenerator generator = DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.inlineDiffByWord(true)
|
||||
.oldTag(f -> "~")
|
||||
.newTag(f -> "**")
|
||||
.build();
|
||||
List<DiffRow> rows = generator.generateDiffRows(
|
||||
Arrays.asList("This is a test senctence.", "This is the second line.", "And here is the finish."),
|
||||
Arrays.asList("This is a test for diffutils.", "This is the second line."));
|
||||
|
||||
System.out.println("|original|new|");
|
||||
System.out.println("|--------|---|");
|
||||
for (DiffRow row : rows) {
|
||||
System.out.println("|" + row.getOldLine() + "|" + row.getNewLine() + "|");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MainMenuBar extends VisualiserMenuBar {
|
||||
setPreferredSize(new Dimension(0, 30));
|
||||
//--
|
||||
|
||||
/*
|
||||
|
||||
add(new MenuBarButton() {
|
||||
{
|
||||
setIcon("/Common/icons/Apply.png");
|
||||
@@ -77,7 +77,6 @@ public class MainMenuBar extends VisualiserMenuBar {
|
||||
});
|
||||
}
|
||||
});
|
||||
*/
|
||||
//--
|
||||
add(new JSeparator());
|
||||
add(MachineButton = new MenuBarButton() {
|
||||
|
||||
@@ -5,10 +5,10 @@ public class VersionsComparisonMenu extends PropertiesSubmenu {
|
||||
public VersionsComparisonMenu() {
|
||||
super("Сравнение версий", null,
|
||||
Global.normalProperties,
|
||||
"RegisterOn",
|
||||
"SpacesOn",
|
||||
"EmptyLinesOn",
|
||||
"FortranWrapsOn",
|
||||
// "RegisterOn",
|
||||
// "SpacesOn",
|
||||
// "EmptyLinesOn",
|
||||
// "FortranWrapsOn",
|
||||
"ExtensionsOn",
|
||||
"ComparsionDiffMergeOn"
|
||||
);
|
||||
|
||||
@@ -51,30 +51,6 @@
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="75549" class="javax.swing.JButton" binding="bPrevious">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<borderPainted value="false"/>
|
||||
<icon value="Common/icons/Previous.png"/>
|
||||
<maximumSize width="30" height="30"/>
|
||||
<minimumSize width="30" height="30"/>
|
||||
<preferredSize width="30" height="30"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Перейти к предыдущему различию "/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f8e56" class="javax.swing.JButton" binding="bNext">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<borderPainted value="false"/>
|
||||
<icon value="Common/icons/Next.png"/>
|
||||
<maximumSize width="30" height="30"/>
|
||||
<minimumSize width="30" height="30"/>
|
||||
<preferredSize width="30" height="30"/>
|
||||
<text value=""/>
|
||||
<toolTipText value="Перейти к следующему различию"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="42c3c" class="javax.swing.JButton" binding="bCompare">
|
||||
<constraints/>
|
||||
<properties>
|
||||
|
||||
@@ -9,20 +9,24 @@ import Common.Visual.Menus.VisualiserMenuBar;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.ProjectData.Files.UI.Editor.SPFEditor;
|
||||
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 java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
public abstract class ComparisonForm<T> {
|
||||
public Class<T> t; //класс объектов.
|
||||
//-->>
|
||||
public Vector<String> lines = new Vector<>(); //строки с учетом/неучетом пробелов. для сравнения
|
||||
public Vector<String> visible_lines = new Vector<>(); //строки с нетронутыми пробелами. для отображения
|
||||
//подсветка.
|
||||
public LinkedHashMap<Integer, Pair<Integer, Boolean>> colors = new LinkedHashMap<>();
|
||||
public RSyntaxTextAreaHighlighter slave_highlighter = null; //погонщик рабов
|
||||
protected JToolBar tools;
|
||||
protected JLabel lObjectName;
|
||||
@@ -39,8 +43,6 @@ public abstract class ComparisonForm<T> {
|
||||
//-->>
|
||||
private JPanel content;
|
||||
private JPanel editorPanel;
|
||||
private JButton bPrevious;
|
||||
private JButton bNext;
|
||||
private JButton bCompare;
|
||||
private RTextScrollPane Scroll;
|
||||
//-----
|
||||
@@ -59,8 +61,6 @@ public abstract class ComparisonForm<T> {
|
||||
t = t_in;
|
||||
this_ = this;
|
||||
slave = slave_in;
|
||||
bPrevious.setVisible(isMaster());
|
||||
bNext.setVisible(isMaster());
|
||||
Scroll.setLineNumbersEnabled(true);
|
||||
bApplyObject.addActionListener(e -> {
|
||||
ApplyObject();
|
||||
@@ -85,24 +85,6 @@ public abstract class ComparisonForm<T> {
|
||||
});
|
||||
//</editor-fold>
|
||||
slave.master = this;
|
||||
bPrevious.addActionListener(e -> {
|
||||
if (current_diff_line != CommonConstants.Nan) {
|
||||
if (current_diff_line > 0)
|
||||
current_diff_line--;
|
||||
else
|
||||
current_diff_line = colors.size() - 1;
|
||||
ShowCurrentDiff();
|
||||
}
|
||||
});
|
||||
bNext.addActionListener(e -> {
|
||||
if (current_diff_line != CommonConstants.Nan) {
|
||||
if (current_diff_line < colors.size() - 1)
|
||||
current_diff_line++;
|
||||
else
|
||||
current_diff_line = 0;
|
||||
ShowCurrentDiff();
|
||||
}
|
||||
});
|
||||
bCompare.addActionListener(e -> {
|
||||
DoComparePass(isReady() && slave.isReady());
|
||||
});
|
||||
@@ -146,7 +128,7 @@ public abstract class ComparisonForm<T> {
|
||||
showObject();
|
||||
}
|
||||
private void ShowCurrentDiff() {
|
||||
Body.gotoLine_(colors.get(current_diff_line).getKey());
|
||||
// Body.gotoLine_(colors.get(current_diff_line).getKey());
|
||||
}
|
||||
private void getLines() {
|
||||
lines.clear();
|
||||
@@ -164,7 +146,6 @@ public abstract class ComparisonForm<T> {
|
||||
protected void Compare() throws Exception {
|
||||
events_on = false;
|
||||
current_diff_line = CommonConstants.Nan;
|
||||
colors.clear();
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
Body.setText("");
|
||||
slave.Body.setText("");
|
||||
@@ -175,62 +156,49 @@ public abstract class ComparisonForm<T> {
|
||||
Vector<String> t1 = new Vector<>();
|
||||
Vector<String> t2 = new Vector<>();
|
||||
//------
|
||||
int old_j = 0;
|
||||
int j = 0;
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
if (Utils.Contains(slave.lines, lines.get(i), old_j)) {
|
||||
for (int k = old_j; k < slave.lines.size(); ++k) {
|
||||
j = k;
|
||||
if (Utils.CompareLines(lines.get(i), slave.lines.get(k))) {
|
||||
j++;
|
||||
t1.add(visible_lines.get(i));
|
||||
t2.add(slave.visible_lines.get(k));
|
||||
break;
|
||||
} else {
|
||||
t1.add("+");
|
||||
t2.add("+ " + slave.visible_lines.get(k));
|
||||
colors.put(d, new Pair(t2.size() - 1, true));
|
||||
++d;
|
||||
}
|
||||
}
|
||||
old_j = j;
|
||||
} else {
|
||||
//строки гарантированно нет.
|
||||
t1.add("- " + visible_lines.get(i));
|
||||
t2.add("- " + visible_lines.get(i));
|
||||
colors.put(d, new Pair(t2.size() - 1, false));
|
||||
++d;
|
||||
}
|
||||
DiffRowGenerator generator = DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.inlineDiffByWord(true)
|
||||
.ignoreWhiteSpaces(true)
|
||||
.oldTag(f -> "~")
|
||||
.newTag(f -> "**")
|
||||
.build();
|
||||
List<DiffRow> rows = generator.generateDiffRows(
|
||||
visible_lines,
|
||||
slave.visible_lines);
|
||||
|
||||
for (DiffRow row : rows) {
|
||||
t1.add(row.getOldLine());
|
||||
t2.add(row.getNewLine());
|
||||
}
|
||||
//теперь граничное условие. если первый файл кончился а второй нет, его остаток это добавление.
|
||||
for (int i = j; i < slave.lines.size(); ++i) {
|
||||
t1.add("+");
|
||||
t2.add("+ " + slave.visible_lines.get(i));
|
||||
colors.put(d, new Pair(t2.size() - 1, true));
|
||||
++d;
|
||||
}
|
||||
///----------------
|
||||
Body.setText(String.join("\n", t1));
|
||||
slave.Body.setText(String.join("\n", t2));
|
||||
Body.setCaretPosition(0);
|
||||
slave.Body.setCaretPosition(0);
|
||||
//теперь покрас.
|
||||
for (Integer diff_num : colors.keySet()) {
|
||||
slave_highlighter.addHighlight(
|
||||
slave.Body.getLineStartOffset(colors.get(diff_num).getKey()),
|
||||
slave.Body.getLineEndOffset(colors.get(diff_num).getKey()),
|
||||
colors.get(diff_num).getValue() ?
|
||||
SPFEditor.GreenTextPainter :
|
||||
SPFEditor.RedTextPainter
|
||||
//--
|
||||
Pattern master_pattern = Pattern.compile("~.*~");
|
||||
Matcher master_matcher = master_pattern.matcher(Body.getText());
|
||||
while (master_matcher.find()) {
|
||||
Body.getHighlighter().addHighlight(
|
||||
master_matcher.start(),
|
||||
master_matcher.end(),
|
||||
SPFEditor.RedTextPainter
|
||||
);
|
||||
}
|
||||
Pattern slave_pattern = Pattern.compile("\\*.*\\*");
|
||||
Matcher slave_matcher = slave_pattern.matcher(slave.Body.getText());
|
||||
while (slave_matcher.find()) {
|
||||
slave_highlighter.addHighlight(
|
||||
slave_matcher.start(),
|
||||
slave_matcher.end(),
|
||||
SPFEditor.GreenTextPainter
|
||||
);
|
||||
}
|
||||
if (colors.size() > 0) current_diff_line = 0;
|
||||
events_on = true;
|
||||
}
|
||||
public void Show() throws Exception {
|
||||
events_on = false;
|
||||
current_diff_line = CommonConstants.Nan;
|
||||
colors.clear();
|
||||
//----------------------------------------------------------------------------------------------
|
||||
Body.setText("");
|
||||
slave.Body.setText("");
|
||||
|
||||
Reference in New Issue
Block a user