コード例 #1
0
  /**
   * Issue #242: CCE when setting icons. Not reproducible? Another issue: icon setting does not
   * repaint (with core default renderer) Does not work at all with SwingX renderer (not
   * surprisingly, the delegating renderer in JXTree looks for a core default to wrap). Think:
   * tree/table should trigger repaint?
   */
  public void interactiveTreeIcons() {
    final JXTree tree = new JXTree(treeTableModel);
    final Icon downIcon = XTestUtils.loadDefaultIcon("wellbottom.gif");
    final Icon upIcon = XTestUtils.loadDefaultIcon("welltop.gif");
    Action toggleClosedIcon =
        new AbstractAction("Toggle closed icon") {
          boolean down;

          public void actionPerformed(ActionEvent e) {
            if (down) {
              tree.setClosedIcon(downIcon);
            } else {
              tree.setClosedIcon(upIcon);
            }
            down = !down;
            // need to force - but shouldn't that be done in the
            // tree/table itself? and shouldn't the tree fire a
            // property change?
            tree.repaint();
          }
        };
    tree.setRowHeight(22);
    JXFrame frame = wrapWithScrollingInFrame(tree, "Toggle Tree icons ");
    addAction(frame, toggleClosedIcon);
    frame.setVisible(true);
  }
コード例 #2
0
 /**
  * Issue #601-swingx: allow LAF to hook in LAF provided renderers.
  *
  * <p>Unexpected: plain ol' tree doesn't install UIResource?
  */
 @Test
 public void testLAFRendererXTree() {
   JXTree tree = new JXTree();
   assertNotNull("default renderer installed", tree.getCellRenderer());
   assertTrue(
       "expected UIResource, but was: " + tree.getCellRenderer().getClass(),
       tree.getCellRenderer() instanceof UIResource);
 }
コード例 #3
0
 /**
  * Issue #1060-swingx: JXTree must update renderer
  *
  * <p>tree renderer not updated if set on the tree (as opposed to using the default set by the
  * ui-delegate)
  */
 public void interactiveUpdateUIXTreeXRenderer() {
   JXTree treeSetRenderer = new JXTree();
   treeSetRenderer
       .getModel()
       .valueForPathChanged(treeSetRenderer.getPathForRow(0), "x with renderer set");
   treeSetRenderer.setCellRenderer(new DefaultTreeRenderer());
   treeSetRenderer.setEditable(true);
   JXFrame frame =
       wrapWithScrollingInFrame(
           treeSetRenderer, "JXTree/x renderer: updateUI must update renderer/editor");
   addComponentOrientationToggle(frame);
   show(frame);
 }
コード例 #4
0
  /**
   * Size effecting decoration vs. initial config (in provider).
   *
   * <p>Decoration: use highlighter - works correctly only with largeModel (due to caching issues)
   *
   * <p>Config in Provider (usually not recommended): - override getRendererComponent, width always
   * correct, height only if enabled via setRowHeight(0)
   */
  public void interactiveBold() {
    JXTree tree = new JXTree();
    tree.setCellRenderer(new DefaultTreeRenderer());
    //        tree.setRowHeight(0);
    tree.setLargeModel(true);
    final Font bold = tree.getFont().deriveFont(Font.BOLD, 20f);
    Highlighter hl =
        new AbstractHighlighter(HighlightPredicate.IS_LEAF) {

          @Override
          protected Component doHighlight(Component component, ComponentAdapter adapter) {
            component.setFont(bold);
            return component;
          }
        };
    tree.addHighlighter(hl);
    JXTree treeP = new JXTree();
    treeP.setRowHeight(0);
    WrappingProvider provider =
        new WrappingProvider() {

          @Override
          public WrappingIconPanel getRendererComponent(CellContext context) {
            super.getRendererComponent(context);
            if (context.isLeaf()) {
              rendererComponent.setFont(bold);
            }
            return rendererComponent;
          }
        };
    treeP.setCellRenderer(new DefaultTreeRenderer(provider));
    showWithScrollingInFrame(tree, treeP, "bold font: decorate vs. config");
  }
コード例 #5
0
  /** use WrappingProvider: default icons */
  public void interactiveProviderStringValue() {
    final JXTree tree = new JXTree(treeTableModel);
    final StringValue sv =
        new StringValue() {

          public String getString(Object value) {
            if (value instanceof File) {
              return ((File) value).getName();
            }
            return StringValues.TO_STRING.getString(value);
          }
        };
    tree.setCellRenderer(new DefaultTreeRenderer(sv));
    tree.setRowHeight(22);
    JXFrame frame =
        wrapWithScrollingInFrame(tree, "Custom StringValue on WrappingProvider, default icons");
    //        addAction(frame, toggleClosedIcon);
    frame.setVisible(true);
  }
コード例 #6
0
  /** use WrappingProvider: custom icons */
  public void interactiveProviderIcons() {
    final JXTree tree = new JXTree(treeTableModel);
    final Icon downIcon = XTestUtils.loadDefaultIcon("wellbottom.gif");
    final Icon upIcon = XTestUtils.loadDefaultIcon("welltop.gif");
    final StringValue sv = StringValues.FILE_NAME;
    IconValue iv =
        new IconValue() {

          public Icon getIcon(Object value) {
            if (sv.getString(value).startsWith("A")) {
              return downIcon;
            } else if (sv.getString(value).startsWith("D")) {
              return upIcon;
            }
            return null;
          }
        };
    tree.setCellRenderer(new DefaultTreeRenderer(iv, sv));
    tree.setRowHeight(22);
    JXFrame frame = wrapWithScrollingInFrame(tree, "IconValue on WrappingProvider");
    //        addAction(frame, toggleClosedIcon);
    frame.setVisible(true);
  }
コード例 #7
0
 /** Issue ??-swingx: JXTree must update renderer share in other tree - okay */
 public void interactiveUpdateUIRendererOther() {
   JXTree tree = new JXTree();
   tree.setCellRenderer(sharedRenderer);
   showWithScrollingInFrame(tree, "updateUI must update renderer");
 }