Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hauptprogramm;
- 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.Image;
- import java.awt.image.BufferedImage;
- import javax.swing.AbstractButton;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JLabel;
- import javax.swing.JMenuBar;
- import javax.swing.JToolBar;
- import <removed>.CMainClass;
- import <removed>.CUiObjectButton;
- import <removed>.CUiObjectFftLocal;
- import <removed>.CUiObjectLabel;
- import <removed>.CUiObjectPanel;
- import <removed>.CUiObjectSlider;
- import <removed>.CUiObjectSwitchImage;
- import <removed>.CUiObjectTsView;
- public class start {
- /**
- *If TRUE the scaling factor is fixed to "2" (for test and debug purposes)
- */
- private static boolean fixedScale2x = false;
- /**
- * If TRUE there will be no scaling no matter of the screen Size / DPI-Value
- */
- private static boolean noScale = false;
- /**
- * Stores the scaling Factor
- * DefaultValue = 2 (scales double the size - will be ignored id noScale is TRUE)
- */
- private static float scaleFactor = 2.0f;
- /**
- * This value is the base value used for calculating the scale factor.
- * The factor is calculated by how much bigger the current screen resolution is, compared to this value.
- */
- private static int baseXResolution = 1920;
- public static void main(String[] args) {
- args = new String[6];
- args[0] = "<path to the tool that is to be fixed>.jar";
- args[1] = "-c"; //Some parameters neccessary
- args[2] = "config_53"; //Some parameters neccessary
- args[3] = "-u"; //Some parameters neccessary
- args[4] = "-n"; //Some parameters neccessary
- args[5] = ""; //Some parameters neccessary
- for(int i=0; i< args.length; i++) {
- if (args[i].trim().equalsIgnoreCase("-fixedscale")) {
- fixedScale2x=true;
- args[i] = ""; //Remove the additional parameter for not confusing the original software
- }
- if (args[i].trim().equalsIgnoreCase("-noscale") ) {
- noScale=true;
- args[i] = ""; //Remove the additional parameter for not confusing the original software
- }
- }
- /*
- * If not disabled by parameter, call mathod to calculate the scaling factor.
- */
- if(!noScale && !fixedScale2x) {
- findScaleFactor();
- }
- CMainClass.main(args); //Call main() mathod and start original programm
- if(!noScale) {
- CMainClass.frame.setSize(new Dimension((int)(CMainClass.frame.getWidth()*scaleFactor), (int)(CMainClass.frame.getHeight()*scaleFactor)));
- getAllComponents(CMainClass.frame); //Iterates all child-components and scales them
- }
- }
- /**
- * Calculates the scaling factor by calculating how much bigger the current screen resolution (x-direction) is
- * in comparision to the value defined as baseXResolution.
- */
- private static void findScaleFactor() {
- GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- int currentXResolution = gd.getDisplayMode().getWidth();
- if(baseXResolution > currentXResolution) return; //if current resolution is less then we do not need to calculate anything
- scaleFactor = currentXResolution / baseXResolution; //calculate factor
- scaleFactor = (float) (Math.round(100.0 * scaleFactor) / 100.0); //round to 2 tailing digits
- System.out.println("Scalefactor:"+scaleFactor);
- }
- /**
- * Iterates all child components of the Container in c
- * and changes sizes, font-sizes, margins, backgrounds, and so on.
- * Because a lot of components are to be handled in a different way, there are a lot of if-cases
- * @param c
- */
- public static void getAllComponents(final Container c) {
- Component[] comps = c.getComponents();
- for (Component comp : comps) {
- if(!(comp instanceof CUiObjectSlider) && !(comp instanceof CUiObjectFftLocal) && !(comp instanceof CUiObjectTsView)) {
- comp.setFont(new Font( comp.getFont().getFontName(),
- comp.getFont().getStyle(),
- (int)(comp.getFont().getSize()*scaleFactor)
- )
- );
- };
- if((comp instanceof CUiObjectFftLocal) || (comp instanceof CUiObjectTsView)) {
- comp.setFont(new Font( comp.getFont().getFontName(),
- Font.BOLD,
- 14/*comp.getFont().getSize()*/
- ));
- };
- comp.setBounds(
- (int)(comp.getBounds().x*scaleFactor),
- (int)(comp.getBounds().y*scaleFactor),
- (int)(comp.getBounds().width*scaleFactor),
- (int)(comp.getBounds().height*scaleFactor)
- );
- if(comp instanceof CUiObjectButton) {
- Icon tIcon;
- try { tIcon = ((CUiObjectButton) comp).getIcon();
- ((CUiObjectButton) comp).setIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectButton) comp).getDisabledIcon();
- ((CUiObjectButton) comp).setDisabledIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectButton) comp).getPressedIcon();
- ((CUiObjectButton) comp).setPressedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectButton) comp).getRolloverIcon();
- ((CUiObjectButton) comp).setRolloverIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectButton) comp).getDisabledSelectedIcon();
- ((CUiObjectButton) comp).setDisabledSelectedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectButton) comp).getRolloverSelectedIcon();
- ((CUiObjectButton) comp).setRolloverSelectedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- }
- else
- if(comp instanceof CUiObjectPanel) {
- String iconPath = ((CUiObjectPanel)comp).getUiImage();
- ((CUiObjectPanel)comp).setUiImage("");
- if(iconPath.length()>0){
- ImageIcon i = new ImageIcon(iconPath);
- /* Atention: double code - can be made better */
- Image scaledImage = i.getImage().getScaledInstance(
- (int)(i.getIconWidth()*scaleFactor),
- (int)(i.getIconHeight()*scaleFactor),
- java.awt.Image.SCALE_SMOOTH);
- ImageIcon imageIcon = new ImageIcon(scaledImage);
- JLabel t = new JLabel();
- t.setIcon(imageIcon);
- t.setLocation(0,0);
- t.setSize(comp.getSize());
- t.setVerticalAlignment(JLabel.TOP);
- t.setHorizontalTextPosition(JLabel.LEFT);
- ((CUiObjectPanel)comp).add(t);
- }
- }
- else
- if(comp instanceof CUiObjectSlider) {
- Icon tIcon;
- try { tIcon = ((AbstractButton) comp).getIcon();
- ((AbstractButton) comp).setIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((AbstractButton) comp).getDisabledIcon();
- ((AbstractButton) comp).setDisabledIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((AbstractButton) comp).getPressedIcon();
- ((AbstractButton) comp).setPressedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((AbstractButton) comp).getRolloverIcon();
- ((AbstractButton) comp).setRolloverIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((AbstractButton) comp).getDisabledSelectedIcon();
- ((AbstractButton) comp).setDisabledSelectedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((AbstractButton) comp).getRolloverSelectedIcon();
- ((AbstractButton) comp).setRolloverSelectedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- }
- else
- if(comp instanceof CUiObjectLabel) {
- Icon tIcon;
- try { tIcon = ((CUiObjectLabel) comp).getIcon();
- ((CUiObjectLabel) comp).setIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectLabel) comp).getDisabledIcon();
- ((CUiObjectLabel) comp).setDisabledIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectLabel) comp).getPressedIcon();
- ((CUiObjectLabel) comp).setPressedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectLabel) comp).getRolloverIcon();
- ((CUiObjectLabel) comp).setRolloverIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectLabel) comp).getDisabledSelectedIcon();
- ((CUiObjectLabel) comp).setDisabledSelectedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- try { tIcon = ((CUiObjectLabel) comp).getRolloverSelectedIcon();
- ((CUiObjectLabel) comp).setRolloverSelectedIcon(iconToScaledImageIcon(tIcon)); }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- }
- else
- if(comp instanceof CUiObjectSwitchImage) {
- Icon tIcon;
- try { tIcon = ((CUiObjectSwitchImage) comp).getIcon();
- ((CUiObjectSwitchImage) comp).setIcon(iconToScaledImageIcon(tIcon));
- }
- catch (Exception e){ /*Gibt eigentlich nichts zu tun... oder?*/ }
- }
- if (comp instanceof Container) {
- if(!(comp instanceof JMenuBar) && !(comp instanceof JToolBar)) {
- getAllComponents((Container) comp);
- }
- }
- }
- }
- static ImageIcon iconToScaledImageIcon(Icon icon) {
- int w = icon.getIconWidth();
- int h = icon.getIconHeight();
- GraphicsEnvironment ge =
- GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice gd = ge.getDefaultScreenDevice();
- GraphicsConfiguration gc = gd.getDefaultConfiguration();
- BufferedImage image = gc.createCompatibleImage(w, h, java.awt.image.BufferedImage.TRANSLUCENT);
- Graphics2D g = image.createGraphics();
- icon.paintIcon(null, g, 0, 0);
- g.dispose();
- /* Achtung, doppelter code ... kann verbessert werden */
- Image scaledImage = image.getScaledInstance(
- (int)(w*scaleFactor),
- (int)(h*scaleFactor),
- java.awt.Image.SCALE_SMOOTH);
- ImageIcon imageIcon = new ImageIcon(scaledImage);
- return imageIcon;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement