< prev index next >

src/java.desktop/share/classes/javax/swing/text/ComponentView.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  68  * @author Timothy Prinzing
  69  */
  70 public class ComponentView extends View  {
  71 
  72     /**
  73      * Creates a new ComponentView object.
  74      *
  75      * @param elem the element to decorate
  76      */
  77     public ComponentView(Element elem) {
  78         super(elem);
  79     }
  80 
  81     /**
  82      * Create the component that is associated with
  83      * this view.  This will be called when it has
  84      * been determined that a new component is needed.
  85      * This would result from a call to setParent or
  86      * as a result of being notified that attributes
  87      * have changed.


  88      */
  89     protected Component createComponent() {
  90         AttributeSet attr = getElement().getAttributes();
  91         Component comp = StyleConstants.getComponent(attr);
  92         return comp;
  93     }
  94 
  95     /**
  96      * Fetch the component associated with the view.

  97      */
  98     public final Component getComponent() {
  99         return createdC;
 100     }
 101 
 102     // --- View methods ---------------------------------------------
 103 
 104     /**
 105      * The real paint behavior occurs naturally from the association
 106      * that the component has with its parent container (the same
 107      * container hosting this view).  This is implemented to do nothing.
 108      *
 109      * @param g the graphics context
 110      * @param a the shape
 111      * @see View#paint
 112      */
 113     public void paint(Graphics g, Shape a) {
 114         if (c != null) {
 115             Rectangle alloc = (a instanceof Rectangle) ?
 116                 (Rectangle) a : a.getBounds();


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  68  * @author Timothy Prinzing
  69  */
  70 public class ComponentView extends View  {
  71 
  72     /**
  73      * Creates a new ComponentView object.
  74      *
  75      * @param elem the element to decorate
  76      */
  77     public ComponentView(Element elem) {
  78         super(elem);
  79     }
  80 
  81     /**
  82      * Create the component that is associated with
  83      * this view.  This will be called when it has
  84      * been determined that a new component is needed.
  85      * This would result from a call to setParent or
  86      * as a result of being notified that attributes
  87      * have changed.
  88      * @return the component that is associated with
  89      * this view
  90      */
  91     protected Component createComponent() {
  92         AttributeSet attr = getElement().getAttributes();
  93         Component comp = StyleConstants.getComponent(attr);
  94         return comp;
  95     }
  96 
  97     /**
  98      * Fetch the component associated with the view.
  99      * @return the component associated with the view
 100      */
 101     public final Component getComponent() {
 102         return createdC;
 103     }
 104 
 105     // --- View methods ---------------------------------------------
 106 
 107     /**
 108      * The real paint behavior occurs naturally from the association
 109      * that the component has with its parent container (the same
 110      * container hosting this view).  This is implemented to do nothing.
 111      *
 112      * @param g the graphics context
 113      * @param a the shape
 114      * @see View#paint
 115      */
 116     public void paint(Graphics g, Shape a) {
 117         if (c != null) {
 118             Rectangle alloc = (a instanceof Rectangle) ?
 119                 (Rectangle) a : a.getBounds();


< prev index next >