List of usage examples for java.awt GridBagConstraints GridBagConstraints
public GridBagConstraints()
From source file:coreferenceresolver.gui.MarkupGUI.java
public MarkupGUI() throws IOException { highlightPainters = new ArrayList<>(); for (int i = 0; i < COLORS.length; ++i) { DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter( COLORS[i]);// ww w . j a v a 2 s . c o m highlightPainters.add(highlightPainter); } defaulPath = FileUtils.readFileToString(new File(".\\src\\coreferenceresolver\\gui\\defaultpath")); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new BorderLayout()); this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); //create menu items JMenuItem importMenuItem = new JMenuItem("Import"); JMenuItem exportMenuItem = new JMenuItem("Export"); fileMenu.add(importMenuItem); fileMenu.add(exportMenuItem); menuBar.add(fileMenu); this.setJMenuBar(menuBar); ScrollablePanel mainPanel = new ScrollablePanel(); mainPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.NONE); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); //IMPORT BUTTON importMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // MarkupGUI.reviewElements.clear(); // MarkupGUI.markupReviews.clear(); JFileChooser markupFileChooser = new JFileChooser(defaulPath); markupFileChooser.setDialogTitle("Choose your markup file"); markupFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { final JDialog d = new JDialog(); JPanel p1 = new JPanel(new GridBagLayout()); p1.add(new JLabel("Please Wait..."), new GridBagConstraints()); d.getContentPane().add(p1); d.setSize(100, 100); d.setLocationRelativeTo(null); d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); d.setModal(true); SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws IOException, BadLocationException { readMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath()); for (int i = 0; i < markupReviews.size(); ++i) { mainPanel.add(newReviewPanel(markupReviews.get(i), i)); } return null; } protected void done() { MarkupGUI.this.revalidate(); d.dispose(); } }; worker.execute(); d.setVisible(true); } else { return; } } }); //EXPORT BUTTON: GET NEW VALUE (REF, TYPE) OF NPs exportMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser markupFileChooser = new JFileChooser(defaulPath); markupFileChooser.setDialogTitle("Choose where your markup file saved"); markupFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (markupFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { final JDialog d = new JDialog(); JPanel p1 = new JPanel(new GridBagLayout()); p1.add(new JLabel("Please Wait..."), new GridBagConstraints()); d.getContentPane().add(p1); d.setSize(100, 100); d.setLocationRelativeTo(null); d.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); d.setModal(true); SwingWorker<?, ?> worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws IOException { for (Review review : markupReviews) { generateNPsRef(review); } int i = 0; for (ReviewElement reviewElement : reviewElements) { int j = 0; for (Element element : reviewElement.elements) { String newType = element.typeSpinner.getValue().toString(); if (newType.equals("Object")) { markupReviews.get(i).getNounPhrases().get(j).setType(0); } else if (newType.equals("Attribute")) { markupReviews.get(i).getNounPhrases().get(j).setType(3); } else if (newType.equals("Other")) { markupReviews.get(i).getNounPhrases().get(j).setType(1); } else if (newType.equals("Candidate")) { markupReviews.get(i).getNounPhrases().get(j).setType(2); } ++j; } ++i; } initMarkupFile(markupFileChooser.getSelectedFile().getAbsolutePath() + File.separator + "markup.out.txt"); return null; } protected void done() { d.dispose(); try { Desktop.getDesktop() .open(new File(markupFileChooser.getSelectedFile().getAbsolutePath())); } catch (IOException ex) { Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex); } } }; worker.execute(); d.setVisible(true); } else { return; } } }); JScrollPane scrollMainPane = new JScrollPane(mainPanel); scrollMainPane.getVerticalScrollBar().setUnitIncrement(16); scrollMainPane.setPreferredSize(new Dimension(this.getWidth(), this.getHeight())); scrollMainPane.setSize(this.getWidth(), this.getHeight()); this.setResizable(false); this.add(scrollMainPane, BorderLayout.CENTER); this.setExtendedState(JFrame.MAXIMIZED_BOTH); this.pack(); }
From source file:gate.gui.docview.AnnotationStack.java
/** * Draw the annotation stack in a JPanel with a GridBagLayout. *///from www . ja v a 2 s.c om 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:com.choicemaker.cm.modelmaker.gui.panels.StatisticsHistogramPanel.java
private void layoutPanel() { GridBagLayout layout = new GridBagLayout(); setLayout(layout);//from w ww . jav a 2 s . c o m GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 10, 5, 10); //Row 0.......................................................... //histo c.gridy = 0; c.gridx = 0; c.gridwidth = 5; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; add(histoPanel, c); //Row 1.......................................................... //binWidthLabel c.gridy = 1; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.EAST; layout.setConstraints(binWidthLabel, c); add(binWidthLabel); //binWidthField c.gridx = 2; c.ipadx = 10; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; layout.setConstraints(binWidthField, c); add(binWidthField); }
From source file:com.vgi.mafscaling.OpenLoop.java
private void createRunTables(JPanel dataRunPanel) { GridBagConstraints gbc_run = new GridBagConstraints(); gbc_run.anchor = GridBagConstraints.PAGE_START; gbc_run.insets = new Insets(0, 2, 0, 2); for (int i = 0; i < RunCount; ++i) { runTables[i] = new JTable(); JTable table = runTables[i]; table.getTableHeader().setReorderingAllowed(false); table.setModel(new DefaultTableModel(RunRowsCount, 3)); table.setColumnSelectionAllowed(true); table.setCellSelectionEnabled(true); table.setBorder(new LineBorder(new Color(0, 0, 0))); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getColumnModel().getColumn(0) .setHeaderValue("<html><center>Engine<br>Speed<br>(RPM)<br></center></html>"); table.getColumnModel().getColumn(1) .setHeaderValue("<html><center>MAF<br>Sensor<br>Voltage<br></center></html>"); table.getColumnModel().getColumn(2) .setHeaderValue("<html><center>AFR<br>Error<br>%<br></center></html>"); Utils.initializeTable(table, ColumnWidth); excelAdapter.addTable(table, true, false); gbc_run.gridx = i;//from w ww . j av a 2 s .c om gbc_run.gridy = 0; dataRunPanel.add(table.getTableHeader(), gbc_run); gbc_run.gridy = 1; dataRunPanel.add(table, gbc_run); } }
From source file:com.digitalgeneralists.assurance.ui.components.ScanDefinitionPanel.java
@Override protected void initializeComponent() { if (!this.initialized) { if (this.definition == null) { mode = AssuranceDialogMode.ADD; this.dialogTitle = "Add New Scan Definition"; this.definition = new ScanDefinition(); } else {/*from w w w.j a v a2 s . c o m*/ mode = AssuranceDialogMode.EDIT; this.dialogTitle = "Edit Scan Definition"; } GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); final JPanel optionsPanel = new JPanel(); optionsPanel.setLayout(new GridBagLayout()); Border optionsBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); optionsBorder = BorderFactory.createTitledBorder(optionsBorder, "Merge Options", TitledBorder.CENTER, TitledBorder.TOP); GridBagConstraints nameTextFieldConstraints = new GridBagConstraints(); nameTextFieldConstraints.anchor = GridBagConstraints.NORTH; nameTextFieldConstraints.fill = GridBagConstraints.HORIZONTAL; nameTextFieldConstraints.gridx = 0; nameTextFieldConstraints.gridy = 0; nameTextFieldConstraints.weightx = 1.0; nameTextFieldConstraints.weighty = 1.0; nameTextFieldConstraints.gridheight = 1; nameTextFieldConstraints.gridwidth = 2; nameTextFieldConstraints.insets = new Insets(10, 5, 0, 5); this.nameTextField.setText(this.definition.getName()); this.nameTextField.getDocument().addDocumentListener(this.textPropertyValidationListener); this.add(this.nameTextField, nameTextFieldConstraints); Border existingScanMappingsPanelBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); existingScanMappingsPanelBorder = BorderFactory.createTitledBorder(existingScanMappingsPanelBorder, "Paths", TitledBorder.CENTER, TitledBorder.TOP); GridBagConstraints existingScanMappingsPanelConstraints = new GridBagConstraints(); existingScanMappingsPanelConstraints.anchor = GridBagConstraints.WEST; existingScanMappingsPanelConstraints.fill = GridBagConstraints.BOTH; existingScanMappingsPanelConstraints.gridx = 0; existingScanMappingsPanelConstraints.gridy = 1; existingScanMappingsPanelConstraints.weightx = 1.0; existingScanMappingsPanelConstraints.weighty = 1.0; existingScanMappingsPanelConstraints.gridheight = 1; existingScanMappingsPanelConstraints.gridwidth = 2; existingScanMappingsPanelConstraints.insets = new Insets(5, 5, 0, 5); JPanel existingScanMappingsPanel = new JPanel(); GridBagLayout panelGridbag = new GridBagLayout(); existingScanMappingsPanel.setLayout(panelGridbag); existingScanMappingsPanel.setBorder(existingScanMappingsPanelBorder); this.add(existingScanMappingsPanel, existingScanMappingsPanelConstraints); GridBagConstraints existingScanMappingsListConstraints = new GridBagConstraints(); existingScanMappingsListConstraints.anchor = GridBagConstraints.WEST; existingScanMappingsListConstraints.fill = GridBagConstraints.BOTH; existingScanMappingsListConstraints.gridx = 0; existingScanMappingsListConstraints.gridy = 0; existingScanMappingsListConstraints.weightx = 1.0; existingScanMappingsListConstraints.weighty = 0.9; existingScanMappingsListConstraints.gridheight = 1; existingScanMappingsListConstraints.gridwidth = 2; existingScanMappingsListConstraints.insets = new Insets(5, 5, 5, 5); this.definition = (ScanDefinition) ModelUtils.initializeEntity(this.definition, ScanDefinition.SCAN_MAPPING_PROPERTY); this.scanMappingsList = new ListInputPanel<ScanMappingDefinition>(this.definition, this); existingScanMappingsPanel.add(this.scanMappingsList, existingScanMappingsListConstraints); GridBagConstraints optionsPanelConstraints = new GridBagConstraints(); optionsPanelConstraints.anchor = GridBagConstraints.SOUTH; optionsPanelConstraints.fill = GridBagConstraints.HORIZONTAL; optionsPanelConstraints.gridx = 0; optionsPanelConstraints.gridy = 3; optionsPanelConstraints.weightx = 1.0; optionsPanelConstraints.weighty = 1.0; optionsPanelConstraints.gridheight = 1; optionsPanelConstraints.gridwidth = 2; optionsPanelConstraints.insets = new Insets(5, 5, 5, 5); optionsPanel.setBorder(optionsBorder); this.add(optionsPanel, optionsPanelConstraints); GridBagConstraints strategyLabelConstraints = new GridBagConstraints(); strategyLabelConstraints.anchor = GridBagConstraints.WEST; strategyLabelConstraints.fill = GridBagConstraints.BOTH; strategyLabelConstraints.gridx = 0; strategyLabelConstraints.gridy = 0; strategyLabelConstraints.weightx = 1.0; strategyLabelConstraints.weighty = 1.0; strategyLabelConstraints.gridheight = 1; strategyLabelConstraints.gridwidth = 1; strategyLabelConstraints.insets = new Insets(5, 5, 0, 5); final JLabel strategyLabel = new JLabel("Strategy", SwingConstants.RIGHT); optionsPanel.add(strategyLabel, strategyLabelConstraints); GridBagConstraints strategyComboBoxConstraints = new GridBagConstraints(); strategyComboBoxConstraints.anchor = GridBagConstraints.WEST; strategyComboBoxConstraints.fill = GridBagConstraints.VERTICAL; strategyComboBoxConstraints.gridx = 1; strategyComboBoxConstraints.gridy = 0; strategyComboBoxConstraints.weightx = 1.0; strategyComboBoxConstraints.weighty = 1.0; strategyComboBoxConstraints.gridheight = 1; strategyComboBoxConstraints.gridwidth = 1; strategyComboBoxConstraints.insets = new Insets(5, 5, 0, 5); String[] strategyLabels = { "Source", "Target", "Both" }; this.strategyComboBox = new JComboBox<String>(strategyLabels); // NOTE: We should have better validation of the data state for these controls. // We could run into problems as the application versions over time. this.strategyComboBox.setSelectedIndex(this.definition.getMergeStrategy().ordinal()); this.strategyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { validateFormState(); } }); optionsPanel.add(this.strategyComboBox, strategyComboBoxConstraints); GridBagConstraints autoMergeCheckBoxConstraints = new GridBagConstraints(); autoMergeCheckBoxConstraints.gridx = 0; autoMergeCheckBoxConstraints.gridy = 1; autoMergeCheckBoxConstraints.weightx = 1.0; autoMergeCheckBoxConstraints.weighty = 1.0; autoMergeCheckBoxConstraints.gridheight = 1; autoMergeCheckBoxConstraints.gridwidth = 2; autoMergeCheckBoxConstraints.insets = new Insets(2, 5, 5, 5); this.autoMergeCheckBox.setHorizontalTextPosition(SwingConstants.LEFT); this.autoMergeCheckBox.setSelected(this.definition.getAutoResolveConflicts()); this.autoMergeCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { validateFormState(); } }); optionsPanel.add(this.autoMergeCheckBox, autoMergeCheckBoxConstraints); GridBagConstraints includeNonCreationTimestampsCheckBoxConstraints = new GridBagConstraints(); includeNonCreationTimestampsCheckBoxConstraints.gridx = 0; includeNonCreationTimestampsCheckBoxConstraints.gridy = 2; includeNonCreationTimestampsCheckBoxConstraints.weightx = 1.0; includeNonCreationTimestampsCheckBoxConstraints.weighty = 1.0; includeNonCreationTimestampsCheckBoxConstraints.gridheight = 1; includeNonCreationTimestampsCheckBoxConstraints.gridwidth = 2; includeNonCreationTimestampsCheckBoxConstraints.insets = new Insets(2, 5, 5, 5); this.includeNonCreationTimestampCheckBox.setHorizontalTextPosition(SwingConstants.LEFT); this.includeNonCreationTimestampCheckBox.setSelected(this.definition.getIncludeNonCreationTimestamps()); this.includeNonCreationTimestampCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { validateFormState(); } }); optionsPanel.add(this.includeNonCreationTimestampCheckBox, includeNonCreationTimestampsCheckBoxConstraints); GridBagConstraints advancedAttributesCheckBoxConstraints = new GridBagConstraints(); advancedAttributesCheckBoxConstraints.gridx = 0; advancedAttributesCheckBoxConstraints.gridy = 3; advancedAttributesCheckBoxConstraints.weightx = 1.0; advancedAttributesCheckBoxConstraints.weighty = 1.0; advancedAttributesCheckBoxConstraints.gridheight = 1; advancedAttributesCheckBoxConstraints.gridwidth = 2; advancedAttributesCheckBoxConstraints.insets = new Insets(2, 5, 5, 5); this.includeAdvancedAttributesCheckBox.setHorizontalTextPosition(SwingConstants.LEFT); this.includeAdvancedAttributesCheckBox.setSelected(this.definition.getAutoResolveConflicts()); this.includeAdvancedAttributesCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { validateFormState(); } }); optionsPanel.add(this.includeAdvancedAttributesCheckBox, advancedAttributesCheckBoxConstraints); this.scanMappingsList.loadData(); if (this.getMode() == AssuranceDialogMode.EDIT) { this.validateFormState(); } this.initialized = true; } }
From source file:be.ac.ua.comp.scarletnebula.gui.addserverwizard.ChooseImagePage.java
private JPanel getSearchPanel(final TableRowSorter<MachineImageTableModel> sorter) { final JPanel searchPanel = new JPanel(new GridBagLayout()); searchPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20)); add(searchPanel, BorderLayout.NORTH); final PlatformComboBox platformComboBox = new PlatformComboBox(); final GridBagConstraints c = new GridBagConstraints(); c.weightx = 0.0;//from w w w.ja v a2 s . com c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.insets = new Insets(0, 0, 0, 5); searchPanel.add(platformComboBox, c); final ArchitectureComboBox architectureComboBox = new ArchitectureComboBox(); c.gridx = 1; searchPanel.add(architectureComboBox, c); final BetterTextField searchField = new BetterTextField(); searchField.setPlaceHolder("Search terms"); searchField.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); c.gridx = 2; c.weightx = 1.0; c.insets = new Insets(0, 0, 0, 0); searchPanel.add(searchField, c); searchField.addActionListener( new SearchFieldListener(architectureComboBox, sorter, platformComboBox, searchField)); return searchPanel; }
From source file:com.idealista.solrmeter.view.statistic.CacheHistoryPanel.java
/** * Creates the left panel, with the combo boxes to select wether to see hit ratio * or specific cache data, and if specific cache data is selected, will also show * the combo box to select the cache and the cumulative information * @return//from ww w . j a v a2 s. c o m */ private Component createLeftPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = 0; constraints.gridy = 0; constraints.weighty = 0; constraints.fill = GridBagConstraints.BOTH; constraints.insets = new Insets(1, 1, 1, 1); for (Component component : this.createControlPanel()) { panel.add(component, constraints); constraints.gridy++; } cumulativeDataPanel = this.createCumulativeDataPanel(); panel.add(cumulativeDataPanel, constraints); constraints.gridy++; constraints.weighty = 2.0; panel.add(Box.createVerticalGlue(), constraints); panel.setMaximumSize(new Dimension(100, Integer.MAX_VALUE)); return panel; }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
private void initializeGUI() { frame = new JFrame("Hybris Demo GUI"); frame.setIconImage(new ImageIcon(getClass().getResource("/clouds.png")).getImage()); frame.setBounds(100, 100, 650, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new GridBagLayout()); JPanel cloudParentPanel = new JPanel(new GridLayout(1, 2, 10, 10)); JPanel hybrisPanel = new JPanel(new GridBagLayout()); JPanel cloudsPanel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0;//from w w w.j a va 2 s . c o m gbc.weighty = 1.0; gbc.insets = new Insets(5, 5, 5, 5); gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = 3; gbc.gridheight = 1; gbc.gridx = 0; gbc.gridy = 0; hybrisPanel.add(new JLabel("<html><b>Hybris</b></html>"), gbc); gbc.gridwidth = 3; gbc.gridheight = 3; gbc.gridx = 0; gbc.gridy = 1; lstHybris = new JList<String>(lmHybris); lstHybris.setPreferredSize(new java.awt.Dimension(100, 500)); lstHybris.setMinimumSize(new java.awt.Dimension(100, 440)); hybrisPanel.add(lstHybris, gbc); gbc.anchor = GridBagConstraints.SOUTH; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = 1; gbc.gridx = 0; gbc.gridy = 4; btnPut = new JButton("Put"); hybrisPanel.add(btnPut, gbc); gbc.gridx = 1; gbc.gridy = 4; btnGet = new JButton("Get"); hybrisPanel.add(btnGet, gbc); gbc.gridx = 2; gbc.gridy = 4; btnDelete = new JButton("Delete"); hybrisPanel.add(btnDelete, gbc); gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; cloudsPanel.add(new JLabel("<html><b>Amazon S3</b></html>"), gbc); gbc.gridheight = 2; gbc.gridy = 1; lstAmazon = new JList<String>(lmAmazon); lstAmazon.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); lstAmazon.setPreferredSize(new java.awt.Dimension(100, 100)); cloudsPanel.add(lstAmazon, gbc); gbc.gridy = 3; gbc.gridheight = 1; cloudsPanel.add(new JLabel("<html><b>Microsoft Azure</b></html>"), gbc); gbc.gridheight = 2; gbc.gridy = 4; lstAzure = new JList<String>(lmAzure); lstAzure.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); lstAzure.setPreferredSize(new java.awt.Dimension(100, 100)); cloudsPanel.add(lstAzure, gbc); gbc.gridy = 6; gbc.gridheight = 1; cloudsPanel.add(new JLabel("<html><b>Google Cloud Storage</b></html>"), gbc); gbc.gridheight = 2; gbc.gridy = 7; lstGoogle = new JList<String>(lmGoogle); lstGoogle.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); lstGoogle.setPreferredSize(new java.awt.Dimension(100, 100)); cloudsPanel.add(lstGoogle, gbc); gbc.gridy = 9; gbc.gridheight = 1; cloudsPanel.add(new JLabel("<html><b>Rackspace Cloud Files</b></html>"), gbc); gbc.gridheight = 2; gbc.gridy = 10; lstRackspace = new JList<String>(lmRackspace); lstRackspace.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); lstRackspace.setPreferredSize(new java.awt.Dimension(100, 100)); cloudsPanel.add(lstRackspace, gbc); cloudParentPanel.add(hybrisPanel); cloudParentPanel.add(cloudsPanel); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; frame.add(cloudParentPanel, gbc); gbc.gridx = 0; gbc.gridy = 1; JTextArea jt = new JTextArea(10, 30); JScrollPane scrollPane = new JScrollPane(jt); frame.add(scrollPane, gbc); PrintStream printStream = new PrintStream(new CustomOutputStream(jt)); System.setOut(printStream); System.setErr(printStream); frame.pack(); frame.setSize(550, 800); frame.setResizable(false); lstAmazon.addKeyListener(this); lstAzure.addKeyListener(this); lstGoogle.addKeyListener(this); lstRackspace.addKeyListener(this); lstHybris.addKeyListener(this); lstAmazon.setCellRenderer(this.new MyListRenderer("amazon")); lstGoogle.setCellRenderer(this.new MyListRenderer("google")); lstAzure.setCellRenderer(this.new MyListRenderer("azure")); lstRackspace.setCellRenderer(this.new MyListRenderer("rackspace")); btnGet.addActionListener(this); btnPut.addActionListener(this); btnDelete.addActionListener(this); }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
public FloatRangeSlider() { super();/*from w w w . j av 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:gdt.jgui.entity.webset.JWeblinkEditor.java
/** * The default constructor./* w w w . j a v a 2 s. com*/ */ public JWeblinkEditor() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0 }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0 }; setLayout(gridBagLayout); String icon$ = Support.readHandlerIcon(null, JEntitiesPanel.class, "globe.png"); byte[] ba = Base64.decodeBase64(icon$); ImageIcon icon = new ImageIcon(ba); Image image = icon.getImage().getScaledInstance(24, 24, 0); icon.setImage(image); JLabel iconLabel = new JLabel("Icon"); c = new GridBagConstraints(); c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.FIRST_LINE_START; c.weighty = 0; c.gridx = 0; c.gridy = 0; add(iconLabel, c); iconLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showIconMenu(e); } }); iconIcon = new JLabel(); iconIcon.setIcon(icon); c_0 = new GridBagConstraints(); c_0.anchor = GridBagConstraints.WEST; c_0.insets = new Insets(0, 5, 5, 0); c.anchor = GridBagConstraints.WEST; c_0.gridx = 1; c_0.gridy = 0; add(iconIcon, c_0); iconIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showIconMenu(e); } }); JLabel lblName = new JLabel("Name"); c_1 = new GridBagConstraints(); c_1.insets = new Insets(5, 5, 5, 5); c_1.fill = GridBagConstraints.HORIZONTAL; c_1.gridx = 0; c_1.gridy = 1; add(lblName, c_1); nameField = new JTextField(); c_2 = new GridBagConstraints(); c_2.insets = new Insets(0, 5, 5, 0); c_2.fill = GridBagConstraints.HORIZONTAL; c_2.gridx = 1; c_2.gridy = 1; add(nameField, c_2); JLabel lblUrl = new JLabel("Address"); c_3 = new GridBagConstraints(); c_3.insets = new Insets(5, 5, 5, 5); c_3.fill = GridBagConstraints.HORIZONTAL; c_3.gridx = 0; c_3.gridy = 2; add(lblUrl, c_3); addressField = new JTextField(); c_4 = new GridBagConstraints(); c_4.insets = new Insets(0, 5, 5, 0); c_4.fill = GridBagConstraints.HORIZONTAL; c_4.gridx = 1; c_4.gridy = 2; add(addressField, c_4); JLabel lblLogin = new JLabel("Login"); c_5 = new GridBagConstraints(); c_5.insets = new Insets(5, 5, 5, 5); c_5.fill = GridBagConstraints.HORIZONTAL; c_5.gridx = 0; c_5.gridy = 3; add(lblLogin, c_5); lblLogin.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showLoginMenu(e); } }); loginField = new JTextField(); c_6 = new GridBagConstraints(); c_6.insets = new Insets(0, 5, 5, 0); c_6.fill = GridBagConstraints.HORIZONTAL; c_6.gridx = 1; c_6.gridy = 3; add(loginField, c_6); JLabel lblPassword = new JLabel("Password"); c_7 = new GridBagConstraints(); c_7.insets = new Insets(5, 5, 5, 5); c_7.fill = GridBagConstraints.HORIZONTAL; c_7.gridx = 0; c_7.gridy = 4; add(lblPassword, c_7); lblPassword.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { showPasswordMenu(e); } }); passwordField = new JTextField(); c_8 = new GridBagConstraints(); c_8.insets = new Insets(0, 5, 5, 0); c_8.fill = GridBagConstraints.HORIZONTAL; c_8.gridx = 1; c_8.gridy = 4; add(passwordField, c_8); JPanel bottom = new JPanel(); c_9 = new GridBagConstraints(); c_9.weighty = 1; c_9.fill = GridBagConstraints.VERTICAL; c_9.gridx = 0; c_9.gridy = 5; add(bottom, c_9); }