Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (C) 2018 OTK Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* The GNU General Public License allows you also to freely redistribute
* the libraries under the same license, if you provide the terms of the
* GNU General Public License with them and add the following
* copyright notice at the appropriate place (with a link to
* http://javacollection.net/reflectionui/ web site when possible).
******************************************************************************/
package xy.reflect.ui.util;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.AWTEventListenerProxy;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.DefaultFormatter;
import xy.reflect.ui.ReflectionUI;
import xy.reflect.ui.control.DefaultFieldControlData;
import xy.reflect.ui.control.ErrorHandlingFieldControlData;
import xy.reflect.ui.control.IContext;
import xy.reflect.ui.control.IFieldControlData;
import xy.reflect.ui.control.IFieldControlInput;
import xy.reflect.ui.control.IMethodControlData;
import xy.reflect.ui.control.plugin.ICustomizableFieldControlPlugin;
import xy.reflect.ui.control.plugin.IFieldControlPlugin;
import xy.reflect.ui.control.swing.IAdvancedFieldControl;
import xy.reflect.ui.control.swing.TextControl;
import xy.reflect.ui.control.swing.renderer.Form;
import xy.reflect.ui.control.swing.renderer.SwingRenderer;
import xy.reflect.ui.info.ColorSpecification;
import xy.reflect.ui.info.ResourcePath;
import xy.reflect.ui.info.ResourcePath.PathKind;
import xy.reflect.ui.info.field.FieldInfoProxy;
import xy.reflect.ui.info.field.IFieldInfo;
import xy.reflect.ui.info.filter.IInfoFilter;
import xy.reflect.ui.info.method.IMethodInfo;
import xy.reflect.ui.info.method.InvocationData;
import xy.reflect.ui.info.type.ITypeInfo;
import xy.reflect.ui.undo.ModificationStack;
import xy.reflect.ui.util.component.AbstractControlButton;
import xy.reflect.ui.util.component.ControlPanel;
public class SwingRendererUtils {
public static final BufferedImage NULL_IMAGE = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
public static final ImageIcon ERROR_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/error.png"));
public static final ImageIcon HELP_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/help.png"));
public static final ImageIcon DETAILS_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/details.png"));
public static final ImageIcon ADD_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/add.png"));
public static final ImageIcon REMOVE_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/remove.png"));
public static final ImageIcon UP_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/up.png"));
public static final ImageIcon DOWN_ICON = new ImageIcon(ReflectionUI.class.getResource("resource/down.png"));
public static final ImageIcon SAVE_ALL_ICON = new ImageIcon(
ReflectionUI.class.getResource("resource/save-all.png"));
public static Map IMAGE_CACHE = new HashMap();
public static boolean isNullImage(Image image) {
return (image.getWidth(null) * image.getHeight(null) == 1);
}
public static ImageIcon getSmallIcon(ImageIcon icon) {
Image image = icon.getImage();
image = SwingRendererUtils.scalePreservingRatio(image, 16, 16, Image.SCALE_SMOOTH);
return new ImageIcon(image);
}
public static Image scalePreservingRatio(Image image, int newWidth, int newHeight, int scaleQuality) {
Dimension imageSize = new Dimension(image.getWidth(null), image.getHeight(null));
Dimension boxSize = new Dimension(newWidth, newHeight);
Rectangle imageBoundsInBox = new Rectangle();
{
float resizeRatioBasedOnWidth = (float) boxSize.width / (float) imageSize.width;
float resizeRatioBasedOnHeight = (float) boxSize.height / (float) imageSize.height;
float resizeRatio = Math.min(resizeRatioBasedOnWidth, resizeRatioBasedOnHeight);
imageBoundsInBox.width = Math.round(imageSize.width * resizeRatio);
imageBoundsInBox.height = Math.round(imageSize.height * resizeRatio);
imageBoundsInBox.x = Math.round((boxSize.width - imageBoundsInBox.width) / 2f);
imageBoundsInBox.y = Math.round((boxSize.height - imageBoundsInBox.height) / 2f);
}
BufferedImage result = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = result.createGraphics();
g.drawImage(image.getScaledInstance(imageBoundsInBox.width, imageBoundsInBox.height, Image.SCALE_SMOOTH),
imageBoundsInBox.x, imageBoundsInBox.y, null);
g.dispose();
return result;
}
public static void showTooltipNow(JComponent c) {
try {
Method showToolTipMehod = ToolTipManager.class.getDeclaredMethod("show",
new Class[] { JComponent.class });
showToolTipMehod.setAccessible(true);
showToolTipMehod.invoke(ToolTipManager.sharedInstance(), new Object[] { c });
} catch (Throwable e1) {
try {
KeyEvent ke = new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), InputEvent.CTRL_MASK,
KeyEvent.VK_F1, KeyEvent.CHAR_UNDEFINED);
c.dispatchEvent(ke);
} catch (Throwable e2) {
System.err.println(
"Failed to show tooltip programmatically: \n1st failure: " + e1 + "\n2nd failure: \n" + e2);
}
}
}
public static void setRecursivelyEnabled(Component c, boolean b) {
c.setEnabled(b);
if (c instanceof Container) {
for (Component child : ((Container) c).getComponents()) {
setRecursivelyEnabled(child, b);
}
}
}
public static Window getWindowAncestorOrSelf(Component c) {
if (c instanceof Window) {
return (Window) c;
}
if (c == null) {
return null;
}
return SwingUtilities.getWindowAncestor(c);
}
public static JPanel flowInLayout(Component c, int gridBagConstraintsAnchor) {
JPanel result = new ControlPanel();
result.setLayout(new GridBagLayout());
GridBagConstraints contraints = new GridBagConstraints();
contraints.gridx = 0;
contraints.gridy = 0;
contraints.weightx = 1;
contraints.weighty = 1;
contraints.anchor = gridBagConstraintsAnchor;
result.add(c, contraints);
return result;
}
public static Form findParentForm(Component component, SwingRenderer swingRenderer) {
Component candidate = component.getParent();
while (candidate != null) {
if (isForm(candidate, swingRenderer)) {
return (Form) candidate;
}
candidate = candidate.getParent();
}
return null;
}
public static List