Example usage for javax.swing JButton getText

List of usage examples for javax.swing JButton getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the button's text.

Usage

From source file:net.itransformers.topologyviewer.dialogs.snmpDiscovery.DiscoveryManagerDialogV2.java

public DiscoveryManagerDialogV2(JFrame frame, File projectDir) {
    this.frame = frame;
    this.projectDir = projectDir;
    setTitle("Discovery Manager");
    setBounds(100, 100, 960, 364);/*from   w  ww. j a va2  s. com*/
    getContentPane().setLayout(new BorderLayout());
    {

        JPanel buttonPane = new JPanel();
        getContentPane().add(buttonPane, BorderLayout.NORTH);
        {
            buttonPane.setLayout(new BorderLayout(0, 0));
            {
                JPanel panel = new JPanel();
                buttonPane.add(panel);
                panel.setLayout(null);
                {
                    depthComboBox = new JComboBox();
                    depthComboBox.setModel(
                            new DefaultComboBoxModel(new Integer[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }));
                    depthComboBox.setBounds(46, 11, 70, 20);
                    panel.add(depthComboBox);
                }

                JLabel lblMode = new JLabel("Depth:");
                lblMode.setBounds(6, 14, 46, 14);
                panel.add(lblMode);

                JLabel lblAddress = new JLabel("Address:");
                lblAddress.setBounds(172, 14, 56, 14);
                panel.add(lblAddress);

                addressTextField = new JTextField();
                addressTextField.setBounds(230, 11, 113, 20);
                panel.add(addressTextField);
                addressTextField.setColumns(10);

                JLabel lblLabel = new JLabel("Label:");
                lblLabel.setBounds(360, 14, 56, 14);
                panel.add(lblLabel);

                labelTextField = new JTextField();
                labelTextField.setBounds(400, 11, 113, 20);
                panel.add(labelTextField);
                labelTextField.setColumns(10);

                autoLabelCheckBox = new JCheckBox("auto-label");
                autoLabelCheckBox.setBounds(520, 11, 113, 20);
                autoLabelCheckBox.setSelected(true);
                panel.add(autoLabelCheckBox);
                postDiscoveryCheckBox = new JCheckBox("Post Discovery");
                postDiscoveryCheckBox.setBounds(620, 11, 153, 20);
                postDiscoveryCheckBox.setSelected(true);
                panel.add(postDiscoveryCheckBox);

            }
        }
        {
            JPanel panel = new JPanel();
            buttonPane.add(panel, BorderLayout.EAST);
            final JButton stopStartButton = new JButton("Start");
            panel.add(stopStartButton);
            stopStartButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    if ("Start".equals(stopStartButton.getText())) {
                        onStartDiscoveryPre(stopStartButton);
                        onStartDiscovery();
                        onStartDiscoveryPost(stopStartButton);
                    } else {
                        onStopDiscoveryPre(stopStartButton);
                        onStopDiscovery();
                        onStopDiscoveryPost(stopStartButton);

                    }
                }
            });
            stopStartButton.setActionCommand("Start");
            getRootPane().setDefaultButton(stopStartButton);
            {
                pauseResumeButton.setEnabled(false);
                panel.add(pauseResumeButton);
                pauseResumeButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if ("Pause".equals(pauseResumeButton.getText())) {
                            pauseResumeButton.setEnabled(false);
                            onPauseDiscovery();
                            pauseResumeButton.setText("Resume");
                            pauseResumeButton.setEnabled(true);
                        } else {
                            pauseResumeButton.setEnabled(false);
                            onResumeDiscovery();
                            pauseResumeButton.setText("Pause");
                            pauseResumeButton.setEnabled(true);
                        }
                    }
                });
            }
        }
    }
    {
        lblDiscoveredDevices = new JTextArea();
        JScrollPane scrolltxt = new JScrollPane(lblDiscoveredDevices);
        lblDiscoveredDevices.append("Discovery process output");
        getContentPane().add(scrolltxt, BorderLayout.CENTER);
    }
    {
        JPanel statusPanel = new JPanel();
        getContentPane().add(statusPanel, BorderLayout.SOUTH);
        statusPanel.setLayout(new BorderLayout(0, 0));
        {
            JPanel panel = new JPanel();
            statusPanel.add(panel);
            panel.setLayout(new BorderLayout(0, 0));
            //panel.setSize(100:100);
            {
                loggerConsole = new JTextArea();
                JScrollPane scrolltxt = new JScrollPane(loggerConsole);
                loggerConsole.append("Discovery logger console");
                panel.add(scrolltxt, BorderLayout.CENTER);
            }
        }
    }
    {
        Logger logger = Logger.getRootLogger();
        logger.setLevel(Level.INFO);
        logger.addAppender(new AppenderSkeleton() {
            @Override
            protected void append(final LoggingEvent loggingEvent) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        loggerConsole.append(loggingEvent.getMessage().toString());
                        loggerConsole.append("\n");
                    }
                });
            }

            @Override
            public void close() {
            }

            @Override
            public boolean requiresLayout() {
                return false;
            }
        });
    }
}

From source file:fungus.JungVisualizer.java

public JungVisualizer(String name) {
    this.name = name;

    showEdges = Configuration.getBoolean(name + "." + PAR_SHOW_EDGES);
    scaleShapes = Configuration.getBoolean(name + "." + PAR_SCALE_SHAPES);
    labelNodes = Configuration.getBoolean(name + "." + PAR_LABEL_NODES);
    imageDir = Configuration.getString(name + "." + PAR_IMAGE_DIR);
    nameFragment = Configuration.getString(PAR_TESTNAME);

    if (vt == null) {
        try {/* ww  w  . j  a  v  a2s  .co  m*/
            Class vtClass = Configuration.getClass(name + "." + PAR_TRANSFORMERS);
            if (VisualizerTransformers.class.isAssignableFrom(vtClass)) {
                vt = (VisualizerTransformers) vtClass.newInstance();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    graph = JungGraphObserver.getGraph();

    vt.setGraph(graph); // Have to call this manually!

    JungGraphObserver.stepBlocked = true;
    JungGraphObserver.noBlock = false;

    layout = vt.makeLayout(graph);

    Dimension preferredSize = new Dimension(660, 660);
    visualizationModel = new DefaultVisualizationModel<MycoNode, MycoEdge>(layout, preferredSize);

    relaxer = visualizationModel.getRelaxer();

    visualizer = new VisualizationViewer<MycoNode, MycoEdge>(visualizationModel, preferredSize);
    visualizer.addGraphMouseListener(new InfoFrameVertexListener());

    visualizer.setDoubleBuffered(true);

    // final Color under50VertexColor = Color.BLACK;
    // final Stroke under50VertexStroke = new BasicStroke(1.0f,
    //                                                    BasicStroke.CAP_BUTT,
    //                                                    BasicStroke.JOIN_MITER);
    // final Color over50VertexColor = Color.MAGENTA;
    // final Stroke over50VertexStroke = new BasicStroke(2.0f,
    //                                                   BasicStroke.CAP_BUTT,
    //                                                   BasicStroke.JOIN_MITER);
    // final Color over80VertexColor = Color.BLUE;
    // final Stroke over80VertexStroke = new BasicStroke(2.0f,
    //                                                   BasicStroke.CAP_BUTT,
    //                                                   BasicStroke.JOIN_MITER);
    // final Color over95VertexColor = Color.GREEN;
    // final Stroke over95VertexStroke = new BasicStroke(2.0f,
    //                                                   BasicStroke.CAP_BUTT,
    //                                                   BasicStroke.JOIN_MITER);
    // final Color over100VertexColor = Color.RED;
    // final Stroke over100VertexStroke = new BasicStroke(5.0f,
    //                                                    BasicStroke.CAP_BUTT,
    //                                                    BasicStroke.JOIN_MITER);
    // Transformer<MycoNode,Stroke> nodeStrokeRenderer =
    //     new Transformer<MycoNode, Stroke>() {
    //   public Stroke transform(MycoNode n){
    //     int capacity = n.getHyphaData().getMax();
    //     int attached = n.getHyphaLink().degree();
    //     double ratio = ((double) attached) / ((double) capacity);

    //     if (ratio > 1.0) {
    //       return over100VertexStroke;
    //     } else if (ratio > 0.95) {
    //       return over95VertexStroke;
    //     } else if (ratio > 0.80) {
    //       return over80VertexStroke;
    //     } else if (ratio > 0.50) {
    //       return over50VertexStroke;
    //     } else {
    //       return under50VertexStroke;
    //     }
    //   }
    // };
    // Transformer<MycoNode,Paint> nodeOutlineRenderer =
    //     new Transformer<MycoNode, Paint>() {
    //   public Paint transform(MycoNode n) {
    //     int capacity = n.getHyphaData().getMax();
    //     int attached = n.getHyphaLink().degree();
    //     double ratio = ((double) attached) / ((double) capacity);

    //     if (ratio > 1.0) {
    //       return over100VertexColor;
    //     } else if (ratio > 0.95) {
    //       return over95VertexColor;
    //     } else if (ratio > 0.80) {
    //       return over80VertexColor;
    //     } else if (ratio > 0.50) {
    //       return over50VertexColor;
    //     } else {
    //       return under50VertexColor;
    //     }
    //   }
    // };

    /*Transformer<MycoNode,Paint> nodeFillRenderer = new Transformer<MycoNode,Paint>() {
      public Paint transform(MycoNode n) {
      HyphaData data = n.getHyphaData();
      if (!n.isUp()) { return Color.BLACK; }
      if (data.isBiomass()) { return Color.BLUE; }
      else if (data.isExtending()) { return Color.RED; }
      else if (data.isBranching()) { return Color.YELLOW; }
      else { return Color.GREEN; }
      }
      };*/

    /*Transformer<MycoNode,Paint> nodeFillRenderer = new Transformer<MycoNode,Paint>() {
      public Paint transform(MycoNode n) {
      HyphaData data = n.getHyphaData();
      if (data.isBiomass()) { return Color.BLUE; }
      else if (data.isExtending()) { return Color.RED; }
      else if (data.isBranching()) { return Color.YELLOW; }
      else { return Color.GREEN; }
      }
      };*/

    final Color transparent = new Color(0, 0, 0, 0);

    Transformer<MycoEdge, Paint> transparentEdges = new Transformer<MycoEdge, Paint>() {
        public Paint transform(MycoEdge e) {
            return transparent;
        }
    };

    visualizer.setBackground(Color.WHITE);

    visualizer.getRenderContext().setVertexFillPaintTransformer(vt.getNodeFillRenderer());
    visualizer.getRenderContext().setVertexShapeTransformer(vt.getShapeTransformer(scaleShapes));
    if (labelNodes) {
        visualizer.getRenderContext().setVertexLabelTransformer(vt.getNodeLabeller());
    }
    visualizer.getRenderContext().setVertexStrokeTransformer(vt.getVertexStrokeTransformer());
    visualizer.getRenderContext().setVertexDrawPaintTransformer(vt.getVertexDrawPaintTransformer());
    //visualizer.setVertexToolTipTransformer(new ToStringLabeller());

    if (showEdges) {
        visualizer.getRenderContext().setEdgeStrokeTransformer(vt.getEdgeStrokeTransformer());
        visualizer.getRenderContext().setEdgeDrawPaintTransformer(vt.getEdgeDrawPaintTransformer());
        visualizer.getRenderContext().setArrowDrawPaintTransformer(vt.getEdgeDrawPaintTransformer());
        visualizer.getRenderContext().setArrowFillPaintTransformer(vt.getEdgeDrawPaintTransformer());
    } else {
        visualizer.getRenderContext().setEdgeDrawPaintTransformer(transparentEdges);
        visualizer.getRenderContext().setArrowDrawPaintTransformer(transparentEdges);
        visualizer.getRenderContext().setArrowFillPaintTransformer(transparentEdges);
    }

    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container c = frame.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));

    //JScrollPane scrollPane = new JScrollPane(visualizer);
    //c.add(scrollPane);
    c.add(visualizer);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));

    final JButton captureButton = new JButton("capture");
    ActionListener capturer = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            saveAsPNG();
        }
    };
    captureButton.addActionListener(capturer);

    final JButton freezeButton = new JButton("freeze");
    ActionListener freezer = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (freezeButton.getText().equals("freeze")) {
                relaxer.pause();
                freezeButton.setText("unfreeze");
            } else {
                relaxer.resume();
                freezeButton.setText("freeze");
            }
        }
    };
    freezeButton.addActionListener(freezer);

    JButton pauseButton = new JButton("pause");
    ActionListener pauser = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //e.consume();
            JungGraphObserver.pauseAction();
        }
    };
    pauseButton.addActionListener(pauser);

    JButton stepButton = new JButton("step");
    ActionListener stepper = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clicked!\n");
            //e.consume();
            JungGraphObserver.stepAction();
        }
    };
    stepButton.addActionListener(stepper);

    JButton walkButton = new JButton("walk");
    ActionListener walker = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clicked!\n");
            //e.consume();
            JungGraphObserver.walkAction();
        }
    };
    walkButton.addActionListener(walker);

    JButton runButton = new JButton("run");
    ActionListener runner = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //e.consume();
            JungGraphObserver.runAction();
        }
    };
    runButton.addActionListener(runner);

    roundField = new JTextField("0");

    buttonPane.add(freezeButton);
    buttonPane.add(captureButton);
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(pauseButton);
    buttonPane.add(stepButton);
    buttonPane.add(walkButton);
    buttonPane.add(runButton);
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(roundField);
    c.add(buttonPane);

    frame.pack();
    frame.setVisible(true);

    JungGraphObserver.setVisualizer(visualizer);
}

From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java

@Override
public synchronized void actionPerformed(ActionEvent event) {
    for (int i = 0; i < transactionRenameButtons.size(); ++i) {
        if (event.getSource() == transactionRenameButtons.get(i)) {
            String newName = (String) JOptionPane.showInputDialog(this,
                    "Enter the new name for this transaction type", "New Dataset", JOptionPane.PLAIN_MESSAGE,
                    null, null, transactionNames.get(i));

            if (newName == null || newName.trim().isEmpty()) {
                return;
            } else {
                newName = newName.trim();
                transactionNames.set(i, newName);
                transactionLabels.get(i).setText(newName);

                DefaultTableModel model = (DefaultTableModel) monitorTable.getModel();
                model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(i)),
                        2 + (i * ROW_PER_TX_TYPE), 0);
                model.setValueAt(/*from  ww w. j  a v a2s . co m*/
                        String.format("Current average latency of '%s' transactions", transactionNames.get(i)),
                        2 + (i * ROW_PER_TX_TYPE) + 1, 0);

                //               TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset();
                throughputCollection.getSeries(i).setKey(newName);
                latencyCollection.getSeries(i).setKey(newName);

                //               if (DBSeerGUI.currentDataset != null)
                //               {
                //                  DBSeerGUI.currentDataset.setTransactionTypeName(i, newName);
                //               }

                for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) {
                    dataset.setTransactionTypeName(i, newName);
                }

                return;
            }
        }
    }

    for (int i = 0; i < transactionViewSampleButtons.size(); ++i) {
        if (event.getSource() == transactionViewSampleButtons.get(i)) {
            final int type = i;
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    DBSeerShowTransactionExampleFrame sampleFrame = new DBSeerShowTransactionExampleFrame(type);
                    sampleFrame.pack();
                    sampleFrame.setLocationRelativeTo(DBSeerGUI.mainFrame);
                    sampleFrame.setVisible(true);
                }
            });
        }
    }

    for (int i = 0; i < transactionEnableDisableButtons.size(); ++i) {
        if (event.getSource() == transactionEnableDisableButtons.get(i)) {
            final XYItemRenderer throughputRenderer = throughputChartPanel.getChart().getXYPlot().getRenderer();
            final XYItemRenderer latencyRenderer = latencyChartPanel.getChart().getXYPlot().getRenderer();
            final int type = i;
            final JButton button = transactionEnableDisableButtons.get(i);
            final DBSeerDataSet dataset = DBSeerGUI.liveDataset;

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (button.getText() == "Disable") {
                        dataset.disableTransaction(type);
                        throughputRenderer.setSeriesVisible(type, false);
                        latencyRenderer.setSeriesVisible(type, false);
                        button.setText("Enable");
                    } else if (button.getText() == "Enable") {
                        dataset.enableTransaction(type);
                        throughputRenderer.setSeriesVisible(type, true);
                        latencyRenderer.setSeriesVisible(type, true);
                        button.setText("Disable");
                    }
                }
            });
        }
    }

    for (int i = 0; i < transactionDeleteButtons.size(); ++i) {
        if (event.getSource() == transactionDeleteButtons.get(i)) {
            synchronized (LiveMonitorInfo.LOCK) {
                try {
                    DBSeerGUI.middlewareSocket.removeTransactionType(i);
                } catch (IOException e) {
                    DBSeerExceptionHandler.handleException(e);
                }

                throughputCollection.removeSeries(i);
                latencyCollection.removeSeries(i);

                DefaultTableModel model = (DefaultTableModel) monitorTable.getModel();
                int newTxSize = transactionNames.size() - 1;
                for (int j = 0; j < transactionNames.size(); ++j) {
                    model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(j)),
                            2 + (j * ROW_PER_TX_TYPE), 0);
                    model.setValueAt(String.format("Current average latency of '%s' transactions",
                            transactionNames.get(j)), 2 + (j * ROW_PER_TX_TYPE) + 1, 0);
                    model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE), 1);
                    model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE) + 1, 1);
                }
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 0);
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 1);
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 0);
                model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 1);

                final JPanel panel = transactionTypesPanel;
                final JLabel label = transactionLabels.remove(i);
                final JButton renameButton = transactionRenameButtons.remove(i);
                final JButton exampleButton = transactionViewSampleButtons.remove(i);
                final JButton deleteButton = transactionDeleteButtons.remove(i);
                transactionNames.remove(i);

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        panel.remove(label);
                        panel.remove(renameButton);
                        panel.remove(exampleButton);
                        panel.remove(deleteButton);

                        panel.revalidate();
                        panel.repaint();
                    }
                });
            }
            break;
        }
    }

}

From source file:de.ailis.xadrian.frames.MainFrame.java

/**
 * Creates the content.//from  w  w w  .  j a  va 2  s .  c om
 */
private void createContent() {
    this.tabs = new JTabbedPane();
    this.tabs.setPreferredSize(new Dimension(640, 480));
    this.tabs.addChangeListener(this);
    this.tabs.setTransferHandler(this.transferHandler);

    final JPanel welcomePanel = this.welcomePanel = new JPanel();
    welcomePanel.setTransferHandler(this.transferHandler);

    welcomePanel.setLayout(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();

    welcomePanel.setPreferredSize(new Dimension(640, 480));
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    c.anchor = GridBagConstraints.CENTER;
    welcomePanel.add(buttonPanel, c);

    final JButton newButton = new JButton(this.newAction);
    newButton.setHorizontalAlignment(SwingConstants.LEFT);
    newButton.setIconTextGap(10);
    newButton.setText("<html><body><strong>" + newButton.getText() + "</strong><br />"
            + newButton.getToolTipText() + "</body></html>");
    newButton.setToolTipText(null);
    newButton.setMargin(new Insets(5, 10, 5, 10));
    c.gridy = 0;
    c.fill = GridBagConstraints.BOTH;
    c.insets.set(5, 5, 5, 5);
    buttonPanel.add(newButton, c);

    final JButton openButton = new JButton(this.openAction);
    openButton.setHorizontalAlignment(SwingConstants.LEFT);
    openButton.setIconTextGap(10);
    openButton.setText("<html><body><strong>" + openButton.getText() + "</strong><br />"
            + openButton.getToolTipText() + "</body></html>");
    openButton.setToolTipText(null);
    openButton.setMargin(new Insets(5, 10, 5, 10));
    c.gridy++;
    buttonPanel.add(openButton, c);

    final JPanel separator = new JPanel();
    separator.setPreferredSize(new Dimension(20, 20));
    c.gridy++;
    buttonPanel.add(separator, c);

    final JButton donateButton = new JButton(this.donateAction);
    donateButton.setHorizontalAlignment(SwingConstants.LEFT);
    donateButton.setIconTextGap(10);
    donateButton.setText("<html><body><strong>" + donateButton.getText() + "</strong><br />"
            + donateButton.getToolTipText() + "</body></html>");
    donateButton.setToolTipText(null);
    donateButton.setMargin(new Insets(5, 10, 5, 10));
    c.gridy++;
    buttonPanel.add(donateButton, c);

    final SocialPane socialPane = new SocialPane();
    c.insets.top = 50;
    c.gridy++;
    buttonPanel.add(socialPane, c);
    installStatusHandler(buttonPanel);

    add(welcomePanel, BorderLayout.CENTER);
}

From source file:ffx.ui.ModelingPanel.java

private void builderCommandEvent(ActionEvent evt) {
    JButton button = (JButton) evt.getSource();
    String arg = evt.getActionCommand();
    int index = acidComboBox.getSelectedIndex();
    String selected = (String) acidComboBox.getItemAt(index);
    if ("Remove".equals(button.getText())) {
        // Remove one entry
        if (acidComboBox.getItemCount() > 0) {
            acidComboBox.removeItemAt(index);
            index--;/*  www .  j av  a2 s  .  c o  m*/
        }
    } else if ("Edit".equals(button.getText())) {
        String entry = new String(acidTextField.getText());
        // Allow editing - should add more input validation here
        if (!entry.equals("")) {
            String s[] = entry.trim().split(" +");
            String newResidue = s[0].toUpperCase();
            if ("NUCLEIC".equals(arg)) {
                // Residue.NA3Set.contains(newResidue);
                try {
                    Residue.NA3.valueOf(newResidue);
                    acidComboBox.removeItemAt(index);
                    acidComboBox.insertItemAt("" + index + " " + entry, index);
                } catch (Exception e) {
                }
            } else {
                try {
                    Residue.AA3.valueOf(newResidue);
                    acidComboBox.removeItemAt(index);
                    acidComboBox.insertItemAt("" + index + " " + entry, index);
                } catch (Exception e) {
                }
            }
        }
    } else if ("Reset".equals(button.getText())) {
        // Remove all entries
        acidComboBox.removeAllItems();
        acidTextArea.setText("");
    } else {
        // A base/residue button was selected
        String newResidue = button.getText();
        if ("PROTEIN".equals(arg)) {
            String c = (String) conformationComboBox.getSelectedItem();
            if (!c.toUpperCase().startsWith("DEFAULT")) {
                c = c.substring(c.indexOf("[") + 1, c.indexOf("]"));
                newResidue = newResidue + " " + c;
            }
            acidComboBox.insertItemAt("" + index + " " + newResidue, index + 1);
            index++;
        } else {
            if (!newResidue.equalsIgnoreCase("MOL")) {
                acidComboBox.insertItemAt("" + index + " " + newResidue, index + 1);
                index++;
            } else if (!selected.equalsIgnoreCase("MOL")) {
                acidComboBox.insertItemAt("" + index + " " + newResidue, index + 1);
                index++;
            }
        }
    }
    // Create the condensed sequence view.
    StringBuilder sequence = new StringBuilder();
    for (int i = 0; i < acidComboBox.getItemCount(); i++) {
        String s[] = ((String) acidComboBox.getItemAt(i)).trim().toUpperCase().split(" +");
        if (s.length > 1) {
            if (s[1].equalsIgnoreCase("MOL")) {
                sequence.append(s[1]).append("\n");
            } else {
                sequence.append(s[1]).append(" ");
            }
        }
    }
    // Renumber the sequence.
    acidTextArea.setText(sequence.toString());
    for (int i = 0; i < acidComboBox.getItemCount(); i++) {
        String s = (String) acidComboBox.getItemAt(i);
        s = s.substring(s.indexOf(" "), s.length()).trim();
        acidComboBox.removeItemAt(i);
        acidComboBox.insertItemAt("" + (i + 1) + " " + s, i);
    }
    // Set the selected entry and fill in the edit textField.
    if (index < 0) {
        index = 0;
    }
    if (index > acidComboBox.getItemCount() - 1) {
        index = acidComboBox.getItemCount() - 1;
    }
    acidComboBox.setSelectedIndex(index);
    String s = (String) acidComboBox.getItemAt(index);
    if (s != null) {
        acidTextField.setText(s.substring(s.indexOf(" "), s.length()).trim());
    } else {
        acidTextField.setText("");
    }
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected JPanel createButtonsPanel(Action[] actions, final DialogWindow dialog) {
    JPanel buttonsPanel = new JPanel();

    boolean hasPrimaryAction = false;
    for (final Action action : actions) {
        JButton button = new JButton(action.getCaption());
        String icon = action.getIcon();

        if (icon != null) {
            button.setIcon(AppBeans.get(IconResolver.class).getIconResource(icon));
        }/*from   w w  w.jav a  2  s  .  c  o m*/

        final DialogActionHandler dialogActionHandler = new DialogActionHandler(dialog, action);
        button.addActionListener(dialogActionHandler);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JButton b = (JButton) e.getSource();
                userActionsLog.trace("Button (name = {}, text = {}) was clicked in dialog", b.getName(),
                        b.getText());
            }
        });
        if (actions.length == 1) {
            dialog.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    dialogActionHandler.onClose();
                }
            });
        }

        button.setPreferredSize(
                new Dimension(button.getPreferredSize().width, DesktopComponentsHelper.BUTTON_HEIGHT));
        button.setMaximumSize(new Dimension(Integer.MAX_VALUE, DesktopComponentsHelper.BUTTON_HEIGHT));

        if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
            hasPrimaryAction = true;

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    button.requestFocus();
                }
            });
        }

        buttonsPanel.add(button);
    }

    if (!hasPrimaryAction && actions.length > 0) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                buttonsPanel.getComponent(0).requestFocus();
            }
        });
    }

    return buttonsPanel;
}

From source file:org.genedb.jogra.plugins.TermRationaliser.java

/**
 * Return a new JFrame which is the main interface to the Rationaliser.
 *///w  w w .j  a v a 2s .c  om
public JFrame getMainPanel() {

    /* JFRAME */
    frame.setTitle(WINDOW_TITLE);
    frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    frame.setLayout(new BorderLayout());

    /* MENU */
    JMenuBar menuBar = new JMenuBar();

    JMenu actions_menu = new JMenu("Actions");
    JMenuItem actions_mitem_1 = new JMenuItem("Refresh lists");
    actions_mitem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            initModels();
        }
    });
    actions_menu.add(actions_mitem_1);

    JMenu about_menu = new JMenu("About");
    JMenuItem about_mitem_1 = new JMenuItem("About");
    about_mitem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JOptionPane.showMessageDialog(null,
                    "Term Rationaliser \n" + "Wellcome Trust Sanger Institute, UK \n" + "2009",
                    "Term Rationaliser", JOptionPane.PLAIN_MESSAGE);
        }
    });
    about_menu.add(about_mitem_1);

    menuBar.add(about_menu);
    menuBar.add(actions_menu);
    frame.add(menuBar, BorderLayout.NORTH);

    /* MAIN BOX */
    Box center = Box.createHorizontalBox(); //A box that displays contents from left to right
    center.add(Box.createHorizontalStrut(5)); //Invisible fixed-width component

    /* FROM LIST AND PANEL */
    fromList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //Allow multiple products to be selected 
    fromList.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
                synchroniseLists(fromList, toList); //synchronise from left to right
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });

    Box fromPanel = this.createRationaliserPanel(FROM_LIST_NAME, fromList); //Box on left hand side
    fromPanel.add(Box.createVerticalStrut(55)); //Add some space
    center.add(fromPanel); //Add to main box
    center.add(Box.createHorizontalStrut(3)); //Add some space

    /* MIDDLE PANE */
    Box middlePane = Box.createVerticalBox();

    ClassLoader classLoader = this.getClass().getClassLoader(); //Needed to access the images later on
    ImageIcon leftButtonIcon = new ImageIcon(classLoader.getResource("left_arrow.gif"));
    ImageIcon rightButtonIcon = new ImageIcon(classLoader.getResource("right_arrow.gif"));

    leftButtonIcon = new ImageIcon(leftButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon!
    rightButtonIcon = new ImageIcon(rightButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon!

    JButton rightSynch = new JButton(rightButtonIcon);
    rightSynch.setToolTipText("Synchronise TO list. \n Shortcut: Right-arrow key");

    rightSynch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            synchroniseLists(fromList, toList);
        }
    });

    JButton leftSynch = new JButton(leftButtonIcon);
    leftSynch.setToolTipText("Synchronise FROM list. \n Shortcut: Left-arrow key");

    leftSynch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            synchroniseLists(toList, fromList);
        }
    });

    middlePane.add(rightSynch);
    middlePane.add(leftSynch);

    center.add(middlePane); //Add middle pane to main box
    center.add(Box.createHorizontalStrut(3));

    /* TO LIST AND PANEL */
    toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Single product selection in TO list
    toList.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
                synchroniseLists(toList, fromList); //synchronise from right to left
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });

    Box toPanel = this.createRationaliserPanel(TO_LIST_NAME, toList);

    Box newTerm = Box.createVerticalBox();

    textField = new JTextArea(1, 1); //textfield to let the user edit the name of an existing term
    textField.setMaximumSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().height, 10));

    textField.setForeground(Color.BLUE);
    JScrollPane jsp = new JScrollPane(textField); //scroll pane so that there is a horizontal scrollbar
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    newTerm.add(jsp);
    TitledBorder editBorder = BorderFactory.createTitledBorder("Edit term name");
    editBorder.setTitleColor(Color.DARK_GRAY);
    newTerm.setBorder(editBorder);
    toPanel.add(newTerm); //add textfield to panel

    center.add(toPanel); //add panel to main box
    center.add(Box.createHorizontalStrut(5));

    frame.add(center); //add the main panel to the frame

    initModels(); //load the lists with data

    /* BOTTOM HALF OF FRAME */
    Box main = Box.createVerticalBox();
    TitledBorder border = BorderFactory.createTitledBorder("Information");
    border.setTitleColor(Color.DARK_GRAY);

    /* INFORMATION BOX */
    Box info = Box.createVerticalBox();

    Box scope = Box.createHorizontalBox();
    scope.add(Box.createHorizontalStrut(5));
    scope.add(scopeLabel); //label showing the scope of the terms
    scope.add(Box.createHorizontalGlue());

    Box productCount = Box.createHorizontalBox();
    productCount.add(Box.createHorizontalStrut(5));
    productCount.add(productCountLabel); //display the label showing the number of terms
    productCount.add(Box.createHorizontalGlue());

    info.add(scope);
    info.add(productCount);
    info.setBorder(border);

    /* ACTION BUTTONS */
    Box actionButtons = Box.createHorizontalBox();
    actionButtons.add(Box.createHorizontalGlue());
    actionButtons.add(Box.createHorizontalStrut(10));

    JButton findFix = new JButton(new FindClosestMatchAction());
    actionButtons.add(findFix);
    actionButtons.add(Box.createHorizontalStrut(10));

    RationaliserAction ra = new RationaliserAction();
    // RationaliserAction2 ra2 = new RationaliserAction2();
    JButton go = new JButton(ra);
    actionButtons.add(go);
    actionButtons.add(Box.createHorizontalGlue());

    /* MORE INFORMATION TOGGLE */
    Box buttonBox = Box.createHorizontalBox();
    final JButton toggle = new JButton("Hide information <<");

    buttonBox.add(Box.createHorizontalStrut(5));
    buttonBox.add(toggle);
    buttonBox.add(Box.createHorizontalGlue());

    Box textBox = Box.createHorizontalBox();

    final JScrollPane scrollPane = new JScrollPane(information);
    scrollPane.setPreferredSize(new Dimension(frame.getWidth(), 100));
    scrollPane.setVisible(true);
    textBox.add(Box.createHorizontalStrut(5));
    textBox.add(scrollPane);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            if (toggle.getText().equals("Show information >>")) {
                scrollPane.setVisible(true);
                toggle.setText("Hide information <<");
                frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() + 100));
                frame.pack();
            } else if (toggle.getText().equals("Hide information <<")) {
                scrollPane.setVisible(false);
                toggle.setText("Show information >>");
                frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() - 100));
                frame.pack();
            }
        }
    };
    toggle.addActionListener(actionListener);

    main.add(Box.createVerticalStrut(5));
    main.add(info);
    main.add(Box.createVerticalStrut(5));
    main.add(Box.createVerticalStrut(5));
    main.add(actionButtons);
    main.add(Box.createVerticalStrut(10));
    main.add(buttonBox);
    main.add(textBox);

    frame.add(main, BorderLayout.SOUTH);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    //initModels();

    return frame;
}

From source file:org.kepler.gui.kar.KarManifestViewer.java

public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();/*from w ww . j  a v  a2s. c  om*/
    if (o instanceof JButton) {
        JButton b = (JButton) o;
        if (b.getText().equals("Refresh")) {
            log.debug("Refresh");
            refreshValues();
        }
    }
}

From source file:org.kepler.gui.lsid.LSIDViewer.java

public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();//from  www.j a  v  a  2  s  .c o m
    if (o instanceof JButton) {
        JButton b = (JButton) o;
        if (b.getText().equals("Refresh")) {
            if (isDebugging)
                log.debug("Refresh");
            refreshValues();
        } else if (b.getText().equals("Roll Revision")) {
            if (isDebugging)
                log.debug("Roll Revision");
            rollRevision();
            refreshValues();
        } else if (b.getText().equals("New Object ID")) {
            if (isDebugging)
                log.debug("New Object ID");
            assignNewObjectId();
            refreshValues();
        }
    }
}

From source file:org.metawidget.integrationtest.swing.allwidgets.SwingAllWidgetsTest.java

protected void runTest(AdvancedWidgetProcessor<JComponent, SwingMetawidget> processor) throws Exception {

    // Model/*ww  w.j a v  a2 s. c  o  m*/

    AllWidgets allWidgets = new AllWidgets$$EnhancerByCGLIB$$1234();

    // App

    SwingMetawidget metawidget = new SwingMetawidget();
    metawidget.setConfig("org/metawidget/integrationtest/swing/allwidgets/metawidget.xml");
    metawidget.addWidgetProcessor(processor);
    metawidget.addWidgetProcessor(new ReflectionBindingProcessor());
    metawidget.setMetawidgetLayout(new SeparatorLayoutDecorator(new SeparatorLayoutDecoratorConfig().setLayout(
            new org.metawidget.swing.layout.GridBagLayout(new GridBagLayoutConfig().setNumberOfColumns(2)))));

    metawidget.setToInspect(allWidgets);

    metawidget.add(new Stub("mystery"));

    // Test missing components

    try {
        metawidget.getValue("no-such-component");
        fail();
    } catch (MetawidgetException e1) {
        assertEquals("No component named 'no-such-component'", e1.getMessage());

        try {
            metawidget.getValue("textbox", "no-such-component");
            fail();
        } catch (MetawidgetException e2) {
            assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage());

            try {
                metawidget.getValue("textbox", "no-such-component1", "no-such-component2");
                fail();
            } catch (MetawidgetException e3) {
                assertEquals(
                        "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'",
                        e3.getMessage());
            }
        }
    }

    try {
        metawidget.setValue(null, "no-such-component");
        fail();
    } catch (MetawidgetException e1) {
        assertEquals("No component named 'no-such-component'", e1.getMessage());

        try {
            metawidget.setValue(null, "textbox", "no-such-component");
            fail();
        } catch (MetawidgetException e2) {
            assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage());

            try {
                metawidget.setValue(null, "textbox", "no-such-component1", "no-such-component2");
                fail();
            } catch (MetawidgetException e3) {
                assertEquals(
                        "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'",
                        e3.getMessage());
            }
        }
    }

    // Check what created, and edit it

    assertEquals("Textbox*:", ((JLabel) metawidget.getComponent(0)).getText());
    assertTrue(metawidget.getComponent(1) instanceof JTextField);
    assertEquals("Textbox", metawidget.getValue("textbox"));
    ((JTextField) metawidget.getComponent(1)).setText("Textbox1");

    assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText());
    assertTrue(metawidget.getComponent(3) instanceof JTextField);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(3)).gridx);
    assertEquals("Limited Textbox", metawidget.getValue("limitedTextbox"));
    ((JTextField) metawidget.getComponent(3)).setText("Limited Textbox1");

    assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText());
    assertTrue(metawidget.getComponent(5) instanceof JScrollPane);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(5)).gridx);
    assertEquals("Textarea", metawidget.getValue("textarea"));

    JTextArea textarea = (JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView();
    assertEquals(2, textarea.getRows());
    assertEquals(true, textarea.getLineWrap());
    assertEquals(true, textarea.getWrapStyleWord());
    textarea.setText("Textarea1");

    assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText());
    assertTrue(metawidget.getComponent(7) instanceof JPasswordField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(7)).gridx);
    assertEquals("Password", metawidget.getValue("password"));
    ((JPasswordField) metawidget.getComponent(7)).setText("Password1");

    // Primitives

    assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText());
    assertTrue(metawidget.getComponent(9) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(9)).gridx);
    assertTrue(Byte.MAX_VALUE == (Byte) metawidget.getValue("bytePrimitive"));
    assertTrue(-5 == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel())
            .getMinimum());
    assertTrue(
            Byte.MAX_VALUE == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel())
                    .getMaximum());
    assertEquals(0, ((JSpinner.DefaultEditor) ((JSpinner) metawidget.getComponent(9)).getEditor())
            .getTextField().getColumns());
    JSpinner spinner = (JSpinner) metawidget.getComponent(9);
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText());
    assertTrue(metawidget.getComponent(11) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(11)).gridx);
    assertEquals(String.valueOf(Byte.MIN_VALUE), metawidget.getValue("byteObject"));
    ((JTextField) metawidget.getComponent(11)).setText(String.valueOf(Byte.MIN_VALUE + 1));

    assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText());
    assertTrue(metawidget.getComponent(13) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(13)).gridx);
    assertTrue(Short.MAX_VALUE == (Short) metawidget.getValue("shortPrimitive"));
    assertTrue(-6 == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)).getModel())
            .getMinimum());
    assertTrue(Short.MAX_VALUE == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13))
            .getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(13);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText());
    assertTrue(metawidget.getComponent(15) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(15)).gridx);
    assertEquals(String.valueOf(Short.MIN_VALUE), metawidget.getValue("shortObject"));
    ((JTextField) metawidget.getComponent(15)).setText(String.valueOf(Short.MIN_VALUE + 1));

    assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText());
    assertTrue(metawidget.getComponent(17) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(17)).gridx);
    assertTrue(Integer.MAX_VALUE == (Integer) metawidget.getValue("intPrimitive"));
    assertTrue(Integer.MIN_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17))
            .getModel()).getMinimum());
    assertTrue(Integer.MAX_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17))
            .getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(17);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText());
    assertTrue(metawidget.getComponent(19) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(19)).gridx);
    assertEquals(String.valueOf(Integer.MIN_VALUE), metawidget.getValue("integerObject"));
    ((JTextField) metawidget.getComponent(19)).setText(String.valueOf(Integer.MIN_VALUE + 1));

    assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText());
    assertTrue(metawidget.getComponent(21) instanceof JSlider);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(21)).gridx);
    assertEquals(1, ((JSlider) metawidget.getComponent(21)).getMinimum());
    assertEquals(100, ((JSlider) metawidget.getComponent(21)).getMaximum());
    assertTrue(32 == (Integer) metawidget.getValue("rangedInt"));
    ((JSlider) metawidget.getComponent(21)).setValue(33);

    assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText());
    assertTrue(metawidget.getComponent(23) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(23)).gridx);
    assertEquals("33", metawidget.getValue("rangedInteger"));
    ((JTextField) metawidget.getComponent(23)).setText(String.valueOf(34));

    assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText());
    assertTrue(metawidget.getComponent(25) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(25)).gridx);
    assertTrue(42 == (Long) metawidget.getValue("longPrimitive"));
    assertTrue(-7 == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel())
            .getMinimum());
    assertTrue(
            Long.MAX_VALUE == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel())
                    .getMaximum());
    spinner = (JSpinner) metawidget.getComponent(25);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertTrue(metawidget.getComponent(26) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(26)).gridx);
    assertEquals("43", metawidget.getValue("longObject"));
    ((JTextField) metawidget.getComponent(26)).setText("44");

    assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText());
    assertTrue(metawidget.getComponent(28) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(28)).gridx);
    assertEquals(4.2f, metawidget.getValue("floatPrimitive"));
    assertEquals(-Float.MAX_VALUE,
            ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()).getMinimum());
    assertTrue(2048 == (Float) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel())
            .getMaximum());
    spinner = (JSpinner) metawidget.getComponent(28);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText());
    assertTrue(metawidget.getComponent(30) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(30)).gridx);
    assertEquals("4.3", metawidget.getValue("floatObject"));
    ((JTextField) metawidget.getComponent(30)).setText("5.4");

    assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText());
    assertTrue(metawidget.getComponent(32) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(32)).gridx);
    assertEquals(42.2d, metawidget.getValue("doublePrimitive"));
    assertTrue(-8 == (Double) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel())
            .getMinimum());
    assertEquals(Double.MAX_VALUE,
            ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(32);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertTrue(metawidget.getComponent(33) instanceof JTextField);
    assertEquals(0, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridx);
    assertEquals(2,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridwidth);
    assertEquals("43.3", metawidget.getValue("doubleObject"));
    ((JTextField) metawidget.getComponent(33)).setText("54.4");

    assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText());
    assertTrue(metawidget.getComponent(35) instanceof JTextField);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(35)).gridx);
    assertEquals("A", metawidget.getValue("charPrimitive"));
    ((JTextField) metawidget.getComponent(35)).setText("Z");

    assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText());
    assertTrue(metawidget.getComponent(37) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx);
    assertEquals("Z", metawidget.getValue("characterObject"));
    ((JTextField) metawidget.getComponent(37)).setText("A");

    assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText());
    assertTrue(metawidget.getComponent(39) instanceof JCheckBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(39)).gridx);
    assertTrue(false == (Boolean) metawidget.getValue("booleanPrimitive"));
    ((JCheckBox) metawidget.getComponent(39)).setSelected(true);

    assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText());
    assertTrue(metawidget.getComponent(41) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx);
    assertEquals(3, ((JComboBox) metawidget.getComponent(41)).getItemCount());
    assertEquals(Boolean.TRUE, metawidget.getValue("booleanObject"));
    ((JComboBox) metawidget.getComponent(41)).setSelectedItem(Boolean.FALSE);

    assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText());
    assertTrue(metawidget.getComponent(43) instanceof JComboBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(43)).gridx);
    assertEquals(4, ((JComboBox) metawidget.getComponent(43)).getItemCount());
    assertEquals("dropdown1", metawidget.getValue("dropdown"));
    ((JComboBox) metawidget.getComponent(43)).setSelectedItem("foo1");

    assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText());
    assertTrue(metawidget.getComponent(45) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(45)).gridx);

    JComboBox combo = (JComboBox) metawidget.getComponent(45);
    assertEquals(5, combo.getItemCount());
    assertEquals("Foo #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "foo2", 1, false, false))
                    .getText());
    assertEquals("Dropdown #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(),
            "dropdown2", 1, false, false)).getText());
    assertEquals("Bar #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "bar2", 1, false, false))
                    .getText());
    assertEquals("Baz #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "baz2", 1, false, false))
                    .getText());
    assertEquals("dropdown2", metawidget.getValue("dropdownWithLabels"));
    ((JComboBox) metawidget.getComponent(45)).setSelectedItem("bar2");

    assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText());
    assertTrue(metawidget.getComponent(47) instanceof JComboBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(47)).gridx);
    assertEquals(3, ((JComboBox) metawidget.getComponent(47)).getItemCount());
    assertTrue(0 == (Byte) metawidget.getValue("notNullDropdown"));
    ((JComboBox) metawidget.getComponent(47)).setSelectedItem((byte) 1);

    assertEquals("Not Null Object Dropdown*:", ((JLabel) metawidget.getComponent(48)).getText());
    assertTrue(metawidget.getComponent(49) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(49)).gridx);
    assertEquals(6, ((JComboBox) metawidget.getComponent(49)).getItemCount());
    assertEquals("dropdown3", metawidget.getValue("notNullObjectDropdown"));
    ((JComboBox) metawidget.getComponent(49)).setSelectedIndex(0);

    assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText());
    assertTrue(metawidget.getComponent(51) instanceof SwingMetawidget);

    SwingMetawidget metawidgetNested = (SwingMetawidget) metawidget.getComponent(51);

    assertEquals("Further Nested Widgets:", ((JLabel) metawidgetNested.getComponent(0)).getText());
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(1)).gridx);

    SwingMetawidget metawidgetFurtherNested = (SwingMetawidget) metawidgetNested.getComponent(1);
    assertEquals("Further Nested Widgets:", ((JLabel) metawidgetFurtherNested.getComponent(0)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(1) instanceof SwingMetawidget);
    assertEquals(((SwingMetawidget) metawidgetFurtherNested.getComponent(1)).getComponentCount(), 0);

    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetFurtherNested.getComponent(2)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(3) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout())
            .getConstraints(metawidgetFurtherNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1",
            metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox1"));
    ((JTextField) metawidgetFurtherNested.getComponent(3)).setText("Nested Textbox 1.1 (further)");

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetFurtherNested.getComponent(4)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(5) instanceof JTextField);

    // (should be 1, as in next row, if getEffectiveNumberOfColumns is working)

    assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout())
            .getConstraints(metawidgetFurtherNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2",
            metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox2"));
    ((JTextField) metawidgetFurtherNested.getComponent(5)).setText("Nested Textbox 2.2 (further)");

    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText());
    assertTrue(metawidgetNested.getComponent(3) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "nestedTextbox1"));
    ((JTextField) metawidgetNested.getComponent(3)).setText("Nested Textbox 1.1");

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText());
    assertTrue(metawidgetNested.getComponent(5) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "nestedTextbox2"));
    ((JTextField) metawidgetNested.getComponent(5)).setText("Nested Textbox 2.2");

    assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText());
    assertTrue(metawidget.getComponent(53) instanceof SwingMetawidget);

    metawidgetNested = (SwingMetawidget) metawidget.getComponent(53);
    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText());
    assertTrue(metawidgetNested.getComponent(3) instanceof JLabel);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox1"));

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText());
    assertTrue(metawidgetNested.getComponent(5) instanceof JLabel);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox2"));

    assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JTextField) metawidget.getComponent(55)).getText());
    ((JTextField) metawidget.getComponent(55)).setText("Nested Textbox 1.01, Nested Textbox 2.02");

    assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText());

    assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText());
    assertTrue(metawidget.getComponent(59) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(59)).gridx);

    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    assertEquals(dateFormat.format(allWidgets.getDate()), metawidget.getValue("date"));
    ((JTextField) metawidget.getComponent(59)).setText("bad date");

    JPanel separatorPanel = (JPanel) metawidget.getComponent(60);
    assertEquals("Section Break", ((JLabel) separatorPanel.getComponent(0)).getText());
    assertEquals(GridBagConstraints.REMAINDER,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(60)).gridwidth);
    assertTrue(separatorPanel.getComponent(1) instanceof JSeparator);

    assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText());
    assertTrue(metawidget.getComponent(62) instanceof JLabel);
    assertEquals("Read Only", metawidget.getValue("readOnly"));

    assertTrue(metawidget.getComponent(63) instanceof JButton);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).gridx);
    assertEquals(GridBagConstraints.NONE,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).fill);
    JButton button = ((JButton) metawidget.getComponent(63));
    assertEquals("Do Action", button.getText());
    assertTrue(button.isEnabled());
    try {
        button.doClick();
        fail();
    } catch (Exception e) {
        assertEquals("doAction called", e.getCause().getCause().getMessage());
    }

    assertEquals(64, metawidget.getComponentCount());

    // Check painting

    JFrame frame = new JFrame();
    metawidget.paint(frame.getGraphics());

    // Check MetawidgetException

    try {
        processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget);
        fail();
    } catch (Exception e) {
        assertEquals("Could not parse 'bad date'", e.getCause().getCause().getMessage());
    }

    // Check saving

    String now = dateFormat.format(new GregorianCalendar().getTime());
    ((JTextField) metawidget.getComponent(59)).setText(now);
    processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget);

    // Check read-only

    metawidget.setReadOnly(true);

    assertEquals("Textbox:", ((JLabel) metawidget.getComponent(0)).getText());
    assertEquals("Textbox1", ((JLabel) metawidget.getComponent(1)).getText());
    assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText());
    assertEquals("Limited Textbox1", ((JLabel) metawidget.getComponent(3)).getText());
    assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText());
    assertEquals("Textarea1",
            ((JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView()).getText());
    assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText());
    assertTrue(metawidget.getComponent(7) instanceof JPanel);
    assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText());
    assertEquals("126", ((JLabel) metawidget.getComponent(9)).getText());
    assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText());
    assertEquals("-127", ((JLabel) metawidget.getComponent(11)).getText());
    assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText());
    assertEquals("32766", ((JLabel) metawidget.getComponent(13)).getText());
    assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText());
    assertEquals("-32767", ((JLabel) metawidget.getComponent(15)).getText());
    assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText());
    assertEquals("2147483646", ((JLabel) metawidget.getComponent(17)).getText());
    assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText());
    assertEquals("-2147483647", ((JLabel) metawidget.getComponent(19)).getText());
    assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText());
    assertEquals("33", ((JLabel) metawidget.getComponent(21)).getText());
    assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText());
    assertEquals("34", ((JLabel) metawidget.getComponent(23)).getText());
    assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText());
    assertEquals("43", ((JLabel) metawidget.getComponent(25)).getText());
    assertEquals("44", ((JLabel) metawidget.getComponent(26)).getText());
    assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText());
    assertTrue(((JLabel) metawidget.getComponent(28)).getText().startsWith("4.3")
            || ((JLabel) metawidget.getComponent(28)).getText().startsWith("4.299"));
    assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText());
    assertEquals("5.4", ((JLabel) metawidget.getComponent(30)).getText());
    assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText());
    assertTrue(((JLabel) metawidget.getComponent(32)).getText().startsWith("42.3")
            || ((JLabel) metawidget.getComponent(32)).getText().startsWith("42.299"));
    assertEquals("54.4", ((JLabel) metawidget.getComponent(33)).getText());
    assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText());
    assertEquals("Z", ((JLabel) metawidget.getComponent(35)).getText());
    assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText());
    assertEquals("A", ((JLabel) metawidget.getComponent(37)).getText());
    assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText());
    assertEquals("true", ((JLabel) metawidget.getComponent(39)).getText());
    assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText());
    assertEquals("No", ((JLabel) metawidget.getComponent(41)).getText());
    assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText());
    assertEquals("foo1", ((JLabel) metawidget.getComponent(43)).getText());
    assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText());
    assertEquals("Bar #2", ((JLabel) metawidget.getComponent(45)).getText());
    assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText());
    assertEquals("1", ((JLabel) metawidget.getComponent(47)).getText());
    assertEquals("Not Null Object Dropdown:", ((JLabel) metawidget.getComponent(48)).getText());
    assertEquals("foo3", ((JLabel) metawidget.getComponent(49)).getText());
    assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(0)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(0)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(2)).getText());
    assertEquals("Nested Textbox 1.1 (further)",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(4)).getText());
    assertEquals("Nested Textbox 2.2 (further)",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(5)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(2)).getText());
    assertEquals("Nested Textbox 1.1",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(4)).getText());
    assertEquals("Nested Textbox 2.2",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(5)).getText());
    assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(0)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(2)).getText());
    assertEquals("Nested Textbox 1",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(4)).getText());
    assertEquals("Nested Textbox 2",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(5)).getText());
    assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText());
    assertEquals("Nested Textbox 1.01, Nested Textbox 2.02", ((JLabel) metawidget.getComponent(55)).getText());
    assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText());
    assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText());
    assertEquals(now, ((JLabel) metawidget.getComponent(59)).getText());
    assertEquals("Section Break", ((JLabel) ((JPanel) metawidget.getComponent(60)).getComponent(0)).getText());
    assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText());
    assertEquals("Read Only", ((JLabel) metawidget.getComponent(62)).getText());
    assertEquals("Do Action", ((JButton) metawidget.getComponent(63)).getText());
    assertTrue(!((JButton) metawidget.getComponent(63)).isEnabled());

    assertEquals(metawidget.getComponentCount(), 64);

    // Test Binding.onStartBuild clears the state

    assertTrue(null != metawidget.getClientProperty(processor.getClass()));
    processor.onStartBuild(metawidget);
    assertEquals(null, metawidget.getClientProperty(processor.getClass()));
}