public NodeSelectionDialog(Frame owner, NodeLibrary library, NodeLibraryManager manager) { super(owner, "New Node", true); getRootPane().putClientProperty("Window.style", "small"); JPanel panel = new JPanel(new BorderLayout()); this.library = library; this.manager = manager; filteredNodeListModel = new FilteredNodeListModel(library, manager); searchField = new JTextField(); searchField.putClientProperty("JTextField.variant", "search"); EscapeListener escapeListener = new EscapeListener(); searchField.addKeyListener(escapeListener); ArrowKeysListener arrowKeysListener = new ArrowKeysListener(); searchField.addKeyListener(arrowKeysListener); SearchFieldChangeListener searchFieldChangeListener = new SearchFieldChangeListener(); searchField.getDocument().addDocumentListener(searchFieldChangeListener); nodeList = new JList(filteredNodeListModel); DoubleClickListener doubleClickListener = new DoubleClickListener(); nodeList.addMouseListener(doubleClickListener); nodeList.addKeyListener(escapeListener); nodeList.addKeyListener(arrowKeysListener); nodeList.setSelectedIndex(0); nodeList.setCellRenderer(new NodeRenderer()); JScrollPane nodeScroll = new JScrollPane( nodeList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); nodeScroll.setBorder(null); panel.add(searchField, BorderLayout.NORTH); panel.add(nodeScroll, BorderLayout.CENTER); setContentPane(panel); setSize(500, 400); SwingUtils.centerOnScreen(this); }
private static Component createDescription(Example example, ExampleGroup group) { Color foreground = group.getPreferredForeground(); WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING); titleLabel.setDrawShade(true); titleLabel.setForeground(foreground); if (foreground.equals(Color.WHITE)) { titleLabel.setShadeColor(Color.BLACK); } if (example.getDescription() == null) { return titleLabel; } else { WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING); descriptionLabel.setForeground(Color.GRAY); SwingUtils.changeFontSize(descriptionLabel, -1); WebPanel vertical = new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false)); vertical.setOpaque(false); vertical.add(titleLabel); vertical.add(descriptionLabel); return vertical; } }
@Override protected void paintComponent(Graphics g) { java.util.List<Network> networks = getNetworkParts(); positions = new int[networks.size()]; Graphics2D g2 = (Graphics2D) g; g2.setFont(SMALL_BOLD_FONT); g2.setPaint(addressGradientPaint); g2.fill(g2.getClipBounds()); // g2.drawImage(addressGradient, 0, 0, getWidth(), 26, null); int x = 14; for (int i = 0; i < networks.size(); i++) { Network part = networks.get(i); if (i == armed) { g2.setColor(TEXT_ARMED_COLOR); } else { g2.setColor(TEXT_NORMAL_COLOR); } String displayName = part.getDisplayName(); SwingUtils.drawShadowText(g2, displayName, x, 16); int width = (int) g2.getFontMetrics().stringWidth(displayName); x += width + 5; positions[i] = x + 10; g2.drawImage(addressArrow, x, 0, null); x += 15; } String version = Application.getInstance().getVersion(); int versionX = getWidth() - g2.getFontMetrics().stringWidth(version) - 10; SwingUtils.drawShadowText(g2, version, versionX, 16); if (renderException != null) { g2.drawImage(addressExclamation, versionX - 30, 0, null); } }
public static Component createGroupView(WebLookAndFeelDemo owner, ExampleGroup group) { // Creating group view Component exampleView; List<Example> examples = group.getGroupExamples(); if (group.isSingleExample() && examples.size() == 1) { Example example = examples.get(0); exampleView = example.getPreview(owner); } else { final List<Component> preview = new ArrayList<Component>(); final WebPanel groupPanel = new WebPanel() { @Override public void setEnabled(boolean enabled) { for (Component previewComponent : preview) { SwingUtils.setEnabledRecursively(previewComponent, enabled); } super.setEnabled(enabled); } }; groupPanel.putClientProperty(SwingUtils.HANDLES_ENABLE_STATE, true); groupPanel.setOpaque(false); exampleView = groupPanel; int rowsAmount = examples.size() > 1 ? examples.size() * 2 - 1 : 1; double[] rows = new double[6 + rowsAmount]; rows[0] = TableLayout.FILL; rows[1] = 20; rows[2] = TableLayout.PREFERRED; for (int i = 3; i < rows.length - 3; i++) { rows[i] = TableLayout.PREFERRED; } rows[rows.length - 3] = TableLayout.PREFERRED; rows[rows.length - 2] = 20; rows[rows.length - 1] = TableLayout.FILL; double[] columns = { 20, 1f - group.getContentPartSize(), TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, group.getContentPartSize(), 20 }; TableLayout groupLayout = new TableLayout(new double[][] {columns, rows}); groupLayout.setHGap(4); groupLayout.setVGap(4); groupPanel.setLayout(groupLayout); groupPanel.add( group.modifySeparator(createVerticalSeparator()), "2,0,2," + (rows.length - 1)); groupPanel.add( group.modifySeparator(createVerticalSeparator()), "4,0,4," + (rows.length - 1)); groupPanel.add( group.modifySeparator(createVerticalSeparator()), "6,0,6," + (rows.length - 1)); groupPanel.add( group.modifySeparator(createVerticalSeparator()), "8,0,8," + (rows.length - 1)); groupPanel.add( group.modifySeparator(createHorizontalSeparator()), "0,2," + (columns.length - 1) + ",2"); groupPanel.add( group.modifySeparator(createHorizontalSeparator()), "0," + (rows.length - 3) + "," + (columns.length - 1) + "," + (rows.length - 3)); int row = 3; for (Example example : examples) { // Title & description groupPanel.add(createDescription(example, group), "1," + row); // Marks Component mark = createMark(owner, example); groupPanel.add(mark, "3," + row); // Source code Component source = createSourceButton(owner, example); groupPanel.add(source, "5," + row); // More usage examples Component usage = createPresentationButton(example); groupPanel.add(usage, "7," + row); SwingUtils.equalizeComponentsSize(mark, source, usage); // Preview Component previewComponent = createPreview(owner, example); groupPanel.add(previewComponent, "9," + row); preview.add(previewComponent); // Rows separator if (row > 3) { groupPanel.add( group.modifySeparator(createHorizontalSeparator()), "0," + (row - 1) + "," + (columns.length - 1) + "," + (row - 1), 0); } row += 2; } } if (group.isShowWatermark()) { WebImage linkImage = new WebImage(logoIcon); linkImage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); TooltipManager.setTooltip(linkImage, linkIcon, "Library site", TooltipWay.trailing); linkImage.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { WebUtils.browseSiteSafely(WebLookAndFeelDemo.WEBLAF_SITE); } }); WebOverlay linkOverlay = new WebOverlay(exampleView, linkImage, WebOverlay.LEADING, WebOverlay.BOTTOM); linkOverlay.setOverlayMargin(15, 15, 15, 15); linkOverlay.setOpaque(false); exampleView = linkOverlay; } return exampleView; }
/** {@inheritDoc} */ @Override public String getFontName() { return SwingUtils.getFontName(this); }
/** {@inheritDoc} */ @Override public WebComboBox setFontName(final String fontName) { return SwingUtils.setFontName(this, fontName); }
/** {@inheritDoc} */ @Override public WebComboBox setFontSizeAndStyle(final int fontSize, final int style) { return SwingUtils.setFontSizeAndStyle(this, fontSize, style); }
/** {@inheritDoc} */ @Override public WebComboBox setFontSizeAndStyle( final int fontSize, final boolean bold, final boolean italic) { return SwingUtils.setFontSizeAndStyle(this, fontSize, bold, italic); }
/** {@inheritDoc} */ @Override public int getFontSize() { return SwingUtils.getFontSize(this); }
/** {@inheritDoc} */ @Override public WebComboBox changeFontSize(final int change) { return SwingUtils.changeFontSize(this, change); }
/** {@inheritDoc} */ @Override public WebComboBox setFontSize(final int fontSize) { return SwingUtils.setFontSize(this, fontSize); }
/** {@inheritDoc} */ @Override public boolean isItalicFont() { return SwingUtils.isItalicFont(this); }
/** {@inheritDoc} */ @Override public WebComboBox setItalicFont(final boolean apply) { return SwingUtils.setItalicFont(this, apply); }
/** {@inheritDoc} */ @Override public WebComboBox setItalicFont() { return SwingUtils.setItalicFont(this); }
/** {@inheritDoc} */ @Override public boolean isPlainFont() { return SwingUtils.isPlainFont(this); }