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

The following examples show how to use com.intellij.openapi.ui.Splitter#setFirstComponent() . 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: ModulesDependenciesPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ModulesDependenciesPanel(final Project project, final Module[] modules) {
  super(new BorderLayout());
  myProject = project;
  myModules = modules;

  //noinspection HardCodedStringLiteral
  myRightTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode("Root"));
  myRightTree = new Tree(myRightTreeModel);
  initTree(myRightTree, true);

  initLeftTree();

  mySplitter = new Splitter();
  mySplitter.setFirstComponent(new MyTreePanel(myLeftTree, myProject));
  mySplitter.setSecondComponent(new MyTreePanel(myRightTree, myProject));

  setSplitterProportion();
  add(mySplitter, BorderLayout.CENTER);
  add(createNorthPanel(), BorderLayout.NORTH);

  project.getMessageBus().connect(this).subscribe(ProjectTopics.PROJECT_ROOTS, this);
}
 
Example 2
Source File: CommittedChangesTreeBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void initSplitters() {
  final Splitter filterSplitter = new Splitter(false, 0.5f);

  filterSplitter.setSecondComponent(ScrollPaneFactory.createScrollPane(myChangesTree));
  myLeftPanel.add(filterSplitter, BorderLayout.CENTER);
  final Splitter mainSplitter = new Splitter(false, 0.7f);
  mainSplitter.setFirstComponent(myLeftPanel);
  mainSplitter.setSecondComponent(myDetailsView);

  add(mainSplitter, BorderLayout.CENTER);

  myInnerSplitter = new WiseSplitter(new Runnable() {
    public void run() {
      filterSplitter.doLayout();
      updateModel();
    }
  }, filterSplitter);
  Disposer.register(this, myInnerSplitter);

  mySplitterProportionsData.externalizeFromDimensionService("CommittedChanges.SplitterProportions");
  mySplitterProportionsData.restoreSplitterProportions(this);
}
 
Example 3
Source File: TemplateListPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public TemplateListPanel() {
  super(new BorderLayout());

  myDetailsPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
  JLabel label = new JLabel("No live template is selected");
  label.setHorizontalAlignment(SwingConstants.CENTER);
  myDetailsPanel.add(label, NO_SELECTION);
  createTemplateEditor(MOCK_TEMPLATE, "Tab", MOCK_TEMPLATE.createOptions(), MOCK_TEMPLATE.createContext());

  add(createExpandByPanel(), BorderLayout.NORTH);

  Splitter splitter = new Splitter(true, 0.9f);
  splitter.setFirstComponent(createTable());
  splitter.setSecondComponent(myDetailsPanel);
  add(splitter, BorderLayout.CENTER);
}
 
Example 4
Source File: ConsoleFoldingConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public JComponent createComponent() {
  if (myMainComponent == null) {
    myMainComponent = new JPanel(new BorderLayout());
    Splitter splitter = new Splitter(true);
    myMainComponent.add(splitter);
    myPositivePanel =
      new MyAddDeleteListPanel("Fold console lines that contain", "Enter a substring of a console line you'd like to see folded:");
    myNegativePanel = new MyAddDeleteListPanel("Exceptions", "Enter a substring of a console line you don't want to fold:");
    splitter.setFirstComponent(myPositivePanel);
    splitter.setSecondComponent(myNegativePanel);

    myPositivePanel.getEmptyText().setText("Fold nothing");
    myNegativePanel.getEmptyText().setText("No exceptions");
  }
  return myMainComponent;
}
 
Example 5
Source File: DataSourcesSettingsForm.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
private Splitter prepareSplitter(DataSourceListPanel dataSourceListPanel,
                                 JPanel dataSourcesConfigurationPanel) {
    Splitter splitter = new Splitter(false, 0.3f);
    splitter.setFirstComponent(dataSourceListPanel);
    splitter.setSecondComponent(dataSourcesConfigurationPanel);
    dataSourcesConfigurationPanel.setMinimumSize(new Dimension(300, 400));
    return splitter;
}
 
Example 6
Source File: QuickListsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public QuickListsPanel() {
  super(new BorderLayout());
  myKeymapListener = ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC);
  Splitter splitter = new OnePixelSplitter(false, 0.3f);
  splitter.setFirstComponent(createQuickListsPanel());
  splitter.setSecondComponent(myRightPanel);
  add(splitter, BorderLayout.CENTER);
}
 
Example 7
Source File: DesktopEditorWindow.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void removeFromSplitter() {
  if (!inSplitter()) return;

  if (myOwner.getCurrentWindow() == this) {
    DesktopEditorWindow[] siblings = findSiblings();
    myOwner.setCurrentWindow(siblings[0], false);
  }

  Splitter splitter = (Splitter)myPanel.getParent();
  JComponent otherComponent = splitter.getOtherComponent(myPanel);

  Container parent = splitter.getParent().getParent();
  if (parent instanceof Splitter) {
    Splitter parentSplitter = (Splitter)parent;
    if (parentSplitter.getFirstComponent() == splitter.getParent()) {
      parentSplitter.setFirstComponent(otherComponent);
    }
    else {
      parentSplitter.setSecondComponent(otherComponent);
    }
  }
  else if (AWTComponentProviderUtil.getMark(parent) instanceof EditorsSplitters) {
    parent.removeAll();
    parent.add(otherComponent, BorderLayout.CENTER);
    parent.revalidate();
  }
  else {
    throw new IllegalStateException("Unknown container: " + parent);
  }

  dispose();
}
 
Example 8
Source File: PreviewPanel.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createGUI() {
	this.setLayout(new BorderLayout());

	// Had to set min size / preferred size in InputPanel.form to get slider to allow left shift of divider
	Splitter splitPane = new Splitter();
	inputPanel = getEditorPanel();
	splitPane.setFirstComponent(inputPanel.getComponent());
	splitPane.setSecondComponent(createParseTreeAndProfileTabbedPanel());

	this.add(splitPane, BorderLayout.CENTER);
	this.buttonBar = createButtonBar();
	this.add(buttonBar.getComponent(), BorderLayout.WEST);
}
 
Example 9
Source File: IgnoreSettingsPanel.java    From idea-gitignore with MIT License 5 votes vote down vote up
/** Create UI components. */
private void createUIComponents() {
    templatesListPanel = new TemplatesListPanel();
    editorPanel = new EditorPanel();
    editorPanel.setPreferredSize(new Dimension(Integer.MAX_VALUE, 200));

    templatesSplitter = new Splitter(false, 0.3f);
    templatesSplitter.setFirstComponent(templatesListPanel);
    templatesSplitter.setSecondComponent(editorPanel);

    languagesTable = new JBTable();
    languagesTable.setModel(new LanguagesTableModel());
    languagesTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    languagesTable.setColumnSelectionAllowed(false);
    languagesTable.setRowHeight(22);
    languagesTable.getColumnModel().getColumn(2).setCellRenderer(new BooleanTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSel, boolean hasFocus,
                                                       int row, int column) {
            boolean editable = table.isCellEditable(row, column);
            Object newValue = editable ? value : null;
            return super.getTableCellRendererComponent(table, newValue, isSel, hasFocus, row, column);
        }
    });
    languagesTable.setPreferredScrollableViewportSize(
            new Dimension(-1, languagesTable.getRowHeight() * IgnoreBundle.LANGUAGES.size() / 2)
    );

    languagesTable.setStriped(true);
    languagesTable.setShowGrid(false);
    languagesTable.setBorder(JBUI.Borders.empty());
    languagesTable.setDragEnabled(false);

    languagesPanel = ScrollPaneFactory.createScrollPane(languagesTable);
}
 
Example 10
Source File: VcsSelectionHistoryDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private JComponent createComments(final JComponent addComp) {
  JPanel panel = new JPanel(new BorderLayout(4, 4));
  panel.add(new JLabel("Commit Message:"), BorderLayout.NORTH);
  panel.add(ScrollPaneFactory.createScrollPane(myComments), BorderLayout.CENTER);

  final Splitter splitter = new Splitter(false);
  splitter.setFirstComponent(panel);
  splitter.setSecondComponent(addComp);
  return splitter;
}
 
Example 11
Source File: RestServicesNavigatorPanel.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
public RestServicesNavigatorPanel(SimpleTree tree) {
    super(true, true);
    this.apiTree = tree;
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(this.apiTree);
    scrollPane.setBorder(BorderFactory.createLineBorder(Color.RED));
    servicesContentPaneSplitter = new Splitter(true, .5f);
    servicesContentPaneSplitter.setShowDividerControls(true);
    servicesContentPaneSplitter.setDividerWidth(10);
    servicesContentPaneSplitter.setBorder(BorderFactory.createLineBorder(Color.RED));
    servicesContentPaneSplitter.setFirstComponent(scrollPane);
    setContent(servicesContentPaneSplitter);
}
 
Example 12
Source File: BaseItemSelectPanel.java    From EasyCode with MIT License 4 votes vote down vote up
/**
 * 获取面板
 */
public JComponent getComponent() {
    // 创建主面板
    JPanel mainPanel = new JPanel(new BorderLayout());
    // 左边的选择列表
    this.leftPanel = new JPanel(new BorderLayout());

    // 头部操作按钮
    JPanel headToolbar = new JPanel(new FlowLayout(FlowLayout.LEFT));

    // 添加事件按钮
    DefaultActionGroup actionGroup = createActionGroup();

    ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar("Item Toolbar", actionGroup, true);

    headToolbar.add(actionToolbar.getComponent());
    // 添加边框
    actionToolbar.getComponent().setBorder(new CustomLineBorder(1, 1, 1, 1));

    // 工具栏添加至左边面板的北边(上面)
    leftPanel.add(actionToolbar.getComponent(), BorderLayout.NORTH);

    // 元素列表
    listPanel = new JBList<>(dataConvert());
    // 只能单选
    listPanel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // 添加元素选中事件
    listPanel.addListSelectionListener(e -> {
        T item = getSelectedItem();
        if (item == null) {
            return;
        }
        selectedItem(item);
    });
    // 添加边框
    listPanel.setBorder(new CustomLineBorder(0, 1, 1, 1));

    // 将列表添加至左边面板的中间
    leftPanel.add(listPanel, BorderLayout.CENTER);

    // 右边面板
    this.rightPanel = new JPanel(new BorderLayout());

    // 左右分割面板并添加至主面板
    Splitter splitter = new Splitter(false, 0.2F);

    splitter.setFirstComponent(leftPanel);
    splitter.setSecondComponent(rightPanel);

    mainPanel.add(splitter, BorderLayout.CENTER);

    mainPanel.setPreferredSize(JBUI.size(400, 300));

    // 存在元素时,默认选中第一个元素
    if (!itemList.isEmpty()) {
        listPanel.setSelectedIndex(0);
    }

    return mainPanel;
}
 
Example 13
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void updateOutline(@NotNull FlutterOutline outline) {
  currentOutline = outline;

  final DefaultMutableTreeNode rootNode = getRootNode();
  rootNode.removeAllChildren();

  outlinesWithWidgets.clear();
  outlineToNodeMap.clear();
  if (outline.getChildren() != null) {
    computeOutlinesWithWidgets(outline);
    updateOutlineImpl(rootNode, outline.getChildren());
  }

  getTreeModel().reload(rootNode);
  tree.expandAll();

  if (currentEditor != null) {
    final Caret caret = currentEditor.getCaretModel().getPrimaryCaret();
    applyEditorSelectionToTree(caret);
  }

  if (FlutterSettings.getInstance().isEnableHotUi() && propertyEditPanel == null) {
    propertyEditSplitter = new Splitter(false, 0.75f);
    propertyEditPanel = new PropertyEditorPanel(inspectorGroupManagerService, project, flutterAnalysisServer, false, false, project);
    propertyEditPanel.initalize(null, activeOutlines, currentFile);
    propertyEditToolbarGroup = new DefaultActionGroup();
    final ActionToolbar windowToolbar = ActionManager.getInstance().createActionToolbar("PropertyArea", propertyEditToolbarGroup, true);

    final SimpleToolWindowPanel window = new SimpleToolWindowPanel(true, true);
    window.setToolbar(windowToolbar.getComponent());
    final JScrollPane propertyScrollPane = ScrollPaneFactory.createScrollPane(propertyEditPanel);
    window.setContent(propertyScrollPane);
    propertyEditSplitter.setFirstComponent(window.getComponent());
    final InspectorGroupManagerService.Client inspectorStateServiceClient = new InspectorGroupManagerService.Client(project) {
      @Override
      public void onInspectorAvailabilityChanged() {
        super.onInspectorAvailabilityChanged();
        // Only show the screen mirror if there is a running device and
        // the inspector supports the neccessary apis.
        if (getInspectorService() != null && getInspectorService().isHotUiScreenMirrorSupported()) {
          // Wait to create the preview area until it is needed.
          if (previewArea == null) {
            previewArea = new PreviewArea(project, outlinesWithWidgets, project);
          }
          propertyEditSplitter.setSecondComponent(previewArea.getComponent());
        }
        else {
          propertyEditSplitter.setSecondComponent(null);
        }
      }
    };
    inspectorGroupManagerService.addListener(inspectorStateServiceClient, project);

    splitter.setSecondComponent(propertyEditSplitter);
  }

  // TODO(jacobr): this is the wrong spot.
  if (propertyEditToolbarGroup != null) {
    final TitleAction propertyTitleAction = new TitleAction("Properties");
    propertyEditToolbarGroup.removeAll();
    propertyEditToolbarGroup.add(propertyTitleAction);
  }
}
 
Example 14
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void initToolWindow(@NotNull ToolWindow toolWindow) {
  final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
  final ContentManager contentManager = toolWindow.getContentManager();

  final Content content = contentFactory.createContent(null, null, false);
  content.setCloseable(false);

  windowPanel = new OutlineComponent(this);
  content.setComponent(windowPanel);

  windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent());

  final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();

  tree = new OutlineTree(rootNode);
  tree.setCellRenderer(new OutlineTreeCellRenderer());
  tree.expandAll();

  initTreePopup();

  // Add collapse all, expand all, and show only widgets buttons.
  if (toolWindow instanceof ToolWindowEx) {
    final ToolWindowEx toolWindowEx = (ToolWindowEx)toolWindow;

    final CommonActionsManager actions = CommonActionsManager.getInstance();
    final TreeExpander expander = new DefaultTreeExpander(tree);

    final AnAction expandAllAction = actions.createExpandAllAction(expander, tree);
    expandAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Expandall);

    final AnAction collapseAllAction = actions.createCollapseAllAction(expander, tree);
    collapseAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Collapseall);

    final ShowOnlyWidgetsAction showOnlyWidgetsAction = new ShowOnlyWidgetsAction();

    toolWindowEx.setTitleActions(expandAllAction, collapseAllAction, showOnlyWidgetsAction);
  }

  new TreeSpeedSearch(tree) {
    @Override
    protected String getElementText(Object element) {
      final TreePath path = (TreePath)element;
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
      final Object object = node.getUserObject();
      if (object instanceof OutlineObject) {
        return ((OutlineObject)object).getSpeedSearchString();
      }
      return null;
    }
  };

  tree.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() > 1) {
        final TreePath selectionPath = tree.getSelectionPath();
        if (selectionPath != null) {
          selectPath(selectionPath, true);
        }
      }
    }
  });

  tree.addTreeSelectionListener(treeSelectionListener);

  scrollPane = ScrollPaneFactory.createScrollPane(tree);
  content.setPreferredFocusableComponent(tree);

  contentManager.addContent(content);
  contentManager.setSelectedContent(content);

  splitter = new Splitter(true);
  setSplitterProportion(getState().getSplitterProportion());
  getState().addListener(e -> {
    final float newProportion = getState().getSplitterProportion();
    if (splitter.getProportion() != newProportion) {
      setSplitterProportion(newProportion);
    }
  });
  //noinspection Convert2Lambda
  splitter.addPropertyChangeListener("proportion", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (!isSettingSplitterProportion) {
        getState().setSplitterProportion(splitter.getProportion());
      }
    }
  });
  scrollPane.setMinimumSize(new Dimension(1, 1));
  splitter.setFirstComponent(scrollPane);
  windowPanel.setContent(splitter);
}
 
Example 15
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();
  }
}
 
Example 16
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 17
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void updateOutline(@NotNull FlutterOutline outline) {
  currentOutline = outline;

  final DefaultMutableTreeNode rootNode = getRootNode();
  rootNode.removeAllChildren();

  outlinesWithWidgets.clear();
  outlineToNodeMap.clear();
  if (outline.getChildren() != null) {
    computeOutlinesWithWidgets(outline);
    updateOutlineImpl(rootNode, outline.getChildren());
  }

  getTreeModel().reload(rootNode);
  tree.expandAll();

  if (currentEditor != null) {
    final Caret caret = currentEditor.getCaretModel().getPrimaryCaret();
    applyEditorSelectionToTree(caret);
  }

  if (FlutterSettings.getInstance().isEnableHotUi() && propertyEditPanel == null) {
    propertyEditSplitter = new Splitter(false, 0.75f);
    propertyEditPanel = new PropertyEditorPanel(inspectorGroupManagerService, project, flutterAnalysisServer, false, false, project);
    propertyEditPanel.initalize(null, activeOutlines, currentFile);
    propertyEditToolbarGroup = new DefaultActionGroup();
    final ActionToolbar windowToolbar = ActionManager.getInstance().createActionToolbar("PropertyArea", propertyEditToolbarGroup, true);

    final SimpleToolWindowPanel window = new SimpleToolWindowPanel(true, true);
    window.setToolbar(windowToolbar.getComponent());
    final JScrollPane propertyScrollPane = ScrollPaneFactory.createScrollPane(propertyEditPanel);
    window.setContent(propertyScrollPane);
    propertyEditSplitter.setFirstComponent(window.getComponent());
    final InspectorGroupManagerService.Client inspectorStateServiceClient = new InspectorGroupManagerService.Client(project) {
      @Override
      public void onInspectorAvailabilityChanged() {
        super.onInspectorAvailabilityChanged();
        // Only show the screen mirror if there is a running device and
        // the inspector supports the neccessary apis.
        if (getInspectorService() != null && getInspectorService().isHotUiScreenMirrorSupported()) {
          // Wait to create the preview area until it is needed.
          if (previewArea == null) {
            previewArea = new PreviewArea(project, outlinesWithWidgets, project);
          }
          propertyEditSplitter.setSecondComponent(previewArea.getComponent());
        }
        else {
          propertyEditSplitter.setSecondComponent(null);
        }
      }
    };
    inspectorGroupManagerService.addListener(inspectorStateServiceClient, project);

    splitter.setSecondComponent(propertyEditSplitter);
  }

  // TODO(jacobr): this is the wrong spot.
  if (propertyEditToolbarGroup != null) {
    final TitleAction propertyTitleAction = new TitleAction("Properties");
    propertyEditToolbarGroup.removeAll();
    propertyEditToolbarGroup.add(propertyTitleAction);
  }
}
 
Example 18
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void initToolWindow(@NotNull ToolWindow toolWindow) {
  final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
  final ContentManager contentManager = toolWindow.getContentManager();

  final Content content = contentFactory.createContent(null, null, false);
  content.setCloseable(false);

  windowPanel = new OutlineComponent(this);
  content.setComponent(windowPanel);

  windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent());

  final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();

  tree = new OutlineTree(rootNode);
  tree.setCellRenderer(new OutlineTreeCellRenderer());
  tree.expandAll();

  initTreePopup();

  // Add collapse all, expand all, and show only widgets buttons.
  if (toolWindow instanceof ToolWindowEx) {
    final ToolWindowEx toolWindowEx = (ToolWindowEx)toolWindow;

    final CommonActionsManager actions = CommonActionsManager.getInstance();
    final TreeExpander expander = new DefaultTreeExpander(tree);

    final AnAction expandAllAction = actions.createExpandAllAction(expander, tree);
    expandAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Expandall);

    final AnAction collapseAllAction = actions.createCollapseAllAction(expander, tree);
    collapseAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Collapseall);

    final ShowOnlyWidgetsAction showOnlyWidgetsAction = new ShowOnlyWidgetsAction();

    toolWindowEx.setTitleActions(expandAllAction, collapseAllAction, showOnlyWidgetsAction);
  }

  new TreeSpeedSearch(tree) {
    @Override
    protected String getElementText(Object element) {
      final TreePath path = (TreePath)element;
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
      final Object object = node.getUserObject();
      if (object instanceof OutlineObject) {
        return ((OutlineObject)object).getSpeedSearchString();
      }
      return null;
    }
  };

  tree.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() > 1) {
        final TreePath selectionPath = tree.getSelectionPath();
        if (selectionPath != null) {
          selectPath(selectionPath, true);
        }
      }
    }
  });

  tree.addTreeSelectionListener(treeSelectionListener);

  scrollPane = ScrollPaneFactory.createScrollPane(tree);
  content.setPreferredFocusableComponent(tree);

  contentManager.addContent(content);
  contentManager.setSelectedContent(content);

  splitter = new Splitter(true);
  setSplitterProportion(getState().getSplitterProportion());
  getState().addListener(e -> {
    final float newProportion = getState().getSplitterProportion();
    if (splitter.getProportion() != newProportion) {
      setSplitterProportion(newProportion);
    }
  });
  //noinspection Convert2Lambda
  splitter.addPropertyChangeListener("proportion", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (!isSettingSplitterProportion) {
        getState().setSplitterProportion(splitter.getProportion());
      }
    }
  });
  scrollPane.setMinimumSize(new Dimension(1, 1));
  splitter.setFirstComponent(scrollPane);
  windowPanel.setContent(splitter);
}
 
Example 19
Source File: ShowFeatureUsageStatisticsDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected JComponent createCenterPanel() {
  Splitter splitter = new Splitter(true);
  splitter.setShowDividerControls(true);

  ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance();
  ArrayList<FeatureDescriptor> features = new ArrayList<FeatureDescriptor>();
  for (String id : registry.getFeatureIds()) {
    features.add(registry.getFeatureDescriptor(id));
  }
  final TableView table = new TableView<FeatureDescriptor>(new ListTableModel<FeatureDescriptor>(COLUMNS, features, 0));
  new TableViewSpeedSearch<FeatureDescriptor>(table) {
    @Override
    protected String getItemText(@Nonnull FeatureDescriptor element) {
      return element.getDisplayName();
    }
  };

  JPanel controlsPanel = new JPanel(new VerticalFlowLayout());


  Application app = ApplicationManager.getApplication();
  long uptime = System.currentTimeMillis() - app.getStartTime();
  long idleTime = app.getIdleTime();

  final String uptimeS = FeatureStatisticsBundle.message("feature.statistics.application.uptime",
                                                         ApplicationNamesInfo.getInstance().getFullProductName(),
                                                         DateFormatUtil.formatDuration(uptime));

  final String idleTimeS = FeatureStatisticsBundle.message("feature.statistics.application.idle.time",
                                                           DateFormatUtil.formatDuration(idleTime));

  String labelText = uptimeS + ", " + idleTimeS;
  CompletionStatistics stats = ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getCompletionStatistics();
  if (stats.dayCount > 0 && stats.sparedCharacters > 0) {
    String total = formatCharacterCount(stats.sparedCharacters, true);
    String perDay = formatCharacterCount(stats.sparedCharacters / stats.dayCount, false);
    labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(stats.startDate) +
                 " (~" + perDay + " per working day)";
  }

  CumulativeStatistics fstats = ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getFixesStats();
  if (fstats.dayCount > 0 && fstats.invocations > 0) {
    labelText +=
      "<br>Quick fixes have saved you from " + fstats.invocations + " possible bugs since " + DateFormatUtil.formatDate(fstats.startDate) +
      " (~" + fstats.invocations / fstats.dayCount + " per working day)";
  }

  controlsPanel.add(new JLabel("<html><body>" + labelText + "</body></html>"), BorderLayout.NORTH);

  JPanel topPanel = new JPanel(new BorderLayout());
  topPanel.add(controlsPanel, BorderLayout.NORTH);
  topPanel.add(ScrollPaneFactory.createScrollPane(table), BorderLayout.CENTER);

  splitter.setFirstComponent(topPanel);

  final JEditorPane browser = new JEditorPane(UIUtil.HTML_MIME, "");
  browser.setEditable(false);
  splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(browser));

  table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
      Collection selection = table.getSelection();
      try {
        if (selection.isEmpty()) {
          browser.read(new StringReader(""), null);
        }
        else {
          FeatureDescriptor feature = (FeatureDescriptor)selection.iterator().next();
          TipUIUtil.openTipInBrowser(feature.getTipFileName(), browser, feature.getProvider());
        }
      }
      catch (IOException ex) {
        LOG.info(ex);
      }
    }
  });

  return splitter;
}
 
Example 20
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);
    }
  });
}