/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * TextVisualizerJPanel.java * * Created on 22.09.2012, 17:28:38 */ package org.oobd.ui.swing.desk; import java.awt.Graphics; import java.awt.List; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.DefaultComboBoxModel; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.json.JSONArray; import org.json.JSONException; import org.oobd.base.*; import org.oobd.base.support.OnionNoEntryException; import org.oobd.base.visualizer.*; import org.oobd.base.support.Onion; /** * * @author steffen */ public class ComboBoxVisualizerJPanel extends VisualizerJPanel implements IFvisualizer, ActionListener { private Boolean justPainting = false; public ComboBoxVisualizerJPanel() { super(); initComponents(); valueComboBox.addActionListener(this); } @Override public void paintComponent(Graphics g) { if (value != null) { functionName.setText("<html>" + value.getToolTip() + "</html>"); justPainting = true; valueComboBox.setSelectedIndex(safeInt(value.toString())); justPainting = false; } if (value.getUpdateFlag(4)) { backImageLabel.setIcon(myIcons[OOBDConstants.VE_BACK + 1]); } else { backImageLabel.setIcon(myIcons[0]); } if (value.getUpdateFlag(1)) { updateImageLabel.setIcon(myIcons[OOBDConstants.VE_UPDATE + 1]); } else { updateImageLabel.setIcon(myIcons[0]); } if (value.getUpdateFlag(2)) { timerImageLabel.setIcon(myIcons[OOBDConstants.VE_TIMER + 1]); } else { timerImageLabel.setIcon(myIcons[0]); } if (value.getUpdateFlag(3)) { logImageLabel.setIcon(myIcons[OOBDConstants.VE_LOG + 1]); } else { logImageLabel.setIcon(myIcons[0]); } if (value.getUpdateFlag(0)) { forwardImageLabel.setIcon(myIcons[OOBDConstants.VE_MENU + 1]); } else { forwardImageLabel.setIcon(myIcons[0]); } super.paintComponent(g); } /** * 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. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { valueComboBox = new javax.swing.JComboBox(); jPanel1 = new javax.swing.JPanel(); functionName = new javax.swing.JLabel(); filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0)); backImageLabel = new javax.swing.JLabel(); updateImageLabel = new javax.swing.JLabel(); timerImageLabel = new javax.swing.JLabel(); logImageLabel = new javax.swing.JLabel(); forwardImageLabel = new javax.swing.JLabel(); filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 0), new java.awt.Dimension(10, 32767)); filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767)); setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); setName("Form"); // NOI18N setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS)); org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(org.oobd.ui.swing.desk.swing.class).getContext().getResourceMap(ComboBoxVisualizerJPanel.class); valueComboBox.setFont(resourceMap.getFont("valueComboBox.font")); // NOI18N valueComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); valueComboBox.setName("valueComboBox"); // NOI18N add(valueComboBox); jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); jPanel1.setMinimumSize(new java.awt.Dimension(14, 20)); jPanel1.setName("jPanel1"); // NOI18N jPanel1.setPreferredSize(new java.awt.Dimension(14, 20)); jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS)); functionName.setFont(resourceMap.getFont("titleLable.font")); // NOI18N functionName.setForeground(resourceMap.getColor("titleLable.foreground")); // NOI18N functionName.setText(resourceMap.getString("titleLable.text")); // NOI18N functionName.setName("titleLable"); // NOI18N jPanel1.add(functionName); filler1.setName("filler1"); // NOI18N jPanel1.add(filler1); backImageLabel.setIcon(resourceMap.getIcon("backImageLabel.icon")); // NOI18N backImageLabel.setName("backImageLabel"); // NOI18N jPanel1.add(backImageLabel); updateImageLabel.setName("updateImageLabel"); // NOI18N jPanel1.add(updateImageLabel); timerImageLabel.setName("timerImageLabel"); // NOI18N jPanel1.add(timerImageLabel); logImageLabel.setName("logImageLabel"); // NOI18N jPanel1.add(logImageLabel); forwardImageLabel.setName("forwardImageLabel"); // NOI18N jPanel1.add(forwardImageLabel); filler2.setName("filler2"); // NOI18N jPanel1.add(filler2); add(jPanel1); filler3.setName("filler3"); // NOI18N add(filler3); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel backImageLabel; private javax.swing.Box.Filler filler1; private javax.swing.Box.Filler filler2; private javax.swing.Box.Filler filler3; private javax.swing.JLabel forwardImageLabel; private javax.swing.JLabel functionName; private javax.swing.JPanel jPanel1; private javax.swing.JLabel logImageLabel; private javax.swing.JLabel timerImageLabel; private javax.swing.JLabel updateImageLabel; private javax.swing.JComboBox valueComboBox; // End of variables declaration//GEN-END:variables @Override public void initValue(Visualizer viz, Onion onion) { functionName.setText(onion.getOnionString("tooltip")); try { Onion items = (Onion) onion.getOnionObject("opts/content"); Vector<String> al = new Vector<String>(); Vector<Integer> keylist = new Vector<Integer>(); Iterator<String> itr = items.keys(); while (itr.hasNext()) { Object element = itr.next(); keylist.add(Double.valueOf(element.toString()) .intValue()); } Enumeration<Integer> enumeration = keylist .elements(); ArrayList<Integer> list = Collections.list(enumeration); Collections.sort(list); for (Integer number : list) { al.add((String) items.get(((Double) number .doubleValue()).toString())); } valueComboBox.setModel(new DefaultComboBoxModel(al.toArray(new String[al.size()]))); } catch (OnionNoEntryException ex) { Logger.getLogger(ComboBoxVisualizerJPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(ComboBoxVisualizerJPanel.class.getName()).log(Level.SEVERE, null, ex); } valueComboBox.setSelectedIndex(safeInt(value.toString())); this.value = viz; } @Override public void actionPerformed(ActionEvent e) { if (!justPainting) { JComboBox cb = (JComboBox) e.getSource(); getVisualizer().inputNewValue(new Integer(cb.getSelectedIndex()).toString()); getVisualizer().updateRequest(OOBDConstants.UR_USER); } } }