gt:         m_x += dX;
context: /*
  * File Shape.java
  *
  * Copyright (C) 2010 Remco Bouckaert remco@cs.auckland.ac.nz
  *
  * This file is part of BEAST2.
  * See the NOTICE file distributed with this work for additional
  * information regarding copyright ownership and licensing.
  *
  * BEAST is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
  *
  *  BEAST is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with BEAST; if not, write to the
  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  * Boston, MA  02110-1301  USA
  */
  package yabby.app.draw;
  
  import java.awt.Color;
  import java.awt.Cursor;
  import java.awt.Font;
  import java.awt.FontMetrics;
  import java.awt.Graphics2D;
  
  import java.awt.Rectangle;
  import java.io.PrintStream;
  import java.util.List;
  import java.util.ArrayList;
  
  import javax.swing.JPanel;
  
  import org.w3c.dom.Node;
  
  abstract public class Shape {
      int m_x = 0;
      int m_y = 0;
      int m_w = 1;
      int m_h = 1;
  
      int m_nPenWidth = 1;
      boolean m_bFilled = true;
      Color m_fillcolor = DEFUALT_FILL_COLOR;
      Color m_pencolor = DEFUALT_PEN_COLOR;
  
      public boolean m_bNeedsDrawing = true;
  
      final static Color DEFUALT_FILL_COLOR = new Color(128, 128, 128);
      final static Color DEFUALT_PEN_COLOR = new Color(0, 0, 0);
      String m_sID;
  
      Document m_doc;
      
      String getID() {
          return m_sID;
      }
  
      public Shape() {
      }
  
      public Shape(Node node, Document doc) {
      	m_doc = doc;
      }
  
      public void draw(Graphics2D g, JPanel panel) {
      }
  
      void drawLabel(Graphics2D g) {
          if (getLabel() != null) {
              FontMetrics fm = g.getFontMetrics(g.getFont());
              String sLabel = getLabel();
              if (m_doc != null && m_doc.sanitiseIDs()) {
              	if (sLabel.contains(".")) {
              		sLabel = sLabel.substring(0, sLabel.indexOf('.'));
              	}
              }
              int i = 0;
              while (sLabel.indexOf('\n') >= 0) {
                  String sStr = sLabel.substring(0, sLabel.indexOf('\n'));
                  g.drawString(sStr, m_x + m_w / 2 - fm.stringWidth(sStr) / 2, m_y + m_h / 2 + i * fm.getHeight());
                  sLabel = sLabel.substring(sStr.length() + 1);
                  i++;
              }
              g.drawString(sLabel, m_x + m_w / 2 - fm.stringWidth(sLabel) / 2, m_y + m_h / 2 + i * fm.getHeight());
          }
      } // drawLabel
  
      List<TrackPoint> getTracker() {
          List<TrackPoint> tracker = new ArrayList<TrackPoint>(8);
          tracker.add(new TrackPoint(m_x, m_y, Cursor.NW_RESIZE_CURSOR));
          tracker.add(new TrackPoint(m_x + m_w, m_y, Cursor.NE_RESIZE_CURSOR));
          tracker.add(new TrackPoint(m_x, m_y + m_h, Cursor.SW_RESIZE_CURSOR));
          tracker.add(new TrackPoint(m_x + m_w, m_y + m_h, Cursor.SE_RESIZE_CURSOR));
  
          tracker.add(new TrackPoint(m_x, m_y + m_h / 2, Cursor.W_RESIZE_CURSOR));
          tracker.add(new TrackPoint(m_x + m_w, m_y + m_h / 2, Cursor.E_RESIZE_CURSOR));
          tracker.add(new TrackPoint(m_x + m_w / 2, m_y, Cursor.N_RESIZE_CURSOR));
          tracker.add(new TrackPoint(m_x + m_w / 2, m_y + m_h, Cursor.S_RESIZE_CURSOR));
          return tracker;
      }
  
      void parse(Node node, Document doc, boolean bReconstructPlugins) {
          if (node.getAttributes().getNamedItem("id") != null) {
              m_sID = node.getAttributes().getNamedItem("id").getNodeValue();
          }
          if (node.getAttributes().getNamedItem("x") != null) {
              m_x = (new Integer(node.getAttributes().getNamedItem("x").getNodeValue())).intValue();
              m_x += 400;
          }
          if (node.getAttributes().getNamedItem("y") != null) {
              m_y = (new Integer(node.getAttributes().getNamedItem("y").getNodeValue())).intValue();
              if (node.getAttributes().getNamedItem("h") != null) {
                  m_h = (new Integer(node.getAttributes().getNamedItem("h").getNodeValue())).intValue();
              }
              m_y = 550 - m_y - m_h;
          }
          if (node.getAttributes().getNamedItem("w") != null) {
              m_w = (new Integer(node.getAttributes().getNamedItem("w").getNodeValue())).intValue();
          }
          if (node.getAttributes().getNamedItem("penwidth") != null) {
              m_nPenWidth = (new Integer(node.getAttributes().getNamedItem("penwidth").getNodeValue())).intValue();
          }
          if (node.getAttributes().getNamedItem("fillcolor") != null) {
              m_fillcolor = string2Color(node.getAttributes().getNamedItem("fillcolor").getNodeValue());
          }
          if (node.getAttributes().getNamedItem("pencolor") != null) {
              m_pencolor = string2Color(node.getAttributes().getNamedItem("pencolor").getNodeValue());
          }
          if (node.getAttributes().getNamedItem("filled") != null) {
              m_bFilled = !node.getAttributes().getNamedItem("filled").getNodeValue().equals("no");
          }
      }
  
      String XMLnormalizeAtt(String sStr) {
          StringBuffer sStr2 = new StringBuffer();
          for (int iStr = 0; iStr < sStr.length(); iStr++) {
              switch (sStr.charAt(iStr)) {
                  case '<':
                      sStr2.append("&lt;");
                      break;
                  case '>':
                      sStr2.append("&gt;");
                      break;
                  case '\"':
                      sStr2.append("&quot;");
                      break;
                  case '\'':
                      sStr2.append("&apos;");
                      break;
                  case '&':
                      sStr2.append("&amp;");
                      break;
                  case 13:
                      break;
                  case '\n':
                      sStr2.append("&#xD;&#xA;");
                      break;
                  default:
                      sStr2.append(sStr.charAt(iStr));
              }
          }
          return sStr2.toString();
      } // XMLnormalizeAtt
  
      String getAtts() {
          return " id='" + getID() + "'" +
                  " x='" + (m_x - 400) + "'" +
                  " y='" + (550 - m_y - m_h) + "'" +
                  " w='" + m_w + "'" +
                  " h='" + m_h + "'" +
                  (m_nPenWidth != 1 ? " penwidth='" + m_nPenWidth + "'" : "") +
                  (!m_bFilled ? " filled='no'" : "") +
                  (m_fillcolor.equals(DEFUALT_FILL_COLOR) ? "" : " fillcolor='" + m_fillcolor.getRed() + " " + m_fillcolor.getGreen() + " " + m_fillcolor.getBlue() + "'") +
                  (m_pencolor.equals(DEFUALT_PEN_COLOR) ? "" : " pencolor='" + m_pencolor.getRed() + " " + m_pencolor.getGreen() + " " + m_pencolor.getBlue() + "'")
                  ;
      }
  
      void assignFrom(Shape other) {
          m_x = other.m_x;
          m_y = other.m_y;
          m_w = other.m_w;
          m_h = other.m_h;
          m_nPenWidth = other.m_nPenWidth;
          m_bFilled = other.m_bFilled;
          m_fillcolor = other.m_fillcolor;
          m_pencolor = other.m_pencolor;
      }
  
      Color string2Color(String sColor) {
          int iSpace = sColor.indexOf(' ');
          if (iSpace < 0) {
              return new Color(128, 128, 128);
          }
          int iStart = 0;
          String sR = sColor.substring(iStart, iSpace);
          int r = (new Integer(sR)).intValue();
          iStart = iSpace + 1;
          iSpace = sColor.indexOf(' ', iStart);
          if (iSpace < 0) {
              return new Color(128, 128, 128);
          }
          String sG = sColor.substring(iStart, iSpace);
          int g = (new Integer(sG)).intValue();
          iStart = iSpace + 1;
          iSpace = sColor.indexOf(' ', iStart);
          if (iSpace < 0) {
              iSpace = sColor.length();
          }
          String sB = sColor.substring(iStart, iSpace);
          int b = (new Integer(sB)).intValue();
          return new Color(r, g, b);
      } // string2Color
  
      public String getXML() {
          return "<shape" + getAtts() + "/>";
      }
  
      boolean intersects(int nX, int nY) {
          return (nX >= m_x - 1 && nX <= m_x + m_w + 1 && nY >= m_y - 1 && nY <= m_y + m_h + 1);
      }
  
      boolean intersects(Rectangle rect) {
          return rect.intersects(m_x - 1, m_y - 1, m_w + 2, m_h + 2);
      }
  //	boolean intersects(int nX, int nY) {
  //		return false;
  //	}
  //	boolean intersects(Rectangle rect) {
  //		return false;
  //	}
  
      int offsetX(int nX) {
          return nX - m_x;
      }
  
      int offsetY(int nY) {
          return nY - m_y;
      }
  
      void offset(int dX, int dY) {
  