64
64
import org .netbeans .api .editor .mimelookup .MimeLookup ;
65
65
import org .netbeans .api .editor .settings .FontColorNames ;
66
66
import org .netbeans .api .editor .settings .FontColorSettings ;
67
+ import org .netbeans .editor .BaseDocument ;
67
68
import org .netbeans .editor .BaseTextUI ;
68
69
import org .netbeans .spi .diff .DiffProvider ;
69
70
import org .netbeans .spi .diff .DiffControllerImpl ;
70
71
import org .netbeans .editor .EditorUI ;
71
72
import org .netbeans .lib .editor .util .swing .DocumentUtilities ;
72
73
import org .netbeans .modules .diff .builtin .visualizer .TextDiffVisualizer ;
74
+ import static org .netbeans .modules .editor .errorstripe .privatespi .MarkProvider .PROP_MARKS ;
73
75
import org .openide .DialogDisplayer ;
74
76
import org .openide .NotifyDescriptor ;
75
77
import org .openide .text .NbDocument ;
@@ -122,6 +124,8 @@ public class EditableDiffView extends DiffControllerImpl implements DiffView, Do
122
124
123
125
final JLabel fileLabel1 = new JLabel ();
124
126
final JLabel fileLabel2 = new JLabel ();
127
+ final JLabel lineEndingLabel1 = new JLabel ();
128
+ final JLabel lineEndingLabel2 = new JLabel ();
125
129
final JPanel filePanel1 = new JPanel ();
126
130
final JPanel filePanel2 = new JPanel ();
127
131
final JPanel textualPanel = new JPanel ();
@@ -166,6 +170,7 @@ public class EditableDiffView extends DiffControllerImpl implements DiffView, Do
166
170
private final Object DIFFING_LOCK = new Object ();
167
171
private final String name1 ;
168
172
private final String name2 ;
173
+
169
174
private boolean sourcesInitialized ;
170
175
private boolean viewAdded ;
171
176
private boolean addedToHierarchy ;
@@ -181,6 +186,7 @@ public EditableDiffView(final StreamSource ss1, final StreamSource ss2, boolean
181
186
if (title1 == null ) title1 = NbBundle .getMessage (EditableDiffView .class , "CTL_DiffPanel_NoTitle" ); // NOI18N
182
187
String title2 = ss2 .getTitle ();
183
188
if (title2 == null ) title2 = NbBundle .getMessage (EditableDiffView .class , "CTL_DiffPanel_NoTitle" ); // NOI18N
189
+
184
190
String mimeType1 = ss1 .getMIMEType ();
185
191
String mimeType2 = ss2 .getMIMEType ();
186
192
name1 = ss1 .getName ();
@@ -237,7 +243,7 @@ public void removeNotify () {
237
243
view .getAccessibleContext ().setAccessibleName (org .openide .util .NbBundle .getMessage (EditableDiffView .class , "ACS_DiffPanelA11yName" )); // NOI18N
238
244
view .getAccessibleContext ().setAccessibleDescription (org .openide .util .NbBundle .getMessage (EditableDiffView .class , "ACS_DiffPanelA11yDesc" )); // NOI18N
239
245
initializeTabPane (ss1 , ss2 );
240
-
246
+
241
247
setSourceTitle (fileLabel1 , title1 );
242
248
setSourceTitle (fileLabel2 , title2 );
243
249
@@ -372,6 +378,24 @@ public void run () {
372
378
}
373
379
}
374
380
381
+ private static String detectLineEnding (DiffContentPanel source ) {
382
+ try {
383
+ Document doc = source .getEditorPane ().getDocument ();
384
+ String separator = doc .getProperty (BaseDocument .READ_LINE_SEPARATOR_PROP ).toString ();
385
+ if ("\n " .equals (separator )) {
386
+ return "LF" ;
387
+ } else if ("\r \n " .equals (separator )) {
388
+ return "CRLF" ;
389
+ } else if ("\r " .equals (separator )) {
390
+ return "CR" ;
391
+ }
392
+ } catch (Exception e ) {
393
+ // fallback to other means of obtaining the source
394
+ }
395
+
396
+ return null ;
397
+ }
398
+
375
399
private void initializeTabPane (StreamSource ss1 , StreamSource ss2 ) {
376
400
if (jTabbedPane != null ) {
377
401
jTabbedPane .addTab (org .openide .util .NbBundle .getMessage (EditableDiffView .class , "EditableDiffView.viewGraphical.title" ), jSplitPane1 ); //NOI18N
@@ -939,19 +963,36 @@ public void run () {
939
963
// scroll the left pane accordingly
940
964
manager .scroll (index == diffs .length - 1 || index == 0 );
941
965
}
942
-
966
+
943
967
/** This method is called from within the constructor to initialize the form.
944
968
*/
945
969
private void initComponents () {
946
970
fileLabel1 .setBorder (BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 ));
947
971
fileLabel1 .setHorizontalAlignment (javax .swing .SwingConstants .CENTER );
972
+ lineEndingLabel1 .setBorder (BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 ));
973
+ lineEndingLabel1 .setHorizontalAlignment (javax .swing .SwingConstants .RIGHT );
974
+ JPanel headerPanel1 = new JPanel (new BorderLayout ());
975
+
976
+ JLabel filler1 = new JLabel ();
977
+ headerPanel1 .add (filler1 , BorderLayout .WEST );
978
+ headerPanel1 .add (fileLabel1 , BorderLayout .CENTER );
979
+ headerPanel1 .add (lineEndingLabel1 , BorderLayout .EAST );
948
980
filePanel1 .setLayout (new BorderLayout ());
949
- filePanel1 .add (fileLabel1 , BorderLayout .PAGE_START );
981
+ filePanel1 .add (headerPanel1 , BorderLayout .PAGE_START );
950
982
951
983
fileLabel2 .setBorder (BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 ));
952
984
fileLabel2 .setHorizontalAlignment (javax .swing .SwingConstants .CENTER );
985
+ lineEndingLabel2 .setBorder (BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 ));
986
+
987
+ lineEndingLabel2 .setHorizontalAlignment (javax .swing .SwingConstants .LEFT );
988
+ JPanel headerPanel2 = new JPanel (new BorderLayout ());
989
+
990
+ JLabel filler2 = new JLabel ();
991
+ headerPanel2 .add (lineEndingLabel2 , BorderLayout .WEST );
992
+ headerPanel2 .add (fileLabel2 , BorderLayout .CENTER );
993
+ headerPanel2 .add (filler2 , BorderLayout .EAST );
953
994
filePanel2 .setLayout (new BorderLayout ());
954
- filePanel2 .add (fileLabel2 , BorderLayout .PAGE_START );
995
+ filePanel2 .add (headerPanel2 , BorderLayout .PAGE_START );
955
996
956
997
textualPanel .setLayout (new BorderLayout ());
957
998
@@ -1518,6 +1559,17 @@ public void run() {
1518
1559
support .firePropertyChange (DiffController .PROP_DIFFERENCES , null , null );
1519
1560
jEditorPane1 .setCurrentDiff (diffs );
1520
1561
jEditorPane2 .setCurrentDiff (diffs );
1562
+
1563
+ String lineEnding1 = detectLineEnding (jEditorPane1 );
1564
+ String lineEnding2 = detectLineEnding (jEditorPane2 );
1565
+
1566
+ boolean showLineEnding = lineEnding1 != null && lineEnding2 != null && !lineEnding1 .equals (lineEnding2 );
1567
+
1568
+ if (showLineEnding ) {
1569
+ lineEndingLabel1 .setText ("<html><strong style='background-color: " + String .format ("#%02x%02x%02x" , colorChanged .getRed (), colorChanged .getGreen (), colorChanged .getBlue ()) + "'>" + lineEnding1 + "</strong></html>" );
1570
+ lineEndingLabel2 .setText ("<html><strong style='background-color: " + String .format ("#%02x%02x%02x" , colorChanged .getRed (), colorChanged .getGreen (), colorChanged .getBlue ()) + "'>" + lineEnding2 + "</strong></html>" );
1571
+ }
1572
+
1521
1573
refreshDividerSize ();
1522
1574
view .repaint ();
1523
1575
diffMarkprovider .refresh ();
0 commit comments