утренние изменения
удаление эталона и роль студента
This commit is contained in:
@@ -15,13 +15,14 @@ import javafx.util.Pair;
|
||||
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> {
|
||||
final String separator = "\u200B";
|
||||
final char cseparator = '\u200B';
|
||||
public Class<T> t; //класс объектов.
|
||||
//-->>
|
||||
public Vector<String> lines = new Vector<>(); //строки с учетом/неучетом пробелов. для сравнения
|
||||
@@ -34,6 +35,10 @@ public abstract class ComparisonForm<T> {
|
||||
protected T object = null;
|
||||
//-->>
|
||||
protected BaseEditor Body;
|
||||
//невидимый пробел https://translated.turbopages.org/proxy_u/en-ru.ru.898e1daf-67e318c0-3fccff8a-74722d776562/https/stackoverflow.com/questions/17978720/invisible-characters-ascii
|
||||
//--->>
|
||||
// protected Object ownScrollModel = null;
|
||||
protected Vector<Pair<Integer, Integer>> diffs = new Vector<>();
|
||||
//-->>
|
||||
ComparisonForm<T> this_ = null; //?
|
||||
ComparisonForm<T> slave = null;
|
||||
@@ -48,22 +53,6 @@ public abstract class ComparisonForm<T> {
|
||||
//-----
|
||||
private boolean events_on = false;//относится только к мастеру, отвечает за скроллы.
|
||||
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
|
||||
//--->>
|
||||
// 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();
|
||||
@@ -130,6 +119,15 @@ public abstract class ComparisonForm<T> {
|
||||
}
|
||||
});
|
||||
}
|
||||
//---<<
|
||||
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 JPanel getContent() {
|
||||
return content;
|
||||
}
|
||||
@@ -176,7 +174,7 @@ public abstract class ComparisonForm<T> {
|
||||
protected void Compare() throws Exception {
|
||||
events_on = false;
|
||||
current_diff_num = CommonConstants.Nan;
|
||||
slave.current_diff_num =CommonConstants.Nan;
|
||||
slave.current_diff_num = CommonConstants.Nan;
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
Body.setText("");
|
||||
slave.Body.setText("");
|
||||
@@ -217,31 +215,30 @@ public abstract class ComparisonForm<T> {
|
||||
diffs.clear();
|
||||
boolean flag = false;
|
||||
char[] chars = Body.getText().toCharArray();
|
||||
int dif_start=CommonConstants.Nan;
|
||||
int dif_end=CommonConstants.Nan;
|
||||
int dif_start = CommonConstants.Nan;
|
||||
int dif_end = CommonConstants.Nan;
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char c = chars[i];
|
||||
//--
|
||||
if (flag) {
|
||||
//различие
|
||||
switch (c){
|
||||
switch (c) {
|
||||
case cseparator:
|
||||
//кончилось различие
|
||||
dif_end =i;
|
||||
flag=false;
|
||||
diffs.add(new Pair<>(dif_start,dif_end));
|
||||
dif_start=CommonConstants.Nan;
|
||||
dif_end=CommonConstants.Nan;
|
||||
dif_end = i;
|
||||
flag = false;
|
||||
diffs.add(new Pair<>(dif_start, dif_end));
|
||||
dif_start = CommonConstants.Nan;
|
||||
dif_end = CommonConstants.Nan;
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
//поиск
|
||||
switch (c) {
|
||||
case cseparator:
|
||||
//началось различие
|
||||
dif_start =i;
|
||||
flag=true;
|
||||
dif_start = i;
|
||||
flag = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -249,18 +246,18 @@ public abstract class ComparisonForm<T> {
|
||||
}
|
||||
}
|
||||
if (!diffs.isEmpty())
|
||||
current_diff_num=0;
|
||||
current_diff_num = 0;
|
||||
}
|
||||
public void colorDiffs() throws Exception{
|
||||
Highlighter.HighlightPainter painter = isMaster()? SPFEditor.RedTextPainter: SPFEditor.GreenTextPainter;
|
||||
for (Pair<Integer, Integer> diff: diffs){
|
||||
Body.getHighlighter().addHighlight(diff.getKey(),diff.getValue(), painter);
|
||||
public void colorDiffs() throws Exception {
|
||||
Highlighter.HighlightPainter painter = isMaster() ? SPFEditor.RedTextPainter : SPFEditor.GreenTextPainter;
|
||||
for (Pair<Integer, Integer> diff : diffs) {
|
||||
Body.getHighlighter().addHighlight(diff.getKey(), diff.getValue(), painter);
|
||||
}
|
||||
}
|
||||
public void Show() throws Exception {
|
||||
events_on = false;
|
||||
current_diff_num = CommonConstants.Nan;
|
||||
slave.current_diff_num =CommonConstants.Nan;
|
||||
slave.current_diff_num = CommonConstants.Nan;
|
||||
//----------------------------------------------------------------------------------------------
|
||||
Body.setText("");
|
||||
slave.Body.setText("");
|
||||
|
||||
Reference in New Issue
Block a user