|
What this is
Other links
The source code/* * MarginViewportUI.java * * Created on January 20, 2004, 6:35 PM */ package org.openide.explorer.propertysheet; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import javax.swing.JComponent; import javax.swing.JViewport; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ViewportUI; import javax.swing.plaf.basic.BasicViewportUI; /** Viewport UI which will paint a margin if the contained * SheetTable is showing one, so the margin appears to continue * down to the bottom of the component. * * @author Tim Boudreau */ class MarginViewportUI extends ViewportUI implements ComponentListener, ContainerListener { private JViewport viewport; private int lastHeight = -1; private int stringWidth = -1; private int stringHeight = -1; private int ascent = -1; Rectangle scratch = new Rectangle(); /** Creates a new instance of MarginViewportUI */ private MarginViewportUI(JViewport jv) { this.viewport = jv; } /** Uses a single shared instance, as does BasicViewportUI */ public static ComponentUI createUI(JComponent c) { return new MarginViewportUI ((JViewport)c); } public void installUI(JComponent c) { super.installUI(c); //Fetch the "no properties" string - it's not going to change //for the life of the session // noPropsString = NbBundle.getMessage(MarginViewportUI.class, // "CTL_NoProperties"); //NOI18N //Set an appropriate font and color. Only really relevant on OS-X to //keep the font consistent with other NB fonts Color fg = UIManager.getColor ("controlShadow"); //NOI18N if (fg == null) { fg = Color.LIGHT_GRAY; } c.setForeground (fg); Color bg = UIManager.getColor ("window"); //NOI18N if (bg == null) { bg = Color.WHITE; } c.setBackground (bg); Font f = UIManager.getFont ("Tree.font"); //NOI18N if (f == null) { f = UIManager.getFont("controlFont"); //NOI18N } if (f != null) { c.setFont (f); } c.addContainerListener (this); Component[] kids = c.getComponents(); for (int i=0; i < kids.length; i++) { //Should almost always be empty anyway, if not only one component, //but for completeness... kids[i].addComponentListener(this); } } public void uninstallUI (JComponent vp) { JViewport jv = (JViewport) vp; Component[] c = jv.getComponents(); for (int i=0; i < c.length; i++) { c[i].removeComponentListener(this); } jv.removeContainerListener (this); } private String emptyString = "THIS IS A BUG"; //NOI18N public void setEmptyString (String s) { emptyString = s; stringWidth = -1; stringHeight = -1; } Color marginColor = UIManager.getColor("controlShadow"); //NOI18N public void setMarginColor (Color c) { marginColor = c; } private int marginWidth = PropUtils.getMarginWidth(); public void setMarginWidth (int margin) { this.marginWidth = margin; } private boolean marginPainted = false; public void setMarginPainted (boolean val) { if (marginPainted != val) { marginPainted = val; viewport.repaint(); } } Dimension lastKnownSize = new Dimension(); /** Overridden to draw "no properties" if necessary */ public void paint(Graphics g, JComponent c) { Component view = ((JViewport) c).getView(); if (view != null) { lastKnownSize = view.getSize(); } if (stringWidth == -1) { calcStringSizes (c.getFont(), g); } //Update will have set paintNoProps to the correct value if (shouldPaintEmptyMessage()) { //We need to paint centered " |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.