From 9067e17343f38fc1e2b305480d0597fdf0234aeb Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Sat, 27 Dec 2014 17:32:25 +0300 Subject: [PATCH] fixed PY-14312 IPython Notebook: cell gets collapsed when editor width is too narrow for the output width --- .../ipnb/editor/panels/IpnbEditablePanel.java | 21 +++---- .../editor/panels/code/IpnbCodePanel.java | 62 ++++++++----------- .../panels/code/IpnbCodeSourcePanel.java | 3 +- 3 files changed, 37 insertions(+), 49 deletions(-) diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java index aa6d9373f2ea..a85336366aa9 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java @@ -40,15 +40,10 @@ public abstract class IpnbEditablePanel { public void addPromptPanel(@NotNull final JComponent parent, Integer promptNumber, @NotNull final IpnbEditorUtil.PromptType promptType, - @NotNull final JComponent component, @NotNull final GridBagConstraints c) { - super.addPromptPanel(parent, promptNumber, promptType, component, c); + @NotNull final JComponent component) { + super.addPromptPanel(parent, promptNumber, promptType, component); if (component instanceof IpnbPanel) myOutputPanels.add((IpnbPanel)component); } @Override protected JComponent createViewPanel() { - final JPanel panel = new JPanel(new GridBagLayout()); - panel.setBackground(IpnbEditorUtil.getBackground()); - - final GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 1; + final JPanel mainPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, true, false)); + mainPanel.setBackground(IpnbEditorUtil.getBackground()); myCodeSourcePanel = new IpnbCodeSourcePanel(myProject, this, myCell); - addPromptPanel(panel, myCell.getPromptNumber(), IpnbEditorUtil.PromptType.In, myCodeSourcePanel, c); + final JPanel panel = new JPanel(new GridBagLayout()); + panel.setBackground(IpnbEditorUtil.getBackground()); + addPromptPanel(panel, myCell.getPromptNumber(), IpnbEditorUtil.PromptType.In, myCodeSourcePanel); + mainPanel.add(panel); - c.gridx = 1; - - c.gridy = 0; for (IpnbOutputCell outputCell : myCell.getCellOutputs()) { - c.gridy++; - addOutputPanel(panel, c, outputCell, true); + addOutputPanel(mainPanel, outputCell, true); } - return panel; + return mainPanel; } - private void addOutputPanel(@NotNull final JComponent panel, @NotNull final GridBagConstraints c, + private void addOutputPanel(@NotNull final JComponent mainPanel, @NotNull final IpnbOutputCell outputCell, boolean addPrompt) { final IpnbEditorUtil.PromptType promptType = addPrompt ? IpnbEditorUtil.PromptType.Out : IpnbEditorUtil.PromptType.None; + final JPanel panel = new JPanel(new GridBagLayout()); + panel.setBackground(IpnbEditorUtil.getBackground()); if (outputCell instanceof IpnbImageOutputCell) { addPromptPanel(panel, myCell.getPromptNumber(), promptType, - new IpnbImagePanel((IpnbImageOutputCell)outputCell), c); + new IpnbImagePanel((IpnbImageOutputCell)outputCell)); } else if (outputCell instanceof IpnbHtmlOutputCell) { addPromptPanel(panel, myCell.getPromptNumber(), promptType, - new IpnbHtmlPanel((IpnbHtmlOutputCell)outputCell), c); + new IpnbHtmlPanel((IpnbHtmlOutputCell)outputCell)); } else if (outputCell instanceof IpnbLatexOutputCell) { addPromptPanel(panel, myCell.getPromptNumber(), promptType, - new IpnbLatexPanel((IpnbLatexOutputCell)outputCell), c); + new IpnbLatexPanel((IpnbLatexOutputCell)outputCell)); } else if (outputCell instanceof IpnbErrorOutputCell) { addPromptPanel(panel, myCell.getPromptNumber(), promptType, - new IpnbErrorPanel((IpnbErrorOutputCell)outputCell), c); + new IpnbErrorPanel((IpnbErrorOutputCell)outputCell)); } else if (outputCell instanceof IpnbStreamOutputCell) { addPromptPanel(panel, myCell.getPromptNumber(), IpnbEditorUtil.PromptType.None, - new IpnbStreamPanel((IpnbStreamOutputCell)outputCell), c); + new IpnbStreamPanel((IpnbStreamOutputCell)outputCell)); } else if (outputCell.getSourceAsString() != null) { addPromptPanel(panel, myCell.getPromptNumber(), promptType, - new IpnbCodeOutputPanel(outputCell), c); + new IpnbCodeOutputPanel(outputCell)); } + mainPanel.add(panel); } @Override @@ -143,23 +140,18 @@ public class IpnbCodePanel extends IpnbEditablePanel { @Override public void run() { myCell.removeCellOutputs(); - myViewPanel.removeAll(); - final GridBagConstraints c = new GridBagConstraints(); - c.fill = GridBagConstraints.HORIZONTAL; - c.gridx = 0; - c.gridy = 0; - c.gridwidth = 1; - addPromptPanel(myViewPanel, myCell.getPromptNumber(), IpnbEditorUtil.PromptType.In, myCodeSourcePanel, c); + final JPanel panel = new JPanel(new GridBagLayout()); + panel.setBackground(IpnbEditorUtil.getBackground()); + addPromptPanel(panel, myCell.getPromptNumber(), IpnbEditorUtil.PromptType.In, myCodeSourcePanel); + myViewPanel.add(panel); for (IpnbOutputCell output : outputContent) { myCell.addCellOutput(output); - c.gridx = 0; - c.gridy += 1; - - addOutputPanel(myViewPanel, c, output, output instanceof IpnbOutOutputCell); + addOutputPanel(myViewPanel, output, true); } + final IpnbFilePanel filePanel = myParent.getIpnbFilePanel(); filePanel.revalidate(); filePanel.repaint(); diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java index a4936596ff9b..b778b3aa3902 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/code/IpnbCodeSourcePanel.java @@ -22,6 +22,7 @@ import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.ui.Gray; +import com.intellij.ui.components.panels.HorizontalLayout; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.ipnb.editor.IpnbEditorUtil; @@ -47,7 +48,7 @@ public class IpnbCodeSourcePanel extends IpnbPanel imp @NotNull private final String mySource; public IpnbCodeSourcePanel(@NotNull final Project project, @NotNull final IpnbCodePanel parent, @NotNull final IpnbCodeCell cell) { - super(cell, new BorderLayout()); + super(cell, new HorizontalLayout(5)); myProject = project; myParent = parent; mySource = cell.getSourceAsString();