Exemplo n.º 1
0
 public void takeScreenshotOfDocument(String documentFileName) {
   File documentFile = new File(documentFileName);
   File documentDirectory = documentFile.getParentFile();
   String imageName = FileUtils.getBaseName(documentFile.getName()) + ".png";
   File screenshotFile = new File(documentDirectory, imageName);
   NodeBoxDocument doc = NodeBoxDocument.load(documentFile);
   addDocument(doc);
   doc.setVisible(true);
   doc.takeScreenshot(screenshotFile);
   doc.close();
 }
Exemplo n.º 2
0
  /**
   * Save the document to a file.
   *
   * @see #write
   */
  public boolean save(String filename) {

    try {
      setFilename(filename);

      // write to tmp file
      File tmpfile = File.createTempFile("gwb", null);
      write(new FileOutputStream(tmpfile));

      // copy to dest file and delete tmp file
      FileUtils.copy(tmpfile, new File(filename));
      tmpfile.delete();

      //

      //
      fireDocumentInit();
      return true;
    } catch (Exception e) {
      LogUtils.report(e);
      return false;
    }
  }
Exemplo n.º 3
0
 public boolean isLocal() {
   return dbURL == null && !FileUtils.isRemote(path) && !Ga4ghAPIHelper.RESOURCE_TYPE.equals(type);
 }
Exemplo n.º 4
0
 public static String createLongString() {
   return FileUtils.readToString(ExamplesManager.class, "resources/long.txt");
 }
Exemplo n.º 5
0
 public static String createSmallString() {
   return FileUtils.readToString(ExamplesManager.class, "resources/small.txt");
 }
Exemplo n.º 6
0
 public boolean isLocal() {
   return serverURL == null && !(FileUtils.isRemote(path));
 }
Exemplo n.º 7
0
 private String loadString(JarEntry lastEntry) {
   return FileUtils.readToString(getEntryInputStream(lastEntry));
 }
Exemplo n.º 8
0
  private Component createEntryViewer(JarEntry entry) {
    if (entry.getType().equals(JarEntryType.classEntry)
        || entry.getType().equals(JarEntryType.javaEntry)
        || entry.getType().equals(JarEntryType.fileEntry)) {
      String ext = FileUtils.getFileExtPart(entry.getName(), false).toLowerCase();
      if (GlobalConstants.IMAGE_FORMATS.contains(ext)) {
        // todo A better image viewer (actually a new component - WebImageViewer)

        // Image file viewer
        WebImage image = new WebImage();
        image.setIcon(ImageUtils.loadImage(getEntryInputStream(entry)));

        // Image scroll
        WebScrollPane imageScroll = new WebScrollPane(image, false);
        imageScroll.setVerticalScrollBarPolicy(WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        imageScroll.setHorizontalScrollBarPolicy(WebScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        return imageScroll;
      } else {
        // Source code viewer
        final RSyntaxTextArea source = new RSyntaxTextArea();

        // Syntax style
        boolean libraryCode = false;
        if (ext.equals("java") || ext.equals("class")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
          libraryCode = true;
        } else if (ext.equals("xml")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        } else if (ext.equals("html")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
        } else if (ext.equals("css")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
        } else if (ext.equals("js")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
        } else if (ext.equals("php")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PHP);
        } else if (ext.equals("sql")) {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
        } else {
          source.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
        }

        // Settings
        source.setEditable(false);
        source.setMargin(new Insets(0, 5, 0, 0));
        source.setAntiAliasingEnabled(true);
        source.setUseFocusableTips(true);
        source.setTabSize(4);
        // source.setLineWrap ( true );
        // source.setWrapStyleWord ( true );
        source.setCodeFoldingEnabled(allowCodeFolding.isSelected());
        source.setPaintTabLines(paintTabLines.isSelected());
        source.setWhitespaceVisible(showWhitespaces.isSelected());
        source.setEOLMarkersVisible(showEol.isSelected());
        source.addHyperlinkListener(
            new HyperlinkListener() {
              @Override
              public void hyperlinkUpdate(HyperlinkEvent e) {
                WebUtils.browseSiteSafely(e.getURL().toExternalForm());
              }
            });
        ((RSyntaxTextAreaHighlighter) source.getHighlighter()).setDrawsLayeredHighlights(false);

        // Source code
        source.setText(libraryCode ? loadSource(entry) : loadString(entry));
        source.setCaretPosition(0);

        // "Jump to source"-like action
        source.addMouseListener(
            new MouseAdapter() {
              @Override
              public void mousePressed(MouseEvent e) {
                // todo Fix when clicked in class "MyName" on string "MyName"
                // Additional feature to dive into related classes
                if (SwingUtilities.isMiddleMouseButton(e)
                    || SwingUtils.isCtrl(e) && SwingUtilities.isLeftMouseButton(e)) {
                  int pos = source.getUI().viewToModel(source, e.getPoint());
                  String word = TextUtils.getWord(source.getText(), pos);
                  if (word != null) {
                    JarEntry classByName = jarStructure.findEntryByName(word);
                    if (classByName != null
                        && (classByName.getType().equals(JarEntryType.classEntry)
                            || classByName.getType().equals(JarEntryType.javaEntry))) {
                      updateClassPath(classByName, true);
                    }
                  }
                }
              }
            });

        // Saving opened editor
        synchronized (activeEditorsLock) {
          activeEditors.put(entry, source);
        }

        // Special code viewer scroll pane
        RTextScrollPane sourceScroll = new RTextScrollPane(source);
        sourceScroll.setVerticalScrollBarPolicy(WebScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        ((WebScrollPaneUI) sourceScroll.getUI()).setDrawBorder(false);

        // Source code viewer theme
        loadTheme(theme.getSelectedItem().toString().toLowerCase(), source);

        return sourceScroll;
      }
    }
    return new WebLabel();
  }