public Insets getInsets(Insets in) { in = super.getInsets(in); in.left += 2; return in; }
public Insets getInsets() { Insets insets = super.getInsets(); if (painting) { if (rotation == ROTATE_LEFT) { int temp = insets.bottom; insets.bottom = insets.left; insets.left = insets.top; insets.top = insets.right; insets.right = temp; } else if (rotation == ROTATE_RIGHT) { int temp = insets.bottom; insets.bottom = insets.right; insets.right = insets.top; insets.top = insets.left; insets.left = temp; } } return insets; }
public Insets getInsets(Insets insets) { insets = super.getInsets(insets); if (painting) { if (rotation == ROTATE_LEFT) { int temp = insets.bottom; insets.bottom = insets.left; insets.left = insets.top; insets.top = insets.right; insets.right = temp; } else if (rotation == ROTATE_RIGHT) { int temp = insets.bottom; insets.bottom = insets.right; insets.right = insets.top; insets.top = insets.left; insets.left = temp; } } return insets; }
/** * Returns the available height to paint text on. This is the height of the * passed component with insets subtracted. * * @param l * a component * @return the available height */ protected int getAvailableHeight(final JLabel l) { l.getInsets(paintViewInsets); return l.getHeight() - paintViewInsets.top - paintViewInsets.bottom; }
/** * The preferred height of the label is the height of the lines with added * top and bottom insets. * * @param label * the label * @return the preferred height of the wrapped lines. */ protected int getPreferredHeight(final JLabel label) { final int numOfLines = getTextLines(label).size(); final Insets insets = label.getInsets(paintViewInsets); return numOfLines * metrics.getHeight() + insets.top + insets.bottom; }
String text = "Hear no evil"; JLabel label = new JLabel(text); System.out.println( label.getPreferredSize() ); System.out.println( label.getInsets() ); JCheckBox checkBox = new JCheckBox(text); System.out.println( checkBox.getPreferredSize() ); System.out.println( checkBox.getInsets() );
private Dimension getClientSize() { Insets insets = displayer.getInsets(); Dimension size = displayer.getSize().equals(ZERO_SIZE) ? displayer.getPreferredSize() : displayer.getSize(); return new Dimension(size.width - insets.left - insets.right, size.height - insets.top - insets.bottom); }
/** * Calculate the paint rectangles for the icon and text for the passed * label. * * @param l * a label * @param fm * the font metrics to use, or <code>null</code> to get the font * metrics from the label * @param width * label width * @param height * label height */ protected void updateLayout(final JLabel l, FontMetrics fm, final int width, final int height) { if (fm == null) { fm = l.getFontMetrics(l.getFont()); } metrics = fm; final String text = l.getText(); final Icon icon = l.getIcon(); final Insets insets = l.getInsets(paintViewInsets); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; layoutCL(l, fm, text, icon, paintViewR, paintIconR, paintTextR); }
/** * {@inheritDoc} <p> * * Paints a diagonal cross over the text if the comp is of type JLabel, * does nothing otherwise. */ @Override protected void doPaint(Graphics2D g, JComponent comp, int width, int height) { if (!(comp instanceof JLabel)) return; JLabel label = (JLabel) comp; Insets insets = label.getInsets(insetss); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; SwingUtilities.layoutCompoundLabel(label, label.getFontMetrics(label.getFont()), label.getText(), null, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap()); doPaint(g, paintTextR); }
@Override public void ancestorResized(HierarchyEvent e) { if (header == e.getComponent()) { View v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); // view might get lost on LAF change ... if (v == null) { descriptionPane.putClientProperty(BasicHTML.propertyKey, MultiLineSupport.createView(descriptionPane)); v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); } if (v != null) { Container tla = header.getTopLevelAncestor(); if (tla == null) { tla = header.getParent(); while (tla.getParent() != null) { tla = tla.getParent(); } } int h = Math.max(descriptionPane.getHeight(), tla.getHeight()); int w = Math.min(tla.getWidth(), header.getParent().getWidth()); // 35 = description pane insets, TODO: obtain dynamically w -= 35 + header.getInsets().left + header.getInsets().right + descriptionPane.getInsets().left + descriptionPane.getInsets().right + imagePanel.getInsets().left + imagePanel.getInsets().right + imagePanel.getWidth() + descriptionPane.getBounds().x; v.setSize(w, h); descriptionPane.setSize(w, (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS))); } } }}; header.addPropertyChangeListener(propListener);
@Override public void ancestorResized(HierarchyEvent e) { if (header == e.getComponent()) { View v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); // view might get lost on LAF change ... if (v == null) { descriptionPane.putClientProperty(BasicHTML.propertyKey, MultiLineSupport.createView(descriptionPane)); v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); } if (v != null) { Container tla = header.getTopLevelAncestor(); if (tla == null) { tla = header.getParent(); while (tla.getParent() != null) { tla = tla.getParent(); } } int h = Math.max(descriptionPane.getHeight(), tla.getHeight()); int w = Math.min(tla.getWidth(), header.getParent().getWidth()); // 35 = description pane insets, TODO: obtain dynamically w -= 35 + header.getInsets().left + header.getInsets().right + descriptionPane.getInsets().left + descriptionPane.getInsets().right + imagePanel.getInsets().left + imagePanel.getInsets().right + imagePanel.getWidth() + descriptionPane.getBounds().x; v.setSize(w, h); descriptionPane.setSize(w, (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS))); } } }}; header.addPropertyChangeListener(propListener);
@Override public void ancestorResized(HierarchyEvent e) { if (header == e.getComponent()) { View v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); // view might get lost on LAF change ... if (v == null) { descriptionPane.putClientProperty(BasicHTML.propertyKey, MultiLineSupport.createView(descriptionPane)); v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); } if (v != null) { Container tla = header.getTopLevelAncestor(); if (tla == null) { tla = header.getParent(); while (tla.getParent() != null) { tla = tla.getParent(); } } int h = Math.max(descriptionPane.getHeight(), tla.getHeight()); int w = Math.min(tla.getWidth(), header.getParent().getWidth()); // 35 = description pane insets, TODO: obtain dynamically w -= 35 + header.getInsets().left + header.getInsets().right + descriptionPane.getInsets().left + descriptionPane.getInsets().right + imagePanel.getInsets().left + imagePanel.getInsets().right + imagePanel.getWidth() + descriptionPane.getBounds().x; v.setSize(w, h); descriptionPane.setSize(w, (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS))); } } }}; header.addPropertyChangeListener(propListener);
@Override public void ancestorResized(HierarchyEvent e) { if (header == e.getComponent()) { View v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); // view might get lost on LAF change ... if (v == null) { descriptionPane.putClientProperty(BasicHTML.propertyKey, descriptionPane.getMultiLineSupport().createView(descriptionPane)); v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); } if (v != null) { Container tla = header.getTopLevelAncestor(); if (tla == null) { tla = header.getParent(); while (tla.getParent() != null) { tla = tla.getParent(); } } int h = Math.max(descriptionPane.getHeight(), tla.getHeight()); int w = Math.min(tla.getWidth(), header.getParent().getWidth()); // 35 = description pane insets, TODO: obtain dynamically w -= 35 + header.getInsets().left + header.getInsets().right + descriptionPane.getInsets().left + descriptionPane.getInsets().right + imagePanel.getInsets().left + imagePanel.getInsets().right + imagePanel.getWidth() + descriptionPane.getBounds().x; v.setSize(w, h); descriptionPane.setSize(w, (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS))); } } }}; header.addPropertyChangeListener(propListener);
/** * {@inheritDoc} <p> * * Paints a diagonal cross over the text if the comp is of type JLabel, * does nothing otherwise. */ @Override protected void doPaint(Graphics2D g, JComponent comp, int width, int height) { if (!(comp instanceof JLabel)) return; JLabel label = (JLabel) comp; Insets insets = label.getInsets(insetss); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; SwingUtilities.layoutCompoundLabel(label, label.getFontMetrics(label.getFont()), label.getText(), null, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap()); doPaint(g, paintTextR); }
@Override public void ancestorResized(HierarchyEvent e) { if (header == e.getComponent()) { View v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); // view might get lost on LAF change ... if (v == null) { descriptionPane.putClientProperty(BasicHTML.propertyKey, MultiLineSupport.createView(descriptionPane)); v = (View) descriptionPane.getClientProperty(BasicHTML.propertyKey); } if (v != null) { Container tla = header.getTopLevelAncestor(); if (tla == null) { tla = header.getParent(); while (tla.getParent() != null) { tla = tla.getParent(); } } int h = Math.max(descriptionPane.getHeight(), tla.getHeight()); int w = Math.min(tla.getWidth(), header.getParent().getWidth()); // 35 = description pane insets, TODO: obtain dynamically w -= 35 + header.getInsets().left + header.getInsets().right + descriptionPane.getInsets().left + descriptionPane.getInsets().right + imagePanel.getInsets().left + imagePanel.getInsets().right + imagePanel.getWidth() + descriptionPane.getBounds().x; v.setSize(w, h); descriptionPane.setSize(w, (int) Math.ceil(v.getPreferredSpan(View.Y_AXIS))); } } }}; header.addPropertyChangeListener(propListener);
/** * {@inheritDoc} <p> * * Paints a diagonal cross over the text if the comp is of type JLabel, * does nothing otherwise. */ @Override protected void doPaint(Graphics2D g, JComponent comp, int width, int height) { if (!(comp instanceof JLabel)) return; JLabel label = (JLabel) comp; Insets insets = label.getInsets(insetss); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; SwingUtilities.layoutCompoundLabel(label, label.getFontMetrics(label.getFont()), label.getText(), null, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap()); doPaint(g, paintTextR); }
/** * {@inheritDoc} <p> * * Paints a diagonal cross over the text if the comp is of type JLabel, * does nothing otherwise. */ @Override protected void doPaint(Graphics2D g, JComponent comp, int width, int height) { if (!(comp instanceof JLabel)) return; JLabel label = (JLabel) comp; Insets insets = label.getInsets(insetss); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; SwingUtilities.layoutCompoundLabel(label, label.getFontMetrics(label.getFont()), label.getText(), null, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap()); doPaint(g, paintTextR); }
/** * {@inheritDoc} <p> * * Paints a diagonal cross over the text if the comp is of type JLabel, * does nothing otherwise. */ @Override protected void doPaint(Graphics2D g, JComponent comp, int width, int height) { if (!(comp instanceof JLabel)) return; JLabel label = (JLabel) comp; Insets insets = label.getInsets(insetss); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = width - (insets.left + insets.right); paintViewR.height = height - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; SwingUtilities.layoutCompoundLabel(label, label.getFontMetrics(label.getFont()), label.getText(), null, label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap()); doPaint(g, paintTextR); }
Insets insets = label.getInsets(paintViewInsets); paintViewR.x = insets.left; paintViewR.y = insets.top;