private Vector createHTMLVector() { Vector htmlViews = new Vector(); int count = tabPane.getTabCount(); if (count > 0) { for (int i = 0; i < count; i++) { String title = tabPane.getTitleAt(i); if (BasicHTML.isHTMLString(title)) { htmlViews.addElement(BasicHTML.createHTMLView(tabPane, title)); } else { htmlViews.addElement(null); } } } return htmlViews; }
/** * Set the error message for the dialog box * * @param errorMessage Message for the error dialog */ private void setErrorMessage(String errorMessage) { if (BasicHTML.isHTMLString(errorMessage)) { this.errorMessage.setContentType("text/html"); } else { this.errorMessage.setContentType("text/plain"); } this.errorMessage.setText(errorMessage); this.errorMessage.setCaretPosition(0); }
/** {@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; }
public void componentAdded(ContainerEvent e) { JTabbedPane tp = (JTabbedPane) e.getContainer(); Component child = e.getChild(); if (child instanceof UIResource) { return; } int index = tp.indexOfComponent(child); String title = tp.getTitleAt(index); boolean isHTML = BasicHTML.isHTMLString(title); if (isHTML) { if (htmlViews == null) { // Initialize vector htmlViews = createHTMLVector(); } else { // Vector already exists View v = BasicHTML.createHTMLView(tp, title); htmlViews.insertElementAt(v, index); } } else { // Not HTML if (htmlViews != null) { // Add placeholder htmlViews.insertElementAt(null, index); } // else nada! } }