Example usage for javax.swing JButton getLocationOnScreen

List of usage examples for javax.swing JButton getLocationOnScreen

Introduction

In this page you can find the example usage for javax.swing JButton getLocationOnScreen.

Prototype

public Point getLocationOnScreen() 

Source Link

Document

Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.

Usage

From source file:fxts.stations.trader.ui.ABaseDialog.java

public void componentShown(ComponentEvent aEvent) {
    try {//  w ww  . j  av a  2  s .c o m
        UserPreferences preferences = UserPreferences.getUserPreferences(TradeDesk.getInst().getUserName());
        JButton button = getRootPane().getDefaultButton();
        if (preferences.getBoolean("Mouse.snapDefaultButton") && button != null) {
            // snap mouse to middle of default button
            Robot robot = new Robot();
            int x = (int) button.getLocationOnScreen().getX();
            int y = (int) button.getLocationOnScreen().getY();
            int width = (int) button.getSize().getWidth();
            int height = (int) button.getSize().getHeight();
            int x1 = x + width / 2;
            int y1 = y + height / 2;
            robot.mouseMove(x1, y1);
        }
    } catch (AWTException e) {
        e.printStackTrace();
    }
}

From source file:SuitaDetails.java

public DefPanel(String descriptions, String button, String id, int width, final int index,
        SuitaDetails container) {//  w ww. j  a  va  2s .co  m
    this.descriptions = descriptions;
    this.id = id;
    reference = this;
    this.container = container;
    this.index = index;
    setBackground(new Color(255, 255, 255));
    setBorder(BorderFactory.createEmptyBorder(2, 20, 2, 20));
    setMaximumSize(new Dimension(32767, 30));
    setMinimumSize(new Dimension(100, 30));
    setPreferredSize(new Dimension(300, 30));
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
    description = new JLabel(descriptions);
    description.setPreferredSize(new Dimension(width, 20));
    description.setMinimumSize(new Dimension(width, 20));
    description.setMaximumSize(new Dimension(width, 20));
    add(description);
    filedsGap = new JPanel();
    filedsGap.setBackground(new Color(255, 255, 255));
    filedsGap.setMaximumSize(new Dimension(20, 20));
    filedsGap.setMinimumSize(new Dimension(20, 20));
    filedsGap.setPreferredSize(new Dimension(20, 20));
    GroupLayout filedsGapLayout = new GroupLayout(filedsGap);
    filedsGap.setLayout(filedsGapLayout);
    filedsGapLayout.setHorizontalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    filedsGapLayout.setVerticalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    add(filedsGap);
    userDefinition = new JTextField();
    doclistener = new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            setParentField(userDefinition.getText(), false);
        }

        public void removeUpdate(DocumentEvent e) {
            setParentField(userDefinition.getText(), false);
        }

        public void insertUpdate(DocumentEvent e) {
            setParentField(userDefinition.getText(), false);
        }
    };
    userDefinition.getDocument().addDocumentListener(doclistener);
    userDefinition.setText("");
    userDefinition.setMaximumSize(new Dimension(300, 100));
    userDefinition.setMinimumSize(new Dimension(50, 20));
    userDefinition.setPreferredSize(new Dimension(100, 20));
    add(userDefinition);
    filedsGap = new JPanel();
    filedsGap.setBackground(new Color(255, 255, 255));
    filedsGap.setMaximumSize(new Dimension(20, 20));
    filedsGap.setMinimumSize(new Dimension(20, 20));
    filedsGap.setPreferredSize(new Dimension(20, 20));
    filedsGapLayout = new GroupLayout(filedsGap);
    filedsGap.setLayout(filedsGapLayout);
    filedsGapLayout.setHorizontalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    filedsGapLayout.setVerticalGroup(
            filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGap(0, 20, Short.MAX_VALUE));
    add(filedsGap);
    if (button.equals("UserSelect")) {
        final JButton database = new JButton("Database");
        database.setMaximumSize(new Dimension(100, 20));
        database.setMinimumSize(new Dimension(50, 20));
        database.setPreferredSize(new Dimension(80, 20));
        add(database);
        database.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                DatabaseFrame frame = new DatabaseFrame(reference);
                frame.executeQuery();
                frame.setLocation((int) database.getLocationOnScreen().getX() - 100,
                        (int) database.getLocationOnScreen().getY());
                frame.setVisible(true);
            }
        });
    } else if (button.equals("UserScript")) {
        JButton script = new JButton("Script");
        script.setMaximumSize(new Dimension(100, 20));
        script.setMinimumSize(new Dimension(50, 20));
        script.setPreferredSize(new Dimension(80, 20));
        add(script);
        script.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                Container c;
                if (RunnerRepository.container != null)
                    c = RunnerRepository.container.getParent();
                else
                    c = RunnerRepository.window;
                try {
                    //                         String passwd = RunnerRepository.getRPCClient().execute("sendFile", new Object[]{"/etc/passwd"}).toString();
                    //                         new MySftpBrowser(RunnerRepository.host,RunnerRepository.user,RunnerRepository.password,userDefinition,c,passwd);
                    new MySftpBrowser(RunnerRepository.host, RunnerRepository.user, RunnerRepository.password,
                            userDefinition, c, false);
                } catch (Exception e) {
                    System.out.println("There was a problem in opening sftp browser!");
                    e.printStackTrace();
                }
            }
        });
        filedsGap = new JPanel();
        filedsGap.setBackground(new Color(255, 255, 255));
        filedsGap.setMaximumSize(new Dimension(10, 10));
        filedsGap.setMinimumSize(new Dimension(10, 10));
        filedsGap.setPreferredSize(new Dimension(10, 10));
        filedsGapLayout = new GroupLayout(filedsGap);
        filedsGap.setLayout(filedsGapLayout);
        filedsGapLayout.setHorizontalGroup(filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGap(0, 20, Short.MAX_VALUE));
        filedsGapLayout.setVerticalGroup(filedsGapLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addGap(0, 20, Short.MAX_VALUE));
        filedsGap.setLayout(filedsGapLayout);
        add(filedsGap);
        final JButton value = new JButton("Value");
        value.setMaximumSize(new Dimension(100, 20));
        value.setMinimumSize(new Dimension(50, 20));
        value.setPreferredSize(new Dimension(80, 20));
        add(value);
        value.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ev) {
                String script = userDefinition.getText();
                if (script != null && !script.equals("")) {
                    try {
                        String result = RunnerRepository.getRPCClient().execute("runUserScript",
                                new Object[] { script }) + "";
                        JFrame f = new JFrame();
                        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                        f.setLocation(value.getLocationOnScreen());
                        JLabel l = new JLabel("Script result: " + result);
                        f.getContentPane().add(l, BorderLayout.CENTER);
                        f.pack();
                        f.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    } else if (button.equals("UserText")) {
        JPanel database = new JPanel();
        database.setBackground(Color.WHITE);
        database.setMaximumSize(new Dimension(100, 20));
        database.setMinimumSize(new Dimension(50, 20));
        database.setPreferredSize(new Dimension(80, 20));
        add(database);
    }
}

From source file:ConfigFiles.java

public ConfigFiles(Dimension screensize) {
    //         initializeFileBrowser();
    paths = new JPanel();
    paths.setBackground(Color.WHITE);
    //paths.setBorder(BorderFactory.createTitledBorder("Paths"));
    paths.setLayout(null);/*from  www  .ja  v  a  2 s.c  o  m*/
    paths.setPreferredSize(new Dimension(930, 1144));
    paths.setSize(new Dimension(930, 1144));
    paths.setMinimumSize(new Dimension(930, 1144));
    paths.setMaximumSize(new Dimension(930, 1144));
    //paths.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    setLayout(null);
    ttcpath = new JTextField();
    addPanel("TestCase Source Path",
            "Master directory with the test cases that can" + " be run by the framework", ttcpath,
            RunnerRepository.TESTSUITEPATH, 10, true, null);
    tMasterXML = new JTextField();
    tUsers = new JTextField();

    addPanel("Projects Path", "Location of projects XML files", tUsers, RunnerRepository.REMOTEUSERSDIRECTORY,
            83, true, null);

    tSuites = new JTextField();
    addPanel("Predefined Suites Path", "Location of predefined suites", tSuites,
            RunnerRepository.PREDEFINEDSUITES, 156, true, null);

    testconfigpath = new JTextField();
    addPanel("Test Configuration Path", "Test Configuration path", testconfigpath,
            RunnerRepository.TESTCONFIGPATH, 303, true, null);

    tepid = new JTextField();
    addPanel("EP name File", "Location of the file that contains" + " the Ep name list", tepid,
            RunnerRepository.REMOTEEPIDDIR, 595, true, null);
    tlog = new JTextField();
    addPanel("Logs Path", "Location of the directory that stores the most recent log files."
            + " The files are re-used each Run.", tlog, RunnerRepository.LOGSPATH, 667, true, null);
    tsecondarylog = new JTextField();

    JPanel p = addPanel("Secondary Logs Path",
            "Location of the directory that archives copies of the most recent log files, with"
                    + " original file names appended with <.epoch time>",
            tsecondarylog, RunnerRepository.SECONDARYLOGSPATH, 930, true, null);
    logsenabled.setSelected(Boolean.parseBoolean(RunnerRepository.PATHENABLED));
    logsenabled.setBackground(Color.WHITE);
    p.add(logsenabled);

    JPanel p7 = new JPanel();
    p7.setBackground(Color.WHITE);
    TitledBorder border7 = BorderFactory.createTitledBorder("Log Files");
    border7.setTitleFont(new Font("Arial", Font.PLAIN, 14));
    border7.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
    p7.setBorder(border7);
    p7.setLayout(new BoxLayout(p7, BoxLayout.Y_AXIS));
    p7.setBounds(80, 740, 800, 190);
    paths.add(p7);
    JTextArea log2 = new JTextArea("All the log files that will be monitored");
    log2.setWrapStyleWord(true);
    log2.setLineWrap(true);
    log2.setEditable(false);
    log2.setCursor(null);
    log2.setOpaque(false);
    log2.setFocusable(false);
    log2.setBorder(null);
    log2.setFont(new Font("Arial", Font.PLAIN, 12));
    log2.setBackground(getBackground());
    log2.setMaximumSize(new Dimension(170, 25));
    log2.setPreferredSize(new Dimension(170, 25));
    JPanel p71 = new JPanel();
    p71.setBackground(Color.WHITE);
    p71.setLayout(new GridLayout());
    p71.setMaximumSize(new Dimension(700, 13));
    p71.setPreferredSize(new Dimension(700, 13));
    p71.add(log2);
    JPanel p72 = new JPanel();
    p72.setBackground(Color.WHITE);
    p72.setLayout(new BoxLayout(p72, BoxLayout.Y_AXIS));
    trunning = new JTextField();
    p72.add(addField(trunning, "Running: ", 0));
    tdebug = new JTextField();
    p72.add(addField(tdebug, "Debug: ", 1));
    tsummary = new JTextField();
    p72.add(addField(tsummary, "Summary: ", 2));
    tinfo = new JTextField();
    p72.add(addField(tinfo, "Info: ", 3));
    tcli = new JTextField();
    p72.add(addField(tcli, "Cli: ", 4));
    p7.add(p71);
    p7.add(p72);
    libpath = new JTextField();

    addPanel("Library path", "Secondary user library path", libpath, RunnerRepository.REMOTELIBRARY, 229, true,
            null);

    JPanel p8 = new JPanel();
    p8.setBackground(Color.WHITE);
    TitledBorder border8 = BorderFactory.createTitledBorder("File");
    border8.setTitleFont(new Font("Arial", Font.PLAIN, 14));
    border8.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
    p8.setBorder(border8);
    p8.setLayout(null);
    p8.setBounds(80, 1076, 800, 50);
    if (PermissionValidator.canChangeFWM()) {
        paths.add(p8);
    }
    JButton save = new JButton("Save");
    save.setToolTipText("Save and automatically load config");
    save.setBounds(490, 20, 70, 20);
    save.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            saveXML(false, "fwmconfig");
            loadConfig("fwmconfig.xml");
        }
    });
    p8.add(save);
    //         if(!PermissionValidator.canChangeFWM()){
    //             save.setEnabled(false);
    //         }
    JButton saveas = new JButton("Save as");
    saveas.setBounds(570, 20, 90, 20);
    saveas.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String filename = CustomDialog.showInputDialog(JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION, ConfigFiles.this, "File Name", "Please enter file name");
            if (!filename.equals("NULL")) {
                saveXML(false, filename);
            }
        }
    });
    p8.add(saveas);

    final JButton loadXML = new JButton("Load Config");
    loadXML.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                String[] configs = RunnerRepository
                        .getRemoteFolderContent(RunnerRepository.USERHOME + "/twister/config/");
                JComboBox combo = new JComboBox(configs);
                int resp = (Integer) CustomDialog.showDialog(combo, JOptionPane.INFORMATION_MESSAGE,
                        JOptionPane.OK_CANCEL_OPTION, ConfigFiles.this, "Config", null);
                final String config;
                if (resp == JOptionPane.OK_OPTION)
                    config = combo.getSelectedItem().toString();
                else
                    config = null;
                if (config != null) {
                    new Thread() {
                        public void run() {
                            setEnabledTabs(false);
                            JFrame progress = new JFrame();
                            progress.setAlwaysOnTop(true);
                            progress.setLocation((int) loadXML.getLocationOnScreen().getX(),
                                    (int) loadXML.getLocationOnScreen().getY());
                            progress.setUndecorated(true);
                            JProgressBar bar = new JProgressBar();
                            bar.setIndeterminate(true);
                            progress.add(bar);
                            progress.pack();
                            progress.setVisible(true);
                            loadConfig(config);
                            progress.dispose();
                            setEnabledTabs(true);
                        }
                    }.start();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    loadXML.setBounds(670, 20, 120, 20);
    p8.add(loadXML);
    //         if(!PermissionValidator.canChangeFWM()){
    //             loadXML.setEnabled(false);
    //         }

    tdbfile = new JTextField();
    addPanel("Database XML path", "File location for database configuration", tdbfile,
            RunnerRepository.REMOTEDATABASECONFIGPATH + RunnerRepository.REMOTEDATABASECONFIGFILE, 375, true,
            null);
    temailfile = new JTextField();
    //         emailpanel = (JPanel)
    addPanel("Email XML path", "File location for email configuration", temailfile,
            RunnerRepository.REMOTEEMAILCONFIGPATH + RunnerRepository.REMOTEEMAILCONFIGFILE, 448, true, null)
                    .getParent();
    //paths.remove(emailpanel);

    //         emailpanel.setBounds(360,440,350,100);
    //         RunnerRepository.window.mainpanel.p4.getEmails().add(emailpanel);

    tglobalsfile = new JTextField();
    addPanel("Globals XML file", "File location for globals parameters", tglobalsfile,
            RunnerRepository.GLOBALSREMOTEFILE, 521, true, null);

    tceport = new JTextField();
    addPanel("Central Engine Port", "Central Engine port", tceport, RunnerRepository.getCentralEnginePort(),
            1003, false, null);
    //         traPort = new JTextField();
    //         addPanel("Resource Allocator Port","Resource Allocator Port",
    //                 traPort,RunnerRepository.getResourceAllocatorPort(),808,false,null);                
    //         thttpPort = new JTextField();
    //         addPanel("HTTP Server Port","HTTP Server Port",thttpPort,
    //                 RunnerRepository.getHTTPServerPort(),740,false,null);

    //paths.add(loadXML);

    if (!PermissionValidator.canChangeFWM()) {
        ttcpath.setEnabled(false);
        tMasterXML.setEnabled(false);
        tUsers.setEnabled(false);
        tepid.setEnabled(false);
        tSuites.setEnabled(false);
        tlog.setEnabled(false);
        trunning.setEnabled(false);
        tdebug.setEnabled(false);
        tsummary.setEnabled(false);
        tinfo.setEnabled(false);
        tcli.setEnabled(false);
        tdbfile.setEnabled(false);
        temailfile.setEnabled(false);
        tceport.setEnabled(false);
        libpath.setEnabled(false);
        tsecondarylog.setEnabled(false);
        testconfigpath.setEnabled(false);
        tglobalsfile.setEnabled(false);
        logsenabled.setEnabled(false);
    }

}