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:graphic.ihm.dialog.createperso.DialCreatePerso.java

/**
 * @param evt/*from   ww  w .  j a  v  a  2s  .  c  o  m*/
 */
private void cancelActionPerformed(ActionEvent evt) {
    MainMenu menu = new MainMenu(null, false);
    Dimension tailleEcran = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    menu.setLocation((int) (tailleEcran.getWidth() / 2 - menu.getWidth() / 2),
            (int) (tailleEcran.getHeight() / 2 - menu.getHeight() / 2));
    menu.setVisible(true);
    this.setVisible(false);
}

From source file:util.NewStreamBlobUtil.java

/**
* Returns scaled blob/*from   w w  w.j  a  v  a  2  s .  c o m*/
* @param b byte stream
* @param type that is "jpeg", "gif", "png"
* @param width width of the image
* @param height height of the image
* @param scale boolean yes or no
* @return scaled byte stream
*/
public synchronized byte[] streamBlob(byte[] b, int width, int height, boolean doIScale)
        throws BasicObjException {

    if (b == null) {
        return null;
    }
    try {
        initializeImageInfo();
        ImgMetadata scaled = null;
        if (doIScale) {
            // scale the image
            InputStream imageInputStream = new ByteArrayInputStream(b);
            // read in the original image from an input stream
            SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
            RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);
            //RenderedOp originalImage = JAI.create("stream", seekableImageStream, true);
            Dimension d = new Dimension(originalImage.getWidth(), originalImage.getHeight());
            d = WebUtil.getDimension(d, width, height);
            ImgMetadata data = imageHelper.makeImg(b);
            scaled = imageHelper.scaleImg(data, (int) d.getWidth(), (int) d.getHeight());
        } else {
            // don't scale the image
            ImgMetadata data = imageHelper.makeImg(b);
            scaled = imageHelper.scaleImg(data, width, height);
        }
        if (scaled != null) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int quality = 75;
            String type = "jpeg"; // any output encoding
            scaled.writeTo(os, type, quality); //calls JAI.create("encode", result, fos, type, null);
            return os.toByteArray();
        }
    } catch (Exception e) {
        throw new BasicObjException("Error writing image stream ", e);
    }
    return null;
}

From source file:com.mc.printer.model.StartTask.java

@Override
public void onSucceeded(Object object) {
    if (object instanceof Exception) {
        Exception e = (Exception) object;
        logger.error(e.getMessage());//from   w  ww .j ava2 s  .  c  o m
    }
    if (AutoPrinterApp.isRegister) {
        logger.info("connect to remote server,please wait...");
    }
    new FileTask(FileTask.TYPE_DOWNLOAD, ClientConstants.GUIDE_DOWNLOAD_DIR, "") {

        @Override
        public void responseResult(String file) {

            if (AutoPrinterApp.isRegister) {
                /*video*/
                new FileTask(FileTask.TYPE_DOWNLOAD, ClientConstants.VIDEO_LIB, "video") {
                    @Override
                    public void responseResult(String file) {
                        logger.info("download video task completed.>" + ClientConstants.VIDEO_LIB);
                    }
                }.execute();
            } else {
                logger.debug("client has not register, can't fetch the video.");
            }

            final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            final int maxWidth = (int) screenSize.getWidth();
            final int maxHeight = (int) Math.round(screenSize.getHeight() / 3); //??1/3
            logger.info("load application completed. try to open guide and form...");

            new BaseTask() {
                @Override
                public Object doBackgrounp() {
                    new OpenGuidePaperTask(Constants.GUIDE_BOTTOM_FILE) {
                        @Override
                        public void onSucceed(Object object, HashMap<String, Integer> statusMap) {

                            if (object == null || object instanceof Exception) {
                                topRealHeight = maxHeight;
                            } else if (object instanceof GuideBean) {
                                GuideBean guideBean = (GuideBean) object;
                                GuidePanel panel = new GuidePanel(null, guideBean, maxWidth,
                                        guideBean.getHeight()) {

                                    @Override
                                    public GuidePanel parentGuideWindow() {
                                        return null;
                                    }

                                    @Override
                                    public GuidePanel targetWindowAfterAuth() {
                                        return null;
                                    }
                                };
                                panel.enableButtonByRemote(statusMap);
                                AutoPrinterApp.getClientMain().setBottomUI(panel);
                                topRealHeight = panel.getCurrentGuideBean().getHeight();
                            }

                        }
                    }.run();

                    new OpenGuidePaperTask(Constants.GUIDE_TOP_FILE) {
                        @Override
                        public void onSucceed(Object object, HashMap<String, Integer> statusMap) {
                            if (object == null || object instanceof Exception) {
                                bottomRealHeight = maxHeight;
                            } else if (object instanceof GuideBean) {

                                GuideBean guideBean = (GuideBean) object;
                                GuidePanel panel = new GuidePanel(null, guideBean, maxWidth,
                                        guideBean.getHeight()) {
                                    @Override
                                    public GuidePanel parentGuideWindow() {
                                        return null;
                                    }

                                    @Override
                                    public GuidePanel targetWindowAfterAuth() {
                                        return null;
                                    }
                                };
                                panel.enableButtonByRemote(statusMap);
                                AutoPrinterApp.getClientMain().setTopUI(panel);
                                bottomRealHeight = panel.getCurrentGuideBean().getHeight();
                            }
                        }
                    }.run();

                    return null;
                }

                @Override
                public void onSucceeded(Object object) {
                    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                    int maxHeight = screenSize.height - topRealHeight - bottomRealHeight;

                    final int finalHeight = maxHeight > screenSize.height ? screenSize.height : maxHeight;

                    new OpenGuidePaperTask(Constants.GUIDE_MAIN_FILE) {
                        @Override
                        public void onSucceed(Object object, HashMap<String, Integer> statusMap) {
                            if (object == null || object instanceof Exception) {
                            } else if (object instanceof GuideBean) {
                                GuideBean guideBean = (GuideBean) object;
                                GuidePanel panel = new GuidePanel(null, guideBean, maxWidth,
                                        finalHeight == 0 ? guideBean.getHeight() : finalHeight) {

                                    @Override
                                    public GuidePanel parentGuideWindow() {
                                        return null;
                                    }

                                    @Override
                                    public GuidePanel targetWindowAfterAuth() {
                                        return null;
                                    }
                                };
                                panel.enableButtonByRemote(statusMap);
                                AutoPrinterApp.getClientMain().setWorkUI(panel);
                            }
                        }

                    }.execute();

                }

            }.execute();

        }
    }.execute();

}

From source file:org.eclipse.jubula.rc.swing.tester.adapter.JComboBoxAdapter.java

/**
 * @return the maximal width for the selection; -1 if none available
 * e.g. the preferred width of the combo box itself is 100 pixel although
 * the preferred size of the embedded items is more than two times bigger
 * --> click outside of component (JList) #3013 
 *///from  w w w.j  ava2 s  .  com
private double getMaxWidth() {
    double maxWidth = NO_MAX_WIDTH;
    Dimension d = m_comboBox.getPreferredSize();
    if (d != null) {
        maxWidth = d.getWidth();
    }
    return maxWidth;
}

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

private void doInit() {
    Graph<V, E> graph = getGraph();
    Dimension d = getSize();
    if (graph != null && d != null) {
        currentIteration = 0;/*  w  w  w  . j  av  a2 s.  com*/
        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:KjellDirdalNotepad.java

public void setNormalSize() {
    JScrollPane scrollPane = getScrollPane();
    int x = 0;//  w  w w . j  av a2s .  c  o m
    int y = 0;
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
        Dimension d = scrollPane.getVisibleRect().getSize();
        if (scrollPane.getBorder() != null) {
            d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right,
                    d.getHeight() - scrollInsets.top - scrollInsets.bottom);
        }

        d.setSize(d.getWidth() - 20, d.getHeight() - 20);
        desktop.setAllSize(x, y);
        scrollPane.invalidate();
        scrollPane.validate();
    }
}

From source file:Visualizer.FRWeightedLayout.java

private void doInit() {
    Graph<Functionality.Node, Functionality.Edge> graph = getGraph();
    Dimension d = getSize();
    if (graph != null && d != null) {
        currentIteration = 0;/*w w w.  jav  a 2  s . c o  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:fxts.stations.util.preferences.EditAction.java

public void actionPerformed(ActionEvent aEvent) {
    JButton okButton = UIManager.getInst().createButton();
    JButton cancelButton = UIManager.getInst().createButton();
    final JDialog dialog = new JDialog(mEditorPanel.getParentDialog());
    dialog.setTitle(mEditorPanel.getTitle());
    JPanel editPanel = new JPanel();
    JPanel buttonPanel = new JPanel();
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout());
    //mainPanel.setLayout(new SideLayout());

    //sets button panel
    buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout());
    okButton.setText(mResMan.getString("IDS_OK_BUTTON"));
    //okButton.setPreferredSize(new Dimension(80, 27));
    GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.insets = new Insets(10, 10, 10, 10);
    sideConstraints.gridx = 0;/*w ww  . j  a va2 s .  co  m*/
    sideConstraints.gridy = 0;
    ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.5, 0.0, 0.5, 0.0);
    resizeParameter.setToConstraints(sideConstraints);
    buttonPanel.add(okButton, sideConstraints);
    cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON"));
    //cancelButton.setPreferredSize(new Dimension(80, 27));
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.insets = new Insets(10, 10, 10, 10);
    sideConstraints.gridx = 1;
    sideConstraints.gridy = 0;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.5, 0.0, 0.5, 0.0);
    resizeParameter.setToConstraints(sideConstraints);
    buttonPanel.add(cancelButton, sideConstraints);

    //adds button panel
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.insets = new Insets(10, 10, 10, 10);
    sideConstraints.gridx = 0;
    sideConstraints.gridy = 1;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 1.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    mainPanel.add(buttonPanel, sideConstraints);

    //sets edit panel
    final IEditor editor = mType.getEditor();
    editor.setValue(mValue);
    editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout());
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 0.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    Component editComp = editor.getComponent();

    //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4.
    if (editComp instanceof FontChooser) {
        FontChooser fc = (FontChooser) editComp;
        fc.setNextFocusedComp(okButton);
    }
    editPanel.add(editComp, sideConstraints);

    //adds editor panel
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.gridx = 0;
    sideConstraints.gridy = 0;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 0.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    mainPanel.add(editPanel, sideConstraints);

    //adds main panel
    dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout());
    //dialog.getContentPane().setLayout(new SideLayout());
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.fill = GridBagConstraints.BOTH;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 0.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    dialog.getContentPane().add(mainPanel, sideConstraints);

    //adds listeners to buttons
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            if (editor.getValue().equals(mValue)) {
                //
            } else {
                mValue = editor.getValue();
                mEditorPanel.setValue(mValue);
                mEditorPanel.refreshControls();
                mEditorPanel.setValueChanged(true);
            }
            dialog.setVisible(false);
            dialog.dispose();
        }
    });
    okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "ExitAction");
    okButton.getActionMap().put("ExitAction", new AbstractAction() {
        /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent aEvent) {
            editor.setValue(mValue);
            dialog.setVisible(false);
            dialog.dispose();
        }
    });
    okButton.requestFocus();
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            editor.setValue(mValue);
            dialog.setVisible(false);
            dialog.dispose();
        }
    });
    //dialog.setResizable(false);
    dialog.setModal(true);
    dialog.pack();

    //sets minimal sizes for components
    Dimension dim = mainPanel.getSize();
    mainPanel.setMinimumSize(dim);
    mainPanel.setPreferredSize(dim);

    //sets size of buttons
    Dimension dimOkButton = okButton.getSize();
    Dimension dimCancelButton = cancelButton.getSize();
    int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth()
            : (int) dimCancelButton.getWidth();
    okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight()));
    okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight()));
    cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight()));
    cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight()));
    dialog.setLocationRelativeTo(dialog.getOwner());
    dialog.setVisible(true);
}

From source file:esmska.gui.AboutFrame.java

private void licenseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_licenseButtonActionPerformed
    //show licence
    try {/* ww  w  .j a v  a 2s .c  o  m*/
        logger.fine("Showing license...");
        String license = IOUtils.toString(getClass().getResourceAsStream(RES + "license.txt"), "UTF-8");
        final String agpl = IOUtils.toString(getClass().getResourceAsStream(RES + "gnu-agpl.txt"), "UTF-8");
        license = MiscUtils.escapeHtml(license);
        license = license.replaceAll("GNU Affero General Public License",
                "<a href=\"agpl\">GNU Affero General Public License</a>");

        final JTextPane tp = new JTextPane();
        tp.setContentType("text/html; charset=UTF-8");
        tp.setText("<html><pre>" + license + "</pre></html>");
        tp.setEditable(false);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        tp.setPreferredSize(new Dimension((int) d.getWidth() / 2, (int) d.getHeight() / 2)); //reasonable size
        tp.setCaretPosition(0);
        //make links clickable
        tp.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(final HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    logger.fine("Showing GNU AGPL...");
                    tp.setText(null);
                    tp.setContentType("text/plain");
                    tp.setText(agpl);
                    tp.setCaretPosition(0);
                }
            }
        });

        String option = l10n.getString("AboutFrame.Acknowledge");
        JOptionPane op = new JOptionPane(new JScrollPane(tp), JOptionPane.INFORMATION_MESSAGE,
                JOptionPane.DEFAULT_OPTION, null, new Object[] { option }, option);
        JDialog dialog = op.createDialog(this, l10n.getString("AboutFrame.License"));
        dialog.setResizable(true);
        dialog.pack();
        dialog.setVisible(true);
    } catch (IOException ex) {
        logger.log(Level.WARNING, "Could not show license", ex);
    }
}

From source file:StrokeChooserPanel.java

/**
 * Draws a line using the sample stroke.
 *
 * @param g  the graphics device./*from   w w  w  . j a v a  2  s . com*/
 */
public void paintComponent(final Graphics g) {

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final Dimension size = getSize();
    final Insets insets = getInsets();
    final double xx = insets.left;
    final double yy = insets.top;
    final double ww = size.getWidth() - insets.left - insets.right;
    final double hh = size.getHeight() - insets.top - insets.bottom;

    // calculate point one
    final Point2D one = new Point2D.Double(xx + 6, yy + hh / 2);
    // calculate point two
    final Point2D two = new Point2D.Double(xx + ww - 6, yy + hh / 2);
    // draw a circle at point one
    final Ellipse2D circle1 = new Ellipse2D.Double(one.getX() - 5, one.getY() - 5, 10, 10);
    final Ellipse2D circle2 = new Ellipse2D.Double(two.getX() - 6, two.getY() - 5, 10, 10);

    // draw a circle at point two
    g2.draw(circle1);
    g2.fill(circle1);
    g2.draw(circle2);
    g2.fill(circle2);

    // draw a line connecting the points
    final Line2D line = new Line2D.Double(one, two);
    if (this.stroke != null) {
        g2.setStroke(this.stroke);
        g2.draw(line);
    }

}