Change the order of the Highlighters

View: New views
11 Messages — Rating Filter:   Alert me  

Change the order of the Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a way to reorder the highlighters attached to a JXTable? was hoping to find a insertHighlighter(int index, highlighter) or addHighlighter(int index, highlighter) ?

Suppose I could iterate over the highlighter array removing and then reattaching things in a new order with some legwork, but I'm also wondering whats the difference between having say half a dozen highlighters and the CompoundHighlighter(s)?
[Message sent by forum member 'osbald' (osbald)]

http://forums.java.net/jive/thread.jspa?messageID=287094

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Change the order of the Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Oh that's a bit wacky looks like my new highlighter after being 'inserted' into the start of the highlighters list is now using the previous residents predicate? only seeing it highlight on alternate rows where it's own predicate has nothing to do with row count..?

Also this highlighter is painting the row with a 30% alpha background (hence why I needed to reorder it before any of my cell colouring highlighters). But I'm seeing a darker background colour used in the Boolean/JCheckbox columns than the rest of the columns?
[Message sent by forum member 'osbald' (osbald)]

http://forums.java.net/jive/thread.jspa?messageID=287096

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Change the order of the Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gah forget the first bit (I'm being dull again) I've managed to put the row colour highlighter before the alternate row one, which were moved to the end. The Booleans look a bit odd though?
[Message sent by forum member 'osbald' (osbald)]

http://forums.java.net/jive/thread.jspa?messageID=287097

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Change the order of the Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, bit out of it today.  What's the problem, Richard?  Odd Boolean rendering?  Can you provide a demo?

Karl
[Message sent by forum member 'kschaefe' (kschaefe)]

http://forums.java.net/jive/thread.jspa?messageID=287110

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Change the order of the Highlighters

by Kleopatra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

jdnc-interest@... schrieb:
>  The Booleans look a bit odd though?
>  

can't see anything from the distance <g>

We had an issue with the checkbox renderer

https://swingx.dev.java.net/issues/show_bug.cgi?id=897

which may or may not be related - Hudson still sleeping (and Jan maybe
on vacation?), so you would have to get the fix from cvs

Cheers
Jeanette






---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Boolean Rendering with Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nope, don't think a new snapshot helped. In the example below I was expecting the whole row to be the same background colour. But booleans appear darker (double?)

[code]
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.color.ColorUtil;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.ComponentAdapter;
import org.jdesktop.swingx.decorator.HighlightPredicate;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.Set;

/*
 * Created by IntelliJ IDEA.
 * User: Richard Osbaldeston
 * Date: 17-Jul-2008
 * Time: 17:42:35
 */

public class BooleanAlphaHighlighterIssue {

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new BooleanAlphaHighlighterIssue();
            }
        });
    }

    public BooleanAlphaHighlighterIssue() {
        JFrame frame = new JFrame(getClass().getSimpleName());
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(createUI());
        frame.setSize(400, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    Component createUI() {
        JPanel content = new JPanel(new BorderLayout());
        JXTable table = new JXTable();
        content.add(new JScrollPane(table));

        Set<String> languages = new HashSet<String>();
        for (Locale locale : Locale.getAvailableLocales()) {
            languages.add(locale.getDisplayLanguage());
        }
        Random random = new Random();
        List<WhatsIt> values = new ArrayList<WhatsIt>();
        for (String language : languages) {
            values.add(new WhatsIt(language, random.nextInt(5) > 2));
        }
        table.setModel(new MyTableModel(values));
        table.addHighlighter(new RowHighlighter(new HighlightPredicate() {
            public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
                return ((Boolean) adapter.getValue(1)).booleanValue();
            }
        }));

        return content;
    }

    static class WhatsIt {
        String language;
        boolean picked;

        WhatsIt(String language, boolean state) {
            this.language = language;
            this.picked = state;
        }

        public String getLanguage() {
            return language;
        }

        public void setLanguage(String language) {
            this.language = language;
        }

        public boolean isPicked() {
            return picked;
        }

        public void setPicked(boolean picked) {
            this.picked = picked;
        }
    }

    class MyTableModel extends AbstractTableModel {
        List<WhatsIt> values;

        MyTableModel(List<WhatsIt> values) {
            this.values = new ArrayList<WhatsIt>(values);
        }

        public int getRowCount() {
            return values.size();
        }

        public int getColumnCount() {
            return 2;
        }

        @Override
        public Class<?> getColumnClass(int column) {
            switch (column) {
                case 0:
                    return String.class;
                case 1:
                    return Boolean.class;
            }
            return super.getColumnClass(column);
        }

        public Object getValueAt(int row, int column) {
            WhatsIt item = values.get(row);
            switch (column) {
                case 0:
                    return item.getLanguage();
                case 1:
                    return item.isPicked();
            }
            return "";
        }

        @Override
        public String getColumnName(int column) {
            switch (column) {
                case 0:
                    return "Nationality";
                case 1:
                    return "Wears socks with sandals";
            }
            return super.getColumnName(column);
        }
    }


    static class RowHighlighter extends ColorHighlighter {
        Font BOLD_FONT;

        RowHighlighter(HighlightPredicate predicate) {
            super(predicate, ColorUtil.setAlpha(Color.ORANGE, 60), Color.RED);
        }

        @Override
        protected Component doHighlight(Component renderer, ComponentAdapter adapter) {
            renderer.setForeground(getForeground());
            if (BOLD_FONT == null) {
                BOLD_FONT = renderer.getFont().deriveFont(Font.BOLD);
            }
            renderer.setFont(BOLD_FONT);
            return super.doHighlight(renderer, adapter);
        }
    }
}
[/code]
[Message sent by forum member 'osbald' (osbald)]

http://forums.java.net/jive/thread.jspa?messageID=287277

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Boolean Rendering with Highlighters

by Kleopatra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

jdnc-interest@... schrieb:
> Nope, don't think a new snapshot helped. In the example below I was expecting the whole row to be the same background colour. But booleans appear darker (double?)
>
>  

I agree - looks like a bug (with Nimbus, colors of the highlighted are
okay, but the unhighlighted aren't ... don't understand what's going on
- Richard the 1. maybe?). Could you please file an issue?

Thanks
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Boolean Rendering with Highlighters

by Kleopatra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Richard,

looks like it's not special to the renderer, but something to checkbox
painting: depending on lf, it gets more or less confused by the alpha.
Try the example below (needs the swingx test package to compile and run).

Jeanette

[code]
public class RendererExperiments extends InteractiveTestCase {
    @SuppressWarnings("unused")
    private static final Logger LOG = Logger
            .getLogger(RendererExperiments.class.getName());
    public static void main(String args[]) {
//      setSystemLF(true);
        RendererExperiments test = new RendererExperiments();
      try {
//        test.runInteractiveTests();
         test.runInteractiveTests(".*Alpha.*");
      } catch (Exception e) {
          System.err.println("exception when executing interactive tests:");
          e.printStackTrace();
      }
  }
   
    public void interactiveAlphaBackground() {
        Color color = ColorUtil.setAlpha(Color.ORANGE, 60);
       
        JCheckBox check = new JCheckBox("what's my color?");
//        check.setOpaque(true);
//        check.setContentAreaFilled(true);
        check.setBackground(color);
        JLabel label = new JLabel("and mine?");
        label.setOpaque(true);
        label.setBackground(color );
        JButton button = new JButton("the new kid on the block");
        button.setBackground(color);
        JComponent box = Box.createVerticalBox();
        box.setOpaque(true);
        box.setBackground(Color.WHITE);
        box.add(check);
        box.add(label);
        box.add(button);
        JXFrame frame = wrapInFrame(box, "alpha in plain ..", true);
        show(frame, 400, 200);
       
    }
    /**
     * Issue ??-swingx: Boolean renderer background is slightly darker if
     * background color is part-transparent.
     *
     */
    public void interactiveBooleanAlpha() {
        JXTable table = new JXTable(new
org.jdesktop.test.AncientSwingTeam());
        table.getColumn(0).setCellRenderer(new DefaultTableRenderer(new
HyperlinkProvider()));
        table.addHighlighter(new RowHighlighter(new HighlightPredicate() {
            public boolean isHighlighted(Component renderer,
ComponentAdapter adapter) {
                return ((Boolean) adapter.getValue(4)).booleanValue();
            }
        }));
        showWithScrollingInFrame(table, "boolean renderer and alpha
background");
       
    }

    static class RowHighlighter extends ColorHighlighter {
        Font BOLD_FONT;

        RowHighlighter(HighlightPredicate predicate) {
            super(predicate, ColorUtil.setAlpha(Color.ORANGE, 60),
Color.RED);
        }

        @Override
        protected Component doHighlight(Component renderer,
ComponentAdapter adapter) {
            renderer.setForeground(getForeground());
            if (BOLD_FONT == null) {
                BOLD_FONT = renderer.getFont().deriveFont(Font.BOLD);
            }
            renderer.setFont(BOLD_FONT);
            return super.doHighlight(renderer, adapter);
        }
    }
}


[/code]



---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Boolean Rendering with Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Only got around to trying that this morning (Monday). I've seen that kind of corruption before http://forums.java.net/jive/thread.jspa?messageID=229377#229377 down to the dodgy opaqueness contract between PanelUI and the way painters are implemented?

Looking at my feed from the CVS changes log you're already ahead of me? <g>
[Message sent by forum member 'osbald' (osbald)]

http://forums.java.net/jive/thread.jspa?messageID=288001

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Boolean Rendering with Highlighters

by jdnc-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Also found http://forums.java.net/jive/thread.jspa?messageID=230409#230070 where the other Richard didn't like the idea of abusing the isOpaque() method much.. but on the other hand I haven't heard of Swing getting a new compositing manager any time soon.
[Message sent by forum member 'osbald' (osbald)]

http://forums.java.net/jive/thread.jspa?messageID=288007

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...


Re: Boolean Rendering with Highlighters

by Kleopatra :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

jdnc-interest@... schrieb:
> Only got around to trying that this morning (Monday). I've seen that kind of corruption before http://forums.java.net/jive/thread.jspa?messageID=229377#229377 down to the dodgy opaqueness contract between PanelUI and the way painters are implemented?
>
>  

I think it has nothing to do with painters (as you see in the renderer
issues) Particularly nice that textfield under vista: type into and see
the frame below shines through ;-) Strictly speaking, one could say that
the opaqueness contract is broken with a transparent background color.

Jeanette


---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@...
For additional commands, e-mail: jdnc-help@...

LightInTheBox - Buy quality products at wholesale price