public MainView() { // set some system-wide UI defaults so that everything appears correctly UIManager.put("TextField.inactiveForeground", new ColorUIResource(Color.BLACK)); UIManager.put("TextArea.inactiveForeground", new ColorUIResource(Color.BLACK)); UIManager.put("ComboBox.disabledForeground", new ColorUIResource(Color.BLACK)); _model = new MainModel(this); // initialize the under-the-hood functionality of the client }
private ActionMap getActionMap() { ActionMap actionMap = (ActionMap) UIManager.get("Grid.actionMap"); if (actionMap == null) { actionMap = createActionMap(); if (actionMap != null) { UIManager.put("Grid.actionMap", actionMap); } } return actionMap; }
@Override protected void installDefaults(AbstractButton b) { super.installDefaults(b); String pp = getPropertyPrefix(); // b.setOpaque(QuaquaManager.getBoolean(pp+"opaque")); QuaquaUtilities.installProperty(b, "opaque", UIManager.get(pp + "opaque")); b.setRequestFocusEnabled(UIManager.getBoolean(pp + "requestFocusEnabled")); b.setFocusable(UIManager.getBoolean(pp + "focusable")); }
protected void installDefaults() { LookAndFeel.installProperty(progressBar, "opaque", Boolean.TRUE); LookAndFeel.installBorder(progressBar, "ProgressBar.border"); LookAndFeel.installColorsAndFont( progressBar, "ProgressBar.background", "ProgressBar.foreground", "ProgressBar.font"); cellLength = UIManager.getInt("ProgressBar.cellLength"); if (cellLength == 0) cellLength = 1; cellSpacing = UIManager.getInt("ProgressBar.cellSpacing"); selectionForeground = UIManager.getColor("ProgressBar.selectionForeground"); selectionBackground = UIManager.getColor("ProgressBar.selectionBackground"); }
protected void installDefaults(JFileChooser fc) { installIcons(fc); installStrings(fc); usesSingleFilePane = UIManager.getBoolean("FileChooser.usesSingleFilePane"); readOnly = UIManager.getBoolean("FileChooser.readOnly"); TransferHandler th = fc.getTransferHandler(); if (th == null || th instanceof UIResource) { fc.setTransferHandler(defaultTransferHandler); } LookAndFeel.installProperty(fc, "opaque", Boolean.FALSE); }
public static void main(String args[]) { // UIManager.put("PopupMenu.border", new BorderUIResource.EmptyBorderUIResource(4,0,4,0)); try { UIManager.setLookAndFeel(QuaquaManager.getLookAndFeelClassName()); // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JFrame f = new JFrame("PopupMenuTest: " + UIManager.getLookAndFeel().getName()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new PopupMenuTest()); f.pack(); f.setVisible(true); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate(x, y); if (((JToolBar) c).isFloatable()) { if (((JToolBar) c).getOrientation() == HORIZONTAL) { int shift = MetalLookAndFeel.usingOcean() ? -1 : 0; bumps.setBumpArea(10, h - 4); if (MetalUtils.isLeftToRight(c)) { bumps.paintIcon(c, g, 2, 2 + shift); } else { bumps.paintIcon(c, g, w - 12, 2 + shift); } } else // vertical { bumps.setBumpArea(w - 4, 10); bumps.paintIcon(c, g, 2, 2); } } if (((JToolBar) c).getOrientation() == HORIZONTAL && MetalLookAndFeel.usingOcean()) { g.setColor(MetalLookAndFeel.getControl()); g.drawLine(0, h - 2, w, h - 2); g.setColor(UIManager.getColor("ToolBar.borderColor")); g.drawLine(0, h - 1, w, h - 1); } g.translate(-x, -y); }
private InputMap getInputMap(int condition) { if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) { return (InputMap) UIManager.get("Grid.ancestorInputMap"); } else { return null; } }
public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
public void actionPerformed(ActionEvent ae) { String cname = nameF.getText().trim(); int state = conditions[stateC.getSelectedIndex()]; try { if (isSpecialCase(cname)) { handleSpecialCase(cname, state); } else { JComponent comp = (JComponent) Class.forName(cname).newInstance(); ComponentUI cui = UIManager.getUI(comp); cui.installUI(comp); results.setText("Map entries for " + cname + ":\n\n"); if (inputB.isSelected()) { loadInputMap(comp.getInputMap(state), ""); results.append("\n"); } if (actionB.isSelected()) { loadActionMap(comp.getActionMap(), ""); results.append("\n"); } if (bindingB.isSelected()) { loadBindingMap(comp, state); } } } catch (ClassCastException cce) { results.setText(cname + " is not a subclass of JComponent."); } catch (ClassNotFoundException cnfe) { results.setText(cname + " was not found."); } catch (InstantiationException ie) { results.setText(cname + " could not be instantiated."); } catch (Exception e) { results.setText("Exception found:\n" + e); e.printStackTrace(); } }
// ******************************** // Defaults // ******************************** public void installDefaults(AbstractButton b) { super.installDefaults(b); if (!defaults_initialized) { icon = UIManager.getIcon(getPropertyPrefix() + "icon"); defaults_initialized = true; } }
@Override public Dimension getMinimumSize(JComponent c) { AbstractButton b = (AbstractButton) c; String style = (String) c.getClientProperty("Quaqua.Button.style"); if (style == null) { style = "push"; } if (style.equals("help")) { return getPreferredSize(c); } Dimension d = super.getMinimumSize(c); if (isFixedHeight(c)) { Dimension p = getPreferredSize(c); if (d != null && p != null) { d.height = Math.max(d.height, p.height); } } if (!QuaquaUtilities.isSmallSizeVariant(c) && style.equals("push") // && b.getIcon() == null && b.getText() != null) { if (d != null) { d.width = Math.max(d.width, UIManager.getInt("Button.minimumWidth")); } } return d; }
/** * Method which renders the text of the current button. * * <p> * * @param g Graphics context * @param b Current button to render * @param textRect Bounding rectangle to render the text. * @param text String to render * @since 1.4 */ @Override protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { ButtonModel model = b.getModel(); FontMetrics fm = g.getFontMetrics(); int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1); boolean borderHasPressedCue = borderHasPressedCue(b); /* Draw the Text */ if (model.isPressed() && model.isArmed() && !borderHasPressedCue) { g.setColor(new Color(0xa0000000, true)); QuaquaUtilities.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset() + 1); } if (model.isEnabled()) { /** * paint the text normally */ g.setColor(b.getForeground()); } else { Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground"); g.setColor((c != null) ? c : b.getForeground()); } QuaquaUtilities.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); }
public FileNameRenderer(JTable table) { Border b = UIManager.getBorder("Table.noFocusBorder"); if (Objects.isNull(b)) { // Nimbus??? Insets i = focusCellHighlightBorder.getBorderInsets(textLabel); b = BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right); } noFocusBorder = b; p.setOpaque(false); panel.setOpaque(false); // http://www.icongalore.com/ XP Style Icons - Windows Application Icon, Software XP Icons nicon = new ImageIcon(getClass().getResource("wi0063-16.png")); sicon = new ImageIcon( p.createImage( new FilteredImageSource(nicon.getImage().getSource(), new SelectedImageFilter()))); iconLabel = new JLabel(nicon); iconLabel.setBorder(BorderFactory.createEmptyBorder()); p.add(iconLabel, BorderLayout.WEST); p.add(textLabel); panel.add(p, BorderLayout.WEST); Dimension d = iconLabel.getPreferredSize(); dim.setSize(d); table.setRowHeight(d.height); }
public FocusBorder(Component comp) { this.comp = comp; comp.addFocusListener(this); // This is the best guess for a L&F specific color focusColor = UIManager.getColor("TabbedPane.focus"); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate(x, y); int messageType = JOptionPane.PLAIN_MESSAGE; if (c instanceof JInternalFrame) { Object obj = ((JInternalFrame) c).getClientProperty("JInternalFrame.messageType"); if (obj != null && (obj instanceof Integer)) { messageType = ((Integer) obj).intValue(); } } Color borderColor; switch (messageType) { case (JOptionPane.ERROR_MESSAGE): borderColor = UIManager.getColor("OptionPane.errorDialog.border.background"); break; case (JOptionPane.QUESTION_MESSAGE): borderColor = UIManager.getColor("OptionPane.questionDialog.border.background"); break; case (JOptionPane.WARNING_MESSAGE): borderColor = UIManager.getColor("OptionPane.warningDialog.border.background"); break; case (JOptionPane.INFORMATION_MESSAGE): case (JOptionPane.PLAIN_MESSAGE): default: borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); break; } g.setColor(borderColor); // Draw outermost lines g.drawLine(1, 0, w - 2, 0); g.drawLine(0, 1, 0, h - 2); g.drawLine(w - 1, 1, w - 1, h - 2); g.drawLine(1, h - 1, w - 2, h - 1); // Draw the bulk of the border for (int i = 1; i < 3; i++) { g.drawRect(i, i, w - (i * 2) - 1, h - (i * 2) - 1); } g.translate(-x, -y); }
/** * Resets the UI property to a value from the current look and feel. * * @see JComponent#updateUI */ public void updateUI() { setUI((SliderUI) UIManager.getUI(this)); // The labels preferred size may be derived from the font // of the slider, so we must update the UI of the slider first, then // that of labels. This way when setSize is called the right // font is used. updateLabelUIs(); }
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) { ListCellRenderer renderer = comboBox.getRenderer(); Component c; Dimension d; c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false); c.setFont(comboBox.getFont()); if (comboBox.isEnabled()) { c.setForeground(comboBox.getForeground()); c.setBackground(comboBox.getBackground()); } else { c.setForeground(UIManager.getColor("ComboBox.disabledForeground")); c.setBackground(UIManager.getColor("ComboBox.disabledBackground")); } d = c.getPreferredSize(); currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, d.height); }
/** Returns the value from the desktop. */ protected Object getValueFromDesktop() { if (this.toolkit == null) { this.toolkit = Toolkit.getDefaultToolkit(); } Object value = toolkit.getDesktopProperty(getKey()); pcl = new WeakPCL(this, toolkit, getKey(), UIManager.getLookAndFeel()); toolkit.addPropertyChangeListener(getKey(), pcl); return value; }
public void installUI(JComponent c) { super.installUI(c); arrowIcon = new MotifComboBoxArrowIcon( UIManager.getColor("controlHighlight"), UIManager.getColor("controlShadow"), UIManager.getColor("control")); Runnable initCode = new Runnable() { public void run() { if (motifGetEditor() != null) { motifGetEditor().setBackground(UIManager.getColor("text")); } } }; SwingUtilities.invokeLater(initCode); }
protected void installStrings(JFileChooser fc) { super.installStrings(fc); Locale l = fc.getLocale(); enterFileNameLabelText = UIManager.getString("FileChooser.enterFileNameLabelText", l); enterFileNameLabelMnemonic = UIManager.getInt("FileChooser.enterFileNameLabelMnemonic"); filesLabelText = UIManager.getString("FileChooser.filesLabelText", l); filesLabelMnemonic = UIManager.getInt("FileChooser.filesLabelMnemonic"); foldersLabelText = UIManager.getString("FileChooser.foldersLabelText", l); foldersLabelMnemonic = UIManager.getInt("FileChooser.foldersLabelMnemonic"); pathLabelText = UIManager.getString("FileChooser.pathLabelText", l); pathLabelMnemonic = UIManager.getInt("FileChooser.pathLabelMnemonic"); filterLabelText = UIManager.getString("FileChooser.filterLabelText", l); filterLabelMnemonic = UIManager.getInt("FileChooser.filterLabelMnemonic"); }
public void paint(Graphics g, JComponent c) { boolean hasFocus = comboBox.hasFocus(); Rectangle r; if (comboBox.isEnabled()) { g.setColor(comboBox.getBackground()); } else { g.setColor(UIManager.getColor("ComboBox.disabledBackground")); } g.fillRect(0, 0, c.getWidth(), c.getHeight()); if (!comboBox.isEditable()) { r = rectangleForCurrentValue(); paintCurrentValue(g, r, hasFocus); } r = rectangleForArrowIcon(); arrowIcon.paintIcon(c, g, r.x, r.y); if (!comboBox.isEditable()) { Border border = comboBox.getBorder(); Insets in; if (border != null) { in = border.getBorderInsets(comboBox); } else { in = new Insets(0, 0, 0, 0); } // Draw the separation if (MotifGraphicsUtils.isLeftToRight(comboBox)) { r.x -= (HORIZ_MARGIN + 2); } else { r.x += r.width + HORIZ_MARGIN + 1; } r.y = in.top; r.width = 1; r.height = comboBox.getBounds().height - in.bottom - in.top; g.setColor(UIManager.getColor("controlShadow")); g.fillRect(r.x, r.y, r.width, r.height); r.x++; g.setColor(UIManager.getColor("controlHighlight")); g.fillRect(r.x, r.y, r.width, r.height); } }
/** Updates the UIs of all the known Frames. */ private static void updateAllUIs() { // Check if the current UI is WindowsLookAndfeel and flush the XP style map. // Note: Change the package test if this class is moved to a different package. Class uiClass = UIManager.getLookAndFeel().getClass(); if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) { XPStyle.invalidateStyle(); } Frame appFrames[] = Frame.getFrames(); for (int j = 0; j < appFrames.length; j++) { updateWindowUI(appFrames[j]); } }
public void propertyChange(PropertyChangeEvent pce) { DesktopProperty property = (DesktopProperty) get(); if (property == null || laf != UIManager.getLookAndFeel()) { // The property was GC'ed, we're no longer interested in // PropertyChanges, remove the listener. dispose(); } else { property.invalidate(); property.updateUI(); } }
static Icon getOceanDisabledButtonIcon(Image image) { Object[] range = (Object[]) UIManager.get("Button.disabledGrayRange"); int min = 180; int max = 215; if (range != null) { min = ((Integer) range[0]).intValue(); max = ((Integer) range[1]).intValue(); } ImageProducer prod = new FilteredImageSource(image.getSource(), new OceanDisabledButtonImageFilter(min, max)); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); }
protected BasicLookAndFeel createBaseLookAndFeel() { try { if (SystemInfo.isMac) { final String name = UIManager.getSystemLookAndFeelClassName(); return (BasicLookAndFeel) Class.forName(name).newInstance(); } else { return new IdeaLaf(); } } catch (Exception e) { log(e); } return null; }
/** {@inheritDoc} */ @Override protected void installListeners(JScrollPane c) { super.installListeners(c); c.addPropertyChangeListener(this); if (UIManager.getBoolean("ScrollPane.useChildTextComponentFocus")) { viewportViewFocusHandler = new ViewportViewFocusHandler(); c.getViewport().addContainerListener(viewportViewFocusHandler); Component view = c.getViewport().getView(); if (view instanceof JTextComponent) { view.addFocusListener(viewportViewFocusHandler); } } }
static int getInt(Object key, int defaultValue) { Object value = UIManager.get(key); if (value instanceof Integer) { return ((Integer) value).intValue(); } if (value instanceof String) { try { return Integer.parseInt((String) value); } catch (NumberFormatException nfe) { } } return defaultValue; }
/** * Draws a radial type gradient. The gradient will be drawn vertically if <code>vertical</code> is * true, otherwise horizontally. The UIManager key consists of five values: r1 r2 c1 c2 c3. The * gradient is broken down into four chunks drawn in order from the origin. * * <ol> * <li>Gradient r1 % of the size from c1 to c2 * <li>Rectangle r2 % of the size in c2. * <li>Gradient r1 % of the size from c2 to c1 * <li>The remaining size will be filled with a gradient from c1 to c3. * </ol> * * @param c Component rendering to * @param g Graphics to draw to. * @param key UIManager key used to look up gradient values. * @param x X coordinate to draw from * @param y Y coordinate to draw from * @param w Width to draw to * @param h Height to draw to * @param vertical Direction of the gradient * @return true if <code>key</code> exists, otherwise false. */ static boolean drawGradient( Component c, Graphics g, String key, int x, int y, int w, int h, boolean vertical) { java.util.List gradient = (java.util.List) UIManager.get(key); if (gradient == null || !(g instanceof Graphics2D)) { return false; } if (w <= 0 || h <= 0) { return true; } GradientPainter.INSTANCE.paint(c, (Graphics2D) g, gradient, x, y, w, h, vertical); return true; }
/** * Create a component that will replace the spinner models value with the object returned by * <code>spinner.getNextValue</code>. By default the <code>nextButton</code> is a JButton who's * <code>ActionListener</code> updates it's <code>JSpinner</code> ancestors model. If a nextButton * isn't needed (in a subclass) then override this method to return null. * * @return a component that will replace the spinners model with the next value in the sequence, * or null * @see #installUI * @see #createPreviousButton */ protected Component createNextButton() { Component tmpButton = super.createNextButton(); if (tmpButton instanceof JButton) { JButton result = new ArrowButton(SwingConstants.NORTH); ((ArrowButton) result).setDrawBottomBorder(false); result.setBorder( BorderFactory.createMatteBorder(1, 1, 0, 1, UIManager.getColor("Button.borderColor"))); ActionListener al[] = ((JButton) tmpButton).getActionListeners(); for (int i = 0; i < al.length; i++) result.addActionListener(al[i]); MouseListener ml[] = ((JButton) tmpButton).getMouseListeners(); for (int i = 0; i < ml.length; i++) result.addMouseListener(ml[i]); return result; } else return tmpButton; }