List of usage examples for java.awt GridBagConstraints BOTH
int BOTH
To view the source code for java.awt GridBagConstraints BOTH.
Click Source Link
From source file:com.polivoto.vistas.Charts.java
public void getHeader(JPanel header) { header.removeAll();/*from w w w . ja v a 2 s .c om*/ GridBagConstraints gridBagConstraints; header.setLayout(new GridBagLayout()); header.setBackground(Color.white); header.setPreferredSize(new Dimension(0, 100)); JLabel titulo = new JLabel("<html> <b>Votacin: </b>" + votacion.getTitulo() + "</html>"); JLabel lugar = new JLabel("<html> <b>Lugar: </b>" + votacion.getLugar() + "</html>"); SimpleDateFormat sdf = new SimpleDateFormat("EEEE d' de 'MMMM' del 'yyyy, hh:mm:ss"); JLabel fechaInicio = new JLabel( "<html><b>Fecha de inicio: </b>" + sdf.format(new Date(votacion.getFechaInicio())) + "</html>"); JLabel fechaFin = new JLabel( "<html><b>Fecha de fin: </b>" + sdf.format(new Date(votacion.getFechaFin())) + "</html>"); titulo.setFont(fuenteNormal); titulo.setVerticalAlignment(JLabel.CENTER); lugar.setFont(fuenteNormal); lugar.setVerticalAlignment(JLabel.CENTER); fechaFin.setFont(fuenteNormal); fechaFin.setVerticalAlignment(JLabel.CENTER); fechaInicio.setFont(fuenteNormal); fechaInicio.setVerticalAlignment(JLabel.CENTER); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5); header.add(titulo, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 1; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 15); header.add(fechaInicio, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 15, 5, 5); header.add(lugar, gridBagConstraints); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = 3; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 15); header.add(fechaFin, gridBagConstraints); header.repaint(); header.revalidate(); }
From source file:com.polivoto.vistas.AnalistaLocal.java
private void setPreguntasText() { JSONArray js = accionesConsultor.getPreguntas(); for (int i = 0; i < js.length(); i++) { try {// www . j a v a2 s . c o m 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:rhinova.gui.dataentry.reserve.ReserveDataEntryPanel.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner non-commercial license vSpacer6 = new JPanel(null); label1 = new JLabel(); hSpacer1 = new JPanel(null); label2 = new JLabel(); txtName = new JTextField(); vSpacer1 = new JPanel(null); label3 = new JLabel(); txtXPos = new JTextField(); vSpacer2 = new JPanel(null); label4 = new JLabel(); txtYPos = new JTextField(); hSpacer2 = new JPanel(null); vSpacer3 = new JPanel(null); label8 = new JLabel(); txtMin = new JTextField(); vSpacer4 = new JPanel(null); label5 = new JLabel(); txtMax = new JTextField(); vSpacer5 = new JPanel(null); label6 = new JLabel(); txtCur = new JTextField(); vSpacer9 = new JPanel(null); label7 = new JLabel(); txtReg = new JTextField(); vSpacer7 = new JPanel(null); btnCreateReserve = new JButton(); vSpacer8 = new JPanel(null); //======== this ======== setBorder(new TitledBorder("Reserve")); setLayout(new GridBagLayout()); ((GridBagLayout) getLayout()).columnWidths = new int[] { 0, 65, 145, 0, 0 }; ((GridBagLayout) getLayout()).rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };/* ww w. ja v a 2 s . c o m*/ ((GridBagLayout) getLayout()).columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 1.0E-4 }; ((GridBagLayout) getLayout()).rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4 }; add(vSpacer6, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label1 ---- label1.setText("Reserve Entry Panel"); label1.setFont(new Font("Tahoma", Font.PLAIN, 16)); add(label1, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(hSpacer1, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label2 ---- label2.setText("name"); add(label2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtName, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer1, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label3 ---- label3.setText("x - position"); add(label3, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtXPos, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer2, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label4 ---- label4.setText("y - position"); add(label4, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtYPos, new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(hSpacer2, new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0)); add(vSpacer3, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label8 ---- label8.setText("minimum population"); add(label8, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtMin, new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer4, new GridBagConstraints(1, 9, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label5 ---- label5.setText("maximum population"); add(label5, new GridBagConstraints(1, 10, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtMax, new GridBagConstraints(2, 10, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer5, new GridBagConstraints(1, 11, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label6 ---- label6.setText("current population"); add(label6, new GridBagConstraints(1, 12, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtCur, new GridBagConstraints(2, 12, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer9, new GridBagConstraints(1, 13, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- label7 ---- label7.setText("regeneration rate"); add(label7, new GridBagConstraints(1, 14, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(txtReg, new GridBagConstraints(2, 14, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer7, new GridBagConstraints(1, 15, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); //---- btnCreateReserve ---- btnCreateReserve.setText("Create Reserve"); btnCreateReserve.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { btnCreateReserveActionPerformed(e); } }); add(btnCreateReserve, new GridBagConstraints(2, 16, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); add(vSpacer8, new GridBagConstraints(2, 17, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:de.codesourcery.jasm16.ide.ui.viewcontainers.EditorContainer.java
private JPanel createPanel() { final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); setColors(result);/*from w w w . j a v a2s . c om*/ tabbedPane.setBackground(Color.WHITE); tabbedPane.setForeground(Color.black); result.add(tabbedPane, cnstrs); if (getViewContainer().getMenuManager() != null) { getViewContainer().getMenuManager().addEntry(saveCurrent); } tabbedPane.addChangeListener(changeListener); tabbedPane.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_W && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) { int idx = tabbedPane.getSelectedIndex(); if (idx != -1) { disposeView(getViewForTabIndex(idx)); } } } }); return result; }
From source file:edu.harvard.mcz.imagecapture.RunnableJobReportDialog.java
/** * This method initializes jPanel //from w w w . j ava 2 s . c o m * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.gridy = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.gridheight = 3; gridBagConstraints.gridx = 0; jLabel = new JLabel(); jLabel.setText(title); jPanel = new JPanel(); jPanel.setLayout(new GridBagLayout()); jPanel.add(jLabel, new GridBagConstraints()); jPanel.add(getJTextArea(), gridBagConstraints); } return jPanel; }
From source file:net.sourceforge.squirrel_sql.client.preferences.WikiTablePreferencesPanel.java
/** * Creates the user Interface/*from ww w . ja va 2 s. co m*/ */ private void createUserInterface() { JPanel jp = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(4, 4, 4, 4); gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 0; gbc.weighty = 1; jp.add(createOverviewPanel(), gbc); gbc.gridy = 1; gbc.weighty = 0; gbc.fill = GridBagConstraints.HORIZONTAL; jp.add(createNotePanel(), gbc); gbc.weightx = 1; gbc.weighty = 1; gbc.gridheight = 2; gbc.gridy = 0; gbc.gridx = 1; gbc.fill = GridBagConstraints.BOTH; jp.add(createDetailPanel(), gbc); gbc.weightx = 1; gbc.weighty = 1; gbc.gridheight = 2; gbc.gridy = 0; gbc.gridx = 2; gbc.fill = GridBagConstraints.BOTH; jp.add(createExamplePanel(), gbc); JScrollPane sp = new JScrollPane(jp); gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1; gbc.weighty = 1; add(sp, gbc); }
From source file:gate.gui.docview.AnnotationStack.java
/** * Draw the annotation stack in a JPanel with a GridBagLayout. */// w ww . jav a2 s .c o m public void drawStack() { // clear the panel removeAll(); boolean textTooLong = text.length() > maxTextLength; int upperBound = text.length() - (maxTextLength / 2); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; /********************** * First row of text * *********************/ gbc.gridwidth = 1; gbc.insets = new java.awt.Insets(10, 10, 10, 10); JLabel labelTitle = new JLabel("Context"); labelTitle.setOpaque(true); labelTitle.setBackground(Color.WHITE); labelTitle.setBorder(new CompoundBorder( new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2)))); labelTitle.setToolTipText("Expression and its context."); add(labelTitle, gbc); gbc.insets = new java.awt.Insets(10, 0, 10, 0); int expressionStart = contextBeforeSize; int expressionEnd = text.length() - contextAfterSize; // for each character for (int charNum = 0; charNum < text.length(); charNum++) { gbc.gridx = charNum + 1; if (textTooLong) { if (charNum == maxTextLength / 2) { // add ellipsis dots in case of a too long text displayed add(new JLabel("..."), gbc); // skip the middle part of the text if too long charNum = upperBound + 1; continue; } else if (charNum > upperBound) { gbc.gridx -= upperBound - (maxTextLength / 2) + 1; } } // set the text and color of the feature value JLabel label = new JLabel(text.substring(charNum, charNum + 1)); if (charNum >= expressionStart && charNum < expressionEnd) { // this part is matched by the pattern, color it label.setBackground(new Color(240, 201, 184)); } else { // this part is the context, no color label.setBackground(Color.WHITE); } label.setOpaque(true); // get the word from which belongs the current character charNum int start = text.lastIndexOf(" ", charNum); int end = text.indexOf(" ", charNum); String word = text.substring((start == -1) ? 0 : start, (end == -1) ? text.length() : end); // add a mouse listener that modify the query label.addMouseListener(textMouseListener.createListener(word)); add(label, gbc); } /************************************ * Subsequent rows with annotations * ************************************/ // for each row to display for (StackRow stackRow : stackRows) { String type = stackRow.getType(); String feature = stackRow.getFeature(); if (feature == null) { feature = ""; } String shortcut = stackRow.getShortcut(); if (shortcut == null) { shortcut = ""; } gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 1; gbc.insets = new Insets(0, 0, 3, 0); // add the header of the row JLabel annotationTypeAndFeature = new JLabel(); String typeAndFeature = type + (feature.equals("") ? "" : ".") + feature; annotationTypeAndFeature.setText(!shortcut.equals("") ? shortcut : stackRow.getSet() != null ? stackRow.getSet() + "#" + typeAndFeature : typeAndFeature); annotationTypeAndFeature.setOpaque(true); annotationTypeAndFeature.setBackground(Color.WHITE); annotationTypeAndFeature .setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2)))); if (feature.equals("")) { annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type)); } else { annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type, feature)); } gbc.insets = new java.awt.Insets(0, 10, 3, 10); add(annotationTypeAndFeature, gbc); gbc.insets = new java.awt.Insets(0, 0, 3, 0); // add all annotations for this row HashMap<Integer, TreeSet<Integer>> gridSet = new HashMap<Integer, TreeSet<Integer>>(); int gridyMax = gbc.gridy; for (StackAnnotation ann : stackRow.getAnnotations()) { gbc.gridx = ann.getStartNode().getOffset().intValue() - expressionStartOffset + contextBeforeSize + 1; gbc.gridwidth = ann.getEndNode().getOffset().intValue() - ann.getStartNode().getOffset().intValue(); if (gbc.gridx == 0) { // column 0 is already the row header gbc.gridwidth -= 1; gbc.gridx = 1; } else if (gbc.gridx < 0) { // annotation starts before displayed text gbc.gridwidth += gbc.gridx - 1; gbc.gridx = 1; } if (gbc.gridx + gbc.gridwidth > text.length()) { // annotation ends after displayed text gbc.gridwidth = text.length() - gbc.gridx + 1; } if (textTooLong) { if (gbc.gridx > (upperBound + 1)) { // x starts after the hidden middle part gbc.gridx -= upperBound - (maxTextLength / 2) + 1; } else if (gbc.gridx > (maxTextLength / 2)) { // x starts in the hidden middle part if (gbc.gridx + gbc.gridwidth <= (upperBound + 3)) { // x ends in the hidden middle part continue; // skip the middle part of the text } else { // x ends after the hidden middle part gbc.gridwidth -= upperBound - gbc.gridx + 2; gbc.gridx = (maxTextLength / 2) + 2; } } else { // x starts before the hidden middle part if (gbc.gridx + gbc.gridwidth < (maxTextLength / 2)) { // x ends before the hidden middle part // do nothing } else if (gbc.gridx + gbc.gridwidth < upperBound) { // x ends in the hidden middle part gbc.gridwidth = (maxTextLength / 2) - gbc.gridx + 1; } else { // x ends after the hidden middle part gbc.gridwidth -= upperBound - (maxTextLength / 2) + 1; } } } if (gbc.gridwidth == 0) { gbc.gridwidth = 1; } JLabel label = new JLabel(); Object object = ann.getFeatures().get(feature); String value = (object == null) ? " " : Strings.toString(object); if (value.length() > maxFeatureValueLength) { // show the full text in the tooltip label.setToolTipText((value.length() > 500) ? "<html><textarea rows=\"30\" cols=\"40\" readonly=\"readonly\">" + value.replaceAll("(.{50,60})\\b", "$1\n") + "</textarea></html>" : ((value.length() > 100) ? "<html><table width=\"500\" border=\"0\" cellspacing=\"0\">" + "<tr><td>" + value.replaceAll("\n", "<br>") + "</td></tr></table></html>" : value)); if (stackRow.getCrop() == CROP_START) { value = "..." + value.substring(value.length() - maxFeatureValueLength - 1); } else if (stackRow.getCrop() == CROP_END) { value = value.substring(0, maxFeatureValueLength - 2) + "..."; } else {// cut in the middle value = value.substring(0, maxFeatureValueLength / 2) + "..." + value.substring(value.length() - (maxFeatureValueLength / 2)); } } label.setText(value); label.setBackground(AnnotationSetsView.getColor(stackRow.getSet(), ann.getType())); label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); label.setOpaque(true); label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, String.valueOf(ann.getId()))); // show the feature values in the tooltip if (!ann.getFeatures().isEmpty()) { String width = (Strings.toString(ann.getFeatures()).length() > 100) ? "500" : "100%"; String toolTip = "<html><table width=\"" + width + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">"; Color color = (Color) UIManager.get("ToolTip.background"); float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); color = Color.getHSBColor(hsb[0], hsb[1], Math.max(0f, hsb[2] - hsb[2] * 0.075f)); // darken the color String hexColor = Integer.toHexString(color.getRed()) + Integer.toHexString(color.getGreen()) + Integer.toHexString(color.getBlue()); boolean odd = false; // alternate background color every other row List<Object> features = new ArrayList<Object>(ann.getFeatures().keySet()); //sort the features into alphabetical order Collections.sort(features, new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { return o1.toString().compareToIgnoreCase(o2.toString()); } }); for (Object key : features) { String fv = Strings.toString(ann.getFeatures().get(key)); toolTip += "<tr align=\"left\"" + (odd ? " bgcolor=\"#" + hexColor + "\"" : "") + "><td><strong>" + key + "</strong></td><td>" + ((fv.length() > 500) ? "<textarea rows=\"20\" cols=\"40\" cellspacing=\"0\">" + StringEscapeUtils .escapeHtml(fv.replaceAll("(.{50,60})\\b", "$1\n")) + "</textarea>" : StringEscapeUtils.escapeHtml(fv).replaceAll("\n", "<br>")) + "</td></tr>"; odd = !odd; } label.setToolTipText(toolTip + "</table></html>"); } else { label.setToolTipText("No features."); } if (!feature.equals("")) { label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, feature, Strings.toString(ann.getFeatures().get(feature)), String.valueOf(ann.getId()))); } // find the first empty row span for this annotation int oldGridy = gbc.gridy; for (int y = oldGridy; y <= (gridyMax + 1); y++) { // for each cell of this row where spans the annotation boolean xSpanIsEmpty = true; for (int x = gbc.gridx; (x < (gbc.gridx + gbc.gridwidth)) && xSpanIsEmpty; x++) { xSpanIsEmpty = !(gridSet.containsKey(x) && gridSet.get(x).contains(y)); } if (xSpanIsEmpty) { gbc.gridy = y; break; } } // save the column x and row y of the current value TreeSet<Integer> ts; for (int x = gbc.gridx; x < (gbc.gridx + gbc.gridwidth); x++) { ts = gridSet.get(x); if (ts == null) { ts = new TreeSet<Integer>(); } ts.add(gbc.gridy); gridSet.put(x, ts); } add(label, gbc); gridyMax = Math.max(gridyMax, gbc.gridy); gbc.gridy = oldGridy; } // add a button at the end of the row gbc.gridwidth = 1; if (stackRow.getLastColumnButton() != null) { // last cell of the row gbc.gridx = Math.min(text.length(), maxTextLength) + 1; gbc.insets = new Insets(0, 10, 3, 0); gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; add(stackRow.getLastColumnButton(), gbc); gbc.insets = new Insets(0, 0, 3, 0); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; } // set the new gridy to the maximum row we put a value gbc.gridy = gridyMax; } if (lastRowButton != null) { // add a configuration button on the last row gbc.insets = new java.awt.Insets(0, 10, 0, 10); gbc.gridx = 0; gbc.gridy++; add(lastRowButton, gbc); } // add an empty cell that takes all remaining space to // align the visible cells at the top-left corner gbc.gridy++; gbc.gridx = Math.min(text.length(), maxTextLength) + 1; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = GridBagConstraints.REMAINDER; gbc.weightx = 1; gbc.weighty = 1; add(new JLabel(""), gbc); validate(); updateUI(); }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
public FloatRangeSlider() { super();/*from ww w . j a v a 2 s . c om*/ addMouseWheelListener(e -> { int rotation = e.getWheelRotation(); float[] float_values = (float[]) (currentParameter.getValue()); currentValue0 = float_values[0]; currentValue1 = float_values[1]; minimum = float_values[2]; maximum = float_values[3]; float change = (currentValue1 - currentValue0 + 1) * rotation * Utils.getMouseWheelClickFactor(); currentValue0 += change; currentValue1 += change; if (!((e.getModifiers() & java.awt.event.InputEvent.ALT_MASK) > 0)) { if (currentValue1 > maximum) { float difference = currentValue1 - currentValue0; currentValue1 = maximum; currentValue0 = currentValue1 - difference; } if (currentValue0 < minimum) { float difference = currentValue1 - currentValue0; currentValue0 = minimum; currentValue1 = currentValue0 + difference; } } currentParameter.setValue(new float[] { currentValue0, currentValue1, minimum, maximum }); readInValuesFromParameter(); updateDisplays(); currentParameter.fireValueChanged(false, false, true); }); nf.setGroupingUsed(true); nf.setMaximumFractionDigits(5); nf.setMaximumIntegerDigits(10); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 4; cForHistogram = (GridBagConstraints) c.clone(); panelForHistogram = new JPanel(); panelForHistogram.setPreferredSize(new Dimension(200, 150)); panelForHistogram.setLayout(new BorderLayout()); c.gridx = 0; c.gridy = 1;// 1 c.weighty = 0.0; c.weightx = 0.0; c.gridwidth = 4; add(Box.createRigidArea(new Dimension(0, 5)), c); slider = new RangeSlider(0, 20); slider.addChangeListener(new sliderListener()); c.gridx = 0; c.gridy = 2; c.weighty = 0.0; c.weightx = 0.0; c.gridwidth = 4; add(slider, c); c.gridx = 0; c.gridy = 3; c.weighty = 0.0; c.weightx = 1.0; c.gridwidth = 4; Component comp = Box.createRigidArea(new Dimension(0, 10)); ((JComponent) comp).setOpaque(true); add(comp, c); c.gridwidth = 1; final textBoxListener minMaxListener = new textBoxListener(); currentTextValue0 = new JTextField(""); currentTextValue1 = new JTextField(""); currentTextValue0.addActionListener(new textBoxListenerTriggersUpdate()); currentTextValue1.addActionListener(new textBoxListenerTriggersUpdate()); Font smallerFont = new Font(currentTextValue0.getFont().getName(), currentTextValue0.getFont().getStyle(), currentTextValue0.getFont().getSize() - 2); textMinimum = new JTextField("0"); textMinimum.setFont(smallerFont); textMinimum.addActionListener(minMaxListener); textMaximum = new JTextField("50"); textMaximum.setFont(smallerFont); textMaximum.addActionListener(minMaxListener); textMaximum.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { minMaxListener.actionPerformed(new ActionEvent(textMaximum, 0, "")); } }); textMinimum.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { minMaxListener.actionPerformed(new ActionEvent(textMinimum, 0, "")); } }); textValueFrame = new JPanel(); textValueFrame.setBackground(getBackground()); textValueFrame.setLayout(new GridBagLayout()); c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.1; textValueFrame.add(textMinimum, c); c.gridx = 1; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.3; textValueFrame.add(currentTextValue0, c); c.gridx = 2; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.3; textValueFrame.add(currentTextValue1, c); c.gridx = 3; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.1; textValueFrame.add(textMaximum, c); c.gridx = 0; c.gridy = 4; c.weighty = 0.0; c.weightx = 0.3; c.gridwidth = 4; add(textValueFrame, c); c.gridwidth = 1; parameterName = new JLabel("parameter"); c.gridx = 0; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.01; c.gridwidth = 1; add(parameterName, c); resetMin = new JButton("Min"); resetMin.setActionCommand("Reset Min"); resetMin.addActionListener(new buttonListener()); resetMax = new JButton("Max"); resetMax.setActionCommand("Reset Max"); resetMax.addActionListener(new buttonListener()); resetRange = new JButton("MinMax"); resetRange.setActionCommand("Reset Range"); resetRange.addActionListener(new buttonListener()); c.gridx = 1; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.2; c.gridwidth = 1; add(resetMin, c); c.gridx = 2; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.2; c.gridwidth = 1; add(resetMax, c); c.gridx = 3; c.gridy = 5; c.weighty = 0.0; c.weightx = 0.2; c.gridwidth = 1; add(resetRange, c); // ,resetMax,resetRange; }
From source file:de.juwimm.cms.gui.admin.PanUnitGroupPerUser.java
void jbInit() throws Exception { this.setLayout(new GridBagLayout()); this.unitPickData = new PickListData(); this.unitPickData.setLeftLabel(rb.getString("panel.admin.tab.units.assigned")); this.unitPickData.setRightLabel(rb.getString("panel.admin.tab.units.all")); this.groupPickData = new PickListData(); this.groupPickData.setLeftLabel(rb.getString("panel.admin.tab.groups.assigned")); this.groupPickData.setRightLabel(rb.getString("panel.admin.tab.groups.all")); this.panUnitPick = new PickListPanel(this.unitPickData); this.panGroupPick = new PickListPanel(this.groupPickData); this.btnSave.setText(rb.getString("dialog.save")); this.lblUser.setText(rb.getString("panel.login.username")); this.btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { save();/*from w w w . ja v a2s. c o m*/ } }); this.tblUser = new JTable(); JScrollPane scrollUser = new NoResizeScrollPane(tblUser); this.add(lblUser, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 5, 0), 0, 0)); this.add(scrollUser, new GridBagConstraints(0, 1, 1, 2, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 10, 0, 0), 0, 0)); this.add(btnSave, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(10, 10, 10, 0), 0, 0)); this.add(this.panUnitPick, new GridBagConstraints(1, 0, 1, 2, 2.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 10, 0, 10), 0, 0)); this.add(this.panGroupPick, new GridBagConstraints(1, 2, 1, 1, 2.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 10, 0, 10), 0, 0)); }
From source file:org.n52.oxf.ui.swing.ChartDialog.java
/** * initializes (or updates) the JFreeChart->ChartPanel. * //from w w w. j ava 2s . c om * @param parameters * @param selectedfeatures */ private void initChartPanel(OXFFeatureCollection observations, ParameterContainer paramCon) { MyGridBagLayout mainLayout = (MyGridBagLayout) getContentPane().getLayout(); int chartPanelPosition = 3; if (getContentPane().getComponentCount() > chartPanelPosition) { getContentPane().remove(chartPanelPosition); } JFreeChart chart = chartRenderer.renderChart(observations, paramCon); org.jfree.chart.ChartPanel chartPanel = new org.jfree.chart.ChartPanel(chart); chartPanel.setMouseZoomable(true, true); mainLayout.addComponent(chartPanelPosition, chartPanel, 0, 0, 2, 1, 100, 100, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(9, 9, 9, 9)); getContentPane().validate(); }