shift for horizontal scroll

fixed issue with size calculation when zoomed
This commit is contained in:
Branislav Stojkovic
2018-12-15 18:23:56 +01:00
parent ed6792800b
commit 2ee81093a0
8 changed files with 260 additions and 232 deletions
+224 -216
View File
@@ -1,223 +1,231 @@
/*
*
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
*
* This file is part of DIYLC.
*
* DIYLC 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.
*
* DIYLC 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.
*
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
* <http://www.gnu.org/licenses/>.
*/
package org.diylc;
DIY Layout Creator (DIYLC).
Copyright (c) 2009-2018 held jointly by the individual authors.
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.SplashScreen;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;
This file is part of DIYLC.
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
DIYLC 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.
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.PropertyInjector;
import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter;
import org.diylc.swing.gui.MainFrame;
import org.diylc.swing.gui.TemplateDialog;
import org.diylc.swingframework.FontChooserComboBox;
DIYLC 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.
/**
* Main class that runs DIYLC.
*
* @author Branislav Stojkovic
*
* @see Presenter
* @see MainFrame
*/
public class DIYLCStarter {
You should have received a copy of the GNU General Public License
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
private static final Logger LOG = Logger.getLogger(DIYLCStarter.class);
*/
package org.diylc;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.SplashScreen;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.PropertyInjector;
import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter;
import org.diylc.swing.gui.MainFrame;
import org.diylc.swing.gui.TemplateDialog;
/**
* Main class that runs DIYLC.
*
* @author Branislav Stojkovic
*
* @see Presenter
* @see MainFrame
*/
public class DIYLCStarter {
private static final Logger LOG = Logger.getLogger(DIYLCStarter.class);
private static final String SCRIPT_RUN = "org.diylc.scriptRun";
/**
* @param args
*/
public static void main(String[] args) {
// Initialize splash screen
final SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null) {
final Graphics2D g = splash.createGraphics();
if (g != null) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 90; i >= 0; i--) {
if (!splash.isVisible())
return;
final int frame = i;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
renderSplashFrame(splash, g, frame);
splash.update();
}
});
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
});
t.start();
}
}
URL url = DIYLCStarter.class.getResource("log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
PropertyConfigurator.configure(properties);
} catch (Exception e) {
LOG.error("Could not initialize log4j configuration", e);
}
ConfigurationManager.initialize("diylc");
LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by "
+ System.getProperty("java.vm.vendor"));
LOG.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
LOG.error("Could not set Look&Feel", e);
}
String val = System.getProperty(SCRIPT_RUN);
if (!"true".equals(val)) {
int response =
JOptionPane.showConfirmDialog(null, "It is not recommended to run DIYLC by clicking on the diylc.jar file.\n"
+ "Please use diylc.exe on Windows or run.sh on OSX/Linux to ensure the best\n"
+ "performance and reliability. Do you want to continue?", "DIYLC", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (response != JOptionPane.YES_OPTION) {
System.exit(0);
}
}
MainFrame mainFrame = new MainFrame();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
if (args.length > 0) {
mainFrame.getPresenter().loadProjectFromFile(args[0]);
} else {
boolean showTemplates = ConfigurationManager.getInstance().readBoolean(TemplateDialog.SHOW_TEMPLATES_KEY, false);
if (showTemplates) {
TemplateDialog templateDialog = new TemplateDialog(mainFrame, mainFrame.getPresenter());
if (!templateDialog.getFiles().isEmpty()) {
templateDialog.setVisible(true);
}
}
}
properties = new Properties();
try {
LOG.info("Injecting default properties.");
File f = new File("config.properties");
if (f.exists()) {
properties.load(new FileInputStream(f));
PropertyInjector.injectProperties(properties);
}
} catch (Exception e) {
LOG.error("Could not read config.properties file", e);
}
}
// Splash screen stuff below
private static ImageIcon resistor = null;
public static ImageIcon getResistor() {
if (resistor == null) {
resistor = (ImageIcon)IconLoader.SplashResistor.getIcon();
}
return resistor;
}
private static ImageIcon film = null;
public static ImageIcon getFilm() {
if (film == null) {
film = (ImageIcon)IconLoader.SplashFilm.getIcon();
}
return film;
}
private static ImageIcon ceramic = null;
public static ImageIcon getCeramic() {
if (ceramic == null) {
ceramic = (ImageIcon)IconLoader.SplashCeramic.getIcon();
}
return ceramic;
}
private static ImageIcon electrolytic = null;
public static ImageIcon getElectrolytic() {
if (electrolytic == null) {
electrolytic = (ImageIcon)IconLoader.SplashElectrolytic.getIcon();
}
return electrolytic;
}
private static ImageIcon splash = null;
public static ImageIcon getSplash() {
if (splash == null) {
splash = (ImageIcon)IconLoader.Splash.getIcon();
}
return splash;
}
private static Point resistorTarget = new Point(112, 114);
private static Point filmTarget = new Point(233, 113);
private static Point electrolyticTarget = new Point(261, 23);
private static Point ceramicTarget = new Point(352, 22);
private static int pxPerFrame = 3;
static void renderSplashFrame(SplashScreen splash, Graphics2D g, int frame) {
g.setComposite(AlphaComposite.Clear);
getSplash().paintIcon(null, g, 0, 0);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f - frame * 0.007f));
getResistor().paintIcon(null, g, resistorTarget.x - pxPerFrame * frame, resistorTarget.y);
getFilm().paintIcon(null, g, filmTarget.x, filmTarget.y + pxPerFrame * frame);
getElectrolytic().paintIcon(null, g, electrolyticTarget.x, electrolyticTarget.y - pxPerFrame * frame);
getCeramic().paintIcon(null, g, ceramicTarget.x + pxPerFrame * frame, ceramicTarget.y);
}
}
private static final String SCRIPT_RUN = "org.diylc.scriptRun";
/**
* @param args
*/
public static void main(String[] args) {
// Initialize splash screen
final SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null) {
final Graphics2D g = splash.createGraphics();
if (g != null) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 90; i >= 0; i--) {
if (!splash.isVisible())
return;
final int frame = i;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
renderSplashFrame(splash, g, frame);
splash.update();
}
});
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
});
t.start();
}
}
URL url = DIYLCStarter.class.getResource("log4j.properties");
Properties properties = new Properties();
try {
properties.load(url.openStream());
PropertyConfigurator.configure(properties);
} catch (Exception e) {
LOG.error("Could not initialize log4j configuration", e);
}
ConfigurationManager.initialize("diylc");
LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by "
+ System.getProperty("java.vm.vendor"));
LOG.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
LOG.error("Could not set Look&Feel", e);
}
// Thread fontThread = new Thread(new Runnable() {
//
// @Override
// public void run() {
// LOG.debug("Starting font pre-loading");
// FontChooserComboBox box = new FontChooserComboBox();
// LOG.debug("Finished font pre-loading");
// }
// });
// fontThread.start();
String val = System.getProperty(SCRIPT_RUN);
if (!"true".equals(val)) {
int response =
JOptionPane.showConfirmDialog(null, "It is not recommended to run DIYLC by clicking on the diylc.jar file.\n"
+ "Please use diylc.exe on Windows or run.sh on OSX/Linux to ensure the best\n"
+ "performance and reliability. Do you want to continue?", "DIYLC", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (response != JOptionPane.YES_OPTION) {
System.exit(0);
}
}
MainFrame mainFrame = new MainFrame();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
if (args.length > 0) {
mainFrame.getPresenter().loadProjectFromFile(args[0]);
} else {
boolean showTemplates = ConfigurationManager.getInstance().readBoolean(TemplateDialog.SHOW_TEMPLATES_KEY, false);
if (showTemplates) {
TemplateDialog templateDialog = new TemplateDialog(mainFrame, mainFrame.getPresenter());
if (!templateDialog.getFiles().isEmpty()) {
templateDialog.setVisible(true);
}
}
}
properties = new Properties();
try {
LOG.info("Injecting default properties.");
File f = new File("config.properties");
if (f.exists()) {
properties.load(new FileInputStream(f));
PropertyInjector.injectProperties(properties);
}
} catch (Exception e) {
LOG.error("Could not read config.properties file", e);
}
}
// Splash screen stuff below
private static ImageIcon resistor = null;
public static ImageIcon getResistor() {
if (resistor == null) {
resistor = (ImageIcon) IconLoader.SplashResistor.getIcon();
}
return resistor;
}
private static ImageIcon film = null;
public static ImageIcon getFilm() {
if (film == null) {
film = (ImageIcon) IconLoader.SplashFilm.getIcon();
}
return film;
}
private static ImageIcon ceramic = null;
public static ImageIcon getCeramic() {
if (ceramic == null) {
ceramic = (ImageIcon) IconLoader.SplashCeramic.getIcon();
}
return ceramic;
}
private static ImageIcon electrolytic = null;
public static ImageIcon getElectrolytic() {
if (electrolytic == null) {
electrolytic = (ImageIcon) IconLoader.SplashElectrolytic.getIcon();
}
return electrolytic;
}
private static ImageIcon splash = null;
public static ImageIcon getSplash() {
if (splash == null) {
splash = (ImageIcon) IconLoader.Splash.getIcon();
}
return splash;
}
private static Point resistorTarget = new Point(112, 114);
private static Point filmTarget = new Point(233, 113);
private static Point electrolyticTarget = new Point(261, 23);
private static Point ceramicTarget = new Point(352, 22);
private static int pxPerFrame = 3;
static void renderSplashFrame(SplashScreen splash, Graphics2D g, int frame) {
g.setComposite(AlphaComposite.Clear);
getSplash().paintIcon(null, g, 0, 0);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f - frame * 0.007f));
getResistor().paintIcon(null, g, resistorTarget.x - pxPerFrame * frame, resistorTarget.y);
getFilm().paintIcon(null, g, filmTarget.x, filmTarget.y + pxPerFrame * frame);
getElectrolytic().paintIcon(null, g, electrolyticTarget.x, electrolyticTarget.y - pxPerFrame * frame);
getCeramic().paintIcon(null, g, ceramicTarget.x + pxPerFrame * frame, ceramicTarget.y);
}
}
@@ -239,17 +239,21 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
public void unitsChanged(boolean isMetric) {
plugInPort.setMetric(isMetric);
}
});
});
// disable scrolling
scrollPane.setWheelScrollingEnabled(false);
scrollPane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
public void mouseWheelMoved(MouseWheelEvent e) {
final JScrollBar horizontalScrollBar = scrollPane.getHorizontalScrollBar();
final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
// disable scrolling
scrollPane.setWheelScrollingEnabled(false);
Point mousePos = getCanvasPanel().getMousePosition(true);
@@ -280,9 +284,16 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
horizontal.setValue(horizontal.getValue() + dx);
JScrollBar vertical = scrollPane.getVerticalScrollBar();
vertical.setValue(vertical.getValue() + dy);
} else {
// enable scrolling
scrollPane.setWheelScrollingEnabled(true);
} if (e.isShiftDown()) {
int iScrollAmount = e.getScrollAmount();
int iNewValue = horizontalScrollBar.getValue() + horizontalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
if (iNewValue <= horizontalScrollBar.getMaximum())
horizontalScrollBar.setValue(iNewValue);
} else {
int iScrollAmount = e.getScrollAmount();
int iNewValue = verticalScrollBar.getValue() + verticalScrollBar.getBlockIncrement() * iScrollAmount * e.getWheelRotation();
if (iNewValue <= verticalScrollBar.getMaximum())
verticalScrollBar.setValue(iNewValue);
}
}
});
@@ -602,7 +613,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override
public void run() {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds());
scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds(true));
}
});
break;