mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
code cleanup
This commit is contained in:
@@ -22,7 +22,6 @@ import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.presenter.Presenter;
|
||||
|
||||
@@ -9,13 +9,13 @@ import java.awt.event.KeyListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
import org.diylc.core.measures.Unit;
|
||||
@@ -26,6 +26,8 @@ public class MeasureEditor extends Container {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final static Logger LOG = Logger.getLogger(MeasureEditor.class);
|
||||
|
||||
private Color oldBg;
|
||||
private DoubleTextField valueField;
|
||||
private JComboBox unitBox;
|
||||
@@ -33,7 +35,7 @@ public class MeasureEditor extends Container {
|
||||
@SuppressWarnings("unchecked")
|
||||
public MeasureEditor(final PropertyWrapper property) {
|
||||
setLayout(new BorderLayout());
|
||||
final AbstractMeasure measure = ((AbstractMeasure) property.getValue());
|
||||
final AbstractMeasure<?> measure = ((AbstractMeasure<?>) property.getValue());
|
||||
valueField = new DoubleTextField(measure == null ? null : measure.getValue());
|
||||
oldBg = valueField.getBackground();
|
||||
valueField.addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY, new PropertyChangeListener() {
|
||||
@@ -41,25 +43,15 @@ public class MeasureEditor extends Container {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
try {
|
||||
Constructor ctor = property.getType().getConstructors()[0];
|
||||
Constructor<?> ctor = property.getType().getConstructors()[0];
|
||||
AbstractMeasure<?> newMeasure =
|
||||
(AbstractMeasure<?>) ctor.newInstance((Double) evt.getNewValue(), unitBox.getSelectedItem());
|
||||
property.setValue(newMeasure);
|
||||
property.setChanged(true);
|
||||
valueField.setBackground(oldBg);
|
||||
unitBox.setBackground(oldBg);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while updating property value", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -74,7 +66,7 @@ public class MeasureEditor extends Container {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
try {
|
||||
Constructor ctor = property.getType().getConstructors()[0];
|
||||
Constructor<?> ctor = property.getType().getConstructors()[0];
|
||||
AbstractMeasure<?> newMeasure =
|
||||
(AbstractMeasure<?>) ctor.newInstance(valueField.getValue(),
|
||||
(Enum<? extends Unit>) unitBox.getSelectedItem());
|
||||
@@ -82,18 +74,8 @@ public class MeasureEditor extends Container {
|
||||
property.setChanged(true);
|
||||
valueField.setBackground(oldBg);
|
||||
unitBox.setBackground(oldBg);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while updating property units", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -103,21 +85,8 @@ public class MeasureEditor extends Container {
|
||||
valueField.setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
unitBox.setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while creating the editor", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -447,13 +447,9 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void processMessage(final EventType eventType, Object... params) {
|
||||
// SwingUtilities.invokeLater(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// LOG.debug("event: " + eventType);
|
||||
switch (eventType) {
|
||||
case PROJECT_LOADED:
|
||||
refreshSize();
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.diylc.common.ITask;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.plugins.cloud.model.CommentEntity;
|
||||
import org.diylc.plugins.cloud.model.ProjectEntity;
|
||||
import org.diylc.plugins.cloud.presenter.CloudException;
|
||||
import org.diylc.plugins.cloud.presenter.CloudPresenter;
|
||||
import org.diylc.swing.plugins.cloud.view.browser.CloudBrowserFrame;
|
||||
|
||||
|
||||
@@ -240,6 +240,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
||||
return EnumSet.of(EventType.SELECTION_CHANGED, EventType.PROJECT_MODIFIED, EventType.PROJECT_LOADED);
|
||||
}
|
||||
|
||||
@SuppressWarnings("incomplete-switch")
|
||||
@Override
|
||||
public void processMessage(EventType eventType, Object... params) {
|
||||
switch (eventType) {
|
||||
|
||||
@@ -28,14 +28,13 @@ import org.diylc.images.IconLoader;
|
||||
import org.diylc.swing.plugins.toolbox.openide.DropDownButtonFactory;
|
||||
|
||||
/**
|
||||
* {@link JButton} that displays component type icon and instantiates the component when clicked.
|
||||
* Factory that creates {@link JButton}s which display component type icons and instantiates the
|
||||
* component when clicked.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
class ComponentButtonFactory {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static int MARGIN = 3;
|
||||
|
||||
public static JButton create(final IPlugInPort plugInPort, final ComponentType componentType, final JPopupMenu menu) {
|
||||
@@ -43,14 +42,9 @@ class ComponentButtonFactory {
|
||||
|
||||
button.setBorder(BorderFactory.createEmptyBorder(MARGIN + 1, MARGIN + 1, MARGIN, MARGIN));
|
||||
|
||||
// mainButton.setBorder(BorderFactory.createEmptyBorder());
|
||||
// dropDownButton.setBorder(BorderFactory.createEmptyBorder());
|
||||
// setBorder(BorderFactory.createLineBorder(Color.gray));
|
||||
|
||||
button.setToolTipText("<html><b>" + componentType.getName() + "</b><br>" + componentType.getDescription()
|
||||
+ "<br>Author: " + componentType.getAuthor() + "<br><br>Right click to select all components of this type"
|
||||
+ "</html>");
|
||||
// initializeDnD();
|
||||
button.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@@ -81,20 +75,7 @@ class ComponentButtonFactory {
|
||||
}
|
||||
}
|
||||
});
|
||||
// addActionListener(new ActionListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// // plugInPort.setCursorIcon(componentType.getIcon());
|
||||
// plugInPort.setNewComponentTypeSlot(componentType);
|
||||
// // try {
|
||||
// // plugInPort.instantiateComponent(componentType
|
||||
// // .getComponentInstanceClass(), null);
|
||||
// // } catch (Exception e1) {
|
||||
// // e1.printStackTrace();
|
||||
// // }
|
||||
// }
|
||||
// });
|
||||
|
||||
button.addKeyListener(new KeyAdapter() {
|
||||
|
||||
@Override
|
||||
@@ -102,27 +83,9 @@ class ComponentButtonFactory {
|
||||
plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(), e.isShiftDown(), e.isAltDown());
|
||||
}
|
||||
});
|
||||
// addKeyListener(new KeyAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void keyPressed(KeyEvent e) {
|
||||
// if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
// plugInPort.setNewComponentSlot(null);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
return button;
|
||||
}
|
||||
|
||||
// private void initializeDnD() {
|
||||
// // Initialize drag source recognizer.
|
||||
// DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
|
||||
// this,
|
||||
// DnDConstants.ACTION_MOVE,
|
||||
// new ToolboxGestureListener(plugInPort, componentType
|
||||
// .getInstanceClass().getName()));
|
||||
// }
|
||||
|
||||
public static JMenuItem createTemplateItem(final IPlugInPort plugInPort, final Template template,
|
||||
final ComponentType componentType) {
|
||||
final JMenuItem item = new JMenuItem(template.getName()) {
|
||||
|
||||
@@ -145,6 +145,7 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Component createRecentComponentsPanel() {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.setOpaque(false);
|
||||
@@ -169,6 +170,7 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
return panel;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void refreshRecentComponentsToolbar(Container toolbar, List<String> recentComponentClassList) {
|
||||
toolbar.removeAll();
|
||||
for (String componentClassName : recentComponentClassList) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.diylc.common.IPlugInPort;
|
||||
*/
|
||||
class ToolboxSourceListener implements DragSourceListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private IPlugInPort presenter;
|
||||
|
||||
public ToolboxSourceListener(IPlugInPort presenter) {
|
||||
|
||||
@@ -21,6 +21,7 @@ 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);
|
||||
|
||||
@@ -13,7 +13,6 @@ class IconWithArrow implements Icon {
|
||||
private Icon orig;
|
||||
private Icon arrow = IconLoader.Arrow.getIcon();
|
||||
private boolean paintRollOver;
|
||||
private static final int GAP = 6;
|
||||
|
||||
public IconWithArrow(Icon orig, boolean paintRollOver) {
|
||||
Parameters.notNull("original icon", orig);
|
||||
|
||||
@@ -6,9 +6,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Image;
|
||||
import java.awt.MediaTracker;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
@@ -16,13 +14,9 @@ import java.awt.image.ImageObserver;
|
||||
import java.awt.image.RGBImageFilter;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
@@ -30,15 +24,6 @@ import javax.swing.JLabel;
|
||||
public final class ImageUtilities {
|
||||
static final String TOOLTIP_SEPAR = "<br>";
|
||||
|
||||
private static final Set<String> extraInitialSlashes = new HashSet<String>();
|
||||
private static volatile Object currentLoader;
|
||||
private static boolean noLoaderWarned;
|
||||
private static final Component component;
|
||||
private static final MediaTracker tracker;
|
||||
private static int mediaTrackerID;
|
||||
private static ImageReader PNG_READER;
|
||||
private static final Logger ERR;
|
||||
|
||||
private ImageUtilities() {}
|
||||
|
||||
public static final Icon image2Icon(Image image) {
|
||||
@@ -89,54 +74,6 @@ public final class ImageUtilities {
|
||||
return rep;
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING - Removed try catching itself - possible behaviour change.
|
||||
*/
|
||||
private static void ensureLoaded(Image image) {
|
||||
if ((Toolkit.getDefaultToolkit().checkImage(image, -1, -1, null) & 48) != 0) {
|
||||
return;
|
||||
}
|
||||
MediaTracker mediaTracker = tracker;
|
||||
synchronized (mediaTracker) {
|
||||
int id = ++mediaTrackerID;
|
||||
tracker.addImage(image, id);
|
||||
try {
|
||||
tracker.waitForID(id, 0);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("INTERRUPTED while loading Image");
|
||||
}
|
||||
assert (tracker.statusID(id, false) == 8);
|
||||
tracker.removeImage(image, id);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Image doMergeImages(Image image1, Image image2, int x, int y) {
|
||||
ImageUtilities.ensureLoaded(image1);
|
||||
ImageUtilities.ensureLoaded(image2);
|
||||
int w = Math.max(image1.getWidth(null), x + image2.getWidth(null));
|
||||
int h = Math.max(image1.getHeight(null), y + image2.getHeight(null));
|
||||
boolean bitmask =
|
||||
image1 instanceof Transparency && ((Transparency) ((Object) image1)).getTransparency() != 3
|
||||
&& image2 instanceof Transparency && ((Transparency) ((Object) image2)).getTransparency() != 3;
|
||||
StringBuilder str = new StringBuilder(image1 instanceof ToolTipImage ? ((ToolTipImage) image1).toolTipText : "");
|
||||
if (image2 instanceof ToolTipImage) {
|
||||
String toolTip = ((ToolTipImage) image2).toolTipText;
|
||||
if (str.length() > 0 && toolTip.length() > 0) {
|
||||
str.append("<br>");
|
||||
}
|
||||
str.append(toolTip);
|
||||
}
|
||||
ColorModel model = ImageUtilities.colorModel(bitmask ? 2 : 3);
|
||||
ToolTipImage buffImage =
|
||||
new ToolTipImage(str.toString(), model, model.createCompatibleWritableRaster(w, h),
|
||||
model.isAlphaPremultiplied(), null, null);
|
||||
Graphics2D g = buffImage.createGraphics();
|
||||
g.drawImage(image1, 0, 0, null);
|
||||
g.drawImage(image2, x, y, null);
|
||||
g.dispose();
|
||||
return buffImage;
|
||||
}
|
||||
|
||||
static final BufferedImage createBufferedImage(int width, int height) {
|
||||
if (Utilities.isMac()) {
|
||||
return new BufferedImage(width, height, 3);
|
||||
@@ -161,44 +98,7 @@ public final class ImageUtilities {
|
||||
}
|
||||
|
||||
static {
|
||||
noLoaderWarned = false;
|
||||
component = new Component() {};
|
||||
tracker = new MediaTracker(component);
|
||||
ERR = Logger.getLogger(ImageUtilities.class.getName());
|
||||
ImageIO.setUseCache(false);
|
||||
PNG_READER = ImageIO.getImageReadersByMIMEType("image/png").next();
|
||||
}
|
||||
|
||||
private static class CompositeImageKey {
|
||||
Image baseImage;
|
||||
Image overlayImage;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
CompositeImageKey(Image base, Image overlay, int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.baseImage = base;
|
||||
this.overlayImage = overlay;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof CompositeImageKey)) {
|
||||
return false;
|
||||
}
|
||||
CompositeImageKey k = (CompositeImageKey) other;
|
||||
return this.x == k.x && this.y == k.y && this.baseImage == k.baseImage && this.overlayImage == k.overlayImage;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hash = (this.x << 3 ^ this.y) << 4;
|
||||
hash = hash ^ this.baseImage.hashCode() ^ this.overlayImage.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Composite key for " + this.baseImage + " + " + this.overlayImage + " at [" + this.x + ", " + this.y + "]";
|
||||
}
|
||||
}
|
||||
|
||||
private static class DisabledButtonFilter extends RGBImageFilter {
|
||||
@@ -212,8 +112,8 @@ public final class ImageUtilities {
|
||||
+ ((rgb & 255) >> 2);
|
||||
}
|
||||
|
||||
public void setProperties(Hashtable props) {
|
||||
props = (Hashtable) props.clone();
|
||||
public void setProperties(Hashtable<?, ?> props) {
|
||||
props = (Hashtable<?, ?>) props.clone();
|
||||
this.consumer.setProperties(props);
|
||||
}
|
||||
}
|
||||
@@ -261,21 +161,6 @@ public final class ImageUtilities {
|
||||
ImageIcon imageIcon;
|
||||
final URL url;
|
||||
|
||||
public static ToolTipImage createNew(String toolTipText, Image image, URL url) {
|
||||
ImageUtilities.ensureLoaded(image);
|
||||
boolean bitmask = image instanceof Transparency && ((Transparency) ((Object) image)).getTransparency() != 3;
|
||||
ColorModel model = ImageUtilities.colorModel(bitmask ? 2 : 3);
|
||||
int w = image.getWidth(null);
|
||||
int h = image.getHeight(null);
|
||||
ToolTipImage newImage =
|
||||
new ToolTipImage(toolTipText, model, model.createCompatibleWritableRaster(w, h),
|
||||
model.isAlphaPremultiplied(), null, url);
|
||||
Graphics2D g = newImage.createGraphics();
|
||||
g.drawImage(image, 0, 0, null);
|
||||
g.dispose();
|
||||
return newImage;
|
||||
}
|
||||
|
||||
public ToolTipImage(String toolTipText, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied,
|
||||
Hashtable<?, ?> properties, URL url) {
|
||||
super(cm, raster, isRasterPremultiplied, properties);
|
||||
@@ -322,32 +207,4 @@ public final class ImageUtilities {
|
||||
return super.getProperty(name, observer);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ToolTipImageKey {
|
||||
Image image;
|
||||
String str;
|
||||
|
||||
ToolTipImageKey(Image image, String str) {
|
||||
this.image = image;
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof ToolTipImageKey)) {
|
||||
return false;
|
||||
}
|
||||
ToolTipImageKey k = (ToolTipImageKey) other;
|
||||
return this.str.equals(k.str) && this.image == k.image;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int hash = this.image.hashCode() ^ this.str.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ImageStringKey for " + this.image + " + " + this.str;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,8 @@ import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
@@ -20,33 +18,23 @@ import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
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.Icon;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
@@ -63,8 +51,6 @@ public final class Utilities {
|
||||
public static final int OS_IRIX = 128;
|
||||
public static final int OS_SUNOS = 256;
|
||||
public static final int OS_TRU64 = 512;
|
||||
@Deprecated
|
||||
public static final int OS_DEC = 1024;
|
||||
public static final int OS_OS2 = 2048;
|
||||
public static final int OS_MAC = 4096;
|
||||
public static final int OS_WIN2000 = 8192;
|
||||
@@ -75,20 +61,10 @@ public final class Utilities {
|
||||
public static final int OS_WINVISTA = 262144;
|
||||
public static final int OS_UNIX_OTHER = 524288;
|
||||
public static final int OS_OPENBSD = 1048576;
|
||||
@Deprecated
|
||||
public static final int OS_WINDOWS_MASK = 303111;
|
||||
@Deprecated
|
||||
public static final int OS_UNIX_MASK = 1709048;
|
||||
public static final int TYPICAL_WINDOWS_TASKBAR_HEIGHT = 27;
|
||||
private static final int TYPICAL_MACOSX_MENU_HEIGHT = 24;
|
||||
private static int operatingSystem = -1;
|
||||
private static Timer clearIntrospector;
|
||||
private static ActionListener doClear;
|
||||
private static final int CTRL_WILDCARD_MASK = 32768;
|
||||
private static final int ALT_WILDCARD_MASK = 65536;
|
||||
private static final Object TRANS_LOCK = new Object();
|
||||
private static Object transLoader;
|
||||
private static RE transExp;
|
||||
private static Reference<NamesAndValues> namesAndValues;
|
||||
private static Method fileToPath;
|
||||
private static Method pathToUri;
|
||||
@@ -210,28 +186,6 @@ public final class Utilities {
|
||||
return Introspector.getBeanInfo(clazz, stopClass);
|
||||
}
|
||||
|
||||
private static String trimString(String s) {
|
||||
int idx = 0;
|
||||
|
||||
int slen = s.length();
|
||||
if (slen == 0) {
|
||||
return s;
|
||||
}
|
||||
char c;
|
||||
do {
|
||||
c = s.charAt(idx++);
|
||||
} while (((c == '\n') || (c == '\r')) && (idx < slen));
|
||||
s = s.substring(--idx);
|
||||
idx = s.length() - 1;
|
||||
if (idx < 0) {
|
||||
return s;
|
||||
}
|
||||
do {
|
||||
c = s.charAt(idx--);
|
||||
} while (((c == '\n') || (c == '\r')) && (idx >= 0));
|
||||
return s.substring(0, idx + 2);
|
||||
}
|
||||
|
||||
public static String pureClassName(String fullName) {
|
||||
int index = fullName.indexOf('$');
|
||||
if ((index >= 0) && (index < fullName.length())) {
|
||||
@@ -580,7 +534,7 @@ public final class Utilities {
|
||||
int INPARAMPENDING = 2;
|
||||
int STICK = 4;
|
||||
int STICKPENDING = 8;
|
||||
Vector<String> params = new Vector(5, 5);
|
||||
Vector<String> params = new Vector<String>(5, 5);
|
||||
|
||||
int state = NULL;
|
||||
StringBuilder buff = new StringBuilder(20);
|
||||
@@ -721,6 +675,7 @@ public final class Utilities {
|
||||
|
||||
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) {
|
||||
@@ -738,8 +693,8 @@ public final class Utilities {
|
||||
}
|
||||
Field[] fields = KeyEvent.class.getDeclaredFields();
|
||||
|
||||
Map<String, Integer> names = new HashMap(fields.length * 4 / 3 + 5, 0.75F);
|
||||
Map<Integer, String> values = new HashMap(fields.length * 4 / 3 + 5, 0.75F);
|
||||
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();
|
||||
@@ -767,7 +722,7 @@ public final class Utilities {
|
||||
values.put(Integer.valueOf(657), "MOUSE_WHEEL_DOWN");
|
||||
|
||||
NamesAndValues nav = new NamesAndValues(values, names);
|
||||
namesAndValues = new SoftReference(nav);
|
||||
namesAndValues = new SoftReference<NamesAndValues>(nav);
|
||||
return nav;
|
||||
}
|
||||
|
||||
@@ -801,37 +756,6 @@ public final class Utilities {
|
||||
return keyToString(stroke);
|
||||
}
|
||||
|
||||
private static boolean usableKeyOnMac(int key, int mask) {
|
||||
if (key == 81) {
|
||||
return false;
|
||||
}
|
||||
boolean isMeta = ((mask & 0x4) != 0) || ((mask & 0x80) != 0);
|
||||
|
||||
boolean isAlt = ((mask & 0x8) != 0) || ((mask & 0x200) != 0);
|
||||
|
||||
boolean isOnlyMeta = (isMeta) && ((mask & 0xFEFB) == 0);
|
||||
if (isOnlyMeta) {
|
||||
return (key != 72) && (key != 32) && (key != 9);
|
||||
}
|
||||
if ((key == 68) && (isMeta) && (isAlt)) {
|
||||
return false;
|
||||
}
|
||||
if ((key == 32) && (isMeta) && ((mask & 0x2) != 0)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int getMenuShortcutKeyMask() {
|
||||
try {
|
||||
if (!GraphicsEnvironment.isHeadless()) {
|
||||
return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
private static boolean addModifiers(StringBuilder buf, int modif) {
|
||||
boolean b = false;
|
||||
if ((modif & 0x2) != 0) {
|
||||
@@ -882,54 +806,6 @@ public final class Utilities {
|
||||
return b;
|
||||
}
|
||||
|
||||
private static int readModifiers(String s) throws NoSuchElementException {
|
||||
int m = 0;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
switch (s.charAt(i)) {
|
||||
case 'C':
|
||||
m |= 0x2;
|
||||
|
||||
break;
|
||||
case 'A':
|
||||
m |= 0x8;
|
||||
|
||||
break;
|
||||
case 'M':
|
||||
m |= 0x4;
|
||||
|
||||
break;
|
||||
case 'S':
|
||||
m |= 0x1;
|
||||
|
||||
break;
|
||||
case 'D':
|
||||
m |= 0x8000;
|
||||
|
||||
break;
|
||||
case 'O':
|
||||
m |= 0x10000;
|
||||
|
||||
break;
|
||||
case 'B':
|
||||
case 'E':
|
||||
case 'F':
|
||||
case 'G':
|
||||
case 'H':
|
||||
case 'I':
|
||||
case 'J':
|
||||
case 'K':
|
||||
case 'L':
|
||||
case 'N':
|
||||
case 'P':
|
||||
case 'Q':
|
||||
case 'R':
|
||||
default:
|
||||
throw new NoSuchElementException(s);
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
|
||||
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
|
||||
if (focusOwner != null) {
|
||||
@@ -999,27 +875,6 @@ public final class Utilities {
|
||||
+ (bounds.height - componentSize.height) / 2, componentSize.width, componentSize.height);
|
||||
}
|
||||
|
||||
private static void loadTranslationFile(RE re, BufferedReader reader, Set<String[]> results) throws IOException {
|
||||
for (;;) {
|
||||
String line = reader.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
if ((line.length() != 0) && (!line.startsWith("#"))) {
|
||||
String[] pair = re.readPair(line);
|
||||
if (pair == null) {
|
||||
throw new InvalidObjectException("Line is invalid: " + line);
|
||||
}
|
||||
results.add(pair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Image icon2Image(Icon icon) {
|
||||
return ImageUtilities.icon2Image(icon);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
fileToPath = File.class.getMethod("toPath", new Class[0]);
|
||||
@@ -1078,35 +933,6 @@ public final class Utilities {
|
||||
return new File(u);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static URL toURL(File f) throws MalformedURLException {
|
||||
if (f == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (!f.isAbsolute()) {
|
||||
throw new IllegalArgumentException("Relative path: " + f);
|
||||
}
|
||||
URI uri = toURI(f);
|
||||
|
||||
return uri.toURL();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static File toFile(URL u) {
|
||||
if (u == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
try {
|
||||
URI uri = u.toURI();
|
||||
|
||||
return toFile(uri);
|
||||
} catch (URISyntaxException use) {
|
||||
return null;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static abstract interface RE {
|
||||
public abstract void init(String[] paramArrayOfString1, String[] paramArrayOfString2);
|
||||
|
||||
@@ -1114,30 +940,4 @@ public final class Utilities {
|
||||
|
||||
public abstract String[] readPair(String paramString);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class UnorderableException extends RuntimeException {
|
||||
static final long serialVersionUID = 6749951134051806661L;
|
||||
private Collection unorderable;
|
||||
private Map deps;
|
||||
|
||||
public UnorderableException(Collection unorderable, Map deps) {
|
||||
this.unorderable = unorderable;
|
||||
this.deps = deps;
|
||||
}
|
||||
|
||||
public UnorderableException(String message, Collection unorderable, Map deps) {
|
||||
super();
|
||||
this.unorderable = unorderable;
|
||||
this.deps = deps;
|
||||
}
|
||||
|
||||
public Collection getUnorderable() {
|
||||
return this.unorderable;
|
||||
}
|
||||
|
||||
public Map getDeps() {
|
||||
return this.deps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user