Esempio n. 1
52
 /**
  * Show the given message in a dialog box or independent window, depending on whether the source
  * component is contained in a Frame or not.
  *
  * @param c The Controller that calls this method, or null if it is not called by a Controller.
  *     (The Controller, if any, will be notified when the error message is cleared.)
  * @param message The message to display.
  */
 public void setErrorMessage(Controller c, String message) {
   if (popup != null) clearErrorMessage();
   if (message == null) return;
   errorSource = c;
   errorMessage = message;
   Component parent = source;
   while (parent != null && !(parent instanceof Frame)) parent = parent.getParent();
   if (parent != null) popup = new Dialog((Frame) parent, "Error Message", true); // modal dialog
   else popup = new Frame("Error Message"); // independent window
   popup.setBackground(Color.white);
   popup.add(new MC(message), BorderLayout.CENTER);
   Panel buttonBar = new Panel();
   buttonBar.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
   Button OK = new Button("    OK    ");
   OK.addActionListener(this);
   buttonBar.add(OK);
   popup.add(buttonBar, BorderLayout.SOUTH);
   popup.pack();
   if (parent == null) popup.setLocation(100, 80);
   else popup.setLocation(parent.getLocation().x + 50, parent.getLocation().y + 30);
   popup.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent evt) {
           popup.dispose();
         }
       });
   popup.show(); // make the dialog visible.
 }
Esempio n. 2
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;
  }
 /**
  * Internal MDI frames have offsets where a popup menu should be shown (in JDK 1.2). This method
  * sums up iteratively all x and y offsets of all parent compontents until the top parent
  * component is reached.
  */
 private void adjustOffsets(Component comp, Point offsetPoint) {
   if (comp != null) {
     Point compLocation = comp.getLocation();
     offsetPoint.translate(compLocation.x, compLocation.y);
     adjustOffsets(comp.getParent(), offsetPoint);
   }
 }
Esempio n. 4
0
 /**
  * Changes the frame's location to a more central screen location
  *
  * @param frame the frame to be moved
  * @param X how far right to move the frame
  * @param Y how far down to move the frame
  */
 public static void changeFrameLocation(Component frame, int X, int Y) {
   Point location = frame.getLocation(); // the window's current location
   // move the window over and down a certain amount of pixels
   location.translate(X, Y);
   // set the location
   frame.setLocation(location);
 }
 public void componentMoved(ComponentEvent evt) {
   Component component = evt.getComponent();
   Point point = component.getLocation();
   if (point.y < 0) {
     component.setBounds(point.x, 0, component.getWidth(), component.getHeight());
   }
 }
Esempio n. 6
0
  private void setupForDragging(MouseEvent e) {
    source.addMouseMotionListener(this);
    potentialDrag = true;

    // Determine the component that will ultimately be moved

    if (destinationComponent != null) {
      destination = destinationComponent;
    } else if (destinationClass == null) {
      destination = source;
    } else // forward events to destination component
    {
      destination = SwingUtilities.getAncestorOfClass(destinationClass, source);
    }

    pressed = e.getLocationOnScreen();
    location = destination.getLocation();

    if (changeCursor) {
      originalCursor = source.getCursor();
      source.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    }

    // Making sure autoscrolls is false will allow for smoother dragging of
    // individual components

    if (destination instanceof JComponent) {
      JComponent jc = (JComponent) destination;
      autoscrolls = jc.getAutoscrolls();
      jc.setAutoscrolls(false);
    }
  }
  public void setTarget(Component paramComponent, Insets paramInsets) {
    if (this.Target != null) {
      this.Target.removeComponentListener(this);
      if (this.TargetParent != null) {
        this.TargetParent.removeContainerListener(this);
        this.TargetParent = null;
      }
    }

    if (paramInsets == null) this.Space = DEFAULTINSETS;
    else this.Space = paramInsets;
    this.Target = paramComponent;

    setLocation(
        paramComponent.getLocation().x - this.Space.left,
        paramComponent.getLocation().y - this.Space.top);
    setSize(
        paramComponent.getSize().width + this.Space.left + this.Space.right,
        paramComponent.getSize().height + this.Space.top + this.Space.bottom);

    paramComponent.addComponentListener(this);

    if (this.Target.getParent() != null) {
      this.TargetParent = this.Target.getParent();
      this.TargetParent.addContainerListener(this);
    }
  }
  private Point getLocationInTabbedPanel(Component c, TabbedPanel tp) {
    Point l = SwingUtilities.convertPoint(c.getParent(), c.getLocation(), tp);
    Insets tpInsets = tp.getInsets();
    l.x -= tpInsets.left;
    l.y -= tpInsets.top;

    return l;
  }
  /**
   * Constructor specifying the component for which the property applies.
   *
   * @param component Component whose location property is to be tracked.
   */
  public ComponentLocationProperty(Component component) {
    super();

    // Hook to component
    this.component = component;
    this.component.addComponentListener(eventAdapter);

    // Set initial value
    value = component.getLocation();
  }
Esempio n. 10
0
 public static void center(Component c, Component rel) {
   if (rel != null) {
     c.setLocation(
         rel.getLocation().x + rel.getSize().width / 2 - c.getSize().width / 2,
         rel.getLocation().y + rel.getSize().height / 2 - c.getSize().height / 2);
   } else {
     c.setLocation(
         Toolkit.getDefaultToolkit().getScreenSize().width / 2 - c.getSize().width / 2,
         +Toolkit.getDefaultToolkit().getScreenSize().height / 2 - c.getSize().height / 2);
   }
 }
  public void layoutContainer(Container target) {
    //      System.out.println("Laying out container " + target);
    super.layoutContainer(target);
    if (free != null) { // what is free??
      Point loc = free.getLocation();
      Dimension sz = free.getSize();

      // System.out.println("Laying out free component " + free);
      free.setBounds(loc.x, loc.y, sz.width, sz.height);
    }
  }
Esempio n. 12
0
 public void mouseDragged(MouseEvent e) {
   Point mousePosition = e.getPoint();
   double dx = mousePosition.getX() - initialClickPoint.getX();
   double dy = mousePosition.getY() - initialClickPoint.getY();
   Point at = componentBeingDragged.getLocation();
   // org.neuralyte.Logger.log("Mouse="+mousePosition + " Component=" + at + " ("+dx+","+dy+")");
   // at.move((int)dx,(int)dy);
   // componentBeingDragged.setLocation(at);
   componentBeingDragged.setLocation((int) (at.getX() + dx), (int) (at.getY() + dy));
   // initialClickPoint = mousePosition;
 }
Esempio n. 13
0
 private static void translateRelatedPoint(
     final Point point, final Component c, final int direction, final boolean stopAtRootPane) {
   Component currentComponent = c;
   while ((currentComponent != null)
       && (!stopAtRootPane || stopAtRootPane && !(currentComponent instanceof JRootPane))) {
     Point componentLocation = currentComponent.getLocation();
     point.x += direction * componentLocation.x;
     point.y += direction * componentLocation.y;
     currentComponent = Utilities.getNotWindowParent(currentComponent);
   }
 }
Esempio n. 14
0
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o instanceof JMenuItem) {
      JMenuItem sender = (JMenuItem) o;
      String name = sender.getText();
      if (name.equals("close")) {
        tabbedPane.removeTabAt(tabbedPane.getSelectedIndex());
      } else if (name.equals("save")) {
        int index = tabbedPane.getSelectedIndex();
        Component c = tabbedPane.getComponent(index);
        Point p = c.getLocation();
        Component t = tabbedPane.getComponentAt(new Point(p.x + 20, p.y + 30));
        if (t instanceof TextView) {
          TextView text = (TextView) t;
          // String code = text.getText();
          // save the code
          // saveTab(code);
        }
        if (t instanceof HTMLTextView) {
          HTMLTextView text = (HTMLTextView) t;
          fileChooser.setSelectedFile(new File(text.node.getName()));
          int returnVal = fileChooser.showSaveDialog(this);

          if (returnVal == JFileChooser.APPROVE_OPTION) {
            File f = fileChooser.getSelectedFile();

            // save the code
            String fileType =
                f.getName().substring(f.getName().lastIndexOf("."), f.getName().length());
            if (fileType.indexOf("htm") != -1) {
              // save as html
              String code = text.getText();
              saveTab(code, f);
            } else if (fileType.indexOf("java") != -1) {
              // save as java
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
            } else if (text.node.fileType.indexOf(FileTypes.MANIFEST) != -1
                || text.node.fileType.indexOf(FileTypes.MANIFEST2) != -1) {
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
              System.out.println("Saved manifest");
            } else {
              System.out.println("FILETYPE UNKNOWN:" + text.node.fileType);
            }
          }
        }
      } else if (name.equals("close all")) {
        tabbedPane.removeAll();
      }
    }
  }
 private static void centerWindow(JInternalFrame w, Component owner) {
   // center based on the owner component, if it is not null
   // otherwise, center based on the center of the screen
   if (owner != null) {
     Point p = owner.getLocation();
     p.x += owner.getWidth() / 2;
     p.y += owner.getHeight() / 2;
     SwingUtilities.convertPointToScreen(p, owner);
     w.setLocation(p);
   } else {
     w.setLocation(WindowUtils.getPointForCentering(w));
   }
 }
Esempio n. 16
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();
 }
Esempio n. 17
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. 18
0
 public void paint(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   Component c;
   Point p;
   paintComponent(g);
   for (int i = 0; i < getComponentCount(); i++) {
     AffineTransform save = g.getTransform();
     c = getComponent(i);
     p = c.getLocation();
     g.translate((int) p.getX(), (int) p.getY());
     c.paint(g);
     g.setTransform(save);
   }
 }
Esempio n. 19
0
  // A click on a picture box
  private void mouseDown(MouseEvent e) {
    if (e.getButton() != MouseEvent.BUTTON1) return;

    Component source = (Component) e.getSource();

    Component parent = source.getParent();
    originalCursor = parent.getCursor();
    parent.setCursor(new Cursor(Cursor.MOVE_CURSOR));

    initLocation = source.getLocation();
    initX = e.getX();
    initY = e.getY();

    isMouseDown = true;
  }
Esempio n. 20
0
  /**
   * Called by ScrollPane's internal observer of the scrollpane's adjustables. This is called
   * whenever a scroll position is changed in one of adjustables, whether it was modified externally
   * or from the native scrollbars themselves.
   */
  public void setValue(Adjustable adj, int v) {
    Component c = getScrollChild();
    if (c == null) {
      return;
    }

    Point p = c.getLocation();
    switch (adj.getOrientation()) {
      case Adjustable.VERTICAL:
        setScrollPosition(-(p.x), v);
        break;
      case Adjustable.HORIZONTAL:
        setScrollPosition(v, -(p.y));
        break;
    }
  }
Esempio n. 21
0
  /**
   * Calculates the position of a frame to be in the center of an other frame.
   *
   * @param parentFrame
   * @param frame
   * @return
   */
  public static Point getCenter(final Component parentFrame, final Window frame) {
    final Point point = new Point();
    int x = 0, y = 0;

    if (parentFrame == null || frame == null) {
      point.setLocation(x, y);
      return point;
    }

    x = parentFrame.getLocation().x + parentFrame.getSize().width / 2 - frame.getSize().width / 2;
    y = parentFrame.getLocation().y + parentFrame.getSize().height / 2 - frame.getSize().height / 2;

    point.setLocation(x, y);

    return point;
  }
  public void show(Event e) {
    Component origin = (Component) e.target;
    WComponentPeer peer = (WComponentPeer) WToolkit.targetToPeer(origin);
    if (peer == null) {
      // A failure to map the peer should only happen for a
      // lightweight component, then find the actual native parent from
      // that component.  The event coorinates are going to have to be
      // remapped as well.
      Component nativeOrigin = WToolkit.getNativeContainer(origin);
      e.target = nativeOrigin;

      // remove the event coordinates
      for (Component c = origin; c != nativeOrigin; c = c.getParent()) {
        Point p = c.getLocation();
        e.x += p.x;
        e.y += p.y;
      }
    }
    _show(e);
  }
 public void mouseDragged(MouseEvent e) {
   Point location =
       SwingUtilities.convertPoint(draggedComponent, e.getPoint(), draggedComponent.getParent());
   if (draggedComponent.getParent().getBounds().contains(location)) {
     Point newLocation = draggedComponent.getLocation();
     newLocation.translate(location.x - lastLocation.x, location.y - lastLocation.y);
     newLocation.x = Math.max(newLocation.x, 0);
     newLocation.x =
         Math.min(
             newLocation.x,
             draggedComponent.getParent().getWidth() - draggedComponent.getWidth());
     newLocation.y = Math.max(newLocation.y, 0);
     newLocation.y =
         Math.min(
             newLocation.y,
             draggedComponent.getParent().getHeight() - draggedComponent.getHeight());
     draggedComponent.setLocation(newLocation);
     lastLocation = location;
   }
 }
Esempio n. 24
0
  /**
   * Calculates the preferred size dimensions for the specified panel given the components in the
   * specified parent container.
   *
   * @see #minimumLayoutSize
   * @param target The component to be laid out.
   * @return A size deemed suitable for laying out the container.
   */
  public Dimension preferredLayoutSize(Container target) {
    int count;
    Container parent;
    Component component;
    Point point;
    Dimension dimension;
    Insets insets;
    Dimension ret;

    synchronized (target.getTreeLock()) {
      count = target.getComponentCount();
      if (0 == count) {
        // be the same size unless we have a parent
        ret = target.getSize();
        parent = target.getParent();
        if (null != parent) {
          insets = parent.getInsets();
          ret = parent.getSize();
          ret.setSize(
              ret.width - insets.left - insets.right, ret.height - insets.top - insets.bottom);
        }
      } else {
        ret = new Dimension(0, 0);
        for (int i = 0; i < count; i++) {
          component = target.getComponent(i);
          if (component.isVisible()) {
            point = component.getLocation();
            dimension = component.getPreferredSize();
            ret.width = Math.max(ret.width, point.x + dimension.width);
            ret.height = Math.max(ret.height, point.y + dimension.height);
          }
        }
        insets = target.getInsets();
        ret.width += insets.left + insets.right;
        ret.height += insets.top + insets.bottom;
      }
    }

    return (ret);
  }
Esempio n. 25
0
 public void setLocationRelativeTo(Component comp) {
   if (w != null) {
     w.setLocationRelativeTo(comp);
   } else {
     //			throw new IllegalStateException();
     final Point p;
     if (comp == null) {
       if (jif == null) {
         p = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
       } else {
         comp = wh.getMasterFrame().getWindow();
         p = new Point(comp.getWidth() >> 1, comp.getHeight() >> 1);
       }
     } else {
       p = comp.getLocation();
       p.translate(comp.getWidth() >> 1, comp.getHeight() >> 1);
     }
     final Point p2 = SwingUtilities.convertPoint(comp, p, c);
     p2.translate(-(c.getWidth() >> 1), -(c.getHeight() >> 1));
     c.setLocation(p2);
   }
 }
Esempio n. 26
0
 /*
  * (non-Javadoc)
  */
 public void componentMoved(ComponentEvent e) {
   Component c = e.getComponent();
   x = c.getLocation().x;
   y = c.getLocation().y;
   updateTitle();
 }
Esempio n. 27
0
  @Override
  public void mouseReleased(MouseEvent e) {
    dragging = false;
    Rectangle box1 = new Rectangle(), box2 = new Rectangle(), box3 = new Rectangle();
    box1.setBounds(
        selectedComponent.getLocation().x,
        selectedComponent.getLocation().y,
        selectedComponent.getWidth(),
        selectedComponent.getHeight());

    try {
      box2.setBounds(view.workPanel.getBounds());
      box3.setBounds(view.holdPanel.getBounds());

    } catch (Exception ex) {
      System.out.println("Bounds could not be set");
    }

    if (box1.intersects(box2)) {
      if (selectedComponent instanceof NumberCard) {
        NumberCard temp = (NumberCard) selectedComponent;
        if (temp.getHome() == "home") { // originated from cardPanel
          if (temp.getNumberTag() == view.cardPanel.card1.getNumberTag()) {
            view.cardPanel.changeCardExistence(0, false);
          } else if (temp.getNumberTag() == view.cardPanel.card2.getNumberTag()) {
            view.cardPanel.changeCardExistence(1, false);
          } else if (temp.getNumberTag() == view.cardPanel.card3.getNumberTag()) {
            view.cardPanel.changeCardExistence(2, false);
          } else if (temp.getNumberTag() == view.cardPanel.card4.getNumberTag()) {
            view.cardPanel.changeCardExistence(3, false);
          } else if (temp.getNumberTag() == view.cardPanel.card5.getNumberTag()) {
            view.cardPanel.changeCardExistence(4, false);
          } else if (temp.getNumberTag() == view.cardPanel.card6.getNumberTag()) {
            view.cardPanel.changeCardExistence(5, false);
          }
        }
      }
      layer.remove(selectedComponent);
      layer.revalidate();
      view.workPanel.add(selectedComponent);
      view.workPanel.revalidate();
      // panel2b.repaint();
      // selectedComponent.setSize(cardHomes[1].getSize());

      view.layer.repaint();
    } else if (box1.intersects(box3)) {
      if (selectedComponent instanceof NumberCard) {
        NumberCard temp = (NumberCard) selectedComponent;
        if (temp.getHome() == "home") { // originated from cardPanel
          if (temp.getNumberTag() == view.cardPanel.card1.getNumberTag()) {
            view.cardPanel.changeCardExistence(0, false);
          } else if (temp.getNumberTag() == view.cardPanel.card2.getNumberTag()) {
            view.cardPanel.changeCardExistence(1, false);
          } else if (temp.getNumberTag() == view.cardPanel.card3.getNumberTag()) {
            view.cardPanel.changeCardExistence(2, false);
          } else if (temp.getNumberTag() == view.cardPanel.card4.getNumberTag()) {
            view.cardPanel.changeCardExistence(3, false);
          } else if (temp.getNumberTag() == view.cardPanel.card5.getNumberTag()) {
            view.cardPanel.changeCardExistence(4, false);
          } else if (temp.getNumberTag() == view.cardPanel.card6.getNumberTag()) {
            view.cardPanel.changeCardExistence(5, false);
          }
        }
      }
      layer.remove(selectedComponent);
      layer.revalidate();
      view.holdPanel.add(selectedComponent);
      view.holdPanel.revalidate();
      view.layer.repaint();
    } else {
      for (int i = 0; i < cards.length; i++) {
        // System.out.println(selectedComponent);
        if (selectedComponent.equals(cards[i])) {

          selectedComponent.setBounds(cardHomes[i]);
          break;
        }
      }
      try {
        if (selectedComponent.getName().equals(("Answer"))) {
          layer.remove(selectedComponent);
          layer.revalidate();
          view.holdPanel.add(selectedComponent);
          view.holdPanel.revalidate();
          view.layer.repaint();
        }
      } catch (Exception ex) {
        System.err.println("can't get selectedComponent name");
      }
    }
  }
Esempio n. 28
0
 public Point getLocation() {
   return c.getLocation();
 }