private void setSubscriberDetails( String subscriberName, String subscriberAddress, String message) { this.name = subscriberName; this.address = subscriberAddress; Color color = messagePane.getForeground(); messagePane.setText( "<FONT COLOR=\"#" + Integer.toHexString(color.getRGB()).substring(2) + "\">" + messageString1 + "<p>" + namePrefix + name + nameSuffix + "<br>" + addressPrefix + address + addressSuffix + "<p>" + ((message != null && message.trim().length() > 0) ? messagePrefix + message + messageSuffix + "<p>" : "") + messageString2 + "</FONT>"); }
public void paintIcon(Component c, Graphics g, int x, int y) { Color color = c == null ? Color.GRAY : c.getBackground(); // In a compound sort, make each succesive triangle 20% // smaller than the previous one. int dx = (int) (size / 2 * Math.pow(0.8, priority)); int dy = descending ? dx : -dx; // Align icon (roughly) with font baseline. y = y + 5 * size / 6 + (descending ? -dy : 0); int shift = descending ? 1 : -1; g.translate(x, y); // Right diagonal. g.setColor(color.darker()); g.drawLine(dx / 2, dy, 0, 0); g.drawLine(dx / 2, dy + shift, 0, shift); // Left diagonal. g.setColor(color.brighter()); g.drawLine(dx / 2, dy, dx, 0); g.drawLine(dx / 2, dy + shift, dx, shift); // Horizontal line. if (descending) { g.setColor(color.darker().darker()); } else { g.setColor(color.brighter().brighter()); } g.drawLine(dx, 0, 0, 0); g.setColor(color); g.translate(-x, -y); }
/** 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; }
/** * Function: getJavaColor Pre: Takes an ANIMAL color string 'c' Post: Returns the java color for * this node (Note: returns "white" as a default) */ private Color getJavaColor(String c) { if (!isValidNodeColor(c)) return Color.white; // Temporary color to use with numbered colors Color temp = Color.white; if (c.compareTo("black") == 0) return Color.black; if (c.compareTo("white") == 0) return Color.white; if (c.compareTo("gray") == 0) return Color.gray; if (c.compareTo("yellow") == 0) return Color.yellow; if (c.startsWith("blue")) temp = Color.blue; if (c.startsWith("cyan")) temp = Color.cyan; if (c.startsWith("pink")) temp = Color.pink; if (c.startsWith("red")) temp = Color.red; if (c.startsWith("magenta")) temp = Color.magenta; if (c.startsWith("green")) temp = Color.green; // Finally, do some final handling for temp = temp.darker().darker(); if (c.endsWith("2")) return temp.brighter(); if (c.endsWith("3")) return temp.brighter().brighter(); if (c.endsWith("4")) return temp.brighter().brighter().brighter(); return temp; }
private void drawColorButton(Graphics g, int no) { g.setColor(cDarkShadowColor); g.drawLine(mRect[no].x, mRect[no].y, mRect[no].x + mRect[no].width - 2, mRect[no].y); g.drawLine(mRect[no].x, mRect[no].y, mRect[no].x, mRect[no].y + mRect[no].height - 2); g.drawLine( mRect[no].x + mRect[no].width - 2, mRect[no].y + 2, mRect[no].x + mRect[no].width - 2, mRect[no].y + mRect[no].height - 2); g.drawLine( mRect[no].x + 2, mRect[no].y + mRect[no].height - 2, mRect[no].x + mRect[no].width - 2, mRect[no].y + mRect[no].height - 2); if (mPressedButton != no || !mMouseOverButton) g.setColor(Color.white); g.drawLine( mRect[no].x + 1, mRect[no].y + 1, mRect[no].x + mRect[no].width - 3, mRect[no].y + 1); g.drawLine( mRect[no].x + 1, mRect[no].y + 1, mRect[no].x + 1, mRect[no].y + mRect[no].height - 3); if (mPressedButton == no && mMouseOverButton) g.setColor(Color.white); g.drawLine( mRect[no].x + mRect[no].width - 1, mRect[no].y + 1, mRect[no].x + mRect[no].width - 1, mRect[no].y + mRect[no].height - 1); g.drawLine( mRect[no].x + 1, mRect[no].y + mRect[no].height - 1, mRect[no].x + mRect[no].width - 1, mRect[no].y + mRect[no].height - 1); if (mColorListMode != VisualizationColor.cColorListModeCategories && no == cColorWedgeButton) { int x1 = mRect[no].x + 2; int x2 = x1 + mRect[no].width - 4; if (x1 < x2) { for (int x = x1; x < x2; x++) { int c = mWedgeColorList.length * (x - x1) / (x2 - x1); g.setColor( (mPressedButton == no && mMouseOverButton) ? mWedgeColorList[c].darker() : mWedgeColorList[c]); g.drawLine(x, mRect[no].y + 2, x, mRect[no].y + mRect[no].height - 3); } } } else { Color color = (mColorListMode == VisualizationColor.cColorListModeCategories) ? mCategoryColorList[no] : mWedgeColorList[no * (mWedgeColorList.length - 1)]; if (mPressedButton == no && mMouseOverButton) color = color.darker(); g.setColor(color); g.fillRect(mRect[no].x + 2, mRect[no].y + 2, mRect[no].width - 4, mRect[no].height - 4); } }
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); }
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(); }
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); }
@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); }
/** * 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(); } }
// 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(); }
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); }
private void remove(int x, int y, Color c) { if (c.equals(Color.RED)) { numRedCheckers--; } else { numBlackCheckers--; } }
private NewPanel() { setBackground(Color.decode(ColorManager.getCreatePanelBackground())); Dimension dim = new Dimension(200, 120); setPreferredSize(dim); JTextField text = new JTextField("", 15); SubmitButton submit = new SubmitButton(text); setBorder( BorderFactory.createMatteBorder( 5, 5, 5, 5, Color.decode(ColorManager.getCreatePanelBorder()))); JLabel label = new JLabel("Create a new button"); label.setForeground(Color.decode(ColorManager.getCreatePanelText())); add(label); add(text); add(submit); }
void drawSpectrum(double h) { Color c; for (int x = 5; x < 7; x++) { for (int y = 0; y < 32; y++) { float hue = (float) (y / (2 * h) - .15); c = Color.getHSBColor(hue, 1f, 1f); setRoi(x * (int) (w / 2), y * (int) (h / 2), (int) w / 2, (int) h / 2); setColor(c); fill(); } } setRoi(55, 32, 22, 16); // Solid red setColor(0xff0000); fill(); setRoi(55, 120, 22, 16); // Solid green setColor(0x00ff00); fill(); setRoi(55, 208, 22, 16); // Solid blue setColor(0x0000ff); fill(); setRoi(55, 80, 22, 8); // Solid yellow setColor(0xffff00); fill(); setRoi(55, 168, 22, 8); // Solid cyan setColor(0x00ffff); fill(); setRoi(55, 248, 22, 8); // Solid magenta setColor(0xff00ff); fill(); }
private Color changeColor() { // Commands to change the colors of the two Yin Yangs randomly // to some other color return new Color( Color.HSBtoRGB( randomNumber.nextFloat(), randomNumber.nextFloat(), randomNumber.nextFloat())); }
/** * Class constructor alloowing specification of the heading text. * * @param properties the Properties object containing the initial values of the extensions list * and the path to be displayed. This object is updated tin response to root changes, * extension changes, and file selections. If any property is missing, a suitable one is * supplied by default. * @param heading the text to appear in the heading of the JPanel. * @param background the background color or null if the default is to be used. */ public SourcePanel(ApplicationProperties properties, String heading, Color background) { super(); this.properties = properties; if (background == null) this.background = Color.getHSBColor(0.58f, 0.17f, 0.95f); else this.background = background; // Make the file filter filter = new GeneralFileFilter(); String extensions = properties.getProperty("extensions"); if (extensions != null) filter.setExtensions(extensions); else { filter.addExtension(".dcm"); properties.setProperty("extensions", filter.getExtensionString()); } // Get the starting directory path from the properties. // If it is missing, start in the directory containing the program. String currentDirectoryPath = properties.getProperty("directory"); if (currentDirectoryPath == null) currentDirectoryPath = System.getProperty("user.dir"); // Create the UI components this.setLayout(new BorderLayout()); directoryPane = new DirectoryPane(filter, currentDirectoryPath); directoryPane.addFileListener(this); headerPanel = new HeaderPanel(heading); footerPanel = new FooterPanel(); this.add(headerPanel, BorderLayout.NORTH); this.add(directoryPane, BorderLayout.CENTER); this.add(footerPanel, BorderLayout.SOUTH); }
public void paintIcon(Component c, Graphics g, int x, int y) { if (color == null) return; g.setColor(color); g.fillRect(x, y, getIconWidth(), getIconHeight()); g.setColor(color.darker()); g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 1); }
/** * \ Draw saved State (color dots on panel) on WhiteBoard * * @param outstream * @throws IOException */ public void writeState(OutputStream outstream) throws IOException { if (state == null) return; synchronized (state) { DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(outstream)); // DataOutputStream dos=new DataOutputStream(outstream); dos.writeInt(state.size()); for (Map.Entry<Point, Color> entry : state.entrySet()) { Point point = entry.getKey(); Color col = entry.getValue(); dos.writeInt(point.x); dos.writeInt(point.x); dos.writeInt(col.getRGB()); } dos.flush(); System.out.println("wrote " + state.size() + " elements"); } }
/** {@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); }
// ------------------------------------------------------------------------------------------------ // 描述: // 设计: Skyline(2001.12.29) // 实现: Skyline // 修改:setFontColor // ------------------------------------------------------------------------------------------------ void setFrontColor(Color clr) { CellFormat CF; try { CF = mBook.getCellFormat(); CF.setFontColor(clr.getRGB()); mBook.setCellFormat(CF); } catch (Exception e) { e.printStackTrace(); } }
public void generateColorWheel() { for (int index = 0; index < myPixels.length; index++) { if (myAlphas[index] != 0) { myPixels[index] = myAlphas[index] | 0xffffff & Color.HSBtoRGB(myHues[index], mySat[index], myBrightness); } } newPixels(); }
void initComponents() { JPanel mainPanel = new JPanel(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); Color bgColor = Color.getHSBColor(0.58f, 0.17f, 0.95f); buttonPanel.setBackground(bgColor); Border empty = BorderFactory.createEmptyBorder(5, 5, 5, 5); buttonPanel.setBorder(empty); textField = new JTextField(75); buttonPanel.add(textField); buttonPanel.add(Box.createHorizontalStrut(10)); searchPHI = new JButton("Search PHI"); searchPHI.addActionListener(this); buttonPanel.add(searchPHI); buttonPanel.add(Box.createHorizontalStrut(10)); searchTrial = new JButton("Search Trial IDs"); searchTrial.addActionListener(this); buttonPanel.add(searchTrial); buttonPanel.add(Box.createHorizontalStrut(20)); buttonPanel.add(Box.createHorizontalGlue()); saveAs = new JCheckBox("Save As..."); saveAs.setBackground(bgColor); buttonPanel.add(saveAs); mainPanel.add(buttonPanel, BorderLayout.NORTH); JScrollPane scrollPane = new JScrollPane(); textPane = new ColorPane(); // textPane.setEditable(false); scrollPane.setViewportView(textPane); mainPanel.add(scrollPane, BorderLayout.CENTER); JPanel footerPanel = new JPanel(); footerPanel.setLayout(new BoxLayout(footerPanel, BoxLayout.X_AXIS)); footerPanel.setBackground(bgColor); message = new JLabel("Ready..."); footerPanel.add(message); mainPanel.add(footerPanel, BorderLayout.SOUTH); setTitle(windowTitle); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); getContentPane().add(mainPanel, BorderLayout.CENTER); pack(); centerFrame(); }
@Override public void setOpaque(boolean isOpaque) { CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque); boolean isTextured = (peer == null) ? false : peer.isTextured(); if (!isTextured) { if (!isOpaque) { CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), 0); } else if (peer != null) { Color color = peer.getBackground(); if (color != null) { int rgb = color.getRGB(); CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), rgb); } } } // This is a temporary workaround. Looks like after 7124236 will be fixed // the correct place for invalidateShadow() is CGLayer.drawInCGLContext. SwingUtilities.invokeLater(this::invalidateShadow); }
// ------------------------------------------------------------------------------------------------ // 描述: // 设计: Skyline(2001.12.29) // 实现: Skyline // 修改: // ------------------------------------------------------------------------------------------------ void setBackColor(Color clr) { CellFormat CF; try { CF = mBook.getCellFormat(); CF.setPattern(CellFormat.ePatternSolid); CF.setPatternFG(clr.getRGB()); mBook.setCellFormat(CF); } catch (Exception e) { e.printStackTrace(); } }
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() + ")"); }
/** * selectClickable -- a recursive function which searches the game board for game balls of the * same color as the one selected, and 'selects' them as well. */ public void selectClickable(int m, int n) { Color home = balls[m][n].getColor(); balls[m][n].select(); scount += 1; if ((n - 1) >= 0) { Color north = balls[m][n - 1].getColor(); if ((home.equals(north)) && !(balls[m][n - 1].isSelected())) selectClickable(m, (n - 1)); } if ((m - 1) >= 0) { Color west = balls[m - 1][n].getColor(); if ((home.equals(west)) && !(balls[m - 1][n].isSelected())) selectClickable((m - 1), n); } if ((n + 1) < B_HEIGHT) { Color south = balls[m][n + 1].getColor(); if ((home.equals(south)) && !(balls[m][n + 1].isSelected())) selectClickable(m, (n + 1)); } if ((m + 1) < B_WIDTH) { Color east = balls[m + 1][n].getColor(); if ((home.equals(east)) && !(balls[m + 1][n].isSelected())) selectClickable((m + 1), n); } }