@Override public void actionPerformed(AnActionEvent e) { JPanel result = new JPanel(new BorderLayout()); JLabel label = new JLabel("Lines around:"); label.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 0)); JPanel wrapper = new JPanel(new BorderLayout()); wrapper.add(label, BorderLayout.NORTH); result.add(wrapper, BorderLayout.WEST); final JSlider slider = new JSlider(JSlider.HORIZONTAL, 1, 5, 1); slider.setMinorTickSpacing(1); slider.setPaintTicks(true); slider.setPaintTrack(true); slider.setSnapToTicks(true); UIUtil.setSliderIsFilled(slider, true); slider.setPaintLabels(true); slider.setLabelTable(LABELS); result.add(slider, BorderLayout.CENTER); final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject); for (int i = 0; i < ourMarks.length; i++) { int mark = ourMarks[i]; if (mark == configuration.SHORT_DIFF_EXTRA_LINES) { slider.setValue(i + 1); } } JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(result, slider).createPopup(); popup.setFinalRunnable( new Runnable() { @Override public void run() { int value = slider.getModel().getValue(); if (configuration.SHORT_DIFF_EXTRA_LINES != ourMarks[value - 1]) { configuration.SHORT_DIFF_EXTRA_LINES = ourMarks[value - 1]; myFragmentedContent.recalculate(); refreshData(myFragmentedContent); } } }); InputEvent inputEvent = e.getInputEvent(); if (inputEvent instanceof MouseEvent) { int width = result.getPreferredSize().width; MouseEvent inputEvent1 = (MouseEvent) inputEvent; Point point1 = new Point(inputEvent1.getX() - width / 2, inputEvent1.getY()); RelativePoint point = new RelativePoint(inputEvent1.getComponent(), point1); popup.show(point); } else { popup.showInBestPositionFor(e.getDataContext()); } }
public void buildUi() { myTopPanel = new JPanel(new BorderLayout()); final JPanel wrapper = new JPanel(); // final BoxLayout boxLayout = new BoxLayout(wrapper, BoxLayout.X_AXIS); wrapper.setLayout(new BorderLayout()); myTitleLabel.setBorder(BorderFactory.createEmptyBorder(1, 2, 0, 0)); wrapper.add(myTitleLabel, BorderLayout.WEST); DefaultActionGroup dag = new DefaultActionGroup(); myPreviousDiff.copyShortcutFrom(ActionManager.getInstance().getAction("PreviousDiff")); myNextDiff.copyShortcutFrom(ActionManager.getInstance().getAction("NextDiff")); dag.add(new MyChangeContextAction()); dag.add(myPreviousDiff); dag.add(myNextDiff); myPreviousDiff.registerCustomShortcutSet(myPreviousDiff.getShortcutSet(), myPanel); myNextDiff.registerCustomShortcutSet(myNextDiff.getShortcutSet(), myPanel); dag.add(new PopupAction()); ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, dag, true); wrapper.add(toolbar.getComponent(), BorderLayout.EAST); myTopPanel.add(wrapper, BorderLayout.CENTER); final JPanel wrapperDiffs = new JPanel(new GridBagLayout()); final JPanel oneMore = new JPanel(new BorderLayout()); oneMore.add(wrapperDiffs, BorderLayout.NORTH); myCurrentHorizontal = myConfiguration.SHORT_DIFF_HORISONTALLY; myHorizontal = createPanel(true); myVertical = createPanel(false); myPanel.add(myTopPanel, BorderLayout.NORTH); myPanel.add(getCurrentPanel().getComponent(), BorderLayout.CENTER); myPreviousDiff.registerCustomShortcutSet(myPreviousDiff.getShortcutSet(), myParent); myNextDiff.registerCustomShortcutSet(myNextDiff.getShortcutSet(), myParent); }
public ImplementationViewComponent(PsiElement[] elements, final int index) { super(new BorderLayout()); final Project project = elements.length > 0 ? elements[0].getProject() : null; EditorFactory factory = EditorFactory.getInstance(); Document doc = factory.createDocument(""); doc.setReadOnly(true); myEditor = factory.createEditor(doc, project); ((EditorEx) myEditor).setBackgroundColor(EditorFragmentComponent.getBackgroundColor(myEditor)); final EditorSettings settings = myEditor.getSettings(); settings.setAdditionalLinesCount(1); settings.setAdditionalColumnsCount(1); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setLineNumbersShown(false); settings.setFoldingOutlineShown(false); myBinarySwitch = new CardLayout(); myViewingPanel = new JPanel(myBinarySwitch); myEditor.setBorder(null); ((EditorEx) myEditor).getScrollPane().setViewportBorder(JBScrollPane.createIndentBorder()); myViewingPanel.add(myEditor.getComponent(), TEXT_PAGE_KEY); myBinaryPanel = new JPanel(new BorderLayout()); myViewingPanel.add(myBinaryPanel, BINARY_PAGE_KEY); add(myViewingPanel, BorderLayout.CENTER); myToolbar = createToolbar(); myLocationLabel = new JLabel(); myCountLabel = new JLabel(); final JPanel header = new JPanel(new BorderLayout(2, 0)); header.setBorder( BorderFactory.createCompoundBorder( IdeBorderFactory.createBorder(SideBorder.BOTTOM), IdeBorderFactory.createEmptyBorder(0, 0, 0, 5))); final JPanel toolbarPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gc = new GridBagConstraints( GridBagConstraints.RELATIVE, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 2, 0, 0), 0, 0); toolbarPanel.add(myToolbar.getComponent(), gc); setPreferredSize(new Dimension(600, 400)); update( elements, new PairFunction<PsiElement[], List<FileDescriptor>, Boolean>() { @Override public Boolean fun( final PsiElement[] psiElements, final List<FileDescriptor> fileDescriptors) { if (psiElements.length == 0) return false; myElements = psiElements; myIndex = index < myElements.length ? index : 0; PsiFile psiFile = getContainingFile(myElements[myIndex]); VirtualFile virtualFile = psiFile.getVirtualFile(); EditorHighlighter highlighter; if (virtualFile != null) highlighter = HighlighterFactory.createHighlighter(project, virtualFile); else { String fileName = psiFile.getName(); // some artificial psi file, lets do best we can highlighter = HighlighterFactory.createHighlighter(project, fileName); } ((EditorEx) myEditor).setHighlighter(highlighter); gc.fill = GridBagConstraints.HORIZONTAL; gc.weightx = 1; if (myElements.length > 1) { myFileChooser = new ComboBox( fileDescriptors.toArray(new FileDescriptor[fileDescriptors.size()]), 250); updateRenderer(project); myFileChooser.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int index = myFileChooser.getSelectedIndex(); if (myIndex != index) { myIndex = index; updateControls(); } } }); myLabel = new JLabel(); myLabel.setVisible(false); toolbarPanel.add(myFileChooser, gc); } else { myFileChooser = new ComboBox(); myFileChooser.setVisible(false); myCountLabel.setVisible(false); myLabel = new JLabel(); VirtualFile file = psiFile.getVirtualFile(); if (file != null) { myLabel.setIcon(getIconForFile(psiFile)); myLabel.setForeground( FileStatusManager.getInstance(project).getStatus(file).getColor()); myLabel.setText(file.getPresentableName()); myLabel.setBorder( new CompoundBorder( IdeBorderFactory.createRoundedBorder(), IdeBorderFactory.createEmptyBorder(0, 0, 0, 5))); } toolbarPanel.add(myLabel, gc); } gc.fill = GridBagConstraints.NONE; gc.weightx = 0; toolbarPanel.add(myCountLabel, gc); header.add(toolbarPanel, BorderLayout.CENTER); header.add(myLocationLabel, BorderLayout.EAST); add(header, BorderLayout.NORTH); updateControls(); return true; } }); }