Example #1
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(LineSize);
    g2.setColor(ColorFactory.getLineColor());

    for (int i = 0; i < connections.length; ++i) {
      g2.draw(connections[i]);
    }

    if (getLocation().x != location.x || getLocation().y != location.y) {
      // if (getLocation().x != 0 && getLocation().y != 0)
      {
        setLocation(location);
      }
    }
  }
Example #2
0
  public NocMapPanel(JLabel tipLabel, int x, int y, final int viewWidth, final int viewHeight) {
    super();

    int m = Simulator.NumRows;
    int n = Simulator.NumColumns;

    width = n * NodeSize + (n + 1) * NodeSpacing;
    height = m * NodeSize + (m + 1) * NodeSpacing;

    setLayout(null);
    setSize(width, height);
    getSize();
    setLocation(x, y);
    setBackground(ColorFactory.getItemBackcolor());
    setForeground(ColorFactory.getItemForecolor());
    setBorder(new LineBorder(Color.RED));
    location = new Point(-1, -1);
    dragPoint = new Point(-1, -1);

    // add nodes
    nodeListeners = new NodeListener[m * n];
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < n; ++j) {
        JLabel node = new JLabel("N " + (i * m + j + 1), SwingConstants.CENTER);
        node.setBackground(ColorFactory.getWindowBackcolor());
        node.setForeground(ColorFactory.getWindowForecolor());
        node.setBorder(LineBorder.createBlackLineBorder());
        node.setSize(NodeSize, NodeSize);
        node.setLocation(
            NodeSpacing * (j + 1) + NodeSize * j, NodeSpacing * (i + 1) + NodeSize * i);
        /*addMouseMotionListener(nodeListeners[i * m + j] = new NodeListener(this, node, "Node "
        + (i * m + j + 1), tipLabel));*/
        add(node);
      }
    }

    // create connections
    connectionListeners = new LineListener[(m - 1) * n + m * (n - 1)];
    connections = new Line2D[(m - 1) * n + m * (n - 1)];
    int c = 0;

    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < n - 1; ++j) {
        Point pStart =
            new Point(
                NodeSpacing * (j + 1) + NodeSize * (j + 1),
                NodeSpacing * (i + 1) + NodeSize * i + NodeSize / 2);
        Point pEnd =
            new Point(
                NodeSpacing * (j + 2) + NodeSize * (j + 1),
                NodeSpacing * (i + 1) + NodeSize * i + NodeSize / 2);

        connections[c] = new Line2D.Double(pStart, pEnd);
        /*addMouseMotionListener(connectionListeners[c] = new LineListener(this, connections[c], "Link "
        + (j + 1 + i * m) + " to " + (j + 2 + i * m), tipLabel));*/

        c++;
      }
    }

    for (int i = 0; i < m - 1; ++i) {
      for (int j = 0; j < n; ++j) {
        Point pStart =
            new Point(
                NodeSpacing * (j + 1) + NodeSize * (j) + NodeSize / 2,
                NodeSpacing * (i + 1) + NodeSize * (i + 1));
        Point pEnd =
            new Point(
                NodeSpacing * (j + 1) + NodeSize * (j) + NodeSize / 2,
                NodeSpacing * (i + 1) + NodeSize * (i + 2));

        connections[c] = new Line2D.Double(pStart, pEnd);
        /*addMouseMotionListener(connectionListeners[c] = new LineListener(this, connections[c], "Link "
        + (j + 1 + i * m) + " to " + (j + 1 + (i + 1) * m), tipLabel));*/
        c++;
      }
    }

    // drag listener
    addMouseMotionListener(
        new MouseMotionListener() {
          public void mouseMoved(MouseEvent e) {
            /**/
          }

          public void mouseDragged(MouseEvent e) {
            Point p = e.getPoint();
            int dx = 0, dy = 0;
            int x = dragPoint.x;
            int y = dragPoint.y;

            if (location.x <= 0 && (location.x + width) >= viewWidth) {
              if (p.x < x) {
                dx = -1;
              } else if (p.x > x) {
                dx = +1;
              }
            }
            if (location.y <= 0 && (location.y + height) >= viewHeight) {
              if (p.y < y) {
                dy = -1;
              } else if (p.y > y) {
                dy = +1;
              }
            }
            location =
                new Point(
                    Math.max(Math.min(0, location.x + dx * DragRatio), viewWidth - width),
                    Math.max(Math.min(0, location.y + dy * DragRatio), viewHeight - height));
            setLocation(location);
            dragPoint = p;
          }
        });
  }
Example #3
0
 /**
  * Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a
  * color, and convert it to a java.awt.Color.
  *
  * @param p properties
  * @param propName the name of the property
  * @param dfault color to use if the property value doesn't work
  * @return java.awt.Color
  * @see ColorFactory#parseColorFromProperties(Properties, String, String, boolean)
  */
 public static Paint parseColorFromProperties(Properties p, String propName, Paint dfault) {
   return ColorFactory.parseColorFromProperties(p, propName, dfault);
 }
Example #4
0
 /**
  * Convert a string representing a 24/32bit hex color value into a Color value. NOTE:
  *
  * <ul>
  *   <li>Only 24bit (RGB) java.awt.Color is supported on the JDK 1.1 platform.
  *   <li>Both 24/32bit (ARGB) java.awt.Color is supported on the Java 2 platform.
  * </ul>
  *
  * @param colorString the 24/32bit hex string value (ARGB)
  * @return java.awt.Color (24bit RGB on JDK 1.1, 24/32bit ARGB on JDK1.2)
  * @exception NumberFormatException if the specified string cannot be interpreted as a hexidecimal
  *     integer
  * @see ColorFactory#parseColor(String, boolean)
  */
 public static Color parseColor(String colorString) throws NumberFormatException {
   return ColorFactory.parseColor(colorString, false);
 }
Example #5
0
 /**
  * Take a string from a properties file, representing the 24bit RGB or 32bit ARGB hex values for a
  * color, and convert it to a java.awt.Color.
  *
  * @param p properties
  * @param propName the name of the property
  * @param dfault color to use if the property value doesn't work
  * @return java.awt.Color
  * @exception NumberFormatException if the specified string cannot be interpreted as a hexidecimal
  *     integer
  * @see ColorFactory#parseColorFromProperties(Properties, String, String, boolean)
  */
 public static Color parseColorFromProperties(Properties p, String propName, String dfault)
     throws NumberFormatException {
   return ColorFactory.parseColorFromProperties(p, propName, dfault, false);
 }