Java Code Examples for javax.swing.text.View#setSize()
The following examples show how to use
javax.swing.text.View#setSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
static Rectangle2D modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException { Document doc = tc.getDocument(); if (doc instanceof AbstractDocument) { ((AbstractDocument)doc).readLock(); } try { Rectangle alloc = getVisibleEditorRect(tc); if (alloc != null) { View rootView = tc.getUI().getRootView(tc); rootView.setSize(alloc.width, alloc.height); Shape s = rootView.modelToView(pos, alloc, bias); if (s != null) { return s.getBounds2D(); } } } finally { if (doc instanceof AbstractDocument) { ((AbstractDocument)doc).readUnlock(); } } return null; }
Example 2
Source File: Utilities.java From netbeans with Apache License 2.0 | 6 votes |
static int viewToModel(JTextComponent tc, double x, double y, Position.Bias[] biasReturn) { int offs = -1; Document doc = tc.getDocument(); if (doc instanceof AbstractDocument) { ((AbstractDocument)doc).readLock(); } try { Rectangle alloc = getVisibleEditorRect(tc); if (alloc != null) { View rootView = tc.getUI().getRootView(tc); View documentView = rootView.getView(0); if (documentView instanceof EditorView) { documentView.setSize(alloc.width, alloc.height); offs = ((EditorView) documentView).viewToModelChecked(x, y, alloc, biasReturn); } else { rootView.setSize(alloc.width, alloc.height); offs = rootView.viewToModel((float) x, (float) y, alloc, biasReturn); } } } finally { if (doc instanceof AbstractDocument) { ((AbstractDocument)doc).readUnlock(); } } return offs; }
Example 3
Source File: JXLabel.java From pgptool with GNU General Public License v3.0 | 6 votes |
@Override public void reshape(int x, int y, int w, int h) { int oldH = getHeight(); super.reshape(x, y, w, h); if (!isLineWrap()) { return; } if (oldH == 0) { return; } if (w > getVisibleRect().width) { w = getVisibleRect().width; } View view = (View) getClientProperty(BasicHTML.propertyKey); if (view != null && view instanceof Renderer) { view.setSize(w - occupiedWidth, h); } }
Example 4
Source File: HelpTooltip.java From consulo with Apache License 2.0 | 6 votes |
void setSizeForWidth(float width) { if (width > MAX_WIDTH.get()) { View v = (View)getClientProperty(BasicHTML.propertyKey); if (v != null) { width = 0.0f; for (View row : getRows(v)) { float rWidth = row.getPreferredSpan(View.X_AXIS); if (width < rWidth) { width = rWidth; } } v.setSize(width, v.getPreferredSpan(View.Y_AXIS)); } } }
Example 5
Source File: InfoPanel.java From ghidra with Apache License 2.0 | 5 votes |
private Component buildDistributionLabel() { String content = distributionInfo; // Use java native JLabel and let it auto-detect html content JLabel resizer = new JLabel(content); final int desiredTextViewWidth = imageWidth - (MARGIN * 2); // If the splash.txt file contains non-HTML text, view is null View view = (View) resizer.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey); if (view == null) { // must not be HTML content in the splash screen text (this shouldn't // happen, but let's just protect against this anyway). JLabel label = new GDLabel(content) { @Override public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); preferredSize.width = desiredTextViewWidth; return preferredSize; } }; return label; } view.setSize(desiredTextViewWidth, 0); float w = view.getPreferredSpan(View.X_AXIS); float h = view.getPreferredSpan(View.Y_AXIS); JLabel distribLabel = new GHtmlLabel(content); distribLabel.setPreferredSize(new Dimension((int) Math.ceil(w), (int) Math.ceil(h + 10))); return distribLabel; }
Example 6
Source File: ImageView.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Sets the size of the view. This should cause * layout of the view if it has any layout duties. * * @param width the width >= 0 * @param height the height >= 0 */ public void setSize(float width, float height) { sync(); if (getImage() == null) { View view = getAltView(); if (view != null) { view.setSize(Math.max(0f, width - (float)(DEFAULT_WIDTH + leftInset + rightInset)), Math.max(0f, height - (float)(topInset + bottomInset))); } } }
Example 7
Source File: ImageView.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Sets the size of the view. This should cause * layout of the view if it has any layout duties. * * @param width the width >= 0 * @param height the height >= 0 */ public void setSize(float width, float height) { sync(); if (getImage() == null) { View view = getAltView(); if (view != null) { view.setSize(Math.max(0f, width - (float)(DEFAULT_WIDTH + leftInset + rightInset)), Math.max(0f, height - (float)(topInset + bottomInset))); } } }
Example 8
Source File: SeaGlassTextFieldUI.java From seaglass with Apache License 2.0 | 5 votes |
/** * @see javax.swing.plaf.basic.BasicTextUI#getPreferredSize(javax.swing.JComponent) */ public Dimension getPreferredSize(JComponent c) { // The following code has been derived from BasicTextUI. Document doc = ((JTextComponent) c).getDocument(); Insets i = c.getInsets(); Dimension d = c.getSize(); View rootView = getRootView((JTextComponent) c); if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).readLock(); } try { if ((d.width > (i.left + i.right)) && (d.height > (i.top + i.bottom))) { rootView.setSize(d.width - i.left - i.right, d.height - i.top - i.bottom); } else if (d.width == 0 && d.height == 0) { // Probably haven't been layed out yet, force some sort of // initial sizing. rootView.setSize(Integer.MAX_VALUE, Integer.MAX_VALUE); } d.width = (int) Math.min((long) rootView.getPreferredSpan(View.X_AXIS) + (long) i.left + (long) i.right, Integer.MAX_VALUE); d.height = (int) Math.min((long) rootView.getPreferredSpan(View.Y_AXIS) + (long) i.top + (long) i.bottom, Integer.MAX_VALUE); } finally { if (doc instanceof AbstractDocument) { ((AbstractDocument) doc).readUnlock(); } } // Fix: The preferred width is always two pixels too small on a Mac. d.width += 2; // We'd like our heights to be odd by default. if ((d.height & 1) == 0) { d.height--; } return d; }
Example 9
Source File: HTMLTableHeader.java From ramus with GNU General Public License v3.0 | 3 votes |
public static java.awt.Dimension getPreferredSize(String text, boolean width, int prefSize) { JLabel resizer = new JLabel(text); View view = (View) resizer .getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey); view.setSize(width ? prefSize : 0, width ? 0 : prefSize); float w = view.getPreferredSpan(View.X_AXIS); float h = view.getPreferredSpan(View.Y_AXIS) + 2; return new java.awt.Dimension((int) Math.ceil(w), (int) Math.ceil(h)); }