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
@@ -99,10 +99,12 @@ public interface ISelectionProcessor {
/** /**
* Returns the minimum rectangle containing all selected components, or null if none exists. * Returns the minimum rectangle containing all selected components, or null if none exists.
* Rectangle is scaled by the current zoom level. * Rectangle is scaled by the current zoom level.
*
* @param applyZoom
* *
* @return * @return
*/ */
Rectangle2D getSelectionBounds(); Rectangle2D getSelectionBounds(boolean applyZoom);
/** /**
* Moves selection for the specified offset. * Moves selection for the specified offset.
@@ -859,7 +859,7 @@ public class Presenter implements IPlugInPort {
} }
@Override @Override
public Rectangle2D getSelectionBounds() { public Rectangle2D getSelectionBounds(boolean applyZoom) {
if (selectedComponents == null || selectedComponents.isEmpty()) if (selectedComponents == null || selectedComponents.isEmpty())
return null; return null;
@@ -871,7 +871,7 @@ public class Presenter implements IPlugInPort {
else else
LOG.info("Area is null"); LOG.info("Area is null");
} }
if (drawingManager.getZoomLevel() != 1) { if (drawingManager.getZoomLevel() != 1 && applyZoom) {
totalArea totalArea
.transform(AffineTransform.getScaleInstance(drawingManager.getZoomLevel(), drawingManager.getZoomLevel())); .transform(AffineTransform.getScaleInstance(drawingManager.getZoomLevel(), drawingManager.getZoomLevel()));
} }
@@ -1881,7 +1881,7 @@ public class Presenter implements IPlugInPort {
if (selectedComponents.isEmpty()) { if (selectedComponents.isEmpty()) {
return null; return null;
} }
Rectangle2D rect = getSelectionBounds(); Rectangle2D rect = getSelectionBounds(false);
double width = rect.getWidth(); double width = rect.getWidth();
double height = rect.getHeight(); double height = rect.getHeight();
Binary file not shown.
@@ -22,7 +22,6 @@ import java.awt.Color;
import java.awt.Composite; import java.awt.Composite;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.geom.Rectangle2D;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.common.OrientationHV; import org.diylc.common.OrientationHV;
Binary file not shown.
+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). import java.awt.AlphaComposite;
Copyright (c) 2009-2018 held jointly by the individual authors. 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 import org.apache.log4j.Logger;
it under the terms of the GNU General Public License as published by import org.apache.log4j.PropertyConfigurator;
the Free Software Foundation, either version 3 of the License, or import org.diylc.appframework.miscutils.ConfigurationManager;
(at your option) any later version. 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 * Main class that runs DIYLC.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
GNU General Public License for more details. * @author Branislav Stojkovic
*
* @see Presenter
* @see MainFrame
*/
public class DIYLCStarter {
You should have received a copy of the GNU General Public License private static final Logger LOG = Logger.getLogger(DIYLCStarter.class);
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
*/ private static final String SCRIPT_RUN = "org.diylc.scriptRun";
package org.diylc;
/**
import java.awt.AlphaComposite; * @param args
import java.awt.Graphics2D; */
import java.awt.Point; public static void main(String[] args) {
import java.awt.SplashScreen; // Initialize splash screen
import java.io.File; final SplashScreen splash = SplashScreen.getSplashScreen();
import java.io.FileInputStream; if (splash != null) {
import java.net.URL; final Graphics2D g = splash.createGraphics();
import java.util.Properties; if (g != null) {
Thread t = new Thread(new Runnable() {
import javax.swing.ImageIcon;
import javax.swing.JOptionPane; @Override
import javax.swing.SwingUtilities; public void run() {
import javax.swing.UIManager; for (int i = 90; i >= 0; i--) {
if (!splash.isVisible())
import org.apache.log4j.Logger; return;
import org.apache.log4j.PropertyConfigurator; final int frame = i;
import org.diylc.appframework.miscutils.ConfigurationManager; SwingUtilities.invokeLater(new Runnable() {
import org.diylc.appframework.miscutils.PropertyInjector;
import org.diylc.images.IconLoader; @Override
import org.diylc.presenter.Presenter; public void run() {
import org.diylc.swing.gui.MainFrame; renderSplashFrame(splash, g, frame);
import org.diylc.swing.gui.TemplateDialog; splash.update();
}
/** });
* Main class that runs DIYLC. try {
* Thread.sleep(10);
* @author Branislav Stojkovic } catch (InterruptedException e) {
* }
* @see Presenter }
* @see MainFrame }
*/ });
public class DIYLCStarter { t.start();
}
private static final Logger LOG = Logger.getLogger(DIYLCStarter.class); }
private static final String SCRIPT_RUN = "org.diylc.scriptRun"; URL url = DIYLCStarter.class.getResource("log4j.properties");
Properties properties = new Properties();
/** try {
* @param args properties.load(url.openStream());
*/ PropertyConfigurator.configure(properties);
public static void main(String[] args) { } catch (Exception e) {
// Initialize splash screen LOG.error("Could not initialize log4j configuration", e);
final SplashScreen splash = SplashScreen.getSplashScreen(); }
if (splash != null) {
final Graphics2D g = splash.createGraphics(); ConfigurationManager.initialize("diylc");
if (g != null) {
Thread t = new Thread(new Runnable() { LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by "
+ System.getProperty("java.vm.vendor"));
@Override LOG.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
public void run() {
for (int i = 90; i >= 0; i--) { LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
if (!splash.isVisible())
return; try {
final int frame = i; UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.invokeLater(new Runnable() { } catch (Exception e) {
LOG.error("Could not set Look&Feel", e);
@Override }
public void run() {
renderSplashFrame(splash, g, frame); // Thread fontThread = new Thread(new Runnable() {
splash.update(); //
} // @Override
}); // public void run() {
try { // LOG.debug("Starting font pre-loading");
Thread.sleep(10); // FontChooserComboBox box = new FontChooserComboBox();
} catch (InterruptedException e) { // LOG.debug("Finished font pre-loading");
} // }
} // });
} // fontThread.start();
});
t.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"
URL url = DIYLCStarter.class.getResource("log4j.properties"); + "Please use diylc.exe on Windows or run.sh on OSX/Linux to ensure the best\n"
Properties properties = new Properties(); + "performance and reliability. Do you want to continue?", "DIYLC", JOptionPane.YES_NO_OPTION,
try { JOptionPane.WARNING_MESSAGE);
properties.load(url.openStream()); if (response != JOptionPane.YES_OPTION) {
PropertyConfigurator.configure(properties); System.exit(0);
} catch (Exception e) { }
LOG.error("Could not initialize log4j configuration", e); }
}
MainFrame mainFrame = new MainFrame();
ConfigurationManager.initialize("diylc"); mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by " if (args.length > 0) {
+ System.getProperty("java.vm.vendor")); mainFrame.getPresenter().loadProjectFromFile(args[0]);
LOG.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version")); } else {
boolean showTemplates = ConfigurationManager.getInstance().readBoolean(TemplateDialog.SHOW_TEMPLATES_KEY, false);
LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir")); if (showTemplates) {
TemplateDialog templateDialog = new TemplateDialog(mainFrame, mainFrame.getPresenter());
try { if (!templateDialog.getFiles().isEmpty()) {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); templateDialog.setVisible(true);
} catch (Exception e) { }
LOG.error("Could not set Look&Feel", e); }
} }
String val = System.getProperty(SCRIPT_RUN); properties = new Properties();
if (!"true".equals(val)) { try {
int response = LOG.info("Injecting default properties.");
JOptionPane.showConfirmDialog(null, "It is not recommended to run DIYLC by clicking on the diylc.jar file.\n" File f = new File("config.properties");
+ "Please use diylc.exe on Windows or run.sh on OSX/Linux to ensure the best\n" if (f.exists()) {
+ "performance and reliability. Do you want to continue?", "DIYLC", JOptionPane.YES_NO_OPTION, properties.load(new FileInputStream(f));
JOptionPane.WARNING_MESSAGE); PropertyInjector.injectProperties(properties);
if (response != JOptionPane.YES_OPTION) { }
System.exit(0); } catch (Exception e) {
} LOG.error("Could not read config.properties file", e);
} }
}
MainFrame mainFrame = new MainFrame();
mainFrame.setLocationRelativeTo(null); // Splash screen stuff below
mainFrame.setVisible(true);
if (args.length > 0) { private static ImageIcon resistor = null;
mainFrame.getPresenter().loadProjectFromFile(args[0]);
} else { public static ImageIcon getResistor() {
boolean showTemplates = ConfigurationManager.getInstance().readBoolean(TemplateDialog.SHOW_TEMPLATES_KEY, false); if (resistor == null) {
if (showTemplates) { resistor = (ImageIcon) IconLoader.SplashResistor.getIcon();
TemplateDialog templateDialog = new TemplateDialog(mainFrame, mainFrame.getPresenter()); }
if (!templateDialog.getFiles().isEmpty()) { return resistor;
templateDialog.setVisible(true); }
}
} private static ImageIcon film = null;
}
public static ImageIcon getFilm() {
properties = new Properties(); if (film == null) {
try { film = (ImageIcon) IconLoader.SplashFilm.getIcon();
LOG.info("Injecting default properties."); }
File f = new File("config.properties"); return film;
if (f.exists()) { }
properties.load(new FileInputStream(f));
PropertyInjector.injectProperties(properties); private static ImageIcon ceramic = null;
}
} catch (Exception e) { public static ImageIcon getCeramic() {
LOG.error("Could not read config.properties file", e); if (ceramic == null) {
} ceramic = (ImageIcon) IconLoader.SplashCeramic.getIcon();
} }
return ceramic;
// Splash screen stuff below }
private static ImageIcon resistor = null; private static ImageIcon electrolytic = null;
public static ImageIcon getResistor() { public static ImageIcon getElectrolytic() {
if (resistor == null) { if (electrolytic == null) {
resistor = (ImageIcon)IconLoader.SplashResistor.getIcon(); electrolytic = (ImageIcon) IconLoader.SplashElectrolytic.getIcon();
} }
return resistor; return electrolytic;
} }
private static ImageIcon film = null; private static ImageIcon splash = null;
public static ImageIcon getFilm() { public static ImageIcon getSplash() {
if (film == null) { if (splash == null) {
film = (ImageIcon)IconLoader.SplashFilm.getIcon(); splash = (ImageIcon) IconLoader.Splash.getIcon();
} }
return film; return splash;
} }
private static ImageIcon ceramic = null; private static Point resistorTarget = new Point(112, 114);
private static Point filmTarget = new Point(233, 113);
public static ImageIcon getCeramic() { private static Point electrolyticTarget = new Point(261, 23);
if (ceramic == null) { private static Point ceramicTarget = new Point(352, 22);
ceramic = (ImageIcon)IconLoader.SplashCeramic.getIcon();
} private static int pxPerFrame = 3;
return ceramic;
} static void renderSplashFrame(SplashScreen splash, Graphics2D g, int frame) {
g.setComposite(AlphaComposite.Clear);
private static ImageIcon electrolytic = null; getSplash().paintIcon(null, g, 0, 0);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f - frame * 0.007f));
public static ImageIcon getElectrolytic() { getResistor().paintIcon(null, g, resistorTarget.x - pxPerFrame * frame, resistorTarget.y);
if (electrolytic == null) { getFilm().paintIcon(null, g, filmTarget.x, filmTarget.y + pxPerFrame * frame);
electrolytic = (ImageIcon)IconLoader.SplashElectrolytic.getIcon(); getElectrolytic().paintIcon(null, g, electrolyticTarget.x, electrolyticTarget.y - pxPerFrame * frame);
} getCeramic().paintIcon(null, g, ceramicTarget.x + pxPerFrame * frame, ceramicTarget.y);
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) { public void unitsChanged(boolean isMetric) {
plugInPort.setMetric(isMetric); plugInPort.setMetric(isMetric);
} }
}); });
// disable scrolling
scrollPane.setWheelScrollingEnabled(false);
scrollPane.addMouseWheelListener(new MouseWheelListener() { scrollPane.addMouseWheelListener(new MouseWheelListener() {
@Override @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); boolean wheelZoom = ConfigurationManager.getInstance().readBoolean(IPlugInPort.WHEEL_ZOOM_KEY, false);
if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) { if (wheelZoom || (Utils.isMac() ? e.isMetaDown() : e.isControlDown())) {
// disable scrolling
scrollPane.setWheelScrollingEnabled(false);
Point mousePos = getCanvasPanel().getMousePosition(true); Point mousePos = getCanvasPanel().getMousePosition(true);
@@ -280,9 +284,16 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
horizontal.setValue(horizontal.getValue() + dx); horizontal.setValue(horizontal.getValue() + dx);
JScrollBar vertical = scrollPane.getVerticalScrollBar(); JScrollBar vertical = scrollPane.getVerticalScrollBar();
vertical.setValue(vertical.getValue() + dy); vertical.setValue(vertical.getValue() + dy);
} else { } if (e.isShiftDown()) {
// enable scrolling int iScrollAmount = e.getScrollAmount();
scrollPane.setWheelScrollingEnabled(true); 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 @Override
public void run() { public void run() {
if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true)) if (ConfigurationManager.getInstance().readBoolean(IPlugInPort.SHOW_RULERS_KEY, true))
scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds()); scrollPane.setSelectionRectangle(plugInPort.getSelectionBounds(true));
} }
}); });
break; break;
+10 -2
View File
@@ -1868,16 +1868,24 @@
<org.diylc.appframework.update.Version> <org.diylc.appframework.update.Version>
<versionNumber> <versionNumber>
<major>3</major> <major>3</major>
<minor>41</minor> <minor>42</minor>
<build>2</build> <build>0</build>
</versionNumber> </versionNumber>
<releaseDate>2018-12-11 00:00:00.000 CET</releaseDate> <releaseDate>2018-12-11 00:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Holding "shift" key switches mouse wheel scrolling from vertical to horizontal</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>"Cut Line" component sometimes disappears</description> <description>"Cut Line" component sometimes disappears</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>Measurement tool shows incorrect readings when zoomed in or out</description>
</org.diylc.appframework.update.Change>
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>