/** {@inheritDoc} */ @Override public Dimension getMaximumSize(JComponent c) { if (c.getComponentCount() > 0 && c.getLayout() != null) { return null; } AbstractButton b = (AbstractButton) c; SynthContext ss = getContext(c); Dimension size = ss.getStyle() .getGraphicsUtils(ss) .getMaximumSize( ss, ss.getStyle().getFont(ss), b.getText(), getSizingIcon(b), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), b.getIconTextGap(), b.getDisplayedMnemonicIndex()); return size; }
/** {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException("Width and height must be >= 0"); } AbstractButton b = (AbstractButton) c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context)); context .getStyle() .getGraphicsUtils(context) .layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View) b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } return baseline; }
static void updateStyle(JTextComponent comp, SynthContext context, String prefix) { SynthStyle style = context.getStyle(); Color color = comp.getCaretColor(); if (color == null || color instanceof UIResource) { comp.setCaretColor((Color) style.get(context, prefix + ".caretForeground")); } Color fg = comp.getForeground(); if (fg == null || fg instanceof UIResource) { fg = style.getColorForState(context, ColorType.TEXT_FOREGROUND); if (fg != null) { comp.setForeground(fg); } } Object ar = style.get(context, prefix + ".caretAspectRatio"); if (ar instanceof Number) { comp.putClientProperty("caretAspectRatio", ar); } context.setComponentState(SELECTED | FOCUSED); Color s = comp.getSelectionColor(); if (s == null || s instanceof UIResource) { comp.setSelectionColor(style.getColor(context, ColorType.TEXT_BACKGROUND)); } Color sfg = comp.getSelectedTextColor(); if (sfg == null || sfg instanceof UIResource) { comp.setSelectedTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); } context.setComponentState(DISABLED); Color dfg = comp.getDisabledTextColor(); if (dfg == null || dfg instanceof UIResource) { comp.setDisabledTextColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); } Insets margin = comp.getMargin(); if (margin == null || margin instanceof UIResource) { margin = (Insets) style.get(context, prefix + ".margin"); if (margin == null) { // Some places assume margins are non-null. margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; } comp.setMargin(margin); } Caret caret = comp.getCaret(); if (caret instanceof UIResource) { Object o = style.get(context, prefix + ".caretBlinkRate"); if (o != null && o instanceof Integer) { Integer rate = (Integer) o; caret.setBlinkRate(rate.intValue()); } } }
/** Returns the amount to shift the text/icon when painting. */ private int getTextShiftOffset(SynthContext state) { AbstractButton button = (AbstractButton) state.getComponent(); ButtonModel model = button.getModel(); if (model.isArmed() && model.isPressed() && button.getPressedIcon() == null) { return state.getStyle().getInt(state, getPropertyPrefix() + "textShiftOffset", 0); } return 0; }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { JComponent jc = (JComponent) c; SynthContext context = getContext(jc); SynthStyle style = context.getStyle(); if (style == null) { assert false : "SynthBorder is being used outside after the " + " UI has been uninstalled"; return; } context.getPainter().paintViewportBorder(context, g, x, y, width, height); }
/** * Paints the specified component. * * @param context context for the component being painted * @param g the {@code Graphics} object used for painting * @see #update(Graphics,JComponent) */ protected void paint(SynthContext context, Graphics g) { AbstractButton b = (AbstractButton) context.getComponent(); g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(style.getFont(context)); context .getStyle() .getGraphicsUtils(context) .paintText( context, g, b.getText(), getIcon(b), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), b.getIconTextGap(), b.getDisplayedMnemonicIndex(), getTextShiftOffset(context)); }
private Icon getIcon(SynthContext context) { if (context != null) { ComponentOrientation co = context.getComponent().getComponentOrientation(); SynthStyle style = context.getStyle(); if (style != this.style) { this.style = style; loadedLTR = loadedRTL = false; } if (co == null || co.isLeftToRight()) { if (!loadedLTR) { loadedLTR = true; ltrIcon = ((GTKStyle) context.getStyle()).getStockIcon(context, key, size); } return ltrIcon; } else if (!loadedRTL) { loadedRTL = true; rtlIcon = ((GTKStyle) context.getStyle()).getStockIcon(context, key, size); } return rtlIcon; } return ltrIcon; }
/* * Paints the grid lines within <I>aRect</I>, using the grid * color set with <I>setGridColor</I>. Paints vertical lines * if <code>getShowVerticalLines()</code> returns true and paints * horizontal lines if <code>getShowHorizontalLines()</code> * returns true. */ private void paintGrid(SynthContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) { g.setColor(table.getGridColor()); Rectangle minCell = table.getCellRect(rMin, cMin, true); Rectangle maxCell = table.getCellRect(rMax, cMax, true); Rectangle damagedArea = minCell.union(maxCell); SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(context); if (table.getShowHorizontalLines()) { int tableWidth = damagedArea.x + damagedArea.width; int y = damagedArea.y; for (int row = rMin; row <= rMax; row++) { y += table.getRowHeight(row); synthG.drawLine(context, "Table.grid", g, damagedArea.x, y - 1, tableWidth - 1, y - 1); } } if (table.getShowVerticalLines()) { TableColumnModel cm = table.getColumnModel(); int tableHeight = damagedArea.y + damagedArea.height; int x; if (table.getComponentOrientation().isLeftToRight()) { x = damagedArea.x; for (int column = cMin; column <= cMax; column++) { int w = cm.getColumn(column).getWidth(); x += w; synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1); } } else { x = damagedArea.x; for (int column = cMax; column >= cMin; column--) { int w = cm.getColumn(column).getWidth(); x += w; synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1); } } } }
ViewportBorder(SynthContext context) { this.insets = (Insets) context.getStyle().get(context, "ScrollPane.viewportBorderInsets"); if (this.insets == null) { this.insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; } }
private void paintDraggedArea( SynthContext context, Graphics g, int rMin, int rMax, TableColumn draggedColumn, int distance) { int draggedColumnIndex = viewIndexForColumn(draggedColumn); Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true); Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true); Rectangle vacatedColumnRect = minCell.union(maxCell); // Paint a gray well in place of the moving column. g.setColor(table.getParent().getBackground()); g.fillRect( vacatedColumnRect.x, vacatedColumnRect.y, vacatedColumnRect.width, vacatedColumnRect.height); // Move to the where the cell has been dragged. vacatedColumnRect.x += distance; // Fill the background. g.setColor(context.getStyle().getColor(context, ColorType.BACKGROUND)); g.fillRect( vacatedColumnRect.x, vacatedColumnRect.y, vacatedColumnRect.width, vacatedColumnRect.height); SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils(context); // Paint the vertical grid lines if necessary. if (table.getShowVerticalLines()) { g.setColor(table.getGridColor()); int x1 = vacatedColumnRect.x; int y1 = vacatedColumnRect.y; int x2 = x1 + vacatedColumnRect.width - 1; int y2 = y1 + vacatedColumnRect.height - 1; // Left synthG.drawLine(context, "Table.grid", g, x1 - 1, y1, x1 - 1, y2); // Right synthG.drawLine(context, "Table.grid", g, x2, y1, x2, y2); } for (int row = rMin; row <= rMax; row++) { // Render the cell value Rectangle r = table.getCellRect(row, draggedColumnIndex, false); r.x += distance; paintCell(context, g, r, row, draggedColumnIndex); // Paint the (lower) horizontal grid line if necessary. if (table.getShowHorizontalLines()) { g.setColor(table.getGridColor()); Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true); rcr.x += distance; int x1 = rcr.x; int y1 = rcr.y; int x2 = x1 + rcr.width - 1; int y2 = y1 + rcr.height - 1; synthG.drawLine(context, "Table.grid", g, x1, y2, x2, y2); } } }
/** * Returns the default icon. This should not callback to the JComponent. * * @param b button the icon is associated with * @return default icon */ protected Icon getDefaultIcon(AbstractButton b) { SynthContext context = getContext(b); Icon icon = context.getStyle().getIcon(context, getPropertyPrefix() + "icon"); return icon; }