use of javax.swing.border.EmptyBorder in project sonarqube by SonarSource.
the class TextLineNumber method setBorderGap.
/**
* The border gap is used in calculating the left and right insets of the
* border. Default value is 5.
*
* @param borderGap the gap in pixels
*/
public void setBorderGap(int borderGap) {
this.borderGap = borderGap;
Border inner = new EmptyBorder(0, borderGap, 0, borderGap);
setBorder(new CompoundBorder(OUTER, inner));
lastDigits = 0;
setPreferredWidth();
}
use of javax.swing.border.EmptyBorder in project jna by java-native-access.
the class AlphaMaskDemo2 method run.
public void run() {
// Must find a graphics configuration with a depth of 32 bits
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
frame = new JFrame("Alpha Mask Demo");
alphaWindow = new JWindow(frame, gconfig);
icon = new JLabel();
icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
alphaWindow.getContentPane().add(icon);
JButton quit = new JButton("Quit");
JLabel label = new JLabel("Drag this window by its image");
label.setHorizontalAlignment(SwingConstants.CENTER);
alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
MouseInputAdapter handler = new MouseInputAdapter() {
private Point offset;
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e))
offset = e.getPoint();
}
public void mouseReleased(MouseEvent e) {
offset = null;
}
public void mouseDragged(MouseEvent e) {
if (offset != null) {
Window w = (Window) e.getSource();
Point where = e.getPoint();
where.translate(-offset.x, -offset.y);
Point loc = w.getLocationOnScreen();
loc.translate(where.x, where.y);
w.setLocation(loc.x, loc.y);
}
}
};
alphaWindow.addMouseListener(handler);
alphaWindow.addMouseMotionListener(handler);
JPanel p = new JPanel(new BorderLayout(8, 8));
p.setBorder(new EmptyBorder(8, 8, 8, 8));
p.setTransferHandler(new TransferHandler() {
private static final long serialVersionUID = 1L;
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
List<DataFlavor> list = Arrays.asList(transferFlavors);
if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
return true;
}
if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
return true;
}
System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
return false;
}
public boolean importData(JComponent comp, Transferable t) {
try {
if (t.isDataFlavorSupported(URL_FLAVOR)) {
URL url = (URL) t.getTransferData(URL_FLAVOR);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
String s = (String) t.getTransferData(URI_LIST_FLAVOR);
String[] uris = s.split("[\r\n]");
if (uris.length > 0) {
URL url = new URL(uris[0]);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
return false;
}
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
setImage(image);
return true;
}
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
File f = files.get(0);
URL url = new URL("file://" + f.toURI().toURL().getPath());
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
if (flavor != null) {
Reader reader = flavor.getReaderForText(t);
char[] buf = new char[512];
StringBuilder b = new StringBuilder();
int count;
// encoding wrong
while ((count = reader.read(buf)) > 0) {
for (int i = 0; i < count; i++) {
if (buf[i] != 0)
b.append(buf, i, 1);
}
}
String html = b.toString();
Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
Matcher m = p.matcher(html);
if (m.find()) {
URL url = new URL(m.group(1));
System.out.println("Load image from " + url);
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
System.err.println("Can't parse text: " + html);
return false;
}
System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
});
p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
final JSlider slider = new JSlider(0, 255, 255);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
}
});
p.add(slider, BorderLayout.SOUTH);
frame.getContentPane().add(p);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
centerOnScreen(frame);
frame.setVisible(true);
WindowUtils.setWindowTransparent(alphaWindow, true);
alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
try {
URL url = getClass().getResource("tardis.png");
if (url != null) {
setImage(Toolkit.getDefaultToolkit().getImage(url));
}
} catch (Exception e) {
}
}
use of javax.swing.border.EmptyBorder in project jna by java-native-access.
the class BalloonManagerDemo method main.
public static void main(String[] args) {
try {
System.setProperty("sun.java2d.noddraw", "true");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
JFrame f = new JFrame("Balloon Test");
final String BALLOON_TEXT = "<html><center>" + "This is some sample balloon text<br>" + "which has been formatted with html.<br>" + "Click to dismiss.</center></html>";
final JLabel content = new JLabel(BALLOON_TEXT);
content.setIconTextGap(10);
content.setBorder(new EmptyBorder(0, 8, 0, 8));
content.setSize(content.getPreferredSize());
content.setIcon(new InfoIcon());
JLabel label = new JLabel("Click anywhere for more information");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.addMouseListener(new MouseAdapter() {
private MouseListener listener = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
hidePopup(e);
}
};
private Popup popup;
private void hidePopup(MouseEvent e) {
e.getComponent().removeMouseListener(listener);
if (popup != null)
popup.hide();
}
public void mousePressed(MouseEvent e) {
hidePopup(e);
popup = BalloonManager.getBalloon(e.getComponent(), content, e.getX(), e.getY());
popup.show();
content.getParent().addMouseListener(listener);
}
});
f.getContentPane().add(label);
f.pack();
f.setSize(new Dimension(300, 300));
f.setLocation(100, 100);
try {
// Force a load of JNA
WindowUtils.setWindowMask(f, WindowUtils.MASK_NONE);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
String msg = e.getMessage() + "\nError loading the JNA library";
JTextArea area = new JTextArea(msg);
area.setOpaque(false);
area.setFont(UIManager.getFont("Label.font"));
area.setEditable(false);
area.setColumns(80);
area.setRows(8);
area.setWrapStyleWord(true);
area.setLineWrap(true);
JOptionPane.showMessageDialog(null, new JScrollPane(area), "Library Load Error: " + System.getProperty("os.name") + "/" + System.getProperty("os.arch"), JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
use of javax.swing.border.EmptyBorder in project processing by processing.
the class DetailPanel method setContribution.
public void setContribution(Contribution contrib) {
this.contrib = contrib;
if (contrib.isSpecial()) {
JLabel iconLabel = new JLabel(foundationIcon);
iconLabel.setBorder(new EmptyBorder(4, 7, 7, 7));
iconLabel.setVerticalAlignment(SwingConstants.TOP);
add(iconLabel, BorderLayout.WEST);
}
// Avoid ugly synthesized bold
Font boldFont = ManagerFrame.SMALL_BOLD;
String fontFace = "<font face=\"" + boldFont.getName() + "\">";
StringBuilder desc = new StringBuilder();
desc.append("<html><body>" + fontFace);
if (contrib.getUrl() == null) {
desc.append(contrib.getName());
} else {
desc.append("<a href=\"" + contrib.getUrl() + "\">" + contrib.getName() + "</a>");
}
desc.append("</font> ");
String prettyVersion = contrib.getPrettyVersion();
if (prettyVersion != null) {
desc.append(prettyVersion);
}
desc.append(" <br/>");
String authorList = contrib.getAuthorList();
if (authorList != null && !authorList.isEmpty()) {
desc.append(toHtmlLinks(contrib.getAuthorList()));
}
desc.append("<br/><br/>");
if (contrib.isDeletionFlagged()) {
desc.append(REMOVE_RESTART_MESSAGE);
} else if (contrib.isRestartFlagged()) {
desc.append(INSTALL_RESTART_MESSAGE);
} else if (contrib.isUpdateFlagged()) {
desc.append(UPDATE_RESTART_MESSAGE);
} else {
String sentence = contrib.getSentence();
if (sentence == null || sentence.isEmpty()) {
sentence = String.format("<i>%s</i>", Language.text("contrib.errors.description_unavailable"));
} else {
sentence = sanitizeHtmlTags(sentence);
sentence = toHtmlLinks(sentence);
}
desc.append(sentence);
}
long lastUpdatedUTC = contrib.getLastUpdated();
if (lastUpdatedUTC != 0) {
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM);
Date lastUpdatedDate = new Date(lastUpdatedUTC);
if (prettyVersion != null) {
desc.append(", ");
}
desc.append("Last Updated on " + dateFormatter.format(lastUpdatedDate));
}
desc.append("</body></html>");
description = desc.toString();
descriptionPane.setText(description);
if (contribListing.hasUpdates(contrib) && contrib.isCompatible(Base.getRevision())) {
StringBuilder versionText = new StringBuilder();
versionText.append("<html><body><i>");
if (contrib.isUpdateFlagged() || contrib.isDeletionFlagged()) {
// versionText.append("To finish an update, reinstall this contribution after restarting.");
;
} else {
String latestVersion = contribListing.getLatestPrettyVersion(contrib);
if (latestVersion != null) {
versionText.append("New version (" + latestVersion + ") available.");
} else {
versionText.append("New version available.");
}
}
versionText.append("</i></body></html>");
notificationLabel.setText(versionText.toString());
notificationLabel.setVisible(true);
} else {
notificationLabel.setText("");
notificationLabel.setVisible(false);
}
updateButton.setEnabled(true);
if (contrib != null) {
updateButton.setVisible((contribListing.hasUpdates(contrib) && !contrib.isUpdateFlagged() && !contrib.isDeletionFlagged()) || updateInProgress);
}
if (contrib.isDeletionFlagged()) {
installRemoveButton.setText(undoText);
} else if (contrib.isInstalled()) {
installRemoveButton.setText(removeText);
installRemoveButton.setVisible(true);
installRemoveButton.setEnabled(!contrib.isUpdateFlagged());
reorganizePaneComponents();
} else {
installRemoveButton.setText(installText);
}
contextMenu.removeAll();
if (contrib.isInstalled()) {
contextMenu.add(openFolder);
setComponentPopupMenu(contextMenu);
} else {
setComponentPopupMenu(null);
}
if (!contrib.isCompatible(Base.getRevision())) {
blurContributionPanel(this);
}
}
use of javax.swing.border.EmptyBorder in project processing by processing.
the class MovieMaker method init.
public void init(Base base) {
initComponents(base.getActiveEditor() == null);
((JComponent) getContentPane()).setBorder(new EmptyBorder(12, 18, 18, 18));
imageFolderField.setTransferHandler(new FileTextFieldTransferHandler(JFileChooser.DIRECTORIES_ONLY));
soundFileField.setTransferHandler(new FileTextFieldTransferHandler());
JComponent[] smallComponents = { compressionBox, compressionLabel, fpsField, fpsLabel, widthField, widthLabel, heightField, heightLabel, originalSizeCheckBox };
for (JComponent c : smallComponents) {
c.putClientProperty("JComponent.sizeVariant", "small");
}
// Get Preferences
prefs = Preferences.userNodeForPackage(MovieMaker.class);
imageFolderField.setText(prefs.get("movie.imageFolder", ""));
soundFileField.setText(prefs.get("movie.soundFile", ""));
widthField.setText("" + prefs.getInt("movie.width", 640));
heightField.setText("" + prefs.getInt("movie.height", 480));
boolean original = prefs.getBoolean("movie.originalSize", false);
originalSizeCheckBox.setSelected(original);
widthField.setEnabled(!original);
heightField.setEnabled(!original);
String fps = "" + prefs.getDouble("movie.fps", 30);
if (fps.endsWith(".0")) {
fps = fps.substring(0, fps.length() - 2);
}
fpsField.setText(fps);
compressionBox.setSelectedIndex(Math.max(0, Math.min(compressionBox.getItemCount() - 1, prefs.getInt("movie.compression", 0))));
originalSizeCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean enabled = !originalSizeCheckBox.isSelected();
widthField.setEnabled(enabled);
heightField.setEnabled(enabled);
}
});
// String streaming = prefs.get("movie.streaming", "fastStartCompressed");
// for (Enumeration<AbstractButton> i = streamingGroup.getElements(); i.hasMoreElements();) {
// AbstractButton btn = i.nextElement();
// if (btn.getActionCommand().equals(streaming)) {
// btn.setSelected(true);
// break;
// }
// }
// scoot everybody around
pack();
// center the frame on screen
setLocationRelativeTo(null);
}
Aggregations