📄 decoratordemopanel.java
字号:
/* * $Id: DecoratorDemoPanel.java,v 1.22 2005/09/06 09:29:12 kleopatra Exp $ * * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. */package org.jdesktop.demo.swingx;import java.awt.Color;import java.beans.IntrospectionException;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.regex.Pattern;import javax.swing.DefaultComboBoxModel;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.ListModel;import javax.swing.table.TableModel;import javax.swing.tree.TreeModel;import org.jdesktop.binding.JavaBeanDataModel;import org.jdesktop.binding.metadata.EnumeratedMetaData;import org.jdesktop.binding.metadata.MetaData;import org.jdesktop.binding.swingx.BindingFactory;import org.jdesktop.binding.swingx.BindingHandler;import org.jdesktop.demo.DemoPanel;import org.jdesktop.demo.swingx.common.ActionMapTableModel;import org.jdesktop.demo.swingx.common.ActionMapTreeTableModel;import org.jdesktop.demo.swingx.common.MarginHighlighter;import org.jdesktop.swingx.JXList;import org.jdesktop.swingx.JXPanel;import org.jdesktop.swingx.JXRadioGroup;import org.jdesktop.swingx.JXTable;import org.jdesktop.swingx.JXTree;import org.jdesktop.swingx.PatternModel;import org.jdesktop.swingx.action.BoundAction;import org.jdesktop.swingx.decorator.Filter;import org.jdesktop.swingx.decorator.FilterPipeline;import org.jdesktop.swingx.decorator.Highlighter;import org.jdesktop.swingx.decorator.HighlighterPipeline;import org.jdesktop.swingx.decorator.PatternFilter;import org.jdesktop.swingx.decorator.RolloverHighlighter;import org.jdesktop.swingx.decorator.SearchHighlighter;import com.jgoodies.forms.builder.PanelBuilder;import com.jgoodies.forms.factories.Borders;import com.jgoodies.forms.layout.CellConstraints;import com.jgoodies.forms.layout.ConstantSize;import com.jgoodies.forms.layout.FormLayout;import com.jgoodies.forms.util.LayoutStyle;/** * Demonstrates usage of Decorators. * * @author Jeanette Winzenburg */public class DecoratorDemoPanel extends DemoPanel { // ----------------- demo components private JXTree tree; private JXList list; private JXTable table; // ----------------- demo decorators /** shared highlighter for rollover effect. */ private Highlighter rolloverHighlighter; /** shared highlighter for matches. */ private SearchHighlighter searchHighlighter; /** hacking highlighter for list's border adjustment. */ private Highlighter marginHighlighter; /** Filter for matching entries used in list. */ private PatternFilter listPatternFilter; private FilterPipeline listFilterPipeline; /** Filter for matching entries used in table. */ private PatternFilter tablePatternFilter; private FilterPipeline tableFilterPipeline; // ---------------- controlling components/models private JXRadioGroup radioGroup; private JTextField inputText; private JButton nextButton; private JTextField patternText; private PatternModel patternModel; private String[] findModi = new String[] { "highlight", "filter", "search" }; private String findModus = findModi[0]; private BoundAction findNextAction; private JLabel radioGroupLabel; private JLabel inputTextLabel; private JLabel patternLabel; /** Creates new form DecoratorDemoPanel */ public DecoratorDemoPanel() { setName("Decorator Demo"); createDecorators(); initComponents(); configureComponents(); build(); bind(); } /** * called after pattern changed. * * @param pattern */ protected void updatePattern(Pattern pattern) { searchHighlighter.setPattern(pattern); tablePatternFilter.setPattern(pattern); listPatternFilter.setPattern(pattern); // repaint(); } /** * called after find modus changed. * */ private void updateDecorators() { boolean highlightMatches = findModi[0].equals(getFindModus()); // update the highlighter pipelines updatePipeline(table.getHighlighters(), highlightMatches); updatePipeline(list.getHighlighters(), highlightMatches); // supported in highlight mode only// list.setEnabled(highlightMatches); tree.setEnabled(highlightMatches); // filter/search support is implemented for JXList FilterPipeline listFilters = findModi[1].equals(getFindModus()) ? getFilterPipeline("list"): null; list.setFilters(listFilters); // filter/search support is implemented for JXTable only FilterPipeline filters = findModi[1].equals(getFindModus()) ? getFilterPipeline("table"): null; table.setFilters(filters); findNextAction.setEnabled(findModi[2].equals(getFindModus())); // repaint(); } private void updatePipeline(HighlighterPipeline highlighters, boolean highlightMatches) { if (highlightMatches) { highlighters.addHighlighter(rolloverHighlighter, true); highlighters.addHighlighter(searchHighlighter, true); } else { highlighters.removeHighlighter(searchHighlighter); highlighters.removeHighlighter(rolloverHighlighter); } }//--------------------------- init decorators private void createDecorators() { createHighlighters(); createFilters(); findNextAction = new BoundAction("Find Next"); }//--------------------------- Highlighters /** * create all highlighters. * * */ private void createHighlighters() { // rollover effect - blue foreground rolloverHighlighter = new RolloverHighlighter(null, Color.BLUE); // highlight matching effect - magenta foreground searchHighlighter = new SearchHighlighter(null, Color.MAGENTA); // highlight matches in all columns searchHighlighter.setHighlightAll(); // hacking a right/left margin marginHighlighter = new MarginHighlighter(marginBorder); }//----------------------- Filters private void createFilters() { // filtering on first column // JW: need option to filter all columns? tablePatternFilter = new PatternFilter(null, 0, 0); listPatternFilter = new PatternFilter(null, 0, 0); } private FilterPipeline getFilterPipeline(String viewKey) { if ("table".equals(viewKey)) { // JW: we have to store the filter pipeline // because filters can be bound once only if (tableFilterPipeline == null) { tableFilterPipeline = new FilterPipeline( new Filter[] { tablePatternFilter }); } return tableFilterPipeline; } else if ("list".equals(viewKey)) { if (listFilterPipeline == null) { listFilterPipeline = new FilterPipeline( new Filter[] { listPatternFilter }); } return listFilterPipeline; } return null; } // ----------------------- initial configure components private void configureComponents() { // show column control table.setColumnControlVisible(true); // enable rollover in collection views table.setRolloverEnabled(true); list.setRolloverEnabled(true); tree.setRolloverEnabled(true); // share highlighterPipeline in table/tree table.setHighlighters(new HighlighterPipeline()); tree.setHighlighters(table.getHighlighters()); // use different pipeline for list list.setHighlighters(new HighlighterPipeline(new Highlighter[] { marginHighlighter})); // enable list filtering list.setFilterEnabled(true); // initial update of decorations for collection views updateDecorators(); } // ------------------------ control find modus /** * PRE: getFindModi() contains value. */ public void setFindModus(String value) { if (value.equals(getFindModus()))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -