Example #1
0
  /**
   * **************************************************
   *
   * <p>private ByteArrayOutputStream popen(ArgumentListBuilder args)
   *
   * <p>Runs the command and captures the output.
   *
   * <p>**************************************************
   */
  private ByteArrayOutputStream popen(ArgumentListBuilder args, String jazzExecutable)
      throws IOException, InterruptedException {
    try {

      // scm produces text in the platform default encoding, so we need to convert it back to UTF-8
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      WriterOutputStream o =
          new WriterOutputStream(
              new OutputStreamWriter(baos, "UTF-8"), java.nio.charset.Charset.forName("UTF-8"));

      PrintStream output = listener.getLogger();

      ForkOutputStream fos = new ForkOutputStream(o, output);
      ProcStarter pstarter = run(args, jazzExecutable);

      if (joinWithPossibleTimeout(pstarter.stdout(fos), listener, null) == 0) {
        o.flush();
        return baos;
      } else {
        String errorString = "Failed to run ";
        boolean[] maskArray = args.toMaskArray();
        String[] cmdArray = args.toCommandArray();

        for (int i = 0; i < maskArray.length; i++) {
          if (maskArray[i] == false) {
            errorString += cmdArray[i] + " ";
          } else {
            errorString += "**** ";
          }
        }

        listener.error(errorString);
        throw new AbortException();
      }
    } catch (Exception e) {
      listener.error("Exception in popen " + e);
      throw new AbortException();
    }
  }
Example #2
0
  /**
   * The constructor creates the NodeTable and DirectedGraph taken the information from files
   * lines-gbg.txt and stops-gbg.txt and makes itself visible.
   */
  public ShortRoute(String file) {

    // try to convert to UTF-8 across plattforms to make Swedish chars work
    // System.out.println("charset = " + java.nio.charset.Charset.defaultCharset());
    // MacRoman macintosh  Windows-1252 ISO 8859-1 UTF-8
    try {
      // convert whatever this file is encoded in to UTF-8,
      // kill the exception (can't happen)
      introText =
          new String(
              introText.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8");
      felTextStart =
          new String(
              felTextStart.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8");
      felTextSlut =
          new String(
              felTextSlut.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8");
      frome =
          new String(frome.getBytes(java.nio.charset.Charset.defaultCharset().toString()), "UTF-8");
    } catch (UnsupportedEncodingException e) {
      System.exit(0);
    }

    // read the graph and draw it in a separate window
    // creates the graph and fills the p-queue "names"
    karta.setLocation(50, 250);
    if (file == null) {
      readAndDrawGraph();
    } else {
      readAndDrawBIGGraph(file);
    }
    System.out.println("Version with sorting fixed"); // debug
    // now to the graphics in the Frame
    // Left part
    // select is a panel for structuring the left part
    // i.e label, textfield for "from", label, textfield for "to"
    JPanel select = new JPanel(new GridLayout(4, 1));
    select.setBackground(Color.yellow);
    select.add(new JLabel("Ange startpunkt !", JLabel.CENTER));
    select.add(from);
    select.add(new JLabel("Ange slutpunkt !", JLabel.CENTER));
    select.add(to);
    from.setBackground(Color.white);
    from.setForeground(Color.blue);
    to.setBackground(Color.white);
    to.setForeground(Color.blue);
    from.addActionListener(this);
    to.addActionListener(this);

    // Middle part
    // route is the middle text area part where messages are displayed
    // give the middle text area a scrollbar to the right
    route = new JTextArea(introText, 12, 40);
    route.setEditable(false);
    JScrollPane routeScrollPane = new JScrollPane(route);
    routeScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    route.setBackground(Color.white);
    route.setForeground(Color.blue);

    // Rigth part
    JLabel head = new JLabel("   ****        Alternativ     *****     ");
    head.setForeground(Color.red);

    // add all stations to the right scrollpane
    // tanken är att dom skall vara valbara men det fungerar inte än
    // En JList vill ha en ListModel som parameter
    // En ListModel är ett interface som implementeras av klassen AbstractListModel
    // DefaultListModel ärver AbstractListModel
    DefaultListModel<String> valList = new DefaultListModel<String>();
    JList<String> alternativ = new JList<String>(valList);
    alternativ.setBackground(Color.white);
    alternativ.setForeground(Color.blue);
    // add a scroll pane to the station list in alternativ
    stationList = new JScrollPane(alternativ);
    // read names from p-queue and load them into the list
    while (!names.isEmpty()) valList.addElement(names.poll());

    // panel for structure
    JPanel valPanel = new JPanel(new BorderLayout());
    valPanel.setBackground(Color.white);
    valPanel.add(head, "North");
    valPanel.add(stationList, "Center");

    // put it all together in the frame
    add(select, "West");
    add(routeScrollPane, "Center");
    add(valPanel, "East");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
  } // end ShortRoute
Example #3
0
 /**
  * Opens a BufferedReader.
  *
  * @return the reader
  */
 public BufferedReader openReader() {
   java.nio.charset.Charset charset = java.nio.charset.Charset.forName(encoding);
   InputStream stream = openInputStream();
   if (stream == null) return null;
   return new BufferedReader(new InputStreamReader(stream, charset));
 }