示例#1
0
 /**
  * Make the edit menu
  *
  * @param editMenu edit menu
  * @return edit menu
  */
 public JMenu makeEditMenu(JMenu editMenu) {
   editMenu.add(GuiUtils.makeDynamicMenu("Symbols", this, "initSymbolsMenu"));
   editMenu.add(
       GuiUtils.makeMenuItem("Set properties on selected", this, "setPropertiesOnSelected"));
   editMenu.addSeparator();
   return super.makeEditMenu(editMenu);
 }
示例#2
0
  /**
   * _more_
   *
   * @param symbols _more_
   * @param listener _more_
   * @param smm _more_
   * @return _more_
   */
  public static List makeStationModelMenuItems(
      List symbols, final ObjectListener listener, StationModelManager smm) {
    List items = new ArrayList();
    List subMenus = new ArrayList();
    Hashtable categories = new Hashtable();
    for (int i = 0; i < symbols.size(); i++) {
      StationModel sm = (StationModel) symbols.get(i);
      boolean isUsers = smm.isUsers(sm);
      String name = sm.getName();
      if (name.equals("")) continue;
      List toks = StringUtil.split(name, ">", true, true);
      if (toks.size() > 0) {
        name = (String) toks.get(toks.size() - 1);
      }
      JMenuItem item = new JMenuItem(GuiUtils.getLocalName(name, isUsers));
      item.addActionListener(
          new ObjectListener(sm) {
            public void actionPerformed(ActionEvent ae) {
              listener.setObject(this.theObject);
              listener.actionPerformed(ae);
            }
          });

      toks.remove(toks.size() - 1);
      if (toks.size() == 0) {
        items.add(item);
        continue;
      }
      JMenu categoryMenu = null;
      String catSoFar = "";
      String menuCategory = "";
      for (int catIdx = 0; catIdx < toks.size(); catIdx++) {
        String subCat = (String) toks.get(catIdx);
        catSoFar = catSoFar + "/" + subCat;
        JMenu m = (JMenu) categories.get(catSoFar);
        if (m == null) {
          m = new JMenu(subCat);
          menuCategory = catSoFar;
          categories.put(catSoFar, m);
          if (categoryMenu != null) {
            categoryMenu.add(m, 0);
          } else {
            subMenus.add(m);
          }
        }
        categoryMenu = m;
      }
      if (categoryMenu == null) {
        categoryMenu = new JMenu("");
        categories.put(toks.toString(), categoryMenu);
        subMenus.add(categoryMenu);
        menuCategory = toks.toString();
      }
      categoryMenu.add(item);
    }
    items.addAll(subMenus);
    return items;
  }
示例#3
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);
    }
  }
示例#4
0
  void initControls() {
    JMenuItem jmi;

    jmi = new JMenuItem("JImage Menu");
    jmi.setEnabled(false);
    popupMenu.add(jmi);

    jmi = new JMenuItem("Fit");
    jmi.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fit = true;
            repaint();
          }
        });
    popupMenu.add(jmi);

    JMenu scaleMenu = new JMenu("Set Scale");
    popupMenu.add(scaleMenu);
    int scales[] = new int[] {25, 50, 100, 200, 400, 800};

    for (int i = 0; i < scales.length; i++) {
      jmi = new JMenuItem(scales[i] + " %");
      jmi.addActionListener(new ScaleAction(scales[i]));
      scaleMenu.add(jmi);
    }

    MyListener l = new MyListener();
    addMouseMotionListener(l);
    addMouseListener(l);
    addMouseWheelListener(l);
    addKeyListener(l);
  }
示例#5
0
  /**
   * Make the view menu
   *
   * @param viewMenu view menu
   * @return The view menu
   */
  public JMenu makeViewMenu(JMenu viewMenu) {
    showAlignmentPointsMI = new JCheckBoxMenuItem("Show Alignment Points", true);
    viewMenu.add(showAlignmentPointsMI);
    showAlignmentPointsMI.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            repaint();
          }
        });

    viewMenu.addSeparator();
    super.makeViewMenu(viewMenu);
    viewMenu.addSeparator();
    viewMenu.add(makeMenuItem("Black background", CMD_BLACKBG));
    viewMenu.add(makeMenuItem("White background", CMD_WHITEBG));
    return viewMenu;
  }
示例#6
0
 // create the menu bar (changed to private)
 private static JMenuBar createMenuBar() {
   JMenuBar menuBar = new JMenuBar();
   JMenu menu = new JMenu("File");
   menuBar.add(menu);
   JMenuItem saveItem = new JMenuItem(" Save...   ");
   saveItem.addActionListener(std);
   saveItem.setAccelerator(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
   menu.add(saveItem);
   return menuBar;
 }
示例#7
0
  public SPanel(JFrame sframe) {
    balls = new Ball[B_WIDTH][B_HEIGHT];
    setBackground(Color.black);

    JMenuBar mb = new JMenuBar();
    sframe.setJMenuBar(mb);
    JMenu smenu = new JMenu("File");
    mb.add(smenu);
    smenu.setMnemonic('F');

    newgame = smenu.add("New Game");
    newgame.setMnemonic('N');
    smenu.addSeparator();
    quitgame = smenu.add("Quit Game");
    quitgame.setMnemonic('Q');
    ButtonHandler b = new ButtonHandler();
    quitgame.addActionListener(b);
    newgame.addActionListener(b);
    resetBoard();

    addMouseListener(new MouseHandler());
    addMouseMotionListener(new MouseMotionHandler());
  }
示例#8
0
 /** Make the file menu */
 private void makeFileMenu() {
   fileMenu.removeAll();
   fileMenu.add(makeMenuItem("New", 'n', GuiUtils.CMD_NEW));
   fileMenu.addSeparator();
   fileMenu.add(makeMenuItem("Save", 's', GuiUtils.CMD_SAVE));
   fileMenu.add(makeMenuItem("Save As...", GuiUtils.CMD_SAVEAS));
   fileMenu.add(makeMenuItem("Rename...", GuiUtils.CMD_RENAME));
   fileMenu.addSeparator();
   JMenuItem removeMenuItem = makeMenuItem("Remove", GuiUtils.CMD_REMOVE);
   removeMenuItem.setEnabled(smm.isUsers(stationModel));
   fileMenu.add(removeMenuItem);
   fileMenu.addSeparator();
   fileMenu.add(makeMenuItem("Import...", GuiUtils.CMD_IMPORT));
   fileMenu.add(makeMenuItem("Export...", GuiUtils.CMD_EXPORT));
   fileMenu.addSeparator();
   fileMenu.add(makeMenuItem("Close", GuiUtils.CMD_CLOSE));
 }
示例#9
0
  /**
   * Add the menus into the menu bar
   *
   * @param menuBar The menu bar
   */
  public void initMenuBar(JMenuBar menuBar) {
    stationModelMenu = new JMenu("Layout Models");
    stationModelMenu.addMenuListener(
        new MenuListener() {
          public void menuCanceled(MenuEvent e) {}

          public void menuDeselected(MenuEvent e) {}

          public void menuSelected(MenuEvent e) {
            makeStationModelMenu();
          }
        });

    fileMenu = new JMenu("File");
    fileMenu.addMenuListener(
        new MenuListener() {
          public void menuCanceled(MenuEvent e) {}

          public void menuDeselected(MenuEvent e) {}

          public void menuSelected(MenuEvent e) {
            makeFileMenu();
          }
        });

    menuBar.add(fileMenu);
    super.initMenuBar(menuBar);

    menuBar.add(stationModelMenu);

    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Layout Models");
    helpMenu.add(helpMenuItem);
    helpMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            showHelp();
          }
        });

    menuBar.add(helpMenu);
  }
  public ImageProcessingFrame() {
    setTitle("ImageProcessingTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    add(
        new JComponent() {
          public void paintComponent(Graphics g) {
            if (image != null) g.drawImage(image, 0, 0, null);
          }
        });

    JMenu fileMenu = new JMenu("File");
    JMenuItem openItem = new JMenuItem("Open");
    openItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            openFile();
          }
        });
    fileMenu.add(openItem);

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });
    fileMenu.add(exitItem);

    JMenu editMenu = new JMenu("Edit");
    JMenuItem blurItem = new JMenuItem("Blur");
    blurItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            float weight = 1.0f / 9.0f;
            float[] elements = new float[9];
            for (int i = 0; i < 9; i++) elements[i] = weight;
            convolve(elements);
          }
        });
    editMenu.add(blurItem);

    JMenuItem sharpenItem = new JMenuItem("Sharpen");
    sharpenItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            float[] elements = {0.0f, -1.0f, 0.0f, -1.0f, 5.f, -1.0f, 0.0f, -1.0f, 0.0f};
            convolve(elements);
          }
        });
    editMenu.add(sharpenItem);

    JMenuItem brightenItem = new JMenuItem("Brighten");
    brightenItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            float a = 1.1f;
            // float b = 20.0f;
            float b = 0;
            RescaleOp op = new RescaleOp(a, b, null);
            filter(op);
          }
        });
    editMenu.add(brightenItem);

    JMenuItem edgeDetectItem = new JMenuItem("Edge detect");
    edgeDetectItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            float[] elements = {0.0f, -1.0f, 0.0f, -1.0f, 4.f, -1.0f, 0.0f, -1.0f, 0.0f};
            convolve(elements);
          }
        });
    editMenu.add(edgeDetectItem);

    JMenuItem negativeItem = new JMenuItem("Negative");
    negativeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            short[] negative = new short[256 * 1];
            for (int i = 0; i < 256; i++) negative[i] = (short) (255 - i);
            ShortLookupTable table = new ShortLookupTable(0, negative);
            LookupOp op = new LookupOp(table, null);
            filter(op);
          }
        });
    editMenu.add(negativeItem);

    JMenuItem rotateItem = new JMenuItem("Rotate");
    rotateItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            if (image == null) return;
            AffineTransform transform =
                AffineTransform.getRotateInstance(
                    Math.toRadians(5), image.getWidth() / 2, image.getHeight() / 2);
            AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);
            filter(op);
          }
        });
    editMenu.add(rotateItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    setJMenuBar(menuBar);
  }
示例#11
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;
  }
示例#12
0
  /**
   * Set up a menu and tool bar
   *
   * @param pane panel to add toolbar to
   * @param ftree file tree display
   */
  private JMenuBar makeMenuBar(JPanel pane, final FileTree ftree) {
    JMenuBar mBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    mBar.add(fileMenu);

    JMenuItem fileMenuGoto = new JMenuItem("Go to Directory ...");
    fileMenuGoto.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String dir = ftree.getRoot().getAbsolutePath();
            String newDir = JOptionPane.showInputDialog(FileManager.this, "Go to Directory:", dir);

            if (newDir == null) return;

            newDir = newDir.trim();
            File newDirFile = new File(newDir);

            if (newDirFile.exists() && newDirFile.canRead() && !newDir.equals(dir))
              ftree.newRoot(newDir);
            else {
              String error = null;
              if (!newDirFile.exists()) error = new String(newDir + " doesn't exist!");
              else if (!newDirFile.canRead()) error = new String(newDir + " cannot be read!");
              else if (newDir.equals(dir)) error = new String("Same directory!");

              if (error != null)
                JOptionPane.showMessageDialog(
                    FileManager.this, error, "Warning", JOptionPane.WARNING_MESSAGE);
            }
          }
        });
    fileMenu.add(fileMenuGoto);
    fileMenu.add(new JSeparator());

    JMenuItem fileMenuClose = new JMenuItem("Close");
    fileMenuClose.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setVisible(false);
          }
        });
    fileMenu.add(fileMenuClose);

    // tool bar set up
    JToolBar toolBar = new JToolBar();
    Dimension buttonSize = new Dimension(22, 24);

    JButton upBt =
        new JButton() {
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;

            g2.setColor(new Color(0, 128, 0));
            float loc1[][] = {{11, 18}, {7, 18}, {7, 14}, {3, 14}, {11, 4}};

            g2.fill(makeShape(loc1));
            g2.setColor(Color.green);

            float loc2[][] = {{11, 18}, {15, 18}, {15, 14}, {19, 14}, {11, 4}};
            g2.fill(makeShape(loc2));

            setSize(22, 24);
          }
        };
    upBt.setPreferredSize(buttonSize);
    upBt.setMinimumSize(buttonSize);

    upBt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            FileManager.this.setCursor(cbusy);
            File root = ftree.getRoot();
            String parent = root.getParent();
            if (parent != null) ftree.newRoot(parent);
            FileManager.this.setCursor(cdone);
          }
        });
    toolBar.add(upBt);

    // yeastpub
    JButton shortCut1 =
        new JButton() {
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            Font font = new Font("Monospaced", Font.BOLD, 14);
            g2.setFont(font);

            g2.setColor(Color.black);
            g2.drawString("Y", 4, 18);
            g2.setColor(Color.red);
            g2.drawString("P", 10, 15);
            setSize(22, 24);
          }
        };
    shortCut1.setPreferredSize(buttonSize);
    shortCut1.setMinimumSize(buttonSize);
    shortCut1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ftree.newRoot("/nfs/disk222/yeastpub");
          }
        });

    if ((new File("/nfs/disk222/yeastpub")).exists()) toolBar.add(shortCut1);

    // pathdata
    JButton shortCut2 =
        new JButton() {
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            Font font = new Font("Monospaced", Font.BOLD, 14);
            g2.setFont(font);

            g2.setColor(Color.black);
            g2.drawString("P", 4, 18);
            g2.setColor(Color.red);
            g2.drawString("D", 10, 15);
            setSize(22, 24);
          }
        };
    shortCut2.setPreferredSize(buttonSize);
    shortCut2.setMinimumSize(buttonSize);
    shortCut2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ftree.newRoot("/nfs/pathdata/");
          }
        });

    if ((new File("/nfs/pathdata/")).exists()) toolBar.add(shortCut2);

    // home button
    JButton homeBt =
        new JButton() {
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;

            g2.setColor(Color.blue);
            float loc1[][] = {{3, 14}, {11, 3}, {19, 14}, {17, 14}, {17, 18}, {5, 18}, {5, 14}};
            g2.fill(makeShape(loc1));

            setSize(22, 24);
          }
        };
    homeBt.setPreferredSize(buttonSize);
    homeBt.setMinimumSize(buttonSize);
    homeBt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ftree.newRoot(System.getProperty("user.home"));
          }
        });
    toolBar.add(homeBt);

    toolBar.add(Box.createVerticalStrut(35));
    pane.add(toolBar, BorderLayout.NORTH);

    return mBar;
  }