All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.randelshofer.quaqua.DefaultColumnCellRenderer Maven / Gradle / Ivy

Go to download

A Mavenisation of the Quaqua Mac OSX Swing Look and Feel (Java library) Quaqua Look and Feel (C) 2003-2010, Werner Randelshofer. Mavenisation by Matt Gumbley, DevZendo.org - for problems with Mavenisation, see Matt; for issues with Quaqua, see the Quaqua home page. For full license details, see http://randelshofer.ch/quaqua/license.html

The newest version!
/*
 * @(#)DefaultColumnCellRenderer.java 
 *
 * Copyright (c) 2003-2010 Werner Randelshofer, Immensee, Switzerland.
 * http://www.randelshofer.ch
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */
package ch.randelshofer.quaqua;

import ch.randelshofer.quaqua.util.*;
import java.awt.*;
import java.awt.image.*;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.swing.*;
import javax.swing.border.*;

/**
 * DefaultColumnCellRenderer.
 *
 * @author Werner Randelshofer
 * @version $Id: DefaultColumnCellRenderer.java 361 2010-11-21 11:19:20Z wrandelshofer $
 */
public class DefaultColumnCellRenderer extends JPanel implements ListCellRenderer {

    private JLabel textLabel;
    private JLabel arrowLabel;
    private JBrowser browser;
    protected Icon expandedIcon = null;
    protected Icon selectedExpandedIcon = null;
    protected Icon focusedSelectedExpandedIcon = null;
    protected Icon expandingIcon = null;
    private static final Border DEFAULT_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);
    private static final Color TRANSPARENT_COLOR = new Color(0, true);

    public DefaultColumnCellRenderer(JBrowser browser) {
        this.browser = browser;

        expandedIcon = UIManager.getIcon("Browser.expandedIcon");
        selectedExpandedIcon = UIManager.getIcon("Browser.selectedExpandedIcon");
        focusedSelectedExpandedIcon = UIManager.getIcon("Browser.focusedSelectedExpandedIcon");

        if (expandedIcon == null) {
            BufferedImage iconImages[] = Images.split(
                    Toolkit.getDefaultToolkit().createImage(
                    DefaultColumnCellRenderer.class.getResource("snow_leopard/images/Browser.disclosureIcons.png")),
                    6, true);

            expandedIcon = new ImageIcon(iconImages[0]);
            selectedExpandedIcon = new ImageIcon(iconImages[4]);
            focusedSelectedExpandedIcon = new ImageIcon(iconImages[2]);
        }

        setLayout(new BorderLayout());

        textLabel = new LabelRenderer();
        arrowLabel = new LabelRenderer();
        setOpaque(true);

        textLabel.putClientProperty("Quaqua.Component.visualMargin", new Insets(0, 0, 0, 0));
        textLabel.setOpaque(false);
        arrowLabel.putClientProperty("Quaqua.Component.visualMargin", new Insets(0, 0, 0, 0));
        arrowLabel.setOpaque(false);

        add(textLabel, BorderLayout.CENTER);
        arrowLabel.setIcon(expandedIcon);
        add(arrowLabel, BorderLayout.EAST);
    }

    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected,
            boolean cellHasFocus) {
        //setComponentOrientation(list.getComponentOrientation());
        boolean isFocused = QuaquaUtilities.isFocused(list);

        if (isSelected) {
            setBackground(list.getSelectionBackground());
            Color foreground = (!isFocused && UIManager.getColor("List.inactiveSelectionForeground") != null) ? UIManager.getColor("List.inactiveSelectionForeground") : list.getSelectionForeground();
            textLabel.setForeground(foreground);
            arrowLabel.setForeground(foreground);
            arrowLabel.setIcon(isFocused ? focusedSelectedExpandedIcon : selectedExpandedIcon);
        } else {
            setBackground(TRANSPARENT_COLOR);
            Color foreground = list.getForeground();
            textLabel.setForeground(foreground);
            arrowLabel.setForeground(foreground);
            arrowLabel.setIcon(expandedIcon);
        }

        textLabel.setText((value == null) ? "null" : value.toString());
        //textLabel.setIcon(getFileChooser().getIcon(file));

        arrowLabel.setVisible(!browser.getModel().isLeaf(value));


        textLabel.setEnabled(list.isEnabled());
        textLabel.setFont(list.getFont());

        // Get border. Handle Look and feels which don't specify a border.
        Border border = UIManager.getBorder((cellHasFocus) ? "List.focusCellHighlightBorder" : "List.cellNoFocusBorder");
        if (border == null) {
            border = DEFAULT_NO_FOCUS_BORDER;
        }
        setBorder(border);

        return this;
    }

    // Overridden for performance reasons.
    //public void validate() {}
    @Override
    public void revalidate() {
    }

    @Override
    public void repaint(long tm, int x, int y, int width, int height) {
    }

    @Override
    public void repaint(Rectangle r) {
    }

    @Override
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
    }

    @Override
    public void firePropertyChange(String propertyName, short oldValue, short newValue) {
    }

    @Override
    public void firePropertyChange(String propertyName, int oldValue, int newValue) {
    }

    @Override
    public void firePropertyChange(String propertyName, long oldValue, long newValue) {
    }

    @Override
    public void firePropertyChange(String propertyName, float oldValue, float newValue) {
    }

    @Override
    public void firePropertyChange(String propertyName, double oldValue, double newValue) {
    }

    @Override
    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
    }

    //
    // Inner classes
    //
    public static class UIResource extends DefaultColumnCellRenderer implements javax.swing.plaf.UIResource {

        public UIResource(JBrowser browser) {
            super(browser);
        }
    }

    private static class LabelRenderer extends JLabel {
        // Overridden for performance reasons.

        @Override
        public void validate() {
        }

        @Override
        public void revalidate() {
        }

        @Override
        public void repaint(
                long tm, int x, int y, int width, int height) {
        }

        @Override
        public void repaint(Rectangle r) {
        }

        @Override
        protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
            if (propertyName != null && propertyName.equals("text")) {
                super.firePropertyChange(propertyName, oldValue, newValue);
            }
        }

        @Override
        public void firePropertyChange(String propertyName, short oldValue, short newValue) {
        }

        @Override
        public void firePropertyChange(String propertyName, int oldValue, int newValue) {
        }

        @Override
        public void firePropertyChange(String propertyName, long oldValue, long newValue) {
        }

        @Override
        public void firePropertyChange(String propertyName, float oldValue, float newValue) {
        }

        @Override
        public void firePropertyChange(String propertyName, double oldValue, double newValue) {
        }

        @Override
        public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
        }
    };
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy