Search in sources :

Example 66 with EtchedBorder

use of javax.swing.border.EtchedBorder in project freeplane by freeplane.

the class AddAttributeAction method getPanel.

/**
 * This method creates the input dialog
 *
 * @return : the input dialog
 */
private JPanel getPanel() {
    final JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.setBorder(new EtchedBorder());
    final GridBagConstraints gridBagConstraints = new GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.CENTER;
    gridBagConstraints.insets = new Insets(20, 10, 2, 10);
    // Size of JComboBoxes
    final String pattern = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    final JLabel patternLabel = new JLabel(pattern);
    final Dimension comboBoxMaximumSize = patternLabel.getPreferredSize();
    comboBoxMaximumSize.width += 4;
    comboBoxMaximumSize.height += 10;
    // Label: name
    final JLabel nameLabel = new JLabel(TextUtils.getText("attribute_name"));
    panel.add(nameLabel, gridBagConstraints);
    gridBagConstraints.gridx++;
    // Label: value
    final JLabel valueLabel = new JLabel(TextUtils.getText("attribute_value"));
    panel.add(valueLabel, gridBagConstraints);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy++;
    // Attribute name combo-box
    gridBagConstraints.insets = new Insets(2, 10, 20, 10);
    attributeNames = new JComboBoxWithBorder();
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    final ComboBoxModel names = attributes.getComboBoxModel();
    attributeNames.setModel(new ClonedComboBoxModel(names));
    attributeNames.setEditable(true);
    attributeNames.setMaximumSize(comboBoxMaximumSize);
    attributeNames.setPreferredSize(comboBoxMaximumSize);
    attributeNames.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            selectedAttributeChanged(e.getItem(), attributeValues);
        }
    });
    panel.add(attributeNames, gridBagConstraints);
    // Attribute value combo-box
    attributeValues = new JComboBoxWithBorder();
    attributeValues.setRenderer(new TypedListCellRenderer());
    attributeValues.setMaximumSize(comboBoxMaximumSize);
    attributeValues.setPreferredSize(comboBoxMaximumSize);
    gridBagConstraints.gridx++;
    panel.add(attributeValues, gridBagConstraints);
    // set focus to attributeNames
    panel.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            final Component component = e.getComponent();
            if (component.isShowing()) {
                attributeNames.requestFocus();
                component.removeHierarchyListener(this);
            }
        }
    });
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) MapModel(org.freeplane.features.map.MapModel) HierarchyListener(java.awt.event.HierarchyListener) EtchedBorder(javax.swing.border.EtchedBorder) TypedListCellRenderer(org.freeplane.core.ui.components.TypedListCellRenderer) AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) HierarchyEvent(java.awt.event.HierarchyEvent) ItemListener(java.awt.event.ItemListener) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) JComboBoxWithBorder(org.freeplane.core.ui.components.JComboBoxWithBorder) Component(java.awt.Component) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel)

Example 67 with EtchedBorder

use of javax.swing.border.EtchedBorder in project bacter by tgvaughan.

the class ACGAnnotator method getOptionsGUI.

/**
 * Use a GUI to retrieve ACGAnnotator options.
 *
 * @param options options object to populate using GUI
 * @return true if options successfully collected, false otherwise
 */
private static boolean getOptionsGUI(ACGAnnotatorOptions options) {
    boolean[] canceled = { false };
    JDialog dialog = new JDialog((JDialog) null, true);
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.setLocationRelativeTo(null);
    dialog.setTitle("ACGAnnotator");
    JLabel logFileLabel = new JLabel("ACG log file:");
    JLabel outFileLabel = new JLabel("Output file:");
    JLabel burninLabel = new JLabel("Burn-in percentage:");
    JLabel summaryMethodLabel = new JLabel("Position summary method:");
    JLabel thresholdLabel = new JLabel("Posterior conversion support threshold:");
    JCheckBox geneFlowCheckBox = new JCheckBox("Record gene flow");
    JTextField inFilename = new JTextField(20);
    inFilename.setEditable(false);
    JButton inFileButton = new JButton("Choose File");
    JTextField outFilename = new JTextField(20);
    outFilename.setText(options.outFile.getName());
    outFilename.setEditable(false);
    JButton outFileButton = new JButton("Choose File");
    JTextField gfOutFilename = new JTextField(20);
    gfOutFilename.setText(options.geneFlowOutFile.getName());
    gfOutFilename.setEditable(false);
    gfOutFilename.setEnabled(false);
    JButton gfOutFileButton = new JButton("Choose File");
    gfOutFileButton.setEnabled(false);
    JSlider burninSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, (int) (options.burninPercentage));
    burninSlider.setMajorTickSpacing(50);
    burninSlider.setMinorTickSpacing(10);
    burninSlider.setPaintTicks(true);
    burninSlider.setPaintLabels(true);
    burninSlider.setSnapToTicks(true);
    JComboBox<SummaryStrategy> heightMethodCombo = new JComboBox<>(SummaryStrategy.values());
    JSlider thresholdSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, (int) (options.convSupportThresh));
    thresholdSlider.setMajorTickSpacing(50);
    thresholdSlider.setMinorTickSpacing(10);
    thresholdSlider.setPaintTicks(true);
    thresholdSlider.setPaintLabels(true);
    thresholdSlider.setSnapToTicks(true);
    Container cp = dialog.getContentPane();
    BoxLayout boxLayout = new BoxLayout(cp, BoxLayout.PAGE_AXIS);
    cp.setLayout(boxLayout);
    JPanel mainPanel = new JPanel();
    GroupLayout layout = new GroupLayout(mainPanel);
    mainPanel.setLayout(layout);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup().addComponent(logFileLabel).addComponent(outFileLabel).addComponent(burninLabel).addComponent(summaryMethodLabel).addComponent(thresholdLabel).addComponent(geneFlowCheckBox)).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false).addComponent(inFilename).addComponent(outFilename).addComponent(burninSlider).addComponent(heightMethodCombo).addComponent(thresholdSlider).addComponent(gfOutFilename)).addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false).addComponent(inFileButton).addComponent(outFileButton).addComponent(gfOutFileButton)));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup().addComponent(logFileLabel).addComponent(inFilename, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(inFileButton)).addGroup(layout.createParallelGroup().addComponent(outFileLabel).addComponent(outFilename, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(outFileButton)).addGroup(layout.createParallelGroup().addComponent(burninLabel).addComponent(burninSlider, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(layout.createParallelGroup().addComponent(summaryMethodLabel).addComponent(heightMethodCombo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(layout.createParallelGroup().addComponent(thresholdLabel).addComponent(thresholdSlider, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGroup(layout.createParallelGroup().addComponent(geneFlowCheckBox).addComponent(gfOutFilename).addComponent(gfOutFileButton)));
    mainPanel.setBorder(new EtchedBorder());
    cp.add(mainPanel);
    JPanel buttonPanel = new JPanel();
    JButton runButton = new JButton("Analyze");
    runButton.addActionListener((e) -> {
        options.burninPercentage = burninSlider.getValue();
        options.convSupportThresh = thresholdSlider.getValue();
        options.summaryStrategy = (SummaryStrategy) heightMethodCombo.getSelectedItem();
        options.recordGeneFlow = geneFlowCheckBox.isSelected();
        dialog.setVisible(false);
    });
    runButton.setEnabled(false);
    buttonPanel.add(runButton);
    JButton cancelButton = new JButton("Quit");
    cancelButton.addActionListener((e) -> {
        dialog.setVisible(false);
        canceled[0] = true;
    });
    buttonPanel.add(cancelButton);
    JFileChooser inFileChooser = new JFileChooser();
    inFileButton.addActionListener(e -> {
        inFileChooser.setDialogTitle("Select ACG log file to summarize");
        if (options.inFile == null)
            inFileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        int returnVal = inFileChooser.showOpenDialog(dialog);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            options.inFile = inFileChooser.getSelectedFile();
            inFilename.setText(inFileChooser.getSelectedFile().getName());
            runButton.setEnabled(true);
        }
    });
    JFileChooser outFileChooser = new JFileChooser();
    outFileButton.addActionListener(e -> {
        outFileChooser.setDialogTitle("Select output file name.");
        if (options.inFile != null)
            outFileChooser.setCurrentDirectory(options.inFile);
        else
            outFileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        outFileChooser.setSelectedFile(options.outFile);
        int returnVal = outFileChooser.showOpenDialog(dialog);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            options.outFile = outFileChooser.getSelectedFile();
            outFilename.setText(outFileChooser.getSelectedFile().getName());
        }
    });
    geneFlowCheckBox.addActionListener(e -> {
        boolean newValue = geneFlowCheckBox.isSelected();
        gfOutFilename.setEnabled(newValue);
        gfOutFileButton.setEnabled(newValue);
    });
    JFileChooser gfOutFileChooser = new JFileChooser();
    gfOutFileButton.addActionListener(e -> {
        gfOutFileChooser.setDialogTitle("Select gene flow output file name.");
        if (options.inFile != null)
            gfOutFileChooser.setCurrentDirectory(options.inFile);
        else
            gfOutFileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
        gfOutFileChooser.setSelectedFile(options.geneFlowOutFile);
        int returnVal = gfOutFileChooser.showOpenDialog(dialog);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            options.geneFlowOutFile = gfOutFileChooser.getSelectedFile();
            gfOutFilename.setText(gfOutFileChooser.getSelectedFile().getName());
        }
    });
    cp.add(buttonPanel);
    dialog.pack();
    dialog.setResizable(false);
    dialog.setVisible(true);
    return !canceled[0];
}
Also used : EtchedBorder(javax.swing.border.EtchedBorder)

Example 68 with EtchedBorder

use of javax.swing.border.EtchedBorder in project MultiTypeTree by tgvaughan.

the class MigrationModelInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption bExpandOption, boolean bAddButtons) {
    // Set up fields
    m_bAddButtons = bAddButtons;
    m_input = input;
    m_beastObject = beastObject;
    this.itemNr = itemNr;
    // Adds label to left of input editor
    addInputLabel();
    // Create component models and fill them with data from input
    migModel = (SCMigrationModel) input.get();
    fullTypeListModel = new DefaultListModel<>();
    additionalTypeListModel = new DefaultListModel<>();
    popSizeModel = new DefaultTableModel();
    rateMatrixModel = new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return row != column && column != migModel.getNTypes();
        }
    };
    popSizeEstCheckBox = new JCheckBox("estimate pop. sizes");
    rateMatrixEstCheckBox = new JCheckBox("estimate mig. rates");
    popSizeScaleFactorEstCheckBox = new JCheckBox("estimate scale factor");
    rateMatrixScaleFactorEstCheckBox = new JCheckBox("estimate scale factor");
    loadFromMigrationModel();
    JPanel panel = new JPanel(new GridBagLayout());
    panel.setBorder(new EtchedBorder());
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(3, 3, 3, 3);
    c.weighty = 0.5;
    // Type list:
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.0;
    c.anchor = GridBagConstraints.LINE_END;
    panel.add(new JLabel("<html><body>Type list:</body></html>"), c);
    JList<String> jlist;
    Box tlBox = Box.createHorizontalBox();
    Box tlBoxLeft = Box.createVerticalBox();
    JLabel labelLeft = new JLabel("All types");
    tlBoxLeft.add(labelLeft);
    jlist = new JList<>(fullTypeListModel);
    jlist.setSelectionModel(new DefaultListSelectionModel() {

        @Override
        public void setSelectionInterval(int index0, int index1) {
            super.setSelectionInterval(-1, -1);
        }
    });
    JScrollPane listScrollPane = new JScrollPane(jlist);
    listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    tlBoxLeft.add(listScrollPane);
    tlBox.add(tlBoxLeft);
    Box tlBoxRight = Box.createVerticalBox();
    JLabel labelRight = new JLabel("Additional types");
    tlBoxRight.add(labelRight);
    jlist = new JList<>(additionalTypeListModel);
    additionalTypeListSelectionModel = jlist.getSelectionModel();
    listScrollPane = new JScrollPane(jlist);
    listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    tlBoxRight.add(listScrollPane);
    Box addRemBox = Box.createHorizontalBox();
    addTypeButton = new JButton("+");
    remTypeButton = new JButton("-");
    remTypeButton.setEnabled(false);
    addTypesFromFileButton = new JButton("Add from file...");
    addRemBox.add(addTypeButton);
    addRemBox.add(remTypeButton);
    addRemBox.add(addTypesFromFileButton);
    tlBoxRight.add(addRemBox);
    tlBox.add(tlBoxRight);
    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.LINE_START;
    panel.add(tlBox, c);
    // Population size table
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0.0;
    c.anchor = GridBagConstraints.LINE_END;
    Box psBox = Box.createVerticalBox();
    psBox.add(new JLabel("Population sizes: "), c);
    loadPopSizesFromFileButton = new JButton("Load from file...");
    psBox.add(loadPopSizesFromFileButton);
    panel.add(psBox, c);
    JTable popSizeTable = new JTable(popSizeModel) {

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            return new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    setHorizontalAlignment(SwingConstants.CENTER);
                    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            };
        }
    };
    popSizeTable.setShowVerticalLines(true);
    popSizeTable.setCellSelectionEnabled(true);
    popSizeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    popSizeTable.setMaximumSize(new Dimension(100, Short.MAX_VALUE));
    c.gridx = 1;
    c.gridy = 1;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.LINE_START;
    panel.add(popSizeTable, c);
    popSizeEstCheckBox.setSelected(((RealParameter) migModel.popSizesInput.get()).isEstimatedInput.get());
    popSizeScaleFactorEstCheckBox.setSelected(((RealParameter) migModel.popSizesScaleFactorInput.get()).isEstimatedInput.get());
    c.gridx = 2;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 1.0;
    Box estBox = Box.createVerticalBox();
    estBox.add(popSizeEstCheckBox);
    estBox.add(popSizeScaleFactorEstCheckBox);
    panel.add(estBox, c);
    // Migration rate table
    // (Uses custom cell renderer to grey out diagonal elements.)
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 0.0;
    c.anchor = GridBagConstraints.LINE_END;
    Box mrBox = Box.createVerticalBox();
    mrBox.add(new JLabel("Migration rates: "), c);
    loadMigRatesFromFileButton = new JButton("Load from file...");
    mrBox.add(loadMigRatesFromFileButton);
    panel.add(mrBox, c);
    JTable rateMatrixTable = new JTable(rateMatrixModel) {

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            return new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    if (row == column) {
                        JLabel label = new JLabel();
                        label.setOpaque(true);
                        label.setBackground(Color.GRAY);
                        return label;
                    } else {
                        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                        if (column == migModel.getNTypes()) {
                            c.setBackground(panel.getBackground());
                            c.setForeground(Color.gray);
                            setHorizontalAlignment(SwingConstants.LEFT);
                        } else {
                            int l = 1, r = 1, t = 1, b = 1;
                            if (column > 0)
                                l = 0;
                            if (row > 0)
                                t = 0;
                            setBorder(BorderFactory.createMatteBorder(t, l, b, r, Color.GRAY));
                            setHorizontalAlignment(SwingConstants.CENTER);
                        }
                        return c;
                    }
                }
            };
        }
    };
    rateMatrixTable.setShowGrid(false);
    rateMatrixTable.setIntercellSpacing(new Dimension(0, 0));
    rateMatrixTable.setCellSelectionEnabled(true);
    rateMatrixTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    rateMatrixTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableColumn col = rateMatrixTable.getColumnModel().getColumn(migModel.getNTypes());
    FontMetrics metrics = new Canvas().getFontMetrics(getFont());
    int maxWidth = 0;
    for (String rowName : rowNames) maxWidth = Math.max(maxWidth, metrics.stringWidth(rowName + "M"));
    col.setPreferredWidth(maxWidth);
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 1.0;
    panel.add(rateMatrixTable, c);
    rateMatrixEstCheckBox.setSelected(((RealParameter) migModel.rateMatrixInput.get()).isEstimatedInput.get());
    rateMatrixScaleFactorEstCheckBox.setSelected(((RealParameter) migModel.rateMatrixScaleFactorInput.get()).isEstimatedInput.get());
    c.gridx = 2;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 1.0;
    estBox = Box.createVerticalBox();
    estBox.add(rateMatrixEstCheckBox);
    estBox.add(rateMatrixScaleFactorEstCheckBox);
    panel.add(estBox, c);
    c.gridx = 1;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 1.0;
    panel.add(new JLabel("Rows: sources, columns: sinks (backwards in time)"), c);
    c.gridx = 1;
    c.gridy = 4;
    c.anchor = GridBagConstraints.LINE_START;
    c.weightx = 1.0;
    JLabel multilineLabel = new JLabel();
    multilineLabel.setText("<html><body>Correspondence between row/col indices<br>" + "and deme names shown to right of matrix.</body></html>");
    panel.add(multilineLabel, c);
    add(panel);
    // Event handlers
    popSizeModel.addTableModelListener(e -> {
        if (e.getType() != TableModelEvent.UPDATE)
            return;
        if (!fileLoadInProgress)
            saveToMigrationModel();
    });
    popSizeEstCheckBox.addItemListener(e -> saveToMigrationModel());
    popSizeScaleFactorEstCheckBox.addItemListener(e -> saveToMigrationModel());
    rateMatrixModel.addTableModelListener(e -> {
        if (e.getType() != TableModelEvent.UPDATE)
            return;
        if (!fileLoadInProgress)
            saveToMigrationModel();
    });
    rateMatrixEstCheckBox.addItemListener(e -> saveToMigrationModel());
    rateMatrixScaleFactorEstCheckBox.addItemListener(e -> saveToMigrationModel());
    addTypeButton.addActionListener(e -> {
        String newTypeName = JOptionPane.showInputDialog("Name of type");
        if (newTypeName != null) {
            if (migModel.getTypeSet().containsTypeWithName(newTypeName)) {
                JOptionPane.showMessageDialog(panel, "Type with this name already present.", "Error", JOptionPane.ERROR_MESSAGE);
            } else {
                additionalTypeListModel.add(additionalTypeListModel.size(), newTypeName);
                saveToMigrationModel();
            }
        }
    });
    addTypesFromFileButton.addActionListener(e -> {
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Choose file containing type names (one per line)");
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        int result = fc.showDialog(panel, "Load");
        if (result == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (!line.isEmpty())
                        additionalTypeListModel.add(additionalTypeListModel.size(), line);
                }
                saveToMigrationModel();
            } catch (IOException e1) {
                JOptionPane.showMessageDialog(panel, "Error reading from file: " + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    additionalTypeListSelectionModel.addListSelectionListener(e -> {
        if (additionalTypeListSelectionModel.getMinSelectionIndex() < 0)
            remTypeButton.setEnabled(false);
        else
            remTypeButton.setEnabled(true);
    });
    remTypeButton.addActionListener(e -> {
        int selectionMin = additionalTypeListSelectionModel.getMinSelectionIndex();
        int selectionMax = additionalTypeListSelectionModel.getMaxSelectionIndex();
        additionalTypeListModel.removeRange(selectionMin, selectionMax);
        additionalTypeListSelectionModel.clearSelection();
        saveToMigrationModel();
    });
    loadPopSizesFromFileButton.addActionListener(e -> {
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Choose file containing population sizes (one per line)");
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        int result = fc.showDialog(panel, "Load");
        if (result == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                List<Double> popSizes = new ArrayList<>();
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (!line.isEmpty())
                        popSizes.add(Double.parseDouble(line));
                }
                if (popSizes.size() == migModel.getNTypes()) {
                    fileLoadInProgress = true;
                    for (int i = 0; i < popSizes.size(); i++) popSizeModel.setValueAt(popSizes.get(i), 0, i);
                    fileLoadInProgress = false;
                    saveToMigrationModel();
                } else {
                    JOptionPane.showMessageDialog(panel, "<html>File must contain exactly one population<br> size for each type/deme.</html>", "Error", JOptionPane.ERROR_MESSAGE);
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(panel, "Error reading from file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            } catch (NumberFormatException ex) {
                JOptionPane.showMessageDialog(panel, "<html>File contains non-numeric line. " + "Every line must contain<br> exactly one population size.</html>", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    loadMigRatesFromFileButton.addActionListener(e -> {
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle("Choose CSV file containing migration rate matrix (diagonal ignored)");
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        int result = fc.showDialog(panel, "Load");
        if (result == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
                List<Double> migRates = new ArrayList<>();
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    for (String field : line.split(",")) {
                        if (!field.isEmpty())
                            migRates.add(Double.parseDouble(field));
                    }
                }
                boolean diagonalsPresent = (migRates.size() == migModel.getNTypes() * migModel.getNTypes());
                if (diagonalsPresent || migRates.size() == migModel.getNTypes() * (migModel.getNTypes() - 1)) {
                    fileLoadInProgress = true;
                    for (int i = 0; i < migModel.getNTypes(); i++) {
                        for (int j = 0; j < migModel.getNTypes(); j++) {
                            if (i == j)
                                continue;
                            int offset;
                            if (diagonalsPresent)
                                offset = i * migModel.getNTypes() + j;
                            else {
                                offset = i * (migModel.getNTypes() - 1) + j;
                                if (j > i)
                                    offset -= 1;
                            }
                            rateMatrixModel.setValueAt(migRates.get(offset), i, j);
                        }
                    }
                    fileLoadInProgress = false;
                    saveToMigrationModel();
                } else {
                    JOptionPane.showMessageDialog(panel, "<html>CSV file must contain a square matrix with exactly one<br>" + "row for each type/deme.</html>", "Error", JOptionPane.ERROR_MESSAGE);
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(panel, "Error reading from file: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            } catch (NumberFormatException ex) {
                JOptionPane.showMessageDialog(panel, "<html>CSV file contains non-numeric element.</html", "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ArrayList(java.util.ArrayList) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) RealParameter(beast.core.parameter.RealParameter) TableColumn(javax.swing.table.TableColumn) EtchedBorder(javax.swing.border.EtchedBorder)

Example 69 with EtchedBorder

use of javax.swing.border.EtchedBorder in project beast2 by CompEvol.

the class TaxonSetDialog method createCancelOKButtons.

// createTaxonSelector
Component createCancelOKButtons() {
    Box cancelOkBox = Box.createHorizontalBox();
    cancelOkBox.setBorder(new EtchedBorder());
    JButton okButton = new JButton("Ok");
    okButton.setName("OK");
    okButton.addActionListener(e -> {
        taxonSet.setID(id);
        List<Taxon> taxa = taxonSet.taxonsetInput.get();
        while (taxa.size() > 0) {
            taxa.remove(0);
        }
        for (int i = 0; i < listModel2.size(); i++) {
            taxa.add(listModel2.get(i));
        }
        isOK = true;
        dispose();
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.setName("Cancel");
    cancelButton.addActionListener(e -> {
        dispose();
    });
    cancelOkBox.add(Box.createHorizontalGlue());
    cancelOkBox.add(okButton);
    cancelOkBox.add(Box.createHorizontalGlue());
    cancelOkBox.add(cancelButton);
    cancelOkBox.add(Box.createHorizontalGlue());
    return cancelOkBox;
}
Also used : EtchedBorder(javax.swing.border.EtchedBorder) Taxon(beast.evolution.alignment.Taxon) JButton(javax.swing.JButton) Box(javax.swing.Box)

Example 70 with EtchedBorder

use of javax.swing.border.EtchedBorder in project GenericKnimeNodes by genericworkflownodes.

the class ParameterDialog method createHeader.

private void createHeader() {
    // use JPanel to be able to create a border
    headerpanel = new JPanel();
    headerpanel.setLayout(new BorderLayout());
    TitledBorder b = new TitledBorder(new EtchedBorder(), "Please cite:");
    b.setTitleFont(MAND_FONT);
    headerpanel.setBorder(b);
    headerpanel.setPreferredSize(new Dimension(table.getWidth(), 50));
    // fill the Panel with a non-editable HTML TextPane
    header = new JTextPane();
    header.setContentType("text/html");
    header.setEditable(false);
    header.addHyperlinkListener(new HyperlinkListener() {

        // Open Desktop browser when clicking links (e.g. dois)
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (URISyntaxException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            }
        }
    });
    headerpanel.add(new JScrollPane(header));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextPane(javax.swing.JTextPane) EtchedBorder(javax.swing.border.EtchedBorder) HyperlinkEvent(javax.swing.event.HyperlinkEvent) BorderLayout(java.awt.BorderLayout) HyperlinkListener(javax.swing.event.HyperlinkListener) Dimension(java.awt.Dimension) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TitledBorder(javax.swing.border.TitledBorder)

Aggregations

EtchedBorder (javax.swing.border.EtchedBorder)116 JPanel (javax.swing.JPanel)92 JButton (javax.swing.JButton)74 JLabel (javax.swing.JLabel)74 ActionEvent (java.awt.event.ActionEvent)73 BorderLayout (java.awt.BorderLayout)72 ActionListener (java.awt.event.ActionListener)70 EmptyBorder (javax.swing.border.EmptyBorder)63 CompoundBorder (javax.swing.border.CompoundBorder)62 AbstractAction (javax.swing.AbstractAction)58 WindowAdapter (java.awt.event.WindowAdapter)55 WindowEvent (java.awt.event.WindowEvent)55 Insets (java.awt.Insets)46 GridBagConstraints (java.awt.GridBagConstraints)43 GridBagLayout (java.awt.GridBagLayout)43 JTextField (javax.swing.JTextField)40 Dimension (java.awt.Dimension)24 TitledBorder (javax.swing.border.TitledBorder)22 FlowLayout (java.awt.FlowLayout)18 JScrollPane (javax.swing.JScrollPane)17