From c76f0217719251692f9b3c4046836ddd34886593 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 3 Feb 2015 18:04:03 -0600 Subject: [PATCH] auto-sync --- java_console/ui/src/com/irnems/Launcher.java | 7 +- .../ui/src/com/rusefi/HorizontalLine.java | 27 + .../ui/src/com/rusefi/SimulatorHelper.java | 2 +- ...PortLookupFrame.java => StartupFrame.java} | 40 +- .../src/org/putgemin/VerticalFlowLayout.java | 589 ++++++++++++++++++ 5 files changed, 643 insertions(+), 22 deletions(-) create mode 100644 java_console/ui/src/com/rusefi/HorizontalLine.java rename java_console/ui/src/com/rusefi/{PortLookupFrame.java => StartupFrame.java} (73%) create mode 100644 java_console/ui/src/org/putgemin/VerticalFlowLayout.java diff --git a/java_console/ui/src/com/irnems/Launcher.java b/java_console/ui/src/com/irnems/Launcher.java index 7d0c6b007a..e7ca7b9419 100644 --- a/java_console/ui/src/com/irnems/Launcher.java +++ b/java_console/ui/src/com/irnems/Launcher.java @@ -6,7 +6,6 @@ import com.rusefi.*; import com.rusefi.io.LinkManager; import com.rusefi.ui.*; import com.rusefi.ui.storage.Node; -import com.rusefi.ui.storage.PersistentConfiguration; import jssc.SerialPortList; import javax.swing.*; @@ -20,7 +19,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * 12/25/12 * (c) Andrey Belomutskiy 2013-2015 * - * @see PortLookupFrame + * @see StartupFrame * @see WavePanel */ public class Launcher extends FrameHelper { @@ -68,7 +67,7 @@ public class Launcher extends FrameHelper { tabbedPane.setSelectedIndex(selectedIndex); } - PortLookupFrame.setAppIcon(frame); + StartupFrame.setAppIcon(frame); showFrame(tabbedPane); } @@ -126,7 +125,7 @@ public class Launcher extends FrameHelper { } else { for (String p : SerialPortList.getPortNames()) MessagesCentral.getInstance().postMessage(Launcher.class, "Available port: " + p); - new PortLookupFrame().chooseSerialPort(); + new StartupFrame().chooseSerialPort(); } } catch (Throwable e) { diff --git a/java_console/ui/src/com/rusefi/HorizontalLine.java b/java_console/ui/src/com/rusefi/HorizontalLine.java new file mode 100644 index 0000000000..dd170ea01f --- /dev/null +++ b/java_console/ui/src/com/rusefi/HorizontalLine.java @@ -0,0 +1,27 @@ +package com.rusefi; + +import javax.swing.*; +import java.awt.*; + +public class HorizontalLine extends JPanel { + @Override + public void paint(Graphics g) { + //Get the current size of this component + Dimension d = this.getSize(); + + //draw in black + g.setColor(Color.BLACK); + //draw a centered horizontal line + g.drawLine(0, d.height / 2, d.width, d.height / 2); + } + + @Override + public Dimension getMinimumSize() { + return new Dimension(150, 10); + } + + @Override + public Dimension getPreferredSize() { + return getMinimumSize(); + } +} diff --git a/java_console/ui/src/com/rusefi/SimulatorHelper.java b/java_console/ui/src/com/rusefi/SimulatorHelper.java index 07dc3d9609..3b3b646e04 100644 --- a/java_console/ui/src/com/rusefi/SimulatorHelper.java +++ b/java_console/ui/src/com/rusefi/SimulatorHelper.java @@ -43,7 +43,7 @@ public class SimulatorHelper { } - public static JComponent createSimulatorComponent(final PortLookupFrame portSelector) { + public static JComponent createSimulatorComponent(final StartupFrame portSelector) { if (!SimulatorHelper.isBinaryHere()) return new JLabel(SimulatorHelper.BINARY + " not found"); diff --git a/java_console/ui/src/com/rusefi/PortLookupFrame.java b/java_console/ui/src/com/rusefi/StartupFrame.java similarity index 73% rename from java_console/ui/src/com/rusefi/PortLookupFrame.java rename to java_console/ui/src/com/rusefi/StartupFrame.java index a1d623d490..718b3afd04 100644 --- a/java_console/ui/src/com/rusefi/PortLookupFrame.java +++ b/java_console/ui/src/com/rusefi/StartupFrame.java @@ -6,6 +6,7 @@ import com.rusefi.io.tcp.TcpConnector; import com.rusefi.ui.UiUtils; import com.rusefi.ui.widgets.URLLabel; import jssc.SerialPortList; +import org.putgemin.VerticalFlowLayout; import javax.swing.*; import java.awt.*; @@ -25,7 +26,7 @@ import java.util.List; *

* 2/14/14 */ -public class PortLookupFrame { +public class StartupFrame { // todo: figure out a better way to work with absolute path public static final String APPICON_PNG = "../../appicon.png"; private static final String LINK_TEXT = "rusEfi (c) 2012-2015"; @@ -34,7 +35,7 @@ public class PortLookupFrame { private final JFrame frame; private boolean isProceeding; - public PortLookupFrame() { + public StartupFrame() { frame = new JFrame(Launcher.CONSOLE_VERSION + ": Serial port selection"); frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @@ -58,15 +59,19 @@ public class PortLookupFrame { ports.addAll(Arrays.asList(SerialPortList.getPortNames())); ports.addAll(TcpConnector.getAvailablePorts()); - JPanel content = new JPanel(new BorderLayout()); + JPanel startupOptions = new JPanel(new VerticalFlowLayout()); + startupOptions.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10), + BorderFactory.createLineBorder(Color.darkGray))); - final JPanel upperPanel = new JPanel(new FlowLayout()); - - if (!ports.isEmpty()) - addPortSelection(ports, frame, upperPanel); + if (!ports.isEmpty()) { + final JPanel connectPanel = new JPanel(new FlowLayout()); + addPortSelection(ports, connectPanel); + startupOptions.add(connectPanel); + startupOptions.add(new HorizontalLine()); + } final JButton buttonLogViewer = new JButton(); - buttonLogViewer.setText("Use " + LinkManager.LOG_VIEWER); + buttonLogViewer.setText("Start " + LinkManager.LOG_VIEWER); buttonLogViewer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -75,18 +80,19 @@ public class PortLookupFrame { } }); - upperPanel.add(buttonLogViewer); + startupOptions.add(buttonLogViewer); + startupOptions.add(new HorizontalLine()); JPanel centerPanel = new JPanel(new FlowLayout()); centerPanel.add(SimulatorHelper.createSimulatorComponent(this)); + startupOptions.add(centerPanel); + startupOptions.add(new HorizontalLine()); + startupOptions.add(new URLLabel(LINK_TEXT, URI)); - JPanel lowerPanel = new JPanel(new FlowLayout()); - lowerPanel.add(new URLLabel(LINK_TEXT, URI)); - content.add(upperPanel, BorderLayout.NORTH); - content.add(centerPanel, BorderLayout.CENTER); - content.add(lowerPanel, BorderLayout.SOUTH); - + JPanel content = new JPanel(new BorderLayout()); + content.add(startupOptions, BorderLayout.WEST); + content.add(new JLabel("Logo"), BorderLayout.EAST); frame.add(content); frame.pack(); @@ -99,7 +105,7 @@ public class PortLookupFrame { frame.dispose(); } - private void addPortSelection(List ports, final JFrame frame, JPanel panel) { + private void addPortSelection(List ports, JPanel panel) { final JComboBox comboPorts = new JComboBox<>(); for (final String port : ports) comboPorts.addItem(port); @@ -117,7 +123,7 @@ public class PortLookupFrame { } public static ImageIcon loadIcon(String strPath) { - URL imgURL = PortLookupFrame.class.getResource(strPath); + URL imgURL = StartupFrame.class.getResource(strPath); if (imgURL != null) return new ImageIcon(imgURL); else diff --git a/java_console/ui/src/org/putgemin/VerticalFlowLayout.java b/java_console/ui/src/org/putgemin/VerticalFlowLayout.java new file mode 100644 index 0000000000..16f31d61cd --- /dev/null +++ b/java_console/ui/src/org/putgemin/VerticalFlowLayout.java @@ -0,0 +1,589 @@ +package org.putgemin; +/* + * @(#)VerticalFlowLayout.java 1.52 03/12/19 + * + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.io.ObjectInputStream; +import java.io.IOException; + +/** + * A flow layout arranges components in a directional flow, much + * like lines of text in a paragraph. The flow direction is + * determined by the container's componentOrientation + * property and may be one of two values: + *

+ * VerticalFlow layouts are typically used + * to arrange buttons in a panel. It arranges buttons + * horizontally until no more buttons fit on the same line. + * The line alignment is determined by the align + * property. The possible values are: + * + *

+ * For example, the following picture shows an applet using the flow + * layout manager (its default layout manager) to position three buttons: + *

+ * Graphic of Layout for Three Buttons + *

+ * Here is the code for this applet: + *

+ *


+ * import java.awt.*;
+ * import java.applet.Applet;
+ * 

+ * public class myButtons extends Applet { + * Button button1, button2, button3; + * public void init() { + * button1 = new Button("Ok"); + * button2 = new Button("Open"); + * button3 = new Button("Close"); + * add(button1); + * add(button2); + * add(button3); + * } + * } + *


+ *

+ * A flow layout lets each component assume its natural (preferred) size. + * + * @author Arthur van Hoff + * @author Sami Shaio + * @version 1.52, 12/19/03 + * @see java.awt.ComponentOrientation + * @since JDK1.0 + */ +public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { + + private boolean maximizeOtherDimension = false; + + public void setMaximizeOtherDimension(boolean max) { + maximizeOtherDimension = max; + } + + public boolean isMaximizeOtherDimension() { + return maximizeOtherDimension; + } + + /** + * This value indicates that each row of components + * should be left-justified. + */ + public static final int TOP = 0; + + /** + * This value indicates that each row of components + * should be centered. + */ + public static final int CENTER = 1; + + /** + * This value indicates that each row of components + * should be right-justified. + */ + public static final int BOTTOM = 2; + + /** + * This value indicates that each row of components + * should be justified to the leading edge of the container's + * orientation, for example, to the left in left-to-right orientations. + * + * @see java.awt.Component#getComponentOrientation + * @see java.awt.ComponentOrientation + * @since 1.2 + * Package-private pending API change approval + */ + public static final int LEADING = 3; + + /** + * This value indicates that each row of components + * should be justified to the trailing edge of the container's + * orientation, for example, to the right in left-to-right orientations. + * + * @see java.awt.Component#getComponentOrientation + * @see java.awt.ComponentOrientation + * @since 1.2 + * Package-private pending API change approval + */ + public static final int TRAILING = 4; + + /** + * align is the property that determines + * how each row distributes empty space. + * It can be one of the following values: + *

+ * + * @serial + * @see #getAlignment + * @see #setAlignment + */ + int align; // This is for 1.1 serialization compatibility + + /** + * newAlign is the property that determines + * how each row distributes empty space for the Java 2 platform, + * v1.2 and greater. + * It can be one of the following three values: + * + * + * @serial + * @see #getAlignment + * @see #setAlignment + * @since 1.2 + */ + int newAlign; // This is the one we actually use + + /** + * The flow layout manager allows a seperation of + * components with gaps. The horizontal gap will + * specify the space between components and between + * the components and the borders of the + * Container. + * + * @serial + * @see #getHgap() + * @see #setHgap(int) + */ + int hgap; + + /** + * The flow layout manager allows a seperation of + * components with gaps. The vertical gap will + * specify the space between rows and between the + * the rows and the borders of the Container. + * + * @serial + * @see #getHgap() + * @see #setHgap(int) + */ + int vgap; + + /* + * JDK 1.1 serialVersionUID + */ + private static final long serialVersionUID = -7262534875583282631L; + + /** + * Constructs a new VerticalFlowLayout with a centered alignment and a + * default 5-unit horizontal and vertical gap. + */ + public VerticalFlowLayout() { + this(CENTER, 5, 5); + } + + /** + * Constructs a new VerticalFlowLayout with the specified + * alignment and a default 5-unit horizontal and vertical gap. + * The value of the alignment argument must be one of + * VerticalFlowLayout.TOP, VerticalFlowLayout.BOTTOM, + * VerticalFlowLayout.CENTER, VerticalFlowLayout.LEADING, + * or VerticalFlowLayout.TRAILING. + * + * @param align the alignment value + */ + public VerticalFlowLayout(int align) { + this(align, 5, 5); + } + + /** + * Creates a new flow layout manager with the indicated alignment + * and the indicated horizontal and vertical gaps. + *

+ * The value of the alignment argument must be one of + * VerticalFlowLayout.TOP, VerticalFlowLayout.BOTTOM, + * VerticalFlowLayout.CENTER, VerticalFlowLayout.LEADING, + * or VerticalFlowLayout.TRAILING. + * + * @param align the alignment value + * @param hgap the horizontal gap between components + * and between the components and the + * borders of the Container + * @param vgap the vertical gap between components + * and between the components and the + * borders of the Container + */ + public VerticalFlowLayout(int align, int hgap, int vgap) { + this.hgap = hgap; + this.vgap = vgap; + setAlignment(align); + } + + /** + * Gets the alignment for this layout. + * Possible values are VerticalFlowLayout.TOP, + * VerticalFlowLayout.BOTTOM, VerticalFlowLayout.CENTER, + * VerticalFlowLayout.LEADING, + * or VerticalFlowLayout.TRAILING. + * + * @return the alignment value for this layout + * @since JDK1.1 + */ + public int getAlignment() { + return newAlign; + } + + /** + * Sets the alignment for this layout. + * Possible values are + *

+ * + * @param align one of the alignment values shown above + * @see #getAlignment() + * @since JDK1.1 + */ + public void setAlignment(int align) { + this.newAlign = align; + + // this.align is used only for serialization compatibility, + // so set it to a value compatible with the 1.1 version + // of the class + + switch (align) { + case LEADING: + this.align = TOP; + break; + case TRAILING: + this.align = BOTTOM; + break; + default: + this.align = align; + break; + } + } + + /** + * Gets the horizontal gap between components + * and between the components and the borders + * of the Container + * + * @return the horizontal gap between components + * and between the components and the borders + * of the Container + */ + public int getHgap() { + return hgap; + } + + /** + * Sets the horizontal gap between components and + * between the components and the borders of the + * Container. + * + * @param hgap the horizontal gap between components + * and between the components and the borders + * of the Container + */ + public void setHgap(int hgap) { + this.hgap = hgap; + } + + /** + * Gets the vertical gap between components and + * between the components and the borders of the + * Container. + * + * @return the vertical gap between components + * and between the components and the borders + * of the Container + */ + public int getVgap() { + return vgap; + } + + /** + * Sets the vertical gap between components and between + * the components and the borders of the Container. + * + * @param vgap the vertical gap between components + * and between the components and the borders + * of the Container + */ + public void setVgap(int vgap) { + this.vgap = vgap; + } + + /** + * Adds the specified component to the layout. + * Not used by this class. + * + * @param name the name of the component + * @param comp the component to be added + */ + public void addLayoutComponent(String name, Component comp) { + } + + /** + * Removes the specified component from the layout. + * Not used by this class. + * + * @param comp the component to remove + * @see java.awt.Container#removeAll + */ + public void removeLayoutComponent(Component comp) { + } + + /** + * Returns the preferred dimensions for this layout given the + * visible components in the specified target container. + * + * @param target the container that needs to be laid out + * @return the preferred dimensions to lay out the + * subcomponents of the specified container + * @see Container + * @see #minimumLayoutSize + * @see java.awt.Container#getPreferredSize + */ + public Dimension preferredLayoutSize(Container target) { + synchronized (target.getTreeLock()) { + Dimension dim = new Dimension(0, 0); + int nmembers = target.getComponentCount(); + boolean firstVisibleComponent = true; + + for (int i = 0; i < nmembers; i++) { + Component m = target.getComponent(i); + if (m.isVisible()) { + Dimension d = m.getPreferredSize(); + dim.width = Math.max(dim.width, d.width); + if (firstVisibleComponent) { + firstVisibleComponent = false; + } else { + dim.height += vgap; + } + dim.height += d.height; + } + } + + Insets insets = target.getInsets(); + dim.width += insets.left + insets.right + hgap * 2; + dim.height += insets.top + insets.bottom + vgap * 2; + return dim; + } + } + + /** + * Returns the minimum dimensions needed to layout the visible + * components contained in the specified target container. + * + * @param target the container that needs to be laid out + * @return the minimum dimensions to lay out the + * subcomponents of the specified container + * @see #preferredLayoutSize + * @see java.awt.Container + * @see java.awt.Container#doLayout + */ + public Dimension minimumLayoutSize(Container target) { + synchronized (target.getTreeLock()) { + Dimension dim = new Dimension(0, 0); + int nmembers = target.getComponentCount(); + + for (int i = 0; i < nmembers; i++) { + Component m = target.getComponent(i); + if (m.isVisible()) { + Dimension d = m.getMinimumSize(); + dim.width = Math.max(dim.width, d.width); + if (i > 0) { + dim.height += vgap; + } + dim.height += d.height; + } + } + Insets insets = target.getInsets(); + dim.width += insets.left + insets.right + hgap * 2; + dim.height += insets.top + insets.bottom + vgap * 2; + return dim; + } + } + + /** + * Centers the elements in the specified row, if there is any slack. + * + * @param target the component which needs to be moved + * @param x the x coordinate + * @param y the y coordinate + * @param width the width dimensions + * @param height the height dimensions + * @param colStart the beginning of the row + * @param colEnd the the ending of the row + */ + private void moveComponents(Container target, int x, int y, int width, int height, + int colStart, int colEnd, boolean ltr) { + synchronized (target.getTreeLock()) { + switch (newAlign) { + case TOP: + y += ltr ? 0 : height; + break; + case CENTER: + y += height / 2; + break; + case BOTTOM: + y += ltr ? height : 0; + break; + case LEADING: + break; + case TRAILING: + y += height; + break; + } + for (int i = colStart; i < colEnd; i++) { + Component m = target.getComponent(i); + if (m.isVisible()) { + if (ltr) { + m.setLocation(x + (width - m.getWidth()) / 2, y); + } else { + m.setLocation(x + (width - m.getWidth()) / 2, target.getHeight() - y - m.getHeight()); + } + y += m.getHeight() + vgap; + } + } + } + } + + /** + * Lays out the container. This method lets each + * visible component take + * its preferred size by reshaping the components in the + * target container in order to satisfy the alignment of + * this VerticalFlowLayout object. + * + * @param target the specified component being laid out + * @see Container + * @see java.awt.Container#doLayout + */ + public void layoutContainer(Container target) { + synchronized (target.getTreeLock()) { + Insets insets = target.getInsets(); + int maxwidth = target.getWidth() - (insets.left + insets.right + hgap * 2); + int maxheight = target.getHeight() - (insets.top + insets.bottom + vgap * 2); + int nmembers = target.getComponentCount(); + int x = insets.left + hgap, y = 0; + int colw = 0, start = 0; + + boolean ltr = target.getComponentOrientation().isLeftToRight(); + + for (int i = 0; i < nmembers; i++) { + Component m = target.getComponent(i); + if (m.isVisible()) { + Dimension d = m.getPreferredSize(); + if (maximizeOtherDimension) { + d.width = maxwidth; + } + m.setSize(d.width, d.height); + + if ((y == 0) || ((y + d.height) <= maxheight)) { + if (y > 0) { + y += vgap; + } + y += d.height; + colw = Math.max(colw, d.width); + } else { + moveComponents(target, insets.left + hgap, y, maxheight - x, colw, start, i, ltr); + moveComponents(target, x, insets.top + vgap, colw, maxheight - y, start, i, ltr); + y = d.height; + x += hgap + colw; + colw = d.width; + start = i; + } + } + } + moveComponents(target, x, insets.top + vgap, colw, maxheight - y, start, nmembers, ltr); + } + } + + // + // the internal serial version which says which version was written + // - 0 (default) for versions before the Java 2 platform, v1.2 + // - 1 for version >= Java 2 platform v1.2, which includes "newAlign" field + // + private static final int currentSerialVersion = 1; + /** + * This represent the currentSerialVersion + * which is bein used. It will be one of two values : + * 0 versions before Java 2 platform v1.2.. + * 1 versions after Java 2 platform v1.2.. + * + * @serial + * @since 1.2 + */ + private int serialVersionOnStream = currentSerialVersion; + + /** + * Reads this object out of a serialization stream, handling + * objects written by older versions of the class that didn't contain all + * of the fields we use now.. + */ + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException { + stream.defaultReadObject(); + + if (serialVersionOnStream < 1) { + // "newAlign" field wasn't present, so use the old "align" field. + setAlignment(this.align); + } + serialVersionOnStream = currentSerialVersion; + } + + /** + * Returns a string representation of this VerticalFlowLayout + * object and its values. + * + * @return a string representation of this layout + */ + public String toString() { + String str = ""; + switch (align) { + case TOP: + str = ",align=top"; + break; + case CENTER: + str = ",align=center"; + break; + case BOTTOM: + str = ",align=bottom"; + break; + case LEADING: + str = ",align=leading"; + break; + case TRAILING: + str = ",align=trailing"; + break; + } + return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]"; + } + + +} \ No newline at end of file