]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix column width issues on HiDPI displays. KeyTiSelection fixes. 83/1783/1
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 17 May 2018 11:14:53 +0000 (14:14 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 17 May 2018 11:14:53 +0000 (14:14 +0300)
gitlab #7

Change-Id: I03a51472f2e9d38a78e38b92617d0e9f975f6c54

bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/KeyToSelectionAdapter.java
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableColumnLayout.java
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableSelectionAdaptor.java
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/TreeNode.java

index 7e0202be37974204df55852aa43406b18773eaf7..9ededd52f1ac78d4cda87fcfbce1cea202ea3089 100644 (file)
@@ -35,20 +35,27 @@ public class KeyToSelectionAdapter extends KeyAdapter {
      * @param explorer
      */
     public KeyToSelectionAdapter(GraphExplorer explorer) {
+       this(explorer,"\\p{Alnum}");
+    }
+    
+    public KeyToSelectionAdapter(GraphExplorer explorer, String pattern) {
         assert explorer != null;
 
         this.explorer = (NatTableGraphExplorer)explorer;
-        this.alphaNum = Pattern.compile("\\p{Alnum}");
+        this.alphaNum = Pattern.compile(pattern);
     }
-
+    
+    public boolean acceptKey(char key) {
+       return alphaNum.matcher(Character.toString(key)).matches();
+    }
+    
     @Override
     public void keyPressed(KeyEvent e) {
        if (explorer.isDisposed())
             return;
 
-         
-         if (!alphaNum.matcher(Character.toString(e.character)).matches())
-                return;
+         if (!acceptKey(e.character))
+                return;
          // concatenate / replace matcher.
          if ((e.time - prevEvent) > KEY_INPUT_DELAY )
                 matcher = "";
@@ -70,8 +77,8 @@ public class KeyToSelectionAdapter extends KeyAdapter {
         }
         
         if (item != null) {
-                explorer.select(item);
                 explorer.show(item);
+                explorer.select(item);
                 } 
         // without this the default handling would take over.
         e.doit = false;
@@ -144,6 +151,8 @@ public class KeyToSelectionAdapter extends KeyAdapter {
      */
     protected boolean matchesColumn(TreeNode item, int column, String matcher) {
        String text = item.getValueString(column);
+       if (text == null)
+               return false;
                if (text.toLowerCase().startsWith(matcher)) {
                        return true;
                }
index 3bff312550d19a2ae40be7c3a0c4429669c2ca1e..2979ab8c1bc6db2448d57203446c92a9511299fe 100644 (file)
@@ -68,6 +68,13 @@ public class NatTableColumnLayout extends Layout implements ILayerListener{
        }
        
        protected void setColumnWidths(Scrollable tree, int[] widths) {
+               // NatTable HiDPI workaround
+               double displayScale = NatTableGraphExplorer.getDisplayScale();
+               if (displayScale != 1.0) {
+                       for (int i=0; i < widths.length; i++) {
+                               widths[i] = (int)Math.floor(((double)widths[i]/ displayScale));
+                       }
+               }
                for (int i=0; i < widths.length; i++) {
                        columnHeaderDataProvider.getDataLayer().setColumnWidthByPosition(i, widths[i]);
                }
index 2e9d5a1fce4504f726f7269aa0af733368349ebb..6765f65ead2e0a87877ee52c73f969b452bac0d6 100644 (file)
@@ -1506,7 +1506,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
     final ExecutorService                        queryUpdateScheduler = Threads.getExecutor();
     
     
-       private double getDisplayScale() {
+    public static double getDisplayScale() {
                Point dpi = Display.getCurrent().getDPI();
                return (double)dpi.x/96.0;
        }
index 8a37d048b918243cb082bfa483567912ac0a9b31..ec3cb221d0734bc520a6ba62f5bb5c66c1bb6a15 100644 (file)
@@ -107,8 +107,10 @@ public class NatTableSelectionAdaptor implements ISelectionProvider, IPostSelect
        private void setSelectionExternal(List<RowSelectionItem> items) {
                selectionLayer.clear(true);
                for (RowSelectionItem item : items) {
-                       for (int c : item.columnIndex)
-                               selectionLayer.selectCell(c, item.rowIndex, false, true);
+                       for (int c : item.columnIndex) {
+                               int r = selectionLayer.getRowPositionByIndex(item.rowIndex);
+                               selectionLayer.selectCell(c, r, false, true);
+                       }
                }
                selection = new StructuredSelection(items);
                fireEvents();
index 269966c30722b0834b965362a17536c1bda1100e..4f9273d9120cfd48547986b1fcb630120fe98582 100644 (file)
@@ -118,20 +118,33 @@ public class TreeNode implements IAdaptable {
                        initData();
                if (labeler != null) {
                        String key = explorerContext.getGe().getColumns()[column].getKey();
-                       String s = null;
-                       if (runtimeLabels != null)
-                               s = runtimeLabels.get(key);
-                       if (s == null)
-                               s = labels.get(key);
-                       if (labelDecorators != null && !labelDecorators.isEmpty()) {
-                               int index = 0;
-                               for (LabelDecorator ld : labelDecorators) {
-                                       String ds = ld.decorateLabel(s, key, index);
-                                       if (ds != null)
-                                               s = ds;
-                               }
+                       return getValue(key);
+               }
+               return null;
+       }
+       
+       private String getValue(String key) {
+               String s = null;
+               if (runtimeLabels != null)
+                       s = runtimeLabels.get(key);
+               if (s == null)
+                       s = labels.get(key);
+               if (labelDecorators != null && !labelDecorators.isEmpty()) {
+                       int index = 0;
+                       for (LabelDecorator ld : labelDecorators) {
+                               String ds = ld.decorateLabel(s, key, index);
+                               if (ds != null)
+                                       s = ds;
                        }
-                       return s;
+               }
+               return s;
+       }
+       
+       public String getValueString(String key) {
+               if (labels == null)
+                       initData();
+               if (labeler != null) {
+                       return getValue(key);
                }
                return null;
        }