List of usage examples for java.awt Component getBackground
@Transient
public Color getBackground()
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * {@inheritDoc}//from ww w .j a v a 2 s . co m */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) { g2.setStroke(new BasicStroke(2.0f)); switch (message.getSeverity()) { case WARNING: g2.setColor(WARN_COLOR); case ALERT: g2.setColor(ALERT_COLOR); case SAFETY: g2.setColor(SAFETY_COLOR); default: g2.setColor(WARN_COLOR); } // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? WARN_COLOR : ALERT_COLOR); g2.draw(area); } }
From source file:de.tor.tribes.ui.renderer.ColoredCoutdownCellRenderer.java
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); try {/* w w w . ja va2 s. co m*/ JLabel renderComponent = ((JLabel) c); Long d = (Long) value; // renderComponent.setText(DurationFormatUtils.formatDuration(d, "HHH:mm:ss.SSS", true)); long diff = d; long five_minutes = 5 * MINUTE; long ten_minutes = 10 * MINUTE; Color color = null; if (row % 2 == 0) { color = Constants.DS_ROW_A; } else { color = Constants.DS_ROW_B; } if (diff <= 0) { //value is expired, stroke result //renderComponent.setText(specialFormat.format(d)); //renderComponent.setForeground(Color.RED); } else if (diff <= ten_minutes && diff > five_minutes) { float ratio = (float) (diff - five_minutes) / (float) five_minutes; Color c1 = Color.YELLOW; Color c2 = Color.GREEN; int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio)); int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio)); int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio)); color = new Color(red, green, blue); } else if (diff <= five_minutes) { float ratio = (float) diff / (float) five_minutes; Color c1 = Color.RED; Color c2 = Color.YELLOW; int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio)); int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio)); int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio)); color = new Color(red, green, blue); } renderComponent.setText(DurationFormatUtils.formatDuration(d, "HHH:mm:ss.SSS", true)); if (isSelected) { color = c.getBackground(); } renderComponent.setOpaque(true); renderComponent.setBackground(color); return renderComponent; } catch (Exception e) { return c; } }
From source file:org.openmicroscopy.shoola.agents.measurement.util.ui.ResultsCellRenderer.java
/** * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, * boolean, boolean, int, int) *//*w w w .j av a 2s . c om*/ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component thisComponent = new JLabel(); JLabel label = new JLabel(); label.setOpaque(true); if (value instanceof Number) { MeasurementTableModel tm = (MeasurementTableModel) table.getModel(); KeyDescription key = tm.getColumnNames().get(column); String k = key.getKey(); MeasurementUnits units = tm.getUnitsType(); Number n = (Number) value; String s; if (units.isInMicrons()) { UnitsObject object; StringBuffer buffer = new StringBuffer(); object = UIUtilities.transformSize(n.doubleValue()); s = twoDecimalPlaces(object.getValue()); if (StringUtils.isNotBlank(s)) { buffer.append(s); if (!(AnnotationKeys.ANGLE.getKey().equals(k) || AnnotationDescription.ZSECTION_STRING.equals(k) || AnnotationDescription.ROIID_STRING.equals(k) || AnnotationDescription.TIME_STRING.equals(k))) { buffer.append(object.getUnits()); } if (AnnotationKeys.AREA.getKey().equals(k)) { buffer = new StringBuffer(); object = UIUtilities.transformSquareSize(n.doubleValue()); s = twoDecimalPlaces(object.getValue()); buffer.append(s); buffer.append(object.getUnits()); } label.setText(buffer.toString()); } } else { s = UIUtilities.twoDecimalPlaces(n.doubleValue()); if (StringUtils.isNotBlank(s)) { label.setText(s); } } thisComponent = label; } else if (value instanceof FigureType || value instanceof String) { thisComponent = makeShapeIcon(label, "" + value); } else if (value instanceof Color) { label.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); label.setBackground((Color) value); thisComponent = label; } else if (value instanceof Boolean) { JCheckBox checkBox = new JCheckBox(); checkBox.setSelected((Boolean) value); thisComponent = checkBox; } else if (value instanceof ArrayList) { thisComponent = createList(value); //return list; } if (!(value instanceof Color)) { RendererUtils.setRowColor(thisComponent, table.getSelectedRow(), row); if (label != null) label.setBackground(thisComponent.getBackground()); } return thisComponent; }
From source file:self.philbrown.javaQuery.$.java
/** * Animate multiple view properties at the same time. Example: * <pre>/*from w w w .ja v a 2s .c o m*/ * $.with(myView).animate(new QuickMap(QuickEntry.qe("alpha", .8f), QuickEntry.qe("width", 50%)), 400, Easing.LINEAR, null); * </pre> * @param properties mapping of property names and final values to animate * @param options the options for setting the duration, easing, etc of the animation * @return this */ public $ animate(Map<String, Object> properties, final AnimationOptions options) { List<Animator> animations = new ArrayList<Animator>(); for (Entry<String, Object> entry : properties.entrySet()) { final String key = entry.getKey(); //Java sometimes will interpret these Strings as Numbers, so some trickery is needed below Object value = entry.getValue(); for (final Component view : this.views) { Animator anim = null; if (value instanceof String) value = getAnimationValue(view, key, (String) value); //final Object fValue = value; if (value != null) { //special color cases if (key.equals("alpha") || key.equals("red") || key.equals("green") || key.equals("blue")) { if (key.equals("alpha") && view instanceof JComponent) { ((JComponent) view).setOpaque(false); } try { final Method getComponent = Color.class .getMethod(Log.buildString("get", capitalize(key))); final int colorComponent = (Integer) getComponent.invoke(view.getBackground()); final ColorHelper color = new ColorHelper(view.getBackground()); final Method setComponent = ColorHelper.class.getMethod( Log.buildString("set", capitalize(key)), new Class<?>[] { int.class }); anim = new Animator(); //if integer - assume 0-255 if (value instanceof Integer || is(value, int.class)) { anim.addTarget(PropertySetter.getTarget(color, key, colorComponent, Integer.parseInt(value.toString()))); } //if float - assume 0.0-1.0 else if (value instanceof Float || is(value, float.class)) { anim.addTarget(PropertySetter.getTarget(color, key, colorComponent, (int) (255 * Float.parseFloat(value.toString())))); } anim.addTarget(new TimingTargetAdapter() { @Override public void timingEvent(Animator source, double fraction) { double d = source.getInterpolator().interpolate(fraction); try { setComponent.invoke(color, (int) d); view.setBackground(color.getColor()); // if (view instanceof JComponent) // ((JComponent) view).revalidate(); view.repaint(); } catch (Throwable t) { if (options.debug()) t.printStackTrace(); } } }); } catch (Throwable t) { if (options.debug()) t.printStackTrace(); } } else { final Rectangle params = view.getBounds(); try { final Field field = params.getClass().getField(key); if (field != null) { anim = new Animator(); anim.addTarget(PropertySetter.getTarget(params, key, field.get(params), value)); anim.addTarget(new TimingTargetAdapter() { @Override public void timingEvent(Animator source, double fraction) { Rectangle bounds = view.getBounds(); double d = source.getInterpolator().interpolate(fraction); try { field.set(bounds, d); } catch (Throwable t) { if (options.debug()) t.printStackTrace(); } view.setBounds(bounds); view.repaint(); if (options.progress() != null) { options.progress().invoke($.with(view), key, d, source.getDuration() - source.getTotalElapsedTime()); } } }); } } catch (Throwable t) { if (options.debug()) Log.w("$", String.format(Locale.US, "%s is not a LayoutParams attribute.", key)); } if (anim == null) { anim = new Animator(); Object first; try { final Method getter = view.getClass() .getMethod(Log.buildString("get", capitalize(key))); first = getter.invoke(view); } catch (Throwable t) { first = 0; } anim.addTarget(PropertySetter.getTarget(view, key, first, value)); if (options.progress() != null) { anim.addTarget(new TimingTargetAdapter() { @Override public void timingEvent(Animator source, double fraction) { double d = source.getInterpolator().interpolate(fraction); if (options.progress() != null) { options.progress().invoke($.with(view), key, d, source.getDuration() - source.getTotalElapsedTime()); } } }); } } } if (options.repeatCount() >= 1) anim.setRepeatCount(options.repeatCount()); if (options.reverse()) anim.setRepeatBehavior(Animator.RepeatBehavior.REVERSE); animations.add(anim); } } } AnimatorSet animation = animationWithOptions(options, animations); animation.start(); return this; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
public static void setBackgroundColor(Component cellRendererComponent, JTable tbl, Object oValue, boolean bSelected, boolean bHasFocus, int iRow, int iColumn) { cellRendererComponent.setBackground(bSelected ? tbl.getSelectionBackground() : iRow % 2 == 0 ? tbl.getBackground() : NuclosThemeSettings.BACKGROUND_PANEL); cellRendererComponent.setForeground(bSelected ? tbl.getSelectionForeground() : tbl.getForeground()); final TableModel tm; final int adjustColIndex; if (tbl instanceof FixedColumnRowHeader.HeaderTable && ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable() != null) { tm = ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable().getModel(); adjustColIndex = FixedRowIndicatorTableModel.ROWMARKERCOLUMN_COUNT; } else {//w w w . j av a 2s .co m tm = tbl.getModel(); adjustColIndex = 0; } // check whether the data of the component is readable for current user, by asking the security agent of the actual field if (tm instanceof SortableCollectableTableModel<?>) { final SortableCollectableTableModel<Collectable> tblModel = (SortableCollectableTableModel<Collectable>) tm; if (tblModel.getRowCount() > iRow) { final Collectable clct = tblModel.getCollectable(iRow); final Integer iTColumn = tbl.getColumnModel().getColumn(iColumn).getModelIndex() - adjustColIndex; final CollectableEntityField clctef = tblModel.getCollectableEntityField(iTColumn); if (clctef == null) { throw new NullPointerException("getTableCellRendererComponent failed to find field: " + clct + " tm index " + iTColumn); } boolean isEnabled = true; if (!clctef.isNullable() && isNull(oValue)) { cellRendererComponent.setBackground(getMandatoryColor()); cellRendererComponent.setForeground(tbl.getForeground()); } else { // if (clct.getId() == null) { // cellRendererComponent.setBackground(tbl.getBackground()); // cellRendererComponent.setForeground(tbl.getForeground()); // } else { if (tbl instanceof SubForm.SubFormTable) { SubFormTable subformtable = (SubForm.SubFormTable) tbl; Column subformcolumn = subformtable.getSubForm().getColumn(clctef.getName()); if (subformcolumn != null && !subformcolumn.isEnabled()) { isEnabled = false; if (bSelected) { cellRendererComponent .setBackground(NuclosThemeSettings.BACKGROUND_INACTIVESELECTEDCOLUMN); } else { cellRendererComponent.setBackground(NuclosThemeSettings.BACKGROUND_INACTIVECOLUMN); } } } // } try { EntityMetaDataVO meta = MetaDataClientProvider.getInstance() .getEntity(clctef.getEntityName()); if (meta.getRowColorScript() != null && !bSelected) { AbstractCollectableComponent.setBackground(cellRendererComponent, meta.getRowColorScript(), clct, meta, isEnabled); } } catch (CommonFatalException ex) { LOG.warn(ex); } } } } if (tbl instanceof TableRowMouseOverSupport) { TableRowMouseOverSupport trmos = (TableRowMouseOverSupport) tbl; if (trmos.isMouseOverRow(iRow)) { final Color bgColor = LangUtils.defaultIfNull(cellRendererComponent.getBackground(), Color.WHITE); cellRendererComponent .setBackground(new Color(Math.max(0, bgColor.getRed() - (bgColor.getRed() * 8 / 100)), Math.max(0, bgColor.getGreen() - (bgColor.getGreen() * 8 / 100)), Math.max(0, bgColor.getBlue() - (bgColor.getBlue() * 8 / 100)))); // cellRendererComponent.setBackground(UIManager.getColor("Table.selectionBackground")); } } }