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(); } }
// ------------------------------ 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
/** Find location of character */ public String findLocation(Point loc) { double x = loc.getX(); double y = loc.getY(); if (x >= 400 && y >= 100 && x <= 680 && y <= 180) { return "Wright Hall"; } else if (x >= 120 && y >= 300 && x <= 210 && y <= 490) { return "Burton Hall"; } else if (x >= 30 && y >= 230 && x <= 120 && y <= 490) { return "Sabin-Reed"; } else if (x >= 30 && y >= 580 && x <= 210 && y <= 660) { return "McConnell"; } else if (x >= 30 && y >= 700 && x <= 210 && y <= 770) { return "Tyler House"; } else if (x >= 260 && y >= 580 && x <= 520 && y <= 670) { return "Bass"; } else if (x >= 260 && y >= 670 && x <= 390 && y <= 750) { return "Young Science Library"; } else if (x >= 600 && y >= 230 && x <= 750 && y <= 630) { return "Neilson Library"; } else if (x >= 600 && y >= 700 && x <= 780 && y <= 790) { return "Corner Store"; } else { return ""; } }
/** 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); } }
private void displaySnake(Graphics g) { LinkedList<Point> coordinates = snake.segmentsToDraw(); // Draw head in grey g.setColor(Color.BLACK); // Changed snake head to be drawn in black to enhance minimalist look. // As the snake is always moving forward, it should be relatively // intuitive to see where the head is. Point head = coordinates.pop(); g.fillRect((int) head.getX(), (int) head.getY(), SnakeGame.squareSize, SnakeGame.squareSize); g.setColor(Color.BLACK); for (Point p : coordinates) { g.fillRect((int) p.getX(), (int) p.getY(), SnakeGame.squareSize, SnakeGame.squareSize); } }
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) { } }
public static void requestFocus(Project project, final boolean useRobot) { JFrame frame = WindowManager.getInstance().getFrame(project); // the only reliable way I found to bring it to the top boolean aot = frame.isAlwaysOnTop(); frame.setAlwaysOnTop(true); frame.setAlwaysOnTop(aot); int frameState = frame.getExtendedState(); if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) { // restore the frame if it is minimized frame.setExtendedState(frameState ^ Frame.ICONIFIED); } frame.toFront(); frame.requestFocus(); if (useRobot && runningOnWindows7()) { try { // remember the last location of mouse final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation(); // simulate a mouse click on title bar of window Robot robot = new Robot(); robot.mouseMove(frame.getX(), frame.getY()); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // move mouse to old location robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY()); } catch (Exception ex) { // just ignore exception, or you can handle it as you want } finally { frame.setAlwaysOnTop(false); } } }
/** * Spusti se pri zmacknuti tlacitka. Pokud je pod mysi obraz figury, zjisti, zda se muze pohnout * (pokud ano, upravi ho pro tahnuti, nastavi ho do figLabel) a zobrazi kontextovou napovedu. */ private void eCatcherMousePressed( java.awt.event.MouseEvent evt) { // GEN-FIRST:event_eCatcherMousePressed if (figLabel != null || finished) { return; } BoardSquare bsquare = (BoardSquare) eCatcher.getComponentAt(evt.getPoint()); JPanel fsquare = (JPanel) figurePan.getComponent(bsquare.getIndex()); sourceBSquare = bsquare; Point defLocation = fsquare.getLocation(); xAdjustment = (int) defLocation.getX() - evt.getX(); yAdjustment = (int) defLocation.getY() - evt.getY(); if (fsquare.getComponentCount() == 0) { return; } figLabel = (JLabel) fsquare.getComponent(0); setFocus(gui.getFocus(bsquare.getColumn(), bsquare.getRow())); if (!gui.canMove(bsquare.getColumn(), bsquare.getRow())) { figLabel = null; return; } fsquare.remove(figLabel); boardPane.add(figLabel, 0); figLabel.setLocation(evt.getX() + xAdjustment, evt.getY() + yAdjustment); figLabel.setSize(figLabel.getWidth(), figLabel.getHeight()); } // GEN-LAST:event_eCatcherMousePressed
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()); }
/** 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())); }
public static void setPositionRelativeToParent( Window w, Component parent, int hOffset, int vOffset) { try { Point p = parent.getLocationOnScreen(); int x = (int) p.getX() + hOffset; int y = (int) p.getY() + vOffset; w.setLocation(x, y); w.pack(); } catch (Throwable t) { } }
// 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())); }
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); } }
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); } } }
public void paintComponent(Graphics g) { if (position == null) return; int x = (int) position.getX(); int y = (int) position.getY(); if (parent.inFirstPath(this)) { g.setColor(Color.yellow); g.fillOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS); } else if (parent.inQueue(this)) { g.setColor(Color.orange); g.fillOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS); } g.setColor(getColor()); g.drawOval(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS); if (parent.isGoalNode(this)) g.setColor(Color.green); else if (parent.isStartNode(this)) g.setColor(Color.blue); g.drawString(toString(), x, y); if (!parent.getHideHeur()) g.drawString(model.getHeuristic() + "", x + RADIUS, y + RADIUS); }
@Override public void mouseClicked(MouseEvent e) { indexOfLabelPressed = -1; for (int i = 0; i < orderLabel.length; i++) { if (e.getSource() == orderLabel[i]) { indexOfLabelPressed = i; PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); int x = (int) b.getX(); int y = (int) b.getY(); popup.setLocation(x, y); popup.setInvoker(popup); popup.setVisible(true); revalidate(); repaint(); } } if (e.getSource() == topPanelLabel) { indexOfLabelPressed = -2; } if (indexOfLabelPressed == -1) { okDiscountButton.setText("Deduct"); discountPopup.setLocation(700, 220); discountPopup.setInvoker(discountPopup); discountPopup.setVisible(true); itemDiscountPopupLabel.setText( "$" + finalModifier + " off with " + menuPanel.df.format((1 - finalPercentModifier) * 100) + "%" + " discount"); } else if (indexOfLabelPressed == -2) { // TODO resetAll(); } }
private boolean isInClickableArea(Point pt) { if (getIcon() != null) { if (pt.getX() < getIcon().getIconWidth() && pt.getY() < getIcon().getIconHeight()) { return true; } } if (getText() != null) { FontMetrics fm = getFontMetrics(getFont()); int height = fm.getHeight() + 1; int y = getHeight() / 2 - fm.getHeight() / 2; int width = fm.stringWidth(getText()); if (myPaintDefaultIcon) { width += LINK.getIconWidth() + DEFAULT_ICON_GAP; } if (getHorizontalAlignment() == LEFT) { return (new Rectangle(myIconWidth, y, width, height).contains(pt)); } else { return (new Rectangle(getWidth() - width - 1, y, getWidth() - 1, height).contains(pt)); } } return false; }
boolean containsPoint(Point p) { if (position == null) return false; return Math.pow(p.getX() - position.getX(), 2) + Math.pow(p.getY() - position.getY(), 2) <= Math.pow(RADIUS, 2); }
/** * 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(); } }
private PortView getPortViewAt(Point point) { return getNet().getPortViewAt(point.getX(), point.getY()); }
/** * method to set the dragndrop action when mouse is released * * @param e */ public void mouseReleased(MouseEvent e) { /** get position if off glass panel then return */ Point p = e.getPoint(); if (!contains(glassPanel, selectedComponent)) return; /** * check drop point is on glasspanel this is copied form below and should be put into a new * method */ Rectangle gP = glassPanel.getBounds(); if (!gP.contains(p)) { glassPanel.remove(selectedComponent); OriP.add(selectedComponent); int x = Original.x; int y = Original.y; Dimension d = selectedComponent.getSize(); selectedComponent.setBounds(x, y, d.width, d.height); return; } /** Calculate actions when dropped remove from glasspanel and set new active panel */ glassPanel.remove(selectedComponent); setActivePanel(p); /** check whether the droppoint was over a symhooks point */ Rectangle PanelA = new Rectangle(activePanel.getBounds()); c1 = new Rectangle(); for (int i = 0; i < SymHooks.length; i++) { c1.setBounds(SymHooks[i].getBounds()); // c1.setLocation(c1.x, c1.y + p1.getHeight()); if (activePanel.equals(p3) && (c1.contains(p))) { activePanel.add(selectedComponent); Rectangle r = activePanel.getBounds(); int x = p.x - offset.x - r.x; int y = p.y - offset.y - r.y; Dimension d = selectedComponent.getSize(); selectedComponent.setBounds(x, y, d.width, d.height); dragging = false; dropflag = true; /** if the icon came from the ImagePanel then repopulate */ if (OriP.equals(Imp)) { for (int j = 0; j < Symlab.length; j++) { if (Original.getY() == Symlab[j].getPosition().getY()) { newlabel = new JLabel(); newlabel.setIcon(new ImageIcon(Symlab[j].getSymImage())); d = new Dimension(); d = newlabel.getPreferredSize(); newlabel.setBounds( Symlab[j].getJLabel().getX(), Symlab[j].getJLabel().getY(), d.width, d.height); newlabel.setName(String.valueOf(Symlab[j].getType())); Imp.add(newlabel); JLabel test = (JLabel) selectedComponent; } } } } } /** if the drop point was over the waste box then don't replace at original site */ if (WasteBox.contains(p) && (!OriP.equals(Imp))) { dropflag = true; } /** if not dropped then return to original position */ if (!dropflag) { glassPanel.remove(selectedComponent); OriP.add(selectedComponent); int x = Original.x; int y = Original.y; Dimension d = selectedComponent.getSize(); selectedComponent.setBounds(x, y, d.width, d.height); } dropflag = false; // activePanel.repaint(); // OriP.repaint(); glassPanel.repaint(); activePanel = null; }
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); } // } } }
private Object getElementAt(Point point) { return getNet().getFirstCellForLocation(point.getX(), point.getY()); }
/** * Draws a Point object on the GrapherPanel as a 5 pixel radius circle centered on the Point * object's x and y values scaled by 25 pixels per integer value and centered around the origin at * 250, 250. * * @param p The Point object to paint. */ private void paintPoint(Point p) { g.setColor(Color.BLUE); g.fillOval(250 + (int) (p.getX() * 25) - 5, 250 - (int) (p.getY() * 25) - 5, 10, 10); }
protected void handleExecute() { ImageView view = getSelectedView(); if (view != null) { ColorBarAnnotation cbar = (ColorBarAnnotation) view.getAnnotation(view.getSelectedPlot(), ColorBarAnnotation.ID); if (cbar == null) { cbar = new ColorBarAnnotation(view.getModel()); view.setAnnotation(view.getSelectedPlot(), cbar.getIdentifier(), cbar); } log.finest("retrieved color bar annotation for editing"); ColorBarAnnotationPresenter presenter = new ColorBarAnnotationPresenter(cbar); Container c = JOptionPane.getFrameForComponent(view); final JButton okButton = new JButton("OK"); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); dialog.dispose(); } }); final JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // view.setAnnotation(safeCopy); // icross.setLinePaint(safeCopy.getLinePaint()); // icross.setLineWidth(safeCopy.getLineWidth()); // icross.setGap(safeCopy.getGap()); // icross.setVisible(safeCopy.isVisible()); dialog.setVisible(false); dialog.dispose(); } }); final JButton applyButton = new JButton("Apply"); dialog = new JDialog(JOptionPane.getFrameForComponent(view)); dialog.setLayout(new BorderLayout()); Point p = c.getLocation(); JPanel mainPanel = new JPanel(); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 8, 15, 8)); mainPanel.setLayout(new BorderLayout()); JPanel buttonPanel = ButtonBarFactory.buildRightAlignedBar(okButton, cancelButton, applyButton); mainPanel.add(presenter.getComponent(), BorderLayout.CENTER); mainPanel.add(buttonPanel, BorderLayout.SOUTH); dialog.add(mainPanel, BorderLayout.CENTER); dialog.pack(); dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setLocation( (int) (p.getX() + c.getWidth() / 2f), (int) (p.getY() + c.getHeight() / 2f)); dialog.setVisible(true); } }
public void mouseClicked(MouseEvent evt) { int btn = evt.getButton(); if (btn == MouseEvent.BUTTON3) { JPopupMenu helpMenu = new JPopupMenu(); String helpLabel = Util.getLabel("CSHMenu"); JMenuItem helpMenuItem = new JMenuItem(helpLabel); helpMenuItem.setActionCommand("help"); helpMenu.add(helpMenuItem); ActionListener alMenuItem = new ActionListener() { public void actionPerformed(ActionEvent e) { String topic = ""; try { JComponent c1 = (JComponent) tabbedPane.getSelectedComponent(); // This component should contain the following embedded items. // We want m_helplink out of the top VGroup. // PushpinObj // XMLToolPanel // JScrollpane // JViewport // JPanel // VGroup // Work down to the VGroup, checking for class type along // the way. if (c1 instanceof PushpinObj) { Component c2[] = c1.getComponents(); int cnt; for (cnt = 0; cnt < c2.length; cnt++) { // The PushpinObj can have multiple items, find the one we want if (c2[cnt] instanceof XMLToolPanel) break; } if (cnt < c2.length && c2[cnt] instanceof XMLToolPanel) { Component c3[] = ((JComponent) c2[cnt]).getComponents(); if (c3[0] instanceof JScrollPane) { Component c4[] = ((JComponent) c3[0]).getComponents(); if (c4[0] instanceof JViewport) { Component c5[] = ((JComponent) c4[0]).getComponents(); if (c5[0] instanceof JPanel) { Component c6[] = ((JComponent) c5[0]).getComponents(); if (c6[0] instanceof VGroup) { // Get the helplink info from the VGroup topic = ((VGroup) c6[0]).getAttribute(VObjDef.HELPLINK); } } } } } } // If no helplink found, try the Tab's name if (topic == null || topic.length() == 0) { topic = c1.getName(); if (topic.equals("Locator")) topic = getLocatorName(); topic = topic.replace(" ", "_"); } } catch (Exception ex) { } // Get the ID and display the help content CSH_Util.displayCSHelp(topic); } }; helpMenuItem.addActionListener(alMenuItem); Point pt = evt.getPoint(); helpMenu.show(VTabbedToolPanel.this, (int) pt.getX(), (int) pt.getY()); } }
public boolean inPicture(Point point) { return point.getX() > bounds[0].getX() && point.getY() < bounds[0].getY() && point.getX() < bounds[1].getX() && point.getY() > bounds[1].getY(); }
public void setPopupLocation(Point location) { setPopupLocation((int) location.getX(), (int) location.getY()); }
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); }