Beispiel #1
0
  private void setApplicationAndMenuButtonIcon(final ResizableIcon icon) {
    if (System.getProperty("os.name").startsWith("Mac")) {
      class MacImages {
        Image icon16;

        Image icon128;

        public MacImages(Image icon16, Image icon128) {
          this.icon16 = icon16;
          this.icon128 = icon128;
        }
      }

      final Image image16 = getImage(icon, 16);
      final Image image128 = getImage(icon, 128);
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              if (image16 != null) {
                setLegacyIconImages(Arrays.asList(image16));
              }
              if (image128 != null) {
                try {
                  Class appClass = Class.forName("com.apple.eawt.Application");
                  if (appClass != null) {
                    Object appInstance = appClass.newInstance();
                    Method setDockImageMethod =
                        appClass.getDeclaredMethod("setDockIconImage", Image.class);
                    if (setDockImageMethod != null) {
                      setDockImageMethod.invoke(appInstance, image128);
                    }
                  }
                } catch (Throwable t) {
                  t.printStackTrace();
                  // give up
                }
              }
              setMainAppIcon(icon);
            }
          });
    } else {
      final List<Image> images = new ArrayList<Image>();
      Image icon16 = getImage(icon, 16);
      if (icon16 != null) images.add(icon16);
      Image icon32 = getImage(icon, 32);
      if (icon32 != null) images.add(icon32);
      Image icon64 = getImage(icon, 64);
      if (icon64 != null) images.add(icon64);
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              if (!images.isEmpty()) setLegacyIconImages(images);
              setMainAppIcon(icon);
            }
          });
    }
  }
Beispiel #2
0
    @Override
    protected void paintComponent(Graphics g) {
      JRibbonFrame ribbonFrame = (JRibbonFrame) SwingUtilities.getWindowAncestor(this);
      if (!ribbonFrame.isShowingKeyTips()) return;

      // don't show keytips on inactive windows
      if (!ribbonFrame.isActive()) return;

      Collection<KeyTipManager.KeyTipLink> keyTips =
          KeyTipManager.defaultManager().getCurrentlyShownKeyTips();
      if (keyTips != null) {
        Graphics2D g2d = (Graphics2D) g.create();
        RenderingUtils.installDesktopHints(g2d);

        for (KeyTipManager.KeyTipLink keyTip : keyTips) {
          // don't display keytips on components in popup panels
          if (SwingUtilities.getAncestorOfClass(JPopupPanel.class, keyTip.comp) != null) continue;

          // don't display key tips on hidden components
          Rectangle compBounds = keyTip.comp.getBounds();
          if (!keyTip.comp.isShowing()
              || (compBounds.getWidth() == 0)
              || (compBounds.getHeight() == 0)) continue;

          Dimension pref =
              KeyTipRenderingUtilities.getPrefSize(g2d.getFontMetrics(), keyTip.keyTipString);

          Point prefCenter = keyTip.prefAnchorPoint;
          Point loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, this);
          Container bandControlPanel =
              SwingUtilities.getAncestorOfClass(AbstractBandControlPanel.class, keyTip.comp);
          if (bandControlPanel != null) {
            // special case for controls in threesome
            // ribbon band rows
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.TOP_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = 0;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = 0;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.MID_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight() / 2;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight() / 2;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.BOTTOM_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight();
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight();
            }
          }

          KeyTipRenderingUtilities.renderKeyTip(
              g2d,
              this,
              new Rectangle(
                  loc.x - pref.width / 2, loc.y - pref.height / 2, pref.width, pref.height),
              keyTip.keyTipString,
              keyTip.enabled);
        }

        g2d.dispose();
      }
    }