public void generarFondo(Component componente) {
    boolean dibujarFondo = false;
    Rectangle med = this.getBounds();
    Rectangle areaDibujo = this.getBounds();
    BufferedImage tmp;
    GraphicsConfiguration gc =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    if (Principal.fondoBlur) {
      dibujarFondo = true;
    }
    if (dibujarFondo) {
      JRootPane root = SwingUtilities.getRootPane(this);
      blurBuffer = GraphicsUtilities.createCompatibleImage(Principal.sysAncho, Principal.sysAlto);
      Graphics2D g2 = blurBuffer.createGraphics();
      g2.setClip(med);
      blurBuffer = blurBuffer.getSubimage(med.x, med.y, med.width, med.height);
      ((Escritorio) Principal.getEscritorio()).getFrameEscritorio().paint(g2);
      g2.dispose();
      backBuffer = blurBuffer;
      // blurBuffer = toGrayScale(blurBuffer);
      blurBuffer = GraphicsUtilities.createThumbnailFast(blurBuffer, getWidth() / 2);
      blurBuffer = new GaussianBlurFilter(4).filter(blurBuffer, null);
      g2 = (Graphics2D) blurBuffer.getGraphics();
      g2.setColor(new Color(0, 0, 0, 195));
      g2.fillRect(0, 0, Principal.sysAncho, Principal.sysAlto);
      listo = true;
    }
  }
Beispiel #2
0
  /** {@inheritDoc} */
  @Override
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) {
      dst = createCompatibleDestImage(src, null);
    }

    int width = src.getWidth();
    int height = src.getHeight();

    int[] pixels = new int[width * height];
    GraphicsUtilities.getPixels(src, 0, 0, width, height, pixels);
    mixColor(pixels);
    GraphicsUtilities.setPixels(dst, 0, 0, width, height, pixels);

    return dst;
  }
  private static BufferedImage convertTo9Patch(BufferedImage image) {
    BufferedImage buffer =
        GraphicsUtilities.createTranslucentCompatibleImage(
            image.getWidth() + 2, image.getHeight() + 2);

    Graphics2D g2 = buffer.createGraphics();
    g2.drawImage(image, 1, 1, null);
    g2.dispose();

    return buffer;
  }
  /**
   * LEGACY METHOD to run older versions of Android Layoutlib. ==== DO NOT CHANGE ====
   *
   * <p>Loads a 9 patch or regular bitmap.
   *
   * @param stream the {@link InputStream} of the file to load.
   * @param is9Patch whether the file represents a 9-patch
   * @param convert if <code>true</code>, non 9-patch bitmap will be converted into a 9 patch. If
   *     <code>false</code> and the bitmap is not a 9 patch, the method will return <code>null
   *     </code>.
   * @return a {@link NinePatch} or <code>null</code>.
   * @throws IOException
   */
  public static NinePatch load(InputStream stream, boolean is9Patch, boolean convert)
      throws IOException {
    BufferedImage image = null;
    try {
      image = GraphicsUtilities.loadCompatibleImage(stream);
    } catch (MalformedURLException e) {
      // really this shouldn't be happening since we're not creating the URL manually.
      return null;
    }

    return load(image, is9Patch, convert);
  }
  /**
   * Returns the reflection of the source image. The appearance of the reflection is defined by the
   * opacity, the length and the blur properties. *
   *
   * <p>The width of the generated image will be augmented when {@link #isBlurEnabled()} is true.
   * The generated image will have the width of the source image plus twice the effective blur
   * radius (see {@link #getEffectiveBlurRadius()}). The default blur radius is 1 so the width will
   * be augmented by 6. You might need to take this into account at drawing time.
   *
   * <p>The returned image height depends on the value returned by {@link #getLength()} and {@link
   * #getEffectiveBlurRadius()}. For instance, if the length is 0.5 (or 50%) and the source image is
   * 480 pixels high, then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.
   *
   * <p>The returned image contains <strong>only</strong> the reflection. You will have to append it
   * to the source image to produce the illusion of a reflective environement. The method {@link
   * #appendReflection(java.awt.image.BufferedImage)} provides an easy way to create an image
   * containing both the source and the reflection.
   *
   * @param image the source image
   * @return the reflection of the source image
   * @see #appendReflection(java.awt.image.BufferedImage)
   */
  public BufferedImage createReflection(BufferedImage image) {
    if (length == 0.0f) {
      return GraphicsUtilities.createCompatibleTranslucentImage(1, 1);
    }

    int blurOffset = isBlurEnabled() ? stackBlurFilter.getEffectiveRadius() : 0;
    int height = (int) (image.getHeight() * length);

    BufferedImage buffer =
        GraphicsUtilities.createCompatibleTranslucentImage(
            image.getWidth() + blurOffset * 2, height + blurOffset * 2);
    Graphics2D g2 = buffer.createGraphics();

    try {
      g2.translate(0, image.getHeight());
      g2.scale(1.0, -1.0);

      g2.drawImage(image, blurOffset, -blurOffset, null);

      g2.scale(1.0, -1.0);
      g2.translate(0, -image.getHeight());

      g2.setComposite(AlphaComposite.DstIn);
      g2.setPaint(
          new GradientPaint(
              0.0f,
              0.0f,
              new Color(0.0f, 0.0f, 0.0f, getOpacity()),
              0.0f,
              buffer.getHeight(),
              new Color(0.0f, 0.0f, 0.0f, 0.0f),
              true));
      g2.fillRect(0, 0, buffer.getWidth(), buffer.getHeight());
    } finally {
      g2.dispose();
    }

    return isBlurEnabled() ? stackBlurFilter.filter(buffer, null) : buffer;
  }
Beispiel #6
0
  public static Shape generateShapeFromText(Font font, String string) {
    BufferedImage img = GraphicsUtilities.createCompatibleTranslucentImage(1, 1);
    Graphics2D g2 = img.createGraphics();

    try {
      GlyphVector vect = font.createGlyphVector(g2.getFontRenderContext(), string);
      Shape shape = vect.getOutline(0f, (float) -vect.getVisualBounds().getY());

      return shape;
    } finally {
      g2.dispose();
    }
  }
  /**
   * LEGACY METHOD to run older versions of Android Layoutlib. ==== DO NOT CHANGE ====
   *
   * <p>Loads a 9 patch or regular bitmap.
   *
   * @param fileUrl the URL of the file to load.
   * @param convert if <code>true</code>, non 9-patch bitmap will be converted into a 9 patch. If
   *     <code>false</code> and the bitmap is not a 9 patch, the method will return <code>null
   *     </code>.
   * @return a {@link NinePatch} or <code>null</code>.
   * @throws IOException
   */
  public static NinePatch load(URL fileUrl, boolean convert) throws IOException {
    BufferedImage image = null;
    try {
      image = GraphicsUtilities.loadCompatibleImage(fileUrl);
    } catch (MalformedURLException e) {
      // really this shouldn't be happening since we're not creating the URL manually.
      return null;
    }

    boolean is9Patch = fileUrl.getPath().toLowerCase(Locale.US).endsWith(EXTENSION_9PATCH);

    return load(image, is9Patch, convert);
  }
  /**
   * Returns the source image and its reflection. The appearance of the reflection is defined by the
   * opacity, the length and the blur properties. *
   *
   * <p>The width of the generated image will be augmented when {@link #isBlurEnabled()} is true.
   * The generated image will have the width of the source image plus twice the effective blur
   * radius (see {@link #getEffectiveBlurRadius()}). The default blur radius is 1 so the width will
   * be augmented by 6. You might need to take this into account at drawing time.
   *
   * <p>The returned image height depends on the value returned by {@link #getLength()} and {@link
   * #getEffectiveBlurRadius()}. For instance, if the length is 0.5 (or 50%) and the source image is
   * 480 pixels high, then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.
   *
   * <p>You can create only the reflection by calling {@link
   * #createReflection(java.awt.image.BufferedImage)}.
   *
   * @param image the source image
   * @return the source image with its reflection below
   * @see #createReflection(java.awt.image.BufferedImage)
   */
  public BufferedImage appendReflection(BufferedImage image) {
    BufferedImage reflection = createReflection(image);
    BufferedImage buffer =
        GraphicsUtilities.createCompatibleTranslucentImage(
            reflection.getWidth(), image.getHeight() + reflection.getHeight());
    Graphics2D g2 = buffer.createGraphics();

    try {
      int effectiveRadius = isBlurEnabled() ? stackBlurFilter.getEffectiveRadius() : 0;
      g2.drawImage(image, effectiveRadius, 0, null);
      g2.drawImage(reflection, 0, image.getHeight() - effectiveRadius, null);
    } finally {
      g2.dispose();
    }

    reflection.flush();

    return buffer;
  }
  public MemoryPanel(final Debugger debugger, boolean is64Bit) {
    super();
    this.debugger = debugger;
    this.is64Bit = is64Bit;
    if (is64Bit) {
      addressSize = 8;
      unmappedAddrString = "??????????????????";
    } else {
      addressSize = 4;
      unmappedAddrString = "??????????";
    }
    setLayout(new BorderLayout());
    setupScrollBar();
    add(scrollBar, BorderLayout.EAST);

    model =
        new AbstractTableModel() {
          public int getRowCount() {
            return numVisibleRows;
          }

          public int getColumnCount() {
            return 2;
          }

          public Object getValueAt(int row, int column) {
            switch (column) {
              case 0:
                return bigIntToHexString(
                    startVal.add(new BigInteger(Integer.toString((row * addressSize)))));
              case 1:
                {
                  try {
                    Address addr =
                        bigIntToAddress(
                            startVal.add(new BigInteger(Integer.toString((row * addressSize)))));
                    if (addr != null) {
                      return addressToString(addr.getAddressAt(0));
                    }
                    return unmappedAddrString;
                  } catch (UnmappedAddressException e) {
                    return unmappedAddrString;
                  }
                }
              default:
                throw new RuntimeException("Column " + column + " out of bounds");
            }
          }

          public boolean isCellEditable(int row, int col) {
            return false;
          }
        };

    // View with JTable with no header
    table = new JTable(model);
    table.setTableHeader(null);
    table.setShowGrid(false);
    table.setIntercellSpacing(new Dimension(0, 0));
    table.setCellSelectionEnabled(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    table.setDragEnabled(true);
    Font font = GraphicsUtilities.lookupFont("Courier");
    if (font == null) {
      throw new RuntimeException("Error looking up monospace font Courier");
    }
    table.setFont(font);

    // Export proper data.
    // We need to keep our own notion of the selection in order to
    // properly export data, since the selection can go beyond the
    // visible area on the screen (and since the table's model doesn't
    // back all of those slots).
    // Code thanks to Shannon.Hickey@sfbay
    table.setTransferHandler(
        new TransferHandler() {
          protected Transferable createTransferable(JComponent c) {
            JTable table = (JTable) c;
            if (haveSelection()) {
              StringBuffer buf = new StringBuffer();
              int iDir = (getRowAnchor() < getRowLead() ? 1 : -1);
              int jDir = (getColAnchor() < getColLead() ? 1 : -1);

              for (int i = getRowAnchor(); i != getRowLead() + iDir; i += iDir) {
                for (int j = getColAnchor(); j != getColLead() + jDir; j += jDir) {
                  Object val = model.getValueAt(i, j);
                  buf.append(val == null ? "" : val.toString());
                  if (j != getColLead()) {
                    buf.append("\t");
                  }
                }
                if (i != getRowLead()) {
                  buf.append("\n");
                }
              }

              return new StringTransferable(buf.toString());
            }
            return null;
          }

          public int getSourceActions(JComponent c) {
            return COPY;
          }

          public boolean importData(JComponent c, Transferable t) {
            if (canImport(c, t.getTransferDataFlavors())) {
              try {
                String str = (String) t.getTransferData(DataFlavor.stringFlavor);
                handleImport(c, str);
                return true;
              } catch (UnsupportedFlavorException ufe) {
              } catch (IOException ioe) {
              }
            }

            return false;
          }

          public boolean canImport(JComponent c, DataFlavor[] flavors) {
            for (int i = 0; i < flavors.length; i++) {
              if (DataFlavor.stringFlavor.equals(flavors[i])) {
                return true;
              }
            }
            return false;
          }

          private void handleImport(JComponent c, String str) {
            // do whatever you want with the string here
            try {
              makeVisible(debugger.parseAddress(str));
              clearSelection();
              table.clearSelection();
            } catch (NumberFormatException e) {
              System.err.println("Unable to parse address \"" + str + "\"");
            }
          }
        });

    // Supporting keyboard scrolling
    // See src/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java,
    // search for Table.AncestorInputMap

    // Actions to override:
    // selectPreviousRow, selectNextRow,
    // scrollUpChangeSelection, scrollDownChangeSelection,
    // selectPreviousRowExtendSelection, selectNextRowExtendSelection,
    // scrollDownExtendSelection, scrollUpExtendSelection (Shift-PgDn/PgUp)

    ActionMap map = table.getActionMap();

    // Up arrow
    installActionWrapper(
        map,
        "selectPreviousRow",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            if (table.getSelectedRow() == 0) {
              scrollBar.scrollUpOrLeft();
              table.setRowSelectionInterval(0, 0);
            } else {
              super.actionPerformed(e);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Down arrow
    installActionWrapper(
        map,
        "selectNextRow",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            int row = table.getSelectedRow();
            if (row >= numUsableRows) {
              scrollBar.scrollDownOrRight();
              table.setRowSelectionInterval(row, row);
            } else {
              super.actionPerformed(e);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Page up
    installActionWrapper(
        map,
        "scrollUpChangeSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            int row = table.getSelectedRow();
            scrollBar.pageUpOrLeft();
            if (row >= 0) {
              table.setRowSelectionInterval(row, row);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Page down
    installActionWrapper(
        map,
        "scrollDownChangeSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            clearSelection();
            int row = table.getSelectedRow();
            scrollBar.pageDownOrRight();
            if (row >= 0) {
              table.setRowSelectionInterval(row, row);
            }
            maybeGrabSelection();
            endUpdate();
          }
        });
    // Shift + Up arrow
    installActionWrapper(
        map,
        "selectPreviousRowExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() - 1;
            int newAnchor = getRowAnchor();
            if (newLead < 0) {
              scrollBar.scrollUpOrLeft();
              ++newLead;
              ++newAnchor;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Left arrow
    installActionWrapper(
        map,
        "selectPreviousColumnExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
            }
            int newLead = Math.max(0, getColLead() - 1);
            setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead);
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Down arrow
    installActionWrapper(
        map,
        "selectNextRowExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() + 1;
            int newAnchor = getRowAnchor();
            if (newLead > numUsableRows) {
              scrollBar.scrollDownOrRight();
              --newLead;
              --newAnchor;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Right arrow
    installActionWrapper(
        map,
        "selectNextColumnExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
            }
            int newLead = Math.min(model.getColumnCount() - 1, getColLead() + 1);
            setSelection(getRowAnchor(), getRowLead(), getColAnchor(), newLead);
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Page up
    installActionWrapper(
        map,
        "scrollUpExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() - numUsableRows;
            int newAnchor = getRowAnchor();
            if (newLead < 0) {
              scrollBar.pageUpOrLeft();
              newLead += numUsableRows;
              newAnchor += numUsableRows;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });
    // Shift + Page down
    installActionWrapper(
        map,
        "scrollDownExtendSelection",
        new ActionWrapper() {
          public void actionPerformed(ActionEvent e) {
            beginUpdate();
            if (!haveAnchor()) {
              setAnchorFromTable();
              setLeadFromTable();
              //            setAnchor(table.getSelectedRow());
              //            setLead(table.getSelectedRow());
            }
            int newLead = getRowLead() + numUsableRows;
            int newAnchor = getRowAnchor();
            if (newLead > numUsableRows) {
              scrollBar.pageDownOrRight();
              newLead -= numUsableRows;
              newAnchor -= numUsableRows;
            }
            setSelection(newAnchor, newLead, getColAnchor(), getColLead());
            //          printSelection();
            endUpdate();
          }
        });

    // Clear our notion of selection upon mouse press
    table.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            if (shouldIgnore(e)) {
              return;
            }
            // Make shift-clicking work properly
            if (e.isShiftDown()) {
              maybeGrabSelection();
              return;
            }
            //          System.err.println("  Clearing selection on mouse press");
            clearSelection();
          }
        });

    // Watch for mouse going out of bounds
    table.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            if (shouldIgnore(e)) {
              //            System.err.println("  (Ignoring consumed mouse event)");
              return;
            }

            // Look for drag events outside table and scroll if necessary
            Point p = e.getPoint();
            if (table.rowAtPoint(p) == -1) {
              // See whether we are above or below the table
              Rectangle rect = new Rectangle();
              getBounds(rect);
              beginUpdate();
              if (p.y < rect.y) {
                //              System.err.println("  Scrolling up due to mouse event");
                // Scroll up
                scrollBar.scrollUpOrLeft();
                setSelection(getRowAnchor(), 0, getColAnchor(), getColLead());
              } else {
                //              System.err.println("  Scrolling down due to mouse event");
                // Scroll down
                scrollBar.scrollDownOrRight();
                setSelection(getRowAnchor(), numUsableRows, getColAnchor(), getColLead());
              }
              //            printSelection();
              endUpdate();
            } else {
              maybeGrabSelection();
            }
          }
        });

    add(table, BorderLayout.CENTER);

    // Make sure we recompute number of visible rows
    addComponentListener(
        new ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
            recomputeNumVisibleRows();
            constrain();
          }
        });
    addHierarchyListener(
        new HierarchyListener() {
          public void hierarchyChanged(HierarchyEvent e) {
            recomputeNumVisibleRows();
            constrain();
          }
        });
    updateFromScrollBar();
  }