예제 #1
1
  /*
   * sets the colormap to Rainbow
   */
  private void setColorModelRainbow() {
    // Copy in the default colors
    for (int i = 0; i < tableSize; i++) {
      cm_red[i] = puke_red[i];
      cm_green[i] = puke_green[i];
      cm_blue[i] = puke_blue[i];
    }

    // Set rainbow for attribute colors
    float maxHue = 0.8f;
    float hue = 0;
    float delta = maxHue / attrSize;
    int rainbowColor;
    for (int i = startColor; i <= endColor; ++i, hue += delta) {
      rainbowColor = Color.HSBtoRGB(hue, 1.0f, 1.0f);
      cm_red[i] = (byte) ((rainbowColor >> 16) & 0xff);
      cm_green[i] = (byte) ((rainbowColor >> 8) & 0xff);
      cm_blue[i] = (byte) ((rainbowColor >> 0) & 0xff);
    }

    colorModel = new IndexColorModel(8, tableSize, cm_red, cm_green, cm_blue);
  }
예제 #2
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();
    }
  }
예제 #3
0
 // Overridden for performance reasons. ---->
 @Override
 public boolean isOpaque() {
   Color back = getBackground();
   Component p = getParent();
   if (Objects.nonNull(p)) {
     p = p.getParent();
   } // p should now be the JTable.
   boolean colorMatch =
       Objects.nonNull(back)
           && Objects.nonNull(p)
           && back.equals(p.getBackground())
           && p.isOpaque();
   return !colorMatch && super.isOpaque();
 }
예제 #4
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);
 }
  /** {@collect.stats} Sets the values of the controls to reflect the color */
  private void setColor(Color newColor) {
    int red = newColor.getRed();
    int blue = newColor.getBlue();
    int green = newColor.getGreen();

    if (redSlider.getValue() != red) {
      redSlider.setValue(red);
    }
    if (greenSlider.getValue() != green) {
      greenSlider.setValue(green);
    }
    if (blueSlider.getValue() != blue) {
      blueSlider.setValue(blue);
    }

    if (((Integer) redField.getValue()).intValue() != red) redField.setValue(new Integer(red));
    if (((Integer) greenField.getValue()).intValue() != green)
      greenField.setValue(new Integer(green));
    if (((Integer) blueField.getValue()).intValue() != blue) blueField.setValue(new Integer(blue));
  }
예제 #6
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in HUE, SAT, or BRI mode, then this method converts these values to HSB
   * coordinates and calls <code>setHSB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param r the red value of the selected color.
   * @param g the green value of the selected color.
   * @param b the blue value of the selected color.
   */
  public void setRGB(int r, int g, int b) {
    if (r < 0 || r > 255)
      throw new IllegalArgumentException("The red value (" + r + ") must be between [0,255].");
    if (g < 0 || g > 255)
      throw new IllegalArgumentException("The green value (" + g + ") must be between [0,255].");
    if (b < 0 || b > 255)
      throw new IllegalArgumentException("The blue value (" + b + ") must be between [0,255].");

    if (red != r || green != g || blue != b) {
      if (mode == ColorPicker.RED || mode == ColorPicker.GREEN || mode == ColorPicker.BLUE) {
        int lastR = red;
        int lastG = green;
        int lastB = blue;
        red = r;
        green = g;
        blue = b;

        if (mode == ColorPicker.RED) {
          if (lastR != r) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.GREEN) {
          if (lastG != g) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BLUE) {
          if (lastB != b) {
            regenerateImage();
          }
        }
      } else {
        float[] hsb = new float[3];
        Color.RGBtoHSB(r, g, b, hsb);
        setHSB(hsb[0], hsb[1], hsb[2]);
        return;
      }
      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
예제 #7
0
 // convert color name in Java Color object
 public Color getColour(String name) {
   if (name.equals("red")) {
     return Color.red;
   } else if (name.equals("blue")) {
     return Color.blue;
   } else if (name.equals("black")) {
     return Color.black;
   } else if (name.equals("cyan")) {
     return Color.cyan;
   } else if (name.equals("dark gray")) {
     return Color.darkGray;
   } else if (name.equals("gray")) {
     return Color.gray;
   } else if (name.equals("light gray")) {
     return Color.lightGray;
   } else if (name.equals("green")) {
     return Color.gray;
   } else if (name.equals("magenta")) {
     return Color.magenta;
   } else if (name.equals("orange")) {
     return Color.orange;
   } else if (name.equals("pink")) {
     return Color.pink;
   } else if (name.equals("white")) {
     return Color.white;
   } else if (name.equals("yellow")) {
     return Color.yellow;
   }
   try {
     // see if the colour is expressed in
     // 0xAABBCC format for RGB...
     return Color.decode(name);
   } catch (NumberFormatException e) {
   }
   // no, ok bail then ... but this will certainly
   // through an exception
   return null;
 }
예제 #8
0
  /** Regenerates the image. */
  private synchronized void regenerateImage() {
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
      float bri2 = this.bri;
      float sat2 = this.sat;
      float radius = ((float) size) / 2f;
      float hue2;
      float k = 1.2f; // the number of pixels to antialias
      for (int y = 0; y < size; y++) {
        float y2 = (y - size / 2f);
        for (int x = 0; x < size; x++) {
          float x2 = (x - size / 2f);
          double theta = Math.atan2(y2, x2) - 3 * Math.PI / 2.0;
          if (theta < 0) theta += 2 * Math.PI;

          double r = Math.sqrt(x2 * x2 + y2 * y2);
          if (r <= radius) {
            if (mode == ColorPicker.BRI) {
              hue2 = (float) (theta / (2 * Math.PI));
              sat2 = (float) (r / radius);
            } else { // SAT
              hue2 = (float) (theta / (2 * Math.PI));
              bri2 = (float) (r / radius);
            }
            row[x] = Color.HSBtoRGB(hue2, sat2, bri2);
            if (r > radius - k) {
              int alpha = (int) (255 - 255 * (r - radius + k) / k);
              if (alpha < 0) alpha = 0;
              if (alpha > 255) alpha = 255;
              row[x] = row[x] & 0xffffff + (alpha << 24);
            }
          } else {
            row[x] = 0x00000000;
          }
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    } else if (mode == ColorPicker.HUE) {
      float hue2 = this.hue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          row[x] = Color.HSBtoRGB(hue2, x2, y2);
        }
        image.getRaster().setDataElements(0, y, image.getWidth(), 1, row);
      }
    } else { // mode is RED, GREEN, or BLUE
      int red2 = red;
      int green2 = green;
      int blue2 = blue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          if (mode == ColorPicker.RED) {
            green2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else if (mode == ColorPicker.GREEN) {
            red2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else {
            red2 = (int) (x2 * 255 + .49);
            green2 = (int) (y2 * 255 + .49);
          }
          row[x] = 0xFF000000 + (red2 << 16) + (green2 << 8) + blue2;
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    }
    repaint();
  }
예제 #9
0
  public AboutDialog(JConsole jConsole) {
    super(jConsole, Resources.getText("Help.AboutDialog.title"), false);

    setAccessibleDescription(this, getText("Help.AboutDialog.accessibleDescription"));
    setDefaultCloseOperation(HIDE_ON_CLOSE);
    setResizable(false);
    JComponent cp = (JComponent) getContentPane();

    createActions();

    JLabel mastheadLabel = new JLabel(mastheadIcon);
    setAccessibleName(mastheadLabel, getText("Help.AboutDialog.masthead.accessibleName"));

    JPanel mainPanel = new TPanel(0, 0);
    mainPanel.add(mastheadLabel, NORTH);

    String jConsoleVersion = Version.getVersion();
    String vmName = System.getProperty("java.vm.name");
    String vmVersion = System.getProperty("java.vm.version");
    String urlStr = getText("Help.AboutDialog.userGuideLink.url");
    if (isBrowseSupported()) {
      urlStr = "<a style='color:#35556b' href=\"" + urlStr + "\">" + urlStr + "</a>";
    }

    JPanel infoAndLogoPanel = new JPanel(new BorderLayout(10, 10));
    infoAndLogoPanel.setBackground(bgColor);

    String colorStr = String.format("%06x", textColor.getRGB() & 0xFFFFFF);
    JEditorPane helpLink =
        new JEditorPane(
            "text/html",
            "<html><font color=#"
                + colorStr
                + ">"
                + getText("Help.AboutDialog.jConsoleVersion", jConsoleVersion)
                + "<p>"
                + getText("Help.AboutDialog.javaVersion", (vmName + ", " + vmVersion))
                + "<p>"
                + getText("Help.AboutDialog.userGuideLink", urlStr)
                + "</html>");
    helpLink.setOpaque(false);
    helpLink.setEditable(false);
    helpLink.setForeground(textColor);
    mainPanel.setBorder(BorderFactory.createLineBorder(borderColor));
    infoAndLogoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    helpLink.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              browse(e.getDescription());
            }
          }
        });
    infoAndLogoPanel.add(helpLink, NORTH);

    ImageIcon brandLogoIcon = new ImageIcon(getClass().getResource("resources/brandlogo.png"));
    JLabel brandLogo = new JLabel(brandLogoIcon, JLabel.LEADING);

    JButton closeButton = new JButton(closeAction);

    JPanel bottomPanel = new TPanel(0, 0);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
    buttonPanel.setOpaque(false);

    mainPanel.add(infoAndLogoPanel, CENTER);
    cp.add(bottomPanel, SOUTH);

    infoAndLogoPanel.add(brandLogo, SOUTH);

    buttonPanel.setBorder(new EmptyBorder(2, 12, 2, 12));
    buttonPanel.add(closeButton);
    bottomPanel.add(buttonPanel, NORTH);

    statusBar = new JLabel(" ");
    bottomPanel.add(statusBar, SOUTH);

    cp.add(mainPanel, NORTH);

    pack();
    setLocationRelativeTo(jConsole);
    Utilities.updateTransparency(this);
  }
  protected void buildChooser() {

    String redString = UIManager.getString("ColorChooser.rgbRedText");
    String greenString = UIManager.getString("ColorChooser.rgbGreenText");
    String blueString = UIManager.getString("ColorChooser.rgbBlueText");

    setLayout(new BorderLayout());
    Color color = getColorFromModel();

    JPanel enclosure = new JPanel();
    enclosure.setLayout(new SmartGridLayout(3, 3));
    enclosure.setInheritsPopupMenu(true);

    // The panel that holds the sliders

    add(enclosure, BorderLayout.CENTER);
    //        sliderPanel.setBorder(new LineBorder(Color.black));

    // The row for the red value
    JLabel l = new JLabel(redString);
    l.setDisplayedMnemonic(AbstractColorChooserPanel.getInt("ColorChooser.rgbRedMnemonic", -1));
    enclosure.add(l);
    redSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getRed());
    redSlider.setMajorTickSpacing(85);
    redSlider.setMinorTickSpacing(17);
    redSlider.setPaintTicks(true);
    redSlider.setPaintLabels(true);
    redSlider.setInheritsPopupMenu(true);
    enclosure.add(redSlider);
    redField = new JSpinner(new SpinnerNumberModel(color.getRed(), minValue, maxValue, 1));
    l.setLabelFor(redSlider);
    redField.setInheritsPopupMenu(true);
    JPanel redFieldHolder = new JPanel(new CenterLayout());
    redFieldHolder.setInheritsPopupMenu(true);
    redField.addChangeListener(this);
    redFieldHolder.add(redField);
    enclosure.add(redFieldHolder);

    // The row for the green value
    l = new JLabel(greenString);
    l.setDisplayedMnemonic(AbstractColorChooserPanel.getInt("ColorChooser.rgbGreenMnemonic", -1));
    enclosure.add(l);
    greenSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getGreen());
    greenSlider.setMajorTickSpacing(85);
    greenSlider.setMinorTickSpacing(17);
    greenSlider.setPaintTicks(true);
    greenSlider.setPaintLabels(true);
    greenSlider.setInheritsPopupMenu(true);
    enclosure.add(greenSlider);
    greenField = new JSpinner(new SpinnerNumberModel(color.getGreen(), minValue, maxValue, 1));
    l.setLabelFor(greenSlider);
    greenField.setInheritsPopupMenu(true);
    JPanel greenFieldHolder = new JPanel(new CenterLayout());
    greenFieldHolder.add(greenField);
    greenFieldHolder.setInheritsPopupMenu(true);
    greenField.addChangeListener(this);
    enclosure.add(greenFieldHolder);

    // The slider for the blue value
    l = new JLabel(blueString);
    l.setDisplayedMnemonic(AbstractColorChooserPanel.getInt("ColorChooser.rgbBlueMnemonic", -1));
    enclosure.add(l);
    blueSlider = new JSlider(JSlider.HORIZONTAL, 0, 255, color.getBlue());
    blueSlider.setMajorTickSpacing(85);
    blueSlider.setMinorTickSpacing(17);
    blueSlider.setPaintTicks(true);
    blueSlider.setPaintLabels(true);
    blueSlider.setInheritsPopupMenu(true);
    enclosure.add(blueSlider);
    blueField = new JSpinner(new SpinnerNumberModel(color.getBlue(), minValue, maxValue, 1));
    l.setLabelFor(blueSlider);
    blueField.setInheritsPopupMenu(true);
    JPanel blueFieldHolder = new JPanel(new CenterLayout());
    blueFieldHolder.add(blueField);
    blueField.addChangeListener(this);
    blueFieldHolder.setInheritsPopupMenu(true);
    enclosure.add(blueFieldHolder);

    redSlider.addChangeListener(this);
    greenSlider.addChangeListener(this);
    blueSlider.addChangeListener(this);

    redSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    greenSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    blueSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
  }
 public MenuButtonAcqMode(Color color) {
   this(color, color.toString());
 }