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

public JDAC() {
    setTitle("JDAC");

    ImageIcon img = new ImageIcon("logo.png");
    setIconImage(img.getImage());// www  .  j  ava  2 s  .c om

    //setLayout(new FlowLayout());

    mDataset = createDataset("A");

    mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL,
            false, true, false);

    mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"),
            PlotOrientation.VERTICAL, false, true, false);
    mChart.getXYPlot().getDomainAxis().setLowerMargin(0);
    mChart.getXYPlot().getDomainAxis().setUpperMargin(0);
    mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0);
    mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0);

    ChartPanel chartPanel = new ChartPanel(mChart);
    ChartPanel chartLastPanel = new ChartPanel(mLastChart);
    //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );

    XYPlot plot = mChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    plot.setRenderer(renderer);

    XYPlot lastPlot = mLastChart.getXYPlot();
    XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer();
    lastRenderer.setSeriesPaint(0, Color.RED);
    lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f));
    lastPlot.setRenderer(lastRenderer);

    resetChartButton = new JButton("Reset");
    resetChartButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetChart();
        }
    });

    mMenuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenu sensorMenu = new JMenu("Sensor");
    JMenu deviceMenu = new JMenu("Device");
    portSubMenu = new JMenu("Port");
    JMenu helpMenu = new JMenu("Help");

    serialStatusLabel = new JLabel("Disconnected");
    statusLabel = new JLabel("Ready");
    clearStatus = new LabelClear(statusLabel);
    clearStatus.resetTime();

    connectButton = new JMenuItem("Connect");
    disconnectButton = new JMenuItem("Disconnect");
    startButton = new JButton("Start");
    stopButton = new JButton("Stop");
    scanButton = new JMenuItem("Refresh port list");
    exportCSVButton = new JMenuItem("Export data to CSV");
    exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S"));
    exportCSVButton.setMnemonic(KeyEvent.VK_S);
    exportPNGButton = new JMenuItem("Export chart to PNG");

    JPanel optionsPanel = new JPanel(new BorderLayout());

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setAccelerator(KeyStroke.getKeyStroke("control X"));
    exitItem.setMnemonic(KeyEvent.VK_X);

    JMenuItem aboutItem = new JMenuItem("About");
    JMenuItem helpItem = new JMenuItem("Help");
    JMenuItem quickStartItem = new JMenuItem("Quick start");

    lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1));

    ActionListener mSensorListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setSensor(e.getActionCommand());
        }
    };
    ButtonGroup sensorGroup = new ButtonGroup();
    JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Distance");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Voltage");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Generic");
    tmpRadioButton.setSelected(true);
    setSensor("Generic");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);

    connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (selectedPortName == null) {
                setStatus("No port selected");
                return;
            }
            connect(selectedPortName);
        }
    });
    disconnectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            serialStatusLabel.setText("Disconnecting...");
            if (serialPort == null) {
                serialStatusLabel.setText("Disconnected");
                serialConnected = false;
                return;
            }

            stopCollect();
            disconnect();
        }
    });
    scanButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            searchForPorts();
        }
    });
    exportCSVButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveData();
        }
    });
    exportPNGButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exportPNG();
        }
    });
    startButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            startCollect();
        }
    });
    stopButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            stopCollect();
        }
    });
    lastSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            numLastValues = (Integer) lastSpinner.getValue();
            updateLastTitle();
        }
    });
    updateLastTitle();
    exitItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    helpItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new HelpFrame();
        }
    });
    aboutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new AboutFrame();
        }
    });
    quickStartItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new StartFrame();
        }
    });

    fileMenu.add(exportCSVButton);
    fileMenu.add(exportPNGButton);
    fileMenu.addSeparator();
    fileMenu.add(exitItem);
    deviceMenu.add(connectButton);
    deviceMenu.add(disconnectButton);
    deviceMenu.addSeparator();
    deviceMenu.add(portSubMenu);
    deviceMenu.add(scanButton);
    helpMenu.add(quickStartItem);
    helpMenu.add(helpItem);
    helpMenu.add(aboutItem);

    mMenuBar.add(fileMenu);
    mMenuBar.add(sensorMenu);
    mMenuBar.add(deviceMenu);
    mMenuBar.add(helpMenu);

    JPanel controlsPanel = new JPanel();
    controlsPanel.add(startButton);
    controlsPanel.add(stopButton);
    controlsPanel.add(resetChartButton);
    optionsPanel.add(controlsPanel, BorderLayout.LINE_START);

    JPanel lastPanel = new JPanel(new FlowLayout());
    lastPanel.add(new JLabel("Shown values: "));
    lastPanel.add(lastSpinner);
    optionsPanel.add(lastPanel);

    JPanel serialPanel = new JPanel(new FlowLayout());
    serialPanel.add(serialStatusLabel);
    optionsPanel.add(serialPanel, BorderLayout.LINE_END);

    add(optionsPanel, BorderLayout.PAGE_START);

    JPanel mainPanel = new JPanel(new GridLayout(0, 2));
    mainPanel.add(chartPanel);
    mainPanel.add(chartLastPanel);
    add(mainPanel);

    add(statusLabel, BorderLayout.PAGE_END);
    setJMenuBar(mMenuBar);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            dispose();
        }
    });

    setSize(800, 800);
    pack();
    new StartFrame();

    //center on screen
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - getHeight()) / 2);
    setLocation(x, y);

    setVisible(true);
}

From source file:RadialLayout.java

/**
 * This is called when the panel is first displayed, and every time its size
 * changes./*from w w w  . jav  a 2s.  co m*/
 * Note: You CAN'T assume preferredLayoutSize or minimumLayoutSize will be
 * called -- in the case of applets, at least, they probably won't be.
 *
 * @param  parent  the parent.
 * @see LayoutManager
 */
public void layoutContainer(final Container parent) {
    final Insets insets = parent.getInsets();
    final int maxWidth = parent.getSize().width - (insets.left + insets.right);
    final int maxHeight = parent.getSize().height - (insets.top + insets.bottom);
    final int nComps = parent.getComponentCount();
    int x = 0;
    int y = 0;

    // Go through the components' sizes, if neither preferredLayoutSize nor
    // minimumLayoutSize has been called.
    if (this.sizeUnknown) {
        setSizes(parent);
    }

    if (nComps < 2) {
        final Component c = parent.getComponent(0);
        if (c.isVisible()) {
            final Dimension d = c.getPreferredSize();
            c.setBounds(x, y, d.width, d.height);
        }
    } else {
        double radialCurrent = Math.toRadians(90);
        final double radialIncrement = 2 * Math.PI / nComps;
        final int midX = maxWidth / 2;
        final int midY = maxHeight / 2;
        final int a = midX - this.maxCompWidth;
        final int b = midY - this.maxCompHeight;
        for (int i = 0; i < nComps; i++) {
            final Component c = parent.getComponent(i);
            if (c.isVisible()) {
                final Dimension d = c.getPreferredSize();
                x = (int) (midX - (a * Math.cos(radialCurrent)) - (d.getWidth() / 2) + insets.left);
                y = (int) (midY - (b * Math.sin(radialCurrent)) - (d.getHeight() / 2) + insets.top);

                // Set the component's size and position.
                c.setBounds(x, y, d.width, d.height);
            }
            radialCurrent += radialIncrement;
        }
    }
}

From source file:ome.services.ThumbnailCtx.java

/**
 * Bulk loads thumbnail metadata.//from   w  ww .  j  a  va 2  s .  co m
 * @param dimensions X-Y dimensions to bulk load metdata for.
 * @param pixelsIds Pixels IDs to bulk load metadata for.
 * @return List of thumbnail objects with <code>thumbnail.pixels</code> and
 * <code>thumbnail.details.updateEvent</code> loaded.
 */
private List<Thumbnail> bulkLoadMetadata(Dimension dimensions, Set<Long> pixelsIds) {
    Parameters params = new Parameters();
    params.addInteger("x", (int) dimensions.getWidth());
    params.addInteger("y", (int) dimensions.getHeight());
    params.addLong("o_id", userId);
    params.addIds(pixelsIds);
    StopWatch s1 = new CommonsLogStopWatch("omero.bulkLoadMetadata");
    List<Thumbnail> toReturn = queryService.findAllByQuery("select t from Thumbnail as t " + "join t.pixels "
            + "join fetch t.details.updateEvent " + "where t.sizeX = :x and t.sizeY = :y "
            + "and t.details.owner.id = :o_id " + "and t.pixels.id in (:ids)", params);
    s1.stop();
    return toReturn;
}

From source file:ome.services.ThumbnailCtx.java

/**
 * Bulk loads thumbnail metadata that is owned by the owner of the Pixels
 * set..//from w  w  w .j  ava2 s. co m
 * @param dimensions X-Y dimensions to bulk load metadata for.
 * @param pixelsIds Pixels IDs to bulk load metadata for.
 * @return List of thumbnail objects with <code>thumbnail.pixels</code> and
 * <code>thumbnail.details.updateEvent</code> loaded.
 */
private List<Thumbnail> bulkLoadOwnerMetadata(Dimension dimensions, Set<Long> pixelsIds) {
    Parameters params = new Parameters();
    params.addInteger("x", (int) dimensions.getWidth());
    params.addInteger("y", (int) dimensions.getHeight());
    params.addIds(pixelsIds);
    StopWatch s1 = new CommonsLogStopWatch("omero.bulkLoadOwnerMetadata");
    List<Thumbnail> toReturn = queryService
            .findAllByQuery(
                    "select t from Thumbnail as t " + "join t.pixels as p "
                            + "join fetch t.details.updateEvent " + "where t.sizeX = :x and t.sizeY = :y "
                            + "and t.details.owner.id = p.details.owner.id " + "and t.pixels.id in (:ids)",
                    params);
    s1.stop();
    return toReturn;
}

From source file:org.ash.gui.MainFrame.java

/**
 * Instantiates a new main frame.//w w w .j a v a2 s. com
 */
public MainFrame() {
    super();
    Options.getInstance().setDateFormat("dd.MM.yyyy hh:mm:ss");
    Options.getInstance().setLanguage(Locale.getDefault().getLanguage());
    Options.getInstance().setJtextAreaSqlTextGanttHAndDetailsH();

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    this.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight() - 24);
    this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    JFrame.setDefaultLookAndFeelDecorated(true);

    this.setExtendedState(this.getExtendedState() | Frame.MAXIMIZED_BOTH);

    // retrieve the HashMap of Default properties.  
    //UIDefaults uiDefs = UIManager.getDefaults();

    // Set indent for SQL plan JTreeTable.  
    //uiDefs.put("Tree.leftChildIndent" , new Integer( 1 ) ); 
    //uiDefs.put("Tree.rightChildIndent" , new Integer( 8 ) );  

    try {
        jbInit();
        menuFileNewConn_actionPerformed(null);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryBrowser.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *///from  www  . j a  va  2  s  .co m
private static void createAndShowGUI() {
    try {
        String callbackHandlerClassName = ProviderProperties.getInstance().getProperty(
                "jaxr-ebxml.security.jaas.callbackHandlerClassName",
                System.getProperty("jaxr-ebxml.security.jaas.callbackHandlerClassName"));

        if ((callbackHandlerClassName == null) || (callbackHandlerClassName.length() == 0)) {
            System.setProperty("jaxr-ebxml.security.jaas.callbackHandlerClassName",
                    "it.cnr.icar.eric.client.xml.registry.jaas.DialogAuthenticationCallbackHandler");
        }

        // By default JDialog and JFrame will not follow theme changes.
        // JDialog.setDefaultLookAndFeelDecorated(true);
        // JFrame.setDefaultLookAndFeelDecorated(true);
        // I18N: Do not localize next statement.
        System.setProperty("sun.awt.noerasebackground", "true");
        MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
        // I18N: Do not localize next statement.
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        // Create a new instance of our application's frame, and make it
        // visible.
        RegistryBrowser browser = getInstance();

        browser.pack();

        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        browser.setBounds(0, 0, (int) (dim.getWidth()), (int) (dim.getHeight()));

        browser.setVisible(true);
    } catch (Throwable t) {
        log.fatal(t);
        t.printStackTrace();

        // Ensure the application exits with an error condition.
        System.exit(1);
    }
}

From source file:hydrograph.ui.graph.figure.ComponentFigure.java

private void showStatusToolTip(org.eclipse.swt.graphics.Point location) {

    if (!componentCanvas.isFocused())
        return;//from  w w w.ja v  a2s.c o  m

    componentCanvas = getComponentCanvas();
    if (componentCanvas.getComponentTooltip() == null) {
        componentToolTip = getStatusToolTip(componentCanvas.getCanvasControl().getShell(), location);
        componentBounds = getComponentBounds();
        componentCanvas.issueToolTip(componentToolTip, componentBounds);

        componentToolTip.setVisible(true);
        setStatusToolTipFocusListener();
        org.eclipse.swt.graphics.Point tooltipSize = componentToolTip.computeSizeHint();
        // componentToolTip.setSizeConstraints(300, 100);
        if (tooltipSize.x > 300) {
            tooltipSize.x = 300;
        }
        componentToolTip.setSize(tooltipSize.x, tooltipSize.y);

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

        int newX, newY;
        int offset = 10;
        if ((componentToolTip.getBounds().x + componentToolTip.getBounds().width) > width) {
            newX = componentToolTip.getBounds().x
                    - (int) ((componentToolTip.getBounds().x + componentToolTip.getBounds().width) - width)
                    - offset;
        } else {
            newX = componentToolTip.getBounds().x;
        }

        if ((componentToolTip.getBounds().y + componentToolTip.getBounds().height) > height) {
            newY = componentToolTip.getBounds().y - getBounds().height - componentToolTip.getBounds().height
                    - offset;
        } else {
            newY = componentToolTip.getBounds().y;
        }
        org.eclipse.swt.graphics.Point newLocation = new org.eclipse.swt.graphics.Point(newX, newY);
        componentToolTip.setLocation(newLocation);

    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (getChart() == null) {
        return;//from  w  w w  . jav  a2s  .c om
    }
    Graphics2D g2 = (Graphics2D) g.create();

    // first determine the size of the chart rendering area...
    Dimension size = getSize();
    Insets insets = getInsets();
    Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
            size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom);

    // work out if scaling is required...
    boolean scale = false;
    double drawWidth = available.getWidth();
    double drawHeight = available.getHeight();
    setChartFieldValue(getChartFieldByName("scaleX"), 1.0);
    // this.scaleX = 1.0;
    setChartFieldValue(getChartFieldByName("scaleY"), 1.0);
    // this.scaleY = 1.0;

    if (drawWidth < getMinimumDrawWidth()) {
        setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth());
        // this.scaleX = drawWidth / getMinimumDrawWidth();
        drawWidth = getMinimumDrawWidth();
        scale = true;
    } else if (drawWidth > getMaximumDrawWidth()) {
        setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth());
        // this.scaleX = drawWidth / getMaximumDrawWidth();
        drawWidth = getMaximumDrawWidth();
        scale = true;
    }

    if (drawHeight < getMinimumDrawHeight()) {
        setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight());
        // this.scaleY = drawHeight / getMinimumDrawHeight();
        drawHeight = getMinimumDrawHeight();
        scale = true;
    } else if (drawHeight > getMaximumDrawHeight()) {
        setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight());
        // this.scaleY = drawHeight / getMaximumDrawHeight();
        drawHeight = getMaximumDrawHeight();
        scale = true;
    }

    Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight);

    // are we using the chart buffer?
    if ((Boolean) getChartFieldValueByName("useBuffer")) {

        // do we need to resize the buffer?
        if ((getChartFieldValueByName("chartBuffer") == null)
                || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth())
                || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) {
            setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth());
            // this.chartBufferWidth = (int) available.getWidth();
            setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight());
            // this.chartBufferHeight = (int) available.getHeight();
            GraphicsConfiguration gc = g2.getDeviceConfiguration();
            setChartFieldValue(getChartFieldByName("chartBuffer"),
                    gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"),
                            (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT));
            // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth,
            // this.chartBufferHeight, Transparency.TRANSLUCENT);
            setRefreshBuffer(true);
        }

        // do we need to redraw the buffer?
        if (getRefreshBuffer()) {

            setRefreshBuffer(false); // clear the flag

            Rectangle2D bufferArea = new Rectangle2D.Double(0, 0,
                    (Integer) getChartFieldValueByName("chartBufferWidth"),
                    (Integer) getChartFieldValueByName("chartBufferHeight"));

            Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics();
            Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"),
                    (Integer) getChartFieldValueByName("chartBufferHeight"));
            bufferG2.setPaint(getBackground());
            bufferG2.fill(r);
            if (scale) {
                AffineTransform saved = bufferG2.getTransform();
                AffineTransform st = AffineTransform.getScaleInstance(
                        (Double) getChartFieldValueByName("scaleX"),
                        (Double) getChartFieldValueByName("scaleY"));
                bufferG2.transform(st);
                getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo());
                bufferG2.setTransform(saved);
            } else {
                getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo());
            }

        }

        // zap the buffer onto the panel...
        g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this);

    }

    // or redrawing the chart every time...
    else {

        AffineTransform saved = g2.getTransform();
        g2.translate(insets.left, insets.top);
        if (scale) {
            AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"),
                    (Double) getChartFieldValueByName("scaleY"));
            g2.transform(st);
        }
        getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo());
        g2.setTransform(saved);

    }

    Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator();
    while (iterator.hasNext()) {
        Overlay overlay = (Overlay) iterator.next();
        overlay.paintOverlay(g2, this);
    }

    // redraw the zoom rectangle (if present) - if useBuffer is false,
    // we use XOR so we can XOR the rectangle away again without redrawing
    // the chart
    drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer"));

    g2.dispose();

    setAnchor(null);
    setVerticalTraceLine(null);
    setHorizontalTraceLine(null);
}

From source file:org.martus.client.swingui.PureFxMainWindow.java

@Override
public void createAndShowModalDialog(FxShellController controller, Dimension preferedDimension, String titleTag)
        throws Exception {
    PureFxDialogStage dialogStage = new PureFxDialogStage(this, controller);
    if (preferedDimension != null) {
        dialogStage.getActualStage().setHeight(preferedDimension.getHeight());
        dialogStage.getActualStage().setWidth(preferedDimension.getWidth());
    }/*from  w  w  w .j  a  v a  2 s .c om*/
    dialogStage.showCurrentPage();
    updateIcon();
    dialogStage.showAndWait();
}

From source file:org.pentaho.di.trans.steps.exceloutput.ExcelOutput.java

private void setFonts() throws Exception {
    // --- Set Header font
    int headerFontSize = Const.toInt(environmentSubstitute(meta.getHeaderFontSize()),
            ExcelOutputMeta.DEFAULT_FONT_SIZE);
    // Set font name
    FontName headerFontName = ExcelFontMap.getFontName(meta.getHeaderFontName());
    // Set UnderlineStyle
    UnderlineStyle underline = ExcelFontMap.getUnderlineStyle(meta.getHeaderFontUnderline());

    WritableFont writableHeaderFont = null;
    if (meta.isHeaderFontBold()) {
        writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.BOLD,
                meta.isHeaderFontItalic(), underline);
    } else {// ww w .  ja v a 2s  .c om
        writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.NO_BOLD,
                meta.isHeaderFontItalic(), underline);
    }

    // Header font color
    Colour fontHeaderColour = ExcelFontMap.getColour(meta.getHeaderFontColor(), Colour.BLACK);
    if (!fontHeaderColour.equals(Colour.BLACK)) {
        writableHeaderFont.setColour(fontHeaderColour);
    }
    data.headerCellFormat = new WritableCellFormat(writableHeaderFont);

    // Header background color
    if (meta.getHeaderBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) {
        data.headerCellFormat.setBackground(ExcelFontMap.getColour(meta.getHeaderBackGroundColor(), null));
    }

    // Set alignment
    data.headerCellFormat = ExcelFontMap.getAlignment(meta.getHeaderAlignment(), data.headerCellFormat);
    data.headerCellFormat = ExcelFontMap.getOrientation(meta.getHeaderFontOrientation(), data.headerCellFormat);

    // Do we need to put a image on the header
    if (!Const.isEmpty(data.realHeaderImage)) {
        FileObject imageFile = null;
        try {
            imageFile = KettleVFS.getFileObject(data.realHeaderImage);
            if (!imageFile.exists()) {
                throw new KettleException(
                        BaseMessages.getString(PKG, "ExcelInputLog.ImageFileNotExists", data.realHeaderImage));
            }
            data.realHeaderImage = KettleVFS.getFilename(imageFile);
            // Put an image
            Dimension m = ExcelFontMap.getImageDimension(data.realHeaderImage);
            data.headerImageWidth = m.getWidth() * 0.016;
            data.headerImageHeight = m.getHeight() * 0.0625;

            byte[] imageData = new byte[(int) imageFile.getContent().getSize()];
            KettleVFS.getInputStream(imageFile).read(imageData);

            data.headerImage = new WritableImage(0, 0, data.headerImageWidth, data.headerImageHeight,
                    imageData);
        } catch (Exception e) {
            throw new KettleException(e);
        } finally {
            if (imageFile != null) {
                try {
                    imageFile.close();
                } catch (Exception e) {
                    // Ignore;
                }
            }
        }
    }

    // --- Set rows font
    // Set font size
    int rowFontSize = Const.toInt(environmentSubstitute(meta.getRowFontSize()),
            ExcelOutputMeta.DEFAULT_FONT_SIZE);
    // Set font name
    FontName rowFontName = ExcelFontMap.getFontName(meta.getRowFontName());

    data.writableFont = new WritableFont(rowFontName, rowFontSize, WritableFont.NO_BOLD, false,
            UnderlineStyle.NO_UNDERLINE);

    // Row font color
    Colour rowFontColour = ExcelFontMap.getColour(meta.getRowFontColor(), Colour.BLACK);
    if (!fontHeaderColour.equals(Colour.BLACK)) {
        data.writableFont.setColour(rowFontColour);
    }

    // Set rows background color if needed
    if (meta.getRowBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) {
        data.rowFontBackgoundColour = ExcelFontMap.getColour(meta.getRowBackGroundColor(), null);
    }
}