com.intellij.openapi.ui.VerticalFlowLayout Java Examples

The following examples show how to use com.intellij.openapi.ui.VerticalFlowLayout. 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: RecentLocationsRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends RecentLocationItem> list, RecentLocationItem value, int index, boolean selected, boolean hasFocus) {
  EditorEx editor = value.getEditor();
  if (myProject.isDisposed() || editor.isDisposed()) {
    return super.getListCellRendererComponent(list, value, index, selected, hasFocus);
  }

  EditorColorsScheme colorsScheme = editor.getColorsScheme();
  String breadcrumbs = myData.getBreadcrumbsMap(myCheckBox.isSelected()).get(value.getInfo());
  JPanel panel = new JPanel(new VerticalFlowLayout(0, 0));
  if (index != 0) {
    panel.add(createSeparatorLine(colorsScheme));
  }
  panel.add(createTitleComponent(myProject, list, mySpeedSearch, breadcrumbs, value.getInfo(), colorsScheme, selected));
  panel.add(setupEditorComponent(editor, editor.getDocument().getText(), mySpeedSearch, colorsScheme, selected));

  return panel;
}
 
Example #2
Source File: MemberChooser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createSouthPanel() {
  JPanel panel = new JPanel(new GridBagLayout());

  customizeOptionsPanel();
  JPanel optionsPanel = new JPanel(new VerticalFlowLayout());
  for (final JComponent component : myOptionControls) {
    optionsPanel.add(component);
  }

  panel.add(optionsPanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 5), 0, 0));

  if (!myAllowEmptySelection && (myElements == null || myElements.length == 0)) {
    setOKActionEnabled(false);
  }
  panel.add(super.createSouthPanel(), new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
  return panel;
}
 
Example #3
Source File: HaxeRestoreReferencesDialog.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final JPanel panel = new JPanel(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP));
  myList = new JBList((Object[])myNamedElements);
  myList.setCellRenderer(new FQNameCellRenderer());
  panel.add(ScrollPaneFactory.createScrollPane(myList), BorderLayout.CENTER);

  panel.add(new JBLabel(CodeInsightBundle.message("dialog.paste.on.import.text"), SMALL, BRIGHTER), BorderLayout.NORTH);

  final JPanel buttonPanel = new JPanel(new VerticalFlowLayout());
  final JButton okButton = new JButton(CommonBundle.getOkButtonText());
  getRootPane().setDefaultButton(okButton);
  buttonPanel.add(okButton);
  final JButton cancelButton = new JButton(CommonBundle.getCancelButtonText());
  buttonPanel.add(cancelButton);

  panel.setPreferredSize(new Dimension(500, 400));

  return panel;
}
 
Example #4
Source File: RunConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showFolderField(final ConfigurationType type, final DefaultMutableTreeNode node, final String folderName) {
  myRightPanel.removeAll();
  JPanel panel = new JPanel(new VerticalFlowLayout(0, 0));
  final JTextField textField = new JTextField(folderName);
  textField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      node.setUserObject(textField.getText());
      myTreeModel.reload(node);
    }
  });
  panel.add(LabeledComponent.left(textField, "Folder name"));
  panel.add(new JLabel(ExecutionBundle.message("run.configuration.rename.folder.disclaimer")));

  myRightPanel.add(panel);
  myRightPanel.revalidate();
  myRightPanel.repaint();
  if (isFolderCreating) {
    textField.selectAll();
    IdeFocusManager.getGlobalInstance().doForceFocusWhenFocusSettlesDown(textField);
  }
}
 
Example #5
Source File: ArtifactPropertiesEditors.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ArtifactPropertiesEditors(ArtifactEditorContext context, Artifact originalArtifact, Artifact artifact) {
  myContext = context;
  myOriginalArtifact = originalArtifact;
  myMainPanels = new HashMap<String, JPanel>();
  myEditors = new ArrayList<PropertiesEditorInfo>();
  for (ArtifactPropertiesProvider provider : artifact.getPropertiesProviders()) {
    final PropertiesEditorInfo editorInfo = new PropertiesEditorInfo(provider);
    myEditors.add(editorInfo);
    final String tabName = editorInfo.myEditor.getTabName();
    JPanel panel = myMainPanels.get(tabName);
    if (panel == null) {
      panel = new JPanel(new VerticalFlowLayout());
      myMainPanels.put(tabName, panel);
    }
    panel.add(editorInfo.myEditor.createComponent());
  }
}
 
Example #6
Source File: CommitPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CommitPanel(@Nonnull VcsLogData logData, @Nonnull VcsLogColorManager colorManager) {
  myLogData = logData;
  myColorManager = colorManager;

  setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
  setOpaque(false);

  myRootPanel = new RootPanel();
  myBranchesPanel = new ReferencesPanel();
  myBranchesPanel.setBorder(JBUI.Borders.empty(REFERENCES_BORDER, 0, 0, 0));
  myTagsPanel = new ReferencesPanel();
  myTagsPanel.setBorder(JBUI.Borders.empty(REFERENCES_BORDER, 0, 0, 0));
  myDataPanel = new DataPanel(myLogData.getProject());
  myContainingBranchesPanel = new BranchesPanel();

  add(myRootPanel);
  add(myDataPanel);
  add(myBranchesPanel);
  add(myTagsPanel);
  add(myContainingBranchesPanel);

  setBorder(getDetailsBorder());
}
 
Example #7
Source File: CommonProgramParametersPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public CommonProgramParametersPanel(boolean init) {
  super();

  setLayout(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 5, true, false));

  if (init) {
    init();
  }
}
 
Example #8
Source File: JBTableRowEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static JPanel createLabeledPanel(String labelText, JComponent component) {
  final JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
  final JBLabel label = new JBLabel(labelText, UIUtil.ComponentStyle.SMALL);
  IJSwingUtilities.adjustComponentsOnMac(label, component);
  panel.add(label);
  panel.add(component);
  return panel;
}
 
Example #9
Source File: ChooseComponentsToExportDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected JComponent createSouthPanel() {
  final JComponent buttons = super.createSouthPanel();
  if (!myShowFilePath) return buttons;
  final JPanel panel = new JPanel(new VerticalFlowLayout());
  panel.add(myPathPanel);
  panel.add(buttons);
  return panel;
}
 
Example #10
Source File: MergedCompositeConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static JPanel createPanel(boolean isUseTitledBorder) {
  int verticalGap = TitledSeparator.TOP_INSET;
  JPanel panel = new JPanel(new VerticalFlowLayout(0, isUseTitledBorder ? 0 : verticalGap));
  // VerticalFlowLayout incorrectly use vertical gap as top inset
  if (!isUseTitledBorder) {
    panel.setBorder(new EmptyBorder(-verticalGap, 0, 0, 0));
  }
  return panel;
}
 
Example #11
Source File: StripeTabPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public StripeTabPanel() {
  super(new BorderLayout());
  myTabPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
  myTabPanel.setBorder(new CustomLineBorder(0, 0, 0, JBUI.scale(1)));

  add(myTabPanel, BorderLayout.WEST);

  myContentPanel = new JPanel(new CardLayout());
  add(myContentPanel, BorderLayout.CENTER);
}
 
Example #12
Source File: RemoveInvalidElementsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private RemoveInvalidElementsDialog(final String title,
                                    ConfigurationErrorType type,
                                    String invalidElements,
                                    final Project project,
                                    List<ConfigurationErrorDescription> errors) {
  super(project, true);
  setTitle(title);
  myDescriptionLabel.setText(ProjectBundle.message(type.canIgnore() ? "label.text.0.cannot.be.loaded.ignore" : "label.text.0.cannot.be.loaded.remove", invalidElements));
  myContentPanel.setLayout(new VerticalFlowLayout());
  for (ConfigurationErrorDescription error : errors) {
    JCheckBox checkBox = new JCheckBox(error.getElementName() + ".");
    checkBox.setSelected(true);
    myCheckboxes.put(checkBox, error);
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.ipadx = 5;
    panel.add(checkBox, constraints);
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.insets.top = 5;
    panel.add(new JLabel("<html><body>" + StringUtil.replace(error.getDescription(), "\n", "<br>") + "</body></html>"), constraints);
    constraints.weightx = 1;
    panel.add(new JPanel(), constraints);
    myContentPanel.add(panel);
  }
  init();
  setOKButtonText(ProjectBundle.message(type.canIgnore() ? "button.text.ignore.selected" : "button.text.remove.selected"));
  setCancelButtonText(ProjectBundle.message("button.text.keep.all"));
}
 
Example #13
Source File: ChoseProjectTypeStep.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ChoseProjectTypeStep(@NotNull FlutterProjectModel model, @NotNull Collection<ModuleGalleryEntry> moduleGalleryEntries) {
  super(model, "New Flutter Project");

  myModuleGalleryEntryList = moduleGalleryEntries;
  myRootPanel = new JPanel();
  myRootPanel.setLayout(new VerticalFlowLayout());
  myRootPanel.add(createGallery());

  JPanel section = new JPanel();
  section.setLayout(new VerticalFlowLayout());
  helpLabels = new JLabel[moduleGalleryEntries.size()];
  int idx = 0;
  for (ModuleGalleryEntry entry : moduleGalleryEntries) {
    helpLabels[idx] = new JLabel(((FlutterGalleryEntry)entry).getHelpText());
    helpLabels[idx].setEnabled(false);
    section.add(helpLabels[idx++]);
  }

  myProjectTypeGallery.addListSelectionListener(e -> {
    if (e.getValueIsAdjusting()) {
      return;
    }
    for (JLabel label : helpLabels) {
      label.setEnabled(false);
    }
    if (myProjectTypeGallery.getSelectedIndex() >= 0) {
      helpLabels[myProjectTypeGallery.getSelectedIndex()].setEnabled(true);
    }
  });

  myRootPanel.add(section);
  FormScalingUtil.scaleComponentTree(this.getClass(), myRootPanel);
}
 
Example #14
Source File: MnemonicChooser.java    From consulo with Apache License 2.0 5 votes vote down vote up
public MnemonicChooser() {
  super(new VerticalFlowLayout());
  JPanel numbers = new NonOpaquePanel(new GridLayout(2, 5, 2, 2));
  for (char i = '1'; i <= '9'; i++) {
    numbers.add(new MnemonicLabel(i));
  }
  numbers.add(new MnemonicLabel('0'));
  

  JPanel letters = new NonOpaquePanel(new GridLayout(5, 6, 2, 2));
  for (char c = 'A'; c <= 'Z'; c++) {
    letters.add(new MnemonicLabel(c));
  }

  add(numbers);
  add(new JSeparator());
  add(letters);
  setBackground(UIUtil.getListBackground());

  addKeyListener(new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
        onCancelled();
      }
      else if (e.getModifiersEx() == 0) {
        final char typed = Character.toUpperCase(e.getKeyChar());
        if (typed >= '0' && typed <= '9' || typed >= 'A' && typed <= 'Z') {
          onMnemonicChosen(typed);
        }
      }
    }
  });

  setFocusable(true);
}
 
Example #15
Source File: ChangeSignatureDialogBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected JComponent createOptionsPanel() {
  final JPanel panel = new JPanel(new BorderLayout());
  if (myAllowDelegation) {
    myDelegationPanel = createDelegationPanel();
    panel.add(myDelegationPanel, BorderLayout.WEST);
  }

  myPropagateParamChangesButton =
    new AnActionButton(RefactoringBundle.message("changeSignature.propagate.parameters.title"), null, new LayeredIcon(AllIcons.Nodes.Parameter, AllIcons.Actions.New)) {
      @Override
      public void actionPerformed(AnActionEvent e) {
        final Ref<CallerChooserBase<Method>> chooser = new Ref<CallerChooserBase<Method>>();
        Consumer<Set<Method>> callback = new Consumer<Set<Method>>() {
          @Override
          public void consume(Set<Method> callers) {
            myMethodsToPropagateParameters = callers;
            myParameterPropagationTreeToReuse = chooser.get().getTree();
          }
        };
        try {
          String message = RefactoringBundle.message("changeSignature.parameter.caller.chooser");
          chooser.set(createCallerChooser(message, myParameterPropagationTreeToReuse, callback));
        }
        catch (ProcessCanceledException ex) {
          // user cancelled initial callers search, don't show dialog
          return;
        }
        chooser.get().show();
      }
    };

  final JPanel result = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP));
  result.add(panel);
  return result;
}
 
Example #16
Source File: RecentProjectPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected RecentProjectItemRenderer(UniqueNameBuilder<ReopenProjectAction> pathShortener) {
  super(new VerticalFlowLayout());
  myShortener = pathShortener;
  myPath.setFont(JBUI.Fonts.label(SystemInfo.isMac ? 10f : 11f));
  setFocusable(true);
  layoutComponents();
}
 
Example #17
Source File: DesktopToolWindowHeader.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JPanel wrapAndFillVertical(JComponent owner) {
  JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, JBUI.scale(5), false, true));
  panel.add(owner);
  panel.setOpaque(false);
  return panel;
}
 
Example #18
Source File: AboutNewDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  JTextArea area = new JTextArea();
  area.setEditable(false);
  area.setText(buildAboutInfo());

  setOKButtonText(CommonBundle.getCloseButtonText());

  JButton okButton = createJButtonForAction(getOKAction());

  JPanel eastPanel = new JPanel(new VerticalFlowLayout());
  eastPanel.add(okButton);

  JButton copyToClipboard = new JButton("Copy to clipboard");
  copyToClipboard.addActionListener(e -> {
    CopyPasteManager.getInstance().setContents(new TextTransferable(area.getText(), area.getText()));

    copyToClipboard.setEnabled(false);

    JobScheduler.getScheduler().schedule(() -> UIUtil.invokeLaterIfNeeded(() -> copyToClipboard.setEnabled(true)), 2, TimeUnit.SECONDS);
  });

  eastPanel.add(copyToClipboard);

  return Couple.of(ScrollPaneFactory.createScrollPane(area, true), eastPanel);
}
 
Example #19
Source File: CustomizeDownloadAndStartStepPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean beforeShown(boolean forward) {
  final Set<PluginDescriptor> pluginsForDownload = myPluginsStepPanel == null ? Collections.<PluginDescriptor>emptySet() : myPluginsStepPanel.getPluginsForDownload();
  if (pluginsForDownload.isEmpty()) {
    add(createStartButton());
  }
  else {
    JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, true, true));
    JBLabel infoLabel = new JBLabel("");
    panel.add(infoLabel);
    JProgressBar progressBar = new JProgressBar();
    panel.add(progressBar);
    add(panel);

    final ProgressIndicator indicator = new MyProgressIndicator(infoLabel, progressBar);
    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
      @Override
      public void run() {
        for (PluginDescriptor ideaPluginDescriptor : pluginsForDownload) {
          try {
            PluginDownloader downloader = PluginDownloader.createDownloader(ideaPluginDescriptor, false);
            downloader.prepareToInstall(indicator);
            downloader.install(true);
          }
          catch (Exception e) {
            CustomizeDownloadAndStartStepPanel.LOGGER.warn(e);
          }
        }

        myDone = true;
        UIUtil.invokeLaterIfNeeded(() -> placeStartButton());
      }
    });
  }

  return true;
}
 
Example #20
Source File: ListCheckboxPanel.java    From EasyCode with MIT License 5 votes vote down vote up
/**
 * 默认构造方法
 */
public ListCheckboxPanel(String title, Collection<String> items) {
    // 使用垂直流式布局
    super(new VerticalFlowLayout());
    this.title = title;
    this.items = items;
    this.init();
}
 
Example #21
Source File: ServiceAuthDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ServiceAuthDialog() {
  super(null);
  setTitle("Service Authorization");
  myRoot = new JPanel(new VerticalFlowLayout(0, 0));

  myServiceAuthConfiguration = ServiceAuthConfiguration.getInstance();

  myAsAnonymousButton = new JBRadioButton("Logged as anonymous");
  myLogAsButton = new JBRadioButton("Log as user");

  JPanel loginPanel = new JPanel(new VerticalFlowLayout(0, 0));
  myEmailField = new JBTextField();
  loginPanel.add(LabeledComponent.left(myEmailField, "Email"));

  ButtonGroup group = new ButtonGroup();
  group.add(myAsAnonymousButton);
  group.add(myLogAsButton);

  myLogAsButton.addItemListener(e -> UIUtil.setEnabled(loginPanel, e.getStateChange() == ItemEvent.SELECTED, true));

  myRoot.add(myAsAnonymousButton);
  myRoot.add(myLogAsButton);
  myRoot.add(loginPanel);

  String email = myServiceAuthConfiguration.getEmail();
  if (email == null) {
    myAsAnonymousButton.setSelected(true);
  }
  else {
    myLogAsButton.setSelected(true);
    myEmailField.setText(email);
  }

  pack();
  init();
}
 
Example #22
Source File: ChoseProjectTypeStep.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ChoseProjectTypeStep(@NotNull FlutterProjectModel model, @NotNull Collection<ModuleGalleryEntry> moduleGalleryEntries) {
  super(model, "New Flutter Project");

  myModuleGalleryEntryList = moduleGalleryEntries;
  myRootPanel = new JPanel();
  myRootPanel.setLayout(new VerticalFlowLayout());
  myRootPanel.add(createGallery());

  JPanel section = new JPanel();
  section.setLayout(new VerticalFlowLayout());
  helpLabels = new JLabel[moduleGalleryEntries.size()];
  int idx = 0;
  for (ModuleGalleryEntry entry : moduleGalleryEntries) {
    helpLabels[idx] = new JLabel(((FlutterGalleryEntry)entry).getHelpText());
    helpLabels[idx].setEnabled(false);
    section.add(helpLabels[idx++]);
  }

  myProjectTypeGallery.addListSelectionListener(e -> {
    if (e.getValueIsAdjusting()) {
      return;
    }
    for (JLabel label : helpLabels) {
      label.setEnabled(false);
    }
    if (myProjectTypeGallery.getSelectedIndex() >= 0) {
      helpLabels[myProjectTypeGallery.getSelectedIndex()].setEnabled(true);
    }
  });

  myRootPanel.add(section);
  FormScalingUtil.scaleComponentTree(this.getClass(), myRootPanel);
}
 
Example #23
Source File: TooltipReferencesPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public TooltipReferencesPanel(@Nonnull VcsLogData logData,
                              @Nonnull LabelPainter referencePainter,
                              @Nonnull Collection<VcsRef> refs) {
  super(new VerticalFlowLayout(JBUI.scale(H_GAP), JBUI.scale(V_GAP)), REFS_LIMIT);
  myReferencePainter = referencePainter;

  VirtualFile root = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(refs)).getRoot();
  setReferences(ContainerUtil.sorted(refs, logData.getLogProvider(root).getReferenceManager().getLabelsOrderComparator()));
}
 
Example #24
Source File: UnnamedConfigurableGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public JComponent createComponent() {
  JPanel panel = new JPanel(new VerticalFlowLayout());
  for (UnnamedConfigurable configurable : myConfigurables) {
    panel.add(configurable.createComponent());
  }

  return panel;
}
 
Example #25
Source File: BeanConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public JComponent createComponent() {
  final JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP));
  for (BeanField field: myFields) {
    panel.add(field.getComponent());
  }
  return panel;
}
 
Example #26
Source File: CSharpCodeGenerationSettingsConfigurable.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
private void createUIComponents()
{
	myAdditionalRootPanel = new JPanel(new VerticalFlowLayout());

	myCommenterForm = new CommenterForm(CSharpLanguage.INSTANCE);
	myAdditionalRootPanel.add(myCommenterForm.getCommenterPanel());
}
 
Example #27
Source File: EditTestsDialog.java    From JHelper with GNU Lesser General Public License v3.0 5 votes vote down vote up
private JPanel generateListPanel() {
	JPanel checkBoxesAndSelectorPanel = new JPanel(new BorderLayout());
	checkBoxesPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, false, false));
	for (Test test : tests) {
		JCheckBox checkBox = createCheckBox(test);
		checkBoxesPanel.add(checkBox);
	}
	checkBoxesAndSelectorPanel.add(checkBoxesPanel, BorderLayout.WEST);
	testList = new JBList<>(tests);
	testList.setFixedCellHeight(HEIGHT);
	testList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	testList.setLayoutOrientation(JList.VERTICAL);
	testList.addListSelectionListener(
			e -> {
				if (updating) {
					return;
				}
				int index = testList.getSelectedIndex();
				if (index >= 0 && index < testList.getItemsCount()) {
					saveCurrentTest();
					setSelectedTest(index);
				}
			}
	);
	checkBoxesAndSelectorPanel.add(testList, BorderLayout.CENTER);
	return checkBoxesAndSelectorPanel;
}
 
Example #28
Source File: ConsuloExpandableSupport.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected Content prepare(@Nonnull T field, @Nonnull Function<? super String, String> onShow) {
  Font font = field.getFont();
  FontMetrics metrics = font == null ? null : field.getFontMetrics(font);
  int height = metrics == null ? 16 : metrics.getHeight();
  Dimension size = new Dimension(field.getWidth(), height * 16);

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

  JTextArea area = new JTextArea(onShow.fun(field.getText()));
  area.putClientProperty(Expandable.class, this);
  area.setEditable(field.isEditable());
  //area.setBackground(field.getBackground());
  //area.setForeground(field.getForeground());
  area.setFont(font);
  area.setWrapStyleWord(true);
  area.setLineWrap(true);
  IntelliJExpandableSupport.copyCaretPosition(field, area);
  UIUtil.addUndoRedoActions(area);

  JLabel label = ExpandableSupport.createLabel(createCollapseExtension());
  label.setBorder(JBUI.Borders.empty(5));

  JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(area, true);

  mainPanel.add(scrollPane, BorderLayout.CENTER);

  JPanel eastPanel = new JPanel(new VerticalFlowLayout(0, 0));
  eastPanel.add(label);
  mainPanel.add(eastPanel, BorderLayout.EAST);

  scrollPane.setPreferredSize(size);

  return new Content() {
    @Nonnull
    @Override
    public JComponent getContentComponent() {
      return mainPanel;
    }

    @Override
    public JComponent getFocusableComponent() {
      return area;
    }

    @Override
    public void cancel(@Nonnull Function<? super String, String> onHide) {
      if (field.isEditable()) {
        field.setText(onHide.fun(area.getText()));
        IntelliJExpandableSupport.copyCaretPosition(area, field);
      }
    }
  };
}
 
Example #29
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 #30
Source File: DesktopVerticalLayoutImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public DesktopVerticalLayoutImpl() {
  initDefaultPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
}