private static Component createDescription(Example example, ExampleGroup group) { Color foreground = group.getPreferredForeground(); WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING); titleLabel.setDrawShade(true); titleLabel.setForeground(foreground); if (foreground.equals(Color.WHITE)) { titleLabel.setShadeColor(Color.BLACK); } if (example.getDescription() == null) { return titleLabel; } else { WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING); descriptionLabel.setForeground(Color.GRAY); SwingUtils.changeFontSize(descriptionLabel, -1); WebPanel vertical = new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false)); vertical.setOpaque(false); vertical.add(titleLabel); vertical.add(descriptionLabel); return vertical; } }
/** * Update the display to show the information about the specified example. * * @param example the currently-selected example */ private void display(Example example) { if (example == null) { tabbedPane.removeAll(); runButton.setEnabled(false); } else { tabbedPane.removeAll(); JEditorPane description = new JEditorPane(); description.setContentType("text/html"); description.setText(example.getDescription()); description.setEditable(false); description.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent hle) { if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(hle.getURL().toURI()); } catch (Exception ex) { // unable to launch browser } } } }); tabbedPane.addTab("Description", description); for (String resource : example.getResources()) { try { RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60); if (resource.endsWith(".java")) { textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); } else { textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); } textArea.setCodeFoldingEnabled(true); textArea.setText(load(resource)); textArea.setSelectionStart(0); textArea.setSelectionEnd(0); textArea.setEditable(false); RTextScrollPane sp = new RTextScrollPane(textArea); tabbedPane.addTab(new File(resource).getName(), sp); } catch (IOException ex) { ex.printStackTrace(); } } if (example.getMainClass() == null) { runButton.setEnabled(false); } else { runButton.setEnabled(true); } } }