matthiasblaesing commented on code in PR #8645: URL: https://github.com/apache/netbeans/pull/8645#discussion_r2240558338
########## ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/EditableDiffView.java: ########## @@ -122,13 +124,18 @@ public class EditableDiffView extends DiffControllerImpl implements DiffView, Do final JLabel fileLabel1 = new JLabel(); final JLabel fileLabel2 = new JLabel(); + final JLabel lineEndingLabel1 = new JLabel(); + final JLabel lineEndingLabel2 = new JLabel(); final JPanel filePanel1 = new JPanel(); final JPanel filePanel2 = new JPanel(); final JPanel textualPanel = new JPanel(); final JTabbedPane jTabbedPane; final JComponent view; final JSplitPane jSplitPane1 = new JSplitPane(); + private String lineEnding1; + private String lineEnding2; + Review Comment: These are not required. `lineEnding1` and `lineEnding2` are only required in `RefreshDiffTask#run` and thus can be declared there. ########## ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/EditableDiffView.java: ########## @@ -1518,6 +1587,20 @@ public void run() { support.firePropertyChange(DiffController.PROP_DIFFERENCES, null, null); jEditorPane1.setCurrentDiff(diffs); jEditorPane2.setCurrentDiff(diffs); + + lineEnding1 = detectLineEnding(source1); + lineEnding2 = detectLineEnding(source2); + + boolean showLineEnding = lineEnding1 != null && lineEnding2 != null && !lineEnding1.equals(lineEnding2); + + if(showLineEnding) { + lineEndingLabel1.setText("<html><strong style='background-color: " + String.format("#%02x%02x%02x", colorChanged.getRed(), colorChanged.getGreen(), colorChanged.getBlue()) + "'>" + lineEnding1 + "</strong></html>"); + lineEndingLabel2.setText("<html><strong style='background-color: " + String.format("#%02x%02x%02x", colorChanged.getRed(), colorChanged.getGreen(), colorChanged.getBlue()) + "'>" + lineEnding2 + "</strong></html>"); + } + + setSourceTitle(fileLabel1, title1); + setSourceTitle(fileLabel2, title2); Review Comment: This is exactly doing, what was already done in the constructor. Thus this can be removed. ########## ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/EditableDiffView.java: ########## @@ -177,10 +190,17 @@ public EditableDiffView (final StreamSource ss1, final StreamSource ss2) { public EditableDiffView(final StreamSource ss1, final StreamSource ss2, boolean enhancedView) { refreshDiffTask = rp.create(new RefreshDiffTask()); initColors(); - String title1 = ss1.getTitle(); - if (title1 == null) title1 = NbBundle.getMessage(EditableDiffView.class, "CTL_DiffPanel_NoTitle"); // NOI18N - String title2 = ss2.getTitle(); - if (title2 == null) title2 = NbBundle.getMessage(EditableDiffView.class, "CTL_DiffPanel_NoTitle"); // NOI18N + + source1 = ss1; + source2 = ss2; Review Comment: If the `DiffContentPanel`s are used, this can be removed. ########## ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/EditableDiffView.java: ########## @@ -166,6 +173,12 @@ public class EditableDiffView extends DiffControllerImpl implements DiffView, Do private final Object DIFFING_LOCK = new Object(); private final String name1; private final String name2; + + private final StreamSource source1; + private final StreamSource source2; + private final String title1; + private final String title2; + Review Comment: These are not required (see comments below). ########## ide/diff/src/org/netbeans/modules/diff/builtin/visualizer/editable/EditableDiffView.java: ########## @@ -372,6 +392,38 @@ public void run () { } } + private static String detectLineEnding(StreamSource source) { + try { + FileObject fo = source.getLookup().lookup(FileObject.class); + DataObject dao = DataObject.find(fo); + + EditorCookie editorCookie = dao.getCookie(EditorCookie.class); + if (editorCookie == null) { + return null; + } + + Document doc; + try { + doc = editorCookie.openDocument(); + } catch (IOException ex) { + return null; + } Review Comment: This will fail if the source is not backed by a file. If you pass in the `DiffContentPanel`, you can simplify this to: ```suggestion private static String detectLineEnding(DiffContentPanel source) { try { Document doc = source.getEditorPane().getDocument(); ``` The panels are directly available in `RefreshDiffTask#diff`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists