/* * (C) Copyright IBM Corp. 2012 * * LICENSE: Eclipse Public License v1.0 * http://www.eclipse.org/legal/epl-v10.html */ package com.ibm.gaiandb.apps.dashboard; import java.awt.event.ActionEvent; import javax.swing.JOptionPane; /** * * @author tom */ public class TrustObservationFrame extends javax.swing.JFrame { // Use PROPRIETARY notice if class contains a main() method, otherwise use COPYRIGHT notice. public static final String COPYRIGHT_NOTICE = "(c) Copyright IBM Corp. 2012"; private static final long serialVersionUID = 1L; String thisNode; /** Creates new form TrustObservationFrame */ public TrustObservationFrame(String s,String[] neighbours) { thisNode = s; initComponents(); // Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); // labelTable.put( new Integer( -10 ), new JLabel("-1.0") ); // labelTable.put( new Integer( 0 ), new JLabel("0.0") ); // labelTable.put( new Integer( 10 ), new JLabel("1.0") ); // this.jSlider1.setLabelTable( labelTable ); // this.jSlider1.setLabelTable(jSlider1.createStandardLabels(5)); this.setTitle(s); this.NodeLabel.setText(s); for(String tmp : neighbours){ this.jComboBox1.addItem(tmp); } } /** 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. */ private void initComponents() { jPopupMenu1 = new javax.swing.JPopupMenu(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jLabel1 = new javax.swing.JLabel(); NodeLabel = new javax.swing.JLabel(); ObservedNodeLabel = new javax.swing.JLabel(); ObservedValueLabel = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jComboBox1 = new javax.swing.JComboBox(); jSlider1 = new javax.swing.JSlider(); jMenuItem1.setText("jMenuItem1"); jPopupMenu1.add(jMenuItem1); jMenuItem2.setText("jMenuItem2"); jPopupMenu1.add(jMenuItem2); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { formMouseClicked(evt); } }); jLabel1.setText("Set Trust Observation for : "); NodeLabel.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N NodeLabel.setText("Node 30"); ObservedNodeLabel.setText("Observed Node : "); ObservedValueLabel.setText("Observation Value (%) : "); jButton1.setText("Ok"); jButton1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton1MouseClicked(evt); } }); jButton1.addActionListener(new java.awt.event.ActionListener(){ @Override public void actionPerformed(ActionEvent e) { // returnSelectedData(); } } ); jButton2.setText("Cancel"); jButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jButton2MouseClicked(evt); } }); jSlider1.setMajorTickSpacing(50); jSlider1.setMaximum(100); jSlider1.setMinimum(-100); jSlider1.setPaintLabels(true); jSlider1.setPaintTicks(true); jSlider1.setValue(0); jSlider1.setDoubleBuffered(true); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(NodeLabel)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(ObservedNodeLabel) .addComponent(ObservedValueLabel)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(13, 13, 13) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(NodeLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ObservedNodeLabel) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(ObservedValueLabel) .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(12, 12, 12) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked }//GEN-LAST:event_formMouseClicked private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked this.dispose(); }//GEN-LAST:event_jButton2MouseClicked /** * ObservationSimulator is the DSM (IBM Watson research lab distributed state machine) class for setting observations. */ // private ObservationSimulator sim = null; private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { double score = (double) (this.jSlider1.getValue()) / 100 ; System.out.println(thisNode + " " + this.jComboBox1.getSelectedItem().toString() + " " + score); try { // if ( null == sim ) sim = new ObservationSimulator(); // boolean success = sim.simulateObservation(thisNode, this.jComboBox1.getSelectedItem().toString(), score); boolean success = false; if(success) System.out.println("Success"); else System.out.println("Not sent"); } catch (Exception e) { System.out.println("Unable to set a dsm observation, cause: " + e); System.out.println("DSM_PROPERTIES_FILE: " + System.getenv("DSM_PROPERTIES_FILE")); e.printStackTrace(); } JOptionPane.showMessageDialog(this, "For " + this.getTitle() + " Observed : " + this.jComboBox1.getSelectedItem().toString() + " Trust Value : "+ score); this.dispose(); } public static int countSubstring(String subStr, String str){ return (str.length() - str.replace(subStr, "").length()) / subStr.length(); } /** * @param args the command line arguments */ // public static void main(String args[]) { // java.awt.EventQueue.invokeLater(new Runnable() { // public void run() { // String tmp[] = {"A","B","C"}; // new TrustObservationFrame("Node 44",tmp).setVisible(true); // } // }); // } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel NodeLabel; private javax.swing.JLabel ObservedNodeLabel; private javax.swing.JLabel ObservedValueLabel; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JComboBox jComboBox1; private javax.swing.JLabel jLabel1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JSlider jSlider1; // End of variables declaration//GEN-END:variables }