List of usage examples for java.awt GridBagConstraints REMAINDER
int REMAINDER
To view the source code for java.awt GridBagConstraints REMAINDER.
Click Source Link
From source file:pcgen.gui2.tabs.SummaryInfoTab.java
private void initRightPanel(JPanel rightPanel) { rightPanel.setLayout(new GridBagLayout()); /*/*from ww w . ja v a 2 s .c o m*/ * initialize Components */ racePanel.setOpaque(false); classPanel.setOpaque(false); ageField.setHorizontalAlignment(SwingConstants.RIGHT); expField.setHorizontalAlignment(SwingConstants.RIGHT); nextlevelField.setHorizontalAlignment(SwingConstants.RIGHT); nextlevelField.setEnabled(false); expmodField.setHorizontalAlignment(SwingConstants.RIGHT); raceComboBox.setPrototypeDisplayValue("PrototypeDisplayValue"); //$NON-NLS-1$ classComboBox.setPrototypeDisplayValue("PrototypeDisplayValue"); //$NON-NLS-1$ expaddButton.setMargin(new Insets(0, 8, 0, 8)); expsubtractButton.setMargin(new Insets(0, 8, 0, 8)); hpButton.setMargin(new Insets(0, 0, 0, 0)); JPanel expmodPanel = new JPanel(new GridBagLayout()); JPanel levelPanel = new JPanel(); JLabel raceLabel = createLabel("in_sumRace"); //$NON-NLS-1$ JLabel ageLabel = createLabel("in_sumAge"); //$NON-NLS-1$ JLabel classLabel = createLabel("in_sumClass"); //$NON-NLS-1$ JLabel hpLabel = createLabel("in_sumTotalHP"); //$NON-NLS-1$ JLabel expLabel = createLabel("in_sumCurrentXp"); //$NON-NLS-1$ JLabel nextlevelLabel = createLabel("in_sumNextlevel"); //$NON-NLS-1$ JLabel xpTableLabel = createLabel("in_sumXpTable"); //$NON-NLS-1$ JLabel expmodLabel = createLabel("in_sumExpMod"); //$NON-NLS-1$ expmodLabel.setHorizontalAlignment(SwingConstants.CENTER); initLevelPanel(levelPanel); /* * initialize constant variables */ Insets racePanelInsets = racePanel.getInsets(); Insets classPanelInsets = classPanel.getInsets(); /* * racePanel */ GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(racePanelInsets.top, racePanelInsets.left, 0, 0); gbc.gridwidth = 2; rightPanel.add(raceLabel, gbc); gbc.insets = new Insets(racePanelInsets.top, 1, 1, racePanelInsets.right); gbc.gridwidth = GridBagConstraints.REMAINDER; rightPanel.add(raceComboBox, gbc); gbc.insets = new Insets(0, racePanelInsets.left, 0, 1); gbc.gridwidth = 1; rightPanel.add(ageLabel, gbc); gbc.insets = new Insets(1, 1, 1, 1); rightPanel.add(ageField, gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets = new Insets(1, 1, 1, racePanelInsets.right); rightPanel.add(ageComboBox, gbc); gbc.insets = new Insets(1, racePanelInsets.left, racePanelInsets.bottom, racePanelInsets.right); rightPanel.add(createMonsterButton, gbc); /* * classPanel */ gbc.gridwidth = 2; gbc.insets = new Insets(classPanelInsets.top, classPanelInsets.left, 0, 0); rightPanel.add(classLabel, gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.insets = new Insets(classPanelInsets.top, 0, 0, classPanelInsets.right); rightPanel.add(classComboBox, gbc); gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(7, classPanelInsets.left, 0, classPanelInsets.right); rightPanel.add(levelPanel, gbc); gbc.insets.top = 0; gbc.insets.bottom = 10; gbc.weighty = 0; { JPanel hpPanel = new JPanel(new FlowLayout()); hpPanel.add(hpLabel); hpPanel.add(Box.createHorizontalStrut(3)); hpPanel.add(totalHPLabel); hpPanel.add(hpButton); rightPanel.add(hpPanel, gbc); } gbc.insets.bottom = 0; GridBagConstraints leftgbc = new GridBagConstraints(); leftgbc.insets = new Insets(0, classPanelInsets.left, 0, 0); leftgbc.gridwidth = 2; leftgbc.fill = GridBagConstraints.BOTH; GridBagConstraints rightgbc = new GridBagConstraints(); rightgbc.insets = new Insets(0, 0, 0, classPanelInsets.right); rightgbc.gridwidth = GridBagConstraints.REMAINDER; rightgbc.fill = GridBagConstraints.BOTH; rightPanel.add(expLabel, leftgbc); rightPanel.add(expField, rightgbc); rightPanel.add(nextlevelLabel, leftgbc); rightPanel.add(nextlevelField, rightgbc); rightPanel.add(xpTableLabel, leftgbc); rightPanel.add(xpTableComboBox, rightgbc); gbc.insets.top = 10; rightPanel.add(expmodLabel, gbc); { GridBagConstraints gbc2 = new GridBagConstraints(); gbc2.fill = GridBagConstraints.HORIZONTAL; gbc2.weightx = 1.0; gbc2.insets = new Insets(0, 1, 0, 1); expmodPanel.add(expaddButton, gbc2); expmodPanel.add(expsubtractButton, gbc2); } leftgbc.insets.bottom = classPanelInsets.bottom; leftgbc.weightx = 0.3; rightPanel.add(expmodPanel, leftgbc); rightgbc.insets.bottom = classPanelInsets.bottom; rightgbc.weightx = 0.7; rightPanel.add(expmodField, rightgbc); gbc = new GridBagConstraints(); gbc.gridx = gbc.gridy = 0; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 3; gbc.fill = GridBagConstraints.BOTH; rightPanel.add(racePanel, gbc); gbc.gridy = 3; gbc.gridheight = GridBagConstraints.REMAINDER; rightPanel.add(classPanel, gbc); }
From source file:net.sf.jabref.gui.groups.GroupSelector.java
/** * The first element for each group defines which field to use for the quicksearch. The next two define the name and * regexp for the group./* w w w . j a va 2 s . c o m*/ */ public GroupSelector(JabRefFrame frame, SidePaneManager manager) { super(manager, IconTheme.JabRefIcon.TOGGLE_GROUPS.getIcon(), Localization.lang("Groups")); this.frame = frame; hideNonHits = new JRadioButtonMenuItem(Localization.lang("Hide non-hits"), !Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); grayOut = new JRadioButtonMenuItem(Localization.lang("Gray out non-hits"), Globals.prefs.getBoolean(JabRefPreferences.GRAY_OUT_NON_HITS)); ButtonGroup nonHits = new ButtonGroup(); nonHits.add(hideNonHits); nonHits.add(grayOut); floatCb.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS, floatCb.isSelected())); andCb.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, andCb.isSelected())); invCb.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS, invCb.isSelected())); showOverlappingGroups.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING, showOverlappingGroups.isSelected()); if (!showOverlappingGroups.isSelected()) { groupsTree.setOverlappingGroups(Collections.emptyList()); } } }); grayOut.addChangeListener( event -> Globals.prefs.putBoolean(JabRefPreferences.GRAY_OUT_NON_HITS, grayOut.isSelected())); JRadioButtonMenuItem highlCb = new JRadioButtonMenuItem(Localization.lang("Highlight"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_FLOAT_SELECTIONS)) { floatCb.setSelected(true); highlCb.setSelected(false); } else { highlCb.setSelected(true); floatCb.setSelected(false); } JRadioButtonMenuItem orCb = new JRadioButtonMenuItem(Localization.lang("Union"), false); if (Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS)) { andCb.setSelected(true); orCb.setSelected(false); } else { orCb.setSelected(true); andCb.setSelected(false); } showNumberOfElements.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Globals.prefs.putBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS, showNumberOfElements.isSelected()); if (groupsTree != null) { groupsTree.invalidate(); groupsTree.repaint(); } } }); autoAssignGroup.addChangeListener(event -> Globals.prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected())); invCb.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_INVERT_SELECTIONS)); showOverlappingGroups.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_OVERLAPPING)); editModeIndicator = Globals.prefs.getBoolean(JabRefPreferences.EDIT_GROUP_MEMBERSHIP_MODE); editModeCb.setSelected(editModeIndicator); showNumberOfElements.setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); JButton openSettings = new JButton(IconTheme.JabRefIcon.PREFERENCES.getSmallIcon()); settings.add(andCb); settings.add(orCb); settings.addSeparator(); settings.add(invCb); settings.addSeparator(); settings.add(editModeCb); settings.addSeparator(); settings.add(grayOut); settings.add(hideNonHits); settings.addSeparator(); settings.add(showOverlappingGroups); settings.addSeparator(); settings.add(showNumberOfElements); settings.add(autoAssignGroup); openSettings.addActionListener(e -> { if (!settings.isVisible()) { JButton src = (JButton) e.getSource(); showNumberOfElements .setSelected(Globals.prefs.getBoolean(JabRefPreferences.GROUP_SHOW_NUMBER_OF_ELEMENTS)); autoAssignGroup.setSelected(Globals.prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP)); settings.show(src, 0, openSettings.getHeight()); } }); editModeCb.addActionListener(e -> setEditMode(editModeCb.getState())); JButton newButton = new JButton(IconTheme.JabRefIcon.ADD_NOBOX.getSmallIcon()); int butSize = newButton.getIcon().getIconHeight() + 5; Dimension butDim = new Dimension(butSize, butSize); newButton.setPreferredSize(butDim); newButton.setMinimumSize(butDim); JButton helpButton = new HelpAction(Localization.lang("Help on groups"), HelpFile.GROUP).getHelpButton(); helpButton.setPreferredSize(butDim); helpButton.setMinimumSize(butDim); JButton autoGroup = new JButton(IconTheme.JabRefIcon.AUTO_GROUP.getSmallIcon()); autoGroup.setPreferredSize(butDim); autoGroup.setMinimumSize(butDim); openSettings.setPreferredSize(butDim); openSettings.setMinimumSize(butDim); Insets butIns = new Insets(0, 0, 0, 0); helpButton.setMargin(butIns); openSettings.setMargin(butIns); newButton.addActionListener(e -> { GroupDialog gd = new GroupDialog(frame, panel, null); gd.setVisible(true); if (gd.okPressed()) { AbstractGroup newGroup = gd.getResultingGroup(); groupsRoot.addNewGroup(newGroup, panel.getUndoManager()); panel.markBaseChanged(); frame.output(Localization.lang("Created group \"%0\".", newGroup.getName())); } }); andCb.addActionListener(e -> valueChanged(null)); orCb.addActionListener(e -> valueChanged(null)); invCb.addActionListener(e -> valueChanged(null)); showOverlappingGroups.addActionListener(e -> valueChanged(null)); autoGroup.addActionListener(e -> { AutoGroupDialog gd = new AutoGroupDialog(frame, panel, groupsRoot, Globals.prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD), " .,", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)); gd.setVisible(true); // gd does the operation itself }); floatCb.addActionListener(e -> valueChanged(null)); highlCb.addActionListener(e -> valueChanged(null)); hideNonHits.addActionListener(e -> valueChanged(null)); grayOut.addActionListener(e -> valueChanged(null)); newButton.setToolTipText(Localization.lang("New group")); andCb.setToolTipText(Localization.lang("Display only entries belonging to all selected groups.")); orCb.setToolTipText( Localization.lang("Display all entries belonging to one or more of the selected groups.")); autoGroup.setToolTipText(Localization.lang("Automatically create groups for database.")); openSettings.setToolTipText(Localization.lang("Settings")); invCb.setToolTipText( "<html>" + Localization.lang("Show entries <b>not</b> in group selection") + "</html>"); showOverlappingGroups.setToolTipText(Localization .lang("Highlight groups that contain entries contained in any currently selected group")); floatCb.setToolTipText(Localization.lang("Move entries in group selection to the top")); highlCb.setToolTipText(Localization.lang("Gray out entries not in group selection")); editModeCb.setToolTipText(Localization.lang("Click group to toggle membership of selected entries")); ButtonGroup bgr = new ButtonGroup(); bgr.add(andCb); bgr.add(orCb); ButtonGroup visMode = new ButtonGroup(); visMode.add(floatCb); visMode.add(highlCb); JPanel rootPanel = new JPanel(); GridBagLayout gbl = new GridBagLayout(); rootPanel.setLayout(gbl); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; con.weightx = 1; con.gridwidth = 1; con.gridy = 0; con.gridx = 0; gbl.setConstraints(newButton, con); rootPanel.add(newButton); con.gridx = 1; gbl.setConstraints(autoGroup, con); rootPanel.add(autoGroup); con.gridx = 2; gbl.setConstraints(openSettings, con); rootPanel.add(openSettings); con.gridx = 3; con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(helpButton, con); rootPanel.add(helpButton); groupsTree = new GroupsTree(this); groupsTree.addTreeSelectionListener(this); JScrollPane groupsTreePane = new JScrollPane(groupsTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); groupsTreePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); con.gridwidth = GridBagConstraints.REMAINDER; con.weighty = 1; con.gridx = 0; con.gridwidth = 4; con.gridy = 1; gbl.setConstraints(groupsTreePane, con); rootPanel.add(groupsTreePane); add(rootPanel, BorderLayout.CENTER); setEditMode(editModeIndicator); definePopup(); NodeAction moveNodeUpAction = new MoveNodeUpAction(); moveNodeUpAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_MASK)); NodeAction moveNodeDownAction = new MoveNodeDownAction(); moveNodeDownAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_MASK)); NodeAction moveNodeLeftAction = new MoveNodeLeftAction(); moveNodeLeftAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_MASK)); NodeAction moveNodeRightAction = new MoveNodeRightAction(); moveNodeRightAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_MASK)); setGroups(GroupTreeNode.fromGroup(new AllEntriesGroup())); }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @param containerPanel/*from w ww. j av a2s.c o m*/ */ private void createPlotPreviewPanel(JPanel containerPanel) { JPanel previewPanel = new JPanel(new GridBagLayout()); previewPanel.setPreferredSize(new Dimension(300, 300)); GridBagConstraints itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.gridwidth = GridBagConstraints.REMAINDER; // nominal value color preview { nominalPreviewPanel = nominalPlotter.getChartPanel(); nominalPreviewPanel.setPreferredSize(new Dimension(150, 150)); previewPanel.add(nominalPreviewPanel, itemConstraint); } // add gradient preview { gradientPreviewPanel = gradientPlotter.getChartPanel(); gradientPreviewPanel.setPreferredSize(new Dimension(150, 150)); previewPanel.add(gradientPreviewPanel, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; containerPanel.add(previewPanel, itemConstraint); }
From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java
private void appendLifespanSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints, JPanel mainPanel) {/*www . ja v a 2s .c om*/ SpinnerModel lifespanModel = new SpinnerNumberModel(lifespanInitial, LIFESPAN_MIN, LIFESPAN_MAX, LIFESPAN_STEP); lifespanSpinner = new JSpinner(lifespanModel); JLabel lifespanLabel = new JLabel(lifespanText); lifespanLabel.setLabelFor(lifespanSpinner); constraints.weightx = LAYOUT_LABEL_WEIGHT; constraints.gridwidth = GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(lifespanLabel, constraints); mainPanel.add(lifespanLabel); constraints.weightx = LAYOUT_INPUT_WEIGHT; constraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(lifespanSpinner, constraints); mainPanel.add(lifespanSpinner); }
From source file:de.codesourcery.flocking.KDTree.java
public static void main(String[] args) { final KDTree<Vec2d> tree = new KDTree<Vec2d>(); Random rnd = new Random(System.currentTimeMillis()); for (int i = 0; i < 100; i++) { final double x = rnd.nextDouble() * MODEL_WIDTH; final double y = rnd.nextDouble() * MODEL_HEIGHT; tree.add(x, y, new Vec2d(x, y)); }//from ww w.j a v a 2 s . c o m final MyPanel panel = new MyPanel(tree); panel.setPreferredSize(new Dimension((int) MODEL_WIDTH * 2, (int) MODEL_HEIGHT * 2)); panel.addMouseListener(new MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { final Vec2d p = panel.viewToModel(e.getX(), e.getY()); panel.mark(p.x, p.y, 55); }; }); final JFrame frame = new JFrame("KDTreeTest"); frame.addKeyListener(new KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { }; }); frame.getContentPane().setLayout(new GridBagLayout()); final GridBagConstraints cnstrs = new GridBagConstraints(); cnstrs.fill = GridBagConstraints.BOTH; cnstrs.gridx = GridBagConstraints.REMAINDER; cnstrs.gridy = GridBagConstraints.REMAINDER; cnstrs.weightx = 1.0; cnstrs.weighty = 1.0; frame.getContentPane().add(panel, cnstrs); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java
private void appendSurvivalRateSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints, JPanel mainPanel) {//from w w w. j av a2 s. c o m SpinnerModel survivalRateModel = new SpinnerNumberModel(survivalInitial, SURVIVAL_MIN, SURVIVAL_MAX, SURVIVAL_STEP); survivalRateSpinner = new JSpinner(survivalRateModel); JLabel survivalRateLabel = new JLabel(survivalRateText); survivalRateLabel.setLabelFor(survivalRateSpinner); constraints.weightx = LAYOUT_LABEL_WEIGHT; constraints.gridwidth = GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(survivalRateLabel, constraints); mainPanel.add(survivalRateLabel); constraints.weightx = LAYOUT_INPUT_WEIGHT; constraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(survivalRateSpinner, constraints); mainPanel.add(survivalRateSpinner); }
From source file:com.rapidminer.gui.graphs.GraphViewer.java
private JComponent createControlPanel() { // === mouse behaviour === if (graphMouse != null) { vv.setGraphMouse(graphMouse);/*from ww w . j a v a2s.c o m*/ vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); } transformAction.setEnabled(false); pickingAction.setEnabled(true); vv.addGraphMouseListener(new GraphMouseListener<V>() { @Override public void graphClicked(V vertex, MouseEvent arg1) { } @Override public void graphPressed(V arg0, MouseEvent arg1) { } @Override public void graphReleased(V vertex, MouseEvent arg1) { if (currentMode.equals(ModalGraphMouse.Mode.TRANSFORMING)) { if (graphCreator.getObjectViewer() != null) { vv.getPickedVertexState().clear(); vv.getPickedVertexState().pick(vertex, true); graphCreator.getObjectViewer().showObject(graphCreator.getObject(vertex)); } } } }); JPanel controls = new JPanel(); GridBagLayout gbLayout = new GridBagLayout(); controls.setLayout(gbLayout); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(4, 4, 4, 4); c.weightx = 1; c.weighty = 0; // zooming JToolBar zoomBar = new ExtendedJToolBar(); zoomBar.setLayout(new FlowLayout(FlowLayout.CENTER)); zoomBar.add(new ZoomInAction(this, IconSize.SMALL)); zoomBar.add(new ZoomOutAction(this, IconSize.SMALL)); zoomBar.setBorder(BorderFactory.createTitledBorder("Zoom")); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(zoomBar, c); controls.add(zoomBar); // mode JToolBar modeBar = new ExtendedJToolBar(); modeBar.setLayout(new FlowLayout(FlowLayout.CENTER)); modeBar.add(transformAction); modeBar.add(pickingAction); modeBar.setBorder(BorderFactory.createTitledBorder("Mode")); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(modeBar, c); controls.add(modeBar); // layout selection c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(layoutSelection, c); controls.add(layoutSelection); // show node labels JCheckBox nodeLabels = new JCheckBox("Node Labels", graphCreator.showVertexLabelsDefault()); nodeLabels.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { togglePaintVertexLabels(); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(nodeLabels, c); controls.add(nodeLabels); // show edge labels JCheckBox edgeLabels = new JCheckBox("Edge Labels", graphCreator.showEdgeLabelsDefault()); edgeLabels.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { togglePaintEdgeLabels(); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(edgeLabels, c); controls.add(edgeLabels); // option components for (int i = 0; i < graphCreator.getNumberOfOptionComponents(); i++) { JComponent optionComponent = graphCreator.getOptionComponent(this, i); if (optionComponent != null) { c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(optionComponent, c); controls.add(optionComponent); } } // save image JButton imageButton = new JButton("Save Image..."); imageButton.setToolTipText("Saves an image of the current graph."); imageButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Component tosave = vv; new ExportImageAction(false) { private static final long serialVersionUID = 1L; @Override protected PrintableComponent getPrintableComponent() { return new SimplePrintableComponent(tosave, "Graph"); } }.actionPerformed(e); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(imageButton, c); controls.add(imageButton); // help JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(vv, INSTRUCTIONS); } }); c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(help, c); controls.add(help); JPanel fillPanel = new JPanel(); c.weighty = 1.0d; c.gridwidth = GridBagConstraints.REMAINDER; gbLayout.setConstraints(fillPanel, c); controls.add(fillPanel); return controls; }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @return//w w w. j a v a 2 s . co m */ private JPanel createGradientConfigurationPanel() { // create gradient config panel JPanel gradientConfigPanel = new JPanel(new GridBagLayout()); gradientConfigPanel.setPreferredSize(new Dimension(100, 50)); GridBagConstraints itemConstraint; // add gradient label { JLabel gradientLabel = new ResourceLabel( "plotter.configuration_dialog.color_scheme_dialog.gradient_preview"); itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.insets = new Insets(2, 2, 2, 2); gradientConfigPanel.add(gradientLabel, itemConstraint); } // add combobox panel { JPanel comboBoxPanel = new JPanel(new GridBagLayout()); // gradient start panel { JPanel startGradientPanel = createStartGradientPanel(); itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 1.0; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.anchor = GridBagConstraints.WEST; itemConstraint.fill = GridBagConstraints.HORIZONTAL; comboBoxPanel.add(startGradientPanel, itemConstraint); } // gradient end panel { JPanel endGradientPanel = createEndGradientPanel(); itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 1.0; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.anchor = GridBagConstraints.EAST; itemConstraint.fill = GridBagConstraints.HORIZONTAL; comboBoxPanel.add(endGradientPanel, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 1; itemConstraint.weighty = 0.0; itemConstraint.fill = GridBagConstraints.HORIZONTAL; itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.insets = new Insets(2, 2, 2, 2); gradientConfigPanel.add(comboBoxPanel, itemConstraint); } // add 0.0 label { JLabel zeroLabel = new JLabel("0"); itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(2, 2, 2, 2); gradientConfigPanel.add(zeroLabel, itemConstraint); } // add gradient preview { preview = new GradientPreview(null); itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.insets = new Insets(2, 2, 2, 2); gradientConfigPanel.add(preview, itemConstraint); } // add 1.0 label { JLabel zeroLabel = new JLabel("1"); itemConstraint = new GridBagConstraints(); itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(2, 2, 2, 2); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; gradientConfigPanel.add(zeroLabel, itemConstraint); } return gradientConfigPanel; }
From source file:gate.gui.docview.AnnotationStack.java
/** * Draw the annotation stack in a JPanel with a GridBagLayout. *//* w w w. ja va2s . 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:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java
private void appendMutationRateSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints, JPanel mainPanel) {/*ww w .jav a 2 s .c o m*/ SpinnerModel mutationRateModel = new SpinnerNumberModel(mutationInitial, MUTATION_MIN, MUTATION_MAX, MUTATION_STEP); mutationRateSpinner = new JSpinner(mutationRateModel); JLabel mutationRateLabel = new JLabel(mutationRateText); mutationRateLabel.setLabelFor(mutationRateSpinner); constraints.weightx = LAYOUT_LABEL_WEIGHT; constraints.gridwidth = GridBagConstraints.RELATIVE; gridBagLayout.setConstraints(mutationRateLabel, constraints); mainPanel.add(mutationRateLabel); constraints.weightx = LAYOUT_INPUT_WEIGHT; constraints.gridwidth = GridBagConstraints.REMAINDER; gridBagLayout.setConstraints(mutationRateSpinner, constraints); mainPanel.add(mutationRateSpinner); }