Beispiel #1
0
 private static int getTreeBaseline(JTree tree, int height) {
   int rowHeight = tree.getRowHeight();
   if (TREE_LABEL == null) {
     TREE_LABEL = new JLabel("X");
     TREE_LABEL.setIcon(UIManager.getIcon("Tree.closedIcon"));
   }
   JLabel label = TREE_LABEL;
   label.setFont(tree.getFont());
   if (rowHeight <= 0) {
     rowHeight = label.getPreferredSize().height;
   }
   return getLabelBaseline(label, rowHeight) + tree.getInsets().top;
 }
  public MetalworksInBox() {
    super("In Box", true, true, true, true);

    DefaultMutableTreeNode unread;
    DefaultMutableTreeNode personal;
    DefaultMutableTreeNode business;
    DefaultMutableTreeNode spam;

    DefaultMutableTreeNode top = new DefaultMutableTreeNode("Mail Boxes");

    top.add(unread = new DefaultMutableTreeNode("Unread Mail"));
    top.add(personal = new DefaultMutableTreeNode("Personal"));
    top.add(business = new DefaultMutableTreeNode("Business"));
    top.add(spam = new DefaultMutableTreeNode("Spam"));

    unread.add(new DefaultMutableTreeNode("Buy Stuff Now"));
    unread.add(new DefaultMutableTreeNode("Read Me Now"));
    unread.add(new DefaultMutableTreeNode("Hot Offer"));
    unread.add(new DefaultMutableTreeNode("Re: Re: Thank You"));
    unread.add(new DefaultMutableTreeNode("Fwd: Good Joke"));

    personal.add(new DefaultMutableTreeNode("Hi"));
    personal.add(new DefaultMutableTreeNode("Good to hear from you"));
    personal.add(new DefaultMutableTreeNode("Re: Thank You"));

    business.add(new DefaultMutableTreeNode("Thanks for your order"));
    business.add(new DefaultMutableTreeNode("Price Quote"));
    business.add(new DefaultMutableTreeNode("Here is the invoice"));
    business.add(new DefaultMutableTreeNode("Project Metal: delivered on time"));
    business.add(new DefaultMutableTreeNode("Your salary raise approved"));

    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Make $$$ Now"));
    spam.add(new DefaultMutableTreeNode("HOT HOT HOT"));
    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Don't Miss This"));
    spam.add(new DefaultMutableTreeNode("Opportunity in Precious Metals"));
    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Last Chance"));
    spam.add(new DefaultMutableTreeNode("Buy Now"));
    spam.add(new DefaultMutableTreeNode("Make $$$ Now"));
    spam.add(new DefaultMutableTreeNode("To Hot To Handle"));
    spam.add(new DefaultMutableTreeNode("I'm waiting for your call"));

    JTree tree = new JTree(top);
    JScrollPane treeScroller = new JScrollPane(tree);
    treeScroller.setBackground(tree.getBackground());
    setContentPane(treeScroller);
    setSize(325, 200);
    setLocation(75, 75);
  }
Beispiel #3
0
 private JComponent makeTitledPanel(String title, JTree tree) {
   JPanel p = new JPanel(new BorderLayout());
   p.setBorder(BorderFactory.createTitledBorder(title));
   p.add(new JScrollPane(tree));
   tree.setRowHeight(0);
   return p;
 }
Beispiel #4
0
  public SwingDnDFrame() {
    setTitle("SwingDnDTest");
    JTabbedPane tabbedPane = new JTabbedPane();

    JList list = SampleComponents.list();
    tabbedPane.addTab("List", list);
    JTable table = SampleComponents.table();
    tabbedPane.addTab("Table", table);
    JTree tree = SampleComponents.tree();
    tabbedPane.addTab("Tree", tree);
    JFileChooser fileChooser = new JFileChooser();
    tabbedPane.addTab("File Chooser", fileChooser);
    JColorChooser colorChooser = new JColorChooser();
    tabbedPane.addTab("Color Chooser", colorChooser);

    final JTextArea textArea = new JTextArea(4, 40);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here"));

    JTextField textField = new JTextField("Drag color here");
    textField.setTransferHandler(new TransferHandler("background"));

    tabbedPane.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            textArea.setText("");
          }
        });

    tree.setDragEnabled(true);
    table.setDragEnabled(true);
    list.setDragEnabled(true);
    fileChooser.setDragEnabled(true);
    colorChooser.setDragEnabled(true);
    textField.setDragEnabled(true);

    add(tabbedPane, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(textField, BorderLayout.SOUTH);
    pack();
  }
  /**
   * 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);
  }