use of javax.swing.plaf.ColorUIResource in project jdk8u_jdk by JetBrains.
the class WrongBackgroundColor method main.
public static void main(final String[] args) throws InvocationTargetException, InterruptedException {
SwingUtilities.invokeAndWait(() -> {
UIDefaults ui = UIManager.getDefaults();
ui.put("control", new ColorUIResource(54, 54, 54));
final JDialog dialog = new JDialog();
final JFrame frame = new JFrame();
frame.pack();
dialog.pack();
final Color dialogBackground = dialog.getBackground();
final Color frameBackground = frame.getBackground();
frame.dispose();
dialog.dispose();
if (!dialogBackground.equals(frameBackground)) {
System.err.println("Expected:" + frameBackground);
System.err.println("Actual:" + dialogBackground);
throw new RuntimeException("Wrong background color");
}
});
}
use of javax.swing.plaf.ColorUIResource in project intellij-community by JetBrains.
the class LafManagerImpl method fixTreeWideSelection.
private static void fixTreeWideSelection(UIDefaults uiDefaults) {
if (UIUtil.isUnderAlloyIDEALookAndFeel() || UIUtil.isUnderJGoodiesLookAndFeel()) {
final Color bg = new ColorUIResource(56, 117, 215);
final Color fg = new ColorUIResource(255, 255, 255);
uiDefaults.put("info", bg);
uiDefaults.put("textHighlight", bg);
for (String key : ourAlloyComponentsToPatchSelection) {
uiDefaults.put(key + ".selectionBackground", bg);
uiDefaults.put(key + ".selectionForeground", fg);
}
}
}
use of javax.swing.plaf.ColorUIResource in project intellij-community by JetBrains.
the class ShowUIDefaultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final UIDefaults defaults = UIManager.getDefaults();
Enumeration keys = defaults.keys();
final Object[][] data = new Object[defaults.size()][2];
int i = 0;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
data[i][0] = key;
data[i][1] = defaults.get(key);
i++;
}
Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
final Project project = getEventProject(e);
new DialogWrapper(project) {
{
setTitle("Edit LaF Defaults");
setModal(false);
init();
}
public JBTable myTable;
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myTable;
}
@Nullable
@Override
protected String getDimensionServiceKey() {
return project == null ? null : "UI.Defaults.Dialog";
}
@Override
protected JComponent createCenterPanel() {
final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 1 && getValueAt(row, column) instanceof Color;
}
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
if (newColor != null) {
final ColorUIResource colorUIResource = new ColorUIResource(newColor);
final Object key = getValueAt(row, 0);
UIManager.put(key, colorUIResource);
setValueAt(colorUIResource, row, column);
}
}
return false;
}
};
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(value == null ? "" : value.toString());
panel.add(label, BorderLayout.CENTER);
if (value instanceof Color) {
final Color c = (Color) value;
label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
try {
final Icon icon = new IconWrap((Icon) value);
if (icon.getIconHeight() <= 20) {
label.setIcon(icon);
}
label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
} catch (Throwable e1) {
//
}
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border) value).getBorderInsets(null);
label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
final JBScrollPane pane = new JBScrollPane(table);
new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
table.setShowGrid(false);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
myTable = table;
TableUtil.ensureSelectionExists(myTable);
return panel;
}
}.show();
}
use of javax.swing.plaf.ColorUIResource in project adempiere by adempiere.
the class ThemeUtils method parseColor.
// getColorAsString
/**
* Parse Color.
* <p>
* Color - [r=102,g=102,b=153,a=0]
*
* @param information string information to be parsed
* @param stdColor color used if info cannot parsed
* @return color
* @see #getColorAsString
*/
public static ColorUIResource parseColor(String information, ColorUIResource stdColor) {
if (information == null || information.length() == 0 || information.trim().length() == 0)
return stdColor;
// System.out.print("ParseColor=" + info);
try {
int r = Integer.parseInt(information.substring(information.indexOf("r=") + 2, information.indexOf(",g=")));
int g = Integer.parseInt(information.substring(information.indexOf("g=") + 2, information.indexOf(",b=")));
int b = 0;
int a = 255;
if (information.indexOf("a=") == -1)
b = Integer.parseInt(information.substring(information.indexOf("b=") + 2, information.indexOf(']')));
else {
b = Integer.parseInt(information.substring(information.indexOf("b=") + 2, information.indexOf(",a=")));
a = Integer.parseInt(information.substring(information.indexOf("a=") + 2, information.indexOf(']')));
}
ColorUIResource retValue = new ColorUIResource(new Color(r, g, b, a));
// System.out.println(" - " + retValue.toString());
return retValue;
} catch (Exception e) {
log.config(information + " - cannot parse: " + e.toString());
}
return stdColor;
}
use of javax.swing.plaf.ColorUIResource in project adempiere by adempiere.
the class AdempiereTheme method addCustomEntriesToTable.
public void addCustomEntriesToTable(UIDefaults table) {
super.addCustomEntriesToTable(table);
Object[] uiDefaults = { "ScrollBar.thumbHighlight", getPrimaryControlHighlight(), PlasticScrollBarUI.MAX_BUMPS_WIDTH_KEY, new Integer(22), PlasticScrollBarUI.MAX_BUMPS_WIDTH_KEY, new Integer(30), //"TabbedPane.selected", getWhite(),
"TabbedPane.selectHighlight", new ColorUIResource(231, 218, 188), ExtendedTheme.ERROR_BG_KEY, error, ExtendedTheme.ERROR_FG_KEY, txt_error, ExtendedTheme.INACTIVE_BG_KEY, inactive, ExtendedTheme.INFO_BG_KEY, info, ExtendedTheme.MANDATORY_BG_KEY, mandatory };
table.putDefaults(uiDefaults);
}
Aggregations