Java Code Examples for com.intellij.openapi.ui.Splitter#setProportion()

The following examples show how to use com.intellij.openapi.ui.Splitter#setProportion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setupLogTreeScrollPane() {
  final JScrollPane treePane = ScrollPaneFactory.createScrollPane(
    logTree,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  treePane.getVerticalScrollBar().getModel().addChangeListener(new LogVerticalScrollChangeListener() {
    @Override
    protected void onScrollUp() {
      scrollToEndAction.disableIfNeeded();
    }

    @Override
    protected void onScrollToEnd() {
      scrollToEndAction.enableIfNeeded();
    }
  });
  logModel.setScrollPane(treePane);

  dataPane = ScrollPaneFactory.createScrollPane(
    dataPanel,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

  treeSplitter = new Splitter(false);
  treeSplitter.setProportion(DATA_PANEL_SPLITTER_PROPORTION_DEFAULT);
  // Data and splitter revealed on demand.
  dataPane.setVisible(false);
  treeSplitter.setVisible(false);

  treeSplitter.setFirstComponent(treePane);
  treeSplitter.setSecondComponent(dataPane);
  toolWindowPanel.setContent(treeSplitter);

  dataPanel.onUpdate(hasContent -> {
    dataPane.setVisible(hasContent);

    if (hasContent) {
      if (treeSplitter.getProportion() != lastSplitProportion) {
        treeSplitter.setProportion(lastSplitProportion);
        treeSplitter.revalidate();
        treeSplitter.repaint();
      }
    }
    else {
      final float proportion = treeSplitter.getProportion();
      if (proportion != 1.0f) {
        lastSplitProportion = proportion;
      }
      treeSplitter.setProportion(1.0f);
    }
  });
}
 
Example 2
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setupLogTreeScrollPane() {
  final JScrollPane treePane = ScrollPaneFactory.createScrollPane(
    logTree,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  treePane.getVerticalScrollBar().getModel().addChangeListener(new LogVerticalScrollChangeListener() {
    @Override
    protected void onScrollUp() {
      scrollToEndAction.disableIfNeeded();
    }

    @Override
    protected void onScrollToEnd() {
      scrollToEndAction.enableIfNeeded();
    }
  });
  logModel.setScrollPane(treePane);

  dataPane = ScrollPaneFactory.createScrollPane(
    dataPanel,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

  treeSplitter = new Splitter(false);
  treeSplitter.setProportion(DATA_PANEL_SPLITTER_PROPORTION_DEFAULT);
  // Data and splitter revealed on demand.
  dataPane.setVisible(false);
  treeSplitter.setVisible(false);

  treeSplitter.setFirstComponent(treePane);
  treeSplitter.setSecondComponent(dataPane);
  toolWindowPanel.setContent(treeSplitter);

  dataPanel.onUpdate(hasContent -> {
    dataPane.setVisible(hasContent);

    if (hasContent) {
      if (treeSplitter.getProportion() != lastSplitProportion) {
        treeSplitter.setProportion(lastSplitProportion);
        treeSplitter.revalidate();
        treeSplitter.repaint();
      }
    }
    else {
      final float proportion = treeSplitter.getProportion();
      if (proportion != 1.0f) {
        lastSplitProportion = proportion;
      }
      treeSplitter.setProportion(1.0f);
    }
  });
}
 
Example 3
Source File: SingleInspectionProfilePanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private JPanel createInspectionProfileSettingsPanel() {

    myBrowser = new JEditorPane(UIUtil.HTML_MIME, EMPTY_HTML);
    myBrowser.setEditable(false);
    myBrowser.setBorder(IdeBorderFactory.createEmptyBorder(5, 5, 5, 5));
    myBrowser.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);

    initToolStates();
    fillTreeData(myProfileFilter != null ? myProfileFilter.getFilter() : null, true);

    JPanel descriptionPanel = new JPanel(new BorderLayout());
    descriptionPanel.setBorder(IdeBorderFactory.createTitledBorder(InspectionsBundle.message("inspection.description.title"), false,
                                                                   new Insets(2, 0, 0, 0)));
    descriptionPanel.add(ScrollPaneFactory.createScrollPane(myBrowser), BorderLayout.CENTER);

    myRightSplitter = new Splitter(true);
    myRightSplitter.setFirstComponent(descriptionPanel);
    myRightSplitter.setProportion(myProperties.getFloat(HORIZONTAL_DIVIDER_PROPORTION, 0.5f));

    myOptionsPanel = new JPanel(new GridBagLayout());
    initOptionsAndDescriptionPanel();
    myRightSplitter.setSecondComponent(myOptionsPanel);
    myRightSplitter.setHonorComponentsMinimumSize(true);

    final JScrollPane tree = initTreeScrollPane();

    final JPanel northPanel = new JPanel(new GridBagLayout());
    northPanel.setBorder(IdeBorderFactory.createEmptyBorder(2, 0, 2, 0));
    myProfileFilter.setPreferredSize(new Dimension(20, myProfileFilter.getPreferredSize().height));
    northPanel.add(myProfileFilter, new GridBagConstraints(0, 0, 1, 1, 0.5, 1, GridBagConstraints.BASELINE_TRAILING, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    northPanel.add(createTreeToolbarPanel().getComponent(), new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.BASELINE_LEADING, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

    myMainSplitter = new Splitter(false, myProperties.getFloat(VERTICAL_DIVIDER_PROPORTION, 0.5f), 0.01f, 0.99f);
    myMainSplitter.setFirstComponent(tree);
    myMainSplitter.setSecondComponent(myRightSplitter);
    myMainSplitter.setHonorComponentsMinimumSize(false);

    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(northPanel, BorderLayout.NORTH);
    panel.add(myMainSplitter, BorderLayout.CENTER);
    return panel;
  }
 
Example 4
Source File: DesktopToolWindowPanelImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  try {
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    class MySplitter extends Splitter implements UISettingsListener {
      @Override
      public void uiSettingsChanged(UISettings uiSettings) {
        if (anchor == ToolWindowAnchor.LEFT) {
          setOrientation(!uiSettings.getLeftHorizontalSplit());
        }
        else if (anchor == ToolWindowAnchor.RIGHT) {
          setOrientation(!uiSettings.getRightHorizontalSplit());
        }
      }
    }
    Splitter splitter = new MySplitter();
    splitter.setOrientation(anchor.isSplitVertically());
    if (!anchor.isHorizontal()) {
      splitter.setAllowSwitchOrientationByMouseClick(true);
      splitter.addPropertyChangeListener(evt -> {
        if (!Splitter.PROP_ORIENTATION.equals(evt.getPropertyName())) return;
        boolean isSplitterHorizontalNow = !splitter.isVertical();
        UISettings settings = UISettings.getInstance();
        if (anchor == ToolWindowAnchor.LEFT) {
          if (settings.getLeftHorizontalSplit() != isSplitterHorizontalNow) {
            settings.setLeftHorizontalSplit(isSplitterHorizontalNow);
            settings.fireUISettingsChanged();
          }
        }
        if (anchor == ToolWindowAnchor.RIGHT) {
          if (settings.getRightHorizontalSplit() != isSplitterHorizontalNow) {
            settings.setRightHorizontalSplit(isSplitterHorizontalNow);
            settings.fireUISettingsChanged();
          }
        }
      });
    }
    JComponent c = getComponentAt(anchor);
    float newWeight;
    if (c instanceof DesktopInternalDecorator) {
      DesktopInternalDecorator oldComponent = (DesktopInternalDecorator)c;
      if (myInfo.isSplit()) {
        splitter.setFirstComponent(oldComponent);
        splitter.setSecondComponent(myNewComponent);
        float proportion = getPreferredSplitProportion(oldComponent.getWindowInfo().getId(), WindowInfoImpl
                .normalizeWeigh(oldComponent.getWindowInfo().getSideWeight() / (oldComponent.getWindowInfo().getSideWeight() + myInfo.getSideWeight())));
        splitter.setProportion(proportion);
        if (!anchor.isHorizontal() && !anchor.isSplitVertically()) {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight());
        }
        else {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight());
        }
      }
      else {
        splitter.setFirstComponent(myNewComponent);
        splitter.setSecondComponent(oldComponent);
        splitter.setProportion(WindowInfoImpl.normalizeWeigh(myInfo.getSideWeight()));
        if (!anchor.isHorizontal() && !anchor.isSplitVertically()) {
          newWeight = WindowInfoImpl.normalizeWeigh(oldComponent.getWindowInfo().getWeight() + myInfo.getWeight());
        }
        else {
          newWeight = WindowInfoImpl.normalizeWeigh(myInfo.getWeight());
        }
      }
    }
    else {
      newWeight = WindowInfoImpl.normalizeWeigh(myInfo.getWeight());
    }
    setComponent(splitter, anchor, newWeight);

    if (!myDirtyMode) {
      myLayeredPane.validate();
      myLayeredPane.repaint();
    }
  }
  finally {
    finish();
  }
}