@Override
    protected void customizeCellRenderer(
        JList list, Object value, int index, boolean selected, boolean hasFocus) {
      setIcon(myListEntryIcon);
      if (myUseIdeaEditor) {
        int max = list.getModel().getSize();
        String indexString = String.valueOf(index + 1);
        int count = String.valueOf(max).length() - indexString.length();
        char[] spaces = new char[count];
        Arrays.fill(spaces, ' ');
        String prefix = indexString + new String(spaces) + "  ";
        append(prefix, SimpleTextAttributes.GRAYED_ATTRIBUTES);
      } else if (UIUtil.isUnderGTKLookAndFeel()) {
        // Fix GTK background
        Color background =
            selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
        UIUtil.changeBackGround(this, background);
      }
      String text = ((Item) value).shortText;

      FontMetrics metrics = list.getFontMetrics(list.getFont());
      int charWidth = metrics.charWidth('m');
      int maxLength = list.getParent().getParent().getWidth() * 3 / charWidth / 2;
      text = StringUtil.first(text, maxLength, true); // do not paint long strings
      append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    }
Example #2
0
 private Dimension calcTypeListPreferredSize(final ModuleType[] allModuleTypes) {
   int width = 0;
   int height = 0;
   final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont());
   final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent();
   for (final ModuleType type : allModuleTypes) {
     final Icon icon = type.getBigIcon();
     final int iconHeight = icon != null ? icon.getIconHeight() : 0;
     final int iconWidth = icon != null ? icon.getIconWidth() : 0;
     height += Math.max(iconHeight, fontHeight) + 6;
     width = Math.max(width, iconWidth + fontMetrics.stringWidth(type.getName()) + 10);
   }
   return new Dimension(width, height);
 }
  protected JComponent createCenterPanel() {
    myList.setCellRenderer(new CvsListCellRenderer());

    myCenterPanelLayout.setHgap(6);

    myCenterPanel.add(createActionsPanel(), BorderLayout.NORTH);
    JComponent listPanel = createListPanel();

    myCenterPanel.add(listPanel, BorderLayout.CENTER);
    myCenterPanel.add(createCvsConfigurationPanel(), BorderLayout.EAST);
    myCenterPanel.add(new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);

    myList.setModel(myModel);

    addSelectionListener();

    int minWidth = myList.getFontMetrics(myList.getFont()).stringWidth(SAMPLE_CVSROOT) + 40;
    Dimension minSize = new Dimension(minWidth, myList.getMaximumSize().height);
    listPanel.setMinimumSize(minSize);
    listPanel.setPreferredSize(minSize);
    return myCenterPanel;
  }
Example #4
0
    @SuppressWarnings("unchecked") // we must be compatible with 1.6
    public VersionManagementPanel(final VisualCanvas canvas) {

      super(canvas);

      setLayout(new GridLayout());

      // TODO @Christian Poliwoda what does manual testing mean?
      // numbers tested manually
      Dimension prefScrollPaneDim = new Dimension(100, 30);
      Dimension visibleRectDim = canvas.getVisibleRect().getSize();

      final VersionController controller =
          canvas.getProjectController().getProject().getProjectFile();

      final int numVersions = controller.getNumberOfVersions() - 1;

      versionData = new Object[numVersions];

      ArrayList<RevCommit> versions = new ArrayList<RevCommit>();

      try {
        versions = controller.getVersions();
      } catch (IOException ex) {
        Logger.getLogger(VersionManagementPanel.class.getName()).log(Level.SEVERE, null, ex);
      }

      int maxTextwidth = 0;
      String longestText = null;

      // the history with timestamp and a short commit message
      for (int i = 1; i < versions.size(); i++) {
        String text =
            // + Message.generateHTMLSpace(3)
            new Date(versions.get(i).getCommitTime() * 1000L)
                + ": "
                + versions.get(i).getShortMessage();

        // truncate texts that are too long
        int maxTextLength = 100;
        String dots = "...";

        int textLength = text.length() - dots.length();

        if (textLength > maxTextLength) {
          text = text.substring(0, maxTextLength) + dots;
        }

        versionData[versions.size() - i - 1] = new Version(text, i);

        if (text.length() > maxTextwidth) {
          maxTextwidth = text.length();
          longestText = text;
        }
      }

      resultModel = new DefaultListModel();

      // first init to show all if search not started yet
      for (int i = 0; i < versionData.length; i++) {
        resultModel.addElement(versionData[i]);
      }

      versionList = new JList(resultModel);

      // set the width of version managment window
      // dependent on largest git short message length
      double maxFontWidth =
          versionList
              .getFontMetrics(versionList.getFont())
              .getStringBounds(longestText, versionList.getGraphics())
              .getWidth();

      if (maxFontWidth <= visibleRectDim.width) {

        prefScrollPaneDim.width = (int) maxFontWidth;
      } else {

        if (visibleRectDim.width < 400) {
          prefScrollPaneDim.width = visibleRectDim.width;
        } else {
          prefScrollPaneDim.width = 400;
        }
      }

      versionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      versionList.setOpaque(false);

      versionList.setBackground(VSwingUtil.TRANSPARENT_COLOR);
      versionList.setBorder(new EmptyBorder(3, 3, 3, 3));

      Box upperTopBox = Box.createVerticalBox();

      // press the commits to top with VerticalGlue
      // contains search area at top and
      // search results at the botton
      Box upperOuterBox = Box.createVerticalBox();

      JButton searchButton = new JButton("search");
      searchButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
              searchAndAddToResultList();
            }
          });

      searchField = new JTextArea();

      // search area box
      Box upperBox1 = Box.createHorizontalBox();

      upperBox1.add(searchField);
      upperBox1.add(searchButton);

      Dimension fieldDim = new Dimension(Short.MAX_VALUE, searchField.getPreferredSize().height);
      searchField.setMaximumSize(fieldDim);

      searchField.addKeyListener(
          new KeyAdapter() {
            String tmp = "";

            @Override
            public void keyReleased(KeyEvent ke) {

              searchAndAddToResultList();
            }
          });

      //            upperOuterBox.add(upperBox1);
      upperTopBox.add(upperBox1);
      upperTopBox.add(upperOuterBox);

      // result area box
      Box upperBox2 = Box.createHorizontalBox();

      upperBox2.add(Box.createHorizontalGlue());
      upperBox2.add(versionList);
      upperBox2.add(Box.createHorizontalGlue());

      upperOuterBox.add(upperBox2);
      upperOuterBox.add(Box.createVerticalGlue());

      // added for optical reasons to force correct scrollbar position
      Box upperInnerBorderPane = Box.createHorizontalBox();
      upperInnerBorderPane.add(upperOuterBox);
      upperInnerBorderPane.setBorder(new EmptyBorder(5, 15, 5, 15));
      upperInnerBorderPane.setBackground(VSwingUtil.TRANSPARENT_COLOR);

      VScrollPane upperScrollPane = new VScrollPane(upperInnerBorderPane);
      upperScrollPane.setHorizontalScrollBarPolicy(VScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      upperScrollPane.setVerticalScrollBarPolicy(VScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      upperScrollPane.setMinimumSize(prefScrollPaneDim);

      JSplitPane splitPane = new VSplitPane(JSplitPane.VERTICAL_SPLIT);
      splitPane.setEnabled(true); // true = transparent
      splitPane.setBackground(VSwingUtil.TRANSPARENT_COLOR);
      splitPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      splitPane.setDividerLocation(0.5);

      upperTopBox.add(upperScrollPane);
      splitPane.add(upperTopBox); // add in the upper part

      htmlCommit.setBackground(VSwingUtil.TRANSPARENT_COLOR);
      htmlCommit.setContentType("text/html");
      htmlCommit.setOpaque(false);
      htmlCommit.setEditable(false);
      htmlCommit.setBorder(new EmptyBorder(0, 15, 0, 15));

      Box lowerBox = Box.createVerticalBox();
      lowerBox.setAlignmentX(Component.LEFT_ALIGNMENT);
      lowerBox.add(htmlCommit);
      lowerBox.add(Box.createVerticalGlue());

      VScrollPane lowerScrollPane = new VScrollPane(lowerBox);

      lowerScrollPane.setHorizontalScrollBarPolicy(VScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      lowerScrollPane.setVerticalScrollBarPolicy(VScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      lowerScrollPane.setMinimumSize(new Dimension(0, 0));

      // add in the lower part
      splitPane.setBottomComponent(lowerScrollPane);

      add(splitPane);

      versionList.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {

              // show commit message in lower part if clicked on a row
              // in upper part
              if (e.getClickCount() == 1) {

                final VersionController controller =
                    canvas.getProjectController().getProject().getProjectFile();

                final int numVersions = controller.getNumberOfVersions() - 1;

                ArrayList<RevCommit> versions = new ArrayList<RevCommit>();

                try {
                  versions = controller.getVersions();
                } catch (IOException ex) {
                  Logger.getLogger(VersionManagementPanel.class.getName())
                      .log(Level.SEVERE, null, ex);
                }

                int versionIndex = ((Version) versionList.getSelectedValue()).getVersion();

                htmlCommit.setText(
                    "<html>"
                        + "<pre> <font color=white><br>"
                        + "<b>SHA-1:</b> "
                        + versions.get(versionIndex).getName()
                        + "<br><br>"
                        + "<b>Message:</b><br><br>"
                        + versions.get(versionIndex).getFullMessage()
                        + "</pre></p>"
                        + "</html>");
                htmlCommit.setCaretPosition(0);
              }

              if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {

                if (((Version) versionList.getSelectedValue()).getVersion() < 2) {
                  VDialog.showMessageDialog(
                      canvas,
                      "Cannot Load Version",
                      "The first version in a project contains no"
                          + " sessions and cannot be loaded!");
                  return;
                }

                //                        if (VDialog.showConfirmDialog(canvas,
                //                                "Checkout Version:",
                //                                "<html><div align=Center>"
                //                                + "<p>Do you want to checkout the selected"
                //                                + " version?<p>"
                //                                + "<p><b>Unsaved changes will be lost!</b></p>"
                //                                + "</div></html>",
                //                                VDialog.DialogType.YES_NO) != VDialog.YES) {
                //                            return;
                //                        }

                int answer =
                    VDialog.showConfirmDialog(
                        canvas,
                        "Checkout Version:",
                        "<html><div align=Center>"
                            + "<p>Checking out selected version.<p><br>"
                            + "<p>Do you want to save the current session?</p><br>"
                            + "<p><b>Unsaved changes will be lost!</b></p>"
                            + "</div></html>",
                        new String[] {"Save", "Discard", "Cancel"});

                if (answer == 0) {
                  try {
                    canvas.getProjectController().saveProject(false);
                  } catch (IOException ex) {
                    Logger.getLogger(VersionManagement.class.getName()).log(Level.SEVERE, null, ex);

                    VDialog.showMessageDialog(
                        canvas,
                        "Cannot save Project:",
                        "<html><div align=Center>" + "Project cannot be saved!" + "</div></html>");
                  }
                } else if (answer == 1) {
                  // nothing to do
                } else if (answer == 2) {
                  return;
                }

                try {

                  int versionIndex = ((Version) versionList.getSelectedValue()).getVersion();

                  canvas.setActive(false);

                  String currentSessionName = canvas.getProjectController().getCurrentSession();

                  canvas.getProjectController().close(currentSessionName);

                  controller.checkoutVersion(versionIndex);

                  if (dialog != null) {
                    dialog.close();
                    dialog = null;
                  }

                  if (canvas
                      .getProjectController()
                      .getProject()
                      .getSessionFileByEntryName(currentSessionName)
                      .exists()) {
                    canvas.getProjectController().open(currentSessionName, false, true);
                  } else {
                    //                                VDialog.showMessageDialog(canvas,
                    //                                        "Cannot load \""
                    //                                        + currentSessionName
                    //                                        +"\":", "<html><div align=Center>"
                    //                                        + "<p>The Session "
                    //                                        + Message.EMPHASIZE_BEGIN
                    //                                        + currentSessionName
                    //                                         +  Message.EMPHASIZE_END
                    //                                        + " does not exist in the current"
                    //                                        + " version."
                    //                                        + "<p>The <b>Main</b>-Session will"
                    //                                        + "be loaded instead</div></html>");
                    canvas.getProjectController().open("Main", false, true);
                  }

                } catch (IOException ex) {
                  Logger.getLogger(VersionManagementPanel.class.getName())
                      .log(Level.SEVERE, null, ex);
                }
              }
            }
          });

      //            setMinimumSize(visibleRectDim);
      setMaximumSize(visibleRectDim);

      int width = getPreferredSize().width;
      setPreferredSize(new Dimension(width, (int) (visibleRectDim.height * 0.5)));
    } // end constructure