~ubuntu-branches/ubuntu/trusty/libswingx-java/trusty

« back to all changes in this revision

Viewing changes to src/java/org/jdesktop/swingx/JXTreeTable.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-11-02 00:17:00 UTC
  • mfrom: (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091102001700-j5k1sy0wdtsp63re
Tags: 1:1.0-1
* New upstream release.
* New "libswingx-java-doc" package:
  - contains API javadoc documentation
* Bump Standards-Version to 3.8.3
  - Change section to "java"
  - Rename debian/README.Debian-source to debian/README.source
  - Describe quilt patch system in debian/README.source
* Bump debhelper version to >= 7
* Remove unused Depends on ${shlibs:Depends}
* Default JRE:
  - Build-Depends on default-jdk
  - Use /usr/lib/jvm/default-java as JAVA_HOME
* Add myself to Uploaders
* Use DEP5 format for debian/copyright
* Maven POMs:
  - Add a Build-Depends-Indep dependency on maven-repo-helper
  - Use mh_installpoms and mh_installjar to install the POM and the jar to the
    Maven repository
  - Remove unneeded dependencies in pom.diff patch
* Maven ant helper (build system):
  - Add a Build-Depends dependency on maven-ant-helper
  - Update debian/build.xml to use /usr/share/maven-ant-helper/maven-build.xml
  - Build classpath is now defined in debian/build.properties

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: JXTreeTable.java,v 1.106 2008/10/14 22:32:49 rah003 Exp $
 
2
 * $Id: JXTreeTable.java,v 1.110 2009/03/20 15:41:31 kleopatra Exp $
3
3
 *
4
4
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5
5
 * Santa Clara, California 95054, U.S.A. All rights reserved.
70
70
import org.jdesktop.swingx.decorator.ComponentAdapter;
71
71
import org.jdesktop.swingx.decorator.FilterPipeline;
72
72
import org.jdesktop.swingx.decorator.SelectionMapper;
 
73
import org.jdesktop.swingx.renderer.StringValue;
 
74
import org.jdesktop.swingx.renderer.StringValues;
73
75
import org.jdesktop.swingx.rollover.RolloverProducer;
74
76
import org.jdesktop.swingx.rollover.RolloverRenderer;
 
77
import org.jdesktop.swingx.tree.DefaultXTreeCellRenderer;
75
78
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
76
79
import org.jdesktop.swingx.treetable.TreeTableCellEditor;
77
80
import org.jdesktop.swingx.treetable.TreeTableModel;
444
447
        }
445
448
 
446
449
        /**
447
 
         * Complete editing if collapsed/expanded.<p>
448
 
         * 
449
 
         * Is: first try to stop editing before falling back to cancel.<p>
450
 
         * This is part of fix for #730-swingx - editingStopped not always called.
451
 
         * The other part is to call this from the renderer before
452
 
         * expansion related state has changed. <p>
453
 
         * 
454
 
         * Was: any editing is always cancelled. <p>
455
 
         * This is a rude fix to #120-jdnc: data corruption on
456
 
         * collapse/expand if editing. This is called from 
457
 
         * the renderer after expansion related state has changed.
458
 
         *
 
450
         * Complete editing if collapsed/expanded.
 
451
         * <p>
 
452
         * 
 
453
         * Is: first try to stop editing before falling back to cancel.
 
454
         * <p>
 
455
         * This is part of fix for #730-swingx - editingStopped not always
 
456
         * called. The other part is to call this from the renderer before
 
457
         * expansion related state has changed.
 
458
         * <p>
 
459
         * 
 
460
         * Was: any editing is always cancelled.
 
461
         * <p>
 
462
         * This is a rude fix to #120-jdnc: data corruption on collapse/expand
 
463
         * if editing. This is called from the renderer after expansion related
 
464
         * state has changed.
 
465
         * 
459
466
         */
460
467
        protected void completeEditing() {
461
468
            if (isEditing()) {
462
469
                boolean success = getCellEditor().stopCellEditing();
463
470
                if (!success) {
464
 
                getCellEditor().cancelCellEditing();
465
 
             }
466
 
//                getCellEditor().cancelCellEditing();
467
 
        }
 
471
                    getCellEditor().cancelCellEditing();
 
472
                }
 
473
            }
468
474
        }
469
475
 
470
476
        /**
627
633
                    || me.getModifiers() == InputEvent.BUTTON1_MASK) {
628
634
                // compute where the mouse point is relative to the tree
629
635
                // renderer
630
 
                Point treeMousePoint = new Point(me.getX()
631
 
                        - getCellRect(0, column, false).x, me.getY());
 
636
                Point treeMousePoint = getTreeMousePoint(column, me);
632
637
                int treeRow = renderer.getRowForLocation(treeMousePoint.x,
633
638
                        treeMousePoint.y);
634
639
                int row = 0;
672
677
            expansionChangedFlag = false;
673
678
            return changedExpansion;
674
679
        }
 
680
 
 
681
        /**
 
682
         * This is a patch provided for Issue #980-swingx which should
 
683
         * improve the bidi-compliance. Still doesn't work in our 
 
684
         * visual tests...
 
685
         * 
 
686
         * @param column the column index under the event, if any.
 
687
         * @param e the event which might trigger a expand/collapse.
 
688
         * @return the Point adjusted for bidi
 
689
         */
 
690
        protected Point getTreeMousePoint(int column, MouseEvent me) {
 
691
//            return new Point(me.getX()
 
692
//                    - getCellRect(0, column, false).x, me.getY());
 
693
            Rectangle tableCellRect = getCellRect(0, column, false);
 
694
           
 
695
            if( getComponentOrientation().isLeftToRight() ) {
 
696
                return new Point(me.getX() - tableCellRect.x, me.getY());
 
697
            }
 
698
 
 
699
            int x = (me.getX() - tableCellRect.x) - tableCellRect.width - 10;
 
700
            return new Point(x, me.getY());
 
701
        }
675
702
    }
676
703
    
677
704
    /**
1650
1677
        return super.getCellEditor(row, column);
1651
1678
    }
1652
1679
    
 
1680
    
 
1681
    @Override
 
1682
    public void updateUI() {
 
1683
        super.updateUI();
 
1684
        updateHierarchicalRendererEditor();
 
1685
    }
 
1686
 
 
1687
    /**
 
1688
     * Updates Ui of renderer/editor for the hierarchical column. Need to do so
 
1689
     * manually, as not accessible by the default lookup.
 
1690
     */
 
1691
    protected void updateHierarchicalRendererEditor() {
 
1692
        if (renderer != null) {
 
1693
           SwingUtilities.updateComponentTreeUI(renderer);
 
1694
        }
 
1695
    }
 
1696
 
1653
1697
    /**
1654
1698
     * {@inheritDoc} <p>
1655
1699
     * 
2543
2587
            return this;
2544
2588
        }
2545
2589
 
2546
 
        private class ClippedTreeCellRenderer extends DefaultTreeCellRenderer {
 
2590
        private class ClippedTreeCellRenderer extends DefaultXTreeCellRenderer 
 
2591
            implements StringValue 
 
2592
            {
2547
2593
            @SuppressWarnings("unused")
2548
2594
            private boolean inpainting;
2549
2595
            private String shortText;
2550
2596
            @Override
2551
2597
            public void paint(Graphics g) {
2552
2598
                String fullText = super.getText();
2553
 
                // getText() calls tree.convertValueToText();
2554
 
                // tree.convertValueToText() should call treeModel.convertValueToText(), if possible
2555
2599
        
2556
2600
                 shortText = SwingUtilities.layoutCompoundLabel(
2557
2601
                    this, g.getFontMetrics(), fullText, getIcon(),
2586
2630
 
2587
2631
            @Override
2588
2632
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
2589
 
                Object val = value;
 
2633
                return super.getTreeCellRendererComponent(tree, getHierarchicalTableValue(value), sel, expanded, leaf,
 
2634
                        row, hasFocus);
 
2635
            }
 
2636
 
 
2637
 
 
2638
            /**
 
2639
             * 
 
2640
             * @param node the node in the treeModel as passed into the TreeCellRenderer
 
2641
             * @return the corresponding value of the hierarchical cell in the TreeTableModel
 
2642
             */
 
2643
            private Object getHierarchicalTableValue(Object node) {
 
2644
                Object val = node;
2590
2645
                
2591
2646
                if (treeTable != null) {
2592
2647
                    int treeColumn = treeTable.getTreeTableModel().getHierarchicalColumn();
2593
2648
                    Object o = null; 
2594
 
//                    LOG.info("value ? " + value);
2595
2649
                    if (treeColumn >= 0) {
2596
2650
                        // following is unreliable during a paint cycle
2597
2651
                        // somehow interferes with BasicTreeUIs painting cache
2600
2654
                        // might blow if the TreeTableModel is strict in
2601
2655
                        // checking the containment of the value and 
2602
2656
                        // this renderer is called for sizing with a prototype
2603
 
                        o = treeTable.getTreeTableModel().getValueAt(value, treeColumn);
 
2657
                        o = treeTable.getTreeTableModel().getValueAt(node, treeColumn);
2604
2658
                    }
2605
 
//                    LOG.info("value ? " + value);
2606
 
                    // JW: why this? null may be a valid value? 
2607
 
                    // removed - didn't see it after asking the model
2608
 
//                    if (o != null) {
2609
 
//                        val = o;
2610
 
//                    }
2611
2659
                    val = o;
2612
2660
                }
2613
 
                
2614
 
                return super.getTreeCellRendererComponent(tree, val, sel, expanded, leaf,
2615
 
                        row, hasFocus);
 
2661
                return val;
 
2662
            }
 
2663
 
 
2664
            /**
 
2665
             * {@inheritDoc} <p>
 
2666
             */
 
2667
            public String getString(Object node) {
 
2668
//                int treeColumn = treeTable.getTreeTableModel().getHierarchicalColumn();
 
2669
//                if (treeColumn >= 0) {
 
2670
//                    return StringValues.TO_STRING.getString(treeTable.getTreeTableModel().getValueAt(value, treeColumn));
 
2671
//                }
 
2672
                return StringValues.TO_STRING.getString(getHierarchicalTableValue(node));
2616
2673
            }
2617
2674
 
2618
2675
            // Rectangles filled in by SwingUtilities.layoutCompoundLabel();