Example usage for javax.swing ListSelectionModel addListSelectionListener

List of usage examples for javax.swing ListSelectionModel addListSelectionListener

Introduction

In this page you can find the example usage for javax.swing ListSelectionModel addListSelectionListener.

Prototype

void addListSelectionListener(ListSelectionListener x);

Source Link

Document

Add a listener to the list that's notified each time a change to the selection occurs.

Usage

From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java

private void initRawPanel() {
    rawPanel.setLayout(new BorderLayout());

    // Textarea/*from  w  ww  . jav a  2 s .c o m*/
    textPane.setEditable(false);

    document = textPane.getStyledDocument();
    addStylesToDocument();

    try {
        document.insertString(0, "", document.getStyle("regular"));
    } catch (BadLocationException ex) {
        LOGGER.warn("Problem setting style", ex);

    }

    OverlayPanel testPanel = new OverlayPanel(textPane, Localization.lang("paste text here"));

    testPanel.setPreferredSize(new Dimension(450, 255));
    testPanel.setMaximumSize(new Dimension(450, Integer.MAX_VALUE));

    // Setup fields (required to be done before setting up popup menu)
    fieldList = new JList<>(getAllFields());
    fieldList.setCellRenderer(new SimpleCellRenderer(fieldList.getFont()));
    ListSelectionModel listSelectionModel = fieldList.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener(new FieldListSelectionHandler());
    fieldList.addMouseListener(new FieldListMouseListener());

    // After the call to getAllFields
    initPopupMenuAndToolbar();

    //Add listener to components that can bring up popup menus.
    MouseListener popupListener = new PopupListener(inputMenu);
    textPane.addMouseListener(popupListener);
    testPanel.addMouseListener(popupListener);

    JPanel leftPanel = new JPanel(new BorderLayout());

    leftPanel.add(toolBar, BorderLayout.NORTH);
    leftPanel.add(testPanel, BorderLayout.CENTER);

    JPanel inputPanel = setUpFieldListPanel();

    // parse with FreeCite button
    parseWithFreeCiteButton.addActionListener(event -> {
        if (parseWithFreeCiteAndAddEntries()) {
            okPressed = false; // we do not want to have the super method to handle our entries, we do it on our own
            dispose();
        }
    });

    rawPanel.add(leftPanel, BorderLayout.CENTER);
    rawPanel.add(inputPanel, BorderLayout.EAST);

    JLabel desc = new JLabel("<html><h3>" + Localization.lang("Plain text import") + "</h3><p>"
            + Localization.lang("This is a simple copy and paste dialog. First load or paste some text into "
                    + "the text input area.<br>After that, you can mark text and assign it to a BibTeX field.")
            + "</p></html>");
    desc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    rawPanel.add(desc, BorderLayout.SOUTH);
}

From source file:simx.profiler.info.actor.ActorTypeInfoTopComponent.java

/**
 * This constructor initializes the top component. It configures the
 * tales creates the visulizations./* w  ww  .j  ava 2s  .  co  m*/
 */
public ActorTypeInfoTopComponent() {
    initComponents();
    setName(Bundle.CTL_ActorTypeInfoTopComponent());
    setToolTipText(Bundle.HINT_ActorTypeInfoTopComponent());

    this.content = new InstanceContent();

    this.associateLookup(new AbstractLookup(this.content));

    ListSelectionModel listSelectionModel = this.instancesTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((final ListSelectionEvent e) -> {
        if (instancesTable.getSelectedRow() != -1) {
            final ActorInstance actorInstance = actorInstances.get(instancesTable.getSelectedRow());
            final ActorType actorType = actorInstance.type;
            final Set<Object> selectedObjects = new HashSet<>();
            selectedObjects.add(actorType);
            selectedObjects.add(actorInstance);
            content.set(selectedObjects, null);
        }
    });

    listSelectionModel = this.messagesSentTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesSentTable.getSelectedRow() != -1) {
            messagesReceivedTable.clearSelection();
            messagesProcessedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = sentMessages.get(messagesSentTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    listSelectionModel = this.messagesReceivedTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesReceivedTable.getSelectedRow() != -1) {
            messagesSentTable.clearSelection();
            messagesProcessedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = receivedMessages.get(messagesReceivedTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    listSelectionModel = this.messagesProcessedTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesProcessedTable.getSelectedRow() != -1) {
            messagesSentTable.clearSelection();
            messagesReceivedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = processedMessages.get(messagesProcessedTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    this.messagesSentDataSet = new DefaultPieDataset();
    this.messagesReceivedDataSet = new DefaultPieDataset();
    this.messagesProcessedDataSet = new DefaultPieDataset();

    this.createPieChart(this.messagesSentDataSet, this.messagesSentPanel);
    this.createPieChart(this.messagesReceivedDataSet, this.messagesReceivedPanel);
    this.createPieChart(this.messagesProcessedDataSet, this.messagesProcessedPanel);
}

From source file:simx.profiler.info.actor.ActorInstanceInfoTopComponent.java

/**
 * This constructor initializes the top component. It configures the
 * tales creates the visulizations.//from w  w w. ja  va 2 s  .  co m
 */
public ActorInstanceInfoTopComponent() {
    initComponents();
    setName(Bundle.CTL_ActorInstanceInfoTopComponent());
    setToolTipText(Bundle.HINT_ActorInstanceInfoTopComponent());

    this.content = new InstanceContent();

    this.associateLookup(new AbstractLookup(this.content));

    ListSelectionModel listSelectionModel = this.messageSentTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messageSentTable.getSelectedRow() != -1) {
            messagesReceivedTable.clearSelection();
            messageProcessedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = sentMessages.get(messageSentTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    listSelectionModel = this.messagesReceivedTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messagesReceivedTable.getSelectedRow() != -1) {
            messageSentTable.clearSelection();
            messageProcessedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = receivedMessages.get(messagesReceivedTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    listSelectionModel = this.messageProcessedTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        if (messageProcessedTable.getSelectedRow() != -1) {
            messageSentTable.clearSelection();
            messagesReceivedTable.clearSelection();
            if (selectedMessageType != null)
                content.remove(selectedMessageType);
            selectedMessageType = processedMessages.get(messageProcessedTable.getSelectedRow()).getKey();
            content.add(selectedMessageType);
        }
    });

    this.messagesSentDataSet = new DefaultPieDataset();
    this.messagesReceivedDataSet = new DefaultPieDataset();
    this.messagesProcessedDataSet = new DefaultPieDataset();

    this.createPieChart(this.messagesSentDataSet, this.messagesSentPanel);
    this.createPieChart(this.messagesReceivedDataSet, this.messagesReceivedPanel);
    this.createPieChart(this.messagesProcessedDataSet, this.messagesProcessedPanel);

    this.frequencyPlotData = new XYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", this.frequencyPlotData);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(261, 157));
    this.frequencyPanel.setLayout(new BorderLayout());
    this.frequencyPanel.add(chartPanel, BorderLayout.CENTER);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

private Component createObsTable(ListSelectionModel seriesSelectionModel) {
    final XTable result = new XTable();
    ColorCellRenderer renderer = new ColorCellRenderer(FontAwesome.FA_CIRCLE_O);
    result.setDefaultRenderer(Color.class, renderer);
    result.setDefaultEditor(Color.class, new ColorCellEditor(colorSchemeSupport, renderer));
    result.setDefaultRenderer(Font.class, FontCellRenderer.INSTANCE);
    result.setDefaultEditor(Font.class, new FontCellEditor());
    result.setDefaultRenderer(Stroke.class, StrokeCellRenderer.INSTANCE);
    result.setDefaultEditor(Stroke.class, new StrokeCellEditor());
    seriesSelectionModel.addListSelectionListener(new ListSelectionListener() {
        @Override//from   w w  w.  j  a  v  a 2 s.co m
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int index = e.getFirstIndex();
                result.setModel(index != -1 ? new ObsModel(support.seriesInfos[index].obsInfos) : null);
                result.getModel().addTableModelListener(new TableModelListener() {
                    @Override
                    public void tableChanged(TableModelEvent e) {
                        chart.fireChartChanged();
                    }
                });
            }
        }
    });
    return ModernUI.withEmptyBorders(new JScrollPane(result));
}

From source file:com.aw.swing.mvp.binding.component.BndSJTable.java

/**
 * Register a selection listener to the JTable related to this class
 *
 * @param rowSelectionListener that will be called when the selection of the JTable changes
 *///from ww  w . j  a  v  a2s  .c o  m
public void registerRowSelectionListener(final RowSelectionListener rowSelectionListener) {
    ListSelectionModel rowSM = jTable.getSelectionModel();
    rowSM.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            //Ignore extra messages.
            if (e.getValueIsAdjusting())
                return;

            ListSelectionModel lsm = (ListSelectionModel) e.getSource();
            if (lsm.isSelectionEmpty()) {
                logger.debug("No rows are selected.");
                rowSelectionListener.onClearSelectedRow();
            } else {
                int selectedRowIndex = lsm.getMinSelectionIndex();
                logger.debug("Row " + selectedRowIndex + " is now selected.");
                Object selectedRow = getSelectedRow();
                rowSelectionListener.onSelectedRow(selectedRowIndex, selectedRow);
            }
        }
    });
}

From source file:gui.AdministracionGrupos.java

/**
     * Creates new form AdministracionGrupos
     *///www.  j av  a 2  s  .  co  m
    public AdministracionGrupos(Desktop aparent) {
        //         super(aparent, true);
        this.parent = aparent;
        initComponents();
        setLocationRelativeTo(null);

        //        setClosable(true);
        //        this.pack();
        //        this.setFrameIcon(new ImageIcon(this.getClass().getResource("/resources/logo tru-test.png")));
        cargarPuertos();

        cargarStick();

        corralSelector.valor_nuevo = true;
        razaSelector.valor_nuevo = true;

        Frame F = JOptionPane.getFrameForComponent(this);
        reporteEntradas = new ReporteEntradas(F);

        String titulos[] = { "Id Animal", "Arete Visual", "Arete Electronico", "Proveedor", "Fecha de Compra",
                "Arete Siniiga", "Arete Campaa", "Sexo", "Ingreso al Corral", "Numero de Lote", "No. Compra",
                "Peso Actual", "Peso de Compra" };

        t_animales.setTitulos(titulos);
        t_animales.cambiarTitulos();

        t_animales.setFormato(new int[] { Table.letra, Table.letra, Table.letra, Table.letra, Table.fecha,
                Table.letra, Table.letra, Table.letra, Table.fecha, Table.numero_double, Table.letra,
                Table.numero_double, Table.numero_double });

        t_animales.ocultarcolumna(0);

        corralActivo = true;

        //   graficar();
        ListSelectionModel lsm = this.t_animales.getSelectionModel();

        lsm.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                selectAnimal();
            }
        });

        t_pesos = new Table();

        t_pesos.setModel(
                new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Title 1", "Title 2" }));

        String titulos2[] = { "Fecha", "Peso (kg)" };

        t_pesos.setTitulos(titulos2);
        t_pesos.cambiarTitulos();
        t_pesos.setFormato(new int[] { 3, 1 });

        g = new Grafica();

        Grafica = g.createChart(g.createDatasetPesos(t_pesos));

        jPanel1 = new ChartPanel(Grafica);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 216, Short.MAX_VALUE));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 186, Short.MAX_VALUE));

        panelGrafica.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, panelGrafica.getWidth(),
                panelGrafica.getHeight()));

        cargarDatosIniciales();

        graficar();

        //        Image i = null;
        //        i = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resources/logo tru-test.png"));
        //        setIconImage(i);
        this.t_alimentoIngresado.textFieldDouble();
        this.t_pesoMaximo.textFieldDouble();
        this.t_pesoMinimo.textFieldDouble();
        this.t_pesoPromedio.textFieldDouble();
        this.t_totalKilos.textFieldDouble();

        this.setTitle(this.getTitle() + " " + rancho.descripcion);

        cargarComponentes();

    }

From source file:com.eviware.soapui.impl.wsdl.monitor.SoapMonitor.java

private JComponent buildLog() {
    tableModel = new MonitorLogTableModel();
    logTable = new JXTable(1, 2);
    logTable.setColumnControlVisible(true);
    logTable.setModel(tableModel);//ww w .  j  a  v a 2 s.  c o  m
    logTable.setHorizontalScrollEnabled(true);
    logTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    operationFilter = new PatternFilter(".*", 0, 4);
    operationFilter.setAcceptNull(true);
    interfaceFilter = new PatternFilter(".*", 0, 3);
    interfaceFilter.setAcceptNull(true);
    targetHostFilter = new PatternFilter(".*", 0, 2);
    targetHostFilter.setAcceptNull(true);
    requestHostFilter = new PatternFilter(".*", 0, 1);
    requestHostFilter.setAcceptNull(true);

    Filter[] filters = new Filter[] { requestHostFilter, targetHostFilter, interfaceFilter, operationFilter };

    FilterPipeline pipeline = new FilterPipeline(filters);
    logTable.setFilters(pipeline);

    ListSelectionModel sel = logTable.getSelectionModel();
    sel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            int row = logTable.getSelectedRow();
            if (row == -1) {
                // requestXmlDocument.setXml( null );
                // responseXmlDocument.setXml( null );
                requestModelItem.setMessageExchange(null);
            } else {
                WsdlMonitorMessageExchange exchange = tableModel.getMessageExchangeAt(row);
                requestModelItem.setMessageExchange(exchange);
                // responseModelItem.setMessageExchange( exchange );
                // requestXmlDocument.setXml( exchange.getRequestContent() );
                // responseXmlDocument.setXml( exchange.getResponseContent() );
            }

            addToMockServiceButton.setEnabled(row != -1);
            addToTestCaseButton.setEnabled(row != -1);
            // addToRestTestCaseButton.setEnabled( row != -1 );
            createRequestButton.setEnabled(row != -1);
        }
    });

    JPanel tablePane = new JPanel();
    tablePane.setLayout(new BorderLayout());

    toolbar.addGlue();

    tablePane.add(buildFilterBar(), BorderLayout.NORTH);
    tablePane.add(new JScrollPane(logTable), BorderLayout.CENTER);

    return tablePane;
}

From source file:simx.profiler.info.application.ActorsInfoTopComponent.java

public ActorsInfoTopComponent() {
    initComponents();//www.j a  v  a 2s  .  c o  m
    setName(Bundle.CTL_ActorsInfoTopComponent());
    setToolTipText(Bundle.HINT_ActorsInfoTopComponent());

    this.content = new InstanceContent();

    this.associateLookup(new AbstractLookup(this.content));

    this.profilingData = ProfilingData.getLoadedProfilingData();
    final Map<MessageType, Integer> applicationCommunicationDataLocal = new HashMap<>();
    this.profilingData.getMessageTypes().stream().forEach((messageType) -> {
        applicationCommunicationDataLocal.put(messageType, messageType.getTimesSent());
    });
    this.applicationCommunicationData = new CommunicationData(new ImmutableTupel<>(null, null),
            applicationCommunicationDataLocal);
    this.content.set(Collections.singleton(this.applicationCommunicationData), null);

    this.actorTypes = this.profilingData.getActorTypes();
    this.actorTypeInformationTable.setModel(new ActorTypeInformationTableModel(this.profilingData));
    ListSelectionModel listSelectionModel = this.actorTypeInformationTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((final ListSelectionEvent e) -> {
        setSelectedActorType(actorTypes.get(actorTypeInformationTable.getSelectedRow()));
    });
    this.actorInstances = profilingData.getActorInstances();
    listSelectionModel = this.actorInstanceInformationTable.getSelectionModel();
    listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSelectionModel.addListSelectionListener((ListSelectionEvent e) -> {
        final ActorInstance actorInstance = actorInstances.get(actorInstanceInformationTable.getSelectedRow());
        setSelectedActorInstance(actorInstance);
    });
    this.actorInstanceInformationTable.setModel(new ActorInstanceInformationTableModel(this.profilingData));

    long minProcessingTime = Long.MAX_VALUE;
    long maxProcessingTime = Long.MIN_VALUE;

    for (final ActorType type : this.actorTypes) {
        if (type.getOverallProcessingTime() < minProcessingTime)
            minProcessingTime = type.getOverallProcessingTime();
        if (type.getOverallProcessingTime() > maxProcessingTime)
            maxProcessingTime = type.getOverallProcessingTime();
    }

    final Map<ImmutableTupel<ActorType, ActorType>, Integer> typeCommunicationScaleFactors = new HashMap<>();
    int minMessagesCount = Integer.MAX_VALUE;
    int maxMessagesCount = Integer.MIN_VALUE;
    for (final ActorType actorType : this.actorTypes) {
        final Map<ActorType, Map<MessageType, Integer>> s = actorType.getReceiverStatistics();
        for (final Map.Entry<ActorType, Map<MessageType, Integer>> e : s.entrySet()) {
            int count = 0;
            count = e.getValue().entrySet().stream().map((d) -> d.getValue()).reduce(count, Integer::sum);
            typeCommunicationScaleFactors.put(new ImmutableTupel<>(actorType, e.getKey()), count);
            if (count < minMessagesCount)
                minMessagesCount = count;
            if (count > maxMessagesCount)
                maxMessagesCount = count;
        }
    }

    int messagesSpan = maxMessagesCount - minMessagesCount;
    for (final Map.Entry<ImmutableTupel<ActorType, ActorType>, Integer> e : typeCommunicationScaleFactors
            .entrySet()) {
        final int factor = (((e.getValue() - minMessagesCount) * 4) / messagesSpan) + 1;
        typeCommunicationScaleFactors.put(e.getKey(), factor);
    }

    double timeSpan = maxProcessingTime - minProcessingTime;

    final Map<ActorType, Double> typeComputationScaleFactors = new HashMap<>();
    for (final ActorType type : this.actorTypes) {
        typeComputationScaleFactors.put(type,
                ((double) (type.getOverallProcessingTime() - minProcessingTime) * 0.4 / timeSpan) + 0.6);
    }

    final ActorTypeGraphScene actorTypeGraphScene = new ActorTypeGraphScene(this, typeComputationScaleFactors,
            typeCommunicationScaleFactors);
    actorTypeGraphScene.addObjectSceneListener(new ObjectSceneListener() {

        @Override
        public void objectAdded(final ObjectSceneEvent ose, final Object o) {
        }

        @Override
        public void objectRemoved(final ObjectSceneEvent ose, final Object o) {
        }

        @Override
        public void objectStateChanged(final ObjectSceneEvent ose, final Object o, final ObjectState os,
                final ObjectState os1) {
        }

        @Override
        public void selectionChanged(final ObjectSceneEvent ose, final Set<Object> oldSelection,
                final Set<Object> newSelection) {
            boolean communicationDataSet = false;
            for (final Object o : newSelection) {
                if (o instanceof ActorType)
                    setSelectedActorType((ActorType) o);
                if (o instanceof CommunicationData) {
                    setSelectedCommunicationData((CommunicationData) o);
                    communicationDataSet = true;
                }
            }
            if (!communicationDataSet)
                setSelectedCommunicationData(null);
        }

        @Override
        public void highlightingChanged(final ObjectSceneEvent ose, final Set<Object> set,
                final Set<Object> set1) {
        }

        @Override
        public void hoverChanged(final ObjectSceneEvent ose, final Object o, final Object o1) {
        }

        @Override
        public void focusChanged(final ObjectSceneEvent ose, final Object o, final Object o1) {
        }
    }, ObjectSceneEventType.OBJECT_SELECTION_CHANGED);
    this.typeScrollPane.setViewportView(actorTypeGraphScene.createView());

    this.actorTypes.stream().forEach((actorType) -> {
        actorTypeGraphScene.addNode(actorType);
    });
    this.actorTypes.stream().forEach((actorType) -> {
        final Map<ActorType, Map<MessageType, Integer>> s = actorType.getReceiverStatistics();
        s.entrySet().stream().forEach((e) -> {
            final CommunicationData edge = new CommunicationData(new ImmutableTupel<>(actorType, e.getKey()),
                    e.getValue());
            actorTypeGraphScene.addEdge(edge);
            actorTypeGraphScene.setEdgeSource(edge, actorType);
            actorTypeGraphScene.setEdgeTarget(edge, e.getKey());
        });
    });

    minProcessingTime = Long.MAX_VALUE;
    maxProcessingTime = Long.MIN_VALUE;

    for (final ActorInstance instance : this.actorInstances) {
        if (instance.getOverallProcessingTime() < minProcessingTime)
            minProcessingTime = instance.getOverallProcessingTime();
        if (instance.getOverallProcessingTime() > maxProcessingTime)
            maxProcessingTime = instance.getOverallProcessingTime();
    }

    timeSpan = maxProcessingTime - minProcessingTime;

    final Map<ImmutableTupel<ActorInstance, ActorInstance>, Integer> instanceCommunicationScaleFactors = new HashMap<>();
    minMessagesCount = Integer.MAX_VALUE;
    maxMessagesCount = Integer.MIN_VALUE;
    for (final ActorInstance instance : this.actorInstances) {
        final Map<ActorInstance, Map<MessageType, Integer>> s = instance.getReceiverStatistics();
        for (final Map.Entry<ActorInstance, Map<MessageType, Integer>> e : s.entrySet()) {
            int count = 0;
            count = e.getValue().entrySet().stream().map((d) -> d.getValue()).reduce(count, Integer::sum);
            instanceCommunicationScaleFactors.put(new ImmutableTupel<>(instance, e.getKey()), count);
            if (count < minMessagesCount)
                minMessagesCount = count;
            if (count > maxMessagesCount)
                maxMessagesCount = count;
        }
    }

    messagesSpan = maxMessagesCount - minMessagesCount;
    for (final Map.Entry<ImmutableTupel<ActorInstance, ActorInstance>, Integer> e : instanceCommunicationScaleFactors
            .entrySet()) {
        final int factor = (((e.getValue() - minMessagesCount) * 4) / messagesSpan) + 1;
        instanceCommunicationScaleFactors.put(e.getKey(), factor);
    }

    final Map<ActorInstance, Double> instanceComputationScaleFactors = new HashMap<>();
    for (final ActorInstance instance : this.actorInstances) {
        instanceComputationScaleFactors.put(instance,
                ((double) (instance.getOverallProcessingTime() - minProcessingTime) * 0.4 / timeSpan) + 0.6);
    }
    final ActorInstanceGraphScene actorInstanceGraphScene = new ActorInstanceGraphScene(this,
            instanceComputationScaleFactors, instanceCommunicationScaleFactors);

    actorInstanceGraphScene.addObjectSceneListener(new ObjectSceneListener() {

        @Override
        public void objectAdded(final ObjectSceneEvent ose, final Object o) {
        }

        @Override
        public void objectRemoved(final ObjectSceneEvent ose, final Object o) {
        }

        @Override
        public void objectStateChanged(final ObjectSceneEvent ose, final Object o, final ObjectState os,
                final ObjectState os1) {
        }

        @Override
        public void selectionChanged(final ObjectSceneEvent ose, final Set<Object> oldSelection,
                final Set<Object> newSelection) {
            boolean communicationDataSet = false;
            for (final Object o : newSelection) {
                if (o instanceof ActorInstance)
                    setSelectedActorInstance((ActorInstance) o);
                if (o instanceof CommunicationData) {
                    setSelectedCommunicationData((CommunicationData) o);
                    communicationDataSet = true;
                }
            }
            if (!communicationDataSet)
                setSelectedCommunicationData(null);
        }

        @Override
        public void highlightingChanged(final ObjectSceneEvent ose, final Set<Object> set,
                final Set<Object> set1) {
        }

        @Override
        public void hoverChanged(final ObjectSceneEvent ose, final Object o, final Object o1) {
        }

        @Override
        public void focusChanged(final ObjectSceneEvent ose, final Object o, final Object o1) {
        }
    }, ObjectSceneEventType.OBJECT_SELECTION_CHANGED);

    this.instancesScrollPane.setViewportView(actorInstanceGraphScene.createView());
    this.actorInstances.stream().forEach((actorInstance) -> {
        actorInstanceGraphScene.addNode(actorInstance);
    });
    this.actorInstances.stream().forEach((actorInstance) -> {
        final Map<ActorInstance, Map<MessageType, Integer>> s = actorInstance.getReceiverStatistics();
        s.entrySet().stream().forEach((e) -> {
            final CommunicationData edge = new CommunicationData(
                    new ImmutableTupel<>(actorInstance, e.getKey()), e.getValue());
            actorInstanceGraphScene.addEdge(edge);
            actorInstanceGraphScene.setEdgeSource(edge, actorInstance);
            actorInstanceGraphScene.setEdgeTarget(edge, e.getKey());
        });
    });

    this.dopPlotData = new XYSeriesCollection();
    JFreeChart dopChart = ChartFactory.createXYLineChart("", "", "", this.dopPlotData);
    final ChartPanel dopChartPanel = new ChartPanel(dopChart);
    dopChartPanel.setPreferredSize(new java.awt.Dimension(261, 157));
    this.dopPanel.setLayout(new BorderLayout());
    this.dopPanel.add(dopChartPanel, BorderLayout.CENTER);

    final XYSeries plotData = new XYSeries("Degree of Parallelism");

    final List<ParallelismEvent> parallelismEvents = this.profilingData.getParallelismEvents();
    Collections.sort(parallelismEvents);
    int parallelismLevel = 1;
    long lastTimeStamp = parallelismEvents.get(0).timestamp;
    final long firstTimeStamp = lastTimeStamp;
    final Map<Integer, Long> histogramData = new HashMap<>();
    plotData.add(0, 1);
    for (int i = 1; i < parallelismEvents.size(); ++i) {
        if (histogramData.containsKey(parallelismLevel)) {
            final long old = histogramData.get(parallelismLevel);
            histogramData.put(parallelismLevel, parallelismEvents.get(i).timestamp - lastTimeStamp + old);
        } else {
            histogramData.put(parallelismLevel, parallelismEvents.get(i).timestamp - lastTimeStamp);
        }
        lastTimeStamp = parallelismEvents.get(i).timestamp;
        if (parallelismEvents.get(i).eventType == ParallelismEvent.ParallelimEventTypes.PROCESSING_START) {
            ++parallelismLevel;
        } else {
            --parallelismLevel;
        }
        plotData.add((double) (lastTimeStamp - firstTimeStamp) / 1000000000.0, parallelismLevel);
    }
    this.dopPlotData.addSeries(plotData);
    this.parallelismHistogramDataSet = new DefaultCategoryDataset();

    double avgParallelism1 = 0.0;
    double avgParallelism2 = 0.0;
    long t = 0;

    for (int i = 1; i < histogramData.size(); ++i) {
        t += histogramData.get(i);
    }

    for (int i = 0; i < histogramData.size(); ++i) {
        parallelismHistogramDataSet.addValue((double) histogramData.get(i) / 1000000.0, "",
                i == 0 ? "Idle" : "" + i);
        avgParallelism1 += i * ((double) histogramData.get(i) / this.profilingData.applicationRunTime());
        avgParallelism2 += i * ((double) histogramData.get(i) / t);
    }

    final JFreeChart chart = ChartFactory.createBarChart("", "Parallelism", "ms",
            this.parallelismHistogramDataSet, PlotOrientation.VERTICAL, false, true, false);
    final ChartPanel chartPanel = new ChartPanel(chart);
    this.parallelismHistogramPanel.setLayout(new BorderLayout());
    this.parallelismHistogramPanel.add(chartPanel, BorderLayout.CENTER);

    this.runtimeTextField.setText("" + (this.profilingData.applicationRunTime() / 1000000.0));
    this.computationTimeMsTextField.setText("" + (this.profilingData.getOverallProcessingTime() / 1000000.0));
    this.computationTimePercentTextField.setText("" + (this.profilingData.getOverallProcessingTime() * 100.0
            / this.profilingData.applicationRunTime()));
    this.actorInstancesTextField.setText("" + this.actorInstances.size());
    this.messagesSentTextField.setText("" + this.profilingData.getMessagesSentCount());
    this.messagesSentPerSecondTextField.setText("" + ((double) this.profilingData.getMessagesSentCount()
            * 1000000000.0 / this.profilingData.applicationRunTime()));
    this.messagesProcessedTextField.setText("" + this.profilingData.getMessagesProcessedCount());
    this.messagesProcessedPerSecondTextField
            .setText("" + ((double) this.profilingData.getMessagesProcessedCount() * 1000000000.0
                    / this.profilingData.applicationRunTime()));
    this.averageTimeInMailboxTextField.setText("" + (this.profilingData.getAverageTimeInMailbox() / 1000000.0));
    this.avgParallelismWithIdleTimeTextField.setText("" + avgParallelism1);
    this.avgParallelismWithouIdleTimeTextField.setText("" + avgParallelism2);

    final SpawnTreeGraphScene spawnTreeGraphScene = new SpawnTreeGraphScene(this);
    this.spawnTreeScrollPane.setViewportView(spawnTreeGraphScene.createView());

    this.actorInstances.stream().forEach((actorInstance) -> {
        spawnTreeGraphScene.addNode(actorInstance);
    });
    for (final ActorInstance actorInstance : this.actorInstances) {
        if (actorInstance.supervisor != null) {
            final ImmutableTupel<ActorInstance, ActorInstance> edge = new ImmutableTupel(
                    actorInstance.supervisor, actorInstance);
            spawnTreeGraphScene.addEdge(edge);
            spawnTreeGraphScene.setEdgeSource(edge, actorInstance.supervisor);
            spawnTreeGraphScene.setEdgeTarget(edge, actorInstance);
        }
    }
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java

/**
 * Class Constructor./*www  . ja va 2s.c  om*/
 *
 * @param model
 *
 * @see
 */
public RegistryObjectsTable(TableModel model) {
    // Gives a TableColumnModel so that AutoCreateColumnsFromModel will be false.
    super(model, new DefaultTableColumnModel());

    this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    if (model instanceof RegistryObjectsTableModel) {
        tableModel = (RegistryObjectsTableModel) model;
    } else if (model instanceof TableSorter) {
        tableModel = (RegistryObjectsTableModel) (((TableSorter) model).getModel());
    } else {
        Object[] unexpectedTableModelArgs = { model };
        MessageFormat form = new MessageFormat(resourceBundle.getString("error.unexpectedTableModel"));
        throw new IllegalArgumentException(form.format(unexpectedTableModelArgs));
    }

    setToolTipText(resourceBundle.getString("tip.registryObjectsTable"));

    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    ListSelectionModel rowSM = getSelectionModel();
    stdRowHeight = getRowHeight();
    setRowHeight(stdRowHeight * 3);

    rowSM.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            ListSelectionModel lsm = (ListSelectionModel) e.getSource();

            if (!lsm.isSelectionEmpty()) {
                setSelectedRow(lsm.getMinSelectionIndex());
            } else {
                setSelectedRow(-1);
            }
        }
    });

    createPopup();

    addRenderers();

    // Add listener to self so that I can bring up popup menus on right mouse click
    popupListener = new PopupListener();
    addMouseListener(popupListener);

    //add listener for 'authenticated' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this);

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);
}

From source file:org.fhcrc.cpl.viewer.quant.gui.QuantitationReviewer.java

/**
 * Initialize all GUI components and display the UI
 *///from   w  w  w.ja v  a 2s . c  om
protected void initGUI() {
    settingsCLM = new ProteinQuantChartsCLM(false);

    setTitle("Qurate");
    try {
        setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewer.xml", this);
        assert null != contentPanel;
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    //Menu
    openFileAction = new OpenFileAction(this);
    createChartsAction = new CreateChartsAction();
    filterPepXMLAction = new FilterPepXMLAction(this);
    proteinSummaryAction = new ProteinSummaryAction(this);

    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewerMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    //Global stuff
    setSize(fullWidth, fullHeight);
    setContentPane(contentPanel);
    ListenerHelper helper = new ListenerHelper(this);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    leftPanel.setLayout(new GridBagLayout());
    leftPanel.setBorder(BorderFactory.createLineBorder(Color.gray));

    //Properties panel stuff
    propertiesTable = new QuantEvent.QuantEventPropertiesTable();
    propertiesScrollPane = new JScrollPane();
    propertiesScrollPane.setViewportView(propertiesTable);
    propertiesScrollPane.setMinimumSize(new Dimension(propertiesWidth, propertiesHeight));

    //event summary table; disembodied
    eventSummaryTable = new QuantEventsSummaryTable();
    eventSummaryTable.setVisible(true);
    ListSelectionModel tableSelectionModel = eventSummaryTable.getSelectionModel();
    tableSelectionModel.addListSelectionListener(new EventSummaryTableListSelectionHandler());
    JScrollPane eventSummaryScrollPane = new JScrollPane();
    eventSummaryScrollPane.setViewportView(eventSummaryTable);
    eventSummaryScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventSummaryFrame = new Frame("All Events");
    eventSummaryFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            eventSummaryFrame.setVisible(false);
        }
    });
    eventSummaryFrame.setSize(950, 450);
    eventSummaryFrame.add(eventSummaryScrollPane);

    //fields related to navigation
    navigationPanel = new JPanel();
    backButton = new JButton("<");
    backButton.setToolTipText("Previous Event");
    backButton.setMaximumSize(new Dimension(50, 30));
    backButton.setEnabled(false);
    forwardButton = new JButton(">");
    forwardButton.setToolTipText("Next Event");
    forwardButton.setMaximumSize(new Dimension(50, 30));
    forwardButton.setEnabled(false);
    showEventSummaryButton = new JButton("Show All");
    showEventSummaryButton.setToolTipText("Show all events in a table");
    showEventSummaryButton.setEnabled(false);

    helper.addListener(backButton, "buttonBack_actionPerformed");
    helper.addListener(forwardButton, "buttonForward_actionPerformed");
    helper.addListener(showEventSummaryButton, "buttonShowEventSummary_actionPerformed");

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    gbc.anchor = GridBagConstraints.WEST;
    navigationPanel.add(backButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    navigationPanel.add(forwardButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    navigationPanel.add(showEventSummaryButton, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    navigationPanel.setBorder(BorderFactory.createTitledBorder("Event"));
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Fields related to curation of events
    curationPanel = new JPanel();
    curationPanel.setLayout(new GridBagLayout());
    curationPanel.setBorder(BorderFactory.createTitledBorder("Curation"));
    //Quantitation curation
    JPanel quantCurationPanel = new JPanel();
    quantCurationPanel.setLayout(new GridBagLayout());
    quantCurationPanel.setBorder(BorderFactory.createTitledBorder("Quantitation"));
    quantCurationButtonGroup = new ButtonGroup();
    JRadioButton unknownRadioButton = new JRadioButton("?");
    JRadioButton goodRadioButton = new JRadioButton("Good");
    JRadioButton badRadioButton = new JRadioButton("Bad");
    onePeakRatioRadioButton = new JRadioButton("1-Peak");

    unknownRadioButton.setEnabled(false);
    goodRadioButton.setEnabled(false);
    badRadioButton.setEnabled(false);
    onePeakRatioRadioButton.setEnabled(false);

    quantCurationButtonGroup.add(unknownRadioButton);
    quantCurationButtonGroup.add(goodRadioButton);
    quantCurationButtonGroup.add(badRadioButton);
    quantCurationButtonGroup.add(onePeakRatioRadioButton);

    unknownRadioButtonModel = unknownRadioButton.getModel();
    goodRadioButtonModel = goodRadioButton.getModel();
    badRadioButtonModel = badRadioButton.getModel();
    onePeakRadioButtonModel = onePeakRatioRadioButton.getModel();

    helper.addListener(unknownRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(goodRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(badRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(onePeakRadioButtonModel, "buttonCuration_actionPerformed");

    gbc.anchor = GridBagConstraints.WEST;
    quantCurationPanel.add(unknownRadioButton, gbc);
    quantCurationPanel.add(badRadioButton, gbc);
    quantCurationPanel.add(goodRadioButton, gbc);
    quantCurationPanel.add(onePeakRatioRadioButton, gbc);

    gbc.anchor = GridBagConstraints.PAGE_START;
    //ID curation
    JPanel idCurationPanel = new JPanel();
    idCurationPanel.setLayout(new GridBagLayout());
    idCurationPanel.setBorder(BorderFactory.createTitledBorder("ID"));
    idCurationButtonGroup = new ButtonGroup();
    JRadioButton idUnknownRadioButton = new JRadioButton("?");
    JRadioButton idGoodRadioButton = new JRadioButton("Good");
    JRadioButton idBadRadioButton = new JRadioButton("Bad");
    idUnknownRadioButton.setEnabled(false);
    idGoodRadioButton.setEnabled(false);
    idBadRadioButton.setEnabled(false);

    idCurationButtonGroup.add(idUnknownRadioButton);
    idCurationButtonGroup.add(idGoodRadioButton);
    idCurationButtonGroup.add(idBadRadioButton);
    idUnknownRadioButtonModel = idUnknownRadioButton.getModel();
    idGoodRadioButtonModel = idGoodRadioButton.getModel();
    idBadRadioButtonModel = idBadRadioButton.getModel();
    helper.addListener(idUnknownRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idGoodRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idBadRadioButton, "buttonIDCuration_actionPerformed");
    gbc.anchor = GridBagConstraints.WEST;
    idCurationPanel.add(idUnknownRadioButton, gbc);
    idCurationPanel.add(idBadRadioButton, gbc);
    idCurationPanel.add(idGoodRadioButton, gbc);

    gbc.gridwidth = GridBagConstraints.RELATIVE;
    curationPanel.add(quantCurationPanel, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    curationPanel.add(idCurationPanel, gbc);

    //curation comment
    commentTextField = new JTextField();
    commentTextField.setToolTipText("Comment on this event");
    //saves after every keypress.  Would be more efficient to save when navigating away or saving to file
    commentTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (quantEvents == null)
                return;
            QuantEvent quantEvent = quantEvents.get(displayedEventIndex);
            //save the comment, being careful about tabs and new lines
            quantEvent.setComment(commentTextField.getText().replace("\t", " ").replace("\n", " "));
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });
    curationPanel.add(commentTextField, gbc);

    assessmentPanel = new JPanel();
    assessmentPanel.setLayout(new GridBagLayout());
    assessmentPanel.setBorder(BorderFactory.createTitledBorder("Algorithmic Assessment"));
    assessmentTypeTextField = new JTextField();
    assessmentTypeTextField.setEditable(false);
    assessmentPanel.add(assessmentTypeTextField, gbc);
    assessmentDescTextField = new JTextField();
    assessmentDescTextField.setEditable(false);
    assessmentPanel.add(assessmentDescTextField, gbc);

    //Theoretical peak distribution
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    theoreticalPeaksPanel = new JPanel();
    theoreticalPeaksPanel.setBorder(BorderFactory.createTitledBorder("Theoretical Peaks"));
    theoreticalPeaksPanel.setLayout(new GridBagLayout());
    theoreticalPeaksPanel.setMinimumSize(new Dimension(leftPanelWidth - 10, theoreticalPeaksPanelHeight));
    theoreticalPeaksPanel.setMaximumSize(new Dimension(1200, theoreticalPeaksPanelHeight));
    showTheoreticalPeaks();

    //Add everything to the left panel
    gbc.insets = new Insets(0, 5, 0, 5);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    leftPanel.addComponentListener(new LeftPanelResizeListener());
    gbc.weighty = 10;
    gbc.fill = GridBagConstraints.VERTICAL;
    leftPanel.add(propertiesScrollPane, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_END;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(assessmentPanel, gbc);
    leftPanel.add(theoreticalPeaksPanel, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(curationPanel, gbc);
    leftPanel.add(navigationPanel, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Chart display
    multiChartDisplay = new TabbedMultiChartDisplayPanel();
    multiChartDisplay.setResizeDelayMS(0);

    rightPanel.addComponentListener(new RightPanelResizeListener());
    rightPanel.add(multiChartDisplay, gbc);

    //status message
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    //paranoia.  Sometimes it seems Qurate doesn't exit when you close every window
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == WindowEvent.WINDOW_CLOSED) {
                dispose();
                System.exit(0);
            }
        }
    });

}