MCPcopy Create free account
hub / github.com/Syncleus/aparapi / SwingDiff

Method SwingDiff

src/test/java/com/aparapi/codegen/SwingDiff.java:82–154  ·  view source on GitHub ↗
(Diff.DiffResult result)

Source from the content-addressed store, hash-verified

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();

Callers

nothing calls this directly

Calls 4

arrayToStringMethod · 0.95
getLhsMethod · 0.65
getRhsMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected