Java Code Examples for java.awt.Color#equals()

The following examples show how to use java.awt.Color#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MouseSelection.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Color getBackgroundA() {
    Color background = functions.get(0).getBackground();
    for (int i = 1; i < functions.size(); i++) {
        if (!background.equals(functions.get(i).getBackground()))
            return null;
    }
    return background;
}
 
Example 2
Source File: DefaultListCellRenderer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Overridden for performance reasons.
 * See the <a href="#override">Implementation Note</a>
 * for more information.
 *
 * @since 1.5
 * @return <code>true</code> if the background is completely opaque
 *         and differs from the JList's background;
 *         <code>false</code> otherwise
 */
@Override
public boolean isOpaque() {
    Color back = getBackground();
    Component p = getParent();
    if (p != null) {
        p = p.getParent();
    }
    // p should now be the JList.
    boolean colorMatch = (back != null) && (p != null) &&
        back.equals(p.getBackground()) &&
                    p.isOpaque();
    return !colorMatch && super.isOpaque();
}
 
Example 3
Source File: UiUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Color extractCommonColorForColorChooserButton(@Nonnull final String colorAttribute, @Nonnull @MustNotContainNull final Topic[] topics) {
  Color result = null;
  for (final Topic t : topics) {
    final Color color = html2color(t.getAttribute(colorAttribute), false);
    if (result == null) {
      result = color;
    } else if (!result.equals(color)) {
      return ColorChooserButton.DIFF_COLORS;
    }
  }
  return result;
}
 
Example 4
Source File: DrawGraphics.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void setTopBorderLineColor(Color color) {
    if ((color != this.topBorderLineColor)
        && (color == null
            || !color.equals(this.topBorderLineColor))
    ) {
        flush();
        this.topBorderLineColor = color;
    }
}
 
Example 5
Source File: WPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the GDI color for text drawing.
 */
protected void setTextColor(Color color) {

    /* We only need to select a brush if the color has changed.
    */
    if (color.equals(mLastTextColor) == false) {
        mLastTextColor = color;
        float[] rgb = color.getRGBColorComponents(null);

        setTextColor(getPrintDC(),
                     (int) (rgb[0] * MAX_WCOLOR),
                     (int) (rgb[1] * MAX_WCOLOR),
                     (int) (rgb[2] * MAX_WCOLOR));
    }
}
 
Example 6
Source File: WPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void selectSolidBrush(Color color) {

        /* We only need to select a brush if the color has changed.
        */
        if (color.equals(mLastColor) == false) {
            mLastColor = color;
            float[] rgb = color.getRGBColorComponents(null);

            selectSolidBrush(getPrintDC(),
                             (int) (rgb[0] * MAX_WCOLOR),
                             (int) (rgb[1] * MAX_WCOLOR),
                             (int) (rgb[2] * MAX_WCOLOR));
        }
    }
 
Example 7
Source File: DefaultListCellRenderer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Overridden for performance reasons.
 * See the <a href="#override">Implementation Note</a>
 * for more information.
 *
 * @since 1.5
 * @return <code>true</code> if the background is completely opaque
 *         and differs from the JList's background;
 *         <code>false</code> otherwise
 */
@Override
public boolean isOpaque() {
    Color back = getBackground();
    Component p = getParent();
    if (p != null) {
        p = p.getParent();
    }
    // p should now be the JList.
    boolean colorMatch = (back != null) && (p != null) &&
        back.equals(p.getBackground()) &&
                    p.isOpaque();
    return !colorMatch && super.isOpaque();
}
 
Example 8
Source File: OutputOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setColorLinkImportant(Color colorLinkImportant) {
    Parameters.notNull("colorLinkImportant", colorLinkImportant);   //NOI18N
    if (!colorLinkImportant.equals(this.colorLinkImportant)) {
        Color oldColorLinkImportant = this.colorLinkImportant;
        this.colorLinkImportant = colorLinkImportant;
        pcs.firePropertyChange(PROP_COLOR_LINK_IMPORTANT,
                oldColorLinkImportant, colorLinkImportant);
    }
}
 
Example 9
Source File: ColorPanel.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void setColor(Color color) {
    if (!color.equals(this.color)) {
        this.color = color;
        this.model.setColor(color.getRGB(), this.values);
        for (int i = 0; i < this.model.getCount(); i++) {
            this.spinners[i].setValue(this.values[i]);
        }
    }
}
 
Example 10
Source File: DefaultTableCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Overridden for performance reasons.
 * See the <a href="#override">Implementation Note</a>
 * for more information.
 */
public boolean isOpaque() {
    Color back = getBackground();
    Component p = getParent();
    if (p != null) {
        p = p.getParent();
    }

    // p should now be the JTable.
    boolean colorMatch = (back != null) && (p != null) &&
        back.equals(p.getBackground()) &&
                    p.isOpaque();
    return !colorMatch && super.isOpaque();
}
 
Example 11
Source File: CodeViewer.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public void setHighlightColor(Color highlight) {
    if (!highlight.equals(highlightColor)) {
        highlightColor = highlight;
        snippetPainter = new SnippetHighlighter.SnippetHighlightPainter(highlightColor);
        if (getCurrentSnippetKey() != null) {
            repaint();
        }
    }
}
 
Example 12
Source File: WPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void selectSolidBrush(Color color) {

        /* We only need to select a brush if the color has changed.
        */
        if (color.equals(mLastColor) == false) {
            mLastColor = color;
            float[] rgb = color.getRGBColorComponents(null);

            selectSolidBrush(getPrintDC(),
                             (int) (rgb[0] * MAX_WCOLOR),
                             (int) (rgb[1] * MAX_WCOLOR),
                             (int) (rgb[2] * MAX_WCOLOR));
        }
    }
 
Example 13
Source File: ListingDisplayOptionsEditor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void apply() {
	if (optionsGui != null) {

		Font font = options.getFont(GhidraOptions.OPTION_BASE_FONT, DEFAULT_FONT);
		Font newFont = optionsGui.getBaseFont();
		if (!newFont.equals(font)) {
			options.setFont(GhidraOptions.OPTION_BASE_FONT, newFont);
		}

		for (ScreenElement element : OptionsGui.elements) {
			Color guiColor = element.getColor();
			Color optionColor =
				options.getColor(element.getColorOptionName(), element.getDefaultColor());
			if (!optionColor.equals(guiColor)) {
				options.setColor(element.getColorOptionName(), guiColor);
			}

			int optionStyle = options.getInt(element.getStyleOptionName(), -1);
			int guiStyle = element.getStyle();
			if (optionStyle != guiStyle) {
				options.setInt(element.getStyleOptionName(), guiStyle);
			}
		}

	}
}
 
Example 14
Source File: Coloring.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Derive a new coloring by changing
* the background-color and its color-mode
* and leaving the rest of the coloring unchanged.
*/
public static Coloring changeBackColor(Coloring c, Color newBackColor) {
    if ((newBackColor == null && c.backColor == null)
            || (newBackColor != null && newBackColor.equals(c.backColor))
       ) {
        return c;
    }

    return new Coloring(c.font, c.foreColor, newBackColor);
}
 
Example 15
Source File: FlatButtonUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
protected void paintBackground( Graphics g, JComponent c ) {
	Color background = getBackground( c );
	if( background == null )
		return;

	Graphics2D g2 = (Graphics2D) g.create();
	try {
		FlatUIUtils.setRenderingHints( g2 );

		boolean isToolBarButton = isToolBarButton( c );
		float focusWidth = isToolBarButton ? 0 : FlatUIUtils.getBorderFocusWidth( c );
		float arc = FlatUIUtils.getBorderArc( c );

		boolean def = isDefaultButton( c );

		int x = 0;
		int y = 0;
		int width = c.getWidth();
		int height = c.getHeight();

		if( isToolBarButton ) {
			Insets spacing = UIScale.scale( toolbarSpacingInsets );
			x += spacing.left;
			y += spacing.top;
			width -= spacing.left + spacing.right;
			height -= spacing.top + spacing.bottom;
		}

		// paint shadow
		Color shadowColor = def ? defaultShadowColor : this.shadowColor;
		if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 &&
			!(isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c )) && c.isEnabled() )
		{
			g2.setColor( shadowColor );
			g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
				width - focusWidth * 2, height - focusWidth * 2, arc, arc ) );
		}

		// paint background
		Color startBg = def ? defaultBackground : startBackground;
		Color endBg = def ? defaultEndBackground : endBackground;
		if( background == startBg && endBg != null && !startBg.equals( endBg ) )
			g2.setPaint( new GradientPaint( 0, 0, startBg, 0, height, endBg ) );
		else
			g2.setColor( FlatUIUtils.deriveColor( background, getBackgroundBase( c, def ) ) );

		FlatUIUtils.paintComponentBackground( g2, x, y, width, height, focusWidth, arc );
	} finally {
		g2.dispose();
	}
}
 
Example 16
Source File: StyleEditor.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
void set(Component[] c) {
   String  ff      = null;
   int     sz      = -1;
   int     st      = -1;
   int     ha      = -1;
   int     va      = -1;
   Color   fg      = null;
   Color   bg      = null;
   boolean enAlign = false;
   if(c != null && c.length != 0) {
     Component cmp = getCmp(c[0]);
     fg = cmp.getForeground();
     bg = cmp.getBackground();
     ff = cmp.getFont().getFamily();
     sz = cmp.getFont().getSize();
     st = cmp.getFont().getStyle();
     for(int i = 0; i < c.length; i++) {
cmp = getCmp(c[i]);
if(fg != null && !fg.equals(cmp.getForeground()))
  fg = null;
if(bg != null && !bg.equals(cmp.getBackground()))
  bg = null;
if(ff != null && !ff.equals(cmp.getFont().getFamily()))
  ff = null;
if(sz != -1 && cmp.getFont().getSize() != sz)
  sz = -1;
if(st != -1 && cmp.getFont().getStyle() != st)
  st = -1;	
if(cmp instanceof JLabel) {
  ha = ((JLabel)cmp).getHorizontalAlignment();
  va = ((JLabel)cmp).getVerticalAlignment();
}
if(cmp instanceof AbstractButton) {
  ha = ((AbstractButton)cmp).getHorizontalAlignment();
  va = ((AbstractButton)cmp).getVerticalAlignment();
}
     }
     
     selStyle = new Style(ff, st, sz, ha, va, bg, fg);
   } else {
     selStyle = null;
   }
   setupUI(getCurrStyle());
   repaint();
 }
 
Example 17
Source File: PGTUtil.java    From PolyGlot with MIT License 4 votes vote down vote up
/**
 * gets a worker that can make a given component flash
 *
 * @param flashMe component to make flash
 * @param flashColor color to use for flashing
 * @param isBack whether display color is background (rather than foreground)
 * @return SwingWorker that will make given component flash if run
 */
public static SwingWorker getFlashWorker(final JComponent flashMe, final Color flashColor, final boolean isBack) {
    // this will pop out in its own little thread...
    return new SwingWorker() {
        @Override
        protected Object doInBackground() {
            Color originColor;
            if (isBack) {
                originColor = flashMe.getBackground();
            } else {
                originColor = flashMe.getForeground();
            }

            Color requiredColor = flashColor.equals(originColor)
                    ? Color.white : flashColor;

            try {
                for (int i = 0; i < PGTUtil.NUM_MENU_FLASHES; i++) {
                    if (isBack) {
                        flashMe.setBackground(requiredColor);
                    } else {
                        flashMe.setEnabled(false);
                    }
                    // suppression for this is broken. Super annoying.
                    Thread.sleep(PGTUtil.MENU_FLASH_SLEEP);
                    if (isBack) {
                        flashMe.setBackground(originColor);
                    } else {
                        flashMe.setEnabled(true);
                    }
                    Thread.sleep(PGTUtil.MENU_FLASH_SLEEP);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                // catch of thread interrupt not logworthy
                // IOHandler.writeErrorLog(e);
            }

            return null;
        }
    };
}
 
Example 18
Source File: TransparencyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsDevice.WindowTranslucency mode = GraphicsDevice.WindowTranslucency.TRANSLUCENT;
        boolean translucencyCheck = gd.isWindowTranslucencySupported(mode);
        if(!translucencyCheck) {
            return;
    }

        Robot robot = new Robot();
        // create a GUI
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                createAndShowGUI();
            }
        });
        robot.waitForIdle();
        Color opaque = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100);

        // set Dialog Opacity
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                dialog.setOpacity(OPACITY);
            }
        });
        robot.waitForIdle();

        // iconify frame
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                frame.setExtendedState(JFrame.ICONIFIED);
            }
        });
        robot.waitForIdle();

        // deiconify frame
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                frame.setExtendedState(JFrame.NORMAL);
            }
        });
        robot.waitForIdle();

        Color transparent = robot.getPixelColor(dlgPos.x + 100, dlgPos.y + 100);
        if (transparent.equals(opaque)) {
            frame.dispose();
            throw new RuntimeException("JDialog transparency lost "
                    + "upon iconify/deiconify sequence");
        }
        frame.dispose();
    }
 
Example 19
Source File: HtmlPrintContainer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private String createStyle (String element, String selector, Font font, Color fg, Color bg, boolean useDefaults) {
    StringBuffer sb = new StringBuffer();
    if (element != null) {
        sb.append (element);
        sb.append (WS);
    }

    if (selector != null) {
        sb.append (DOT);
        sb.append (selector);
        sb.append (WS);
    }

    sb.append (ST_BEGIN);
    boolean first = true;
    if ((!useDefaults || !fg.equals(getDefaultColor())) && fg != null) {
        sb.append (ST_COLOR);
        sb.append (getHtmlColor(fg));
        first = false;
    }

    if ((!useDefaults || !bg.equals (getDefaultBackgroundColor())) && bg != null) {
        if (!first) {
            sb.append (ST_SEPARATOR);
        }
        sb.append (ST_BGCOLOR);
        sb.append (getHtmlColor(bg));
        first = false;
    }

    if ((!useDefaults || !font.equals (getDefaultFont())) && font != null) {
        if (!first) {
            sb.append (ST_SEPARATOR);
        }
        sb.append (ST_FONT_FAMILY);
        switch(font.getFamily()) {
            case Font.MONOSPACED:
                sb.append (FF_MONOSPACE);
                break;
            case Font.SERIF:
                sb.append (FF_SERIF);
                break;
            case Font.SANS_SERIF:
                sb.append (FF_SANSSERIF);
                break;
            case Font.DIALOG:
                sb.append (FF_SANSSERIF);
                break;
            case Font.DIALOG_INPUT:
                sb.append (FF_MONOSPACE);
                break;
            default:
                sb.append (font.getFamily()); //TODO: Locale should go here
        }
        if (font.isBold()) {
            sb.append (ST_SEPARATOR);
            sb.append (ST_BOLD);
        }
        if (font.isItalic()) {
            sb.append (ST_SEPARATOR);
            sb.append (ST_ITALIC);
        }
        Font df = getDefaultFont();
        if (df != null && df.getSize() != font.getSize()) {
            sb.append (ST_SEPARATOR);
            sb.append (ST_SIZE);
            sb.append (String.valueOf(font.getSize()));
        }

    }
    sb.append (ST_END);
    return sb.toString();
}
 
Example 20
Source File: ColorButton.java    From jclic with GNU General Public License v2.0 4 votes vote down vote up
public void changeColor(Color c) {
  Color oldColor = getColor();
  setColor(c);
  if (!oldColor.equals(c))
    firePropertyChange(PROP_COLOR, oldColor, c);
}