List of usage examples for javax.swing UIManager put
public static Object put(Object key, Object value)
From source file:org.notebook.gui.widget.LookAndFeelSelector.java
/** * Sets the look and feel./*from w ww . jav a 2s . c o m*/ * * @param theme * the new look and feel */ public void setLookAndFeel(String theme) { try { log.info("Updating skin '" + theme + "'"); if (skins.containsKey(theme)) { UIManager.setLookAndFeel(skins.get(theme)); } else { log.error("Not found skin '" + theme + "'"); return; } /** fix font bug start */ if (SwingUtilities.isEventDispatchThread()) { fixFontBug(); } else { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { fixFontBug(); } }); } } catch (Exception e) { log.error(e.toString(), e); } /** * ?????? * tiptool */ if (!isDefaultLookAndFeel(theme)) { // Get border color try { Color c = SubstanceLookAndFeel.getCurrentSkin().getMainActiveColorScheme().getMidColor(); UIManager.put("ToolTip.border", BorderFactory.createLineBorder(c)); UIManager.put("ToolTip.background", new ColorUIResource(Color.WHITE)); UIManager.put("ToolTip.foreground", new ColorUIResource(Color.BLACK)); SubstanceSkin skin = SubstanceLookAndFeel.getCurrentSkin(); SubstanceColorScheme scheme = skin.getMainActiveColorScheme(); GuiUtils.putLookAndFeelColor("borderColor", scheme.getMidColor()); GuiUtils.putLookAndFeelColor("lightColor", scheme.getLightColor()); GuiUtils.putLookAndFeelColor("lightBackgroundFillColor", scheme.getLightBackgroundFillColor()); GuiUtils.putLookAndFeelColor("darkColor", scheme.getDarkColor()); GuiUtils.putLookAndFeelColor("backgroundFillColor", scheme.getBackgroundFillColor()); GuiUtils.putLookAndFeelColor("lineColor", scheme.getLineColor()); GuiUtils.putLookAndFeelColor("selectionForegroundColor", scheme.getSelectionForegroundColor()); GuiUtils.putLookAndFeelColor("selectionBackgroundColor", scheme.getSelectionBackgroundColor()); GuiUtils.putLookAndFeelColor("foregroundColor", scheme.getForegroundColor()); GuiUtils.putLookAndFeelColor("focusRingColor", scheme.getFocusRingColor()); } catch (Exception e) { log.info("This is not a SubstanceLookAndFeel skin."); } UIManager.put(LafWidget.ANIMATION_KIND, LafConstants.AnimationKind.NONE); UIManager.put(SubstanceLookAndFeel.TABBED_PANE_CONTENT_BORDER_KIND, SubstanceConstants.TabContentPaneBorderKind.SINGLE_FULL); JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); } }
From source file:org.notebook.gui.widget.LookAndFeelSelector.java
private static void fixFontBug() { int sizeOffset = 0; Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof Font) { Font oldFont = (Font) value; // logger.info(oldFont.getName()); Font newFont = new Font("Dialog", oldFont.getStyle(), oldFont.getSize() + sizeOffset); UIManager.put(key, newFont); }/*from w w w . j a v a 2s. co m*/ } }
From source file:org.openstreetmap.josm.Main.java
/** * Should be called before the main constructor to setup some parameter * stuff// ww w. ja v a 2 s . com * * @param args * The parsed argument list. */ public static void preConstructorInit(Map<String, Collection<String>> args) { try { // Main.proj = new Epsg4326(); Main.proj = new Mercator(); } catch (final Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, tr("The projection could not be read from preferences. Using Mercartor")); Main.proj = new Mercator(); } try { try { String laf = Main.pref.get("laf"); if (laf != null && laf.length() > 0) UIManager.setLookAndFeel(laf); } catch (final javax.swing.UnsupportedLookAndFeelException e) { log.debug("Look and Feel not supported: " + Main.pref.get("laf")); } } catch (final Exception e) { e.printStackTrace(); } UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); String geometry = Main.pref.get("gui.geometry"); if (args.containsKey("geometry")) { geometry = args.get("geometry").iterator().next(); } if (geometry.length() != 0) { final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(geometry); if (m.matches()) { int w = Integer.valueOf(m.group(1)); int h = Integer.valueOf(m.group(2)); int x = 0, y = 0; if (m.group(3) != null) { x = Integer.valueOf(m.group(5)); y = Integer.valueOf(m.group(7)); if (m.group(4).equals("-")) x = screenDimension.width - x - w; if (m.group(6).equals("-")) y = screenDimension.height - y - h; } bounds = new Rectangle(x, y, w, h); if (!Main.pref.get("gui.geometry").equals(geometry)) { // remember this geometry Main.pref.put("gui.geometry", geometry); } } else { System.out.println("Ignoring malformed geometry: " + geometry); } } if (bounds == null) bounds = !args.containsKey("no-maximize") ? new Rectangle(0, 0, screenDimension.width, screenDimension.height) : new Rectangle(1000, 740); // preinitialize a wait dialog for all early downloads (e.g. via command // line) pleaseWaitDlg = new PleaseWaitDialog(null); }
From source file:org.paxle.desktop.impl.Activator.java
public void start(final BundleContext bc) throws Exception { // first we check whether the DI-bundle will able to work on the system if (GraphicsEnvironment.isHeadless()) { logger.fatal(/*from ww w . ja v a 2 s.c o m*/ "Java runs in a headless environment, cannot initialize any graphical user interfaces, aborting"); return; } uiClassLoader = this.getClass().getClassLoader(); Thread.currentThread().setContextClassLoader(uiClassLoader); /* * Configuring the classloader to use by the UIManager. * ATTENTION: do not remove this, otherwise we get ClassNotFoundExceptions */ UIManager.put("ClassLoader", this.getClass().getClassLoader()); final float javaVersion = getJavaVersion(); logger.debug(String.format("Detected java version: %f", Float.valueOf(javaVersion))); final Iterator<Map.Entry<Float, String>> implIt = KNOWN_IMPLS.entrySet().iterator(); boolean started = false; // TODO: instantiate (and register) ServiceManager, DialogServices and the DICommandProvider here while (implIt.hasNext()) { final Map.Entry<Float, String> impl = implIt.next(); // discard if not supported by JRE if (impl.getKey().floatValue() > javaVersion) { logger.info(String.format("Implementation %s skipped because of missing java version %f.", impl.getValue(), impl.getKey())); continue; } try { // display icon initUI(bc, impl.getValue()); started = true; logger.info(String.format("Successfully started bundle using backend '%s'", impl)); break; } catch (Exception e) { final Throwable ex = ((e instanceof InvocationTargetException) ? e.getCause() : e); final String cause = ((ex instanceof UnsupportedOperationException) ? "Java claims your system to not support the system-tray." : ex.toString()); final String err = String.format( "Error starting bundle using backend '%s': %s Skipping implementation...", impl, cause); if (logger.isDebugEnabled()) { logger.error(err, ex); } else { logger.error(err); } } } if (!started) logger.fatal("No backends left, could not start bundle"); }
From source file:org.pgptool.gui.ui.tools.UiUtils.java
public static void setLookAndFeel() { // NOTE: We doing it this way to prevent dead=locks that is sometimes // happens if do it in main thread Edt.invokeOnEdtAndWait(new Runnable() { @Override/*from w w w . j a v a 2 s .c o m*/ public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); fixCheckBoxMenuItemForeground(); fixFontSize(); } catch (Throwable t) { log.error("Failed to set L&F", t); } } /** * In some cases (depends on OS theme) check menu item foreground is same as * bacground - thus it;'s invisible when cheked */ private void fixCheckBoxMenuItemForeground() { UIDefaults defaults = UIManager.getDefaults(); Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground"); Color foreground = defaults.getColor("CheckBoxMenuItem.foreground"); Color background = defaults.getColor("CheckBoxMenuItem.background"); if (colorsDiffPercentage(selectionForeground, background) < 10) { // TODO: That doesn't actually affect defaults. Need to find out how to fix it defaults.put("CheckBoxMenuItem.selectionForeground", foreground); } } private int colorsDiffPercentage(Color c1, Color c2) { int diffRed = Math.abs(c1.getRed() - c2.getRed()); int diffGreen = Math.abs(c1.getGreen() - c2.getGreen()); int diffBlue = Math.abs(c1.getBlue() - c2.getBlue()); float pctDiffRed = (float) diffRed / 255; float pctDiffGreen = (float) diffGreen / 255; float pctDiffBlue = (float) diffBlue / 255; return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100); } private void fixFontSize() { if (isJreHandlesScaling()) { log.info("JRE handles font scaling, won't change it"); return; } log.info("JRE doesnt't seem to support font scaling"); Toolkit toolkit = Toolkit.getDefaultToolkit(); int dpi = toolkit.getScreenResolution(); if (dpi == 96) { if (log.isDebugEnabled()) { Font font = UIManager.getDefaults().getFont("TextField.font"); String current = font != null ? Integer.toString(font.getSize()) : "unknown"; log.debug( "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be " + current); } return; } int targetFontSize = 12 * dpi / 96; log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize); setDefaultSize(targetFontSize); } private boolean isJreHandlesScaling() { try { JreVersion noNeedToScaleForVer = JreVersion.parseString("9"); String jreVersionStr = System.getProperty("java.version"); if (jreVersionStr != null) { JreVersion curVersion = JreVersion.parseString(jreVersionStr); if (noNeedToScaleForVer.compareTo(curVersion) <= 0) { return true; } } return false; } catch (Throwable t) { log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: " + System.getProperty("java.version"), t); return true; } } public void setDefaultSize(int size) { Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet(); Object[] keys = keySet.toArray(new Object[keySet.size()]); for (Object key : keys) { if (key != null && key.toString().toLowerCase().contains("font")) { Font font = UIManager.getDefaults().getFont(key); if (font != null) { Font changedFont = font.deriveFont((float) size); UIManager.put(key, changedFont); Font doubleCheck = UIManager.getDefaults().getFont(key); log.debug("Font size changed for " + key + ". From " + font.getSize() + " to " + doubleCheck.getSize()); } } } } }); log.info("L&F set"); }
From source file:org.pmedv.core.gui.ApplicationWindowAdvisorImpl.java
@Override public void preWindowCreate() { log.info("initializing."); String laf = (String) Preferences.values.get("org.pmedv.blackboard.BoardDesignerPerspective.lookAndFeel"); try {// w w w . j av a2 s .c o m if (laf.equals("Nimbus")) { UIManager.setLookAndFeel(new NimbusLookAndFeel()); } else if (laf.equals("SkyBlue")) { Plastic3DLookAndFeel.setPlasticTheme(new SkyBluer()); UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); com.jgoodies.looks.Options.setPopupDropShadowEnabled(true); } else { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception e2) { log.info("failed to set look and feel."); } final Color blackboardLightBlue = new Color(225, 234, 242); final Color blackBoardDarkBlue = new Color(182, 191, 205); final Color blackboardLightGrey = new Color(220, 220, 222); UIManager.put("TaskPane.titleBackgroundGradientStart", Color.WHITE); UIManager.put("TaskPane.titleBackgroundGradientEnd", blackboardLightBlue); UIManager.put("TaksPane.specialTitleBackground", blackboardLightBlue); UIManager.put("TaskPane.titleBackground", blackboardLightBlue); UIManager.put("TaskPane.borderColor", blackboardLightBlue); UIManager.put("TaskPane.background", blackboardLightGrey); UIManager.put("TaskPaneContainer.backgroundPainter", new MattePainter(blackBoardDarkBlue)); log.info("setting look and feel to: " + UIManager.getLookAndFeel()); // construct app icon Image iconImage = resources.getIcon("icon.application").getImage(); MediaTracker mt = new MediaTracker(win); mt.addImage(iconImage, 0); try { mt.waitForAll(); } catch (InterruptedException e) { // Silently ignore } InputStream is = getClass().getClassLoader().getResourceAsStream("application.properties"); Properties properties = new Properties(); try { properties.load(is); } catch (IOException e1) { properties.setProperty("version", "not set"); } win.setTitle(windowConfig.getConfig().getTitle() + " Version " + properties.get("version")); win.setIconImage(iconImage); win.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); win.addWindowListener(win); ToolTipManager.sharedInstance().setInitialDelay(100); ToolTipManager.sharedInstance().setDismissDelay(1000); }
From source file:org.roche.antibody.services.graphsynchronizer.GraphSynchronizer.java
/** * Validates in order to decide, if we can sync our model back or not! * /*w ww. j a va 2s.c o m*/ * @param code * @return JOptionPane.YES_NO_CANCEL_OPTION */ private int validate(HELMCode code) { int blockersInCode = 0; boolean activeDomainDetected = false; boolean activeDomainChanged = false; String domainChangesMsg = ""; for (HELMElement elem : code.getAllElements()) { if (blocksToRemove.contains(elem.getSequenceRepresentation())) { blockersInCode++; } if (elem instanceof HELMPeptide) { HELMPeptide pep = (HELMPeptide) elem; if (pep.getSimpleSequence().startsWith(activeDomain.getSequence()) || pep.getSimpleSequence().endsWith(activeDomain.getSequence())) { activeDomainDetected = true; } else { domainChangesMsg = checkForSequenceChanges(activeDomain.getSequence(), pep.getSimpleSequence()); activeDomainChanged = true; } } } if (blockersInCode != blockerCount) { JOptionPane.showMessageDialog(me.getFrame(), "Blockers were mainpulated! Model cannot be sync back!", "Sync Error", JOptionPane.ERROR_MESSAGE); return JOptionPane.CANCEL_OPTION; } else if (!activeDomainDetected && activeDomainChanged) { FontUIResource defaultFont = (FontUIResource) UIManager.get("OptionPane.messageFont"); UIManager.put("OptionPane.messageFont", new FontUIResource("Courier New", FontUIResource.PLAIN, 13)); int isConfirmed = JOptionPane.showConfirmDialog(me.getFrame(), domainChangesMsg, "Sequence has changed", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); UIManager.put("OptionPane.messageFont", defaultFont); return isConfirmed; } return JOptionPane.YES_OPTION; }
From source file:org.silverpeas.openoffice.windows.webdav.WebdavManager.java
/** * Get the ressource from the webdav server. * * @param uri the uri to the ressource./*from w w w . j a v a 2 s . c om*/ * @param lockToken the current lock token. * @return the path to the saved file on the filesystem. * @throws IOException */ public String getFile(URI uri, String lockToken) throws IOException { GetMethod method = executeGetFile(uri); String fileName = uri.getPath(); fileName = fileName.substring(fileName.lastIndexOf('/') + 1); fileName = URLDecoder.decode(fileName, "UTF-8"); UIManager.put("ProgressMonitor.progressText", MessageUtil.getMessage("download.file.title")); ProgressMonitorInputStream is = new ProgressMonitorInputStream(null, MessageUtil.getMessage("downloading.remote.file") + ' ' + fileName, new BufferedInputStream(method.getResponseBodyAsStream())); fileName = fileName.replace(' ', '_'); ProgressMonitor monitor = is.getProgressMonitor(); monitor.setMaximum(new Long(method.getResponseContentLength()).intValue()); monitor.setMillisToDecideToPopup(0); monitor.setMillisToPopup(0); File tempDir = new File(System.getProperty("java.io.tmpdir"), "silver-" + System.currentTimeMillis()); tempDir.mkdirs(); File tmpFile = new File(tempDir, fileName); FileOutputStream fos = new FileOutputStream(tmpFile); byte[] data = new byte[64]; int c; try { while ((c = is.read(data)) > -1) { fos.write(data, 0, c); } } catch (InterruptedIOException ioinex) { logger.log(Level.INFO, "{0} {1}", new Object[] { MessageUtil.getMessage("info.user.cancel"), ioinex.getMessage() }); unlockFile(uri, lockToken); System.exit(0); } finally { fos.close(); } return tmpFile.getAbsolutePath(); }
From source file:org.ut.biolab.medsavant.client.view.MedSavantFrame.java
private MedSavantFrame() { super(""); MacUtils.makeWindowLeopardStyle(this.getRootPane()); UIManager.put("Panel.background", new Color(237, 237, 237)); // the above line makes the bg dark, setting back setIconImage(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.MENU_USER).getImage()); setLayout(new BorderLayout()); setMinimumSize(new Dimension(550, 550)); view = new StackableJPanelContainer(); view.setDoubleBuffered(true);//from www. j a v a 2 s . co m view.setBackground(new Color(217, 222, 229)); UIManager.put("ToolTip.background", Color.black); UIManager.put("ToolTip.foreground", Color.white); UIManager.put("ToolTip.border", ViewUtil.getMediumBorder()); UIManager.put("ToolTip.font", ViewUtil.detailFontBold); UIManager.put("Table.gridColor", new Color(250, 250, 250)); add(view, BorderLayout.CENTER); LOG.info("Loading apps..."); AppController pc = AppController.getInstance(); pc.loadPlugins(DirectorySettings.getPluginsDirectory()); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { requestClose(); } }); }
From source file:org.ut.biolab.medsavant.MedSavantClient.java
private static void setLAF() { try {//from w ww . java2 s. co m if (ClientMiscUtils.MAC) { customizeForMac(); } // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); //Metal works with sliders. //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //GTK doesn't work with sliders. //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); //Nimbus doesn't work with sliders. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { LOG.debug("Installed LAF: " + info.getName() + " class: " + info.getClassName()); } LOG.debug("System LAF is: " + UIManager.getSystemLookAndFeelClassName()); LOG.debug("Cross platform LAF is: " + UIManager.getCrossPlatformLookAndFeelClassName()); LookAndFeelFactory.addUIDefaultsInitializer(new LookAndFeelFactory.UIDefaultsInitializer() { public void initialize(UIDefaults defaults) { Map<String, Object> defaultValues = new HashMap<String, Object>(); defaultValues.put("Slider.trackWidth", new Integer(7)); defaultValues.put("Slider.majorTickLength", new Integer(6)); defaultValues.put("Slider.highlight", new ColorUIResource(255, 255, 255)); defaultValues.put("Slider.horizontalThumbIcon", javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon()); defaultValues.put("Slider.verticalThumbIcon", javax.swing.plaf.metal.MetalIconFactory.getVerticalSliderThumbIcon()); defaultValues.put("Slider.focusInsets", new InsetsUIResource(0, 0, 0, 0)); for (Map.Entry<String, Object> e : defaultValues.entrySet()) { if (defaults.get(e.getKey()) == null) { LOG.debug("Missing key " + e.getKey() + ", using default value " + e.getValue()); defaults.put(e.getKey(), e.getValue()); } else { LOG.debug("Found key " + e.getKey() + " with value " + defaults.get(e.getKey())); } } } }); if (MiscUtils.WINDOWS) { UIManager.put("CheckBox.background", new javax.swing.plaf.ColorUIResource(Color.WHITE)); UIManager.put("Panel.background", new javax.swing.plaf.ColorUIResource(Color.WHITE)); LookAndFeelFactory.installJideExtension(LookAndFeelFactory.XERTO_STYLE_WITHOUT_MENU); /*UIManager.put("JideTabbedPane.tabAreaBackground", new javax.swing.plaf.ColorUIResource(Color.WHITE)); UIManager.put("JideTabbedPane.background", new javax.swing.plaf.ColorUIResource(Color.WHITE)); UIManager.put("SidePane.background", new javax.swing.plaf.ColorUIResource(Color.WHITE));*/ } else { LookAndFeelFactory.installJideExtension(); } LookAndFeelFactory.installDefaultLookAndFeelAndExtension(); System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("swing.aatext", "true"); UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); //tooltips UIManager.put("ToolTip.background", new ColorUIResource(255, 255, 255)); ToolTipManager.sharedInstance().setDismissDelay(8000); ToolTipManager.sharedInstance().setInitialDelay(500); } catch (Exception x) { LOG.error("Unable to install look & feel.", x); } }