/** Returns the tool bar for the panel. */
    protected JComponent getToolBar() {
      JToolBar tbarDir = new JToolBar();
      JButton btnNew = new JButton();
      // m_btnSave = new JButton("Save File");
      // i118n
      // btnNew.setText("New Label");
      btnNew.setText(Util.getAdmLabel("_adm_New_Label"));
      btnNew.setActionCommand("new");
      // m_btnSave.setActionCommand("save");

      ActionListener alTool =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              doAction(e);
            }
          };

      btnNew.addActionListener(alTool);
      // m_btnSave.addActionListener(alTool);

      tbarDir.setFloatable(false);
      tbarDir.add(btnNew);
      /*tbarDir.add(new JLabel("        "));
      tbarDir.add(m_btnSave);*/

      return tbarDir;
    }
 private JToolBar initToolbar() {
   JToolBar toolbar = new JToolBar();
   toolbar.setFloatable(false);
   fRun = createRunButton();
   toolbar.add(fRun);
   return toolbar;
 }
 private JToolBar buildToolBar() {
   // build tool bar
   JToolBar toolBar = new JToolBar("Toolbar");
   toolBar.add(makeToolbarButton("stock_new.png", "New file", "New"));
   toolBar.add(makeToolbarButton("stock_open.png", "Open file", "Open"));
   toolBar.add(makeToolbarButton("stock_save.png", "Save file", "Save"));
   // run button is special
   runButton = makeToolbarButton("Play24.gif", "Run Program", "Run");
   toolBar.add(runButton);
   toolBar.add(makeToolbarButton("stock_text_left.png", "Pretty Print", "Pretty"));
   toolBar.addSeparator();
   toolBar.add(new JButton(copyAction));
   toolBar.add(new JButton(cutAction));
   toolBar.add(new JButton(pasteAction));
   return toolBar;
 }
  // Create a simple JToolBar with some buttons.
  protected JToolBar createToolBar() {
    JToolBar bar = new JToolBar();

    // Add simple actions for opening & saving.
    bar.add(getOpenAction()).setText("");
    bar.add(getSaveAction()).setText("");
    bar.addSeparator();

    // Add cut/copy/paste buttons.
    bar.add(textComp.getActionMap().get(DefaultEditorKit.cutAction)).setText("");
    bar.add(textComp.getActionMap().get(DefaultEditorKit.copyAction)).setText("");
    bar.add(textComp.getActionMap().get(DefaultEditorKit.pasteAction)).setText("");
    return bar;
  }
  /** 程式的GUI畫面配置,並登入按鈕、選項監聽。 */
  private void GUI() {
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

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

    JMenuItem file_newMenuItem = new JMenuItem("New");
    file_newMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
    file_newMenuItem.addActionListener(new SystemFileNew());
    fileMenu.add(file_newMenuItem);

    JMenuItem file_openMenuItem = new JMenuItem("Open File...");
    file_openMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/com/sun/java/swing/plaf/windows/icons/TreeOpen.gif")));
    file_openMenuItem.addActionListener(new SystemFileOpen());
    fileMenu.add(file_openMenuItem);

    JMenu file_saveMenu = new JMenu("Save");
    fileMenu.add(file_saveMenu);

    JMenuItem file_save_saveMenuItem = new JMenuItem("Save");
    file_save_saveMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/com/sun/java/swing/plaf/windows/icons/FloppyDrive.gif")));
    file_save_saveMenuItem.addActionListener(new SystemFileSave());
    file_save_saveMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    file_saveMenu.add(file_save_saveMenuItem);

    JMenuItem file_save_save_asMenuItem = new JMenuItem("Save as");
    file_save_save_asMenuItem.addActionListener(new SystemFileSaveAS());
    file_saveMenu.add(file_save_save_asMenuItem);

    JMenuItem file_save_save_allMenuItem = new JMenuItem("Save all");
    file_save_save_allMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
    file_save_save_allMenuItem.addActionListener(new SystemFileSaveAll());
    file_saveMenu.add(file_save_save_allMenuItem);

    JMenu file_closeMenu = new JMenu("Close");
    fileMenu.add(file_closeMenu);

    JMenuItem file_close_closeMenuItem = new JMenuItem("Close File");
    file_close_closeMenuItem.addActionListener(new SystemFileClose());
    file_closeMenu.add(file_close_closeMenuItem);

    JMenuItem file_close_close_all_fileMenuItem = new JMenuItem("Close all File");
    file_close_close_all_fileMenuItem.addActionListener(new SystemFileCloseAll());
    file_closeMenu.add(file_close_close_all_fileMenuItem);

    JMenuItem file_exitMenuItem = new JMenuItem("Exit");
    file_exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
    file_exitMenuItem.addActionListener(new SystemExit());
    fileMenu.add(file_exitMenuItem);

    JMenu editMenu = new JMenu("Edit");
    menuBar.add(editMenu);

    replace_searchMenuItem.addActionListener(replace_search);
    replace_searchMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
    editMenu.add(replace_searchMenuItem);

    SystemEditCut_Copy_Paste cut_copy_paste = new SystemEditCut_Copy_Paste();
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    cutMenuItem.addActionListener(cut_copy_paste);
    editMenu.add(cutMenuItem);
    copyMenutem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));

    copyMenutem.addActionListener(cut_copy_paste);
    editMenu.add(copyMenutem);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));

    pasteMenuItem.addActionListener(cut_copy_paste);
    editMenu.add(pasteMenuItem);

    JMenuItem pathMenuItem = new JMenuItem("Default AutoSave-Path");
    pathMenuItem.addActionListener(new SystemEditSetPath());
    editMenu.add(pathMenuItem);

    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    JMenuItem HelpMenuItem = new JMenuItem("Help");
    HelpMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(null, help, "Help!", JOptionPane.INFORMATION_MESSAGE);
          }
        });
    helpMenu.add(HelpMenuItem);

    JMenuItem AboutNewMenuItem = new JMenuItem("About");
    AboutNewMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, about, "About...", JOptionPane.INFORMATION_MESSAGE);
          }
        });
    helpMenu.add(AboutNewMenuItem);

    JToolBar toolBar = new JToolBar();
    getContentPane().add(toolBar, BorderLayout.NORTH);

    scrollPane.setViewportView(td);
    JButton newFileButton = new JButton("New");
    newFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
    newFileButton.setToolTipText("New File.");
    newFileButton.addActionListener(new SystemFileNew());
    toolBar.add(newFileButton);

    JButton openFileButton = new JButton("Open");
    openFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/javax/swing/plaf/metal/icons/ocean/directory.gif")));
    openFileButton.setToolTipText("Open File.");
    openFileButton.addActionListener(new SystemFileOpen());
    toolBar.add(openFileButton);

    JButton save_asFileButton = new JButton("Save as");
    save_asFileButton.setToolTipText("Save as File.");
    save_asFileButton.addActionListener(new SystemFileSaveAS());
    toolBar.add(save_asFileButton);

    JButton saveFileButton = new JButton("Save");
    saveFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/floppy.gif")));
    saveFileButton.setToolTipText("Savet his File.");
    saveFileButton.addActionListener(new SystemFileSave());
    toolBar.add(saveFileButton);

    JButton save_allFileButton = new JButton("Save all");
    save_allFileButton.setToolTipText("Save all File.");
    save_allFileButton.addActionListener(new SystemFileSaveAll());
    toolBar.add(save_allFileButton);

    JButton closeButton = new JButton("Close");
    closeButton.setToolTipText("Close this file.");
    closeButton.addActionListener(new SystemFileClose());
    toolBar.add(closeButton);

    JButton close_allButton = new JButton("Close all");
    close_allButton.setToolTipText("Close al File.");
    close_allButton.addActionListener(new SystemFileCloseAll());
    toolBar.add(close_allButton);
  }
  /** Constructor to create the frame and its components */
  public CoreyTextEditor() {
    // Create a scroll pane
    area.setFont(new Font("Monospaced", Font.PLAIN, 12));
    JScrollPane scroll =
        new JScrollPane(
            area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    add(scroll, BorderLayout.CENTER);

    // Adds the system default look and feel

    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException
        | InstantiationException
        | UnsupportedLookAndFeelException
        | IllegalAccessException e) {
      e.printStackTrace();
    }

    // Create a menu bar
    JMenuBar JMB = new JMenuBar();
    setJMenuBar(JMB);
    JMenu file = new JMenu("File");
    JMenu edit = new JMenu("Edit");
    JMB.add(file);
    JMB.add(edit);

    // Finishing our menu bar
    file.add(New);
    file.add(Open);
    file.add(Save);
    file.add(SaveAs);
    file.addSeparator();
    file.add(Quit);

    edit.add(Cut);
    edit.add(Copy);
    edit.add(Paste);

    edit.getItem(0).setText("Cut");
    edit.getItem(0).setIcon(new ImageIcon("cut.gif"));
    edit.getItem(1).setText("Copy");
    edit.getItem(1).setIcon(new ImageIcon("copy.gif"));
    edit.getItem(2).setText("Paste");
    edit.getItem(2).setIcon(new ImageIcon("paste.gif"));

    // Time to make a toolbar!
    JToolBar tool = new JToolBar();
    add(tool, BorderLayout.NORTH);
    tool.add(New);
    tool.add(Open);
    tool.add(Save);
    tool.addSeparator();

    JButton cut = tool.add(Cut);
    JButton cop = tool.add(Copy);
    JButton pas = tool.add(Paste);

    cut.setText(null);
    cut.setIcon(new ImageIcon("cut.gif"));
    cop.setText(null);
    cop.setIcon(new ImageIcon("copy.gif"));
    pas.setText(null);
    pas.setIcon(new ImageIcon("paste.gif"));

    Save.setEnabled(false);
    SaveAs.setEnabled(false);

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    pack();

    /*
     KeyListener to change Save and SaveAs
    */
    KeyListener k1 =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            changed = true;
            Save.setEnabled(true);
            SaveAs.setEnabled(true);
          }
        };
    area.addKeyListener(k1);
    setTitle(currentFile + " - CoreyTextEditor");
    setVisible(true);
  }