Exemplo n.º 1
0
 protected boolean accept(Component jc) {
   if (extListener != null && extListener.accept(jc)) {
     return true;
   }
   if (!(jc instanceof JComponent)) {
     return false;
   }
   if (jc instanceof TableCellEditor
       || jc instanceof TreeCellEditor
       || SwingUtilities.getAncestorOfClass(JTable.class, jc) != null
       || SwingUtilities.getAncestorOfClass(JTree.class, jc) != null
       || SwingUtilities.getAncestorOfClass(JList.class, jc) != null) {
     // Don't listen to cell editors, we can end up listening to them
     // multiple times, and the tree/table model will give us the event
     // we need
     return false;
   }
   return isProbablyAContainer(jc)
       || jc instanceof JList
       || jc instanceof JComboBox
       || jc instanceof JTree
       || jc instanceof JToggleButton
       || // covers toggle, radio, checkbox
       jc instanceof JTextComponent
       || jc instanceof JColorChooser
       || jc instanceof JSpinner
       || jc instanceof JSlider;
 }
Exemplo n.º 2
0
  /**
   * Displays a custom file chooser sheet with a custom approve button.
   *
   * @param chooser the chooser
   * @param parent the parent component of the dialog; can be {@code null}
   * @param approveButtonText the text of the {@code ApproveButton}
   * @param listener The listener for SheetEvents.
   */
  public static void showSheet(
      final JFileChooser chooser,
      Component parent,
      String approveButtonText,
      SheetListener listener) {
    if (approveButtonText != null) {
      chooser.setApproveButtonText(approveButtonText);
      chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
    }

    // Begin Create Dialog
    Frame frame =
        parent instanceof Frame
            ? (Frame) parent
            : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    String title = chooser.getUI().getDialogTitle(chooser);
    chooser.getAccessibleContext().setAccessibleDescription(title);

    final JSheet sheet = new JSheet(frame);
    sheet.addSheetListener(listener);

    Container contentPane = sheet.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(chooser, BorderLayout.CENTER);
    // End Create Dialog

    final ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent evt) {
            int option;
            if (evt.getActionCommand().equals("ApproveSelection")) {
              option = JFileChooser.APPROVE_OPTION;
            } else {
              option = JFileChooser.CANCEL_OPTION;
            }
            sheet.hide();
            sheet.fireOptionSelected(chooser, option);
            chooser.removeActionListener(this);
          }
        };
    chooser.addActionListener(actionListener);
    sheet.addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            sheet.fireOptionSelected(chooser, JFileChooser.CANCEL_OPTION);
            chooser.removeActionListener(actionListener);
          }
        });
    chooser.rescanCurrentDirectory();
    sheet.pack();
    sheet.show();
    sheet.toFront();
  }
Exemplo n.º 3
0
  public static JDialog createDialog(JComponent parent, OWLEditorKit editorKit) {
    JFrame parentFrame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, parent);
    final JDialog dialog = new JDialog(parentFrame, "Search", Dialog.ModalityType.MODELESS);

    final SearchDialogPanel searchDialogPanel = new SearchDialogPanel(editorKit);
    searchDialogPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    searchDialogPanel
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "CLOSE_DIALOG");
    searchDialogPanel
        .getActionMap()
        .put(
            "CLOSE_DIALOG",
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
              }
            });

    searchDialogPanel
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "CLOSE_DIALOG_WITH_ENTER");
    searchDialogPanel
        .getActionMap()
        .put(
            "CLOSE_DIALOG_WITH_ENTER",
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
                searchDialogPanel.selectEntity();
              }
            });

    dialog.setContentPane(searchDialogPanel);
    dialog.setResizable(true);
    dialog.pack();
    dialog.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowOpened(WindowEvent e) {
            searchDialogPanel.searchField.requestFocusInWindow();
          }
        });
    return dialog;
  }
  /**
   * Show tracker
   *
   * @param parent GUI parent widget
   */
  public final void show(final Component parent) {
    Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);

    dialog.getContentPane().setLayout(new BorderLayout());

    label = new JLabel(START_HTML + labelText + END_HTML);

    JPanel labelPanel = new JPanel();
    labelPanel.setLayout(new BorderLayout());
    labelPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    labelPanel.add(label, BorderLayout.CENTER);

    dialog.getContentPane().add(labelPanel, BorderLayout.CENTER);

    dialog.pack();
    Windows.centerOnScreen(dialog);
    dialog.show();
  }
Exemplo n.º 5
0
  /**
   * @param parent parent component which is used to calculate heavy weight window ancestor. <code>
   *     parent</code> cannot be <code>null</code> and must be showing.
   */
  protected DialogWrapperPeerImpl(
      @NotNull DialogWrapper wrapper, @NotNull Component parent, boolean canBeParent) {
    myWrapper = wrapper;
    if (!parent.isShowing() && parent != JOptionPane.getRootFrame()) {
      throw new IllegalArgumentException("parent must be showing: " + parent);
    }
    myWindowManager = null;
    Application application = ApplicationManager.getApplication();
    if (application != null && application.hasComponent(WindowManager.class)) {
      myWindowManager = (WindowManagerEx) WindowManager.getInstance();
    }

    Window owner =
        parent instanceof Window
            ? (Window) parent
            : (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);
    if (!(owner instanceof Dialog) && !(owner instanceof Frame)) {
      owner = JOptionPane.getRootFrame();
    }
    createDialog(owner, canBeParent);
  }
  /** Applies specified decoration. */
  public final void apply(@NotNull WindowInfoImpl info) {
    if (Comparing.equal(myInfo, info) || myProject == null || myProject.isDisposed()) {
      return;
    }
    myInfo = info;

    // Anchor
    final ToolWindowAnchor anchor = myInfo.getAnchor();
    if (info.isSliding()) {
      myDivider.invalidate();
      if (ToolWindowAnchor.TOP == anchor) {
        add(myDivider, BorderLayout.SOUTH);
      } else if (ToolWindowAnchor.LEFT == anchor) {
        add(myDivider, BorderLayout.EAST);
      } else if (ToolWindowAnchor.BOTTOM == anchor) {
        add(myDivider, BorderLayout.NORTH);
      } else if (ToolWindowAnchor.RIGHT == anchor) {
        add(myDivider, BorderLayout.WEST);
      }
      myDivider.setPreferredSize(new Dimension(0, 0));
    } else { // docked and floating windows don't have divider
      remove(myDivider);
    }

    validate();
    repaint();

    // Push "apply" request forward

    if (myInfo.isFloating() && myInfo.isVisible()) {
      final FloatingDecorator floatingDecorator =
          (FloatingDecorator) SwingUtilities.getAncestorOfClass(FloatingDecorator.class, this);
      if (floatingDecorator != null) {
        floatingDecorator.apply(myInfo);
      }
    }

    myToolWindow.getContentUI().setType(myInfo.getContentUiType());
    setBorder(new InnerPanelBorder(myToolWindow));
  }
Exemplo n.º 7
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();
      }
    }