Example usage for javax.swing.text View X_AXIS

List of usage examples for javax.swing.text View X_AXIS

Introduction

In this page you can find the example usage for javax.swing.text View X_AXIS.

Prototype

int X_AXIS

To view the source code for javax.swing.text View X_AXIS.

Click Source Link

Document

Axis for format/break operations.

Usage

From source file:Main.java

public float getMinimumSpan(int axis) {
    switch (axis) {
    case View.X_AXIS:
        return 0;
    case View.Y_AXIS:
        return super.getMinimumSpan(axis);
    default://from   w  w w . j  a va  2s.c o m
        throw new IllegalArgumentException("Invalid axis: " + axis);
    }
}

From source file:com.hexidec.ekit.component.RelativeImageView.java

/** Determines the preferred span for this view along an axis.
  *//from   w  w w.j  a v a 2  s  .  c  om
  * @param axis may be either X_AXIS or Y_AXIS
  * @returns  the span the view would like to be rendered into.
  *           Typically the view is told to render into the span
  *           that is returned, although there is no guarantee.
  *           The parent may choose to resize or break the view.
  */
public float getPreferredSpan(int axis) {
    int extra = 2 * (getBorder() + getSpace(axis));
    switch (axis) {
    case View.X_AXIS:
        return fWidth + extra;
    case View.Y_AXIS:
        return fHeight + extra;
    default:
        throw new IllegalArgumentException("Invalid axis in getPreferredSpan() : " + axis);
    }
}

From source file:org.pmedv.core.components.RelativeImageView.java

/**
 * Determines the preferred span for this view along an axis.
 * /*from  www .  jav a 2s  . c  o m*/
 * @param axis
 *            may be either X_AXIS or Y_AXIS
 * @return the span the view would like to be rendered into. Typically the
 *         view is told to render into the span that is returned, although
 *         there is no guarantee. The parent may choose to resize or break
 *         the view.
 */
public float getPreferredSpan(int axis) {

    int extra = 2 * (getBorder() + getSpace(axis));
    switch (axis) {
    case View.X_AXIS:
        return fWidth + extra;
    case View.Y_AXIS:
        return fHeight + extra;
    default:
        throw new IllegalArgumentException("Invalid axis in getPreferredSpan() : " + axis);
    }
}

From source file:tufts.vue.RichTextBox.java

public Dimension getPreferredSize() {
    Dimension s = null;//www. j av  a 2s.  c  o  m
    //   Dimension s = super.getPreferredSize();

    Dimension minS = getMinimumSize();

    //System.out.println(javax.swing.SwingUtilities.getLocalBounds(this));
    //if (TestDebug||DEBUG.TEXT) out("getPrefer", s);

    // System.out.println("GetPrefSize : " +  mBounds.width + " "+ s.width);
    //    System.out.println("Required Lines : " + s.width/mBounds.width);
    Caret c = this.getCaret();
    Point position = c.getMagicCaretPosition();
    //    if (position != null)
    //       System.out.println("magic caret : " + position.getX());

    //HTMLDocument builds a hierarchical Element structure where each Element
    //represents a structural block of HTML, and not just a line of text. so I'm not sure
    //how to figure out what line you're on.

    Dimension min = new Dimension();
    final Dimension text = getMinimumSize();
    min.width = text.width;

    int EdgePadY = 0; // Was 3 in VUE 1.5
    int LabelPadLeft = 8; // Was 6 in VUE 1.5; fixed

    //System.out.println("Text.height : " + text.height);
    // *** set icon Y position in all cases to a centered vertical
    // position, but never such that baseline is below bottom of
    // first icon -- this is tricky tho, as first icon can move
    // down a bit to be centered with the label!

    min.width += LabelPadLeft;

    min.width = Math.max(min.width, minS.width);
    /*
    System.out.println("Min.Width =" + min.width);
    System.out.println("MinS.Width =" + minS.width);
    System.out.println("S.Width =" + s.width);
    System.out.println("MBounds.Width = " + mBounds.width);
    System.out.println("GetSize.Width = " + getSize().width);
    System.out.println("Bounds : " + this.getBounds().width);
    System.out.println("LWC width : " + lwc.width);
    System.out.println("LWC bounds : " + lwc.getBounds().width);
    System.out.println("LWC layoutbounds : " + lwc.getLayoutBounds().width);
    System.out.println("LWC min size : " + lwc.getMinimumSize().width);
    System.out.println("Get super width : " + super.getWidth());
    System.out.println("Selection Eend : " + this.getSelectionEnd());
    System.out.println("Selection Start : " +       this.getSelectionStart());
    System.out.println("Bounds Box Width : " +this.getBoxBounds().getBounds().width);      
    System.out.println("Visible Rect : " +this.getVisibleRect().width);*/
    //**      Rectangle p2 = null;
    //if (this.getGraphics() != null)
    //{
    //   System.out.println("GRAPHICS : " + this.getGraphics().toString());
    //   if (this.getGraphics().getClipBounds() != null)
    //   System.out.println("GRAPHICS : " + this.getGraphics().getClipBounds().width);
    //   this.getPreferredScrollableViewportSize().width
    //   
    //   

    View ui = getUI().getRootView(this);
    ui = ui.createFragment(this.getSelectionStart(), this.getSelectionEnd());
    //System.out.println("min span: " + ui.getMinimumSpan(View.X_AXIS));

    //**        int start = getSelectionStart();
    //**        int end = getSelectionEnd();
    //**       float f = ui.getPreferredSpan(View.X_AXIS);
    //System.out.println("Preferred span : " + f);

    //**       f = ui.getPreferredSpan(View.Y_AXIS);
    //System.out.println("Preferred span y : " + f);
    //**       f = ui.getPreferredSpan(View.X_AXIS);
    //System.out.println("{referred span X : " + f);
    //ui.breakView(View.X_AXIS, offset, pos, len)
    //((HTMLEditorKit)this.getEditorKit()).getViewFactory().create(this.getDocument().getDefaultRootElement()).
    //  System.out.println("BREAK WEIGHT : " + ui.getBreakWeight(View.X_AXIS, this.getCaretPosition(), this.getSelectionEnd()));
    //  System.out.println("RESIZE WEIGHT : " + ui.getResizeWeight(View.X_AXIS));
    //  System.out.println("RESIZE WEIGHTY : " + ui.getResizeWeight(View.Y_AXIS));
    //**       float align = ui.getAlignment(View.X_AXIS);
    //  System.out.println("align span : " + align);

    //**      try {
    //**         p2 = this.modelToView(this.getSelectionEnd());
    //**         
    //**      } catch (BadLocationException e) {         
    //**         //Nothing we can do really.
    //**      }
    //**      //if (p2 != null)
    //**         //System.out.println("Selection end rect : " + p2.x);
    //**      
    if (mBounds.width > 0) {
        //**           if (p2 != null && p2.x > mBounds.width)
        //**              mBounds.width = p2.x;

        //int height = 48;
        /*if (getFont() != null &&this.getFontMetrics(getFont())!=null)
        {
        System.out.println("A:"+this.getFontMetrics(getFont()).getMaxAscent());
        System.out.println("B:"+this.getFontMetrics(getFont()).getMaxDescent());
        }*/

        int height = super.getPreferredSize().height;//s.height;//Math.max(s.height, 48);

        Style style = ((HTMLDocument) getDocument()).getStyleSheet().getStyle("body");
        Object a = style.getAttribute(javax.swing.text.html.CSS.Attribute.FONT_SIZE);

        if (a != null) {
            if (DEBUG.TEXT)
                out("got style");
            int diff = 0;
            Integer i = new Integer(a.toString());
            diff = i.intValue();
            //minS.height = minS.height - diff;
            if (VUE.getActiveViewer() != null) {
                java.awt.Container parent = getParent();
                double zoom = 1.0;
                if (parent != null)
                    zoom = ((MapViewer) parent).getZoomFactor();
                else {
                    //parent is null during duplicate.
                    zoom = VUE.getActiveViewer().getZoomFactor();
                }
                zoom *= lwc.getMapScale();

                diff *= zoom;
            }
            height = height - diff;
        }

        if (position != null) {

            float minSpan = ui.getMinimumSpan(View.X_AXIS);
            float mins2 = Math.max(minSpan, (float) position.getX());
            s = new Dimension((int) (mBounds.width > mins2 ? mBounds.width : mins2), (int) height);
        } else {
            float minSpan = ui.getMinimumSpan(View.X_AXIS);
            s = new Dimension((int) (mBounds.width > minSpan ? mBounds.width : minSpan), (int) height);
        }
        //float widthRatio = ((float)s.width /(float)lwc.width);
        //   float heightRatio =((float)s.height/(float)lwc.height);
        /*    if ((widthRatio > 0) && (heightRatio > 0) && (widthRatio != heightRatio))
              {
                
        s.height = (int)(lwc.height * widthRatio);
              //   System.out.print("NEW SHEIGHT : " + s.height);
              //   prevDim = s;
        //            
              }
            System.out.println("width ratio : " + widthRatio);
              System.out.println("height ratio : " + heightRatio);
           */
        /*if (this.getGraphics() != null)
         System.out.println("FONT HEIGHT : " +this.getGraphics().getFontMetrics().getMaxAscent());
         System.out.println("===================================");
         System.out.println("super pref height : " + s.height);
         System.out.println("Min Vertical Span : " +ui.getMinimumSpan(View.Y_AXIS));
         System.out.println("MBounds height : " + mBounds.height);
         System.out.println("super pref height : " + s.height);
         System.out.println("Min Vertical Span : " +ui.getMinimumSpan(View.Y_AXIS));
         System.out.println("MBounds height : " + mBounds.height);
         System.out.println("Mins height : " + min.height);
         System.out.println("Bounds Y : " + this.getBounds().y);
         System.out.println("Bounds height :" +this.getBounds().height);
         System.out.println("Bounds2D Y : " +this.getBoxBounds().getY());
         System.out.println("Bounds2D height : " +this.getBoxBounds().getHeight());
         if (this.getCaret().getMagicCaretPosition() != null)
         System.out.println("Cursor : " + this.getCaret().getMagicCaretPosition().toString());
         //this.getCaret().getMagicCaretPosition().
         System.out.println("===================================");*/
        /*if (position != null)
        {
           System.out.println("Y Pos : " + position.getY());
        try {
            Rectangle r = modelToView(this.getCaretPosition());
            System.out.println("model pos : " + r.y);
            System.out.println("Model height : " + r.height);
         } catch (BadLocationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
        }*/

    }
    // s.width = (int)(s.width * VUE.getActiveViewer().getZoomFactor());
    //   s.height = (int)(s.height * VUE.getActiveViewer().getZoomFactor());
    //   s.height=(int) this.getBoxBounds().getHeight();

    if (this.getBoxBounds() != null && s.height < this.getBoxBounds().getHeight()) {
        s.height = (int) this.getBoxBounds().getHeight();

    }

    return s;
}