Example usage for javax.swing.event ListSelectionListener ListSelectionListener

List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener

Introduction

In this page you can find the example usage for javax.swing.event ListSelectionListener ListSelectionListener.

Prototype

ListSelectionListener

Source Link

Usage

From source file:com.floreantpos.ui.views.order.OrderView.java

private void addActionButtonPanel() {
    ticketView.getTicketViewerTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override//from   www  .ja v  a 2s  .c  o  m
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handleTicketItemSelection();
            }
        }
    });

    btnDone.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {

                ticketView.doFinishOrder();

            } catch (StaleObjectStateException x) {
                POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("TicketView.22")); //$NON-NLS-1$
                return;
            } catch (PosException x) {
                POSMessageDialog.showError(x.getMessage());
            } catch (Exception x) {
                POSMessageDialog.showError(Application.getPosWindow(), POSConstants.ERROR_MESSAGE, x);
            }
        }
    });

    btnCancel.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {

            if (ticketView.isCancelable()) {
                ticketView.doCancelOrder();
                return;
            }

            int result = POSMessageDialog.showYesNoQuestionDialog(null,
                    "Items have been sent to kitchen, are you sure to cancel this ticket?", "Confirm");
            if (result != JOptionPane.YES_OPTION) {
                return;
            }

            ticketView.doCancelOrder();
            ticketView.setAllowToLogOut(true);
        }
    });

    btnSend.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {

                ticketView.sendTicketToKitchen();
                ticketView.updateView();
                POSMessageDialog.showMessage("Items sent to kitchen");
            } catch (StaleObjectStateException x) {
                POSMessageDialog.showError(Application.getPosWindow(), Messages.getString("TicketView.22")); //$NON-NLS-1$
                return;
            } catch (PosException x) {
                POSMessageDialog.showError(x.getMessage());
            } catch (Exception x) {
                POSMessageDialog.showError(Application.getPosWindow(), POSConstants.ERROR_MESSAGE, x);
            }

        }
    });

    btnOrderType.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // doViewOrderInfo();
            //doChangeOrderType(); fix
        }
    });

    btnCustomer.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doAddEditCustomer();
        }
    });

    btnMisc.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            doInsertMisc(evt);
        }
    });

    btnGuestNo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCustomerNumberActionPerformed();
        }
    });

    btnSeatNo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            doAddSeatNumber();
        }
    });

    btnTableNumber.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            updateTableNumber();
        }
    });

    btnCookingInstruction.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doAddCookingInstruction();
        }
    });

    btnHold.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            OrderType orderType = currentTicket.getOrderType();
            if (orderType.isShowTableSelection() && orderType.isRequiredCustomerData()//fix
                    && !Application.getCurrentUser().hasPermission(UserPermission.HOLD_TICKET)) {
                //

                String password = PasswordEntryDialog.show(Application.getPosWindow(),
                        "Please enter privileged password");
                if (StringUtils.isEmpty(password)) {
                    return;
                }

                User user2 = UserDAO.getInstance().findUserBySecretKey(password);
                if (user2 == null) {
                    POSMessageDialog.showError(Application.getPosWindow(),
                            "No user found with that secret key");
                    return;
                } else {
                    if (!user2.hasPermission(UserPermission.HOLD_TICKET)) {
                        POSMessageDialog.showError(Application.getPosWindow(), "No permission");
                        return;
                    }
                }
            }

            if (!currentTicket.isBarTab() && (ticketView.getTicket().getTicketItems() == null
                    || ticketView.getTicket().getTicketItems().size() == 0)) {
                POSMessageDialog.showError(com.floreantpos.POSConstants.TICKET_IS_EMPTY_);
                return;
            }
            ticketView.doHoldOrder();
            ticketView.setAllowToLogOut(true);
        }
    });

    //      btnAddOn.addActionListener(new ActionListener() {
    //         @Override
    //         public void actionPerformed(ActionEvent e) {
    //            doAddAddOn();
    //         }
    //      });

    btnDiscount.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addDiscount();
        }
    });

    actionButtonPanel.add(btnOrderType);
    actionButtonPanel.add(btnCustomer);
    actionButtonPanel.add(btnTableNumber);
    actionButtonPanel.add(btnGuestNo);
    actionButtonPanel.add(btnSeatNo);
    actionButtonPanel.add(btnCookingInstruction);
    //      actionButtonPanel.add(btnAddOn);
    actionButtonPanel.add(btnMisc);
    actionButtonPanel.add(btnHold);
    actionButtonPanel.add(btnSend);
    actionButtonPanel.add(btnCancel);
    actionButtonPanel.add(btnDone);

    btnCookingInstruction.setEnabled(false);
    //      btnAddOn.setEnabled(false);
}

From source file:edu.ku.brc.specify.tasks.subpane.lm.LifeMapperPane.java

/**
 * Creates the UI.//from w w  w.j a v  a 2 s .  co  m
 */
@SuppressWarnings("unchecked")
protected void createUI() {
    currentSize = getCurrentSizeSquare();

    searchText = createTextField(25);
    searchSciNameBtn = createI18NButton("LM_SEARCH");
    list = new JList(listModel);
    imgDisplay = new ImageDisplay(IMG_WIDTH, IMG_HEIGHT, false, true);

    imgDisplay.setChangeListener(this);

    wwPanel = new WorldWindPanel(false);
    wwPanel.setPreferredSize(new Dimension(currentSize, currentSize));
    wwPanel.setZoomInMeters(600000.0);

    imgDisplay.setDoShowText(false);

    searchMyDataBtn = createI18NButton("LM_SRCH_SP_DATA");
    myDataTF = UIHelper.createTextField();

    CellConstraints cc = new CellConstraints();

    PanelBuilder pb1 = new PanelBuilder(new FormLayout("p,2px,f:p:g,2px,p", "p"));
    pb1.add(createI18NFormLabel("LM_SRCH_COL"), cc.xy(1, 1));
    pb1.add(searchText, cc.xy(3, 1));
    pb1.add(searchSciNameBtn, cc.xy(5, 1));

    PanelBuilder myPB = new PanelBuilder(new FormLayout("f:p:g,p", "p,2px,p,2px,p"));
    mySepComp = myPB.addSeparator(getResourceString("LM_MYDATA_TITLE"), cc.xyw(1, 1, 2));
    myPB.add(myDataTF, cc.xyw(1, 3, 2));
    myPB.add(searchMyDataBtn, cc.xy(2, 5));

    PanelBuilder pb2 = new PanelBuilder(new FormLayout("MAX(p;300px),2px,f:p:g", "f:p:g,20px,p"));
    pb2.add(createScrollPane(list), cc.xy(1, 1));
    pb2.add(myPB.getPanel(), cc.xy(1, 3));

    PanelBuilder pb3 = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g", "f:p:g,p,4px,p,f:p:g"));
    pb3.add(createI18NLabel("LM_WRLD_OVRVW", SwingConstants.CENTER), cc.xy(2, 2));
    pb3.add(imgDisplay, cc.xy(2, 4));

    PanelBuilder pb4 = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g", "f:p:g,p,4px,p,f:p:g"));
    pb4.add(createI18NLabel("LM_INTRACT_VW", SwingConstants.CENTER), cc.xy(2, 2));
    pb4.add(wwPanel, cc.xy(2, 4));

    PanelBuilder pb5 = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,p,f:p:g"));
    pb5.add(pb3.getPanel(), cc.xy(1, 1));
    pb5.add(pb4.getPanel(), cc.xy(1, 3));

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,8px,f:p:g", "p,8px,f:p:g"), this);
    pb.add(pb1.getPanel(), cc.xyw(1, 1, 3));
    pb.add(pb2.getPanel(), cc.xy(1, 3));
    pb.add(pb5.getPanel(), cc.xy(3, 3));

    updateMyDataUIState(false);

    searchText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                searchSciNameBtn.doClick();
            }
        }
    });

    myDataTF.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                searchMyDataBtn.doClick();
            }
        }
    });

    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (list.getSelectedIndex() == -1) {
                    wwPanel.reset();
                    imgDisplay.setImage(blueMarble);

                } else {
                    SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() {
                        @Override
                        protected Boolean doInBackground() throws Exception {
                            if (doResetWWPanel) {
                                wwPanel.reset();
                            }
                            doSearchOccur();
                            return null;
                        }

                        @Override
                        protected void done() {
                            imgDisplay.repaint();
                        }
                    };
                    worker.execute();
                }
            }
        }
    });

    searchMyDataBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    doSearchSpecifyData(myDataTF.getText().trim());
                }
            });

        }
    });

    searchSciNameBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSearchGenusSpecies();
        }
    });

    blueMarbleListener = new BufferedImageFetcherIFace() {
        @Override
        public void imageFetched(BufferedImage image) {
            blueMarble = image;
            imgDisplay.setImage(blueMarble);
        }

        @Override
        public void error() {
            blueMarbleTries++;
            if (blueMarbleTries < 5) {
                blueMarbleRetry();
            }
        }
    };

    blueMarbleURL = BG_URL + String.format("WIDTH=%d&HEIGHT=%d", IMG_WIDTH, IMG_HEIGHT);

    pointsMapImageListener = new BufferedImageFetcherIFace() {
        @Override
        public void imageFetched(final BufferedImage image) {
            if (renderImage == null) {
                renderImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
            }
            Graphics2D g2d = renderImage.createGraphics();
            if (g2d != null) {
                g2d.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT);
                if (blueMarble != null) {
                    g2d.drawImage(blueMarble, 0, 0, null);
                }
                if (image != null) {
                    g2d.drawImage(image, 0, 0, null);
                }
                g2d.dispose();

                imgDisplay.setImage(renderImage);
            }
        }

        @Override
        public void error() {
        }
    };
    blueMarbleRetry();
}

From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java

private void initMeasurements() {
    addMeasurements();/*  www  . ja va 2s .  c o m*/
    measurementSelectedList.setModel(new DefaultListModel());
    measurementDescriptionTextArea.setText("");
    updateMeasurementButtonsStatus();

    measurementAvailableList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent evt) {
            measurementAvailableListSelectionListner();
        }
    });
    measurementSelectedList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent evt) {
            measurementSelectedListSelectionListner();
        }
    });
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeoChooserDlg.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override// w  w  w  .  ja v a2s  .com
public void createUI() {
    boolean doStatesOrCounties = doAllCountries[1] || doAllCountries[2] || doInvCountry[1] || doInvCountry[2];
    //this.whichBtns = doStatesOrCounties && !doInvCountry[1] && rankId > 200 ? CustomDialog.OKCANCELAPPLYHELP : CustomDialog.OKCANCELHELP;

    boolean isStCnty = true;//rankId > 200; 

    dataListModel = new DefaultListModel<GeoSearchResultsItem>();
    mainList = new JList<GeoSearchResultsItem>(dataListModel);
    JScrollPane sb = createScrollPane(mainList, true);

    String listDim;
    if (UIHelper.isWindows()) {
        listDim = "250px";
        Dimension sz = new Dimension(250, 250);
        mainList.setPreferredSize(sz);
        sb.setPreferredSize(sz);
    } else {
        listDim = "f:p:g";
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g",
            "p,2px,p,12px,p,2px," + listDim + ",8px,p,4px,p,10px,p" + (isStCnty ? ",8px,p" : "")));

    this.contentPanel = pb.getPanel();

    super.createUI();

    okBtn.setEnabled(false);

    calcProgress();

    try {
        if (coInfoList != null && coInfoList.size() > 0) {
            fillFromLuceneResults();
        } else {
            fillFromQuery();
        }

        mainList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    getOkBtn().doClick();

                } else if (e.getClickCount() == 1 && !noMatchesFound && !mainList.isSelectionEmpty()) {
                    getOkBtn().setEnabled(true);
                }
            }
        });
        mainList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    listItemSelected();
                }
            }
        });

        updateNameCB = createCheckBox("Update the Name in the Geography tree."); // I18N
        //mergeCB      = createCheckBox("Merge all the geographies with the same name.");
        addISOCodeCB = createCheckBox("Add the ISO Code to the record");
        isoCodeTF = createTextField(8);
        isoCodeTF.setVisible(rankId < 400);

        updateNameCB.setSelected(isUpdateNamesChecked);
        //mergeCB.setSelected(true);
        addISOCodeCB.setSelected(true);

        updateNameCB.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(final ChangeEvent e) {
                isUpdateNamesChecked = updateNameCB.isSelected();
            }
        });

        DocumentListener dl = new DocumentAdaptor() {
            @Override
            protected void changed(DocumentEvent e) {
                okBtn.setEnabled(!isoCodeTF.getText().isEmpty());
            }
        };
        isoCodeTF.getDocument().addDocumentListener(dl);
        //labels.add(nameStr);// + "  (Unknown)");

        PanelBuilder lookPB = null;
        JButton lookupBtn = null;
        if (isStCnty) {
            lookPB = new PanelBuilder(new FormLayout("f:p:g,p", "p"));
            lookupBtn = createI18NButton("CLNUP_GEO_LOOK_UP_ISO");
            lookPB.add(lookupBtn, cc.xy(2, 1));
            lookupBtn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    globalRankSearch();
                }
            });
        }

        int i = 0;
        ArrayList<String> labels = new ArrayList<String>();
        while (i < parentNames.length && parentRanks[i] > -1) {
            labels.add(i18NLabelsMap.get(parentRanks[i++]));
        }

        PanelBuilder pbTop = new PanelBuilder(
                new FormLayout("p,2px,f:p:g", UIHelper.createDuplicateJGoodiesDef("p", "2px", labels.size())));
        int y = 1;
        for (i = 0; i < labels.size(); i++) {
            JLabel lbl = createLabel(parentNames[i]);
            pbTop.add(createFormLabel(labels.get(i)), cc.xy(1, y));
            pbTop.add(lbl, cc.xy(3, y));
            lbl.setBackground(Color.WHITE);
            lbl.setOpaque(true);
            y += 2;
        }

        pb.add(pbTop.getPanel(), cc.xy(1, 3));
        pb.addSeparator("Possible standard Geography choices", cc.xy(1, 5)); // I18N
        pb.add(sb, cc.xy(1, 7));
        pb.add(updateNameCB, cc.xy(1, 9));

        PanelBuilder pbc = new PanelBuilder(new FormLayout("p,10px,p,f:p:g", "p"));
        pbc.add(addISOCodeCB, cc.xy(1, 1));
        pbc.add(isoCodeTF, cc.xy(3, 1));

        pb.add(pbc.getPanel(), cc.xy(1, 11));

        i = 13;
        if (isStCnty) {
            pb.add(lookPB.getPanel(), cc.xy(1, i));
            i += 2;
        }

        //if (doAllCountries[0])
        if (false) // hidding it for now
        {
            progressBar = new JProgressBar(0, 100);
            progressBar.setStringPainted(true);
            PanelBuilder prgPB = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p"));
            prgPB.add(createFormLabel("Progress"), cc.xy(1, 1));
            prgPB.add(progressBar, cc.xy(3, 1));
            pb.add(prgPB.getPanel(), cc.xy(1, i));
            i += 2;
        }

        mainList.setSelectedIndex(selectedIndex);
        mainList.ensureIndexIsVisible(selectedIndex);

        noMatchesFound = dataListModel.size() == 0;

        // Optional Depending on States / Countries
        if (doStatesOrCounties) {
            if (dataListModel.getSize() == 0) {
                dataListModel.addElement(new GeoSearchResultsItem("No matches found."));// I18N
            }
        }

        pb.setDefaultDialogBorder();

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (UIHelper.isWindows()) {
        setResizable(false);
    }
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Must be called at the end 'createUI'
}

From source file:de.mprengemann.intellij.plugin.androidicons.dialogs.AndroidBatchScaleImporter.java

private void initRowSelection() {
    table.getColumnModel().setColumnSelectionAllowed(false);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override// w  w w  . j  a va 2  s.co  m
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            int selectedRow = table.getSelectedRow();
            if (table.getSelectedRowCount() == 1) {
                updateImage(controller.getImage(selectedRow));
            } else {
                updateImage(null);
            }
        }
    });
}

From source file:com.microsoft.alm.plugin.idea.ui.checkout.CheckoutPageModelImpl.java

private void setupSelectionListener() {
    // Set up event listener to set the Directory name when the selection changes
    repositoryTableModel.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override/*from w w w. j a va2 s  .  c o  m*/
        public void valueChanged(ListSelectionEvent e) {
            // No need to change things while the list is adjusting
            if (!e.getValueIsAdjusting()) {
                final ServerContext row = repositoryTableModel.getSelectedContext();
                // Get the repository name and set the directory name to match
                final String repositoryName = (row != null && row.getGitRepository() != null)
                        ? row.getGitRepository().getName()
                        : "";
                setDirectoryName(repositoryName);
            }
        }
    });
}

From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java

@Override
protected JPanel createPanel() {

    // add search textfield
    final JPanel inputPanel = new JPanel();
    inputPanel.setBorder(lineBorder(Color.black));
    inputPanel.setLayout(new GridBagLayout());

    inputPanel.add(itemNameFilter.getPanel(), constraints(0, 0).anchorWest().noResizing().end());

    importMarketLogButton.addActionListener(new ActionListener() {

        @Override// w  w  w. j av  a2  s.  c  o m
        public void actionPerformed(ActionEvent e) {
            importMarketLogs();
        }

    });

    inputPanel.add(importMarketLogButton, constraints(0, 1).anchorWest().noResizing().end());

    // add item description text area
    selectedItemDescription.setEditable(false);
    selectedItemDescription.setWrapStyleWord(true);
    selectedItemDescription.setLineWrap(true);

    final JScrollPane selectedItemDescPanel = new JScrollPane(selectedItemDescription);
    selectedItemDescPanel.setBorder(BorderFactory.createTitledBorder("Selected item"));

    // setup table
    tableModel.setViewFilter(this.itemNameFilter.getViewFilter());
    table.setModel(tableModel);
    table.setRowSorter(tableModel.getRowSorter());
    table.setDefaultRenderer(String.class, new StalePriceInfoHighlighter());
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            if (!e.getValueIsAdjusting()) {
                final int viewRow = table.getSelectedRow();
                if (viewRow != -1) {
                    final int modelRow = table.convertRowIndexToModel(viewRow);
                    updateItemDescriptionDisplay(modelRow);
                }
            }
        }

    });

    table.setFillsViewportHeight(true);
    table.addMouseListener(popupListener);

    table.setFillsViewportHeight(true);

    // setup split pane
    final JPanel result = new JPanel();

    final JPanel topPanel = new JPanel();

    new GridLayoutBuilder().add(new GridLayoutBuilder.HorizontalGroup(new GridLayoutBuilder.Cell(inputPanel),
            new GridLayoutBuilder.Cell(selectedItemDescPanel))).addTo(topPanel);

    final JSplitPane pane = new ImprovedSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, tablePane);

    pane.setDividerLocation(0.3d); // only works because of the splitpane
    // hack
    pane.setContinuousLayout(true);

    result.setLayout(new GridBagLayout());
    result.add(pane, constraints().resizeBoth().useRemainingSpace().end());

    return result;
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

/**
 * Constructor.//from ww  w  .  j a  v a  2s. c o  m
 */
public GapFillingFrame(final AbstractTabView atv, final Instances dataSet, final Attribute attr,
        final int dateIdx, final int valuesBeforeAndAfter, final int position, final int gapsize,
        final StationsDataProvider gcp, final boolean inBatchMode) {
    super();

    setTitle("Gap filling for " + attr.name() + " ("
            + dataSet.attribute(dateIdx).formatDate(dataSet.instance(position).value(dateIdx)) + " -> "
            + dataSet.attribute(dateIdx).formatDate(dataSet.instance(position + gapsize).value(dateIdx)) + ")");
    LogoHelper.setLogo(this);

    this.atv = atv;

    this.dataSet = dataSet;
    this.attr = attr;
    this.dateIdx = dateIdx;
    this.valuesBeforeAndAfter = valuesBeforeAndAfter;
    this.position = position;
    this.gapsize = gapsize;

    this.gcp = gcp;

    final Instances testds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0,
            dataSet.numAttributes() - 1, Math.max(0, position - valuesBeforeAndAfter),
            Math.min(position + gapsize + valuesBeforeAndAfter, dataSet.numInstances() - 1));

    this.attrNames = WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(testds);

    this.isGapSimulated = (this.attrNames.contains(attr.name()));
    this.originaldataSet = new Instances(dataSet);
    if (this.isGapSimulated) {
        setTitle(getTitle() + " [SIMULATED GAP]");
        /*final JXLabel fictiveGapLabel=new JXLabel("                                                                        FICTIVE GAP");
        fictiveGapLabel.setForeground(Color.RED);
        fictiveGapLabel.setFont(new Font(fictiveGapLabel.getFont().getName(), Font.PLAIN,fictiveGapLabel.getFont().getSize()*2));
        final JXPanel fictiveGapPanel=new JXPanel();
        fictiveGapPanel.setLayout(new BorderLayout());
        fictiveGapPanel.add(fictiveGapLabel,BorderLayout.CENTER);
        getContentPane().add(fictiveGapPanel,BorderLayout.NORTH);*/
        this.attrNames.remove(attr.name());
        this.originalDataBeforeGapSimulation = dataSet.attributeToDoubleArray(attr.index());
        for (int i = position; i < position + gapsize; i++)
            dataSet.instance(i).setMissing(attr);
    }

    final Object[] attrNamesObj = this.attrNames.toArray();

    this.centerPanel = new JXPanel();
    this.centerPanel.setLayout(new BorderLayout());
    getContentPane().add(this.centerPanel, BorderLayout.CENTER);

    //final JXPanel algoPanel=new JXPanel();
    //getContentPane().add(algoPanel,BorderLayout.NORTH);
    final JXPanel filterPanel = new JXPanel();
    //filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.Y_AXIS));      
    filterPanel.setLayout(new GridBagLayout());
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(10, 10, 10, 10);
    getContentPane().add(filterPanel, BorderLayout.WEST);

    final JXComboBox algoCombo = new JXComboBox(Algo.values());
    algoCombo.setBorder(new TitledBorder("Algorithm"));
    filterPanel.add(algoCombo, gbc);
    gbc.gridy++;

    final JXLabel infoLabel = new JXLabel("Usable = with no missing values on the period");
    //infoLabel.setBorder(new TitledBorder(""));
    filterPanel.add(infoLabel, gbc);
    gbc.gridy++;

    final JList<Object> timeSeriesList = new JList<Object>(attrNamesObj);
    timeSeriesList.setBorder(new TitledBorder("Usable time series"));
    timeSeriesList.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final JScrollPane jcpMap = new JScrollPane(timeSeriesList);
    jcpMap.setPreferredSize(new Dimension(225, 150));
    jcpMap.setMinimumSize(new Dimension(225, 150));
    filterPanel.add(jcpMap, gbc);
    gbc.gridy++;

    final JXPanel mapPanel = new JXPanel();
    mapPanel.setBorder(new TitledBorder(""));
    mapPanel.setLayout(new BorderLayout());
    mapPanel.add(gcp.getMapPanel(Arrays.asList(attr.name()), this.attrNames, true), BorderLayout.CENTER);
    filterPanel.add(mapPanel, gbc);
    gbc.gridy++;

    final JXLabel mssLabel = new JXLabel(
            "<html>Most similar usable serie: <i>[... computation ...]</i></html>");
    mssLabel.setBorder(new TitledBorder(""));
    filterPanel.add(mssLabel, gbc);
    gbc.gridy++;

    final JXLabel nsLabel = new JXLabel("<html>Nearest usable serie: <i>[... computation ...]</i></html>");
    nsLabel.setBorder(new TitledBorder(""));
    filterPanel.add(nsLabel, gbc);
    gbc.gridy++;

    final JXLabel ussLabel = new JXLabel("<html>Upstream serie: <i>[... computation ...]</i></html>");
    ussLabel.setBorder(new TitledBorder(""));
    filterPanel.add(ussLabel, gbc);
    gbc.gridy++;

    final JXLabel dssLabel = new JXLabel("<html>Downstream serie: <i>[... computation ...]</i></html>");
    dssLabel.setBorder(new TitledBorder(""));
    filterPanel.add(dssLabel, gbc);
    gbc.gridy++;

    final JCheckBox hideOtherSeriesCB = new JCheckBox("Hide the others series");
    hideOtherSeriesCB.setSelected(DEFAULT_HIDE_OTHER_SERIES_OPTION);
    filterPanel.add(hideOtherSeriesCB, gbc);
    gbc.gridy++;

    final JCheckBox showErrorCB = new JCheckBox("Show error on plot");
    filterPanel.add(showErrorCB, gbc);
    gbc.gridy++;

    final JCheckBox zoomCB = new JCheckBox("Auto-adjusted size");
    zoomCB.setSelected(DEFAULT_ZOOM_OPTION);
    filterPanel.add(zoomCB, gbc);
    gbc.gridy++;

    final JCheckBox multAxisCB = new JCheckBox("Multiple axis");
    filterPanel.add(multAxisCB, gbc);
    gbc.gridy++;

    final JCheckBox showEnvelopeCB = new JCheckBox("Show envelope (all algorithms, SLOW)");
    filterPanel.add(showEnvelopeCB, gbc);
    gbc.gridy++;

    final JXButton showModelButton = new JXButton("Show the model");
    filterPanel.add(showModelButton, gbc);
    gbc.gridy++;

    showModelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            final JXFrame dialog = new JXFrame();
            dialog.setTitle("Model");
            LogoHelper.setLogo(dialog);
            dialog.getContentPane().removeAll();
            dialog.getContentPane().setLayout(new BorderLayout());
            final JTextPane modelTxtPane = new JTextPane();
            modelTxtPane.setText(gapFiller.getModel());
            modelTxtPane.setBackground(Color.WHITE);
            modelTxtPane.setEditable(false);
            final JScrollPane jsp = new JScrollPane(modelTxtPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            jsp.setSize(new Dimension(400 - 20, 400 - 20));
            dialog.getContentPane().add(jsp, BorderLayout.CENTER);
            dialog.setSize(new Dimension(400, 400));
            dialog.setLocationRelativeTo(centerPanel);
            dialog.pack();
            dialog.setVisible(true);
        }
    });

    algoCombo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
                showModelButton.setEnabled(gapFiller.hasExplicitModel());
            } catch (final Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    timeSeriesList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(final ListSelectionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
                mapPanel.removeAll();
                final List<String> currentlySelected = new ArrayList<String>();
                currentlySelected.add(attr.name());
                for (final Object sel : timeSeriesList.getSelectedValues())
                    currentlySelected.add(sel.toString());
                mapPanel.add(gcp.getMapPanel(currentlySelected, attrNames, true), BorderLayout.CENTER);
            } catch (final Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    hideOtherSeriesCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (final Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    showErrorCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    zoomCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    showEnvelopeCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    multAxisCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    this.inBatchMode = inBatchMode;

    if (!inBatchMode) {
        try {
            refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), new int[0],
                    DEFAULT_HIDE_OTHER_SERIES_OPTION, false, DEFAULT_ZOOM_OPTION, false, false);
            showModelButton.setEnabled(gapFiller.hasExplicitModel());
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

    if (!inBatchMode) {
        /* automatically select computed series */
        new AbstractSimpleAsync<Void>(true) {
            @Override
            public Void execute() throws Exception {
                mostSimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(testds, attr, attrNames,
                        false);
                mssLabel.setText("<html>Most similar usable serie: <b>" + mostSimilar + "</b></html>");

                nearest = gcp.findNearestStation(attr.name(), attrNames);
                nsLabel.setText("<html>Nearest usable serie: <b>" + nearest + "</b></html>");

                upstream = gcp.findUpstreamStation(attr.name(), attrNames);
                if (upstream != null) {
                    ussLabel.setText("<html>Upstream usable serie: <b>" + upstream + "</b></html>");
                } else {
                    ussLabel.setText("<html>Upstream usable serie: <b>N/A</b></html>");
                }

                downstream = gcp.findDownstreamStation(attr.name(), attrNames);
                if (downstream != null) {
                    dssLabel.setText("<html>Downstream usable serie: <b>" + downstream + "</b></html>");
                } else {
                    dssLabel.setText("<html>Downstream usable serie: <b>N/A</b></html>");
                }

                timeSeriesList.setSelectedIndices(
                        new int[] { attrNames.indexOf(mostSimilar), attrNames.indexOf(nearest),
                                attrNames.indexOf(upstream), attrNames.indexOf(downstream) });

                return null;
            }

            @Override
            public void onSuccess(final Void result) {
            }

            @Override
            public void onFailure(final Throwable caught) {
                caught.printStackTrace();
            }
        }.start();
    } else {
        try {
            mostSimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(testds, attr, attrNames, false);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        nearest = gcp.findNearestStation(attr.name(), attrNames);
        upstream = gcp.findUpstreamStation(attr.name(), attrNames);
        downstream = gcp.findDownstreamStation(attr.name(), attrNames);
    }
}

From source file:com.microsoft.alm.plugin.idea.common.ui.checkout.CheckoutPageModelImpl.java

private void setupSelectionListener() {
    // Set up event listener to set the Directory name when the selection changes
    repositoryTableModel.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override/*from w w  w .j a v  a  2 s.co m*/
        public void valueChanged(ListSelectionEvent e) {
            // No need to change things while the list is adjusting
            if (!e.getValueIsAdjusting()) {
                final ServerContext row = repositoryTableModel.getSelectedContext();
                // Get the repository name and set the directory name to match
                final String repositoryName = parentModel.getRepositoryName(row);
                setDirectoryName(repositoryName);
            }
        }
    });
}

From source file:ca.uhn.hl7v2.testpanel.ui.AddMessageDialog.java

private void initLocal() {

    DefaultListModel versionListModel = new DefaultListModel();
    myVersionList.setModel(versionListModel);
    for (Version nextVersion : Version.values()) {
        versionListModel.addElement(nextVersion.getVersion());
    }//w  w  w  .  j av a2s .  c om

    myVersionList.setSelectedIndex(versionListModel.getSize() - 1);
    myVersionList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent theE) {
            updateTypes();
        }
    });

    myMessageTypeListModel = new DefaultListModel();
    myMessageTypeList.setModel(myMessageTypeListModel);

    updateTypes();

}