本文整理汇总了Java中org.jdesktop.swingx.decorator.ComponentAdapter类的典型用法代码示例。如果您正苦于以下问题:Java ComponentAdapter类的具体用法?Java ComponentAdapter怎么用?Java ComponentAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ComponentAdapter类属于org.jdesktop.swingx.decorator包,在下文中一共展示了ComponentAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConfiguredComponentAdapter
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* test convenience method accessing the configured adapter.
*
*/
@Test
public void testConfiguredComponentAdapter() {
JXTree list = new JXTree();
list.expandAll();
assertTrue(list.getRowCount() > 0);
ComponentAdapter adapter = list.getComponentAdapter();
assertEquals(0, adapter.column);
assertEquals(0, adapter.row);
assertTrue(adapter.isHierarchical());
adapter.row = 1;
// corrupt adapter
adapter.column = 1;
adapter = list.getComponentAdapter(0);
assertEquals(0, adapter.column);
assertEquals(0, adapter.row);
}
示例2: interactiveTableColorBasedOnComponentValue
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* Example of custom predicate based on the component's value,
* (as opposed to on the value of the adapter).
*
*
*/
public void interactiveTableColorBasedOnComponentValue() {
TableModel model = new AncientSwingTeam();
JXTable table = new JXTable(model);
table.setForeground(Color.GREEN);
HighlightPredicate predicate = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
if (!(renderer instanceof JLabel)) return false;
String text = ((JLabel) renderer).getText();
return text.contains("y");
}
};
ColorHighlighter hl = new ColorHighlighter(predicate, null, Color.RED);
table.addHighlighter(HighlighterFactory.createSimpleStriping(HighlighterFactory.GENERIC_GRAY));
table.addHighlighter(hl);
showWithScrollingInFrame(table,
"component value-based rendering (label text contains y) ");
}
示例3: interactiveSimpleStriping
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* shows the effect of a simple striping highlighter on a
* colored table.
*
*/
public void interactiveSimpleStriping() {
JXTable table = new JXTable(tableModel);
table.setVisibleRowCount(table.getRowCount() + 3);
table.setBackground(new Color(0xC0FFC0));
table.addHighlighter(HighlighterFactory.createSimpleStriping());
Highlighter disabled = new AbstractHighlighter(HighlightPredicate.READ_ONLY) {
@Override
protected Component doHighlight(Component component,
ComponentAdapter adapter) {
component.setEnabled(false);
return component;
}
};
table.getColumnExt(0).setEditable(false);
table.getColumnExt(2).setEditable(false);
table.getColumnExt(0).setCellRenderer(new DefaultTableRenderer(new TextFieldProvider()));
table.addHighlighter(disabled);
showWithScrollingInFrame(table, "Simple gray striping");
}
示例4: testConfiguredComponentAdapter
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* test convenience method accessing the configured adapter.
*/
@Test
public void testConfiguredComponentAdapter() {
JXComboBox combo = new JXComboBox(new Object[] {1, 2, 3});
ComponentAdapter adapter = combo.getComponentAdapter();
assertThat(adapter.column, is(0));
assertThat(adapter.row, is(0));
// corrupt adapter
adapter.row = 1;
adapter.column = 1;
adapter = combo.getComponentAdapter(0);
assertThat(adapter.column, is(0));
assertThat(adapter.row, is(0));
}
示例5: createXTableWithIndyRowHeights
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* Creates and returns a JXTable with model as returned by createTableModel with
* eventBig == false.
* Has a FontHighlighter which decorates the renderer with a big font if
* the cell value is BIG.
*
* @return a JXTable configured
*/
private JXTable createXTableWithIndyRowHeights() {
DefaultTableModel model = createTableModel(false);
JXTable table = new JXTable(model);
HighlightPredicate predicate = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer,
ComponentAdapter adapter) {
return BIG.equals(adapter.getValue());
}
};
FontHighlighter highlighter = new FontHighlighter(predicate, table.getFont().deriveFont(50f));
table.addHighlighter(highlighter);
return table;
}
示例6: interactiveTestHierarchicalColumnHighlightConditional
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* Requirement: color the leafs of the hierarchical columns differently.
*
* http://forums.java.net/jive/thread.jspa?messageID=165876
*
*
*/
public void interactiveTestHierarchicalColumnHighlightConditional() {
JXTreeTable treeTable = new JXTreeTable(treeTableModel);
HighlightPredicate hierarchical = new ColumnHighlightPredicate(0);
treeTable.addHighlighter(new ShadingColorHighlighter(hierarchical));
HighlightPredicate predicate = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
return adapter.isLeaf();
}
};
ColorHighlighter highlighter = new ColorHighlighter(new AndHighlightPredicate(hierarchical, predicate),
new Color(247,246,239), null);
treeTable.addHighlighter(highlighter);
showWithScrollingInFrame(treeTable,
"HierarchicalColumn And Conditional ");
}
示例7: interactiveRepaintOnUpdateSingleCell
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* After moving to Mustang, this might be vieweda as a bug ;-)
* Was: Unconditional repaint on cell update (through the default
* identify filter).
* Is: only the updated cell is repainted, unrelated (from model perspective)
* cells (like others in row) are not repainted.
*/
public void interactiveRepaintOnUpdateSingleCell() {
JXTable table = new JXTable(10, 5);
// highlight complete row if first cell starts with a
HighlightPredicate predicate = new HighlightPredicate() {
public boolean isHighlighted(Component renderer,
ComponentAdapter adapter) {
return adapter.getString(0).startsWith("a");
}
};
ColorHighlighter highlighter = new ColorHighlighter(predicate, Color.MAGENTA, null, Color.MAGENTA, null);
table.addHighlighter(highlighter);
JXTable other = new JXTable(table.getModel());
other.addHighlighter(highlighter);
JXFrame frame = wrapWithScrollingInFrame(table, other, "repaint on update in first");
addMessage(frame, "edit first cell in left table (start with/out a)");
show(frame);
}
示例8: updateHighlighter
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
protected void updateHighlighter(Component component) {
mouseOverHighlighter.setHighlightPredicate(HighlightPredicate.NEVER);
if (component != null) {
List<Component> pathList = new ArrayList<Component>();
while (component != null) {
pathList.add(0, component);
component = component.getParent();
}
final TreePath treePath = new TreePath(pathList.toArray());
treeTable.scrollPathToVisible(treePath);
HighlightPredicate predicate = new HighlightPredicate() {
@Override
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
return adapter.row == treeTable.getRowForPath(treePath);
}
};
mouseOverHighlighter.setHighlightPredicate(predicate);
// </snip>
}
}
示例9: highlight
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
@Override
public Component highlight(Component comp, ComponentAdapter compAdapter) {
Color bg = comp.getBackground();
JPanel panel = new JPanel(new MigLayout("ins 3"));
panel.setOpaque(true);
panel.setBackground(bg);
try {
Object val = compAdapter.getValue();
Integer intVal = Integer.parseInt(val.toString());
Color clr = new Color(intVal);
JLabel lb = new JLabel();
lb.setPreferredSize(new Dimension(24, 16));
lb.setOpaque(true);
lb.setBackground(clr);
panel.add(lb);
return panel;
} catch (NumberFormatException e) {
return panel;
}
}
示例10: highlight
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
public Component highlight( Component component, ComponentAdapter adapter ) {
if ( adapter.getValue() instanceof Ticket ) {
Ticket ticket = (Ticket) adapter.getValue();
switch( ticket.getPriority() ) {
case 1:
component.setBackground( new Color( 0xAA, 0xAA, 0xFF ) );
break;
case 2:
component.setBackground( new Color( 0xDD, 0xDD, 0xFF ) );
break;
case 3:
component.setBackground( new Color( 0xFF, 0xFF, 0xFF ) );
break;
case 4:
component.setBackground( new Color( 0xFF, 0xDD, 0xDD ) );
break;
case 5:
component.setBackground( new Color( 0xFF, 0xAA, 0xAA ) );
break;
default:
System.out.println( "WARNING: unknown priority!" );
}
if ( ticket.getStatus().equals( "closed" ) ) {
component.setForeground( new Color( 0x33, 0x33, 0x33 ) );
}
else if ( ticket.getStatus().equals( "resolved" ) ) {
component.setForeground( new Color( 0x00, 0x88, 0x00 ) );
}
else {
component.setForeground( new Color( 0x00, 0x00, 0x00 ) );
Font f = component.getFont();
component.setFont( f.deriveFont( f.getStyle() ^ Font.BOLD ) );
}
}
return component;
}
示例11: getComponentAdapter
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* @return the unconfigured ComponentAdapter.
*/
protected ComponentAdapter getComponentAdapter() {
if (dataAdapter == null) {
dataAdapter = new ListAdapter(this);
}
return dataAdapter;
}
示例12: applyBackground
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
@Override
protected void applyBackground(Component renderer, ComponentAdapter adapter) {
if (!adapter.isSelected()) {
Color ok, error, disabled;
if (adapter.getDepth() == 1) {
ok = new Color(157, 204, 88);
error = new Color(204, 0, 20);
disabled = Color.darkGray;
} else {
ok = new Color(208, 217, 146);
error = new Color(230, 80, 70);
disabled = Color.lightGray;
}
Object value = adapter.getValue(PluginInformationPane.UID_INDEX);
if (value instanceof String) {
String uid = (String) value;
if (PluginManager.getInstance().isActive(uid) && PluginManager.getInstance().isCurrentlyEnabled(uid)) {
renderer.setBackground(ok);
} else if (!PluginManager.getInstance().isCurrentlyEnabled(uid)) {
renderer.setBackground(disabled);
} else if (!PluginManager.getInstance().isActive(uid)) {
renderer.setBackground(error);
}
}
}
super.applyBackground(renderer, adapter);
}
示例13: getComponentAdapter
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* @return the unconfigured ComponentAdapter.
*/
protected ComponentAdapter getComponentAdapter() {
if (dataAdapter == null) {
dataAdapter = new ComboBoxAdapter(this);
}
return dataAdapter;
}
示例14: applyRenderer
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* Performs configuration of the tree's renderer if the adapter's column is
* the hierarchical column, does nothing otherwise.
* <p>
*
* Note: this is legacy glue if the treeCellRenderer is of type
* DefaultTreeCellRenderer. In that case the renderer's
* background/foreground/Non/Selection colors are set to the tree's
* background/foreground depending on the adapter's selection state. Does
* nothing if the treeCellRenderer is backed by a ComponentProvider.
*
* @param component the rendering component
* @param adapter component data adapter
* @throws NullPointerException if the specified component or adapter is
* null
*/
protected Component applyRenderer(Component component,
ComponentAdapter adapter) {
if (component == null) {
throw new IllegalArgumentException("null component");
}
if (adapter == null) {
throw new IllegalArgumentException("null component data adapter");
}
if (isHierarchical(adapter.column)) {
// After all decorators have been applied, make sure that relevant
// attributes of the table cell renderer are applied to the
// tree cell renderer before the hierarchical column is rendered!
TreeCellRenderer tcr = renderer.getCellRenderer();
if (tcr instanceof JXTree.DelegatingRenderer) {
tcr = ((JXTree.DelegatingRenderer) tcr).getDelegateRenderer();
}
if (tcr instanceof DefaultTreeCellRenderer) {
DefaultTreeCellRenderer dtcr = ((DefaultTreeCellRenderer) tcr);
// this effectively overwrites the dtcr settings
if (adapter.isSelected()) {
dtcr.setTextSelectionColor(component.getForeground());
dtcr.setBackgroundSelectionColor(component.getBackground());
} else {
dtcr.setTextNonSelectionColor(component.getForeground());
dtcr.setBackgroundNonSelectionColor(component
.getBackground());
}
}
}
return component;
}
示例15: getComponentAdapter
import org.jdesktop.swingx.decorator.ComponentAdapter; //导入依赖的package包/类
/**
* @return the unconfigured ComponentAdapter.
*/
protected ComponentAdapter getComponentAdapter() {
if (dataAdapter == null) {
dataAdapter = new TableAdapter(this);
}
return dataAdapter;
}