Example usage for java.awt.event MouseListener MouseListener

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

Introduction

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

Prototype

MouseListener

Source Link

Usage

From source file:gda.images.GUI.CmuCameraDisplayPanel.java

@Override
public void configure() {
    //logger.info("Cmu Camera Panel config called");
    samplePanel = new RTPCameraClient();
    samplePanel.setPreferredSize(ImageSize);
    samplePanel.setMinimumSize(ImageSize);
    samplePanel.setMaximumSize(ImageSize);
    samplePanel.getImageModifier().setDisplayCrossHair(true);

    samplePanel.addMouseListener(new MouseListener() {

        @Override/* ww  w.  java2 s .c  om*/
        public void mouseClicked(MouseEvent mevt) {
            //logger.info("mouse clicked at " + mevt.getLocationOnScreen());
            //samplePanel.setCentre(mevt.getLocationOnScreen());
            if (mevt.isControlDown()) {
                Point p = mevt.getPoint();
                x = p.x;
                y = p.y;
                samplePanel.getImageModifier().setCentre(p);
                save();
            }
            //samplePanel.revalidate();

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseReleased(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

    });
    try {
        config = LocalParameters.getXMLConfiguration();
    } catch (ConfigurationException e) {
        logger.error("unable to configure beam centre values ", e);

    } catch (IOException e) {
        logger.error("unable to read beam centre values ", e);
    }
    this.load();
    //samplePanel.setDisplayCrossHair(true);
    //samplePanel.setDisplayBeamSize(true);

    //
    samplePanel.getImageModifier().setCentre(new Point(x, y));
    //samplePanel.setBeamSize(new Point(50, 50), new Point(200, 200));

    this.setLayout(new BorderLayout());
    this.add(samplePanel, BorderLayout.CENTER);
    this.add(getButtonPanel(), BorderLayout.SOUTH);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            CmuCameraDisplayPanel.this.add(samplePanel);
            //samplePanel.setXScale(0.9);
            //samplePanel.setYScale(1.1);
            //samplePanel.setDisplayScale(true);
            //samplePanel.start();
        }
    });

    videoReceiver.addImageListener(this);
}

From source file:com.antelink.sourcesquare.gui.view.CopyrightPanel.java

private JLabel createJLabelWithHyperlink(String text, final String href) {
    JLabel label = new JLabel("<html><a href=\"\">" + text + "<a/></html>");
    label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new MouseListener() {

        @Override//from   w w  w  .  j av a  2 s. co m
        public void mouseReleased(MouseEvent arg0) {
        }

        @Override
        public void mousePressed(MouseEvent arg0) {
        }

        @Override
        public void mouseExited(MouseEvent arg0) {
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            try {
                Desktop.getDesktop().browse(new URI(href));
            } catch (IOException e) {
                logger.error("Error opening the browser", e);
            } catch (URISyntaxException e) {
                logger.error("Error opening the browser", e);
            }
        }
    });
    return label;
}

From source file:fi.todoordelay.gui.GuiMainFrame.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./*from  ww w  . j  a  v  a2  s  .c om*/
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    menuBar = new javax.swing.JMenuBar();
    projectMenu = new javax.swing.JMenu();
    addprojectMenuItem = new javax.swing.JMenuItem();
    saveMenuItem = new javax.swing.JMenuItem();
    saveAsMenuItem = new javax.swing.JMenuItem();
    exitMenuItem = new javax.swing.JMenuItem();
    taskMenu = new javax.swing.JMenu();
    addtaskMenuItem = new javax.swing.JMenuItem();
    copyMenuItem = new javax.swing.JMenuItem();
    pasteMenuItem = new javax.swing.JMenuItem();
    deleteMenuItem = new javax.swing.JMenuItem();
    ownlistMenu = new javax.swing.JMenu();
    addownlistMenuItem = new javax.swing.JMenuItem();
    aboutMenuItem = new javax.swing.JMenuItem();

    projectListModel = new javax.swing.DefaultListModel();
    projectsList = new javax.swing.JList(projectListModel);
    projectsPane = new javax.swing.JScrollPane(projectsList);

    taskListModel = new javax.swing.DefaultListModel();
    tasksList = new javax.swing.JList(taskListModel);
    tasksPane = new javax.swing.JScrollPane(tasksList);

    informationTextArea = new javax.swing.JTextArea();
    informationPane = new javax.swing.JScrollPane(informationTextArea);

    addItemDialog = new javax.swing.JOptionPane();
    editItemDialog = new javax.swing.JOptionPane();

    mainLogic = new fi.todoordelay.logic.LogicMain();

    projectsListMouseListener = new MouseListener() {
        public void mouseClicked(MouseEvent evt) {
            int index = projectsList.locationToIndex(evt.getPoint());
            selectedProject = index;
            selectionGroup = 0;

            if (evt.getButton() == 3) {
                int d = editItemDialog.showConfirmDialog(null,
                        "ARE YOU SURE YOU WANT TO DELETE CHOSEN PROJECT?", "Delete project dialog",
                        editItemDialog.YES_NO_OPTION, editItemDialog.WARNING_MESSAGE);
                if (d == 0) {
                    mainLogic.removeProject(mainLogic.getProjects().get(selectedProject));
                }
                selectedProject = -1;
                updateProjectListModel();
            }

            if (evt.getClickCount() == 2 && selectedProject > -1) {
                List pl = mainLogic.getProjects();
                Project p = (Project) pl.get(index);

                editItemDialog.setWantsInput(true);
                String name = editItemDialog.showInputDialog(null, "New project name (required):",
                        "Edit project dialog", editItemDialog.INFORMATION_MESSAGE);
                String description = editItemDialog.showInputDialog(null, "New project description:",
                        "Edit project dialog", editItemDialog.INFORMATION_MESSAGE);
                String dueString = editItemDialog.showInputDialog(null, "New due date in x day(s):",
                        "Edit project dialog", editItemDialog.INFORMATION_MESSAGE);

                try {
                    if (name.equals("")) {
                        JOptionPane.showMessageDialog(editItemDialog,
                                "Project name cannot be empty (exiting without changes)");
                    } else if (Long.parseLong(dueString) < 0) {
                        JOptionPane.showMessageDialog(editItemDialog, "Due date must be zero or higher");
                    } else {
                        p.setName(name);
                        p.setDescription(description);
                        p.setDuedate(LocalDateTime.now().plusDays(Long.parseLong(dueString)));
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(editItemDialog, "Due date must be valid number");
                }

            }

            updateProjectListModel();
            mouseClickedOnProjectActionPerformed(evt);

        }

        public void mouseEntered(MouseEvent evt) {
        }

        public void mouseExited(MouseEvent evt) {
        }

        public void mouseReleased(MouseEvent evt) {
        }

        public void mousePressed(MouseEvent evt) {
        }

    };
    projectsList.addMouseListener(projectsListMouseListener);

    tasksListMouseListener = new MouseListener() {
        public void mouseClicked(MouseEvent evt) {
            int index = tasksList.locationToIndex(evt.getPoint());
            selectedTask = index;
            selectionGroup = 1;

            if (evt.getButton() == 3) {
                int d = editItemDialog.showConfirmDialog(null, "ARE YOU SURE YOU WANT TO DELETE CHOSEN TASK?",
                        "Delete task dialog", editItemDialog.YES_NO_OPTION, editItemDialog.WARNING_MESSAGE);
                if (d == 0) {
                    mainLogic.getProjects().get(selectedProject).removeTask(
                            mainLogic.getProjects().get(selectedProject).getTasks().get(selectedTask));
                }
                updateProjectListModel();
            }

            if (evt.getClickCount() == 2 && selectedTask > -1) {
                List tl = mainLogic.getProjects().get(selectedProject).getTasks();
                Task t = (Task) tl.get(index);

                editItemDialog.setWantsInput(true);
                String name = editItemDialog.showInputDialog(null, "New task name (required):",
                        "Edit task dialog", editItemDialog.INFORMATION_MESSAGE);
                String description = editItemDialog.showInputDialog(null, "New task description:",
                        "Edit task dialog", editItemDialog.INFORMATION_MESSAGE);
                String dueString = editItemDialog.showInputDialog(null, "New due date in x day(s):",
                        "Edit task dialog", editItemDialog.INFORMATION_MESSAGE);

                try {
                    if (name.equals("")) {
                        JOptionPane.showMessageDialog(editItemDialog,
                                "Task name cannot be empty (exiting without changes)");
                    } else if (Long.parseLong(dueString) < 0) {
                        JOptionPane.showMessageDialog(editItemDialog, "Due date must be zero or higher");
                    } else {
                        t.setName(name);
                        t.setDescription(description);
                        t.setDuedate(LocalDateTime.now().plusDays(Long.parseLong(dueString)));
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(editItemDialog, "Due date must be valid number");
                }

            }

            updateProjectListModel();
            mouseClickedOnProjectActionPerformed(evt);

        }

        public void mouseEntered(MouseEvent evt) {
        }

        public void mouseExited(MouseEvent evt) {
        }

        public void mouseReleased(MouseEvent evt) {
        }

        public void mousePressed(MouseEvent evt) {
        }

    };
    tasksList.addMouseListener(tasksListMouseListener);

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    projectsPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Projects"));
    projectsPane.setViewportBorder(null);

    tasksPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Tasks"));
    tasksPane.setViewportBorder(null);

    informationPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));
    projectsPane.setViewportBorder(null);

    projectMenu.setText("Project");
    addprojectMenuItem.setMnemonic('p');
    addprojectMenuItem.setText("Add Project");
    projectMenu.add(addprojectMenuItem);
    addprojectMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            addItemDialog.setWantsInput(true);
            String name = addItemDialog.showInputDialog(null, "Project name (required):", "Add project dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            String description = addItemDialog.showInputDialog(null, "Project description:",
                    "Add project dialog", addItemDialog.INFORMATION_MESSAGE);
            String due_at = addItemDialog.showInputDialog(null, "Due in x day(s):", "Add project dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            Project newProject = new Project(name, description, Long.parseLong(due_at));
            mainLogic.addProject(newProject);
            projectListModel.addElement(name);

            updateProjectListModel();
            addprojectMenuItemActionPerformed(evt);
        }
    });
    menuBar.add(projectMenu);

    taskMenu.setText("Task");
    addtaskMenuItem.setMnemonic('t');
    addtaskMenuItem.setText("Add Task");
    taskMenu.add(addtaskMenuItem);
    addtaskMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            addItemDialog.setWantsInput(true);
            String name = addItemDialog.showInputDialog(null, "Task name (required):", "Add task dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            String description = addItemDialog.showInputDialog(null, "Task description:", "Add task dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            String due_at = addItemDialog.showInputDialog(null, "Due in x day(s):", "Add task dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            Task newTask = new Task(name, description, Long.parseLong(due_at));

            Project s = mainLogic.getProjects().get(selectedProject);

            s.addTask(newTask);
            taskListModel.addElement(name);

            updateProjectListModel();
            addprojectMenuItemActionPerformed(evt);
        }
    });
    menuBar.add(taskMenu);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(
                                    projectsPane, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(
                                    layout.createSequentialGroup().addGap(312, 312, 312).addComponent(tasksPane,
                                            javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                            javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup().addGap(624, 624, 624).addComponent(
                                    informationPane, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                    Short.MAX_VALUE)))

                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            javax.swing.GroupLayout.Alignment.TRAILING,
            layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(informationPane, javax.swing.GroupLayout.DEFAULT_SIZE, 860,
                                    Short.MAX_VALUE)
                            .addComponent(tasksPane, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(projectsPane, javax.swing.GroupLayout.Alignment.LEADING))

                    .addContainerGap()));

    pack();
}

From source file:org.kootox.episodesmanager.ui.systray.EpisodesTrayIcon.java

public void create() {

    //Check the SystemTray support
    if (!SystemTray.isSupported()) {
        if (log.isInfoEnabled()) {
            log.info("SystemTray is not supported");
        }//  w  w w .  j  ava  2s  .com
        return;
    }

    if (loaded) {
        return;
    }

    final PopupMenu popup = new PopupMenu();
    final TrayIcon trayIcon = new TrayIcon(createImage("systray.png", "tray icon"));
    final SystemTray tray = SystemTray.getSystemTray();

    // Create a popup menu components
    MenuItem display = new MenuItem("Display");
    MenuItem exit = new MenuItem("Exit");

    //Add components to popup menu
    popup.add(display);
    popup.addSeparator();
    popup.add(exit);

    trayIcon.setPopupMenu(popup);

    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        if (log.isDebugEnabled()) {
            log.debug("TrayIcon could not be added.");
        }
        return;
    }

    trayIcon.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
                showHide();
            }
        }

        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            //Do nothing
        }

        @Override
        public void mouseReleased(MouseEvent mouseEvent) {
            //Do nothing
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            //Do nothing
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            //Do nothing
        }
    });

    display.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showHide();
        }
    });

    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            EpisodesManagerMainUI mainUI = EpisodesManagerContext.MAIN_UI_ENTRY_DEF.getContextValue(context);
            mainUI.close();
        }
    });

    loaded = true;
    if (log.isDebugEnabled()) {
        log.debug("Systray loaded");
    }
}

From source file:com.mirth.connect.client.ui.TemplatePanel.java

public TemplatePanel(MirthEditorPane m) {
    this.parent = m;

    initComponents();/*  w w w  . j  a va  2s .com*/
    openFileButton.setIcon(UIConstants.ICON_FILE_PICKER);

    if (PlatformUI.MIRTH_FRAME != null) {
        dataTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(
                PlatformUI.MIRTH_FRAME.dataTypeToDisplayName.values().toArray()));
    }

    hl7Document = new SyntaxDocument();
    hl7Document.setTokenMarker(new HL7TokenMarker());
    pasteBox.setDocument(hl7Document);

    // handles updating the tree
    pasteBox.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            updateText();
        }

        public void insertUpdate(DocumentEvent e) {
            updateText();
        }

        public void removeUpdate(DocumentEvent e) {
            updateText();
        }
    });
    pasteBox.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON2) {
                if (pasteBox.getText().equals(DEFAULT_TEXT)) {
                    pasteBox.setText("");
                }
            }
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON2) {
                if (pasteBox.getText().length() == 0) {
                    pasteBox.setText(DEFAULT_TEXT);
                }
            }
        }
    });

    new DropTarget(pasteBox, this);
}

From source file:org.kchine.r.server.impl.RGraphicsPanelRemote.java

public void init() {
    try {//from  w  ww  .  ja va2s .  c  om
        if (!(_graphicNotifier instanceof LocalGraphicNotifier)) {
            _gdcServer = new GDContainerAdapterImpl(this);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
            }
            _graphicNotifier.registerContainer(_gdcServer);
        } else {
            _graphicNotifier.registerContainer(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    new Thread(new Runnable() {
        public void run() {
            while (true) {
                if (_lastResizeTime != null && ((System.currentTimeMillis() - _lastResizeTime) > 1000)) {
                    try {
                        _graphicNotifier.fireSizeChangedEvent(_devNr);
                    } catch (RemoteException e) {
                        e.printStackTrace();
                    }
                    _lastResizeTime = null;
                }

                try {
                    Thread.sleep(20);
                } catch (Exception e) {
                }
            }

        }
    }).start();

    addMouseListener(new MouseListener() {
        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            _graphicNotifier.putLocation(new Point(e.getX(), e.getY()));
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }).start();
            }

        }

        public void mouseReleased(MouseEvent e) {
        }

    });

}

From source file:net.technicpack.launcher.ui.InstallerFrame.java

private void addGlassPane() {
    glassPane = new JPanel() {
        @Override//from  w w  w . j a  v  a2  s  . co  m
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(LauncherFrame.COLOR_CENTRAL_BACK);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    glassPane.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            e.consume();
        }
    });
    glassPane.setOpaque(false);
    glassPane.setLayout(new GridBagLayout());

    JLabel spinner = new JLabel(resources.getIcon("loader.gif"));
    glassPane.add(spinner);
    setGlassPane(glassPane);
}

From source file:vacationscheduler.UpcomingReservations.java

public UpcomingReservations() {
    initComponents();//from w w  w. j  av a 2  s  .c  o m
    UpdateDataSet();
    makeTable("Select * From Reservations");

    ////////////////////////////////////////////////////////////////////////
    //              FIll Up Owner combo box
    ////////////////////////////////////////////////////////////////////////
    Vector<Owner> allOwners = OwnersFactory.getAllOwners();
    Vector<String> userNames = new Vector();
    userNames.add("");
    for (int i = 0; i < allOwners.size(); i++) {
        userNames.add(allOwners.get(i).getUserName());
    }

    Combobox_UserNameFilter.setModel(new DefaultComboBoxModel(userNames));

    ////////////////////////////////////////////////////////////////////////
    //              FIll Up Locations combo box
    ////////////////////////////////////////////////////////////////////////
    Vector<String> allResorts = new <String>Vector();
    allResorts.add("");
    allResorts.addAll(LocationsFactory.GetAllLocations());

    Set<String> uniqueResorts = new HashSet<String>();
    uniqueResorts.addAll(allResorts);

    ComboBox_ResortFilter.setModel(new DefaultComboBoxModel(uniqueResorts.toArray()));
    ComboBox_ResortFilter.setSelectedItem("");

    ////////////////////////////////////////////////////////////////////////
    //              FIll Up Upgrade Status combo box
    ////////////////////////////////////////////////////////////////////////
    Vector<String> allUpgradeStates = new <String>Vector();

    allUpgradeStates.add("");

    String queryToGetAllUpgradeStates = "Select Upgrade_Status from reservations";

    Connection con = RuthDBConnection.getConnection();
    try {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(queryToGetAllUpgradeStates);

        while (rs.next()) {
            allUpgradeStates.add(rs.getString("Upgrade_Status"));
        }
        con.close();

    } catch (Exception e) {
        System.out.println(e);

    }

    Set<String> uniqueUpgrades = new HashSet<String>();
    uniqueUpgrades.addAll(allUpgradeStates);

    ComboBox_UpgradeStateFilter.setModel(new DefaultComboBoxModel(uniqueUpgrades.toArray()));

    this.setVisible(true);
    jtable_upcomingReservations.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            int rowClicked = jtable_upcomingReservations.rowAtPoint(e.getPoint());
            String confirmationNumberClicked = reservations.get(rowClicked).getConfimationNumber();
            System.out.println("confirmation number = " + confirmationNumberClicked);
            new ReservationForm(confirmationNumberClicked);
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });

    updateUsingFilters();
}

From source file:eu.cassandra.csn.gui.CSN.java

/**
 * /*from w  ww .  j a v  a2  s.c  o m*/
 * @param graph
 * @return
 */
public static JPanel setUpView() {
    JPanel csnPanel = new JPanel();
    vv.getGraphLayout().setSize(new Dimension(csnPanel.getWidth(), csnPanel.getHeight()));
    setUpVV();
    GraphZoomScrollPane graphZoomScrollPane = new GraphZoomScrollPane(vv);
    JPanel thisPanel = new JPanel(new BorderLayout());
    thisPanel.add(graphZoomScrollPane, BorderLayout.CENTER);

    slider.setBackground(Color.WHITE);
    slider.setPreferredSize(new Dimension(210, 50));
    slider.setPaintTicks(true);
    slider.setMaximum(100);
    slider.setMinimum(0);
    slider.setValue(0);
    slider.setMajorTickSpacing(50);
    slider.setPaintLabels(true);
    slider.setPaintTicks(true);
    slider.setBorder(BorderFactory.createLineBorder(Color.black));
    slider.setEnabled(false);
    sliderLabel.setEnabled(false);
    slider.addMouseListener(new MouseListener() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (sliderLabel.getText().contains("oltage"))
                ClusterGraph.clusterAndRecolor(ClusterGraph.VoltageClusterer, slider.getValue());
            else if (sliderLabel.getText().contains("etweenness"))
                ClusterGraph.clusterAndRecolor(ClusterGraph.BetweennessClusterer, slider.getValue());
        }

        public void mouseClicked(MouseEvent arg0) {
        }

        public void mouseEntered(MouseEvent arg0) {
        }

        public void mouseExited(MouseEvent arg0) {
        }

        public void mousePressed(MouseEvent arg0) {
        }
    });
    JPanel p = new JPanel(new BorderLayout());
    p.add(sliderLabel, BorderLayout.PAGE_START);
    p.add(slider, BorderLayout.CENTER);

    sliderEdge.setBackground(Color.WHITE);
    sliderEdge.setPreferredSize(new Dimension(210, 50));
    sliderEdge.setPaintTicks(true);
    sliderEdge.setValue(0);
    sliderEdge.setMajorTickSpacing(5);
    sliderEdge.setPaintLabels(true);
    sliderEdge.setPaintTicks(true);
    sliderEdge.setBorder(BorderFactory.createLineBorder(Color.black));
    sliderEdge.setEnabled(false);
    sliderLabelEdge.setEnabled(false);
    sliderEdge.addMouseListener(new MouseListener() {
        @Override
        public void mouseReleased(MouseEvent e) {
            double v = Double
                    .parseDouble(((JLabel) sliderEdge.getLabelTable().get(sliderEdge.getValue())).getText());
            CSNGraph.addEdgesBasedOnKL(v);
        }

        public void mouseClicked(MouseEvent arg0) {
        }

        public void mouseEntered(MouseEvent arg0) {
        }

        public void mouseExited(MouseEvent arg0) {
        }

        public void mousePressed(MouseEvent arg0) {
        }
    });
    JPanel pEdge = new JPanel(new BorderLayout());
    pEdge.add(sliderLabelEdge, BorderLayout.PAGE_START);
    pEdge.add(sliderEdge, BorderLayout.CENTER);

    JPanel p2 = new JPanel(new BorderLayout());
    p2.add(pEdge, BorderLayout.PAGE_START);
    p2.add(p, BorderLayout.PAGE_END);

    thisPanel.add(p2, BorderLayout.PAGE_END);

    return thisPanel;
}

From source file:ca.sqlpower.swingui.object.VariablesPanel.java

/**
 * Default constructor for the variables panel.
 * @param variableHelper A helper that will be used in order to
 * resolve discover and resolve variables.
 * @param action An implementation of {@link VariableInserter} that 
 * gets called once the variable has been created. This action will be executed
 * on the Swing Event Dispatch Thread./*  w ww  . j  a v a 2s .c  om*/
 * @param varDefinition The default variable definition string.
 */
public VariablesPanel(SPVariableHelper variableHelper, VariableInserter action, String varDefinition) {
    this.variableHelper = variableHelper;
    this.action = action;

    this.generalLabel = new JLabel("General");
    this.generalLabel.setFont(this.generalLabel.getFont().deriveFont(Font.BOLD));

    this.pickerLabel = new JLabel("Pick a variable");
    this.varNameText = new JTextField();
    this.varNameText.setEditable(false);
    this.varNameText.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseClicked(MouseEvent e) {
            ShowPickerAction act = new ShowPickerAction();
            act.actionPerformed(null);
        }
    });
    this.varPicker = new JButton(new ShowPickerAction());

    this.optionsLabel = new JLabel("Options");
    this.optionsLabel.setFont(this.optionsLabel.getFont().deriveFont(Font.BOLD));

    this.varDefaultLabel = new JLabel("Default value");
    this.varDefaultText = new JTextField();
    this.varDefaultText.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    currentDefValue = varDefaultText.getText();
                    updateGUI();
                }
            });
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });

    this.varEditLabel = new JLabel("Customization");
    this.varEditText = new JTextField();
    this.varEditText.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    int carPos = varEditText.getCaretPosition();
                    String text = varEditText.getText().replace("$", "").replace("{", "").replace("}", "");
                    currentPickedVariable = SPVariableHelper.stripDefaultValue(text);
                    if (currentPickedVariable == null) {
                        currentPickedVariable = "";
                    }
                    currentDefValue = SPVariableHelper.getDefaultValue(text);
                    if (currentDefValue == null) {
                        currentDefValue = "";
                    }
                    if (SPVariableHelper.getNamespace(text) == null) {
                        namespaceBox.setSelected(false);
                    } else {
                        namespaceBox.setSelected(true);
                    }
                    updateGUI();
                    try {
                        varEditText.setCaretPosition(carPos);
                    } catch (IllegalArgumentException e) {
                        varEditText.setCaretPosition(carPos - 1);
                    }
                }
            });
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });

    this.namespaceLabel = new JLabel("Constrain to namespace");
    this.namespaceBox = new JCheckBox("");
    if (SPVariableHelper.getNamespace(varDefinition) != null || "".equals(varDefinition)) {
        this.namespaceBox.setSelected(true);
    } else {
        this.namespaceBox.setSelected(false);
    }
    this.namespaceBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateGUI();
        }
    });

    this.previewLabel = new JLabel("Preview");
    this.previewLabel.setFont(this.previewLabel.getFont().deriveFont(Font.BOLD));
    this.varPreviewLabel1 = new JLabel("Current value is");
    this.varPreviewLabel1.setForeground(Color.GRAY);
    this.varPreviewLabel2 = new JLabel();
    this.varPreviewLabel2.setForeground(Color.GRAY);

    this.panel = new JPanel(new MigLayout());

    this.panel.add(this.generalLabel, "growx, span, wrap");
    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.pickerLabel);
    this.panel.add(this.varNameText, "growx, wmin 275, wmax 275, gapright 0");
    this.panel.add(this.varPicker, "wmax 20, hmax 20, wrap, gapleft 0");

    this.panel.add(this.optionsLabel, "growx, span, wrap");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.varDefaultLabel);
    this.panel.add(this.varDefaultText, "span, wrap, wmin 300, wmax 300");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(namespaceLabel);
    this.panel.add(namespaceBox, "span, wrap");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.varEditLabel);
    this.panel.add(this.varEditText, "span, wmin 300, wmax 300, wrap");

    this.panel.add(this.previewLabel, "growx, span, wrap");

    this.panel.add(new JLabel(" "), "wmin 20, wmax 20");
    this.panel.add(this.varPreviewLabel1);
    this.panel.add(this.varPreviewLabel2, "span, growx");

    this.currentPickedVariable = varDefinition;
    updateGUI();
}