private void adjustTo(final int idx) {
   final Splitter target = mySplitters.get(idx);
   for (int i = 0; i < mySplitters.size(); i++) {
     final Splitter splitter = mySplitters.get(i);
     splitter.setProportion(target.getProportion());
   }
   for (Splitter splitter : myListening) {
     splitter.setProportion(target.getProportion());
   }
 }
Пример #2
0
  public void initSplitterProportion(
      final Splitter splitter, float defaultProportion, final String id) {
    final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
    String value =
        propertiesComponent.getValue(UnitTestViewComponent.SPLITTER_SIZE_PROPERTY + "." + id);
    float proportion = defaultProportion;
    if ((value != null && value.length() > 0)) {
      try {
        proportion = Float.parseFloat(value);
      } catch (NumberFormatException ignore) {
      }
    }

    splitter.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent event) {
            if (event.getPropertyName().equals(Splitter.PROP_PROPORTION)) {
              propertiesComponent.setValue(
                  UnitTestViewComponent.SPLITTER_SIZE_PROPERTY + "." + id,
                  String.valueOf(splitter.getProportion()));
            }
          }
        });

    splitter.setProportion(proportion);
  }
 private int restoreSplitterProportions(Component root, int index) {
   if (root instanceof Splitter) {
     if (proportions.size() <= index) return index;
     ((Splitter) root).setProportion(proportions.get(index++).floatValue());
   }
   if (root instanceof Container) {
     Component[] children = ((Container) root).getComponents();
     for (Component child : children) {
       index = restoreSplitterProportions(child, index);
     }
   }
   return index;
 }
    @Override
    protected JComponent createCenterPanel() {
      final JComponent tree = super.createCenterPanel();

      myCommitMessagePanel = new CommitMessage(myProject);
      myCommitMessagePanel.setCommitMessage("Initial commit");

      Splitter splitter = new Splitter(true);
      splitter.setHonorComponentsMinimumSize(true);
      splitter.setFirstComponent(tree);
      splitter.setSecondComponent(myCommitMessagePanel);
      splitter.setProportion(0.7f);

      return splitter;
    }
  void restoreLastSplitterProportions(PlaceInGrid placeInGrid) {
    if (getRootPane() == null) return;
    if (!RunnerContentUi.ensureValid(this)) return;

    final TabImpl tab = (TabImpl) getTab();
    if (tab != null) {
      switch (placeInGrid) {
        case left:
          setLeftProportion(tab.getLeftProportion());
          break;
        case right:
          setRightProportion(tab.getRightProportion());
          break;
        case bottom:
          mySplitter.setProportion(tab.getBottomProportion());
          break;
        case center:
          break;
      }
    }
  }
  public JPanel getPanel() {
    if (mySplitter == null) {
      mySplitter = new Splitter(false, 0.5f);
      final String value = PropertiesComponent.getInstance().getValue(SPLITTER_PROPORTION);
      if (value != null) {
        mySplitter.setProportion(Float.parseFloat(value));
      }

      mySplitter.setFirstComponent(
          ToolbarDecorator.createDecorator(myMacrosList)
              .setEditAction(
                  new AnActionButtonRunnable() {
                    @Override
                    public void run(AnActionButton button) {
                      final int selIndex = myMacrosList.getSelectedIndex();
                      if (selIndex == -1) return;
                      final ActionMacro macro = (ActionMacro) myMacrosModel.getElementAt(selIndex);
                      String newName;
                      do {
                        newName =
                            Messages.showInputDialog(
                                mySplitter,
                                IdeBundle.message("prompt.enter.new.name"),
                                IdeBundle.message("title.rename.macro"),
                                Messages.getQuestionIcon(),
                                macro.getName(),
                                null);
                        if (newName == null || macro.getName().equals(newName)) return;
                      } while (!canRenameMacro(newName));

                      if (myRenamingList == null)
                        myRenamingList = new ArrayList<Pair<String, String>>();
                      myRenamingList.add(new Pair<String, String>(macro.getName(), newName));
                      macro.setName(newName);
                      myMacrosList.repaint();
                    }

                    private boolean canRenameMacro(final String name) {
                      final Enumeration elements = myMacrosModel.elements();
                      while (elements.hasMoreElements()) {
                        final ActionMacro macro = (ActionMacro) elements.nextElement();
                        if (macro.getName().equals(name)) {
                          if (Messages.showYesNoDialog(
                                  IdeBundle.message("message.macro.exists", name),
                                  IdeBundle.message("title.macro.name.already.used"),
                                  Messages.getWarningIcon())
                              != 0) {
                            return false;
                          }
                          myMacrosModel.removeElement(macro);
                          break;
                        }
                      }
                      return true;
                    }
                  })
              .disableAddAction()
              .disableUpDownActions()
              .createPanel());

      mySplitter.setSecondComponent(
          ToolbarDecorator.createDecorator(myMacroActionsList)
              .setRemoveAction(
                  new AnActionButtonRunnable() {
                    @Override
                    public void run(AnActionButton button) {
                      final int macrosSelectedIndex = myMacrosList.getSelectedIndex();
                      if (macrosSelectedIndex != -1) {
                        final ActionMacro macro =
                            (ActionMacro) myMacrosModel.getElementAt(macrosSelectedIndex);
                        macro.deleteAction(myMacroActionsList.getSelectedIndex());
                      }
                      ListUtil.removeSelectedItems(myMacroActionsList);
                    }
                  })
              .disableAddAction()
              .disableUpDownActions()
              .createPanel());
    }
    return mySplitter;
  }