Example #1
1
 public int getTitleHeight(Component c) {
   int th = 21;
   int fh = getBorderInsets(c).top + getBorderInsets(c).bottom;
   if (c instanceof JDialog) {
     JDialog dialog = (JDialog) c;
     th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1;
     if (dialog.getJMenuBar() != null) {
       th -= dialog.getJMenuBar().getSize().height;
     }
   } else if (c instanceof JInternalFrame) {
     JInternalFrame frame = (JInternalFrame) c;
     th = frame.getSize().height - frame.getRootPane().getSize().height - fh - 1;
     if (frame.getJMenuBar() != null) {
       th -= frame.getJMenuBar().getSize().height;
     }
   } else if (c instanceof JRootPane) {
     JRootPane jp = (JRootPane) c;
     if (jp.getParent() instanceof JFrame) {
       JFrame frame = (JFrame) c.getParent();
       th = frame.getSize().height - frame.getContentPane().getSize().height - fh - 1;
       if (frame.getJMenuBar() != null) {
         th -= frame.getJMenuBar().getSize().height;
       }
     } else if (jp.getParent() instanceof JDialog) {
       JDialog dialog = (JDialog) c.getParent();
       th = dialog.getSize().height - dialog.getContentPane().getSize().height - fh - 1;
       if (dialog.getJMenuBar() != null) {
         th -= dialog.getJMenuBar().getSize().height;
       }
     }
   }
   return th;
 }
 @Override
 public Insets getBorderInsets(final Component c) {
   if (myProject == null) return new Insets(0, 0, 0, 0);
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
   if (!(toolWindowManager instanceof ToolWindowManagerImpl)
       || !((ToolWindowManagerImpl) toolWindowManager).isToolWindowRegistered(myInfo.getId())
       || myWindow.getType() == ToolWindowType.FLOATING) {
     return new Insets(0, 0, 0, 0);
   }
   ToolWindowAnchor anchor = myWindow.getAnchor();
   Component component = myWindow.getComponent();
   Container parent = component.getParent();
   while (parent != null) {
     if (parent instanceof Splitter) {
       Splitter splitter = (Splitter) parent;
       boolean isFirst = splitter.getFirstComponent() == component;
       boolean isVertical = splitter.isVertical();
       return new Insets(
           0,
           anchor == ToolWindowAnchor.RIGHT || (!isVertical && !isFirst) ? 1 : 0,
           (isVertical && isFirst) ? 1 : 0,
           anchor == ToolWindowAnchor.LEFT || (!isVertical && isFirst) ? 1 : 0);
     }
     component = parent;
     parent = component.getParent();
   }
   return new Insets(
       0,
       anchor == ToolWindowAnchor.RIGHT ? 1 : 0,
       anchor == ToolWindowAnchor.TOP ? 1 : 0,
       anchor == ToolWindowAnchor.LEFT ? 1 : 0);
 }
Example #3
0
  /**
   * We generally draw lines to/from the <I>center</I> of components; this method finds the center
   * of the argument's enclosing rectangle
   *
   * @return Point at the center of <CODE>c</CODE>
   * @param c The component whose center point we wish to determine
   */
  protected Point getCenterLocation(Component c) {

    Point p1 = new Point();
    Point p2 = new Point();

    // start with the relative location...
    c.getLocation(p1);
    // get to the middle of the fractionsLabel
    Dimension d = c.getSize();
    p1.x += d.width / 2;
    p1.y += d.height / 2;

    Component parent = c.getParent();
    // System.err.println("parent=" + parent);

    while (parent != null) {
      parent.getLocation(p2);
      p1.x += p2.x;
      p1.y += p2.y;

      if (STOP.equals(parent.getName())) break;

      parent = parent.getParent();
    }
    return p1;
  }
 @Override
 public void createToolWindowContent(Project project, ToolWindow toolWindow) {
   Component component = toolWindow.getComponent();
   JPanel kevoreeEditorPanel = KevoreeEditorComponent.getInstance(project).kevoreeEditorPanel;
   if (kevoreeEditorPanel != null) {
     component.getParent().add(kevoreeEditorPanel);
   } else {
     component.getParent().add(new JLabel("loading..."));
   }
 }
  public static final int getComponentIndex(Component component) {
    if (component != null && component.getParent() != null) {
      Container container = component.getParent();
      for (int i = 0; i < container.getComponentCount(); i++) {
        if (container.getComponent(i) == component) return i;
      }
    }

    return -1;
  }
  protected Frame getFrame(Component comp) {
    if (comp == null) {
      comp = this;
    }

    if (comp.getParent() instanceof Frame) {
      return (Frame) comp.getParent();
    }

    return getFrame(comp.getParent());
  }
  public static void getComponentTreePosition(Component component, ArrayList pos) {
    if (component.getParent() == null) {
      return;
    }

    getComponentTreePosition(component.getParent(), pos);

    pos.add(
        new Integer(
            component.getParent().getComponentCount()
                - ComponentUtil.getComponentIndex(component)));
  }
  @Override
  protected boolean isInState(JComponent c) {

    Component parent = c;
    while (parent.getParent() != null) {
      if (parent instanceof JInternalFrame) {
        break;
      }
      parent = parent.getParent();
    }
    if (parent instanceof JInternalFrame) {
      return !(((JInternalFrame) parent).isSelected());
    }
    return false;
  }
Example #9
0
 public static void hidePopups(Component comp) {
   if (comp != null) {
     label0:
     for (Component c = comp; c != null; c = c.getParent()) {
       if (!(c instanceof ZPopupGallery)) continue;
       do {
         if (currShownList.size() <= 0) continue label0;
         if (currShownList.getLast() == c) return;
         ZPopupGallery jpg = (ZPopupGallery) currShownList.removeLast();
         Popup popup = (Popup) popupGalleryHM.get(jpg);
         popup.hide();
         popupGalleryHM.remove(jpg);
       } while (true);
     }
   }
   Iterator iterator = popupGalleryHM.keySet().iterator();
   do {
     if (!iterator.hasNext()) break;
     ZPopupGallery gallery = (ZPopupGallery) iterator.next();
     ((Popup) popupGalleryHM.get(gallery)).hide();
     if (gallery.getActionListener() != null)
       gallery.getActionListener().actionPerformed(new ActionEvent(gallery, 1, "Hidden"));
   } while (true);
   popupGalleryHM.clear();
 }
Example #10
0
 public static Frame findParentFrame(Component parent) {
   while (true) {
     if (parent == null) return null;
     if (parent instanceof Frame) return (Frame) parent;
     parent = parent.getParent();
   }
 }
 private void disposeAndUpdate(boolean update) {
   if (myView != null) {
     boolean visible = myView.isVisible();
     myView.setVisible(false);
     Container container = myContent.getParent();
     if (container != null) {
       container.remove(myContent);
     }
     if (myView instanceof Window) {
       myViewBounds = myView.getBounds();
       Window window = (Window) myView;
       if (!push(UIUtil.getWindow(myOwner), window)) {
         window.dispose();
       }
     } else {
       Container parent = myView.getParent();
       if (parent == null) {
         myViewBounds = new Rectangle(myContent.getPreferredSize());
       } else {
         myViewBounds = new Rectangle(myView.getBounds());
         parent.remove(myView);
         Point point = new Point(myViewBounds.x, myViewBounds.y);
         SwingUtilities.convertPointToScreen(point, parent);
         myViewBounds.x = point.x;
         myViewBounds.y = point.y;
       }
     }
     myView = null;
     if (update && visible) {
       setVisible(true);
     }
   }
 }
Example #12
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   Color borderColorLo = AbstractLookAndFeel.getFrameColor();
   Color borderColorHi =
       ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40);
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || model.isSelected()) {
       g.setColor(borderColorLo);
       g.drawLine(x, y, x + w - 1, y);
       g.drawLine(x, y, x, y + h - 1);
       g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
       g.setColor(borderColorHi);
       g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
       g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(borderColorLo);
       g.drawLine(x, y, x + w - 1, y);
       g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
       g.setColor(borderColorHi);
       g.drawLine(x, y + 1, x + w - 2, y + 1);
     }
   }
 }
Example #13
0
  /**
   * Creates a new AWT <tt>Container</tt> which can display a single <tt>Component</tt> at a time
   * (supposedly, one which represents video) and, in the absence of such a <tt>Component</tt>,
   * displays a predefined default <tt>Component</tt> (in accord with the previous supposition, one
   * which is the default when there is no video). The returned <tt>Container</tt> will track the
   * <tt>Components</tt>s added to and removed from it in order to make sure that
   * <tt>noVideoContainer</tt> is displayed as described.
   *
   * @param noVideoComponent the predefined default <tt>Component</tt> to be displayed in the
   *     returned <tt>Container</tt> when there is no other <tt>Component</tt> in it
   * @return a new <tt>Container</tt> which can display a single <tt>Component</tt> at a time and,
   *     in the absence of such a <tt>Component</tt>, displays <tt>noVideoComponent</tt>
   */
  private VideoContainer createVideoContainer(Component noVideoComponent) {
    Container oldParent = noVideoComponent.getParent();

    if (oldParent != null) oldParent.remove(noVideoComponent);

    return new VideoContainer(noVideoComponent, false);
  }
Example #14
0
  private Insets getButtonInsets(SynthContext context, Insets insets) {
    // The following calculations are derived from gtkbutton.c
    // (GTK+ version 2.8.20), gtk_button_size_allocate() method.
    int CHILD_SPACING = 1;
    int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
    int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
    int xThickness = getXThickness();
    int yThickness = getYThickness();
    int w = focusSize + focusPad + xThickness + CHILD_SPACING;
    int h = focusSize + focusPad + yThickness + CHILD_SPACING;
    insets.left = insets.right = w;
    insets.top = insets.bottom = h;

    Component component = context.getComponent();
    if ((component instanceof JButton)
        && !(component.getParent() instanceof JToolBar)
        && ((JButton) component).isDefaultCapable()) {
      // Include the default border insets, but only for JButtons
      // that are default capable.  Note that
      // JButton.getDefaultCapable() returns true by default, but
      // GtkToolButtons are never default capable, so we skip this
      // step if the button is contained in a toolbar.
      Insets defaultInsets =
          getClassSpecificInsetsValue(context, "default-border", BUTTON_DEFAULT_BORDER_INSETS);
      insets.left += defaultInsets.left;
      insets.right += defaultInsets.right;
      insets.top += defaultInsets.top;
      insets.bottom += defaultInsets.bottom;
    }

    return insets;
  }
Example #15
0
    @Override
    public void keyPressed(KeyEvent evt) {
      if (evt.isConsumed()) return;
      Component comp = getFocusOwner();
      if (evt.getKeyCode() == KeyEvent.VK_ENTER && enterEnabled) {
        while (comp != null) {
          if (comp instanceof JComboBox) {
            JComboBox<?> combo = (JComboBox<?>) comp;
            if (combo.isEditable()) {
              Object selected = combo.getEditor().getItem();
              if (selected != null) combo.setSelectedItem(selected);
            }

            if (combo.isPopupVisible()) {
              evt.consume();
              combo.setPopupVisible(false);
            }
            return;
          }
          // TODO: add other classes that need custom key handling here.
          comp = comp.getParent();
        }
        evt.consume();
        ok();
      } else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE || isCloseBufferShortcut(evt)) {
        evt.consume();
        if (comp instanceof JComboBox) {
          JComboBox<?> combo = (JComboBox<?>) comp;
          if (combo.isPopupVisible()) combo.setPopupVisible(false);
          else cancel();
        } else cancel();
      }
    }
 public static Component getTopLevelAncestor(Component component) {
   Component componentTemp = component;
   while (componentTemp != null) {
     if (componentTemp instanceof Window || componentTemp instanceof Applet) break;
     componentTemp = componentTemp.getParent();
   }
   return componentTemp;
 }
 /** Return the JComboBox for the given event, or null if none. */
 private JComboBox getComboBox(AWTEvent event) {
   Component comp = (Component) event.getSource();
   // Depends somewhat on LAF; sometimes the combo box is itself the
   // button, sometimes a panel containing the button.
   if (comp instanceof javax.swing.JButton) comp = comp.getParent();
   if (comp instanceof JComboBox) return (JComboBox) comp;
   return null;
 }
  public static JFrame getFrame(Component c) {
    if (c instanceof JFrame) return (JFrame) c;

    while ((c = c.getParent()) != null) {
      if (c instanceof JFrame) return (JFrame) c;
    }
    return null;
  }
Example #19
0
    void recursivelyHandleMagnify(final MagnificationEvent e) {
      for (final MagnificationListener listener : handler.magnifiers) {
        listener.magnify(e);
        if (e.isConsumed()) return;
      }

      final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
      if (next != null) next.recursivelyHandleMagnify(e);
    }
Example #20
0
 /**
  * Returns the specified component's toplevel {@code Frame} or {@code Dialog}.
  *
  * @param parentComponent the {@code Component} to check for a {@code Frame} or {@code Dialog}
  * @return the {@code Frame} or {@code Dialog} that contains the component, or the default frame
  *     if the component is {@code null}, or does not have a valid {@code Frame} or {@code Dialog}
  *     parent
  */
 static Window getWindowForComponent(Component parentComponent) {
   if (parentComponent == null) {
     return JOptionPane.getRootFrame();
   }
   if (parentComponent instanceof Frame || parentComponent instanceof Dialog) {
     return (Window) parentComponent;
   }
   return getWindowForComponent(parentComponent.getParent());
 }
Example #21
0
    void recursivelyHandlePressure(final PressureEvent e) {
      for (final PressureListener listener : handler.pressures) {
        listener.pressure(e);
        if (e.isConsumed()) return;
      }

      final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
      if (next != null) next.recursivelyHandlePressure(e);
    }
Example #22
0
 private JComboBox getParentComboBox(Component comp) {
   do {
     if (comp instanceof JComboBox) {
       return (JComboBox) comp;
     }
     comp = comp.getParent();
   } while (comp != null);
   return null;
 }
Example #23
0
 /**
  * Checks whether the specified component or one of its ancestors has the specified client
  * property set to {@link Boolean#TRUE}.
  *
  * @param c Component.
  * @param clientPropName Client property name.
  * @return <code>true</code> if the specified component or one of its ancestors has the
  *     specified client property set to {@link Boolean#TRUE}, <code>false</code> otherwise.
  */
 private boolean hasClientPropertySetToTrue(Component c, String clientPropName) {
   while (c != null) {
     if (c instanceof JComponent) {
       JComponent jc = (JComponent) c;
       if (Boolean.TRUE.equals(jc.getClientProperty(clientPropName))) return true;
     }
     c = c.getParent();
   }
   return false;
 }
  public static JTableRenderer getVertex(Component component) {
    while (component != null) {
      if (component instanceof JTableRenderer) {
        return (JTableRenderer) component;
      }
      component = component.getParent();
    }

    return null;
  }
Example #25
0
  // recursive helper to find the next component/handler pair
  static PerComponentNotifier getNextNotifierForComponent(final Component c) {
    if (c == null) return null;

    final GestureHandler handler = getHandlerForComponent(c);
    if (handler != null) {
      return new PerComponentNotifier(c, handler);
    }

    return getNextNotifierForComponent(c.getParent());
  }
 private static boolean isHorizontalScrolling(Component c, MouseEvent e) {
   if (c != null
       && e instanceof MouseWheelEvent
       && (!SystemInfo.isMac || isDiagramViewComponent(c.getParent()))) {
     final MouseWheelEvent mwe = (MouseWheelEvent) e;
     return mwe.isShiftDown()
         && mwe.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL
         && findHorizontalScrollBar(c) != null;
   }
   return false;
 }
Example #27
0
 public boolean isResizable(Component c) {
   boolean resizable = true;
   if (c instanceof JDialog) {
     JDialog dialog = (JDialog) c;
     resizable = dialog.isResizable();
   } else if (c instanceof JInternalFrame) {
     JInternalFrame frame = (JInternalFrame) c;
     resizable = frame.isResizable();
   } else if (c instanceof JRootPane) {
     JRootPane jp = (JRootPane) c;
     if (jp.getParent() instanceof JFrame) {
       JFrame frame = (JFrame) c.getParent();
       resizable = frame.isResizable();
     } else if (jp.getParent() instanceof JDialog) {
       JDialog dialog = (JDialog) c.getParent();
       resizable = dialog.isResizable();
     }
   }
   return resizable;
 }
 public void internalFrameClosed(InternalFrameEvent e) {
   Component cont = getParent();
   while ((cont != null) && (!(cont instanceof JInternalFrame))) {
     cont = cont.getParent();
   }
   if (cont != null) {
     if (!((JInternalFrame) cont).isClosed()) {
       refreshMe();
     }
   }
 }
    public void propertyChange(PropertyChangeEvent ev) {
      if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) { // NOI18N
        return;
      }

      Component c = focusManager.getPermanentFocusOwner();
      while (c != null) {
        if (c == JListMutable.this) {
          // focus remains inside the table
          return;
        } else if ((c instanceof Window) || (c instanceof Applet && c.getParent() == null)) {
          if (c == SwingUtilities.getRoot(JListMutable.this)) {
            if (!getListCellEditor().stopCellEditing()) {
              getListCellEditor().cancelCellEditing();
            }
          }
          break;
        }
        c = c.getParent();
      }
    }
Example #30
0
    void recursivelyHandleSwipe(final double x, final double y, final SwipeEvent e) {
      for (final SwipeListener listener : handler.swipers) {
        if (x < 0) listener.swipedLeft(e);
        if (x > 0) listener.swipedRight(e);
        if (y < 0) listener.swipedDown(e);
        if (y > 0) listener.swipedUp(e);
        if (e.isConsumed()) return;
      }

      final PerComponentNotifier next = getNextNotifierForComponent(component.getParent());
      if (next != null) next.recursivelyHandleSwipe(x, y, e);
    }