public HDMColdAccountForm(final WalletListPanel walletListPanel) {
    this.walletListPanel = walletListPanel;

    inactiveBackGroundColor = Color.WHITE;
    selected = false;
    panelMain.setOpaque(true);
    panelMain.setFocusable(true);
    panelMain.setBackground(inactiveBackGroundColor);

    if (ColorAndFontConstants.isInverse()) {
      inactiveBackGroundColor =
          new Color(
              Math.min(255, Themes.currentTheme.detailPanelBackground().getRed() + 2 * COLOR_DELTA),
              Math.min(
                  255, Themes.currentTheme.detailPanelBackground().getBlue() + 2 * COLOR_DELTA),
              Math.min(
                  255, Themes.currentTheme.detailPanelBackground().getGreen() + 2 * COLOR_DELTA));
    } else {
      inactiveBackGroundColor =
          new Color(
              Math.max(0, Themes.currentTheme.detailPanelBackground().getRed() - COLOR_DELTA),
              Math.max(0, Themes.currentTheme.detailPanelBackground().getBlue() - COLOR_DELTA),
              Math.max(0, Themes.currentTheme.detailPanelBackground().getGreen() - COLOR_DELTA));
    }
    panelMain.applyComponentOrientation(
        ComponentOrientation.getOrientation(LocaliserUtils.getLocale()));

    updateFromModel();
    panelMain.addMouseListener(
        new WalletMouseListener(this.walletListPanel, HDMColdAccountForm.this));

    setSelected(false);
    setContent();
  }
Exemple #2
0
  public ImagePanel(Kdu_coords viewSize) throws KduException {
    int width = Math.min(viewSize.Get_x(), 1600);
    int height = Math.min(viewSize.Get_y(), 1200);

    setPreferredSize(new Dimension(width, height));

    getInputMap().put(KeyStroke.getKeyStroke("UP"), "pressedUpArrow");
    getActionMap()
        .put(
            "pressedUpArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
    getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "pressedDownArrow");
    getActionMap()
        .put(
            "pressedDownArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
  }
Exemple #3
0
  void MidpointLine(int x0, int y0, int x1, int y1, Graphics g) {
    if (x0 == x1) {
      for (int i = Math.min(y1, y0); i <= Math.max(y1, y0); i++) {
        WritePixel(x0, i, 10, g);
      }
    } else if (y0 == y1) {
      for (int i = Math.min(x1, x0); i <= Math.max(x1, x0); i++) {
        WritePixel(i, y0, 10, g);
      }
    } else {

      int dx = Math.abs(x1 - x0);
      int dy = Math.abs(y1 - y0);
      int d = dx - dy;
      int sx, sy, d2;
      if (x0 < x1) sx = 1;
      else sx = -1;
      if (y0 < y1) sy = 1;
      else sy = -1;
      do {
        WritePixel(x0, y0, 10, g);
        d2 = d * 2;
        if (d2 > -dy) {
          x0 += sx;
          d -= dy;
        }

        if (d2 < dx) {
          d += dx;
          y0 += sy;
        }

      } while (x0 != x1 && y0 != y1);
    }
  }
 public void invokeStep(int x, int y, int anchorX, int anchorY, DrawingView view) {
   Rectangle r = owner().displayBox();
   owner()
       .displayBox(
           new Point(Math.min(r.x + r.width, x), Math.min(r.y + r.height, y)),
           new Point(r.x + r.width, r.y + r.height));
 }
  public static void Label8(float[][] image, int[][] labels) {
    int h = image.length, w = image[0].length;
    DisjointSet ds = new DisjointSet();
    for (int y = 0; y < h; ++y)
      for (int x = 0; x < w; ++x) {
        if (image[y][x] == 0) {
          labels[y][x] = -1;
          continue;
        }

        int minLabel = -1;
        for (int yy = Math.max(0, y - 1); yy <= y; ++yy)
          for (int xx = Math.max(0, x - 1); xx <= Math.min(w - 1, x + 1); ++xx)
            if ((yy < y || xx == x - 1)
                && labels[yy][xx] != -1
                && (minLabel == -1 || labels[yy][xx] < minLabel)) minLabel = labels[yy][xx];

        if (minLabel == -1) labels[y][x] = ds.MakeSet();
        else {
          labels[y][x] = minLabel;
          for (int yy = Math.max(0, y - 1); yy <= y; ++yy)
            for (int xx = Math.max(0, x - 1); xx <= Math.min(w - 1, x + 1); ++xx)
              if ((yy < y || xx == x - 1) && labels[yy][xx] != -1 && labels[yy][xx] != minLabel)
                ds.Union(minLabel, labels[yy][xx]);
        }
      }

    for (int y = 0; y < h; ++y)
      for (int x = 0; x < w; ++x) if (labels[y][x] != -1) labels[y][x] = ds.Find(labels[y][x]);
  }
  /**
   * Current runner for conversion that looks closest to acrobat. The algorithm is a little
   * expensive but it does the best approximation.
   *
   * @param f 4 component values of the cmyk, assumes compoents between 0.0 and 1.0
   * @return valid rgb colour object.
   */
  private static Color alternative2(float[] f) {
    float inCyan = f[3];
    float inMagenta = f[2];
    float inYellow = f[1];
    float inBlack = f[0];

    double c, m, y, aw, ac, am, ay, ar, ag, ab;
    c = Math.min(1.0, inCyan + inBlack);
    m = Math.min(1.0, inMagenta + inBlack);
    y = Math.min(1.0, inYellow + inBlack);
    aw = (1 - c) * (1 - m) * (1 - y);
    ac = c * (1 - m) * (1 - y);
    am = (1 - c) * m * (1 - y);
    ay = (1 - c) * (1 - m) * y;
    ar = (1 - c) * m * y;
    ag = c * (1 - m) * y;
    ab = c * m * (1 - y);

    float outRed = (float) (aw + 0.9137 * am + 0.9961 * ay + 0.9882 * ar);
    float outGreen = (float) (aw + 0.6196 * ac + ay + 0.5176 * ag);
    float outBlue =
        (float) (aw + 0.7804 * ac + 0.5412 * am + 0.0667 * ar + 0.2118 * ag + 0.4863 * ab);

    return new Color(outRed, outGreen, outBlue);
  }
 private int wrapPositionForTabbedTextWithOptimization(
     @NotNull CharSequence text,
     int tabSize,
     int startLineOffset,
     int endLineOffset,
     int targetRangeEndOffset) {
   int width = 0;
   int symbolWidth;
   int result = Integer.MAX_VALUE;
   boolean wrapLine = false;
   for (int i = startLineOffset; i < Math.min(endLineOffset, targetRangeEndOffset); i++) {
     char c = text.charAt(i);
     switch (c) {
       case '\t':
         symbolWidth = tabSize - (width % tabSize);
         break;
       default:
         symbolWidth = 1;
     }
     if (width + symbolWidth + FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS
             >= mySettings.RIGHT_MARGIN
         && (Math.min(endLineOffset, targetRangeEndOffset) - i)
             >= FormatConstants.RESERVED_LINE_WRAP_WIDTH_IN_COLUMNS) {
       // Remember preferred position.
       result = i - 1;
     }
     if (width + symbolWidth >= mySettings.RIGHT_MARGIN) {
       wrapLine = true;
       break;
     }
     width += symbolWidth;
   }
   return wrapLine ? result : -1;
 }
 // the following method added for LegacyTristateCheckBox
 protected void drawSquare(Component c, Graphics g, int x, int y) {
   final int w = Math.min(getIconWidth(), getIconHeight());
   final int h = Math.min(getIconWidth(), getIconHeight());
   int xMargin = w / 3;
   int yMargin = h / 3;
   g.fillRect(x + xMargin, y + yMargin, w - xMargin * 2, h - yMargin * 2);
 }
 private boolean setColumnPreferredSize() {
   boolean sizeCalculated = false;
   Font tableFont = UIManager.getFont("Table.font");
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == GraphTableModel.ROOT_COLUMN) { // thin stripe, or root name, or nothing
       setRootColumnSize(column);
     } else if (i
         == GraphTableModel.COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i == GraphTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int maxWidth = 0;
       for (int row = 0; row < maxRowsToCheck; row++) {
         String value = getModel().getValueAt(row, i).toString();
         maxWidth = Math.max(getFontMetrics(tableFont).stringWidth(value), maxWidth);
         if (!value.isEmpty()) sizeCalculated = true;
       }
       column.setMinWidth(
           Math.min(maxWidth + UIUtil.DEFAULT_HGAP, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == GraphTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
   return sizeCalculated;
 }
Exemple #10
0
 private void setColumnPreferredSize() {
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing
       int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0;
       // NB: all further instructions and their order are important, otherwise the minimum size
       // which is less than 15 won't be applied
       column.setMinWidth(rootWidth);
       column.setMaxWidth(rootWidth);
       column.setPreferredWidth(rootWidth);
     } else if (i
         == AbstractVcsLogTableModel
             .COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i
         == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck);
       column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       Font tableFont = UIManager.getFont("Table.font");
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
 }
 protected void drawImageMosaic(Graphics2D g2) {
   // Break the image up into tiles. Draw each
   //   tile with its own transparency, allowing
   //   the background to show through to varying
   //   degrees.
   int side = 36;
   int width = mImage.getWidth();
   int height = mImage.getHeight();
   for (int y = 0; y < height; y += side) {
     for (int x = 0; x < width; x += side) {
       // Calculate an appropriate transparency value.
       float xBias = (float) x / (float) width;
       float yBias = (float) y / (float) height;
       float alpha = 1.0f - Math.abs(xBias - yBias);
       g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
       // Draw the subimage.
       int w = Math.min(side, width - x);
       int h = Math.min(side, height - y);
       BufferedImage tile = mImage.getSubimage(x, y, w, h);
       g2.drawImage(tile, x, y, null);
     }
   }
   // Reset the composite.
   g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
 }
Exemple #12
0
  /**
   * Move to the specified origin (in bins)
   *
   * @param newBinX new location X
   * @param newBinY new location Y
   */
  private void moveTo(double newBinX, double newBinY) {
    try {
      MatrixZoomData zd = getZd();

      final double wBins = (superAdapter.getHeatmapPanel().getWidth() / getScaleFactor());
      double maxX = zd.getXGridAxis().getBinCount() - wBins;

      final double hBins = (superAdapter.getHeatmapPanel().getHeight() / getScaleFactor());
      double maxY = zd.getYGridAxis().getBinCount() - hBins;

      double x = Math.max(0, Math.min(maxX, newBinX));
      double y = Math.max(0, Math.min(maxY, newBinY));

      xContext.setBinOrigin(x);
      yContext.setBinOrigin(y);

      superAdapter.repaint();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (linkedMode) {
      broadcastLocation();
    }
  }
 @Override
 protected void processKeyEvent(KeyEvent e) {
   // TODO: Convert into Actions and put into InputMap/ActionMap?
   final int hexColumns = model.getNumberOfHexColumns();
   final long lastOffset = model.getSize() - 1;
   final boolean extend = e.isShiftDown();
   if (e.getID() == KeyEvent.KEY_PRESSED) {
     switch (e.getKeyCode()) {
       case KeyEvent.VK_LEFT:
         long offs = leadSelectionIndex > 0 ? leadSelectionIndex - 1 : 0;
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_RIGHT:
         offs = Math.min(leadSelectionIndex + 1, lastOffset);
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_UP:
         offs = Math.max(leadSelectionIndex - hexColumns, 0);
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_DOWN:
         offs = Math.min(leadSelectionIndex + hexColumns, lastOffset);
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_PAGE_DOWN:
         int visibleRowCount = getVisibleRect().height / getRowHeight();
         offs = Math.min(leadSelectionIndex + visibleRowCount * hexColumns, lastOffset);
         changeSelectionByOffset(offs, extend);
         e.consume();
         break;
       case KeyEvent.VK_PAGE_UP:
         visibleRowCount = getVisibleRect().height / getRowHeight();
         offs = Math.max(leadSelectionIndex - visibleRowCount * hexColumns, 0);
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_HOME:
         offs = (leadSelectionIndex / hexColumns) * hexColumns;
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_END:
         offs = (leadSelectionIndex / hexColumns) * hexColumns + hexColumns - 1;
         offs = Math.min(offs, lastOffset);
         changeSelectionByOffset(offs, extend);
         e.consume();
         return;
       case KeyEvent.VK_BACK_SPACE:
         // System.out.println();
         // Profiler.print();
         // System.out.println(Profiler.getTime());
         return;
     }
   }
   super.processKeyEvent(e);
 }
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
  @NotNull
  public static Icon cropIcon(@NotNull Icon icon, int maxWidth, int maxHeight) {
    if (icon.getIconHeight() <= maxHeight && icon.getIconWidth() <= maxWidth) {
      return icon;
    }

    final int w = Math.min(icon.getIconWidth(), maxWidth);
    final int h = Math.min(icon.getIconHeight(), maxHeight);

    final BufferedImage image =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration()
            .createCompatibleImage(
                icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT);
    final Graphics2D g = image.createGraphics();
    icon.paintIcon(new JPanel(), g, 0, 0);
    g.dispose();

    final BufferedImage img = UIUtil.createImage(w, h, Transparency.TRANSLUCENT);
    final int offX = icon.getIconWidth() > maxWidth ? (icon.getIconWidth() - maxWidth) / 2 : 0;
    final int offY = icon.getIconHeight() > maxHeight ? (icon.getIconHeight() - maxHeight) / 2 : 0;
    for (int col = 0; col < w; col++) {
      for (int row = 0; row < h; row++) {
        img.setRGB(col, row, image.getRGB(col + offX, row + offY));
      }
    }

    return new ImageIcon(img);
  }
  @Override
  public void updateMinimumSize() {
    final Dimension min;
    if (getTarget().isMinimumSizeSet()) {
      min = getTarget().getMinimumSize();
      min.width = Math.max(min.width, MINIMUM_WIDTH);
      min.height = Math.max(min.height, MINIMUM_HEIGHT);
    } else {
      min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
    }

    final int maxW, maxH;
    if (graphicsConfig instanceof TextureSizeConstraining) {
      maxW = ((TextureSizeConstraining) graphicsConfig).getMaxTextureWidth();
      maxH = ((TextureSizeConstraining) graphicsConfig).getMaxTextureHeight();
    } else {
      maxW = maxH = Integer.MAX_VALUE;
    }

    final Dimension max;
    if (getTarget().isMaximumSizeSet()) {
      max = getTarget().getMaximumSize();
      max.width = Math.min(max.width, maxW);
      max.height = Math.min(max.height, maxH);
    } else {
      max = new Dimension(maxW, maxH);
    }

    platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
  }
      @Override
      public void mouseDragged(MouseEvent e) {
        if (!myDragging) return;
        MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, MyDivider.this);
        final ToolWindowAnchor anchor = myInfo.getAnchor();
        final Point point = event.getPoint();
        final Container windowPane = InternalDecorator.this.getParent();
        myLastPoint = SwingUtilities.convertPoint(MyDivider.this, point, windowPane);
        myLastPoint.x = Math.min(Math.max(myLastPoint.x, 0), windowPane.getWidth());
        myLastPoint.y = Math.min(Math.max(myLastPoint.y, 0), windowPane.getHeight());

        final Rectangle bounds = InternalDecorator.this.getBounds();
        if (anchor == ToolWindowAnchor.TOP) {
          InternalDecorator.this.setBounds(0, 0, bounds.width, myLastPoint.y);
        } else if (anchor == ToolWindowAnchor.LEFT) {
          InternalDecorator.this.setBounds(0, 0, myLastPoint.x, bounds.height);
        } else if (anchor == ToolWindowAnchor.BOTTOM) {
          InternalDecorator.this.setBounds(
              0, myLastPoint.y, bounds.width, windowPane.getHeight() - myLastPoint.y);
        } else if (anchor == ToolWindowAnchor.RIGHT) {
          InternalDecorator.this.setBounds(
              myLastPoint.x, 0, windowPane.getWidth() - myLastPoint.x, bounds.height);
        }
        InternalDecorator.this.validate();
        e.consume();
      }
  /** Removes all highlights. */
  public void removeAllHighlights() {
    TextUI mapper = component.getUI();
    if (getDrawsLayeredHighlights()) {
      int len = highlights.size();
      if (len != 0) {
        int minX = 0;
        int minY = 0;
        int maxX = 0;
        int maxY = 0;
        int p0 = -1;
        int p1 = -1;
        for (int i = 0; i < len; i++) {
          HighlightInfo hi = highlights.elementAt(i);
          if (hi instanceof LayeredHighlightInfo) {
            LayeredHighlightInfo info = (LayeredHighlightInfo) hi;
            minX = Math.min(minX, info.x);
            minY = Math.min(minY, info.y);
            maxX = Math.max(maxX, info.x + info.width);
            maxY = Math.max(maxY, info.y + info.height);
          } else {
            if (p0 == -1) {
              p0 = hi.p0.getOffset();
              p1 = hi.p1.getOffset();
            } else {
              p0 = Math.min(p0, hi.p0.getOffset());
              p1 = Math.max(p1, hi.p1.getOffset());
            }
          }
        }
        if (minX != maxX && minY != maxY) {
          component.repaint(minX, minY, maxX - minX, maxY - minY);
        }
        if (p0 != -1) {
          try {
            safeDamageRange(p0, p1);
          } catch (BadLocationException e) {
          }
        }
        highlights.removeAllElements();
      }
    } else if (mapper != null) {
      int len = highlights.size();
      if (len != 0) {
        int p0 = Integer.MAX_VALUE;
        int p1 = 0;
        for (int i = 0; i < len; i++) {
          HighlightInfo info = highlights.elementAt(i);
          p0 = Math.min(p0, info.p0.getOffset());
          p1 = Math.max(p1, info.p1.getOffset());
        }
        try {
          safeDamageRange(p0, p1);
        } catch (BadLocationException e) {
        }

        highlights.removeAllElements();
      }
    }
  }
Exemple #19
0
 public void brighter() {
   float[] rgb = color.get().getRGBComponents(null);
   rgb[0] = (float) Math.min(rgb[0] + 0.1, 1.0);
   rgb[1] = (float) Math.min(rgb[1] + 0.1, 1.0);
   rgb[2] = (float) Math.min(rgb[2] + 0.1, 1.0);
   color = new Color3f(rgb);
   updateLight();
 }
 public static Color gradientColor(double value) {
   if (value < 0.0) return Color.gray;
   if (value > 1.0) value = 1.0;
   int red = Math.min(255, (int) (512.0 - (value * 512.0)));
   int green = Math.min(255, (int) (value * 512.0));
   int blue = 0;
   return new Color(red, green, blue);
 }
Exemple #21
0
 public boolean containsPoint(int x, int y) {
   int l = Math.min(getStart().x, getEnd().x);
   int t = Math.min(getStart().y, getEnd().y);
   int w = Math.abs(getWidth());
   int h = Math.abs(getHeight());
   if (x >= l && x < l + w && y >= t && y < t + h) return true;
   else return false;
 }
 private int rozmer(final float ratio, final int size, final int pr, final int mi, final int ma) {
   final int mypr = (int) (size * ratio);
   int v = Math.min(mypr, pr);
   v = Math.max(v, mi);
   v = Math.min(v, ma);
   v = Math.min(v, size); // a omezit prostorem, ktery mame
   return v;
 }
  /** {@inheritDoc} */
  @Override
  public void mouseDragged(final MouseEvent aEvent) {
    final MouseEvent event = convertEvent(aEvent);
    final Point point = event.getPoint();

    // Update the selected channel while dragging...
    this.controller.setSelectedChannel(point);

    if (getModel().isCursorMode() && (this.movingCursor >= 0)) {
      this.controller.moveCursor(this.movingCursor, getCursorDropPoint(point));

      aEvent.consume();
    } else {
      if ((this.lastClickPosition == null)
          && ((aEvent.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0)) {
        this.lastClickPosition = new Point(point);
      }

      final JScrollPane scrollPane =
          getAncestorOfClass(JScrollPane.class, (Component) aEvent.getSource());
      if ((scrollPane != null) && (this.lastClickPosition != null)) {
        final JViewport viewPort = scrollPane.getViewport();
        final Component signalView = this.controller.getSignalDiagram().getSignalView();

        boolean horizontalOnly = (aEvent.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0;
        boolean verticalOnly =
            horizontalOnly && ((aEvent.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0);

        int dx = aEvent.getX() - this.lastClickPosition.x;
        int dy = aEvent.getY() - this.lastClickPosition.y;

        Point scrollPosition = viewPort.getViewPosition();
        int newX = scrollPosition.x;
        if (!verticalOnly) {
          newX -= dx;
        }
        int newY = scrollPosition.y;
        if (verticalOnly || !horizontalOnly) {
          newY -= dy;
        }

        int diagramWidth = signalView.getWidth();
        int viewportWidth = viewPort.getWidth();
        int maxX = diagramWidth - viewportWidth - 1;
        scrollPosition.x = Math.max(0, Math.min(maxX, newX));

        int diagramHeight = signalView.getHeight();
        int viewportHeight = viewPort.getHeight();
        int maxY = diagramHeight - viewportHeight;
        scrollPosition.y = Math.max(0, Math.min(maxY, newY));

        viewPort.setViewPosition(scrollPosition);
      }

      // Use UNCONVERTED/ORIGINAL mouse event!
      handleZoomRegion(aEvent, this.lastClickPosition);
    }
  }
  public ErrorListDialog(
      Frame frame, String title, String caption, Vector messages, boolean showPluginMgrButton) {
    super(frame, title, true);

    JPanel content = new JPanel(new BorderLayout(12, 12));
    content.setBorder(new EmptyBorder(12, 12, 12, 12));
    setContentPane(content);

    Box iconBox = new Box(BoxLayout.Y_AXIS);
    iconBox.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon")));
    iconBox.add(Box.createGlue());
    content.add(BorderLayout.WEST, iconBox);

    JPanel centerPanel = new JPanel(new BorderLayout());

    JLabel label = new JLabel(caption);
    label.setBorder(new EmptyBorder(0, 0, 6, 0));
    centerPanel.add(BorderLayout.NORTH, label);

    JList errors = new JList(messages);
    errors.setCellRenderer(new ErrorListCellRenderer());
    errors.setVisibleRowCount(Math.min(messages.size(), 4));

    JScrollPane scrollPane =
        new JScrollPane(
            errors, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    Dimension size = scrollPane.getPreferredSize();
    size.width = Math.min(size.width, 400);
    scrollPane.setPreferredSize(size);

    centerPanel.add(BorderLayout.CENTER, scrollPane);

    content.add(BorderLayout.CENTER, centerPanel);

    Box buttons = new Box(BoxLayout.X_AXIS);
    buttons.add(Box.createGlue());

    ok = new JButton(jEdit.getProperty("common.ok"));
    ok.addActionListener(new ActionHandler());

    if (showPluginMgrButton) {
      pluginMgr = new JButton(jEdit.getProperty("error-list.plugin-manager"));
      pluginMgr.addActionListener(new ActionHandler());
      buttons.add(pluginMgr);
      buttons.add(Box.createHorizontalStrut(6));
    }

    buttons.add(ok);

    buttons.add(Box.createGlue());
    content.add(BorderLayout.SOUTH, buttons);

    getRootPane().setDefaultButton(ok);

    pack();
    setLocationRelativeTo(frame);
    show();
  }
  protected void paintLineHighlight(Graphics gfx, int line, int y) {
    int height = fm.getHeight();
    y += fm.getLeading() + fm.getMaxDescent();

    int selectionStart = textArea.getSelectionStart();
    int selectionEnd = textArea.getSelectionStop();

    if (selectionStart == selectionEnd) {
      if (lineHighlight) {
        gfx.setColor(lineHighlightColor);
        gfx.fillRect(0, y, getWidth(), height);
      }
    } else {
      gfx.setColor(selectionColor);

      int selectionStartLine = textArea.getSelectionStartLine();
      int selectionEndLine = textArea.getSelectionStopLine();
      int lineStart = textArea.getLineStartOffset(line);

      int x1, x2;
      if (textArea.isSelectionRectangular()) {
        int lineLen = textArea.getLineLength(line);
        x1 =
            textArea._offsetToX(
                line,
                Math.min(
                    lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine)));
        x2 =
            textArea._offsetToX(
                line,
                Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine)));
        if (x1 == x2) x2++;
      } else if (selectionStartLine == selectionEndLine) {
        x1 = textArea._offsetToX(line, selectionStart - lineStart);
        x2 = textArea._offsetToX(line, selectionEnd - lineStart);
      } else if (line == selectionStartLine) {
        x1 = textArea._offsetToX(line, selectionStart - lineStart);
        x2 = getWidth();
      } else if (line == selectionEndLine) {
        // x1 = 0;
        // hack from stendahl to avoid doing weird side selection thing
        x1 = textArea._offsetToX(line, 0);
        // attempt at getting the gutter too, but doesn't seem to work
        // x1 = textArea._offsetToX(line, -textArea.getHorizontalOffset());
        x2 = textArea._offsetToX(line, selectionEnd - lineStart);
      } else {
        // x1 = 0;
        // hack from stendahl to avoid doing weird side selection thing
        x1 = textArea._offsetToX(line, 0);
        // attempt at getting the gutter too, but doesn't seem to work
        // x1 = textArea._offsetToX(line, -textArea.getHorizontalOffset());
        x2 = getWidth();
      }

      // "inlined" min/max()
      gfx.fillRect(x1 > x2 ? x2 : x1, y, x1 > x2 ? (x1 - x2) : (x2 - x1), height);
    }
  }
Exemple #26
0
  // ParserListener methods
  public void noteEvent(Note note) {
    if (layer >= staves) {
      return;
    }
    // System.out.println(note.getMusicString() + " " + note.getMillisDuration() + " " +
    // note.getDecimalDuration());
    Vector<Chord> currChords = chords[layer];
    Iterator<NotePanel> currNote = currNotes[layer];

    if (!currNote.hasNext()) {
      System.err.println("Received noteEvent, but no PostScript notes are left");
      return;
    }

    if (note.getMillisDuration() > 0) {
      NotePanel notePanel = currNote.next();
      // time the last chord ended
      long tempTime = 0;
      for (int i = currChords.size() - 1; i >= 0; --i) {
        if (!currChords.get(i).isTie()) {
          tempTime = currChords.get(i).getTime() + currChords.get(i).getDuration();
          break;
        }
      }

      if (notePanel.isTie) {
        Chord chord = new Chord();
        // for each note in the last chord, set the next note as a tied note
        for (int i = 0; i < currChords.lastElement().size(); ++i) {
          notePanel.setTie(true).setTime(Math.min(tempTime, time - 1)).setTempo(tempo);
          chord.addNote(notePanel);
          notePanel = currNote.next();
        }
        currChords.add(chord);
      }

      while (notePanel.isRest) {
        notePanel
            .setTime(Math.min(tempTime, time - 1)) // hack, in case the rest should be trimmed
            .setTempo(tempo);
        tempTime += notePanel.getDuration();
        Chord chord = new Chord(notePanel);
        currChords.add(chord);
        // System.out.println("REST: " + notePanel.getMusicString() + " " +
        // notePanel.getDuration());
        notePanel = currNote.next();
      }

      notePanel.setNote(note).setTime(time).setTempo(tempo);
      if (currChords.isEmpty() || currChords.lastElement().getTime() != time) {
        Chord chord = new Chord(notePanel);
        currChords.add(chord);
      } else {
        currChords.lastElement().addNote(notePanel);
      }
    }
  }
  /** @return Point in layered pane coordinate system */
  static Pair<Point, Short> chooseBestHintPosition(
      Project project,
      Editor editor,
      int line,
      int col,
      LightweightHint hint,
      boolean awtTooltip,
      short preferredPosition) {
    HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
    Dimension hintSize = hint.getComponent().getPreferredSize();
    JComponent editorComponent = editor.getComponent();
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();

    Point p1;
    Point p2;
    boolean isLookupShown = LookupManager.getInstance(project).getActiveLookup() != null;
    if (isLookupShown) {
      p1 = hintManager.getHintPosition(hint, editor, HintManager.UNDER);
      p2 = hintManager.getHintPosition(hint, editor, HintManager.ABOVE);
    } else {
      LogicalPosition pos = new LogicalPosition(line, col);
      p1 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.UNDER);
      p2 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.ABOVE);
    }

    if (!awtTooltip) {
      p1.x = Math.min(p1.x, layeredPane.getWidth() - hintSize.width);
      p1.x = Math.max(p1.x, 0);
      p2.x = Math.min(p2.x, layeredPane.getWidth() - hintSize.width);
      p2.x = Math.max(p2.x, 0);
    }

    boolean p1Ok = p1.y + hintSize.height < layeredPane.getHeight();
    boolean p2Ok = p2.y >= 0;

    if (isLookupShown) {
      if (p1Ok) return new Pair<Point, Short>(p1, HintManager.UNDER);
      if (p2Ok) return new Pair<Point, Short>(p2, HintManager.ABOVE);
    } else {
      if (preferredPosition != HintManager.DEFAULT) {
        if (preferredPosition == HintManager.ABOVE) {
          if (p2Ok) return new Pair<Point, Short>(p2, HintManager.ABOVE);
        } else if (preferredPosition == HintManager.UNDER) {
          if (p1Ok) return new Pair<Point, Short>(p1, HintManager.UNDER);
        }
      }

      if (p1Ok) return new Pair<Point, Short>(p1, HintManager.UNDER);
      if (p2Ok) return new Pair<Point, Short>(p2, HintManager.ABOVE);
    }

    int underSpace = layeredPane.getHeight() - p1.y;
    int aboveSpace = p2.y;
    return aboveSpace > underSpace
        ? new Pair<Point, Short>(new Point(p2.x, 0), HintManager.UNDER)
        : new Pair<Point, Short>(p1, HintManager.ABOVE);
  }
  public void documentChanged(DocumentEvent e) {
    finishUpdate();

    DocumentEventImpl event = (DocumentEventImpl) e;
    final Document document = myEditor.getDocument();
    boolean performSoftWrapAdjustment =
        e.getNewLength() > 0 // We want to put caret just after the last added symbol
            // There is a possible case that the user removes text just before the soft wrap. We
            // want to keep caret
            // on a visual line with soft wrap start then.
            || myEditor.getSoftWrapModel().getSoftWrap(e.getOffset()) != null;

    if (event.isWholeTextReplaced()) {
      int newLength = document.getTextLength();
      if (myOffset == newLength - e.getNewLength() + e.getOldLength() || newLength == 0) {
        moveToOffset(newLength, performSoftWrapAdjustment);
      } else {
        final int line;
        try {
          line = event.translateLineViaDiff(myLogicalCaret.line);
          moveToLogicalPosition(
              new LogicalPosition(line, myLogicalCaret.column), performSoftWrapAdjustment);
        } catch (FilesTooBigForDiffException e1) {
          LOG.info(e1);
          moveToOffset(0);
        }
      }
    } else {
      if (document instanceof DocumentEx && ((DocumentEx) document).isInBulkUpdate()) return;
      int startOffset = e.getOffset();
      int oldEndOffset = startOffset + e.getOldLength();

      int newOffset = myOffset;

      if (myOffset > oldEndOffset || myOffset == oldEndOffset && needToShiftWhiteSpaces(e)) {
        newOffset += e.getNewLength() - e.getOldLength();
      } else if (myOffset >= startOffset && myOffset <= oldEndOffset) {
        newOffset = Math.min(newOffset, startOffset + e.getNewLength());
      }

      newOffset = Math.min(newOffset, document.getTextLength());

      // if (newOffset != myOffset) {
      moveToOffset(newOffset, performSoftWrapAdjustment);
      // }
      // else {
      //  moveToVisualPosition(oldPosition);
      // }
    }

    myVisualLineStart =
        myEditor.logicalPositionToOffset(
            myEditor.visualToLogicalPosition(new VisualPosition(myVisibleCaret.line, 0)));
    myVisualLineEnd =
        myEditor.logicalPositionToOffset(
            myEditor.visualToLogicalPosition(new VisualPosition(myVisibleCaret.line + 1, 0)));
  }
Exemple #29
0
 /**
  * Computes the luminance of a color pixel.
  *
  * @param c the color values.
  * @return the corresponding lumincancevalue.
  */
 private static int computeLuminance(Color c) {
   int r = c.getRed();
   int g = c.getGreen();
   int b = c.getBlue();
   int max = Math.max(Math.max(r, g), b);
   int min = Math.min(Math.min(r, g), b);
   int luminance = (max + min) / 2;
   return luminance;
 }
Exemple #30
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }