Ejemplo n.º 1
0
 private void saveSrc() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(asmFilter);
   fileChooser.setFileFilter(asmFilter);
   if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = fileChooser.getSelectedFile();
       if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) {
         file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]);
       }
       if (file.exists()) {
         if (JOptionPane.showConfirmDialog(
                 frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION)
             != JOptionPane.YES_OPTION) {
           return;
         }
       }
       PrintStream output = new PrintStream(file);
       output.print(sourceTextarea.getText());
       output.close();
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }
Ejemplo n.º 2
0
    private static void createBrokenMarkerFile(@Nullable Throwable reason) {
      final File brokenMarker = getCorruptionMarkerFile();

      try {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final PrintStream stream = new PrintStream(out);
        try {
          new Exception().printStackTrace(stream);
          if (reason != null) {
            stream.print("\nReason:\n");
            reason.printStackTrace(stream);
          }
        } finally {
          stream.close();
        }
        LOG.info("Creating VFS corruption marker; Trace=\n" + out.toString());

        final FileWriter writer = new FileWriter(brokenMarker);
        try {
          writer.write(
              "These files are corrupted and must be rebuilt from the scratch on next startup");
        } finally {
          writer.close();
        }
      } catch (IOException e) {
        // No luck.
      }
    }
Ejemplo n.º 3
0
  /**
   * Locate the linux fonts based on the XML configuration file
   *
   * @param file The location of the XML file
   */
  private static void locateLinuxFonts(File file) {
    if (!file.exists()) {
      System.err.println("Unable to open: " + file.getAbsolutePath());
      return;
    }

    try {
      InputStream in = new FileInputStream(file);

      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
      ByteArrayOutputStream temp = new ByteArrayOutputStream();
      PrintStream pout = new PrintStream(temp);
      while (reader.ready()) {
        String line = reader.readLine();
        if (line.indexOf("DOCTYPE") == -1) {
          pout.println(line);
        }
      }

      in = new ByteArrayInputStream(temp.toByteArray());

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();

      Document document = builder.parse(in);

      NodeList dirs = document.getElementsByTagName("dir");
      for (int i = 0; i < dirs.getLength(); i++) {
        Element element = (Element) dirs.item(i);
        String dir = element.getFirstChild().getNodeValue();

        if (dir.startsWith("~")) {
          dir = dir.substring(1);
          dir = userhome + dir;
        }

        addFontDirectory(new File(dir));
      }

      NodeList includes = document.getElementsByTagName("include");
      for (int i = 0; i < includes.getLength(); i++) {
        Element element = (Element) dirs.item(i);
        String inc = element.getFirstChild().getNodeValue();
        if (inc.startsWith("~")) {
          inc = inc.substring(1);
          inc = userhome + inc;
        }

        locateLinuxFonts(new File(inc));
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.err.println("Unable to process: " + file.getAbsolutePath());
    }
  }
Ejemplo n.º 4
0
 public void save(PrintStream stream) {
   saved = true;
   stream.println("<?xml version=\"1.0\"?>");
   stream.println("<scale>");
   stream.println("  <name>" + nameTF.getText() + "</name>");
   for (Enumeration en = sp.notes.elements(); en.hasMoreElements(); ) {
     ScalePanel.Notik cur = (ScalePanel.Notik) en.nextElement();
     stream.println("  <note>" + cur.n + "</note>");
   }
   stream.println("</scale>");
 }
Ejemplo n.º 5
0
 /**
  * Draw a filled rectangle in current pen color.
  *
  * @param x starting x coord
  * @param y starting y coord
  * @param width rectangle width
  * @param height rectangle height
  */
 public void fillRect(int x, int y, int width, int height) {
   if (width == m_extent.width && height == m_extent.height) {
     clearRect(x, y, width, height); // if we're painting the entire background, just make it white
   } else {
     if (DEBUG) m_printstream.println("% fillRect");
     setStateToLocal();
     m_printstream.println(
         xTransform(xScale(x))
             + " "
             + yTransform(yScale(y))
             + " "
             + xScale(width)
             + " "
             + yScale(height)
             + " true Rect");
   }
 }
Ejemplo n.º 6
0
  /**
   * Set current font. Default to Plain Courier 11 if null.
   *
   * @param font new font.
   */
  public void setFont(Font font) {

    if (font != null) {
      m_localGraphicsState.setFont(font);
      if (font.getName().equals(m_psGraphicsState.getFont().getName())
          && (m_psGraphicsState.getFont().getStyle() == font.getStyle())
          && (m_psGraphicsState.getFont().getSize() == yScale(font.getSize()))) return;
      m_psGraphicsState.setFont(
          new Font(font.getName(), font.getStyle(), yScale(getFont().getSize())));
    } else {
      m_localGraphicsState.setFont(new Font("Courier", Font.PLAIN, 11));
      m_psGraphicsState.setFont(getFont());
    }

    m_printstream.println("/(" + replacePSFont(getFont().getPSName()) + ")" + " findfont");
    m_printstream.println(yScale(getFont().getSize()) + " scalefont setfont");
  }
Ejemplo n.º 7
0
 // --------------------------------------------------
 public void close() {
   try {
     is.close();
     os.close();
     socket.close();
     responseArea.appendText("***Connection closed" + "\n");
   } catch (IOException e) {
     responseArea.appendText("IO Exception" + "\n");
   }
 }
Ejemplo n.º 8
0
  public static void main(final String[] args) {

    File logdir = new File(LOG_DIR);
    if (!logdir.exists()) logdir.mkdirs();
    File log = new File(logdir, "client.log");
    // redirect all console output to the file
    try {
      PrintStream out = new PrintStream(new FileOutputStream(log, true), true);
      out.format("[%s] ===== Client started =====%n", timestampf.format(new Date()));
      System.setOut(out);
      System.setErr(out);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    /* Set up the error handler as early as humanly possible. */
    ThreadGroup g = new ThreadGroup("Haven main group");
    String ed;
    if (!(ed = Utils.getprop("haven.errorurl", "")).equals("")) {
      try {
        final haven.error.ErrorHandler hg = new haven.error.ErrorHandler(new java.net.URL(ed));
        hg.sethandler(
            new haven.error.ErrorGui(null) {
              public void errorsent() {
                hg.interrupt();
              }
            });
        g = hg;
      } catch (java.net.MalformedURLException e) {
      }
    }
    Thread main =
        new HackThread(
            g,
            new Runnable() {
              public void run() {
                main2(args);
              }
            },
            "Haven main thread");
    main.start();
  }
Ejemplo n.º 9
0
 /**
  * Draw text in current pen color.
  *
  * @param str Text to output
  * @param x starting x coord
  * @param y starting y coord
  */
 public void drawString(String str, int x, int y) {
   setStateToLocal();
   m_printstream.println(
       xTransform(xScale(x))
           + " "
           + yTransform(yScale(y))
           + " moveto"
           + " ("
           + escape(str)
           + ") show stroke");
 }
Ejemplo n.º 10
0
  private void doExportTimeTree() {
    FileDialog dialog = new FileDialog(this, "Export Time Tree File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      PrintStream ps = null;
      try {
        ps = new PrintStream(file);
        writeTimeTreeFile(ps);
        ps.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing tree file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Ejemplo n.º 11
0
 /**
  * Draw a filled Oval in current pen color.
  *
  * @param x x-axis center of oval
  * @param y y-axis center of oval
  * @param width oval width
  * @param height oval height
  */
 public void fillOval(int x, int y, int width, int height) {
   setStateToLocal();
   m_printstream.println(
       xTransform(xScale(x))
           + " "
           + yTransform(yScale(y))
           + " "
           + xScale(width)
           + " "
           + yScale(height)
           + " true Oval");
 }
Ejemplo n.º 12
0
 /**
  * Draw an outlined rectangle in current pen color.
  *
  * @param x starting x coord
  * @param y starting y coord
  * @param width rectangle width
  * @param height rectangle height
  */
 public void drawRect(int x, int y, int width, int height) {
   setStateToLocal();
   m_printstream.println(
       xTransform(xScale(x))
           + " "
           + yTransform(yScale(y))
           + " "
           + xScale(width)
           + " "
           + yScale(height)
           + " false Rect");
 }
Ejemplo n.º 13
0
 /**
  * Draw a line in current pen color.
  *
  * @param x1 starting x coord
  * @param y1 starting y coord
  * @param x2 ending x coord
  * @param y2 ending y coord
  */
 public void drawLine(int x1, int y1, int x2, int y2) {
   setStateToLocal();
   m_printstream.println(
       xTransform(xScale(x1))
           + " "
           + yTransform(yScale(y1))
           + " moveto "
           + xTransform(xScale(x2))
           + " "
           + yTransform(yScale(y2))
           + " lineto stroke");
 }
    public void applyAction(ActionEvent evt) {
      String fileStr = getArg("file");

      System.out.println("Output string " + fileStr);

      if (FormatProperties.contains(getArg("format"))) {
        if (parent instanceof AlignFrame) {
          AlignFrame af = (AlignFrame) parent;
          String outStr =
              FormatAdapter.get(getArg("format").toUpperCase(), av.getAlignment().getSequences());
          System.out.println(outStr + " " + fileStr);
          try {
            PrintStream ps =
                new PrintStream(new BufferedOutputStream(new FileOutputStream(fileStr)));
            fireStatusEvent("Saving file");

            try {
              Thread.sleep(500);
            } catch (Exception ex2) {
            }
            ps.print(outStr);
            ps.close();

            fireStatusEvent("done");

            fireJalActionEvent(new JalActionEvent(this, this, JalActionEvent.DONE));
          } catch (IOException ex) {
            fireStatusEvent("Can't open file", StatusEvent.ERROR);
            System.out.println("Exception : " + ex);
          }
        } else {
          fireStatusEvent("(Internal Error) Parent isn't Alignment Frame", StatusEvent.ERROR);
        }
      } else {
        fireStatusEvent("Format not yet supported", StatusEvent.ERROR);
      }
    }
Ejemplo n.º 15
0
 /**
  * Draw a filled rectangle with the background color.
  *
  * @param x starting x coord
  * @param y starting y coord
  * @param width rectangle width
  * @param height rectangle height
  */
 public void clearRect(int x, int y, int width, int height) {
   setStateToLocal();
   Color saveColor = getColor();
   setColor(Color.white); // background color for page
   m_printstream.println(
       xTransform(xScale(x))
           + " "
           + yTransform(yScale(y))
           + " "
           + xScale(width)
           + " "
           + yScale(height)
           + " true Rect");
   setColor(saveColor);
 }
Ejemplo n.º 16
0
 private void helpPrintToStream2(PrintStream ps, TreeDisplayable tgt, int indentNum) {
   if (tgt == null) return;
   indent(ps, indentNum);
   ps.println("*====list====*");
   for (int subobjCount = 0; ; subobjCount++) {
     try {
       TreeDisplayable subobj = tgt.getDrawTreeSubobj(subobjCount);
       if (subobj != null && subobj.nodeIsList()) {
         helpPrintToStream2(ps, subobj, indentNum + 1);
       } else {
         helpPrintToStream(ps, subobj, indentNum + 1);
       }
     } catch (TreeDrawException x) {
       break;
     }
   }
 }
Ejemplo n.º 17
0
  private void saveDataToFile(File file) {
    try {
      PrintStream out = new PrintStream(new FileOutputStream(file));

      // Print header line
      out.print("Time");
      for (Sequence seq : seqs) {
        out.print("," + seq.name);
      }
      out.println();

      // Print data lines
      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        for (int i = 0; i < seqs.get(0).size; i++) {
          double excelTime = toExcelTime(times.time(i));
          out.print(String.format(Locale.ENGLISH, "%.6f", excelTime));
          for (Sequence seq : seqs) {
            out.print("," + getFormattedValue(seq.value(i), false));
          }
          out.println();
        }
      }

      out.close();
      JOptionPane.showMessageDialog(
          this,
          Resources.format(
              Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length()));
    } catch (IOException ex) {
      String msg = ex.getLocalizedMessage();
      String path = file.getAbsolutePath();
      if (msg.startsWith(path)) {
        msg = msg.substring(path.length()).trim();
      }
      JOptionPane.showMessageDialog(
          this,
          Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg),
          Messages.FILE_CHOOSER_SAVE_FAILED_TITLE,
          JOptionPane.ERROR_MESSAGE);
    }
  }
Ejemplo n.º 18
0
  public void doit() throws Exception {
    br = new BufferedReader(new FileReader("color.in"));
    ps = new PrintStream(new FileOutputStream("color.sol"));
    // ps = System.out;
    int i, j, k;
    String tokens[];

    for (; ; ) {
      tokens = br.readLine().trim().split("\\s+");
      int n = Integer.parseInt(tokens[0]);
      int r = Integer.parseInt(tokens[1]);
      if (n == 0 && r == 0) break;

      --r;

      Node nodes[] = new Node[n];
      tokens = br.readLine().trim().split("\\s+");
      for (i = 0; i < n; i++) {
        nodes[i] = new Node(i);
        nodes[i].c = Integer.parseInt(tokens[i]);
      }

      for (i = 0; i < n - 1; i++) {
        tokens = br.readLine().trim().split("\\s+");
        int parent = Integer.parseInt(tokens[0]) - 1;
        int child = Integer.parseInt(tokens[1]) - 1;
        nodes[parent].children.add(nodes[child]);
      }

      nodes[r].computeOrdering();

      int sum = 0;
      for (i = 0; i < nodes[r].o.length; i++) {
        sum += nodes[r].o[i] * (i + 1);
      }

      ps.println(sum);
      System.out.println(sum);
    }
  }
Ejemplo n.º 19
0
 /**
  * Set current pen color. Default to black if null.
  *
  * @param c new pen color.
  */
 public void setColor(Color c) {
   if (c != null) {
     m_localGraphicsState.setColor(c);
     if (m_psGraphicsState.getColor().equals(c)) {
       return;
     }
     m_psGraphicsState.setColor(c);
   } else {
     m_localGraphicsState.setColor(Color.black);
     m_psGraphicsState.setColor(getColor());
   }
   m_printstream.print(getColor().getRed() / 255.0);
   m_printstream.print(" ");
   m_printstream.print(getColor().getGreen() / 255.0);
   m_printstream.print(" ");
   m_printstream.print(getColor().getBlue() / 255.0);
   m_printstream.println(" setrgbcolor");
 }
Ejemplo n.º 20
0
 /** Clone a PostscriptGraphics object */
 public Graphics create() {
   if (DEBUG) m_printstream.println("%create");
   PostscriptGraphics psg = new PostscriptGraphics(this);
   return (psg);
 }
Ejemplo n.º 21
0
 // --------------------------------------------------
 public void send() {
   os.println(commandArea.getText());
 }
Ejemplo n.º 22
0
 public void dataout(String data) {
   theOutputStream.println(data);
 }
Ejemplo n.º 23
0
  /** Output postscript header to PrintStream, including helper macros. */
  private void Header() {
    m_printstream.println("%!PS-Adobe-3.0 EPSF-3.0");
    m_printstream.println(
        "%%BoundingBox: 0 0 " + xScale(m_extent.width) + " " + yScale(m_extent.height));
    m_printstream.println("%%CreationDate: " + Calendar.getInstance().getTime());

    m_printstream.println("/Oval { % x y w h filled");
    m_printstream.println("gsave");
    m_printstream.println("/filled exch def /h exch def /w exch def /y exch def /x exch def");
    m_printstream.println("x w 2 div add y h 2 div sub translate");
    m_printstream.println("1 h w div scale");
    m_printstream.println("filled {0 0 moveto} if");
    m_printstream.println("0 0 w 2 div 0 360 arc");
    m_printstream.println("filled {closepath fill} {stroke} ifelse grestore} bind def");

    m_printstream.println("/Rect { % x y w h filled");
    m_printstream.println("/filled exch def /h exch def /w exch def /y exch def /x exch def");
    m_printstream.println("newpath ");
    m_printstream.println("x y moveto");
    m_printstream.println("w 0 rlineto");
    m_printstream.println("0 h neg rlineto");
    m_printstream.println("w neg 0 rlineto");
    m_printstream.println("closepath");
    m_printstream.println("filled {fill} {stroke} ifelse} bind def");

    m_printstream.println("%%BeginProlog\n%%EndProlog");
    m_printstream.println("%%Page 1 1");
    setFont(null); // set to default
    setColor(null); // set to default
    setStroke(null); // set to default
  }
Ejemplo n.º 24
0
  private void dumpEditorMarkupAndSelection(PrintStream dumpStream) {
    dumpStream.println(mySearchResults.getFindModel());
    if (myReplacementPreviewText != null) {
      dumpStream.println("--");
      dumpStream.println("Replacement Preview: " + myReplacementPreviewText);
    }
    dumpStream.println("--");

    Editor editor = mySearchResults.getEditor();

    RangeHighlighter[] highlighters = editor.getMarkupModel().getAllHighlighters();
    List<Pair<Integer, Character>> ranges = new ArrayList<Pair<Integer, Character>>();
    for (RangeHighlighter highlighter : highlighters) {
      ranges.add(new Pair<Integer, Character>(highlighter.getStartOffset(), '['));
      ranges.add(new Pair<Integer, Character>(highlighter.getEndOffset(), ']'));
    }

    SelectionModel selectionModel = editor.getSelectionModel();

    if (selectionModel.getSelectionStart() != selectionModel.getSelectionEnd()) {
      ranges.add(new Pair<Integer, Character>(selectionModel.getSelectionStart(), '<'));
      ranges.add(new Pair<Integer, Character>(selectionModel.getSelectionEnd(), '>'));
    }
    ranges.add(new Pair<Integer, Character>(-1, '\n'));
    ranges.add(new Pair<Integer, Character>(editor.getDocument().getTextLength() + 1, '\n'));
    ContainerUtil.sort(
        ranges,
        new Comparator<Pair<Integer, Character>>() {
          @Override
          public int compare(Pair<Integer, Character> pair, Pair<Integer, Character> pair2) {
            int res = pair.first - pair2.first;
            if (res == 0) {

              Character c1 = pair.second;
              Character c2 = pair2.second;
              if (c1 == '<' && c2 == '[') {
                return 1;
              } else if (c1 == '[' && c2 == '<') {
                return -1;
              }
              return c1.compareTo(c2);
            }
            return res;
          }
        });

    Document document = editor.getDocument();
    for (int i = 0; i < ranges.size() - 1; ++i) {
      Pair<Integer, Character> pair = ranges.get(i);
      Pair<Integer, Character> pair1 = ranges.get(i + 1);
      dumpStream.print(
          pair.second
              + document.getText(
                  TextRange.create(
                      Math.max(pair.first, 0), Math.min(pair1.first, document.getTextLength()))));
    }
    dumpStream.println("\n--");

    if (NotFound) {
      dumpStream.println("Not Found");
      dumpStream.println("--");
      NotFound = false;
    }

    for (RangeHighlighter highlighter : highlighters) {
      dumpStream.println(highlighter + " : " + highlighter.getTextAttributes());
    }
    dumpStream.println("------------");
  }
Ejemplo n.º 25
0
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }
Ejemplo n.º 26
0
 private static void indent(PrintStream ps, int n) {
   for (int i = 0; i < n; i++) ps.print(" ");
 }
Ejemplo n.º 27
0
 void setPassword() throws IOException {
   PrintStream ps = new PrintStream(new FileOutputStream("password.txt"));
   ps.println(password);
   ps.close();
 }
Ejemplo n.º 28
0
 public void saveUnsaved() throws SaveAbortedException {
   if (!saved) {
     int option = 0;
     if (loadedFile == null)
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to UNTITLED?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     else
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to " + loadedFile.getName() + "?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) {
       if (loadedFile == null) // SAVE NEW FILE
       {
         if (nameTF.getText().equals("")) {
           JOptionPane.showMessageDialog(
               this,
               new JLabel("Please type in the Scale Name"),
               "Warning",
               JOptionPane.WARNING_MESSAGE);
           throw new SaveAbortedException();
         }
         fileChooser.setFileFilter(filter);
         int option2 = fileChooser.showSaveDialog(this);
         if (option2 == JFileChooser.APPROVE_OPTION) {
           File target = fileChooser.getSelectedFile();
           try {
             PrintStream stream = new PrintStream(new FileOutputStream(target), true);
             save(stream);
             stream.close();
           } catch (Exception ex) {
             JOptionPane.showMessageDialog(
                 this,
                 new JLabel("Error: " + ex.getMessage()),
                 "Error",
                 JOptionPane.ERROR_MESSAGE);
           }
         } else throw new SaveAbortedException();
         ;
       } else // save LOADED FILE
       {
         try {
           PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true);
           save(stream);
           stream.close();
         } catch (Exception ex) {
           JOptionPane.showMessageDialog(
               this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
         }
       }
     } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException();
     ;
   }
 }
Ejemplo n.º 29
0
 /** Finalizes output file. */
 public void finished() {
   m_printstream.flush();
 }
Ejemplo n.º 30
0
  /**
   * PS see http://astronomy.swin.edu.au/~pbourke/geomformats/postscript/ Java
   * http://show.docjava.com:8086/book/cgij/doc/ip/graphics/SimpleImageFrame.java.html
   */
  public boolean drawImage(
      Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
    try {
      // get data from image
      int[] pixels = new int[width * height];
      PixelGrabber grabber = new PixelGrabber(img, 0, 0, width, height, pixels, 0, width);
      grabber.grabPixels();
      ColorModel model = ColorModel.getRGBdefault();

      // print data to ps
      m_printstream.println("gsave");
      m_printstream.println(
          xTransform(xScale(x)) + " " + (yTransform(yScale(y)) - yScale(height)) + " translate");
      m_printstream.println(xScale(width) + " " + yScale(height) + " scale");
      m_printstream.println(
          width + " " + height + " " + "8" + " [" + width + " 0 0 " + (-height) + " 0 " + height
              + "]");
      m_printstream.println("{<");

      int index;
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          index = i * width + j;
          m_printstream.print(toHex(model.getRed(pixels[index])));
          m_printstream.print(toHex(model.getGreen(pixels[index])));
          m_printstream.print(toHex(model.getBlue(pixels[index])));
        }
        m_printstream.println();
      }

      m_printstream.println(">}");
      m_printstream.println("false 3 colorimage");
      m_printstream.println("grestore");
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }