List of usage examples for javax.swing JCheckBox setSelected
public void setSelected(boolean b)
From source file:org.paxle.desktop.impl.dialogues.cconsole.CrawlingConsole.java
private void initOptions() { options.setLayout(new GridBagLayout()); final GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = Utilities.INSETS_ZERO; gbc.anchor = GridBagConstraints.WEST; gbc.gridx = gbc.gridy = 0;//from w ww . j ava2 s . c om final int show = model.type.showCmd; for (final Columns col : Columns.values()) { final int mask = 1 << col.ordinal(); final JCheckBox cbox = new JCheckBox(); cbox.setSelected((show & mask) != 0); // TODO: make static by setting an action-command which represents the respective cbox final class CboxAC implements ActionListener { public void actionPerformed(ActionEvent e) { if (cbox.isSelected()) { model.setCols(model.type.showCmd | mask); } else { model.setCols(model.type.showCmd & ~mask); } } } ; options.add(Utilities.instance.setButtonProps(cbox, col.getL10n(), new CboxAC(), null, -1, null), gbc); if (gbc.gridy < 5) { gbc.gridy++; } else { gbc.gridx++; gbc.gridy = 0; } } }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private TableCellRenderer getCellRenderer(final SwingTreeCol col) { return new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ColumnType colType = col.getColumnType(); if (colType == ColumnType.DYNAMIC) { colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column)); }/* w ww . j a v a 2 s. c o m*/ final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column); switch (colType) { case CHECKBOX: JCheckBox checkbox = new JCheckBox(); if (value instanceof String) { checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$ } else if (value instanceof Boolean) { checkbox.setSelected((Boolean) value); } else if (value == null) { checkbox.setSelected(false); } if (isSelected) { checkbox.setBackground(Color.LIGHT_GRAY); } checkbox.setEnabled(!cell.isDisabled()); return checkbox; case COMBOBOX: case EDITABLECOMBOBOX: Vector data; final JComboBox comboBox = new JComboBox(); if (cell == null) { } else { data = (cell.getValue() != null) ? (Vector) cell.getValue() : new Vector(); if (data == null) { logger.debug("SwingTreeCell combobox data is null, passed in value: " + value); //$NON-NLS-1$ if (value instanceof Vector) { data = (Vector) value; } } if (data != null) { comboBox.setModel(new DefaultComboBoxModel(data)); try { comboBox.setSelectedIndex(cell.getSelectedIndex()); } catch (Exception e) { logger.error("error setting selected index on the combobox editor"); //$NON-NLS-1$ } } } if (colType == ColumnType.EDITABLECOMBOBOX) { comboBox.setEditable(true); ((JTextComponent) comboBox.getEditor().getEditorComponent()).setText(cell.getLabel()); } if (isSelected) { comboBox.setBackground(Color.LIGHT_GRAY); } comboBox.setEnabled(!cell.isDisabled()); return comboBox; case CUSTOM: return new CustomCellEditorWrapper(cell, customEditors.get(col.getType())); default: JLabel label = new JLabel((String) value); if (isSelected) { label.setOpaque(true); label.setBackground(Color.LIGHT_GRAY); } return label; } } }; }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private TableCellEditor getCellEditor(final SwingTreeCol col) { return new DefaultCellEditor(new JComboBox()) { JComponent control;//from w w w . ja v a 2s. c o m @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, final int row, final int column) { Component comp; ColumnType colType = col.getColumnType(); if (colType == ColumnType.DYNAMIC) { colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column)); } final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column); switch (colType) { case CHECKBOX: final JCheckBox checkbox = new JCheckBox(); final JTable tbl = table; checkbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column); tbl.getCellEditor().stopCellEditing(); } }); control = checkbox; if (value instanceof String) { checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$ } else if (value instanceof Boolean) { checkbox.setSelected((Boolean) value); } else if (value == null) { checkbox.setSelected(false); } if (isSelected) { checkbox.setBackground(Color.LIGHT_GRAY); } comp = checkbox; checkbox.setEnabled(!cell.isDisabled()); break; case EDITABLECOMBOBOX: case COMBOBOX: Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector(); final JComboBox comboBox = new JComboBox(val); if (isSelected) { comboBox.setBackground(Color.LIGHT_GRAY); } if (colType == ColumnType.EDITABLECOMBOBOX) { comboBox.setEditable(true); final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent(); textComp.addKeyListener(new KeyListener() { private String oldValue = ""; //$NON-NLS-1$ public void keyPressed(KeyEvent e) { oldValue = textComp.getText(); } public void keyReleased(KeyEvent e) { if (oldValue != null && !oldValue.equals(textComp.getText())) { SwingTree.this.table.setValueAt(textComp.getText(), row, column); oldValue = textComp.getText(); } else if (oldValue == null) { // AWT error where sometimes the keyReleased is fired before keyPressed. oldValue = textComp.getText(); } else { logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$ } } public void keyTyped(KeyEvent e) { } }); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // if(textComp.hasFocus() == false && comboBox.hasFocus()){ SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$ + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$ SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column); // } } }); } else { comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$ + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$ SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column); } }); } control = comboBox; comboBox.setEnabled(!cell.isDisabled()); comp = comboBox; break; case LABEL: JLabel lbl = new JLabel(cell.getLabel()); comp = lbl; control = lbl; break; case CUSTOM: return new CustomCellEditorWrapper(cell, customEditors.get(col.getType())); default: final JTextField label = new JTextField((String) value); label.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } public void insertUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } public void removeUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } }); if (isSelected) { label.setOpaque(true); // label.setBackground(Color.LIGHT_GRAY); } control = label; comp = label; label.setEnabled(!cell.isDisabled()); label.setDisabledTextColor(Color.DARK_GRAY); break; } return comp; } @Override public Object getCellEditorValue() { if (control instanceof JCheckBox) { return ((JCheckBox) control).isSelected(); } else if (control instanceof JComboBox) { JComboBox box = (JComboBox) control; if (box.isEditable()) { return ((JTextComponent) box.getEditor().getEditorComponent()).getText(); } else { return box.getSelectedIndex(); } } else if (control instanceof JTextField) { return ((JTextField) control).getText(); } else { return ((JLabel) control).getText(); } } }; }
From source file:org.p_vcd.ui.VcdDialog.java
public void updateDatabases(String defaultValue) { List<VideoDatabase> refDbs = VideoDatabase.getReferenceDatabases(); // remove from map List<VideoDatabase> entriesToRemove = new ArrayList<VideoDatabase>(); for (VideoDatabase edb : map_refDbCheck.keySet()) { if (!refDbs.contains(edb)) entriesToRemove.add(edb);/*from w w w . j a va 2s . c o m*/ } for (VideoDatabase edb : entriesToRemove) map_refDbCheck.remove(edb); // add to map List<VideoDatabase> entriesToAdd = new ArrayList<VideoDatabase>(); for (VideoDatabase db : refDbs) { if (!map_refDbCheck.containsKey(db)) entriesToAdd.add(db); } for (VideoDatabase db : entriesToAdd) { JCheckBox chkbox = new JCheckBox(db.getName() + " (" + db.getFileList().size() + " files, " + MyUtil.getSecondsToHHMMSS(db.getTotalSeconds()) + " length)"); chkbox.setBackground(Color.WHITE); chkbox.setFont(new Font("Tahoma", Font.PLAIN, 13)); chkbox.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateReferenceDbDetail(); } }); map_refDbCheck.put(db, chkbox); } // draw checkboxes panel_refDatabasesList.removeAll(); int cont = 0; for (JCheckBox chkbox : map_refDbCheck.values()) { panel_refDatabasesList.add(chkbox, "cell 0 " + cont); cont++; } panel_refDatabasesList.validate(); // default value if (defaultValue != null) { for (Map.Entry<VideoDatabase, JCheckBox> entry : map_refDbCheck.entrySet()) { if (!defaultValue.equals(entry.getKey().getName())) continue; JCheckBox chkbox = entry.getValue(); chkbox.setSelected(true); chkbox.requestFocus(); break; } } List<String> listQ = new ArrayList<String>(); listQ.add("-- select a db --"); for (VideoDatabase db : refDbs) { listQ.add(db.getName()); } comboBox_queryDb.setModel(new DefaultComboBoxModel<String>(listQ.toArray(new String[0]))); updateReferenceDbDetail(); updateQueryDbDetail(); }
From source file:org.tinymediamanager.ui.dialogs.ImageChooserDialog.java
/** * Instantiates a new image chooser dialog. * //from w ww.j av a 2 s .com * @param ids * the ids * @param type * the type * @param artworkScrapers * the artwork providers * @param imageLabel * the image label * @param extraThumbs * the extra thumbs * @param extraFanarts * the extra fanarts * @param mediaType * the media for for which artwork has to be chosen */ public ImageChooserDialog(final HashMap<String, Object> ids, ImageType type, List<MediaScraper> artworkScrapers, ImageLabel imageLabel, List<String> extraThumbs, List<String> extraFanarts, MediaType mediaType) { super("", "imageChooser"); this.imageLabel = imageLabel; this.type = type; this.mediaType = mediaType; this.artworkScrapers = artworkScrapers; this.extraThumbs = extraThumbs; this.extraFanarts = extraFanarts; switch (type) { case FANART: setTitle(BUNDLE.getString("image.choose.fanart")); //$NON-NLS-1$ break; case POSTER: setTitle(BUNDLE.getString("image.choose.poster")); //$NON-NLS-1$ break; case BANNER: setTitle(BUNDLE.getString("image.choose.banner")); //$NON-NLS-1$ break; case SEASON: Object season = ids.get("tvShowSeason"); if (season != null) { setTitle(BUNDLE.getString("image.choose.season") + " - " + BUNDLE.getString("metatag.season") + " " //$NON-NLS-1$ + season); } else { setTitle(BUNDLE.getString("image.choose.season")); //$NON-NLS-1$ } break; case CLEARART: setTitle(BUNDLE.getString("image.choose.clearart")); //$NON-NLS-1$ break; case DISC: setTitle(BUNDLE.getString("image.choose.disc")); //$NON-NLS-1$ break; case LOGO: setTitle(BUNDLE.getString("image.choose.logo")); //$NON-NLS-1$ break; case CLEARLOGO: setTitle(BUNDLE.getString("image.choose.clearlogo")); //$NON-NLS-1$ break; case THUMB: setTitle(BUNDLE.getString("image.choose.thumb")); //$NON-NLS-1$ break; } setBounds(5, 5, 1000, 590); getContentPane().setLayout(new BorderLayout()); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("258px:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.LABEL_COMPONENT_GAP_COLSPEC, }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("fill:266px:grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, })); { scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); contentPanel.add(scrollPane, "2, 2, 3, 1, fill, fill"); { panelImages = new JPanel(); scrollPane.setViewportView(panelImages); scrollPane.getVerticalScrollBar().setUnitIncrement(16); panelImages.setLayout(new WrapLayout(FlowLayout.LEFT)); } } { tfImageUrl = new EnhancedTextField(BUNDLE.getString("image.inserturl")); //$NON-NLS-1$ contentPanel.add(tfImageUrl, "2, 4, fill, default"); tfImageUrl.setColumns(10); JButton btnAddImage = new JButton(BUNDLE.getString("image.downloadimage")); //$NON-NLS-1$ btnAddImage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (StringUtils.isNotBlank(tfImageUrl.getText())) { downloadAndPreviewImage(tfImageUrl.getText()); } } }); contentPanel.add(btnAddImage, "4, 4"); } { JPanel bottomPane = new JPanel(); getContentPane().add(bottomPane, BorderLayout.SOUTH); bottomPane.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.NARROW_LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.NARROW_LINE_GAP_ROWSPEC, RowSpec.decode("23px:grow"), FormFactory.RELATED_GAP_ROWSPEC, })); { if (type == ImageType.FANART && extraFanarts != null && extraThumbs != null) { JPanel panelExtraButtons = new JPanel(); bottomPane.add(panelExtraButtons, "2, 2, fill, bottom"); panelExtraButtons.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0)); { if (mediaType == MediaType.MOVIE && MovieModuleManager.MOVIE_SETTINGS.isImageExtraThumbs()) { JLabel labelThumbs = new JLabel("Extrathumbs:"); panelExtraButtons.add(labelThumbs); JButton btnMarkExtrathumbs = new JButton(""); btnMarkExtrathumbs.setMargin(new Insets(0, 0, 0, 0)); btnMarkExtrathumbs.setIcon(IconManager.CHECK_ALL); btnMarkExtrathumbs.setToolTipText(BUNDLE.getString("image.extrathumbs.markall")); //$NON-NLS-1$ btnMarkExtrathumbs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { for (JToggleButton button : buttons) { if (button .getClientProperty("MediaArtworkExtrathumb") instanceof JCheckBox) { JCheckBox chkbx = (JCheckBox) button .getClientProperty("MediaArtworkExtrathumb"); chkbx.setSelected(true); } } } }); panelExtraButtons.add(btnMarkExtrathumbs); JButton btnUnMarkExtrathumbs = new JButton(""); btnUnMarkExtrathumbs.setMargin(new Insets(0, 0, 0, 0)); btnUnMarkExtrathumbs.setIcon(IconManager.UNCHECK_ALL); btnUnMarkExtrathumbs.setToolTipText(BUNDLE.getString("image.extrathumbs.unmarkall")); //$NON-NLS-1$ btnUnMarkExtrathumbs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { for (JToggleButton button : buttons) { if (button .getClientProperty("MediaArtworkExtrathumb") instanceof JCheckBox) { JCheckBox chkbx = (JCheckBox) button .getClientProperty("MediaArtworkExtrathumb"); chkbx.setSelected(false); } } } }); panelExtraButtons.add(btnUnMarkExtrathumbs); } if (mediaType == MediaType.MOVIE && MovieModuleManager.MOVIE_SETTINGS.isImageExtraThumbs() && MovieModuleManager.MOVIE_SETTINGS.isImageExtraFanart()) { JSeparator separator = new JSeparator(SwingConstants.VERTICAL); separator.setPreferredSize(new Dimension(2, 16)); panelExtraButtons.add(separator); } if (mediaType == MediaType.MOVIE && MovieModuleManager.MOVIE_SETTINGS.isImageExtraFanart()) { JLabel labelFanart = new JLabel("Extrafanart:"); panelExtraButtons.add(labelFanart); JButton btnMarkExtrafanart = new JButton(""); btnMarkExtrafanart.setMargin(new Insets(0, 0, 0, 0)); btnMarkExtrafanart.setIcon(IconManager.CHECK_ALL); btnMarkExtrafanart.setToolTipText(BUNDLE.getString("image.extrafanart.markall")); //$NON-NLS-1$ btnMarkExtrafanart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { for (JToggleButton button : buttons) { if (button.getClientProperty( "MediaArtworkExtrafanart") instanceof JCheckBox) { JCheckBox chkbx = (JCheckBox) button .getClientProperty("MediaArtworkExtrafanart"); chkbx.setSelected(true); } } } }); panelExtraButtons.add(btnMarkExtrafanart); JButton btnUnMarkExtrafanart = new JButton(""); btnUnMarkExtrafanart.setMargin(new Insets(0, 0, 0, 0)); btnUnMarkExtrafanart.setIcon(IconManager.UNCHECK_ALL); btnUnMarkExtrafanart.setToolTipText(BUNDLE.getString("image.extrafanart.unmarkall")); //$NON-NLS-1$ btnUnMarkExtrafanart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { for (JToggleButton button : buttons) { if (button.getClientProperty( "MediaArtworkExtrafanart") instanceof JCheckBox) { JCheckBox chkbx = (JCheckBox) button .getClientProperty("MediaArtworkExtrafanart"); chkbx.setSelected(false); } } } }); panelExtraButtons.add(btnUnMarkExtrafanart); } } } } { progressBar = new JProgressBar(); bottomPane.add(progressBar, "2, 4"); } { lblProgressAction = new JLabel(""); bottomPane.add(lblProgressAction, "4, 4"); } { JPanel buttonPane = new JPanel(); EqualsLayout layout = new EqualsLayout(5); buttonPane.setLayout(layout); layout.setMinWidth(100); bottomPane.add(buttonPane, "6, 4, fill, top"); JButton okButton = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$ okButton.setAction(actionOK); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); JButton btnAddFile = new JButton(BUNDLE.getString("Button.addfile")); //$NON-NLS-1$ btnAddFile.setAction(actionLocalFile); buttonPane.add(btnAddFile); JButton cancelButton = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$ cancelButton.setAction(actionCancel); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } task = new DownloadTask(ids, this.artworkScrapers); task.execute(); }
From source file:org.tinymediamanager.ui.panels.MediaScraperConfigurationPanel.java
private JPanel createConfigPanel() { JPanel panel = new JPanel(); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0 }; gridBagLayout.rowHeights = new int[] { 0 }; gridBagLayout.columnWeights = new double[] { Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { Double.MIN_VALUE }; panel.setLayout(gridBagLayout);/*from w ww. j av a2s . c om*/ GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = 0; // build up the panel for being displayed in the popup MediaProviderConfig config = mediaProvider.getProviderInfo().getConfig(); for (Entry<String, MediaProviderConfigObject> entry : config.getConfigObjects().entrySet()) { if (!entry.getValue().isVisible()) { continue; } constraints.anchor = GridBagConstraints.LINE_START; constraints.ipadx = 20; // label JLabel label = new JLabel(entry.getValue().getKeyDescription()); constraints.gridx = 0; panel.add(label, constraints); JComponent comp; switch (entry.getValue().getType()) { case BOOL: // display as checkbox JCheckBox checkbox = new JCheckBox(); checkbox.setSelected(entry.getValue().getValueAsBool()); checkbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dirty = true; } }); comp = checkbox; break; case SELECT: case SELECT_INDEX: // display as combobox JComboBox<String> combobox = new JComboBox<>( entry.getValue().getPossibleValues().toArray(new String[0])); combobox.setSelectedItem(entry.getValue().getValueAsString()); combobox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dirty = true; } }); comp = combobox; break; default: // display as text JTextField tf; if (entry.getValue().isEncrypt()) { tf = new JPasswordField(config.getValue(entry.getKey())); } else { tf = new JTextField(config.getValue(entry.getKey())); } tf.setPreferredSize(new Dimension(100, 24)); tf.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { dirty = true; } @Override public void insertUpdate(DocumentEvent e) { dirty = true; } @Override public void changedUpdate(DocumentEvent e) { dirty = true; } }); comp = tf; break; } comp.putClientProperty(entry.getKey(), entry.getKey()); constraints.ipadx = 0; constraints.gridx = 1; panel.add(comp, constraints); // add a hint if a long text has been found try { String desc = BUNDLE.getString( "scraper." + mediaProvider.getProviderInfo().getId() + "." + entry.getKey() + ".desc"); //$NON-NLS-1$ if (StringUtils.isNotBlank(desc)) { JLabel lblHint = new JLabel(IconManager.HINT); lblHint.setToolTipText(desc); constraints.gridx = 2; panel.add(lblHint, constraints); } } catch (Exception ignored) { } constraints.gridy++; } return panel; }
From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java
@Override public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException { double[] selectedValues; if (encoding == null) { selectedValues = null;/* w w w . ja va 2s .c o m*/ } else { selectedValues = NumericConditionEncoder.unencodeConditions(encoding); } final double[] extremeValues = generator.getExtremeNumericValues(); this.removeAll(); if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(Box.createHorizontalGlue()); p.add(new JLabel("<html>All values are blank for this condition.</html>")); p.add(Box.createHorizontalGlue()); this.add(p); return; } setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel p = ViewUtil.getClearPanel(); ViewUtil.applyVerticalBoxLayout(p); JPanel labelPanel = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(labelPanel); labelPanel.add(Box.createHorizontalGlue()); labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": ")); labelPanel.add(Box.createHorizontalGlue()); ButtonGroup group = new ButtonGroup(); //JRadioButton isButton = new JRadioButton("is within the following range:"); //JRadioButton nullButton = new JRadioButton("is missing"); //group.add(isButton); //group.add(nullButton); final JCheckBox nullButton = new JCheckBox("include missing values"); JPanel bp = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(bp); p.add(labelPanel); p.add(bp); add(p); final DecimalRangeSlider slider = new DecimalRangeSlider(); slider.setMajorTickSpacing(5); slider.setMinorTickSpacing(1); final JTextField fromBox = new JTextField(); final JTextField toBox = new JTextField(); nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding)); nullButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } }); fromBox.setMaximumSize(new Dimension(10000, 24)); toBox.setMaximumSize(new Dimension(10000, 24)); fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24)); toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24)); fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24)); toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24)); fromBox.setHorizontalAlignment(JTextField.RIGHT); toBox.setHorizontalAlignment(JTextField.RIGHT); final JLabel fromLabel = new JLabel(); final JLabel toLabel = new JLabel(); ViewUtil.makeMini(fromLabel); ViewUtil.makeMini(toLabel); JPanel fromToContainer = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(fromToContainer); fromToContainer.add(Box.createHorizontalGlue()); fromToContainer.add(fromBox); fromToContainer.add(new JLabel(" - ")); fromToContainer.add(toBox); fromToContainer.add(Box.createHorizontalGlue()); JPanel minMaxContainer = ViewUtil.getClearPanel(); minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS)); JPanel sliderContainer = ViewUtil.getClearPanel(); sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS)); sliderContainer.add(slider); JPanel nullValueContainer = ViewUtil.getClearPanel(); ViewUtil.applyHorizontalBoxLayout(nullValueContainer); nullValueContainer.add(Box.createHorizontalGlue()); nullValueContainer.add(nullButton); nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue. nullValueContainer.add(Box.createHorizontalGlue()); JPanel labelContainer = ViewUtil.getClearPanel(); labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS)); labelContainer.add(fromLabel); labelContainer.add(Box.createHorizontalGlue()); labelContainer.add(toLabel); sliderContainer.add(labelContainer); minMaxContainer.add(Box.createHorizontalGlue()); minMaxContainer.add(sliderContainer); minMaxContainer.add(Box.createHorizontalGlue()); add(fromToContainer); add(minMaxContainer); add(nullValueContainer); add(Box.createVerticalBox()); slider.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (slider.isEnabled()) { fromBox.setText(ViewUtil.numToString(slider.getLow())); toBox.setText(ViewUtil.numToString(slider.getHigh())); encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } } }); final KeyListener keyListener = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText())); setSelectedValues(slider, fromBox, toBox, selectedRage); } } private double getNumber(String s) { try { return Double.parseDouble(s.replaceAll(",", "")); } catch (NumberFormatException ignored) { return 0; } } }; CaretListener caretListener = new CaretListener() { @Override public void caretUpdate(CaretEvent ce) { if (!isAdjustingSlider) { try { encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()), ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0], extremeValues[1], nullButton.isSelected()); } catch (Exception e) { } } } }; fromBox.addKeyListener(keyListener); toBox.addKeyListener(keyListener); fromBox.addCaretListener(caretListener); toBox.addCaretListener(caretListener); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { isAdjustingSlider = true; fromBox.setText(ViewUtil.numToString(slider.getLow())); toBox.setText(ViewUtil.numToString(slider.getHigh())); isAdjustingSlider = false; } }); JPanel bottomContainer = new JPanel(); bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS)); bottomContainer.add(Box.createHorizontalGlue()); add(bottomContainer); setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0, new Range(extremeValues[0], extremeValues[1])); if (encoding != null) { double[] d = NumericConditionEncoder.unencodeConditions(encoding); setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1])); } }
From source file:org.yawlfoundation.yawl.procletService.editor.pconns.VertexDemo.java
public VertexDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Number, Number>(); createGraph(VERTEX_COUNT);// w w w . j a va2 s . co m // a Map for the labels Map<Number, String> map = new HashMap<Number, String>(); for (int i = 0; i < VERTEX_COUNT; i++) { map.put(i, iconNames[i % iconNames.length]); } // a Map for the Icons Map<Number, Icon> iconMap = new HashMap<Number, Icon>(); for (int i = 0; i < VERTEX_COUNT; i++) { String name = "/images/topic" + iconNames[i] + ".gif"; try { Icon icon = new LayeredIcon(new ImageIcon(VertexDemo.class.getResource(name)).getImage()); iconMap.put(i, icon); } catch (Exception ex) { System.err.println("You need slashdoticons.jar in your classpath to see the image " + name); } } FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); layout.setInitializer(new RandomLocationTransformer<Number>(new Dimension(400, 400), 0)); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400)); // This demo uses a special renderer to turn outlines on and off. // you do not need to do this in a real application. // Instead, just let vv use the Renderer it already has vv.getRenderer().setVertexRenderer(new DemoRenderer<Number, Number>()); Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(), Color.white, Color.yellow); vv.getRenderContext().setVertexFillPaintTransformer(vpf); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.setBackground(Color.white); final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number, String>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Number,String>() { // URL url = getClass().getResource("/images/lightning-s.gif"); // public String transform(Number input) { // // return "<html><img src="+url+" height=10 width=21>"+input.toString(); // }}); // For this demo only, I use a special class that lets me turn various // features on and off. For a real application, use VertexIconShapeTransformer instead. final DemoVertexIconShapeTransformer<Number> vertexIconShapeTransformer = new DemoVertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DemoVertexIconTransformer<Number> vertexIconTransformer = new DemoVertexIconTransformer<Number>(); vertexIconShapeTransformer.setIconMap(iconMap); vertexIconTransformer.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexIconShapeTransformer); vv.getRenderContext().setVertexIconTransformer(vertexIconTransformer); // un-comment for RStar Tree visual testing //vv.addPostRenderPaintable(new BoundingRectanglePaintable(vv.getRenderContext(), vv.getGraphLayout())); // Get the pickedState and add a listener that will decorate the // Vertex images with a checkmark icon when they are picked PickedState<Number> ps = vv.getPickedVertexState(); ps.addItemListener(new PickWithIconListener<Number>(vertexIconTransformer)); vv.addPostRenderPaintable(new VisualizationViewer.Paintable() { int x; int y; Font font; FontMetrics metrics; int swidth; int sheight; String str = "Thank You, slashdot.org, for the images!"; public void paint(Graphics g) { Dimension d = vv.getSize(); if (font == null) { font = new Font(g.getFont().getName(), Font.BOLD, 20); metrics = g.getFontMetrics(font); swidth = metrics.stringWidth(str); sheight = metrics.getMaxAscent() + metrics.getMaxDescent(); x = (d.width - swidth) / 2; y = (int) (d.height - sheight * 1.5); } g.setFont(font); Color oldColor = g.getColor(); g.setColor(Color.lightGray); g.drawString(str, x, y); g.setColor(oldColor); } public boolean useTransform() { return false; } }); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Number>()); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JCheckBox shape = new JCheckBox("Shape"); shape.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { vertexIconShapeTransformer.setShapeImages(e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); shape.setSelected(true); JCheckBox fill = new JCheckBox("Fill"); fill.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { vertexIconTransformer.setFillImages(e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); fill.setSelected(true); JCheckBox drawOutlines = new JCheckBox("Outline"); drawOutlines.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { vertexIconTransformer.setOutlineImages(e.getStateChange() == ItemEvent.SELECTED); vv.repaint(); } }); JComboBox modeBox = graphMouse.getModeComboBox(); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel labelFeatures = new JPanel(new GridLayout(1, 0)); labelFeatures.setBorder(BorderFactory.createTitledBorder("Image Effects")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); labelFeatures.add(shape); labelFeatures.add(fill); labelFeatures.add(drawOutlines); controls.add(labelFeatures); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); }
From source file:org.zaproxy.zap.extension.ascan.CustomScanDialog.java
private void populateRequestField(SiteNode node) { try {//w ww.j a v a 2 s .com if (node == null || node.getHistoryReference() == null || node.getHistoryReference().getHttpMessage() == null) { this.getRequestField().setText(""); } else { // Populate the custom vectors http pane HttpMessage msg = node.getHistoryReference().getHttpMessage(); String header = msg.getRequestHeader().toString(); StringBuilder sb = new StringBuilder(); sb.append(header); this.headerLength = header.length(); this.urlPathStart = header.indexOf("/", header.indexOf("://") + 2) + 1; // Ignore <METHOD> http(s)://host:port/ sb.append(msg.getRequestBody().toString()); this.getRequestField().setText(sb.toString()); // Only set the recurse option if the node has children, and disable it otherwise JCheckBox recurseChk = (JCheckBox) this.getField(FIELD_RECURSE); recurseChk.setEnabled(node.getChildCount() > 0); recurseChk.setSelected(node.getChildCount() > 0); } this.setFieldStates(); } catch (HttpMalformedHeaderException | DatabaseException e) { // this.getRequestField().setText(""); } }
From source file:org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.java
private void alertIfOutOfDate(boolean alwaysPrompt) { final OptionsParamCheckForUpdates options = getModel().getOptionsParam().getCheckForUpdatesParam(); Date today = new Date(); Date releaseCreated = Constant.getReleaseCreateDate(); Date lastInstallWarning = options.getDayLastInstallWarned(); int result = -1; logger.debug("Install created " + releaseCreated); if (releaseCreated != null) { // Should only be null for dev builds int daysOld = dayDiff(today, releaseCreated); logger.debug("Install is " + daysOld + " days old"); if (daysOld > 365) { // Oh no, its more than a year old! boolean setCfuOnStart = false; if (alwaysPrompt || lastInstallWarning == null || dayDiff(today, lastInstallWarning) > 30) { JCheckBox cfuOnStart = new JCheckBox(Constant.messages.getString("cfu.label.cfuonstart")); cfuOnStart.setSelected(true); String msg = Constant.messages.getString("cfu.label.oldzap"); result = View.getSingleton().showYesNoDialog(View.getSingleton().getMainFrame(), new Object[] { msg, cfuOnStart }); setCfuOnStart = cfuOnStart.isSelected(); }// w ww . j a va 2 s. com options.setDayLastInstallWarned(); if (result == JOptionPane.OK_OPTION) { if (setCfuOnStart) { options.setCheckOnStart(true); } getAddOnsDialog().setVisible(true); getAddOnsDialog().checkForUpdates(); } else if (!oldZapAlertAdded) { JButton button = new JButton(Constant.messages.getString("cfu.label.outofdatezap")); button.setIcon( new ImageIcon(ExtensionAutoUpdate.class.getResource("/resource/icon/16/050.png"))); // Alert triangle button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { alertIfOutOfDate(true); } }); View.getSingleton().getMainFrame().getMainFooterPanel().addFooterToolbarLeftComponent(button); oldZapAlertAdded = true; } return; } } Date lastChecked = options.getDayLastChecked(); Date lastUpdateWarning = options.getDayLastUpdateWarned(); Date installDate = Constant.getInstallDate(); if (installDate == null || dayDiff(today, installDate) < 90) { // Dont warn if installed in the last 3 months } else if (lastChecked == null || dayDiff(today, lastChecked) > 90) { // Not checked for updates in 3 months :( boolean setCfuOnStart = false; if (alwaysPrompt || lastUpdateWarning == null || dayDiff(today, lastUpdateWarning) > 30) { JCheckBox cfuOnStart = new JCheckBox(Constant.messages.getString("cfu.label.cfuonstart")); cfuOnStart.setSelected(true); String msg = Constant.messages.getString("cfu.label.norecentcfu"); result = View.getSingleton().showYesNoDialog(View.getSingleton().getMainFrame(), new Object[] { msg, cfuOnStart }); setCfuOnStart = cfuOnStart.isSelected(); } options.setDayLastUpdateWarned(); if (result == JOptionPane.OK_OPTION) { if (setCfuOnStart) { options.setCheckOnStart(true); } getAddOnsDialog().setVisible(true); getAddOnsDialog().checkForUpdates(); if (noCfuAlertAdded) { View.getSingleton().getMainFrame().getMainFooterPanel() .removeFooterToolbarLeftComponent(getOutOfDateButton()); } } else if (!noCfuAlertAdded) { View.getSingleton().getMainFrame().getMainFooterPanel() .addFooterToolbarLeftComponent(getOutOfDateButton()); noCfuAlertAdded = true; } } }