List of usage examples for java.awt GridBagConstraints GridBagConstraints
public GridBagConstraints()
From source file:com.polivoto.vistas.AnalistaLocal.java
private void setPreguntasText() { JSONArray js = accionesConsultor.getPreguntas(); for (int i = 0; i < js.length(); i++) { try {//w w w. ja v a 2 s . c om JPanel panel = new JPanel(new GridBagLayout()); panel.setBackground(new Color(255, 255, 255)); panelPreguntas.add(panel, "Pregunta " + (i + 1)); JLabel lab1 = new JLabel( "Pregunta " + (i + 1) + ": " + ((JSONObject) js.get(i)).getString("pregunta"), JLabel.CENTER); lab1.setFont(new Font("Roboto", 1, 18)); lab1.setForeground(new Color(134, 36, 31)); GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.2; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); panel.add(lab1, gridBagConstraints); JSONArray jarr = ((JSONObject) js.get(i)).getJSONArray("opciones"); for (int j = 0; j < jarr.length(); j++) { JLabel lab2 = new JLabel("Opcin " + (j + 1) + ": " + jarr.getString(j), JLabel.CENTER); lab2.setFont(new Font("Roboto", 1, 15)); lab2.setForeground(new Color(0, 0, 0)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = j + 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); panel.add(lab2, gridBagConstraints); } JPanel panelRelleno = new JPanel(new BorderLayout(20, 20)); panelRelleno.setBackground(Color.white); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = jarr.length() + 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.9; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); panel.add(panelRelleno, gridBagConstraints); } catch (JSONException ex) { Logger.getLogger(AnalistaLocal.class.getName()).log(Level.SEVERE, null, ex); } } cardsPreguntas.show(panelPreguntas, "Pregunta " + 1); }
From source file:FontChooser.java
private void createUserInterface() { final JPanel content = new JPanel(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); setContentPane(content);/*from ww w . j ava 2s .c o m*/ content.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(2, 2, 2, 2); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = gbc.gridy = 0; content.add(new JLabel("Font"), gbc); ++gbc.gridx; content.add(new JLabel("Size"), gbc); if (_selectStyles) { ++gbc.gridx; content.add(new JLabel("Style"), gbc); } ++gbc.gridy; gbc.gridx = 0; _fontNamesCmb = new JComboBox( GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); content.add(_fontNamesCmb, gbc); ++gbc.gridx; _fontSizesCmb.setEditable(true); content.add(_fontSizesCmb, gbc); if (_selectStyles) { ++gbc.gridx; content.add(_boldChk, gbc); ++gbc.gridy; content.add(_italicChk, gbc); } gbc.gridx = 0; ++gbc.gridy; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; content.add(createPreviewPanel(), gbc); ++gbc.gridy; gbc.fill = GridBagConstraints.HORIZONTAL; content.add(createButtonsPanel(), gbc); pack(); setResizable(true); }
From source file:IconDemoApplet.java
public void init() { //Parse the applet parameters pictures = parseParameters();/* w ww .j a va2 s . c o m*/ //If the applet tag doesn't provide an "IMAGE0" parameter, //display an error message. if (pictures.size() == 0) { captionLabel = new JLabel("No images listed in applet tag."); captionLabel.setHorizontalAlignment(JLabel.CENTER); getContentPane().add(captionLabel); return; } //NOW CREATE THE GUI COMPONENTS //A label to identify XX of XX. numberLabel = new JLabel("Picture " + (current + 1) + " of " + pictures.size()); numberLabel.setHorizontalAlignment(JLabel.LEFT); numberLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5)); //A label for the caption. final Photo first = (Photo) pictures.firstElement(); captionLabel = new JLabel(first.caption); captionLabel.setHorizontalAlignment(JLabel.CENTER); captionLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); //A label for displaying the photographs. photographLabel = new JLabel("Loading first image..."); photographLabel.setHorizontalAlignment(JLabel.CENTER); photographLabel.setVerticalAlignment(JLabel.CENTER); photographLabel.setVerticalTextPosition(JLabel.CENTER); photographLabel.setHorizontalTextPosition(JLabel.CENTER); photographLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); photographLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0), photographLabel.getBorder())); //Set the preferred size for the picture, //with room for the borders. Insets i = photographLabel.getInsets(); photographLabel.setPreferredSize( new Dimension(widthOfWidest + i.left + i.right, heightOfTallest + i.bottom + i.top)); //Create the next and previous buttons. ImageIcon nextIcon = new ImageIcon(getURL(imagedir + "right.gif")); ImageIcon dimmedNextIcon = new ImageIcon(getURL(imagedir + "dimmedRight.gif")); ImageIcon previousIcon = new ImageIcon(getURL(imagedir + "left.gif")); ImageIcon dimmedPreviousIcon = new ImageIcon(getURL(imagedir + "dimmedLeft.gif")); previousButton = new JButton("Previous Picture", previousIcon); previousButton.setDisabledIcon(dimmedPreviousIcon); previousButton.setVerticalTextPosition(AbstractButton.CENTER); previousButton.setHorizontalTextPosition(AbstractButton.RIGHT); previousButton.setMnemonic(KeyEvent.VK_P); previousButton.setActionCommand("previous"); previousButton.addActionListener(this); previousButton.setEnabled(false); nextButton = new JButton("Next Picture", nextIcon); nextButton.setDisabledIcon(dimmedNextIcon); nextButton.setVerticalTextPosition(AbstractButton.CENTER); nextButton.setHorizontalTextPosition(AbstractButton.LEFT); nextButton.setMnemonic(KeyEvent.VK_N); nextButton.setActionCommand("next"); nextButton.addActionListener(this); //Lay out the GUI. GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); Container contentPane = getContentPane(); contentPane.setLayout(layout); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(numberLabel, c); contentPane.add(numberLabel); layout.setConstraints(captionLabel, c); contentPane.add(captionLabel); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; layout.setConstraints(photographLabel, c); contentPane.add(photographLabel); c.gridwidth = GridBagConstraints.RELATIVE; c.fill = GridBagConstraints.HORIZONTAL; layout.setConstraints(previousButton, c); contentPane.add(previousButton); c.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(nextButton, c); contentPane.add(nextButton); //Start loading the image for the first photograph now. //The loadImage method uses a SwingWorker //to load the image in a separate thread. loadImage(imagedir + first.filename, current); }
From source file:org.gvsig.remotesensing.profiles.gui.ZProfileOptionsPanel.java
public JPanel getControlPanel() { if (controlPanel == null) { controlPanel = new JPanel(); //controlPanel.setPreferredSize(new Dimension(80,20)); GridBagLayout gb = new GridBagLayout(); controlPanel.setLayout(gb);// w w w . ja v a 2s. c o m GridBagConstraints constrains = new GridBagConstraints(); constrains.insets = new java.awt.Insets(1, 5, 1, 1); constrains.gridx = 0; constrains.gridy = 0; controlPanel.add(getNewButton(), constrains); constrains.insets = new java.awt.Insets(1, 5, 1, 1); constrains.gridx = 0; constrains.gridy = 1; controlPanel.add(getDeleteButton(), constrains); } return controlPanel; }
From source file:edu.harvard.mcz.imagecapture.WhatsThisImageDialog.java
/** * This method initializes jPanel //from w w w . j a v a 2 s .com * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); gridBagConstraints9.fill = GridBagConstraints.BOTH; gridBagConstraints9.gridy = 4; gridBagConstraints9.weightx = 1.0; gridBagConstraints9.anchor = GridBagConstraints.WEST; gridBagConstraints9.gridx = 1; GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); gridBagConstraints8.gridx = 0; gridBagConstraints8.anchor = GridBagConstraints.EAST; gridBagConstraints8.gridy = 4; jLabel4 = new JLabel(); jLabel4.setText("Image Of:"); GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); gridBagConstraints7.gridx = 1; gridBagConstraints7.weighty = 1.0; gridBagConstraints7.gridy = 6; GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); gridBagConstraints6.gridx = 1; gridBagConstraints6.gridy = 5; GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); gridBagConstraints5.fill = GridBagConstraints.BOTH; gridBagConstraints5.gridy = 3; gridBagConstraints5.weightx = 1.0; gridBagConstraints5.anchor = GridBagConstraints.WEST; gridBagConstraints5.gridx = 1; GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); gridBagConstraints4.gridx = 0; gridBagConstraints4.anchor = GridBagConstraints.EAST; gridBagConstraints4.weighty = 0.0; gridBagConstraints4.gridy = 3; jLabel3 = new JLabel(); jLabel3.setText("DrawerNumber:"); GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); gridBagConstraints3.gridwidth = 2; gridBagConstraints3.weighty = 0.0; gridBagConstraints3.anchor = GridBagConstraints.NORTH; GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.fill = GridBagConstraints.BOTH; gridBagConstraints2.gridy = 2; gridBagConstraints2.weightx = 1.0; gridBagConstraints2.anchor = GridBagConstraints.WEST; gridBagConstraints2.gridx = 1; GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.gridx = 0; gridBagConstraints1.anchor = GridBagConstraints.EAST; gridBagConstraints1.weighty = 0.0; gridBagConstraints1.gridy = 2; jLabel2 = new JLabel(); jLabel2.setText("Barcode:"); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.insets = new Insets(0, 0, 5, 0); gridBagConstraints.weighty = 0.0; gridBagConstraints.gridy = 1; jLabel1 = new JLabel(); jLabel1.setText("Please Identify this Image."); jLabel = new JLabel(); jLabel.setText("No Barcode or drawer number found."); jPanel = new JPanel(); jPanel.setLayout(new GridBagLayout()); jPanel.add(jLabel, gridBagConstraints3); jPanel.add(jLabel1, gridBagConstraints); jPanel.add(jLabel2, gridBagConstraints1); jPanel.add(getJTextFieldBarcode(), gridBagConstraints2); jPanel.add(jLabel3, gridBagConstraints4); jPanel.add(getJTextFieldDrawerNumber(), gridBagConstraints5); jPanel.add(getJButton(), gridBagConstraints6); jPanel.add(getJPanel2(), gridBagConstraints7); jPanel.add(jLabel4, gridBagConstraints8); jPanel.add(getJComboBox(), gridBagConstraints9); } return jPanel; }
From source file:gov.loc.repository.bagger.ui.NewBagInPlaceFrame.java
private void layoutBagVersionContent(JPanel contentPanel, int row) { GridBagConstraints glbc = new GridBagConstraints(); JLabel bagVersionLabel = new JLabel(bagView.getPropertyMessage("bag.label.version")); bagVersionLabel.setToolTipText(bagView.getPropertyMessage("bag.versionlist.help")); ArrayList<String> versionModel = new ArrayList<String>(); Version[] vals = Version.values();//w w w . j a v a2s. c om for (int i = 0; i < vals.length; i++) { versionModel.add(vals[i].versionString); } bagVersionList = new JComboBox(versionModel.toArray()); bagVersionList.setName(bagView.getPropertyMessage("bag.label.versionlist")); bagVersionList.setSelectedItem(Version.V0_96.versionString); bagVersionList.setToolTipText(bagView.getPropertyMessage("bag.versionlist.help")); glbc = LayoutUtil.buildGridBagConstraints(0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); contentPanel.add(bagVersionLabel, glbc); glbc = LayoutUtil.buildGridBagConstraints(1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); contentPanel.add(bagVersionList, glbc); }
From source file:au.org.ala.delta.intkey.ui.FindInCharactersDialog.java
public FindInCharactersDialog(Intkey intkeyApp, IntkeyContext context) { super(intkeyApp.getMainFrame(), false); setResizable(false);/*from ww w . j ava2 s. c o m*/ ResourceMap resourceMap = Application.getInstance().getContext() .getResourceMap(FindInCharactersDialog.class); resourceMap.injectFields(this); ActionMap actionMap = Application.getInstance().getContext().getActionMap(this); _intkeyApp = intkeyApp; _numMatchedCharacters = 0; _currentMatchedCharacter = -1; _findAction = actionMap.get("findCharacters"); _nextAction = actionMap.get("nextCharacter"); this.setTitle(windowTitle); _pnlMain = new JPanel(); _pnlMain.setBorder(new EmptyBorder(20, 20, 20, 20)); getContentPane().add(_pnlMain, BorderLayout.CENTER); _pnlMain.setLayout(new BorderLayout(0, 0)); _pnlMainTop = new JPanel(); _pnlMain.add(_pnlMainTop, BorderLayout.NORTH); _pnlMainTop.setLayout(new BoxLayout(_pnlMainTop, BoxLayout.Y_AXIS)); _lblEnterSearchString = new JLabel(enterSearchStringCaption); _lblEnterSearchString.setBorder(new EmptyBorder(0, 0, 5, 0)); _pnlMainTop.add(_lblEnterSearchString); _textField = new JTextField(); _pnlMainTop.add(_textField); _textField.setColumns(10); _textField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { reset(); } @Override public void insertUpdate(DocumentEvent e) { reset(); } @Override public void changedUpdate(DocumentEvent e) { reset(); } }); _pnlMainBottom = new JPanel(); _pnlMainBottom.setBorder(new EmptyBorder(20, 0, 0, 0)); _pnlMain.add(_pnlMainBottom, BorderLayout.CENTER); _pnlMainBottom.setLayout(new BoxLayout(_pnlMainBottom, BoxLayout.Y_AXIS)); _chckbxSearchStates = new JCheckBox(searchStatesCaption); _chckbxSearchStates.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { reset(); } }); _pnlMainBottom.add(_chckbxSearchStates); _chckbxSearchUsedCharacters = new JCheckBox(searchUsedCharactersCaption); _chckbxSearchUsedCharacters.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { reset(); } }); _pnlMainBottom.add(_chckbxSearchUsedCharacters); _pnlButtons = new JPanel(); _pnlButtons.setBorder(new EmptyBorder(20, 0, 0, 10)); getContentPane().add(_pnlButtons, BorderLayout.EAST); _pnlButtons.setLayout(new BorderLayout(0, 0)); _pnlInnerButtons = new JPanel(); _pnlButtons.add(_pnlInnerButtons, BorderLayout.NORTH); GridBagLayout gbl__pnlInnerButtons = new GridBagLayout(); gbl__pnlInnerButtons.columnWidths = new int[] { 0, 0 }; gbl__pnlInnerButtons.rowHeights = new int[] { 0, 0, 0, 0 }; gbl__pnlInnerButtons.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl__pnlInnerButtons.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; _pnlInnerButtons.setLayout(gbl__pnlInnerButtons); _btnFindNext = new JButton(); _btnFindNext.setAction(_findAction); GridBagConstraints gbc__btnFindNext = new GridBagConstraints(); gbc__btnFindNext.fill = GridBagConstraints.HORIZONTAL; gbc__btnFindNext.insets = new Insets(0, 0, 5, 0); gbc__btnFindNext.gridx = 0; gbc__btnFindNext.gridy = 0; _pnlInnerButtons.add(_btnFindNext, gbc__btnFindNext); _btnPrevious = new JButton(); _btnPrevious.setAction(actionMap.get("previousCharacter")); _btnPrevious.setEnabled(false); GridBagConstraints gbc__btnPrevious = new GridBagConstraints(); gbc__btnPrevious.insets = new Insets(0, 0, 5, 0); gbc__btnPrevious.gridx = 0; gbc__btnPrevious.gridy = 1; _pnlInnerButtons.add(_btnPrevious, gbc__btnPrevious); _btnDone = new JButton(); _btnDone.setAction(actionMap.get("findCharactersDone")); GridBagConstraints gbc__btnDone = new GridBagConstraints(); gbc__btnDone.fill = GridBagConstraints.HORIZONTAL; gbc__btnDone.gridx = 0; gbc__btnDone.gridy = 2; _pnlInnerButtons.add(_btnDone, gbc__btnDone); this.pack(); this.setLocationRelativeTo(_intkeyApp.getMainFrame()); }
From source file:edu.harvard.mcz.imagecapture.encoder.UnitTrayLabelBrowser.java
/** * This method initializes jPanel /*w ww . j a v a 2s . c o m*/ * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.gridx = 2; gridBagConstraints1.gridy = 0; GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; jPanel = new JPanel(); jPanel.setLayout(new GridBagLayout()); jPanel.add(getJButton(), new GridBagConstraints()); jPanel.add(getJButton1(), gridBagConstraints); jPanel.add(getJButton2(), gridBagConstraints1); } return jPanel; }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Setup the GUI.//from w ww. j a v a 2 s .co m */ private void setupGUI() { JPanel mainPanel = new JPanel(); this.setContentPane(mainPanel); // start layout mainPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 0; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JPanel radioPanel = new JPanel(); radioPanel.setLayout(new BorderLayout()); zoomRadiobutton = new JRadioButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.label")); zoomRadiobutton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.zoom.tip")); zoomRadiobutton.setSelected(true); radioPanel.add(zoomRadiobutton, BorderLayout.LINE_START); gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 1; selectionRadiobutton = new JRadioButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.label")); selectionRadiobutton .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.selection.tip")); selectionRadiobutton.setHorizontalAlignment(SwingConstants.CENTER); radioPanel.add(selectionRadiobutton, BorderLayout.LINE_END); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 3; this.add(radioPanel, gbc); ButtonGroup group = new ButtonGroup(); group.add(zoomRadiobutton); group.add(selectionRadiobutton); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.CENTER; rangeAxisSelectionCombobox = new JComboBox(); rangeAxisSelectionCombobox.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.range_axis_combobox.tip")); rangeAxisSelectionCombobox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateValueRange(); } }); this.add(rangeAxisSelectionCombobox, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 1; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 2, 5); JLabel domainRangeLowerBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.label")); this.add(domainRangeLowerBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.insets = new Insets(2, 5, 2, 5); gbc.fill = GridBagConstraints.HORIZONTAL; domainRangeLowerBoundField = new JTextField(); domainRangeLowerBoundField.setText(String.valueOf(domainRangeLowerBound)); domainRangeLowerBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyDomainRangeLowerBoundInput(input); } }); domainRangeLowerBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_lower_bound.tip")); this.add(domainRangeLowerBoundField, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.NONE; JLabel domainRangeUpperBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.label")); this.add(domainRangeUpperBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; domainRangeUpperBoundField = new JTextField(); domainRangeUpperBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.domain_upper_bound.tip")); domainRangeUpperBoundField.setText(String.valueOf(domainRangeUpperBound)); domainRangeUpperBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyDomainRangeUpperBoundInput(input); } }); this.add(domainRangeUpperBoundField, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.fill = GridBagConstraints.NONE; JLabel valueRangeLowerBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.label")); this.add(valueRangeLowerBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 4; gbc.fill = GridBagConstraints.HORIZONTAL; valueRangeLowerBoundField = new JTextField(); valueRangeLowerBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_lower_bound.tip")); valueRangeLowerBoundField.setText(String.valueOf(valueRangeLowerBound)); valueRangeLowerBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyValueRangeLowerBoundInput(input); } }); this.add(valueRangeLowerBoundField, gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.fill = GridBagConstraints.NONE; JLabel valueRangeUpperBoundLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.label")); this.add(valueRangeUpperBoundLabel, gbc); gbc.gridx = 1; gbc.gridy = 5; gbc.fill = GridBagConstraints.HORIZONTAL; valueRangeUpperBoundField = new JTextField(); valueRangeUpperBoundField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.value_upper_bound.tip")); valueRangeUpperBoundField.setText(String.valueOf(valueRangeUpperBound)); valueRangeUpperBoundField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyValueRangeUpperBoundInput(input); } }); this.add(valueRangeUpperBoundField, gbc); gbc.gridx = 0; gbc.gridy = 6; gbc.gridwidth = 3; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 7; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; JLabel colorMinValueLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.label")); this.add(colorMinValueLabel, gbc); gbc.gridx = 1; gbc.gridy = 7; gbc.fill = GridBagConstraints.HORIZONTAL; colorMinValueField = new JTextField(); colorMinValueField .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_min_value.tip")); colorMinValueField.setText(String.valueOf(colorMinValue)); colorMinValueField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyColorInput(input); } }); colorMinValueField.setEnabled(false); this.add(colorMinValueField, gbc); gbc.gridx = 0; gbc.gridy = 8; gbc.fill = GridBagConstraints.NONE; JLabel colorMaxValueLabel = new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.label")); this.add(colorMaxValueLabel, gbc); gbc.gridx = 1; gbc.gridy = 8; gbc.fill = GridBagConstraints.HORIZONTAL; colorMaxValueField = new JTextField(); colorMaxValueField .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.color_max_value.tip")); colorMaxValueField.setText(String.valueOf(colorMaxValue)); colorMaxValueField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { return verifyColorInput(input); } }); colorMaxValueField.setEnabled(false); this.add(colorMaxValueField, gbc); gbc.gridx = 1; gbc.gridy = 9; gbc.fill = GridBagConstraints.NONE; restoreColorButton = new JButton( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.label")); restoreColorButton .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.tip")); restoreColorButton.setIcon(SwingTools.createIcon( "16/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.restore_color.icon"))); restoreColorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LinkAndBrushSelection linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.RESTORE_COLOR, new LinkedList<Pair<Integer, Range>>(), new LinkedList<Pair<Integer, Range>>(), null, null, engine.getPlotInstance()); engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection); updateColorValues(); } }); restoreColorButton.setEnabled(false); this.add(restoreColorButton, gbc); gbc.gridx = 0; gbc.gridy = 10; gbc.gridwidth = 3; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(2, 5, 5, 5); this.add(new JSeparator(), gbc); gbc.gridx = 0; gbc.gridy = 11; gbc.gridwidth = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 5, 5, 5); okButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.label")); okButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.tip")); okButton.setIcon(SwingTools .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.icon"))); okButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.ok.mne").toCharArray()[0]); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // make sure fields have correct values boolean fieldsPassedChecks = checkFields(); if (!fieldsPassedChecks) { return; } Object selectedItem = rangeAxisSelectionCombobox.getSelectedItem(); if (selectedItem != null && selectedItem instanceof RangeAxisConfig) { RangeAxisConfig config = (RangeAxisConfig) selectedItem; boolean zoomOnLinkAndBrushSelection = engine.getChartPanel().getZoomOnLinkAndBrushSelection(); Range domainRange = new Range(Double.parseDouble(domainRangeLowerBoundField.getText()), Double.parseDouble(domainRangeUpperBoundField.getText())); Range valueRange = new Range(Double.parseDouble(valueRangeLowerBoundField.getText()), Double.parseDouble(valueRangeUpperBoundField.getText())); LinkedList<Pair<Integer, Range>> domainRangeList = new LinkedList<Pair<Integer, Range>>(); // only add domain zoom if != 0 if (domainRange.getUpperBound() != 0) { domainRangeList.add(new Pair<Integer, Range>(0, domainRange)); } LinkedList<Pair<Integer, Range>> valueRangeList = new LinkedList<Pair<Integer, Range>>(); // only add range zoom if at least one RangeAxisConfig exists if (engine.getPlotInstance().getMasterPlotConfiguration().getRangeAxisConfigs().size() > 0) { if (valueRange.getUpperBound() != 0) { // only add value zoom if != 0 valueRangeList.add( new Pair<Integer, Range>(engine.getPlotInstance().getMasterPlotConfiguration() .getIndexOfRangeAxisConfigById(config.getId()), valueRange)); } } // zoom or select or color LinkAndBrushSelection linkAndBrushSelection = null; if (zoomRadiobutton.isSelected()) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.ZOOM_IN, domainRangeList, valueRangeList); if (isColorChanged(Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()))) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_ZOOM, domainRangeList, valueRangeList, Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance()); } } else if (selectionRadiobutton.isSelected()) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.SELECTION, domainRangeList, valueRangeList); if (isColorChanged(Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()))) { linkAndBrushSelection = new LinkAndBrushSelection(SelectionType.COLOR_SELECTION, domainRangeList, valueRangeList, Double.parseDouble(colorMinValueField.getText()), Double.parseDouble(colorMaxValueField.getText()), engine.getPlotInstance()); } } engine.getChartPanel().informLinkAndBrushSelectionListeners(linkAndBrushSelection); engine.getChartPanel().setZoomOnLinkAndBrushSelection(zoomOnLinkAndBrushSelection); } else { return; } ManageZoomDialog.this.dispose(); } }); okButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { okButton.doClick(); } } }); this.add(okButton, gbc); gbc.gridx = 2; gbc.gridy = 11; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.EAST; cancelButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.label")); cancelButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.tip")); cancelButton.setIcon(SwingTools .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.icon"))); cancelButton.setMnemonic( I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.cancel.mne").toCharArray()[0]); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // cancel requested, close dialog ManageZoomDialog.this.dispose(); } }); this.add(cancelButton, gbc); // misc settings this.setMinimumSize(new Dimension(375, 360)); // center dialog this.setLocationRelativeTo(null); this.setTitle(I18N.getMessage(I18N.getGUIBundle(), "gui.action.manage_zoom.title.label")); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setModal(true); this.addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { okButton.requestFocusInWindow(); } }); }
From source file:mineria.UI.java
public UI() { this.setLayout(new GridBagLayout()); Label lblnodatos = new Label("NoDatos: "); Label label = new Label("BD: "); JTextField filename = new JTextField("/Users/eduardomartinez/Documents/mineria/representacion.txt"); JTextField nodatos = new JTextField(); nodatos.setText("500"); JTextField funcion = new JTextField("6"); JTextField individuos = new JTextField("200"); JTextField enteros = new JTextField("1"); JTextField decimales = new JTextField("40"); JTextField variables = new JTextField("6"); JTextField Pc = new JTextField("0.9"); JTextField Pm = new JTextField("0.01"); JTextField generaciones = new JTextField("100"); JTextField minimiza = new JTextField("0"); Label lblfuncion = new Label("funcion: "); Label lblindividuos = new Label("individuos: "); Label lblenteros = new Label("enteros: "); Label lbldecimales = new Label("decimales: "); Label lblvariables = new Label("variables: "); Label lblpc = new Label("Pc: "); Label lblpm = new Label("Pm: "); Label lblgeneraciones = new Label("generaciones: "); Label lblminimiza = new Label("[0 Min/1 Max] : "); /*/*from ww w. j a v a 2 s . c om*/ FN=funcion; N =individuos; E =bits_enteros; D =bits_decimales; V =variables; Pc=porcentaje_cruza; Pm=porcentaje_muta; G =generaciones; MM=minimiza; */ JButton openBtn = new JButton("Open BD"); JButton ejecutarEGA = new JButton("Ejecutar EGA"); JTextField resultado = new JTextField(); Label fitness = new Label("fitness: "); XYSeriesCollection datosSerie = new XYSeriesCollection(); AGF agf = new AGF(2); EGA ega = new EGA(); JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title "X", // x axis label "Y", // y axis label datosSerie, // data ***-----PROBLEM------*** PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // create and display a frame... ChartPanel panelChart = new ChartPanel(chart); //leer BD openBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //datosSerie.removeAllSeries(); if (filename.getText().length() > 0) { agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText())); createDataset(datosSerie, agf.data, "Datos"); chart.fireChartChanged(); } else { JFileChooser openFile = new JFileChooser(); int rVal = openFile.showOpenDialog(null); if (rVal == JFileChooser.APPROVE_OPTION) { filename.setText(openFile.getSelectedFile().getAbsolutePath()); agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText())); //createDataset(datosSerie, agf.data, "Datos"); //chart.fireChartChanged(); } if (rVal == JFileChooser.CANCEL_OPTION) { filename.setText(""); //dir.setText(""); } } } }); ejecutarEGA.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { //datosSerie.removeAllSeries(); if (datosSerie.getSeriesCount() > 1) datosSerie.removeSeries(1); int fn = Integer.parseInt(funcion.getText()); int n = Integer.parseInt(individuos.getText()); int e = Integer.parseInt(enteros.getText()); int d = Integer.parseInt(decimales.getText()); int v = Integer.parseInt(variables.getText()); double pc = Double.parseDouble(Pc.getText()); double pm = Double.parseDouble(Pm.getText()); int g = Integer.parseInt(generaciones.getText()); int mm = Integer.parseInt(minimiza.getText()); ega.setParams(fn, n, e, d, v, pc, pm, g, mm); Resultado res = ega.ejecutarAlgoritmoGenetico(agf); resultado.setText(String.valueOf(res.getFitnessSemental())); res.creaArchivo(); createDataset(datosSerie, res.getFenotipoSemental(), "Centros"); Shape cross = ShapeUtilities.createDiagonalCross(5, 1); XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesShape(1, cross); renderer.setSeriesPaint(1, Color.blue); chart.fireChartChanged(); } }); //ejecutar AG GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 2; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblnodatos, gbc); gbc.gridx = 3; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(nodatos, gbc); gbc.gridx = 2; gbc.gridy = 1; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(filename, gbc); gbc.gridx = 3; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(openBtn, gbc); gbc.gridx = 2; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(fitness, gbc); gbc.gridx = 3; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(resultado, gbc); gbc.gridx = 2; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(ejecutarEGA, gbc); //-----------------PARAMETROS gbc.gridx = 0; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblfuncion, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.weighty = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(funcion, gbc); gbc.gridx = 0; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblindividuos, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(individuos, gbc); gbc.gridx = 0; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblenteros, gbc); gbc.gridx = 1; gbc.gridy = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(enteros, gbc); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lbldecimales, gbc); gbc.gridx = 1; gbc.gridy = 3; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(decimales, gbc); gbc.gridx = 0; gbc.gridy = 4; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblvariables, gbc); gbc.gridx = 1; gbc.gridy = 4; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(variables, gbc); gbc.gridx = 0; gbc.gridy = 5; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblpc, gbc); gbc.gridx = 1; gbc.gridy = 5; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(Pc, gbc); gbc.gridx = 0; gbc.gridy = 6; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblpm, gbc); gbc.gridx = 1; gbc.gridy = 6; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(Pm, gbc); gbc.gridx = 0; gbc.gridy = 7; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblgeneraciones, gbc); gbc.gridx = 1; gbc.gridy = 7; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(generaciones, gbc); gbc.gridx = 0; gbc.gridy = 8; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(lblminimiza, gbc); gbc.gridx = 1; gbc.gridy = 8; gbc.fill = GridBagConstraints.HORIZONTAL; this.add(minimiza, gbc); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 9; gbc.gridheight = 2; gbc.gridwidth = 4; this.add(panelChart, gbc); this.setTitle("File Chooser"); this.pack(); }