/** Creates the color menu. */
 protected JMenu createColorMenu(String title, String attribute) {
   CommandMenu menu = new CommandMenu(title);
   for (int i = 0; i < ColorMap.size(); i++)
     menu.add(
         new UndoableCommand(
             new ChangeAttributeCommand(ColorMap.name(i), attribute, ColorMap.color(i), this)));
   return menu;
 }
 /**
  * Creates the fonts menus. It installs all available fonts supported by the toolkit
  * implementation.
  */
 protected JMenu createFontMenu() {
   CommandMenu menu = new CommandMenu("Font");
   String fonts[] = Toolkit.getDefaultToolkit().getFontList();
   for (int i = 0; i < fonts.length; i++) {
     menu.add(
         new UndoableCommand(new ChangeAttributeCommand(fonts[i], "FontName", fonts[i], this)));
   }
   return menu;
 }
 /** Creates the font size menu. */
 protected JMenu createFontSizeMenu() {
   CommandMenu menu = new CommandMenu("Font Size");
   int sizes[] = {9, 10, 12, 14, 18, 24, 36, 48, 72};
   for (int i = 0; i < sizes.length; i++) {
     menu.add(
         new UndoableCommand(
             new ChangeAttributeCommand(
                 Integer.toString(sizes[i]), "FontSize", new Integer(sizes[i]), this)));
   }
   return menu;
 }
 /** Creates the font style menu with entries (Plain, Italic, Bold). */
 protected JMenu createFontStyleMenu() {
   CommandMenu menu = new CommandMenu("Font Style");
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand("Plain", "FontStyle", new Integer(Font.PLAIN), this)));
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand("Italic", "FontStyle", new Integer(Font.ITALIC), this)));
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand("Bold", "FontStyle", new Integer(Font.BOLD), this)));
   return menu;
 }
Example #5
0
 protected JMenu createImagesMenu() {
   CommandMenu menu = new CommandMenu("Images");
   File imagesDirectory = new File(fgSampleImagesPath);
   try {
     String[] list = imagesDirectory.list();
     for (int i = 0; i < list.length; i++) {
       String name = list[i];
       String path = fgSampleImagesResourcePath + name;
       menu.add(new UndoableCommand(new InsertImageCommand(name, path, this)));
     }
   } catch (Exception e) {
   }
   return menu;
 }
 /** Creates the alignment menu. Clients override this method to add additional menu items. */
 protected JMenu createAlignmentMenu() {
   CommandMenu menu = new CommandMenu("Align");
   menu.addCheckItem(new ToggleGridCommand("Toggle Snap to Grid", this, new Point(4, 4)));
   menu.addSeparator();
   menu.add(new UndoableCommand(new AlignCommand(AlignCommand.Alignment.LEFTS, this)));
   menu.add(new UndoableCommand(new AlignCommand(AlignCommand.Alignment.CENTERS, this)));
   menu.add(new UndoableCommand(new AlignCommand(AlignCommand.Alignment.RIGHTS, this)));
   menu.addSeparator();
   menu.add(new UndoableCommand(new AlignCommand(AlignCommand.Alignment.TOPS, this)));
   menu.add(new UndoableCommand(new AlignCommand(AlignCommand.Alignment.MIDDLES, this)));
   menu.add(new UndoableCommand(new AlignCommand(AlignCommand.Alignment.BOTTOMS, this)));
   return menu;
 }
  /** Create a menu which allows the user to select a different look and feel at runtime. */
  public JMenu createLookAndFeelMenu() {
    CommandMenu menu = new CommandMenu("Look'n'Feel");

    UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();

    for (int i = 0; i < lafs.length; i++) {
      final String lnfClassName = lafs[i].getClassName();
      Command cmd =
          new AbstractCommand(lafs[i].getName(), this) {
            public void execute() {
              newLookAndFeel(lnfClassName);
            }
          };
      menu.add(cmd);
    }
    return menu;
  }
Example #8
0
  protected JMenu createAnimationMenu() {
    CommandMenu menu = new CommandMenu("Animation");
    Command cmd =
        new AbstractCommand("Start Animation", this) {
          public void execute() {
            startAnimation();
          }
        };
    menu.add(cmd);

    cmd =
        new AbstractCommand("Stop Animation", this) {
          public void execute() {
            endAnimation();
          }
        };
    menu.add(cmd);
    return menu;
  }
 /** Creates the arrows menu. */
 protected JMenu createArrowMenu() {
   CommandMenu menu = new CommandMenu("Arrow");
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand(
               "none", "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_NONE), this)));
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand(
               "at Start", "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_START), this)));
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand(
               "at End", "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_END), this)));
   menu.add(
       new UndoableCommand(
           new ChangeAttributeCommand(
               "at Both", "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_BOTH), this)));
   return menu;
 }
  /** Creates the debug menu. Clients override this method to add additional menu items. */
  protected JMenu createDebugMenu() {
    CommandMenu menu = new CommandMenu("Debug");

    Command cmd =
        new AbstractCommand("Simple Update", this) {
          public void executable() {
            this.view().setDisplayUpdate(new SimpleUpdateStrategy());
          }
        };
    menu.add(cmd);

    cmd =
        new AbstractCommand("Buffered Update", this) {
          public void executable() {
            this.view().setDisplayUpdate(new BufferedUpdateStrategy());
          }
        };
    menu.add(cmd);
    return menu;
  }
Example #11
0
  protected JMenu createWindowMenu() {
    CommandMenu menu = new CommandMenu("Window");
    Command cmd =
        new AbstractCommand("New View", this) {
          public void execute() {
            newView();
          }
        };
    menu.add(cmd);

    cmd =
        new AbstractCommand("New Window", this, false) {
          public void execute() {
            newWindow(createDrawing());
          }
        };
    menu.add(cmd);

    menu.addSeparator();
    menu.add(new WindowMenu("Window List", (MDIDesktopPane) getDesktop(), this));

    return menu;
  }
  /**
   * Fired by a view when the figure seleciton changes. Since Commands and Tools are Actions and
   * they are registered to hear these events, they will handle themselves. So selection sensitive
   * menuitems will update their own states.
   *
   * @see DrawingEditor
   */
  public void figureSelectionChanged(DrawingView view) {
    JMenuBar mb = getJMenuBar();
    CommandMenu editMenu = (CommandMenu) mb.getMenu(EDIT_MENU);
    // make sure it does exist
    if (editMenu != null) {
      editMenu.checkEnabled();
    }
    CommandMenu alignmentMenu = (CommandMenu) mb.getMenu(ALIGNMENT_MENU);
    // make sure it does exist
    if (alignmentMenu != null) {
      alignmentMenu.checkEnabled();
    }

    JMenu attributeMenu = mb.getMenu(ATTRIBUTES_MENU);
    // make sure it does exist
    if (attributeMenu != null) {
      for (int i = 0; i < attributeMenu.getItemCount(); i++) {
        JMenuItem currentMenu = attributeMenu.getItem(i);
        if (currentMenu instanceof CommandMenu) {
          ((CommandMenu) currentMenu).checkEnabled();
        }
      }
    }
  }
  /** Creates the file menu. Clients override this method to add additional menu items. */
  protected JMenu createFileMenu() {
    CommandMenu menu = new CommandMenu("File");
    Command cmd =
        new AbstractCommand("New", this, false) {
          public void execute() {
            promptNew();
          }
        };
    menu.add(cmd, new MenuShortcut('n'));

    cmd =
        new AbstractCommand("Open...", this, false) {
          public void execute() {
            promptOpen();
          }
        };
    menu.add(cmd, new MenuShortcut('o'));

    cmd =
        new AbstractCommand("Save As...", this, true) {
          public void execute() {
            promptSaveAs();
          }
        };
    menu.add(cmd, new MenuShortcut('s'));
    menu.addSeparator();

    cmd =
        new AbstractCommand("Print...", this, true) {
          public void execute() {
            print();
          }
        };
    menu.add(cmd, new MenuShortcut('p'));
    menu.addSeparator();

    cmd =
        new AbstractCommand("Exit", this, true) {
          public void execute() {
            exit();
          }
        };
    menu.add(cmd);
    return menu;
  }
 /** Creates the edit menu. Clients override this method to add additional menu items. */
 protected JMenu createEditMenu() {
   CommandMenu menu = new CommandMenu("Edit");
   menu.add(new UndoableCommand(new SelectAllCommand("Select All", this)), new MenuShortcut('a'));
   menu.addSeparator();
   menu.add(new UndoableCommand(new CutCommand("Cut", this)), new MenuShortcut('x'));
   menu.add(new CopyCommand("Copy", this), new MenuShortcut('c'));
   menu.add(new UndoableCommand(new PasteCommand("Paste", this)), new MenuShortcut('v'));
   menu.addSeparator();
   menu.add(new UndoableCommand(new DuplicateCommand("Duplicate", this)), new MenuShortcut('d'));
   menu.add(new UndoableCommand(new DeleteCommand("Delete", this)));
   menu.addSeparator();
   menu.add(new UndoableCommand(new GroupCommand("Group", this)));
   menu.add(new UndoableCommand(new UngroupCommand("Ungroup", this)));
   menu.addSeparator();
   menu.add(new UndoableCommand(new SendToBackCommand("Send to Back", this)));
   menu.add(new UndoableCommand(new BringToFrontCommand("Bring to Front", this)));
   menu.addSeparator();
   menu.add(new UndoCommand("Undo Command", this));
   menu.add(new RedoCommand("Redo Command", this));
   return menu;
 }