Search in sources :

Example 56 with Panel

use of java.awt.Panel in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.

private Composite createJSONEditorComposite(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, true));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    if (isWindows()) {
        Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        final GridLayout gridLayout = new GridLayout();
        gridLayout.verticalSpacing = 0;
        gridLayout.marginWidth = 0;
        gridLayout.marginHeight = 0;
        gridLayout.horizontalSpacing = 0;
        embedComposite.setLayout(gridLayout);
        embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        Frame frame = SWT_AWT.new_Frame(embedComposite);
        Panel heavyWeightPanel = new Panel();
        heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
        frame.add(heavyWeightPanel);
        frame.setFocusTraversalKeysEnabled(false);
        // Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
        // This reduces flicker on resize in RSyntaxTextArea
        JApplet applet = new JApplet();
        JRootPane root = applet.getRootPane();
        Container contentPane = root.getContentPane();
        contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
        heavyWeightPanel.add(applet);
        m_textArea = new RSyntaxTextArea(10, 60);
        m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
        m_textArea.setCodeFoldingEnabled(true);
        m_textArea.setAntiAliasingEnabled(true);
        RTextScrollPane sp = new RTextScrollPane(m_textArea);
        sp.setDoubleBuffered(true);
        m_textArea.setText(m_jsonDocument);
        m_textArea.setEditable(true);
        m_textArea.setEnabled(true);
        contentPane.add(sp);
        Dimension size = sp.getPreferredSize();
        embedComposite.setSize(size.width, size.height);
        // forward focus to RSyntaxTextArea
        embedComposite.addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(final FocusEvent e) {
                ViewUtils.runOrInvokeLaterInEDT(new Runnable() {

                    @Override
                    public void run() {
                        m_textArea.requestFocus();
                        m_textArea.setCaretPosition(m_caretPosition);
                    }
                });
            }

            @Override
            public void focusLost(final FocusEvent e) {
            // do nothing
            }
        });
        // delete content of status line, when something is inserted or deleted
        m_textArea.getDocument().addDocumentListener(new DocumentListener() {

            @Override
            public void changedUpdate(final DocumentEvent arg0) {
                if (!composite.isDisposed()) {
                    composite.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            if (m_statusLine != null && !m_statusLine.isDisposed()) {
                                m_statusLine.setText("");
                                updateModelFromJson();
                            }
                        }
                    });
                }
            }

            @Override
            public void insertUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }

            @Override
            public void removeUpdate(final DocumentEvent arg0) {
            /* do nothing */
            }
        });
        // remember caret position
        m_textArea.addCaretListener(new CaretListener() {

            @Override
            public void caretUpdate(final CaretEvent arg0) {
                m_caretPosition = arg0.getDot();
            }
        });
    } else {
        m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        GridData layoutData = new GridData(GridData.FILL_BOTH);
        layoutData.widthHint = 600;
        layoutData.heightHint = 400;
        m_text.setLayoutData(layoutData);
        m_text.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                m_jsonDocument = m_text.getText();
                if (m_statusLine != null && !m_statusLine.isDisposed()) {
                    m_statusLine.setText("");
                    updateModelFromJson();
                }
            }
        });
        m_text.setText(m_jsonDocument);
    }
    // add status line
    m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
    GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
    int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
    statusGridData.heightHint = maxHeight + 5;
    // seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
    statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
    m_statusLine.setLayoutData(statusGridData);
    compareNodeIDs();
    return composite;
}
Also used : CaretEvent(javax.swing.event.CaretEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) DocumentListener(javax.swing.event.DocumentListener) Frame(java.awt.Frame) ModifyListener(org.eclipse.swt.events.ModifyListener) BoxLayout(javax.swing.BoxLayout) Label(org.eclipse.swt.widgets.Label) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) JApplet(javax.swing.JApplet) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) Container(java.awt.Container) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Text(org.eclipse.swt.widgets.Text) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) Point(org.eclipse.swt.graphics.Point) Panel(java.awt.Panel) CaretListener(javax.swing.event.CaretListener) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) JRootPane(javax.swing.JRootPane) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Example 57 with Panel

use of java.awt.Panel in project bundle-app-ui by astrapi69.

the class HelpJFrame method createLayout.

/**
 * Creates the layout.
 */
private void createLayout() {
    jlabelTitle = new JLabel(LABEL_HELP);
    getContentPane().add(jlabelTitle, BorderLayout.NORTH);
    // JTextArea Help:
    jtaHelp = new JTextArea(10, 10);
    jtpHelp = new JTextPane();
    jtpHelp.replaceSelection(helptext);
    jtaHelp.setText(helptext);
    jtaHelp.setCaretPosition(0);
    jtaHelp.setLineWrap(true);
    jtaHelp.setWrapStyleWord(true);
    jtaHelp.setEditable(false);
    jscrollPanejtaHelp = new JScrollPane(jtpHelp);
    getContentPane().add(jscrollPanejtaHelp, BorderLayout.CENTER);
    buttonClose = new JButton(BUTTONLABEL_CLOSE);
    buttonClose.addActionListener(new DisposeWindowAction(this));
    final Panel unten = new Panel();
    unten.add(buttonClose, BorderLayout.WEST);
    getContentPane().add(unten, BorderLayout.SOUTH);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextPane(javax.swing.JTextPane) Panel(java.awt.Panel) JTextArea(javax.swing.JTextArea) DisposeWindowAction(de.alpharogroup.actions.DisposeWindowAction) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel)

Example 58 with Panel

use of java.awt.Panel in project bioformats by openmicroscopy.

the class ColorDialog method createSwatch.

private Panel createSwatch(Color color) {
    Panel swatch = new Panel();
    swatch.setPreferredSize(SWATCH_SIZE);
    swatch.setMinimumSize(SWATCH_SIZE);
    swatch.setMaximumSize(SWATCH_SIZE);
    swatch.setBackground(color);
    return swatch;
}
Also used : Panel(java.awt.Panel)

Example 59 with Panel

use of java.awt.Panel in project bioformats by openmicroscopy.

the class SeriesDialog method rebuildDialog.

private void rebuildDialog(GenericDialog gd, int buttonRow) {
    // rebuild dialog to organize things more nicely
    final String cols = p == null ? "pref" : "pref, 3dlu, pref";
    final StringBuilder sb = new StringBuilder("pref");
    for (int s = 1; s < boxes.length; s++) sb.append(", 3dlu, pref");
    final String rows = sb.toString();
    final PanelBuilder builder = new PanelBuilder(new FormLayout(cols, rows));
    final CellConstraints cc = new CellConstraints();
    int row = 1;
    for (int s = 0; s < boxes.length; s++) {
        builder.add(boxes[s], cc.xy(1, row));
        if (p != null)
            builder.add(p[s], cc.xy(3, row));
        row += 2;
    }
    final JPanel masterPanel = builder.getPanel();
    gd.removeAll();
    GridBagLayout gdl = (GridBagLayout) gd.getLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gdl.setConstraints(masterPanel, gbc);
    gd.add(masterPanel);
    WindowTools.addScrollBars(gd);
    // HACK: workaround for JPanel in a Dialog
    gd.setBackground(Color.white);
    // add Select All and Deselect All buttons
    Panel buttons = new Panel();
    Button select = new Button("Select All");
    select.setActionCommand("select");
    select.addActionListener(this);
    Button deselect = new Button("Deselect All");
    deselect.setActionCommand("deselect");
    deselect.addActionListener(this);
    buttons.add(select);
    buttons.add(deselect);
    gbc.gridx = 2;
    gbc.gridy = buttonRow;
    gbc.anchor = GridBagConstraints.EAST;
    gbc.insets = new Insets(15, 0, 0, 0);
    gdl.setConstraints(buttons, gbc);
    gd.add(buttons);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) JPanel(javax.swing.JPanel) Panel(java.awt.Panel) JPanel(javax.swing.JPanel) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Button(java.awt.Button) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 60 with Panel

use of java.awt.Panel in project jsql-injection by ron190.

the class ShadowPopup method reset.

/**
 * Reinitializes this ShadowPopup using the given parameters.
 *
 * @param owner component mouse coordinates are relative to, may be null
 * @param contents the contents of the popup
 * @param x the desired x location of the popup
 * @param y the desired y location of the popup
 * @param popup the popup to wrap
 */
private void reset(Component owner, Component contents, int x, int y, Popup popup) {
    this.owner = owner;
    this.contents = contents;
    this.popup = popup;
    this.x = x;
    this.y = y;
    // Do not install the shadow border when the contents
    // has a preferred size less than or equal to 0.
    // We can't use the size, because it is(0, 0) for new popups.
    Dimension contentsPrefSize = new Dimension();
    // Implementation by javax.swing.plaf.metal.MetalToolTipUI.getPreferredSize()
    try {
        contentsPrefSize = contents.getPreferredSize();
    } catch (NullPointerException e) {
        LOGGER.error(e.getMessage(), e);
    }
    if (contentsPrefSize.width <= 0 || contentsPrefSize.height <= 0) {
        return;
    }
    for (Container p = contents.getParent(); p != null; p = p.getParent()) {
        if (p instanceof JWindow || p instanceof Panel) {
            // Workaround for the gray rect problem.
            p.setBackground(contents.getBackground());
            this.heavyWeightContainer = p;
            break;
        }
    }
    JComponent parent = (JComponent) contents.getParent();
    this.oldOpaque = parent.isOpaque();
    this.oldBorder = parent.getBorder();
    parent.setOpaque(false);
    parent.setBorder(SHADOW_BORDER);
    // Pack it because we have changed the border.
    if (this.heavyWeightContainer != null) {
        this.heavyWeightContainer.setSize(this.heavyWeightContainer.getPreferredSize());
    } else {
        parent.setSize(parent.getPreferredSize());
    }
}
Also used : Panel(java.awt.Panel) Container(java.awt.Container) JWindow(javax.swing.JWindow) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension)

Aggregations

Panel (java.awt.Panel)70 BorderLayout (java.awt.BorderLayout)26 Button (java.awt.Button)25 Label (java.awt.Label)25 Frame (java.awt.Frame)18 GridBagLayout (java.awt.GridBagLayout)17 TextField (java.awt.TextField)17 GridBagConstraints (java.awt.GridBagConstraints)16 JPanel (javax.swing.JPanel)14 Dimension (java.awt.Dimension)13 Insets (java.awt.Insets)10 Point (java.awt.Point)10 Choice (java.awt.Choice)9 FlowLayout (java.awt.FlowLayout)9 Graphics (java.awt.Graphics)9 Checkbox (java.awt.Checkbox)7 GridLayout (java.awt.GridLayout)7 Font (java.awt.Font)6 JButton (javax.swing.JButton)6 Component (java.awt.Component)5