Example usage for java.awt Dimension getWidth

List of usage examples for java.awt Dimension getWidth

Introduction

In this page you can find the example usage for java.awt Dimension getWidth.

Prototype

public double getWidth() 

Source Link

Usage

From source file:ome.services.ThumbnailBean.java

@RolesAllowed("user")
@Transactional(readOnly = false)/*from  w  w w.  j  ava 2 s  .  c om*/
public Map<Long, byte[]> getThumbnailByLongestSideSet(Integer size, Set<Long> pixelsIds) {
    // Set defaults and sanity check thumbnail sizes
    Dimension checkedDimensions = sanityCheckThumbnailSizes(size, size);
    size = (int) checkedDimensions.getWidth();

    // Prepare our thumbnail context
    newContext();
    ctx.loadAndPrepareRenderingSettings(pixelsIds);
    ctx.createAndPrepareMissingRenderingSettings(pixelsIds);
    ctx.loadAndPrepareMetadata(pixelsIds, size);

    return retrieveThumbnailSet(pixelsIds);
}

From source file:org.apache.fop.render.pcl.PCLImageHandlerGraphics2D.java

/** {@inheritDoc} */
public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
    PCLRenderingContext pclContext = (PCLRenderingContext) context;
    ImageGraphics2D imageG2D = (ImageGraphics2D) image;
    Dimension imageDim = imageG2D.getSize().getDimensionMpt();
    PCLGenerator gen = pclContext.getPCLGenerator();

    Point2D transPoint = pclContext.transformedPoint(pos.x, pos.y);
    gen.setCursorPos(transPoint.getX(), transPoint.getY());

    boolean painted = false;
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution());
    tempGen.setDitheringQuality(gen.getDitheringQuality());
    try {/*from  w  w  w.  j av  a2 s.c  om*/
        GraphicContext ctx = (GraphicContext) pclContext.getGraphicContext().clone();

        AffineTransform prepareHPGL2 = new AffineTransform();
        prepareHPGL2.scale(0.001, 0.001);
        ctx.setTransform(prepareHPGL2);

        PCLGraphics2D graphics = new PCLGraphics2D(tempGen);
        graphics.setGraphicContext(ctx);
        graphics.setClippingDisabled(false /*pclContext.isClippingDisabled()*/);
        Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imageDim.getWidth(), imageDim.getHeight());
        imageG2D.getGraphics2DImagePainter().paint(graphics, area);

        //If we arrive here, the graphic is natively paintable, so write the graphic
        gen.writeCommand(
                "*c" + gen.formatDouble4(pos.width / 100f) + "x" + gen.formatDouble4(pos.height / 100f) + "Y");
        gen.writeCommand("*c0T");
        gen.enterHPGL2Mode(false);
        gen.writeText("\nIN;");
        gen.writeText("SP1;");
        //One Plotter unit is 0.025mm!
        double scale = imageDim.getWidth() / UnitConv.mm2pt(imageDim.getWidth() * 0.025);
        gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;");
        gen.writeText("IR0,100,0,100;");
        gen.writeText("PU;PA0,0;\n");
        baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream
        gen.writeText("\n");

        gen.enterPCLMode(false);
        painted = true;
    } catch (UnsupportedOperationException uoe) {
        log.debug(
                "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage());
    }

    if (!painted) {
        //Fallback solution: Paint to a BufferedImage
        FOUserAgent ua = context.getUserAgent();
        ImageManager imageManager = ua.getFactory().getImageManager();
        ImageRendered imgRend;
        try {
            imgRend = (ImageRendered) imageManager.convertImage(imageG2D,
                    new ImageFlavor[] { ImageFlavor.RENDERED_IMAGE }/*, hints*/);
        } catch (ImageException e) {
            throw new IOException("Image conversion error while converting the image to a bitmap"
                    + " as a fallback measure: " + e.getMessage());
        }

        gen.paintBitmap(imgRend.getRenderedImage(), new Dimension(pos.width, pos.height),
                pclContext.isSourceTransparencyEnabled());
    }
}

From source file:metdemo.Finance.SHNetworks.java

/**
 * This method does../*w ww.jav  a  2s .c o m*/
 *
 */
protected void moveVertices() {

    // first, organize the vertices by SocialScore Level (5 different
    // stages)
    HashMap<Integer, ArrayList<VIPVertex>> levels = stepDivide(SHNetworks.STRAIGHT_SCALE);

    // next, place the vertices according to their echelon
    Iterator levelIter = levels.keySet().iterator();
    while (levelIter.hasNext()) {
        // first, get critical objects/information for the current level
        Integer level = (Integer) levelIter.next();
        ArrayList<VIPVertex> verts = levels.get(level);
        int numVerts = verts.size();

        // next, get the dimension attributes of the current window
        Dimension winSize = m_layout.getCurrentSize();
        double winHeight = winSize.getHeight();
        double winWidth = winSize.getWidth();

        // then, place each of the vertices according window/level size
        double curY = (winHeight / 6) * level + 20;
        double xInc = winWidth / (numVerts + 1);
        double curX = xInc;
        Iterator vertIter = verts.iterator();
        while (vertIter.hasNext()) {
            VIPVertex vert = (VIPVertex) vertIter.next();
            m_layout.forceMove(vert, curX, curY);
            curX += xInc;
        }
    }
}

From source file:ome.services.ThumbnailBean.java

/** Actually does the work specified by {@link getThumbnailByLongestSideDirect()}.*/
private byte[] _getThumbnailByLongestSideDirect(Integer size, Integer theZ, Integer theT) {
    // Sanity check thumbnail sizes
    Dimension dimensions = sanityCheckThumbnailSizes(size, size);

    dimensions = ctx.calculateXYWidths(pixels, (int) dimensions.getWidth());
    return retrieveThumbnailDirect((int) dimensions.getWidth(), (int) dimensions.getHeight(), theZ, theT);
}

From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java

private BufferedImage mergeRows(Queue<BufferedImage> legendsQueue) {
    // I am doing a straight cast since I know that I built this
    // dimension object by using the widths and heights of the various
    // bufferedimages for the various bkgColor map entries.
    final Dimension finalDimension = new Dimension();
    final int numRows = legendsQueue.size();
    finalDimension.setSize(Math.max(footerW, colorW + ruleW + labelW) + 2 * dx + 2 * margin,
            rowH * numRows + 2 * margin + (numRows - 1) * dy);

    final int totalWidth = (int) finalDimension.getWidth();
    final int totalHeight = (int) finalDimension.getHeight();
    BufferedImage finalLegend = ImageUtils.createImage(totalWidth, totalHeight, (IndexColorModel) null,
            transparent);/*ww  w  .ja  va2s  .c o m*/

    /*
     * For RAMP type, only HORIZONTAL or VERTICAL condition is valid
     */
    if (colorMapType == ColorMapType.RAMP) {

        final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
        Graphics2D finalGraphics = ImageUtils.prepareTransparency(transparent, backgroundColor, finalLegend,
                hintsMap);
        hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        finalGraphics.setRenderingHints(hintsMap);

        int topOfRow = (int) (margin + 0.5);
        for (int i = 0; i < numRows; i++) {
            final BufferedImage img = legendsQueue.remove();

            // draw the image
            finalGraphics.drawImage(img, (int) (margin + 0.5), topOfRow, null);
            topOfRow += img.getHeight() + dy;

        }

        if (this.layout == LegendLayout.HORIZONTAL) {
            BufferedImage newImage = new BufferedImage(totalHeight, totalWidth, finalLegend.getType());
            Graphics2D g2 = newImage.createGraphics();
            g2.rotate(-Math.PI / 2, 0, 0);
            g2.drawImage(finalLegend, null, -totalWidth, 0);
            finalLegend = newImage;
            g2.dispose();
            finalGraphics.dispose();
        }
    } else {
        List<RenderedImage> imgs = new ArrayList<RenderedImage>(legendsQueue);

        LegendMerger.MergeOptions options = new LegendMerger.MergeOptions(imgs, (int) dx, (int) dy,
                (int) margin, 0, backgroundColor, transparent, true, layout, rowWidth, rows, columnHeight,
                columns, null, false, false);
        finalLegend = LegendMerger.mergeRasterLegends(options);
    }

    return finalLegend;

}

From source file:com.clough.android.adbv.view.MainFrame.java

public MainFrame() {
    initComponents();//from w  ww. j ava2  s .co  m
    setIconImage(ValueHolder.Icons.APPLICATION.getImage());
    setExtendedState(JFrame.MAXIMIZED_BOTH);

    Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
    double windowWidth = screenDimension.getWidth();
    double windowHeight = screenDimension.getHeight();
    int frameWidth = (int) (windowWidth * (3d / 4d));
    int frameHeight = (int) (windowHeight * (3d / 4d));
    setMinimumSize(new Dimension(frameWidth, frameHeight));
    setLocation((int) ((windowWidth - frameWidth) / 2d), (int) ((windowHeight - frameHeight) / 2d));

    int deviderSize = (int) (frameWidth * (1d / 100d));

    int deviderLocationForSpliter0 = (int) (frameWidth / 5d);
    splitPane0.setDividerLocation(deviderLocationForSpliter0);

    int deviderLocationForSpliter1 = (int) (frameWidth * (6d / 7d));
    splitPane1.setDividerLocation(deviderLocationForSpliter1);

    int subDeviderLocation = (int) (frameHeight / 6d);
    splitPane2.setDividerLocation(subDeviderLocation);

    queryHistoryContainerPanel.setMinimumSize(new Dimension(deviderLocationForSpliter0, 0));
    queryRootConatinerPanel.setMinimumSize(new Dimension(0, subDeviderLocation));

    queryingTextArea.requestFocus();

    resultTable.setModel(new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

    });

    defaultTableModel = (DefaultTableModel) resultTable.getModel();
    resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    tableColumnAdjuster = new TableColumnAdjuster(resultTable);

    historyContainingPanel.setLayout(new GridLayout(0, 1));

}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

/**
 * adjusts the viewable are of the log (zoom)
 *///w ww . ja  v  a 2 s  . c o  m
public void setViewportZoomIn() {
    Dimension d = dca.getViewportSize();
    int width = Math.abs(p1.x - p2.x);
    int height = Math.abs(p1.y - p2.y);

    int value = (int) (Math.log10(this.getWidth() * (d.getWidth() / width) / dca.getViewportSize().getWidth())
            * 1000.0);
    if (value > 3000)
        return;
    value = (int) (Math.log10(this.getHeight() * (d.getHeight() / height) / dca.getViewportSize().getHeight())
            * 1000.0);
    if (value > 3000)
        return;

    updWidth = (int) (this.getWidth() * (d.getWidth() / width));
    updHight = (int) (this.getHeight() * (d.getHeight() / height));
    Dimension dim = new Dimension(updWidth, updHight);
    int pos_x = Math.min(p1.x, p2.x);
    int pos_y = Math.min(p1.y, p2.y);

    Point p = new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height));
    this.setPreferredSize(dim);
    coUtil.updateMilli2pixelsRatio(this.getWidth(), BORDER);
    this.revalidate();
    dca.setScrollBarPosition(p);
    p1 = null;
    p2 = null;
    adjustSlideBar();
}

From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java

/**
 * adjusts the viewable are of the log (zoom)
 *//* w  w w  .j  a  v  a2 s . co  m*/
public Point zoomInViewPort() {
    if (p1 == null || p2 == null)
        return null;
    Dimension d = dca.getViewportSize();
    int width = Math.abs(p1.x - p2.x);
    int height = Math.abs(p1.y - p2.y);

    int value = (int) (Math.log10(this.getWidth() * (d.getWidth() / width) / dca.getViewportSize().getWidth())
            * 1000.0);
    if (value > 3000)
        return null;
    value = (int) (Math.log10(this.getHeight() * (d.getHeight() / height) / dca.getViewportSize().getHeight())
            * 1000.0);
    if (value > 3000)
        return null;

    updWidth = (int) (this.getWidth() * (d.getWidth() / width));
    updHight = (int) (this.getHeight() * (d.getHeight() / height));

    Dimension dim = new Dimension(updWidth, updHight);
    int pos_x = Math.min(p1.x, p2.x);
    int pos_y = Math.min(p1.y, p2.y);

    this.setPreferredSize(dim);
    coUtil.updateMilli2pixelsRatio(this.getWidth(), BORDER);
    this.revalidate();
    p1 = null;
    p2 = null;
    adjustSlideBar();
    return new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height));
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

@SuppressWarnings("serial")
private Component makeRosterPanel() {
    rosterPanel = new JPanel(new WrapLayout()) {
        // Fix to make it play nice with the scroll bar.
        @Override/* w ww . j  av a  2s. c o  m*/
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width = (int) (d.getWidth() - 20);
            return d;
        }
    };
    rosterScrollPane = new JScrollPane(rosterPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    rosterScrollPane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            rosterScrollPane.revalidate();
        }
    });
    rosterScrollPane.getVerticalScrollBar().setUnitIncrement(27);
    return rosterScrollPane;
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public Rectangle2D computeSizeData(AnnotationObject a) {
    // compute bbox
    theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a));
    Rectangle bbox = theGlycanRenderer.computeBoundingBoxes(a.getStructures(), false, false,
            new PositionManager(), new BBoxManager(), false);

    // compute text bbox        
    DecimalFormat mz_df = new DecimalFormat("0.0");
    String mz_text = mz_df.format(a.getPeakPoint().getX());
    Dimension mz_dim = textBounds(mz_text, theOptions.ANNOTATION_MZ_FONT, theOptions.ANNOTATION_MZ_SIZE);

    // update bbox
    double width = Math.max(bbox.getWidth(), mz_dim.getWidth());
    double height = bbox.getHeight() + theOptions.ANNOTATION_MARGIN + theOptions.ANNOTATION_MZ_SIZE;
    return new Rectangle2D.Double(0, 0, screenToDataX(width), screenToDataY(height));
}