/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. */ public static JFrame createAndShowGUI() { // Create and set up the window. JFrame frame = new JFrame("DropDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new DropDemo(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); return frame; }
@Override protected JComponent createCenterPane() { graphpanel = new SampleGraphPanel(); graphpanel.setPreferredSize(new Dimension(600, 300)); new DropTarget(graphpanel, new FileDropTargetListener() { @Override protected void openFile(File file) { // insert your own function for loading a file JOptionPane.showMessageDialog(graphpanel, "Opened " + file.getName()); } @Override protected boolean canOpenFile() { // is GUI ready for opening a file? return true; } }); return graphpanel; }
public void initialize(WizardDescriptor wiz) { this.wizardDescriptor = wiz; Object prop = wiz.getProperty(WizardDescriptor.PROP_CONTENT_DATA); //NOI18N String[] beforeSteps = null; if (prop != null && prop instanceof String[]) { beforeSteps = (String[]) prop; } String[] steps = createSteps(beforeSteps, panels); // Make sure list of steps is accurate. for (int i = 0; i < panels.length; i++) { Component c = panels[i].getComponent(); if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Step #. jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, //NOI18N new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); //NOI18N } } }
protected void paintHorizontalSeparators(Graphics g, JComponent c) { Rectangle clipBounds = g.getClipBounds(); int beginRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y)); int endRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y + clipBounds.height - 1)); if ((beginRow <= -1) || (endRow <= -1)) { return; } for (int i = beginRow; i <= endRow; ++i) { TreePath path = getPathForRow(this.tree, i); if ((path != null) && (path.getPathCount() == 2)) { Rectangle rowBounds = getPathBounds(this.tree, getPathForRow(this.tree, i)); // Draw a line at the top if (rowBounds != null) { g.drawLine(clipBounds.x, rowBounds.y, clipBounds.x + clipBounds.width, rowBounds.y); } } } }
/** * create returns the thumb selector component * * @param f * @return */ private JComponent getThumbSelector(final String f) { final JCheckBox cb = new JCheckBox(); cb.setText(""); cb.setSelected(false); cb.setName(f); cb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cb.isSelected()) { selflist.add(f); } else { selflist.remove(f); } } }); cb.setPreferredSize(CB_SIZE); return cb; }
public void initialize(WizardDescriptor wiz) { this.wiz = wiz; index = 0; panels = createPanels(); // Make sure list of steps is accurate. String[] steps = createSteps(); for (int i = 0; i < panels.length; i++) { Component c = panels[i].getComponent(); if (steps[i] == null) { // Default step name to component name of panel. // Mainly useful for getting the name of the target // chooser to appear in the list of steps. steps[i] = c.getName(); } if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Step #. // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps); } } }
private JComponent createDetailsSection() { final JLabel notesLabel = new JLabel(getString("label.notes")); //$NON-NLS-1$ notes = new JTextArea(); notes.setWrapStyleWord(true); notes.setLineWrap(true); notes.setRows(3); notes.setBorder(new EmptyBorder(0, 0, 10, 0)); final int height1 = notesLabel.getPreferredSize().height; final int height2 = notes.getPreferredSize().height; final int[] rows = {height1, height2}; final int[] cols = {TableLayout.FILL}; final JPanel all = new JPanel(new TableLayout(rows, cols)); all.add(notesLabel, new Rectangle(0, 0, 1, 1)); all.add(new JScrollPane(notes), new Rectangle(0, 1, 1, 1)); return all; }
@Override protected JButton makeNoButton() { ResourceAction noAction = new ResourceAction("start.normally") { private static final long serialVersionUID = -8887199234055845095L; @Override public void actionPerformed(ActionEvent e) { setReturnOption(NO_OPTION); no(); } }; getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "NO"); getRootPane().getActionMap().put("NO", noAction); JButton noButton = new JButton(noAction); return noButton; }
private JComponent createBooleanOption(OptionDescriptor option, Preferences prefs) { JCheckBox checkBox = new JCheckBox(); org.openide.awt.Mnemonics.setLocalizedText(checkBox, option.displayName); checkBox.setToolTipText(option.tooltip); checkBox.addActionListener(new ActionListenerImpl(option.preferencesKey, prefs)); checkBox.setSelected(prefs.getBoolean(option.preferencesKey, Boolean.TRUE == option.defaultValue)); prefs.putBoolean(option.preferencesKey, checkBox.isSelected()); GridBagConstraints constraints = new GridBagConstraints(); constraints.anchor = GridBagConstraints.WEST; constraints.fill = GridBagConstraints.NONE; constraints.gridheight = 1; constraints.gridwidth = 2; constraints.gridx = 0; constraints.gridy = row++; constraints.weightx = 0; constraints.weighty = 0; add(checkBox, constraints); return checkBox; }
private JComponent getEditorComponent(JComponent text) { if ( !Config.getDefault().isLineNumbers()) { return text; } JComponent lineNumber = getLineNumberComponent(getParent(text)); if (lineNumber == null) { return text; } List<JComponent> components = new ArrayList<JComponent>(); components.add(lineNumber); components.add(text); return new ComponentPanel(components); }
@Override public void watchRemoved(Watch watch) { synchronized(watchToAnnotation) { Annotation annotation = watchToAnnotation.remove(watch); if(annotation != null) { annotation.detach(); } JComponent frame = watchToWindow.remove(watch); if(frame != null) { EditorUI eui = ((StickyPanel) frame).eui; eui.getStickyWindowSupport().removeWindow(frame); } } }
@HTMLComponent( url = "simple.html", className = "TestPages", type = JComponent.class, techIds = "second" ) static void getSwing(int param, CountDownLatch called) { assertEquals(param, 10, "Correct value passed in"); called.countDown(); ATech t = Contexts.find(BrwsrCtx.findDefault(ComponentsTest.class), ATech.class); assertNotNull(t, "A technology found"); assertEquals(t.getClass(), ATech.Second.class); }
/** * Displays an information bubble that alerts the user that the attribute specified in the * operator parameters was not found. The bubble is located at the operator and the process view * will change to said operator. This method is used after the error occurred during process * execution. * * @param error * the error containing all the information about the operator, the parameter and the * name of the attribute which was not found * @param i18nKey * the i18n key which defines the title, text and button label for the bubble. Format * is "gui.bubble.{i18nKey}.title", "gui.bubble.{i18nKey}.body" and * "gui.bubble.{i18nKey}.button.label". * @param isError * if {@code true}, an error bubble will be shown; otherwise a warning bubble is * displayed * @param arguments * optional i18n arguments * @return the {@link OperatorInfoBubble} instance, never {@code null} */ private static OperatorInfoBubble displayAttributeNotFoundParameterInformation(final AttributeNotFoundError error, final boolean isError, final String i18nKey, final Object... arguments) { final Operator op = error.getOperator(); final ParameterType param = op.getParameterType(error.getKey()); final JButton ackButton = new JButton(I18N.getGUIMessage("gui.bubble." + i18nKey + ".button.label", arguments)); ackButton.setToolTipText(I18N.getGUIMessage("gui.bubble." + i18nKey + ".button.tip")); String decoratorKey = param instanceof CombinedParameterType || param instanceof ParameterTypeAttributes ? "attributes_not_found_decoration" : "attribute_not_found_decoration"; ParameterErrorBubbleBuilder builder = new ParameterErrorBubbleBuilder(RapidMinerGUI.getMainFrame(), op, param, decoratorKey, i18nKey, arguments); final ParameterErrorInfoBubble attributeNotFoundParameterBubble = builder.setHideOnDisable(true) .setAlignment(AlignedSide.BOTTOM).setStyle(isError ? BubbleStyle.ERROR : BubbleStyle.WARNING) .setEnsureVisible(true).hideCloseButton().setHideOnProcessRun(true) .setAdditionalComponents(new JComponent[] { ackButton }).build(); ackButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { attributeNotFoundParameterBubble.killBubble(true); } }); attributeNotFoundParameterBubble.setVisible(true); return attributeNotFoundParameterBubble; }
private void clearPopupMenu(JComponent component) { component.setComponentPopupMenu(null); for (int i = 0; i < component.getComponentCount(); i++) { Component c = component.getComponent(i); if (c instanceof JComponent) clearPopupMenu((JComponent) c); } }
private static boolean isInTabbedContainer( Component c ) { Component parent = c.getParent(); while( null != parent ) { if( parent instanceof JComponent && "TabbedContainerUI".equals( ((JComponent)parent).getUIClassID() ) ) //NOI18N return true; parent = parent.getParent(); } return false; }
@Override protected void doPaint(Graphics2D g, JComponent c, int width, int height, Object[] extendedCacheKeys) { //it is assumed that in the normal orientation the separator renders //horizontally. Other code rotates it as necessary for a vertical //separator. g.setColor(c.getForeground()); int y = height / 2; for (int i=INSET; i<=width-INSET; i+=SPACE) { g.fillRect(i, y, 1, 1); } }
RepoSelectorPanel(JComponent repoSelector, JComponent newRepoButton) { super(null); JLabel repoSelectorLabel = new JLabel(); repoSelectorLabel.setLabelFor(repoSelector); repoSelectorLabel.setFocusCycleRoot(true); Mnemonics.setLocalizedText( repoSelectorLabel, NbBundle.getMessage(getClass(), "QueryTopComponent.repoLabel.text"));//NOI18N setOpaque(false); newRepoButton.addFocusListener(this); repoSelector.addFocusListener(this); GroupLayout layout; setLayout(layout = new GroupLayout(this)); layout.setHorizontalGroup( layout.createSequentialGroup() .addComponent(repoSelectorLabel) .addPreferredGap(RELATED) .addComponent(repoSelector) .addPreferredGap(RELATED) .addComponent(newRepoButton)); layout.setVerticalGroup( layout.createParallelGroup(BASELINE) .addComponent(repoSelectorLabel) .addComponent(repoSelector, DEFAULT_SIZE, DEFAULT_SIZE, PREFERRED_SIZE) .addComponent(newRepoButton)); }
private String getName(List<JComponent> printable, JComponent top) { for (JComponent component : printable) { Object object = component.getClientProperty(PrintManager.PRINT_NAME); if (object instanceof String) { return (String) object; } } return getName(getData(top)); }
/** * Returns a multiplexing UI instance if any of the auxiliary * <code>LookAndFeel</code>s supports this UI. Otherwise, just returns the * UI object obtained from the default <code>LookAndFeel</code>. */ public static ComponentUI createUI(JComponent a) { ComponentUI mui = new MultiButtonUI(); return MultiLookAndFeel.createUIs(mui, ((MultiButtonUI) mui).uis, a); }
/** * Invokes the <code>getPreferredSize</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Dimension getPreferredSize(JComponent a) { Dimension returnValue = uis.elementAt(0).getPreferredSize(a); for (int i = 1; i < uis.size(); i++) { uis.elementAt(i).getPreferredSize(a); } return returnValue; }
@Override public Dimension getPreferredSize(JComponent c) { FontMetrics fm = getTxtFontMetrics(); int height = fm == null ? 19 : fm.getAscent() + 2 * fm.getDescent() + 2; Insets insets = c.getInsets(); prefSize.height = height + insets.bottom + insets.top; return prefSize; }
/** * Paints bottom "activation" line */ private void paintBottomBorder(Graphics g, JComponent c) { Color color = isActive() ? getActBgColor() : getInactBgColor(); g.setColor(color); Rectangle bounds = c.getBounds(); g.fillRect(1, bounds.height - 3, bounds.width - 1, 2); g.setColor(getBorderShadow()); g.drawLine(1, bounds.height - 1, bounds.width - 1, bounds.height - 1); }
@Override protected void paintDeterminate(Graphics g, JComponent c) { Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - (b.right + b.left); int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); if (barRectWidth <= 0 || barRectHeight <= 0) { return; } // amount of progress to draw int amountFull = getAmountFull(b, barRectWidth, barRectHeight); Graphics2D g2 = (Graphics2D) g; g2.setColor(progressBar.getForeground()); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2.setPaint(high); g2.fillRect(0, 0, amountFull, c.getHeight() / 2); g2.setPaint(low); g2.fillRect(0, c.getHeight() / 2, amountFull, c.getHeight()); } else { // VERTICAL } // Deal with possible text painting if (progressBar.isStringPainted()) { paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b); } }
/** * Invokes the <code>getAccessibleChild</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Accessible getAccessibleChild(JComponent a, int b) { Accessible returnValue = uis.elementAt(0).getAccessibleChild(a,b); for (int i = 1; i < uis.size(); i++) { uis.elementAt(i).getAccessibleChild(a,b); } return returnValue; }
/** * Returns the amount to indent the specified component if it's * a JCheckBox or JRadioButton. If the component is not a JCheckBox or * JRadioButton, 0 will be returned. */ int getButtonChildIndent(JComponent c, int position) { if ((c instanceof JRadioButton) || (c instanceof JCheckBox)) { AbstractButton button = (AbstractButton)c; Insets insets = c.getInsets(); Icon icon = getIcon(button); int gap = button.getIconTextGap(); if (isLeftAligned(button, position)) { return insets.left + icon.getIconWidth() + gap; } else if (isRightAligned(button, position)) { return insets.right + icon.getIconWidth() + gap; } } return 0; }
PaddingSpring(JComponent source, JComponent target, int type, boolean canGrow) { this.source = source; this.target = target; this.type = type; this.canGrow = canGrow; }
private JComponent[] convertArray(JComponent[] arr) { if (arr == null || arr.length == 0) { return new JComponent[] { new InvisibleMenuItem() }; } JComponent[] toRet = new JComponent[arr.length]; for (int i = 0; i < arr.length; i++) { if (arr[i] == null) { toRet[i] = createSeparator(); } else { toRet[i] = arr[i]; } } return toRet; }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int columnIndex) { Component renderer = super.getTableCellRendererComponent(table, value, hasFocus, hasFocus, rowIndex, columnIndex); if (renderer instanceof JComponent) { String strValue = tableModel.getNode(rowIndex).getValue(); ((JComponent) renderer).setToolTipText(strValue); } setToolTipText(value.toString()); return renderer; }
/** * Invokes the <code>getAccessibleChildrenCount</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public int getAccessibleChildrenCount(JComponent a) { int returnValue = ((ComponentUI) (uis.elementAt(0))).getAccessibleChildrenCount(a); for (int i = 1; i < uis.size(); i++) { ((ComponentUI) (uis.elementAt(i))).getAccessibleChildrenCount(a); } return returnValue; }
@Override public boolean verify(JComponent input) { if (dbColumn != null && input instanceof JTextComponent) { String inputText = ((JTextComponent) input).getText(); try { DBReadWriteHelper.validate(inputText, dbColumn); } catch (DBException ex) { return false; } return true; } else { return true; } }
private int getWidth(JComponent component) { Dimension size = getSize(component); if (size == null) { return component.getWidth(); } return size.width; }
private JComponent createDetails() { JLabel titleLabel = new JLabel(CurrentLocale.get("wizard.controls.title")); //$NON-NLS-1$ JLabel descriptionLabel = new JLabel(CurrentLocale.get("wizard.controls.description")); //$NON-NLS-1$ title = new I18nTextField(BundleCache.getLanguages()); description = new I18nTextField(BundleCache.getLanguages()); mandatory = new JCheckBox(CurrentLocale.get("wizard.controls.mandatory")); //$NON-NLS-1$ multiselect = new JCheckBox(CurrentLocale.get("wizard.controls.multiplegroups")); //$NON-NLS-1$ final int width1 = descriptionLabel.getPreferredSize().width; final int height1 = title.getPreferredSize().height; final int[] rows = {height1, height1, height1, height1,}; final int[] cols = {width1, TableLayout.FILL,}; JPanel all = new JPanel(new TableLayout(rows, cols)); all.add(titleLabel, new Rectangle(0, 0, 1, 1)); all.add(title, new Rectangle(1, 0, 1, 1)); all.add(descriptionLabel, new Rectangle(0, 1, 1, 1)); all.add(description, new Rectangle(1, 1, 1, 1)); all.add(mandatory, new Rectangle(0, 2, 2, 1)); all.add(multiselect, new Rectangle(0, 3, 2, 1)); return all; }
@Override public void initialize(WizardDescriptor wiz) { this.wiz = wiz; index = 0; final Project project = Templates.getProject(wiz); final JavaFileWizardIteratorFactory templateProvider = project != null ? project.getLookup().lookup(JavaFileWizardIteratorFactory.class) : null; if (templateProvider != null) { projectSpecificIterator = templateProvider.createIterator(Templates.getTemplate(wiz)); asInstantiatingIterator(projectSpecificIterator) .ifPresent((it)->it.initialize(wiz)); } panels = createPanels(wiz, projectSpecificIterator); // Make sure list of steps is accurate. String[] beforeSteps = null; Object prop = wiz.getProperty(WizardDescriptor.PROP_CONTENT_DATA); if (prop != null && prop instanceof String[]) { beforeSteps = (String[])prop; } String[] steps = createSteps (beforeSteps, panels); for (int i = 0; i < panels.length; i++) { Component c = panels[i].getComponent(); if (steps[i] == null) { // Default step name to component name of panel. // Mainly useful for getting the name of the target // chooser to appear in the list of steps. steps[i] = c.getName(); } if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent)c; // Step #. jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps); } } }
public CollapsibleErrorTable(AbstractErrorWarningTableModel errorWarningTableModel) { this.errorWarningTableModel = errorWarningTableModel; errorTable = new JTable(errorWarningTableModel) { private static final long serialVersionUID = 1L; @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { // add tooltip for last column JComponent component = (JComponent) super.prepareRenderer(renderer, row, column); if (column == getColumnCount() - 1) { component.setToolTipText(getValueAt(row, column).toString()); } return component; } }; errorScrollPane = new JScrollPane(errorTable); errorWarningTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { update(); } }); setupGUI(); }
/** * Invokes the <code>contains</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public boolean contains(JComponent a, int b, int c) { boolean returnValue = ((ComponentUI) (uis.elementAt(0))).contains(a,b,c); for (int i = 1; i < uis.size(); i++) { ((ComponentUI) (uis.elementAt(i))).contains(a,b,c); } return returnValue; }
public FileConnectionSettingsType () { this.inputFields = new JComponent[] { panel.directoryBrowseButton, panel.proxySettingsButton, panel.repositoryLabel, panel.tipLabel }; acceptableSchemes = EnumSet.of(Scheme.FILE); }
@Override public void paint(Graphics g, JComponent c) { ColorUtil.setupAntialiasing(g); TabData tabData; int x, y, width, height; String text; paintDisplayerBackground( g, c ); for (int i = 0; i < dataModel.size(); i++) { // gather data tabData = dataModel.getTab(i); x = layoutModel.getX(i); y = layoutModel.getY(i); width = layoutModel.getW(i); height = layoutModel.getH(i); text = tabData.getText(); // perform paint if (g.hitClip(x, y, width, height)) { paintTabBackground(g, i, x, y, width, height); paintTabContent(g, i, text, x, y, width, height); paintTabBorder(g, i, x, y, width, height); } } }
public static BufferedImage getAreaAsImage(final int w, final int h, final JComponent component) { final int type = BufferedImage.TYPE_INT_RGB; final BufferedImage image = new BufferedImage(w, h, type); final Graphics2D g2 = image.createGraphics(); component.paint(g2); g2.dispose(); return image; }
public JComponent createComponent(Category category, Lookup context) { Project project = getProject(context); ConfigFileManager manager = getConfigFileManager(project); SpringCustomizerPanel panel = new SpringCustomizerPanel(project, manager.getConfigFiles(), manager.getConfigFileGroups()); CategoryListener listener = new CategoryListener(manager, panel); category.setOkButtonListener(listener); category.setStoreListener(listener); return panel; }
/** * Returns a multiplexing UI instance if any of the auxiliary * <code>LookAndFeel</code>s supports this UI. Otherwise, just returns the * UI object obtained from the default <code>LookAndFeel</code>. */ public static ComponentUI createUI(JComponent a) { ComponentUI mui = new MultiScrollBarUI(); return MultiLookAndFeel.createUIs(mui, ((MultiScrollBarUI) mui).uis, a); }