--- /dev/null
+<?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>
--- /dev/null
+/*
+ * 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);
+ }
+}
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;
@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();
}
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;
+
+ }
}
* @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;
myLastPresentation = new NumpyArrayPresentation(((XValueNodeImpl)node).getName(), this);
}
- public ArrayTableComponent getComponent(){
+ public ArrayTableForm getComponent(){
return myComponent;
}
}
});
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) {
private class MyDialog extends DialogWrapper {
public JTable myTable;
private Project myProject;
- private ArrayTableComponent myComponent;
+ private ArrayTableForm myComponent;
private MyDialog(Project project) {
super(project, false);
myProject = project;
- myComponent = new ArrayTableComponent();
+ myComponent = new ArrayTableForm();
myTable = myComponent.getTable();
init();
@Override
protected JComponent createCenterPanel() {
- return myComponent;
+ return myComponent.getMainPanel();
}
}
}