예제 #1
0
 private void addMenuItem(
     JMenu menu,
     String label,
     int mnemonic,
     String accessibleDescription,
     String actionCallbackName)
     throws NoSuchMethodException {
   JMenuItem menuItem = new JMenuItem(label, mnemonic);
   menuItem
       .getAccessibleContext()
       .setAccessibleDescription((accessibleDescription != null) ? accessibleDescription : label);
   final Method callback =
       getClass().getMethod(actionCallbackName, new Class[] {ActionEvent.class});
   menuItem.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           try {
             callback.invoke(WordListScreen.this, new Object[] {e});
           } catch (InvocationTargetException ex) {
             handleException(ex.getTargetException());
           } catch (IllegalAccessException ex) {
             handleException(ex);
           }
         }
       });
   menu.add(menuItem);
 }
예제 #2
0
  /** Creates a JRadioButtonMenuItem for the Look and Feel menu */
  private JMenuItem createLafMenuItem(
      JMenu menu, String label, char mnemonic, String accessibleDescription, String laf) {
    JMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(label));
    lafMenuGroup.add(mi);
    mi.setMnemonic(mnemonic);
    mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
    mi.addActionListener(new ChangeLookAndFeelAction(this, laf));
    mi.setEnabled(isAvailableLookAndFeel(laf));

    return mi;
  }
예제 #3
0
 /** Creates a generic menu item */
 protected JMenuItem createMenuItem(
     JMenu menu, String label, char mnemonic, String accessibleDescription, Action action) {
   JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(label));
   mi.setMnemonic(mnemonic);
   mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
   mi.addActionListener(action);
   if (action == null) {
     mi.setEnabled(false);
   }
   return mi;
 }
예제 #4
0
  /**
   * Set the value of frame
   *
   * @param newVar the new value of frame
   */
  private void setFrame(final counts a, final connections cnc_a) {
    // Creates a frame with a title of "Circuit Editor"
    frame = new JFrame("SRSCKT - Circuit Editor");

    JMenu menu;
    JMenuBar menuBar;
    JMenuItem menuItem;
    /** *****************Menu Bar**************** */
    menuBar = new JMenuBar(); // Creating MenuBar

    // Build the first (Main)-menu.
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(menu);

    // Sub-menu of "File"
    // a group of JMenuItems
    menuItem = new JMenuItem("New", KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("A New Window");
    // File -> New || ActionListener
    ActionListener new_window =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            MainEditor new_wndw = new MainEditor();
          };
        };
    menuItem.addActionListener(new_window);
    menu.add(menuItem);

    menuItem = new JMenuItem("Open", KeyEvent.VK_O);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open previously saved file");
    // File -> Open || ActionListener
    ActionListener open =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (a.is_empty()) {
              String tempPath;
              JFileChooser opn_c = new JFileChooser();
              FileFilter xml = new FileNameExtensionFilter("XML Files", "xml");
              opn_c.setFileFilter(xml);
              int rVal = opn_c.showOpenDialog(panel);
              if (rVal == JFileChooser.APPROVE_OPTION) {
                tempPath = opn_c.getSelectedFile().getPath();
                drawPad.load(tempPath, a, cnc_a);
                setSaved(true);
                setPath(tempPath);
                changeTitle(new File(tempPath).getName());
              }
            } else
              JOptionPane.showMessageDialog(
                  frame,
                  "Your Pad is not empty. Open a new window and then try.",
                  "Error",
                  JOptionPane.ERROR_MESSAGE);
          };
        };
    menuItem.addActionListener(open);
    menu.add(menuItem);

    menuItem = new JMenuItem("Save", KeyEvent.VK_S);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Save a file");
    // File -> Save || ActionListener
    ActionListener save =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (!saved) {
              String[] extns = {"xml"};
              String path_ret = save_listener("XML Files", extns);
              if (path_ret != null)
                try {
                  save(path_ret, a, cnc_a);
                } catch (ParserConfigurationException ex) {
                  Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                  Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else {
              File f = new File(path);
              try {
                f.createNewFile();
              } catch (IOException ex) {
                Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
              }
              try {
                save(path, a, cnc_a);
              } catch (ParserConfigurationException ex) {
                Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
              } catch (IOException ex) {
                Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
              }
            }
          };
        };
    menuItem.addActionListener(save);
    menu.add(menuItem);

    menuItem = new JMenuItem("Save As", KeyEvent.VK_A);
    menuItem.getAccessibleContext().setAccessibleDescription("Save in a new file");
    // File -> Save || ActionListener
    ActionListener saveas =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String[] extns = {"xml"};
            String path_ret = save_listener("XML Files", extns);
            if (path_ret != null)
              try {
                save(path_ret, a, cnc_a);
              } catch (ParserConfigurationException ex) {
                Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
              } catch (IOException ex) {
                Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
              }
          };
        };
    menuItem.addActionListener(saveas);
    menu.add(menuItem);

    menuItem = new JMenuItem("Export", KeyEvent.VK_E);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Export as picture");
    // File -> Export || ActionListener
    ActionListener export =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String[] extns = {"jpg", "jpeg"};
            String path_ret = save_listener("JPEG Picture Files", extns);
            if (path_ret != null) {
              try {
                BufferedImage bi = Get_Component_Image(drawPad, drawPad.getBounds());
                try {
                  System.out.println(ImageIO.write(bi, "jpg", new File(path_ret)));
                } catch (IOException ex) {
                  Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
                }
              } catch (IOException ex) {
                Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
              }
            }
          };
        };
    menuItem.addActionListener(export);
    menu.add(menuItem);

    menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Close the window");
    // File -> Open || ActionListener
    ActionListener exit =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.dispose();
          };
        };
    menuItem.addActionListener(exit);
    menu.add(menuItem);

    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    menuBar.add(menu);

    menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_V);
    menuBar.add(menu);

    ButtonGroup view_btn_grp = new ButtonGroup();

    // Sub-menu of "View"
    // a group of JMenuItems
    menuItem = new JRadioButtonMenuItem("None");
    menuItem.getAccessibleContext().setAccessibleDescription("No Grid");
    // File -> New || ActionListener
    ActionListener no_grid =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              drawPad.view(0);
            } catch (IOException ex) {
              Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
          };
        };
    view_btn_grp.add(menuItem);
    menuItem.addActionListener(no_grid);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("Small Grid");
    menuItem.getAccessibleContext().setAccessibleDescription("Small Grid View");
    // File -> New || ActionListener
    ActionListener sml_grid =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              drawPad.view(1);
            } catch (IOException ex) {
              Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
          };
        };
    view_btn_grp.add(menuItem);
    menuItem.addActionListener(sml_grid);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("Medium Grid");
    menuItem.getAccessibleContext().setAccessibleDescription("Medium Grid View");
    // File -> New || ActionListener
    ActionListener mdm_grid =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              drawPad.view(2);
            } catch (IOException ex) {
              Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
          };
        };
    view_btn_grp.add(menuItem);
    menuItem.addActionListener(mdm_grid);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("Large Grid");
    menuItem.getAccessibleContext().setAccessibleDescription("Large Grid View");
    // File -> New || ActionListener
    ActionListener lrg_grid =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              drawPad.view(3);
            } catch (IOException ex) {
              Logger.getLogger(MainEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
          };
        };
    view_btn_grp.add(menuItem);
    menuItem.addActionListener(lrg_grid);
    menu.add(menuItem);

    menu = new JMenu("Tool");
    menu.setMnemonic(KeyEvent.VK_T);
    menuBar.add(menu);

    // a group of JMenuItems
    menuItem = new JMenuItem("Install New Package", KeyEvent.VK_I);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK));
    menuItem
        .getAccessibleContext()
        .setAccessibleDescription("Add a new type of circuit component through a Package");
    ActionListener new_package =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String tempPath;
            JFileChooser i_n_p = new JFileChooser(); // i_n_p => install new package
            FileFilter b = new FileNameExtensionFilter("Zip Files", "zip");
            i_n_p.setFileFilter(b);
            int rVal = i_n_p.showOpenDialog(panel);
            if (rVal == JFileChooser.APPROVE_OPTION) {
              frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
              tempPath = i_n_p.getSelectedFile().getPath();
              package_cls new_pkg =
                  new package_cls(tempPath, a, 0); // sysCall is 0, as zipped file will be opened
              add_componentType_buttons(new_pkg, a);
              frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              taskbar.setText("Package is installed");
            }
          };
        };
    menuItem.addActionListener(new_package);
    menu.add(menuItem);

    menuItem = new JMenuItem("Uninstall Package", KeyEvent.VK_U);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK));
    menuItem
        .getAccessibleContext()
        .setAccessibleDescription("Uninstall a previously installed package");
    ActionListener unInstl =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            // It means a JDialog with frame as parent or owner and 'true' assures that
            JDialog chooser = new JDialog(frame, "Choose from Packages", true);
            Container chooser_content = chooser.getContentPane();
            List pkg_list = new List(a.noUserPkg(), true);
            for (package_cls x : a.getPackage_list()) {
              if (!x.getIsSysPkg()) pkg_list.add(x.getName());
            }
            chooser_content.setLayout(new FlowLayout());
            chooser_content.add(pkg_list);
            chooser.setType(Window.Type.POPUP);
            chooser.setAlwaysOnTop(true);
            chooser.setSize(200, 200);
            chooser.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            chooser.setResizable(false);
            chooser.setVisible(true);
          };
        };
    menuItem.addActionListener(unInstl);
    menu.add(menuItem);

    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);

    frame.setJMenuBar(menuBar);
    /** *****************End of Menu Bar**************** */
    this.setContent(a, cnc_a);
    // sets the size of the frame
    frame.setSize(1000, 700);
    // frame.setLayout(new BoxLayout(frame, BoxLayout.Y_AXIS));
    // makes it so that you can close different instance indiviually(if you've pressed "File->New")
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    // so that u can't change the dafault size
    // frame.setResizable(false);
    // makes it so you can see it
    frame.setVisible(true);
  }
예제 #5
0
  public fileBackupProgram(JFrame frame) {
    super(new BorderLayout());
    this.frame = frame;

    errorDialog = new CustomDialog(frame, "Please enter a new name for the error log", this);
    errorDialog.pack();

    moveDialog = new CustomDialog(frame, "Please enter a new name for the move log", this);
    moveDialog.pack();

    printer = new FilePrinter();
    timers = new ArrayList<>();
    log = new JTextArea(5, 20);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);
    Object obj;
    copy = true;
    listModel = new DefaultListModel();
    // destListModel = new DefaultListModel();
    directoryList = new directoryStorage();

    // Create a file chooser
    fc = new JFileChooser();

    // Create the menu bar.
    menuBar = new JMenuBar();

    // Build the first menu.
    menu = new JMenu("File");
    menu.getAccessibleContext()
        .setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    editError = new JMenuItem("Save Error Log As...");
    editError
        .getAccessibleContext()
        .setAccessibleDescription("Change the name of the error log file");
    editError.addActionListener(new ErrorListener());
    menu.add(editError);

    editMove = new JMenuItem("Save Move Log As...");
    editMove
        .getAccessibleContext()
        .setAccessibleDescription("Change the name of the move log file");
    editMove.addActionListener(new MoveListener());
    menu.add(editMove);

    exit = new JMenuItem("Exit");
    exit.getAccessibleContext().setAccessibleDescription("Exit the Program");
    exit.addActionListener(new CloseListener());
    menu.add(exit);
    frame.setJMenuBar(menuBar);
    // Uncomment one of the following lines to try a different
    // file selection mode.  The first allows just directories
    // to be selected (and, at least in the Java look and feel,
    // shown).  The second allows both files and directories
    // to be selected.  If you leave these lines commented out,
    // then the default mode (FILES_ONLY) will be used.
    //
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    // fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    openButton = new JButton(openString);
    openButton.setActionCommand(openString);
    openButton.addActionListener(new OpenListener());

    destButton = new JButton(destString);
    destButton.setActionCommand(destString);
    destButton.addActionListener(new DestListener());

    // Create the save button.  We use the image from the JLF
    // Graphics Repository (but we extracted it from the jar).
    saveButton = new JButton(saveString);
    saveButton.setActionCommand(saveString);
    saveButton.addActionListener(new SaveListener());

    URL imageURL = getClass().getResource(greenButtonIcon);
    ImageIcon greenSquare = new ImageIcon(imageURL);
    startButton = new JButton("Start", greenSquare);
    startButton.setSize(60, 20);
    startButton.setHorizontalTextPosition(AbstractButton.LEADING);
    startButton.setActionCommand("Start");
    startButton.addActionListener(new StartListener());

    imageURL = getClass().getResource(redButtonIcon);
    ImageIcon redSquare = new ImageIcon(imageURL);
    stopButton = new JButton("Stop", redSquare);
    stopButton.setSize(60, 20);
    stopButton.setHorizontalTextPosition(AbstractButton.LEADING);
    stopButton.setActionCommand("Stop");
    stopButton.addActionListener(new StopListener());

    copyButton = new JRadioButton("Copy");
    copyButton.setActionCommand("Copy");
    copyButton.setSelected(true);
    copyButton.addActionListener(new RadioListener());

    moveButton = new JRadioButton("Move");
    moveButton.setActionCommand("Move");
    moveButton.addActionListener(new RadioListener());

    ButtonGroup group = new ButtonGroup();
    group.add(copyButton);
    group.add(moveButton);

    // For layout purposes, put the buttons in a separate panel

    JPanel optionPanel = new JPanel();

    GroupLayout layout = new GroupLayout(optionPanel);
    optionPanel.setLayout(layout);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    layout.setHorizontalGroup(
        layout.createSequentialGroup().addComponent(copyButton).addComponent(moveButton));
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(copyButton)
                    .addComponent(moveButton)));

    JPanel buttonPanel = new JPanel(); // use FlowLayout

    layout = new GroupLayout(buttonPanel);
    buttonPanel.setLayout(layout);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(openButton)
                    .addComponent(optionPanel))
            .addComponent(destButton)
            .addComponent(startButton)
            .addComponent(stopButton)
        // .addComponent(saveButton)
        );
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(openButton)
                    .addComponent(destButton)
                    .addComponent(startButton)
                    .addComponent(stopButton)
                // .addComponent(saveButton)
                )
            .addComponent(optionPanel));

    buttonPanel.add(optionPanel);
    /*
    buttonPanel.add(openButton);
    buttonPanel.add(destButton);
    buttonPanel.add(startButton);
    buttonPanel.add(stopButton);
    buttonPanel.add(saveButton);
    buttonPanel.add(listLabel);
    buttonPanel.add(copyButton);
    buttonPanel.add(moveButton);
    */
    destButton.setEnabled(false);
    startButton.setEnabled(false);
    stopButton.setEnabled(false);

    // Add the buttons and the log to this panel.

    // add(logScrollPane, BorderLayout.CENTER);

    JLabel listLabel = new JLabel("Monitored Directory:");
    listLabel.setLabelFor(list);

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);
    list.setVisibleRowCount(8);
    JScrollPane listScrollPane = new JScrollPane(list);
    JPanel listPane = new JPanel();
    listPane.setLayout(new BorderLayout());

    listPane.add(listLabel, BorderLayout.PAGE_START);
    listPane.add(listScrollPane, BorderLayout.CENTER);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    // monitored, destination, waitInt, check

    destination = new JLabel("Destination Directory: ");

    waitField = new JFormattedTextField();
    // waitField.setValue(240);
    waitField.setEditable(false);
    waitField.addPropertyChangeListener(new FormattedTextListener());

    waitInt = new JLabel("Wait Interval (in minutes)");
    // waitInt.setLabelFor(waitField);

    checkField = new JFormattedTextField();
    checkField.setSize(1, 10);
    // checkField.setValue(60);
    checkField.setEditable(false);
    checkField.addPropertyChangeListener(new FormattedTextListener());

    check = new JLabel("Check Interval (in minutes)");
    // check.setLabelFor(checkField);

    fireButton = new JButton(fireString);
    fireButton.setActionCommand(fireString);
    fireButton.addActionListener(new FireListener());

    JPanel fieldPane = new JPanel();
    // fieldPane.add(destField);
    layout = new GroupLayout(fieldPane);
    fieldPane.setLayout(layout);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(waitInt)
                    .addComponent(check))
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(waitField, 60, 60, 60)
                    .addComponent(checkField, 60, 60, 60)));

    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(waitInt)
                    .addComponent(waitField))
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(check)
                    .addComponent(checkField)));

    JPanel labelPane = new JPanel();

    labelPane.setLayout(new BorderLayout());

    labelPane.add(destination, BorderLayout.PAGE_START);
    labelPane.add(fieldPane, BorderLayout.CENTER);

    layout = new GroupLayout(labelPane);
    labelPane.setLayout(layout);

    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);

    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(destination)
                    .addComponent(fieldPane)));

    layout.setVerticalGroup(
        layout.createSequentialGroup().addComponent(destination).addComponent(fieldPane));
    // labelPane.add(destination);
    // labelPane.add(fieldPane);

    try {
      // Read from disk using FileInputStream
      FileInputStream f_in = new FileInputStream(LOG_DIRECTORY + "\\save.data");

      // Read object using ObjectInputStream
      ObjectInputStream obj_in = new ObjectInputStream(f_in);

      // Read an object
      directoryList = (directoryStorage) obj_in.readObject();
      ERROR_LOG_NAME = (String) obj_in.readObject();
      MOVE_LOG_NAME = (String) obj_in.readObject();

      if (ERROR_LOG_NAME instanceof String) {
        printer.changeErrorLogName(ERROR_LOG_NAME);
      }

      if (MOVE_LOG_NAME instanceof String) {
        printer.changeMoveLogName(MOVE_LOG_NAME);
      }

      if (directoryList instanceof directoryStorage) {
        System.out.println("found object");
        // directoryList = (directoryStorage) obj;

        Iterator<Directory> directories = directoryList.getDirectories();
        Directory d;
        while (directories.hasNext()) {
          d = directories.next();

          try {
            listModel.addElement(d.getDirectory().toRealPath());
          } catch (IOException x) {
            printer.printError(x.toString());
          }

          int index = list.getSelectedIndex();
          if (index == -1) {
            list.setSelectedIndex(0);
          }

          index = list.getSelectedIndex();
          Directory dir = directoryList.getDirectory(index);

          destButton.setEnabled(true);
          checkField.setValue(dir.getInterval());
          waitField.setValue(dir.getWaitInterval());
          checkField.setEditable(true);
          waitField.setEditable(true);

          // directoryList.addNewDirectory(d);
          // try {
          // listModel.addElement(d.getDirectory().toString());
          // } catch (IOException x) {
          // printer.printError(x.toString());
          // }

          // timer = new Timer();
          // timer.schedule(new CopyTask(d.directory, d.destination, d.getWaitInterval(), printer,
          // d.copy), 0, d.getInterval());
        }

      } else {
        System.out.println("did not find object");
      }
      obj_in.close();
    } catch (ClassNotFoundException x) {
      printer.printError(x.getLocalizedMessage());
      System.err.format("Unable to read");
    } catch (IOException y) {
      printer.printError(y.getLocalizedMessage());
    }

    // Layout the text fields in a panel.

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(buttonPanel, BorderLayout.PAGE_START);
    add(listPane, BorderLayout.LINE_START);
    // add(destListScrollPane, BorderLayout.CENTER);

    add(fieldPane, BorderLayout.LINE_END);
    add(labelPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
  }
예제 #6
0
  // Rebuild the contents of the menu based on current program state
  public void UpdateMenuBar() {
    JMenu menu;
    int i;

    menuBar.removeAll();

    // Build the first menu.
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(menu);

    buttonOpenFile = new JMenuItem("Open File...", KeyEvent.VK_O);
    buttonOpenFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.ALT_MASK));
    buttonOpenFile.getAccessibleContext().setAccessibleDescription("Open a g-code file...");
    buttonOpenFile.addActionListener(this);
    menu.add(buttonOpenFile);

    menu.addSeparator();

    // list recent files
    if (recentFiles != null && recentFiles.length > 0) {
      // list files here
      for (i = 0; i < recentFiles.length; ++i) {
        if (recentFiles[i] == null || recentFiles[i].length() == 0) break;
        buttonRecent[i] = new JMenuItem((1 + i) + " " + recentFiles[i], KeyEvent.VK_1 + i);
        if (buttonRecent[i] != null) {
          buttonRecent[i].addActionListener(this);
          menu.add(buttonRecent[i]);
        }
      }
      if (i != 0) menu.addSeparator();
    }

    buttonExit = new JMenuItem("Exit", KeyEvent.VK_Q);
    buttonExit.getAccessibleContext().setAccessibleDescription("Goodbye...");
    buttonExit.addActionListener(this);
    menu.add(buttonExit);

    menuBar.add(menu);

    // settings menu
    menu = new JMenu("Settings");
    menu.setMnemonic(KeyEvent.VK_T);
    menu.getAccessibleContext().setAccessibleDescription("Adjust the robot settings.");

    JMenu subMenu = new JMenu("Port");
    subMenu.setMnemonic(KeyEvent.VK_P);
    subMenu.getAccessibleContext().setAccessibleDescription("What port to connect to?");
    subMenu.setEnabled(!running);
    ButtonGroup group = new ButtonGroup();

    ListSerialPorts();
    buttonPorts = new JRadioButtonMenuItem[portsDetected.length];
    for (i = 0; i < portsDetected.length; ++i) {
      buttonPorts[i] = new JRadioButtonMenuItem(portsDetected[i]);
      if (recentPort.equals(portsDetected[i]) && portOpened) {
        buttonPorts[i].setSelected(true);
      }
      buttonPorts[i].addActionListener(this);
      group.add(buttonPorts[i]);
      subMenu.add(buttonPorts[i]);
    }

    subMenu.addSeparator();

    buttonRescan = new JMenuItem("Rescan", KeyEvent.VK_N);
    buttonRescan.getAccessibleContext().setAccessibleDescription("Rescan the available ports.");
    buttonRescan.addActionListener(this);
    subMenu.add(buttonRescan);

    menu.add(subMenu);

    buttonConfig = new JMenuItem("Configure limits", KeyEvent.VK_L);
    buttonConfig.getAccessibleContext().setAccessibleDescription("Adjust the robot & paper shape.");
    buttonConfig.addActionListener(this);
    buttonConfig.setEnabled(portConfirmed && !running);
    menu.add(buttonConfig);

    buttonJogMotors = new JMenuItem("Jog Motors", KeyEvent.VK_J);
    buttonJogMotors.addActionListener(this);
    buttonJogMotors.setEnabled(portConfirmed && !running);
    menu.add(buttonJogMotors);

    buttonDrive = new JMenuItem("Drive Manually", KeyEvent.VK_R);
    buttonDrive.getAccessibleContext().setAccessibleDescription("Etch-a-sketch style driving");
    buttonDrive.addActionListener(this);
    buttonDrive.setEnabled(portConfirmed && !running);
    menu.add(buttonDrive);

    menuBar.add(menu);

    // Draw menu
    menu = new JMenu("Draw");
    menu.setMnemonic(KeyEvent.VK_D);
    menu.getAccessibleContext().setAccessibleDescription("Start & Stop progress");

    buttonStart = new JMenuItem("Start", KeyEvent.VK_S);
    buttonStart.getAccessibleContext().setAccessibleDescription("Start sending g-code");
    buttonStart.addActionListener(this);
    buttonStart.setEnabled(portConfirmed && !running);
    menu.add(buttonStart);

    buttonPause = new JMenuItem("Pause", KeyEvent.VK_P);
    buttonPause.getAccessibleContext().setAccessibleDescription("Pause sending g-code");
    buttonPause.addActionListener(this);
    buttonPause.setEnabled(portConfirmed && running);
    menu.add(buttonPause);

    buttonHalt = new JMenuItem("Halt", KeyEvent.VK_H);
    buttonHalt.getAccessibleContext().setAccessibleDescription("Halt sending g-code");
    buttonHalt.addActionListener(this);
    buttonHalt.setEnabled(portConfirmed && running);
    menu.add(buttonHalt);

    menuBar.add(menu);

    // tools menu
    menu = new JMenu("Tools");
    buttonZoomOut = new JMenuItem("Zoom -");
    buttonZoomOut.addActionListener(this);
    buttonZoomOut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, ActionEvent.ALT_MASK));
    menu.add(buttonZoomOut);

    buttonZoomIn = new JMenuItem("Zoom +", KeyEvent.VK_EQUALS);
    buttonZoomIn.addActionListener(this);
    buttonZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ActionEvent.ALT_MASK));
    menu.add(buttonZoomIn);

    menuBar.add(menu);

    // Help menu
    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    menu.getAccessibleContext().setAccessibleDescription("Get help");

    buttonAbout = new JMenuItem("About", KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("Find out about this program");
    buttonAbout.addActionListener(this);
    menu.add(buttonAbout);

    buttonCheckForUpdate = new JMenuItem("Check for updates", KeyEvent.VK_U);
    menu.getAccessibleContext().setAccessibleDescription("Is there a newer version available?");
    buttonCheckForUpdate.addActionListener(this);
    buttonCheckForUpdate.setEnabled(false);
    menu.add(buttonCheckForUpdate);

    menuBar.add(menu);

    // finish
    menuBar.updateUI();
  }