Example usage for java.awt Toolkit createImage

List of usage examples for java.awt Toolkit createImage

Introduction

In this page you can find the example usage for java.awt Toolkit createImage.

Prototype

public Image createImage(byte[] imagedata) 

Source Link

Document

Creates an image which decodes the image stored in the specified byte array.

Usage

From source file:Main.java

public static Image getImage(Class relativeClass, String filename) {
    Image returnValue = null;/*from www .ja v  a  2  s. co  m*/
    InputStream is = relativeClass.getResourceAsStream(filename);
    if (is != null) {
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            int ch;
            while ((ch = bis.read()) != -1) {
                baos.write(ch);
            }
            Toolkit t = Toolkit.getDefaultToolkit();
            returnValue = t.createImage(baos.toByteArray());
        } catch (IOException exception) {
            System.err.println("Error loading: " + filename);
        }
    }
    return returnValue;
}

From source file:Main.java

public static Image getImage(Class relativeClass, String filename) {
    Image returnValue = null;//www .j  av  a  2  s  . com
    InputStream is = relativeClass.getResourceAsStream(filename);
    if (is != null) {
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            int ch;
            while ((ch = bis.read()) != -1) {
                baos.write(ch);
            }
            Toolkit t = Toolkit.getDefaultToolkit();

            returnValue = t.createImage(baos.toByteArray());
        } catch (IOException exception) {
            System.err.println("Error loading: " + filename);
        }
    }
    return returnValue;
}

From source file:llc.rockford.webcast.EC2Driver.java

private void createAndShowGUI() {
    // Set the look and feel.
    initLookAndFeel();//from  ww  w.  j  a  v a 2s  . c  om

    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    // Create and set up the window.
    JFrame frame = new JFrame("Webcast Utility");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(300, 400));
    java.net.URL url = ClassLoader.getSystemResource("llc/rockford/webcast/resources/internet.png");
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(url);
    frame.setIconImage(img);
    Component contents = createComponents();
    frame.getContentPane().add(contents, BorderLayout.CENTER);

    // Display the window.
    frame.pack();
    frame.setVisible(true);

}

From source file:org.sbml.bargraph.MainWindow.java

/**
 * Creates the main application frame./* ww w .  j a  v  a2  s.  c  o m*/
 * 
 * @param file A file to read and graph upon start up.  If null, nothing
 * is graphed initially.
 */
public MainWindow(File file) {
    Log.note("Creating main application window.");
    setPlatformProperties();

    setBackground(new Color(255, 255, 255));
    setMaximumSize(new Dimension(2000, 1000));
    setMinimumSize(new Dimension(600, 400));
    setTitle("SBML Bar Graph");
    setSize(new Dimension(600, 400));
    setPreferredSize(new Dimension(600, 400));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 550, 400);
    contentPane = new JPanel();
    contentPane.setSize(new Dimension(600, 400));
    contentPane.setPreferredSize(new Dimension(600, 400));
    contentPane.setMinimumSize(new Dimension(600, 400));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    fileNamePanel = new JPanel();
    fileNamePanel.setPreferredSize(new Dimension(590, 20));
    fileNamePanel.setMinimumSize(new Dimension(590, 20));
    fileNamePanel.setLayout(new BorderLayout(0, 0));
    contentPane.add(fileNamePanel, BorderLayout.NORTH);

    fileNameField = new JTextField();
    fileNameField.setHorizontalAlignment(SwingConstants.CENTER);
    fileNameField.setText("No file selected");
    fileNameField.setDisabledTextColor(Color.LIGHT_GRAY);
    fileNameField.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
    fileNameField.setBorder(null);
    fileNameField.setOpaque(true);
    fileNameField.setBackground(UIManager.getColor("Separator.foreground"));
    fileNameField.setEnabled(false);
    fileNameField.setSize(new Dimension(590, 0));
    fileNameField.setPreferredSize(new Dimension(590, 28));
    fileNameField.setMinimumSize(new Dimension(590, 28));
    fileNameField.setColumns(10);
    fileNamePanel.add(fileNameField, BorderLayout.CENTER);

    // The bar graph panel.

    chartPanel = new ChartPanel(createModelBarGraph(), false);
    contentPane.add(chartPanel, BorderLayout.CENTER);
    updatePanelForSBMLFile(file);

    // Manual additions for File menu.

    fileMenu = new JMenu();
    fileMenu.setText("File");

    openFileMenuItem = new JMenuItem();
    openFileMenuItem
            .setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, shortcutKeyMask));
    openFileMenuItem.setText("Open...");
    openFileMenuItem.setToolTipText("Open file to be graphed");
    openFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            openFileHandler(evt);
        }
    });

    fileMenu.add(openFileMenuItem);
    menuBar = new javax.swing.JMenuBar();
    menuBar.add(fileMenu);

    setJMenuBar(menuBar);

    // Replace the default Java window icon with our own.
    // This only has an effect on non-Mac OS systems.

    URL iconImageURL = getClass().getResource(Config.RES_ICON_APP);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image img = toolkit.createImage(iconImageURL);
    setIconImage(img);

    Log.note("Finished constructing panel and menu bar");
}

From source file:J3dSwingFrame.java

/**
 * Set the texture on our goemetry//from   w  w w.  ja  va  2  s.c  o m
 * <P>
 * Always specified as a URL so that we may fetch it from anywhere.
 * 
 * @param url
 *            The url to the image.
 */
public void setTexture(URL url) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image src_img = tk.createImage(url);
    BufferedImage buf_img = null;

    if (!(src_img instanceof BufferedImage)) {
        // create a component anonymous inner class to give us the image
        // observer we need to get the width and height of the source image.
        Component obs = new Component() {
        };

        int width = src_img.getWidth(obs);
        int height = src_img.getHeight(obs);

        // construct the buffered image from the source data.
        buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics g = buf_img.getGraphics();
        g.drawImage(src_img, 0, 0, null);
        g.dispose();
    } else
        buf_img = (BufferedImage) src_img;

    src_img.flush();

    ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img);

    texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight());

    appearance.setTexture(texture);

    buf_img.flush();
}

From source file:Interfaz.adminZone.java

private void ponerImagen() {

    Toolkit tk = Toolkit.getDefaultToolkit();
    String ruta = "./_data/Bicicol.png";
    Image imagen = tk.createImage(ruta);
    logo.setIcon(new ImageIcon(
            imagen.getScaledInstance(logo.getWidth(), logo.getHeight(), Image.SCALE_AREA_AVERAGING)));

}

From source file:Interfaz.adminZone.java

private void cbEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEmpActionPerformed
    ArrayList<String> arr = con.search(6,
            "E.Nombre, C.Nombre Cargo, E.Telefono, COUNT(Empleado), " + "SUM(ValorTotal), E.Documento", "Venta",
            "INNER JOIN Empleado E ON E.Documento = Venta.Empleado "
                    + "INNER JOIN Cargo C ON E.Cargo = C.IdCargo " + "GROUP BY Empleado HAVING E.Nombre =" + "'"
                    + this.cbEmp.getSelectedItem().toString() + "'");
    this.txtCargo.setText(arr.get(1));
    this.txtTelefono.setText(arr.get(2));
    this.txtCan.setText(arr.get(3));
    this.txtTotal.setText(arr.get(4));

    Toolkit tk = Toolkit.getDefaultToolkit();
    String ruta = "./_data/" + arr.get(5) + ".jpg";
    Image imagen = tk.createImage(ruta);
    fotoEmp.setIcon(new ImageIcon(
            imagen.getScaledInstance(fotoEmp.getWidth(), fotoEmp.getHeight(), Image.SCALE_AREA_AVERAGING)));

}

From source file:openqcm.mainGUI.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    java.net.URL url = getClass().getResource("openQCM-icon-30x30.png");
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(url);
    this.setIconImage(img);
}

From source file:org.panbox.desktop.common.gui.PanboxClientGUI.java

public PanboxClientGUI(final PanboxClient client) {
    this.client = client;

    this.shareModel = client.getShareList();
    this.contactModel = client.getContactList();
    this.deviceModel = client.getDeviceList();

    initComponents();/*from   ww w. j  av a 2s.c o  m*/

    ActionListener changesDetectedActionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setSettingsChangesDetected();
        }
    };

    DocumentListener changesDetectedDocumentListener = new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            setSettingsChangesDetected();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            setSettingsChangesDetected();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {

        }
    };

    dropboxSettingsPanel = new DropboxSettingsPanel(changesDetectedActionListener,
            changesDetectedDocumentListener);

    initSettingsConfig();

    // set the icon
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image img = kit.createImage(getClass().getResource("panbox-icon-big.png"));
    setIconImage(img);

    // set the default locale for popup messages
    JOptionPane.setDefaultLocale(Settings.getInstance().getLocale());

    // Hide these for now. Do we still need this?
    syncStatusLabel.setVisible(false);
    syncStatusTextField.setVisible(false);

    cspInfoTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // NOI18N

    shareList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            refreshShare();
        }
    });
    shareList.setSelectedIndex(0); // always try to select first share

    enableDisableAddDeviceContactForShare();

    addressbookList.addListSelectionListener(new ListSelectionListener() {

        private DocumentListener firstNameFieldDocListener = new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }

            public void changed() {
                if (!firstNameTextField.getText().equals(contact.getFirstName()) && !unsavedContactChanges) {
                    setContactChangesDetected();
                }
            }
        };
        private DocumentListener lastNameFieldDocListener = new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changed();
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
            }

            public void changed() {
                if (!lastNameTextField.getText().equals(contact.getName()) && !unsavedContactChanges) {
                    setContactChangesDetected();
                }
            }
        };
        private ListSelectionListener cspListSelectionListener = new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                int selectedIndex = cspInfoTable.getSelectedRow();
                int max = ((CSPTableModel) cspInfoTable.getModel()).getMax();
                if (selectedIndex != -1 && selectedIndex < max) {
                    removeCSPInfoButton.setEnabled(true);
                } else {
                    removeCSPInfoButton.setEnabled(false);
                }
            }
        };

        boolean manuallySetSelection = false;

        @Override
        public void valueChanged(ListSelectionEvent e) {
            final List<PanboxGUIContact> selected = addressbookList.getSelectedValuesList();

            firstNameTextField.getDocument().removeDocumentListener(firstNameFieldDocListener);
            lastNameTextField.getDocument().removeDocumentListener(lastNameFieldDocListener);
            cspInfoTable.getSelectionModel().removeListSelectionListener(cspListSelectionListener);

            if (!manuallySetSelection) {
                if (!uneditedCSPsExist()) {
                    if (unsavedContactChanges) {
                        int saveUnchanged = JOptionPane.showConfirmDialog(null,
                                bundle.getString("PanboxClientGUI.unsavedChangesToContact"), // NOI18N
                                bundle.getString("PanboxClientGUI.panboxMessage"), // NOI18N
                                JOptionPane.YES_NO_CANCEL_OPTION);
                        if (saveUnchanged == JOptionPane.YES_OPTION) {
                            saveContactChanges();
                            refreshContact();
                            resetContactApplyDiscardButtons();
                        } else if (saveUnchanged == JOptionPane.CANCEL_OPTION) {
                            manuallySetSelection = true;
                            int previousIndex = e.getFirstIndex() == addressbookList.getSelectedIndex()
                                    ? e.getLastIndex()
                                    : e.getFirstIndex();
                            addressbookList.setSelectedIndex(previousIndex);
                        } else {
                            refreshContact();
                            resetContactApplyDiscardButtons();
                        }
                        unsavedContactChanges = false;
                    }

                    int selectedIndex = addressbookList.getSelectedIndex();
                    if (selectedIndex != -1) {
                        // enable Buttons
                        removeContactButton.setEnabled(true);
                        exportContactButton.setEnabled(true);

                        // refresh contact infos
                        contact = contactModel.getElementAt(selectedIndex);
                        contacts = selected;
                        firstNameTextField.setText(contact.getFirstName());
                        lastNameTextField.setText(contact.getName());
                        emailTextField.setText(contact.getEmail());
                        cspInfoTable.setModel(contact.generateCspInfoTableModel());
                        cspInfoTable.getSelectionModel().addListSelectionListener(cspListSelectionListener);

                        // show certificate info
                        encKeyFprintTextField.setText(contact.getCertEncFingerprint());
                        signKeyFprintTextField.setText(contact.getCertSignFingerprint());
                        validFromUntilLabel.setText(bundle.getString("valid.from") + " " + contact.getFromDate()
                                + " " + bundle.getString("valid.to") + " " + contact.getUntilDate());

                        // disable apply and discard buttons when contact
                        // selection
                        // changes
                        contactApplyButton.setEnabled(false);
                        contactDiscardButton.setEnabled(false);

                        // disable csp add button when no further csps are
                        // available to add
                        if (contact.getAvailableCSPs() > 0) {
                            addCSPInfoButton.setEnabled(true);
                        } else {
                            addCSPInfoButton.setEnabled(false);
                        }
                        removeCSPInfoButton.setEnabled(false);

                        if (contact instanceof PanboxMyContact) {
                            firstNameTextField.setEnabled(false);
                            lastNameTextField.setEnabled(false);
                            removeContactButton.setEnabled(false);
                            contactVerificationStatusCheckBox.setEnabled(false);
                        } else {
                            firstNameTextField.setEnabled(true);
                            lastNameTextField.setEnabled(true);
                            removeContactButton.setEnabled(true);
                            firstNameTextField.getDocument().addDocumentListener(firstNameFieldDocListener);
                            lastNameTextField.getDocument().addDocumentListener(lastNameFieldDocListener);
                            contactVerificationStatusCheckBox.setEnabled(true);
                        }

                    } else {
                        // disable export and remove button when no item is
                        // selected
                        removeContactButton.setEnabled(false);
                        exportContactButton.setEnabled(false);
                    }
                } else {
                    manuallySetSelection = true;
                    int previousIndex = e.getFirstIndex() == addressbookList.getSelectedIndex()
                            ? e.getLastIndex()
                            : e.getFirstIndex();
                    addressbookList.setSelectedIndex(previousIndex);
                }
            } else {
                manuallySetSelection = false;
            }

            if (contact.isVerified()) {
                contactVerificationStatusCheckBox.setSelected(true);
                contactVerificationStatusCheckBox.setText(bundle.getString("PanboxClientGUI.contact.verified"));
            } else {
                contactVerificationStatusCheckBox.setSelected(false);
                contactVerificationStatusCheckBox.setText(bundle.getString("PanboxClientGUI.contact.verified"));
            }
        }
    });
    addressbookList.setSelectedIndex(0); // always try to select first
    // contact

    // contact
    firstNameTextField.setDisabledTextColor(Color.BLACK);
    lastNameTextField.setDisabledTextColor(Color.BLACK);
    emailTextField.setDisabledTextColor(Color.BLACK);
    encKeyFprintTextField.setDisabledTextColor(Color.BLACK);
    signKeyFprintTextField.setDisabledTextColor(Color.BLACK);

    deviceList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int selected = deviceList.getSelectedIndex();
            if (!e.getValueIsAdjusting() && selected != -1) {
                device = deviceModel.getElementAt(selected);

                deviceKeyFprintTextField.setText(device.getDevicePubKeyFingerprint());

                deviceShareList.setModel(client.getDeviceShares(device));

                checkIfRemoveDeviceShouldBeEnabled();
            }
        }
    });
    deviceList.setSelectedIndex(0); // always try to select first device

    checkIfRemoveDeviceShouldBeEnabled();

    // expert mode visible/invisible
    expertModeCheckBoxActionPerformed(null);

    languageComboBox.addActionListener(changesDetectedActionListener);
    expertModeCheckBox.addActionListener(changesDetectedActionListener);
    networkAddressComboBox.addActionListener(changesDetectedActionListener);
    networkInterfaceComboBox.addActionListener(changesDetectedActionListener);

    panboxFolderTextField.getDocument().addDocumentListener(changesDetectedDocumentListener);
    settingsFolderTextField.getDocument().addDocumentListener(changesDetectedDocumentListener);

    // disable settings apply and discard buttons
    settingsApplyButton.setEnabled(false);
    settingsRevertButton.setEnabled(false);

    // TODO: add action and document listeners to the csp settings after it
    // has been fixed (see trac ticket #139)

    // Disable device pairing for SLAVE devices and enable the click for MASTER devices!
    if (Settings.getInstance().isSlave()) {
        addDeviceButton.setEnabled(false);
        addDeviceButton.setToolTipText(bundle.getString("client.disabledPairingSlave"));
    } else {
        addDeviceButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                addDeviceButtonMousePressed(evt);
            }
        });
    }

    if (OS.getOperatingSystem().isWindows()) {
        panboxFolderLabel.setText(bundle.getString("client.settings.panboxDrive")); // NOI18N

        panboxFolderChooseButton.setVisible(false);
    }
}