(Diff.DiffResult result)
| 80 | JFrame frame; |
| 81 | |
| 82 | public SwingDiff(Diff.DiffResult result) { |
| 83 | try { |
| 84 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 85 | |
| 86 | frame = new JFrame("SwingDiff"); |
| 87 | |
| 88 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
| 89 | JPanel panel = new JPanel(){ |
| 90 | @Override public void paint(Graphics g) { |
| 91 | super.paint(g); |
| 92 | g.drawRect(10, 10, 100, 100); |
| 93 | } |
| 94 | }; |
| 95 | panel.setLayout(new BorderLayout()); |
| 96 | |
| 97 | StyleContext sc = new StyleContext(); |
| 98 | |
| 99 | // Create and add the style |
| 100 | final Style rootStyle = sc.addStyle("Root", null); |
| 101 | rootStyle.addAttribute(StyleConstants.Foreground, Color.black); |
| 102 | rootStyle.addAttribute(StyleConstants.FontSize, new Integer(12)); |
| 103 | rootStyle.addAttribute(StyleConstants.FontFamily, "serif"); |
| 104 | rootStyle.addAttribute(StyleConstants.Bold, new Boolean(false)); |
| 105 | final Style heading1Style = sc.addStyle("Heading1", rootStyle); |
| 106 | heading1Style.addAttribute(StyleConstants.Foreground, Color.blue); |
| 107 | |
| 108 | final Style heading2Style = sc.addStyle("Heading2", rootStyle); |
| 109 | heading2Style.addAttribute(StyleConstants.Foreground, Color.red); |
| 110 | heading2Style.addAttribute(StyleConstants.Background, Color.green); |
| 111 | |
| 112 | final DefaultStyledDocument lhsdoc = new DefaultStyledDocument(sc); |
| 113 | JTextPane lhs = new JTextPane(lhsdoc); |
| 114 | |
| 115 | lhsdoc.insertString(0, arrayToString(result.getLhs()), null); |
| 116 | |
| 117 | // Finally, apply the style to the heading |
| 118 | |
| 119 | lhsdoc.setParagraphAttributes(4, 1, heading2Style, false); |
| 120 | lhsdoc.setParagraphAttributes(20, 5, heading1Style, false); |
| 121 | |
| 122 | lhs.setPreferredSize(new Dimension(800, 800)); |
| 123 | final DefaultStyledDocument rhsdoc = new DefaultStyledDocument(sc); |
| 124 | JTextPane rhs = new JTextPane(rhsdoc); |
| 125 | rhsdoc.insertString(0, arrayToString(result.getRhs()), null); |
| 126 | |
| 127 | rhsdoc.setParagraphAttributes(4, 1, heading2Style, false); |
| 128 | rhsdoc.setParagraphAttributes(20, 5, heading1Style, false); |
| 129 | rhs.setPreferredSize(new Dimension(800, 800)); |
| 130 | panel.add(new JScrollPane(lhs), BorderLayout.WEST); |
| 131 | panel.add(new JScrollPane(rhs), BorderLayout.EAST); |
| 132 | |
| 133 | // frame.setBackground(background); |
| 134 | frame.getContentPane().add(panel); |
| 135 | frame.pack(); |
| 136 | frame.setVisible(true); |
| 137 | } catch (ClassNotFoundException e) { |
| 138 | // TODO Auto-generated catch block |
| 139 | e.printStackTrace(); |
nothing calls this directly
no test coverage detected