Example usage for java.awt.event ItemEvent getItem

List of usage examples for java.awt.event ItemEvent getItem

Introduction

In this page you can find the example usage for java.awt.event ItemEvent getItem.

Prototype

public Object getItem() 

Source Link

Document

Returns the item affected by the event.

Usage

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.graph.SimpleCollapsableGraph.java

public SimpleCollapsableGraph(UndirectedSparseMultigraph<IB_Vertex, IB_Edge> graph, OSM_Node subnetManager,
        Dimension preferredSize) throws HeadlessException {
    super();//from  w  w w .j  a  va  2s .com
    setGraph(graph);

    layout = new FRLayout<IB_Vertex, IB_Edge>(graph);

    if (preferredSize == null)
        preferredSize = new Dimension(600, 600);
    else {
        // trim 10% off the supplied size
        preferredSize = new Dimension((preferredSize.width * 9) / 10, (preferredSize.height * 9) / 10);
    }

    final VisualizationModel<IB_Vertex, IB_Edge> visualizationModel = new DefaultVisualizationModel<IB_Vertex, IB_Edge>(
            layout, preferredSize);
    VisualizationViewer<IB_Vertex, IB_Edge> vv = new VisualizationViewer<IB_Vertex, IB_Edge>(visualizationModel,
            preferredSize);

    vv.addGraphMouseListener(new SimpleGraphMouseListener<IB_Vertex>(this));

    final PickedState<IB_Vertex> picked_v_state = vv.getPickedVertexState();
    PickedState<IB_Edge> picked_e_state = vv.getPickedEdgeState();

    picked_e_state.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            Object subject = e.getItem();

            if (subject instanceof IB_Edge) {
                IB_Edge edge = (IB_Edge) subject;

                if (e.getStateChange() == ItemEvent.SELECTED) {
                    // craft a selection event, for this edge
                    GraphSelectionManager.getInstance()
                            .updateAllListeners(new IB_GraphSelectionEvent(this, subject, edge));
                    MessageManager.getInstance().postMessage(
                            new SmtMessage(SmtMessageType.SMT_MSG_INFO, "SCG - edge selected: Color it!"));
                } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                    // this is deselected, do nothing
                    MessageManager.getInstance()
                            .postMessage(new SmtMessage(SmtMessageType.SMT_MSG_INFO, "SCG - edge deselected"));
                } else {
                    System.err.println(
                            "SCG - edge not selected or deselected - unknown state change: The edge itemEvent is: "
                                    + e.getStateChange());
                }
            } else {
                System.err.println("SCG - not edge??: The edge subject picked is: "
                        + subject.getClass().getCanonicalName());
            }
        }
    });

    // create decorators
    vv.getRenderContext().setVertexLabelTransformer(IB_TransformerFactory.getVertexLabelTransformer(vv));
    vv.getRenderContext().setVertexShapeTransformer(IB_TransformerFactory.getVertexShapeTransformer(vv));
    vv.getRenderContext().setVertexFillPaintTransformer(
            IB_TransformerFactory.getVertexFillPaintTransformer(vv, subnetManager));
    vv.getRenderContext().setEdgeLabelTransformer(IB_TransformerFactory.getEdgeLabelTransformer(vv));
    vv.getRenderContext().setEdgeFillPaintTransformer(IB_TransformerFactory.getEdgeFillPaintTransformer(vv));
    vv.getRenderContext().setEdgeDrawPaintTransformer(IB_TransformerFactory.getEdgeDrawPaintTransformer(vv));

    // add a listener for ToolTips
    vv.setVertexToolTipTransformer(IB_TransformerFactory.getVertexToolTipTransformer(vv));
    vv.setEdgeToolTipTransformer(IB_TransformerFactory.getEdgeToolTipTransformer(vv));

    setVisViewer(vv);

    final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance();
    final Set exclusions = new HashSet();
    eif.setPredicate(new Predicate() {

        public boolean evaluate(Object e) {
            return exclusions.contains(e);
        }
    });

    vv.getRenderContext().setParallelEdgeIndexFunction(eif);

    vv.setBackground(Color.white);

    /**
     * the regular graph mouse for the normal view
     */
    final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();

    vv.setGraphMouse(graphMouse);

    // Container content = getContentPane(); // for JApplet or JFrame
    Container content = this; // for JPanel
    content.setLayout(new BorderLayout());
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    content.add(gzsp, BorderLayout.CENTER);
}

From source file:org.apache.jmeter.testbeans.gui.ComboStringEditor.java

/**
 * {@inheritDoc}/*from  w  w  w.  j a  va2  s  .  c o  m*/
 */
@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        if (EDIT.equals(e.getItem())) {
            startingEdit = true;
            startEditing();
            startingEdit = false;
        } else {
            if (!startingEdit && combo.getSelectedIndex() >= 0) {
                combo.setEditable(false);
            }

            firePropertyChange();
        }
    }
}

From source file:op.controlling.DlgQMSPlan.java

private void cmbNotifyItemStateChanged(ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        if (!notifyList.contains(e.getItem())) {
            notifyList.add((Users) e.getItem());
            lstNotify.setModel(SYSTools.list2dlm(notifyList));
        }//from   w  w w. ja  v a2  s.  c o m
    }
}

From source file:net.lldp.checksims.ui.results.ScrollViewer.java

/**
 * Create a scroll viewer from a sortable Matrix Viewer
 * @param results the sortableMatrix to view
 * @param toRevalidate frame to revalidate sometimes
 */// ww  w  . ja va2s. co m
public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) {
    resultsView = new JScrollPane(results);
    setBackground(Color.black);
    resultsView.addComponentListener(new ComponentListener() {

        @Override
        public void componentHidden(ComponentEvent arg0) {
        }

        @Override
        public void componentMoved(ComponentEvent arg0) {
        }

        @Override
        public void componentResized(ComponentEvent ce) {
            Dimension size = ce.getComponent().getSize();
            results.padToSize(size);
        }

        @Override
        public void componentShown(ComponentEvent arg0) {
        }
    });

    resultsView.getViewport().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Rectangle r = resultsView.getViewport().getViewRect();
            results.setViewAt(r);
        }
    });

    resultsView.setBackground(Color.black);
    sidebar = new JPanel();

    setPreferredSize(new Dimension(900, 631));
    setMinimumSize(new Dimension(900, 631));
    sidebar.setPreferredSize(new Dimension(200, 631));
    sidebar.setMaximumSize(new Dimension(200, 3000));
    resultsView.setMinimumSize(new Dimension(700, 631));
    resultsView.setPreferredSize(new Dimension(700, 631));

    sidebar.setBackground(Color.GRAY);

    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    this.add(sidebar);
    this.add(resultsView);

    resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    resultsView.getVerticalScrollBar().setUnitIncrement(16);
    resultsView.getHorizontalScrollBar().setUnitIncrement(16);

    Integer[] presetThresholds = { 80, 60, 40, 20, 0 };
    JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds);
    threshHold.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Integer item = (Integer) event.getItem();
                results.updateThreshold(item / 100.0);
                toRevalidate.revalidate();
                toRevalidate.repaint();
            }
        }
    });
    threshHold.setSelectedIndex(0);
    results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0);

    JTextField student1 = new JTextField(15);
    JTextField student2 = new JTextField(15);

    KeyListener search = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            results.highlightMatching(student1.getText(), student2.getText());
            toRevalidate.revalidate();
            toRevalidate.repaint();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }
    };

    student1.addKeyListener(search);
    student2.addKeyListener(search);

    Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance()
            .getSupportedImplementations();
    JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet));
    JButton exportAsSave = new JButton("Save");

    JFileChooser fc = new JFileChooser();

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setCurrentDirectory(new java.io.File("."));
    fc.setDialogTitle("Save results");

    exportAsSave.addActionListener(ae -> {
        MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem();

        int err = fc.showDialog(toRevalidate, "Save");
        if (err == JFileChooser.APPROVE_OPTION) {
            try {
                FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix));
            } catch (InternalAlgorithmError | IOException e1) {
                // TODO log / show error
            }
        }
    });

    JPanel thresholdLabel = new JPanel();
    JPanel studentSearchLabel = new JPanel();
    JPanel fileOutputLabel = new JPanel();

    thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold"));
    studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search"));
    fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results"));

    thresholdLabel.add(threshHold);
    studentSearchLabel.add(student1);
    studentSearchLabel.add(student2);
    fileOutputLabel.add(exportAs);
    fileOutputLabel.add(exportAsSave);

    studentSearchLabel.setPreferredSize(new Dimension(200, 100));
    studentSearchLabel.setMinimumSize(new Dimension(200, 100));
    thresholdLabel.setPreferredSize(new Dimension(200, 100));
    thresholdLabel.setMinimumSize(new Dimension(200, 100));
    fileOutputLabel.setPreferredSize(new Dimension(200, 100));
    fileOutputLabel.setMinimumSize(new Dimension(200, 100));

    sidebar.setMaximumSize(new Dimension(200, 4000));

    sidebar.add(thresholdLabel);
    sidebar.add(studentSearchLabel);
    sidebar.add(fileOutputLabel);
}

From source file:assign3.client.WaypointClient.java

public void itemStateChanged(ItemEvent event) {
    if (event.getStateChange() == ItemEvent.SELECTED) {
        Object comp = event.getSource();
        debug("Selection event generated by " + ((comp == frWps) ? "from " : "to ") + "combobox. "
                + "Selected waypoint is: " + (String) event.getItem());
        String To = "to waypoint";
        String From = "from waypoint";
        String currentSelection;//w  ww  . j  a  va2s . c  o  m
        if (comp == frWps) {
            currentSelection = frWps.getSelectedItem().toString();
        } else {
            currentSelection = toWps.getSelectedItem().toString();
        }
        if ((currentSelection == "from waypoint") || (currentSelection == "to waypoint")) {
            latIn.setText("null");
            lonIn.setText("null");
            eleIn.setText("null");
            nameIn.setText("null");
            addrIn.setText("null");
        } else {
            try {
                Waypoint currentWaypoint = server.get(currentSelection);
                //System.out.println("Description Changed: "+server.get(currentSelection));
                latIn.setText(String.valueOf(currentWaypoint.getLat()));
                lonIn.setText(String.valueOf(currentWaypoint.getLon()));
                eleIn.setText(String.valueOf(currentWaypoint.getEle()));
                nameIn.setText(currentWaypoint.getName());
                addrIn.setText(currentWaypoint.getAddr());
            } catch (RemoteException e) {
                System.out.println("Error retrieving name from server.");
            }
        }
    }
}

From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java

public void setPickedVertexState(PickedState<V> pickedVertexState) {
    if (pickEventListener != null && this.pickedVertexState != null) {
        this.pickedVertexState.removeItemListener(pickEventListener);
    }//w  w  w. ja  va2s.com
    this.pickedVertexState = pickedVertexState;
    this.renderContext.setPickedVertexState(pickedVertexState);
    if (pickEventListener == null) {
        pickEventListener = new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                System.err.println(e.getItem() + " was picked");
            }
        };
    }
    pickedVertexState.addItemListener(pickEventListener);
}

From source file:com.emr.schemas.ForeignDataMover.java

/**
 * Form for moving foreign data// w w  w .j  av  a2s.com
 * @param emrConn Connection to the emr database
 * @param mpiConn Connection to the mpi database
 * @param sourceColumn The column that has the foreign key
 */
public ForeignDataMover(final Connection emrConn, final Connection mpiConn, String sourceColumn) {
    this.emrConn = emrConn;
    this.mpiConn = mpiConn;
    this.sourceColumn = sourceColumn;
    sourceTables = getDatabaseTables(emrConn);
    sourceTablesModel = new DefaultComboBoxModel(sourceTables.toArray(new String[sourceTables.size()]));

    destTables = getDatabaseTables(mpiConn);
    destTablesModel = new DefaultComboBoxModel(destTables.toArray(new String[destTables.size()]));

    initComponents();
    txtSelectedCollumn.setText("<html><b color='green'>" + sourceColumn + "</b></html>");
    cmbForeignTables.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) e.getItem();
                //populate primary table columns
                List primaryColumns = getTableColumns(selectedTable, emrConn);
                sourcePrimaryFields = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                cmbPrimaryKey.setModel(sourcePrimaryFields);
                sourceUniqueFields = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                cmbUniquekey.setModel(sourceUniqueFields);
            }
        }
    });
    cmbMPITables.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) e.getItem();
                //populate primary table columns
                List columns = getTableColumns(selectedTable, mpiConn);
                mpiPrimarycolumns = new DefaultComboBoxModel(columns.toArray(new String[columns.size()]));
                cmbMPIPrimaryKey.setModel(mpiPrimarycolumns);
                mpiUniquFields = new DefaultComboBoxModel(columns.toArray(new String[columns.size()]));
                cmbMPIUniqueField.setModel(mpiUniquFields);
            }
        }
    });
}

From source file:org.risk.model.MapVisualization.java

/**
 * This method is used to customize the graph which represents map of the
 * game/* w w  w  . j a v a 2  s .  c  om*/
 * @param map 
 */
private void customizeGraph(final Map map) {

    Transformer<Integer, Point2D> locationTransformer = new Transformer<Integer, Point2D>() {

        @Override
        public Point2D transform(Integer v) {

            float xPoint = states.get(v - 1).getxPoint();
            float yPoint = states.get(v - 1).getyPoint();
            return new Point2D.Float(xPoint, yPoint);
        }
    };

    StaticLayout<Integer, Number> layout = new StaticLayout<Integer, Number>(graph, locationTransformer);
    vv = new VisualizationViewer<Integer, Number>(layout);

    //vv.setBackground(Color.white);
    // add my listener for ToolTips

    vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Integer, Number>());
    vv.setVertexToolTipTransformer(new stateInfoTip<Number>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    // Remove Arrows
    vv.getRenderContext().setEdgeArrowPredicate(new Predicate<Context<Graph<Integer, Number>, Number>>() {
        public boolean evaluate(Context<Graph<Integer, Number>, Number> context) {
            return false;
        }
    });

    final PickedState<Integer> pickedState = vv.getPickedVertexState();

    pickedState.addItemListener(new ItemListener() {

        /**
         * This method is used to override itemStateChanged
         */
        @Override
        public void itemStateChanged(ItemEvent e) {
            Object selectedNode = e.getItem();
            if (selectedNode instanceof Integer) {
                Integer vertex = (Integer) selectedNode;

                if (pickedState.isPicked(vertex)) {
                    String inspectionDetail = inspectState(map, vertex);
                    JOptionPane.showMessageDialog(vv, inspectionDetail);
                }
            }
        }
    });
}

From source file:org.smart.migrate.ui.RelationDialog.java

private void cbxFKTableItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxFKTableItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        initFields(cbxFK, (String) evt.getItem());
        if (StringUtils.isNotBlank(tableRelation.getForeignKey())) {
            cbxFK.setSelectedItem(tableRelation.getForeignKey());
        }/*from  w  w w  .jav a2  s  .  c  o  m*/
    }
}

From source file:org.smart.migrate.ui.RelationDialog.java

private void cbxPKTableItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxPKTableItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        initFields(cbxPK, (String) evt.getItem());
        if (StringUtils.isNotBlank(tableRelation.getPrimaryKey())) {
            cbxPK.setSelectedItem(tableRelation.getPrimaryKey());
        }/*from w w w  .j  a  v a2  s  .c  om*/
    }
}