Example usage for javax.swing UIManager get

List of usage examples for javax.swing UIManager get

Introduction

In this page you can find the example usage for javax.swing UIManager get.

Prototype

public static Object get(Object key) 

Source Link

Document

Returns an object from the defaults.

Usage

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Returns foreground color for labels, as set by Look And Feel
 * //from   ww w .jav a  2s. c  o m
 * @return the forefround color
 */
public static Color getForegroundColor() {
    return (Color) UIManager.get("Label.foreground");
}

From source file:org.notebook.gui.widget.GuiUtils.java

/**
 * Sets the default font for all Swing components.
 * //from   w  ww.  ja  v  a  2 s  .c o  m
 * @param f
 *            the f
 */
public static void setUIFont(FontUIResource f) {
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
            UIManager.put(key, f);
        }
    }
}

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 va2 s.  co  m*/
    }
}

From source file:org.openstreetmap.josm.Main.java

/**
 * Should be called before the main constructor to setup some parameter
 * stuff/*from ww  w  .j ava  2 s .  c  o m*/
 * 
 * @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.rimudb.editor.swing.OkCancelPanel.java

/** 
 * Register the UI Delegate /*  w  w  w.  java  2 s.c  om*/
 */
protected ComponentUI registerUIDelegate() {
    ComponentUI compUI = null;

    Object obj = UIManager.get(uiClassID);
    if (obj == null) {
        // The default delegate class name
        Class basicDelegateClassName = org.rimudb.editor.swing.plaf.basic.BasicOkCancelPanelUI.class;
        String lafName = UIManager.getLookAndFeel().getID();

        // Look for a delegate for this LAF
        String packageName = basicDelegateClassName.getPackage().getName();
        int pos = packageName.indexOf("basic");
        String delegatePackageName = packageName.substring(0, pos);

        String lafDelegateClassName = delegatePackageName + lafName.toLowerCase() + "." + lafName
                + "OkCancelPanelUI";

        try {
            // Try the specific delegate
            compUI = (ComponentUI) (Class.forName(lafDelegateClassName)).newInstance();
        } catch (Exception e1) {
            try {
                // Default to the default delegate
                compUI = (ComponentUI) basicDelegateClassName.newInstance();
            } catch (Exception e2) {
                log.error("in OkCancelPanel.registerUIDelegate", e2);
            }
        }
    } else {
        compUI = (ComponentUI) obj;
    }
    return compUI;
}

From source file:org.roche.antibody.services.graphsynchronizer.GraphSynchronizer.java

/**
 * Validates in order to decide, if we can sync our model back or not!
 * /*from  www.  j a  v a  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.yccheok.jstock.gui.JStock.java

/**
 * @param args the command line arguments
 *//*from  w w w  . j av  a 2 s.c o m*/
public static void main(String args[]) {
    /***********************************************************************
     * UI Manager initialization via JStockOptions.
     **********************************************************************/
    final JStockOptions jStockOptions = getJStockOptionsViaXML();

    // OSX menu bar at top.
    if (Utils.isMacOSX()) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("apple.awt.brushMetalLook", "true");
    }

    boolean uiManagerLookAndFeelSuccess = false;
    try {
        String lookNFeel = jStockOptions.getLooknFeel();
        if (null != lookNFeel) {
            UIManager.setLookAndFeel(lookNFeel);
            uiManagerLookAndFeelSuccess = true;
        }
    } catch (java.lang.ClassNotFoundException | java.lang.InstantiationException
            | java.lang.IllegalAccessException | javax.swing.UnsupportedLookAndFeelException exp) {
        log.error(null, exp);
    }

    if (!uiManagerLookAndFeelSuccess) {
        String className = Utils.setDefaultLookAndFeel();
        if (null != className) {
            final String lookNFeel = jStockOptions.getLooknFeel();
            // When jStockOptions.getLookNFeel returns null, it means we wish
            // to use system default value. Hence, don't overwrite the null value,
            // so that we can use the same jStockOptions, across different
            // platforms.
            if (lookNFeel != null) {
                jStockOptions.setLooknFeel(className);
            }
        }
    }

    /***********************************************************************
     * Ensure correct localization.
     **********************************************************************/
    // This global effect, should just come before anything else, 
    // after we get an instance of JStockOptions.
    Locale.setDefault(jStockOptions.getLocale());

    /***********************************************************************
     * Single application instance enforcement.
     **********************************************************************/
    if (false == AppLock.lock()) {
        final int choice = JOptionPane.showOptionDialog(null,
                MessagesBundle.getString("warning_message_running_2_jstock"),
                MessagesBundle.getString("warning_title_running_2_jstock"), JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null,
                new String[] { MessagesBundle.getString("yes_button_running_2_jstock"),
                        MessagesBundle.getString("no_button_running_2_jstock") },
                MessagesBundle.getString("no_button_running_2_jstock"));
        if (choice != JOptionPane.YES_OPTION) {
            System.exit(0);
            return;
        }
    }

    // Avoid "JavaFX IllegalStateException when disposing JFXPanel in Swing"
    // http://stackoverflow.com/questions/16867120/javafx-illegalstateexception-when-disposing-jfxpanel-in-swing
    Platform.setImplicitExit(false);

    // As ProxyDetector is affected by system properties
    // http.proxyHost, we are forced to initialized ProxyDetector right here,
    // before we manually change the system properties according to
    // JStockOptions.
    ProxyDetector.getInstance();

    /***********************************************************************
     * Apply large font if possible.
     **********************************************************************/
    if (jStockOptions.useLargeFont()) {
        java.util.Enumeration keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value != null && value instanceof javax.swing.plaf.FontUIResource) {
                javax.swing.plaf.FontUIResource fr = (javax.swing.plaf.FontUIResource) value;
                UIManager.put(key, new javax.swing.plaf.FontUIResource(
                        fr.deriveFont((float) fr.getSize2D() * (float) Constants.FONT_ENLARGE_FACTOR)));
            }
        }
    }

    /***********************************************************************
     * GA tracking.
     **********************************************************************/
    GA.trackAsynchronously("main");

    java.awt.EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            final JStock mainFrame = JStock.instance();

            // We need to first assign jStockOptions to mainFrame, as during
            // Utils.migrateXMLToCSVPortfolios, we will be accessing mainFrame's
            // jStockOptions.
            mainFrame.initJStockOptions(jStockOptions);

            mainFrame.init();
            mainFrame.setVisible(true);
            mainFrame.updateDividerLocation();
            mainFrame.requestFocusOnJComboBox();
        }
    });
}

From source file:plugin.notes.gui.JIcon.java

private void buttonFocusLost(FocusEvent evt) {

    setBackground((Color) UIManager.getDefaults().get("Panel.background"));
    button.setBackground((Color) UIManager.getDefaults().get("Button.background"));
}

From source file:plugin.notes.gui.JIcon.java

/**
 *  This method is called from within the constructor to initialize the form.
 *  WARNING: Do NOT modify this code. The content of this method is always
 *  regenerated by the Form Editor./*  w w w  .j av  a 2s . c  o m*/
 */
private void initComponents() {

    contextMenu = new JPopupMenu();
    JMenuItem launchMI = new JMenuItem();
    JMenuItem deleteMI = new JMenuItem();
    button = new JButton();
    label = new JLabel();

    launchMI.setText("Launch File (enter)");
    launchMI.addActionListener(this::launchMIActionPerformed);

    contextMenu.add(launchMI);
    deleteMI.setText("Delete File (del)");
    deleteMI.addActionListener(this::deleteMIActionPerformed);

    contextMenu.add(deleteMI);

    setLayout(new BorderLayout());

    setBackground((Color) UIManager.getDefaults().get("Panel.background"));
    setBorder(new LineBorder(new Color(0, 0, 0)));
    button.setBackground((Color) UIManager.getDefaults().get("Button.background"));
    button.setBorder(null);
    button.addActionListener(this::buttonActionPerformed);

    button.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent evt) {
            buttonFocusGained(evt);
        }

        @Override
        public void focusLost(FocusEvent evt) {
            buttonFocusLost(evt);
        }
    });

    button.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent evt) {
            buttonKeyReleased(evt);
        }
    });

    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            buttonMouseClicked(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            buttonMouseReleased(evt);
        }
    });

    add(button, BorderLayout.NORTH);

    label.setBackground(new Color(204, 204, 204));
    add(label, BorderLayout.CENTER);
}

From source file:ro.nextreports.designer.template.report.TemplateManager.java

public static ReportTemplate createDefaultReportTemplate() {
    ReportTemplate template = new ReportTemplate();
    template.setVersion(ReleaseInfoAdapter.getVersionNumber());
    BandElement title = new BandElement("Title");
    title.setBackground(Color.WHITE);
    title.setForeground(Color.BLACK);
    Font font = (Font) UIManager.getDefaults().get("Panel.font");
    title.setFont(font);// w  w w . j a  v  a2s  .co m
    title.setPadding(new Padding(0, 0, 0, 0));
    Border border = new Border();
    border.setLeftColor(Color.BLACK);
    border.setRightColor(Color.BLACK);
    border.setTopColor(Color.BLACK);
    border.setBottomColor(Color.BLACK);
    title.setBorder(border);
    template.setTitleBand(title);

    BandElement header = new BandElement("Header");
    TemplateManager.restoreBandElement(header, title);
    template.setHeaderBand(header);

    BandElement detail = new BandElement("Detail");
    TemplateManager.restoreBandElement(detail, title);
    template.setDetailBand(detail);

    BandElement footer = new BandElement("Footer");
    TemplateManager.restoreBandElement(footer, title);
    template.setFooterBand(footer);

    return template;
}