@Override public UIDefaults getDefaults() { getColors(); UIDefaults table = new UIDefaults(); // copy existing default values over // enables AntiAliasing if AntiAliasing is enabled in the OS // EXCEPT for key "Menu.opaque" which will glitch out JMenues UIDefaults lookAndFeelDefaults = UIManager.getLookAndFeelDefaults(); Hashtable copy = new Hashtable<>(lookAndFeelDefaults); for (Object key : copy.keySet()) { if (!String.valueOf(key).equals("Menu.opaque")) { table.put(key, lookAndFeelDefaults.get(key)); } } initClassDefaults(table); initSystemColorDefaults(table); initComponentDefaults(table); COLORS.addCustomEntriesToTable(table); return table; }
private void initBorderDefaults(UIDefaults table) { Object[] borderDefaults = { "TextField.border", Borders.getTextFieldBorder(), "PasswordField.border", Borders.getTextFieldBorder(), "FilterTextField.border", Borders.getTextFieldBorder(), "FormattedTextField.border", Borders.getTextFieldBorder(), "TextArea.border", Borders.getTextFieldBorder(), "SplitPane.border", Borders.getSplitPaneBorder(), "ScrollPane.border", Borders.getScrollPaneBorder(), "InternalFrame.border", Borders.getInternalFrameBorder(), "Table.scrollPaneBorder", null, // removed // table // border, // original: // Borders.getSplitPaneBorder() "Table.tabbedPaneBorder", null, // remove double borders "ToolBar.border", Borders.getToolBarBorder(), "Spinner.border", Borders.getSpinnerBorder(), "ComboBox.border", Borders.getComboBoxBorder(), "Button.border", Borders.getEmptyButtonBorder(), "ToggleButton.border", Borders.getEmptyButtonBorder(), "ProgressBar.border", Borders.getProgressBarBorder(), "PopupMenu.border", Borders.getPopupMenuBorder(), "MenuBar.border", Borders.getMenuBarBorder(), "CheckBox.border", Borders.getCheckBoxBorder(), "RadioButton.border", Borders.getCheckBoxBorder(), "ToolTip.border", Borders.getToolTipBorder(), "CheckBox.icon", IconFactory.getCheckBoxIcon(), "RadioButton.icon", IconFactory.getRadioButtonIcon(), "ComboBox.focusCellHighlightBorder", Borders.getComboBoxListCellRendererFocusBorder(), }; table.putDefaults(borderDefaults); }
@Override public void addCustomEntriesToTable(UIDefaults table) { super.addCustomEntriesToTable(table); final int internalFrameIconSize = 22; table.put("InternalFrame.closeIcon", MetalIconFactory. getInternalFrameCloseIcon(internalFrameIconSize)); table.put("InternalFrame.maximizeIcon", MetalIconFactory. getInternalFrameMaximizeIcon(internalFrameIconSize)); table.put("InternalFrame.iconifyIcon", MetalIconFactory. getInternalFrameMinimizeIcon(internalFrameIconSize)); table.put("InternalFrame.minimizeIcon", MetalIconFactory. getInternalFrameAltMaximizeIcon(internalFrameIconSize)); table.put("ScrollBar.width", 21); }
@Override public void addCustomEntriesToTable(UIDefaults table) { Border blackLineBorder = new BorderUIResource(new LineBorder(getBlack())); Border whiteLineBorder = new BorderUIResource(new LineBorder(getWhite())); Object textBorder = new BorderUIResource(new CompoundBorder( blackLineBorder, new BasicBorders.MarginBorder())); table.put("ToolTip.border", blackLineBorder); table.put("TitledBorder.border", blackLineBorder); table.put("Table.focusCellHighlightBorder", whiteLineBorder); table.put("Table.focusCellForeground", getWhite()); table.put("TextField.border", textBorder); table.put("PasswordField.border", textBorder); table.put("TextArea.border", textBorder); table.put("TextPane.font", textBorder); }
/** * Creates the value retrieved from the <code>UIDefaults</code> table. * The object is created each time it is accessed. * * @param table a <code>UIDefaults</code> table * @return the created <code>Object</code> */ @Override public Object createValue(UIDefaults table) { Object obj = null; // check specified state if (state!=null){ obj = uiDefaults.get(prefix+"["+state+"]."+suffix); } // check enabled state if (obj==null){ obj = uiDefaults.get(prefix+"[Enabled]."+suffix); } // check for defaults if (obj==null){ if (isFont) { obj = uiDefaults.get("defaultFont"); } else { obj = uiDefaults.get(suffix); } } return obj; }
@Override protected void installKeyboardActions() { super.installKeyboardActions(); JTextComponent comp = getComponent(); UIDefaults uidefaults = XToolkit.getUIDefaults(); String prefix = getPropertyPrefix(); InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap"); if (map != null) { SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED, map); } }
@Override protected void configureScrollBarColors() { UIDefaults uidefaults = XToolkit.getUIDefaults(); Color bg = scrollbar.getBackground(); if (bg == null || bg instanceof UIResource) { scrollbar.setBackground(uidefaults.getColor("ScrollBar.background")); } Color fg = scrollbar.getForeground(); if (fg == null || fg instanceof UIResource) { scrollbar.setForeground(uidefaults.getColor("ScrollBar.foreground")); } thumbHighlightColor = uidefaults.getColor("ScrollBar.thumbHighlight"); thumbLightShadowColor = uidefaults.getColor("ScrollBar.thumbShadow"); thumbDarkShadowColor = uidefaults.getColor("ScrollBar.thumbDarkShadow"); thumbColor = uidefaults.getColor("ScrollBar.thumb"); trackColor = uidefaults.getColor("ScrollBar.track"); trackHighlightColor = uidefaults.getColor("ScrollBar.trackHighlight"); }
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"); } }); }
public static void main(String[] args) { UIDefaults table= new MetalLookAndFeel().getDefaults(); test(table.get("ToolBar.rolloverBorder"), "javax.swing.plaf.metal.MetalBorders$ButtonBorder", "javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder"); test(table.get("ToolBar.nonrolloverBorder"), "javax.swing.plaf.metal.MetalBorders$ButtonBorder", "javax.swing.plaf.metal.MetalBorders$RolloverMarginBorder"); test(table.get("RootPane.frameBorder"), "javax.swing.plaf.metal.MetalBorders$FrameBorder"); test(table.get("RootPane.plainDialogBorder"), "javax.swing.plaf.metal.MetalBorders$DialogBorder"); test(table.get("RootPane.informationDialogBorder"), "javax.swing.plaf.metal.MetalBorders$DialogBorder"); test(table.get("RootPane.errorDialogBorder"), "javax.swing.plaf.metal.MetalBorders$ErrorDialogBorder"); test(table.get("RootPane.colorChooserDialogBorder"), "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder"); test(table.get("RootPane.fileChooserDialogBorder"), "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder"); test(table.get("RootPane.questionDialogBorder"), "javax.swing.plaf.metal.MetalBorders$QuestionDialogBorder"); test(table.get("RootPane.warningDialogBorder"), "javax.swing.plaf.metal.MetalBorders$WarningDialogBorder"); }
/** * Do some common setup for all applications at startup * @param name the application name used for Java logging and database logging */ public static void appSetup(String name) { // Set our platform wide L&F System.setProperty("swing.defaultlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel"); UIDefaults defaults = UIManager.getLookAndFeelDefaults(); defaults.put("Table.gridColor", new Color(140,140,140)); defaults.put("Table.showGrid", true); // Set the program name which is used by PostgresqlDatabase to identify the app in logs System.setProperty("program.name", name); // Start with a fresh root set at warning Logger root = LogManager.getLogManager().getLogger(""); Formatter format = new SingleLineFormatter(); root.setLevel(Level.WARNING); for(Handler handler : root.getHandlers()) { root.removeHandler(handler); } // Set prefs levels before windows preference load barfs useless data on the user Logger.getLogger("java.util.prefs").setLevel(Level.SEVERE); // postgres JDBC spits out a lot of data even though we catch the exception Logger.getLogger("org.postgresql.jdbc").setLevel(Level.OFF); Logger.getLogger("org.postgresql.Driver").setLevel(Level.OFF); // Add console handler if running in debug mode if (Prefs.isDebug()) { ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(Level.ALL); ch.setFormatter(format); root.addHandler(ch); } // For our own logs, we can set super fine level or info depending on if debug mode and attach dialogs to those Logger applog = Logger.getLogger("org.wwscc"); applog.setLevel(Prefs.isDebug() ? Level.FINEST : Level.INFO); applog.addHandler(new AlertHandler()); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { applog.log(Level.WARNING, String.format("\bUncaughtException in %s: %s", t, e), e); }}); try { File logdir = Prefs.getLogDirectory().toFile(); if (!logdir.exists()) if (!logdir.mkdirs()) throw new IOException("Can't create log directory " + logdir); FileHandler fh = new FileHandler(new File(logdir, name+".%g.log").getAbsolutePath(), 1000000, 10, true); fh.setFormatter(format); fh.setLevel(Level.ALL); root.addHandler(fh); } catch (IOException ioe) { JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(), "Unable to enable logging to file: " + ioe, "Log Error", JOptionPane.ERROR_MESSAGE); } // force the initialization of IdGenerator on another thread so app can start now without an odd delay later new Thread() { public void run() { IdGenerator.generateId(); } }.start(); }
public UIDefaultsTableModel() { // make a local copy of the defaults table in case the look and feel changes defaults = new UIDefaults(); keys = new ArrayList<Object>(); UIDefaults realDefaults = UIManager.getDefaults(); Enumeration keysEnum = realDefaults.keys(); while (keysEnum.hasMoreElements()) { Object key = keysEnum.nextElement(); if (!defaults.containsKey(key)) { keys.add(key); defaults.put(key, realDefaults.get(key)); } else { System.out.println("found duplicate key:"+key); } } }
@Override protected void installBorder(UIDefaults table) { // 初始化阴影边框 Insets insets = new Insets(5, 5, 5, 5); BufferedImage shadowImg = LuckRes.getImage("frame/shadow_border.9.png"); Border shadowBorder = getBorderRes(new LuckNinePatchBorder(insets, shadowImg)); // 设置窗体、弹窗边框配置 table.put(FRAME_BORDER, shadowBorder); table.put(PLAINDIALOG_BORDER, shadowBorder); table.put(INFORMATIONDIALOG_BORDER, shadowBorder); table.put(ERRORDIALOG_BORDER, shadowBorder); table.put(COLORCHOOSERDIALOG_BORDER, shadowBorder); table.put(FILECHOOSERDIALOG_BORDER, shadowBorder); table.put(QUESTIONDIALOG_BORDER, shadowBorder); table.put(WARNINGDIALOG_BORDER, shadowBorder); }
@Override public void addCustomEntriesToTable(final UIDefaults table) { final Border blackLineBorder = new BorderUIResource(new LineBorder(getBlack())); final Object textBorder = new BorderUIResource(new CompoundBorder(blackLineBorder, new BasicBorders.MarginBorder())); table.put("ToolTip.border", blackLineBorder); table.put("TitledBorder.border", blackLineBorder); table.put("TextField.border", textBorder); table.put("PasswordField.border", textBorder); table.put("TextArea.border", textBorder); table.put("TextPane.border", textBorder); table.put("EditorPane.border", textBorder); }
private Object[] getCustomGradientTable(UIDefaults table) { List<Serializable> buttonGradient = Arrays.asList(1.0, 0.0, getSecondary3(), getSecondary2(), getSecondary2()); Object[] result = { "Button.gradient", buttonGradient, "CheckBox.gradient", buttonGradient, "CheckBoxMenuItem.gradient", buttonGradient, "InternalFrame.activeTitleGradient", buttonGradient, "RadioButton.gradient", buttonGradient, "RadioButtonMenuItem.gradient", buttonGradient, "ScrollBar.gradient", buttonGradient, "Slider.focusGradient", buttonGradient, "Slider.gradient", buttonGradient, "ToggleButton.gradient", buttonGradient, }; return result; }
/** Create the display that shows instruction */ public JTextPane buildInstructionDisplay(String instructionText) { JTextPane instructionDisplay = new JTextPane(); UIDefaults defaults = new UIDefaults(); defaults.put("TextPane[Enabled].backgroundPainter", MAIN_BACKGROUND_COLOR); instructionDisplay.putClientProperty("Nimbus.Overrides", defaults); instructionDisplay.putClientProperty("Nimbus.Overrides.InheritDefaults", true); instructionDisplay.setBackground(MAIN_BACKGROUND_COLOR); instructionDisplay.setEditable(false); instructionDisplay.setPreferredSize(new Dimension(200, 100)); instructionDisplay.setContentType("text/html"); instructionText = this.setHTMLTextProperties(instructionText, KioskFrame.INSTRUCTION_TEXT_FONT_SIZE, KioskFrame.INSTRUCTION_TEXT_FONT_FACE, "<center>", KioskFrame.INSTRUCTION_FONT_COLOR); instructionDisplay.setText(instructionText); return instructionDisplay; }