Author: rwhitcomb
Date: Fri Nov 15 04:43:47 2013
New Revision: 1542171

URL: http://svn.apache.org/r1542171
Log:
PIVOT-930: Show tooltip over file names in a file browser so long file names
can be completely seen.

This is a merge of revision 1542170 from branches/2.0.x to trunk.


Modified:
    pivot/trunk/   (props changed)
    
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java

Propchange: pivot/trunk/
------------------------------------------------------------------------------
  Merged /pivot/branches/2.0.x:r1542170

Modified: 
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java?rev=1542171&r1=1542170&r2=1542171&view=diff
==============================================================================
--- 
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
 (original)
+++ 
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
 Fri Nov 15 04:43:47 2013
@@ -47,8 +47,10 @@ import org.apache.pivot.wtk.ButtonPressL
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.ComponentKeyListener;
 import org.apache.pivot.wtk.ComponentMouseButtonListener;
+import org.apache.pivot.wtk.ComponentTooltipListener;
 import org.apache.pivot.wtk.Container;
 import org.apache.pivot.wtk.Dimensions;
+import org.apache.pivot.wtk.Display;
 import org.apache.pivot.wtk.FileBrowser;
 import org.apache.pivot.wtk.FocusTraversalDirection;
 import org.apache.pivot.wtk.GridPane;
@@ -72,8 +74,10 @@ import org.apache.pivot.wtk.TableView;
 import org.apache.pivot.wtk.TableViewSelectionListener;
 import org.apache.pivot.wtk.TableViewSortListener;
 import org.apache.pivot.wtk.TaskAdapter;
+import org.apache.pivot.wtk.TextArea;
 import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.TextInputContentListener;
+import org.apache.pivot.wtk.Tooltip;
 import org.apache.pivot.wtk.VerticalAlignment;
 import org.apache.pivot.wtk.media.Image;
 import org.apache.pivot.wtk.skin.FileBrowserSkin;
@@ -912,6 +916,58 @@ public class TerraFileBrowserSkin extend
         });
 
         fileTableView.setSort(TableViewFileRenderer.NAME_KEY, 
SortDirection.ASCENDING);
+        fileTableView.getComponentTooltipListeners().add(new 
ComponentTooltipListener() {
+
+            @Override
+            public void tooltipTriggered(Component component, int x, int y) {
+
+                // Check that we are on the first column.
+                if (fileTableView.getColumnAt(x) != 0) {
+                    return;
+                }
+
+                // Gets the underlying file
+                File file = (File) 
fileTableView.getTableData().get(fileTableView.getRowAt(y));
+
+                // Construct and show the tooltip.
+                final Tooltip tooltip = new Tooltip();
+
+                String text = null;
+
+                if (file != null){
+                    text = text = file.getName();
+                }
+
+                if (text == null || text.isEmpty()) {
+                    return;
+                }
+
+                TextArea toolTipTextArea = new TextArea();
+
+                toolTipTextArea.setText(text);
+                toolTipTextArea.getStyles().put("wrapText", true);
+
+                tooltip.setContent(toolTipTextArea);
+
+                Point location = component.getDisplay().getMouseLocation();
+                x = location.x;
+                y = location.y;
+
+                // Ensure that the tooltip stays on screen
+                Display display = component.getDisplay();
+                int tooltipHeight = tooltip.getPreferredHeight();
+                if (y + tooltipHeight > display.getHeight()) {
+                    y -= tooltipHeight;
+                }
+
+                int tooltipXOffset = 16;
+                int padding = 15;
+
+                toolTipTextArea.setMaximumWidth(display.getWidth() - ( x + 
tooltipXOffset + padding) );
+                tooltip.setLocation(x + tooltipXOffset, y);
+                tooltip.open(component.getWindow());
+            }
+        });
 
         rootDirectoryChanged(fileBrowser, null);
         selectedFilesChanged(fileBrowser, null);


Reply via email to