示例#1
0
 public NodeDisplay() {
   super(new BorderLayout());
   // setPreferredSize(new Dimension(300, 300));
   editorPane = new JEditorPane();
   editorPane.setEditorKit(new HTMLEditorKit());
   add(new JScrollPane(editorPane), BorderLayout.CENTER);
 }
 /**
  * Called when the selection changed in the tree. Loads the selected certificate.
  *
  * @param e the event
  */
 private void valueChangedPerformed(TreeSelectionEvent e) {
   Object o = e.getNewLeadSelectionPath().getLastPathComponent();
   if (o instanceof DefaultMutableTreeNode) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
     infoTextPane.setText(toString(node.getUserObject()));
   }
 }
示例#3
0
 public void display(CavityDBObject obj) {
   String str = obj.asString();
   // System.out.println(String.format("Displaying:\n%s", str));
   editorPane.setText(str);
   revalidate();
 }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }
示例#5
0
  /** Construct a new Help panel */
  public HelpPanel() {
    // Try to build our help tree, keeping an eye out for malformed URLs
    try {
      // root node
      top = new DefaultMutableTreeNode(new HelpItem("MIDIMatrix", "top"));

      // matrices node
      category = new DefaultMutableTreeNode(new HelpItem("Matrices", "matrices"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Note Entry", "matrices-noteentry")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Pitches, volume, and instruments", "matrices-metadata")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "matrices-playback")));

      // sequences node
      category = new DefaultMutableTreeNode(new HelpItem("Sequences", "sequences"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("Parts of a sequence", "sequences-parts")));
      category.add(
          new DefaultMutableTreeNode(
              new HelpItem("Constructing a sequence", "sequences-construction")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Playback", "sequences-playback")));

      // controls node
      category = new DefaultMutableTreeNode(new HelpItem("Controls", "controls"));
      top.add(category);
      category.add(
          new DefaultMutableTreeNode(new HelpItem("MIDI devices", "controls-mididevices")));
      category.add(new DefaultMutableTreeNode(new HelpItem("Saving", "controls-saving")));

      // about node
      category = new DefaultMutableTreeNode(new HelpItem("About", "about"));
      top.add(category);
      category.add(new DefaultMutableTreeNode(new HelpItem("Author", "about-author")));
      category.add(new DefaultMutableTreeNode(new HelpItem("License", "about-license")));

      // javadoc node
      // category = new DefaultMutableTreeNode(new HelpItem("JavaDoc", base + "javadoc/"));
      // top.add(category);
    } catch (MalformedURLException e) {
      top = new DefaultMutableTreeNode("ERROR");
    }
    helpTree = new JTree(top);
    helpTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    helpTree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) helpTree.getLastSelectedPathComponent();
            if (node == null) {
              return;
            }
            // try {
            helpPane.scrollToReference(((HelpItem) node.getUserObject()).getHash());
            /*} catch (IOException exc) {

                JOptionPane.showMessageDialog(
                        null,
                        "There was a problem fetching the help page " + exc.getMessage() + "\n" +
                        "Make sure you're connected to the internet before continuing",
                        "Help Oops!",
                        JOptionPane.ERROR_MESSAGE,
                        null);
            }*/
          }
        });

    treePane = new JScrollPane(helpTree);
    treePane.setPreferredSize(new Dimension(200, 750));

    helpPane = new JEditorPane();
    scroller = new JScrollPane(helpPane);
    helpPane.setEditable(false);
    helpPane.setPreferredSize(new Dimension(550, 750));
    helpPane.addHyperlinkListener(
        new HyperlinkListener() {

          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              JEditorPane pane = (JEditorPane) e.getSource();
              if (e instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
                HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
                if (e.getDescription().indexOf("#") != -1) {
                  System.err.println("Found anchor");
                  pane.scrollToReference(
                      e.getDescription().substring(e.getDescription().indexOf("#")));
                }
              } else {
                try {
                  pane.setPage(e.getURL());
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            }
          }
        });
    try {
      helpPane.setPage(HelpPanel.class.getResource("help.xhtml"));
    } catch (IOException e) {
      helpPane.setText("Couldn't fetch help page, sorry!  " + e.getMessage());
    }

    content = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    content.add(treePane);
    content.add(scroller);

    add(content);
  }