PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/rococoa/rococoa-core/src/main/java/org/rococoa/cocoa/foundation/NSRect.java

http://rococoa.googlecode.com/
Java | 62 lines | 31 code | 10 blank | 21 comment | 0 complexity | 59480780784ab729c880d1521ca03b10 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. /*
  2. * Copyright 2007, 2008 Duncan McGregor
  3. *
  4. * This file is part of Rococoa, a library to allow Java to talk to Cocoa.
  5. *
  6. * Rococoa is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Rococoa is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Rococoa. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.rococoa.cocoa.foundation;
  20. import java.awt.geom.Dimension2D;
  21. import java.awt.geom.Point2D;
  22. import java.awt.geom.Rectangle2D;
  23. import com.sun.jna.Structure;
  24. /**
  25. * @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
  26. */
  27. public class NSRect extends Structure implements Structure.ByValue {
  28. public NSPoint origin;
  29. public NSSize size;
  30. public NSRect() {
  31. this(new NSPoint(0, 0), new NSSize());
  32. }
  33. public NSRect(NSPoint origin, NSSize size) {
  34. this.origin = origin;
  35. this.size = size;
  36. }
  37. public NSRect(Point2D origin, Dimension2D size) {
  38. this.origin = new NSPoint(origin);
  39. this.size = new NSSize(size);
  40. }
  41. public NSRect(Rectangle2D rect) {
  42. this.origin = new NSPoint(rect.getX(), rect.getY());
  43. this.size = new NSSize(rect.getWidth(), rect.getHeight());
  44. }
  45. public NSRect(double w, double h) {
  46. this.origin = new NSPoint(0, 0);
  47. this.size = new NSSize(w, h);
  48. }
  49. public Rectangle2D getBounds() {
  50. return new Rectangle2D.Double(origin.x.doubleValue(), origin.y.doubleValue(), size.width.doubleValue(), size.height.doubleValue());
  51. }
  52. }