diff --git a/diylc/diylc-library/lib/diylc-core.jar b/diylc/diylc-library/lib/diylc-core.jar index 7a02be5b..b935a0b0 100644 Binary files a/diylc/diylc-library/lib/diylc-core.jar and b/diylc/diylc-library/lib/diylc-core.jar differ diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java index 61433e2f..b815fb08 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/HumbuckerPickup.java @@ -42,7 +42,7 @@ public class HumbuckerPickup extends AbstractTransparentComponent { private static Color BODY_COLOR = Color.lightGray; private static Color POINT_COLOR = Color.darkGray; - public static Color PIN_COLOR = Color.decode("#C3E4ED"); + public static Color POLE_COLOR = METAL_COLOR; private static Size WIDTH = new Size(36.5d, SizeUnit.mm); private static Size LENGTH = new Size(68.58d, SizeUnit.mm); private static Size WIDTH_MINI = new Size(29.3d, SizeUnit.mm); @@ -100,7 +100,7 @@ public class HumbuckerPickup extends AbstractTransparentComponent { g2d.draw(body[0]); g2d.draw(body[1]); if (!outlineMode) { - g2d.setColor(PIN_COLOR); + g2d.setColor(POLE_COLOR); g2d.fill(body[3]); g2d.setColor(color.darker()); g2d.draw(body[3]); diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/P90DogEarPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/P90DogEarPickup.java index 9ac491f0..e4b0a84c 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/P90DogEarPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/P90DogEarPickup.java @@ -42,7 +42,7 @@ public class P90DogEarPickup extends AbstractTransparentComponent { private static Color BODY_COLOR = Color.decode("#D8C989");; private static Color POINT_COLOR = Color.darkGray; - public static Color POLE_COLOR = Color.decode("#C3E4ED"); + public static Color POLE_COLOR = METAL_COLOR; private static Size WIDTH = new Size(41d, SizeUnit.mm); private static Size LENGTH = new Size(86.9d, SizeUnit.mm); private static Size TOTAL_LENGTH = new Size(118.7d, SizeUnit.mm); @@ -52,8 +52,8 @@ public class P90DogEarPickup extends AbstractTransparentComponent { private static Size POINT_SIZE = new Size(3d, SizeUnit.mm); private static Size LIP_HOLE_SIZE = new Size(2.5d, SizeUnit.mm); private static Size LIP_HOLE_SPACING = new Size(97d, SizeUnit.mm); - private static Size POLE_SIZE = new Size(3d, SizeUnit.mm); - private static Size POLE_SPACING = new Size(10.1d, SizeUnit.mm); + private static Size POLE_SIZE = new Size(4d, SizeUnit.mm); + private static Size POLE_SPACING = new Size(11.68d, SizeUnit.mm); private String value = ""; private Point controlPoint = new Point(0, 0); diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/P90SoapBarPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/P90SoapBarPickup.java index e2569cca..726df5da 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/P90SoapBarPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/P90SoapBarPickup.java @@ -42,14 +42,14 @@ public class P90SoapBarPickup extends AbstractTransparentComponent { private static Color BODY_COLOR = Color.decode("#D8C989"); private static Color POINT_COLOR = Color.darkGray; - public static Color POLE_COLOR = Color.decode("#C3E4ED"); + public static Color POLE_COLOR = METAL_COLOR; private static Size WIDTH = new Size(35.3d, SizeUnit.mm); private static Size LENGTH = new Size(85.6d, SizeUnit.mm); private static Size EDGE_RADIUS = new Size(8d, SizeUnit.mm); private static Size POINT_MARGIN = new Size(5d, SizeUnit.mm); private static Size POINT_SIZE = new Size(3d, SizeUnit.mm); - private static Size POLE_SIZE = new Size(3d, SizeUnit.mm); - private static Size POLE_SPACING = new Size(10.1d, SizeUnit.mm); + private static Size POLE_SIZE = new Size(4d, SizeUnit.mm); + private static Size POLE_SPACING = new Size(11.68d, SizeUnit.mm); private String value = ""; private Point controlPoint = new Point(0, 0); diff --git a/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java b/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java index 96f20c69..f72724e3 100644 --- a/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java +++ b/diylc/diylc-library/src/org/diylc/components/guitar/SingleCoilPickup.java @@ -41,16 +41,17 @@ public class SingleCoilPickup extends AbstractTransparentComponent { private static final long serialVersionUID = 1L; - private static Color BODY_COLOR = Color.darkGray; + private static Color BODY_COLOR = Color.gray; private static Color POINT_COLOR = Color.lightGray; private static Size WIDTH = new Size(15.5d, SizeUnit.mm); - private static Size LENGTH = new Size(83.82d, SizeUnit.mm); + private static Size LENGTH = new Size(83d, SizeUnit.mm); + private static Size INNER_LENGTH = new Size(70d, SizeUnit.mm); private static Size LIP_WIDTH = new Size(5d, SizeUnit.mm); private static Size LIP_LENGTH = new Size(20d, SizeUnit.mm); private static Size POINT_SIZE = new Size(3d, SizeUnit.mm); private static Size HOLE_SIZE = new Size(2d, SizeUnit.mm); private static Size HOLE_MARGIN = new Size(4d, SizeUnit.mm); - private static Size POLE_SIZE = new Size(3d, SizeUnit.mm); + private static Size POLE_SIZE = new Size(4d, SizeUnit.mm); private static Size POLE_SPACING = new Size(11.68d, SizeUnit.mm); private String value = ""; @@ -74,6 +75,8 @@ public class SingleCoilPickup extends AbstractTransparentComponent { g2d.fill(body[0]); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : POINT_COLOR); g2d.fill(body[1]); + // g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : color); + // g2d.fill(body[3]); g2d.setComposite(oldComposite); } @@ -87,13 +90,18 @@ public class SingleCoilPickup extends AbstractTransparentComponent { } else { finalBorderColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR - : color.brighter(); + : color.darker(); } g2d.setColor(finalBorderColor); g2d.draw(body[0]); + g2d.draw(body[3]); + if (!outlineMode) { + g2d.setColor(METAL_COLOR.darker()); g2d.draw(body[2]); + g2d.setColor(METAL_COLOR); + g2d.fill(body[2]); } Color finalLabelColor; @@ -118,12 +126,13 @@ public class SingleCoilPickup extends AbstractTransparentComponent { @SuppressWarnings("incomplete-switch") public Shape[] getBody() { if (body == null) { - body = new Shape[3]; + body = new Shape[4]; int x = controlPoint.x; int y = controlPoint.y; int width = (int) WIDTH.convertToPixels(); int length = (int) LENGTH.convertToPixels(); + int innerLength = (int) INNER_LENGTH.convertToPixels(); int lipWidth = (int) LIP_WIDTH.convertToPixels(); int lipLength = (int) LIP_LENGTH.convertToPixels(); int pointSize = getClosestOdd(POINT_SIZE.convertToPixels()); @@ -132,9 +141,9 @@ public class SingleCoilPickup extends AbstractTransparentComponent { Area mainArea = new Area(new RoundRectangle2D.Double(x - length / 2, y - lipWidth / 2 - width, length, width, width, width)); - mainArea.add(new Area(new Polygon(new int[] {x - length / 2 + width / 2, x + length / 2 - width / 2, - x + lipLength / 2, x - lipLength / 2}, new int[] {y - lipWidth / 2, y - lipWidth / 2, y + lipWidth / 2, - y + lipWidth / 2}, 4))); + mainArea.add(new Area(new Polygon(new int[] {(int) (x - length / 2 + width * 0.47), + (int) (x + length / 2 - width * 0.47), x + lipLength / 2, x - lipLength / 2}, new int[] {y - lipWidth / 2, + y - lipWidth / 2, y + lipWidth / 2, y + lipWidth / 2}, 4))); // Cutout holes mainArea.subtract(new Area(new Ellipse2D.Double(x - length / 2 + holeMargin - holeSize / 2, y - lipWidth / 2 - width / 2 - holeSize / 2, holeSize, holeSize))); @@ -151,12 +160,15 @@ public class SingleCoilPickup extends AbstractTransparentComponent { Area poleArea = new Area(); for (int i = 0; i < 6; i++) { Ellipse2D pole = - new Ellipse2D.Double(x - length / 2 + poleMargin + i * poleSpacing, y - lipWidth / 2 - width / 2 - poleSize - / 2, poleSize, poleSize); + new Ellipse2D.Double(x - length / 2 + poleMargin + i * poleSpacing - poleSize / 2, y - lipWidth / 2 - width + / 2 - poleSize / 2, poleSize, poleSize); poleArea.add(new Area(pole)); } body[2] = poleArea; + body[3] = + new RoundRectangle2D.Double(x - innerLength / 2, y - lipWidth / 2 - width, innerLength, width, width, width); + // Rotate if needed if (orientation != Orientation.DEFAULT) { double theta = 0; @@ -184,7 +196,7 @@ public class SingleCoilPickup extends AbstractTransparentComponent { @Override public void drawIcon(Graphics2D g2d, int width, int height) { g2d.rotate(Math.PI / 4, width / 2, height / 2); - + int bodyWidth = 8 * width / 32; int bodyLength = 30 * width / 32; g2d.setColor(BODY_COLOR); diff --git a/diylc/diylc-swing/lib/diylc-core.jar b/diylc/diylc-swing/lib/diylc-core.jar index 7a02be5b..b935a0b0 100644 Binary files a/diylc/diylc-swing/lib/diylc-core.jar and b/diylc/diylc-swing/lib/diylc-core.jar differ diff --git a/diylc/diylc-swing/library/main.jar b/diylc/diylc-swing/library/main.jar index d96c670f..1daacec2 100644 Binary files a/diylc/diylc-swing/library/main.jar and b/diylc/diylc-swing/library/main.jar differ diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java index 5d7f5600..3edc57a9 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java @@ -19,6 +19,8 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; import org.diylc.common.ComponentType; import org.diylc.common.IPlugInPort; @@ -33,7 +35,7 @@ import org.diylc.swingframework.openide.DropDownButtonFactory; * * @author Branislav Stojkovic */ -class ComponentButtonFactory { +public class ComponentButtonFactory { public static int MARGIN = 3; @@ -127,6 +129,8 @@ class ComponentButtonFactory { e.consume(); } }); + Border margin = new EmptyBorder(4, 0, 0, 0); + label.setBorder(margin); item.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0)); item.add(label); return item; diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/ComponentTree.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/ComponentTree.java index 6b4565fc..9f02ae42 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/ComponentTree.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/ComponentTree.java @@ -1,5 +1,8 @@ package org.diylc.swing.plugins.tree; +import java.awt.KeyEventDispatcher; +import java.awt.KeyboardFocusManager; +import java.awt.event.KeyEvent; import java.util.EnumSet; import javax.swing.SwingConstants; @@ -49,6 +52,18 @@ public class ComponentTree implements IPlugIn { getTreePanel().setVisible( ConfigurationManager.getInstance().readString(ConfigPlugin.COMPONENT_BROWSER, ConfigPlugin.SEARCHABLE_TREE) .equals(ConfigPlugin.SEARCHABLE_TREE)); + + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { + + @Override + public boolean dispatchKeyEvent(KeyEvent e) { + if (e.getKeyChar() == 'q') { + getTreePanel().getSearchField().requestFocusInWindow(); + return true; + } + return false; + } + }); } public TreePanel getTreePanel() { diff --git a/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java b/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java index 9d067e23..81bb5877 100644 --- a/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java +++ b/diylc/diylc-swing/src/org/diylc/swing/plugins/tree/TreePanel.java @@ -8,20 +8,32 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.event.ActionEvent; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import javax.swing.AbstractAction; import javax.swing.Icon; +import javax.swing.JMenuItem; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import javax.swing.JScrollPane; +import javax.swing.JSeparator; import javax.swing.JTextField; import javax.swing.JTree; +import javax.swing.SwingUtilities; +import javax.swing.ToolTipManager; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; @@ -29,20 +41,33 @@ import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; +import org.apache.log4j.Logger; +import org.diylc.appframework.miscutils.ConfigurationManager; +import org.diylc.appframework.miscutils.IConfigListener; import org.diylc.common.ComponentType; import org.diylc.common.IPlugInPort; +import org.diylc.core.IDIYComponent; +import org.diylc.core.Template; import org.diylc.images.IconLoader; +import org.diylc.presenter.ComponentProcessor; +import org.diylc.swing.plugins.toolbox.ComponentButtonFactory; public class TreePanel extends JPanel { private static final long serialVersionUID = 1L; + private static final Logger LOG = Logger.getLogger(TreePanel.class); + private DefaultTreeModel treeModel; private JTree tree; private JTextField searchField; + private DefaultMutableTreeNode recentNode; + private List recentComponents; private IPlugInPort plugInPort; + private JPopupMenu popup; + public TreePanel(IPlugInPort plugInPort) { this.plugInPort = plugInPort; setLayout(new GridBagLayout()); @@ -65,11 +90,63 @@ public class TreePanel extends JPanel { add(scroll, gbc); setPreferredSize(new Dimension(240, 200)); + + ConfigurationManager.getInstance().addConfigListener(IPlugInPort.RECENT_COMPONENTS_KEY, new IConfigListener() { + + @SuppressWarnings("unchecked") + @Override + public void valueChanged(String key, Object value) { + List newComponents = (List) value; + if (!new HashSet(newComponents).equals(new HashSet(TreePanel.this.recentComponents))) { + LOG.info("Detected change"); + refreshRecentComponentsToolbar(newComponents); + } else + LOG.info("Detected no change"); + TreePanel.this.recentComponents = new ArrayList(newComponents); + } + }); + + getTree().expandRow(0); + } + + public DefaultMutableTreeNode getRecentNode() { + if (this.recentNode == null) { + this.recentNode = new DefaultMutableTreeNode(new Payload("(Recently Used)"), true); + @SuppressWarnings("unchecked") + List recent = + (List) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null); + if (recent != null) { + this.recentComponents = new ArrayList(recent); + refreshRecentComponentsToolbar(recent); + } else { + this.recentComponents = new ArrayList(); + } + } + return this.recentNode; + } + + @SuppressWarnings("unchecked") + private void refreshRecentComponentsToolbar(List recentComponentClassList) { + getRecentNode().removeAllChildren(); + for (String componentClassName : recentComponentClassList) { + ComponentType componentType; + try { + componentType = + ComponentProcessor.getInstance().extractComponentTypeFrom( + (Class>) Class.forName(componentClassName)); + final DefaultMutableTreeNode componentNode = new DefaultMutableTreeNode(new Payload(componentType), false); + getRecentNode().add(componentNode); + } catch (ClassNotFoundException e) { + LOG.error("Could not create recent component button for " + componentClassName, e); + } + } + getTreeModel().nodeStructureChanged(getRecentNode()); } public DefaultTreeModel getTreeModel() { if (treeModel == null) { final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Components", true); + rootNode.add(getRecentNode()); Map> componentTypes = plugInPort.getComponentTypes(); List categories = new ArrayList(componentTypes.keySet()); Collections.sort(categories); @@ -88,12 +165,11 @@ public class TreePanel extends JPanel { public JTree getTree() { if (tree == null) { - - tree = new JTree(getTreeModel()); tree.setRootVisible(false); tree.setCellRenderer(new ComponentCellRenderer()); tree.setRowHeight(0); + ToolTipManager.sharedInstance().registerComponent(tree); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override @@ -109,10 +185,62 @@ public class TreePanel extends JPanel { } } }); + + tree.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + + if (SwingUtilities.isRightMouseButton(e)) { + int row = tree.getClosestRowForLocation(e.getX(), e.getY()); + tree.setSelectionRow(row); + getPopup().show(e.getComponent(), e.getX(), e.getY()); + } + } + }); } return tree; } + public JPopupMenu getPopup() { + if (popup == null) { + popup = new JPopupMenu(); + popup.add("Loading..."); + popup.addPopupMenuListener(new PopupMenuListener() { + + @Override + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + popup.removeAll(); + + popup.add(new SelectAllAction(plugInPort)); + ComponentType componentType = plugInPort.getNewComponentTypeSlot(); + if (componentType != null) { + popup.add(new JSeparator()); + + List