Example usage for java.awt.event MouseEvent BUTTON1

List of usage examples for java.awt.event MouseEvent BUTTON1

Introduction

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

Prototype

int BUTTON1

To view the source code for java.awt.event MouseEvent BUTTON1.

Click Source Link

Document

Indicates mouse button #1; used by #getButton .

Usage

From source file:lu.fisch.unimozer.Diagram.java

@Override
public void mouseReleased(MouseEvent e) {
    if (isEnabled() && e.getButton() == MouseEvent.BUTTON1) {
        if (mode == MODE_EXTENDS) {
            extendsTo = getMouseClass(e.getPoint());
            if ((extendsFrom != null) && (extendsTo != null) && (extendsFrom != extendsTo)) {
                // %TODO%
                extendsFrom.addExtends(extendsTo.getShortName());
                repaint();/* w  w w  .jav  a2  s  . c  o  m*/
            }
            // change the mode back to SELECT
            setMode(MODE_SELECT);
            // update the bouttons in the mainform
            frame.updateMode();

            // free pointers
            extendsDragPoint = null;
            extendsFrom = null;
            extendsTo = null;
            deselectAll();
        } else {
            // load the clickled class (if clicked!)
            if (mousePressed == true)
                loadClickedClass(e);
            mousePressed = false;
        }
    }
}

From source file:v800_trainer.JCicloTronic.java

private void DatentabelleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DatentabelleMouseClicked
    // Add your handling code here:
    if (evt.getButton() == MouseEvent.BUTTON3 && evt.getButton() != MouseEvent.BUTTON1) {

        int dummy = Datentabelle.rowAtPoint(evt.getPoint());
        int selection[] = Datentabelle.getSelectedRows();

        boolean isselected = false;
        for (int i = 0; i < selection.length; i++) {
            if (dummy == selection[i]) {
                isselected = true;//from w ww . j a va 2  s .c o  m
            }
        }
        ;
        Datentabelle.clearSelection();
        if (!isselected) {
            Datentabelle.addRowSelectionInterval(dummy, dummy);
        }

        for (int i = 0; i < selection.length; i++) {
            if (dummy != selection[i]) {
                Datentabelle.addRowSelectionInterval(selection[i], selection[i]);
            }

        }

    }
    SelectionChanged = true;
    Update = false;
    Datenliste_Monat.setEnabled(false);
    Datenliste_Monat.setSelectedIndex(0);
    Datenliste_Jahr.setSelectedIndex(0);
    Datenliste_Zeitabschnitt.setSelectedIndex(0);
    Datenliste_TourTyp.setSelectedIndex(0);

    Update = true;
    jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount());
    if (evt.getClickCount() == 2) {
        Hauptfenster.setSelectedIndex(1);
    }
}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIProd(Machine[] machs) { //TODO don't need machs actually... (part of results)

    if (results != null && RoiData.value >= 0) {

        if (listCompareRoi.getSelectedIndices().length > 1) {
            DefaultCategoryDataset roidata = new DefaultCategoryDataset();
            String series1 = "Value Added";
            double offset = 0.;
            for (int i = 0; i < results.getSize(); ++i) {
                String name = results.get(i).getModel() + ": " + results.get(i).getName();
                if (i == 0) {
                    // offset all relative to first value
                    offset = results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value
                            / 1000;//from  ww w .ja va 2 s  .c  om
                    roidata.addValue(0, series1, name);
                    RoiResults.get(i).value = 0;
                } else {
                    roidata.addValue(
                            results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR) * RoiData.value / 1000
                                    - offset,
                            series1, name);
                    RoiResults.get(i).value = results.get(i).getResult(ResultType.WEIGHT, ResultTime.YEAR)
                            * RoiData.value / 1000 - offset;
                }
            }

            // draw graph
            JFreeChart chart = ChartFactory.createBarChart("", "", "Relative Value Added (/year)", roidata,
                    PlotOrientation.VERTICAL, false, true, false);
            CategoryPlot cp = chart.getCategoryPlot();
            cp.setBackgroundPaint(new Color(240, 240, 240));
            cp.setRangeGridlinePaint(Color.gray);
            CategoryItemRenderer renderer = new CustomRenderer(
                    new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                            new Color(251, 251, 0), new Color(86, 228, 200) });
            cp.setRenderer(renderer);
            BarRenderer b = (BarRenderer) cp.getRenderer();
            b.setBarPainter(new StandardBarPainter());
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));
            ValueAxis va = cp.getRangeAxis();
            va.setLabelFont(new Font("Tahoma", Font.BOLD, 13));

            ResetStatusLabel();
            RoiResults.setProdGraph(chart);
            // Display results graph
            try {
                pnlGraphProd.remove(lblNoGraph);
            } catch (Exception e) {
            }
            try {
                pnlGraphProd.remove(pnlGraphProdInner);
            } catch (Exception e) {
            }
            pnlGraphProdInner = new ChartPanel(RoiResults.getProdGraph());
            pnlGraphProdInner.setBounds(2, 2, 435, 226);
            pnlGraphProdInner.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseReleased(MouseEvent e) {
                    if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphProdInner.contains(e.getPoint())
                            && RoiResults != null && RoiResults.getProdGraph() != null) {
                        JFreeChart chart = RoiResults.getProdGraph();
                        JFrame pop = new JFrame();
                        pop.getContentPane().add(new ChartPanel(chart));
                        try {
                            pop.setIconImage(
                                    ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                        } catch (Exception e11) {

                        }
                        pop.setTitle("ROI Graph");
                        pop.pack();
                        pop.setLocationRelativeTo(frmTitanRoiCalculator);
                        pop.setVisible(true);
                    }
                }
            });
            pnlGraphProd.add(pnlGraphProdInner);
            pnlGraphProdInner.repaint();

            // marginal improvement label
            int ind1 = cmbMarg1.getSelectedIndex();
            int ind2 = cmbMarg2.getSelectedIndex();
            double diff = roidata.getValue(0, ind2).doubleValue() - roidata.getValue(0, ind1).doubleValue();
            lblMarginalImprovement.setText("" + formatDecimal(diff) + " per annum");
        } else {
            ResetStatusLabel();
            ShowMessageStandard("Select at least 2 machines to view marginal benefits.");
            lblMarginalImprovement.setText("0.00 per annum");
            // Display results graph
            try {
                pnlGraphProd.remove(pnlGraphProdInner);
            } catch (Exception e) {
            }
            pnlGraphProd.add(lblNoGraph);
            lblNoGraph.repaint();
        }

    } else {
        ShowMessageStandard("Enter relevant data above to view graph.");
        lblMarginalImprovement.setText("0.00 per annum");
        // Display results graph
        try {
            pnlGraphProd.remove(pnlGraphProdInner);
        } catch (Exception e2) {
        }
        pnlGraphProd.add(lblNoGraph);
        lblNoGraph.repaint();
    }

}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIEnergy(Machine[] mach) {
    if (RoiData != null && results != null && RoiData.energies.size() >= results.getSize()) { //  TODO first case redundant?
        double powercost = 0.;
        try {/*from   w w  w. ja  v a 2 s .co m*/
            powercost = Double.parseDouble(txtenergycost.getText());
        } catch (Exception e) {
            powercost = 0.;
        }

        RoiData.energycost = powercost;

        DefaultCategoryDataset energydata = new DefaultCategoryDataset();
        String series1 = "Energy Costs";
        for (int i = 0; i < results.getSize(); ++i) {
            String name = results.get(i).getModel() + ": " + results.get(i).getName();
            energydata.addValue(
                    RoiData.energies.get(listCompareRoi.getSelectedIndices()[i]).kwhrsperyear * powercost,
                    series1, name);
            RoiResults.get(
                    i).energycost = RoiData.energies.get(listCompareRoi.getSelectedIndices()[i]).kwhrsperyear
                            * powercost;
        }

        // draw graph
        JFreeChart chart = ChartFactory.createBarChart("", "", "Energy Cost ( / year)", energydata,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot cp = chart.getCategoryPlot();
        cp.setBackgroundPaint(new Color(240, 240, 240));
        cp.setRangeGridlinePaint(Color.gray);
        CategoryItemRenderer renderer = new CustomRenderer(
                new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                        new Color(251, 251, 0), new Color(86, 228, 200) });
        cp.setRenderer(renderer);
        BarRenderer b = (BarRenderer) cp.getRenderer();
        b.setBarPainter(new StandardBarPainter());
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));

        RoiResults.setEnergyGraph(chart);

        // Display results graph
        try {
            pnlGraphEnergy.remove(lblNoGraph2);
        } catch (Exception e) {
        }
        try {
            pnlGraphEnergy.remove(pnlGraphEnergyInner);
        } catch (Exception e) {
        }
        pnlGraphEnergyInner = new ChartPanel(RoiResults.getEnergyGraph());
        pnlGraphEnergyInner.setBounds(2, 2, 435, 222);
        pnlGraphEnergyInner.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphEnergyInner.contains(e.getPoint())
                        && RoiResults != null && RoiResults.getEnergyGraph() != null) {
                    JFreeChart chart = RoiResults.getEnergyGraph();
                    JFrame pop = new JFrame();
                    pop.getContentPane().add(new ChartPanel(chart));
                    try {
                        pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                    } catch (Exception e11) {
                    }
                    pop.setTitle("ROI Graph");
                    pop.pack();
                    pop.setLocationRelativeTo(frmTitanRoiCalculator);
                    pop.setVisible(true);
                }
            }
        });
        pnlGraphEnergy.add(pnlGraphEnergyInner);
        pnlGraphEnergyInner.repaint();

        // marginal improvement label
        int ind1 = cmbMargEnergy1.getSelectedIndex();
        int ind2 = cmbMargEnergy2.getSelectedIndex();
        double diff = energydata.getValue(0, ind1).doubleValue() - energydata.getValue(0, ind2).doubleValue();
        lblMarginalEnergy.setText("" + formatDecimal(diff) + " per annum");

    }

}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIMaint(Machine[] mach) {
    //ResetStatusLabel();

    if (results != null && RoiData.maintenance.size() >= results.getSize()) {
        DefaultCategoryDataset maintdata = new DefaultCategoryDataset();
        String series1 = "Basic Costs";
        String series2 = "Production Loss";
        for (int i = 0; i < results.getSize(); ++i) {
            String name = results.get(i).getModel() + ": " + results.get(i).getName();
            maintdata.addValue(RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).totcost, series1,
                    name);//from  ww  w  . j  a v  a2 s .  co  m
            maintdata.addValue(
                    RoiData.value * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours
                            * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000,
                    series2, name);
            RoiResults.get(i).prodloss = RoiData.value
                    * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours
                    * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000;
            RoiResults.get(i).partcosts = RoiData.maintenance
                    .get(listCompareRoi.getSelectedIndices()[i]).totcost;
            RoiResults
                    .get(i).maintcost = RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).totcost
                            + RoiData.value
                                    * RoiData.maintenance.get(listCompareRoi.getSelectedIndices()[i]).tothours
                                    * results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR) / 1000;
        }

        // draw graph
        //JFreeChart chart = ChartFactory.createBarChart("", "", "Maintenance Cost ( / year)", maintdata, PlotOrientation.VERTICAL, false, true, false);
        JFreeChart chart = ChartFactory.createStackedBarChart("", "", "Maintenance Cost ( / year)", maintdata,
                PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot cp = chart.getCategoryPlot();
        cp.setBackgroundPaint(new Color(240, 240, 240));
        cp.setRangeGridlinePaint(Color.gray);
        CategoryItemRenderer renderer = new CustomRenderer(
                new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                        new Color(251, 251, 0), new Color(86, 228, 200) });
        //cp.setRenderer(renderer);
        cp.setShadowGenerator(new DefaultShadowGenerator(7, Color.DARK_GRAY, 1f, 5, -Math.PI / 4));
        BarRenderer b = (BarRenderer) cp.getRenderer();
        b.setBarPainter(new StandardBarPainter());
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator("{1}, {2}", NumberFormat.getInstance()));
        ValueAxis va = cp.getRangeAxis();
        va.setLabelFont(new Font("Tahoma", Font.BOLD, 13));

        RoiResults.setMaintGraph(chart);

        // Display results graph
        try {
            pnlGraphMaint.remove(lblNoGraph3);
        } catch (Exception e) {
        }
        try {
            pnlGraphMaint.remove(pnlGraphMaintInner);
        } catch (Exception e) {
        }
        pnlGraphMaintInner = new ChartPanel(RoiResults.getMaintGraph());
        pnlGraphMaintInner.setBounds(2, 2, 435, 238);
        pnlGraphMaintInner.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphMaintInner.contains(e.getPoint())
                        && RoiResults != null && RoiResults.getMaintGraph() != null) {
                    JFreeChart chart = RoiResults.getMaintGraph();
                    JFrame pop = new JFrame();
                    pop.getContentPane().add(new ChartPanel(chart));
                    try {
                        pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                    } catch (Exception e11) {

                    }
                    pop.setTitle("ROI Graph");
                    pop.pack();
                    pop.setLocationRelativeTo(frmTitanRoiCalculator);
                    pop.setVisible(true);
                }
            }
        });
        pnlGraphMaint.add(pnlGraphMaintInner);
        pnlGraphMaintInner.repaint();

        // Update production loss stat
        try {
            int sel = cmbMachinesmaintenance.getSelectedIndex();
            if (arrayContains(listCompareRoi.getSelectedIndices(), sel))
                lblProdLoss
                        .setText(""
                                + formatDecimal(RoiData.value * RoiData.maintenance.get(sel).tothours
                                        * results.get(arrayIndex(listCompareRoi.getSelectedIndices(), sel))
                                                .getResult(ResultType.WEIGHT, ResultTime.HOUR)
                                        / 1000)
                                + " / year");
            else
                lblProdLoss.setText("Machine not selected");
        } catch (Exception e) {
            lblProdLoss.setText("0.00 / year");
        }

        // marginal improvement label
        int ind1 = cmbMargMaint1.getSelectedIndex();
        int ind2 = cmbMargMaint2.getSelectedIndex();
        double diff = maintdata.getValue(0, ind1).doubleValue() + maintdata.getValue(1, ind1).doubleValue()
                - maintdata.getValue(0, ind2).doubleValue() - maintdata.getValue(1, ind2).doubleValue();
        lblMarginalMaint.setText("" + formatDecimal(diff) + " per annum");
    }
}

From source file:atlas.kingj.roi.FrmMain.java

private void UpdateROIWaste(Machine[] mach) {

    if (results != null) {
        //ResetStatusLabel();
        double wasteflags = 0.;
        double wasteguide = 0.;
        double wastetable = 0.;
        try {/*from   www  .  j  a  va 2  s.c  o m*/
            wasteflags = Math.max(0, Double.parseDouble(txtwastesavedflags.getText()));
            if (!metric)
                wasteflags = Core.FtToM(wasteflags);
        } catch (NumberFormatException e) {
            wasteflags = 0.;
        }
        try {
            wasteguide = Math.max(0, Double.parseDouble(txtwastesavedguide.getText()));
            if (!metric)
                wasteguide = Core.FtToM(wasteguide);
        } catch (NumberFormatException e) {
            wasteguide = 0.;
        }

        RoiData.wastesavedflag = wasteflags;
        RoiData.wastesavedguide = wasteguide;
        RoiData.wastesavedtable = wastetable;

        DefaultCategoryDataset wastedata = new DefaultCategoryDataset();
        String series1 = "Waste Saved";
        for (int i = 0; i < results.getSize(); ++i) {
            double totsave = 0.;
            double SchedulesPerYear = results.get(i).ScheduleTime == 0 ? 0
                    : environment.HrsPerYear / results.get(i).ScheduleTime;
            String name = results.get(i).getModel() + ": " + results.get(i).getName();
            if (mach[i].flags)
                totsave += wasteflags * results.get(i).SplicesPerSchedule * SchedulesPerYear;
            if (mach[i].alignment)
                totsave += wasteguide * results.get(i).MothersPerSchedule * SchedulesPerYear;
            if (mach[i].splice_table)
                totsave += wastetable * results.get(i).SplicesPerSchedule * SchedulesPerYear;
            wastedata.addValue(totsave, series1, name);
            RoiResults.get(i).wastesave = totsave;
            double conversion = results.get(i).getResult(ResultType.LENGTH, ResultTime.HOUR) == 0 ? 0
                    : results.get(i).getResult(ResultType.WEIGHT, ResultTime.HOUR)
                            / results.get(i).getResult(ResultType.LENGTH, ResultTime.HOUR) / 1000;
            RoiResults.get(i).wasteval = totsave * conversion * RoiData.sellingprice;
        }

        // draw graph
        JFreeChart chart = ChartFactory.createBarChart("", "", "Waste Reduced (m / year)", wastedata,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot cp = chart.getCategoryPlot();
        cp.setBackgroundPaint(new Color(240, 240, 240));
        cp.setRangeGridlinePaint(Color.gray);
        CategoryItemRenderer renderer = new CustomRenderer(
                new Paint[] { new Color(255, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85),
                        new Color(251, 251, 0), new Color(86, 228, 200) });
        cp.setRenderer(renderer);
        BarRenderer b = (BarRenderer) cp.getRenderer();
        b.setBarPainter(new StandardBarPainter());
        renderer.setBaseToolTipGenerator(
                new StandardCategoryToolTipGenerator("{1}, {2}m", NumberFormat.getInstance()));

        RoiResults.setWasteGraph(chart);

        // Display results graph
        try {
            pnlGraphWaste.remove(lblNoGraph4);
        } catch (Exception e) {
        }
        try {
            pnlGraphWaste.remove(pnlGraphWasteInner);
        } catch (Exception e) {
        }
        pnlGraphWasteInner = new ChartPanel(RoiResults.getWasteGraph());
        pnlGraphWasteInner.setBounds(2, 2, 435, 258);
        pnlGraphWasteInner.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1 && pnlGraphWasteInner.contains(e.getPoint())
                        && RoiResults != null && RoiResults.getWasteGraph() != null) {
                    JFreeChart chart = RoiResults.getWasteGraph();
                    JFrame pop = new JFrame();
                    pop.getContentPane().add(new ChartPanel(chart));
                    try {
                        pop.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
                    } catch (Exception e11) {

                    }
                    pop.setTitle("ROI Graph");
                    pop.pack();
                    pop.setLocationRelativeTo(frmTitanRoiCalculator);
                    pop.setVisible(true);
                }
            }
        });
        pnlGraphWaste.add(pnlGraphWasteInner);
        pnlGraphWasteInner.repaint();

        // marginal improvement label
        int ind1 = cmbMargWaste1.getSelectedIndex();
        int ind2 = cmbMargWaste2.getSelectedIndex();
        double diff = wastedata.getValue(0, ind2).doubleValue() - wastedata.getValue(0, ind1).doubleValue();
        lblMarginalWaste.setText(
                formatDecimal((metric ? diff : Core.MToFt(diff))) + (metric ? "m per annum" : "ft per annum"));
        if (RoiData.value <= 0)
            lblMarginalWasteValue.setText("(0.00 per annum)");
        else {
            double conversion1 = results.get(ind1).getResult(ResultType.LENGTH, ResultTime.HOUR) == 0 ? 0
                    : results.get(ind1).getResult(ResultType.WEIGHT, ResultTime.HOUR)
                            / results.get(ind1).getResult(ResultType.LENGTH, ResultTime.HOUR);
            double conversion2 = results.get(ind2).getResult(ResultType.LENGTH, ResultTime.HOUR) == 0 ? 0
                    : results.get(ind2).getResult(ResultType.WEIGHT, ResultTime.HOUR)
                            / results.get(ind2).getResult(ResultType.LENGTH, ResultTime.HOUR);
            double weight1 = conversion1 * wastedata.getValue(0, ind1).doubleValue();
            double weight2 = conversion2 * wastedata.getValue(0, ind2).doubleValue();
            double diff_weight = weight2 - weight1;
            // convert to tonnes
            diff_weight = diff_weight / 1000;
            lblMarginalWasteValue
                    .setText("(" + formatDecimal(diff_weight * RoiData.sellingprice) + " per annum)");
        }

    }

}