/** @param presentationModel A presentation model with panel's logic. */
  public ImageRenderingPanel(ImagePresentationModel presentationModel) {
    if (presentationModel == null)
      throw new IllegalArgumentException("presentationModel cannot be null.");

    mUIModel = presentationModel;
    mUIModel.addListener(
        new Listener() {
          @Override
          public void onVisibleImageContentUpdate() {
            SwingUtilities.invokeLater(() -> repaint());
          }

          @Override
          public void onImageChange() {
            SwingUtilities.invokeLater(() -> repaint());
          }
        });

    MouseHandler handler = new MouseHandler();

    super.addMouseListener(handler);
    super.addMouseMotionListener(handler);
    super.addMouseWheelListener(handler);
    super.addComponentListener(new ResizeHandler());
  }
Example #2
0
  private void initZoomer(ImageIcon imgIcon) {

    _fullSizeImgIcon = imgIcon;

    this.setTitle(
        _titleBarStartTxt
            + ": Initial Size ("
            + imgIcon.getIconWidth()
            + "x"
            + imgIcon.getIconHeight()
            + "). Full size: "
            + imgIcon.getImage().getWidth(null)
            + "x"
            + imgIcon.getImage().getHeight(null)
            + ".");

    _panel = new JPanel();
    _panel.setBackground(Color.BLACK);
    _panel.setLayout(new BorderLayout());

    _label = new JLabel(_fullSizeImgIcon);
    _panel.add(_label, BorderLayout.CENTER);
    _mouseHandler = new ZoomMouseClickAndWheelListener();
    _panel.addMouseWheelListener(_mouseHandler);
    _panel.addMouseListener(_mouseHandler);
    _panel.addMouseMotionListener(_mouseHandler);

    // _panel.setSize(...

    // Make sure resources are deallocated
    // when window is closed:
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    _scrollPane = new JScrollPane(_panel);
    _scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    _scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.add(_scrollPane);

    ZoomAction zoomUpAction = new ZoomUpAction();
    ZoomAction zoomDownAction = new ZoomDownAction();
    WindowCloseAction winCloseAction = new Misc().new WindowCloseAction(this);

    Misc.bindKey(_panel, "control PLUS", zoomUpAction);
    Misc.bindKey(_panel, "control EQUALS", zoomUpAction);
    Misc.bindKey(_panel, "control shift EQUALS", zoomUpAction);

    Misc.bindKey(_panel, "control MINUS", zoomDownAction);
    Misc.bindKey(_panel, "control shift MINUS", zoomDownAction);

    Misc.bindKey(this, "control W", winCloseAction);
    Misc.bindKey(
        this,
        "F1",
        new ShowHelpAction("To do in Zoomer Window", "HelpFiles/zoomerHelp.html", this));

    // Center the window on the screen.
    this.setLocationRelativeTo(null);

    this.setVisible(true);
    pack();
    addWindowListener(new ZoomWindowListener());
    requestFocus();
  }
  public JavaMouse(JPanel panel) {
    panel.addMouseListener(
        new java.awt.event.MouseAdapter() {
          @Override
          public void mousePressed(java.awt.event.MouseEvent e) {
            buttons[e.getButton() - 1] = true;
            MouseEvent event = createEvent(e, true);
            for (MouseListener listener : listeners) {
              listener.mouseButtonPressed(event);
            }
          }

          @Override
          public void mouseReleased(java.awt.event.MouseEvent e) {
            buttons[e.getButton() - 1] = false;
            MouseEvent event = createEvent(e, false);
            for (MouseListener listener : listeners) {
              listener.mouseButtonReleased(event);
            }
          }

          @Override
          public void mouseClicked(java.awt.event.MouseEvent e) {
            MouseEvent event = createEvent(e, false);
            for (MouseListener listener : listeners) {
              listener.mouseButtonClicked(event);
            }
          }
        });
    panel.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseMoved(java.awt.event.MouseEvent e) {
            x = e.getX();
            y = e.getY();
            MouseEvent event = createEvent(e, false);
            for (MouseListener listener : listeners) {
              listener.mouseMoved(event);
            }
          }

          @Override
          public void mouseDragged(java.awt.event.MouseEvent e) {
            x = e.getX();
            y = e.getY();
            MouseEvent event = createEvent(e, true);
            for (MouseListener listener : listeners) {
              listener.mouseDragged(event);
            }
          }
        });
    panel.addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
            scroll += e.getPreciseWheelRotation();
            MouseWheelEvent event =
                new MouseWheelEvent(
                    e.getPreciseWheelRotation(), e.getX(), e.getY(), JavaUtil.getEventMods(e));
            for (MouseListener listener : listeners) {
              listener.mouseScrolled(event);
            }
          }
        });
  }
Example #4
0
  public void setContents() {
    String name = this.name.toLowerCase();
    panelArea.setCodeFoldingEnabled(true);
    panelArea.setAntiAliasingEnabled(true);
    RTextScrollPane scrollPane = new RTextScrollPane(panelArea);
    panelArea.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent e) {
            if ((e.getKeyCode() == KeyEvent.VK_F)
                && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
              field.requestFocus();
            }

            BytecodeViewer.checkHotKey(e);
          }

          @Override
          public void keyReleased(KeyEvent arg0) {}

          @Override
          public void keyTyped(KeyEvent arg0) {}
        });

    String contentsS = new String(contents);

    if (!isPureAscii(contentsS)) {
      if (name.endsWith(".png")
          || name.endsWith(".jpg")
          || name.endsWith(".jpeg")
          || name.endsWith(".gif")
          || name.endsWith(".tif")
          || name.endsWith(".bmp")) {
        canRefresh = true;
        try {
          image = ImageIO.read(new ByteArrayInputStream(contents)); // gifs fail cause of this
          JLabel label = new JLabel("", new ImageIcon(image), JLabel.CENTER);
          panel2.add(label, BorderLayout.CENTER);
          panel2.addMouseWheelListener(
              new MouseWheelListener() {
                @Override
                public void mouseWheelMoved(MouseWheelEvent e) {
                  int notches = e.getWheelRotation();
                  if (notches < 0) {
                    image =
                        Scalr.resize(
                            image,
                            Scalr.Method.SPEED,
                            image.getWidth() + 10,
                            image.getHeight() + 10);
                  } else {
                    image =
                        Scalr.resize(
                            image,
                            Scalr.Method.SPEED,
                            image.getWidth() - 10,
                            image.getHeight() - 10);
                  }
                  panel2.removeAll();
                  JLabel label = new JLabel("", new ImageIcon(image), JLabel.CENTER);
                  panel2.add(label, BorderLayout.CENTER);
                  panel2.updateUI();
                }
              });
          return;
        } catch (Exception e) {
          new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
        }
      } else {
        JHexEditor hex = new JHexEditor(contents);
        panel2.add(hex);
        return;
      }
    }

    if (name.endsWith(".xml") || contentsS.startsWith("<?xml") || contentsS.startsWith(("<xml"))) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".py") || name.endsWith(".python")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".rb") || name.endsWith(".ruby")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_RUBY);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".java")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".html")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".css")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".properties") || name.endsWith(".mf") || name.endsWith(".sf")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PROPERTIES_FILE);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".php") || contentsS.startsWith("<?php")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PHP);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".js")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".bat")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_WINDOWS_BATCH);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".sh")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_UNIX_SHELL);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".c")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".cpp")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".scala")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SCALA);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".clojure")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CLOJURE);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".groovy")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".lua")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LUA);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".sql")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".json")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
      panelArea.setText(contentsS);
    } else if (name.endsWith(".jsp")) {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSP);
      panelArea.setText(contentsS);
    } else {
      panelArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
      panelArea.setText(contentsS);
    }

    panelArea.setCaretPosition(0);
    scrollPane.setColumnHeaderView(panel);
    panel2.add(scrollPane);
  }