Esempio n. 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;
 }
 /** Find the first ancestor <em>not</em> descending from a {@link CellRendererPane}. */
 private Component findNonRendererAncestor(Component c) {
   Component ancestor = SwingUtilities.getAncestorOfClass(CellRendererPane.class, c);
   if (ancestor != null && ancestor != c && ancestor.getParent() != null) {
     c = findNonRendererAncestor(ancestor.getParent());
   }
   return c;
 }
 @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);
 }
Esempio n. 4
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;
  }
Esempio n. 5
0
  public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    // choose which colors we want to use
    Color bg = c.getBackground();

    if (c.getParent() != null) {
      bg = c.getParent().getBackground();
    }

    if (bg != null) {
      Color mid = bg.darker();
      Color edge = average(mid, bg);

      g.setColor(bg);
      g.drawLine(0, h - 2, w, h - 2);
      g.drawLine(0, h - 1, w, h - 1);
      g.drawLine(w - 2, 0, w - 2, h);
      g.drawLine(w - 1, 0, w - 1, h);

      // draw the drop-shadow
      g.setColor(mid);
      g.drawLine(1, h - 2, w - 2, h - 2);
      g.drawLine(w - 2, 1, w - 2, h - 2);

      g.setColor(edge);
      g.drawLine(2, h - 1, w - 2, h - 1);
      g.drawLine(w - 1, 2, w - 1, h - 2);
    }
  }
  /**
   * method called when the action has to be performed
   *
   * @param e an ActionEvent
   */
  public void actionPerformed(ActionEvent e) {
    this.newlyCreatedItem = null;

    Object item = this.getType();
    if (item instanceof SibCollection) {
      SibCollection collection = (SibCollection) item;
      if (collection.isCreateAuthorized()) {
        Component c = null;

        Frame frame = null;

        if (e.getSource() instanceof Component) {
          c = (Component) e.getSource();
        }

        if (c != null) {
          if (c instanceof JMenuItem) {

            while (c.getParent() != null) {
              c = c.getParent();
            }

            if (c instanceof JPopupMenu) {
              c = ((JPopupMenu) c).getInvoker();
            }
          }

          Window window = (c instanceof Window ? (Window) c : SwingUtilities.getWindowAncestor(c));

          if (window instanceof Frame) {
            frame = (Frame) window;
          }
        }

        CreationWizard wizard = new CreationWizard(frame, collection, this.getClassToPropose());

        wizard.setMinimumSize(new Dimension(300, 200));
        wizard.setPreferredSize(new Dimension(500, 300));
        wizard.pack();

        wizard.setVisibleOnCenterOfOwner();

        int result = wizard.getReturnCode();

        if (result == WizardConstants.WIZARD_VALID_OPTION) {
          SibType newType = wizard.getCreatedObject();
          if (newType != null) {
            collection.add(newType);
          }

          wizard.dispose();

          this.newlyCreatedItem = new WeakReference<SibType>(newType);
        }
      }
    }
    //        Kernel.getInstance().getResources().edit(this.getType());
  }
Esempio n. 7
0
 /**
  * Configures the header component in the enclosing scrollpane, if the parent we were just added
  * to is the viewport of a scrollpane.
  */
 @Override
 public void addNotify() {
   super.addNotify();
   Component p = getParent();
   if (p instanceof JViewport && p.getParent() instanceof JScrollPane) {
     JScrollPane sp = (JScrollPane) p.getParent();
     sp.setColumnHeaderView(clipPositionHeader);
   }
 }
Esempio n. 8
0
 public void mouseReleased(MouseEvent e) {
   initialClickPoint = null;
   componentBeingDragged = null;
   // org.neuralyte.Logger.log("initialClickPoint=null");
   if (bring_to_front && componentBeingDragged.getParent() instanceof JLayeredPane) {
     ((JLayeredPane) componentBeingDragged.getParent())
         .setLayer(componentBeingDragged, JLayeredPane.DEFAULT_LAYER.intValue());
   }
 }
Esempio n. 9
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static void getComponentTreePosition(Component c, ArrayList pos) {
    if (c.getParent() == null) {
      return;
    }

    getComponentTreePosition(c.getParent(), pos);

    pos.add(new Integer(c.getParent().getComponentCount() - getComponentIndex(c)));
  }
Esempio n. 10
0
  public static final int getComponentIndex(Component component) {
    if (component != null && component.getParent() != null) {
      Container c = component.getParent();
      for (int i = 0; i < c.getComponentCount(); i++) {
        if (c.getComponent(i) == component) return i;
      }
    }

    return COMPONENT_NOT_IN_CONTAINER;
  }
 @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;
  }
 /**
  * A private helper method that locates the Window to which the component is currently added.
  *
  * @param component the component for which the Window should be returned.
  * @return the AWT-Window that is the (possibly indirect) parent of this component.
  */
 protected static Window getWindowAncestor(final Component component) {
   Component parent = component.getParent();
   while (parent != null) {
     if (parent instanceof Window) {
       return (Window) parent;
     }
     parent = parent.getParent();
   }
   return null;
 }
Esempio n. 14
0
 public void mousePressed(MouseEvent e) {
   initialClickPoint = e.getPoint();
   // componentBeingDragged = (Component)e.getSource();
   componentBeingDragged = e.getComponent();
   org.neuralyte.Logger.log("initialClickPoint=" + initialClickPoint);
   if (bring_to_front && componentBeingDragged.getParent() instanceof JLayeredPane) {
     ((JLayeredPane) componentBeingDragged.getParent())
         .setLayer(componentBeingDragged, JLayeredPane.DRAG_LAYER.intValue());
   }
 }
    @Override
    public void mousePressed(MouseEvent e) {
      draggedComponent = e.getComponent();
      lastLocation =
          SwingUtilities.convertPoint(draggedComponent, e.getPoint(), draggedComponent.getParent());

      draggedComponent1 = e.getComponent();
      lastLocation1 =
          SwingUtilities.convertPoint(
              draggedComponent1, e.getPoint(), draggedComponent1.getParent());
    }
Esempio n. 16
0
  @Override
  public void mousePressed(MouseEvent e) {

    selectedComponent = (Component) e.getSource();
    // Point tempPoint = selectedComponent.getLocation();
    offset = e.getPoint();
    dragging = true;

    // System.out.println(selectedComponent.getParent());

    try {
      if (selectedComponent.getParent().equals(workPanel)) {

        view.workPanel.remove(selectedComponent);
        view.workPanel.revalidate();
        view.layer.add(selectedComponent, new Integer(1));
        view.layer.revalidate();
        layer.repaint();

        // offset = selectedComponent.getLocationOnScreen();
        // selectedComponent.setBounds(MouseInfo.getPointerInfo().getLocation().x,
        // MouseInfo.getPointerInfo().getLocation().y, cardHomes[1].getSize().width,
        // cardHomes[1].getSize().height);
        // selectedComponent.setLocation(MouseInfo.getPointerInfo().getLocation());
        /*System.out.println(MouseInfo.getPointerInfo().getLocation());
        System.out.println(selectedComponent.getLocation());
        System.out.println(selectedComponent.getLocationOnScreen());
        System.out.println(tempPoint);*/
        selectedComponent.setLocation(-200, -200);

        // selectedComponent.setSize(cardHomes[1].getSize().width, cardHomes[1].getSize().height);

      } else if (selectedComponent.getParent().equals(holdPanel)) {
        int tempX = selectedComponent.getX();
        int tempY = selectedComponent.getLocationOnScreen().y;
        view.holdPanel.remove(selectedComponent);
        view.holdPanel.revalidate();
        view.layer.add(selectedComponent, new Integer(1));
        view.layer.revalidate();
        layer.repaint();

        selectedComponent.setLocation(tempX, tempY);
      }
      /*	 else
      {
       System.out.println("normal workpanel:"+workPanel);
       System.out.println("parent:"+selectedComponent.getParent());
      }*/

    } catch (Exception ex) {
      System.out.println("error removing from panel");
      ex.printStackTrace();
    }
  }
Esempio n. 17
0
  protected Frame getFrame(Component comp) {
    if (comp == null) {
      comp = this;
    }

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

    return getFrame(comp.getParent());
  }
Esempio n. 18
0
  public static Container getAncestorOfClass(
      final Class<?> wantedClass, final Component component) {
    if (component == null || wantedClass == null) {
      return null;
    }

    Component ancestor = null;
    for (ancestor = component.getParent();
        !((ancestor == null) || (wantedClass.isAssignableFrom(ancestor.getClass())));
        ancestor = ancestor.getParent()) {}
    return (Container) ancestor;
  }
  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)));
  }
Esempio n. 20
0
 /** Return the semantic recorder for the given component. */
 private SemanticRecorder getSemanticRecorder(Component comp) {
   // FIXME extract into AWT.getLAFParent?
   // Account for LAF implementations that use a JButton on top
   // of the combo box
   if ((comp instanceof JButton) && (comp.getParent() instanceof JComboBox)) {
     comp = comp.getParent();
   }
   // Account for LAF components of JInternalFrame
   else if (AWT.isInternalFrameDecoration(comp)) {
     while (!(comp instanceof JInternalFrame)) comp = comp.getParent();
   }
   return getSemanticRecorder(comp.getClass());
 }
Esempio n. 21
0
 public static void ajustWidth(Component aChild, int aValue) {
   assert aChild.getParent().getLayout() instanceof MarginLayout;
   MarginLayout layout = (MarginLayout) aChild.getParent().getLayout();
   MarginConstraints anchors = layout.getLayoutConstraints(aChild);
   int containerWidth = aChild.getParent().getWidth();
   int childLeft = aChild.getLocation().x;
   if (anchors.getWidth() != null) {
     anchors.getWidth().setPlainValue(aValue, containerWidth);
   } else if (anchors.getLeft() != null && anchors.getRight() != null) {
     anchors.getRight().setPlainValue(containerWidth - childLeft - aValue, containerWidth);
   }
   aChild.getParent().revalidate();
   aChild.getParent().repaint();
 }
Esempio n. 22
0
 public static void ajustHeight(java.awt.Component aChild, int aValue) {
   assert aChild.getParent().getLayout() instanceof MarginLayout;
   MarginLayout layout = (MarginLayout) aChild.getParent().getLayout();
   MarginConstraints anchors = layout.getLayoutConstraints(aChild);
   int containerHeight = aChild.getParent().getHeight();
   int childTop = aChild.getLocation().y;
   if (anchors.getHeight() != null) {
     anchors.getHeight().setPlainValue(aValue, containerHeight);
   } else if (anchors.getTop() != null && anchors.getBottom() != null) {
     anchors.getBottom().setPlainValue(containerHeight - childTop - aValue, containerHeight);
   }
   aChild.getParent().revalidate();
   aChild.getParent().repaint();
 }
 protected boolean isInState(JComponent c) {
   Component parent = c;
   while (parent.getParent() != null) {
     if (parent instanceof Window) {
       break;
     }
     parent = parent.getParent();
   }
   if (parent instanceof Window) {
     return ((Window) parent).isFocused();
   }
   // Default to true.
   return true;
 }
Esempio n. 24
0
  /**
   * An improved version of {@link SwingUtilities#getAncestorOfClass(Class, Component)}. This method
   * traverses {@code JPopupMenu} invoker and uses generics to return an appropriately typed object.
   *
   * @param <T> the type of ancestor to find
   * @param clazz the class instance of the ancestor to find
   * @param c the component to start the search from
   * @return an ancestor of the correct type or {@code null} if no such ancestor exists. This method
   *     also returns {@code null} if any parameter is {@code null}.
   */
  @SuppressWarnings("unchecked")
  public static <T> T getAncestor(Class<T> clazz, Component c) {
    if (clazz == null || c == null) {
      return null;
    }

    Component parent = c.getParent();

    while (parent != null && !(clazz.isInstance(parent))) {
      parent =
          parent instanceof JPopupMenu ? ((JPopupMenu) parent).getInvoker() : parent.getParent();
    }

    return (T) parent;
  }
Esempio n. 25
0
    @Override
    public void actionPerformed(ActionEvent arg0) {
      x = Integer.parseInt((String) XIn.getValue().toString());
      y = Integer.parseInt((String) YIn.getValue().toString());
      z = Integer.parseInt((String) ZIn.getValue().toString());

      Component c = getParent();
      while (c.getParent() != null) {
        c = c.getParent();
      }
      JFrame pFrame = (JFrame) c;
      pFrame.setVisible(false);

      panel.createNewTemplate(x, y, z);
    }
  @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;
  }
Esempio n. 27
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);
     }
   }
 }
Esempio n. 28
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;
  }
Esempio n. 29
0
    /* (non-Javadoc)
     * @see javax.swing.border.EmptyBorder#getBorderInsets(java.awt.Component, java.awt.Insets)
     */
    public Insets getBorderInsets(Component c, Insets insets) {
      insets = super.getBorderInsets(c, insets);

      Insets margin = null;
      if (c instanceof AbstractButton) {
        Insets m = ((AbstractButton) c).getMargin();
        // if this is a toolbar button then ignore getMargin()
        // and subtract the padding added by the constructor
        if (c.getParent() instanceof JToolBar
            && !(c instanceof JRadioButton)
            && !(c instanceof JCheckBox)
            && m instanceof InsetsUIResource) {
          insets.top -= 2;
          insets.left -= 2;
          insets.bottom -= 2;
          insets.right -= 2;
        } else {
          margin = m;
        }
      } else if (c instanceof JToolBar) {
        margin = ((JToolBar) c).getMargin();
      } else if (c instanceof JTextComponent) {
        margin = ((JTextComponent) c).getMargin();
      }
      if (margin != null) {
        insets.top = margin.top + 2;
        insets.left = margin.left + 2;
        insets.bottom = margin.bottom + 2;
        insets.right = margin.right + 2;
      }
      return insets;
    }
Esempio n. 30
0
 @Override
 public void setBounds(int x, int y, int width, int height, int op) {
   super.setBounds(x, y, width, height, op);
   if (xtext != null) {
     /*
      * Fixed 6277332, 6198290:
      * the coordinates is coming (to peer): relatively to closest HW parent
      * the coordinates is setting (to textField): relatively to closest ANY parent
      * the parent of peer is target.getParent()
      * the parent of textField is the same
      * see 6277332, 6198290 for more information
      */
     int childX = x;
     int childY = y;
     Component parent = target.getParent();
     // we up to heavyweight parent in order to be sure
     // that the coordinates of the text pane is relatively to closest parent
     while (parent.isLightweight()) {
       childX -= parent.getX();
       childY -= parent.getY();
       parent = parent.getParent();
     }
     xtext.setBounds(childX, childY, width, height);
     xtext.validate();
   }
 }