Example usage for java.awt.event MouseAdapter MouseAdapter

List of usage examples for java.awt.event MouseAdapter MouseAdapter

Introduction

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

Prototype

MouseAdapter

Source Link

Usage

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

/**
 * Constructor./*  www.  j  a v a2  s  .co m*/
 */
GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp)
        throws Exception {
    LogoHelper.setLogo(this);
    this.setTitle("KnowledgeDB: explorer");

    this.gcp = gcp;

    this.tablePanel = new JXPanel();
    this.tablePanel.setBorder(new TitledBorder("Cases"));

    final JXPanel highPanel = new JXPanel();
    highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS));
    highPanel.add(this.tablePanel);

    this.geomapPanel = new JXPanel();
    this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>()));
    highPanel.add(this.geomapPanel);

    this.caseChartPanel = new JXPanel();
    this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap"));

    this.mostSimilarChartPanel = new JXPanel();
    this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar"));
    this.nearestChartPanel = new JXPanel();
    this.nearestChartPanel.setBorder(new TitledBorder("Nearest"));
    this.downstreamChartPanel = new JXPanel();
    this.downstreamChartPanel.setBorder(new TitledBorder("Downstream"));
    this.upstreamChartPanel = new JXPanel();
    this.upstreamChartPanel.setBorder(new TitledBorder("Upstream"));

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    //getContentPane().add(new JCheckBox("Use incomplete series"));
    getContentPane().add(highPanel);
    //getContentPane().add(new JXButton("Export"));      
    getContentPane().add(caseChartPanel);
    getContentPane().add(mostSimilarChartPanel);
    getContentPane().add(nearestChartPanel);
    getContentPane().add(downstreamChartPanel);
    getContentPane().add(upstreamChartPanel);

    //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly();      
    final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB();

    final JXTable gapsTable = buidJXTable(kdbDS);
    final JScrollPane tableScrollPane = new JScrollPane(gapsTable);
    tableScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight())));
    this.tablePanel.add(tableScrollPane);

    gapsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    gapsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(final ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final int modelRow = gapsTable.getSelectedRow();

                final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString();
                final int gapsize = (int) Double
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue();
                final int position = (int) Double
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue();

                final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString();
                final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString();
                final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString();
                final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString();

                final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString();
                final boolean useDiscretizedTime = Boolean
                        .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString());

                try {
                    geomapPanel.removeAll();

                    caseChartPanel.removeAll();

                    mostSimilarChartPanel.removeAll();
                    nearestChartPanel.removeAll();
                    downstreamChartPanel.removeAll();
                    upstreamChartPanel.removeAll();

                    final Set<String> selected = new HashSet<String>();

                    final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0,
                            ds.numAttributes() - 1,
                            Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)),
                            Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize),
                                    ds.numInstances() - 1));

                    final List<String> attributeNames = WekaTimeSeriesUtil
                            .getNamesOfAttributesWithoutGap(tmpds);
                    //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds);
                    attributeNames.remove(attrname);
                    attributeNames.remove("timestamp");

                    if (Boolean.valueOf(mostSimilarFlag)) {
                        final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil
                                .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames,
                                        false);
                        selected.add(mostSimilarStationName);
                        final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx,
                                mostSimilarStationAttr, gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        mostSimilarChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(nearestFlag)) {
                        final String nearestStationName = gcp.findNearestStation(attrname, attributeNames);
                        selected.add(nearestStationName);
                        final Attribute nearestStationAttr = ds.attribute(nearestStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        nearestChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(downstreamFlag)) {
                        final String downstreamStationName = gcp.findDownstreamStation(attrname,
                                attributeNames);
                        selected.add(downstreamStationName);
                        final Attribute downstreamStationAttr = ds.attribute(downstreamStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        downstreamChartPanel.add(cp0);
                    }

                    if (Boolean.valueOf(upstreamFlag)) {
                        final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames);
                        selected.add(upstreamStationName);
                        final Attribute upstreamStationAttr = ds.attribute(upstreamStationName);

                        final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr,
                                gapsize, position);
                        cp0.getChart().removeLegend();
                        cp0.setPreferredSize(CHART_DIMENSION);
                        upstreamChartPanel.add(cp0);
                    }

                    final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime);
                    final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx,
                            ds.attribute(attrname), gapsize, position, gapFiller, selected);
                    cp.getChart().removeLegend();
                    cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(),
                            (int) (CHART_DIMENSION.getHeight() * 1.5)));
                    caseChartPanel.add(cp);

                    geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected));

                    getContentPane().repaint();
                    pack();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    gapsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!e.isPopupTrigger()) {
                // nothing?
            } else {
                final JPopupMenu jPopupMenu = new JPopupMenu("feur");

                final JMenuItem mExport = new JMenuItem("Export this table as CSV");
                mExport.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        final JFileChooser fc = new JFileChooser();
                        fc.setAcceptAllFileFilterUsed(false);
                        final int returnVal = fc.showSaveDialog(gapsTable);
                        if (returnVal == JFileChooser.APPROVE_OPTION) {
                            try {
                                final File file = fc.getSelectedFile();
                                WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file);
                            } catch (Exception ee) {
                                ee.printStackTrace();
                            }
                        }
                    }
                });
                jPopupMenu.add(mExport);

                jPopupMenu.show(gapsTable, e.getX(), e.getY());
            }
        }
    });

    setPreferredSize(new Dimension(FRAME_WIDTH, 1000));

    pack();
    setVisible(true);

    /* select the first row */
    gapsTable.setRowSelectionInterval(0, 0);
}

From source file:com.android.tools.idea.gradle.structure.editors.MavenDependencyLookupDialog.java

public MavenDependencyLookupDialog(@NotNull Project project, @Nullable Module module) {
    super(project, true);
    myAndroidModule = module != null && AndroidFacet.getInstance(module) != null;
    myProgressIcon.suspend();/*w  ww . j  ava  2 s .com*/

    mySearchField.setButtonIcon(AllIcons.Actions.Menu_find);
    mySearchField.getButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            startSearch();
        }
    });

    mySearchTextField = mySearchField.getTextField();
    mySearchTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (StringUtil.isEmpty(mySearchField.getText())) {
                return;
            }
            if (!isValidCoordinateSelected()) {
                startSearch();
            } else {
                close(OK_EXIT_CODE);
            }
        }
    });

    boolean preview = false;
    if (module != null) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null) {
            AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
            if (androidModel != null) {
                ApiVersion minSdkVersion = androidModel.getSelectedVariant().getMergedFlavor()
                        .getMinSdkVersion();
                if (minSdkVersion != null) {
                    preview = new AndroidVersion(minSdkVersion.getApiLevel(), minSdkVersion.getCodename())
                            .isPreview();
                }
            }
        }
    }

    RepositoryUrlManager manager = RepositoryUrlManager.get();
    for (SupportLibrary library : SupportLibrary.values()) {
        String libraryCoordinate = manager.getLibraryStringCoordinate(library, true);
        if (libraryCoordinate != null) {
            Artifact artifact = Artifact.fromCoordinate(libraryCoordinate);
            if (artifact != null) {
                myAndroidSdkLibraries.add(libraryCoordinate);
                myShownItems.add(artifact);
            }
        }
    }
    myShownItems.addAll(COMMON_LIBRARIES);
    myResultList.setModel(new CollectionComboBoxModel(myShownItems, null));
    myResultList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            Artifact value = (Artifact) myResultList.getSelectedValue();
            if (value != null) {
                mySearchTextField.setText(value.getCoordinates());
            }
        }
    });
    myResultList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2 && isValidCoordinateSelected()) {
                close(OK_EXIT_CODE);
            }
        }
    });

    myOKAction = new OkAction() {
        @Override
        protected void doAction(ActionEvent e) {
            String text = mySearchField.getText();
            if (text != null && !hasVersion(text) && isKnownLocalLibrary(text)) {
                // If it's a known library that doesn't exist in the local repository, we don't display the version for it. Add it back so that
                // final string is a valid gradle coordinate.
                mySearchField.setText(text + ':' + REVISION_ANY);
            }
            super.doAction(e);
        }
    };
    init();
}

From source file:gda.gui.mca.McaGUI.java

private SimplePlot getSimplePlot() {
    if (simplePlot == null) {
        simplePlot = new SimplePlot();
        simplePlot.setYAxisLabel("Values");
        simplePlot.setTitle("MCA");
        /*//  w  w w  . j  av  a2 s  . c om
         * do not attempt to get calibration until the analyser is available getEnergyCalibration();
         */

        simplePlot.setXAxisLabel("Channel Number");

        simplePlot.setTrackPointer(true);
        JPopupMenu menu = simplePlot.getPopupMenu();
        JMenuItem item = new JMenuItem("Add Region Of Interest");
        menu.add(item);
        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "To add a region of interest, please click on region low"
                        + " and region high channels\n" + "in the graph and set the index\n");
                regionClickCount = 0;
            }
        });

        JMenuItem calibitem = new JMenuItem("Calibrate Energy");
        /*
         * Comment out as calibration is to come from the analyser directly menu.add(calibitem);
         */
        calibitem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    // regionClickCount = 0;
                    int[] data = (int[]) analyser.getData();
                    double[] dData = new double[data.length];
                    for (int i = 0; i < dData.length; i++) {
                        dData[i] = data[i];
                    }
                    if (energyCalibrationDialog == null) {
                        energyCalibrationDialog = new McaCalibrationPanel(
                                (EpicsMCARegionOfInterest[]) analyser.getRegionsOfInterest(), dData, mcaName);
                        energyCalibrationDialog.addIObserver(McaGUI.this);
                    }
                    energyCalibrationDialog.setVisible(true);
                } catch (DeviceException e1) {
                    logger.error("Exception: " + e1.getMessage());
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, ex.getMessage());
                    ex.printStackTrace();
                }
            }

        });

        simplePlot.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent me) {
                // /////////System.out.println("Mouse clicked " +
                // me.getX() + " "
                // /////// + me.getY());
                SimpleDataCoordinate coordinates = simplePlot.convertMouseEvent(me);
                if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY()) && regionClickCount == 0) {
                    regionLow = coordinates.toArray();
                    regionClickCount++;
                } else if (simplePlot.getScreenDataArea().contains(me.getX(), me.getY())
                        && regionClickCount == 1) {
                    regionHigh = coordinates.toArray();
                    regionClickCount++;

                    if (regionValid(regionLow[0], regionHigh[0])) {

                        final String s = (String) JOptionPane.showInputDialog(null,
                                "Please select the Region Index:\n", "Region Of Interest",
                                JOptionPane.PLAIN_MESSAGE, null, null, String.valueOf(getNextRegion()));
                        Thread t1 = uk.ac.gda.util.ThreadManager.getThread(new Runnable() {
                            @Override
                            public void run() {

                                try {

                                    if (s != null) {
                                        int rIndex = Integer.parseInt(s);
                                        EpicsMCARegionOfInterest[] epc = { new EpicsMCARegionOfInterest() };
                                        epc[0].setRegionLow(regionLow[0]);
                                        epc[0].setRegionHigh(regionHigh[0]);
                                        epc[0].setRegionIndex(rIndex);
                                        epc[0].setRegionName("region " + rIndex);
                                        analyser.setRegionsOfInterest(epc);

                                        addRegionMarkers(rIndex, regionLow[0], regionHigh[0]);
                                    }

                                } catch (DeviceException e) {
                                    logger.error("Unable to set the table values");
                                }

                            }

                        });
                        t1.start();
                    }
                }
            }

        });

        // TODO note that selectePlot cannot be changed runtime
        simplePlot.initializeLine(selectedPlot);
        simplePlot.setLineName(selectedPlot, getSelectedPlotString());
        simplePlot.setLineColor(selectedPlot, getSelectedPlotColor());
        simplePlot.setLineType(selectedPlot, "LineOnly");

    }
    return simplePlot;
}

From source file:com.android.tools.idea.structure.gradle.MavenDependencyLookupDialog.java

public MavenDependencyLookupDialog(@NotNull Project project, @Nullable Module module) {
    super(project, true);
    myAndroidModule = module != null && AndroidFacet.getInstance(module) != null;
    myProgressIcon.suspend();// w  ww .j a v a2 s .c om

    mySearchField.setButtonIcon(AllIcons.Actions.Menu_find);
    mySearchField.getButton().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            startSearch();
        }
    });

    mySearchTextField = mySearchField.getTextField();
    mySearchTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (StringUtil.isEmpty(mySearchField.getText())) {
                return;
            }
            if (!isValidCoordinateSelected()) {
                startSearch();
            } else {
                close(OK_EXIT_CODE);
            }
        }
    });

    boolean preview = false;
    if (module != null) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null) {
            IdeaAndroidProject androidProject = facet.getIdeaAndroidProject();
            if (androidProject != null) {
                ApiVersion minSdkVersion = androidProject.getSelectedVariant().getMergedFlavor()
                        .getMinSdkVersion();
                if (minSdkVersion != null) {
                    preview = new AndroidVersion(minSdkVersion.getApiLevel(), minSdkVersion.getCodename())
                            .isPreview();
                }
            }
        }
    }

    RepositoryUrlManager manager = RepositoryUrlManager.get();
    for (String libraryId : RepositoryUrlManager.EXTRAS_REPOSITORY.keySet()) {
        String libraryCoordinate = manager.getLibraryCoordinate(libraryId, null, preview);
        if (libraryCoordinate != null) {
            Artifact artifact = Artifact.fromCoordinate(libraryCoordinate, libraryId);
            if (artifact != null) {
                myAndroidSdkLibraries.add(libraryCoordinate);
                myShownItems.add(artifact);
            }
        }
    }
    myShownItems.addAll(COMMON_LIBRARIES);
    myResultList.setModel(new CollectionComboBoxModel(myShownItems, null));
    myResultList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            Artifact value = (Artifact) myResultList.getSelectedValue();
            if (value != null) {
                mySearchTextField.setText(value.getCoordinates());
            }
        }
    });
    myResultList.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2 && isValidCoordinateSelected()) {
                close(OK_EXIT_CODE);
            }
        }
    });

    myOKAction = new OkAction() {
        @Override
        protected void doAction(ActionEvent e) {
            String text = mySearchField.getText();
            if (text != null && !hasVersion(text)
                    && RepositoryUrlManager.EXTRAS_REPOSITORY.containsKey(getArtifact(text))) {
                // If it's a known library that doesn't exist in the local repository, we don't display the version for it. Add it back so that
                // final string is a valid gradle coordinate.
                mySearchField.setText(text + ':' + REVISION_ANY);
            }
            super.doAction(e);
        }
    };
    init();
}

From source file:gtu._work.ui.SaveFileToPropertiesUI.java

private void initGUI() {
    try {//w  w w .  j av  a2  s .c om
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        this.setTitle("save file to properties");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("load", null, jPanel1, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel1.add(jScrollPane2, BorderLayout.CENTER);
                    {
                        textArea = new JTextArea();
                        jScrollPane2.setViewportView(textArea);
                    }
                }
                {
                    jPanel2 = new JPanel();
                    jPanel1.add(jPanel2, BorderLayout.NORTH);
                    jPanel2.setPreferredSize(new java.awt.Dimension(400, 40));
                    {
                        addPropsFile = new JButton();
                        jPanel2.add(addPropsFile);
                        addPropsFile.setText("load properties from file");
                        addPropsFile.setPreferredSize(new java.awt.Dimension(234, 30));
                        addPropsFile.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                try {
                                    props.load(new InputStreamReader(new FileInputStream(file),
                                            (String) openUnknowFilecharSet.getSelectedItem()));
                                    reloadPropertiesTable();
                                } catch (Exception e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                    {
                        openFile = new JButton();
                        jPanel2.add(openFile);
                        openFile.setText("open unknow file");
                        openFile.setPreferredSize(new java.awt.Dimension(204, 30));
                        openFile.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                try {
                                    String encode = (String) openUnknowFilecharSet.getSelectedItem();
                                    BufferedReader reader = new BufferedReader(
                                            new InputStreamReader(new FileInputStream(file), encode));
                                    StringBuilder sb = new StringBuilder();
                                    for (String line = null; (line = reader.readLine()) != null;) {
                                        sb.append(line + "\n");
                                    }
                                    reader.close();
                                    textArea.setText(textArea.getText() + "\n" + sb);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                    {
                        ComboBoxModel openUnknowFilecharSetModel = new DefaultComboBoxModel(
                                new String[] { "BIG5", "UTF8" });
                        openUnknowFilecharSet = new JComboBox();
                        jPanel2.add(openUnknowFilecharSet);
                        openUnknowFilecharSet.setModel(openUnknowFilecharSetModel);
                        openUnknowFilecharSet.setPreferredSize(new java.awt.Dimension(73, 24));
                    }
                    {
                        appendTextAreaToProps = new JButton();
                        jPanel2.add(appendTextAreaToProps);
                        appendTextAreaToProps.setText("append textarea to properties");
                        appendTextAreaToProps.setPreferredSize(new java.awt.Dimension(227, 30));
                        appendTextAreaToProps.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                if (StringUtils.isBlank(textArea.getText())) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("textArea is empty", "ERROR");
                                    return;
                                }
                                try {
                                    BufferedReader reader = new BufferedReader(
                                            new StringReader(textArea.getText()));
                                    int pos = -1;
                                    String key = null;
                                    String value = null;
                                    for (String line = null; (line = reader.readLine()) != null;) {
                                        if ((pos = line.lastIndexOf("=")) != -1) {
                                            key = line.substring(0, pos);
                                            value = line.substring(pos + 1);
                                            props.put(key, value);
                                        }
                                    }
                                    reader.close();
                                    JOptionPaneUtil.newInstance().iconInformationMessage()
                                            .showMessageDialog("append success!", "SUCCESS");
                                    reloadPropertiesTable();
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("props edit", null, jPanel3, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel3.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(629, 361));
                    {
                        TableModel propsTableModel = new DefaultTableModel();
                        propsTable = new JTable();
                        jScrollPane1.setViewportView(propsTable);
                        propsTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                if (propsTable.getRowCount() == 0) {
                                    return;
                                }
                                int rowPos = JTableUtil.newInstance(propsTable).getSelectedRow();
                                Object key = propsTable.getValueAt(rowPos, 0);
                                Object value = propsTable.getValueAt(rowPos, 1);

                                JMenuItem insertRowItem = JTableUtil.newInstance(propsTable)
                                        .jMenuItem_addRow(false, null);
                                insertRowItem.setText("inert row...");

                                String rowInfo = "delete row : [" + key + "] = [" + value + "]";
                                JMenuItem delRowItem = JTableUtil.newInstance(propsTable)
                                        .jMenuItem_removeRow("are you sure remove row : \n" + rowInfo);
                                delRowItem.setText(rowInfo);

                                JPopupMenuUtil.newInstance(propsTable).applyEvent(evt)
                                        .addJMenuItem(insertRowItem, delRowItem).show();
                            }
                        });
                        propsTable.setModel(propsTableModel);
                        JTableUtil.defaultSetting(propsTable);
                    }
                }
                {
                    jPanel4 = new JPanel();
                    jPanel3.add(jPanel4, BorderLayout.SOUTH);
                    jPanel4.setPreferredSize(new java.awt.Dimension(629, 45));
                    {
                        clearProps = new JButton();
                        jPanel4.add(clearProps);
                        clearProps.setText("clear properties");
                        clearProps.setPreferredSize(new java.awt.Dimension(182, 36));
                        clearProps.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                props.clear();
                                reloadPropertiesTable();
                            }
                        });
                    }
                    {
                        savePropsToFile = new JButton();
                        jPanel4.add(savePropsToFile);
                        savePropsToFile.setText("save properties to file");
                        savePropsToFile.setPreferredSize(new java.awt.Dimension(182, 36));
                        savePropsToFile.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                try {
                                    props.clear();
                                    DefaultTableModel model = (DefaultTableModel) propsTable.getModel();
                                    Object key = null;
                                    Object value = null;
                                    for (int ii = 0; ii < model.getRowCount(); ii++) {
                                        key = model.getValueAt(ii, 0);
                                        value = model.getValueAt(ii, 1);
                                        props.put(key, value);
                                    }
                                    props.store(new FileOutputStream(file),
                                            SaveFileToPropertiesUI.class.getSimpleName());
                                    JOptionPaneUtil.newInstance().iconInformationMessage()
                                            .showMessageDialog("save completed!\n" + file, "SUCCESS");
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                }
            }
        }
        pack();
        this.setSize(798, 505);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.clough.android.adbv.view.MainFrame.java

public MainFrame(IOManager ioManager, HistoryManager historyManager) {
    this();/*from ww  w .  j a  va 2 s. c  om*/
    this.ioManager = ioManager;
    this.historyManager = historyManager;
    ioManager.addConnectionLostListener(new IOManager.ConnectionLostListener() {
        @Override
        public void onDisconnect() {
            showDeviceDisconnectedDialog();
        }
    });

    new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
            try {
                applicationID = MainFrame.this.ioManager.getApplicationID();
                deviceName = MainFrame.this.ioManager.getDeviceName();
                databaseName = MainFrame.this.ioManager.getDatabaseName();
                setTitle(ValueHolder.WINDOW_TITLE + " - (" + deviceName + " - " + applicationID + ")");
            } catch (IOManagerException ex) {
                showDeviceDisconnectedDialog();
            }
            return null;
        }

        @Override
        protected void done() {
            closeProgressDialog();
        }

    }.execute();
    showProgressDialog(true, 0, "Waiting for device/app info");

    refreshDatabase();

    tableInfoTree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) value;
            String nodeString = String.valueOf(dmtn.getUserObject());
            ImageIcon selectedImageIcon = null;
            if (nodeString.equals(databaseName)) {
                selectedImageIcon = ValueHolder.Icons.DATABASE;
            } else {
                l: for (int i = 0; i < tables.length; i++) {
                    String tableName = tables[i];
                    if (tableName.equals(nodeString)) {
                        selectedImageIcon = ValueHolder.Icons.TABLE;
                        break;
                    } else if (i == tables.length - 1) {
                        for (int p = 0; p < tables.length; p++) {
                            for (int j = 0; j < columns[p].length; j++) {
                                String columnName = columns[p][j];
                                if (columnName.equals(nodeString)) {
                                    selectedImageIcon = ValueHolder.Icons.PENCIL;
                                    break l;
                                } else if (j == columns[p].length - 1) {
                                    for (int q = 0; q < tables.length; q++) {
                                        for (int r = 0; r < columns[q].length; r++) {
                                            for (int k = 0; k < columnInfos[q][r].length; k++) {
                                                String columnInfo = columnInfos[q][r][k];
                                                if (columnInfo.equals(nodeString)) {
                                                    switch (k) {
                                                    case 0: {
                                                        selectedImageIcon = ValueHolder.Icons.HASH_TAG;
                                                        break l;
                                                    }
                                                    case 1: {
                                                        selectedImageIcon = ValueHolder.Icons.BLUE;
                                                        break l;
                                                    }
                                                    case 2: {
                                                        selectedImageIcon = ValueHolder.Icons.ORANGE;
                                                        break l;
                                                    }
                                                    case 3: {
                                                        selectedImageIcon = ValueHolder.Icons.GREEN;
                                                        break l;
                                                    }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            setIcon(selectedImageIcon);
            return this;
        }

    });

    tableInfoTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            Object[] data = evt.getPath().getPath();
            selectedTreeNodeValue = String.valueOf(data[data.length - 1]);
        }
    });

    tableInfoTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (evt.getButton() == MouseEvent.BUTTON3) {
                if (selectedTreeNodeValue.equals(databaseName)) {
                    showTreeNodePopup(evt.getX(), evt.getY(), true);
                } else {
                    for (String table : tables) {
                        if (table.equals(selectedTreeNodeValue)) {
                            showTreeNodePopup(evt.getX(), evt.getY(), false);
                            break;
                        }
                    }
                }
            } else if (evt.getClickCount() >= 2) {
                queryingTextArea.setText(queryingTextArea.getText() + "`" + selectedTreeNodeValue + "`");
            }
        }

    });

    currentHistoryList = historyManager.getHistoryList();
    for (int i = 0; i < currentHistoryList.size(); i++) {
        String[] history = currentHistoryList.get(i);
        historyContainingPanel.add(
                new HistoryItemPanel(i + 1, history[0].equals(applicationID), history[1], queryingTextArea));
    }
    adjustHistoryScrollbar();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                MainFrame.this.historyManager.saveApplicationDb();
            } catch (HistoryManagerException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "Application history saving",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }));

}

From source file:biz.wolschon.finance.jgnucash.accountProperties.AccountProperties.java

/**
 * @return a panel to edit the settings of this section
 *//*from   w  w w.j  a  va 2 s  .  c  o m*/
private JPanel getMySettingsPanel() {
    if (mySettingsPanel == null) {
        mySettingsPanel = new JPanel();

        mySettingsPanel.setLayout(new BorderLayout());
        myPropertySheet = new PropertySheetPanel();
        myPropertySheet.setToolBarVisible(true);
        myPropertySheet.setSorting(false);
        myPropertySheet.setMode(PropertySheetPanel.VIEW_AS_CATEGORIES);
        myPropertySheet.setDescriptionVisible(true);

        myPropertySheet.addPropertySheetChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent aEvt) {
                Object property = aEvt.getSource();
                if (property instanceof DefaultProperty) {
                    DefaultProperty prop = (DefaultProperty) property;
                    try {
                        myAccount.setUserDefinedAttribute(prop.getName(), prop.getValue().toString());
                    } catch (Exception e) {
                        LOGGER.error("error in writing userDefinedAttribute", e);
                    }
                }
            }

        });
        myPropertySheet.getTable().addMouseListener(new MouseAdapter() {

            /** show popup if mouseReleased is a popupTrigger on this platform.
             * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
             */
            @Override
            public void mouseReleased(final MouseEvent aE) {
                if (aE.isPopupTrigger()) {
                    JPopupMenu menu = getPropertyPopup();
                    menu.show(myPropertySheet, aE.getX(), aE.getY());
                }
                super.mouseClicked(aE);
            }

            /** show popup if mousePressed is a popupTrigger on this platform.
             * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
             */
            @Override
            public void mousePressed(final MouseEvent aE) {
                if (aE.isPopupTrigger()) {
                    JPopupMenu menu = getPropertyPopup();
                    menu.show(myPropertySheet, aE.getX(), aE.getY());
                }
                super.mouseClicked(aE);
            }

        });
        //
        updateCustomAttributesPanel();
        //        for (ConfigurationSetting setting : getConfigSection().getSettings()) {
        //            MyProperty myProperty = new MyProperty(setting);
        //            myProperty.addPropertyChangeListener(savingPropertyChangeListener);
        //            propertySheet.addProperty(myProperty);
        //        }
        mySettingsPanel.add(new JLabel("custom attributes:"), BorderLayout.NORTH);
        mySettingsPanel.add(myPropertySheet, BorderLayout.CENTER);
        mySettingsPanel.add(getAddCustomAttrPanel(), BorderLayout.SOUTH);

        //        MyPropertyEditorFactory propertyEditorFactory = new MyPropertyEditorFactory();
        //        propertySheet.setEditorFactory(propertyEditorFactory);
        //        propertySheet.setRendererFactory(propertyEditorFactory);

    }
    return mySettingsPanel;
}

From source file:com.diversityarrays.kdxplore.trials.TrialDetailsPanel.java

TrialDetailsPanel(WindowOpener<JFrame> windowOpener, MessagePrinter mp, BackgroundRunner backgroundRunner,
        OfflineData offlineData, Action editTrialAction, Action seedPrepAction, Action harvestAction,
        Action uploadTrialAction, Action refreshTrialInfoAction, ImageIcon barcodeIcon,
        Transformer<Trial, Boolean> checkIfEditorActive, Consumer<Trial> onTraitInstancesRemoved) {
    super(new BorderLayout());

    this.editTrialAction = editTrialAction;
    this.uploadTrialAction = uploadTrialAction;
    this.refreshTrialInfoAction = refreshTrialInfoAction;
    this.onTraitInstancesRemoved = onTraitInstancesRemoved;

    this.messagePrinter = mp;
    this.backgroundRunner = backgroundRunner;
    this.offlineData = offlineData;

    if (barcodeIcon == null) {
        barcodesMenuButton = new JLabel("Barcodes"); //$NON-NLS-1$
    } else {/*from   w  w w.j ava  2  s.  com*/
        barcodesMenuButton = new JLabel(barcodeIcon);
    }
    barcodesMenuButton.setBorder(BorderFactory.createRaisedSoftBevelBorder());

    barcodesMenuButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (trial != null) {
                barcodesMenuHandler.handleMouseClick(e.getPoint());
            }
        }
    });

    trialViewPanel = new TrialViewPanel(windowOpener, offlineData, checkIfEditorActive, onTraitInstancesRemoved,
            mp);

    Box buttons = Box.createHorizontalBox();
    buttons.add(new JButton(refreshTrialInfoAction));
    buttons.add(new JButton(seedPrepAction));
    buttons.add(new JButton(editTrialAction));
    buttons.add(new JButton(uploadTrialAction));
    buttons.add(new JButton(harvestAction));
    buttons.add(barcodesMenuButton);
    buttons.add(Box.createHorizontalGlue());

    //      JPanel trialPanel = new JPanel(new BorderLayout());
    //      trialPanel.add(buttons, BorderLayout.NORTH);
    //      trialPanel.add(fieldViewPanel, BorderLayout.CENTER);

    cardPanel.add(new JLabel(Msg.LABEL_NO_TRIAL_SELECTED()), CARD_NO_TRIAL);
    cardPanel.add(trialViewPanel, CARD_HAVE_TRIAL);

    setSelectedTrial(null);

    add(buttons, BorderLayout.NORTH);
    add(cardPanel, BorderLayout.CENTER);
}

From source file:edu.ku.brc.ui.ChooseFromListDlg.java

/**
 * Create the UI for the dialog.// ww w  .  j a  v a  2  s  .  c o  m
 * 
 * @param altName title for dialog
 * @param desc the list to be selected from
 * @param includeCancelBtn  indicates whether to create and display a cancel btn
 * @param includeHelpBtn indicates whether to create and display a help btn
 * @param helpContext help context identifier
 * @param titleArg title for dialog
 * @param desc the list to be selected from
 * @param includeCancelBtn indicates whether to create and display a cancel btn
 */
public void createUI() {
    setTitle(title);

    boolean hasDesc = StringUtils.isNotEmpty(desc);
    PanelBuilder builder = new PanelBuilder(
            new FormLayout("f:max(300px;p):g", "p," + (hasDesc ? "2px,p," : "") + "5px,p"));
    CellConstraints cc = new CellConstraints();
    //builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 10));
    builder.setDefaultDialogBorder();

    int y = 1;
    if (hasDesc) {
        JLabel lbl = createLabel(desc, SwingConstants.CENTER);
        builder.add(lbl, cc.xy(1, y));
        y += 2;
    }

    try {
        ListModel listModel = new AbstractListModel() {
            public int getSize() {
                return items.size();
            }

            public Object getElementAt(int index) {
                return items.get(index).toString();
            }
        };

        list = new JList(listModel);
        if (icon != null) {
            list.setCellRenderer(getListCellRenderer()); // icon comes from the base
            // class (it's probably size
            // 16)
        }
        list.setSelectionMode(isMultiSelect ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
                : ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(10);

        if (selectedIndices != null) {
            list.setSelectedIndices(selectedIndices);
        }

        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    okBtn.doClick(); // emulate button click
                }
            }
        });
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    updateUIState();
                }
            }
        });
        JScrollPane listScroller = new JScrollPane(list);
        builder.add(listScroller, cc.xy(1, y));
        y += 2;

        // Bottom Button UI
        okBtn = createButton(StringUtils.isNotEmpty(okLabel) ? okLabel : getResourceString("OK"));
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                isCancelled = false;
                btnPressed = OK_BTN;
                setVisible(false);
            }
        });
        getRootPane().setDefaultButton(okBtn);

        if ((whichBtns & CANCEL_BTN) == CANCEL_BTN) {
            cancelBtn = createButton(
                    StringUtils.isNotEmpty(cancelLabel) ? cancelLabel : getResourceString("CANCEL"));
            cancelBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    isCancelled = true;
                    btnPressed = CANCEL_BTN;
                    setVisible(false);
                }
            });
        }

        if ((whichBtns & HELP_BTN) == HELP_BTN) {
            helpBtn = createButton(
                    StringUtils.isNotEmpty(cancelLabel) ? cancelLabel : getResourceString("HELP"));
            if (StringUtils.isNotEmpty(helpContext)) {
                HelpMgr.registerComponent(helpBtn, helpContext);
            } else {
                helpBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        btnPressed = HELP_BTN;
                    }
                });
            }
        }

        if ((whichBtns & APPLY_BTN) == APPLY_BTN) {
            applyBtn = createButton(
                    StringUtils.isNotEmpty(applyLabel) ? applyLabel : getResourceString("Apply"));
            applyBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    btnPressed = APPLY_BTN;
                    if (isCloseOnApply) {
                        isCancelled = false;
                        setVisible(false);
                    }
                }
            });
        }

        JPanel bb;
        if (whichBtns == OK_BTN) {
            bb = ButtonBarFactory.buildOKBar(okBtn);

        } else if (whichBtns == OKCANCEL) {
            bb = ButtonBarFactory.buildOKCancelBar(okBtn, cancelBtn);

        } else if (whichBtns == OKCANCELAPPLY) {
            bb = ButtonBarFactory.buildOKCancelApplyBar(okBtn, cancelBtn, applyBtn);

        } else if (whichBtns == OKHELP) {
            bb = ButtonBarFactory.buildOKHelpBar(okBtn, helpBtn);

        } else if (whichBtns == OKCANCELHELP) {
            bb = ButtonBarFactory.buildOKCancelHelpBar(okBtn, cancelBtn, helpBtn);

        } else if (whichBtns == OKCANCELAPPLYHELP) {
            bb = ButtonBarFactory.buildOKCancelApplyHelpBar(okBtn, cancelBtn, applyBtn, helpBtn);

        } else {
            bb = ButtonBarFactory.buildOKBar(okBtn);
        }

        builder.add(bb, cc.xy(1, y));
        y += 2;

        updateUIState();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ChooseFromListDlg.class, ex);
        log.error(ex);
    }

    setContentPane(builder.getPanel());
    pack();
    // setLocationRelativeTo(locationComp);
}

From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java

/**
 * @return panel containing search ui//  ww  w.j ava  2s .  c  om
 */
private JPanel createSearchPanel() {
    ActionListener doQuery = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //doQuery();
        }
    };

    searchBoxComp = new SearchBoxComponent(new SearchBoxMenuCreator(), doQuery, false,
            PickListDBAdapterFactory.getInstance().create("ExpressSearch", true));
    searchBoxComp.createUI();
    searchBox = searchBoxComp.getSearchBox();
    searchText = searchBoxComp.getSearchText();
    searchBtn = searchBoxComp.getSearchBtn();
    textBGColor = searchBoxComp.getTextBGColor();
    badSearchColor = searchBoxComp.getBadSearchColor();

    searchBtn.setToolTipText(getResourceString("ExpressSearchTT"));
    HelpMgr.setHelpID(searchBtn, "Express_Search");
    HelpMgr.registerComponent(searchText, "Express_Search");

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    searchText.setText(localPrefs.get(getLastSearchKey(), ""));
    textBGColor = searchText.getBackground();

    searchText.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            showContextMenu(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showContextMenu(e);
        }
    });
    return searchBoxComp;
}