Java Code Examples for java.awt.Point

The following are top voted examples for showing how to use java.awt.Point. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: brModelo   File: SuperLinha.java   View source code 6 votes vote down vote up
@Override
protected void ProcessaDblClick(MouseEvent e) {
    Point p = e.getPoint();
    for (int i = 1; i < getPontosParaDesenho().length; i++) {
        if (Linha.SegmentIntersectRectangle(p.x - 1, p.y - 1, p.x + 1, p.y + 1,
                getPontosParaDesenho()[i - 1].x, getPontosParaDesenho()[i - 1].y,
                getPontosParaDesenho()[i].x, getPontosParaDesenho()[i].y)) {
            PontoDeLinha pt = InserirPonto(i);
            pt.setCentro(p);
            //pt.IsHide = false;
            pt.setVisible(true);
            mouseExited(null);//evita que a linha permaneça na forma do mouseEntred.
            return;
        }
    }
}
 
Example 2
Project: SE2017-Team1   File: SingleRelationTests.java   View source code 6 votes vote down vote up
@Test
  public void testCondFlip() throws Exception {
  	String fileNameExpected = "images/expected/cond_flip";
      ConditionFlipped graphExpected = new ConditionFlipped();
      TestUtil.drawAndSave(graphExpected, fileNameExpected);
      
      String fileNameGenerated = "images/generated/cond_flip";
      ConresGraph graph = new ConresGraph();
graph.activities = new ArrayList<ConresActivity>();
graph.relations = new ArrayList<ConresRelation>();
ConresActivity act1 = new ConresActivity(0, new Point(50, 35), "Activity 1", "ROLE", false, false, false);
ConresActivity act2 = new ConresActivity(1, new Point(250, 35), "Activity 2", "ROLE", false, false, false);
graph.activities.add(act1);
graph.activities.add(act2);
ConresRelation relation = new ConresRelation(act1, act2, "cond");
graph.relations.add(relation);
JPanel graphGenerated = crv.draw(graph);
      TestUtil.drawAndSave(graphGenerated, fileNameGenerated);
  	
  	String cs1 = TestUtil.getChecksum(fileNameExpected + IMAGE_FORMAT);
  	String cs2 = TestUtil.getChecksum(fileNameGenerated + IMAGE_FORMAT);
  	assertEquals(cs1, cs2);
  }
 
Example 3
Project: Neukoelln_SER316   File: EstimatePanel.java   View source code 6 votes vote down vote up
private void newEstimateB_actionPerformed(ActionEvent e, String tasktext, Date startDate, Date endDate) {    	
  	EstimateDialog dlg = new EstimateDialog(App.getFrame(), Local.getString("New Estimate Worksheet"));
  	Dimension frmSize = App.getFrame().getSize();
  	Point loc = App.getFrame().getLocation();
  	dlg.setLocation((frmSize.width - dlg.getSize().width) / 2 + loc.x, (frmSize.height - dlg.getSize().height) / 2 + loc.y);    	
dlg.setVisible(true);

if (dlg.CANCELLED)
  		return;

// create Estimate			
  	int size = (int)dlg.loc.getValue();
  	int time = (int)dlg.minutes.getValue();
  	//PSP.Phase phase = PSP.Phase.valueOf(PSP.reverseConversion(dlg.phase.getSelectedItem().toString(),0));
  	PSP.Phase phase = PSP.Phase.valueOf(dlg.phase.getSelectedItem().toString());
  	String comments = dlg.comments.getText();		
  	String mod = dlg.module.getText();			
  	EstimateManager.createEstimate(phase, mod, size, time, comments);
  	saveEstimate();
  }
 
Example 4
Project: brModelo   File: EapBarraLigacao.java   View source code 6 votes vote down vote up
/**
 * Qual a forma mais a direita e qual a mais a esquerda e qual a distnacia delas ao 'centro' da EAP
 *
 * @param areas
 * @return p.x = LEFT e p.y = Right
 */
protected Point calcDifCentroEapHorizontal(HashMap<Forma, EapBarraLigacao> areas) {
    ArrayList<Forma> lst = getListaDeFormasLigadas();
    Forma ma = capturePrincipal();
    lst.remove(ma);
    Forma fmE = getFormaMaisEsquerda(lst);
    Forma fmD = getFormaMaisDireita(lst);
    ArrayList<EapBarraLigacao> jatmp = new ArrayList<>();

    fmE = (areas.get(fmE) == null ? fmE : areas.get(fmE).calcMaisAEsquerda(jatmp, areas));
    jatmp = new ArrayList<>();
    fmD = (areas.get(fmD) == null ? fmD : areas.get(fmD).calcMaisADireita(jatmp, areas));

    int tamE = ma.getLeft() + (ma.getWidth() / 2) - fmE.getLeft();
    int tamD = fmD.getLeftWidth() - (ma.getLeftWidth() - (ma.getWidth() / 2));

    return new Point(tamE, tamD);
}
 
Example 5
Project: AeroStory   File: MapleMap.java   View source code 6 votes vote down vote up
public final void spawnItemDrop(final MapleMapObject dropper, final MapleCharacter owner, final Item item, Point pos, final boolean ffaDrop, final boolean playerDrop) {
    final Point droppos = calcDropPos(pos, pos);
    final MapleMapItem drop = new MapleMapItem(item, droppos, dropper, owner, (byte) (ffaDrop ? 2 : 0), playerDrop);

    spawnAndAddRangedMapObject(drop, new DelayedPacketCreation() {
        @Override
        public void sendPackets(MapleClient c) {
            c.announce(MaplePacketCreator.dropItemFromMapObject(drop, dropper.getPosition(), droppos, (byte) 1));
        }
    }, null);
    broadcastMessage(MaplePacketCreator.dropItemFromMapObject(drop, dropper.getPosition(), droppos, (byte) 0));

    if (!everlast) {
        TimerManager.getInstance().schedule(new ExpireMapItemJob(drop), 180000);
        activateItemReactors(drop, owner.getClient());
    }
}
 
Example 6
Project: JavaGraph   File: ContributorsTable.java   View source code 6 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    JTable table = (JTable) e.getSource();
    Point pt = e.getPoint();
    int ccol = table.columnAtPoint(pt);
    int crow = table.rowAtPoint(pt);
    Object value = table.getValueAt(crow, ccol);
    if (value instanceof URL) {
        URL url = (URL) value;
        try {
            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().browse(url.toURI());
            }
        } catch (Exception ex) {
            throw new IllegalStateException(ex);
        }
    }
}
 
Example 7
Project: Lucid2.0   File: CField.java   View source code 6 votes vote down vote up
public static byte[] getCapturePosition(MapleMap map) {
    PacketWriter pw = new PacketWriter();

    Point p1 = map.getPointOfItem(2910000);
    Point p2 = map.getPointOfItem(2910001);
    pw.writeShort(SendPacketOpcode.CAPTURE_POSITION.getValue());
    pw.write(p1 == null ? 0 : 1);
    if (p1 != null) {
        pw.writeInt(p1.x);
        pw.writeInt(p1.y);
    }
    pw.write(p2 == null ? 0 : 1);
    if (p2 != null) {
        pw.writeInt(p2.x);
        pw.writeInt(p2.y);
    }

    return pw.getPacket();
}
 
Example 8
Project: jmt   File: DefaultIconsToolkit.java   View source code 6 votes vote down vote up
@Override
public Image getEdgeIcon(Rectangle bounds, Point[] anglePoints) {
	/*creates background image.*/
	BufferedImage bgImage = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics bgGr = bgImage.getGraphics();
	bgGr.setColor(new Color(0, 0, 0, 0));
	bgGr.fillRect(0, 0, bounds.width, bounds.height);
	for (int i = 0; i < anglePoints.length - 1; i++) {
		//Must convert absolute coords to local coords
		int x0 = anglePoints[i].x - bounds.x, y0 = anglePoints[i].y - bounds.y, x1 = anglePoints[i + 1].x - bounds.x, y1 = anglePoints[i + 1].y
				- bounds.y;
		bgGr.setColor(Color.GRAY);
		bgGr.drawLine(x0, y0, x1, y1);
		bgGr.setColor(new Color(30, 30, 30, 30));
		//bgGr.fillRect(Math.min(x0,x1)-1, Math.min(y0,y1)-1, Math.abs(x1-x0)+3, Math.abs(y1-y0)+3);
		bgGr.drawLine(x0 - 1, y0 - 1, x1 - 1, y1 - 1);
	}
	return bgImage;
}
 
Example 9
Project: incubator-netbeans   File: GlassPane.java   View source code 6 votes vote down vote up
/**
 * Calculates the grid location of the moved component.
 *
 * @param cursorLocation current position of the cursor.
 */
void calculateMovingGridLocation(Point cursorLocation) {
    Point start = toComponentPane(draggingStart);
    Point end = toComponentPane(cursorLocation);
    int startX = gridXLocation(start.x, true);
    int startY = gridYLocation(start.y, true);
    int endX = gridXLocation(end.x, false);
    int endY = gridYLocation(end.y, false);
    int deltaX = endX-startX;
    int deltaY = endY-startY;
    deltaX = Math.max(deltaX, -selMinX);
    deltaY = Math.max(deltaY, -selMinY);
    int tempGridX = gridInfo.getGridX(focusedComponent) + deltaX;
    int tempGridY = gridInfo.getGridY(focusedComponent) + deltaY;
    if( !gridInfo.isGapColumn(tempGridX) && !gridInfo.isGapRow(tempGridY) ) {
        newGridX = tempGridX;
        newGridY = tempGridY;
    }
}
 
Example 10
Project: Pogamut3   File: DnDMoveProvider.java   View source code 6 votes vote down vote up
@Override
public void setNewLocation(Widget w, Point currentLocation) {
    ghost.setPreferredLocation(currentLocation);

    Point center = getGhostCenter();
    PoshWidget<? extends PoshElement> hitWidget = this.findContainingWidget(center);
    if (hitWidget == null) {
        ghost.setBorder(FUTILE_BORDER);
        return;
    }

    List<AbstractAcceptAction> acceptProviders = hitWidget.getAcceptProviders();

    for (AbstractAcceptAction acceptProvider : acceptProviders) {
        DataFlavor ghostDataFlavor = ghost.associatedWidget.getDataNode().getDataFlavor();
        DataFlavor acceptDataFlavor = acceptProvider.getDataFlavor();

        if (acceptDataFlavor.equals(ghostDataFlavor)) {
            ghost.setBorder(ACCEPTING_BORDER);
            return;
        }
    }
    ghost.setBorder(FUTILE_BORDER);
}
 
Example 11
Project: jdk8u-jdk   File: PolicyTool.java   View source code 6 votes vote down vote up
/**
 * displays a dialog box describing an error which occurred.
 */
void displayErrorDialog(Window w, String error) {
    ToolDialog ed = new ToolDialog
            (PolicyTool.getMessage("Error"), tool, this, true);

    // find where the PolicyTool gui is
    Point location = ((w == null) ?
            getLocationOnScreen() : w.getLocationOnScreen());
    //ed.setBounds(location.x + 50, location.y + 50, 600, 100);
    ed.setLayout(new GridBagLayout());

    JLabel label = new JLabel(error);
    addNewComponent(ed, label, 0,
                    0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);

    JButton okButton = new JButton(PolicyTool.getMessage("OK"));
    ActionListener okListener = new ErrorOKButtonListener(ed);
    okButton.addActionListener(okListener);
    addNewComponent(ed, okButton, 1,
                    0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);

    ed.getRootPane().setDefaultButton(okButton);
    ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);

    ed.pack();
    ed.setLocationRelativeTo(w);
    ed.setVisible(true);
}
 
Example 12
Project: TrabalhoFinalEDA2   File: mxGraphOutline.java   View source code 6 votes vote down vote up
/**
 * Paints the graph outline.
 */
public void paintGraph(Graphics g)
{
	if (graphComponent != null)
	{
		Graphics2D g2 = (Graphics2D) g;
		AffineTransform tx = g2.getTransform();

		try
		{
			Point tr = graphComponent.getGraphControl().getTranslate();
			g2.translate(translate.x + tr.getX() * scale,
					translate.y + tr.getY() * scale);
			g2.scale(scale, scale);

			// Draws the scaled graph
			graphComponent.getGraphControl().drawGraph(g2, drawLabels);
		}
		finally
		{
			g2.setTransform(tx);
		}
	}
}
 
Example 13
Project: genetic-algorithm   File: VorführungGenAdv.java   View source code 6 votes vote down vote up
static void loop(Simulation sim, PrintWriter out) throws GameOver {
	SimulationState simState = sim.getSimulationState();
	bot.update(simState);

	if (bot.bomb) {
		System.out.println("true");
		out.println("true");
		sim.update(true);
	} else {
		int x = bot.x;
		int y = bot.y;

		System.out.println(x + " " + y);
		out.println(x + " " + y);
		sim.update(new Point(x, y));
	}

}
 
Example 14
Project: alevin-svn2   File: MySatelliteVisualizationViewer.java   View source code 6 votes vote down vote up
@Override
public void paint(Graphics g) {
	ShapeTransformer masterViewTransformer = master.getRenderContext()
			.getMultiLayerTransformer().getTransformer(Layer.VIEW);
	ShapeTransformer masterLayoutTransformer = master
			.getRenderContext().getMultiLayerTransformer()
			.getTransformer(Layer.LAYOUT);
	ShapeTransformer vvLayoutTransformer = vv.getRenderContext()
			.getMultiLayerTransformer().getTransformer(Layer.LAYOUT);

	// changed: bounds without offset
	Shape lens = new Rectangle(new Point(), master.getSize());

	lens = masterViewTransformer.inverseTransform(lens);
	lens = masterLayoutTransformer.inverseTransform(lens);
	lens = vvLayoutTransformer.transform(lens);
	Graphics2D g2d = (Graphics2D) g;
	Color old = g.getColor();
	Color lensColor = master.getBackground();
	vv.setBackground(lensColor.darker());
	g.setColor(lensColor);
	g2d.fill(lens);
	g.setColor(Color.gray);
	g2d.draw(lens);
	g.setColor(old);
}
 
Example 15
Project: VTerminal   File: ImagePrinter.java   View source code 6 votes vote down vote up
/**
 * Prints an image on a component.
 *
 * @param component
 *         The component.
 *
 * @param columnIndex
 *         The x-axis (column) coordinate of the top-left character.
 *
 * @param rowIndex
 *         The y-axis (row) coordinate of the top-left character.
 *
 * @throws NullPointerException
 *         If the screen is null.
 */
private void print(final @NonNull Component component, final int columnIndex, final int rowIndex) {
    final BufferedImage temp = applyTransformations();
    final Point charPosition = new Point(0, 0);

    for (int y = 0 ; y < temp.getHeight() && y < component.getHeight() ; y++) {
        for (int x = 0 ; x < temp.getWidth() && x < component.getWidth() ; x++) {
            final int hexColor = temp.getRGB(x,y);
            final int red = (hexColor & 0x00ff0000) >> 16;
            final int green = (hexColor & 0x0000ff00) >> 8;
            final int blue =  hexColor & 0x000000ff;

            final int charX = x + columnIndex;
            final int charY = y + rowIndex;
            charPosition.setLocation(charX, charY);

            final AsciiCharacter character = component.getCharacterAt(charPosition);
            character.setCharacter(printChar);
            character.setForegroundColor(new Color(red, green, blue));
        }
    }
}
 
Example 16
Project: incubator-netbeans   File: TableRendererTest.java   View source code 6 votes vote down vote up
@Override
public boolean isCellEditable(EventObject anEvent) {
    if (anEvent.getSource() instanceof JTable) {
        JTable table = (JTable) anEvent.getSource();
        if (anEvent instanceof MouseEvent) {
            MouseEvent event = (MouseEvent) anEvent;
            Point p = event.getPoint();
            int row = table.rowAtPoint(p);
            int col = table.columnAtPoint(p);
            Rectangle rect = table.getCellRect(row, col, true);
            p.translate(-rect.x, -rect.y);
            System.out.println("isCellEditable("+anEvent+")");
            System.out.println("Point "+p+"in rectangle "+rect);
            if (p.x > rect.width - 24) {
                // last 24 points not editable
                return false;
            }
        }
    }
    return true;
}
 
Example 17
Project: litiengine   File: Spritesheet.java   View source code 6 votes vote down vote up
public BufferedImage getSprite(final int index) {
  final String imageCacheKey = MessageFormat.format("{0}_{1}", this.hashCode, index);
  if (ImageCache.SPRITES.containsKey(imageCacheKey)) {
    return ImageCache.SPRITES.get(imageCacheKey);
  }

  if (this.getImage() == null) {
    log.warning("no image defined for sprite '" + this.getName() + "'");
    return null;
  }

  final Point position = this.getLocation(index);
  try {
    final BufferedImage smallImage = this.getImage().getSubimage(position.x, position.y, this.spriteWidth, this.spriteHeight);
    ImageCache.SPRITES.put(imageCacheKey, smallImage);
    return smallImage;
  } catch (final RasterFormatException rfe) {
    log.warning("could not read sprite of size [" + this.spriteWidth + "x" + this.spriteHeight + " at position [" + position.x + "," + position.y + "] from sprite'" + this.getName() + "'");
    return null;
  }
}
 
Example 18
Project: incubator-netbeans   File: ShortcutCellPanel.java   View source code 6 votes vote down vote up
private void changeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed
    JComponent tf = changeButton;
    Point p = new Point(tf.getX(), tf.getY());
    SwingUtilities.convertPointToScreen(p, this);
    //show special key popup
    if (popup == null) {
        changeButton.setText(""); // NOI18N
        changeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/options/keymap/more_closed.png")));
        if (Utilities.isUnix()) {
            // #156869 workaround, force HW for Linux
            popup = PopupFactory.getSharedInstance().getPopup(null, specialkeyList, p.x, p.y + tf.getHeight());
        } else {
            popup = factory.getPopup(this, specialkeyList, p.x, p.y + tf.getHeight());
        }
        popup.show();
    } else {
        changeButton.setText(""); // NOI18N
        changeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/netbeans/modules/options/keymap/more_opened.png")));
        hidePopup();
    }
}
 
Example 19
Project: incubator-netbeans   File: CloseButtonHandler.java   View source code 6 votes vote down vote up
@Override
public void mouseMoved( MouseEvent e ) {
    if( e.getSource() instanceof TabTable ) {
        int closeButtonRow = -1;
        int closeButtonColumn = -1;
        TabTable table = ( TabTable ) e.getSource();
        Point p = e.getPoint();
        int row = table.rowAtPoint( p );
        int col = table.columnAtPoint( p );
        if( row >= 0 && col >= 0 ) {
            TableCellRenderer ren = table.getCellRenderer( row, col );
            if( ren instanceof TabDataRenderer ) {
                TabDataRenderer tabRenderer = ( TabDataRenderer ) ren;
                if( tabRenderer.isInCloseButton( table.getCellRect( row, col, true ), p ) ) {
                    closeButtonRow = row;
                    closeButtonColumn = col;
                }
            }
        }
        table.setCurrentCloseButtonCoords( closeButtonRow, closeButtonColumn );
    }
}
 
Example 20
Project: Pixie   File: ResizeTest.java   View source code 6 votes vote down vote up
@Test
public void testOriginalToResized_03() {
    final String testDescription = "----------originalToResized_03----------\n"
            + " Summary: Test of originalToResized(int, int) method, of class Resize\n"
            + " Description: Check if the resize ratio of 1.0 is outputing the same input value. Check if resize ratio 1.0 is neutral element / identity element. Input point (10, 10), the resize is set to (1.0, 1.0).\n"
            + " Pre-conditions: none\n"
            + " Conditions: none\n"
            + " Expected result: It shall output the point (10, 10); no errors or exceptions shall occur.\n";
    System.out.println(testDescription);

    int x = 10;
    int y = 10;
    Resize instance = new Resize(1.0, 1.0);
    Point expResult = new Point(10, 10);
    Point result = instance.originalToResized(x, y);
    assertEquals(expResult, result);
}
 
Example 21
Project: jmt   File: Convex3DGraph.java   View source code 6 votes vote down vote up
public void mouseReleased(MouseEvent evt) {
	switch (evt.getButton()) {
	case MouseEvent.BUTTON1: {
		mouseLeft = false;
		break;
	}
	case MouseEvent.BUTTON2: {
		mouseRight = false;
		break;
	}
	}
	if (!mouseLeft && !mouseRight) {
		mouseMode = MouseMode.NONE;
	}
	// This is the last mouse action, so keep track of it.
	mouseEnd.x = evt.getX();
	mouseEnd.y = evt.getY();
	mouseDelta = new Point(mouseEnd.x - mouseStart.x, mouseEnd.y
			- mouseStart.y);
	repaint();
}
 
Example 22
Project: jdk8u-jdk   File: MutterMaximizeTest.java   View source code 6 votes vote down vote up
private static Thread startRegTest(final Frame f) {
    Thread robot = new Thread(new Runnable() {
        public void run() {
            Robot r = Util.createRobot();
            dragWindow(f, 100, 100, r);
            // wait for the location to be set.
            sleepFor(2000);

            final Point l2 = f.getLocationOnScreen();

            // double click should maximize the frame
            doubleClick(r);

            // wait for location again.
            sleepFor(2000);
            final Point l3 = f.getLocationOnScreen();
            if (l3.equals(l2)) {
                throw new RuntimeException("Bad location after maximize. Window location has not moved");
            }
        }
    });
    return robot;
}
 
Example 23
Project: JDigitalSimulator   File: ALU74181.java   View source code 5 votes vote down vote up
protected void setContactLocations() {
	inputs[0].setLocation(new Point(0, 52)); //M
	inputs[1].setLocation(new Point(0, 60)); //Cn
	outputs[0].setLocation(new Point(size.width, 17)); //P
	outputs[1].setLocation(new Point(size.width, 25)); //G
	outputs[2].setLocation(new Point(size.width, 43)); //Cn+4
	outputs[3].setLocation(new Point(size.width, 61)); //A=B
	for(int number=0;number<4;number++) {
		int top = 63+number*20;
		inputsA[number].setLocation(new Point(0, top+18)); //A
		inputsB[number].setLocation(new Point(0, top+28)); //B
		inputsS[number].setLocation(new Point(0, 9+number*10)); //S
		outputsF[number].setLocation(new Point(size.width, top+22)); //F
	}
}
 
Example 24
Project: Neukoelln_SER316   File: HTMLEditor.java   View source code 5 votes vote down vote up
void setElementProperties(Element el, String id, String cls, String sty) {
	ElementDialog dlg = new ElementDialog(null);
	//dlg.setLocation(linkActionB.getLocationOnScreen());
	Dimension dlgSize = dlg.getPreferredSize();
	Dimension frmSize = this.getSize();
	Point loc = this.getLocationOnScreen();
	dlg.setLocation(
		(frmSize.width - dlgSize.width) / 2 + loc.x,
		(frmSize.height - dlgSize.height) / 2 + loc.y);
	dlg.setModal(true);
	dlg.setTitle(Local.getString("Object properties"));
	dlg.idField.setText(id);
	dlg.classField.setText(cls);
	dlg.styleField.setText(sty);
	// Uncommented, returns a simple p into the header... fix needed ?
	//dlg.header.setText(el.getName());
	dlg.setVisible(true);
	if (dlg.CANCELLED)
		return;
	SimpleAttributeSet attrs = new SimpleAttributeSet(el.getAttributes());
	if (dlg.idField.getText().length() > 0)
		attrs.addAttribute(HTML.Attribute.ID, dlg.idField.getText());
	if (dlg.classField.getText().length() > 0)
		attrs.addAttribute(HTML.Attribute.CLASS, dlg.classField.getText());
	if (dlg.styleField.getText().length() > 0)
		attrs.addAttribute(HTML.Attribute.STYLE, dlg.styleField.getText());
	document.setParagraphAttributes(el.getStartOffset(), 0, attrs, true);
}
 
Example 25
Project: MaxSim   File: InputSlotWidget.java   View source code 5 votes vote down vote up
public InputSlotWidget(InputSlot slot, DiagramScene scene, Widget parent, FigureWidget fw) {
    super(slot, scene, parent, fw);
    inputSlot = slot;
    //init();
    //getFigureWidget().getLeftWidget().addChild(this);
    Point p = inputSlot.getRelativePosition();
    p.x -= this.calculateClientArea().width / 2;
    p.y += Figure.SLOT_START;
    this.setPreferredLocation(p);
}
 
Example 26
Project: MaxSim   File: PolylineRouter.java   View source code 5 votes vote down vote up
private boolean intersects(Collection<Widget> nodeWidgets, Point start, Point end) {
    List<Point> pointlist = new ArrayList<>();
    pointlist.add(start);
    pointlist.add(end);

    for(Widget w : nodeWidgets){
        if(w.isVisible() && intersects(w, pointlist)) {
            return true;
        }
    }
    return false;
}
 
Example 27
Project: OpenJSharp   File: SunDragSourceContextPeer.java   View source code 5 votes vote down vote up
/**
 * initiate a DnD operation ...
 */

public void startDrag(DragSourceContext dsc, Cursor c, Image di, Point p)
  throws InvalidDnDOperationException {

    /* Fix for 4354044: don't initiate a drag if event sequence provided by
     * DragGestureRecognizer is empty */
    if (getTrigger().getTriggerEvent() == null) {
        throw new InvalidDnDOperationException("DragGestureEvent has a null trigger");
    }

    dragSourceContext = dsc;
    cursor            = c;
    sourceActions     = getDragSourceContext().getSourceActions();
    dragImage         = di;
    dragImageOffset   = p;

    Transferable transferable  = getDragSourceContext().getTransferable();
    SortedMap<Long,DataFlavor> formatMap = DataTransferer.getInstance().
        getFormatsForTransferable(transferable, DataTransferer.adaptFlavorMap
            (getTrigger().getDragSource().getFlavorMap()));
    long[] formats = DataTransferer.getInstance().
        keysToLongArray(formatMap);
    startDrag(transferable, formats, formatMap);

    /*
     * Fix for 4613903.
     * Filter out all mouse events that are currently on the event queue.
     */
    discardingMouseEvents = true;
    EventQueue.invokeLater(new Runnable() {
            public void run() {
                discardingMouseEvents = false;
            }
        });
}
 
Example 28
Project: VASSAL-src   File: FreeRotator.java   View source code 5 votes vote down vote up
private Point getGhostPosition() {
  final AffineTransform t =
    AffineTransform.getRotateInstance(-PI_180 * (tempAngle - getAngle()),
                                      pivot.x + centerX(),
                                      pivot.y + centerY());
  final Point2D newPos2D =
    new Point2D.Float(getPosition().x, getPosition().y);
  t.transform(newPos2D, newPos2D);
  return new Point((int) Math.round(newPos2D.getX()),
                   (int) Math.round(newPos2D.getY()));
}
 
Example 29
Project: incubator-netbeans   File: FileCompletionPopup.java   View source code 5 votes vote down vote up
public void mouseDragged(MouseEvent e) {
    if (e.getSource() == list) {
        return;
    }
    if ( isVisible() ) {
        MouseEvent newEvent = convertMouseEvent( e );
        Rectangle r = new Rectangle();
        list.computeVisibleRect( r );
        Point location =  newEvent.getPoint();
        int index = list.locationToIndex(location);
        if ( r.contains( location ) ) {
            list.setSelectedIndex(index);
        }
    }
}
 
Example 30
Project: incubator-netbeans   File: CheckListener.java   View source code 5 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
 
Example 31
Project: Tarski   File: JTableRenderer.java   View source code 5 votes vote down vote up
public void dragOver(DropTargetDragEvent e)
{
	if (!((mxGraphTransferHandler) graphContainer.getTransferHandler())
			.isLocalDrag()
			&& JTableRenderer.this != dragSource)
	{
		Point p = e.getLocation();
		int row = rowAtPoint(p);
		getSelectionModel().setSelectionInterval(row, row);
	}
}
 
Example 32
Project: MaxSim   File: CfgScene.java   View source code 5 votes vote down vote up
private void centerSelection() {
    Point sceneCenter = null;
    Collection<CfgNode> nodes = this.selectedNodes;
    if (nodes.size() == 0) {
        nodes = this.getNodes();
    }

    for (CfgNode n : nodes) {
        if (sceneCenter == null) {
            sceneCenter = this.findWidget(n).getLocation();
            continue;
        }
        Point location = this.findWidget(n).getLocation();
        sceneCenter.x = (location.x + sceneCenter.x) / 2;
        sceneCenter.y = (location.y + sceneCenter.y) / 2;
    }

    JComponent view = this.getView();
    if (view != null) {
        Rectangle viewBounds = view.getVisibleRect();

        Point viewCenter = this.convertSceneToView(sceneCenter);

        view.scrollRectToVisible(new Rectangle(
                viewCenter.x - viewBounds.width / 2,
                viewCenter.y - viewBounds.height / 2,
                viewBounds.width,
                viewBounds.height));
    }
}
 
Example 33
Project: incubator-netbeans   File: PropertyPanelInDialogTest.java   View source code 5 votes vote down vote up
private void clickOn(final PropertyPanel ren) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            Point toClick = new Point(5,5);
            Component target=ren.getComponentAt(toClick);
            MouseEvent me = new MouseEvent(target, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, toClick.x, toClick.y, 2, false);
            target.dispatchEvent(me);
        }
    });
    sleep();
}
 
Example 34
Project: VASSAL-src   File: Map.java   View source code 5 votes vote down vote up
/**
 * Return the name of the deck whose position is p
 *
 * @param p
 * @return
 */
public String getDeckNameAt(Point p) {
  String deck = null;
  if (p != null) {
    for (DrawPile d : getComponentsOf(DrawPile.class)) {
      if (d.getPosition().equals(p)) {
        deck = d.getConfigureName();
        break;
      }
    }
  }
  return deck;
}
 
Example 35
Project: rapidminer   File: ListPropertyTable.java   View source code 5 votes vote down vote up
/** This method ensures that the correct tool tip for the current table cell is delivered. */
@Override
public String getToolTipText(MouseEvent e) {
	Point p = e.getPoint();
	int column = columnAtPoint(p);
	if (column == 0) {
		return keyToolTip;
	} else {
		return super.getToolTipText(e);
	}
}
 
Example 36
Project: VASSAL-src   File: MapBoard.java   View source code 5 votes vote down vote up
/**
 * Move the upper left and lower-right points to just within the map board.
 */
void constrainRectangle(Point upperLeft, Point lowerRight) {
  if (upperLeft.x < 0)
    upperLeft.x = 0;
  if (upperLeft.y < 0)
    upperLeft.y = 0;
  Dimension d = getBoardSize();

  if (lowerRight.x >= d.width)
    lowerRight.x = d.width-1;
  if (lowerRight.y >= d.height)
    lowerRight.y = d.height-1;
}
 
Example 37
Project: openjdk-jdk10   File: IntegerInterleavedRaster.java   View source code 5 votes vote down vote up
/**
 * Creates a subraster given a region of the raster.  The x and y
 * coordinates specify the horizontal and vertical offsets
 * from the upper-left corner of this raster to the upper-left corner
 * of the subraster.  A subset of the bands of the parent Raster may
 * be specified.  If this is null, then all the bands are present in the
 * subRaster. A translation to the subRaster may also be specified.
 * Note that the subraster will reference the same
 * DataBuffer as the parent raster, but using different offsets.
 * @param x               X offset.
 * @param y               Y offset.
 * @param width           Width (in pixels) of the subraster.
 * @param height          Height (in pixels) of the subraster.
 * @param x0              Translated X origin of the subraster.
 * @param y0              Translated Y origin of the subraster.
 * @param bandList        Array of band indices.
 * @exception RasterFormatException
 *            if the specified bounding box is outside of the parent raster.
 */
public WritableRaster createWritableChild (int x, int y,
                                           int width, int height,
                                           int x0, int y0,
                                           int bandList[]) {
    if (x < this.minX) {
        throw new RasterFormatException("x lies outside raster");
    }
    if (y < this.minY) {
        throw new RasterFormatException("y lies outside raster");
    }
    if ((x+width < x) || (x+width > this.minX + this.width)) {
        throw new RasterFormatException("(x + width) is outside raster");
    }
    if ((y+height < y) || (y+height > this.minY + this.height)) {
        throw new RasterFormatException("(y + height) is outside raster");
    }

    SampleModel sm;

    if (bandList != null)
        sm = sampleModel.createSubsetSampleModel(bandList);
    else
        sm = sampleModel;

    int deltaX = x0 - x;
    int deltaY = y0 - y;

    return new IntegerInterleavedRaster(sm,
                                      (DataBufferInt) dataBuffer,
                                      new Rectangle(x0,y0,width,height),
                                      new Point(sampleModelTranslateX+deltaX,
                                                sampleModelTranslateY+deltaY),
                                      this);
}
 
Example 38
Project: incubator-netbeans   File: DefaultTabbedContainerUI.java   View source code 5 votes vote down vote up
public Polygon getInsertTabIndication(int idx) {
    Polygon result = tabDisplayer.getUI().getInsertTabIndication(idx);
    scratchPoint.setLocation(0,0);
    Point p = SwingUtilities.convertPoint(tabDisplayer, scratchPoint, container);
    result.translate (-p.x, -p.y);
    return appendContentBoundsTo(result);
}
 
Example 39
Project: openjdk-jdk10   File: JTableOperator.java   View source code 5 votes vote down vote up
/**
 * Maps {@code JTable.rowAtPoint(Point)} through queue
 */
public int rowAtPoint(final Point point) {
    return (runMapping(new MapIntegerAction("rowAtPoint") {
        @Override
        public int map() {
            return ((JTable) getSource()).rowAtPoint(point);
        }
    }));
}
 
Example 40
Project: poe-ladder-tracker-java   File: GUILadderTracker.java   View source code 5 votes vote down vote up
public void mouseDragged(MouseEvent e){
	if(rightMouseButtonPressed){
  Point currCoords = e.getLocationOnScreen();
  windowLadderTracker.setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y);
  prefs.put("LadderTrackerLocationX", Integer.toString(currCoords.x - mouseDownCompCoords.x));
  prefs.put("LadderTrackerLocationY", Integer.toString(currCoords.y - mouseDownCompCoords.y));
	}
}