Search in sources :

Example 1 with ColorUIResource

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");
        }
    });
}
Also used : UIDefaults(javax.swing.UIDefaults) JFrame(javax.swing.JFrame) Color(java.awt.Color) ColorUIResource(javax.swing.plaf.ColorUIResource) JDialog(javax.swing.JDialog)

Example 2 with ColorUIResource

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);
        }
    }
}
Also used : JBColor(com.intellij.ui.JBColor) ColorUIResource(javax.swing.plaf.ColorUIResource)

Example 3 with ColorUIResource

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();
}
Also used : EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) DefaultTableModel(javax.swing.table.DefaultTableModel) Enumeration(java.util.Enumeration) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) ColorUIResource(javax.swing.plaf.ColorUIResource) MouseEvent(java.awt.event.MouseEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) Border(javax.swing.border.Border) EventObject(java.util.EventObject) java.awt(java.awt) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) PairFunction(com.intellij.util.PairFunction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) ColorUIResource(javax.swing.plaf.ColorUIResource) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) EventObject(java.util.EventObject) Project(com.intellij.openapi.project.Project) EventObject(java.util.EventObject) EmptyIcon(com.intellij.util.ui.EmptyIcon) Border(javax.swing.border.Border) Nullable(org.jetbrains.annotations.Nullable) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 4 with ColorUIResource

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;
}
Also used : Color(java.awt.Color) SystemColor(java.awt.SystemColor) CompiereColor(org.compiere.plaf.CompiereColor) ColorUIResource(javax.swing.plaf.ColorUIResource)

Example 5 with ColorUIResource

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);
}
Also used : ColorUIResource(javax.swing.plaf.ColorUIResource)

Aggregations

ColorUIResource (javax.swing.plaf.ColorUIResource)36 Color (java.awt.Color)9 FontUIResource (javax.swing.plaf.FontUIResource)4 Dimension (java.awt.Dimension)3 UIDefaults (javax.swing.UIDefaults)3 BorderLayout (java.awt.BorderLayout)2 Insets (java.awt.Insets)2 MouseEvent (java.awt.event.MouseEvent)2 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 ImageIcon (javax.swing.ImageIcon)2 JScrollPane (javax.swing.JScrollPane)2 Border (javax.swing.border.Border)2 InsetsUIResource (javax.swing.plaf.InsetsUIResource)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)2 ColumnInfo (org.compiere.minigrid.ColumnInfo)2 DarculaButtonPainter (com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter)1 DarculaButtonUI (com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1