Пример #1
0
  /**
   * Override the pain method do draw the axis lines
   *
   * @param g The graphics to paint to
   */
  public void paint(Graphics g) {
    Rectangle b = getBounds();
    g.setColor(canvasBg);
    g.fillRect(0, 0, b.width, b.height);
    paintGrid(g);

    Point center = getCenter();
    if (g instanceof Graphics2D) {
      ((Graphics2D) g).translate(center.x, center.y);
    }
    super.paint(g);
    if (g instanceof Graphics2D) {
      ((Graphics2D) g).scale(1.0, 1.0);
    }
    g.setColor(Color.gray);
    g.drawLine(0, -10 * b.height, 0, 10 * b.height);
    g.drawLine(-10 * b.width, 0, 10 * b.width, 0);

    MetSymbol tmp = highlightedMetSymbol;
    if (tmp != null) {
      Rectangle tb = tmp.getBounds();
      g.setColor(Color.red);
      g.drawRect(tb.x - 2, tb.y - 2, tb.width + 4, tb.height + 4);
    }
  }
Пример #2
0
  /**
   * initialize the symbols menu
   *
   * @param m menu
   */
  public void initSymbolsMenu(JMenu m) {
    m.removeAll();
    for (int i = 0; i < glyphs.size(); i++) {
      final MetSymbol metSymbol = (MetSymbol) glyphs.get(i);
      JMenuItem mi = GuiUtils.makeMenuItem(metSymbol.getLabel(), this, "showProperties", metSymbol);
      mi.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              highlightedMetSymbol = null;
              StationModelCanvas.this.repaint();
            }

            public void mouseReleased(MouseEvent e) {
              highlightedMetSymbol = null;
              StationModelCanvas.this.repaint();
            }

            public void mouseEntered(MouseEvent e) {
              highlightedMetSymbol = metSymbol;
              StationModelCanvas.this.repaint();
            }

            public void mouseExited(MouseEvent e) {
              highlightedMetSymbol = null;
              StationModelCanvas.this.repaint();
            }
          });
      m.add(mi);
    }
  }
Пример #3
0
 /**
  * Show the properties dialog for the given symbol.
  *
  * @param metSymbol The symbol.
  */
 public void showProperties(MetSymbol metSymbol) {
   metSymbol.showPropertiesDialog(this);
   repaint();
 }
Пример #4
0
  /**
   * Make menu items for the given glyph
   *
   * @param metSymbol The glyph
   * @param l List ot put items in
   * @param forPopup Is this for a popup menu
   * @return The list
   */
  protected List doMakeMetSymbolMenu(final MetSymbol metSymbol, List l, boolean forPopup) {
    if (l == null) {
      l = new ArrayList();
    }
    JMenuItem mi;
    if (!forPopup) {
      l = super.doMakeMenuItems(metSymbol, l);
    }

    l.add(mi = new JMenuItem(metSymbol.getActive() ? "Hide" : "Show"));
    mi.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            metSymbol.setActive(!metSymbol.getActive());
          }
        });

    if (metSymbol.doAlignmentMenu()) {
      JMenu rectPtMenu =
          new JMenu("Alignment Point (" + Glyph.getRectPointName(metSymbol.getRectPoint()) + ")");
      l.add(rectPtMenu);
      for (int i = 0; i < Glyph.RECTPOINTNAMES.length; i++) {
        rectPtMenu.add(mi = new JMenuItem(Glyph.RECTPOINTNAMES[i]));
        mi.addActionListener(
            new ObjectListener(Glyph.RECTPOINTS[i]) {
              public void actionPerformed(ActionEvent ae) {
                metSymbol.setRectPoint(theObject.toString());
                setHaveChanged(true);
                repaint();
              }
            });
      }
    }

    JMenu alignMenu = new JMenu("Center");
    l.add(alignMenu);

    alignMenu.add(mi = new JMenuItem("Center"));
    mi.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            Rectangle b = metSymbol.getBounds();
            Point2D rp = Glyph.getPointOnRect(metSymbol.getRectPoint(), b);
            metSymbol.moveBy((int) -(rp.getX()), (int) -(rp.getY()));
            repaint();
            setHaveChanged(true);
          }
        });

    alignMenu.add(mi = new JMenuItem("Center Vertically"));
    mi.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            Rectangle b = metSymbol.getBounds();
            Point2D rp = Glyph.getPointOnRect(metSymbol.getRectPoint(), b);
            metSymbol.moveBy(0, (int) -(rp.getY()));
            repaint();
            setHaveChanged(true);
          }
        });
    alignMenu.add(mi = new JMenuItem("Center Horizontally"));
    mi.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            Rectangle b = metSymbol.getBounds();
            Point2D rp = Glyph.getPointOnRect(metSymbol.getRectPoint(), b);
            metSymbol.moveBy((int) -(rp.getX()), 0);
            repaint();
            setHaveChanged(true);
          }
        });

    if (forPopup) {
      l.add(GuiUtils.MENU_SEPARATOR);
      l.add(mi = new JMenuItem("Properties..."));
      mi.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              showProperties(metSymbol);
            }
          });
    }

    return l;
  }
Пример #5
0
 /**
  * Initialize the new glyph from the given xml node. Only do this if the glyph is a MetSymbol
  *
  * @param g The new glyph
  * @param symbolNode The xml it was created from
  */
 protected void initializeGlyphFromXml(Glyph g, Element symbolNode) {
   if (!(g instanceof MetSymbol)) {
     return;
   }
   ((MetSymbol) g).initialize(symbolNode);
 }
Пример #6
0
 /** Close any open property dialogs */
 protected void closeDialogs() {
   for (int i = 0; i < glyphs.size(); i++) {
     MetSymbol metSymbol = (MetSymbol) glyphs.get(i);
     metSymbol.closePropertiesDialog();
   }
 }