com.intellij.ui.OnePixelSplitter Java Examples

The following examples show how to use com.intellij.ui.OnePixelSplitter. 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: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Test
public void categoryNodesHaveCorrectExtraInformation() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();

  TreePath webPPath = getTreePathWithString(suggestionTree, webPCategoryData.toString());
  TreeCellRenderer treeCellRenderer = suggestionTree.getCellRenderer();
  Component renderedNode =
      treeCellRenderer.getTreeCellRendererComponent(
          suggestionTree,
          webPPath.getLastPathComponent(),
          false,
          false,
          false,
          suggestionTree.getRowForPath(webPPath),
          false);
  assertThat(renderedNode.toString()).contains("2 recommendations");
  assertThat(renderedNode.toString()).contains("29.30 KB");
}
 
Example #2
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Test
public void multipleSuggestionsCreateIssueTypeNode() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();

  TreePath webPIssuePath =
      getTreePathWithString(
          suggestionTree, SuggestionDataFactory.issueTypeNodeNames.get(IssueType.WEBP));
  DefaultMutableTreeNode webPIssueNode =
      (DefaultMutableTreeNode) webPIssuePath.getLastPathComponent();
  assertThat(webPIssueNode.getChildCount()).isEqualTo(2);
}
 
Example #3
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Test
public void autofixIsNotShownWhenNull() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();
  JPanel rightPane = (JPanel) splitter.getSecondComponent();

  TreePath streamingPath =
      getTreePathWithString(suggestionTree, streamingSuggestionData.toString());
  suggestionTree.addSelectionPath(streamingPath);

  for (Component component : rightPane.getComponents()) {
    if (component instanceof JButton) {
      assertThat(component.isVisible()).isFalse();
    }
  }
}
 
Example #4
Source File: OnePixelDivider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
  final Rectangle bounds = g.getClipBounds();
  if (mySplitter instanceof OnePixelSplitter) {
    final Producer<Insets> blindZone = ((OnePixelSplitter)mySplitter).getBlindZone();
    if (blindZone != null) {
      final Insets insets = blindZone.produce();
      if (insets != null) {
        bounds.x += insets.left;
        bounds.y += insets.top;
        bounds.width -= insets.left + insets.right;
        bounds.height -= insets.top + insets.bottom;
        g.setColor(getBackground());
        g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
        return;
      }
    }
  }
  super.paint(g);
}
 
Example #5
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 5 votes vote down vote up
@Test
public void selectingCategoryNodeChangesCategoryPanel() {
  JPanel toolPanel = toolWindow.getContent();
  Component[] components = toolPanel.getComponents();
  OnePixelSplitter splitter = (OnePixelSplitter) components[0];
  JBScrollPane leftPane = (JBScrollPane) splitter.getFirstComponent();
  JViewport leftView = leftPane.getViewport();
  Tree suggestionTree = (Tree) leftView.getView();

  assertThat(suggestionTree.getSelectionCount()).isEqualTo(0);

  TreePath webPPath = getTreePathWithString(suggestionTree, webPCategoryData.toString());
  suggestionTree.addSelectionPath(webPPath);
  JPanel rightPane = (JPanel) splitter.getSecondComponent();

  assertThat(suggestionTree.getSelectionCount()).isEqualTo(1);
  for (Component component : rightPane.getComponents()) {
    if (component instanceof SimpleColoredComponent) {
      assertThat(component.toString()).contains(webPCategoryData.toString());
      assertThat(component.toString()).contains("Estimated savings: 29.30 KB");
    } else if (component instanceof JPanel) {
      Component[] suggestionPanelComponents = ((JPanel) component).getComponents();
      assertThat(suggestionPanelComponents).hasLength(1);
      for (Component linkLabel : suggestionPanelComponents) {
        assertThat(((LinkLabel<?>) linkLabel).getText()).isEqualTo(SuggestionDataFactory.issueTypeNodeNames.get(IssueType.WEBP));
      }
    }
  }
}
 
Example #6
Source File: PostfixTemplatesChildConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nullable
@Override
public JComponent createComponent() {
  PostfixTemplateProvider postfixTemplateProvider = myExtensionPoint.getInstance();
  if (postfixTemplateProvider == null) {
    return null;
  }

  OnePixelSplitter splitter = new OnePixelSplitter();
  splitter.setSplitterProportionKey("PostfixTemplatesChildConfigurable.splitter");

  myCheckBoxList = new CheckBoxList<>();

  splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myCheckBoxList, true));

  myPostfixDescriptionPanel = new PostfixDescriptionPanel();
  JPanel component = myPostfixDescriptionPanel.getComponent();
  component.setBorder(JBUI.Borders.empty(0, 8, 0, 0));
  splitter.setSecondComponent(component);

  myCheckBoxList.setItems(new ArrayList<>(postfixTemplateProvider.getTemplates()), PostfixTemplate::getPresentableName, postfixTemplate -> Boolean.TRUE);

  myCheckBoxList.addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent e) {
      PostfixTemplate itemAt = myCheckBoxList.getItemAt(myCheckBoxList.getSelectedIndex());

      myPostfixDescriptionPanel.reset(PostfixTemplateMetaData.createMetaData(itemAt));
    }
  });
  return splitter;
}
 
Example #7
Source File: CSharpAssemblyFileEditor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public JComponent getComponent()
{
	DefaultMutableTreeNode root = new DefaultMutableTreeNode();

	for(CSharpAssemblyBlock block : myBlocks)
	{
		DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(block);

		root.add(newChild);
	}

	final SimpleTree simpleTree = new SimpleTree(new DefaultTreeModel(root));
	simpleTree.setRootVisible(false);
	simpleTree.setCellRenderer(new ColoredTreeCellRenderer()
	{
		@RequiredUIAccess
		@Override
		public void customizeCellRenderer(JTree jTree, Object o, boolean b, boolean b2, boolean b3, int i, boolean b4)
		{
			Object object = ((DefaultMutableTreeNode) o).getUserObject();
			if(object instanceof CSharpAssemblyBlock)
			{
				append(((CSharpAssemblyBlock) object).getTitle());
			}
		}
	});

	final OnePixelSplitter splitter = new OnePixelSplitter();
	simpleTree.addTreeSelectionListener(new TreeSelectionListener()
	{
		@Override
		public void valueChanged(TreeSelectionEvent e)
		{
			List<CSharpAssemblyBlock> cSharpAssemblyBlocks = TreeUtil.collectSelectedObjectsOfType(simpleTree, CSharpAssemblyBlock.class);

			CSharpAssemblyBlock firstItem = ContainerUtil.getFirstItem(cSharpAssemblyBlocks);
			if(firstItem == null)
			{
				splitter.setSecondComponent(new JPanel());
			}
			else
			{

				splitter.setSecondComponent(firstItem.createAndLoadComponent(myPsiFile, !myIsReadonlyFile));
			}
		}
	});

	splitter.setAndLoadSplitterProportionKey("CSharpAssemblyFileEditor");

	splitter.setFirstComponent(simpleTree);
	splitter.setSecondComponent(new JPanel());

	return ScrollPaneFactory.createScrollPane(splitter);
}
 
Example #8
Source File: ServersToolWindowContent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ServersToolWindowContent(@Nonnull Project project) {
  super(new BorderLayout());
  myProject = project;

  myTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
  myTree = new Tree(myTreeModel);
  myTree.setRootVisible(false);

  myTree.setShowsRootHandles(true);
  myTree.setCellRenderer(new NodeRenderer());
  myTree.setLineStyleAngled();

  getMainPanel().add(createToolbar(), BorderLayout.WEST);
  Splitter splitter = new OnePixelSplitter(false, 0.3f);
  splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree, SideBorder.LEFT));
  myPropertiesPanelLayout = new CardLayout();
  myPropertiesPanel = new JPanel(myPropertiesPanelLayout);
  myMessageLabel = new JLabel(EMPTY_SELECTION_MESSAGE, SwingConstants.CENTER);
  myPropertiesPanel.add(MESSAGE_CARD, new Wrapper(myMessageLabel));
  splitter.setSecondComponent(myPropertiesPanel);
  getMainPanel().add(splitter, BorderLayout.CENTER);

  setupBuilder(project);

  for (RemoteServersViewContributor contributor : RemoteServersViewContributor.EP_NAME.getExtensionList()) {
    contributor.setupTree(myProject, myTree, myBuilder);
  }

  myTree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      onSelectionChanged();
    }
  });
  new DoubleClickListener() {
    @Override
    protected boolean onDoubleClick(MouseEvent event) {
      Set<ServersTreeStructure.RemoteServerNode> nodes = getSelectedRemoteServerNodes();
      if (nodes.size() == 1) {
        RemoteServer<?> server = nodes.iterator().next().getValue();
        ServerConnectionManager.getInstance().getOrCreateConnection(server).computeDeployments(EmptyRunnable.INSTANCE);
        return true;
      }
      return false;
    }
  }.installOn(myTree);
}
 
Example #9
Source File: ExtensionEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected JComponent createComponentImpl() {
  JPanel rootPane = new JPanel(new BorderLayout());

  mySplitter = new OnePixelSplitter();

  myTree = new CheckboxTreeNoPolicy(new ExtensionTreeCellRenderer(), new ExtensionCheckedTreeNode(null, myState, this)) {
    @Override
    protected void adjustParentsAndChildren(CheckedTreeNode node, boolean checked) {
      if (!checked) {
        changeNodeState(node, false);
        checkOrUncheckChildren(node, false);
      }
      else {
        // we need collect parents, and enable it in right order
        // A
        // - B
        // -- C
        // when we enable C, ill be calls like A -> B -> C
        List<CheckedTreeNode> parents = new ArrayList<>();
        TreeNode parent = node.getParent();
        while (parent != null) {
          if (parent instanceof CheckedTreeNode) {
            parents.add((CheckedTreeNode)parent);
          }
          parent = parent.getParent();
        }

        Collections.reverse(parents);
        for (CheckedTreeNode checkedTreeNode : parents) {
          checkNode(checkedTreeNode, true);
        }
        changeNodeState(node, true);
      }
      repaint();
    }
  };

  myTree.setRootVisible(false);
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myTree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    @RequiredUIAccess
    public void valueChanged(final TreeSelectionEvent e) {
      final List<MutableModuleExtension> selected = TreeUtil.collectSelectedObjectsOfType(myTree, MutableModuleExtension.class);
      updateSecondComponent(ContainerUtil.<MutableModuleExtension>getFirstItem(selected));
    }
  });
  TreeUtil.expandAll(myTree);

  mySplitter.setFirstComponent(myTree);

  rootPane.add(new JBScrollPane(mySplitter), BorderLayout.CENTER);

  return rootPane;
}
 
Example #10
Source File: IntentionSettingsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public IntentionSettingsPanel() {
  myIntentionSettingsTree = new IntentionSettingsTree() {
    @Override
    protected void selectionChanged(Object selected) {
      if (selected instanceof IntentionActionMetaData) {
        final IntentionActionMetaData actionMetaData = (IntentionActionMetaData)selected;
        final Runnable runnable = new Runnable() {
          @Override
          public void run() {
            intentionSelected(actionMetaData);
          }
        };
        myResetAlarm.cancelAllRequests();
        myResetAlarm.addRequest(runnable, 100);
      }
      else {
        categorySelected((String)selected);
      }
    }

    @Override
    protected List<IntentionActionMetaData> filterModel(String filter, final boolean force) {
      final List<IntentionActionMetaData> list = IntentionManagerSettings.getInstance().getMetaData();
      if (filter == null || filter.length() == 0) return list;
      final HashSet<String> quoted = new HashSet<String>();
      List<Set<String>> keySetList = SearchUtil.findKeys(filter, quoted);
      List<IntentionActionMetaData> result = new ArrayList<IntentionActionMetaData>();
      for (IntentionActionMetaData metaData : list) {
        if (isIntentionAccepted(metaData, filter, force, keySetList, quoted)){
          result.add(metaData);
        }
      }
      final Set<String> filters = SearchableOptionsRegistrar.getInstance().getProcessedWords(filter);
      if (force && result.isEmpty()){
        if (filters.size() > 1){
          result = filterModel(filter, false);
        }
      }
      return result;
    }
  };
  myComponent = new OnePixelSplitter(false, 0.4f);

  myComponent.setFirstComponent(myIntentionSettingsTree.getComponent());
  myComponent.setSecondComponent(myIntentionDescriptionPanel.getComponent());
}
 
Example #11
Source File: ContentEntriesEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public JPanel createComponentImpl() {
  final Module module = getModule();
  final Project project = module.getProject();

  myContentEntryEditorListener = new MyContentEntryEditorListener();

  final JPanel mainPanel = new JPanel(new BorderLayout());

  final JPanel entriesPanel = new JPanel(new BorderLayout());

  final DefaultActionGroup group = new DefaultActionGroup();
  final AddContentEntryAction action = new AddContentEntryAction();
  action.registerCustomShortcutSet(KeyEvent.VK_C, InputEvent.ALT_DOWN_MASK, mainPanel);
  group.add(action);

  myEditorsPanel = new ScrollablePanel(new VerticalStackLayout());
  myEditorsPanel.setBackground(BACKGROUND_COLOR);
  JScrollPane myScrollPane = ScrollPaneFactory.createScrollPane(myEditorsPanel, true);
  entriesPanel.add(new ToolbarPanel(myScrollPane, group), BorderLayout.CENTER);

  final JBSplitter splitter = new OnePixelSplitter(false);
  splitter.setProportion(0.6f);
  splitter.setHonorComponentsMinimumSize(true);

  myRootTreeEditor = new ContentEntryTreeEditor(project, myState);
  JComponent component = myRootTreeEditor.createComponent();
  component.setBorder(new CustomLineBorder(JBUI.scale(1),0,0,0));

  splitter.setFirstComponent(component);
  splitter.setSecondComponent(entriesPanel);
  JPanel contentPanel = new JPanel(new GridBagLayout());

  final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, myRootTreeEditor.getEditingActionsGroup(), true);
  contentPanel.add(new JLabel("Mark as:"),
                   new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, 0, new JBInsets(0, 5, 0, 5), 0,
                                          0));
  contentPanel.add(actionToolbar.getComponent(),
                   new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
                                          new JBInsets(0, 0, 0, 0), 0, 0));
  contentPanel.add(splitter,
                   new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH,
                                          new JBInsets(0, 0, 0, 0), 0, 0));

  mainPanel.add(contentPanel, BorderLayout.CENTER);

  final ModifiableRootModel model = getModel();
  if (model != null) {
    final ContentEntry[] contentEntries = model.getContentEntries();
    if (contentEntries.length > 0) {
      for (final ContentEntry contentEntry : contentEntries) {
        addContentEntryPanel(contentEntry);
      }
      selectContentEntry(contentEntries[0]);
    }
  }

  return mainPanel;
}