예제 #1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   for (Options option : Options.values())
     if (e.getActionCommand().equals(option.getCaption())) this.option = option;
   for (Tool tool : Tool.values())
     if (e.getActionCommand().equals(tool.name())) {
       try {
         Method m = BusLaneAdderWindow.class.getMethod(tool.function, new Class[] {});
         m.invoke(this, new Object[] {});
       } catch (SecurityException e1) {
         e1.printStackTrace();
       } catch (NoSuchMethodException e1) {
         e1.printStackTrace();
       } catch (IllegalArgumentException e1) {
         e1.printStackTrace();
       } catch (IllegalAccessException e1) {
         e1.printStackTrace();
       } catch (InvocationTargetException e1) {
         e1.printStackTrace();
       }
       setVisible(true);
       repaint();
     }
   if (e.getActionCommand().equals(READY_TO_EXIT)) {
     setVisible(false);
     readyToExit = true;
   }
 }
예제 #2
0
    static Arguments valueOf(String[] args, Configuration conf) throws IOException {
      List<Path> srcs = new ArrayList<Path>();
      Path dst = null;
      Path log = null;
      EnumSet<Options> flags = EnumSet.noneOf(Options.class);
      String presevedAttributes = null;
      String mapredSslConf = null;
      long filelimit = Long.MAX_VALUE;
      long sizelimit = Long.MAX_VALUE;

      for (int idx = 0; idx < args.length; idx++) {
        Options[] opt = Options.values();
        int i = 0;
        for (; i < opt.length && !args[idx].startsWith(opt[i].cmd); i++) ;

        if (i < opt.length) {
          flags.add(opt[i]);
          if (opt[i] == Options.PRESERVE_STATUS) {
            presevedAttributes = args[idx].substring(2);
            FileAttribute.parse(presevedAttributes); // validation
          } else if (opt[i] == Options.FILE_LIMIT) {
            filelimit = Options.FILE_LIMIT.parseLong(args, ++idx);
          } else if (opt[i] == Options.SIZE_LIMIT) {
            sizelimit = Options.SIZE_LIMIT.parseLong(args, ++idx);
          }
        } else if ("-f".equals(args[idx])) {
          if (++idx == args.length) {
            throw new IllegalArgumentException("urilist_uri not specified in -f");
          }
          srcs.addAll(fetchFileList(conf, new Path(args[idx])));
        } else if ("-log".equals(args[idx])) {
          if (++idx == args.length) {
            throw new IllegalArgumentException("logdir not specified in -log");
          }
          log = new Path(args[idx]);
        } else if ("-mapredSslConf".equals(args[idx])) {
          if (++idx == args.length) {
            throw new IllegalArgumentException("ssl conf file not specified in -mapredSslConf");
          }
          mapredSslConf = args[idx];
        } else if ("-m".equals(args[idx])) {
          if (++idx == args.length) {
            throw new IllegalArgumentException("num_maps not specified in -m");
          }
          try {
            conf.setInt(MAX_MAPS_LABEL, Integer.valueOf(args[idx]));
          } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid argument to -m: " + args[idx]);
          }
        } else if ('-' == args[idx].codePointAt(0)) {
          throw new IllegalArgumentException("Invalid switch " + args[idx]);
        } else if (idx == args.length - 1) {
          dst = new Path(args[idx]);
        } else {
          srcs.add(new Path(args[idx]));
        }
      }
      // mandatory command-line parameters
      if (srcs.isEmpty() || dst == null) {
        throw new IllegalArgumentException("Missing " + (dst == null ? "dst path" : "src"));
      }
      // incompatible command-line flags
      final boolean isOverwrite = flags.contains(Options.OVERWRITE);
      final boolean isUpdate = flags.contains(Options.UPDATE);
      final boolean isDelete = flags.contains(Options.DELETE);
      if (isOverwrite && isUpdate) {
        throw new IllegalArgumentException("Conflicting overwrite policies");
      }
      if (isDelete && !isOverwrite && !isUpdate) {
        throw new IllegalArgumentException(
            Options.DELETE.cmd
                + " must be specified with "
                + Options.OVERWRITE
                + " or "
                + Options.UPDATE
                + ".");
      }
      return new Arguments(
          srcs, dst, log, flags, presevedAttributes, filelimit, sizelimit, mapredSslConf);
    }
예제 #3
0
 // Methods
 public BusLaneAdderWindow(
     String title,
     Network network,
     File imageFile,
     double[] upLeft,
     double[] downRight,
     String finalNetworkFile,
     CoordinateTransformation coordinateTransformation)
     throws IOException {
   setTitle(title);
   this.finalNetworkFile = finalNetworkFile;
   this.network = network;
   NetworkTwoNodesPainter networkPainter = new NetworkTwoNodesPainter(network, Color.BLACK);
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   this.setLocation(0, 0);
   this.setLayout(new BorderLayout());
   layersPanels.put(
       PanelIds.ONE,
       new BusLaneAdderPanel(
           this, networkPainter, imageFile, upLeft, downRight, coordinateTransformation));
   this.add(layersPanels.get(PanelIds.ONE), BorderLayout.CENTER);
   option = Options.ZOOM;
   JPanel toolsPanel = new JPanel();
   toolsPanel.setLayout(new GridBagLayout());
   for (Tool tool : Tool.values()) {
     JButton toolButton = new JButton(tool.caption);
     toolButton.setActionCommand(tool.name());
     toolButton.addActionListener(this);
     GridBagConstraints gbc = new GridBagConstraints();
     gbc.gridx = tool.gx;
     gbc.gridy = tool.gy;
     gbc.gridwidth = tool.sx;
     gbc.gridheight = tool.sy;
     toolsPanel.add(toolButton, gbc);
   }
   this.add(toolsPanel, BorderLayout.NORTH);
   JPanel buttonsPanel = new JPanel();
   buttonsPanel.setLayout(new GridLayout(Options.values().length, 1));
   for (Options option : Options.values()) {
     JButton optionButton = new JButton(option.getCaption());
     optionButton.setActionCommand(option.getCaption());
     optionButton.addActionListener(this);
     buttonsPanel.add(optionButton);
   }
   this.add(buttonsPanel, BorderLayout.EAST);
   JPanel infoPanel = new JPanel();
   infoPanel.setLayout(new BorderLayout());
   readyButton = new JButton("Ready to exit");
   readyButton.addActionListener(this);
   readyButton.setActionCommand(READY_TO_EXIT);
   infoPanel.add(readyButton, BorderLayout.WEST);
   JPanel labelsPanel = new JPanel();
   labelsPanel.setLayout(new GridLayout(1, Labels.values().length));
   labelsPanel.setBorder(new TitledBorder("Information"));
   labels = new JTextField[Labels.values().length];
   for (int i = 0; i < Labels.values().length; i++) {
     labels[i] = new JTextField("");
     labels[i].setEditable(false);
     labels[i].setBackground(null);
     labels[i].setBorder(null);
     labelsPanel.add(labels[i]);
   }
   infoPanel.add(labelsPanel, BorderLayout.CENTER);
   JPanel coordsPanel = new JPanel();
   coordsPanel.setLayout(new GridLayout(1, 2));
   coordsPanel.setBorder(new TitledBorder("Coordinates"));
   coordsPanel.add(lblCoords[0]);
   coordsPanel.add(lblCoords[1]);
   infoPanel.add(coordsPanel, BorderLayout.EAST);
   this.add(infoPanel, BorderLayout.SOUTH);
   super.setSize(
       Toolkit.getDefaultToolkit().getScreenSize().width,
       Toolkit.getDefaultToolkit().getScreenSize().height);
 }