This commit is contained in:
Branislav Stojkovic
2025-03-10 13:03:51 +01:00
parent ad9a575dc6
commit f820c23093
2148 changed files with 11547 additions and 48 deletions
@@ -0,0 +1,148 @@
package org.diylc;
import java.awt.AlphaComposite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.AffineTransform;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import org.diylc.swing.images.IconLoader;
/**
* Custom splash screen with animated components. Does not use standard SplashScreen because of issues with OS X and Java 8.
*
* @author bancika
*
*/
public class DIYLCSplash extends JDialog {
private static final long serialVersionUID = 1L;
private Thread t;
private int TOTAL_FRAMES = 90;
private int frameNumber = TOTAL_FRAMES;
private Point resistorTarget = new Point(112, 114);
private Point filmTarget = new Point(233, 113);
private Point electrolyticTarget = new Point(261, 23);
private Point ceramicTarget = new Point(352, 22);
private int pxPerFrame = 3;
public DIYLCSplash() {
setPreferredSize(new Dimension(getSplash().getIconWidth(), getSplash().getIconHeight()));
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
setUndecorated(true);
pack();
setLocationRelativeTo(null);
setVisible(true);
setAlwaysOnTop(true);
repaint();
t = new Thread(new Runnable() {
@Override
public void run() {
for (int i = TOTAL_FRAMES; i >= 0; i--) {
if (!isVisible())
return;
frameNumber = i;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
repaint();
}
});
try {
Thread.sleep(14);
} catch (InterruptedException e) {
}
}
}
});
t.start();
}
@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setComposite(AlphaComposite.SrcOver);
getSplash().paintIcon(null, g, 0, 0);
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
getResistor().paintIcon(null, g, resistorTarget.x - pxPerFrame * frameNumber, resistorTarget.y);
getFilm().paintIcon(null, g, filmTarget.x, filmTarget.y + pxPerFrame * frameNumber);
getElectrolytic().paintIcon(null, g, electrolyticTarget.x, electrolyticTarget.y - pxPerFrame * frameNumber);
getCeramic().paintIcon(null, g, ceramicTarget.x + pxPerFrame * frameNumber, ceramicTarget.y);
int splashX = 90;
int splashY = 52;
double theta = 2 * Math.PI * frameNumber / TOTAL_FRAMES;
g2d.translate(splashX, splashY);
g2d.transform(AffineTransform.getRotateInstance(theta));
getIc().paintIcon(null, g, -getIc().getIconWidth() / 2, -getIc().getIconHeight() / 2);
}
public void start() {
if (t != null)
t.start();
}
private ImageIcon resistor = null;
public ImageIcon getResistor() {
if (resistor == null) {
resistor = (ImageIcon) IconLoader.SplashResistor.getIcon();
}
return resistor;
}
private ImageIcon film = null;
private ImageIcon getFilm() {
if (film == null) {
film = (ImageIcon) IconLoader.SplashFilm.getIcon();
}
return film;
}
private ImageIcon ceramic = null;
private ImageIcon getCeramic() {
if (ceramic == null) {
ceramic = (ImageIcon) IconLoader.SplashCeramic.getIcon();
}
return ceramic;
}
private ImageIcon electrolytic = null;
private ImageIcon getElectrolytic() {
if (electrolytic == null) {
electrolytic = (ImageIcon) IconLoader.SplashElectrolytic.getIcon();
}
return electrolytic;
}
private ImageIcon ic = null;
private ImageIcon getIc() {
if (ic == null) {
ic = (ImageIcon) IconLoader.SplashIC.getIcon();
}
return ic;
}
private ImageIcon splash = null;
private ImageIcon getSplash() {
if (splash == null) {
splash = (ImageIcon) IconLoader.Splash.getIcon();
}
return splash;
}
}
@@ -0,0 +1,290 @@
/*
*
* 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;
import java.awt.Desktop;
import java.io.File;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Arrays;
import java.util.Properties;
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.appframework.miscutils.Utils;
import org.diylc.common.IPlugInPort;
import org.diylc.core.IView;
import org.diylc.lang.LangUtil;
import org.diylc.presenter.Presenter;
import org.diylc.serialization.ProjectFileManager;
import org.diylc.swing.gui.MainFrame;
import org.diylc.swing.gui.TemplateDialog;
import org.diylc.swing.plugins.file.ProjectDrawingProvider;
import org.diylc.swingframework.export.DrawingExporter;
import org.diylc.swingframework.fonts.FontOptimizer;
import com.thoughtworks.xstream.XStream;
import ca.cgjennings.jvm.JarLoader;
/**
* 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
* @throws InvalidActivityException
*/
public static void main(String[] args) {
try {
runDIYLC(args);
} catch (Throwable t) {
LOG.error("Major error while starting DIYLC", t);
System.out.println("Major error while starting DIYLC");
t.printStackTrace(System.out);
}
}
public static void runDIYLC(String[] args) {
// Initialize splash screen
DIYLCSplash splash = null;
Exception splashException = null;
boolean exportMode = Arrays.stream(args).anyMatch(a -> a.equalsIgnoreCase("--export"));
if (!exportMode) {
try {
splash = new DIYLCSplash();
} catch (Exception e) {
System.out.println("Splash screen could not be initialized: " + e.getMessage());
splashException = e;
}
}
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);
}
initializeConfiguration();
if (exportMode) {
LOG.info("Running in export mode with params: " + String.join(", ", args));
}
// disable HIGHLIGHT_CONTINUITY_AREA config, keep it transient
ConfigurationManager.getInstance().writeValue(IPlugInPort.HIGHLIGHT_CONTINUITY_AREA, false);
LOG.info("JarLoader strategy: " + JarLoader.getStrategy());
LOG.info("Loading languages...");
LangUtil.configure();
LOG.debug("Java version: " + System.getProperty("java.runtime.version") + " by "
+ System.getProperty("java.vm.vendor"));
LOG.debug("Java home: " + System.getProperty("java.home"));
LOG.debug("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
// set OS name as HTTP agent, java will append java version
Properties props = System.getProperties();
props.setProperty("http.agent", System.getProperty("os.name"));
LOG.info("Starting DIYLC with working directory " + System.getProperty("user.dir"));
LOG.info("Configuration dump start.");
// log configuration
Field[] fields = IPlugInPort.class.getFields();
for (Field f : fields) {
if (f.getType() != String.class || !f.getName().toUpperCase().equals(f.getName()))
continue;
try {
String key = (String) f.get(null);
Object configValue = ConfigurationManager.getInstance().readObject(key, null);
if (configValue != null
&& (configValue.getClass() == Boolean.class || configValue.getClass() == String.class)) {
LOG.info(key + " = " + configValue);
}
} catch (Exception e) {
LOG.info("Error logging for field: " + f.getName());
}
}
LOG.info("Configuration dump end.");
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() {
try {
FontOptimizer.run(ConfigurationManager.getInstance());
} catch (Exception e) {
LOG.error("Could not ", e);
}
}
});
fontThread.setPriority(Thread.MIN_PRIORITY);
fontThread.start();
String val = System.getProperty(SCRIPT_RUN);
if (!"true".equals(val)) {
LOG.info("Detected no scriptRun setting!");
int response = JOptionPane.showConfirmDialog(splash,
"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);
}
}
LOG.info("Creating the main frame...");
MainFrame mainFrame = new MainFrame();
Presenter presenter = mainFrame.getPresenter();
LOG.info("Main frame created.");
// mainFrame.setLocationRelativeTo(null);
if (!exportMode) {
if (splash == null) {
LOG.warn("Splash screen could not be initialized", splashException);
} else {
LOG.info("Hiding splash screen...");
splash.setVisible(false);
splash.dispose();
LOG.info("Done hiding splash screen.");
}
}
if (!exportMode) {
mainFrame.setVisible(true);
}
// assign open file handler for Mac
if (Utils.isMac()) {
LOG.info("Setting up open file handler for Mac...");
SwingUtilities.invokeLater(() -> {
// On macOS this function is called when a new file is opened.
Desktop.getDesktop().setOpenFileHandler(new OpenDIYFilesHandler(presenter));
});
}
if (args.length > 0) {
presenter.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.");
URL resource = Presenter.class.getResource("config.properties");
if (resource != null) {
properties.load(resource.openStream());
PropertyInjector.injectProperties(properties);
}
} catch (Exception e) {
LOG.error("Could not read config.properties file", e);
}
if (!exportMode && ConfigurationManager.getInstance().isFileWithErrors())
mainFrame.showMessage("<html>"
+ "There was an error reading the configuration file and it was replaced by a default configuration.<br>"
+ "The backup file is created and placed in user directory under 'diylc' sub-directory with the current timestamp at the end.<br>"
+ "</html>", "Warning", IView.WARNING_MESSAGE);
if (exportMode) {
String exportFile = args[args.length - 1];
if (exportFile == null || exportFile.startsWith("--")) {
LOG.error("No output file provided");
System.exit(-1);
}
boolean forceMode = Arrays.stream(args).anyMatch(x -> "--force".equalsIgnoreCase(x));
if (new File(exportFile).exists()) {
if (forceMode) {
LOG.info("Replacing existing file.");
} else {
LOG.error("File already exists. Use --force flag to overwrite existing files or change export file name.");
System.exit(-1);
}
}
if (exportFile.toLowerCase().endsWith(".png")) {
try {
ProjectDrawingProvider drawingProvider = new ProjectDrawingProvider(presenter, false, false, false);
DrawingExporter.getInstance().exportPNG(drawingProvider, new File(exportFile));
LOG.info("Done.");
System.exit(0);
} catch (Exception e) {
LOG.error(e.getMessage());
System.exit(-1);
}
}
if (exportFile.toLowerCase().endsWith(".pdf")) {
try {
ProjectDrawingProvider drawingProvider = new ProjectDrawingProvider(presenter, false, false, false);
DrawingExporter.getInstance().exportPDF(drawingProvider, new File(exportFile));
LOG.info("Done.");
System.exit(0);
} catch (Exception e) {
LOG.error(e.getMessage());
System.exit(-1);
}
}
System.err.println("Unsupported output file type. Only PDF and PNG are currently supported");
System.exit(-1);
}
}
private static void initializeConfiguration() {
// initialize
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
XStream xStream = configurationManager.getSerializer();
ProjectFileManager.configure(xStream);
configurationManager.initialize("diylc");
}
}
@@ -0,0 +1,35 @@
package org.diylc;
import java.awt.desktop.OpenFilesEvent;
import java.awt.desktop.OpenFilesHandler;
import java.io.File;
import java.util.List;
import org.apache.log4j.Logger;
import org.diylc.common.IPlugInPort;
public class OpenDIYFilesHandler implements OpenFilesHandler {
private static final Logger LOG = Logger.getLogger(DIYLCStarter.class);
private final IPlugInPort presenter;
public OpenDIYFilesHandler(IPlugInPort presenter) {
super();
this.presenter = presenter;
}
@Override
public void openFiles(OpenFilesEvent e) {
List<File> files = e.getFiles();
if (files != null && files.size() > 0) {
String filePath = files.get(0).getAbsolutePath();
if (presenter.allowFileAction()) {
presenter.loadProjectFromFile(filePath);
}
}
LOG.info("Finished setting up open file handler for Mac.");
}
}
@@ -0,0 +1,6 @@
# Uncomment lines you want to edit and change the part after the "=" sign.
#org.diylc.presenter.InstantiationManager.MAX_RECENT_COMPONENTS=20
#org.diylc.swing.plugins.canvas.CanvasPanel.USE_HARDWARE_ACCELLERATION=true
#org.diylc.swingframework.ruler.Ruler.USE_HARDWARE_ACCELLERATION=true
#org.diylc.swing.gui.editor.PropertyEditorDialog.SHOW_DEFAULT_BOXES=true
#org.diylc.swing.plugins.autosave.AutoSavePlugin.MAX_TOTAL_SIZE_MB=64
@@ -0,0 +1,43 @@
/*
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.flags;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
* Loads image resources as Icons.
*
* @author Branislav Stojkovic
*/
public class FlagLoader {
public static Icon getIcon(String name) {
java.net.URL imgURL = FlagLoader.class.getResource("flag_" + name + ".png");
if (imgURL != null) {
return new ImageIcon(imgURL, name);
} else {
System.err.println("Couldn't find file: " + name);
return null;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 772 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 605 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 696 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 734 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 632 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 697 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 739 B

Some files were not shown because too many files have changed in this diff Show More