示例#1
0
 private void paintBell(Graphics g) {
   P9TermPreferences preferences = P9Term.getPreferences();
   if (preferences.getBoolean(P9TermPreferences.VISUAL_BELL) == false) {
     return;
   }
   Color foreground = preferences.getColor(P9TermPreferences.FOREGROUND_COLOR);
   if (preferences.getBoolean(P9TermPreferences.FANCY_BELL)) {
     // On decent hardware, we can produce a really tasteful effect by compositing a
     // semi-transparent rectangle over the terminal.
     // We need to choose a color that will show up against the background.
     // A reasonable assumption is that the user has already chosen such a color for the
     // foreground.
     Color color =
         new Color(foreground.getRed(), foreground.getGreen(), foreground.getBlue(), 100);
     g.setColor(color);
     g.fillRect(0, 0, getWidth(), getHeight());
   } else {
     // On a remote X11 display (or really rubbish hardware) the compositing effect is
     // prohibitively expensive, so we offer XOR instead.
     Color background = preferences.getColor(P9TermPreferences.BACKGROUND_COLOR);
     ;
     final int R = blend(background.getRed(), foreground.getRed());
     final int G = blend(background.getGreen(), foreground.getGreen());
     final int B = blend(background.getBlue(), foreground.getBlue());
     g.setColor(background);
     g.setXORMode(new Color(R, G, B));
     g.fillRect(0, 0, getWidth(), getHeight());
     g.setPaintMode();
   }
 }
示例#2
0
  public void save() {
    Rectangle rect = this.getBounds();
    prefs.putInt(LOCATION_X, rect.x);
    prefs.putInt(LOCATION_Y, rect.y);
    prefs.putInt(WIDTH, rect.width);
    prefs.putInt(HEIGHT, rect.height);

    prefs.put(FONTSTYLE, this.myMenu.fontStyle);
    prefs.putInt(FONTSIZE, this.myMenu.fontSize);

    Color fColor = this.myMenu.fontColor;
    fRed = fColor.getRed();
    fGreen = fColor.getGreen();
    fBlue = fColor.getBlue();
    prefs.putInt(FRED, fRed);
    prefs.putInt(FGREEN, fGreen);
    prefs.putInt(FBLUE, fBlue);

    Color color = this.myMenu.getBackground();
    bgRed = color.getRed();
    bgGreen = color.getGreen();
    bgBlue = color.getBlue();
    prefs.putInt(BGRED, bgRed);
    prefs.putInt(BGGREEN, bgGreen);
    prefs.putInt(BGBLUE, bgBlue);
  }
示例#3
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in RED, GREEN, or BLUE mode, then this method converts these values to RGB
   * coordinates and calls <code>setRGB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param h the hue value of the selected color.
   * @param s the saturation value of the selected color.
   * @param b the brightness value of the selected color.
   */
  public void setHSB(float h, float s, float b) {
    if (Float.isInfinite(h) || Float.isNaN(h))
      throw new IllegalArgumentException("The hue value (" + h + ") is not a valid number.");
    // hue is cyclic, so it can be any value:
    while (h < 0) h++;
    while (h > 1) h--;

    if (s < 0 || s > 1)
      throw new IllegalArgumentException("The saturation value (" + s + ") must be between [0,1]");
    if (b < 0 || b > 1)
      throw new IllegalArgumentException("The brightness value (" + b + ") must be between [0,1]");

    if (hue != h || sat != s || bri != b) {
      if (mode == ColorPicker.HUE || mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
        float lastHue = hue;
        float lastBri = bri;
        float lastSat = sat;
        hue = h;
        sat = s;
        bri = b;
        if (mode == ColorPicker.HUE) {
          if (lastHue != hue) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.SAT) {
          if (lastSat != sat) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BRI) {
          if (lastBri != bri) {
            regenerateImage();
          }
        }
      } else {

        Color c = new Color(Color.HSBtoRGB(h, s, b));
        setRGB(c.getRed(), c.getGreen(), c.getBlue());
        return;
      }

      Color c = new Color(Color.HSBtoRGB(hue, sat, bri));
      red = c.getRed();
      green = c.getGreen();
      blue = c.getBlue();

      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
示例#4
0
 /** Patches attributes to be visible under debugger active line */
 @SuppressWarnings("UseJBColor")
 private static TextAttributes patchAttributesColor(
     TextAttributes attributes, TextRange range, Editor editor) {
   int line = editor.offsetToLogicalPosition(range.getStartOffset()).line;
   for (RangeHighlighter highlighter : editor.getMarkupModel().getAllHighlighters()) {
     if (!highlighter.isValid()) continue;
     if (highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE
         && editor.offsetToLogicalPosition(highlighter.getStartOffset()).line == line) {
       TextAttributes textAttributes = highlighter.getTextAttributes();
       if (textAttributes != null) {
         Color color = textAttributes.getBackgroundColor();
         if (color != null
             && color.getBlue() > 128
             && color.getRed() < 128
             && color.getGreen() < 128) {
           TextAttributes clone = attributes.clone();
           clone.setForegroundColor(Color.orange);
           clone.setEffectColor(Color.orange);
           return clone;
         }
       }
     }
   }
   return attributes;
 }
示例#5
0
 public ColorPane(Color c) {
   col = c;
   setBackground(c);
   setBorder(unselectedBorder);
   String msg = "R " + c.getRed() + ", G " + c.getGreen() + ", B " + c.getBlue();
   setToolTipText(msg);
   addMouseListener(this);
 }
示例#6
0
 public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) {
   BufferedImage coloredTile = tiles[tileNum];
   for (int i = 0; i < this.tW; i++) {
     for (int j = 0; j < this.tH; j++) {
       Color originalColor = new Color(coloredTile.getRGB(i, j), true);
       Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha());
       coloredTile.setRGB(i, j, nc.getRGB());
     }
   }
   g.drawImage(tiles[tileNum], x, y, null);
 }
 public Color getColor() {
   if (myColorWheelPanel.myColorWheel.myOpacity == 255) {
     return myColor;
   } else {
     //noinspection UseJBColor
     return new Color(
         myColor.getRed(),
         myColor.getGreen(),
         myColor.getBlue(),
         myColorWheelPanel.myColorWheel.myOpacity);
   }
 }
    private void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
      myColor = color;
      myHue = hsb[0];
      mySaturation = hsb[1];
      myBrightness = hsb[2];
      myOpacity = color.getAlpha();

      fireColorChanged(source);

      repaint();
    }
示例#9
0
 void initGraphics(Graphics g, Color textColor, Color defaultColor) {
   if (smallFont == null) {
     smallFont = new Font("SansSerif", Font.PLAIN, 9);
     largeFont = new Font("SansSerif", Font.PLAIN, 12);
   }
   if (textColor != null) {
     labelColor = textColor;
     if (overlay != null && overlay.getDrawBackgrounds())
       bgColor =
           new Color(
               255 - labelColor.getRed(), 255 - labelColor.getGreen(), 255 - labelColor.getBlue());
     else bgColor = null;
   } else {
     int red = defaultColor.getRed();
     int green = defaultColor.getGreen();
     int blue = defaultColor.getBlue();
     if ((red + green + blue) / 3 < 128) labelColor = Color.white;
     else labelColor = Color.black;
     bgColor = defaultColor;
   }
   this.defaultColor = defaultColor;
   g.setColor(defaultColor);
 }
    @Override
    public String getToolTipText(MouseEvent event) {
      Color color = getColor(event);
      if (color != null) {
        return String.format(
            "R: %d G: %d B: %d A: %s",
            color.getRed(),
            color.getGreen(),
            color.getBlue(),
            String.format("%.2f", (float) (color.getAlpha() / 255.0)));
      }

      return super.getToolTipText(event);
    }
示例#11
0
 public void overlay() {
   for (int y = 0; y < height; ++y) {
     for (int x = 0; x < width; ++x) {
       // System.out.println(nonMax.getRGB(x,y));
       if (nonMax.getRGB(x, y) != -1) {
         int rgb = img.getRGB(x, y);
         Color color = new Color(rgb);
         Color res = new Color(255, color.getGreen(), color.getBlue());
         img.setRGB(x, y, res.getRGB());
       }
     }
   }
   ImageIcon icon1 = new ImageIcon(img);
   lbl1.setIcon(icon1);
 }
    public void setColor(Color color, Object source) {
      float[] hsb = new float[3];
      Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);

      myBrightnessComponent.setValue(255 - (int) (hsb[2] * 255));
      myBrightnessComponent.repaint();

      myColorWheel.dropImage();
      if (myOpacityComponent != null && source instanceof ColorPicker) {
        myOpacityComponent.setValue(color.getAlpha());
        myOpacityComponent.repaint();
      }

      myColorWheel.setColor(color, source);
    }
  /** {@inheritDoc} */
  public void setBackgroundColor(Color color) {
    if (color == null) {
      String message = Logging.getMessage("nullValue.ColorIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    // Only set the color if it actually changed
    if (!color.equals(this.getBackgroundColor())) {
      this.backgroundColor = color;

      // Convert the color to an RGB hex triplet string that the WebBrowser will understand
      int rgb =
          (color.getRed() & 0xFF) << 16 | (color.getGreen() & 0xFF) << 8 | (color.getBlue() & 0xFF);
      String colorString = String.format("#%06X", rgb);

      WindowsWebViewJNI.setBackgroundColor(this.webViewWindowPtr, colorString);
    }
  }
    public void saveColors() {
      final List<String> values = new ArrayList<>();
      for (Color recentColor : myRecentColors) {
        if (recentColor == null) break;
        values.add(
            String.format(
                "%d-%d-%d-%d",
                recentColor.getRed(),
                recentColor.getGreen(),
                recentColor.getBlue(),
                recentColor.getAlpha()));
      }

      PropertiesComponent.getInstance()
          .setValue(
              COLOR_CHOOSER_COLORS_KEY,
              values.isEmpty() ? null : StringUtil.join(values, ",,,"),
              null);
    }
示例#15
0
 protected void setDrawingColor(int ox, int oy, boolean setBackground) {
   // IJ.log("setDrawingColor: "+setBackground+this);
   int type = imp.getType();
   int[] v = imp.getPixel(ox, oy);
   switch (type) {
     case ImagePlus.GRAY8:
       {
         if (setBackground) setBackgroundColor(getColor(v[0]));
         else setForegroundColor(getColor(v[0]));
         break;
       }
     case ImagePlus.GRAY16:
     case ImagePlus.GRAY32:
       {
         double min = imp.getProcessor().getMin();
         double max = imp.getProcessor().getMax();
         double value = (type == ImagePlus.GRAY32) ? Float.intBitsToFloat(v[0]) : v[0];
         int index = (int) (255.0 * ((value - min) / (max - min)));
         if (index < 0) index = 0;
         if (index > 255) index = 255;
         if (setBackground) setBackgroundColor(getColor(index));
         else setForegroundColor(getColor(index));
         break;
       }
     case ImagePlus.COLOR_RGB:
     case ImagePlus.COLOR_256:
       {
         Color c = new Color(v[0], v[1], v[2]);
         if (setBackground) setBackgroundColor(c);
         else setForegroundColor(c);
         break;
       }
   }
   Color c;
   if (setBackground) c = Toolbar.getBackgroundColor();
   else {
     c = Toolbar.getForegroundColor();
     imp.setColor(c);
   }
   IJ.showStatus("(" + c.getRed() + ", " + c.getGreen() + ", " + c.getBlue() + ")");
 }
 /** Methode appelee quand l'utilisateur appuie sur le bouton. */
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == button) {
     Color choosedColor =
         JColorChooser.showDialog(parent.dialog(), "Choose color", new Color(R, G, B));
     if (choosedColor != null) {
       this.R = choosedColor.getRed();
       this.G = choosedColor.getGreen();
       this.B = choosedColor.getBlue();
       parent.elementModified();
     }
     String tmp =
         new String(
             label
                 + Integer.toString(getRed())
                 + ", "
                 + Integer.toString(getGreen())
                 + ", "
                 + Integer.toString(getBlue()));
     while (tmp.length() < 38) {
       tmp = tmp + " ";
     }
     jlabel.setText(tmp);
   }
 }
 private void applyColorToHSB(final Color c) {
   final float[] hbs = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
   myRed.setText(String.valueOf(((int) (360f * hbs[0]))));
   myGreen.setText(String.valueOf(((int) (100f * hbs[1]))));
   myBlue.setText(String.valueOf(((int) (100f * hbs[2]))));
 }
示例#18
0
    ImageProcessor setup(ImagePlus imp) {

      ImageProcessor ip;
      int type = imp.getType();
      if (type != ImagePlus.COLOR_RGB) return null;
      ip = imp.getProcessor();
      int id = imp.getID();
      int slice = imp.getCurrentSlice();

      if ((id != previousImageID) | (slice != previousSlice) | (flag)) {
        flag = false; // if true, flags a change from HSB to RGB or viceversa
        numSlices = imp.getStackSize();
        stack = imp.getStack();
        width = stack.getWidth();
        height = stack.getHeight();
        numPixels = width * height;

        hSource = new byte[numPixels];
        sSource = new byte[numPixels];
        bSource = new byte[numPixels];

        // restore = (int[])ip.getPixelsCopy(); //This runs into trouble sometimes, so do it the
        // long way:
        int[] temp = (int[]) ip.getPixels();
        restore = new int[numPixels];
        for (int i = 0; i < numPixels; i++) restore[i] = temp[i];

        fillMask = new int[numPixels];

        // Get hsb or rgb from image.
        ColorProcessor cp = (ColorProcessor) ip;
        IJ.showStatus("Gathering data");

        if (isRGB) cp.getRGB(hSource, sSource, bSource);
        else cp.getHSB(hSource, sSource, bSource);

        IJ.showStatus("done");

        // Create a spectrum ColorModel for the Hue histogram plot.
        Color c;
        byte[] reds = new byte[256];
        byte[] greens = new byte[256];
        byte[] blues = new byte[256];
        for (int i = 0; i < 256; i++) {
          c = Color.getHSBColor(i / 255f, 1f, 1f);

          reds[i] = (byte) c.getRed();
          greens[i] = (byte) c.getGreen();
          blues[i] = (byte) c.getBlue();
        }
        ColorModel cm = new IndexColorModel(8, 256, reds, greens, blues);

        // Make an image with just the hue from the RGB image and the spectrum LUT.
        // This is just for a hue histogram for the plot.  Do not show it.
        // ByteProcessor bpHue = new ByteProcessor(width,height,h,cm);
        ByteProcessor bpHue = new ByteProcessor(width, height, hSource, cm);
        ImagePlus impHue = new ImagePlus("Hue", bpHue);
        // impHue.show();

        ByteProcessor bpSat = new ByteProcessor(width, height, sSource, cm);
        ImagePlus impSat = new ImagePlus("Sat", bpSat);
        // impSat.show();

        ByteProcessor bpBri = new ByteProcessor(width, height, bSource, cm);
        ImagePlus impBri = new ImagePlus("Bri", bpBri);
        // impBri.show();

        plot.setHistogram(impHue, 0);
        splot.setHistogram(impSat, 1);
        bplot.setHistogram(impBri, 2);

        updateLabels();
        updatePlot();
        updateScrollBars();
        imp.updateAndDraw();
      }
      previousImageID = id;
      previousSlice = slice;
      return ip;
    }
示例#19
0
 private void setBackgroundColor(Color c) {
   Toolbar.setBackgroundColor(c);
   if (Recorder.record)
     Recorder.record("setBackgroundColor", c.getRed(), c.getGreen(), c.getBlue());
 }
示例#20
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }
 private void applyColorToRGB(final Color color) {
   myRed.setText(String.valueOf(color.getRed()));
   myGreen.setText(String.valueOf(color.getGreen()));
   myBlue.setText(String.valueOf(color.getBlue()));
 }
示例#22
0
 private String getColorText(final Color color) {
   final boolean hex = fieldType.equals(ColorChooserFieldType.hex);
   return hex
       ? ColorUtils.getHexColor(color)
       : color.getRed() + "," + color.getGreen() + "," + color.getBlue();
 }