mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added transparency
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
<string>defaults</string>
|
||||
<map/>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>lastPath</string>
|
||||
<string>C:\Documents and Settings\Branislav Stojkovic\Desktop</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>metric</string>
|
||||
<boolean>true</boolean>
|
||||
|
||||
Binary file not shown.
+10
-39
@@ -1,7 +1,9 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
@@ -9,7 +11,6 @@ import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.measures.Size;
|
||||
@@ -23,7 +24,7 @@ import org.diylc.utils.Constants;
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T> {
|
||||
public abstract class AbstractLeadedDIYComponent<T> extends AbstractTransparentComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -35,7 +36,6 @@ public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T>
|
||||
protected Size height;
|
||||
protected Point[] points = new Point[] { new Point((int) (-Constants.GRID * 5), 0),
|
||||
new Point((int) (Constants.GRID * 5), 0) };
|
||||
protected String name = "New Component";
|
||||
|
||||
protected AbstractLeadedDIYComponent() {
|
||||
super();
|
||||
@@ -83,7 +83,7 @@ public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T>
|
||||
protected Size getLeadThickness() {
|
||||
return new Size(0.5d, SizeUnit.mm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return default lead color. Override this method to change it.
|
||||
*/
|
||||
@@ -131,8 +131,14 @@ public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T>
|
||||
g2d.rotate(theta, shapeRect.width / 2, shapeRect.height / 2);
|
||||
// Draw body.
|
||||
if (componentState != ComponentState.DRAGGING) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
1f * alpha / MAX_ALPHA));
|
||||
}
|
||||
g2d.setColor(getBodyColor());
|
||||
g2d.fill(shape);
|
||||
g2d.setComposite(oldComposite);
|
||||
}
|
||||
g2d.setStroke(new BasicStroke(1));
|
||||
g2d.setColor(getBorderColor());
|
||||
@@ -148,15 +154,6 @@ public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T>
|
||||
(int) (shapeRect.height - textRect.getHeight()) / 2 + fontMetrics.getAscent());
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@EditableProperty(defaultable = true)
|
||||
public Size getWidth() {
|
||||
return width;
|
||||
@@ -174,30 +171,4 @@ public abstract class AbstractLeadedDIYComponent<T> implements IDIYComponent<T>
|
||||
public void setHeight(Size height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractLeadedDIYComponent other = (AbstractLeadedDIYComponent) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package org.diylc.components;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
public abstract class AbstractTransparentComponent<T> implements IDIYComponent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static byte MAX_ALPHA = 127;
|
||||
|
||||
protected String name = "New Component";
|
||||
protected byte alpha = MAX_ALPHA;
|
||||
|
||||
@EditableProperty(defaultable = false)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@EditableProperty
|
||||
public Byte getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(Byte alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -31,7 +31,6 @@ import org.diylc.plugins.statusbar.StatusBar;
|
||||
import org.diylc.plugins.toolbox.ToolBox;
|
||||
import org.diylc.presenter.Presenter;
|
||||
|
||||
|
||||
public class MainFrame extends JFrame implements IView {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -64,7 +63,7 @@ public class MainFrame extends JFrame implements IView {
|
||||
presenter.installPlugin(new ToolBox());
|
||||
presenter.installPlugin(new FileManager());
|
||||
presenter.installPlugin(new ClipboardManager());
|
||||
// presenter.installPlugin(new OnlineManager());
|
||||
// presenter.installPlugin(new OnlineManager());
|
||||
presenter.installPlugin(new HelpManager());
|
||||
|
||||
presenter.installPlugin(new StatusBar());
|
||||
@@ -97,7 +96,7 @@ public class MainFrame extends JFrame implements IView {
|
||||
super.setVisible(b);
|
||||
// TODO: hack to prevent painting issues in the scroll bar rulers. Find
|
||||
// a better fix if possible.
|
||||
Timer timer = new Timer(200, new ActionListener() {
|
||||
Timer timer = new Timer(500, new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package org.diylc.gui.editor;
|
||||
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
public class ByteEditor extends JSlider {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ByteEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
setMinimum(0);
|
||||
setMaximum(127);
|
||||
setValue((Byte) property.getValue());
|
||||
addChangeListener(new ChangeListener() {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
property.setValue(new Integer(getValue()).byteValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+5
@@ -25,6 +25,11 @@ public class FieldEditorFactory {
|
||||
EnumEditor editor = new EnumEditor(property);
|
||||
return editor;
|
||||
}
|
||||
if (Byte.class.isAssignableFrom(property.getType())
|
||||
|| byte.class.isAssignableFrom(property.getType())) {
|
||||
ByteEditor byteEditor = new ByteEditor(property);
|
||||
return byteEditor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+72
-8
@@ -1,6 +1,13 @@
|
||||
package org.diylc.plugins.toolbox;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -8,19 +15,25 @@ import java.util.Map;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.presenter.ComparatorFactory;
|
||||
import org.diylc.presenter.Presenter;
|
||||
|
||||
/**
|
||||
* Tabbed pane that shows all available components categorized into
|
||||
* tabs.
|
||||
* Tabbed pane that shows all available components categorized into tabs.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
class ComponentTabbedPane extends JTabbedPane {
|
||||
|
||||
public static int SCROLL_STEP = Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 2;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final IPlugInPort plugInPort;
|
||||
|
||||
@@ -31,17 +44,68 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
List<String> categories = new ArrayList<String>(componentTypes.keySet());
|
||||
Collections.sort(categories);
|
||||
for (String category : categories) {
|
||||
addTab(category, createComponentPanel(componentTypes.get(category)));
|
||||
JPanel panel = createTab((componentTypes.get(category)));
|
||||
addTab(category, panel);
|
||||
}
|
||||
setPreferredSize(new Dimension(-1, Presenter.ICON_SIZE + ComponentButton.MARGIN * 2 + 38));
|
||||
}
|
||||
|
||||
private Container createComponentPanel(List<ComponentType> componentTypes) {
|
||||
Container componentPanel = new Container();
|
||||
componentPanel.setLayout(new BoxLayout(componentPanel, BoxLayout.X_AXIS));
|
||||
private JPanel createTab(List<ComponentType> componentTypes) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
final JScrollPane scrollPane = createComponentScrollBar(componentTypes);
|
||||
panel.setOpaque(false);
|
||||
JButton leftButton = new JButton("<");
|
||||
leftButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Rectangle rect = scrollPane.getVisibleRect();
|
||||
if (rect.x > SCROLL_STEP) {
|
||||
rect.translate(-SCROLL_STEP, 0);
|
||||
} else {
|
||||
rect.translate(-rect.x, 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
leftButton.setMargin(new Insets(0, 2, 0, 2));
|
||||
JButton rightButton = new JButton(">");
|
||||
rightButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Rectangle rect = scrollPane.getVisibleRect();
|
||||
if (rect.x + rect.width < scrollPane.getViewport().getSize().width - SCROLL_STEP) {
|
||||
rect.translate(SCROLL_STEP, 0);
|
||||
} else {
|
||||
rect.translate(scrollPane.getViewport().getSize().width - rect.x - rect.width,
|
||||
0);
|
||||
}
|
||||
}
|
||||
});
|
||||
rightButton.setMargin(new Insets(0, 2, 0, 2));
|
||||
panel.add(leftButton, BorderLayout.WEST);
|
||||
panel.add(scrollPane);
|
||||
panel.add(rightButton, BorderLayout.EAST);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private JScrollPane createComponentScrollBar(List<ComponentType> componentTypes) {
|
||||
JScrollPane scrollPane = new JScrollPane(createComponentPanel(componentTypes));
|
||||
scrollPane.setOpaque(false);
|
||||
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
|
||||
return scrollPane;
|
||||
}
|
||||
|
||||
private Component createComponentPanel(List<ComponentType> componentTypes) {
|
||||
Container toolbar = new Container();
|
||||
Collections.sort(componentTypes, ComparatorFactory.getInstance()
|
||||
.getComponentTypeComparator());
|
||||
toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS));
|
||||
for (ComponentType componentType : componentTypes) {
|
||||
JButton button = new ComponentButton(plugInPort, componentType);
|
||||
componentPanel.add(button);
|
||||
toolbar.add(button);
|
||||
}
|
||||
return componentPanel;
|
||||
return toolbar;
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -3,6 +3,7 @@ package org.diylc.presenter;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class ComparatorFactory {
|
||||
@@ -10,6 +11,7 @@ public class ComparatorFactory {
|
||||
private static ComparatorFactory instance;
|
||||
|
||||
private Comparator<IDIYComponent<?>> componentNameComparator;
|
||||
private Comparator<ComponentType> componentTypeComparator;
|
||||
|
||||
public static ComparatorFactory getInstance() {
|
||||
if (instance == null) {
|
||||
@@ -36,6 +38,19 @@ public class ComparatorFactory {
|
||||
return componentNameComparator;
|
||||
}
|
||||
|
||||
public Comparator<ComponentType> getComponentTypeComparator() {
|
||||
if (componentTypeComparator == null) {
|
||||
componentTypeComparator = new Comparator<ComponentType>() {
|
||||
|
||||
@Override
|
||||
public int compare(ComponentType o1, ComponentType o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
return componentTypeComparator;
|
||||
}
|
||||
|
||||
public Comparator<IDIYComponent<?>> getComponentZOrderComparator(
|
||||
final List<IDIYComponent<?>> components) {
|
||||
Comparator<IDIYComponent<?>> componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
Reference in New Issue
Block a user