May 25, 2018 updates: Privacy Policy
  • R/O
  • SSH
  • HTTPS

smart-gs: Commit


Commit MetaInfo

Revision1195 (tree)
Time2016-10-02 16:34:16
Authorohura

Log Message

[editor-simplyhtml-merge] 改行コードの変更
内容の変更はなし。

Change Summary

Incremental Difference

--- branches/editor-simplyhtml-merge/src/smart_gs/smleditor/swingui/GSWysiwygMouseListener.java (revision 1194)
+++ branches/editor-simplyhtml-merge/src/smart_gs/smleditor/swingui/GSWysiwygMouseListener.java (revision 1195)
@@ -1,32 +1,32 @@
1-/* $Id$ */
1+/* $Id$ */
22 package smart_gs.smleditor.swingui;
33
4-import java.awt.Point;
4+import java.awt.Point;
55 import java.awt.event.MouseEvent;
6-import java.awt.geom.Rectangle2D;
7-import java.util.regex.Matcher;
8-import java.util.regex.Pattern;
9-
6+import java.awt.geom.Rectangle2D;
7+import java.util.regex.Matcher;
8+import java.util.regex.Pattern;
9+
1010 import javax.swing.JComponent;
11-import javax.swing.text.AttributeSet;
12-import javax.swing.text.BadLocationException;
13-import javax.swing.text.Element;
11+import javax.swing.text.AttributeSet;
12+import javax.swing.text.BadLocationException;
13+import javax.swing.text.Element;
1414 import javax.swing.text.SimpleAttributeSet;
1515 import javax.swing.text.html.HTML;
16-
16+
1717 import smart_gs.connection.ConnectionCreator;
18-import smart_gs.drawing_tool.SpreadCanvas;
18+import smart_gs.drawing_tool.SpreadCanvas;
1919 import smart_gs.drawing_tool.action.JumpWebPageAction;
20-import smart_gs.drawing_tool.view.RectangleView;
21-import smart_gs.logical.LineSegment;
22-import smart_gs.logical.Region;
20+import smart_gs.drawing_tool.view.RectangleView;
21+import smart_gs.logical.LineSegment;
22+import smart_gs.logical.Region;
2323 import smart_gs.logical.TextSegment;
24-import smart_gs.simplyhtml.SGSDocumentPane;
25-import smart_gs.swingui.AbstractGSWindow;
24+import smart_gs.simplyhtml.SGSDocumentPane;
25+import smart_gs.swingui.AbstractGSWindow;
2626 import smart_gs.swingui.WorkspaceWindow;
2727 import smart_gs.swingui.toolbar.action.ShowLocalViewAction;
2828 import smart_gs.util.HrefChecker;
29-import smart_gs.util.GSWindowByMouseEvent;
29+import smart_gs.util.GSWindowByMouseEvent;
3030 import sml_editor.swingui.wysiwyg.WysiwygMouseListener;
3131
3232
@@ -40,8 +40,8 @@
4040 @Override
4141 public void mouseClicked(MouseEvent e) {
4242 super.mouseClicked(e);
43- if(e.getButton() == MouseEvent.BUTTON3 ||
44- /* alternative for right button click */
43+ if(e.getButton() == MouseEvent.BUTTON3 ||
44+ /* alternative for right button click */
4545 (e.getButton() == MouseEvent.BUTTON1 & WorkspaceWindow.getInstance().isAlt())){
4646 SimpleAttributeSet element = textPane.getSelectID(e.getPoint());
4747 if(element == null){
@@ -52,15 +52,15 @@
5252
5353 boolean href = false;
5454 String id = (String)element.getAttribute(HTML.Attribute.HREF);
55- TextSegment segment = null;
55+ TextSegment segment = null;
5656 if(id != null){
5757 int checkid = HrefChecker.check(id);
5858 if(checkid == -1){
5959 href = true;
6060 }else{
61- segment = ((GSEditorTextPane)textPane).getSmartDocument().getSegmentByID(checkid);
62- if (segment == null) {
63- segment = ((GSEditorTextPane)textPane).getSmartDocument().getZombieSegmentByID(checkid);
61+ segment = ((GSEditorTextPane)textPane).getSmartDocument().getSegmentByID(checkid);
62+ if (segment == null) {
63+ segment = ((GSEditorTextPane)textPane).getSmartDocument().getZombieSegmentByID(checkid);
6464 }
6565 }
6666 /*
@@ -73,25 +73,25 @@
7373 }
7474 if(e.getButton() == MouseEvent.BUTTON1){
7575 SimpleAttributeSet element = textPane.getSelectID(e.getPoint());
76- if(element == null){
77- if (e.getClickCount()==2) {
78- Element elm = textPane.getElementFromPoint(e.getPoint());
79- // ocrで読み取った単語の場合は該当イメージにジャンプする
80- if (isOCRWord(elm)){
81- jumpToCorrespondingWordInImage(e, elm);
82- }
83- jumpToCorrespondingLineInImage(e);
84- }
76+ if(element == null){
77+ if (e.getClickCount()==2) {
78+ Element elm = textPane.getElementFromPoint(e.getPoint());
79+ // ocrで読み取った単語の場合は該当イメージにジャンプする
80+ if (isOCRWord(elm)){
81+ jumpToCorrespondingWordInImage(e, elm);
82+ }
83+ jumpToCorrespondingLineInImage(e);
84+ }
8585 return;
8686 }
8787 TextSegment segment = null;
8888 String id = (String)element.getAttribute(HTML.Attribute.HREF);
89- int checkid = HrefChecker.check(id);
90-
89+ int checkid = HrefChecker.check(id);
90+
9191 //2011/10/16 kukita
92- if (element.getAttribute(ConnectionCreator.EXTERNAL_LINK) != null) {
93- new JumpWebPageAction(textPane,e.getPoint()).actionPerformed(null);
94- return;
92+ if (element.getAttribute(ConnectionCreator.EXTERNAL_LINK) != null) {
93+ new JumpWebPageAction(textPane,e.getPoint()).actionPerformed(null);
94+ return;
9595 }else{
9696 segment = ((GSEditorTextPane)textPane).getSmartDocument().getSegmentByID(checkid);
9797 }
@@ -105,152 +105,152 @@
105105 }
106106 if(e.getClickCount() == 2){
107107 new ShowLocalViewAction(segment).execute();
108- }
108+ }
109109 }
110110 }
111- }
112-
113- private void jumpToCorrespondingLineInImage(MouseEvent e) {
114- AbstractGSWindow window = (new GSWindowByMouseEvent()).getWindow(e);
115- if (window == null) return;
116- boolean iscompacteditor=false;
117- if (window instanceof GSEditor) {
118- if (((GSEditor)window).getEditorType() == GSEditor.COMPACT) {
119- iscompacteditor=true;
120- }
121- }
122- GSTabbedPane gsTabbedPane = window.getTabbedPane();
123- if (gsTabbedPane.getSelectedIndex() != (iscompacteditor?1:0)) return;
124- IDATPanel fstIdatPanel = (IDATPanel)gsTabbedPane.getSelectedComponent();
125- SGSDocumentPane theTextPane = (SGSDocumentPane)e.getComponent();
126- if (theTextPane != fstIdatPanel.getTextPane().getSGSDocumentPane()) return;
127- int pos = theTextPane.getCaretPosition();
128-
129- char ch = getCharAt(theTextPane,pos);
130- char chprev = getCharAt(theTextPane,pos-1);
131-
132- String ansString = "";
133- int left = 0;
134- boolean leftfound = false;
135-
136- if (ch == '$'){
137- left = pos;
138- while (left > 0) {
139- left--;
140- ch = getCharAt(theTextPane,left);;
141- if (! (('0' <= ch && ch <= '9') || ch == '$')) {
142- break;
143- } else if (ch == '$') {
144- if (left == pos - 1) return;
145- leftfound = true;
146- break;
147- }
148- }
149- if (!leftfound) return;
150- try {
151- ansString = theTextPane.getText(left,pos-left+1);
152- if (ansString.charAt(0)=='$' && ansString.charAt(ansString.length()-1)=='$') {
153- jumpToLine(new Integer(ansString.substring(1,ansString.length()-1)),window);
154- if (iscompacteditor) window.getTabbedPane().setSelectedIndex(0);
155- }
156- return;
157- } catch (BadLocationException e1) {
158- return;
159- }
160- } else if (chprev == '$'){
161- pos--;
162- left = pos;
163- while (left > 0) {
164- left--;
165- ch = getCharAt(theTextPane,left);;
166- if (! (('0' <= ch && ch <= '9') || ch == '$')) {
167- break;
168- } else if (ch == '$') {
169- if (left == pos - 1) return;
170- leftfound = true;
171- break;
172- }
173- }
174- if (!leftfound) return;
175- try {
176- ansString = theTextPane.getText(left,pos-left+1);
177- if (ansString.charAt(0)=='$' && ansString.charAt(ansString.length()-1)=='$') {
178- int index = new Integer(ansString.substring(1,ansString.length()-1));
179- jumpToLine(index,window);
180- if (iscompacteditor) window.getTabbedPane().setSelectedIndex(0);
181- }
182- return;
183- } catch (BadLocationException e1) {
184- return;
185- }
186- }
187- }
188-
189-
190- private void jumpToLine(Integer n,AbstractGSWindow window) {
191- SpreadCanvas canvas = window.getSpreadCanvas();
192- LineSegment lineseg = canvas.imageLabel.getLineSeg(n);
193- Region region = lineseg.transformToPolygonRegion(canvas.getSpread());
194- region.setTemporary(true);
195- region.setJumpedTo(true);
196- canvas.addRegion(region);
197- canvas.tmpPolyDeleteAndResetSelection(true);
198- canvas.selectRegion(region);
199- canvas.imageLabel.showImage();
200- canvas.imageLabel.moveToLine(lineseg.getCornerPoint());
201- }
202-
203- private char getCharAt(SGSDocumentPane theTextPane, int pos) {
204- try {
205- return theTextPane.getText(pos,1).charAt(0);
206- } catch (BadLocationException e) {
207- return 0;
208- }
209- }
210-
211- private boolean isOCRWord (Element elm) {
212- Object attribute = elm.getAttributes().getAttribute(HTML.Tag.SPAN);
213- AttributeSet set = (AttributeSet) attribute;
214- String cls = null;
215- if (set != null) {
216- cls = (String) set.getAttribute(HTML.Attribute.CLASS);
217- }
218- if (cls != null) {
219- return cls.equals("ocrx_word");
220- }
221- return false;
222- }
223-
224- private void jumpToCorrespondingWordInImage (MouseEvent event, Element elm) {
225- Object attribute = elm.getAttributes().getAttribute(HTML.Tag.SPAN);
226- AttributeSet set = (AttributeSet) attribute;
227- String bbox = (String) set.getAttribute(HTML.Attribute.TITLE);
228- // U+a0のスペースが含まれているのでor条件でマッチ
229- String regex = "bbox(?: | )(\\d+)(?: | )(\\d+)(?: | )(\\d+)(?: | )(\\d+)";
230- Pattern p = Pattern.compile(regex);
231- Matcher m = p.matcher(bbox);
232- int x = 0;
233- int y = 0;
234- int w = 0;
235- int h = 0;
236- if (m.find()) {
237- x = Integer.parseInt(m.group(1));
238- y = Integer.parseInt(m.group(2));
239- w = Integer.parseInt(m.group(3)) - x;
240- h = Integer.parseInt(m.group(4)) - y;
241- }
242- AbstractGSWindow window = (new GSWindowByMouseEvent()).getWindow(event);
243- if (window == null) return;
244- SpreadCanvas canvas = window.getSpreadCanvas();
245- Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
246- RectangleView view = new RectangleView(rect);
247- Region region = new Region(canvas.getSpread(), view);
248- region.setTemporary(true);
249- region.setJumpedTo(true);
250- canvas.addRegion(region);
251- canvas.tmpPolyDeleteAndResetSelection(true);
252- canvas.selectRegion(region);
253- canvas.imageLabel.showImage();
254- canvas.imageLabel.moveTo(new Point(x,y));
111+ }
112+
113+ private void jumpToCorrespondingLineInImage(MouseEvent e) {
114+ AbstractGSWindow window = (new GSWindowByMouseEvent()).getWindow(e);
115+ if (window == null) return;
116+ boolean iscompacteditor=false;
117+ if (window instanceof GSEditor) {
118+ if (((GSEditor)window).getEditorType() == GSEditor.COMPACT) {
119+ iscompacteditor=true;
120+ }
121+ }
122+ GSTabbedPane gsTabbedPane = window.getTabbedPane();
123+ if (gsTabbedPane.getSelectedIndex() != (iscompacteditor?1:0)) return;
124+ IDATPanel fstIdatPanel = (IDATPanel)gsTabbedPane.getSelectedComponent();
125+ SGSDocumentPane theTextPane = (SGSDocumentPane)e.getComponent();
126+ if (theTextPane != fstIdatPanel.getTextPane().getSGSDocumentPane()) return;
127+ int pos = theTextPane.getCaretPosition();
128+
129+ char ch = getCharAt(theTextPane,pos);
130+ char chprev = getCharAt(theTextPane,pos-1);
131+
132+ String ansString = "";
133+ int left = 0;
134+ boolean leftfound = false;
135+
136+ if (ch == '$'){
137+ left = pos;
138+ while (left > 0) {
139+ left--;
140+ ch = getCharAt(theTextPane,left);;
141+ if (! (('0' <= ch && ch <= '9') || ch == '$')) {
142+ break;
143+ } else if (ch == '$') {
144+ if (left == pos - 1) return;
145+ leftfound = true;
146+ break;
147+ }
148+ }
149+ if (!leftfound) return;
150+ try {
151+ ansString = theTextPane.getText(left,pos-left+1);
152+ if (ansString.charAt(0)=='$' && ansString.charAt(ansString.length()-1)=='$') {
153+ jumpToLine(new Integer(ansString.substring(1,ansString.length()-1)),window);
154+ if (iscompacteditor) window.getTabbedPane().setSelectedIndex(0);
155+ }
156+ return;
157+ } catch (BadLocationException e1) {
158+ return;
159+ }
160+ } else if (chprev == '$'){
161+ pos--;
162+ left = pos;
163+ while (left > 0) {
164+ left--;
165+ ch = getCharAt(theTextPane,left);;
166+ if (! (('0' <= ch && ch <= '9') || ch == '$')) {
167+ break;
168+ } else if (ch == '$') {
169+ if (left == pos - 1) return;
170+ leftfound = true;
171+ break;
172+ }
173+ }
174+ if (!leftfound) return;
175+ try {
176+ ansString = theTextPane.getText(left,pos-left+1);
177+ if (ansString.charAt(0)=='$' && ansString.charAt(ansString.length()-1)=='$') {
178+ int index = new Integer(ansString.substring(1,ansString.length()-1));
179+ jumpToLine(index,window);
180+ if (iscompacteditor) window.getTabbedPane().setSelectedIndex(0);
181+ }
182+ return;
183+ } catch (BadLocationException e1) {
184+ return;
185+ }
186+ }
187+ }
188+
189+
190+ private void jumpToLine(Integer n,AbstractGSWindow window) {
191+ SpreadCanvas canvas = window.getSpreadCanvas();
192+ LineSegment lineseg = canvas.imageLabel.getLineSeg(n);
193+ Region region = lineseg.transformToPolygonRegion(canvas.getSpread());
194+ region.setTemporary(true);
195+ region.setJumpedTo(true);
196+ canvas.addRegion(region);
197+ canvas.tmpPolyDeleteAndResetSelection(true);
198+ canvas.selectRegion(region);
199+ canvas.imageLabel.showImage();
200+ canvas.imageLabel.moveToLine(lineseg.getCornerPoint());
201+ }
202+
203+ private char getCharAt(SGSDocumentPane theTextPane, int pos) {
204+ try {
205+ return theTextPane.getText(pos,1).charAt(0);
206+ } catch (BadLocationException e) {
207+ return 0;
208+ }
209+ }
210+
211+ private boolean isOCRWord (Element elm) {
212+ Object attribute = elm.getAttributes().getAttribute(HTML.Tag.SPAN);
213+ AttributeSet set = (AttributeSet) attribute;
214+ String cls = null;
215+ if (set != null) {
216+ cls = (String) set.getAttribute(HTML.Attribute.CLASS);
217+ }
218+ if (cls != null) {
219+ return cls.equals("ocrx_word");
220+ }
221+ return false;
222+ }
223+
224+ private void jumpToCorrespondingWordInImage (MouseEvent event, Element elm) {
225+ Object attribute = elm.getAttributes().getAttribute(HTML.Tag.SPAN);
226+ AttributeSet set = (AttributeSet) attribute;
227+ String bbox = (String) set.getAttribute(HTML.Attribute.TITLE);
228+ // U+a0のスペースが含まれているのでor条件でマッチ
229+ String regex = "bbox(?: | )(\\d+)(?: | )(\\d+)(?: | )(\\d+)(?: | )(\\d+)";
230+ Pattern p = Pattern.compile(regex);
231+ Matcher m = p.matcher(bbox);
232+ int x = 0;
233+ int y = 0;
234+ int w = 0;
235+ int h = 0;
236+ if (m.find()) {
237+ x = Integer.parseInt(m.group(1));
238+ y = Integer.parseInt(m.group(2));
239+ w = Integer.parseInt(m.group(3)) - x;
240+ h = Integer.parseInt(m.group(4)) - y;
241+ }
242+ AbstractGSWindow window = (new GSWindowByMouseEvent()).getWindow(event);
243+ if (window == null) return;
244+ SpreadCanvas canvas = window.getSpreadCanvas();
245+ Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
246+ RectangleView view = new RectangleView(rect);
247+ Region region = new Region(canvas.getSpread(), view);
248+ region.setTemporary(true);
249+ region.setJumpedTo(true);
250+ canvas.addRegion(region);
251+ canvas.tmpPolyDeleteAndResetSelection(true);
252+ canvas.selectRegion(region);
253+ canvas.imageLabel.showImage();
254+ canvas.imageLabel.moveTo(new Point(x,y));
255255 }
256256 }
\ No newline at end of file
--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSVerticalInlineView.java (revision 1194)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSVerticalInlineView.java (revision 1195)
@@ -1,58 +1,58 @@
1-package smart_gs.simplyhtml;
2-
3-import java.awt.Graphics;
4-import java.awt.Graphics2D;
5-import java.awt.Rectangle;
6-import java.awt.Shape;
7-import java.awt.geom.AffineTransform;
8-
9-import javax.swing.text.BadLocationException;
10-import javax.swing.text.Element;
11-import javax.swing.text.html.InlineView;
12-
13-public class SGSVerticalInlineView extends InlineView {
14-
15- private float width;
16- private float height;
17- private String text;
18-
19- public SGSVerticalInlineView(Element elem) {
20- super(elem);
21- try {
22- this.text = elem.getDocument().getText(elem.getStartOffset(), elem.getEndOffset()-elem.getStartOffset());
23- } catch (BadLocationException e) {
24- e.printStackTrace();
25- }
26- }
27-
28- @Override
29- public void paint(Graphics g, Shape a) {
30- Rectangle rect = a.getBounds();
31- Graphics2D g2d = (Graphics2D) g;
32- AffineTransform old = g2d.getTransform();
33-
34- char ch = text.charAt(0);
35- if(Character.isIdeographic(ch)
36- ||Character.UnicodeBlock.of(ch).equals(Character.UnicodeBlock.HIRAGANA)
37- ||Character.UnicodeBlock.of(ch).equals(Character.UnicodeBlock.KATAKANA)
38- ||ch == '\u3005'){ // 々
39- g2d.rotate(-Math.PI / 2, rect.x, rect.y);
40- g2d.translate(-width, 0);
41- } else if(ch == '\u3001' // 、
42- ||ch == '\u3002'){ // 。
43- g2d.rotate(Math.PI /2 , rect.x, rect.y);
44- g2d.translate(0, -height);
45- }
46-// g.drawRect(rect.x, rect.y, rect.width, rect.height);
47- super.paint(g2d, a);
48- g2d.setTransform(old);
49- }
50-
51- @Override
52- public void setSize(float width, float height) {
53- this.width = width;
54- this.height = height;
55- super.setSize(width, height);
56- }
57-
58-}
1+package smart_gs.simplyhtml;
2+
3+import java.awt.Graphics;
4+import java.awt.Graphics2D;
5+import java.awt.Rectangle;
6+import java.awt.Shape;
7+import java.awt.geom.AffineTransform;
8+
9+import javax.swing.text.BadLocationException;
10+import javax.swing.text.Element;
11+import javax.swing.text.html.InlineView;
12+
13+public class SGSVerticalInlineView extends InlineView {
14+
15+ private float width;
16+ private float height;
17+ private String text;
18+
19+ public SGSVerticalInlineView(Element elem) {
20+ super(elem);
21+ try {
22+ this.text = elem.getDocument().getText(elem.getStartOffset(), elem.getEndOffset()-elem.getStartOffset());
23+ } catch (BadLocationException e) {
24+ e.printStackTrace();
25+ }
26+ }
27+
28+ @Override
29+ public void paint(Graphics g, Shape a) {
30+ Rectangle rect = a.getBounds();
31+ Graphics2D g2d = (Graphics2D) g;
32+ AffineTransform old = g2d.getTransform();
33+
34+ char ch = text.charAt(0);
35+ if(Character.isIdeographic(ch)
36+ ||Character.UnicodeBlock.of(ch).equals(Character.UnicodeBlock.HIRAGANA)
37+ ||Character.UnicodeBlock.of(ch).equals(Character.UnicodeBlock.KATAKANA)
38+ ||ch == '\u3005'){ // 々
39+ g2d.rotate(-Math.PI / 2, rect.x, rect.y);
40+ g2d.translate(-width, 0);
41+ } else if(ch == '\u3001' // 、
42+ ||ch == '\u3002'){ // 。
43+ g2d.rotate(Math.PI /2 , rect.x, rect.y);
44+ g2d.translate(0, -height);
45+ }
46+// g.drawRect(rect.x, rect.y, rect.width, rect.height);
47+ super.paint(g2d, a);
48+ g2d.setTransform(old);
49+ }
50+
51+ @Override
52+ public void setSize(float width, float height) {
53+ this.width = width;
54+ this.height = height;
55+ super.setSize(width, height);
56+ }
57+
58+}
--- branches/editor-simplyhtml-merge/src/smart_gs/diff/ResourceDiff.java (revision 1194)
+++ branches/editor-simplyhtml-merge/src/smart_gs/diff/ResourceDiff.java (revision 1195)
@@ -1,126 +1,126 @@
1-package smart_gs.diff;
2-
3-import java.util.Arrays;
4-import java.util.List;
5-import difflib.DiffRow;
6-import difflib.DiffRowGenerator;
7-
8-
9-
10-public class ResourceDiff {
11-
12- private String name;
13- private Type type;
14- private State state;
15- private String diffHtml;
16- private boolean changed;
17-
18- public static enum Type {
19- DIRECTORY, SPREAD, SPREAD_DOCUMENT;
20- }
21- public static enum State {
22- EQUAL, INSERT, DELETE, CHANGE;
23- }
24-
25- public ResourceDiff(String name, Type type) {
26- this.name = name;
27- this.setType(type);
28- this.diffHtml = "";
29- this.changed = false;
30-
31- }
32-
33- public String getName() {
34- return name;
35- }
36-
37- public void setName(String name) {
38- this.name = name;
39- }
40-
41- @Override
42- public String toString(){
43- if (this.changed) {
44- return ">" + this.name;
45- }
46- return this.name;
47- }
48-
49- public static void main(String[] args) {
50- String original = "$0$  ○老女死期に紀念を託す條<br>$1$ こゝに哀れをとゞめしハ。深川冨川町の辺とかや。柏屋の何某なる者。以<br>$2$ 前ハ有徳に暮しゝが。薄命のうち続き。今ハ次第に困窮して召仕<br>$3$ にも暇をとらせ。たゞ夫婦さし対ひにて。いと淋しく送りけるが十月三日<br>$4$ ハ過さりし。母の年忌にあたるにより。心ばかりの佛事をいとなミ。親き<br>$5$ 人にも供養せん。と同二日ハ逮夜とて。朝まだきより野菜を調へ。米<br>$6$ なンど炊くをりから。僅一二町を隔だてし所に。大工何某なるものゝ<br>$7$ 娘。二十ばかりになりけるが。日来親しく往かふにより。今日の佛事の手<br>$8$ 傅ひせんとて。この家に来りツヽ。いと甲斐〴〵しく働きて。夫婦が手をぞ<br>$9$ 助けける。かくて其夜戌時頃。その事も大かた果て。娘ハ帰らんといひけるを。<br>$10$ 柏屋夫婦ハこれを止め。はや亥刻にも程近からんに。今宵ハ泊りて<br><br>$11$ 翌の朝。とく帰られよといふほどに。その意に任して逗りツヽ。猶とりちら<br>$12$ せし調度など推かたづけて亥刻もうちぬ。はや憩んと床なンど。敷ん<br>$13$ としたるその折から。暴に虚空動揺なし。その家将に覆らんとす。三<br>$14$ 人ハ大に駭きて。表の戸を引開て。矢庭に走り出けるが。柏屋の檐倒<br>$15$ れて。大道へ横たハる。今少し遅からバこの檐に打れツヽ。身を傷んを<br>$16$ 危ふかりしと吐息吻て跪ミ居る。かの娘ハこれを見て。父母の身の<br>$17$ うへ心許なし。暇まうすといひも敢ず。一散に駈出す。夫婦ハ呼び止め<br>$18$ 尤なり。今諸共に行て訪ん。霎時待ねといひけれど。聞えしやまた<br>$19$ 聞えずや。回答もせずして走りゆけバ。柏屋ハ妻に向ひ。日来よりし<br>$20$ て孝心の世に勝れたるものなれバ。心裡然もあるべし。程近けれど<br>$21$ 夜更たり一人やハ帰されじ。我ハ跡より逐着て彼家へ送り達(とどけ)ん";
51- String revised = "$0$  ○老女死期に紀念を託す條<br>$1$ こゝに哀れをとゞめしハ。深川冨川町の辺とかや。柏屋の何某なる者。以<br>$2$ 前ハ有徳に暮しゝが。薄命のうち続き。今ハ次第に困窮して召仕<br>$3$ にも暇をとらせ。たゞ夫婦さし対ひにて。いと淋しく送りけるが十月三日<br>$4$ ハ過さりし。母の年忌にあたるにより。心ばかりの佛事をいとなミ。親き<br>$8$ 傅ひせんとて。この家に来りツヽ。いと甲斐〴〵しく働きて。夫婦が手をぞ<br>$9$ 助けける。かくて其夜戌時頃。その事も大かた果て。娘ハ帰らんといひけるを。<br>$10$ 柏屋夫婦ハこれを止め。はや亥刻にも程近からんに。今宵ハ泊りて<br><br>$11$ 翌の朝。とく帰られよといふほどに。その意に任して逗りツヽ。猶とりちら<br>$12$ せし調度など推かたづけて亥刻もうちぬ。はや憩んと床なンど。敷ん<br>$13$ としたるその折から。暴に虚空動揺なし。その家将に覆らんとす。三<br>ああああああ<br>ああああああ<br>いいいいいい<br>$14$ 人ハ大に駭きて。表の戸を引開て。矢庭に走り出けるが。柏屋の檐倒<br>$15$ れて。大道へ横たハる。今少し遅からバこの檐に打れツヽ。身を傷んを<br>$16$ 危ふかりしと吐息吻て跪ミ居る。かあkjdfぁksjdfヵskjの娘ハこれを見て。父母の身の<br>$17$ うへ心許なし。暇まうすといひも敢ず。一散に駈出す。夫婦ハ呼び止め<br>$18$ 尤なり。今諸共に行て訪ん。霎時待ねといひけれど。聞えしやまた<br>$19$ 聞えずや。回答もせずして走りゆけバ。柏屋ハ妻に向ひ。日来よりし<br>$20$ て孝心の世に勝れたるものなれバ。心裡然もあるべし。程近けれど<br>$21$ 夜更たり一人やハ帰されじ。我ハ跡より逐着て彼家へ送り達(とどけ)ん";
52- List<String> originalList = Arrays.asList(original.split("<br/?>"));
53- List<String> revisedList = Arrays.asList(revised.split("<br/?>"));
54-
55- DiffRowGenerator.Builder builder = new DiffRowGenerator.Builder();
56- boolean sideBySide = true; //default -> inline
57- builder.showInlineDiffs(!sideBySide);
58- builder.columnWidth(120);
59- DiffRowGenerator dfg = builder.build();
60- List<DiffRow> rows = dfg.generateDiffRows( originalList, revisedList);
61- // original text
62- System.out.println("<table>");
63- int count = 1;
64- for (DiffRow row : rows) {
65- System.out.println("<tr>");
66- System.out.print("<td>"+count+"</td>");
67- count++;
68- String oldLine = row.getOldLine();
69- String newLine = row.getNewLine();
70- switch(row.getTag()) {
71- case EQUAL:
72- System.out.print("<td>"+oldLine+"</td>");
73- System.out.print("<td>"+newLine+"</td>");
74- break;
75- case CHANGE:
76- System.out.print("<td style='background-color: yellow'>"+oldLine+"</td>");
77- System.out.print("<td style='background-color: yellow'>"+newLine+"</td>");
78- break;
79- case DELETE:
80- System.out.print("<td style='background-color: skyblue'><del>"+oldLine+"</del></td>");
81- System.out.print("<td></td>");
82- break;
83- case INSERT:
84- System.out.print("<td></td>");
85- System.out.print("<td style='background-color: red'>"+newLine+"</td>");
86- default:
87- break;
88- }
89- System.out.println("</tr>");
90- }
91- System.out.println("</table>");
92- }
93-
94- public Type getType() {
95- return type;
96- }
97-
98- public void setType(Type type) {
99- this.type = type;
100- }
101-
102- public State getState() {
103- return state;
104- }
105-
106- public void setState(State state) {
107- this.state = state;
108- }
109-
110- public String getDiffHtml() {
111- return diffHtml;
112- }
113-
114- public void setDiffHtml(String diffHtml) {
115- this.diffHtml = diffHtml;
116- }
117-
118- public boolean isChanged() {
119- return changed;
120- }
121-
122- public void setChanged(boolean changed) {
123- this.changed = changed;
124- }
125-
126-}
1+package smart_gs.diff;
2+
3+import java.util.Arrays;
4+import java.util.List;
5+import difflib.DiffRow;
6+import difflib.DiffRowGenerator;
7+
8+
9+
10+public class ResourceDiff {
11+
12+ private String name;
13+ private Type type;
14+ private State state;
15+ private String diffHtml;
16+ private boolean changed;
17+
18+ public static enum Type {
19+ DIRECTORY, SPREAD, SPREAD_DOCUMENT;
20+ }
21+ public static enum State {
22+ EQUAL, INSERT, DELETE, CHANGE;
23+ }
24+
25+ public ResourceDiff(String name, Type type) {
26+ this.name = name;
27+ this.setType(type);
28+ this.diffHtml = "";
29+ this.changed = false;
30+
31+ }
32+
33+ public String getName() {
34+ return name;
35+ }
36+
37+ public void setName(String name) {
38+ this.name = name;
39+ }
40+
41+ @Override
42+ public String toString(){
43+ if (this.changed) {
44+ return ">" + this.name;
45+ }
46+ return this.name;
47+ }
48+
49+ public static void main(String[] args) {
50+ String original = "$0$  ○老女死期に紀念を託す條<br>$1$ こゝに哀れをとゞめしハ。深川冨川町の辺とかや。柏屋の何某なる者。以<br>$2$ 前ハ有徳に暮しゝが。薄命のうち続き。今ハ次第に困窮して召仕<br>$3$ にも暇をとらせ。たゞ夫婦さし対ひにて。いと淋しく送りけるが十月三日<br>$4$ ハ過さりし。母の年忌にあたるにより。心ばかりの佛事をいとなミ。親き<br>$5$ 人にも供養せん。と同二日ハ逮夜とて。朝まだきより野菜を調へ。米<br>$6$ なンど炊くをりから。僅一二町を隔だてし所に。大工何某なるものゝ<br>$7$ 娘。二十ばかりになりけるが。日来親しく往かふにより。今日の佛事の手<br>$8$ 傅ひせんとて。この家に来りツヽ。いと甲斐〴〵しく働きて。夫婦が手をぞ<br>$9$ 助けける。かくて其夜戌時頃。その事も大かた果て。娘ハ帰らんといひけるを。<br>$10$ 柏屋夫婦ハこれを止め。はや亥刻にも程近からんに。今宵ハ泊りて<br><br>$11$ 翌の朝。とく帰られよといふほどに。その意に任して逗りツヽ。猶とりちら<br>$12$ せし調度など推かたづけて亥刻もうちぬ。はや憩んと床なンど。敷ん<br>$13$ としたるその折から。暴に虚空動揺なし。その家将に覆らんとす。三<br>$14$ 人ハ大に駭きて。表の戸を引開て。矢庭に走り出けるが。柏屋の檐倒<br>$15$ れて。大道へ横たハる。今少し遅からバこの檐に打れツヽ。身を傷んを<br>$16$ 危ふかりしと吐息吻て跪ミ居る。かの娘ハこれを見て。父母の身の<br>$17$ うへ心許なし。暇まうすといひも敢ず。一散に駈出す。夫婦ハ呼び止め<br>$18$ 尤なり。今諸共に行て訪ん。霎時待ねといひけれど。聞えしやまた<br>$19$ 聞えずや。回答もせずして走りゆけバ。柏屋ハ妻に向ひ。日来よりし<br>$20$ て孝心の世に勝れたるものなれバ。心裡然もあるべし。程近けれど<br>$21$ 夜更たり一人やハ帰されじ。我ハ跡より逐着て彼家へ送り達(とどけ)ん";
51+ String revised = "$0$  ○老女死期に紀念を託す條<br>$1$ こゝに哀れをとゞめしハ。深川冨川町の辺とかや。柏屋の何某なる者。以<br>$2$ 前ハ有徳に暮しゝが。薄命のうち続き。今ハ次第に困窮して召仕<br>$3$ にも暇をとらせ。たゞ夫婦さし対ひにて。いと淋しく送りけるが十月三日<br>$4$ ハ過さりし。母の年忌にあたるにより。心ばかりの佛事をいとなミ。親き<br>$8$ 傅ひせんとて。この家に来りツヽ。いと甲斐〴〵しく働きて。夫婦が手をぞ<br>$9$ 助けける。かくて其夜戌時頃。その事も大かた果て。娘ハ帰らんといひけるを。<br>$10$ 柏屋夫婦ハこれを止め。はや亥刻にも程近からんに。今宵ハ泊りて<br><br>$11$ 翌の朝。とく帰られよといふほどに。その意に任して逗りツヽ。猶とりちら<br>$12$ せし調度など推かたづけて亥刻もうちぬ。はや憩んと床なンど。敷ん<br>$13$ としたるその折から。暴に虚空動揺なし。その家将に覆らんとす。三<br>ああああああ<br>ああああああ<br>いいいいいい<br>$14$ 人ハ大に駭きて。表の戸を引開て。矢庭に走り出けるが。柏屋の檐倒<br>$15$ れて。大道へ横たハる。今少し遅からバこの檐に打れツヽ。身を傷んを<br>$16$ 危ふかりしと吐息吻て跪ミ居る。かあkjdfぁksjdfヵskjの娘ハこれを見て。父母の身の<br>$17$ うへ心許なし。暇まうすといひも敢ず。一散に駈出す。夫婦ハ呼び止め<br>$18$ 尤なり。今諸共に行て訪ん。霎時待ねといひけれど。聞えしやまた<br>$19$ 聞えずや。回答もせずして走りゆけバ。柏屋ハ妻に向ひ。日来よりし<br>$20$ て孝心の世に勝れたるものなれバ。心裡然もあるべし。程近けれど<br>$21$ 夜更たり一人やハ帰されじ。我ハ跡より逐着て彼家へ送り達(とどけ)ん";
52+ List<String> originalList = Arrays.asList(original.split("<br/?>"));
53+ List<String> revisedList = Arrays.asList(revised.split("<br/?>"));
54+
55+ DiffRowGenerator.Builder builder = new DiffRowGenerator.Builder();
56+ boolean sideBySide = true; //default -> inline
57+ builder.showInlineDiffs(!sideBySide);
58+ builder.columnWidth(120);
59+ DiffRowGenerator dfg = builder.build();
60+ List<DiffRow> rows = dfg.generateDiffRows( originalList, revisedList);
61+ // original text
62+ System.out.println("<table>");
63+ int count = 1;
64+ for (DiffRow row : rows) {
65+ System.out.println("<tr>");
66+ System.out.print("<td>"+count+"</td>");
67+ count++;
68+ String oldLine = row.getOldLine();
69+ String newLine = row.getNewLine();
70+ switch(row.getTag()) {
71+ case EQUAL:
72+ System.out.print("<td>"+oldLine+"</td>");
73+ System.out.print("<td>"+newLine+"</td>");
74+ break;
75+ case CHANGE:
76+ System.out.print("<td style='background-color: yellow'>"+oldLine+"</td>");
77+ System.out.print("<td style='background-color: yellow'>"+newLine+"</td>");
78+ break;
79+ case DELETE:
80+ System.out.print("<td style='background-color: skyblue'><del>"+oldLine+"</del></td>");
81+ System.out.print("<td></td>");
82+ break;
83+ case INSERT:
84+ System.out.print("<td></td>");
85+ System.out.print("<td style='background-color: red'>"+newLine+"</td>");
86+ default:
87+ break;
88+ }
89+ System.out.println("</tr>");
90+ }
91+ System.out.println("</table>");
92+ }
93+
94+ public Type getType() {
95+ return type;
96+ }
97+
98+ public void setType(Type type) {
99+ this.type = type;
100+ }
101+
102+ public State getState() {
103+ return state;
104+ }
105+
106+ public void setState(State state) {
107+ this.state = state;
108+ }
109+
110+ public String getDiffHtml() {
111+ return diffHtml;
112+ }
113+
114+ public void setDiffHtml(String diffHtml) {
115+ this.diffHtml = diffHtml;
116+ }
117+
118+ public boolean isChanged() {
119+ return changed;
120+ }
121+
122+ public void setChanged(boolean changed) {
123+ this.changed = changed;
124+ }
125+
126+}
Show on old repository browser