示例#1
0
 /**
  * Creates a new instance of ColorText Inputs: p -- reference to the Panel where you want to draw
  * the text text -- the text you wish to appear (for example, 'CS15 is awesome!') color -- the
  * java.awt.Color that you wish your text to have posX -- the x position of where the upper left
  * corner of the text should be placed posY -- the y position of where the upper left corner of
  * the text should be placed
  */
 public ColorText(JPanel p, String text, Color color, int posX, int posY) {
   _text = text;
   _font = new Font("SansSerif", Font.PLAIN, 20);
   _color = color;
   _posX = posX;
   _posY = posY;
   FontMetrics fm = p.getFontMetrics(_font);
   _size = new Dimension(fm.stringWidth(_text), fm.getHeight());
 }
示例#2
0
 private static int getPanelBaseline(JPanel panel, int height) {
   Border border = panel.getBorder();
   if (border instanceof TitledBorder) {
     TitledBorder titledBorder = (TitledBorder) border;
     if (titledBorder.getTitle() != null && !"".equals(titledBorder.getTitle())) {
       Font font = titledBorder.getTitleFont();
       if (font == null) {
         font = panel.getFont();
         if (font == null) {
           font = new Font("Dialog", Font.PLAIN, 12);
         }
       }
       Border border2 = titledBorder.getBorder();
       Insets borderInsets;
       if (border2 != null) {
         borderInsets = border2.getBorderInsets(panel);
       } else {
         borderInsets = EMPTY_INSETS;
       }
       FontMetrics fm = panel.getFontMetrics(font);
       int fontHeight = fm.getHeight();
       int descent = fm.getDescent();
       int ascent = fm.getAscent();
       int y = EDGE_SPACING;
       int h = height - EDGE_SPACING * 2;
       int diff;
       switch (((TitledBorder) border).getTitlePosition()) {
         case TitledBorder.ABOVE_TOP:
           diff = ascent + descent + (Math.max(EDGE_SPACING, TEXT_SPACING * 2) - EDGE_SPACING);
           return y + diff - (descent + TEXT_SPACING);
         case TitledBorder.TOP:
         case TitledBorder.DEFAULT_POSITION:
           diff = Math.max(0, ((ascent / 2) + TEXT_SPACING) - EDGE_SPACING);
           return (y + diff - descent) + (borderInsets.top + ascent + descent) / 2;
         case TitledBorder.BELOW_TOP:
           return y + borderInsets.top + ascent + TEXT_SPACING;
         case TitledBorder.ABOVE_BOTTOM:
           return (y + h) - (borderInsets.bottom + descent + TEXT_SPACING);
         case TitledBorder.BOTTOM:
           h -= fontHeight / 2;
           return ((y + h) - descent) + ((ascent + descent) - borderInsets.bottom) / 2;
         case TitledBorder.BELOW_BOTTOM:
           h -= fontHeight;
           return y + h + ascent + TEXT_SPACING;
       }
     }
   }
   return -1;
 }
  public CopiesPanel(final Project project) {
    myProject = project;
    myConnection = myProject.getMessageBus().connect(myProject);
    myVcs = SvnVcs.getInstance(myProject);
    myCurrentInfoList = null;

    final Runnable focus =
        new Runnable() {
          public void run() {
            IdeFocusManager.getInstance(myProject).requestFocus(myRefreshLabel, true);
          }
        };
    final Runnable refreshView =
        new Runnable() {
          public void run() {
            final List<WCInfo> infoList = myVcs.getAllWcInfos();
            if (myCurrentInfoList != null) {
              final List<OverrideEqualsWrapper<WCInfo>> newList =
                  ObjectsConvertor.convert(
                      infoList,
                      new Convertor<WCInfo, OverrideEqualsWrapper<WCInfo>>() {
                        public OverrideEqualsWrapper<WCInfo> convert(WCInfo o) {
                          return new OverrideEqualsWrapper<WCInfo>(
                              InfoEqualityPolicy.getInstance(), o);
                        }
                      },
                      ObjectsConvertor.NOT_NULL);

              if (Comparing.haveEqualElements(newList, myCurrentInfoList)) {
                myRefreshLabel.setEnabled(true);
                return;
              }
              myCurrentInfoList = newList;
            }
            Collections.sort(infoList, WCComparator.getInstance());
            updateList(infoList);
            myRefreshLabel.setEnabled(true);
            SwingUtilities.invokeLater(focus);
          }
        };
    myConnection.subscribe(
        SvnVcs.ROOTS_RELOADED,
        new Runnable() {
          public void run() {
            ApplicationManager.getApplication().invokeLater(refreshView, ModalityState.NON_MODAL);
          }
        });

    final JPanel holderPanel = new JPanel(new BorderLayout());
    FontMetrics fm = holderPanel.getFontMetrics(holderPanel.getFont());
    myTextHeight = (int) (fm.getHeight() * 1.3);
    myPanel = new JPanel(new GridBagLayout());
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(myPanel, BorderLayout.NORTH);
    holderPanel.add(panel, BorderLayout.WEST);
    myRefreshLabel =
        new MyLinkLabel(
            myTextHeight,
            "Refresh",
            new LinkListener() {
              public void linkSelected(LinkLabel aSource, Object aLinkData) {
                if (myRefreshLabel.isEnabled()) {
                  myVcs.invokeRefreshSvnRoots(true);
                  myRefreshLabel.setEnabled(false);
                }
              }
            });
    myHolder = ScrollPaneFactory.createScrollPane(holderPanel);
    myHolder.setBorder(null);
    setFocusableForLinks(myRefreshLabel);
    refreshView.run();
    initView();
  }
  public CopiesPanel(final Project project) {
    myProject = project;
    myConnection = myProject.getMessageBus().connect(myProject);
    myVcs = SvnVcs.getInstance(myProject);
    myCurrentInfoList = null;

    final Runnable focus =
        new Runnable() {
          @Override
          public void run() {
            IdeFocusManager.getInstance(myProject).requestFocus(myRefreshLabel, true);
          }
        };
    final Runnable refreshView =
        new Runnable() {
          @Override
          public void run() {
            final List<WCInfo> infoList = myVcs.getWcInfosWithErrors();
            final boolean hasErrors = !myVcs.getSvnFileUrlMapping().getErrorRoots().isEmpty();
            final List<WorkingCopyFormat> supportedFormats = getSupportedFormats();
            Runnable runnable =
                new Runnable() {
                  @Override
                  public void run() {
                    if (myCurrentInfoList != null) {
                      final List<OverrideEqualsWrapper<WCInfo>> newList =
                          ObjectsConvertor.convert(
                              infoList,
                              new Convertor<WCInfo, OverrideEqualsWrapper<WCInfo>>() {
                                @Override
                                public OverrideEqualsWrapper<WCInfo> convert(WCInfo o) {
                                  return new OverrideEqualsWrapper<WCInfo>(
                                      InfoEqualityPolicy.getInstance(), o);
                                }
                              },
                              ObjectsConvertor.NOT_NULL);

                      if (Comparing.haveEqualElements(newList, myCurrentInfoList)) {
                        myRefreshLabel.setEnabled(true);
                        return;
                      }
                      myCurrentInfoList = newList;
                    }
                    Collections.sort(infoList, WCComparator.getInstance());
                    updateList(infoList, supportedFormats);
                    myRefreshLabel.setEnabled(true);
                    showErrorNotification(hasErrors);
                    SwingUtilities.invokeLater(focus);
                  }
                };
            ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL);
          }
        };
    final Consumer<Boolean> refreshOnPooled =
        new Consumer<Boolean>() {
          @Override
          public void consume(Boolean somethingNew) {
            if (Boolean.TRUE.equals(somethingNew)) {
              if (ApplicationManager.getApplication().isUnitTestMode()) {
                refreshView.run();
              } else {
                ApplicationManager.getApplication().executeOnPooledThread(refreshView);
              }
            } else {
              ApplicationManager.getApplication()
                  .invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          myRefreshLabel.setEnabled(true);
                        }
                      },
                      ModalityState.NON_MODAL);
            }
          }
        };
    myConnection.subscribe(SvnVcs.ROOTS_RELOADED, refreshOnPooled);

    final JPanel holderPanel = new JPanel(new BorderLayout());
    FontMetrics fm = holderPanel.getFontMetrics(holderPanel.getFont());
    myTextHeight = (int) (fm.getHeight() * 1.3);
    myPanel = new JPanel(new GridBagLayout());
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(myPanel, BorderLayout.NORTH);
    holderPanel.add(panel, BorderLayout.WEST);
    myRefreshLabel =
        new MyLinkLabel(
            myTextHeight,
            "Refresh",
            new LinkListener() {
              @Override
              public void linkSelected(LinkLabel aSource, Object aLinkData) {
                if (myRefreshLabel.isEnabled()) {
                  myVcs.invokeRefreshSvnRoots();
                  myRefreshLabel.setEnabled(false);
                }
              }
            });
    final JScrollPane pane = ScrollPaneFactory.createScrollPane(holderPanel);
    myHolder = pane;
    final JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.setBlockIncrement(vBar.getBlockIncrement() * 5);
    vBar.setUnitIncrement(vBar.getUnitIncrement() * 5);
    myHolder.setBorder(null);
    setFocusableForLinks(myRefreshLabel);
    refreshOnPooled.consume(true);
    initView();
  }