move some code to framework lib

This commit is contained in:
Branislav Stojkovic
2016-10-30 09:11:20 +01:00
parent 22b06e2a3b
commit f6e5078028
9 changed files with 2 additions and 1632 deletions
@@ -238,6 +238,7 @@ public class UploadDialog extends ButtonDialog {
private JTextField getKeywordsField() {
if (keywordsField == null) {
keywordsField = new JTextField();
keywordsField.setColumns(32);
keywordsField.setText(KeywordExtractor.getInstance().extractKeywords(plugInPort.getCurrentProject()));
}
return keywordsField;
@@ -25,7 +25,7 @@ import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Template;
import org.diylc.images.IconLoader;
import org.diylc.swing.plugins.toolbox.openide.DropDownButtonFactory;
import org.diylc.swingframework.openide.DropDownButtonFactory;
/**
* Factory that creates {@link JButton}s which display component type icons and instantiates the
@@ -1,374 +0,0 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultButtonModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPopupMenu;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
class DropDownButton extends JButton {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
private boolean mouseInButton = false;
private boolean mouseInArrowArea = false;
private Map<String, Icon> regIcons = new HashMap<String, Icon>(5);
private Map<String, Icon> arrowIcons = new HashMap<String, Icon>(5);
private static final String ICON_NORMAL = "normal";
private static final String ICON_PRESSED = "pressed";
private static final String ICON_ROLLOVER = "rollover";
private static final String ICON_ROLLOVER_SELECTED = "rolloverSelected";
private static final String ICON_SELECTED = "selected";
private static final String ICON_DISABLED = "disabled";
private static final String ICON_DISABLED_SELECTED = "disabledSelected";
private static final String ICON_ROLLOVER_LINE = "rolloverLine";
private static final String ICON_ROLLOVER_SELECTED_LINE = "rolloverSelectedLine";
private PopupMenuListener menuListener;
public DropDownButton(Icon icon, JPopupMenu popup) {
Parameters.notNull((CharSequence) "icon", (Object) icon);
assert (null != icon);
this.putClientProperty("dropDownMenu", popup);
this.setIcon(icon);
this.setDisabledIcon(ImageUtilities.createDisabledIcon((Icon) icon));
this.resetIcons();
this.addPropertyChangeListener("dropDownMenu", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
DropDownButton.this.resetIcons();
}
});
this.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
if (null != DropDownButton.this.getPopupMenu()) {
DropDownButton.this.mouseInArrowArea = DropDownButton.this.isInArrowArea(e.getPoint());
DropDownButton.this.updateRollover(DropDownButton.this._getRolloverIcon(),
DropDownButton.this._getRolloverSelectedIcon());
}
}
});
this.addMouseListener(new MouseAdapter() {
private boolean popupMenuOperation;
@Override
public void mousePressed(MouseEvent e) {
this.popupMenuOperation = false;
JPopupMenu menu = DropDownButton.this.getPopupMenu();
if (menu != null && DropDownButton.this.getModel() instanceof Model) {
Model model = (Model) DropDownButton.this.getModel();
if (!model._isPressed()) {
if (DropDownButton.this.isInArrowArea(e.getPoint()) && menu.getComponentCount() > 0) {
model._press();
menu.addPopupMenuListener(DropDownButton.this.getMenuListener());
menu.show(DropDownButton.this, 0, DropDownButton.this.getHeight());
this.popupMenuOperation = true;
}
} else {
model._release();
menu.removePopupMenuListener(DropDownButton.this.getMenuListener());
this.popupMenuOperation = true;
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (this.popupMenuOperation) {
this.popupMenuOperation = false;
e.consume();
}
}
@Override
public void mouseEntered(MouseEvent e) {
DropDownButton.this.mouseInButton = true;
if (DropDownButton.this.hasPopupMenu()) {
DropDownButton.this.mouseInArrowArea = DropDownButton.this.isInArrowArea(e.getPoint());
DropDownButton.this.updateRollover(DropDownButton.this._getRolloverIcon(),
DropDownButton.this._getRolloverSelectedIcon());
}
}
@Override
public void mouseExited(MouseEvent e) {
DropDownButton.this.mouseInButton = false;
DropDownButton.this.mouseInArrowArea = false;
if (DropDownButton.this.hasPopupMenu()) {
DropDownButton.this.updateRollover(DropDownButton.this._getRolloverIcon(),
DropDownButton.this._getRolloverSelectedIcon());
}
}
});
this.setModel(new Model());
}
private PopupMenuListener getMenuListener() {
if (null == this.menuListener) {
this.menuListener = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
JPopupMenu menu;
if (DropDownButton.this.getModel() instanceof Model) {
((Model) DropDownButton.this.getModel())._release();
}
if (null != (menu = DropDownButton.this.getPopupMenu())) {
menu.removePopupMenuListener(this);
}
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {}
};
}
return this.menuListener;
}
private void updateRollover(Icon rollover, Icon rolloverSelected) {
super.setRolloverIcon(rollover);
super.setRolloverSelectedIcon(rolloverSelected);
}
private void resetIcons() {
Icon icon = this.regIcons.get(ICON_NORMAL);
if (null != icon) {
this.setIcon(icon);
}
if (null != (icon = this.regIcons.get(ICON_PRESSED))) {
this.setPressedIcon(icon);
}
if (null != (icon = this.regIcons.get(ICON_ROLLOVER))) {
this.setRolloverIcon(icon);
}
if (null != (icon = this.regIcons.get(ICON_ROLLOVER_SELECTED))) {
this.setRolloverSelectedIcon(icon);
}
if (null != (icon = this.regIcons.get(ICON_SELECTED))) {
this.setSelectedIcon(icon);
}
if (null != (icon = this.regIcons.get(ICON_DISABLED))) {
this.setDisabledIcon(icon);
}
if (null != (icon = this.regIcons.get(ICON_DISABLED_SELECTED))) {
this.setDisabledSelectedIcon(icon);
}
}
private Icon _getRolloverIcon() {
Icon icon = null;
icon = this.arrowIcons.get(this.mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE);
if (null == icon) {
Icon orig = this.regIcons.get(ICON_ROLLOVER);
if (null == orig) {
orig = this.regIcons.get(ICON_NORMAL);
}
icon = new IconWithArrow(orig, !this.mouseInArrowArea);
this.arrowIcons.put(this.mouseInArrowArea ? ICON_ROLLOVER : ICON_ROLLOVER_LINE, icon);
}
return icon;
}
private Icon _getRolloverSelectedIcon() {
Icon icon = null;
icon = this.arrowIcons.get(this.mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE);
if (null == icon) {
Icon orig = this.regIcons.get(ICON_ROLLOVER_SELECTED);
if (null == orig) {
orig = this.regIcons.get(ICON_ROLLOVER);
}
if (null == orig) {
orig = this.regIcons.get(ICON_NORMAL);
}
icon = new IconWithArrow(orig, !this.mouseInArrowArea);
this.arrowIcons.put(this.mouseInArrowArea ? ICON_ROLLOVER_SELECTED : ICON_ROLLOVER_SELECTED_LINE, icon);
}
return icon;
}
JPopupMenu getPopupMenu() {
Object menu = this.getClientProperty("dropDownMenu");
if (menu instanceof JPopupMenu) {
return (JPopupMenu) menu;
}
return null;
}
boolean hasPopupMenu() {
return null != this.getPopupMenu();
}
private boolean isInArrowArea(Point p) {
return p.getLocation().x >= this.getWidth() - IconWithArrow.getArrowAreaWidth() - this.getInsets().right;
}
@Override
public void setIcon(Icon icon) {
assert (null != icon);
Icon arrow = this.updateIcons(icon, ICON_NORMAL);
this.arrowIcons.remove(ICON_ROLLOVER_LINE);
this.arrowIcons.remove(ICON_ROLLOVER_SELECTED_LINE);
this.arrowIcons.remove(ICON_ROLLOVER);
this.arrowIcons.remove(ICON_ROLLOVER_SELECTED);
super.setIcon(this.hasPopupMenu() ? arrow : icon);
}
private Icon updateIcons(Icon orig, String iconType) {
ImageIcon arrow = null;
if (null == orig) {
this.regIcons.remove(iconType);
this.arrowIcons.remove(iconType);
} else {
this.regIcons.put(iconType, orig);
arrow = new ImageIcon(ImageUtilities.icon2Image((Icon) new IconWithArrow(orig, false)));
this.arrowIcons.put(iconType, arrow);
}
return arrow;
}
@Override
public void setPressedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, ICON_PRESSED);
super.setPressedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setSelectedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, ICON_SELECTED);
super.setSelectedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setRolloverIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, ICON_ROLLOVER);
this.arrowIcons.remove(ICON_ROLLOVER_LINE);
this.arrowIcons.remove(ICON_ROLLOVER_SELECTED_LINE);
super.setRolloverIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setRolloverSelectedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, ICON_ROLLOVER_SELECTED);
this.arrowIcons.remove(ICON_ROLLOVER_SELECTED_LINE);
super.setRolloverSelectedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setDisabledIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, ICON_DISABLED);
super.setDisabledIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setDisabledSelectedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, ICON_DISABLED_SELECTED);
super.setDisabledSelectedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setText(String text) {}
@Override
public String getText() {
return null;
}
private class Model extends DefaultButtonModel {
private static final long serialVersionUID = 1L;
private boolean _pressed;
private Model() {
this._pressed = false;
}
@Override
public void setPressed(boolean b) {
if (DropDownButton.this.mouseInArrowArea || this._pressed) {
return;
}
super.setPressed(b);
}
public void _press() {
if (this.isPressed() || !this.isEnabled()) {
return;
}
this.stateMask |= 5;
this.fireStateChanged();
this._pressed = true;
}
public void _release() {
this._pressed = false;
DropDownButton.this.mouseInArrowArea = false;
this.setArmed(false);
this.setPressed(false);
this.setRollover(false);
this.setSelected(false);
}
public boolean _isPressed() {
return this._pressed;
}
@Override
protected void fireStateChanged() {
if (this._pressed) {
return;
}
super.fireStateChanged();
}
@Override
public void setArmed(boolean b) {
if (this._pressed) {
return;
}
super.setArmed(b);
}
@Override
public void setEnabled(boolean b) {
if (this._pressed) {
return;
}
super.setEnabled(b);
}
@Override
public void setSelected(boolean b) {
if (this._pressed) {
return;
}
super.setSelected(b);
}
@Override
public void setRollover(boolean b) {
if (this._pressed) {
return;
}
super.setRollover(b);
}
}
}
@@ -1,13 +0,0 @@
package org.diylc.swing.plugins.toolbox.openide;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPopupMenu;
public final class DropDownButtonFactory {
public static final String PROP_DROP_DOWN_MENU = "dropDownMenu";
public static JButton createDropDownButton(Icon icon, JPopupMenu dropDownMenu) {
return new DropDownButton(icon, dropDownMenu);
}
}
@@ -1,56 +0,0 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.UIManager;
import org.diylc.images.IconLoader;
class IconWithArrow implements Icon {
private Icon orig;
private Icon arrow = IconLoader.Arrow.getIcon();
private boolean paintRollOver;
public IconWithArrow(Icon orig, boolean paintRollOver) {
Parameters.notNull("original icon", orig);
this.orig = orig;
this.paintRollOver = paintRollOver;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
int height = getIconHeight();
this.orig.paintIcon(c, g, x, y + (height - this.orig.getIconHeight()) / 2);
this.arrow.paintIcon(c, g, x + 6 + this.orig.getIconWidth(), y + (height - this.arrow.getIconHeight()) / 2);
if (this.paintRollOver) {
Color brighter = UIManager.getColor("controlHighlight");
Color darker = UIManager.getColor("controlShadow");
if ((null == brighter) || (null == darker)) {
brighter = c.getBackground().brighter();
darker = c.getBackground().darker();
}
if ((null != brighter) && (null != darker)) {
g.setColor(brighter);
g.drawLine(x + this.orig.getIconWidth() + 1, y, x + this.orig.getIconWidth() + 1, y + getIconHeight());
g.setColor(darker);
g.drawLine(x + this.orig.getIconWidth() + 2, y, x + this.orig.getIconWidth() + 2, y + getIconHeight());
}
}
}
public int getIconWidth() {
return this.orig.getIconWidth() + 6 + this.arrow.getIconWidth();
}
public int getIconHeight() {
return Math.max(this.orig.getIconHeight(), this.arrow.getIconHeight());
}
public static int getArrowAreaWidth() {
return 8;
}
}
@@ -1,210 +0,0 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageObserver;
import java.awt.image.RGBImageFilter;
import java.awt.image.WritableRaster;
import java.net.URL;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public final class ImageUtilities {
static final String TOOLTIP_SEPAR = "<br>";
private ImageUtilities() {}
public static final Icon image2Icon(Image image) {
if (image instanceof ToolTipImage) {
return ((ToolTipImage) image).getIcon();
}
return new ImageIcon(image);
}
public static final Image icon2Image(Icon icon) {
if (icon instanceof ImageIcon) {
return ((ImageIcon) icon).getImage();
}
ToolTipImage image = new ToolTipImage("", icon.getIconWidth(), icon.getIconHeight(), 2);
Graphics g = image.getGraphics();
icon.paintIcon(new JLabel(), g, 0, 0);
g.dispose();
return image;
}
public static final String getImageToolTip(Image image) {
if (image instanceof ToolTipImage) {
return ((ToolTipImage) image).toolTipText;
}
return "";
}
public static Icon createDisabledIcon(Icon icon) {
Parameters.notNull("icon", icon);
return new LazyDisabledIcon(ImageUtilities.icon2Image(icon));
}
public static Image createDisabledImage(Image image) {
Parameters.notNull("image", image);
return LazyDisabledIcon.createDisabledImage(image);
}
static final Image toBufferedImage(Image img) {
new ImageIcon(img, "");
if (img.getHeight(null) * img.getWidth(null) > 576) {
return img;
}
BufferedImage rep = ImageUtilities.createBufferedImage(img.getWidth(null), img.getHeight(null));
Graphics2D g = rep.createGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
img.flush();
return rep;
}
static final BufferedImage createBufferedImage(int width, int height) {
if (Utilities.isMac()) {
return new BufferedImage(width, height, 3);
}
ColorModel model = ImageUtilities.colorModel(3);
BufferedImage buffImage =
new BufferedImage(model, model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(),
null);
return buffImage;
}
private static ColorModel colorModel(int transparency) {
ColorModel model;
try {
model =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration()
.getColorModel(transparency);
} catch (HeadlessException he) {
model = ColorModel.getRGBdefault();
}
return model;
}
static {
ImageIO.setUseCache(false);
}
private static class DisabledButtonFilter extends RGBImageFilter {
DisabledButtonFilter() {
this.canFilterIndexColorModel = true;
}
@Override
public int filterRGB(int x, int y, int rgb) {
return (rgb & -16777216) + 8947848 + ((rgb >> 16 & 255) >> 2 << 16) + ((rgb >> 8 & 255) >> 2 << 8)
+ ((rgb & 255) >> 2);
}
public void setProperties(Hashtable<?, ?> props) {
props = (Hashtable<?, ?>) props.clone();
this.consumer.setProperties(props);
}
}
private static class LazyDisabledIcon implements Icon {
private static final RGBImageFilter DISABLED_BUTTON_FILTER = new DisabledButtonFilter();
private Image img;
private Icon disabledIcon;
public LazyDisabledIcon(Image img) {
assert (null != img);
this.img = img;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
this.getDisabledIcon().paintIcon(c, g, x, y);
}
@Override
public int getIconWidth() {
return this.getDisabledIcon().getIconWidth();
}
@Override
public int getIconHeight() {
return this.getDisabledIcon().getIconHeight();
}
private synchronized Icon getDisabledIcon() {
if (null == this.disabledIcon) {
this.disabledIcon = new ImageIcon(LazyDisabledIcon.createDisabledImage(this.img));
}
return this.disabledIcon;
}
static Image createDisabledImage(Image img) {
FilteredImageSource prod = new FilteredImageSource(img.getSource(), DISABLED_BUTTON_FILTER);
return Toolkit.getDefaultToolkit().createImage(prod);
}
}
private static class ToolTipImage extends BufferedImage implements Icon {
final String toolTipText;
ImageIcon imageIcon;
final URL url;
public ToolTipImage(String toolTipText, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied,
Hashtable<?, ?> properties, URL url) {
super(cm, raster, isRasterPremultiplied, properties);
this.toolTipText = toolTipText;
this.url = url;
}
public ToolTipImage(String toolTipText, int width, int height, int imageType) {
super(width, height, imageType);
this.toolTipText = toolTipText;
this.url = null;
}
synchronized ImageIcon getIcon() {
if (this.imageIcon == null) {
this.imageIcon = new ImageIcon(this);
}
return this.imageIcon;
}
@Override
public int getIconHeight() {
return super.getHeight();
}
@Override
public int getIconWidth() {
return super.getWidth();
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.drawImage(this, x, y, null);
}
@Override
public Object getProperty(String name, ImageObserver observer) {
if ("url".equals(name)) {
if (this.url != null) {
return this.url;
}
return this.imageIcon.getImage().getProperty("url", observer);
}
return super.getProperty(name, observer);
}
}
}
@@ -1,35 +0,0 @@
package org.diylc.swing.plugins.toolbox.openide;
public class Parameters {
public static void notNull(CharSequence name, Object value) {
if (value == null) {
throw new NullPointerException("The " + name + " parameter cannot be null");
}
}
public static void notEmpty(CharSequence name, CharSequence value) {
notNull(name, value);
if (value.length() == 0) {
throw new IllegalArgumentException("The " + name + " parameter cannot be an empty character sequence");
}
}
public static void notWhitespace(CharSequence name, CharSequence value) {
notNull(name, value);
if (value.toString().trim().length() == 0) {
throw new IllegalArgumentException("The " + name
+ " parameter must contain at least one non-whitespace character");
}
}
public static void javaIdentifier(CharSequence name, CharSequence value) {
notNull(name, value);
javaIdentifierOrNull(name, value);
}
public static void javaIdentifierOrNull(CharSequence name, CharSequence value) {
if ((value != null) && (!Utilities.isJavaIdentifier(value.toString()))) {
throw new IllegalArgumentException("The " + name + " parameter ('" + value + "') is not a valid Java identifier");
}
}
}
@@ -1,943 +0,0 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.lang.model.SourceVersion;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
public final class Utilities {
private static final Logger LOG = Logger.getLogger(Utilities.class.getName());
public static final int OS_WINNT = 1;
public static final int OS_WIN95 = 2;
public static final int OS_WIN98 = 4;
public static final int OS_SOLARIS = 8;
public static final int OS_LINUX = 16;
public static final int OS_HP = 32;
public static final int OS_AIX = 64;
public static final int OS_IRIX = 128;
public static final int OS_SUNOS = 256;
public static final int OS_TRU64 = 512;
public static final int OS_OS2 = 2048;
public static final int OS_MAC = 4096;
public static final int OS_WIN2000 = 8192;
public static final int OS_VMS = 16384;
public static final int OS_WIN_OTHER = 32768;
public static final int OS_OTHER = 65536;
public static final int OS_FREEBSD = 131072;
public static final int OS_WINVISTA = 262144;
public static final int OS_UNIX_OTHER = 524288;
public static final int OS_OPENBSD = 1048576;
public static final int TYPICAL_WINDOWS_TASKBAR_HEIGHT = 27;
private static int operatingSystem = -1;
private static Timer clearIntrospector;
private static ActionListener doClear;
private static Reference<NamesAndValues> namesAndValues;
private static Method fileToPath;
private static Method pathToUri;
private static Method pathsGet;
private static Method pathToFile;
public static int getOperatingSystem() {
if (operatingSystem == -1) {
String osName = System.getProperty("os.name");
if ("Windows NT".equals(osName)) {
operatingSystem = 1;
} else if ("Windows 95".equals(osName)) {
operatingSystem = 2;
} else if ("Windows 98".equals(osName)) {
operatingSystem = 4;
} else if ("Windows 2000".equals(osName)) {
operatingSystem = 8192;
} else if ("Windows Vista".equals(osName)) {
operatingSystem = 262144;
} else if (osName.startsWith("Windows ")) {
operatingSystem = 32768;
} else if ("Solaris".equals(osName)) {
operatingSystem = 8;
} else if (osName.startsWith("SunOS")) {
operatingSystem = 8;
} else if (osName.endsWith("Linux")) {
operatingSystem = 16;
} else if ("HP-UX".equals(osName)) {
operatingSystem = 32;
} else if ("AIX".equals(osName)) {
operatingSystem = 64;
} else if ("Irix".equals(osName)) {
operatingSystem = 128;
} else if ("SunOS".equals(osName)) {
operatingSystem = 256;
} else if ("Digital UNIX".equals(osName)) {
operatingSystem = 512;
} else if ("OS/2".equals(osName)) {
operatingSystem = 2048;
} else if ("OpenVMS".equals(osName)) {
operatingSystem = 16384;
} else if (osName.equals("Mac OS X")) {
operatingSystem = 4096;
} else if (osName.startsWith("Darwin")) {
operatingSystem = 4096;
} else if (osName.toLowerCase(Locale.US).startsWith("freebsd")) {
operatingSystem = 131072;
} else if ("OpenBSD".equals(osName)) {
operatingSystem = 1048576;
} else if (File.pathSeparatorChar == ':') {
operatingSystem = 524288;
} else {
operatingSystem = 65536;
}
}
return operatingSystem;
}
public static boolean isWindows() {
return (getOperatingSystem() & 0x4A007) != 0;
}
public static boolean isMac() {
return (getOperatingSystem() & 0x1000) != 0;
}
public static boolean isUnix() {
return (getOperatingSystem() & 0x1A13F8) != 0;
}
static void resetOperatingSystem() {
operatingSystem = -1;
}
public static boolean isJavaIdentifier(String id) {
if (id == null) {
return false;
}
return (SourceVersion.isIdentifier(id)) && (!SourceVersion.isKeyword(id));
}
public static BeanInfo getBeanInfo(Class<?> clazz) throws IntrospectionException {
BeanInfo bi;
try {
bi = Introspector.getBeanInfo(clazz);
} catch (IntrospectionException ie) {
throw ie;
} catch (Error e) {
throw e;
}
if (Component.class.isAssignableFrom(clazz)) {
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
if (pds[i].getName().equals("cursor")) {
try {
Method getter = Component.class.getDeclaredMethod("getCursor", new Class[0]);
Method setter = Component.class.getDeclaredMethod("setCursor", new Class[] {Cursor.class});
pds[i] = new PropertyDescriptor("cursor", getter, setter);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
}
if (bi != null) {
if (clearIntrospector == null) {
doClear = new ActionListener() {
public void actionPerformed(ActionEvent ev) {}
};
clearIntrospector = new Timer(15000, doClear);
clearIntrospector.setRepeats(false);
}
clearIntrospector.restart();
}
return bi;
}
public static BeanInfo getBeanInfo(Class<?> clazz, Class<?> stopClass) throws IntrospectionException {
return Introspector.getBeanInfo(clazz, stopClass);
}
public static String pureClassName(String fullName) {
int index = fullName.indexOf('$');
if ((index >= 0) && (index < fullName.length())) {
return fullName.substring(index + 1, fullName.length());
}
return fullName;
}
@Deprecated
public static boolean isLargeFrameIcons() {
return (getOperatingSystem() == 8) || (getOperatingSystem() == 32);
}
@Deprecated
public static int arrayHashCode(Object[] arr) {
int c = 0;
int len = arr.length;
for (int i = 0; i < len; i++) {
Object o = arr[i];
int v = o == null ? 1 : o.hashCode();
c += (v ^ i);
}
return c;
}
public static boolean compareObjects(Object o1, Object o2) {
return compareObjectsImpl(o1, o2, 1);
}
public static boolean compareObjectsImpl(Object o1, Object o2, int checkArraysDepth) {
if (o1 == null) {
return o2 == null;
}
if (o2 == null) {
return false;
}
if (checkArraysDepth > 0) {
if (((o1 instanceof Object[])) && ((o2 instanceof Object[]))) {
Object[] o1a = (Object[]) o1;
Object[] o2a = (Object[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (!compareObjectsImpl(o1a[i], o2a[i], checkArraysDepth - 1)) {
return false;
}
}
return true;
}
if (((o1 instanceof byte[])) && ((o2 instanceof byte[]))) {
byte[] o1a = (byte[]) o1;
byte[] o2a = (byte[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof short[])) && ((o2 instanceof short[]))) {
short[] o1a = (short[]) o1;
short[] o2a = (short[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof int[])) && ((o2 instanceof int[]))) {
int[] o1a = (int[]) o1;
int[] o2a = (int[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof long[])) && ((o2 instanceof long[]))) {
long[] o1a = (long[]) o1;
long[] o2a = (long[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof float[])) && ((o2 instanceof float[]))) {
float[] o1a = (float[]) o1;
float[] o2a = (float[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof double[])) && ((o2 instanceof double[]))) {
double[] o1a = (double[]) o1;
double[] o2a = (double[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof char[])) && ((o2 instanceof char[]))) {
char[] o1a = (char[]) o1;
char[] o2a = (char[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
if (((o1 instanceof boolean[])) && ((o2 instanceof boolean[]))) {
boolean[] o1a = (boolean[]) o1;
boolean[] o2a = (boolean[]) o2;
int l1 = o1a.length;
int l2 = o2a.length;
if (l1 != l2) {
return false;
}
for (int i = 0; i < l1; i++) {
if (o1a[i] != o2a[i]) {
return false;
}
}
return true;
}
}
return o1.equals(o2);
}
public static String getClassName(Class<?> clazz) {
if (clazz.isArray()) {
return getClassName(clazz.getComponentType()) + "[]";
}
return clazz.getName();
}
public static String getShortClassName(Class<?> clazz) {
if (clazz.isArray()) {
return getShortClassName(clazz.getComponentType()) + "[]";
}
String name = clazz.getName().replace('$', '.');
return name.substring(name.lastIndexOf('.') + 1, name.length());
}
public static Object[] toObjectArray(Object array) {
if ((array instanceof Object[])) {
return (Object[]) array;
}
if ((array instanceof int[])) {
int k = ((int[]) array).length;
Integer[] r = new Integer[k];
for (int i = 0; i < k; i++) {
r[i] = Integer.valueOf(((int[]) (int[]) array)[i]);
}
return r;
}
if ((array instanceof boolean[])) {
int k = ((boolean[]) array).length;
Boolean[] r = new Boolean[k];
for (int i = 0; i < k; i++) {
r[i] = Boolean.valueOf(((boolean[]) (boolean[]) array)[i]);
}
return r;
}
if ((array instanceof byte[])) {
int k = ((byte[]) array).length;
Byte[] r = new Byte[k];
for (int i = 0; i < k; i++) {
r[i] = Byte.valueOf(((byte[]) (byte[]) array)[i]);
}
return r;
}
if ((array instanceof char[])) {
int k = ((char[]) array).length;
Character[] r = new Character[k];
for (int i = 0; i < k; i++) {
r[i] = Character.valueOf(((char[]) (char[]) array)[i]);
}
return r;
}
if ((array instanceof double[])) {
int k = ((double[]) array).length;
Double[] r = new Double[k];
for (int i = 0; i < k; i++) {
r[i] = Double.valueOf(((double[]) (double[]) array)[i]);
}
return r;
}
if ((array instanceof float[])) {
int k = ((float[]) array).length;
Float[] r = new Float[k];
for (int i = 0; i < k; i++) {
r[i] = Float.valueOf(((float[]) (float[]) array)[i]);
}
return r;
}
if ((array instanceof long[])) {
int k = ((long[]) array).length;
Long[] r = new Long[k];
for (int i = 0; i < k; i++) {
r[i] = Long.valueOf(((long[]) (long[]) array)[i]);
}
return r;
}
if ((array instanceof short[])) {
int k = ((short[]) array).length;
Short[] r = new Short[k];
for (int i = 0; i < k; i++) {
r[i] = Short.valueOf(((short[]) (short[]) array)[i]);
}
return r;
}
throw new IllegalArgumentException();
}
public static Class<?> getObjectType(Class<?> c) {
if (!c.isPrimitive()) {
return c;
}
if (c == Integer.TYPE) {
return Integer.class;
}
if (c == Boolean.TYPE) {
return Boolean.class;
}
if (c == Byte.TYPE) {
return Byte.class;
}
if (c == Character.TYPE) {
return Character.class;
}
if (c == Double.TYPE) {
return Double.class;
}
if (c == Float.TYPE) {
return Float.class;
}
if (c == Long.TYPE) {
return Long.class;
}
if (c == Short.TYPE) {
return Short.class;
}
throw new IllegalArgumentException();
}
public static Class<?> getPrimitiveType(Class<?> c) {
if (!c.isPrimitive()) {
return c;
}
if (c == Integer.class) {
return Integer.TYPE;
}
if (c == Boolean.class) {
return Boolean.TYPE;
}
if (c == Byte.class) {
return Byte.TYPE;
}
if (c == Character.class) {
return Character.TYPE;
}
if (c == Double.class) {
return Double.TYPE;
}
if (c == Float.class) {
return Float.TYPE;
}
if (c == Long.class) {
return Long.TYPE;
}
if (c == Short.class) {
return Short.TYPE;
}
throw new IllegalArgumentException();
}
public static Component getFocusTraversableComponent(Component c) {
if (c.isFocusable()) {
return c;
}
if (!(c instanceof Container)) {
return null;
}
int k = ((Container) c).getComponentCount();
for (int i = 0; i < k; i++) {
Component v = ((Container) c).getComponent(i);
if (v != null) {
return v;
}
}
return null;
}
public static String[] parseParameters(String s) {
int NULL = 0;
int INPARAM = 1;
int INPARAMPENDING = 2;
int STICK = 4;
int STICKPENDING = 8;
Vector<String> params = new Vector<String>(5, 5);
int state = NULL;
StringBuilder buff = new StringBuilder(20);
int slength = s.length();
for (int i = 0; i < slength; i++) {
char c = s.charAt(i);
if (Character.isWhitespace(c)) {
if (state == NULL) {
if (buff.length() > 0) {
params.addElement(buff.toString());
buff.setLength(0);
}
} else if (state == STICK) {
params.addElement(buff.toString());
buff.setLength(0);
state = NULL;
} else if (state == STICKPENDING) {
buff.append('\\');
params.addElement(buff.toString());
buff.setLength(0);
state = NULL;
} else if (state == INPARAMPENDING) {
state = INPARAM;
buff.append('\\');
buff.append(c);
} else {
buff.append(c);
}
} else if (c == '\\') {
if (state == NULL) {
i++;
if (i < slength) {
char cc = s.charAt(i);
if ((cc == '"') || (cc == '\\')) {
buff.append(cc);
} else if (Character.isWhitespace(cc)) {
buff.append(c);
i--;
} else {
buff.append(c);
buff.append(cc);
}
} else {
buff.append('\\');
break;
}
} else if (state == INPARAM) {
state = INPARAMPENDING;
} else if (state == INPARAMPENDING) {
buff.append('\\');
state = INPARAM;
} else if (state == STICK) {
state = STICKPENDING;
} else if (state == STICKPENDING) {
buff.append('\\');
state = STICK;
}
} else if (c == '"') {
if (state == NULL) {
state = INPARAM;
} else if (state == INPARAM) {
state = STICK;
} else if (state == STICK) {
state = INPARAM;
} else if (state == STICKPENDING) {
buff.append('"');
state = STICK;
} else {
buff.append('"');
state = INPARAM;
}
} else {
if (state == INPARAMPENDING) {
buff.append('\\');
state = INPARAM;
} else if (state == STICKPENDING) {
buff.append('\\');
state = STICK;
}
buff.append(c);
}
}
if (state == INPARAM) {
params.addElement(buff.toString());
} else if ((state & (INPARAMPENDING | STICKPENDING)) != 0) {
buff.append('\\');
params.addElement(buff.toString());
} else if (buff.length() != 0) {
params.addElement(buff.toString());
}
String[] ret = new String[params.size()];
params.copyInto(ret);
return ret;
}
public static String escapeParameters(String[] params) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < params.length; i++) {
escapeString(params[i], sb);
sb.append(' ');
}
int len = sb.length();
if (len > 0) {
sb.setLength(len - 1);
}
return sb.toString().trim();
}
private static void escapeString(String s, StringBuffer sb) {
if (s.length() == 0) {
sb.append("\"\"");
return;
}
boolean hasSpace = false;
int sz = sb.length();
int slen = s.length();
for (int i = 0; i < slen; i++) {
char c = s.charAt(i);
if (Character.isWhitespace(c)) {
hasSpace = true;
sb.append(c);
} else if (c == '\\') {
sb.append('\\').append('\\');
} else if (c == '"') {
sb.append('\\').append('"');
} else {
sb.append(c);
}
}
if (hasSpace) {
sb.insert(sz, '"');
sb.append('"');
}
}
private static final class NamesAndValues {
final Map<Integer, String> keyToString;
@SuppressWarnings("unused")
final Map<String, Integer> stringToKey;
NamesAndValues(Map<Integer, String> keyToString, Map<String, Integer> stringToKey) {
this.keyToString = keyToString;
this.stringToKey = stringToKey;
}
}
private static synchronized NamesAndValues initNameAndValues() {
if (namesAndValues != null) {
NamesAndValues nav = (NamesAndValues) namesAndValues.get();
if (nav != null) {
return nav;
}
}
Field[] fields = KeyEvent.class.getDeclaredFields();
Map<String, Integer> names = new HashMap<String, Integer>(fields.length * 4 / 3 + 5, 0.75F);
Map<Integer, String> values = new HashMap<Integer, String>(fields.length * 4 / 3 + 5, 0.75F);
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers())) {
String name = f.getName();
if (name.startsWith("VK_")) {
name = name.substring(3);
try {
int numb = f.getInt(null);
names.put(name, Integer.valueOf(numb));
values.put(Integer.valueOf(numb), name);
} catch (IllegalArgumentException ex) {
} catch (IllegalAccessException ex) {
}
}
}
}
if (names.get("CONTEXT_MENU") == null) {
names.put("CONTEXT_MENU", Integer.valueOf(524));
values.put(Integer.valueOf(524), "CONTEXT_MENU");
names.put("WINDOWS", Integer.valueOf(525));
values.put(Integer.valueOf(525), "WINDOWS");
}
names.put("MOUSE_WHEEL_UP", Integer.valueOf(656));
names.put("MOUSE_WHEEL_DOWN", Integer.valueOf(657));
values.put(Integer.valueOf(656), "MOUSE_WHEEL_UP");
values.put(Integer.valueOf(657), "MOUSE_WHEEL_DOWN");
NamesAndValues nav = new NamesAndValues(values, names);
namesAndValues = new SoftReference<NamesAndValues>(nav);
return nav;
}
public static String keyToString(KeyStroke stroke) {
StringBuilder sb = new StringBuilder();
if (addModifiers(sb, stroke.getModifiers())) {
sb.append('-');
}
appendRest(sb, stroke);
return sb.toString();
}
private static void appendRest(StringBuilder sb, KeyStroke stroke) {
String c = (String) initNameAndValues().keyToString.get(Integer.valueOf(stroke.getKeyCode()));
if (c == null) {
sb.append(stroke.getKeyChar());
} else {
sb.append(c);
}
}
public static String keyToString(KeyStroke stroke, boolean portable) {
if (portable) {
StringBuilder sb = new StringBuilder();
if (addModifiersPortable(sb, stroke.getModifiers())) {
sb.append('-');
}
appendRest(sb, stroke);
return sb.toString();
}
return keyToString(stroke);
}
private static boolean addModifiers(StringBuilder buf, int modif) {
boolean b = false;
if ((modif & 0x2) != 0) {
buf.append("C");
b = true;
}
if ((modif & 0x8) != 0) {
buf.append("A");
b = true;
}
if ((modif & 0x1) != 0) {
buf.append("S");
b = true;
}
if ((modif & 0x4) != 0) {
buf.append("M");
b = true;
}
if ((modif & 0x8000) != 0) {
buf.append("D");
b = true;
}
if ((modif & 0x10000) != 0) {
buf.append("O");
b = true;
}
return b;
}
private static boolean addModifiersPortable(StringBuilder buf, int modifiers) {
boolean b = false;
if ((modifiers & 0x1) != 0) {
buf.append('S');
b = true;
}
if (((isMac()) && ((modifiers & 0x4) != 0)) || ((!isMac()) && ((modifiers & 0x2) != 0))) {
buf.append('D');
b = true;
}
if (((isMac()) && ((modifiers & 0x2) != 0)) || ((!isMac()) && ((modifiers & 0x8) != 0))) {
buf.append('O');
b = true;
}
if ((isMac()) && ((modifiers & 0x8) != 0)) {
buf.append('A');
b = true;
}
return b;
}
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner != null) {
Window w = SwingUtilities.getWindowAncestor(focusOwner);
if (w != null) {
return w.getGraphicsConfiguration();
}
}
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
public static Rectangle getUsableScreenBounds() {
return getUsableScreenBounds(getCurrentGraphicsConfiguration());
}
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) {
if (gconf == null) {
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
Rectangle bounds = new Rectangle(gconf.getBounds());
String str = System.getProperty("netbeans.screen.insets");
if (str != null) {
StringTokenizer st = new StringTokenizer(str, ", ");
if (st.countTokens() == 4) {
try {
bounds.y = Integer.parseInt(st.nextToken());
bounds.x = Integer.parseInt(st.nextToken());
bounds.height -= bounds.y + Integer.parseInt(st.nextToken());
bounds.width -= bounds.x + Integer.parseInt(st.nextToken());
} catch (NumberFormatException ex) {
LOG.log(Level.WARNING, null, ex);
}
}
return bounds;
}
str = System.getProperty("netbeans.taskbar.height");
if (str != null) {
bounds.height -= Integer.getInteger(str, 0).intValue();
return bounds;
}
try {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Insets insets = toolkit.getScreenInsets(gconf);
bounds.y += insets.top;
bounds.x += insets.left;
bounds.height -= insets.top + insets.bottom;
bounds.width -= insets.left + insets.right;
} catch (Exception ex) {
LOG.log(Level.WARNING, null, ex);
}
return bounds;
}
public static Rectangle findCenterBounds(Dimension componentSize) {
return findCenterBounds(getCurrentGraphicsConfiguration(), componentSize);
}
private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension componentSize) {
if (gconf == null) {
gconf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
}
Rectangle bounds = gconf.getBounds();
return new Rectangle(bounds.x + (bounds.width - componentSize.width) / 2, bounds.y
+ (bounds.height - componentSize.height) / 2, componentSize.width, componentSize.height);
}
static {
try {
fileToPath = File.class.getMethod("toPath", new Class[0]);
} catch (NoSuchMethodException x) {
}
if (fileToPath != null) {
try {
Class<?> path = Class.forName("java.nio.file.Path");
pathToUri = path.getMethod("toUri", new Class[0]);
pathsGet = Class.forName("java.nio.file.Paths").getMethod("get", new Class[] {URI.class});
pathToFile = path.getMethod("toFile", new Class[0]);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
}
}
public static URI toURI(File f) {
if (fileToPath != null) {
try {
URI u = (URI) pathToUri.invoke(fileToPath.invoke(f, new Object[0]), new Object[0]);
if (u.toString().startsWith("file:///")) {
}
return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(),
u.getFragment());
} catch (Exception x) {
LOG.log(Level.FINE, "could not convert " + f + " to URI", x);
}
}
String path = f.getAbsolutePath();
if (path.startsWith("\\\\")) {
if ((!path.endsWith("\\")) && (f.isDirectory())) {
path = path + "\\";
}
try {
return new URI("file", null, path.replace('\\', '/'), null);
} catch (URISyntaxException x) {
LOG.log(Level.FINE, "could not convert " + f + " to URI", x);
}
}
return f.toURI();
}
public static File toFile(URI u) throws IllegalArgumentException {
if (pathsGet != null) {
try {
return (File) pathToFile.invoke(pathsGet.invoke(null, new Object[] {u}), new Object[0]);
} catch (Exception x) {
LOG.log(Level.FINE, "could not convert " + u + " to File", x);
}
}
String host = u.getHost();
if ((host != null) && (!host.isEmpty()) && ("file".equals(u.getScheme()))) {
return new File("\\\\" + host + u.getPath().replace('/', '\\'));
}
return new File(u);
}
static abstract interface RE {
public abstract void init(String[] paramArrayOfString1, String[] paramArrayOfString2);
public abstract String convert(String paramString);
public abstract String[] readPair(String paramString);
}
}