protected void movePolygon(Point previousMousePoint, Point mousePoint) {
    // Intersect a ray through each mouse point, with a geoid passing through the reference
    // elevation.
    // If either ray fails to intersect the geoid, then ignore this event. Use the difference
    // between the two
    // intersected positions to move the control point's location.

    View view = this.wwd.getView();
    Globe globe = this.wwd.getModel().getGlobe();

    Position refPos = this.polygon.getReferencePosition();
    if (refPos == null) return;

    Line ray = view.computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Line previousRay =
        view.computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray);
    Vec4 previousVec =
        AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    this.polygon.move(new Position(change.getLatitude(), change.getLongitude(), 0.0));
  }
示例#2
0
 // ------------------------------
 public void
     scrollToCaret() { // not called - fixed with putting visible scrollbars on JScrollPane
   //
   Rectangle rect1 = scroller1.getViewport().getViewRect();
   double x1 = rect1.getX();
   double y1 = rect1.getY();
   double r1height = rect1.getHeight();
   double r1width = rect1.getWidth();
   Caret caret1 = editor1.getCaret();
   Point pt2 = caret1.getMagicCaretPosition(); // the end of the string
   double x2 = pt2.getX();
   double y2 = pt2.getY();
   if (((x2 > x1) && (x2 < (x1 + r1width))) && ((y2 > y1) && (y2 < (y1 + r1height)))) {
     // inview
   } else {
     double newheight = r1height / 2;
     double newwidth = r1width / 2;
     double x3 = pt2.getX() - newwidth;
     double y3 = pt2.getY() - newheight;
     if (x3 < 0) x3 = 0;
     if (y3 < 0) y3 = 0;
     Rectangle rect3 = new Rectangle((int) x3, (int) y3, (int) newwidth, (int) newheight);
     editor1.scrollRectToVisible(rect3);
   }
 } // end scrollToCaret
示例#3
0
    public void mouseDragged(MouseEvent e) {
      int mods = e.getModifiersEx();
      Point dragEnd = e.getPoint();
      boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) > 0;
      boolean ctrl = (mods & MouseEvent.CTRL_DOWN_MASK) > 0;
      boolean alt = shift & ctrl;
      ctrl = ctrl & (!alt);
      shift = shift & (!alt);
      boolean nomods = !(shift | ctrl | alt);

      if (dragBegin == null) dragBegin = dragEnd;

      nodrag = false;

      if ((mods & InputEvent.BUTTON3_DOWN_MASK) > 0 || true) {
        double dx = dragEnd.getX() - dragBegin.getX();
        double dy = dragEnd.getY() - dragBegin.getY();

        synchronized (JImage.this) {
          t.preConcatenate(AffineTransform.getTranslateInstance(dx, dy));
        }

        dragBegin = dragEnd;
        repaint();
      }
    }
示例#4
0
文件: Tray.java 项目: Tyf0n/musique
    private void showJPopupMenu(MouseEvent e) {
      try {
        if (e.isPopupTrigger() && menu != null) {
          if (window == null) {

            if (isWindows) {
              window = new JDialog((Frame) null);
              ((JDialog) window).setUndecorated(true);
            } else {
              window = new JWindow((Frame) null);
            }
            window.setAlwaysOnTop(true);
            Dimension size = menu.getPreferredSize();

            Point centerPoint = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
            if (e.getY() > centerPoint.getY()) window.setLocation(e.getX(), e.getY() - size.height);
            else window.setLocation(e.getX(), e.getY());

            window.setVisible(true);

            menu.show(((RootPaneContainer) window).getContentPane(), 0, 0);

            // popup works only for focused windows
            window.toFront();
          }
        }
      } catch (Exception ignored) {
      }
    }
  private void showSliderMenu() {
    Point location = new Point(getX(), getY() + getHeight());

    SwingUtilities.convertPointToScreen(location, InputVolumeControlButton.this.getParent());

    if (isFullScreen()) {
      location.setLocation(
          location.getX(),
          location.getY() - sliderMenu.getPreferredSize().getHeight() - getHeight());
    }

    sliderMenu.setLocation(location);

    sliderMenu.addPopupMenuListener(
        new PopupMenuListener() {
          public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = true;
          }

          public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
            sliderMenuIsVisible = false;
          }

          public void popupMenuCanceled(PopupMenuEvent ev) {}
        });

    sliderMenu.setVisible(!sliderMenu.isVisible());
  }
示例#6
0
  /** Write file with position and size of the login box */
  public static void writePersistence() {

    Messages.postDebug("LoginBox", "LoginBox.writePersistence");
    // If the panel has not been created, don't try to write a file
    if (position == null) return;

    String filepath = FileUtil.savePath("USER/PERSISTENCE/LoginPanel");

    FileWriter fw;
    PrintWriter os;
    try {
      File file = new File(filepath);
      fw = new FileWriter(file);
      os = new PrintWriter(fw);
      os.println("Login Panel");

      os.println(height);
      os.println(width);
      double xd = position.getX();
      int xi = (int) xd;
      os.println(xi);
      double yd = position.getY();
      int yi = (int) yd;
      os.println(yi);

      os.close();
    } catch (Exception er) {
      Messages.postError("Problem creating  " + filepath);
      Messages.writeStackTrace(er);
    }
  }
 /** Returns the coordinates of the top left corner of the value at the given index. */
 public Point getCoordinates(int index) {
   JScrollBar bar = scrollPane.getVerticalScrollBar();
   Rectangle r = segmentTable.getCellRect(index, 1, true);
   segmentTable.scrollRectToVisible(r);
   setTopLevelLocation();
   return new Point(
       (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY()));
 }
  protected void setPolygonHeight(Point previousMousePoint, Point mousePoint) {
    // Find the closest points between the rays through each screen point, and the ray from the
    // control point
    // and in the direction of the globe's surface normal. Compute the elevation difference between
    // these two
    // points, and use that as the change in polygon height.

    Position referencePos = this.polygon.getReferencePosition();
    if (referencePos == null) return;

    Vec4 referencePoint = this.wwd.getModel().getGlobe().computePointFromPosition(referencePos);

    Vec4 surfaceNormal =
        this.wwd
            .getModel()
            .getGlobe()
            .computeSurfaceNormalAtLocation(
                referencePos.getLatitude(), referencePos.getLongitude());
    Line verticalRay = new Line(referencePoint, surfaceNormal);
    Line screenRay =
        this.wwd.getView().computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Line previousScreenRay =
        this.wwd
            .getView()
            .computeRayFromScreenPoint(previousMousePoint.getX(), previousMousePoint.getY());

    Vec4 pointOnLine = AirspaceEditorUtil.nearestPointOnLine(verticalRay, screenRay);
    Vec4 previousPointOnLine =
        AirspaceEditorUtil.nearestPointOnLine(verticalRay, previousScreenRay);

    Position pos = this.wwd.getModel().getGlobe().computePositionFromPoint(pointOnLine);
    Position previousPos =
        this.wwd.getModel().getGlobe().computePositionFromPoint(previousPointOnLine);
    double elevationChange = pos.getElevation() - previousPos.getElevation();

    java.util.List<Position> boundary = new ArrayList<Position>();
    for (LatLon ll : this.polygon.getOuterBoundary()) {
      boundary.add(new Position(ll, ((Position) ll).getElevation() + elevationChange));
    }

    this.polygon.setOuterBoundary(boundary);
  }
  //  Repaint the message at the new location
  public void paintComponent(Graphics page) {
    // use paintComponent method of its parent class
    // to have all graphics properties
    super.paintComponent(page);

    // change the page color and font
    page.setColor(Color.cyan);
    page.setFont(new Font("TimesRoman", Font.PLAIN, 24));

    page.drawString(message.getText(), (int) (location.getX()), (int) (location.getY()));
  }
示例#10
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);
   }
 }
示例#11
0
        public void mousePressed(MouseEvent e) {
          requestFocus();
          Point p = e.getPoint();
          int size =
              Math.min(
                  MAX_SIZE,
                  Math.min(
                      getWidth() - imagePadding.left - imagePadding.right,
                      getHeight() - imagePadding.top - imagePadding.bottom));
          p.translate(-(getWidth() / 2 - size / 2), -(getHeight() / 2 - size / 2));
          if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
            // the two circular views:
            double radius = ((double) size) / 2.0;
            double x = p.getX() - size / 2.0;
            double y = p.getY() - size / 2.0;
            double r = Math.sqrt(x * x + y * y) / radius;
            double theta = Math.atan2(y, x) / (Math.PI * 2.0);

            if (r > 1) r = 1;

            if (mode == ColorPicker.BRI) {
              setHSB((float) (theta + .25f), (float) (r), bri);
            } else {
              setHSB((float) (theta + .25f), sat, (float) (r));
            }
          } else if (mode == ColorPicker.HUE) {
            float s = ((float) p.x) / ((float) size);
            float b = ((float) p.y) / ((float) size);
            if (s < 0) s = 0;
            if (s > 1) s = 1;
            if (b < 0) b = 0;
            if (b > 1) b = 1;
            setHSB(hue, s, b);
          } else {
            int x2 = p.x * 255 / size;
            int y2 = p.y * 255 / size;
            if (x2 < 0) x2 = 0;
            if (x2 > 255) x2 = 255;
            if (y2 < 0) y2 = 0;
            if (y2 > 255) y2 = 255;

            if (mode == ColorPicker.RED) {
              setRGB(red, x2, y2);
            } else if (mode == ColorPicker.GREEN) {
              setRGB(x2, green, y2);
            } else {
              setRGB(x2, y2, blue);
            }
          }
        }
示例#12
0
  protected void moveControlPoint(
      ControlPointMarker controlPoint, Point lastMousePoint, Point moveToPoint) {
    View view = this.wwd.getView();
    Globe globe = this.wwd.getModel().getGlobe();

    Position refPos = controlPoint.getPosition();
    if (refPos == null) return;

    Line ray = view.computeRayFromScreenPoint(moveToPoint.getX(), moveToPoint.getY());
    Line previousRay = view.computeRayFromScreenPoint(lastMousePoint.getX(), lastMousePoint.getY());

    Vec4 vec = AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), ray);
    Vec4 previousVec =
        AirspaceEditorUtil.intersectGlobeAt(this.wwd, refPos.getElevation(), previousRay);

    if (vec == null || previousVec == null) {
      return;
    }

    Position pos = globe.computePositionFromPoint(vec);
    Position previousPos = globe.computePositionFromPoint(previousVec);
    LatLon change = pos.subtract(previousPos);

    java.util.List<LatLon> boundary = new ArrayList<LatLon>();
    for (LatLon ll : this.polygon.getOuterBoundary()) {
      boundary.add(ll);
    }

    boundary.set(controlPoint.getIndex(), new Position(pos.add(change), refPos.getAltitude()));

    // ExtrudedPolygon ensures that the last boundary position is the same as the first. Remove the
    // last point
    // before setting the boundary.
    boundary.remove(boundary.size() - 1);

    this.polygon.setOuterBoundary(boundary);
  }
示例#13
0
  /**
   * Add a vertex to the polygon's outer boundary.
   *
   * @param mousePoint the point at which the mouse was clicked. The new vertex will be placed as
   *     near as possible to this point, at the elevation of the polygon.
   */
  protected void addVertex(Point mousePoint) {
    // Try to find the edge that is closest to a ray passing through the screen point. We're trying
    // to determine
    // the user's intent as to which edge a new two control points should be added to.

    Line ray = this.wwd.getView().computeRayFromScreenPoint(mousePoint.getX(), mousePoint.getY());
    Vec4 pickPoint = this.intersectPolygonAltitudeAt(ray);

    double nearestDistance = Double.MAX_VALUE;
    int newVertexIndex = 0;

    // Loop through the control points and determine which edge is closest to the pick point
    for (int i = 0; i < this.controlPoints.size(); i++) {
      ControlPointMarker thisMarker = (ControlPointMarker) this.controlPoints.get(i);
      ControlPointMarker nextMarker =
          (ControlPointMarker) this.controlPoints.get((i + 1) % this.controlPoints.size());

      Vec4 pointOnEdge =
          AirspaceEditorUtil.nearestPointOnSegment(thisMarker.point, nextMarker.point, pickPoint);
      if (!AirspaceEditorUtil.isPointBehindLineOrigin(ray, pointOnEdge)) {
        double d = pointOnEdge.distanceTo3(pickPoint);
        if (d < nearestDistance) {
          newVertexIndex = i + 1;
          nearestDistance = d;
        }
      }
    }

    Position newPosition = this.wwd.getModel().getGlobe().computePositionFromPoint(pickPoint);

    // Copy the outer boundary list
    ArrayList<Position> positionList = new ArrayList<Position>(this.controlPoints.size());
    for (LatLon position : this.getPolygon().getOuterBoundary()) {
      positionList.add((Position) position);
    }

    // Add the new vertex
    positionList.add(newVertexIndex, newPosition);

    this.getPolygon().setOuterBoundary(positionList);
  }
 public void setPopupLocation(Point location) {
   setPopupLocation((int) location.getX(), (int) location.getY());
 }
示例#15
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    _tG.readTile((char) _game.topTile().get(new Point(3, 3)));
    _rotateNum = (char) (_game.topTile().get(new Point(3, 4))) - '0';
    _emptySlot = _game.get_Slot();

    for (int i = 0; i < 10000; i++) {
      g.setColor(Color.black);
      g.fillRect(
          (i % 100) * squareSize + (i % 100 + 1) * 1,
          (i / 100) * squareSize + (i / 100 + 1),
          squareSize,
          squareSize);
    }
    for (Point p : _emptySlot) {
      g.setColor(Color.green);
      g.fillRect(p.x * (squareSize + 1) + 1, p.y * (squareSize + 1) + 1, 80, 80);
    }
    _tilePiece = cutImage(TileGeneratorView.k, TileGeneratorView.j);
    for (int i = 0; i < _rotateNum; i++) {
      _tilePiece = rotateImage(_tilePiece, 90);
    }

    tilePiece = _tilePiece;
    g.drawImage(tilePiece, x, y, 80, 80, this);

    HashMap<Point, HashMap<Point, Object>> gameBoard = _game.get_gameBoard();
    for (HashMap.Entry<Point, HashMap<Point, Object>> entry : gameBoard.entrySet()) {
      int j = -1, k = -1; // using j,k to indicate where are the tiles locate in our picture.
      Point position = entry.getKey();
      int xp = (int) position.getX();
      int yp = (int) position.getY();
      HashMap<Point, Object> tileMap = entry.getValue();
      int xMeeple = 10, yMeeple = 10;

      for (HashMap.Entry<Point, Object> entry1 : tileMap.entrySet()) {
        Point meeplePosition = entry1.getKey();
        char parts = (char) entry1.getValue();
        // System.out.println(parts);

        if (parts >= 'a' && parts <= 'z') {
          xMeeple = (int) meeplePosition.getX();
          yMeeple = (int) meeplePosition.getY();
        }
      }
      char tile = (char) entry.getValue().get(new Point(3, 3));
      switch (tile) {
        case 'A':
          j = 3;
          k = 4;
          break;
        case 'B':
          j = 3;
          k = 3;
          break;
        case 'C':
          j = 1;
          k = 2;
          break;
        case 'D':
          j = 2;
          k = 0;
          break;
        case 'E':
          j = 0;
          k = 0;
          break;
        case 'F':
          j = 1;
          k = 1;
          break;
        case 'G':
          j = 1;
          k = 0;
          break;
        case 'H':
          j = 0;
          k = 2;
          break;
        case 'I':
          j = 0;
          k = 1;
          break;
        case 'J':
          j = 2;
          k = 2;
          break;
        case 'K':
          j = 2;
          k = 1;
          break;
        case 'L':
          j = 3;
          k = 2;
          break;
        case 'M':
          j = 0;
          k = 4;
          break;
        case 'N':
          j = 0;
          k = 3;
          break;
        case 'O':
          j = 2;
          k = 4;
          break;
        case 'P':
          j = 2;
          k = 3;
          break;
        case 'Q':
          j = 1;
          k = 4;
          break;
        case 'R':
          j = 1;
          k = 3;
          break;
        case 'S':
          j = 3;
          k = 1;
          break;
        case 'T':
          j = 3;
          k = 0;
          break;
        case 'U':
          j = 4;
          k = 0;
          break;
        case 'V':
          j = 4;
          k = 1;
          break;
        case 'W':
          j = 4;
          k = 2;
          break;
        case 'X':
          j = 4;
          k = 3;
          break;
      }
      Image tempTile;
      tempTile = cutImage(k, j);
      int rotateNumber = 0;
      char rotateNum = (char) entry.getValue().get(new Point(3, 4));
      switch (rotateNum) {
        case '0':
          rotateNumber = 0;
          break;
        case '1':
          rotateNumber = 1;
          break;
        case '2':
          rotateNumber = 2;
          break;
        case '3':
          rotateNumber = 3;
          break;
      }

      tempTile = rotateImage(tempTile, rotateNumber * 90);
      g.drawImage(tempTile, xp * (squareSize + 1) + 1, yp * (squareSize + 1) + 1, 80, 80, this);
      Image meeple;
      meeple = cutMeeple();

      meeple = PutMeepleView.makeColorTransparent((BufferedImage) meeple, Color.white);
      // if((char)tileMap.get(new Point(3,5)) = 'a'){

      //				System.out.println(xMeeple);
      //				System.out.println(yMeeple);
      if (xMeeple < 10 && yMeeple < 10) {
        g.drawImage(
            meeple,
            xp * (squareSize + 1) + 1 + 27 * xMeeple,
            yp * (squareSize + 1) + 1 + 27 * yMeeple,
            27,
            27,
            this);
      }

      // }
    }
  }
示例#16
0
  /**
   * Shows/hides the security panel.
   *
   * @param isVisible <tt>true</tt> to show the security panel, <tt>false</tt> to hide it
   */
  public void setSecurityPanelVisible(final boolean isVisible) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              setSecurityPanelVisible(isVisible);
            }
          });
      return;
    }

    final JFrame callFrame = callRenderer.getCallContainer().getCallWindow().getFrame();

    final JPanel glassPane = (JPanel) callFrame.getGlassPane();

    if (!isVisible) {
      // Need to hide the security panel explicitly in order to keep the
      // fade effect.
      securityPanel.setVisible(false);
      glassPane.setVisible(false);
      glassPane.removeAll();
    } else {
      glassPane.setLayout(null);
      glassPane.addMouseListener(
          new MouseListener() {
            public void mouseClicked(MouseEvent e) {
              redispatchMouseEvent(glassPane, e);
            }

            public void mouseEntered(MouseEvent e) {
              redispatchMouseEvent(glassPane, e);
            }

            public void mouseExited(MouseEvent e) {
              redispatchMouseEvent(glassPane, e);
            }

            public void mousePressed(MouseEvent e) {
              redispatchMouseEvent(glassPane, e);
            }

            public void mouseReleased(MouseEvent e) {
              redispatchMouseEvent(glassPane, e);
            }
          });

      Point securityLabelPoint = securityStatusLabel.getLocation();

      Point newPoint =
          SwingUtilities.convertPoint(
              securityStatusLabel.getParent(),
              securityLabelPoint.x,
              securityLabelPoint.y,
              callFrame);

      securityPanel.setBeginPoint(new Point((int) newPoint.getX() + 15, 0));
      securityPanel.setBounds(0, (int) newPoint.getY() - 5, this.getWidth(), 130);

      glassPane.add(securityPanel);
      // Need to show the security panel explicitly in order to keep the
      // fade effect.
      securityPanel.setVisible(true);
      glassPane.setVisible(true);

      glassPane.addComponentListener(
          new ComponentAdapter() {
            /** Invoked when the component's size changes. */
            @Override
            public void componentResized(ComponentEvent e) {
              if (glassPane.isVisible()) {
                glassPane.setVisible(false);
                callFrame.removeComponentListener(this);
              }
            }
          });
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == open) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      chooser = new JFileChooser();
      chooser.setAcceptAllFileFilterUsed(false);
      chooser.setFileFilter(new InputFileFilter(false));
      if (loadedFile != null) chooser.setSelectedFile(loadedFile);
      int returnValue = chooser.showOpenDialog(this);
      if (returnValue == JFileChooser.APPROVE_OPTION) {
        boolean approved =
            ((InputFileFilter) chooser.getFileFilter()).isFileApproved(chooser.getSelectedFile());
        if (approved) {
          startProgress();
          new MultiThread(
                  new Runnable() {
                    public void run() {
                      try {

                        loadedFile = chooser.getSelectedFile();
                        FileInputStream fis = new FileInputStream(loadedFile);
                        InputParser ip = new InputParser(fis);
                        if (ip.parseInput()) {
                          field = new Field(new ArrayList<Point>(Arrays.asList(ip.getPoints())));
                          minAlgo.setText(String.valueOf(ip.minimumClusters));
                          maxAlgo.setText(String.valueOf(ip.maximumClusters));
                        }
                      } catch (FileNotFoundException e1) {
                      }
                      contentpanel.center();
                      stopProgress();
                    }
                  })
              .start();
        }
      }
    } else if (e.getSource() == center) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      startProgress();
      new MultiThread(
              new Runnable() {
                public void run() {
                  contentpanel.removeMouseWheelListener(contentpanel);
                  contentpanel.center();
                  contentpanel.addMouseWheelListener(contentpanel);
                  stopProgressRepaint();
                }
              })
          .start();
    } else if (e.getSource() == save) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      chooser = new JFileChooser();
      chooser.setAcceptAllFileFilterUsed(false);
      chooser.setFileFilter(new InputFileFilter(true));
      if (loadedFile != null) chooser.setSelectedFile(loadedFile);
      int returnValue = chooser.showSaveDialog(this);
      if (returnValue == JFileChooser.APPROVE_OPTION) {
        boolean approved =
            ((InputFileFilter) chooser.getFileFilter()).isFileApproved(chooser.getSelectedFile());
        if (approved) {
          loadedFile = chooser.getSelectedFile();
          boolean halt = loadedFile.exists();
          if (halt) {
            int i =
                JOptionPane.showInternalConfirmDialog(
                    c,
                    "Are you sure you want to override this file?",
                    "Warning",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE);
            if (i == JOptionPane.YES_OPTION) {
              halt = false;
            }
          }

          if (!halt) {
            try {
              PrintWriter pw = new PrintWriter(new FileWriter(loadedFile));
              pw.println("find " + field.getNumberOfClusters() + " clusters");
              pw.println(field.size() + " points");
              Object[] obj = field.toArray();
              for (int i = 0; i < obj.length; i++) {
                Point p = (Point) obj[i];
                pw.println(p.getX() + " " + p.getY());
              }
              pw.close();
            } catch (IOException e1) {
            }
          }
        }
      }
    } else if (e.getSource() == clear) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      int i =
          JOptionPane.showInternalConfirmDialog(
              c,
              "Are you sure you want to clear the field?",
              "Warning",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.WARNING_MESSAGE);

      checkRunned();
      if (i == JOptionPane.YES_OPTION) {
        field = new Field();
        updateContentPanel();
      }
    } else if (e.getSource() == circle) {
      contentpanel.setSelectionMode(ContentPanel.SELECT_CIRCLE);
    } else if (e.getSource() == square) {
      contentpanel.setSelectionMode(ContentPanel.SELECT_SQUARE);
    } else if (e.getSource() == addacluster) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      contentpanel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    } else if (e.getSource() == addnoise) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();
      final String s =
          JOptionPane.showInternalInputDialog(
              c, "How many points?", "Add noise", JOptionPane.QUESTION_MESSAGE);

      startProgress();
      new MultiThread(
              new Runnable() {
                public void run() {
                  if (s != null) {
                    int number;
                    try {
                      number = Integer.parseInt(s);
                    } catch (Exception ex) {
                      number = 0;
                    }

                    int tillX = 1000000000;
                    int tillY = 1000000000;
                    int addX = 0;
                    int addY = 0;
                    if (inRectangle.isSelected()) {
                      Rectangle r = field.getBoundingRectangle();
                      if (!(r.x1 == 0 && r.y1 == 0 && r.x2 == 0 && r.y2 == 0)) {
                        tillX = r.x2 - r.x1;
                        addX = r.x1;
                        tillY = r.y2 - r.y1;
                        addY = r.y1;
                      } else {
                        tillX = 500000000;
                        tillY = 500000000;
                      }
                    }

                    for (int i = 0; i < number; i++) {
                      int x = random.nextInt(tillX);
                      x += addX;
                      int y;

                      boolean busy = true;
                      while (busy) {
                        y = random.nextInt(tillY);
                        y += addY;
                        boolean inside = false;
                        Object[] array = field.toArray();
                        for (int j = 0; j < field.size(); j++) {
                          if (((Point) array[j]).compareTo(x, y)) {
                            inside = true;
                            break;
                          }
                        }

                        if (!inside) {
                          field.add(new Point(x, y));
                          busy = false;
                        }
                      }
                    }
                  }
                  stopProgress();
                }
              })
          .start();
    } else if (e.getSource() == run) {
      if (isInProgress()) {
        systemIsBusy();
        return;
      }

      checkRunned();

      startProgress();

      runAlgo();
    }
  }
  public static void main(String[] args) throws Throwable {

    sun.awt.SunToolkit toolkit = (sun.awt.SunToolkit) Toolkit.getDefaultToolkit();

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            test = new TaskbarPositionTest();
          }
        });

    // Use Robot to automate the test
    Robot robot;
    robot = new Robot();
    robot.setAutoDelay(125);

    // 1 - menu
    Util.hitMnemonics(robot, KeyEvent.VK_1);

    toolkit.realSync();
    isPopupOnScreen(menu1.getPopupMenu(), screenBounds);

    // 2 menu with sub menu
    robot.keyPress(KeyEvent.VK_RIGHT);
    robot.keyRelease(KeyEvent.VK_RIGHT);
    Util.hitMnemonics(robot, KeyEvent.VK_S);

    toolkit.realSync();
    isPopupOnScreen(menu2.getPopupMenu(), screenBounds);

    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);

    // Focus should go to non editable combo box
    toolkit.realSync();
    Thread.sleep(500);

    robot.keyPress(KeyEvent.VK_DOWN);

    // How do we check combo boxes?

    // Editable combo box
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);

    // combo1.getUI();

    // Popup from Text field
    robot.keyPress(KeyEvent.VK_TAB);
    robot.keyRelease(KeyEvent.VK_TAB);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    // Popup from a mouse click.
    Point pt = new Point(2, 2);
    SwingUtilities.convertPointToScreen(pt, panel);
    robot.mouseMove((int) pt.getX(), (int) pt.getY());
    robot.mousePress(InputEvent.BUTTON3_MASK);
    robot.mouseRelease(InputEvent.BUTTON3_MASK);

    toolkit.realSync();
    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            test.setLocation(-30, 100);
            combo1.addPopupMenuListener(new ComboPopupCheckListener());
            combo1.requestFocus();
          }
        });

    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);

    toolkit.realSync();
    Thread.sleep(500);
  }