Esempio n. 1
0
 @Override
 public synchronized void setIconImages(List<? extends Image> icons) {
   super.setIconImages(icons);
   this.wasSetIconImagesCalled = true;
 }
Esempio n. 2
0
 private void setLegacyIconImages(List<Image> images) {
   if (this.wasSetIconImagesCalled) {
     return;
   }
   super.setIconImages(images);
 }
Esempio n. 3
0
  /** Initializes the layout and the ribbon. */
  private void initRibbon() {
    this.setLayout(new RibbonFrameLayout());
    this.ribbon = new JRibbon(this);
    this.add(this.ribbon, BorderLayout.NORTH);

    // this.keyTipManager = new KeyTipManager(this);
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              private boolean prevAltModif = false;

              @Override
              public void eventDispatched(AWTEvent event) {
                Object src = event.getSource();
                if (src instanceof Component) {
                  Component c = (Component) src;
                  if ((c == JRibbonFrame.this)
                      || (SwingUtilities.getWindowAncestor(c) == JRibbonFrame.this)) {
                    if (event instanceof KeyEvent) {
                      KeyEvent keyEvent = (KeyEvent) event;
                      // System.out.println(keyEvent.getID() + ":"
                      // + keyEvent.getKeyCode());
                      switch (keyEvent.getID()) {
                        case KeyEvent.KEY_PRESSED:
                          // if (keyEvent.getKeyCode() ==
                          // KeyEvent.VK_ESCAPE) {
                          // keyTipManager.showPreviousChain();
                          // }

                          break;
                        case KeyEvent.KEY_RELEASED:
                          boolean wasAltModif = prevAltModif;
                          prevAltModif = keyEvent.getModifiersEx() == InputEvent.ALT_DOWN_MASK;
                          if (wasAltModif && keyEvent.getKeyCode() == KeyEvent.VK_ALT) break;
                          char keyChar = keyEvent.getKeyChar();
                          if (Character.isLetter(keyChar) || Character.isDigit(keyChar)) {
                            // System.out.println("Will handle key press "
                            // + keyChar);
                            KeyTipManager.defaultManager().handleKeyPress(keyChar);
                          }
                          if ((keyEvent.getKeyCode() == KeyEvent.VK_ALT)
                              || (keyEvent.getKeyCode() == KeyEvent.VK_F10)) {
                            if (keyEvent.getModifiers() != 0 || keyEvent.getModifiersEx() != 0)
                              break;
                            boolean hadPopups =
                                !PopupPanelManager.defaultManager().getShownPath().isEmpty();
                            PopupPanelManager.defaultManager().hidePopups(null);
                            if (hadPopups || KeyTipManager.defaultManager().isShowingKeyTips()) {
                              KeyTipManager.defaultManager().hideAllKeyTips();
                            } else {
                              KeyTipManager.defaultManager().showRootKeyTipChain(JRibbonFrame.this);
                            }
                          }
                          if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) {
                            // System.out.println("In KTM");
                            KeyTipManager.defaultManager().showPreviousChain();
                          }
                          break;
                      }
                    }
                    if (event instanceof MouseEvent) {
                      MouseEvent mouseEvent = (MouseEvent) event;
                      switch (mouseEvent.getID()) {
                        case MouseEvent.MOUSE_CLICKED:
                        case MouseEvent.MOUSE_DRAGGED:
                        case MouseEvent.MOUSE_PRESSED:
                        case MouseEvent.MOUSE_RELEASED:
                          KeyTipManager.defaultManager().hideAllKeyTips();
                      }
                    }
                  }
                }
              }
            },
            AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);

    final KeyTipLayer keyTipLayer = new KeyTipLayer();
    JRootPane rootPane = this.getRootPane();
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    final LayoutManager currLM = rootPane.getLayout();
    rootPane.setLayout(
        new LayoutManager() {
          @Override
          public void addLayoutComponent(String name, Component comp) {
            currLM.addLayoutComponent(name, comp);
          }

          @Override
          public void layoutContainer(Container parent) {
            currLM.layoutContainer(parent);
            JRibbonFrame ribbonFrame = JRibbonFrame.this;
            if (ribbonFrame.getRootPane().getWindowDecorationStyle() != JRootPane.NONE)
              keyTipLayer.setBounds(ribbonFrame.getRootPane().getBounds());
            else keyTipLayer.setBounds(ribbonFrame.getRootPane().getContentPane().getBounds());
          }

          @Override
          public Dimension minimumLayoutSize(Container parent) {
            return currLM.minimumLayoutSize(parent);
          }

          @Override
          public Dimension preferredLayoutSize(Container parent) {
            return currLM.preferredLayoutSize(parent);
          }

          @Override
          public void removeLayoutComponent(Component comp) {
            currLM.removeLayoutComponent(comp);
          }
        });
    // layeredPane.setLayout(new OverlayLayout(layeredPane));
    layeredPane.add(keyTipLayer, (Integer) (JLayeredPane.DEFAULT_LAYER + 60));

    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowDeactivated(WindowEvent e) {
            // hide all key tips on window deactivation
            KeyTipManager keyTipManager = KeyTipManager.defaultManager();
            if (keyTipManager.isShowingKeyTips()) {
              keyTipManager.hideAllKeyTips();
            }
          }
        });

    KeyTipManager.defaultManager()
        .addKeyTipListener(
            new KeyTipManager.KeyTipListener() {
              @Override
              public void keyTipsHidden(KeyTipEvent event) {
                if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(false);
              }

              @Override
              public void keyTipsShown(KeyTipEvent event) {
                if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(true);
              }
            });

    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    super.setIconImages(Arrays.asList(FlamingoUtilities.getBlankImage(16, 16)));
  }