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:KjellDirdalNotepad.java

protected void resizeDesktop() {
    int x = 0;//from  w w w . j a va 2s . c om
    int y = 0;
    JScrollPane scrollPane = getScrollPane();
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
        JInternalFrame allFrames[] = desktop.getAllFrames();
        for (int i = 0; i < allFrames.length; i++) {
            if (allFrames[i].getX() + allFrames[i].getWidth() > x) {
                x = allFrames[i].getX() + allFrames[i].getWidth();
            }
            if (allFrames[i].getY() + allFrames[i].getHeight() > y) {
                y = allFrames[i].getY() + allFrames[i].getHeight();
            }
        }
        Dimension d = scrollPane.getVisibleRect().getSize();
        if (scrollPane.getBorder() != null) {
            d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right,
                    d.getHeight() - scrollInsets.top - scrollInsets.bottom);
        }

        if (x <= d.getWidth())
            x = ((int) d.getWidth()) - 20;
        if (y <= d.getHeight())
            y = ((int) d.getHeight()) - 20;
        desktop.setAllSize(x, y);
        scrollPane.invalidate();
        scrollPane.validate();
    }
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.ChartDisplayPanel.java

/**
 * Creates a Swing control that displays this panel's chart.
 * <p>/*from  w  w w. j ava2s .  c o  m*/
 * The newly created panel is stored in the {@link #chartPanel} field.
 * </p>
 * 
 * @return The newly created panel instance that displays the chart.
 */
private JPanel createChartPanel() {
    chartPanel = JFreeChartConn.createPanel(chart);
    Dimension size = chartPanel.getPreferredSize();
    size.setSize(size.getWidth() / 3 * 2, size.getHeight() / 3 * 2);
    chartPanel.setPreferredSize(size);
    return chartPanel;
}

From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java

private void doInit() {
    Graph<V, E> graph = getGraph();
    Dimension d = getSize();

    if (graph != null && d != null) {
        currentIteration = 0;//from  w  ww  .j  a  v  a 2s .  co  m
        temperature = d.getWidth() / 10;

        forceConstant = Math.sqrt(d.getHeight() * d.getWidth() / graph.getVertexCount());

        attraction_constant = attraction_multiplier * forceConstant;
        repulsion_constant = repulsion_multiplier * forceConstant;
    }
}

From source file:jdroidremote.ServerFrame.java

public void initEventDriven() {
    jbtRunServer.addActionListener(new ActionListener() {
        @Override//from ww  w  .j  av a  2  s  . c  om
        public void actionPerformed(ActionEvent e) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        serverSocket = new ServerSocket(5005);
                        System.out.println("Server is running...");
                        clientSocket = serverSocket.accept();
                        dis = new DataInputStream(clientSocket.getInputStream());
                        dos = new DataOutputStream(clientSocket.getOutputStream());
                        System.out.println(
                                "some device connected us from address: " + clientSocket.getInetAddress());

                        thReceiveMouseCoords.start();
                        thStartMonitoring.start();

                    } catch (IOException ex) {
                        Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }).start();

            thReceiveMouseCoords = new Thread(new Runnable() {
                @Override
                public void run() {

                    System.out.println("START RECEIVING COORDS.............");

                    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                    double width = screenSize.getWidth();
                    double height = screenSize.getHeight();

                    while (1 == 1) {
                        try {
                            String receivedStr = dis.readUTF();

                            if (receivedStr.contains("left_click")) {
                                robot.mousePress(KeyEvent.BUTTON1_DOWN_MASK);
                                robot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK);
                            } else if (receivedStr.contains("right_click")) {
                                robot.mousePress(KeyEvent.BUTTON3_DOWN_MASK);
                                robot.mouseRelease(KeyEvent.BUTTON3_DOWN_MASK);
                            } else if (receivedStr.contains("coords")) {
                                System.out.println(receivedStr);
                                String[] mouseCoords = receivedStr.split(":");

                                int x = (int) (Integer.parseInt(mouseCoords[0]) * width / 100);
                                int y = (int) (Integer.parseInt(mouseCoords[1]) * height / 100);

                                robot.mouseMove(x, y);
                            } else {
                                String[] dataArr = receivedStr.split("-");

                                typeCharacter(dataArr[1]);
                            }
                        } catch (IOException ex) {
                            Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            });
        }
    });
}

From source file:edu.purdue.cc.bionet.ui.layout.MultipleCirclesLayout.java

/**
 * Sets the initial position of the Graph nodes.
 *///w w  w.j  av  a 2 s .  c om
public void initialize() {
    if (this.sampleGroups != null) {
        Dimension d = this.getSize();
        List<List<V>> moleculeGroups = new ArrayList<List<V>>();
        for (int i = 0; i < 3; i++) {
            moleculeGroups.add(new ArrayList<V>());
        }
        if (d != null) {
            double height = d.getHeight();
            double width = d.getWidth();

            String groupName;
            for (V v : this.getGraph().getVertices()) {
                if (this.isUpRegulated(sampleGroups, v))
                    moleculeGroups.get(1).add(v);
                else if (this.isDownRegulated(sampleGroups, v))
                    moleculeGroups.get(2).add(v);
                else
                    moleculeGroups.get(0).add(v);
            }

            this.radius = (Math.min(height, width)) * 0.3;
            int groupRadius = (int) (this.radius / Math.sqrt(moleculeGroups.size()));

            int j = 0, x, y;
            Point2D.Double graphCenter = new Point2D.Double(width / 2.0, height / 2.0);
            PolarPoint2D center = new PolarPoint2D(0, 0, graphCenter);
            PolarPoint2D coord = new PolarPoint2D(0, 0, center);
            double theta;

            for (List<V> group : moleculeGroups) {
                theta = (2 * Math.PI * j) / moleculeGroups.size();
                j++;
                center.setLocation(this.radius, theta, PolarPoint2D.POLAR);
                int i = 0;
                for (V vertex : group) {
                    theta = (2 * Math.PI * i) / group.size();
                    coord.setLocation(groupRadius, theta, PolarPoint2D.POLAR);
                    this.setLocation(vertex, coord);
                    i++;
                }
            }
        }
    }
}

From source file:org.yamj.core.service.artwork.ArtworkProcessorService.java

private boolean checkArtworkQuality(ArtworkLocated located) {
    if (StringUtils.isNotBlank(located.getUrl())) {

        if (located.getWidth() <= 0 || located.getHeight() <= 0) {
            // retrieve dimension
            try {
                // get dimension
                Dimension dimension = GraphicTools.getDimension(located.getUrl());
                if (dimension.getHeight() <= 0 || dimension.getWidth() <= 0) {
                    LOG.warn("No valid image dimension determined: {}", located);
                    return Boolean.FALSE;
                }/*from ww  w  .j av  a 2 s  .co m*/

                // set values for later usage
                located.setWidth((int) dimension.getWidth());
                located.setHeight((int) dimension.getHeight());
            } catch (IOException ex) {
                LOG.warn("Could not determine image dimension cause invalid image: {}", located);
                LOG.trace("Invalid image error", ex);
                return Boolean.FALSE;
            }
        }

        // TODO: check quality of artwork?

        /*
         float urlAspect = (float) urlWidth / (float) urlHeight;
         if (urlAspect > 1.0) {
         LOG.info("{} rejected: URL is wrong aspect (portrait/landscape)", located);
         return Boolean.FALSE;
         }
                
         // Adjust artwork width / height by the ValidateMatch figure
         int newArtworkWidth = artworkWidth * (artworkValidateMatch / 100);
         int newArtworkHeight = artworkHeight * (artworkValidateMatch / 100);
                
         if (urlWidth < newArtworkWidth) {
         logger.debug(LOG_MESSAGE + artworkImage + " rejected: URL width (" + urlWidth + ") is smaller than artwork width (" + newArtworkWidth + ")");
         return Boolean.FALSE;
         }
                
         if (urlHeight < newArtworkHeight) {
         logger.debug(LOG_MESSAGE + artworkImage + " rejected: URL height (" + urlHeight + ") is smaller than artwork height (" + newArtworkHeight + ")");
         return Boolean.FALSE;
         }
         */
    } else {
        // TODO: stage file needs no validation??
        LOG.trace("Located URL was blank for {}", located.toString());
    }

    return Boolean.TRUE;
}

From source file:org.jannocessor.ui.RenderPreviewDialog.java

private void initialize() {
    logger.debug("Initializing UI...");
    DefaultSyntaxKit.initKit();/*from   w  w  w . j  a v  a 2  s.  co  m*/

    JEditorPane.registerEditorKitForContentType("text/java_template", "org.jannocessor.syntax.JavaTemplateKit",
            getClass().getClassLoader());

    JEditorPane.registerEditorKitForContentType("text/java_output", "org.jannocessor.syntax.JavaOutputKit",
            getClass().getClassLoader());

    setTitle("JAnnocessor - Java Annotation Processor");
    setLayout(new BorderLayout(5, 5));

    listFiles();

    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenSize = tk.getScreenSize();
    double width = screenSize.getWidth() * 0.9;
    double height = screenSize.getHeight() * 0.8;

    // Font font = new Font("Courier New", Font.PLAIN, 14);

    input = createInput();
    JScrollPane scroll1 = new JScrollPane(input, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    input.setContentType("text/java_template");

    input.setText("");

    scroll1.setMinimumSize(new Dimension(200, 200));
    scroll1.setPreferredSize(new Dimension((int) (width * 0.5), (int) height));
    add(scroll1, BorderLayout.CENTER);

    output = Box.createVerticalBox();

    scroll2 = new JScrollPane(output, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll2.setMinimumSize(new Dimension(200, 200));
    scroll2.setPreferredSize(new Dimension((int) (width * 0.5), (int) height));
    add(scroll2, BorderLayout.EAST);

    combo = createCombo();

    combo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            load((File) combo.getSelectedItem());
        }
    });

    add(combo, BorderLayout.NORTH);
    JLabel help = new JLabel(
            " Choose a template from the drop-down box to edit it. Navigation: Alt + Left & Alt + Right; Refresh = F5, Close = Esc",
            JLabel.CENTER);

    help.setForeground(Color.WHITE);
    help.setBackground(Color.BLACK);
    help.setOpaque(true);
    help.setFont(new Font("Courier New", Font.BOLD, 14));
    add(help, BorderLayout.SOUTH);

    keyListener = new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F5) {
                e.consume();
                processElements();
                refresh();
            } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                e.consume();
                dispose();
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT && e.isAltDown()) {
                e.consume();
                moveBackward();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT && e.isAltDown()) {
                e.consume();
                moveForward();
            } else if (e.getKeyCode() == KeyEvent.VK_S && e.isControlDown()) {
                e.consume();
                save();
            } else if (e.getKeyCode() == KeyEvent.VK_I && e.isControlDown()) {
                e.consume();
                increase();
            } else if (e.getKeyCode() == KeyEvent.VK_D && e.isControlDown()) {
                e.consume();
                decrease();
            }
        }
    };

    input.addKeyListener(keyListener);
    combo.addKeyListener(keyListener);

    setActive(0);

    pack();
    setModal(true);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    input.requestFocus();
    logger.debug("Initialized UI.");
}

From source file:org.opennms.features.topology.app.internal.jung.D3LayoutTest.java

private D3TopoLayout<VertexRef, EdgeRef> runD3Layout(int count, Graph g, Layout graphLayout,
        List<Vertex> vertices) throws IOException {
    D3TopoLayout<VertexRef, EdgeRef> layout = new D3TopoLayout<>(createJungGraph(g));
    Dimension size = selectLayoutSize(m_graphContainer);

    layout.setInitializer(initializer(graphLayout, size));
    layout.setSize(size);/*from  w  w  w .  j a va2 s  . c  om*/

    try (PrintWriter out = new PrintWriter(new FileWriter("target/data" + count + ".js"))) {
        out.println("var gCenter = { x: " + size.getWidth() / 2.0 + ", y: " + size.getHeight() / 2.0 + "};");
        out.println("var data = [");
        while (!layout.done()) {
            out.println("[");

            for (int i = 0; i < vertices.size(); i++) {
                Vertex v = vertices.get(i);
                if (i + 1 == vertices.size()) {
                    out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " }");
                } else {
                    out.println("{ x:" + layout.getX(v) + ", y:" + layout.getY(v) + " },");
                }
            }

            layout.step();
            out.println("],");
        }
        out.println("];");
        LOG.info("/******** D3Layout Run **********/");
    }

    for (Vertex v : vertices) {
        graphLayout.setLocation(v,
                new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
        LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
    }
    LOG.info("/******** End D3Layout Run **********/");
    return layout;
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private Rectangle positionPlot(Dimension size, int x, int y, int bottom, int right) {
    //insets.setValue(top, left, bottom, right);
    //Rectangle r = insets.shrinkRect(size);
    final Rectangle r = new Rectangle(x, y, (int) size.getWidth() - x - right,
            (int) size.getHeight() - y - bottom);
    origin = r.getLocation();//from   ww  w .j av a 2  s  .  co m
    graphSize.setSize(r.width, r.height);
    return r;
}

From source file:jfix.zk.Mediafield.java

public Mediafield() {
    setHflex("1");
    upload.addEventListener(Events.ON_UPLOAD, $event -> uploadPerformed(((UploadEvent) $event).getMedia()));
    download.addEventListener(Events.ON_CLICK, $event -> downloadPerformed());
    rotateImage.addEventListener(Events.ON_CLICK, $event -> {
        try {// w  w w . j  av  a  2s  .co m
            File imageFile = Medias.asFile(media);
            imageFile.deleteOnExit();
            File rotatedImage = jfix.util.Images.rotate(imageFile);
            rotatedImage.deleteOnExit();
            setMedia(media.getName(), media.getContentType(), rotatedImage);
        } catch (IOException e) {
            Modal.exception(e);
        }

    });

    aspectRatioLock.setChecked(true);
    EventListener<Event> dimensionChanged = $event -> {
        Dimension scaledDimension = null;
        if (aspectRatioLock.isChecked()) {
            scaledDimension = jfix.util.Images.scaleDimension(originalDimension,
                    new Dimension(width.intValue(), height.intValue()));
            width.setValue((int) scaledDimension.getWidth());
            height.setValue((int) scaledDimension.getHeight());
        } else {
            scaledDimension = new Dimension(width.intValue(), height.intValue());
        }
        File imageFile = Medias.asFile(media);
        imageFile.deleteOnExit();
        File scaledImage = jfix.util.Images.scale(imageFile, scaledDimension);
        scaledImage.deleteOnExit();
        setMedia(media.getName(), media.getContentType(), scaledImage);
    };
    width.addEventListener(Events.ON_CHANGE, dimensionChanged);
    height.addEventListener(Events.ON_CHANGE, dimensionChanged);

    setHeight("300px");
    setPreview(true);
    codemirror.setVisible(false);
    imagePreview.setVisible(false);
    width.setStep(10);
    height.setStep(10);

    download.setImage(Images.DriveRemovableMedia);
    download.setVisible(false);

    appendChild(codemirror);
    appendChild(imagePreview);
    appendChild(new Row(download, upload));
}