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:org.neo4j.bench.chart.GenerateOpsPerSecChart.java

private void generateChart() throws Exception {
    DefaultCategoryDataset dataset = generateDataset();
    JFreeChart chart = ChartFactory.createBarChart("Performance chart", "Bench case", "Operations per sec",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    Dimension dimensions = new Dimension(1600, 900);
    File chartFile = new File(outputFilename);
    if (alarm) {/*from  w  w  w  .  j av  a 2  s  .c o m*/
        chart.setBackgroundPaint(Color.RED);
    }
    ChartUtilities.saveChartAsPNG(chartFile, chart, (int) dimensions.getWidth(), (int) dimensions.getHeight());
}

From source file:org.optaplanner.examples.tsp.swingui.TspWorldPanel.java

public void resetPanel(TravelingSalesmanTour travelingSalesmanTour) {
    translator = new LatitudeLongitudeTranslator();
    for (Location location : travelingSalesmanTour.getLocationList()) {
        translator.addCoordinates(location.getLatitude(), location.getLongitude());
    }//from  w  w w  .ja va2s.co  m

    Dimension size = getSize();
    double width = size.getWidth();
    double height = size.getHeight();
    translator.prepareFor(width, height);

    Graphics2D g = createCanvas(width, height);
    String tourName = travelingSalesmanTour.getName();
    if (tourName.startsWith("europe")) {
        g.drawImage(europaBackground.getImage(), 0, 0, translator.getImageWidth(), translator.getImageHeight(),
                this);
    }
    g.setFont(g.getFont().deriveFont((float) LOCATION_NAME_TEXT_SIZE));
    g.setColor(TangoColorFactory.PLUM_2);
    List<Visit> visitList = travelingSalesmanTour.getVisitList();
    for (Visit visit : visitList) {
        Location location = visit.getLocation();
        int x = translator.translateLongitudeToX(location.getLongitude());
        int y = translator.translateLatitudeToY(location.getLatitude());
        g.fillRect(x - 1, y - 1, 3, 3);
        if (location.getName() != null && visitList.size() <= 500) {
            g.drawString(StringUtils.abbreviate(location.getName(), 20), x + 3, y - 3);
        }
    }
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    Domicile domicile = travelingSalesmanTour.getDomicile();
    Location domicileLocation = domicile.getLocation();
    int domicileX = translator.translateLongitudeToX(domicileLocation.getLongitude());
    int domicileY = translator.translateLatitudeToY(domicileLocation.getLatitude());
    g.fillRect(domicileX - 2, domicileY - 2, 5, 5);
    if (domicileLocation.getName() != null && visitList.size() <= 500) {
        g.drawString(domicileLocation.getName(), domicileX + 3, domicileY - 3);
    }
    Set<Visit> needsBackToDomicileLineSet = new HashSet<Visit>(visitList);
    for (Visit trailingVisit : visitList) {
        if (trailingVisit.getPreviousStandstill() instanceof Visit) {
            needsBackToDomicileLineSet.remove(trailingVisit.getPreviousStandstill());
        }
    }
    g.setColor(TangoColorFactory.CHOCOLATE_1);
    for (Visit visit : visitList) {
        if (visit.getPreviousStandstill() != null) {
            Location previousLocation = visit.getPreviousStandstill().getLocation();
            Location location = visit.getLocation();
            translator.drawRoute(g, previousLocation.getLongitude(), previousLocation.getLatitude(),
                    location.getLongitude(), location.getLatitude(), location instanceof AirLocation, false);
            // Back to domicile line
            if (needsBackToDomicileLineSet.contains(visit)) {
                translator.drawRoute(g, location.getLongitude(), location.getLatitude(),
                        domicileLocation.getLongitude(), domicileLocation.getLatitude(),
                        location instanceof AirLocation, true);
            }
        }
    }
    // Drag
    if (dragSourceStandstill != null) {
        g.setColor(TangoColorFactory.CHOCOLATE_2);
        Location sourceLocation = dragSourceStandstill.getLocation();
        Location targetLocation = dragTargetStandstill.getLocation();
        translator.drawRoute(g, sourceLocation.getLongitude(), sourceLocation.getLatitude(),
                targetLocation.getLongitude(), targetLocation.getLatitude(),
                sourceLocation instanceof AirLocation, dragTargetStandstill instanceof Domicile);
    }
    // Legend
    g.setColor(TangoColorFactory.ALUMINIUM_4);
    g.fillRect(5, (int) height - 15 - TEXT_SIZE, 5, 5);
    g.drawString("Domicile", 15, (int) height - 10 - TEXT_SIZE);
    g.setColor(TangoColorFactory.PLUM_2);
    g.fillRect(6, (int) height - 9, 3, 3);
    g.drawString("Visit", 15, (int) height - 5);
    g.setColor(TangoColorFactory.ALUMINIUM_5);
    String locationsSizeString = travelingSalesmanTour.getLocationList().size() + " locations";
    g.drawString(locationsSizeString, ((int) width - g.getFontMetrics().stringWidth(locationsSizeString)) / 2,
            (int) height - 5);
    if (travelingSalesmanTour.getDistanceType() == DistanceType.AIR_DISTANCE) {
        String leftClickString = "Left click and drag between 2 locations to connect them.";
        g.drawString(leftClickString, (int) width - 5 - g.getFontMetrics().stringWidth(leftClickString),
                (int) height - 10 - TEXT_SIZE);
        String rightClickString = "Right click anywhere on the map to add a visit.";
        g.drawString(rightClickString, (int) width - 5 - g.getFontMetrics().stringWidth(rightClickString),
                (int) height - 5);
    }
    // Show soft score
    g.setColor(TangoColorFactory.ORANGE_3);
    SimpleLongScore score = travelingSalesmanTour.getScore();
    if (score != null) {
        String distanceString = travelingSalesmanTour.getDistanceString(NUMBER_FORMAT);
        g.setFont(g.getFont().deriveFont(Font.BOLD, (float) TEXT_SIZE * 2));
        g.drawString(distanceString, (int) width - g.getFontMetrics().stringWidth(distanceString) - 10,
                (int) height - 15 - 2 * TEXT_SIZE);
    }
    repaint();
}

From source file:pt.lsts.neptus.plugins.wg.WgCtdLayer.java

private boolean isVisibleInRender(Point2D sPos, StateRenderer2D renderer) {
    Dimension rendDim = renderer.getSize();
    if (sPos.getX() < 0 && sPos.getY() < 0)
        return false;
    else if (sPos.getX() > rendDim.getWidth() && sPos.getY() > rendDim.getHeight())
        return false;

    return true;//from w w  w  . j  av a 2  s .co m
}

From source file:edu.uci.ics.jung.algorithms.layout.CircleLayout.java

public void initialize() {
    Dimension d = getSize();

    if (d != null) {
        if (vertex_ordered_list == null)
            setVertexOrder(new ArrayList<V>(getGraph().getVertices()));

        double height = d.getHeight();
        double width = d.getWidth();

        if (radius <= 0) {
            radius = 0.45 * (height < width ? height : width);
        }//from   ww w  .  j  av  a  2  s .co m

        int i = 0;
        for (V v : vertex_ordered_list) {
            Point2D coord = transform(v);

            double angle = (2 * Math.PI * i) / vertex_ordered_list.size();

            coord.setLocation(Math.cos(angle) * radius + width / 2, Math.sin(angle) * radius + height / 2);

            CircleVertexData data = getCircleData(v);
            data.setAngle(angle);
            i++;
        }
    }
}

From source file:org.jtrfp.trcl.obj.ProjectileFactory.java

public ProjectileFactory(TR tr, Weapon weapon, ExplosionType explosionType) {
    this.tr = tr;
    this.weapon = weapon;
    this.projectileSpeed = weapon.getSpeed() / TR.crossPlatformScalar;
    Model modelToUse;/* w ww  .  j  a v  a2s  .  com*/
    TextureDescription t;
    Triangle[] tris;
    final int damageOnImpact = weapon.getDamage();
    try {
        modelToUse = new Model(false, tr);
        final ModelingType modelingType = weapon.getModelingType();
        if (modelingType instanceof ModelingType.FlatModelingType) {
            ModelingType.FlatModelingType mt = (ModelingType.FlatModelingType) modelingType;
            Dimension dims = mt.getSegmentSize();
            final int laserplaneLength = (int) (dims.getWidth() / TR.crossPlatformScalar);
            final int laserplaneWidth = (int) (dims.getHeight() / TR.crossPlatformScalar);
            t = tr.getResourceManager()
                    .getRAWAsTexture(tr.config.getGameVersion() != GameVersion.TV ? mt.getF3RawFileName()
                            : mt.getTvRawFileName(), tr.getDarkIsClearPaletteVL(), null, false);
            final double Y_SLANT = 1024;
            tris = (Triangle.quad2Triangles(
                    new double[] { -laserplaneLength / 2., laserplaneLength / 2., laserplaneLength / 2.,
                            -laserplaneLength / 2. }, //X
                    new double[] { 0, 0, Y_SLANT, Y_SLANT },
                    new double[] { -laserplaneWidth / 2., -laserplaneWidth / 2., laserplaneWidth / 2.,
                            laserplaneWidth / 2. }, //YZ
                    new double[] { 1, 0, 0, 1 }, new double[] { 0, 0, 1, 1 }, t, RenderMode.STATIC,
                    Vector3D.ZERO, "ProjectileFactory:" + weapon.toString()));//UVtr
            tris[0].setAlphaBlended(true);
            tris[1].setAlphaBlended(true);
            modelToUse.addTriangles(tris);
            modelToUse.finalizeModel();
            for (int i = 0; i < projectiles.length; i++) {
                projectiles[i] = new ProjectileObject3D(tr, modelToUse, weapon, explosionType);
            }
        } //end if(isLaser)
        else if (modelingType instanceof ModelingType.BillboardModelingType) {
            final ModelingType.BillboardModelingType mt = (ModelingType.BillboardModelingType) modelingType;
            final Texture[] frames = new Texture[mt.getRawFileNames().length];
            final String[] fileNames = mt.getRawFileNames();
            final ResourceManager mgr = tr.getResourceManager();
            final ColorPaletteVectorList pal = tr.getGlobalPaletteVL();
            GL3 gl = tr.gpu.get().getGl();
            for (int i = 0; i < frames.length; i++) {
                frames[i] = (Texture) mgr.getRAWAsTexture(fileNames[i], pal, null, false);
            } //end for(frames)
            TextureDescription tex = new AnimatedTexture(
                    new Sequencer(mt.getTimeInMillisPerFrame(), frames.length, false), frames);
            for (int i = 0; i < projectiles.length; i++) {
                projectiles[i] = new ProjectileBillboard(tr, weapon, tex, ExplosionType.Billow);
            }
        } //end (billboard)
        else if (modelingType instanceof ModelingType.BINModelingType) {
            final ModelingType.BINModelingType mt = (ModelingType.BINModelingType) modelingType;
            modelToUse = tr.getResourceManager().getBINModel(mt.getBinFileName(), tr.getGlobalPaletteVL(), null,
                    tr.gpu.get().getGl());
            for (int i = 0; i < projectiles.length; i++) {
                projectiles[i] = new ProjectileObject3D(tr, modelToUse, weapon, explosionType);
            }
        } //end BIN Modeling Type
        else {
            throw new RuntimeException("Unhandled ModelingType: " + modelingType.getClass().getName());
        }
    } //end try
    catch (Exception e) {
        e.printStackTrace();
    }
    //CLAUSE: FFF needs destroysEvertyhing behavior
    if (weapon == Weapon.DAM) {
        for (int i = 0; i < projectiles.length; i++) {
            ((WorldObject) projectiles[i]).addBehavior(new DestroysEverythingBehavior());
        }
    } //end if(DAM)

    //Sound
    String soundFile = null;
    switch (weapon) {
    //PEW!!!
    case PAC: {
        soundFile = "LASER2.WAV";
        break;
    }
    case ION: {
        soundFile = "LASER3.WAV";
        break;
    }
    case RTL: {
        soundFile = "LASER4.WAV";
        break;
    }
    case DAM:
    case redLaser:
    case blueLaser:
    case greenLaser:
    case purpleLaser:
    case purpleRing: {
        soundFile = "LASER5.WAV";
        break;
    }
    //Missile
    case enemyMissile:
    case SWT:
    case MAM:
    case SAD: {
        soundFile = "MISSILE.WAV";
        break;
    }
    //SILENT
    case purpleBall:
    case goldBall:
    case fireBall:
    case blueFireBall:
    case bullet:
    case bossW8:
    case bossW7:
    case bossW6:
    case atomWeapon:
    default:
        break;
    }//end case()
    soundTexture = soundFile != null ? tr.getResourceManager().soundTextures.get(soundFile) : null;
}

From source file:genlib.output.gui.Graph2D.java

/**
 * open a window with one or more plot-collections
 *
 * @param rows count of rows//from   ww w . ja v  a2 s .  co  m
 * @param cols count of columns
 * @param gap size of gaps between Plots (in pixel)
 * @param percentSizeOfScreen the size of the complete window in per-cent of the windows
 * @param plots the plot-collections, can have null's inside,then there is empty space on the window
 * @return the window-object
 * @throws IllegalArgumentException if rows or cols lower than 1, gap lower than 0, percentSizeOfScreen lower than 0.001 or higher than 1 or number of plots not the same as rows*cols
 */
public static Graph2D open(int rows, int cols, int gap, double percentSizeOfScreen, PlotCollection... plots) {
    if (rows <= 0)
        throw new IllegalArgumentException("invalid rows-count: '" + rows + "'.");
    if (cols <= 0)
        throw new IllegalArgumentException("invalid cols-count: '" + cols + "'.");
    if (gap < 0)
        throw new IllegalArgumentException("invalid gap: '" + gap + "'.");
    if (percentSizeOfScreen < 0.001 || percentSizeOfScreen > 1)
        throw new IllegalArgumentException("invalid percentSizeOfScreen: '" + percentSizeOfScreen + "'.");
    if (plots == null || plots.length != rows * cols)
        throw new IllegalArgumentException("length of plots is not rows*cols.");

    //the window-title is a concatenation of all plots
    //but first, we have to ignore all null-plots
    String windowTitle = "";
    List<PlotCollection> plotsNotNull = new ArrayList();
    for (PlotCollection plot : plots)
        if (plot != null)
            plotsNotNull.add(plot);

    if (plotsNotNull.isEmpty())
        windowTitle = "no plots";
    else
        for (int i = 0; i < plotsNotNull.size(); i++)
            windowTitle += (i > 0 ? ", " : "") + plotsNotNull.get(i).title;

    //create the window
    Graph2D ret = new Graph2D(windowTitle);

    //and create the row-col-layout
    JPanel grid = new JPanel();
    grid.setLayout(new GridLayout(rows, cols, gap, gap));
    for (PlotCollection plot : plots)
        if (plot == null)
            grid.add(new JLabel(""));
        else
            grid.add(plot.getGUIElement());

    //some other attributes of the window
    grid.setBackground(Color.BLACK);
    ret.setContentPane(grid);
    ret.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    ret.setSize(new Dimension((int) (screenSize.getWidth() * percentSizeOfScreen),
            (int) (screenSize.getHeight() * percentSizeOfScreen)));
    RefineryUtilities.centerFrameOnScreen(ret);
    ret.setVisible(true);

    return ret;
}

From source file:org.neo4j.bench.chart.AbstractJFreeChart.java

public void open(Reader input, Args options) throws IOException {
    final T dataset = instantiateDataset();
    ResultHandler handler = new ResultHandler() {
        public void newResult(Map<String, String> header) {
        }/*from   w  ww.j ava  2s.  com*/

        public void value(Map<String, String> header, double value, int numberOfIterations, String benchCase,
                String timer) {
            addValue(dataset, header, (int) value, numberOfIterations, benchCase, timer);
        }

        public void endResult() {
        }
    };

    Map<String, Collection<String>> aggregations = RunUtil.loadAggregations(options);
    if (aggregations != null) {
        handler = new AggregatedResultHandler(handler, aggregations);
    }

    ResultParser parser = new ResultParser(handler);
    parser.parse(input, options);

    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    Dimension dimensions = getDimensions();
    chartPanel.setPreferredSize(dimensions);
    File chartFile = new File(
            "chart-" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ".jpg");
    ChartUtilities.saveChartAsJPEG(chartFile, chart, (int) dimensions.getWidth(), (int) dimensions.getHeight());
}

From source file:fedora.client.Uploader.java

/**
 * Send a file to the server, getting back the identifier.
 *///from w ww .ja v a  2s . c o m
public String upload(File file) throws IOException {
    if (Administrator.INSTANCE == null) {
        return fc.uploadFile(file);
    } else {
        // paint initial status to the progress bar
        String msg = "Uploading " + file.length() + " bytes to " + fc.getUploadURL();
        Dimension d = Administrator.PROGRESS.getSize();
        Administrator.PROGRESS.setString(msg);
        Administrator.PROGRESS.setValue(100);
        Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1);

        // then start the thread, passing parms in
        HashMap<String, Object> PARMS = new HashMap<String, Object>();
        PARMS.put("fc", fc);
        PARMS.put("file", file);
        SwingWorker worker = new SwingWorker(PARMS) {

            @Override
            public Object construct() {
                try {
                    FedoraClient fc = (FedoraClient) parms.get("fc");
                    File file = (File) parms.get("file");
                    return fc.uploadFile(file);
                } catch (IOException e) {
                    thrownException = e;
                    return "";
                }
            }
        };
        worker.start();

        // keep updating status till the worker's finished
        int ms = 200;
        while (!worker.done) {
            try {
                Administrator.PROGRESS.setValue(ms);
                Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1);
                Thread.sleep(100);
                ms = ms + 100;
                if (ms >= 2000) {
                    ms = 200;
                }
            } catch (InterruptedException ie) {
            }
        }

        // reset the status bar to normal
        Administrator.PROGRESS.setValue(2000);
        Administrator.PROGRESS.paintImmediately(0, 0, (int) d.getWidth() - 1, (int) d.getHeight() - 1);
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
        }

        // report if there was an error; otherwise return the response
        if (worker.thrownException != null) {
            throw (IOException) worker.thrownException;
        } else {
            return (String) worker.getValue();
        }

    }
}

From source file:com.projity.pm.graphic.network.rendering.FormComponent.java

public void paint(Graphics g) {
    /*CommonGraphCell cell=(CommonGraphCell)view.getCell();
    if (cell.getNode().isVoid()) return;*/

    Graphics2D g2 = (Graphics2D) g;
    Dimension d = getSize();
    double w = d.getWidth();
    double h = d.getHeight();

    paintSelectedBars(g2, w - 1, h - 1);
    //      ImageIcon link=IconManager.getIcon("common.link.image");
    //      g2.drawImage(link.getImage(),(int)(w-link.getIconWidth()),(int)(h-link.getIconHeight()),this);
    //x=w and y=h are outside

    try {/*from ww w .  j av a2  s .  c om*/
        //if (preview && !isDoubleBuffered)
        //   setOpaque(false);
        super.paint(g);
        //paintSelectionBorder(g);
    } catch (IllegalArgumentException e) {
        // JDK Bug: Zero length string passed to TextLayout constructor
    }
}

From source file:org.richfaces.component.InputNumberSpinnerComponentTest.java

public void testImages() throws Exception {
    InternetResource image = InternetResourceBuilder.getInstance().createResource(null,
            SpinnerFieldGradient.class.getName());
    Dimension imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 30 && imageDim.getHeight() == 50);

    image = InternetResourceBuilder.getInstance().createResource(null, SpinnerButtonGradient.class.getName());
    imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 30 && imageDim.getHeight() == 50);

    image = InternetResourceBuilder.getInstance().createResource(null, SpinnerButtonDown.class.getName());
    imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 14 && imageDim.getHeight() == 7);

    image = InternetResourceBuilder.getInstance().createResource(null, SpinnerButtonUp.class.getName());
    imageDim = ((Java2Dresource) image).getDimensions(facesContext, null);
    assertTrue(imageDim.getWidth() == 14 && imageDim.getHeight() == 7);
}