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:com.puzzle.gui.MainFrame.java

private void jTable3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable3MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        int rowNumber = this.jTable3.getSelectedRow();
        String fileName = (String) this.jTable3.getValueAt(rowNumber, 1);

        String content = null;/*  w ww.  ja v  a2  s . com*/
        try {
            content = org.apache.commons.io.FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        //              String ll=this.readXML(workpath,ff);
        this.jDialog1.setTitle(fileName);
        //??

        textArea.setText(content);
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        textArea.setCodeFoldingEnabled(true);
        textArea.setAutoscrolls(true);
        //            textArea.setBackground(Color.black);
        textArea.setEditable(false);
        //             textArea.setVisible(true);
        this.jPanel6.add(sp);

        this.jDialog1.setLocationRelativeTo(this);
        this.jDialog1.setVisible(true);
    } //GEN-LAST:event_jTable3MouseClicked
}

From source file:userinterface.properties.GUIGraphHandler.java

public void plotNewFunction() {

    JDialog dialog;/*w  w  w  .ja v a 2 s  .  com*/
    JRadioButton radio2d, radio3d, newGraph, existingGraph;
    JTextField functionField, seriesName;
    JButton ok, cancel;
    JComboBox<String> chartOptions;
    JLabel example;

    //init all the fields of the dialog
    dialog = new JDialog(GUIPrism.getGUI());
    radio2d = new JRadioButton("2D");
    radio3d = new JRadioButton("3D");
    newGraph = new JRadioButton("New Graph");
    existingGraph = new JRadioButton("Exisiting");
    chartOptions = new JComboBox<String>();
    functionField = new JTextField();
    ok = new JButton("Plot");
    cancel = new JButton("Cancel");
    seriesName = new JTextField();
    example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
    example.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.HAND_CURSOR));
            example.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            example.setForeground(Color.BLACK);
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {

                if (radio2d.isSelected()) {
                    functionField.setText("x/2 + 5");
                } else {
                    functionField.setText("x+y+5");
                }

                functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
                functionField.setForeground(Color.BLACK);

            }
        }

    });

    //set dialog properties
    dialog.setSize(400, 350);
    dialog.setTitle("Plot a new function");
    dialog.setModal(true);
    dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    dialog.setLocationRelativeTo(GUIPrism.getGUI());

    //add every component to their dedicated panels
    JPanel graphTypePanel = new JPanel(new FlowLayout());
    graphTypePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type"));
    graphTypePanel.add(radio2d);
    graphTypePanel.add(radio3d);

    JPanel functionFieldPanel = new JPanel(new BorderLayout());
    functionFieldPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function"));
    functionFieldPanel.add(functionField, BorderLayout.CENTER);
    functionFieldPanel.add(example, BorderLayout.SOUTH);

    JPanel chartSelectPanel = new JPanel();
    chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS));
    chartSelectPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to"));
    JPanel radioPlotPanel = new JPanel(new FlowLayout());
    radioPlotPanel.add(newGraph);
    radioPlotPanel.add(existingGraph);
    JPanel chartOptionsPanel = new JPanel(new FlowLayout());
    chartOptionsPanel.add(chartOptions);
    chartSelectPanel.add(radioPlotPanel);
    chartSelectPanel.add(chartOptionsPanel);

    JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bottomControlPanel.add(ok);
    bottomControlPanel.add(cancel);

    JPanel seriesNamePanel = new JPanel(new BorderLayout());
    seriesNamePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name"));
    seriesNamePanel.add(seriesName, BorderLayout.CENTER);

    // add all the panels to the dialog

    dialog.add(graphTypePanel);
    dialog.add(functionFieldPanel);
    dialog.add(chartSelectPanel);
    dialog.add(seriesNamePanel);
    dialog.add(bottomControlPanel);

    // do all the enables and set properties

    radio2d.setSelected(true);
    newGraph.setSelected(true);
    chartOptions.setEnabled(false);
    functionField.setText("Add function expression here....");
    functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
    functionField.setForeground(Color.GRAY);
    seriesName.setText("New function");
    ok.setMnemonic('P');
    cancel.setMnemonic('C');
    example.setToolTipText("click to try out");

    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
    ok.getActionMap().put("ok", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok.doClick();
        }
    });

    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    cancel.getActionMap().put("cancel", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel.doClick();
        }
    });

    boolean found = false;

    for (int i = 0; i < theTabs.getTabCount(); i++) {

        if (theTabs.getComponentAt(i) instanceof Graph) {
            chartOptions.addItem(getGraphName(i));
            found = true;
        }
    }

    if (!found) {

        existingGraph.setEnabled(false);
        chartOptions.setEnabled(false);
    }

    //add all the action listeners

    radio2d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio2d.isSelected()) {

                radio3d.setSelected(false);

                if (chartOptions.getItemCount() > 0) {
                    existingGraph.setEnabled(true);
                    chartOptions.setEnabled(true);
                }

                example.setText(
                        "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
            }
        }
    });

    radio3d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio3d.isSelected()) {

                radio2d.setSelected(false);
                newGraph.setSelected(true);
                existingGraph.setEnabled(false);
                chartOptions.setEnabled(false);
                example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>");

            }

        }
    });

    newGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (newGraph.isSelected()) {
                existingGraph.setSelected(false);
                chartOptions.setEnabled(false);
            }
        }
    });

    existingGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (existingGraph.isSelected()) {

                newGraph.setSelected(false);
                chartOptions.setEnabled(true);
            }
        }
    });

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            String function = functionField.getText();

            Expression expr = null;

            try {

                expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function);
                expr = (Expression) expr.accept(new ASTTraverseModify() {

                    @Override
                    public Object visit(ExpressionIdent e) throws PrismLangException {
                        return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                    }

                });

                expr.typeCheck();
                expr.semanticCheck();

            } catch (PrismLangException e1) {

                // for copying style
                JLabel label = new JLabel();

                // html content in our case the error we want to show
                JEditorPane ep = new JEditorPane("text/html",
                        "<html> There was an error parsing the function. To read about what built-in"
                                + " functions are supported <br>and some more information on the functions, visit "
                                + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>."
                                + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>");

                // handle link events
                ep.addHyperlinkListener(new HyperlinkListener() {
                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                            try {
                                Desktop.getDesktop().browse(e.getURL().toURI());
                            } catch (IOException | URISyntaxException e1) {

                                e1.printStackTrace();
                            }
                        }
                    }
                });
                ep.setEditable(false);
                ep.setBackground(label.getBackground());

                // show the error dialog
                JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (radio2d.isSelected()) {

                ParametricGraph graph = null;

                if (newGraph.isSelected()) {

                    graph = new ParametricGraph("");
                } else {

                    for (int i = 0; i < theTabs.getComponentCount(); i++) {

                        if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) {

                            graph = (ParametricGraph) theTabs.getComponent(i);
                        }
                    }

                }

                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true);

            } else if (radio3d.isSelected()) {

                try {

                    expr = (Expression) expr.accept(new ASTTraverseModify() {
                        @Override
                        public Object visit(ExpressionIdent e) throws PrismLangException {
                            return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                        }

                    });

                    expr.semanticCheck();
                    expr.typeCheck();

                } catch (PrismLangException e1) {
                    e1.printStackTrace();
                }

                if (expr.getAllConstants().size() < 2) {

                    JOptionPane.showMessageDialog(dialog,
                            "There are not enough variables in the function to plot a 3D chart!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                // its always a new graph
                ParametricGraph3D graph = new ParametricGraph3D(expr);
                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false);
            }

            dialog.dispose();
        }
    });

    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    // we will show info about the function when field is out of focus
    functionField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

            if (!functionField.getText().equals("")) {
                return;
            }

            functionField.setText("Add function expression here....");
            functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
            functionField.setForeground(Color.GRAY);
        }

        @Override
        public void focusGained(FocusEvent e) {

            if (!functionField.getText().equals("Add function expression here....")) {
                return;
            }

            functionField.setForeground(Color.BLACK);
            functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
            functionField.setText("");
        }
    });

    // show the dialog
    dialog.setVisible(true);
}

From source file:com.puzzle.gui.MainFrame.java

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        int rowNumber = this.jTable1.getSelectedRow();
        String fileName = (String) this.jTable1.getValueAt(rowNumber, 1);
        String[] names = fileName.split("\\\\");
        String ff = names[names.length - 1];
        fileName = FileDto.getSingleInstance().fileSendBakPath + File.separator + DateUtil.getCurrDateMM()
                + File.separator + ff;
        String content = null;//from  w  ww.  jav a2  s . c  o  m
        try {
            content = org.apache.commons.io.FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
            return;
        }
        //              String ll=this.readXML(workpath,ff);
        this.jDialog1.setTitle(fileName);
        //??
        textArea.setText(content);
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        textArea.setCodeFoldingEnabled(true);
        textArea.setAutoscrolls(true);
        //            textArea.setBackground(Color.black);
        textArea.setEditable(false);
        //             textArea.setVisible(true);
        this.jPanel6.add(sp);

        this.jDialog1.setLocationRelativeTo(this);
        this.jDialog1.setVisible(true);
    }
}

From source file:com.puzzle.gui.MainFrame.java

private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        int rowNumber = this.jTable2.getSelectedRow();
        String fileName = (String) this.jTable2.getValueAt(rowNumber, 1);

        String content = null;//from w  w  w . j  av a2 s  . c om
        try {
            content = org.apache.commons.io.FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
            return;
        }
        //              String ll=this.readXML(workpath,ff);
        this.jDialog1.setTitle(fileName);
        //??
        textArea.setText(content);
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        textArea.setCodeFoldingEnabled(true);
        textArea.setAutoscrolls(true);
        //            textArea.setBackground(Color.black);
        textArea.setEditable(false);
        //             textArea.setVisible(true);
        this.jPanel6.add(sp);

        this.jDialog1.setLocationRelativeTo(this);
        this.jDialog1.setVisible(true);
    }

}

From source file:corelyzer.ui.CorelyzerGLCanvas.java

public void mouseClicked(final MouseEvent e) {
    Point prePos = e.getPoint();//from ww  w  .  jav a 2 s.  c  om
    float sp[] = { 0.0f, 0.0f };
    this.convertMousePointToSceneSpace(prePos, scenePos);

    switch (e.getButton()) {
    case MouseEvent.BUTTON1:
        if (e.getClickCount() > 1) { // doubleclick zoom in/out
            Point mousePos = e.getPoint();

            float[] cp = { 0.0f, 0.0f };
            float[] sc = { 0.0f, 0.0f };

            canvasLock.lock();

            convertMousePointToSceneSpace(mousePos, cp);

            sc[0] = SceneGraph.getSceneCenterX();
            sc[1] = SceneGraph.getSceneCenterY();

            // alt down for zoom out?!
            float base;
            if (e.isAltDown()) { // zoom out
                base = 1.05f;
            } else { // zoom out
                base = 0.95f;
            }

            float scale = (float) Math.pow(base, 3);

            SceneGraph.scaleScene(scale);

            float ncp[] = { 0.0f, 0.0f };

            this.convertMousePointToSceneSpace(mousePos, ncp);
            ncp[0] = ncp[0] - cp[0];
            ncp[1] = ncp[1] - cp[1];

            SceneGraph.panScene(-ncp[0], -ncp[1]);
            canvasLock.unlock();

            CorelyzerApp.getApp().updateGLWindows();
            return;
        }

        // measuring mode
        if (canvasMode == CorelyzerApp.APP_MEASURE_MODE) {
            int nPoint = SceneGraph.addMeasurePoint(scenePos[0], scenePos[1]);
            this.convertScenePointToAbsolute(scenePos, sp);
            if (nPoint == 1) {
                CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 1);
            } else if (nPoint == 2) {
                CorelyzerApp.getApp().getToolFrame().addMeasure(sp, 2);
            }

            PAN_MODE = 0;
            return;
        }

        if (selectedFreeDraw > -1) {
            CorelyzerApp.getApp().getPluginManager().broadcastEventToPlugin(
                    SceneGraph.getFreeDrawPluginID(selectedFreeDraw), CorelyzerPluginEvent.FREE_DRAW_SELECTED,
                    "" + selectedFreeDraw);
            return;
        }

        selectedMarker = SceneGraph.accessPickedMarker();

        if (selectedMarker < 0) {
            if (canvasMode == CorelyzerApp.APP_MARKER_MODE) {
                SceneGraph.setCoreSectionMarkerFocus(false);
                CorelyzerApp.getApp().updateGLWindows();
            }
            return;
        } else {
            if (canvasMode == CorelyzerApp.APP_NORMAL_MODE) {
                AnnotationUtils.openAnnotation(getCanvas(), selectedTrack, selectedTrackSection,
                        selectedMarker);
            } else { // marker mode
                // TODO do something if want to allow user adjust the
                // selected
                // TODO block, like sync to ClastInfo hash...
                if (selectedMarker != SceneGraph.focusedMarker
                        || selectedTrackSection != SceneGraph.focusedTrackSection
                        || selectedTrack != SceneGraph.focusedTrack) {
                    SceneGraph.setCoreSectionMarkerFocus(false);

                    SceneGraph.focusedTrack = selectedTrack;
                    SceneGraph.focusedTrackSection = selectedTrackSection;
                    SceneGraph.focusedMarker = selectedMarker;
                    SceneGraph.setCoreSectionMarkerFocus(true);
                }
            }
        }

        break;

    case MouseEvent.BUTTON2:
        /*
         * System.out.println("---- Middle button clicked at: " +
         * prePos.x + ", " + prePos.y);
         * System.out.println("Converted to Scene Space: " + scenePos[0]
         * + ", " + scenePos[1]);
         */
        break;

    case MouseEvent.BUTTON3:
        /*
         * System.out.println("---- Right button clicked at: " +
         * prePos.x + ", " + prePos.y);
         * System.out.println("Converted to Scene Space: " + scenePos[0]
         * + ", " + scenePos[1]);
         */
        this.handleRightMouseClick(e);
        break;
    default:
        if (e.isPopupTrigger()) {
            this.handleRightMouseClick(e);
        }
    }
}

From source file:com.puzzle.gui.MainFrame.java

private void jDialog1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jDialog1MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        if (jDialog1.getSize().width < 900) {
            jDialog1.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,
                    Toolkit.getDefaultToolkit().getScreenSize().height);
            jDialog1.setLocationRelativeTo(null);
        } else {//from  w w w .  ja  v a2s.  co m
            jDialog1.setSize(800, 540);
            jDialog1.setLocationRelativeTo(null);
        }

    }

}

From source file:oct.analysis.application.OCTAnalysisUI.java

private void octAnalysisPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_octAnalysisPanelMouseClicked
    octAnalysisPanel.requestFocus();//w  w w .  ja v a  2 s .  c  o  m
    //only perform actions when mouse click occurs over image area
    if (analysisMngr.getAnalysisMode() != null
            && octAnalysisPanel.coordinateOverlapsOCT(evt.getX(), evt.getY())) {
        switch (evt.getButton()) {
        case MouseEvent.BUTTON1:
            switch (analysisMngr.getAnalysisMode()) {
            case SINGLE:
                switch (toolMode) {
                case SELECT_SINGLE:
                    //clear out any current analysis selection
                    selectionLRPManager.removeSelections(false);
                    octAnalysisPanel.repaint();
                    //add new selections and redraw panel
                    selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection(
                            octAnalysisPanel.translatePanelPointToOctPoint(evt.getPoint()).x, "Selection",
                            SelectionType.NONFOVEAL, true));
                    octAnalysisPanel.repaint();
                    break;
                case SCREEN_SELECT:
                    selectSelection(evt.getPoint());
                    break;
                }
                break;
            case MIRROR:
                switch (toolMode) {
                case SELECT_SINGLE:
                    //clear out any current analysis selection
                    selectionLRPManager.removeNonfovealSelections(false);
                    octAnalysisPanel.repaint();
                    //add new selections and redraw panel
                    int distFromFovea = Math.abs(analysisMngr.getFoveaCenterXPosition()
                            - octAnalysisPanel.translatePanelPointToOctPoint(evt.getPoint()).x);
                    selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection(
                            analysisMngr.getFoveaCenterXPosition() - distFromFovea, "Left",
                            SelectionType.NONFOVEAL, true));
                    selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection(
                            analysisMngr.getFoveaCenterXPosition() + distFromFovea, "Right",
                            SelectionType.NONFOVEAL, true));
                    octAnalysisPanel.repaint();
                    break;
                case SCREEN_SELECT:
                    selectSelection(evt.getPoint());
                    break;
                }
                break;
            case EZ:
                //allow user to select and change position of the EZ edge selections after the fact
                switch (toolMode) {
                case SCREEN_SELECT:
                    selectSelection(evt.getPoint());
                default:
                    break;
                }
                break;
            case EQUIDISTANT:
                //allow user to change placement of fovea after the fact
                if (toolMode == ToolMode.SELECT_FOVEA) {
                    //clear out any current analysis information
                    selectionLRPManager.removeSelections(true);
                    octAnalysisPanel.repaint();
                    //add new selections and redraw panel
                    selectionLRPManager.addOrUpdateEquidistantSelections(evt.getX(),
                            analysisMngr.getMicronsBetweenSelections());
                    octAnalysisPanel.repaint();
                }
                break;
            default:
                break;
            }
            break;
        case MouseEvent.BUTTON3:
            selectionLRPManager.removeSelections(true);
            octAnalysisPanel.repaint();
            break;
        default:
            break;
        }
    }
}

From source file:com.puzzle.gui.MainFrame.java

private void jTable4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable4MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        int rowNumber = this.jTable4.getSelectedRow();
        String fileName = (String) this.jTable4.getValueAt(rowNumber, 1);

        String content = null;// w w w  .  java2s. c  o  m
        try {
            content = org.apache.commons.io.FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        //              String ll=this.readXML(workpath,ff);
        this.jDialog1.setTitle(fileName);
        //??

        textArea.setText(content);
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        textArea.setCodeFoldingEnabled(true);
        textArea.setAutoscrolls(true);
        //            textArea.setBackground(Color.black);
        textArea.setEditable(false);
        //             textArea.setVisible(true);
        this.jPanel6.add(sp);

        this.jDialog1.setLocationRelativeTo(this);
        this.jDialog1.setVisible(true);
    }
}

From source file:Clavis.Windows.WShedule.java

public synchronized void create() {
    initComponents();/*ww w. j  a va2 s.c o m*/
    this.setModal(true);
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            close();
        }
    });
    this.setTitle(lingua.translate("Registos de emprstimo para o recurso") + ": "
            + lingua.translate(mat.getTypeOfMaterialName()).toLowerCase() + " "
            + lingua.translate(mat.getDescription()));
    KeyQuest.addtoPropertyListener(jPanelInicial, true);
    String dat = new TimeDate.Date().toString();
    String[] auxiliar = prefs.get("datainicio", dat).split("/");
    if (auxiliar[0].length() > 1) {
        if (auxiliar[0].charAt(0) == '0') {
            auxiliar[0] = auxiliar[0].replaceFirst("0", "");
        }
    }
    if (auxiliar[1].length() > 1) {
        if (auxiliar[1].charAt(0) == '0') {
            auxiliar[1] = auxiliar[1].replaceFirst("0", "");
        }
    }
    if (auxiliar[2].length() > 1) {
        if (auxiliar[2].charAt(0) == '0') {
            auxiliar[2] = auxiliar[2].replaceFirst("0", "");
        }
    }
    inicio = new TimeDate.Date(Integer.valueOf(auxiliar[0]), Integer.valueOf(auxiliar[1]),
            Integer.valueOf(auxiliar[2]));
    auxiliar = prefs.get("datafim", dat).split("/");
    if (auxiliar[0].length() > 1) {
        if (auxiliar[0].charAt(0) == '0') {
            auxiliar[0] = auxiliar[0].replaceFirst("0", "");
        }
    }
    if (auxiliar[1].length() > 1) {
        if (auxiliar[1].charAt(0) == '0') {
            auxiliar[1] = auxiliar[1].replaceFirst("0", "");
        }
    }
    if (auxiliar[2].length() > 1) {
        if (auxiliar[2].charAt(0) == '0') {
            auxiliar[2] = auxiliar[2].replaceFirst("0", "");
        }
    }
    fim = new TimeDate.Date(Integer.valueOf(auxiliar[0]), Integer.valueOf(auxiliar[1]),
            Integer.valueOf(auxiliar[2]));

    SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
    Date date;
    try {
        date = sdf.parse(fim.toString());
    } catch (ParseException ex) {
        date = new Date();

    }
    jXDatePickerFim.setDate(date);
    try {
        date = sdf.parse(inicio.toString());
    } catch (ParseException ex) {
        date = new Date();
    }
    jXDatePickerInicio.setDate(date);
    andamento = 0;
    if (DataBase.DataBase.testConnection(url)) {
        DataBase.DataBase db = new DataBase.DataBase(url);
        java.util.List<Keys.Request> requisicoes = Clavis.RequestList
                .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim));
        db.close();
        estado = lingua.translate("Todos");
        DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
        if (requisicoes.size() > 0) {
            valores = new String[requisicoes.size()][4];
            lista = new java.util.ArrayList<>();
            requisicoes.stream().map((req) -> {
                if (mat.getMaterialTypeID() == 1) {
                    valores[andamento][0] = req.getPerson().getName();
                    valores[andamento][1] = req.getTimeBegin().toString(0) + " - "
                            + req.getTimeEnd().toString(0);
                    valores[andamento][2] = req.getBeginDate().toString();
                    String[] multipla = req.getActivity().split(":::");
                    if (multipla.length > 1) {
                        Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                        pop.create();
                        jTable1.addMouseListener(new MouseAdapter() {
                            int x = andamento;
                            int y = 3;

                            @Override
                            public void mousePressed(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    int row = jTable1.rowAtPoint(e.getPoint());
                                    int col = jTable1.columnAtPoint(e.getPoint());
                                    if ((row == x) && (col == y)) {
                                        pop.show(e.getComponent(), e.getX(), e.getY());
                                    }
                                }
                            }

                            @Override
                            public void mouseReleased(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    if (pop.isShowing()) {
                                        pop.setVisible(false);
                                    }
                                }
                            }
                        });
                        valores[andamento][3] = lingua.translate(multipla[0]) + "";
                    } else {
                        valores[andamento][3] = lingua.translate(req.getActivity());
                    }
                    if (valores[andamento][3].equals("")) {
                        valores[andamento][3] = lingua.translate("Sem descrio");
                    }
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), valores[andamento][3], req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    valores[andamento][0] = req.getPerson().getName();
                    valores[andamento][1] = req.getBeginDate().toString();
                    valores[andamento][2] = req.getEndDate().toString();
                    String[] multipla = req.getActivity().split(":::");
                    if (multipla.length > 1) {
                        Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                        pop.create();
                        jTable1.addMouseListener(new MouseAdapter() {
                            int x = andamento;
                            int y = 3;

                            @Override
                            public void mousePressed(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    int row = jTable1.rowAtPoint(e.getPoint());
                                    int col = jTable1.columnAtPoint(e.getPoint());
                                    if ((row == x) && (col == y)) {
                                        pop.show(e.getComponent(), e.getX(), e.getY());
                                    }
                                }
                            }

                            @Override
                            public void mouseReleased(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    if (pop.isShowing()) {
                                        pop.setVisible(false);
                                    }
                                }
                            }
                        });
                        valores[andamento][3] = multipla[0];
                    } else {
                        valores[andamento][3] = lingua.translate(req.getActivity());
                    }
                    if (valores[andamento][3].equals("")) {
                        valores[andamento][3] = lingua.translate("Sem descrio");
                    }
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), valores[andamento][3] };
                    modelo.addRow(ob);
                }
                return req;
            }).map((req) -> {
                lista.add(req);
                return req;
            }).forEach((_item) -> {
                andamento++;
            });
        }
    }
    jComboBoxEstado.setSelectedIndex(prefs.getInt("comboboxvalue", 0));
    String[] opcoes = { lingua.translate("Ver detalhes da requisio"),
            lingua.translate("Ver requisices com a mesma data"),
            lingua.translate("Ver requisices com o mesmo estado") };
    ActionListener[] eventos = new ActionListener[opcoes.length];
    eventos[0] = (ActionEvent r) -> {
        Border border = BorderFactory.createCompoundBorder(
                BorderFactory.createCompoundBorder(new org.jdesktop.swingx.border.DropShadowBorder(Color.BLACK,
                        3, 0.5f, 6, false, false, true, true), BorderFactory.createLineBorder(Color.BLACK, 1)),
                BorderFactory.createEmptyBorder(0, 10, 0, 10));
        int val = jTable1.getSelectedRow();
        Keys.Request req = lista.get(val);
        javax.swing.JPanel pan = new javax.swing.JPanel(null);
        pan.setPreferredSize(new Dimension(500, 300));
        pan.setBounds(0, 20, 500, 400);
        pan.setBackground(Components.MessagePane.BACKGROUND_COLOR);
        javax.swing.JLabel lrecurso1 = new javax.swing.JLabel(lingua.translate("Recurso") + ": ");
        lrecurso1.setBounds(10, 20, 120, 26);
        lrecurso1.setFocusable(true);
        lrecurso1.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso1);
        javax.swing.JLabel lrecurso11 = new javax.swing.JLabel(
                lingua.translate(req.getMaterial().getTypeOfMaterialName()) + " "
                        + lingua.translate(req.getMaterial().getDescription()));
        lrecurso11.setBounds(140, 20, 330, 26);
        lrecurso11.setBorder(border);
        pan.add(lrecurso11);
        javax.swing.JLabel lrecurso2 = new javax.swing.JLabel(lingua.translate("Utilizador") + ": ");
        lrecurso2.setBounds(10, 50, 120, 26);
        lrecurso2.setFocusable(true);
        lrecurso2.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso2);
        javax.swing.JLabel lrecurso22 = new javax.swing.JLabel(req.getPerson().getName());
        lrecurso22.setBounds(140, 50, 330, 26);
        lrecurso22.setBorder(border);
        pan.add(lrecurso22);
        javax.swing.JLabel lrecurso3 = new javax.swing.JLabel(lingua.translate("Data inicial") + ": ");
        lrecurso3.setBounds(10, 80, 120, 26);
        lrecurso3.setFocusable(true);
        lrecurso3.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso3);
        javax.swing.JLabel lrecurso33 = new javax.swing.JLabel(
                req.getBeginDate().toStringWithMonthWord(lingua));
        lrecurso33.setBounds(140, 80, 330, 26);
        lrecurso33.setBorder(border);
        pan.add(lrecurso33);
        javax.swing.JLabel lrecurso4 = new javax.swing.JLabel(lingua.translate("Data final") + ": ");
        lrecurso4.setBounds(10, 110, 120, 26);
        lrecurso4.setFocusable(true);
        lrecurso4.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso4);
        javax.swing.JLabel lrecurso44 = new javax.swing.JLabel(req.getEndDate().toStringWithMonthWord(lingua));
        lrecurso44.setBounds(140, 110, 330, 26);
        lrecurso44.setBorder(border);
        pan.add(lrecurso44);

        javax.swing.JLabel lrecurso5 = new javax.swing.JLabel(lingua.translate("Atividade") + ": ");
        lrecurso5.setBounds(10, 140, 120, 26);
        lrecurso5.setFocusable(true);
        lrecurso5.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso5);
        javax.swing.JLabel lrecurso55;
        if (req.getActivity().equals("")) {
            lrecurso55 = new javax.swing.JLabel(lingua.translate("Sem descrio"));
        } else {
            String[] saux = req.getActivity().split(":::");
            String atividade;
            boolean situacao = false;
            if (saux.length > 1) {
                situacao = true;
                atividade = saux[0];
            } else {
                atividade = req.getActivity();
            }
            if (req.getSubject().getId() > 0) {
                lrecurso55 = new javax.swing.JLabel(
                        lingua.translate(atividade) + ": " + req.getSubject().getName());
            } else {
                lrecurso55 = new javax.swing.JLabel(lingua.translate(atividade));
            }
            if (situacao) {
                Components.PopUpMenu pop = new Components.PopUpMenu(saux, lingua);
                pop.create();
                lrecurso55.addMouseListener(new MouseAdapter() {

                    @Override
                    public void mouseEntered(MouseEvent e) {
                        pop.show(e.getComponent(), e.getX(), e.getY());
                    }

                    @Override
                    public void mouseExited(MouseEvent e) {
                        pop.setVisible(false);
                    }

                });
            }
        }
        lrecurso55.setBounds(140, 140, 330, 26);
        lrecurso55.setBorder(border);
        pan.add(lrecurso55);
        int distancia = 170;
        if (req.getBeginDate().isBigger(req.getEndDate()) == 0) {
            javax.swing.JLabel lrecurso6 = new javax.swing.JLabel(lingua.translate("Horrio") + ": ");
            lrecurso6.setBounds(10, distancia, 120, 26);
            lrecurso6.setFocusable(true);
            lrecurso6.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso6);
            javax.swing.JLabel lrecurso66 = new javax.swing.JLabel(
                    req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0));
            lrecurso66.setBounds(140, distancia, 330, 26);
            lrecurso66.setBorder(border);
            pan.add(lrecurso66);
            distancia = 200;
        }
        if (req.getBeginDate().isBigger(req.getEndDate()) == 0) {
            javax.swing.JLabel lrecurso7 = new javax.swing.JLabel(lingua.translate("Dia da semana") + ": ");
            lrecurso7.setBounds(10, distancia, 120, 26);
            lrecurso7.setFocusable(true);
            lrecurso7.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso7);
            javax.swing.JLabel lrecurso77 = new javax.swing.JLabel(
                    lingua.translate(req.getWeekDay().perDayName()));
            lrecurso77.setBounds(140, distancia, 330, 26);
            lrecurso77.setBorder(border);
            pan.add(lrecurso77);
            if (distancia == 200) {
                distancia = 230;
            } else {
                distancia = 200;
            }
        }
        if (req.isTerminated() || req.isActive()) {
            javax.swing.JLabel lrecurso8 = new javax.swing.JLabel(lingua.translate("Levantamento") + ": ");
            lrecurso8.setBounds(10, distancia, 120, 26);
            lrecurso8.setFocusable(true);
            lrecurso8.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso8);
            javax.swing.JLabel lrecurso88;
            if ((req.getLiftDate() != null) && (req.getLiftTime() != null)) {
                lrecurso88 = new javax.swing.JLabel(req.getLiftDate().toString() + " " + lingua.translate("s")
                        + " " + req.getLiftTime().toString(0));
            } else {
                lrecurso88 = new javax.swing.JLabel(lingua.translate("sem dados para apresentar"));
            }
            lrecurso88.setBounds(140, distancia, 330, 26);
            lrecurso88.setBorder(border);
            pan.add(lrecurso88);
            switch (distancia) {
            case 200:
                distancia = 230;
                break;
            case 230:
                distancia = 260;
                break;
            default:
                distancia = 200;
                break;
            }
        }
        if (req.isTerminated()) {
            javax.swing.JLabel lrecurso9 = new javax.swing.JLabel(lingua.translate("Entrega") + ": ");
            lrecurso9.setBounds(10, distancia, 120, 26);
            lrecurso9.setFocusable(true);
            lrecurso9.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso9);
            javax.swing.JLabel lrecurso99;
            if ((req.getDeliveryDate() != null) && (req.getDeliveryTime() != null)) {
                lrecurso99 = new javax.swing.JLabel(req.getDeliveryDate().toString() + " "
                        + lingua.translate("s") + " " + req.getDeliveryTime().toString(0));
            } else {
                lrecurso99 = new javax.swing.JLabel(lingua.translate("sem dados para apresentar"));
            }
            lrecurso99.setBounds(140, distancia, 330, 26);
            lrecurso99.setBorder(border);
            pan.add(lrecurso99);
            switch (distancia) {
            case 200:
                distancia = 230;
                break;
            case 230:
                distancia = 260;
                break;
            case 260:
                distancia = 290;
                break;
            default:
                distancia = 200;
                break;
            }
        }
        Components.MessagePane mensagem = new Components.MessagePane(this, Components.MessagePane.INFORMACAO,
                Clavis.KeyQuest.getSystemColor(), lingua.translate(""), 500, 400, pan, "",
                new String[] { lingua.translate("Voltar") });
        mensagem.showMessage();
    };
    eventos[1] = (ActionEvent r) -> {
        String val = jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 2).toString();
        SimpleDateFormat sdf_auxiliar = new SimpleDateFormat("dd/MM/yyyy");
        Date data_auxiliar;
        try {
            data_auxiliar = sdf_auxiliar.parse(val);
            Calendar cal = Calendar.getInstance();
            cal.setTime(data_auxiliar);
            int dia = cal.get(Calendar.DAY_OF_MONTH);
            int mes = cal.get(Calendar.MONTH) + 1;
            int ano = cal.get(Calendar.YEAR);
            inicio = new TimeDate.Date(dia, mes, ano);
            fim = new TimeDate.Date(dia, mes, ano);
        } catch (ParseException ex) {
            data_auxiliar = new Date();
        }
        jXDatePickerFim.setDate(data_auxiliar);
        jXDatePickerInicio.setDate(data_auxiliar);
        refreshTable(jComboBoxEstado.getSelectedIndex());
    };
    eventos[2] = (ActionEvent r) -> {
        String val = jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 3).toString();
        for (int i = 0; i < jComboBoxEstado.getItemCount(); i++) {
            if (jComboBoxEstado.getItemAt(i).equals(val)) {
                jComboBoxEstado.setSelectedIndex(i);
            }
        }
    };
    KeyStroke[] strokes = new KeyStroke[opcoes.length];
    strokes[0] = KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK);
    strokes[1] = KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK);
    strokes[2] = KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK);
    Components.PopUpMenu pop = new Components.PopUpMenu(opcoes, eventos, strokes);
    pop.create();
    mouseaction = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            java.awt.Point ponto = new java.awt.Point(e.getX(), e.getY());
            if (jTable1.rowAtPoint(ponto) > -1) {
                jTable1.setRowSelectionInterval(jTable1.rowAtPoint(ponto),
                        jTable1.rowAtPoint(new java.awt.Point(e.getX(), e.getY())));
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                if (jTable1.getSelectedRow() >= 0) {
                    java.awt.Point ponto = new java.awt.Point(e.getX(), e.getY());
                    if (jTable1.rowAtPoint(ponto) > -1) {
                        pop.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }
        }

    };
    jTable1.addMouseListener(mouseaction);
}

From source file:simMPLS.ui.simulator.JVentanaHija.java

/** Action when the mouse button is pressed and released
 * @since 1.0/*from w  ww.jav  a  2 s. c  o  m*/
 */
private void ratonPulsadoYSoltadoEnPanelSimulacion(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ratonPulsadoYSoltadoEnPanelSimulacion
    if (evt.getButton() == MouseEvent.BUTTON1) {
        TTopologyElement et = escenario.getTopology().obtenerElementoEnPosicion(evt.getPoint());
        if (et != null) {
            if (et.getElementType() == TTopologyElement.NODO) {
                TNode nt = (TNode) et;
                nt.toCongest();
            } else if (et.getElementType() == TTopologyElement.LINK) {
                //                    TLink ent = (TLink) et;
                //                    if (ent.isBroken()) {
                //                        ent.ponerEnlaceCaido(false);
                //                    } else {
                //                        ent.ponerEnlaceCaido(true);
                //                    }
            }
        } else {
            if (this.panelSimulacion.obtenerMostrarLeyenda()) {
                this.panelSimulacion.ponerMostrarLeyenda(false);
            } else {
                this.panelSimulacion.ponerMostrarLeyenda(true);
            }
        }
    } else if (evt.getButton() == MouseEvent.BUTTON3) {
        TTopologyElement et = escenario.getTopology().obtenerElementoEnPosicion(evt.getPoint());
        if (et != null) {
            if (et.getElementType() == TTopologyElement.LINK) {
                TLink ent = (TLink) et;
                if (!ent.isBroken()) {
                    JWindowLinkDump linkWindow = new JWindowLinkDump(VentanaPadre, true, ent);
                    linkWindow.setVisible(true);
                }
            }
        }
    } else {
        elementoDisenioClicDerecho = null;
        panelDisenio.repaint();
    }
}