create new UI in UiDesigner
authorAlexander Marchuk <Alexander.Marchuk@jetbrains.com>
Wed, 17 Sep 2014 08:46:31 +0000 (12:46 +0400)
committerAlexander Marchuk <Alexander.Marchuk@jetbrains.com>
Wed, 17 Sep 2014 08:46:31 +0000 (12:46 +0400)
python/src/com/jetbrains/python/actions/view/array/ArrayTableForm.form [new file with mode: 0644]
python/src/com/jetbrains/python/actions/view/array/ArrayTableForm.java [new file with mode: 0644]
python/src/com/jetbrains/python/actions/view/array/NumpyArrayPresentation.java
python/src/com/jetbrains/python/actions/view/array/NumpyArrayValueProvider.java
python/src/com/jetbrains/python/actions/view/array/PyViewArrayAction.java

diff --git a/python/src/com/jetbrains/python/actions/view/array/ArrayTableForm.form b/python/src/com/jetbrains/python/actions/view/array/ArrayTableForm.form
new file mode 100644 (file)
index 0000000..99afc8c
--- /dev/null
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.actions.view.array.ArrayTableForm">
+  <grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+    <margin top="0" left="0" bottom="0" right="0"/>
+    <constraints>
+      <xy x="20" y="20" width="500" height="375"/>
+    </constraints>
+    <properties/>
+    <border type="none"/>
+    <children>
+      <scrollpane id="90774" class="com.intellij.ui.components.JBScrollPane" binding="myScrollPane">
+        <constraints>
+          <grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <horizontalScrollBarPolicy value="30"/>
+        </properties>
+        <border type="none"/>
+        <children>
+          <component id="c7f7c" class="com.intellij.ui.table.JBTable" binding="myTable" custom-create="true">
+            <constraints/>
+            <properties>
+              <autoResizeMode value="0"/>
+              <fillsViewportHeight value="true"/>
+            </properties>
+          </component>
+        </children>
+      </scrollpane>
+      <component id="32570" class="javax.swing.JTextField" binding="mySliceTextField">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
+            <preferred-size width="150" height="-1"/>
+          </grid>
+        </constraints>
+        <properties>
+          <toolTipText value="Current slice"/>
+        </properties>
+      </component>
+      <component id="b6d58" class="javax.swing.JCheckBox" binding="myColoredCheckbox">
+        <constraints>
+          <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <enabled value="true"/>
+          <selected value="true"/>
+          <text value="Colored"/>
+        </properties>
+      </component>
+      <grid id="db2ae" binding="myFormatPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+        <margin top="0" left="0" bottom="0" right="0"/>
+        <constraints>
+          <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties/>
+        <border type="none"/>
+        <children>
+          <component id="8f575" class="javax.swing.JLabel" binding="myFormatLabel">
+            <constraints>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <text value="Format:"/>
+            </properties>
+          </component>
+          <component id="b056a" class="javax.swing.JTextField" binding="myFormatTextField">
+            <constraints>
+              <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
+                <preferred-size width="150" height="-1"/>
+              </grid>
+            </constraints>
+            <properties>
+              <toolTipText value="Array value format"/>
+            </properties>
+          </component>
+        </children>
+      </grid>
+    </children>
+  </grid>
+</form>
diff --git a/python/src/com/jetbrains/python/actions/view/array/ArrayTableForm.java b/python/src/com/jetbrains/python/actions/view/array/ArrayTableForm.java
new file mode 100644 (file)
index 0000000..302f20f
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.actions.view.array;
+
+import com.intellij.ui.components.JBScrollPane;
+import com.intellij.ui.table.JBTable;
+import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
+
+import javax.swing.*;
+import javax.swing.table.DefaultTableModel;
+
+/**
+ * @author amarch
+ */
+public class ArrayTableForm {
+  private JTextField mySliceTextField;
+  private JCheckBox myColoredCheckbox;
+  private JTextField myFormatTextField;
+  private JBScrollPane myScrollPane;
+  private JLabel myFormatLabel;
+  private JPanel myFormatPanel;
+  private JPanel myMainPanel;
+  public JBTable myTable;
+
+
+  private static final String DATA_LOADING_IN_PROCESS = "Please wait, load array data.";
+
+  private static final String NOT_APPLICABLE = "View not applicable for ";
+
+  public ArrayTableForm(){
+  }
+
+  public JTextField getSliceTextField() {
+    return mySliceTextField;
+  }
+
+  public JTextField getFormatTextField() {
+    return myFormatTextField;
+  }
+
+  public JBTable getTable() {
+    return myTable;
+  }
+
+  public JCheckBox getColored() {
+    return myColoredCheckbox;
+  }
+
+  private void setSpinnerText(String text) {
+    DefaultTableModel model = new DefaultTableModel(1, 1) {
+      @Override
+      public boolean isCellEditable(int row, int column) {
+        return false;
+      }
+    };
+    myTable.setModel(model);
+    myTable.setValueAt(text, 0, 0);
+  }
+
+  public void setDefaultSpinnerText() {
+    setSpinnerText(DATA_LOADING_IN_PROCESS);
+  }
+
+  public void setErrorSpinnerText(Exception e) {
+    setSpinnerText(e.getMessage());
+  }
+
+  public void setErrorSpinnerText(String message) {
+    //todo: Access to realized (ever shown) UI components
+    // should be done only from the AWT event dispatch thread,
+    // revalidate(), invalidate() & repaint() is ok from any thread
+    setSpinnerText(message);
+  }
+
+  public void setNotApplicableSpinner(XValueNodeImpl node) {
+    setSpinnerText(NOT_APPLICABLE + node.getName());
+  }
+
+
+  public JComponent getMainPanel() {
+    return myMainPanel;
+  }
+
+  private void createUIComponents() {
+    myTable = new JBTable() {
+      public boolean getScrollableTracksViewportWidth() {
+        return getPreferredSize().width < getParent().getWidth();
+      }
+    };
+    myTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
+    myTable.setRowSelectionAllowed(false);
+  }
+}
index b01bcbce06fae8a821bf87b0307962a4c6d26ee8..d4ade899c65e55faace6b2ef709ca6e806752a62 100644 (file)
@@ -42,6 +42,14 @@ class NumpyArrayPresentation {
   private String myDtype;
   private NumpyArrayValueProvider myValueProvider;
 
+  public final static String DEFAULT_STRING_FORMAT = "\'%s\'";
+
+  public final static String DEFAULT_FLOAT_FORMAT = "\'%.3f\'";
+
+  public final static String DEFAULT_INT_FORMAT = "\'%d\'";
+
+  public final static String DEFAULT_COMPLEX_FORMAT = "\'%d\'";
+
   public NumpyArrayPresentation(String name, NumpyArrayValueProvider valueProvider) {
     myArrayName = name;
     myValueProvider = valueProvider;
@@ -208,11 +216,11 @@ class NumpyArrayPresentation {
       @Override
       public void childrenLoaded(@NotNull XDebuggerTreeNode node, @NotNull List<XValueContainerNode<?>> children, boolean last) {
         String fullName = ((XValueNodeImpl)node).getName();
-        int row = 0;
+        int row = -1;
         if (fullName != null && fullName.contains("[")) {
           row = Integer.parseInt(fullName.substring(fullName.lastIndexOf('[') + 1, fullName.length() - 2));
         }
-        if (myData[row][0] == null) {
+        if (row != -1 && myData[row][0] == null) {
           for (int i = 0; i < node.getChildCount() - 1; i++) {
             myData[row][i] = ((XValueNodeImpl)node.getChildAt(i + 1)).getRawValue();
           }
@@ -276,5 +284,22 @@ class NumpyArrayPresentation {
 
     setSlice(presentation);
   }
+
+
+  public String getFormat() {
+    if (isNumeric()){
+      return DEFAULT_FLOAT_FORMAT;
+    } else {
+      return DEFAULT_STRING_FORMAT;
+    }
+  }
+
+  public boolean isNumeric() {
+    if (getDtype() != null) {
+      return "biufc".contains(getDtype().substring(0, 1));
+    }
+    return false;
+
+  }
 }
 
index d27045ad424c3d293aa83aff9fbfe59d2f74812e..a8367d8703aae16a52f98e2ef287263c84d192e0 100644 (file)
@@ -36,14 +36,13 @@ import javax.swing.table.DefaultTableModel;
  * @author amarch
  */
 class NumpyArrayValueProvider extends ArrayValueProvider {
-
-  private ArrayTableComponent myComponent;
+  private ArrayTableForm myComponent;
   private JTable myTable;
   private Project myProject;
   private PyDebuggerEvaluator myEvaluator;
   private NumpyArrayPresentation myLastPresentation;
 
-  public NumpyArrayValueProvider(@NotNull XValueNode node, @NotNull ArrayTableComponent component, @NotNull Project project) {
+  public NumpyArrayValueProvider(@NotNull XValueNode node, @NotNull ArrayTableForm component, @NotNull Project project) {
     super(node);
     myComponent = component;
     myProject = project;
@@ -52,7 +51,7 @@ class NumpyArrayValueProvider extends ArrayValueProvider {
     myLastPresentation = new NumpyArrayPresentation(((XValueNodeImpl)node).getName(), this);
   }
 
-  public ArrayTableComponent getComponent(){
+  public ArrayTableForm getComponent(){
     return myComponent;
   }
 
@@ -191,7 +190,8 @@ class NumpyArrayValueProvider extends ArrayValueProvider {
       }
     });
     enableColor(data);
-    myComponent.getTextField().setText(myLastPresentation.getSlice());
+    myComponent.getSliceTextField().setText(myLastPresentation.getSlice());
+    myComponent.getFormatTextField().setText(myLastPresentation.getFormat());
   }
 
   private static String[] range(int min, int max) {
index 4dd38019175eef6fadaf8198fa2f156aa78a29f5..0637dfb979be626ca1f15b83298f33d5d0ca0446 100644 (file)
@@ -46,7 +46,7 @@ public class PyViewArrayAction extends XDebuggerTreeActionBase {
   private class MyDialog extends DialogWrapper {
     public JTable myTable;
     private Project myProject;
-    private ArrayTableComponent myComponent;
+    private ArrayTableForm myComponent;
 
     private MyDialog(Project project) {
       super(project, false);
@@ -56,7 +56,7 @@ public class PyViewArrayAction extends XDebuggerTreeActionBase {
 
       myProject = project;
 
-      myComponent = new ArrayTableComponent();
+      myComponent = new ArrayTableForm();
       myTable = myComponent.getTable();
 
       init();
@@ -133,7 +133,7 @@ public class PyViewArrayAction extends XDebuggerTreeActionBase {
 
     @Override
     protected JComponent createCenterPanel() {
-      return myComponent;
+      return myComponent.getMainPanel();
     }
   }
 }