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:de.bfs.radon.omsimulation.gui.OMPanelData.java

/**
 * Initialises the interface of the data panel.
 *///from  w w  w .j a va2 s.co m
protected void initialize() {
    setLayout(null);

    lblExportChartTo = new JLabel("Export chart to ...");
    lblExportChartTo.setBounds(436, 479, 144, 14);
    lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblExportChartTo.setVisible(false);
    add(lblExportChartTo);

    btnCsv = new JButton("CSV");
    btnCsv.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String csv;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("csv")) {
                    csv = "";
                } else {
                    csv = ".csv";
                }
                String csvPath = file.getAbsolutePath() + csv;
                OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem();
                double[] selectedValues = selectedRoom.getValues();
                File csvFile = new File(csvPath);
                try {
                    FileWriter logWriter = new FileWriter(csvFile);
                    BufferedWriter csvOutput = new BufferedWriter(logWriter);
                    csvOutput.write("\"ID\";\"" + selectedRoom.getId() + "\"");
                    csvOutput.newLine();
                    for (int i = 0; i < selectedValues.length; i++) {
                        csvOutput.write("\"" + i + "\";\"" + (int) selectedValues[i] + "\"");
                        csvOutput.newLine();
                    }
                    JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                    csvOutput.close();
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnCsv.setBounds(590, 475, 70, 23);
    btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnCsv.setVisible(false);
    add(btnCsv);

    btnPdf = new JButton("PDF");
    btnPdf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf"));
            fileDialog.showSaveDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String pdf;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("pdf")) {
                    pdf = "";
                } else {
                    pdf = ".pdf";
                }
                String pdfPath = file.getAbsolutePath() + pdf;
                OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                String title = building.getName();
                OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem();
                JFreeChart chart = OMCharts.createRoomChart(title, selectedRoom, false);
                int height = (int) PageSize.A4.getWidth();
                int width = (int) PageSize.A4.getHeight();
                try {
                    OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title);
                    JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success",
                            JOptionPane.INFORMATION_MESSAGE);
                } catch (IOException ioe) {
                    JOptionPane.showMessageDialog(null,
                            "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed",
                            JOptionPane.ERROR_MESSAGE);
                    ioe.printStackTrace();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!",
                        "Failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    btnPdf.setBounds(670, 475, 70, 23);
    btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnPdf.setVisible(false);
    add(btnPdf);

    lblSelectProject = new JLabel("Select Project");
    lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblSelectProject.setBounds(10, 65, 132, 14);
    add(lblSelectProject);

    lblSelectRoom = new JLabel("Select Room");
    lblSelectRoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblSelectRoom.setBounds(10, 94, 132, 14);
    add(lblSelectRoom);

    panelData = new JPanel();
    panelData.setBounds(10, 118, 730, 347);
    add(panelData);

    btnRefresh = new JButton("Load");
    btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnRefresh.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("")
                    && !txtOmbFile.getText().equals(" ")) {
                txtOmbFile.setBackground(Color.WHITE);
                String ombPath = txtOmbFile.getText();
                String omb;
                String[] tmpFileName = ombPath.split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(ombPath + omb);
                setOmbFile(ombPath + omb);
                File ombFile = new File(ombPath + omb);
                if (ombFile.exists()) {
                    txtOmbFile.setBackground(Color.WHITE);
                    btnRefresh.setEnabled(false);
                    comboBoxProjects.setEnabled(false);
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    btnPdf.setVisible(false);
                    btnCsv.setVisible(false);
                    lblExportChartTo.setVisible(false);
                    progressBar.setVisible(true);
                    progressBar.setStringPainted(true);
                    progressBar.setIndeterminate(true);
                    refreshProjectsTask = new RefreshProjects();
                    refreshProjectsTask.execute();
                } else {
                    txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                    JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!",
                            "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                txtOmbFile.setBackground(new Color(255, 222, 222, 128));
                JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    });
    btnRefresh.setBounds(616, 61, 124, 23);
    add(btnRefresh);

    btnMaximize = new JButton("Fullscreen");
    btnMaximize.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnMaximize.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxRooms.isEnabled()) {
                if (comboBoxRooms.getSelectedItem() != null) {
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    String title = building.getName();
                    OMRoom room = (OMRoom) comboBoxRooms.getSelectedItem();
                    panelRoom = createRoomPanel(title, room, false, false);
                    JFrame chartFrame = new JFrame();
                    JPanel chartPanel = createRoomPanel(title, room, false, true);
                    chartFrame.getContentPane().add(chartPanel);
                    chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                    chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight());
                    chartFrame.setTitle("OM Simulation Tool: " + title + ", Room " + room.getId());
                    chartFrame.setResizable(true);
                    chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    chartFrame.setVisible(true);
                }
            }
        }
    });
    btnMaximize.setBounds(10, 475, 124, 23);
    btnMaximize.setVisible(false);
    add(btnMaximize);

    comboBoxProjects = new JComboBox<OMBuilding>();
    comboBoxProjects.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    comboBoxProjects.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled()) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRooms.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRooms.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRooms.addItem(building.getCellars()[i]);
                    }
                    for (int i = 0; i < building.getMiscs().length; i++) {
                        comboBoxRooms.addItem(building.getMiscs()[i]);
                    }
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRoom.setEnabled(b);
            panelData.setEnabled(b);
            btnMaximize.setVisible(b);
            comboBoxRooms.setEnabled(b);
            panelData.setBackground(c);
        }
    });
    comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled()) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRooms.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRooms.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRooms.addItem(building.getCellars()[i]);
                    }
                    for (int i = 0; i < building.getMiscs().length; i++) {
                        comboBoxRooms.addItem(building.getMiscs()[i]);
                    }
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRoom.setEnabled(b);
            panelData.setEnabled(b);
            btnMaximize.setVisible(b);
            comboBoxRooms.setEnabled(b);
            panelData.setBackground(c);
        }
    });
    comboBoxProjects.setBounds(152, 61, 454, 22);
    add(comboBoxProjects);

    comboBoxRooms = new JComboBox<OMRoom>();
    comboBoxRooms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    comboBoxRooms.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (comboBoxRooms.isEnabled()) {
                if (comboBoxRooms.getSelectedItem() != null) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    remove(panelData);
                    comboBoxRooms.setEnabled(false);
                    refreshChartsTask = new RefreshCharts();
                    refreshChartsTask.execute();
                }
            }
        }
    });
    comboBoxRooms.setBounds(152, 90, 454, 22);
    add(comboBoxRooms);

    progressBar = new JProgressBar();
    progressBar.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    progressBar.setBounds(10, 475, 730, 23);
    progressBar.setVisible(false);
    add(progressBar);

    lblSelectRoom.setEnabled(false);
    panelData.setEnabled(false);
    comboBoxRooms.setEnabled(false);

    lblHelp = new JLabel(
            "Select an OMB-Object file to analyse its data. You can inspect radon concentration for each room.");
    lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblHelp.setForeground(Color.GRAY);
    lblHelp.setBounds(10, 10, 730, 14);
    add(lblHelp);

    txtOmbFile = new JTextField();
    txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    txtOmbFile.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent arg0) {
            setOmbFile(txtOmbFile.getText());
        }
    });
    txtOmbFile.setBounds(152, 33, 454, 20);
    add(txtOmbFile);
    txtOmbFile.setColumns(10);

    btnBrowse = new JButton("Browse");
    btnBrowse.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    btnBrowse.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser fileDialog = new JFileChooser();
            fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb"));
            fileDialog.showOpenDialog(getParent());
            final File file = fileDialog.getSelectedFile();
            if (file != null) {
                String omb;
                String[] tmpFileName = file.getAbsolutePath().split("\\.");
                if (tmpFileName[tmpFileName.length - 1].equals("omb")) {
                    omb = "";
                } else {
                    omb = ".omb";
                }
                txtOmbFile.setText(file.getAbsolutePath() + omb);
                setOmbFile(file.getAbsolutePath() + omb);
            }
        }
    });
    btnBrowse.setBounds(616, 32, 124, 23);
    add(btnBrowse);

    lblSelectOmbfile = new JLabel("Select OMB-File");
    lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11));
    lblSelectOmbfile.setBounds(10, 36, 132, 14);
    add(lblSelectOmbfile);
}

From source file:com.sshtools.common.ui.SshToolsApplicationFrame.java

/**
 *
 *
 * @param application/*w  w  w . j a v  a2s . c o  m*/
 * @param panel
 *
 * @throws SshToolsApplicationException
 */
public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    this.panel = panel;
    this.application = application;

    if (application != null) {
        setTitle(ConfigurationLoader.getVersionString(application.getApplicationName(),
                application.getApplicationVersion())); // + " " + application.getApplicationVersion());
    }

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    // Register the File menu
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));

        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));

        // Register the Help menu
    }
    panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 99));

    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));

    }

    // Register the Changelog box action
    if (showChangelogBox && application != null) {
        panel.registerAction(changelogAction = new ChangelogAction(this, application));

    }
    panel.registerAction(faqAction = new FAQAction());
    panel.registerAction(beginnerAction = new BeginnerAction());
    panel.registerAction(advancedAction = new AdvancedAction());

    getApplicationPanel().rebuildActionComponents();

    JPanel p = new JPanel(new BorderLayout());

    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        JPanel t = new JPanel(new BorderLayout());
        t.add(panel.getToolBar(), BorderLayout.NORTH);
        t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH);
        toolSeparator.setVisible(panel.getToolBar().isVisible());

        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {
            public void componentHidden(ComponentEvent evt) {
                log.debug("Tool separator is now " + pnl.getToolBar().isVisible());
                toolSeparator.setVisible(pnl.getToolBar().isVisible());
            }
        });
        p.add(t, BorderLayout.NORTH);
    }

    p.add(panel, BorderLayout.CENTER);

    if (panel.getStatusBar() != null) {
        p.add(panel.getStatusBar(), BorderLayout.SOUTH);
    }

    getContentPane().setLayout(new GridLayout(1, 1));
    getContentPane().add(p);

    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }

            }
        }
    });

    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;

    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);

            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());

                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;

                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }

                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }

                setLocation(newLocation);
                found = true;
            }
        }
    }

    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
}

From source file:io.github.dsheirer.spectrum.SpectrumPanel.java

/**
 * Draws the current fft spectrum with a line and a gradient fill.
 *///  w  ww  . j a v a2  s .  c o m
private void drawSpectrum(Graphics2D graphics) {
    Dimension size = getSize();

    //Draw the background
    Rectangle background = new Rectangle(0, 0, size.width, size.height);
    graphics.setColor(mColorSpectrumBackground);
    graphics.draw(background);
    graphics.fill(background);

    //Define the gradient
    GradientPaint gradient = new GradientPaint(0, (getSize().height - mSpectrumInset) / 2,
            mColorSpectrumGradientTop, 0, getSize().height, mColorSpectrumGradientBottom);

    graphics.setBackground(mColorSpectrumBackground);

    GeneralPath spectrumShape = new GeneralPath();

    //Start at the lower right inset point
    spectrumShape.moveTo(size.getWidth(), size.getHeight() - mSpectrumInset);

    //Draw to the lower left
    spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);

    float[] bins = getBins();

    //If we have FFT data to display ...
    if (bins != null) {
        float insideHeight = size.height - mSpectrumInset;

        float scalor = insideHeight / -mDBScale;

        /* Calculate based on bin size - 1, since bin 0 is rendered at zero
           * and the last bin is rendered at the width */
        float binSize = (float) size.width / ((float) (bins.length));

        for (int x = 0; x < bins.length; x++) {
            float height;

            height = bins[x] * scalor;

            if (height > insideHeight) {
                height = insideHeight;
            }

            if (height < 0) {
                height = 0;
            }

            float xAxis = (float) x * binSize;

            spectrumShape.lineTo(xAxis, height);
        }
    }
    //Otherwise show an empty spectrum
    else {
        //Draw Left Size
        graphics.setPaint(gradient);
        spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);
        //Draw Middle
        spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset);
    }

    //Draw Right Side
    spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset);

    graphics.setPaint(gradient);
    graphics.draw(spectrumShape);
    graphics.fill(spectrumShape);

    graphics.setPaint(mColorSpectrumLine);

    //Draw the bottom line under the spectrum
    graphics.draw(new Line2D.Float(0, size.height - mSpectrumInset, size.width, size.height - mSpectrumInset));
}

From source file:com.sshtools.appframework.ui.SshToolsApplicationFrame.java

/**
 * @param application/* w  w w. j  a v  a2  s  .c  o m*/
 * @param panel
 * 
 * @throws SshToolsApplicationException
 */

public void init(final SshToolsApplication application, SshToolsApplicationPanel panel)
        throws SshToolsApplicationException {
    log.debug("Initialising frame");
    this.panel = panel;
    this.application = application;
    if (application != null) {
        setTitle(application.getApplicationName() + " - " + application.getApplicationVersion());
    }
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    // Register the File menu
    panel.registerActionMenu(new ActionMenu("File", "File", 'f', 0));
    // Register the Exit action
    if (showExitAction && application != null) {
        panel.registerAction(exitAction = new ExitAction(application, this));
        // Register the New Window Action
    }
    if (showNewWindowAction && application != null) {
        panel.registerAction(newWindowAction = new NewWindowAction(application));
        // Register the Help menu
    }
    panel.registerActionMenu(new ActionMenu("Help", "Help", 'h', 99));
    // Register the About box action
    if (showAboutBox && application != null) {
        panel.registerAction(aboutAction = new AboutAction(this, application));
    }

    getApplicationPanel().rebuildActionComponents();
    // JPanel p = new JPanel(new ToolBarLayout());
    JPanel p = new JPanel(new BorderLayout(0, 0));
    JPanel center = new JPanel(new BorderLayout(0, 0));
    if (panel.getJMenuBar() != null) {
        setJMenuBar(panel.getJMenuBar());
    }

    if (panel.getToolBar() != null) {
        // center.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL),
        // BorderLayout.NORTH);
        // toolSeparator.setVisible(panel.getToolBar().isVisible());
        // panel.getToolBar().addComponentListener(new ComponentAdapter() {
        // public void componentShown(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // public void componentHidden(ComponentEvent e) {
        // toolSeparator.setVisible(SshToolsApplicationFrame.this.panel.getToolBar().isVisible());
        // }
        //
        // });
        final SshToolsApplicationPanel pnl = panel;
        panel.getToolBar().addComponentListener(new ComponentAdapter() {

            public void componentHidden(ComponentEvent evt) {
                // toolSeparator.setVisible(pnl.getToolBar().isVisible());

            }

        });
        p.add(panel.getToolBar(), BorderLayout.NORTH);
    }
    center.add(panel, BorderLayout.CENTER);
    p.add(center, BorderLayout.CENTER);
    getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
    getContentPane().add(p);
    // Watch for the frame closing
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent evt) {
            if (application != null) {
                application.closeContainer(SshToolsApplicationFrame.this);
            } else {
                int confirm = JOptionPane.showOptionDialog(SshToolsApplicationFrame.this,
                        "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (confirm == 0) {
                    hide();
                }
            }

        }

    });
    // If this is the first frame, center the window on the screen
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    boolean found = false;
    if (application != null && application.getContainerCount() != 0) {
        for (int i = 0; (i < application.getContainerCount()) && !found; i++) {
            SshToolsApplicationContainer c = application.getContainerAt(i);
            if (c instanceof SshToolsApplicationFrame) {
                SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
                setSize(f.getSize());
                Point newLocation = new Point(f.getX(), f.getY());
                newLocation.x += 48;
                newLocation.y += 48;
                if (newLocation.x > (screenSize.getWidth() - 64)) {
                    newLocation.x = 0;
                }
                if (newLocation.y > (screenSize.getHeight() - 64)) {
                    newLocation.y = 0;
                }
                setLocation(newLocation);
                found = true;
            }
        }
    }
    if (!found) {
        // Is there a previous stored geometry we can use?
        if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
            setBounds(PreferencesStore.getRectangle(PREF_LAST_FRAME_GEOMETRY, getBounds()));
        } else {
            pack();
            setSize(800, 600);
            UIUtil.positionComponent(SwingConstants.CENTER, this);
        }
    }
    log.debug("Initialisation of frame complete");
}

From source file:org.apache.jmeter.visualizers.StatGraphVisualizer.java

public void makeGraph() {
    nbColToGraph = getNbColumns();//from  w  w  w.j  a v  a 2  s .c  o m
    Dimension size = graphPanel.getSize();
    String lstr = maxLengthXAxisLabel.getText();
    // canvas size
    int width = (int) size.getWidth();
    int height = (int) size.getHeight();
    if (!dynamicGraphSize.isSelected()) {
        String wstr = graphWidth.getText();
        String hstr = graphHeight.getText();
        if (wstr.length() != 0) {
            width = Integer.parseInt(wstr);
        }
        if (hstr.length() != 0) {
            height = Integer.parseInt(hstr);
        }
    }

    if (lstr.length() == 0) {
        lstr = "20";//$NON-NLS-1$
    }
    int maxLength = Integer.parseInt(lstr);
    String yAxisStr = maxValueYAxisLabel.getText();
    int maxYAxisScale = yAxisStr.length() == 0 ? 0 : Integer.parseInt(yAxisStr);

    graphPanel.setData(this.getData());
    graphPanel.setTitle(graphTitle.getText());
    graphPanel.setMaxLength(maxLength);
    graphPanel.setMaxYAxisScale(maxYAxisScale);
    graphPanel.setXAxisLabels(getAxisLabels());
    graphPanel.setXAxisTitle(JMeterUtils.getResString((String) columnsList.getSelectedItem()));
    graphPanel.setYAxisLabels(this.yAxisLabel);
    graphPanel.setYAxisTitle(this.yAxisTitle);
    graphPanel.setLegendLabels(getLegendLabels());
    graphPanel.setColor(getBackColors());
    graphPanel.setForeColor(colorForeGraph);
    graphPanel.setOutlinesBarFlag(drawOutlinesBar.isSelected());
    graphPanel.setShowGrouping(numberShowGrouping.isSelected());
    graphPanel.setValueOrientation(valueLabelsVertical.isSelected());
    graphPanel.setLegendPlacement(
            StatGraphProperties.getPlacementNameMap().get(legendPlacementList.getSelectedItem()).intValue());

    graphPanel.setTitleFont(
            new Font(StatGraphProperties.getFontNameMap().get(titleFontNameList.getSelectedItem()),
                    StatGraphProperties.getFontStyleMap().get(titleFontStyleList.getSelectedItem()).intValue(),
                    Integer.parseInt((String) titleFontSizeList.getSelectedItem())));
    graphPanel.setLegendFont(new Font(StatGraphProperties.getFontNameMap().get(fontNameList.getSelectedItem()),
            StatGraphProperties.getFontStyleMap().get(fontStyleList.getSelectedItem()).intValue(),
            Integer.parseInt((String) fontSizeList.getSelectedItem())));
    graphPanel.setValueFont(
            new Font(StatGraphProperties.getFontNameMap().get(valueFontNameList.getSelectedItem()),
                    StatGraphProperties.getFontStyleMap().get(valueFontStyleList.getSelectedItem()).intValue(),
                    Integer.parseInt((String) valueFontSizeList.getSelectedItem())));

    graphPanel.setHeight(height);
    graphPanel.setWidth(width);
    spane.repaint();
}

From source file:ome.services.ThumbnailCtx.java

/**
 * Creates metadata for a thumbnail of a given set of pixels set and X-Y
 * dimensions.//from  w  w  w . j av  a 2 s .  co  m
 * 
 * @param pixels The Pixels set to create thumbnail metadata for.
 * @param dimensions The dimensions of the thumbnail.
 * 
 * @return the thumbnail metadata as created.
 * @see getThumbnailMetadata()
 */
public Thumbnail createThumbnailMetadata(Pixels pixels, Dimension dimensions) {
    // Unload the pixels object to avoid transactional headaches
    Pixels unloadedPixels = new Pixels(pixels.getId(), false);
    Thumbnail thumb = new Thumbnail();
    thumb.setPixels(unloadedPixels);
    thumb.setMimeType(DEFAULT_MIME_TYPE);
    thumb.setSizeX((int) dimensions.getWidth());
    thumb.setSizeY((int) dimensions.getHeight());
    return thumb;
}

From source file:com.mightypocket.ashot.Mediator.java

private void updateImageProcessor(final ImageEx img) {
    final boolean ls = isLandscape();
    if (isScaleFit()) {
        Dimension customBounds = presenter.getPresenterDimension();

        int w = img.getValue().getWidth(null);
        int h = img.getValue().getHeight(null);

        if (landscape != img.isLandscape()) {
            final int t = w;
            w = h;//from w  w w.j a  va 2 s . c o  m
            h = t;
        }

        double scale = Math.min(customBounds.getWidth() / w, customBounds.getHeight() / h);
        imageProcessor.setScale(scale);
    }

    final boolean ccw = p.getBoolean(PREF_ROTATION_CCW, true);

    if (ls != img.isLandscape()) {
        if (ccw == img.isCcw()) {
            if (ccw)
                imageProcessor.setRotation(ls ? ImageProcessor.Rotation.R270 : ImageProcessor.Rotation.R90);
            else
                imageProcessor.setRotation(ls ? ImageProcessor.Rotation.R90 : ImageProcessor.Rotation.R270);
        } else {
            if (ls) {
                imageProcessor.setRotation(ccw ? ImageProcessor.Rotation.R270 : ImageProcessor.Rotation.R90);
            } else {
                imageProcessor
                        .setRotation(img.isCcw() ? ImageProcessor.Rotation.R90 : ImageProcessor.Rotation.R270);
            }
        }
    } else {
        if (ccw == img.isCcw()) {
            imageProcessor.setRotation(ImageProcessor.Rotation.R0);
        } else {
            imageProcessor.setRotation(ls ? ImageProcessor.Rotation.R180 : ImageProcessor.Rotation.R0);
        }
    }
}

From source file:org.safs.selenium.webdriver.CFComponent.java

/** @return Rectangle, the rectangle relative to the browser. 
 * //from w  w w .  j av a  2  s.  c o m
 * If this return 'absolute rectangle on screen', we SHOULD remove override method {@link #getRectangleImage(Rectangle)}.<br>
 * But we need to be careful, Robot will be used to get image, we have to implement RMI to get image if the <br>
 * browser is running on a remote machine.<br>
 */
protected Rectangle getComponentRectangle() {
    String debugmsg = StringUtils.debugmsg(false);
    WebElement component = (compObject != null ? compObject : winObject);
    try {
        //Get component's location relative to the browser
        Point p = WDLibrary.getLocation(component, false);
        org.openqa.selenium.Dimension dim = component.getSize();
        return new Rectangle(p.x, p.y, dim.getWidth(), dim.getHeight());
    } catch (Exception e) {
        IndependantLog.warn(debugmsg + "Fail to get bounds for " + windowName + ":" + compName
                + " on screen due to " + StringUtils.debugmsg(e));
    }
    return null;
}

From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java

/**
 * Called via SingleInstanceListener / SingleInstanceService. Shows a
 * splashscreen and bring the existing instance to the front.
 *//*from   w ww .  jav a  2  s.  com*/
@Override
public void newActivation(String[] arg0) {
    LOGGER.info(
            "A second instance of AtlasViewer has been started.. The single instance if requesting focus now...");

    /*
     * Showing the Spalshscreen for one secong
     */
    try {
        final URL splashscreenUrl = atlasConfig.getResource(AtlasConfig.SPLASHSCREEN_RESOURCE_NAME);
        if (splashscreenUrl != null) {
            JWindow splashWindow = new JWindow(atlasJFrame);
            JPanel panel = new JPanel(new BorderLayout());
            ImageIcon icon = new ImageIcon(splashscreenUrl);
            panel.add(new JLabel(icon), BorderLayout.CENTER);
            panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            splashWindow.getContentPane().add(panel);
            splashWindow.getRootPane().setOpaque(true);
            splashWindow.pack();
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            splashWindow.setLocation((int) (d.getWidth() - splashWindow.getWidth()) / 2,
                    (int) (d.getHeight() - splashWindow.getHeight()) / 2);
            splashWindow.setVisible(true);
            Thread.sleep(1500);
            splashWindow.dispose();
            splashWindow = null;
        }
    } catch (Exception e) {
        LOGGER.warn("Singleinstance.newActivation had problems while showing the splashscreen:", e);
    }

    if (getJFrame() != null) {
        if (!getJFrame().isShowing())
            getJFrame().setVisible(true);

        /* In case that it has been iconified */
        getJFrame().setExtendedState(Frame.NORMAL);

        getJFrame().requestFocus();
        getJFrame().toFront();
    }
}

From source file:ome.services.ThumbnailBean.java

@RolesAllowed("user")
@Transactional(readOnly = false)/*from w w  w  .  j  a va2s. c  om*/
public byte[] getThumbnailByLongestSide(Integer size) {
    errorIfNullPixelsAndRenderingDef();
    // Set defaults and sanity check thumbnail sizes
    Dimension dimensions = sanityCheckThumbnailSizes(size, size);
    size = (int) dimensions.getWidth();

    // Ensure that we do not have "dirty" pixels or rendering settings left
    // around in the Hibernate session cache.
    iQuery.clear();
    // Resetting thumbnail metadata because we don't know what may have
    // happened in the database since or if sizeX and sizeY have changed.
    Set<Long> pixelsIds = new HashSet<Long>();
    pixelsIds.add(pixelsId);
    ctx.loadAndPrepareMetadata(pixelsIds, size);
    thumbnailMetadata = ctx.getMetadata(pixelsId);
    return retrieveThumbnailAndUpdateMetadata();
}