6464import org .netbeans .api .editor .mimelookup .MimeLookup ;
6565import org .netbeans .api .editor .settings .FontColorNames ;
6666import org .netbeans .api .editor .settings .FontColorSettings ;
67+ import org .netbeans .editor .BaseDocument ;
6768import org .netbeans .editor .BaseTextUI ;
6869import org .netbeans .spi .diff .DiffProvider ;
6970import org .netbeans .spi .diff .DiffControllerImpl ;
7071import org .netbeans .editor .EditorUI ;
7172import org .netbeans .lib .editor .util .swing .DocumentUtilities ;
7273import org .netbeans .modules .diff .builtin .visualizer .TextDiffVisualizer ;
74+ import static org .netbeans .modules .editor .errorstripe .privatespi .MarkProvider .PROP_MARKS ;
7375import org .openide .DialogDisplayer ;
7476import org .openide .NotifyDescriptor ;
7577import org .openide .text .NbDocument ;
@@ -122,6 +124,8 @@ public class EditableDiffView extends DiffControllerImpl implements DiffView, Do
122124
123125 final JLabel fileLabel1 = new JLabel ();
124126 final JLabel fileLabel2 = new JLabel ();
127+ final JLabel lineEndingLabel1 = new JLabel ();
128+ final JLabel lineEndingLabel2 = new JLabel ();
125129 final JPanel filePanel1 = new JPanel ();
126130 final JPanel filePanel2 = new JPanel ();
127131 final JPanel textualPanel = new JPanel ();
@@ -166,6 +170,7 @@ public class EditableDiffView extends DiffControllerImpl implements DiffView, Do
166170 private final Object DIFFING_LOCK = new Object ();
167171 private final String name1 ;
168172 private final String name2 ;
173+
169174 private boolean sourcesInitialized ;
170175 private boolean viewAdded ;
171176 private boolean addedToHierarchy ;
@@ -181,6 +186,7 @@ public EditableDiffView(final StreamSource ss1, final StreamSource ss2, boolean
181186 if (title1 == null ) title1 = NbBundle .getMessage (EditableDiffView .class , "CTL_DiffPanel_NoTitle" ); // NOI18N
182187 String title2 = ss2 .getTitle ();
183188 if (title2 == null ) title2 = NbBundle .getMessage (EditableDiffView .class , "CTL_DiffPanel_NoTitle" ); // NOI18N
189+
184190 String mimeType1 = ss1 .getMIMEType ();
185191 String mimeType2 = ss2 .getMIMEType ();
186192 name1 = ss1 .getName ();
@@ -237,7 +243,7 @@ public void removeNotify () {
237243 view .getAccessibleContext ().setAccessibleName (org .openide .util .NbBundle .getMessage (EditableDiffView .class , "ACS_DiffPanelA11yName" )); // NOI18N
238244 view .getAccessibleContext ().setAccessibleDescription (org .openide .util .NbBundle .getMessage (EditableDiffView .class , "ACS_DiffPanelA11yDesc" )); // NOI18N
239245 initializeTabPane (ss1 , ss2 );
240-
246+
241247 setSourceTitle (fileLabel1 , title1 );
242248 setSourceTitle (fileLabel2 , title2 );
243249
@@ -372,6 +378,24 @@ public void run () {
372378 }
373379 }
374380
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+
375399 private void initializeTabPane (StreamSource ss1 , StreamSource ss2 ) {
376400 if (jTabbedPane != null ) {
377401 jTabbedPane .addTab (org .openide .util .NbBundle .getMessage (EditableDiffView .class , "EditableDiffView.viewGraphical.title" ), jSplitPane1 ); //NOI18N
@@ -939,19 +963,36 @@ public void run () {
939963 // scroll the left pane accordingly
940964 manager .scroll (index == diffs .length - 1 || index == 0 );
941965 }
942-
966+
943967 /** This method is called from within the constructor to initialize the form.
944968 */
945969 private void initComponents () {
946970 fileLabel1 .setBorder (BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 ));
947971 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 );
948980 filePanel1 .setLayout (new BorderLayout ());
949- filePanel1 .add (fileLabel1 , BorderLayout .PAGE_START );
981+ filePanel1 .add (headerPanel1 , BorderLayout .PAGE_START );
950982
951983 fileLabel2 .setBorder (BorderFactory .createEmptyBorder (4 , 4 , 4 , 4 ));
952984 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 );
953994 filePanel2 .setLayout (new BorderLayout ());
954- filePanel2 .add (fileLabel2 , BorderLayout .PAGE_START );
995+ filePanel2 .add (headerPanel2 , BorderLayout .PAGE_START );
955996
956997 textualPanel .setLayout (new BorderLayout ());
957998
@@ -1518,6 +1559,17 @@ public void run() {
15181559 support .firePropertyChange (DiffController .PROP_DIFFERENCES , null , null );
15191560 jEditorPane1 .setCurrentDiff (diffs );
15201561 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+
15211573 refreshDividerSize ();
15221574 view .repaint ();
15231575 diffMarkprovider .refresh ();
0 commit comments