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;
}
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);
}
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;
}
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);
}
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());
}
}
Aggregations