/* * FlowerFrame.java * * Created on September 5, 2007, 11:18 AM */ package flowerclient; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.Map; import javax.swing.ImageIcon; /** * * @author mkuchtiak */ public class FlowerFrame extends javax.swing.JFrame { public static final String[] FLOWERS = {"aster", "honeysuckle", "rose", "sunflower"}; private Map flowers; /** Creates new form FlowerFrame */ public FlowerFrame(Map flowers) { this.flowers = flowers; for (String flower:FLOWERS) { flowers.put(flower,null); } initComponents(); setTitle("Garden Flowers [waiting for picture]"); ItemListener rbListener = new RBListener(); jRadioButton1.addItemListener(rbListener); jRadioButton2.addItemListener(rbListener); jRadioButton3.addItemListener(rbListener); jRadioButton4.addItemListener(rbListener); ActionListener bListener = new ButtonListener(); jButton1.addActionListener(bListener); jButton2.addActionListener(bListener); jButton3.addActionListener(bListener); jButton4.addActionListener(bListener); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { buttonGroup1 = new javax.swing.ButtonGroup(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jRadioButton3 = new javax.swing.JRadioButton(); jRadioButton4 = new javax.swing.JRadioButton(); jScrollPane1 = new javax.swing.JScrollPane(); jPanel1 = new javax.swing.JPanel(); flowerButton = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jPanel2 = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); buttonGroup1.add(jRadioButton1); jRadioButton1.setFont(new java.awt.Font("Dialog", 1, 14)); jRadioButton1.setSelected(true); jRadioButton1.setText("Aster (Coreopsis tinctoria)"); buttonGroup1.add(jRadioButton2); jRadioButton2.setFont(new java.awt.Font("Dialog", 1, 14)); jRadioButton2.setText("Honeysuckle"); buttonGroup1.add(jRadioButton3); jRadioButton3.setFont(new java.awt.Font("Dialog", 1, 14)); jRadioButton3.setText("Rose"); buttonGroup1.add(jRadioButton4); jRadioButton4.setFont(new java.awt.Font("Dialog", 1, 14)); jRadioButton4.setText("Sunflower"); jPanel1.setPreferredSize(new java.awt.Dimension(640, 480)); jPanel1.setLayout(new java.awt.BorderLayout()); flowerButton.setText("Waiting for picture ..."); jPanel1.add(flowerButton, java.awt.BorderLayout.CENTER); jScrollPane1.setViewportView(jPanel1); jLabel1.setFont(new java.awt.Font("Dialog", 1, 20)); jLabel1.setText("Garden Flowers"); jPanel2.setPreferredSize(new java.awt.Dimension(640, 160)); jPanel2.setLayout(new java.awt.GridLayout()); jButton1.setText("Waiting ..."); jButton1.setPreferredSize(new java.awt.Dimension(160, 160)); jPanel2.add(jButton1); jButton2.setText("Waiting ..."); jButton2.setPreferredSize(new java.awt.Dimension(160, 160)); jPanel2.add(jButton2); jButton3.setText("Waiting ..."); jButton3.setPreferredSize(new java.awt.Dimension(160, 160)); jPanel2.add(jButton3); jButton4.setText("Waiting ..."); jButton4.setPreferredSize(new java.awt.Dimension(160, 160)); jPanel2.add(jButton4); jScrollPane2.setViewportView(jPanel2); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(286, 286, 286) .addComponent(jLabel1) .addContainerGap(322, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(54, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addComponent(jRadioButton1) .addGap(44, 44, 44) .addComponent(jRadioButton2) .addGap(71, 71, 71) .addComponent(jRadioButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jRadioButton4)) .addComponent(jScrollPane2) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 663, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(52, 52, 52)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jRadioButton3) .addComponent(jRadioButton2) .addComponent(jRadioButton1) .addComponent(jRadioButton4)) .addGap(8, 8, 8) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE) .addContainerGap()) ); pack(); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton flowerButton; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JRadioButton jRadioButton3; private javax.swing.JRadioButton jRadioButton4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; // End of variables declaration//GEN-END:variables private class RBListener implements ItemListener { public void itemStateChanged(ItemEvent e) { showFlower(); } } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == jButton1) jRadioButton1.setSelected(true); else if (e.getSource() == jButton2) jRadioButton2.setSelected(true); else if (e.getSource() == jButton3) jRadioButton3.setSelected(true); else if (e.getSource() == jButton4) jRadioButton4.setSelected(true); } } void showFlower() { Image img = null; if (jRadioButton1.isSelected()) { img = flowers.get("aster"); if (img != null) { flowerButton.setIcon(new ImageIcon(img)); setTitle("Garden Flowers [Aster]"); } } else if (jRadioButton2.isSelected()) { img = flowers.get("honeysuckle"); if (img != null) { flowerButton.setIcon(new ImageIcon(img)); setTitle("Garden Flowers [Honeysuckle]"); } } else if (jRadioButton3.isSelected()) { img = flowers.get("rose"); if (img != null) { flowerButton.setIcon(new ImageIcon(img)); setTitle("Garden Flowers [Rose]"); } } else if (jRadioButton4.isSelected()) { img = flowers.get("sunflower"); if (img != null) { flowerButton.setIcon(new ImageIcon(img)); setTitle("Garden Flowers [Sunflower]"); } } if (img == null) { flowerButton.setIcon(null); setTitle("Garden Flowers [waiting for picture]"); } else flowerButton.setText(""); } void setThumbnails(Map thumbs) { Image img = thumbs.get("aster"); if (img != null) { jButton1.setIcon(new ImageIcon(img)); jButton1.setText(""); } img = thumbs.get("honeysuckle"); if (img != null) { jButton2.setIcon(new ImageIcon(img)); jButton2.setText(""); } img = thumbs.get("rose"); if (img != null) { jButton3.setIcon(new ImageIcon(img)); jButton3.setText(""); } img = thumbs.get("sunflower"); if (img != null) { jButton4.setIcon(new ImageIcon(img)); jButton4.setText(""); } } }