Example #1
0
 public static void saveImageResultsToPng(String prefix, ImageSearchHits hits, String queryImage)
     throws IOException {
   LinkedList<BufferedImage> results = new LinkedList<BufferedImage>();
   int width = 0;
   for (int i = 0; i < hits.length(); i++) {
     // hits.score(i)
     // hits.doc(i).get("descriptorImageIdentifier")
     BufferedImage tmp =
         ImageIO.read(new FileInputStream(hits.doc(i).get("descriptorImageIdentifier")));
     //            if (tmp.getHeight() > 200) {
     double factor = 200d / ((double) tmp.getHeight());
     tmp = ImageUtils.scaleImage(tmp, (int) (tmp.getWidth() * factor), 200);
     //            }
     width += tmp.getWidth() + 5;
     results.add(tmp);
   }
   BufferedImage result = new BufferedImage(width, 220, BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = (Graphics2D) result.getGraphics();
   g2.setColor(Color.white);
   g2.setBackground(Color.white);
   g2.clearRect(0, 0, result.getWidth(), result.getHeight());
   g2.setColor(Color.black);
   g2.setFont(Font.decode("\"Arial\", Font.BOLD, 12"));
   int offset = 0;
   int count = 0;
   for (Iterator<BufferedImage> iterator = results.iterator(); iterator.hasNext(); ) {
     BufferedImage next = iterator.next();
     g2.drawImage(next, offset, 20, null);
     g2.drawString(hits.score(count) + "", offset + 5, 12);
     offset += next.getWidth() + 5;
     count++;
   }
   ImageIO.write(
       result, "PNG", new File(prefix + "_" + (System.currentTimeMillis() / 1000) + ".png"));
 }
Example #2
0
  private void doInit() {
    GUIUtils.setAppIcon(this, "burn.png");
    GUIUtils.centerOnScreen(this);
    setVisible(true);

    int W = 28, H = W;
    boolean blur = false;
    float alpha = .7f;

    try {
      btnGetMap.setIcon(ImageUtils.loadScaledBufferedIcon("ok1.png", W, H, blur, alpha));
      btnQuit.setIcon(ImageUtils.loadScaledBufferedIcon("charging.png", W, H, blur, alpha));
    } catch (Exception e) {
      System.out.println(e);
    }

    _setupTask();
  }
Example #3
0
  /**
   * Establishes a call.
   *
   * @param isVideo indicates if a video call should be established.
   * @param isDesktopSharing indicates if a desktopSharing should be established.
   */
  private void call(boolean isVideo, boolean isDesktopSharing) {
    ChatPanel chatPanel = chatContainer.getCurrentChat();

    ChatSession chatSession = chatPanel.getChatSession();

    Class<? extends OperationSet> opSetClass;
    if (isVideo) {
      if (isDesktopSharing) opSetClass = OperationSetDesktopSharingServer.class;
      else opSetClass = OperationSetVideoTelephony.class;
    } else opSetClass = OperationSetBasicTelephony.class;

    List<ChatTransport> telTransports = null;
    if (chatSession != null) telTransports = chatSession.getTransportsForOperationSet(opSetClass);

    List<ChatTransport> contactOpSetSupported;

    contactOpSetSupported = getOperationSetForCapabilities(telTransports, opSetClass);

    List<UIContactDetail> res = new ArrayList<UIContactDetail>();
    for (ChatTransport ct : contactOpSetSupported) {
      HashMap<Class<? extends OperationSet>, ProtocolProviderService> m =
          new HashMap<Class<? extends OperationSet>, ProtocolProviderService>();
      m.put(opSetClass, ct.getProtocolProvider());

      UIContactDetailImpl d =
          new UIContactDetailImpl(
              ct.getName(), ct.getDisplayName(), null, null, null, m, null, ct.getName());
      PresenceStatus status = ct.getStatus();
      byte[] statusIconBytes = status.getStatusIcon();

      if (statusIconBytes != null && statusIconBytes.length > 0) {
        d.setStatusIcon(
            new ImageIcon(
                ImageLoader.getIndexedProtocolImage(
                    ImageUtils.getBytesInImage(statusIconBytes), ct.getProtocolProvider())));
      }

      res.add(d);
    }

    Point location = new Point(callButton.getX(), callButton.getY() + callButton.getHeight());

    SwingUtilities.convertPointToScreen(location, this);

    MetaContact metaContact = GuiActivator.getUIService().getChatContact(chatPanel);
    UIContactImpl uiContact = null;
    if (metaContact != null) uiContact = MetaContactListSource.getUIContact(metaContact);

    CallManager.call(res, uiContact, isVideo, isDesktopSharing, callButton, location);
  }
Example #4
0
  /**
   * Create thumbnail for the image.
   *
   * @param image to scale.
   * @return the thumbnail image.
   */
  private static BufferedImage createThumbnail(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    // Image smaller than the thumbnail size
    if (width < THUMB_WIDTH && height < THUMB_HEIGHT) return image;

    Image i;

    if (width > height) i = image.getScaledInstance(THUMB_WIDTH, -1, Image.SCALE_SMOOTH);
    else i = image.getScaledInstance(-1, THUMB_HEIGHT, Image.SCALE_SMOOTH);

    return ImageUtils.getBufferedImage(i);
  }
Example #5
0
 @Test
 public void generateCaptcha() throws Exception {
   ImageUtils imageUtils = new ImageUtils();
   imageUtils.setPath("captcha");
   imageUtils.setBase("captcha");
   imageUtils.setType("png");
   imageUtils.setDefaultBackground(new Color(1f, 1f, 1f, 0f));
   FileOutputStream os = new FileOutputStream("E:/test/sisda/captcha.png");
   imageUtils.createCaptchaImage("Halo", os);
   os.close();
 }
Example #6
0
  /**
   * Action performed on various action links(buttons).
   *
   * @param e the action.
   */
  public void actionPerformed(ActionEvent e) {
    JButton src = (JButton) e.getSource();

    if (src instanceof SIPCommButton) {
      // Load image
      int index = Integer.parseInt(src.getName());
      BufferedImage image = AvatarStackManager.loadImage(index);

      // Set the new image
      setNewImage(image);
    } else if (src.getName().equals("chooseButton")) {
      // Open the image picker
      Image currentImage = this.avatarImage.getAvatar();

      ImagePickerDialog dialog = new ImagePickerDialog(96, 96);

      byte[] bimage = dialog.showDialog(currentImage);

      if (bimage == null) return;

      // New image
      BufferedImage image = ImageUtils.getBufferedImage(new ImageIcon(bimage).getImage());

      // Store image
      if (this.nextImageIndex == MAX_STORED_IMAGES) {
        // No more place to store images
        // Pop the first element (index 0)
        AvatarStackManager.popFirstImage(MAX_STORED_IMAGES);

        this.nextImageIndex = MAX_STORED_IMAGES - 1;
      }

      // Store the new image on hard drive
      AvatarStackManager.storeImage(image, this.nextImageIndex);

      // Inform protocols about the new image
      setNewImage(image);
    } else if (src.getName().equals("removeButton")) {
      // Removes the current photo.
      setNewImage(null);
    } else if (src.getName().equals("clearButton")) {
      clearRecentImages();
    }

    setVisible(false);
  }
Example #7
0
  @Test
  public void generateText() throws IOException {
    ImageUtils imageUtils = new ImageUtils();
    imageUtils.setPath("captcha");
    imageUtils.setBase("captcha");
    imageUtils.setType("png");
    imageUtils.setDefaultBackground(new Color(1f, 1f, 1f, 0f));
    FileOutputStream os = new FileOutputStream("E:/test/sisda/email.png");
    imageUtils.createTextImage("*****@*****.**", os);

    os.close();
  }
  /**
   * Set the image of the peer
   *
   * @param image new image
   */
  public void setPeerImage(byte[] image) {
    // If the image is still null we try to obtain it from one of the
    // available contact sources.
    if (image == null || image.length <= 0) {
      GuiActivator.getContactList().setSourceContactImage(peerName, photoLabel, 100, 100);
    } else {
      peerImage = ImageUtils.getScaledRoundedIcon(image, 100, 100);
      if (peerImage == null) peerImage = getPhotoLabelIcon();

      if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                photoLabel.setIcon(peerImage);
                photoLabel.repaint();
              }
            });
      } else {
        photoLabel.setIcon(peerImage);
        photoLabel.repaint();
      }
    }
  }
Example #9
0
 @Test
 public void rescale() throws IOException {
   ImageUtils imageUtils = new ImageUtils();
   FileInputStream is = new FileInputStream("E:/test/image/108.jpg");
   BufferedImage image = imageUtils.resizeImage(is, 120, 0);
 }
Example #10
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();
  }