Example usage for javax.swing JButton setEnabled

List of usage examples for javax.swing JButton setEnabled

Introduction

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

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables (or disables) the button.

Usage

From source file:com.bwc.ora.OraUtils.java

/**
 * Create the anchor LRP. Does this by creating the LRP model and then adds
 * it to the LRP collections used by the application for storing LRPs for
 * analysis and display//from  w ww .  java 2s . co m
 *
 * @param assisted use fovea finding algorithm or manual click to identify
 *                 fovea
 */
public static void generateAnchorLrp(boolean assisted, JButton buttonToEnable) {
    OCTDisplayPanel octDisplayPanel = OCTDisplayPanel.getInstance();
    LrpSettings lrpSettings = ModelsCollection.getInstance().getLrpSettings();
    DisplaySettings displaySettings = ModelsCollection.getInstance().getDisplaySettings();

    if (assisted) {
        JOptionPane.showMessageDialog(null, "Click and drag a window on the OCT which\n"
                + "contains the foveal pit, some of the vitrious,\n"
                + "and some of the Bruch's membrane and choroid.\n"
                + "ORA will the place a LRP at what it believes is\n" + "the center of the foveal pit.\n" + "\n"
                + "Use the arrow keys to move the LRP if desired after placement.\n"
                + "If any setting are adjusted while in this mode\n"
                + "you'll have to click the mouse on the OCT to regain\n"
                + "the ability to move the LRP with the arrow keys.", "Draw foveal pit window",
                JOptionPane.INFORMATION_MESSAGE);

        //allow the user to select region on screen where fovea should be found
        OctWindowSelector octWindowSelector = ModelsCollection.getInstance().getOctWindowSelector();

        MouseInputAdapter selectorMouseListener = new MouseInputAdapter() {
            Point firstPoint = null;
            Point secondPoint = null;
            Point lastWindowPoint = null;

            @Override
            public void mousePressed(MouseEvent e) {
                Collections.getInstance().getOctDrawnLineCollection().clear();
                Collections.getInstance().getLrpCollection().clearLrps();
                if ((firstPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    octWindowSelector.setDisplay(true);
                    displaySettings.setDisplaySelectorWindow(true);
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                secondPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint());
                octWindowSelector.setDisplay(false);
                displaySettings.setDisplaySelectorWindow(false);
                octDisplayPanel.removeMouseListener(this);
                octDisplayPanel.removeMouseMotionListener(this);
                OctPolyLine ilm = ILMsegmenter.segmentILM(firstPoint,
                        secondPoint == null ? lastWindowPoint : secondPoint);
                Collections.getInstance().getOctDrawnLineCollection().add(ilm);
                //use ILM segmented line to find local minima and place LRP
                Point maxYPoint = ilm.stream().max(Comparator.comparingInt(p -> p.y)).orElse(ilm.get(0));
                int fovealCenterX = (int) Math.round(ilm.stream().filter(p -> p.y == maxYPoint.y)
                        .mapToInt(p -> p.x).average().getAsDouble());

                Lrp newLrp;
                try {
                    newLrp = new Lrp("Fovea", fovealCenterX, Oct.getInstance().getImageHeight() / 2,
                            lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.FOVEAL);
                    lrpCollection.setLrps(Arrays.asList(newLrp));
                    octDisplayPanel.removeMouseListener(this);
                    if (buttonToEnable != null) {
                        buttonToEnable.setEnabled(true);
                    }
                } catch (LRPBoundaryViolationException e1) {
                    JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.", "LRP generation error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                Point dragPoint;
                if ((dragPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    lastWindowPoint = dragPoint;
                    int minX = Math.min(firstPoint.x, dragPoint.x);
                    int minY = Math.min(firstPoint.y, dragPoint.y);
                    int width = Math.max(firstPoint.x, dragPoint.x) - minX;
                    int height = Math.max(firstPoint.y, dragPoint.y) - minY;
                    octWindowSelector.setRect(minX, minY, width, height);
                    displaySettings.setDisplaySelectorWindow(false);
                    displaySettings.setDisplaySelectorWindow(true);
                }
            }
        };

        octDisplayPanel.addMouseListener(selectorMouseListener);
        octDisplayPanel.addMouseMotionListener(selectorMouseListener);
    } else {
        JOptionPane.showMessageDialog(null,
                "Click on the OCT where the anchor LRP should go.\n" + "Use the arrow keys to move the LRP.\n"
                        + "If any setting are adjusted while in this mode\n"
                        + "you'll have to click the mouse on the OCT to regain\n"
                        + "the ability to move the LRP with the arrow keys.",
                "Click anchor point", JOptionPane.INFORMATION_MESSAGE);
        //listen for the location on the screen where the user clicks, create LRP at location
        octDisplayPanel.addMouseListener(new MouseInputAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                Point clickPoint;
                if ((clickPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    Lrp newLrp;
                    try {
                        newLrp = new Lrp("Fovea", clickPoint.x, clickPoint.y, lrpSettings.getLrpWidth(),
                                lrpSettings.getLrpHeight(), LrpType.FOVEAL);
                        lrpCollection.setLrps(Arrays.asList(newLrp));
                        octDisplayPanel.removeMouseListener(this);
                        if (buttonToEnable != null) {
                            buttonToEnable.setEnabled(true);
                        }
                    } catch (LRPBoundaryViolationException e1) {
                        JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.",
                                "LRP generation error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                }
            }
        });

    }
}

From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java

public PanelsPanel(JFrame frame, final PanelSave ps) {
    this.ps = ps;
    this.frame = frame;
    this.setSize(new Dimension(395, frame.getHeight() - 27 - 23));
    this.setLocation(300, 0);
    this.setBorder(BorderFactory.createTitledBorder("Edition du panneau"));

    JPanel content = new JPanel();
    JScrollPane scroll = new JScrollPane(content);
    scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    scroll.setBorder(null);//from  w ww .  j  a v  a2 s.  com
    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
    scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20));

    JPanel namePanel = new JPanel();
    name.setPreferredSize(new Dimension(this.getWidth() - 280, 30));
    name.setEditable(false);
    namePanel.add(new JLabel("Nom :"));
    namePanel.add(name);
    namePanel.add(Box.createRigidArea(new Dimension(10, 1)));
    layout.addItem("Basique");
    layout.addItem("Bordures");
    layout.addItem("Ligne");
    layout.addItem("Colonne");
    layout.addItem("Grille");
    layout.addItem("Empil");
    layout.setPreferredSize(new Dimension(110, 30));
    layout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            cl.show(advanced, listContent[combo.getSelectedIndex()]);
            ps.set("layout", combo.getSelectedIndex());
            ActionPanel.updateLists();
        }

    });
    namePanel.add(new JLabel("Disposition :"));
    namePanel.add(layout);
    namePanel.setPreferredSize(new Dimension(365, 50));
    namePanel.setMaximumSize(new Dimension(365, 50));
    content.add(namePanel);

    advanced.setPreferredSize(new Dimension(365, 300));
    advanced.setMaximumSize(new Dimension(365, 300));
    advanced.add(ble, listContent[0]);
    advanced.add(brdle, listContent[1]);
    advanced.add(lle, listContent[2]);
    advanced.add(rle, listContent[3]);
    advanced.add(gle, listContent[4]);
    advanced.add(cle, listContent[5]);

    content.add(advanced);

    topBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.top", combo.getSelectedItem());
        }

    });
    leftBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.left", combo.getSelectedItem());
        }

    });
    centerBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.center", combo.getSelectedItem());
        }

    });
    rightBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.right", combo.getSelectedItem());
        }

    });
    bottomBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            @SuppressWarnings("unchecked")
            JComboBox<String> combo = (JComboBox<String>) event.getSource();
            ps.set("border.bottom", combo.getSelectedItem());
        }

    });

    JPanel prefSize = new JPanel();
    prefSize.setPreferredSize(new Dimension(365, 110));
    prefSize.setMaximumSize(new Dimension(365, 110));
    prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre"));
    JPanel prefSizePanel = new JPanel();
    prefSizePanel.setLayout(new GridLayout(2, 4));
    prefSizePanel.setPreferredSize(new Dimension(300, 55));
    prefSizePanel.setMaximumSize(new Dimension(300, 55));
    prefSizePanel.add(prefSizeEnabled);
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel(""));
    prefSizePanel.add(new JLabel("(en pixels)"));
    prefSizePanel.add(new JLabel("Largeur :"));
    prefSizePanel.add(prefWidth);
    prefSizePanel.add(new JLabel("Hauteur :"));
    prefSizePanel.add(prefHeight);
    prefWidth.setEnabled(false);
    prefHeight.setEnabled(false);
    prefSizeEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            ps.set("preferredSize", check.isSelected());
            prefWidth.setEnabled(check.isSelected());
            prefHeight.setEnabled(check.isSelected());
        }
    });
    prefWidth.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredWidth", spinner.getValue());
        }
    });
    prefHeight.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("preferredHeight", spinner.getValue());
        }
    });
    prefSize.add(prefSizePanel);

    content.add(prefSize);

    JPanel insetsPanel = new JPanel();
    insetsPanel.setBorder(BorderFactory.createTitledBorder("carts"));
    insetsPanel.setPreferredSize(new Dimension(365, 100));
    insetsPanel.setMaximumSize(new Dimension(365, 100));

    JPanel insetsContent = new JPanel();
    insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS));

    JPanel insetInput = new JPanel();
    insetInput.setLayout(new GridLayout(2, 4));
    insetInput.add(insetsEnabled);
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel(""));
    insetInput.add(new JLabel("(en pixels)"));
    insetInput.add(new JLabel("Horizontaux :"));
    insetInput.add(insetHz);
    insetInput.add(new JLabel("Verticaux :"));
    insetInput.add(insetVt);

    insetsEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JCheckBox check = (JCheckBox) event.getSource();
            if (check.isSelected()) {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", true);
            } else {
                insetHz.setEnabled(true);
                insetVt.setEnabled(true);
                ps.set("insets", false);
            }
        }

    });

    insetHz.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.horizontal", spinner.getValue());
        }
    });
    insetVt.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JSpinner spinner = (JSpinner) event.getSource();
            ps.set("insets.vertical", spinner.getValue());
        }
    });

    insetsContent.add(insetInput);
    insetsPanel.add(insetsContent);

    content.add(insetsPanel);

    JPanel web = new JPanel();
    web.setPreferredSize(new Dimension(365, 100));
    web.setMaximumSize(new Dimension(365, 100));
    web.setBorder(BorderFactory.createTitledBorder("Page Web"));

    JPanel webContent = new JPanel();
    webContent.setLayout(new BorderLayout());
    webContent.add(webEnabled, BorderLayout.NORTH);
    webEnabled.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("web", check.isSelected());
            if (check.isSelected() == true) {
                layout.setSelectedIndex(0);
                layout.setEnabled(false);
                ble.removeAllComponents();
                ble.disableComponents();
                adress.setEnabled(true);
            } else {
                ble.enableComponents();
                layout.setEnabled(true);
                adress.setEnabled(false);
            }
        }
    });
    JPanel webInput = new JPanel();
    webInput.add(new JLabel("Adresse :"));
    adress.setPreferredSize(new Dimension(250, 30));
    CaretListener caretUpdate = new CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent e) {
            JTextField text = (JTextField) e.getSource();
            ps.set("web.adress", text.getText());
        }
    };
    adress.addCaretListener(caretUpdate);
    webInput.add(adress);
    webContent.add(webInput, BorderLayout.CENTER);

    web.add(webContent);

    JPanel background = new JPanel();
    BorderLayout bLayout = new BorderLayout();
    bLayout.setVgap(12);
    background.setLayout(bLayout);
    background.setBorder(BorderFactory.createTitledBorder("Couleur de fond"));
    background.setPreferredSize(new Dimension(365, 210));
    background.setMaximumSize(new Dimension(365, 210));
    cp.setPreferredSize(new Dimension(347, 145));
    cp.setMaximumSize(new Dimension(347, 145));
    opaque.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox check = (JCheckBox) e.getSource();
            ps.set("background.opaque", check.isSelected());
            cp.enableComponents(check.isSelected());
        }
    });
    background.add(opaque, BorderLayout.NORTH);
    background.add(cp, BorderLayout.CENTER);

    JPanel image = new JPanel();
    image.setBorder(BorderFactory.createTitledBorder("Image de fond"));
    image.setPreferredSize(new Dimension(365, 125));
    image.setMaximumSize(new Dimension(365, 125));
    image.setLayout(new BorderLayout());
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.setEnabled(false);
    remove.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            File img = new File(
                    "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png");
            if (img.exists()) {
                img.delete();
            }
            browseImage.setEnabled(true);
        }

    });
    JPanel top = new JPanel();
    browseImage.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JButton button = (JButton) e.getSource();
            String path = null;
            JFileChooser chooser = new JFileChooser(Editor.lastPath);
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg",
                    "bmp");
            chooser.setFileFilter(filter);
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int option = chooser.showOpenDialog(null);
            if (option == JFileChooser.APPROVE_OPTION) {
                path = chooser.getSelectedFile().getAbsolutePath();
                Editor.lastPath = chooser.getSelectedFile().getParent();
                copyImage(new File(path), "background.png");
                nameBackground.setText(new File(path).getName());
                ps.set("background.image", new File(path).getName());
                button.setEnabled(false);
                size.setEnabled(true);
                size2.setEnabled(true);
                remove.setEnabled(true);
            }
        }

    });
    bg.add(size);
    bg.add(size2);
    JPanel sizePanel = new JPanel();
    sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS));
    size.setEnabled(false);
    size2.setEnabled(false);
    sizePanel.add(size);
    sizePanel.add(size2);
    size.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 0);
        }

    });
    size2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            ps.set("background.size", 1);
        }

    });
    top.add(browseImage);
    top.add(sizePanel);

    remove.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png")
                    .delete();
            nameBackground.setText("");
            ps.set("background.image", "");
            button.setEnabled(false);
        }

    });
    nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15));
    JPanel center = new JPanel(new BorderLayout());
    center.add(nameBackground, BorderLayout.CENTER);
    center.add(remove, BorderLayout.EAST);

    image.add(top, BorderLayout.NORTH);
    image.add(center, BorderLayout.CENTER);

    content.add(web);
    content.add(background);
    content.add(image);

    this.add(scroll);
}

From source file:fi.hoski.remote.ui.Admin.java

private void editReservations(final EventType eventType) {
    final Event event = chooseEvent(eventType, "CHOOSE");
    if (event != null) {
        final String eventTitle = TextUtil.getText(event.getEventType().name()) + " "
                + event.get(Event.EventDate);
        safeTitle = frame.getTitle();//from w  ww  . j  a v  a2  s  .co m
        frame.setTitle(eventTitle);
        reservationList = dss.getReservations(event);
        selectedReservations = new ArrayList<Reservation>();
        unSelectedReservations = new ArrayList<Reservation>();
        if (Event.isInspection(eventType)) {
            for (Reservation reservation : reservationList) {
                Boolean inspected = (Boolean) reservation.get(Reservation.INSPECTED);
                if (inspected != null && inspected) {
                    selectedReservations.add(reservation);
                } else {
                    unSelectedReservations.add(reservation);
                }
            }
        } else {
            for (Reservation reservation : reservationList) {
                Long order = (Long) reservation.get(Reservation.ORDER);
                if (order != null && order != 0) {
                    selectedReservations.add(reservation);
                } else {
                    unSelectedReservations.add(reservation);
                }
            }
        }
        DataObjectModel baseModel = Reservation.getModel(eventType);
        DataObjectModel unorderedModel = null;
        DataObjectModel orderedModel = null;
        switch (eventType) {
        case LAUNCH:
        case LIFT:
        case HULL_INSPECTION:
            unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR);
            orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR);
            break;
        case INSPECTION:
            unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR,
                    Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER,
                    Reservation.INSPECTION_GASS, Reservation.INSPECTOR);
            orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR,
                    Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER,
                    Reservation.NOTES);
            break;
        }

        final DataObjectListTableModel<Reservation> unorderedTableModel = new DataObjectListTableModel<Reservation>(
                unorderedModel, unSelectedReservations);
        final JTable unorderedtable = new FitTable(unorderedTableModel);
        TableSelectionHandler tsh1 = new TableSelectionHandler(unorderedtable);
        unorderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer());
        unorderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer());

        unorderedtable.addKeyListener(unorderedTableModel.getRemover(dss));
        unorderedtable.setDragEnabled(true);
        unorderedtable.setDropMode(DropMode.INSERT_ROWS);
        TransferHandler unorderedTransferHandler = new DataObjectTransferHandler<Reservation>(
                unorderedTableModel);
        unorderedtable.setTransferHandler(unorderedTransferHandler);

        final DataObjectListTableModel<Reservation> orderedTableModel = new DataObjectListTableModel<Reservation>(
                orderedModel, selectedReservations);
        orderedTableModel.setEditable(Reservation.INSPECTION_CLASS, Reservation.INSPECTION_GASS,
                Reservation.BASICINSPECTION, Reservation.INSPECTOR);
        final JTable orderedtable = new FitTable(orderedTableModel);
        TableSelectionHandler tsh2 = new TableSelectionHandler(orderedtable);
        orderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer());
        orderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer());

        orderedtable.addKeyListener(orderedTableModel.getRemover(dss));
        orderedtable.setDragEnabled(true);
        orderedtable.setDropMode(DropMode.INSERT_ROWS);
        TransferHandler orderedTransferHandler = new DataObjectTransferHandler<Reservation>(orderedTableModel);
        orderedtable.setTransferHandler(orderedTransferHandler);
        if (Event.isInspection(eventType)) {
            unorderedtable.setAutoCreateRowSorter(true);
            orderedtable.setAutoCreateRowSorter(true);
        }
        leftPane = new JScrollPane();
        leftPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-leftPane")));
        leftPane.setViewportView(unorderedtable);
        leftPane.setTransferHandler(unorderedTransferHandler);

        rightPane = new JScrollPane();
        rightPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-rightPane")));
        rightPane.setViewportView(orderedtable);
        rightPane.setTransferHandler(orderedTransferHandler);

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane);
        splitPane.setDividerLocation(0.5);
        menuReservation.setEnabled(false);
        safeContainer = frame.getContentPane();
        JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.add(splitPane, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());
        contentPane.add(buttonPanel, BorderLayout.SOUTH);

        JButton saveButton = new JButton();
        TextUtil.populate(saveButton, "SAVE");
        saveButton.setEnabled(!Event.isInspection(eventType));
        ActionListener saveAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                saveReservations();
            }
        };
        saveButton.addActionListener(saveAction);
        buttonPanel.add(saveButton);

        switch (eventType) {
        case INSPECTION: {
            if (privileged) {
                JButton inspectButton = new JButton();
                TextUtil.populate(inspectButton, "SET INSPECTED");
                ActionListener inspectAction = new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        TableCellEditor cellEditor = orderedtable.getCellEditor();
                        if (cellEditor != null) {
                            cellEditor.stopCellEditing();
                        }
                        try {
                            setAsInspected();
                        } catch (SQLException | ClassNotFoundException ex) {
                            ex.printStackTrace();
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                        }
                    }
                };
                inspectButton.addActionListener(inspectAction);
                buttonPanel.add(inspectButton);
            }

            JButton addBoat = new JButton();
            TextUtil.populate(addBoat, "ADD BOAT");
            ActionListener addBoatAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Reservation reservation = reservate(eventType, event);
                    if (reservation != null) {
                        reservationList.add(reservation);
                        unSelectedReservations.add(reservation);
                        unorderedTableModel.fireTableDataChanged();
                    }
                }
            };
            addBoat.addActionListener(addBoatAction);
            buttonPanel.add(addBoat);

            JButton printTypeButton = new JButton();
            TextUtil.populate(printTypeButton, "PRINT");
            ActionListener printTypeAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printNameBoatTypeOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printTypeButton.addActionListener(printTypeAction);
            buttonPanel.add(printTypeButton);

            JButton printDockButton = new JButton();
            TextUtil.populate(printDockButton, "PRINT DOCK ORDER");
            ActionListener printDockAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printDockOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printDockButton.addActionListener(printDockAction);
            buttonPanel.add(printDockButton);

        }
            break;
        case HULL_INSPECTION: {
            JButton print = new JButton();
            TextUtil.populate(print, "PRINT");
            ActionListener printAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printAlphaOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            print.addActionListener(printAction);
            buttonPanel.add(print);

        }
            break;
        case LAUNCH:
        case LIFT: {
            JButton addBoat = new JButton();
            TextUtil.populate(addBoat, "ADD BOAT");
            ActionListener addBoatAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Reservation reservation = reservate(eventType, event);
                    if (reservation != null) {
                        reservationList.add(reservation);
                        unSelectedReservations.add(reservation);
                        unorderedTableModel.fireTableDataChanged();
                    }
                }
            };
            addBoat.addActionListener(addBoatAction);
            buttonPanel.add(addBoat);

            JButton printBrief = new JButton();
            TextUtil.populate(printBrief, "BRIEF PRINT");
            ActionListener printBriefAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printOrderBrief(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printBrief.addActionListener(printBriefAction);
            buttonPanel.add(printBrief);

            JButton print = new JButton();
            TextUtil.populate(print, "PRINT");
            ActionListener printAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        if (eventType == EventType.LAUNCH) {
                            printLaunchOrder(eventTitle);
                        } else {
                            printLiftOrder(eventTitle);
                        }
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            print.addActionListener(printAction);
            buttonPanel.add(print);
        }
            break;
        }

        JButton cancelButton = new JButton();
        TextUtil.populate(cancelButton, "CANCEL");
        ActionListener cancelAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        };
        cancelButton.addActionListener(cancelAction);
        buttonPanel.add(cancelButton);

        frame.setContentPane(contentPane);
        frame.pack();
        frame.setVisible(true);
        KeyListener keyListener = new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == 10) {
                    int selectedRow = unorderedtable.getSelectedRow();
                    if (selectedRow != -1) {
                        RowSorter<? extends TableModel> rowSorter = unorderedtable.getRowSorter();
                        if (rowSorter != null) {
                            selectedRow = rowSorter.convertRowIndexToModel(selectedRow);
                        }
                        Reservation reservation = unorderedTableModel.getObject(selectedRow);
                        orderedTableModel.add(reservation);
                        unorderedTableModel.remove(reservation);
                        e.consume();
                        unorderedtable.changeSelection(selectedRow, 0, false, false);
                    }
                }
            }
        };
        unorderedtable.addKeyListener(keyListener);
        unorderedtable.requestFocusInWindow();
    }
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Shows the About dialog./*w ww.j  a  v a2 s. c o  m*/
 */
public void doAbout() {
    AppContextMgr acm = AppContextMgr.getInstance();
    boolean showDetailedAbout = acm.hasContext() && acm.getClassObject(Division.class) != null
            && acm.getClassObject(Discipline.class) != null && acm.getClassObject(Collection.class) != null;

    int baseNumRows = 14;
    String serverName = AppPreferences.getLocalPrefs().get("login.servers_selected", null);
    if (serverName != null) {
        baseNumRows++;
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder infoPB = new PanelBuilder(new FormLayout("p,6px,f:p:g",
            "p,4px,p,4px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", baseNumRows)));

    JLabel iconLabel = new JLabel(IconManager.getIcon("SpecifyLargeIcon"), SwingConstants.CENTER); //$NON-NLS-1$
    PanelBuilder iconPB = new PanelBuilder(new FormLayout("p", "20px,t:p,f:p:g"));
    iconPB.add(iconLabel, cc.xy(1, 2));

    if (showDetailedAbout) {
        final ArrayList<String> values = new ArrayList<String>();

        DBTableIdMgr tableMgr = DBTableIdMgr.getInstance();
        boolean hasReged = !RegisterSpecify.isAnonymous() && RegisterSpecify.hasInstitutionRegistered();

        int y = 1;
        infoPB.addSeparator(getResourceString("Specify.SYS_INFO"), cc.xyw(1, y, 3));
        y += 2;

        JLabel lbl = UIHelper.createLabel(databaseName);
        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.DB"), cc.xy(1, y));
        addLabel(values, infoPB, lbl, cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openLocalPrefs();
                }
            }
        });

        int instId = Institution.getClassTableId();
        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(instId)), cc.xy(1, y));
        addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Institution.class).getName()),
                cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(instId)), cc.xy(1, y));

        String noGUID = "<No GUID>";
        String guidStr = acm.getClassObject(Institution.class).getGuid();
        addLabel(values, infoPB, lbl = UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y));
        y += 2;

        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openRemotePrefs();
                }
            }
        });
        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Division.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Division.class).getName()),
                cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openGlobalPrefs();
                }
            }
        });

        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Discipline.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Discipline.class).getName()),
                cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Collection.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Collection.class).getCollectionName()),
                cc.xy(3, y));
        y += 2;
        addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(Collection.getClassTableId())),
                cc.xy(1, y));

        guidStr = acm.getClassObject(Collection.class).getGuid();
        addLabel(values, infoPB, UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y));
        y += 2;
        //addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        //addLabel(values, infoPB, UIHelper.createLabel(appBuildVersion),cc.xy(3, y)); y += 2;

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        UIRegistry.loadAndPushResourceBundle("bld");
        addLabel(values, infoPB, UIHelper.createLabel(getResourceString("build")), cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD_TM"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(getResourceString("buildtime")), cc.xy(3, y));
        y += 2;
        UIRegistry.popResourceBundle();

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.REG"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createI18NLabel(hasReged ? "Specify.HASREG" : "Specify.NOTREG"),
                cc.xy(3, y));
        y += 2;

        String isaNumber = RegisterSpecify.getISANumber();
        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.ISANUM"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(isaNumber) ? isaNumber : ""),
                cc.xy(3, y));
        y += 2;

        if (serverName != null) {
            addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.SERVER"), cc.xy(1, y));
            addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(serverName) ? serverName : ""),
                    cc.xy(3, y));
            y += 2;
        }

        if (StringUtils.contains(DBConnection.getInstance().getConnectionStr(), "mysql")) {
            Vector<Object[]> list = BasicSQLUtils.query("select version() as ve");
            if (list != null && list.size() > 0) {
                addLabel(values, infoPB, UIHelper.createFormLabel("MySQL Version"), cc.xy(1, y));
                addLabel(values, infoPB, UIHelper.createLabel(list.get(0)[0].toString()), cc.xy(3, y));
                y += 2;
            }
        }

        addLabel(values, infoPB, UIHelper.createFormLabel("Java Version"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(System.getProperty("java.version")), cc.xy(3, y));
        y += 2;

        JButton copyCBBtn = createIconBtn("ClipboardCopy", IconManager.IconSize.Std24, "Specify.CPY_ABT_TO_TT",
                null);
        //copyCBBtn.setBackground(Color.WHITE);
        //copyCBBtn.setOpaque(true);
        //copyCBBtn.setBorder(BorderFactory.createEtchedBorder());

        copyCBBtn.setEnabled(true);

        PanelBuilder cbPB = new PanelBuilder(new FormLayout("f:p:g,p", "p"));
        cbPB.add(copyCBBtn, cc.xy(2, 1));
        copyCBBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Copy to Clipboard
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < values.size(); i++) {
                    sb.append(String.format("%s = %s\n", values.get(i), values.get(i + 1)));
                    i++;
                }
                UIHelper.setTextToClipboard(sb.toString());
                UIRegistry.displayInfoMsgDlgLocalized("Specify.CPY_ABT_TO_MSG");
            }
        });
        infoPB.add(cbPB.getPanel(), cc.xy(3, y));
        y += 2;
    }

    String txt = getAboutText(appName, appVersion);
    JLabel txtLbl = createLabel(txt);
    txtLbl.setFont(UIRegistry.getDefaultFont());

    final JEditorPane txtPane = new JEditorPane("text/html", txt);
    txtPane.setEditable(false);
    txtPane.setBackground(new JPanel().getBackground());

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,20px,f:min(400px;p):g,10px,8px,10px,p:g", "f:p:g"));

    pb.add(iconPB.getPanel(), cc.xy(1, 1));
    pb.add(txtPane, cc.xy(3, 1));
    Color bg = getBackground();

    if (showDetailedAbout) {
        pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xy(5, 1));
        pb.add(infoPB.getPanel(), cc.xy(7, 1));
    }

    pb.setDefaultDialogBorder();

    String title = getResourceString("Specify.ABOUT");//$NON-NLS-1$
    CustomDialog aboutDlg = new CustomDialog(topFrame, title + " " + appName, true, CustomDialog.OK_BTN, //$NON-NLS-1$
            pb.getPanel());
    String okLabel = getResourceString("Specify.CLOSE");//$NON-NLS-1$
    aboutDlg.setOkLabel(okLabel);

    aboutDlg.createUI();
    aboutDlg.pack();

    // for some strange reason I can't get the dialog to size itself correctly
    Dimension size = aboutDlg.getSize();
    size.height += 120;
    aboutDlg.setSize(size);

    txtPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    AttachmentUtils.openURI(event.getURL().toURI());

                } catch (Exception e) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                }
            }
        }
    });

    UIHelper.centerAndShow(aboutDlg);
}

From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java

/**
 * Displays a dialog used for editing the Master Username and Password.
 * @param isLocal whether u/p is stored locally or not
 * @param usrName/*from  w  ww . j  ava 2 s  .  com*/
 * @param dbName
 * @param masterPath the path to the password
 * @return whether to ask for the information because it wasn't found
 */
protected boolean askForInfo(final Boolean isLocal, final String usrName, final String dbName,
        final String masterPath) {
    loadAndPushResourceBundle("masterusrpwd");

    FormLayout layout = new FormLayout("p, 2px, f:p:g, 4px, p, 4px, p, 4px, p", "p,2px,p,2px,p,2dlu,p,2dlu,p");

    PanelBuilder pb = new PanelBuilder(layout);
    pb.setDefaultDialogBorder();

    ButtonGroup group = new ButtonGroup();
    final JRadioButton isNetworkRB = new JRadioButton(getResourceString("IS_NET_BASED"));
    final JRadioButton isPrefBasedRB = new JRadioButton(getResourceString("IS_ENCRYPTED_KEY"));
    isPrefBasedRB.setSelected(true);
    group.add(isNetworkRB);
    group.add(isPrefBasedRB);

    final JTextField keyTxt = createTextField(35);
    final JTextField urlTxt = createTextField(35);
    final JLabel keyLbl = createI18NFormLabel("ENCRYPTED_USRPWD");
    final JLabel urlLbl = createI18NFormLabel("URL");
    final JButton createBtn = createI18NButton("CREATE_KEY");

    final JButton copyCBBtn = createIconBtn("ClipboardCopy", IconManager.IconSize.Std24, "CPY_TO_CB_TT", null);
    final JButton pasteCBBtn = createIconBtn("ClipboardPaste", IconManager.IconSize.Std24, "CPY_FROM_CB_TT",
            null);

    // retrieves the encrypted key for the current settings in the dialog
    String dbNameFromForm = AppPreferences.getLocalPrefs().get("login.databases_selected", null);
    if (isNotEmpty(dbNameFromForm) && isNotEmpty(usersUserName)) {
        String masterKey = getMasterPrefPath(usersUserName, dbNameFromForm, true);
        if (isNotEmpty(masterKey)) {
            String encryptedKey = AppPreferences.getLocalPrefs().get(masterKey, null);
            if (isNotEmpty(encryptedKey) && !encryptedKey.startsWith("http")) {
                keyTxt.setText(encryptedKey);
            }
        }
    }

    CellConstraints cc = new CellConstraints();

    int y = 1;
    pb.add(createI18NFormLabel("MASTER_LOC"), cc.xywh(1, y, 1, 3));
    pb.add(isPrefBasedRB, cc.xy(3, y));
    y += 2;
    pb.add(isNetworkRB, cc.xy(3, y));
    y += 2;

    pb.addSeparator("", cc.xyw(1, y, 9));
    y += 2;
    pb.add(keyLbl, cc.xy(1, y));
    pb.add(keyTxt, cc.xy(3, y));
    pb.add(createBtn, cc.xy(5, y));
    pb.add(copyCBBtn, cc.xy(7, y));
    pb.add(pasteCBBtn, cc.xy(9, y));
    y += 2;

    pb.add(urlLbl, cc.xy(1, y));
    pb.add(urlTxt, cc.xy(3, y));
    y += 2;

    boolean isEditMode = isLocal != null && isNotEmpty(masterPath);
    if (isEditMode) {
        isPrefBasedRB.setSelected(isLocal);
        if (isLocal) {
            keyTxt.setText(masterPath);
        } else {
            urlTxt.setText(masterPath);
        }
    }

    copyCBBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Copy to Clipboard
            UIHelper.setTextToClipboard(keyTxt.getText());
        }
    });

    pasteCBBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            keyTxt.setText(UIHelper.getTextFromClipboard());
        }
    });

    final CustomDialog dlg = new CustomDialog((Frame) null, getResourceString("MASTER_TITLE"), true,
            CustomDialog.OKCANCELHELP, pb.getPanel());
    if (!isEditMode) {
        dlg.setOkLabel(getResourceString("CONT"));
        dlg.setCancelLabel(getResourceString("BACK"));
    }
    dlg.setHelpContext("MASTERPWD_MAIN");
    dlg.createUI();
    dlg.getOkBtn().setEnabled(false);
    urlLbl.setEnabled(false);
    urlTxt.setEnabled(false);
    copyCBBtn.setEnabled(true);
    pasteCBBtn.setEnabled(true);

    DocumentListener dl = new DocumentAdaptor() {
        @Override
        protected void changed(DocumentEvent e) {
            dlg.getOkBtn().setEnabled((isPrefBasedRB.isSelected() && !keyTxt.getText().isEmpty())
                    || (isNetworkRB.isSelected() && !urlTxt.getText().isEmpty()));
        }
    };
    keyTxt.getDocument().addDocumentListener(dl);
    urlTxt.getDocument().addDocumentListener(dl);

    ChangeListener chgListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            boolean isNet = isNetworkRB.isSelected();
            keyLbl.setEnabled(!isNet);
            keyTxt.setEnabled(!isNet);
            createBtn.setEnabled(!isNet);
            copyCBBtn.setEnabled(!isNet);
            pasteCBBtn.setEnabled(!isNet);
            urlLbl.setEnabled(isNet);
            urlTxt.setEnabled(isNet);
            dlg.getOkBtn().setEnabled((isPrefBasedRB.isSelected() && !keyTxt.getText().isEmpty())
                    || (isNetworkRB.isSelected() && !urlTxt.getText().isEmpty()));
        }
    };

    isNetworkRB.addChangeListener(chgListener);
    isPrefBasedRB.addChangeListener(chgListener);

    boolean isPref = AppPreferences.getLocalPrefs().getBoolean(getIsLocalPrefPath(usrName, dbName, true), true);
    isNetworkRB.setSelected(!isPref);
    isPrefBasedRB.setSelected(isPref);

    createBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String[] keys = getUserNamePasswordKey();
            if (keys != null && keys.length == 4) {
                String encryptedStr = encrypt(keys[0], keys[1], keys[3]);
                if (encryptedStr != null) {
                    keyTxt.setText(encryptedStr);
                    dlg.getOkBtn().setEnabled(true);

                    usersUserName = keys[2];
                }
            }
        }
    });

    popResourceBundle();

    dlg.setVisible(true);

    if (!dlg.isCancelled()) {
        String value;
        if (isNetworkRB.isSelected()) {
            value = StringEscapeUtils.escapeHtml(urlTxt.getText());
        } else {
            value = keyTxt.getText();
        }

        AppPreferences.getLocalPrefs().putBoolean(getIsLocalPrefPath(usrName, dbName, true),
                !isNetworkRB.isSelected());
        AppPreferences.getLocalPrefs().put(getMasterPrefPath(usrName, dbName, true), value);
        return true;
    }
    return false;
}

From source file:au.org.ala.delta.intkey.Intkey.java

private void updateDynamicButtons() {
    for (JButton b : _advancedModeOnlyDynamicButtons) {
        b.setVisible(_advancedMode);/*from   ww w  .ja v  a 2  s.  c o  m*/
    }

    for (JButton b : _normalModeOnlyDynamicButtons) {
        b.setVisible(!_advancedMode);
    }

    for (JButton b : _activeOnlyWhenCharactersUsedButtons) {
        if (_usedCharacterListModel != null) {
            b.setEnabled(_usedCharacterListModel.size() > 0);
        } else {
            b.setEnabled(false);
        }
    }

    _rootPanel.revalidate();
}

From source file:edu.ku.brc.specify.config.init.secwiz.DatabasePanel.java

/**
 * Creates a dialog for entering database name and selecting the appropriate driver.
 *///from   ww  w  . j a  va  2s .  c  o m
public DatabasePanel(final JButton nextBtn, final JButton prevBtn, final String helpContext,
        final boolean doSetDefaultValues) {
    super("DATABASE", helpContext, nextBtn, prevBtn);

    this.doSetDefaultValues = doSetDefaultValues;

    String header = getResourceString("ENTER_DB_INFO") + ":";

    CellConstraints cc = new CellConstraints();

    String rowDef = "p,2px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", isMobile() ? 5 : 4)
            + ",10px,p,10px,p,4px,p,4px,p,10px,f:p:g";
    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p:g", rowDef), this);
    int row = 1;

    builder.add(createLabel(header, SwingConstants.CENTER), cc.xywh(1, row, 3, 1));
    row += 2;

    usernameTxt = createField(builder, "IT_USERNAME", true, row);
    row += 2;
    passwordTxt = createField(builder, "IT_PASSWORD", true, row, true, null);
    row += 2;
    if (isMobile()) {
        dbNameTxt = createField(builder, "DB_NAME", true, row);
        row += 2;
    } else {
        dbNameTxt = createTextField();
    }
    hostNameTxt = createField(builder, "HOST_NAME", true, row);
    row += 2;

    driverList = DatabaseDriverInfo.getDriversList();
    drivers = createComboBox(driverList);

    // MySQL as the default
    drivers.setSelectedItem(DatabaseDriverInfo.getDriver("MySQL"));

    JLabel lbl = createI18NFormLabel("DRIVER", SwingConstants.RIGHT);
    lbl.setFont(bold);
    builder.add(lbl, cc.xy(1, row));
    builder.add(drivers, cc.xy(3, row));
    row += 2;

    label = UIHelper.createLabel("", SwingConstants.CENTER);

    PanelBuilder panelPB = new PanelBuilder(new FormLayout("f:p:g", "20px,p,8px,p"));
    panelPB.add(getProgressBar(), cc.xy(1, 2));
    panelPB.add(label, cc.xy(1, 4));

    builder.add(panelPB.getPanel(), cc.xy(3, row));
    row += 2;

    //panelPB.getPanel().setBackground(Color.RED);
    //setBackground(Color.GREEN);

    // Advance part of pane
    advLabel = UIHelper.createI18NLabel("SEC_ADV_MU_DESC", SwingConstants.CENTER);
    skipStepBtn = UIHelper.createI18NButton("ADV_DB_TEST");
    builder.add(advLabel, cc.xyw(3, row, 1));
    row += 2;

    PanelBuilder tstPB = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g", "p"));
    tstPB.add(skipStepBtn, cc.xy(2, 1));
    builder.add(tstPB.getPanel(), cc.xyw(3, row, 1));
    row += 2;

    JComponent helpComponent = createHelpPanel(getBackground(), "database");
    builder.add(helpComponent, cc.xyw(3, row, 1));
    row += 2;

    skipStepBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            skipStepBtn.setEnabled(false);
            boolean ok = skipDBCreate();

            if (ok) {
                ok = checkForPermissions();
            }

            isOK = ok;
            skipStepBtn.setEnabled(true);
            advLabel.setText(getResourceString(ok ? "ADV_DB_OK" : "ADV_DB_ERR"));
            advLabel.setForeground(ok ? Color.BLACK : Color.RED);
            nextBtn.setEnabled(isOK);
        }
    });

    if (isMobile()) {
        skipStepBtn.setVisible(false);
        advLabel.setVisible(false);
    }

    progressBar.setVisible(false);

    updateBtnUI();
}

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

/**
 * Creates an icon button with tooltip and action listener.
 * @param iconName the name of the icon (use default size)
 * @param toolTipTextKey the tooltip text resource bundle key
 * @param al the action listener/*from  w  w  w. j a  v a 2 s  .c  om*/
 * @param withEmptyBorder set an empyt border
 * @return the JButton icon button
 */
public static JButton createIconBtn(final String iconName, final IconManager.IconSize size,
        final String toolTipTextKey, final boolean withEmptyBorder, final Action action) {
    JButton btn = new JButton(action) {
        @Override
        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            setBorder(emptyBorder);
        }
    };

    btn.setOpaque(false);
    if (!withEmptyBorder) {
        btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(focusBorder);
                }
                super.mouseEntered(e);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(emptyBorder);
                }
                super.mouseExited(e);
            }

        });
        btn.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(focusBorder);
                }
            }

            public void focusLost(FocusEvent e) {
                if (((JButton) e.getSource()).isEnabled()) {
                    ((JButton) e.getSource()).setBorder(emptyBorder);
                }
            }

        });
        btn.setBorder(emptyBorder);
    }
    btn.setIcon(size != null ? IconManager.getIcon(iconName, size) : IconManager.getIcon(iconName));
    btn.setText(null);
    if (StringUtils.isNotEmpty(toolTipTextKey)) {
        btn.setToolTipText(getResourceString(toolTipTextKey));
    }
    btn.setEnabled(false);

    btn.setFocusable(true);
    btn.setMargin(new Insets(0, 0, 0, 0));
    setControlSize(btn);
    return btn;
}

From source file:com.awesomecoding.minetestlauncher.Main.java

private void initialize() {
    fileGetter = new FileGetter(userhome + "\\minetest\\temp\\");
    latest = fileGetter.getContents("http://socialmelder.com/minetest/latest.txt", true);
    currentVersion = latest.split("\n")[0];
    changelog = fileGetter.getContents("http://socialmelder.com/minetest/changelog.html", false);

    try {//from w ww .ja  v  a  2  s . co  m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    frmMinetestLauncherV = new JFrame();
    frmMinetestLauncherV.setResizable(false);
    frmMinetestLauncherV.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(Main.class.getResource("/com/awesomecoding/minetestlauncher/icon.png")));
    frmMinetestLauncherV.setTitle("Minetest Launcher (Version 0.1)");
    frmMinetestLauncherV.setBounds(100, 100, 720, 480);
    frmMinetestLauncherV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout springLayout = new SpringLayout();
    frmMinetestLauncherV.getContentPane().setLayout(springLayout);

    final JProgressBar progressBar = new JProgressBar();
    springLayout.putConstraint(SpringLayout.WEST, progressBar, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, progressBar, -10, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, progressBar, -130, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(progressBar);

    final JButton btnDownloadPlay = new JButton("Play!");
    springLayout.putConstraint(SpringLayout.WEST, btnDownloadPlay, 6, SpringLayout.EAST, progressBar);
    springLayout.putConstraint(SpringLayout.SOUTH, btnDownloadPlay, 0, SpringLayout.SOUTH, progressBar);
    springLayout.putConstraint(SpringLayout.EAST, btnDownloadPlay, -10, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(btnDownloadPlay);

    final JLabel label = new JLabel("Ready to play!");
    springLayout.putConstraint(SpringLayout.WEST, label, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, btnDownloadPlay, 0, SpringLayout.NORTH, label);
    springLayout.putConstraint(SpringLayout.SOUTH, label, -37, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, progressBar, 6, SpringLayout.SOUTH, label);
    frmMinetestLauncherV.getContentPane().add(label);

    JTextPane txtpnNewFeatures = new JTextPane();
    txtpnNewFeatures.setBackground(SystemColor.window);
    springLayout.putConstraint(SpringLayout.NORTH, txtpnNewFeatures, 10, SpringLayout.NORTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, txtpnNewFeatures, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, txtpnNewFeatures, -10, SpringLayout.NORTH, btnDownloadPlay);
    springLayout.putConstraint(SpringLayout.EAST, txtpnNewFeatures, 0, SpringLayout.EAST, btnDownloadPlay);
    txtpnNewFeatures.setEditable(false);
    txtpnNewFeatures.setContentType("text/html");
    txtpnNewFeatures.setText(changelog);
    txtpnNewFeatures.setFont(new Font("Tahoma", Font.PLAIN, 12));
    frmMinetestLauncherV.getContentPane().add(txtpnNewFeatures);

    File file = new File(userhome + "\\minetest\\version.txt");

    if (!file.exists())
        newVersion = true;
    else {
        String version = fileGetter.getLocalContents(file, false);
        if (!version.equals(currentVersion))
            newVersion = true;
    }

    if (newVersion) {
        label.setText("New Version Available! (" + currentVersion + ")");
        btnDownloadPlay.setText("Download & Play");

        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                Thread t = new Thread() {
                    public void run() {
                        File file = new File(userhome + "\\minetest\\version.txt");
                        String version = fileGetter.getLocalContents(file, false);
                        try {
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\minetest-" + version));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        fileGetter.download(latest.split("\n")[1], userhome + "\\minetest\\temp\\",
                                "minetest.zip", label, progressBar, btnDownloadPlay, currentVersion);
                        try {
                            label.setText("Cleaning up...");
                            btnDownloadPlay.setText("Cleaning up...");
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\temp"));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.exit(0);
                    }
                };
                t.start();
            }
        });
    } else {
        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                try {
                    label.setText("Launching...");
                    btnDownloadPlay.setEnabled(false);
                    btnDownloadPlay.setText("Launching...");
                    File file = new File(userhome + "\\minetest\\version.txt");
                    String version = fileGetter.getLocalContents(file, false);
                    Runtime.getRuntime()
                            .exec(userhome + "\\minetest\\minetest-" + version + "\\bin\\minetest.exe");
                    System.exit(0);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        progressBar.setValue(100);
    }
}

From source file:eu.apenet.dpt.standalone.gui.eaccpf.EacCpfDescriptionPanel.java

/**
 * Functions add further part with a button.
 *///from  w  w  w. j a va 2 s .c  om
private PanelBuilder buildButtonAddFurtherAddressDetails(PanelBuilder builder, CellConstraints cc,
        Integer index, boolean filled) {
    JButton addAddressDetails = new ButtonTab(
            this.labels.getString("eaccpf.description.button.addaddressdetails"));
    addAddressDetails.addActionListener(
            new AddFurtherAddressAndComponentButton(this.eaccpf, this.tabbedPane, this.model, index));
    addAddressDetails.setEnabled(filled);
    this.addPlaceEntryAddressDetailsButton(addAddressDetails);
    builder.add(addAddressDetails, cc.xy(1, rowNb));
    setNextRow();
    return builder;
}