Пример #1
0
  public void displayGUI() {
    JFrame frame = new JFrame("Mark Up");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    MainPanel mainPanel;
    try {
      UndoRedoManager undoRedoManager = UndoRedoManagerImpl.getInstance();
      BufferedImage image = ImageIO.read(getClass().getResourceAsStream("/images/test3.png"));
      mainPanel = new MainPanel();
      MainPanelModel model = mainPanel.getModel();
      mainPanel.setImage(image);

      AnnotationMouseAdapter ama = new AnnotationMouseAdapter(model);
      model.addPropertyChangeListener(mainPanel);

      mainPanel.addMouseListener(ama);
      mainPanel.addMouseMotionListener(ama);

      JScrollPane scrollTablePane = setUpTable(mainPanel);

      JMenuBar menuBar = new JMenuBar();

      JMenu fileMenu = new JMenu("File");
      menuBar.add(fileMenu);

      JMenu editMenu = new JMenu("Edit");
      UndoAction undoAction =
          new UndoAction("Undo", null, "Undo last command", new Integer(KeyEvent.VK_Z));
      undoRedoManager.addPropertyChangeListener(undoAction);
      RedoAction redoAction =
          new RedoAction("Redo", null, "Redo last command", new Integer(KeyEvent.VK_R));
      undoRedoManager.addPropertyChangeListener(redoAction);
      redoAction.setModel(model);
      undoAction.setMainPanelModel(model);
      JMenuItem undoItem = new JMenuItem(undoAction);
      JMenuItem redoItem = new JMenuItem(redoAction);
      editMenu.add(undoItem);
      editMenu.add(redoItem);
      menuBar.add(editMenu);
      frame.setJMenuBar(menuBar);

      frame.add(scrollTablePane, BorderLayout.EAST);
      frame.add(mainPanel, BorderLayout.WEST);
      frame.pack();
      frame.setVisible(true);

    } catch (IOException ex) {
      Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
  }