mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
code format
This commit is contained in:
Binary file not shown.
+3
-6
@@ -10,13 +10,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.diyfever.diylc.model.IComponentInstance;
|
import com.diyfever.diylc.model.IComponentInstance;
|
||||||
|
|
||||||
public class ComponentSelection extends ArrayList<IComponentInstance> implements
|
public class ComponentSelection extends ArrayList<IComponentInstance> implements Transferable {
|
||||||
Transferable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final DataFlavor listFlavor = new DataFlavor(List.class,
|
public static final DataFlavor listFlavor = new DataFlavor(List.class, "Java List");
|
||||||
"Java List");
|
|
||||||
|
|
||||||
public ComponentSelection() {
|
public ComponentSelection() {
|
||||||
super();
|
super();
|
||||||
@@ -27,8 +25,7 @@ public class ComponentSelection extends ArrayList<IComponentInstance> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor)
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||||
throws UnsupportedFlavorException, IOException {
|
|
||||||
if (flavor.equals(listFlavor)) {
|
if (flavor.equals(listFlavor)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-8
@@ -17,8 +17,8 @@ public class ControlPointWrapper {
|
|||||||
private boolean sticky;
|
private boolean sticky;
|
||||||
private VisibilityPolicy visibilityPolicy;
|
private VisibilityPolicy visibilityPolicy;
|
||||||
|
|
||||||
public ControlPointWrapper(String name, Method getter, Method setter,
|
public ControlPointWrapper(String name, Method getter, Method setter, boolean editable,
|
||||||
boolean editable, boolean sticky, VisibilityPolicy visibilityPolicy) {
|
boolean sticky, VisibilityPolicy visibilityPolicy) {
|
||||||
super();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.getter = getter;
|
this.getter = getter;
|
||||||
@@ -28,15 +28,13 @@ public class ControlPointWrapper {
|
|||||||
this.visibilityPolicy = visibilityPolicy;
|
this.visibilityPolicy = visibilityPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFrom(IComponentInstance component)
|
public void readFrom(IComponentInstance component) throws IllegalArgumentException,
|
||||||
throws IllegalArgumentException, IllegalAccessException,
|
IllegalAccessException, InvocationTargetException {
|
||||||
InvocationTargetException {
|
|
||||||
value = (Point) getter.invoke(component);
|
value = (Point) getter.invoke(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(IComponentInstance component)
|
public void writeTo(IComponentInstance component) throws IllegalArgumentException,
|
||||||
throws IllegalArgumentException, IllegalAccessException,
|
IllegalAccessException, InvocationTargetException {
|
||||||
InvocationTargetException {
|
|
||||||
setter.invoke(component, value);
|
setter.invoke(component, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -108,8 +108,7 @@ public interface IPlugInPort {
|
|||||||
* @throws BadPositionException
|
* @throws BadPositionException
|
||||||
* in case invalid position is specified
|
* in case invalid position is specified
|
||||||
*/
|
*/
|
||||||
void injectGUIComponent(JComponent component, int position)
|
void injectGUIComponent(JComponent component, int position) throws BadPositionException;
|
||||||
throws BadPositionException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injects a custom menu action into application's main menu. If
|
* Injects a custom menu action into application's main menu. If
|
||||||
@@ -144,8 +143,7 @@ public interface IPlugInPort {
|
|||||||
*
|
*
|
||||||
* @param point
|
* @param point
|
||||||
*/
|
*/
|
||||||
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown,
|
void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown);
|
||||||
boolean altDown);
|
|
||||||
|
|
||||||
void mouseMoved(Point point);
|
void mouseMoved(Point point);
|
||||||
|
|
||||||
@@ -266,8 +264,7 @@ public interface IPlugInPort {
|
|||||||
* @param properties
|
* @param properties
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
void applyPropertiesToSelection(List<PropertyWrapper> properties)
|
void applyPropertiesToSelection(List<PropertyWrapper> properties) throws Exception;
|
||||||
throws Exception;
|
|
||||||
|
|
||||||
// void setCursorIcon(Icon icon);
|
// void setCursorIcon(Icon icon);
|
||||||
|
|
||||||
|
|||||||
+6
-8
@@ -14,8 +14,8 @@ public class PropertyWrapper implements Cloneable {
|
|||||||
private Method getter;
|
private Method getter;
|
||||||
private boolean defaultable;
|
private boolean defaultable;
|
||||||
|
|
||||||
public PropertyWrapper(String name, Class<?> type, Method getter,
|
public PropertyWrapper(String name, Class<?> type, Method getter, Method setter,
|
||||||
Method setter, boolean defaultable) {
|
boolean defaultable) {
|
||||||
super();
|
super();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -24,9 +24,8 @@ public class PropertyWrapper implements Cloneable {
|
|||||||
this.defaultable = defaultable;
|
this.defaultable = defaultable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFrom(IComponentInstance component)
|
public void readFrom(IComponentInstance component) throws IllegalArgumentException,
|
||||||
throws IllegalArgumentException, IllegalAccessException,
|
IllegalAccessException, InvocationTargetException {
|
||||||
InvocationTargetException {
|
|
||||||
this.value = getter.invoke(component);
|
this.value = getter.invoke(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,9 +38,8 @@ public class PropertyWrapper implements Cloneable {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void writeTo(IComponentInstance component)
|
public void writeTo(IComponentInstance component) throws IllegalArgumentException,
|
||||||
throws IllegalArgumentException, IllegalAccessException,
|
IllegalAccessException, InvocationTargetException {
|
||||||
InvocationTargetException {
|
|
||||||
setter.invoke(component, value);
|
setter.invoke(component, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+23
-32
@@ -55,10 +55,8 @@ public class DialogFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyEditorDialog createPropertyEditorDialog(
|
public PropertyEditorDialog createPropertyEditorDialog(List<PropertyWrapper> properties) {
|
||||||
List<PropertyWrapper> properties) {
|
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties);
|
||||||
PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame,
|
|
||||||
properties);
|
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,33 +65,28 @@ public class DialogFactory {
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File showOpenDialog(FileFilter fileFilter, File initialFile,
|
public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||||
String defaultExtension, IFileChooserAccessory accessory) {
|
IFileChooserAccessory accessory) {
|
||||||
JFileChooser openFileChooser = new JFileChooser();
|
JFileChooser openFileChooser = new JFileChooser();
|
||||||
initializeFileChooser(openFileChooser, fileFilter, initialFile,
|
initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
||||||
defaultExtension, accessory);
|
|
||||||
|
|
||||||
int result = openFileChooser.showOpenDialog(mainFrame);
|
int result = openFileChooser.showOpenDialog(mainFrame);
|
||||||
|
|
||||||
return processFileChooserResult(result, openFileChooser,
|
return processFileChooserResult(result, openFileChooser, defaultExtension);
|
||||||
defaultExtension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File showSaveDialog(FileFilter fileFilter, File initialFile,
|
public File showSaveDialog(FileFilter fileFilter, File initialFile, String defaultExtension,
|
||||||
String defaultExtension, IFileChooserAccessory accessory) {
|
IFileChooserAccessory accessory) {
|
||||||
JFileChooser saveFileChooser = new OverwritePromptFileChooser();
|
JFileChooser saveFileChooser = new OverwritePromptFileChooser();
|
||||||
initializeFileChooser(saveFileChooser, fileFilter, initialFile,
|
initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory);
|
||||||
defaultExtension, accessory);
|
|
||||||
|
|
||||||
int result = saveFileChooser.showSaveDialog(mainFrame);
|
int result = saveFileChooser.showSaveDialog(mainFrame);
|
||||||
|
|
||||||
return processFileChooserResult(result, saveFileChooser,
|
return processFileChooserResult(result, saveFileChooser, defaultExtension);
|
||||||
defaultExtension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeFileChooser(JFileChooser fileChooser,
|
private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter,
|
||||||
FileFilter fileFilter, File initialFile, String defaultExtension,
|
File initialFile, String defaultExtension, IFileChooserAccessory accessory) {
|
||||||
IFileChooserAccessory accessory) {
|
|
||||||
if (accessory != null) {
|
if (accessory != null) {
|
||||||
accessory.install(fileChooser);
|
accessory.install(fileChooser);
|
||||||
}
|
}
|
||||||
@@ -101,8 +94,7 @@ public class DialogFactory {
|
|||||||
fileChooser.removeChoosableFileFilter(filter);
|
fileChooser.removeChoosableFileFilter(filter);
|
||||||
}
|
}
|
||||||
if (fileChooser instanceof OverwritePromptFileChooser) {
|
if (fileChooser instanceof OverwritePromptFileChooser) {
|
||||||
((OverwritePromptFileChooser) fileChooser).setFileFilter(
|
((OverwritePromptFileChooser) fileChooser).setFileFilter(fileFilter, defaultExtension);
|
||||||
fileFilter, defaultExtension);
|
|
||||||
} else {
|
} else {
|
||||||
fileChooser.setFileFilter(fileFilter);
|
fileChooser.setFileFilter(fileFilter);
|
||||||
}
|
}
|
||||||
@@ -122,19 +114,18 @@ public class DialogFactory {
|
|||||||
if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) {
|
if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) {
|
||||||
return fileChooser.getSelectedFile();
|
return fileChooser.getSelectedFile();
|
||||||
} else {
|
} else {
|
||||||
return new File(fileChooser.getSelectedFile().getAbsoluteFile()
|
return new File(fileChooser.getSelectedFile().getAbsoluteFile() + "."
|
||||||
+ "." + defaultExtension);
|
+ defaultExtension);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AboutDialog createAboutDialog(String appName, Icon icon,
|
public AboutDialog createAboutDialog(String appName, Icon icon, String version, String author,
|
||||||
String version, String author, String url, String mail,
|
String url, String mail, String htmlContent) {
|
||||||
String htmlContent) {
|
AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, author, url, mail,
|
||||||
AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version,
|
htmlContent);
|
||||||
author, url, mail, htmlContent);
|
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,10 +144,10 @@ public class DialogFactory {
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgressDialog createProgressDialog(String title,
|
public ProgressDialog createProgressDialog(String title, String[] buttonCaptions,
|
||||||
String[] buttonCaptions, String description, boolean useProgress) {
|
String description, boolean useProgress) {
|
||||||
ProgressDialog dialog = new ProgressDialog(mainFrame, title,
|
ProgressDialog dialog = new ProgressDialog(mainFrame, title, buttonCaptions, description,
|
||||||
buttonCaptions, description, useProgress);
|
useProgress);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -25,8 +25,7 @@ public interface IView {
|
|||||||
*
|
*
|
||||||
* @see IPlugInPort#injectGUIComponent
|
* @see IPlugInPort#injectGUIComponent
|
||||||
*/
|
*/
|
||||||
void addComponent(JComponent component, int position)
|
void addComponent(JComponent component, int position) throws BadPositionException;
|
||||||
throws BadPositionException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a menu action.
|
* Adds a menu action.
|
||||||
|
|||||||
+1
-2
@@ -124,8 +124,7 @@ public class MainFrame extends JFrame implements IView {
|
|||||||
// IView
|
// IView
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addComponent(JComponent component, int position)
|
public void addComponent(JComponent component, int position) throws BadPositionException {
|
||||||
throws BadPositionException {
|
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case SwingConstants.TOP:
|
case SwingConstants.TOP:
|
||||||
topPanel.add(component);
|
topPanel.add(component);
|
||||||
|
|||||||
+4
-7
@@ -16,16 +16,13 @@ public class OverwritePromptFileChooser extends JFileChooser {
|
|||||||
if (getSelectedFile().getAbsolutePath().contains(".")) {
|
if (getSelectedFile().getAbsolutePath().contains(".")) {
|
||||||
lSelectedFile = getSelectedFile();
|
lSelectedFile = getSelectedFile();
|
||||||
} else {
|
} else {
|
||||||
lSelectedFile = new File(getSelectedFile().getAbsoluteFile() + "."
|
lSelectedFile = new File(getSelectedFile().getAbsoluteFile() + "." + defaultExtension);
|
||||||
+ defaultExtension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lSelectedFile != null && lSelectedFile.exists()) {
|
if (lSelectedFile != null && lSelectedFile.exists()) {
|
||||||
int lResponse = JOptionPane.showConfirmDialog(this, lSelectedFile
|
int lResponse = JOptionPane.showConfirmDialog(this, lSelectedFile.getAbsolutePath()
|
||||||
.getAbsolutePath()
|
+ " already exists.\nDo you " + "want to replace it?", "Warning",
|
||||||
+ " already exists.\nDo you " + "want to replace it?",
|
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
|
||||||
"Warning", JOptionPane.YES_NO_OPTION,
|
|
||||||
JOptionPane.WARNING_MESSAGE);
|
|
||||||
|
|
||||||
if (lResponse != JOptionPane.YES_OPTION) {
|
if (lResponse != JOptionPane.YES_OPTION) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-2
@@ -27,8 +27,8 @@ public class ColorEditor extends JLabel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
Color newColor = JColorChooser.showDialog(ColorEditor.this,
|
Color newColor = JColorChooser.showDialog(ColorEditor.this, "Choose Color",
|
||||||
"Choose Color", getBackground());
|
getBackground());
|
||||||
if (newColor != null) {
|
if (newColor != null) {
|
||||||
property.setValue(newColor);
|
property.setValue(newColor);
|
||||||
setBackground(newColor);
|
setBackground(newColor);
|
||||||
|
|||||||
+1
-2
@@ -35,8 +35,7 @@ public class MeasureEditor extends Container {
|
|||||||
add(valueField, BorderLayout.CENTER);
|
add(valueField, BorderLayout.CENTER);
|
||||||
try {
|
try {
|
||||||
Method method = measure.getUnit().getClass().getMethod("values");
|
Method method = measure.getUnit().getClass().getMethod("values");
|
||||||
final JComboBox unitBox = new JComboBox((Object[]) method
|
final JComboBox unitBox = new JComboBox((Object[]) method.invoke(measure.getUnit()));
|
||||||
.invoke(measure.getUnit()));
|
|
||||||
unitBox.setSelectedItem(measure.getUnit());
|
unitBox.setSelectedItem(measure.getUnit());
|
||||||
unitBox.addActionListener(new ActionListener() {
|
unitBox.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
|||||||
+4
-8
@@ -24,8 +24,7 @@ import com.diyfever.gui.ButtonDialog;
|
|||||||
|
|
||||||
public class PropertyEditorDialog extends ButtonDialog {
|
public class PropertyEditorDialog extends ButtonDialog {
|
||||||
|
|
||||||
private static final Logger LOG = Logger
|
private static final Logger LOG = Logger.getLogger(PropertyEditorDialog.class);
|
||||||
.getLogger(PropertyEditorDialog.class);
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@@ -35,8 +34,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
private Set<PropertyWrapper> defaultedProperties;
|
private Set<PropertyWrapper> defaultedProperties;
|
||||||
|
|
||||||
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
|
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
|
||||||
super(owner, "Editor", new String[] { ButtonDialog.OK,
|
super(owner, "Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
||||||
ButtonDialog.CANCEL });
|
|
||||||
|
|
||||||
LOG.debug("Creating property editor for: " + properties);
|
LOG.debug("Creating property editor for: " + properties);
|
||||||
|
|
||||||
@@ -85,8 +83,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc.weightx = 1;
|
gbc.weightx = 1;
|
||||||
|
|
||||||
editorPanel
|
editorPanel.add(FieldEditorFactory.createFieldEditor(property), gbc);
|
||||||
.add(FieldEditorFactory.createFieldEditor(property), gbc);
|
|
||||||
|
|
||||||
if (property.isDefaultable()) {
|
if (property.isDefaultable()) {
|
||||||
gbc.gridx = 2;
|
gbc.gridx = 2;
|
||||||
@@ -124,8 +121,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties) {
|
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties) {
|
||||||
PropertyEditorDialog editor = new PropertyEditorDialog(owner,
|
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties);
|
||||||
properties);
|
|
||||||
editor.setVisible(true);
|
editor.setVisible(true);
|
||||||
if (OK.equals(editor.getSelectedButtonCaption())) {
|
if (OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+12
-42
@@ -10,48 +10,18 @@ import javax.swing.ImageIcon;
|
|||||||
*/
|
*/
|
||||||
public enum IconLoader {
|
public enum IconLoader {
|
||||||
|
|
||||||
Delete("delete.png"),
|
Delete("delete.png"), Add("add.png"), FolderOut("folder_out.png"), Garbage("garbage.png"), DiskBlue(
|
||||||
Add("add.png"),
|
"disk_blue.png"), SaveAs("save_as.png"), Exit("exit.png"), DocumentPlainYellow(
|
||||||
FolderOut("folder_out.png"),
|
"document_plain_yellow.png"), PhotoScenery("photo_scenery.png"), LightBulbOn(
|
||||||
Garbage("garbage.png"),
|
"lightbulb_on.png"), LightBulbOff("lightbulb_off.png"), NotebookAdd("notebook_add.png"), FormGreen(
|
||||||
DiskBlue("disk_blue.png"),
|
"form_green.png"), Gears("gears.png"), About("about.png"), Donate("donate.gif"), WindowColors(
|
||||||
SaveAs("save_as.png"),
|
"window_colors.png"), WindowGear("window_gear.png"), NavigateCheck("navigate_check.png"), Undo(
|
||||||
Exit("exit.png"),
|
"undo.png"), Error("error.png"), Warning("warning.png"), ZoomSmall("zoom_small.png"), MoveSmall(
|
||||||
DocumentPlainYellow("document_plain_yellow.png"),
|
"move_small.png"), Print("print.png"), PDF("pdf.png"), Excel("excel.png"), CSV(
|
||||||
PhotoScenery("photo_scenery.png"),
|
"csv.png"), HTML("html.png"), Image("image.png"), Cut("cut.png"), Copy("copy.png"), Paste(
|
||||||
LightBulbOn("lightbulb_on.png"),
|
"paste.png"), Selection("selection.png"), BOM("bom.png"), BlackBoard("blackboard.png"), IdCard(
|
||||||
LightBulbOff("lightbulb_off.png"),
|
"id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench(
|
||||||
NotebookAdd("notebook_add.png"),
|
"wrench.png"), ;
|
||||||
FormGreen("form_green.png"),
|
|
||||||
Gears("gears.png"),
|
|
||||||
About("about.png"),
|
|
||||||
Donate("donate.gif"),
|
|
||||||
WindowColors("window_colors.png"),
|
|
||||||
WindowGear("window_gear.png"),
|
|
||||||
NavigateCheck("navigate_check.png"),
|
|
||||||
Undo("undo.png"),
|
|
||||||
Error("error.png"),
|
|
||||||
Warning("warning.png"),
|
|
||||||
ZoomSmall("zoom_small.png"),
|
|
||||||
MoveSmall("move_small.png"),
|
|
||||||
Print("print.png"),
|
|
||||||
PDF("pdf.png"),
|
|
||||||
Excel("excel.png"),
|
|
||||||
CSV("csv.png"),
|
|
||||||
HTML("html.png"),
|
|
||||||
Image("image.png"),
|
|
||||||
Cut("cut.png"),
|
|
||||||
Copy("copy.png"),
|
|
||||||
Paste("paste.png"),
|
|
||||||
Selection("selection.png"),
|
|
||||||
BOM("bom.png"),
|
|
||||||
BlackBoard("blackboard.png"),
|
|
||||||
IdCard("id_card.png"),
|
|
||||||
IdCardAdd("id_card_add.png"),
|
|
||||||
Chest("chest.png"),
|
|
||||||
Upload("upload.png"),
|
|
||||||
Wrench("wrench.png"),
|
|
||||||
;
|
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -27,8 +27,8 @@ public class Project implements Serializable {
|
|||||||
height = new Size(21d, SizeUnit.cm);
|
height = new Size(21d, SizeUnit.cm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Project(String title, String author, String description, Size width,
|
public Project(String title, String author, String description, Size width, Size height,
|
||||||
Size height, List<IComponentInstance> components) {
|
List<IComponentInstance> components) {
|
||||||
super();
|
super();
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
@@ -92,10 +92,8 @@ public class Project implements Serializable {
|
|||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((author == null) ? 0 : author.hashCode());
|
result = prime * result + ((author == null) ? 0 : author.hashCode());
|
||||||
result = prime * result
|
result = prime * result + ((components == null) ? 0 : components.hashCode());
|
||||||
+ ((components == null) ? 0 : components.hashCode());
|
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||||
result = prime * result
|
|
||||||
+ ((description == null) ? 0 : description.hashCode());
|
|
||||||
result = prime * result + ((height == null) ? 0 : height.hashCode());
|
result = prime * result + ((height == null) ? 0 : height.hashCode());
|
||||||
result = prime * result + ((title == null) ? 0 : title.hashCode());
|
result = prime * result + ((title == null) ? 0 : title.hashCode());
|
||||||
result = prime * result + ((width == null) ? 0 : width.hashCode());
|
result = prime * result + ((width == null) ? 0 : width.hashCode());
|
||||||
@@ -146,7 +144,8 @@ public class Project implements Serializable {
|
|||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public Project clone() throws CloneNotSupportedException {
|
// public Project clone() throws CloneNotSupportedException {
|
||||||
// List<IComponentInstance> clonedComponents = new ArrayList<IComponentInstance>();
|
// List<IComponentInstance> clonedComponents = new
|
||||||
|
// ArrayList<IComponentInstance>();
|
||||||
// for (IComponentInstance component : components) {
|
// for (IComponentInstance component : components) {
|
||||||
// clonedComponents.add(component.clone());
|
// clonedComponents.add(component.clone());
|
||||||
// }
|
// }
|
||||||
|
|||||||
+1
-2
@@ -4,8 +4,7 @@ import java.io.Serializable;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.Format;
|
import java.text.Format;
|
||||||
|
|
||||||
public class AbstractMeasure<T extends Enum<? extends Unit>> implements
|
public class AbstractMeasure<T extends Enum<? extends Unit>> implements Serializable, Cloneable {
|
||||||
Serializable, Cloneable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -6,8 +6,7 @@ public class Size extends AbstractMeasure<SizeUnit> {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit()
|
public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution();
|
||||||
.getScreenResolution();
|
|
||||||
|
|
||||||
public Size() {
|
public Size() {
|
||||||
super();
|
super();
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ class CanvasGestureListener implements DragGestureListener {
|
|||||||
@Override
|
@Override
|
||||||
public void dragGestureRecognized(DragGestureEvent dge) {
|
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||||
presenter.dragStarted(dge.getDragOrigin());
|
presenter.dragStarted(dge.getDragOrigin());
|
||||||
dge.startDrag(Cursor.getDefaultCursor(), new EmptyTransferable(),
|
dge.startDrag(Cursor.getDefaultCursor(), new EmptyTransferable(), new CanvasSourceListener(
|
||||||
new CanvasSourceListener(presenter));
|
presenter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-26
@@ -48,9 +48,9 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
private VolatileImage bufferImage;
|
private VolatileImage bufferImage;
|
||||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||||
|
|
||||||
private static final EnumSet<DrawOption> drawOptions = EnumSet.of(
|
private static final EnumSet<DrawOption> drawOptions = EnumSet.of(DrawOption.GRID,
|
||||||
DrawOption.GRID, DrawOption.SELECTION, DrawOption.ZOOM,
|
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
|
||||||
DrawOption.ANTIALIASING, DrawOption.CONTROL_POINTS);
|
DrawOption.CONTROL_POINTS);
|
||||||
|
|
||||||
public CanvasPanel(IPlugInPort plugInPort) {
|
public CanvasPanel(IPlugInPort plugInPort) {
|
||||||
super();
|
super();
|
||||||
@@ -59,8 +59,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
initializeListeners();
|
initializeListeners();
|
||||||
initializeDnD();
|
initializeDnD();
|
||||||
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment
|
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
.getLocalGraphicsEnvironment();
|
|
||||||
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices();
|
||||||
screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
|
screenGraphicsConfiguration = devices[0].getDefaultConfiguration();
|
||||||
|
|
||||||
@@ -73,9 +72,8 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
|
|
||||||
private void initializeDnD() {
|
private void initializeDnD() {
|
||||||
// Initialize drag source recognizer.
|
// Initialize drag source recognizer.
|
||||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
|
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this,
|
||||||
this, DnDConstants.ACTION_MOVE,
|
DnDConstants.ACTION_MOVE, new CanvasGestureListener(plugInPort));
|
||||||
new CanvasGestureListener(plugInPort));
|
|
||||||
// Initialize drop target.
|
// Initialize drop target.
|
||||||
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE,
|
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE,
|
||||||
new CanvasTargetListener(plugInPort), true);
|
new CanvasTargetListener(plugInPort), true);
|
||||||
@@ -96,8 +94,8 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void createBufferImage() {
|
protected void createBufferImage() {
|
||||||
bufferImage = screenGraphicsConfiguration
|
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(getWidth(),
|
||||||
.createCompatibleVolatileImage(getWidth(), getHeight());
|
getHeight());
|
||||||
bufferImage.validate(screenGraphicsConfiguration);
|
bufferImage.validate(screenGraphicsConfiguration);
|
||||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||||
plugInPort.draw(g2d, drawOptions);
|
plugInPort.draw(g2d, drawOptions);
|
||||||
@@ -157,24 +155,19 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
if (properties.isEmpty()) {
|
if (properties.isEmpty()) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PropertyEditorDialog editor = DialogFactory
|
PropertyEditorDialog editor = DialogFactory.getInstance()
|
||||||
.getInstance()
|
|
||||||
.createPropertyEditorDialog(properties);
|
.createPropertyEditorDialog(properties);
|
||||||
editor.setVisible(true);
|
editor.setVisible(true);
|
||||||
if (ButtonDialog.OK.equals(editor
|
if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) {
|
||||||
.getSelectedButtonCaption())) {
|
|
||||||
try {
|
try {
|
||||||
plugInPort
|
plugInPort.applyPropertiesToSelection(properties);
|
||||||
.applyPropertiesToSelection(properties);
|
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
for (PropertyWrapper property : editor
|
for (PropertyWrapper property : editor.getDefaultedProperties()) {
|
||||||
.getDefaultedProperties()) {
|
|
||||||
if (property.getValue() != null) {
|
if (property.getValue() != null) {
|
||||||
plugInPort.setDefaultPropertyValue(
|
plugInPort.setDefaultPropertyValue(property.getName(),
|
||||||
property.getName(),
|
|
||||||
property.getValue());
|
property.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,8 +175,7 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
plugInPort.mouseClicked(e.getPoint(),
|
plugInPort.mouseClicked(e.getPoint(), e.isControlDown(), e.isShiftDown(), e
|
||||||
e.isControlDown(), e.isShiftDown(), e
|
|
||||||
.isAltDown());
|
.isAltDown());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,14 +187,13 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void autoscroll(Point cursorLocn) {
|
public void autoscroll(Point cursorLocn) {
|
||||||
scrollRectToVisible(new Rectangle(cursorLocn.x - 15, cursorLocn.y - 15,
|
scrollRectToVisible(new Rectangle(cursorLocn.x - 15, cursorLocn.y - 15, 30, 30));
|
||||||
30, 30));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getAutoscrollInsets() {
|
public Insets getAutoscrollInsets() {
|
||||||
Rectangle rect = getVisibleRect();
|
Rectangle rect = getVisibleRect();
|
||||||
return new Insets(rect.y - 15, rect.x - 15, rect.y + rect.height + 15,
|
return new Insets(rect.y - 15, rect.x - 15, rect.y + rect.height + 15, rect.x + rect.width
|
||||||
rect.x + rect.width + 15);
|
+ 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-12
@@ -33,8 +33,7 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
canvasPanel = new CanvasPanel(plugInPort);
|
canvasPanel = new CanvasPanel(plugInPort);
|
||||||
try {
|
try {
|
||||||
plugInPort.injectGUIComponent(getScrollPane(),
|
plugInPort.injectGUIComponent(getScrollPane(), SwingConstants.CENTER);
|
||||||
SwingConstants.CENTER);
|
|
||||||
} catch (BadPositionException e) {
|
} catch (BadPositionException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -42,10 +41,9 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
|
|
||||||
private RulerScrollPane getScrollPane() {
|
private RulerScrollPane getScrollPane() {
|
||||||
if (scrollPane == null) {
|
if (scrollPane == null) {
|
||||||
scrollPane = new RulerScrollPane(canvasPanel,
|
scrollPane = new RulerScrollPane(canvasPanel, new ProjectDrawingProvider(plugInPort));
|
||||||
new ProjectDrawingProvider(plugInPort));
|
Boolean metric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem(
|
||||||
Boolean metric = (Boolean) ConfigurationManager.getInstance()
|
METRIC_KEY);
|
||||||
.getConfigurationItem(METRIC_KEY);
|
|
||||||
if (metric == null) {
|
if (metric == null) {
|
||||||
metric = true;
|
metric = true;
|
||||||
}
|
}
|
||||||
@@ -54,8 +52,7 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unitsChanged(boolean isMetric) {
|
public void unitsChanged(boolean isMetric) {
|
||||||
ConfigurationManager.getInstance().setConfigurationItem(
|
ConfigurationManager.getInstance().setConfigurationItem(METRIC_KEY, isMetric);
|
||||||
METRIC_KEY, isMetric);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -64,8 +61,7 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||||
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED,
|
return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT);
|
||||||
EventType.REPAINT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -81,8 +77,7 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
if ((Boolean) params[1]) {
|
if ((Boolean) params[1]) {
|
||||||
// Scroll to the center.
|
// Scroll to the center.
|
||||||
Rectangle visibleRect = canvasPanel.getVisibleRect();
|
Rectangle visibleRect = canvasPanel.getVisibleRect();
|
||||||
visibleRect.setLocation(
|
visibleRect.setLocation((canvasPanel.getWidth() - visibleRect.width) / 2,
|
||||||
(canvasPanel.getWidth() - visibleRect.width) / 2,
|
|
||||||
(canvasPanel.getHeight() - visibleRect.height) / 2);
|
(canvasPanel.getHeight() - visibleRect.height) / 2);
|
||||||
canvasPanel.scrollRectToVisible(visibleRect);
|
canvasPanel.scrollRectToVisible(visibleRect);
|
||||||
canvasPanel.revalidate();
|
canvasPanel.revalidate();
|
||||||
|
|||||||
+1
-2
@@ -39,8 +39,7 @@ class CanvasSourceListener implements DragSourceListener {
|
|||||||
public void dragOver(DragSourceDragEvent dsde) {
|
public void dragOver(DragSourceDragEvent dsde) {
|
||||||
Point p = dsde.getDragSourceContext().getComponent().getMousePosition();
|
Point p = dsde.getDragSourceContext().getComponent().getMousePosition();
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
dsde.getDragSourceContext().getComponent().firePropertyChange(
|
dsde.getDragSourceContext().getComponent().firePropertyChange("dragPoint", p.x, p.y);
|
||||||
"dragPoint", p.x, p.y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -8,8 +8,7 @@ import java.io.IOException;
|
|||||||
public class EmptyTransferable implements Transferable {
|
public class EmptyTransferable implements Transferable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor)
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||||
throws UnsupportedFlavorException, IOException {
|
|
||||||
throw new UnsupportedFlavorException(flavor);
|
throw new UnsupportedFlavorException(flavor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -8,8 +8,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class PointTransferable implements Transferable {
|
public class PointTransferable implements Transferable {
|
||||||
|
|
||||||
public static final DataFlavor pointFlavor = new DataFlavor(Point.class,
|
public static final DataFlavor pointFlavor = new DataFlavor(Point.class, "Java Point");
|
||||||
"Java Point");
|
|
||||||
|
|
||||||
private Point startPoint;
|
private Point startPoint;
|
||||||
|
|
||||||
@@ -19,8 +18,7 @@ public class PointTransferable implements Transferable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor)
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||||
throws UnsupportedFlavorException, IOException {
|
|
||||||
if (flavor.equals(pointFlavor)) {
|
if (flavor.equals(pointFlavor)) {
|
||||||
return startPoint;
|
return startPoint;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -17,16 +17,14 @@ public class SelectionTransferable implements Transferable {
|
|||||||
private Point startPoint;
|
private Point startPoint;
|
||||||
private List<IComponentInstance> selection;
|
private List<IComponentInstance> selection;
|
||||||
|
|
||||||
public SelectionTransferable(List<IComponentInstance> selection,
|
public SelectionTransferable(List<IComponentInstance> selection, Point startPoint) {
|
||||||
Point startPoint) {
|
|
||||||
super();
|
super();
|
||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
this.startPoint = startPoint;
|
this.startPoint = startPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor)
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||||
throws UnsupportedFlavorException, IOException {
|
|
||||||
if (flavor.equals(selectionFlavor)) {
|
if (flavor.equals(selectionFlavor)) {
|
||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
@@ -38,8 +36,7 @@ public class SelectionTransferable implements Transferable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataFlavor[] getTransferDataFlavors() {
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
return new DataFlavor[] { selectionFlavor,
|
return new DataFlavor[] { selectionFlavor, PointTransferable.pointFlavor };
|
||||||
PointTransferable.pointFlavor };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+13
-16
@@ -82,8 +82,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<EventType> getSubscribedEventTypes() {
|
public EnumSet<EventType> getSubscribedEventTypes() {
|
||||||
return EnumSet.of(EventType.SELECTION_CHANGED,
|
return EnumSet.of(EventType.SELECTION_CHANGED, EventType.PROJECT_MODIFIED);
|
||||||
EventType.PROJECT_MODIFIED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,8 +92,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
refreshActions();
|
refreshActions();
|
||||||
break;
|
break;
|
||||||
case PROJECT_MODIFIED:
|
case PROJECT_MODIFIED:
|
||||||
undoHandler.stateChanged((Project) params[0], (Project) params[1],
|
undoHandler.stateChanged((Project) params[0], (Project) params[1], (String) params[2]);
|
||||||
(String) params[2]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,8 +102,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
cutAction.setEnabled(enabled);
|
cutAction.setEnabled(enabled);
|
||||||
copyAction.setEnabled(enabled);
|
copyAction.setEnabled(enabled);
|
||||||
try {
|
try {
|
||||||
pasteAction.setEnabled(clipboard
|
pasteAction.setEnabled(clipboard.isDataFlavorAvailable(ComponentSelection.listFlavor));
|
||||||
.isDataFlavorAvailable(ComponentSelection.listFlavor));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
pasteAction.setEnabled(false);
|
pasteAction.setEnabled(false);
|
||||||
}
|
}
|
||||||
@@ -118,8 +115,8 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
public CutAction() {
|
public CutAction() {
|
||||||
super();
|
super();
|
||||||
putValue(AbstractAction.NAME, "Cut");
|
putValue(AbstractAction.NAME, "Cut");
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X,
|
||||||
KeyEvent.VK_X, ActionEvent.CTRL_MASK));
|
ActionEvent.CTRL_MASK));
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Cut.getIcon());
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Cut.getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,16 +133,16 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
public CopyAction() {
|
public CopyAction() {
|
||||||
super();
|
super();
|
||||||
putValue(AbstractAction.NAME, "Copy");
|
putValue(AbstractAction.NAME, "Copy");
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
|
||||||
KeyEvent.VK_C, ActionEvent.CTRL_MASK));
|
ActionEvent.CTRL_MASK));
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
LOG.info("Copy triggered");
|
LOG.info("Copy triggered");
|
||||||
clipboard.setContents(cloner.deepClone(plugInPort
|
clipboard.setContents(cloner.deepClone(plugInPort.getSelectedComponents()),
|
||||||
.getSelectedComponents()), ClipboardManager.this);
|
ClipboardManager.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,8 +153,8 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
public PasteAction() {
|
public PasteAction() {
|
||||||
super();
|
super();
|
||||||
putValue(AbstractAction.NAME, "Paste");
|
putValue(AbstractAction.NAME, "Paste");
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V,
|
||||||
KeyEvent.VK_V, ActionEvent.CTRL_MASK));
|
ActionEvent.CTRL_MASK));
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Paste.getIcon());
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Paste.getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,8 +179,8 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner {
|
|||||||
public SelectAllAction() {
|
public SelectAllAction() {
|
||||||
super();
|
super();
|
||||||
putValue(AbstractAction.NAME, "Select All");
|
putValue(AbstractAction.NAME, "Select All");
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(
|
putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A,
|
||||||
KeyEvent.VK_A, ActionEvent.CTRL_MASK));
|
ActionEvent.CTRL_MASK));
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Selection.getIcon());
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Selection.getIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-12
@@ -54,9 +54,8 @@ public class BomDialog extends JDialog {
|
|||||||
private ObjectListTable<BomEntry> getTable() {
|
private ObjectListTable<BomEntry> getTable() {
|
||||||
if (table == null) {
|
if (table == null) {
|
||||||
try {
|
try {
|
||||||
table = new ObjectListTable<BomEntry>(BomEntry.class,
|
table = new ObjectListTable<BomEntry>(BomEntry.class, new String[] { "getName",
|
||||||
new String[] { "getName", "getValue", "getQuantity",
|
"getValue", "getQuantity", "getNotes/setNotes" }, null);
|
||||||
"getNotes/setNotes" }, null);
|
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
@@ -115,9 +114,8 @@ public class BomDialog extends JDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance().showSaveDialog(
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.CSV.getFilter(),
|
||||||
FileFilterEnum.CSV.getFilter(), null,
|
null, FileFilterEnum.CSV.getExtensions()[0], null);
|
||||||
FileFilterEnum.CSV.getExtensions()[0], null);
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
TableExporter.getInstance().exportToCSV(getTable(), file);
|
TableExporter.getInstance().exportToCSV(getTable(), file);
|
||||||
@@ -141,9 +139,8 @@ public class BomDialog extends JDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance().showSaveDialog(
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.HTML.getFilter(),
|
||||||
FileFilterEnum.HTML.getFilter(), null,
|
null, FileFilterEnum.HTML.getExtensions()[0], null);
|
||||||
FileFilterEnum.HTML.getExtensions()[0], null);
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
TableExporter.getInstance().exportToHTML(getTable(), file);
|
TableExporter.getInstance().exportToHTML(getTable(), file);
|
||||||
@@ -167,9 +164,8 @@ public class BomDialog extends JDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance().showSaveDialog(
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(),
|
||||||
FileFilterEnum.PNG.getFilter(), null,
|
null, FileFilterEnum.PNG.getExtensions()[0], null);
|
||||||
FileFilterEnum.PNG.getExtensions()[0], null);
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
try {
|
try {
|
||||||
TableExporter.getInstance().exportToPNG(getTable(), file);
|
TableExporter.getInstance().exportToPNG(getTable(), file);
|
||||||
|
|||||||
+4
-8
@@ -6,12 +6,9 @@ import javax.swing.filechooser.FileFilter;
|
|||||||
|
|
||||||
enum FileFilterEnum {
|
enum FileFilterEnum {
|
||||||
|
|
||||||
PNG("PNG Images (*.png)", "png"),
|
PNG("PNG Images (*.png)", "png"), PDF("PDF Files (*.pdf)", "pdf"), DIY(
|
||||||
PDF("PDF Files (*.pdf)", "pdf"),
|
"DIY Project Files (*.diy)", "diy"), EXCEL("Excel Workbooks (*.xls)", "xls"), CSV(
|
||||||
DIY("DIY Project Files (*.diy)", "diy"),
|
"Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)", "html");
|
||||||
EXCEL("Excel Workbooks (*.xls)", "xls"),
|
|
||||||
CSV("Comma Separated Files (*.csv)", "csv"),
|
|
||||||
HTML("HTML Files (*.html)", "html");
|
|
||||||
|
|
||||||
FileFilter filter;
|
FileFilter filter;
|
||||||
String[] extensions;
|
String[] extensions;
|
||||||
@@ -23,8 +20,7 @@ enum FileFilterEnum {
|
|||||||
@Override
|
@Override
|
||||||
public boolean accept(File f) {
|
public boolean accept(File f) {
|
||||||
String fileExt = f.getName();
|
String fileExt = f.getName();
|
||||||
fileExt = fileExt.substring(fileExt.lastIndexOf('.') + 1)
|
fileExt = fileExt.substring(fileExt.lastIndexOf('.') + 1).toLowerCase();
|
||||||
.toLowerCase();
|
|
||||||
for (String ext : extensions) {
|
for (String ext : extensions) {
|
||||||
if (ext.equals(fileExt)) {
|
if (ext.equals(fileExt)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+11
-20
@@ -59,8 +59,7 @@ public class FileManager implements IPlugIn {
|
|||||||
public NewAction() {
|
public NewAction() {
|
||||||
super();
|
super();
|
||||||
putValue(AbstractAction.NAME, "New");
|
putValue(AbstractAction.NAME, "New");
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow
|
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow.getIcon());
|
||||||
.getIcon());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,10 +81,8 @@ public class FileManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance()
|
File file = DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(),
|
||||||
.showOpenDialog(FileFilterEnum.DIY.getFilter(), null,
|
null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
||||||
FileFilterEnum.DIY.getExtensions()[0],
|
|
||||||
new ProjectPreview());
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LOG.info("Loading project from file.");
|
LOG.info("Loading project from file.");
|
||||||
FileInputStream fis;
|
FileInputStream fis;
|
||||||
@@ -117,10 +114,8 @@ public class FileManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance()
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(),
|
||||||
.showSaveDialog(FileFilterEnum.DIY.getFilter(), null,
|
null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
||||||
FileFilterEnum.DIY.getExtensions()[0],
|
|
||||||
new ProjectPreview());
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LOG.info("Saving project to file.");
|
LOG.info("Saving project to file.");
|
||||||
FileOutputStream fos;
|
FileOutputStream fos;
|
||||||
@@ -151,10 +146,8 @@ public class FileManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance()
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(),
|
||||||
.showSaveDialog(FileFilterEnum.DIY.getFilter(), null,
|
null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview());
|
||||||
FileFilterEnum.DIY.getExtensions()[0],
|
|
||||||
new ProjectPreview());
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LOG.info("Saving project to file.");
|
LOG.info("Saving project to file.");
|
||||||
FileOutputStream fos;
|
FileOutputStream fos;
|
||||||
@@ -204,9 +197,8 @@ public class FileManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance().showSaveDialog(
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PDF.getFilter(),
|
||||||
FileFilterEnum.PDF.getFilter(), null,
|
null, FileFilterEnum.PDF.getExtensions()[0], null);
|
||||||
FileFilterEnum.PDF.getExtensions()[0], null);
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
DrawingExporter.getInstance().exportPDF(drawingProvider, file);
|
DrawingExporter.getInstance().exportPDF(drawingProvider, file);
|
||||||
}
|
}
|
||||||
@@ -225,9 +217,8 @@ public class FileManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
File file = DialogFactory.getInstance().showSaveDialog(
|
File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(),
|
||||||
FileFilterEnum.PNG.getFilter(), null,
|
null, FileFilterEnum.PNG.getExtensions()[0], null);
|
||||||
FileFilterEnum.PNG.getExtensions()[0], null);
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
DrawingExporter.getInstance().exportPNG(drawingProvider, file);
|
DrawingExporter.getInstance().exportPNG(drawingProvider, file);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -26,8 +26,7 @@ public class ProjectDrawingProvider implements IDrawingProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics g) {
|
public void draw(Graphics g) {
|
||||||
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM,
|
plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING));
|
||||||
DrawOption.ANTIALIASING));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-4
@@ -35,8 +35,7 @@ import com.thoughtworks.xstream.io.xml.DomDriver;
|
|||||||
*
|
*
|
||||||
* @author Branislav Stojkovic
|
* @author Branislav Stojkovic
|
||||||
*/
|
*/
|
||||||
public class ProjectPreview extends JPanel implements PropertyChangeListener,
|
public class ProjectPreview extends JPanel implements PropertyChangeListener, IFileChooserAccessory {
|
||||||
IFileChooserAccessory {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@@ -148,8 +147,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener,
|
|||||||
presenter.draw(g2d, EnumSet.noneOf(DrawOption.class));
|
presenter.draw(g2d, EnumSet.noneOf(DrawOption.class));
|
||||||
|
|
||||||
g2d.setColor(Color.black);
|
g2d.setColor(Color.black);
|
||||||
g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height
|
g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - (int) (1 / zoomRatio));
|
||||||
- (int) (1 / zoomRatio));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -37,10 +37,10 @@ public class HelpManager implements IPlugIn {
|
|||||||
|
|
||||||
private AboutDialog getAboutDialog() {
|
private AboutDialog getAboutDialog() {
|
||||||
if (aboutDialog == null) {
|
if (aboutDialog == null) {
|
||||||
aboutDialog = DialogFactory.getInstance().createAboutDialog(
|
aboutDialog = DialogFactory.getInstance().createAboutDialog("DIY Layout Creator 4",
|
||||||
"DIY Layout Creator 4", IconLoader.BlackBoard.getIcon(),
|
IconLoader.BlackBoard.getIcon(),
|
||||||
plugInPort.getCurrentVersionNumber().toString(),
|
plugInPort.getCurrentVersionNumber().toString(), "Bane Stojkovic",
|
||||||
"Bane Stojkovic", "diy-fever.com", "bancika@gmail.com", "");
|
"diy-fever.com", "bancika@gmail.com", "");
|
||||||
}
|
}
|
||||||
return aboutDialog;
|
return aboutDialog;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-9
@@ -95,8 +95,7 @@ public class OnlineManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
LoginDialog dialog = DialogFactory.getInstance()
|
LoginDialog dialog = DialogFactory.getInstance().createLoginDialog();
|
||||||
.createLoginDialog();
|
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,8 +112,7 @@ public class OnlineManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
NewUserDialog dialog = DialogFactory.getInstance()
|
NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog();
|
||||||
.createNewUserDialog();
|
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,8 +129,7 @@ public class OnlineManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
UploadDialog dialog = DialogFactory.getInstance()
|
UploadDialog dialog = DialogFactory.getInstance().createUploadDialog();
|
||||||
.createUploadDialog();
|
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,9 +146,8 @@ public class OnlineManager implements IPlugIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ProgressDialog dialog = DialogFactory.getInstance()
|
ProgressDialog dialog = DialogFactory.getInstance().createProgressDialog("Test",
|
||||||
.createProgressDialog("Test", new String[] {}, "Some text",
|
new String[] {}, "Some text", false);
|
||||||
false);
|
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@ import org.apache.log4j.BasicConfigurator;
|
|||||||
|
|
||||||
import com.diyfever.diylc.plugins.online.presenter.LibraryPresenter;
|
import com.diyfever.diylc.plugins.online.presenter.LibraryPresenter;
|
||||||
|
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-6
@@ -21,8 +21,7 @@ public class ProjectEntity implements Serializable {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectEntity(int id, String name, String description, String owner,
|
public ProjectEntity(int id, String name, String description, String owner, String category) {
|
||||||
String category) {
|
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -88,10 +87,8 @@ public class ProjectEntity implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result
|
result = prime * result + ((category == null) ? 0 : category.hashCode());
|
||||||
+ ((category == null) ? 0 : category.hashCode());
|
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||||
result = prime * result
|
|
||||||
+ ((description == null) ? 0 : description.hashCode());
|
|
||||||
result = prime * result + id;
|
result = prime * result + id;
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
||||||
|
|||||||
+19
-27
@@ -53,19 +53,17 @@ public class LibraryPresenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createUser(String userName, String password, String email)
|
public void createUser(String userName, String password, String email) throws SQLException,
|
||||||
throws SQLException, NotConnectedException, AlreadyExistsException {
|
NotConnectedException, AlreadyExistsException {
|
||||||
LOG.info("Creating user: " + userName);
|
LOG.info("Creating user: " + userName);
|
||||||
if (dbManager.isConnected()) {
|
if (dbManager.isConnected()) {
|
||||||
ResultSet resultSet = dbManager.getResultSet(String.format(
|
ResultSet resultSet = dbManager.getResultSet(String.format(USER_SQL, userName));
|
||||||
USER_SQL, userName));
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
throw new AlreadyExistsException();
|
throw new AlreadyExistsException();
|
||||||
}
|
}
|
||||||
dbManager.updateDB(String.format(CREATE_USER_SQL, userName,
|
dbManager.updateDB(String.format(CREATE_USER_SQL, userName, hashPassword(password),
|
||||||
hashPassword(password), email));
|
email));
|
||||||
resultSet = dbManager.getResultSet(String
|
resultSet = dbManager.getResultSet(String.format(USER_SQL, userName));
|
||||||
.format(USER_SQL, userName));
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
LOG.info("Logged in as \"" + userName + "\"");
|
LOG.info("Logged in as \"" + userName + "\"");
|
||||||
currentUserId = resultSet.getInt("user_id");
|
currentUserId = resultSet.getInt("user_id");
|
||||||
@@ -80,8 +78,7 @@ public class LibraryPresenter {
|
|||||||
NotConnectedException {
|
NotConnectedException {
|
||||||
LOG.info("Logging in as: " + userName);
|
LOG.info("Logging in as: " + userName);
|
||||||
if (dbManager.isConnected()) {
|
if (dbManager.isConnected()) {
|
||||||
ResultSet resultSet = dbManager.getResultSet(String.format(
|
ResultSet resultSet = dbManager.getResultSet(String.format(USER_SQL, userName));
|
||||||
USER_SQL, userName));
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
String dbPassword = resultSet.getString("password");
|
String dbPassword = resultSet.getString("password");
|
||||||
String hashPassword = hashPassword(password);
|
String hashPassword = hashPassword(password);
|
||||||
@@ -99,15 +96,13 @@ public class LibraryPresenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, String> fetchCategories() throws SQLException,
|
public Map<Integer, String> fetchCategories() throws SQLException, NotConnectedException {
|
||||||
NotConnectedException {
|
|
||||||
LOG.info("Fetching categories");
|
LOG.info("Fetching categories");
|
||||||
if (dbManager.isConnected()) {
|
if (dbManager.isConnected()) {
|
||||||
Map<Integer, String> categories = new HashMap<Integer, String>();
|
Map<Integer, String> categories = new HashMap<Integer, String>();
|
||||||
ResultSet resultSet = dbManager.getResultSet(CATEGORY_SQL);
|
ResultSet resultSet = dbManager.getResultSet(CATEGORY_SQL);
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
categories.put(resultSet.getInt("category_id"), resultSet
|
categories.put(resultSet.getInt("category_id"), resultSet.getString("name"));
|
||||||
.getString("name"));
|
|
||||||
}
|
}
|
||||||
return categories;
|
return categories;
|
||||||
} else {
|
} else {
|
||||||
@@ -116,18 +111,17 @@ public class LibraryPresenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProjectEntity> fetchMyProjectRows()
|
public List<ProjectEntity> fetchMyProjectRows() throws NotLoggedInException,
|
||||||
throws NotLoggedInException, NotConnectedException, SQLException {
|
NotConnectedException, SQLException {
|
||||||
if (dbManager.isConnected()) {
|
if (dbManager.isConnected()) {
|
||||||
if (isLoggedIn()) {
|
if (isLoggedIn()) {
|
||||||
Map<Integer, String> categories = fetchCategories();
|
Map<Integer, String> categories = fetchCategories();
|
||||||
List<ProjectEntity> projects = new ArrayList<ProjectEntity>();
|
List<ProjectEntity> projects = new ArrayList<ProjectEntity>();
|
||||||
ResultSet resultSet = dbManager.getResultSet(String.format(
|
ResultSet resultSet = dbManager.getResultSet(String.format(MY_PROJECTS_SQL,
|
||||||
MY_PROJECTS_SQL, currentUserId));
|
currentUserId));
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
projects.add(new ProjectEntity(resultSet
|
projects.add(new ProjectEntity(resultSet.getInt("project_id"), resultSet
|
||||||
.getInt("project_id"), resultSet.getString("name"),
|
.getString("name"), resultSet.getString("description"), "", categories
|
||||||
resultSet.getString("description"), "", categories
|
|
||||||
.get(resultSet.getInt("category_id"))));
|
.get(resultSet.getInt("category_id"))));
|
||||||
}
|
}
|
||||||
return projects;
|
return projects;
|
||||||
@@ -141,16 +135,14 @@ public class LibraryPresenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String downloadProjectContent(int projectId)
|
public String downloadProjectContent(int projectId) throws NotConnectedException,
|
||||||
throws NotConnectedException, NotExistsException, SQLException {
|
NotExistsException, SQLException {
|
||||||
if (dbManager.isConnected()) {
|
if (dbManager.isConnected()) {
|
||||||
ResultSet resultSet = dbManager.getResultSet(String.format(
|
ResultSet resultSet = dbManager.getResultSet(String.format(PROJECT_SQL, projectId));
|
||||||
PROJECT_SQL, projectId));
|
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
return resultSet.getString("content");
|
return resultSet.getString("content");
|
||||||
}
|
}
|
||||||
throw new NotExistsException("Project with id = " + projectId
|
throw new NotExistsException("Project with id = " + projectId + " does not exist.");
|
||||||
+ " does not exist.");
|
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Not connected");
|
LOG.error("Not connected");
|
||||||
throw new NotConnectedException();
|
throw new NotConnectedException();
|
||||||
|
|||||||
+3
-6
@@ -82,15 +82,13 @@ public class LoginDialog extends ButtonDialog {
|
|||||||
this.password = new String(getPasswordField().getPassword());
|
this.password = new String(getPasswordField().getPassword());
|
||||||
|
|
||||||
JButton okButton = getButton(OK);
|
JButton okButton = getButton(OK);
|
||||||
okButton.setEnabled((this.userName.length() > 0)
|
okButton.setEnabled((this.userName.length() > 0) && (this.password.length() > 0));
|
||||||
&& (this.password.length() > 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JTextField getUserNameField() {
|
private JTextField getUserNameField() {
|
||||||
if (userNameField == null) {
|
if (userNameField == null) {
|
||||||
userNameField = new JTextField();
|
userNameField = new JTextField();
|
||||||
userNameField.getDocument().addDocumentListener(
|
userNameField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
new DocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
@@ -114,8 +112,7 @@ public class LoginDialog extends ButtonDialog {
|
|||||||
private JPasswordField getPasswordField() {
|
private JPasswordField getPasswordField() {
|
||||||
if (passwordField == null) {
|
if (passwordField == null) {
|
||||||
passwordField = new JPasswordField();
|
passwordField = new JPasswordField();
|
||||||
passwordField.getDocument().addDocumentListener(
|
passwordField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
new DocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
|||||||
+7
-12
@@ -100,8 +100,7 @@ public class NewUserDialog extends ButtonDialog {
|
|||||||
private void refreshState() {
|
private void refreshState() {
|
||||||
this.userName = getUserNameField().getText();
|
this.userName = getUserNameField().getText();
|
||||||
String password = new String(getPasswordField().getPassword());
|
String password = new String(getPasswordField().getPassword());
|
||||||
String confirmPassword = new String(getConfirmPasswordField()
|
String confirmPassword = new String(getConfirmPasswordField().getPassword());
|
||||||
.getPassword());
|
|
||||||
if (password.equals(confirmPassword)) {
|
if (password.equals(confirmPassword)) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
} else {
|
} else {
|
||||||
@@ -109,15 +108,14 @@ public class NewUserDialog extends ButtonDialog {
|
|||||||
}
|
}
|
||||||
this.email = getEmailField().getText();
|
this.email = getEmailField().getText();
|
||||||
JButton okButton = getButton(OK);
|
JButton okButton = getButton(OK);
|
||||||
okButton.setEnabled((this.userName.length() > 0)
|
okButton.setEnabled((this.userName.length() > 0) && (this.password != null)
|
||||||
&& (this.password != null) && (this.password.length() > 0));
|
&& (this.password.length() > 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private JTextField getUserNameField() {
|
private JTextField getUserNameField() {
|
||||||
if (userNameField == null) {
|
if (userNameField == null) {
|
||||||
userNameField = new JTextField();
|
userNameField = new JTextField();
|
||||||
userNameField.getDocument().addDocumentListener(
|
userNameField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
new DocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
@@ -141,8 +139,7 @@ public class NewUserDialog extends ButtonDialog {
|
|||||||
private JPasswordField getPasswordField() {
|
private JPasswordField getPasswordField() {
|
||||||
if (passwordField == null) {
|
if (passwordField == null) {
|
||||||
passwordField = new JPasswordField();
|
passwordField = new JPasswordField();
|
||||||
passwordField.getDocument().addDocumentListener(
|
passwordField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
new DocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
@@ -166,8 +163,7 @@ public class NewUserDialog extends ButtonDialog {
|
|||||||
private JPasswordField getConfirmPasswordField() {
|
private JPasswordField getConfirmPasswordField() {
|
||||||
if (confirmPasswordField == null) {
|
if (confirmPasswordField == null) {
|
||||||
confirmPasswordField = new JPasswordField();
|
confirmPasswordField = new JPasswordField();
|
||||||
confirmPasswordField.getDocument().addDocumentListener(
|
confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
new DocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
@@ -191,8 +187,7 @@ public class NewUserDialog extends ButtonDialog {
|
|||||||
private JTextField getEmailField() {
|
private JTextField getEmailField() {
|
||||||
if (emailField == null) {
|
if (emailField == null) {
|
||||||
emailField = new JTextField();
|
emailField = new JTextField();
|
||||||
emailField.getDocument().addDocumentListener(
|
emailField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
new DocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
|||||||
+3
-6
@@ -34,9 +34,7 @@ public class UploadDialog extends ButtonDialog {
|
|||||||
+ "You can <b>not</b> use Online Library to advertise products or services.<br>"
|
+ "You can <b>not</b> use Online Library to advertise products or services.<br>"
|
||||||
+ BULLET
|
+ BULLET
|
||||||
+ "Users that do not follow these terms may be banned from the server, with or without notice.<br>"
|
+ "Users that do not follow these terms may be banned from the server, with or without notice.<br>"
|
||||||
+ BULLET
|
+ BULLET + "Administrator is not responsible for library contents.<br>" + "</html>";
|
||||||
+ "Administrator is not responsible for library contents.<br>"
|
|
||||||
+ "</html>";
|
|
||||||
|
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private JLabel termsLabel;
|
private JLabel termsLabel;
|
||||||
@@ -98,9 +96,8 @@ public class UploadDialog extends ButtonDialog {
|
|||||||
termsLabel = new JLabel();
|
termsLabel = new JLabel();
|
||||||
termsLabel.setOpaque(true);
|
termsLabel.setOpaque(true);
|
||||||
termsLabel.setBackground(UIManager.getColor("ToolTip.background"));
|
termsLabel.setBackground(UIManager.getColor("ToolTip.background"));
|
||||||
termsLabel.setBorder(BorderFactory.createCompoundBorder(
|
termsLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
|
||||||
BorderFactory.createEtchedBorder(), BorderFactory
|
.createEtchedBorder(), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
|
||||||
.createEmptyBorder(2, 2, 2, 2)));
|
|
||||||
termsLabel.setText(TERMS_HTML);
|
termsLabel.setText(TERMS_HTML);
|
||||||
}
|
}
|
||||||
return termsLabel;
|
return termsLabel;
|
||||||
|
|||||||
+5
-10
@@ -49,8 +49,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
|
|
||||||
private JComboBox getZoomBox() {
|
private JComboBox getZoomBox() {
|
||||||
if (zoomBox == null) {
|
if (zoomBox == null) {
|
||||||
zoomBox = new JComboBox(new Double[] { 0.25d, 0.5d, 0.75d, 1d,
|
zoomBox = new JComboBox(new Double[] { 0.25d, 0.5d, 0.75d, 1d, 1.5d, 2d });
|
||||||
1.5d, 2d });
|
|
||||||
zoomBox.setSelectedItem(1d);
|
zoomBox.setSelectedItem(1d);
|
||||||
zoomBox.setFocusable(false);
|
zoomBox.setFocusable(false);
|
||||||
zoomBox.setRenderer(new PercentageListCellRenderer());
|
zoomBox.setRenderer(new PercentageListCellRenderer());
|
||||||
@@ -168,8 +167,7 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
|
|
||||||
private void refreshStatusText() {
|
private void refreshStatusText() {
|
||||||
if (componentSlot == null) {
|
if (componentSlot == null) {
|
||||||
if ((componentsUnderCursor == null)
|
if ((componentsUnderCursor == null) || (componentsUnderCursor.isEmpty())) {
|
||||||
|| (componentsUnderCursor.isEmpty())) {
|
|
||||||
getStatusLabel().setText("");
|
getStatusLabel().setText("");
|
||||||
} else {
|
} else {
|
||||||
String formattedNames = "";
|
String formattedNames = "";
|
||||||
@@ -178,17 +176,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
formattedNames += ", ";
|
formattedNames += ", ";
|
||||||
}
|
}
|
||||||
formattedNames += ComponentProcessor.getInstance()
|
formattedNames += ComponentProcessor.getInstance().extractBomName(component)
|
||||||
.extractBomName(component)
|
|
||||||
+ " (<b><font color=\"blue\">" + n++ + "</font></b>)";
|
+ " (<b><font color=\"blue\">" + n++ + "</font></b>)";
|
||||||
}
|
}
|
||||||
getStatusLabel().setText(
|
getStatusLabel().setText("<html>" + "Edit: " + formattedNames + "</html>");
|
||||||
"<html>" + "Edit: " + formattedNames + "</html>");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getStatusLabel().setText(
|
getStatusLabel().setText(
|
||||||
"Click on the canvas to create a new "
|
"Click on the canvas to create a new " + componentSlot.getName()
|
||||||
+ componentSlot.getName()
|
|
||||||
+ " or press Esc to cancel");
|
+ " or press Esc to cancel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -23,8 +23,7 @@ class ComponentButton extends JButton {
|
|||||||
private IPlugInPort plugInPort;
|
private IPlugInPort plugInPort;
|
||||||
private IComponentType componentType;
|
private IComponentType componentType;
|
||||||
|
|
||||||
public ComponentButton(final IPlugInPort plugInPort,
|
public ComponentButton(final IPlugInPort plugInPort, final IComponentType componentType) {
|
||||||
final IComponentType componentType) {
|
|
||||||
super(componentType.getIcon());
|
super(componentType.getIcon());
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
this.componentType = componentType;
|
this.componentType = componentType;
|
||||||
@@ -62,7 +61,7 @@ class ComponentButton extends JButton {
|
|||||||
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
|
DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
|
||||||
this,
|
this,
|
||||||
DnDConstants.ACTION_MOVE,
|
DnDConstants.ACTION_MOVE,
|
||||||
new ToolboxGestureListener(plugInPort, componentType
|
new ToolboxGestureListener(plugInPort, componentType.getComponentInstanceClass()
|
||||||
.getComponentInstanceClass().getName()));
|
.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -19,18 +19,15 @@ class ComponentTabbedPane extends JTabbedPane {
|
|||||||
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
public ComponentTabbedPane(IPlugInPort plugInPort) {
|
||||||
super();
|
super();
|
||||||
this.plugInPort = plugInPort;
|
this.plugInPort = plugInPort;
|
||||||
Map<String, List<IComponentType>> componentTypes = plugInPort
|
Map<String, List<IComponentType>> componentTypes = plugInPort.getComponentTypes();
|
||||||
.getComponentTypes();
|
for (Map.Entry<String, List<IComponentType>> entry : componentTypes.entrySet()) {
|
||||||
for (Map.Entry<String, List<IComponentType>> entry : componentTypes
|
|
||||||
.entrySet()) {
|
|
||||||
addTab(entry.getKey(), createComponentPanel(entry.getValue()));
|
addTab(entry.getKey(), createComponentPanel(entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Container createComponentPanel(List<IComponentType> componentTypes) {
|
private Container createComponentPanel(List<IComponentType> componentTypes) {
|
||||||
Container componentPanel = new Container();
|
Container componentPanel = new Container();
|
||||||
componentPanel
|
componentPanel.setLayout(new BoxLayout(componentPanel, BoxLayout.X_AXIS));
|
||||||
.setLayout(new BoxLayout(componentPanel, BoxLayout.X_AXIS));
|
|
||||||
for (IComponentType componentType : componentTypes) {
|
for (IComponentType componentType : componentTypes) {
|
||||||
JButton button = new ComponentButton(plugInPort, componentType);
|
JButton button = new ComponentButton(plugInPort, componentType);
|
||||||
componentPanel.add(button);
|
componentPanel.add(button);
|
||||||
|
|||||||
+1
-2
@@ -14,8 +14,7 @@ public class ToolBox implements IPlugIn {
|
|||||||
@Override
|
@Override
|
||||||
public void connect(IPlugInPort plugInPort) {
|
public void connect(IPlugInPort plugInPort) {
|
||||||
try {
|
try {
|
||||||
plugInPort.injectGUIComponent(new ComponentTabbedPane(plugInPort),
|
plugInPort.injectGUIComponent(new ComponentTabbedPane(plugInPort), SwingConstants.TOP);
|
||||||
SwingConstants.TOP);
|
|
||||||
} catch (BadPositionException e) {
|
} catch (BadPositionException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
+2
-3
@@ -26,8 +26,7 @@ class ToolboxGestureListener implements DragGestureListener {
|
|||||||
@Override
|
@Override
|
||||||
public void dragGestureRecognized(DragGestureEvent dge) {
|
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||||
presenter.dragStarted(dge.getDragOrigin());
|
presenter.dragStarted(dge.getDragOrigin());
|
||||||
dge.startDrag(Cursor.getDefaultCursor(),
|
dge.startDrag(Cursor.getDefaultCursor(), new StringSelection(className),
|
||||||
new StringSelection(className), new ToolboxSourceListener(
|
new ToolboxSourceListener(presenter));
|
||||||
presenter));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-29
@@ -20,8 +20,7 @@ import com.rits.cloning.Cloner;
|
|||||||
|
|
||||||
public class ComponentProcessor {
|
public class ComponentProcessor {
|
||||||
|
|
||||||
private static final Logger LOG = Logger
|
private static final Logger LOG = Logger.getLogger(ComponentProcessor.class);
|
||||||
.getLogger(ComponentProcessor.class);
|
|
||||||
|
|
||||||
private static ComponentProcessor instance;
|
private static ComponentProcessor instance;
|
||||||
|
|
||||||
@@ -44,8 +43,7 @@ public class ComponentProcessor {
|
|||||||
this.controlPointCache = new HashMap<Class<?>, List<ControlPointWrapper>>();
|
this.controlPointCache = new HashMap<Class<?>, List<ControlPointWrapper>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PropertyWrapper> extractProperties(
|
public List<PropertyWrapper> extractProperties(Class<? extends IComponentInstance> clazz) {
|
||||||
Class<? extends IComponentInstance> clazz) {
|
|
||||||
if (propertyCache.containsKey(clazz)) {
|
if (propertyCache.containsKey(clazz)) {
|
||||||
return cloner.deepClone(propertyCache.get(clazz));
|
return cloner.deepClone(propertyCache.get(clazz));
|
||||||
}
|
}
|
||||||
@@ -53,12 +51,10 @@ public class ComponentProcessor {
|
|||||||
for (Method method : clazz.getMethods()) {
|
for (Method method : clazz.getMethods()) {
|
||||||
if (method.getName().startsWith("get")) {
|
if (method.getName().startsWith("get")) {
|
||||||
try {
|
try {
|
||||||
Method setter = clazz.getMethod("set"
|
Method setter = clazz.getMethod("set" + method.getName().substring(3), method
|
||||||
+ method.getName().substring(3), method
|
|
||||||
.getReturnType());
|
.getReturnType());
|
||||||
if (method.isAnnotationPresent(EditableProperty.class)) {
|
if (method.isAnnotationPresent(EditableProperty.class)) {
|
||||||
EditableProperty annotation = method
|
EditableProperty annotation = method.getAnnotation(EditableProperty.class);
|
||||||
.getAnnotation(EditableProperty.class);
|
|
||||||
String name;
|
String name;
|
||||||
if (annotation.name().equals("")) {
|
if (annotation.name().equals("")) {
|
||||||
name = method.getName().substring(3);
|
name = method.getName().substring(3);
|
||||||
@@ -66,13 +62,12 @@ public class ComponentProcessor {
|
|||||||
name = annotation.name();
|
name = annotation.name();
|
||||||
}
|
}
|
||||||
PropertyWrapper property = new PropertyWrapper(name,
|
PropertyWrapper property = new PropertyWrapper(name,
|
||||||
method.getReturnType(), method, setter,
|
method.getReturnType(), method, setter, annotation.defaultable());
|
||||||
annotation.defaultable());
|
|
||||||
properties.add(property);
|
properties.add(property);
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
LOG.debug("No matching setter found for \""
|
LOG.debug("No matching setter found for \"" + method.getName()
|
||||||
+ method.getName() + "\". Skipping...");
|
+ "\". Skipping...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,8 +76,7 @@ public class ComponentProcessor {
|
|||||||
return cloner.deepClone(properties);
|
return cloner.deepClone(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ControlPointWrapper> extractControlPoints(
|
public List<ControlPointWrapper> extractControlPoints(Class<? extends IComponentInstance> clazz) {
|
||||||
Class<? extends IComponentInstance> clazz) {
|
|
||||||
if (controlPointCache.containsKey(clazz)) {
|
if (controlPointCache.containsKey(clazz)) {
|
||||||
return cloner.deepClone(controlPointCache.get(clazz));
|
return cloner.deepClone(controlPointCache.get(clazz));
|
||||||
}
|
}
|
||||||
@@ -90,27 +84,22 @@ public class ComponentProcessor {
|
|||||||
for (Method method : clazz.getMethods()) {
|
for (Method method : clazz.getMethods()) {
|
||||||
if (method.getName().startsWith("get")) {
|
if (method.getName().startsWith("get")) {
|
||||||
try {
|
try {
|
||||||
Method setter = clazz.getMethod("set"
|
Method setter = clazz.getMethod("set" + method.getName().substring(3), method
|
||||||
+ method.getName().substring(3), method
|
|
||||||
.getReturnType());
|
.getReturnType());
|
||||||
if (method.isAnnotationPresent(ControlPoint.class)) {
|
if (method.isAnnotationPresent(ControlPoint.class)) {
|
||||||
if (method.getReturnType().equals(Point.class)) {
|
if (method.getReturnType().equals(Point.class)) {
|
||||||
ControlPoint annotation = method
|
ControlPoint annotation = method.getAnnotation(ControlPoint.class);
|
||||||
.getAnnotation(ControlPoint.class);
|
ControlPointWrapper controlPoint = new ControlPointWrapper(method
|
||||||
ControlPointWrapper controlPoint = new ControlPointWrapper(
|
.getName().substring(3), method, setter, annotation.editable(),
|
||||||
method.getName().substring(3), method,
|
annotation.sticky(), annotation.visibilityPolicy());
|
||||||
setter, annotation.editable(), annotation
|
|
||||||
.sticky(), annotation
|
|
||||||
.visibilityPolicy());
|
|
||||||
controlPoints.add(controlPoint);
|
controlPoints.add(controlPoint);
|
||||||
} else {
|
} else {
|
||||||
LOG
|
LOG.debug("Control point return type must be java.awt.Point.");
|
||||||
.debug("Control point return type must be java.awt.Point.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
LOG.debug("No matching setter found for \""
|
LOG.debug("No matching setter found for \"" + method.getName()
|
||||||
+ method.getName() + "\". Skipping...");
|
+ "\". Skipping...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,8 +127,7 @@ public class ComponentProcessor {
|
|||||||
}
|
}
|
||||||
for (int i = 1; i < selectedComponents.size(); i++) {
|
for (int i = 1; i < selectedComponents.size(); i++) {
|
||||||
IComponentInstance component = selectedComponents.get(i);
|
IComponentInstance component = selectedComponents.get(i);
|
||||||
List<PropertyWrapper> newProperties = extractProperties(component
|
List<PropertyWrapper> newProperties = extractProperties(component.getClass());
|
||||||
.getClass());
|
|
||||||
for (PropertyWrapper property : newProperties) {
|
for (PropertyWrapper property : newProperties) {
|
||||||
try {
|
try {
|
||||||
property.readFrom(component);
|
property.readFrom(component);
|
||||||
|
|||||||
+31
-44
@@ -180,8 +180,7 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void drawString(AttributedCharacterIterator iterator, float x,
|
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
|
||||||
float y) {
|
|
||||||
canvasGraphics.drawString(iterator, x, y);
|
canvasGraphics.drawString(iterator, x, y);
|
||||||
// FIXME: process map
|
// FIXME: process map
|
||||||
}
|
}
|
||||||
@@ -441,8 +440,7 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void drawArc(int x, int y, int width, int height, int startAngle,
|
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
|
||||||
int arcAngle) {
|
|
||||||
canvasGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
|
canvasGraphics.drawArc(x, y, width, height, startAngle, arcAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -459,8 +457,7 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public boolean drawImage(Image img, int x, int y, Color bgcolor,
|
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
|
||||||
ImageObserver observer) {
|
|
||||||
// FIXME: map
|
// FIXME: map
|
||||||
return canvasGraphics.drawImage(img, x, y, bgcolor, observer);
|
return canvasGraphics.drawImage(img, x, y, bgcolor, observer);
|
||||||
}
|
}
|
||||||
@@ -469,8 +466,7 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public boolean drawImage(Image img, int x, int y, int width, int height,
|
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
|
||||||
ImageObserver observer) {
|
|
||||||
// FIXME: map
|
// FIXME: map
|
||||||
return canvasGraphics.drawImage(img, x, y, width, height, observer);
|
return canvasGraphics.drawImage(img, x, y, width, height, observer);
|
||||||
}
|
}
|
||||||
@@ -479,34 +475,30 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public boolean drawImage(Image img, int x, int y, int width, int height,
|
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor,
|
||||||
Color bgcolor, ImageObserver observer) {
|
|
||||||
// FIXME: map
|
|
||||||
return canvasGraphics.drawImage(img, x, y, width, height, bgcolor,
|
|
||||||
observer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*{@inheritDoc}
|
|
||||||
**/
|
|
||||||
@Override
|
|
||||||
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
|
|
||||||
int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
|
|
||||||
// FIXME: map
|
|
||||||
return canvasGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2,
|
|
||||||
sy2, observer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*{@inheritDoc}
|
|
||||||
**/
|
|
||||||
@Override
|
|
||||||
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2,
|
|
||||||
int sx1, int sy1, int sx2, int sy2, Color bgcolor,
|
|
||||||
ImageObserver observer) {
|
ImageObserver observer) {
|
||||||
// FIXME: map
|
// FIXME: map
|
||||||
return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor,
|
return canvasGraphics.drawImage(img, x, y, width, height, bgcolor, observer);
|
||||||
observer);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*{@inheritDoc}
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
|
||||||
|
int sx2, int sy2, ImageObserver observer) {
|
||||||
|
// FIXME: map
|
||||||
|
return canvasGraphics.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*{@inheritDoc}
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
|
||||||
|
int sx2, int sy2, Color bgcolor, ImageObserver observer) {
|
||||||
|
// FIXME: map
|
||||||
|
return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -545,8 +537,7 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void drawRoundRect(int x, int y, int width, int height,
|
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
|
||||||
int arcWidth, int arcHeight) {
|
|
||||||
canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
|
canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,11 +545,9 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void fillArc(int x, int y, int width, int height, int startAngle,
|
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
|
||||||
int arcAngle) {
|
|
||||||
canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
|
canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle);
|
||||||
appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle,
|
appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE));
|
||||||
Arc2D.PIE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -592,11 +581,9 @@ class G2DWrapper extends Graphics2D {
|
|||||||
*{@inheritDoc}
|
*{@inheritDoc}
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void fillRoundRect(int x, int y, int width, int height,
|
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
|
||||||
int arcWidth, int arcHeight) {
|
|
||||||
canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
|
canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
|
||||||
appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth,
|
appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight));
|
||||||
arcHeight));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+68
-108
@@ -55,8 +55,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
||||||
|
|
||||||
private static final VersionNumber CURRENT_VERSION = new VersionNumber(0,
|
private static final VersionNumber CURRENT_VERSION = new VersionNumber(0, 0, 0);
|
||||||
0, 0);
|
|
||||||
private static final String DEFAULTS_KEY = "defaults";
|
private static final String DEFAULTS_KEY = "defaults";
|
||||||
private static final int CONTROL_POINT_SENSITIVITY = 4;
|
private static final int CONTROL_POINT_SENSITIVITY = 4;
|
||||||
|
|
||||||
@@ -104,8 +103,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void installPlugin(IPlugIn plugIn) {
|
public void installPlugin(IPlugIn plugIn) {
|
||||||
LOG.debug(String.format("installPlugin(%s)", plugIn.getClass()
|
LOG.debug(String.format("installPlugin(%s)", plugIn.getClass().getSimpleName()));
|
||||||
.getSimpleName()));
|
|
||||||
plugIns.add(plugIn);
|
plugIns.add(plugIn);
|
||||||
plugIn.connect(this);
|
plugIn.connect(this);
|
||||||
messageDispatcher.registerListener(plugIn);
|
messageDispatcher.registerListener(plugIn);
|
||||||
@@ -135,10 +133,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
@Override
|
@Override
|
||||||
public Cursor getCursorAt(Point point) {
|
public Cursor getCursorAt(Point point) {
|
||||||
// Scale point to remove zoom factor.
|
// Scale point to remove zoom factor.
|
||||||
Point2D scaledPoint = new Point2D.Double(point.getX() / zoomLevel,
|
Point2D scaledPoint = new Point2D.Double(point.getX() / zoomLevel, point.getY() / zoomLevel);
|
||||||
point.getY() / zoomLevel);
|
for (Map.Entry<IComponentInstance, Area> entry : componentAreaMap.entrySet()) {
|
||||||
for (Map.Entry<IComponentInstance, Area> entry : componentAreaMap
|
|
||||||
.entrySet()) {
|
|
||||||
if (entry.getValue().contains(scaledPoint)) {
|
if (entry.getValue().contains(scaledPoint)) {
|
||||||
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
|
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
|
||||||
}
|
}
|
||||||
@@ -167,8 +163,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
LOG.info("Loading project: " + project.getTitle());
|
LOG.info("Loading project: " + project.getTitle());
|
||||||
this.currentProject = project;
|
this.currentProject = project;
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project,
|
messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart);
|
||||||
freshStart);
|
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,20 +172,17 @@ public class Presenter implements IPlugInPort {
|
|||||||
if (componentTypes == null) {
|
if (componentTypes == null) {
|
||||||
LOG.info("Loading component types.");
|
LOG.info("Loading component types.");
|
||||||
componentTypes = new HashMap<String, List<IComponentType>>();
|
componentTypes = new HashMap<String, List<IComponentType>>();
|
||||||
List<Class<?>> componentTypeClasses = JarScanner.getInstance()
|
List<Class<?>> componentTypeClasses = JarScanner.getInstance().scanFolder("library/",
|
||||||
.scanFolder("library/", IComponentType.class);
|
IComponentType.class);
|
||||||
for (Class<?> clazz : componentTypeClasses) {
|
for (Class<?> clazz : componentTypeClasses) {
|
||||||
try {
|
try {
|
||||||
IComponentType componentType = (IComponentType) clazz
|
IComponentType componentType = (IComponentType) clazz.newInstance();
|
||||||
.newInstance();
|
|
||||||
List<IComponentType> nestedList;
|
List<IComponentType> nestedList;
|
||||||
if (componentTypes.containsKey(componentType.getCategory())) {
|
if (componentTypes.containsKey(componentType.getCategory())) {
|
||||||
nestedList = componentTypes.get(componentType
|
nestedList = componentTypes.get(componentType.getCategory());
|
||||||
.getCategory());
|
|
||||||
} else {
|
} else {
|
||||||
nestedList = new ArrayList<IComponentType>();
|
nestedList = new ArrayList<IComponentType>();
|
||||||
componentTypes.put(componentType.getCategory(),
|
componentTypes.put(componentType.getCategory(), nestedList);
|
||||||
nestedList);
|
|
||||||
}
|
}
|
||||||
nestedList.add(componentType);
|
nestedList.add(componentType);
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
@@ -211,7 +203,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
G2DWrapper g2dWrapper = new G2DWrapper(g2d);
|
G2DWrapper g2dWrapper = new G2DWrapper(g2d);
|
||||||
|
|
||||||
if (drawOptions.contains(DrawOption.ANTIALIASING)) {
|
if (drawOptions.contains(DrawOption.ANTIALIASING)) {
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
g2d
|
||||||
|
.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,15 +229,13 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((drawOptions.contains(DrawOption.ZOOM))
|
if ((drawOptions.contains(DrawOption.ZOOM)) && (Math.abs(1.0 - zoomLevel) > 1e-4)) {
|
||||||
&& (Math.abs(1.0 - zoomLevel) > 1e-4)) {
|
|
||||||
g2dWrapper.scale(zoomLevel, zoomLevel);
|
g2dWrapper.scale(zoomLevel, zoomLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
g2dWrapper.resetTx();
|
g2dWrapper.resetTx();
|
||||||
|
|
||||||
List<IComponentInstance> components = getCurrentProject()
|
List<IComponentInstance> components = getCurrentProject().getComponents();
|
||||||
.getComponents();
|
|
||||||
componentAreaMap.clear();
|
componentAreaMap.clear();
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
for (IComponentInstance component : components) {
|
for (IComponentInstance component : components) {
|
||||||
@@ -253,14 +244,12 @@ public class Presenter implements IPlugInPort {
|
|||||||
.contains(DrawOption.SELECTION)) ? ComponentState.SELECTED
|
.contains(DrawOption.SELECTION)) ? ComponentState.SELECTED
|
||||||
: ComponentState.NORMAL;
|
: ComponentState.NORMAL;
|
||||||
component.draw(g2dWrapper, state);
|
component.draw(g2dWrapper, state);
|
||||||
componentAreaMap.put(component, g2dWrapper
|
componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent());
|
||||||
.finishedDrawingComponent());
|
|
||||||
|
|
||||||
// Draw control points
|
// Draw control points
|
||||||
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
if (drawOptions.contains(DrawOption.CONTROL_POINTS)) {
|
||||||
List<ControlPointWrapper> controlPoints = ComponentProcessor
|
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||||
.getInstance().extractControlPoints(
|
.extractControlPoints(component.getClass());
|
||||||
component.getClass());
|
|
||||||
for (ControlPointWrapper controlPoint : controlPoints) {
|
for (ControlPointWrapper controlPoint : controlPoints) {
|
||||||
try {
|
try {
|
||||||
controlPoint.readFrom(component);
|
controlPoint.readFrom(component);
|
||||||
@@ -273,8 +262,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
// .getValue().y - 2, 5, 5);
|
// .getValue().y - 2, 5, 5);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG
|
LOG.error("Could not obtain control points for component of type "
|
||||||
.error("Could not obtain control points for component of type "
|
|
||||||
+ component.getClass().getName());
|
+ component.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,8 +273,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
g2d.setTransform(initialTx);
|
g2d.setTransform(initialTx);
|
||||||
|
|
||||||
// At the end draw selection rectangle.
|
// At the end draw selection rectangle.
|
||||||
if (drawOptions.contains(DrawOption.SELECTION)
|
if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) {
|
||||||
&& (selectionRect != null)) {
|
|
||||||
g2d.setColor(Color.white);
|
g2d.setColor(Color.white);
|
||||||
g2d.drawRect(selectionRect.x, selectionRect.y, selectionRect.width,
|
g2d.drawRect(selectionRect.x, selectionRect.y, selectionRect.width,
|
||||||
selectionRect.height);
|
selectionRect.height);
|
||||||
@@ -298,8 +285,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectGUIComponent(JComponent component, int position)
|
public void injectGUIComponent(JComponent component, int position) throws BadPositionException {
|
||||||
throws BadPositionException {
|
|
||||||
view.addComponent(component, position);
|
view.addComponent(component, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,8 +307,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
*/
|
*/
|
||||||
private List<IComponentInstance> findComponentsAt(Point point) {
|
private List<IComponentInstance> findComponentsAt(Point point) {
|
||||||
List<IComponentInstance> components = new ArrayList<IComponentInstance>();
|
List<IComponentInstance> components = new ArrayList<IComponentInstance>();
|
||||||
for (Map.Entry<IComponentInstance, Area> entry : componentAreaMap
|
for (Map.Entry<IComponentInstance, Area> entry : componentAreaMap.entrySet()) {
|
||||||
.entrySet()) {
|
|
||||||
if (entry.getValue().contains(point)) {
|
if (entry.getValue().contains(point)) {
|
||||||
components.add(entry.getKey());
|
components.add(entry.getKey());
|
||||||
}
|
}
|
||||||
@@ -331,15 +316,13 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown,
|
public void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) {
|
||||||
boolean altDown) {
|
LOG.debug(String
|
||||||
LOG.debug(String.format("mouseClicked(%s, %s, %s, %s)", point,
|
.format("mouseClicked(%s, %s, %s, %s)", point, ctrlDown, shiftDown, altDown));
|
||||||
ctrlDown, shiftDown, altDown));
|
|
||||||
Point scaledPoint = scalePoint(point);
|
Point scaledPoint = scalePoint(point);
|
||||||
if (componentSlot != null) {
|
if (componentSlot != null) {
|
||||||
try {
|
try {
|
||||||
instantiateComponent(componentSlot.getComponentInstanceClass(),
|
instantiateComponent(componentSlot.getComponentInstanceClass(), scaledPoint);
|
||||||
scaledPoint);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error instatiating component of type: "
|
LOG.error("Error instatiating component of type: "
|
||||||
+ componentSlot.getComponentInstanceClass().getName());
|
+ componentSlot.getComponentInstanceClass().getName());
|
||||||
@@ -366,8 +349,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
selectedComponents.add(component);
|
selectedComponents.add(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
selectedComponents);
|
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,8 +359,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
List<IComponentInstance> components = new ArrayList<IComponentInstance>();
|
List<IComponentInstance> components = new ArrayList<IComponentInstance>();
|
||||||
Point scaledPoint = scalePoint(point);
|
Point scaledPoint = scalePoint(point);
|
||||||
for (IComponentInstance component : currentProject.getComponents()) {
|
for (IComponentInstance component : currentProject.getComponents()) {
|
||||||
List<ControlPointWrapper> currentPoints = ComponentProcessor
|
List<ControlPointWrapper> currentPoints = ComponentProcessor.getInstance()
|
||||||
.getInstance().extractControlPoints(component.getClass());
|
.extractControlPoints(component.getClass());
|
||||||
for (ControlPointWrapper controlPoint : currentPoints) {
|
for (ControlPointWrapper controlPoint : currentPoints) {
|
||||||
if (shouldShowControlPoint(controlPoint, component)) {
|
if (shouldShowControlPoint(controlPoint, component)) {
|
||||||
try {
|
try {
|
||||||
@@ -388,8 +370,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG
|
LOG.warn("Error reading control point for component of type: "
|
||||||
.warn("Error reading control point for component of type: "
|
|
||||||
+ component.getClass().getName());
|
+ component.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,8 +378,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
if (!components.equals(componentsUnderCursor)) {
|
if (!components.equals(componentsUnderCursor)) {
|
||||||
componentsUnderCursor = components;
|
componentsUnderCursor = components;
|
||||||
messageDispatcher.dispatchMessage(
|
messageDispatcher.dispatchMessage(EventType.AVAILABLE_CTRL_POINTS_CHANGED, components);
|
||||||
EventType.AVAILABLE_CTRL_POINTS_CHANGED, components);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,16 +406,14 @@ public class Presenter implements IPlugInPort {
|
|||||||
List<IComponentInstance> components = findComponentsAt(scaledPoint);
|
List<IComponentInstance> components = findComponentsAt(scaledPoint);
|
||||||
if (components.isEmpty()) {
|
if (components.isEmpty()) {
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
selectedComponents);
|
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
} else {
|
} else {
|
||||||
IComponentInstance component = components.get(0);
|
IComponentInstance component = components.get(0);
|
||||||
if (!selectedComponents.contains(component)) {
|
if (!selectedComponents.contains(component)) {
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
selectedComponents.add(component);
|
selectedComponents.add(component);
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
selectedComponents);
|
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,8 +423,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
public boolean dragOver(Point point) {
|
public boolean dragOver(Point point) {
|
||||||
if (selectedComponents.isEmpty()) {
|
if (selectedComponents.isEmpty()) {
|
||||||
this.selectionRect = Utils.createRectangle(point, dragStartPoint);
|
this.selectionRect = Utils.createRectangle(point, dragStartPoint);
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED, selectionRect);
|
||||||
selectionRect);
|
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -462,23 +439,20 @@ public class Presenter implements IPlugInPort {
|
|||||||
// If there's no selection finalize selectionRect and see which
|
// If there's no selection finalize selectionRect and see which
|
||||||
// components intersect with it.
|
// components intersect with it.
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
this.selectionRect = Utils.createRectangle(point,
|
this.selectionRect = Utils.createRectangle(point, dragStartPoint);
|
||||||
dragStartPoint);
|
|
||||||
}
|
}
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
for (IComponentInstance component : currentProject.getComponents()) {
|
for (IComponentInstance component : currentProject.getComponents()) {
|
||||||
Area area = componentAreaMap.get(component);
|
Area area = componentAreaMap.get(component);
|
||||||
if ((area != null)
|
if ((area != null)
|
||||||
&& area.intersects(selectionRect.x / zoomLevel,
|
&& area.intersects(selectionRect.x / zoomLevel,
|
||||||
selectionRect.y / zoomLevel,
|
selectionRect.y / zoomLevel, selectionRect.width / zoomLevel,
|
||||||
selectionRect.width / zoomLevel,
|
|
||||||
selectionRect.height / zoomLevel)) {
|
selectionRect.height / zoomLevel)) {
|
||||||
selectedComponents.add(component);
|
selectedComponents.add(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectionRect = null;
|
selectionRect = null;
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED,
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents);
|
||||||
selectedComponents);
|
|
||||||
} else {
|
} else {
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
|
|
||||||
@@ -486,9 +460,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
int dx = (int) ((point.x - dragStartPoint.x) / zoomLevel);
|
int dx = (int) ((point.x - dragStartPoint.x) / zoomLevel);
|
||||||
int dy = (int) ((point.y - dragStartPoint.y) / zoomLevel);
|
int dy = (int) ((point.y - dragStartPoint.y) / zoomLevel);
|
||||||
for (IComponentInstance component : selectedComponents) {
|
for (IComponentInstance component : selectedComponents) {
|
||||||
List<ControlPointWrapper> controlPoints = ComponentProcessor
|
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||||
.getInstance().extractControlPoints(
|
.extractControlPoints(component.getClass());
|
||||||
component.getClass());
|
|
||||||
for (ControlPointWrapper controlPoint : controlPoints) {
|
for (ControlPointWrapper controlPoint : controlPoints) {
|
||||||
try {
|
try {
|
||||||
controlPoint.readFrom(component);
|
controlPoint.readFrom(component);
|
||||||
@@ -497,14 +470,13 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
controlPoint.writeTo(component);
|
controlPoint.writeTo(component);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Could not translate control points: "
|
LOG.error("Could not translate control points: " + e.getMessage());
|
||||||
+ e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!oldProject.equals(currentProject)) {
|
if (!oldProject.equals(currentProject)) {
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
oldProject, cloner.deepClone(currentProject), "Move");
|
.deepClone(currentProject), "Move");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
@@ -512,13 +484,12 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addComponents(List<IComponentInstance> components,
|
public void addComponents(List<IComponentInstance> components, Point preferredPoint) {
|
||||||
Point preferredPoint) {
|
|
||||||
LOG.debug(String.format("addComponents(%s)", components));
|
LOG.debug(String.format("addComponents(%s)", components));
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
currentProject.getComponents().addAll(components);
|
currentProject.getComponents().addAll(components);
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
oldProject, cloner.deepClone(currentProject), "Add");
|
.deepClone(currentProject), "Add");
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,27 +529,23 @@ public class Presenter implements IPlugInPort {
|
|||||||
// componentClass.getName() + ":" + propertyName);
|
// componentClass.getName() + ":" + propertyName);
|
||||||
// }
|
// }
|
||||||
public void setDefaultPropertyValue(String propertyName, Object value) {
|
public void setDefaultPropertyValue(String propertyName, Object value) {
|
||||||
LOG.debug(String.format("setDefaultPropertyValue(%s, %s)",
|
LOG.debug(String.format("setDefaultPropertyValue(%s, %s)", propertyName, value));
|
||||||
propertyName, value));
|
Map<String, Object> defaultMap = (Map<String, Object>) ConfigurationManager.getInstance()
|
||||||
Map<String, Object> defaultMap = (Map<String, Object>) ConfigurationManager
|
.getConfigurationItem(DEFAULTS_KEY);
|
||||||
.getInstance().getConfigurationItem(DEFAULTS_KEY);
|
|
||||||
if (defaultMap == null) {
|
if (defaultMap == null) {
|
||||||
defaultMap = new HashMap<String, Object>();
|
defaultMap = new HashMap<String, Object>();
|
||||||
ConfigurationManager.getInstance().setConfigurationItem(
|
ConfigurationManager.getInstance().setConfigurationItem(DEFAULTS_KEY, defaultMap);
|
||||||
DEFAULTS_KEY, defaultMap);
|
|
||||||
}
|
}
|
||||||
for (IComponentInstance component : selectedComponents) {
|
for (IComponentInstance component : selectedComponents) {
|
||||||
String className = component.getClass().getName();
|
String className = component.getClass().getName();
|
||||||
LOG.debug("Default property value set for " + className + ":"
|
LOG.debug("Default property value set for " + className + ":" + propertyName);
|
||||||
+ propertyName);
|
|
||||||
defaultMap.put(className + ":" + propertyName, value);
|
defaultMap.put(className + ":" + propertyName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void instantiateComponent(
|
private void instantiateComponent(Class<? extends IComponentInstance> componentClass,
|
||||||
Class<? extends IComponentInstance> componentClass, Point point)
|
Point point) throws Exception {
|
||||||
throws Exception {
|
|
||||||
LOG.info("Instatiating component of type: " + componentClass.getName());
|
LOG.info("Instatiating component of type: " + componentClass.getName());
|
||||||
|
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
@@ -589,8 +556,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
currentProject.getComponents().add(component);
|
currentProject.getComponents().add(component);
|
||||||
|
|
||||||
// Extract control points.
|
// Extract control points.
|
||||||
List<ControlPointWrapper> controlPoints = ComponentProcessor
|
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||||
.getInstance().extractControlPoints(componentClass);
|
.extractControlPoints(componentClass);
|
||||||
// Translate them to the desired location.
|
// Translate them to the desired location.
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
for (ControlPointWrapper controlPoint : controlPoints) {
|
for (ControlPointWrapper controlPoint : controlPoints) {
|
||||||
@@ -601,16 +568,15 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract properties.
|
// Extract properties.
|
||||||
List<PropertyWrapper> properties = ComponentProcessor.getInstance()
|
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
||||||
.extractProperties(componentClass);
|
componentClass);
|
||||||
// Override with default values if available.
|
// Override with default values if available.
|
||||||
for (PropertyWrapper property : properties) {
|
for (PropertyWrapper property : properties) {
|
||||||
Object defaultValue = null;
|
Object defaultValue = null;
|
||||||
Map<String, Object> defaultMap = (Map<String, Object>) ConfigurationManager
|
Map<String, Object> defaultMap = (Map<String, Object>) ConfigurationManager
|
||||||
.getInstance().getConfigurationItem(DEFAULTS_KEY);
|
.getInstance().getConfigurationItem(DEFAULTS_KEY);
|
||||||
if (defaultMap != null) {
|
if (defaultMap != null) {
|
||||||
defaultValue = defaultMap.get(componentClass.getName() + ":"
|
defaultValue = defaultMap.get(componentClass.getName() + ":" + property.getName());
|
||||||
+ property.getName());
|
|
||||||
}
|
}
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
property.setValue(cloner.deepClone(defaultValue));
|
property.setValue(cloner.deepClone(defaultValue));
|
||||||
@@ -620,21 +586,19 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
// Notify the listeners.
|
// Notify the listeners.
|
||||||
if (!oldProject.equals(currentProject)) {
|
if (!oldProject.equals(currentProject)) {
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
oldProject, cloner.deepClone(currentProject), "Create");
|
.deepClone(currentProject), "Create");
|
||||||
}
|
}
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PropertyWrapper> getMutualSelectionProperties() {
|
public List<PropertyWrapper> getMutualSelectionProperties() {
|
||||||
return ComponentProcessor.getInstance().getMutualSelectionProperties(
|
return ComponentProcessor.getInstance().getMutualSelectionProperties(selectedComponents);
|
||||||
selectedComponents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyPropertiesToSelection(List<PropertyWrapper> properties)
|
public void applyPropertiesToSelection(List<PropertyWrapper> properties) throws Exception {
|
||||||
throws Exception {
|
|
||||||
LOG.debug(String.format("applyPropertiesToSelection(%s)", properties));
|
LOG.debug(String.format("applyPropertiesToSelection(%s)", properties));
|
||||||
Project oldProject = cloner.deepClone(currentProject);
|
Project oldProject = cloner.deepClone(currentProject);
|
||||||
try {
|
try {
|
||||||
@@ -646,8 +610,8 @@ public class Presenter implements IPlugInPort {
|
|||||||
} finally {
|
} finally {
|
||||||
// Notify the listeners.
|
// Notify the listeners.
|
||||||
if (!oldProject.equals(currentProject)) {
|
if (!oldProject.equals(currentProject)) {
|
||||||
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED,
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner
|
||||||
oldProject, cloner.deepClone(currentProject), "Edit");
|
.deepClone(currentProject), "Edit");
|
||||||
}
|
}
|
||||||
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
}
|
}
|
||||||
@@ -655,26 +619,22 @@ public class Presenter implements IPlugInPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNewComponentSlot(IComponentType componentType) {
|
public void setNewComponentSlot(IComponentType componentType) {
|
||||||
LOG.debug(String.format("setNewComponentSlot(%s)",
|
LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null
|
||||||
componentType == null ? null : componentType.getName()));
|
: componentType.getName()));
|
||||||
this.componentSlot = componentType;
|
this.componentSlot = componentType;
|
||||||
selectedComponents.clear();
|
selectedComponents.clear();
|
||||||
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED);
|
messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED);
|
||||||
messageDispatcher
|
messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentSlot);
|
||||||
.dispatchMessage(EventType.SLOT_CHANGED, componentSlot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point scalePoint(Point point) {
|
private Point scalePoint(Point point) {
|
||||||
return new Point((int) (point.x / zoomLevel),
|
return new Point((int) (point.x / zoomLevel), (int) (point.y / zoomLevel));
|
||||||
(int) (point.y / zoomLevel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldShowControlPoint(ControlPointWrapper controlPoint,
|
private boolean shouldShowControlPoint(ControlPointWrapper controlPoint,
|
||||||
IComponentInstance component) {
|
IComponentInstance component) {
|
||||||
return controlPoint.getVisibilityPolicy().equals(
|
return controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.ALWAYS)
|
||||||
VisibilityPolicy.ALWAYS)
|
|| ((controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.WHEN_SELECTED)) && (getSelectedComponents()
|
||||||
|| ((controlPoint.getVisibilityPolicy()
|
|
||||||
.equals(VisibilityPolicy.WHEN_SELECTED)) && (getSelectedComponents()
|
|
||||||
.contains(component)));
|
.contains(component)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -7,12 +7,10 @@ import java.awt.Toolkit;
|
|||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
public static final float GRID = Toolkit.getDefaultToolkit()
|
public static final float GRID = Toolkit.getDefaultToolkit().getScreenResolution() / 10f;
|
||||||
.getScreenResolution() / 10f;
|
|
||||||
|
|
||||||
public static final Color GRID_COLOR = new Color(240, 240, 240);
|
public static final Color GRID_COLOR = new Color(240, 240, 240);
|
||||||
|
|
||||||
public static final Stroke dashedStroke = new BasicStroke(1.0f,
|
public static final Stroke dashedStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
|
||||||
BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f,
|
BasicStroke.JOIN_MITER, 2.0f, new float[] { 2.0f }, 0.0f);
|
||||||
new float[] { 2.0f }, 0.0f);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+133
-101
@@ -26,17 +26,19 @@ import javax.swing.JLayeredPane;
|
|||||||
import javax.swing.RootPaneContainer;
|
import javax.swing.RootPaneContainer;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
/** Provide a method for consistently augmenting the appearance of a given
|
/**
|
||||||
* component by painting something on it <i>after</i> the component itself
|
* Provide a method for consistently augmenting the appearance of a given
|
||||||
* gets painted. If not explicitly removed via {@link #dispose}, an instance
|
* component by painting something on it <i>after</i> the component itself gets
|
||||||
* of this object will live as long as its target component.<p>
|
* painted. If not explicitly removed via {@link #dispose}, an instance of this
|
||||||
|
* object will live as long as its target component.
|
||||||
|
* <p>
|
||||||
* By default, the decorator matches the location and size of the decorated
|
* By default, the decorator matches the location and size of the decorated
|
||||||
* component, but the bounds can be adjusted by overriding
|
* component, but the bounds can be adjusted by overriding
|
||||||
* {@link #getDecorationBounds()}. The {@link #synch()} method should be called
|
* {@link #getDecorationBounds()}. The {@link #synch()} method should be called
|
||||||
* whenever the bounds returned by {@link #getDecorationBounds()} would change.
|
* whenever the bounds returned by {@link #getDecorationBounds()} would change.
|
||||||
* <p>
|
* <p>
|
||||||
* The decoration is clipped to the bounds set on the decoration, which does
|
* The decoration is clipped to the bounds set on the decoration, which does not
|
||||||
* not necessarily need to be the same as the decorated component bounds. The
|
* necessarily need to be the same as the decorated component bounds. The
|
||||||
* decoration may extend beyond the decorated component bounds, or it may be
|
* decoration may extend beyond the decorated component bounds, or it may be
|
||||||
* reduced to a smaller region.
|
* reduced to a smaller region.
|
||||||
*/
|
*/
|
||||||
@@ -49,8 +51,9 @@ public abstract class AbstractComponentDecorator {
|
|||||||
public static final int TOP = 0;
|
public static final int TOP = 0;
|
||||||
// Disabled for now, since it doesn't work properly
|
// Disabled for now, since it doesn't work properly
|
||||||
private static final int BOTTOM = -1;
|
private static final int BOTTOM = -1;
|
||||||
/** Account for the difference between the decorator actual origin
|
/**
|
||||||
* and the logical origin we want to pass to the {@link #paint} method.
|
* Account for the difference between the decorator actual origin and the
|
||||||
|
* logical origin we want to pass to the {@link #paint} method.
|
||||||
*/
|
*/
|
||||||
private Point originOffset = new Point(0, 0);
|
private Point originOffset = new Point(0, 0);
|
||||||
|
|
||||||
@@ -67,19 +70,23 @@ public abstract class AbstractComponentDecorator {
|
|||||||
this(c, 1);
|
this(c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a decorator for the given component, indicating the layer
|
/**
|
||||||
* offset from the target component. Negative values mean the decoration
|
* Create a decorator for the given component, indicating the layer offset
|
||||||
* is painted <em>before</em> the target component is painted.
|
* from the target component. Negative values mean the decoration is painted
|
||||||
|
* <em>before</em> the target component is painted.
|
||||||
*/
|
*/
|
||||||
public AbstractComponentDecorator(JComponent c, int layerOffset) {
|
public AbstractComponentDecorator(JComponent c, int layerOffset) {
|
||||||
this(c, layerOffset, TOP);
|
this(c, layerOffset, TOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a decorator with the given position within its layer.
|
/**
|
||||||
* Use {@link #TOP} to cover other decorations, or {@link #BOTTOM}
|
* Create a decorator with the given position within its layer. Use
|
||||||
* to be covered by other decorations.<p>
|
* {@link #TOP} to cover other decorations, or {@link #BOTTOM} to be covered
|
||||||
* WARNING: BOTTOM doesn't currently work, probably a JLayeredPane bug
|
* by other decorations.
|
||||||
* in either the code or documentation.
|
* <p>
|
||||||
|
* WARNING: BOTTOM doesn't currently work, probably a JLayeredPane bug in
|
||||||
|
* either the code or documentation.
|
||||||
|
*
|
||||||
* @see JLayeredPane
|
* @see JLayeredPane
|
||||||
*/
|
*/
|
||||||
public AbstractComponentDecorator(JComponent c, int layerOffset, int position) {
|
public AbstractComponentDecorator(JComponent c, int layerOffset, int position) {
|
||||||
@@ -96,33 +103,40 @@ public abstract class AbstractComponentDecorator {
|
|||||||
attach();
|
attach();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the text to be displayed when the mouse is over the decoration.
|
/**
|
||||||
|
* Set the text to be displayed when the mouse is over the decoration.
|
||||||
|
*
|
||||||
* @see JComponent#setToolTipText(String)
|
* @see JComponent#setToolTipText(String)
|
||||||
*/
|
*/
|
||||||
public void setToolTipText(String text) {
|
public void setToolTipText(String text) {
|
||||||
painter.setToolTipText(text);
|
painter.setToolTipText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the currently set default tooltip text.
|
/**
|
||||||
|
* Return the currently set default tooltip text.
|
||||||
|
*
|
||||||
* @see JComponent#setToolTipText
|
* @see JComponent#setToolTipText
|
||||||
*/
|
*/
|
||||||
public String getToolTipText() {
|
public String getToolTipText() {
|
||||||
return painter.getToolTipText();
|
return painter.getToolTipText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provide for different tool tips depending on the actual location
|
/**
|
||||||
* over the decoration. Note that if you <em>only</em> override this
|
* Provide for different tool tips depending on the actual location over the
|
||||||
* method, you must also invoke {@link #setToolTipText(String)} with
|
* decoration. Note that if you <em>only</em> override this method, you must
|
||||||
* a non-<span class="javakeyword">null</span> argument.
|
* also invoke {@link #setToolTipText(String)} with a non-<span
|
||||||
|
* class="javakeyword">null</span> argument.
|
||||||
|
*
|
||||||
* @see JComponent#getToolTipText(MouseEvent)
|
* @see JComponent#getToolTipText(MouseEvent)
|
||||||
*/
|
*/
|
||||||
public String getToolTipText(MouseEvent e) {
|
public String getToolTipText(MouseEvent e) {
|
||||||
return getToolTipText();
|
return getToolTipText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Indicate whether any of the decoration is visible. The decoration
|
/**
|
||||||
* may be clipped by ancestor scroll panes or by being moved outside
|
* Indicate whether any of the decoration is visible. The decoration may be
|
||||||
* if the visible region of its parent window.
|
* clipped by ancestor scroll panes or by being moved outside if the visible
|
||||||
|
* region of its parent window.
|
||||||
*/
|
*/
|
||||||
public boolean isVisible() {
|
public boolean isVisible() {
|
||||||
return painter.isVisible();
|
return painter.isVisible();
|
||||||
@@ -142,12 +156,10 @@ public abstract class AbstractComponentDecorator {
|
|||||||
if (this instanceof BackgroundPainter) {
|
if (this instanceof BackgroundPainter) {
|
||||||
layer = ((BackgroundPainter) this).layer;
|
layer = ((BackgroundPainter) this).layer;
|
||||||
painter.setDecoratedLayer(layer);
|
painter.setDecoratedLayer(layer);
|
||||||
}
|
} else if (layeredChild == lp) {
|
||||||
else if (layeredChild == lp) {
|
|
||||||
// Is this the best layer to use?
|
// Is this the best layer to use?
|
||||||
painter.setDecoratedLayer(layer);
|
painter.setDecoratedLayer(layer);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
while (layeredChild.getParent() != lp) {
|
while (layeredChild.getParent() != lp) {
|
||||||
layeredChild = layeredChild.getParent();
|
layeredChild = layeredChild.getParent();
|
||||||
}
|
}
|
||||||
@@ -159,8 +171,8 @@ public abstract class AbstractComponentDecorator {
|
|||||||
// layer.
|
// layer.
|
||||||
layer = base + layerOffset;
|
layer = base + layerOffset;
|
||||||
if (layerOffset < 0) {
|
if (layerOffset < 0) {
|
||||||
BackgroundPainter bp = (BackgroundPainter)
|
BackgroundPainter bp = (BackgroundPainter) lp
|
||||||
lp.getClientProperty(BackgroundPainter.key(base));
|
.getClientProperty(BackgroundPainter.key(base));
|
||||||
if (bp == null) {
|
if (bp == null) {
|
||||||
bp = new BackgroundPainter(lp, base);
|
bp = new BackgroundPainter(lp, base);
|
||||||
}
|
}
|
||||||
@@ -168,8 +180,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
painter.setDecoratedLayer(base);
|
painter.setDecoratedLayer(base);
|
||||||
}
|
}
|
||||||
lp.add(painter, new Integer(layer), position);
|
lp.add(painter, new Integer(layer), position);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Always detach when the target component's window is null
|
// Always detach when the target component's window is null
|
||||||
// or is not a suitable container,
|
// or is not a suitable container,
|
||||||
// otherwise we might prevent GC of the component
|
// otherwise we might prevent GC of the component
|
||||||
@@ -189,8 +200,9 @@ public abstract class AbstractComponentDecorator {
|
|||||||
synch();
|
synch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ensure the size of the decorator matches the current
|
/**
|
||||||
* decoration bounds with appropriate clipping to viewports.
|
* Ensure the size of the decorator matches the current decoration bounds
|
||||||
|
* with appropriate clipping to viewports.
|
||||||
*/
|
*/
|
||||||
protected void synch() {
|
protected void synch() {
|
||||||
Container painterParent = painter.getParent();
|
Container painterParent = painter.getParent();
|
||||||
@@ -198,13 +210,12 @@ public abstract class AbstractComponentDecorator {
|
|||||||
Rectangle decorated = getDecorationBounds();
|
Rectangle decorated = getDecorationBounds();
|
||||||
Rectangle clipRect = clipDecorationBounds(decorated);
|
Rectangle clipRect = clipDecorationBounds(decorated);
|
||||||
|
|
||||||
Point pt = SwingUtilities.convertPoint(component, clipRect.x, clipRect.y,
|
Point pt = SwingUtilities
|
||||||
painterParent);
|
.convertPoint(component, clipRect.x, clipRect.y, painterParent);
|
||||||
if (clipRect.width <= 0 || clipRect.height <= 0) {
|
if (clipRect.width <= 0 || clipRect.height <= 0) {
|
||||||
setPainterBounds(-1, -1, 0, 0);
|
setPainterBounds(-1, -1, 0, 0);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setPainterBounds(pt.x, pt.y, clipRect.width, clipRect.height);
|
setPainterBounds(pt.x, pt.y, clipRect.width, clipRect.height);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
@@ -212,9 +223,10 @@ public abstract class AbstractComponentDecorator {
|
|||||||
painter.repaint();
|
painter.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adjust the painting offsets and size of the decoration to
|
/**
|
||||||
* account for ancestor clipping. This might be due to scroll panes
|
* Adjust the painting offsets and size of the decoration to account for
|
||||||
* or having the decoration lie outside the parent layered pane.
|
* ancestor clipping. This might be due to scroll panes or having the
|
||||||
|
* decoration lie outside the parent layered pane.
|
||||||
*/
|
*/
|
||||||
protected Rectangle clipDecorationBounds(Rectangle decorated) {
|
protected Rectangle clipDecorationBounds(Rectangle decorated) {
|
||||||
// Amount we have to translate the Graphics context
|
// Amount we have to translate the Graphics context
|
||||||
@@ -233,26 +245,24 @@ public abstract class AbstractComponentDecorator {
|
|||||||
return clipRect;
|
return clipRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return any clipping rectangle detected above the given component,
|
/**
|
||||||
* in the coordinate space of the given component. The given rectangle
|
* Return any clipping rectangle detected above the given component, in the
|
||||||
* is desired to be visible.
|
* coordinate space of the given component. The given rectangle is desired
|
||||||
|
* to be visible.
|
||||||
*/
|
*/
|
||||||
private Rectangle getClippingRect(Container component, Rectangle desired) {
|
private Rectangle getClippingRect(Container component, Rectangle desired) {
|
||||||
Rectangle clip = component instanceof JComponent
|
Rectangle clip = component instanceof JComponent ? ((JComponent) component)
|
||||||
? ((JComponent)component).getVisibleRect()
|
.getVisibleRect()
|
||||||
: new Rectangle(0, 0, component.getWidth(), component.getHeight());
|
: new Rectangle(0, 0, component.getWidth(), component.getHeight());
|
||||||
if (desired.x >= clip.x && desired.y >= clip.y
|
if (desired.x >= clip.x && desired.y >= clip.y
|
||||||
&& desired.x + desired.width <= clip.x + clip.width
|
&& desired.x + desired.width <= clip.x + clip.width
|
||||||
&& desired.y + desired.height <= clip.y + clip.height) {
|
&& desired.y + desired.height <= clip.y + clip.height) {
|
||||||
// desired rect is within the current clip rect
|
// desired rect is within the current clip rect
|
||||||
}
|
} else if (component.getParent() != null) {
|
||||||
else if (component.getParent() != null) {
|
|
||||||
// Only apply the clip if it is actually smaller than the
|
// Only apply the clip if it is actually smaller than the
|
||||||
// component's visible area
|
// component's visible area
|
||||||
if (component != painter.getParent()
|
if (component != painter.getParent() && clip.x > 0 && clip.y > 0
|
||||||
&& clip.x > 0 && clip.y > 0
|
&& clip.width < component.getWidth() && clip.height < component.getHeight()) {
|
||||||
&& clip.width < component.getWidth()
|
|
||||||
&& clip.height < component.getHeight()) {
|
|
||||||
// Don't alter the original rectangle
|
// Don't alter the original rectangle
|
||||||
desired = new Rectangle(desired);
|
desired = new Rectangle(desired);
|
||||||
// Check for clipping further up the hierarchy
|
// Check for clipping further up the hierarchy
|
||||||
@@ -266,32 +276,33 @@ public abstract class AbstractComponentDecorator {
|
|||||||
return clip;
|
return clip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the bounds, relative to the decorated component, of the
|
/**
|
||||||
* decoration. The default covers the entire component. Note that
|
* Return the bounds, relative to the decorated component, of the
|
||||||
* this method will be called from the constructor, so be careful
|
* decoration. The default covers the entire component. Note that this
|
||||||
* when overriding and referencing derived class state.
|
* method will be called from the constructor, so be careful when overriding
|
||||||
|
* and referencing derived class state.
|
||||||
*/
|
*/
|
||||||
protected Rectangle getDecorationBounds() {
|
protected Rectangle getDecorationBounds() {
|
||||||
return bounds != DEFAULT_BOUNDS
|
return bounds != DEFAULT_BOUNDS ? bounds : new Rectangle(0, 0, component.getWidth(),
|
||||||
? bounds : new Rectangle(0, 0, component.getWidth(), component.getHeight());
|
component.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Change the bounds of the decoration, relative to the decorated
|
/**
|
||||||
* component. The special value {@link #DEFAULT_BOUNDS} means the bounds
|
* Change the bounds of the decoration, relative to the decorated component.
|
||||||
* will track the component bounds.
|
* The special value {@link #DEFAULT_BOUNDS} means the bounds will track the
|
||||||
|
* component bounds.
|
||||||
*/
|
*/
|
||||||
public void setDecorationBounds(Rectangle bounds) {
|
public void setDecorationBounds(Rectangle bounds) {
|
||||||
if (bounds == DEFAULT_BOUNDS) {
|
if (bounds == DEFAULT_BOUNDS) {
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.bounds = new Rectangle(bounds);
|
this.bounds = new Rectangle(bounds);
|
||||||
}
|
}
|
||||||
synch();
|
synch();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Change the bounds of the decoration, relative to the decorated
|
/**
|
||||||
* component.
|
* Change the bounds of the decoration, relative to the decorated component.
|
||||||
*/
|
*/
|
||||||
public void setDecorationBounds(int x, int y, int w, int h) {
|
public void setDecorationBounds(int x, int y, int w, int h) {
|
||||||
setDecorationBounds(new Rectangle(x, y, w, h));
|
setDecorationBounds(new Rectangle(x, y, w, h));
|
||||||
@@ -303,8 +314,13 @@ public abstract class AbstractComponentDecorator {
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JComponent getComponent() { return component; }
|
protected JComponent getComponent() {
|
||||||
protected JComponent getPainter() { return painter; }
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected JComponent getPainter() {
|
||||||
|
return painter;
|
||||||
|
}
|
||||||
|
|
||||||
/** Set the cursor to appear anywhere over the decoration bounds. */
|
/** Set the cursor to appear anywhere over the decoration bounds. */
|
||||||
public void setCursor(Cursor cursor) {
|
public void setCursor(Cursor cursor) {
|
||||||
@@ -336,11 +352,12 @@ public abstract class AbstractComponentDecorator {
|
|||||||
component = null;
|
component = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Define the decoration's appearance. The point (0,0) represents
|
/**
|
||||||
* the upper left corner of the decorated component.
|
* Define the decoration's appearance. The point (0,0) represents the upper
|
||||||
* The default clip mask will be the extents of the decoration bounds, as
|
* left corner of the decorated component. The default clip mask will be the
|
||||||
* indicated by {@link #getDecorationBounds()}, which defaults to the
|
* extents of the decoration bounds, as indicated by
|
||||||
* decorated component bounds.
|
* {@link #getDecorationBounds()}, which defaults to the decorated component
|
||||||
|
* bounds.
|
||||||
*/
|
*/
|
||||||
public abstract void paint(Graphics g);
|
public abstract void paint(Graphics g);
|
||||||
|
|
||||||
@@ -353,8 +370,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
try {
|
try {
|
||||||
nComponents = Container.class.getDeclaredField("ncomponents");
|
nComponents = Container.class.getDeclaredField("ncomponents");
|
||||||
nComponents.setAccessible(true);
|
nComponents.setAccessible(true);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
nComponents = null;
|
nComponents = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,38 +383,45 @@ public abstract class AbstractComponentDecorator {
|
|||||||
private class Painter extends JComponent {
|
private class Painter extends JComponent {
|
||||||
private int base;
|
private int base;
|
||||||
private Cursor cursor;
|
private Cursor cursor;
|
||||||
|
|
||||||
public JComponent getComponent() {
|
public JComponent getComponent() {
|
||||||
return AbstractComponentDecorator.this.getComponent();
|
return AbstractComponentDecorator.this.getComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDecoratedLayer(int base) {
|
public void setDecoratedLayer(int base) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDecoratedLayer() {
|
public int getDecoratedLayer() {
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBackgroundDecoration() {
|
public boolean isBackgroundDecoration() {
|
||||||
return layerOffset < 0;
|
return layerOffset < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the cursor to something else. */
|
/** Set the cursor to something else. */
|
||||||
public void setCursor(Cursor cursor) {
|
public void setCursor(Cursor cursor) {
|
||||||
Cursor oldCursor = getCursor();
|
Cursor oldCursor = getCursor();
|
||||||
// Make sure the cursor actually changed, otherwise
|
// Make sure the cursor actually changed, otherwise
|
||||||
// we get cursor flicker (notably on w32 title bars)
|
// we get cursor flicker (notably on w32 title bars)
|
||||||
if (oldCursor == null && cursor != null
|
if (oldCursor == null && cursor != null || oldCursor != null
|
||||||
|| oldCursor != null && !oldCursor.equals(cursor)) {
|
&& !oldCursor.equals(cursor)) {
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
super.setCursor(cursor);
|
super.setCursor(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the cursor of the decorated component, or the last
|
/**
|
||||||
* cursor set by {@link #setCursor}.
|
* Returns the cursor of the decorated component, or the last cursor set
|
||||||
|
* by {@link #setCursor}.
|
||||||
*/
|
*/
|
||||||
public Cursor getCursor() {
|
public Cursor getCursor() {
|
||||||
return cursor != null ? cursor : component.getCursor();
|
return cursor != null ? cursor : component.getCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Delegate to the containing decorator to perform the paint.
|
/**
|
||||||
|
* Delegate to the containing decorator to perform the paint.
|
||||||
*/
|
*/
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
if (!component.isShowing())
|
if (!component.isShowing())
|
||||||
@@ -408,47 +431,51 @@ public abstract class AbstractComponentDecorator {
|
|||||||
AbstractComponentDecorator.this.paint(g2);
|
AbstractComponentDecorator.this.paint(g2);
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
/*
|
/*
|
||||||
g = g.create();
|
* g = g.create(); g.setClip(null); g.setColor(Color.red);
|
||||||
g.setClip(null);
|
* g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
||||||
g.setColor(Color.red);
|
|
||||||
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
/** Provide a decorator-specific tooltip, shown when within the
|
|
||||||
|
/**
|
||||||
|
* Provide a decorator-specific tooltip, shown when within the
|
||||||
* decorator's bounds.
|
* decorator's bounds.
|
||||||
*/
|
*/
|
||||||
public String getToolTipText(MouseEvent e) {
|
public String getToolTipText(MouseEvent e) {
|
||||||
return AbstractComponentDecorator.this.getToolTipText(e);
|
return AbstractComponentDecorator.this.getToolTipText(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Painter for " + AbstractComponentDecorator.this;
|
return "Painter for " + AbstractComponentDecorator.this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Provides a shared background painting mechanism for multiple
|
/**
|
||||||
* decorations. This ensures that the background is only painted once
|
* Provides a shared background painting mechanism for multiple decorations.
|
||||||
* if more than one background decorator is applied.
|
* This ensures that the background is only painted once if more than one
|
||||||
|
* background decorator is applied.
|
||||||
*/
|
*/
|
||||||
private static class BackgroundPainter extends AbstractComponentDecorator {
|
private static class BackgroundPainter extends AbstractComponentDecorator {
|
||||||
private static String key(int layer) {
|
private static String key(int layer) {
|
||||||
return "backgroundPainter for layer " + layer;
|
return "backgroundPainter for layer " + layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private int layer;
|
private int layer;
|
||||||
|
|
||||||
public BackgroundPainter(JLayeredPane p, int layer) {
|
public BackgroundPainter(JLayeredPane p, int layer) {
|
||||||
super(p, 0, TOP);
|
super(p, 0, TOP);
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
key = key(layer);
|
key = key(layer);
|
||||||
p.putClientProperty(key, this);
|
p.putClientProperty(key, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int hideChildren(Container c) {
|
private int hideChildren(Container c) {
|
||||||
if (c == null)
|
if (c == null)
|
||||||
return 0;
|
return 0;
|
||||||
int value = c.getComponentCount();
|
int value = c.getComponentCount();
|
||||||
try {
|
try {
|
||||||
nComponents.set(c, new Integer(0));
|
nComponents.set(c, new Integer(0));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
return c.getComponentCount();
|
return c.getComponentCount();
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@@ -458,8 +485,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
if (c != null) {
|
if (c != null) {
|
||||||
try {
|
try {
|
||||||
nComponents.set(c, new Integer(count));
|
nComponents.set(c, new Integer(count));
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,8 +503,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
if (useSimpleBackground()) {
|
if (useSimpleBackground()) {
|
||||||
g.setColor(jc.getBackground());
|
g.setColor(jc.getBackground());
|
||||||
g.fillRect(0, 0, jc.getWidth(), jc.getHeight());
|
g.fillRect(0, 0, jc.getWidth(), jc.getHeight());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
int count = hideChildren(jc);
|
int count = hideChildren(jc);
|
||||||
boolean db = jc.isDoubleBuffered();
|
boolean db = jc.isDoubleBuffered();
|
||||||
if (db)
|
if (db)
|
||||||
@@ -496,6 +521,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List findOpaque(Component root) {
|
private List findOpaque(Component root) {
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
if (root.isOpaque() && root instanceof JComponent) {
|
if (root.isOpaque() && root instanceof JComponent) {
|
||||||
@@ -510,6 +536,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List findDoubleBuffered(Component root) {
|
private List findDoubleBuffered(Component root) {
|
||||||
List list = new ArrayList();
|
List list = new ArrayList();
|
||||||
if (root.isDoubleBuffered() && root instanceof JComponent) {
|
if (root.isDoubleBuffered() && root instanceof JComponent) {
|
||||||
@@ -524,6 +551,7 @@ public abstract class AbstractComponentDecorator {
|
|||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintForeground(Graphics g, JComponent jc) {
|
private void paintForeground(Graphics g, JComponent jc) {
|
||||||
List opaque = findOpaque(jc);
|
List opaque = findOpaque(jc);
|
||||||
List db = findDoubleBuffered(jc);
|
List db = findDoubleBuffered(jc);
|
||||||
@@ -548,15 +576,12 @@ public abstract class AbstractComponentDecorator {
|
|||||||
for (int i = kids.length - 1; i >= 0; i--) {
|
for (int i = kids.length - 1; i >= 0; i--) {
|
||||||
if (kids[i] instanceof Painter) {
|
if (kids[i] instanceof Painter) {
|
||||||
Painter p = (Painter) kids[i];
|
Painter p = (Painter) kids[i];
|
||||||
if (p.isBackgroundDecoration()
|
if (p.isBackgroundDecoration() && p.getDecoratedLayer() == layer
|
||||||
&& p.getDecoratedLayer() == layer
|
|
||||||
&& p.isShowing()) {
|
&& p.isShowing()) {
|
||||||
painters.add(p);
|
painters.add(p);
|
||||||
area.add(new Area(p.getBounds()));
|
area.add(new Area(p.getBounds()));
|
||||||
}
|
}
|
||||||
}
|
} else if (lp.getLayer(kids[i]) == layer && kids[i] instanceof JComponent) {
|
||||||
else if (lp.getLayer(kids[i]) == layer
|
|
||||||
&& kids[i] instanceof JComponent) {
|
|
||||||
components.add(kids[i]);
|
components.add(kids[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,41 +608,48 @@ public abstract class AbstractComponentDecorator {
|
|||||||
paintForeground(g.create(c.getX(), c.getY(), c.getWidth(), c.getHeight()), c);
|
paintForeground(g.create(c.getX(), c.getY(), c.getWidth(), c.getHeight()), c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
getComponent().putClientProperty(key, null);
|
getComponent().putClientProperty(key, null);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return key + " on " + getComponent();
|
return key + " on " + getComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tracks changes to component configuration. */
|
/** Tracks changes to component configuration. */
|
||||||
private final class Listener extends ComponentAdapter
|
private final class Listener extends ComponentAdapter implements HierarchyListener,
|
||||||
implements HierarchyListener, PropertyChangeListener {
|
PropertyChangeListener {
|
||||||
public void hierarchyChanged(HierarchyEvent e) {
|
public void hierarchyChanged(HierarchyEvent e) {
|
||||||
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
|
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
|
||||||
attach();
|
attach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent e) {
|
public void propertyChange(PropertyChangeEvent e) {
|
||||||
if (JLayeredPane.LAYER_PROPERTY.equals(e.getPropertyName())) {
|
if (JLayeredPane.LAYER_PROPERTY.equals(e.getPropertyName())) {
|
||||||
attach();
|
attach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void componentMoved(ComponentEvent e) {
|
public void componentMoved(ComponentEvent e) {
|
||||||
// FIXME figure out why attach works and synch doesn't
|
// FIXME figure out why attach works and synch doesn't
|
||||||
// when painting a selection marquee over a decorated background
|
// when painting a selection marquee over a decorated background
|
||||||
attach();
|
attach();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
// FIXME figure out why attach works and synch doesn't
|
// FIXME figure out why attach works and synch doesn't
|
||||||
// when painting a selection marquee over a decorated background
|
// when painting a selection marquee over a decorated background
|
||||||
attach();
|
attach();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void componentHidden(ComponentEvent e) {
|
public void componentHidden(ComponentEvent e) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void componentShown(ComponentEvent e) {
|
public void componentShown(ComponentEvent e) {
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-24
@@ -57,10 +57,10 @@ public class GhostedDragImage extends AbstractComponentDecorator {
|
|||||||
* @param imageOffset
|
* @param imageOffset
|
||||||
* offset of the image from the cursor
|
* offset of the image from the cursor
|
||||||
*/
|
*/
|
||||||
public GhostedDragImage(JComponent dragSource, Point screenLocation,
|
public GhostedDragImage(JComponent dragSource, Point screenLocation, Icon icon,
|
||||||
Icon icon, Point imageOffset) {
|
Point imageOffset) {
|
||||||
this(dragSource, dragSource.getRootPane().getLayeredPane(),
|
this(dragSource, dragSource.getRootPane().getLayeredPane(), screenLocation, icon,
|
||||||
screenLocation, icon, imageOffset, true);
|
imageOffset, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,29 +80,26 @@ public class GhostedDragImage extends AbstractComponentDecorator {
|
|||||||
* if true, creates additional ghosts for all extant frames which
|
* if true, creates additional ghosts for all extant frames which
|
||||||
* contain a {@link JLayeredPane} where the image can be painted.
|
* contain a {@link JLayeredPane} where the image can be painted.
|
||||||
*/
|
*/
|
||||||
protected GhostedDragImage(JComponent dragSource, JLayeredPane root,
|
protected GhostedDragImage(JComponent dragSource, JLayeredPane root, Point screenLocation,
|
||||||
Point screenLocation, Icon icon, Point imageOffset,
|
Icon icon, Point imageOffset, boolean trackFrames) {
|
||||||
boolean trackFrames) {
|
|
||||||
super(root);
|
super(root);
|
||||||
this.dragSource = dragSource;
|
this.dragSource = dragSource;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.imageOffset = imageOffset;
|
this.imageOffset = imageOffset;
|
||||||
Point loc = root.getLocationOnScreen();
|
Point loc = root.getLocationOnScreen();
|
||||||
setLocation(screenLocation.x - loc.x + imageOffset.x, screenLocation.y
|
setLocation(screenLocation.x - loc.x + imageOffset.x, screenLocation.y - loc.y
|
||||||
- loc.y + imageOffset.y);
|
+ imageOffset.y);
|
||||||
if (trackFrames) {
|
if (trackFrames) {
|
||||||
Window w = SwingUtilities.getWindowAncestor(root);
|
Window w = SwingUtilities.getWindowAncestor(root);
|
||||||
Frame[] frames = Frame.getFrames();
|
Frame[] frames = Frame.getFrames();
|
||||||
// Log.debug("track " + frames.length + " other frames");
|
// Log.debug("track " + frames.length + " other frames");
|
||||||
for (int i = 0; i < frames.length; i++) {
|
for (int i = 0; i < frames.length; i++) {
|
||||||
Frame frame = frames[i];
|
Frame frame = frames[i];
|
||||||
if (frame instanceof RootPaneContainer && frame.isShowing()
|
if (frame instanceof RootPaneContainer && frame.isShowing() && frame != w) {
|
||||||
&& frame != w) {
|
|
||||||
// Log.debug("Track " + frame);
|
// Log.debug("Track " + frame);
|
||||||
JLayeredPane p = ((RootPaneContainer) frame)
|
JLayeredPane p = ((RootPaneContainer) frame).getLayeredPane();
|
||||||
.getLayeredPane();
|
GhostedDragImage slave = new GhostedDragImage(dragSource, p, screenLocation,
|
||||||
GhostedDragImage slave = new GhostedDragImage(dragSource,
|
icon, imageOffset, false);
|
||||||
p, screenLocation, icon, imageOffset, false);
|
|
||||||
ghosts.add(slave);
|
ghosts.add(slave);
|
||||||
slave.move(screenLocation);
|
slave.move(screenLocation);
|
||||||
}
|
}
|
||||||
@@ -143,8 +140,7 @@ public class GhostedDragImage extends AbstractComponentDecorator {
|
|||||||
* with {@link #returnToOrigin}.
|
* with {@link #returnToOrigin}.
|
||||||
*/
|
*/
|
||||||
private void setLocation(int x, int y) {
|
private void setLocation(int x, int y) {
|
||||||
location = SwingUtilities
|
location = SwingUtilities.convertPoint(getComponent(), x, y, dragSource);
|
||||||
.convertPoint(getComponent(), x, y, dragSource);
|
|
||||||
if (origin == null)
|
if (origin == null)
|
||||||
origin = location;
|
origin = location;
|
||||||
setDecorationBounds(x, y, icon.getIconWidth(), icon.getIconHeight());
|
setDecorationBounds(x, y, icon.getIconWidth(), icon.getIconHeight());
|
||||||
@@ -176,8 +172,7 @@ public class GhostedDragImage extends AbstractComponentDecorator {
|
|||||||
public void move(Point screen) {
|
public void move(Point screen) {
|
||||||
// Log.debug("Move to " + screen);
|
// Log.debug("Move to " + screen);
|
||||||
Point loc = getComponent().getLocationOnScreen();
|
Point loc = getComponent().getLocationOnScreen();
|
||||||
setLocation(screen.x - loc.x + imageOffset.x, screen.y - loc.y
|
setLocation(screen.x - loc.x + imageOffset.x, screen.y - loc.y + imageOffset.y);
|
||||||
+ imageOffset.y);
|
|
||||||
for (Iterator i = ghosts.iterator(); i.hasNext();) {
|
for (Iterator i = ghosts.iterator(); i.hasNext();) {
|
||||||
GhostedDragImage g = (GhostedDragImage) i.next();
|
GhostedDragImage g = (GhostedDragImage) i.next();
|
||||||
// Log.debug("Move on other frame");
|
// Log.debug("Move on other frame");
|
||||||
@@ -189,8 +184,7 @@ public class GhostedDragImage extends AbstractComponentDecorator {
|
|||||||
public void paint(Graphics graphics) {
|
public void paint(Graphics graphics) {
|
||||||
Rectangle r = getDecorationBounds();
|
Rectangle r = getDecorationBounds();
|
||||||
Graphics2D g = (Graphics2D) graphics.create();
|
Graphics2D g = (Graphics2D) graphics.create();
|
||||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ghostAlpha));
|
||||||
ghostAlpha));
|
|
||||||
g.translate(CURSOR_SIZE, CURSOR_SIZE);
|
g.translate(CURSOR_SIZE, CURSOR_SIZE);
|
||||||
icon.paintIcon(getPainter(), g, r.x, r.y);
|
icon.paintIcon(getPainter(), g, r.x, r.y);
|
||||||
g.dispose();
|
g.dispose();
|
||||||
@@ -208,9 +202,8 @@ public class GhostedDragImage extends AbstractComponentDecorator {
|
|||||||
int dy = (origin.y - location.y) / 2;
|
int dy = (origin.y - location.y) / 2;
|
||||||
if (dx != 0 || dy != 0) {
|
if (dx != 0 || dy != 0) {
|
||||||
Point loc = dragSource.getLocationOnScreen();
|
Point loc = dragSource.getLocationOnScreen();
|
||||||
Point where = new Point(loc.x + location.x + dx
|
Point where = new Point(loc.x + location.x + dx - imageOffset.x, loc.y
|
||||||
- imageOffset.x, loc.y + location.y + dy
|
+ location.y + dy - imageOffset.y);
|
||||||
- imageOffset.y);
|
|
||||||
move(where);
|
move(where);
|
||||||
} else {
|
} else {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|||||||
+7
-13
@@ -24,22 +24,16 @@ public class TableTest {
|
|||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
|
|
||||||
List<ProjectEntity> projects = new ArrayList<ProjectEntity>();
|
List<ProjectEntity> projects = new ArrayList<ProjectEntity>();
|
||||||
projects
|
projects.add(new ProjectEntity(1, "first", "some text", "bane", "none"));
|
||||||
.add(new ProjectEntity(1, "first", "some text", "bane", "none"));
|
projects.add(new ProjectEntity(2, "second", "anoter text", "bisera", "none"));
|
||||||
projects.add(new ProjectEntity(2, "second", "anoter text", "bisera",
|
|
||||||
"none"));
|
|
||||||
|
|
||||||
ObjectListTable<ProjectEntity> t = new ObjectListTable<ProjectEntity>(
|
ObjectListTable<ProjectEntity> t = new ObjectListTable<ProjectEntity>(ProjectEntity.class,
|
||||||
ProjectEntity.class, new String[] { "getName",
|
new String[] { "getName", "getDescription", "getCategory", "getOwner",
|
||||||
"getDescription", "getCategory", "getOwner",
|
"action:Download" }, new IActionProcessor<ProjectEntity>() {
|
||||||
"action:Download" },
|
|
||||||
new IActionProcessor<ProjectEntity>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionExecuted(ProjectEntity value,
|
public void actionExecuted(ProjectEntity value, String actionColumnName) {
|
||||||
String actionColumnName) {
|
System.out.println("row clicked: " + actionColumnName + " - " + value);
|
||||||
System.out.println("row clicked: " + actionColumnName
|
|
||||||
+ " - " + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-3
@@ -29,9 +29,8 @@ public class Test {
|
|||||||
// System.out.println(xstream.toXML(projects));
|
// System.out.println(xstream.toXML(projects));
|
||||||
|
|
||||||
BasicConfigurator.configure();
|
BasicConfigurator.configure();
|
||||||
ProjectSearch search = new ProxyFactory(new PhpFlatProxy())
|
ProjectSearch search = new ProxyFactory(new PhpFlatProxy()).createProxy(
|
||||||
.createProxy(ProjectSearch.class,
|
ProjectSearch.class, "http://host07.dwhost.net/~diyfever/diylc/db/");
|
||||||
"http://host07.dwhost.net/~diyfever/diylc/db/");
|
|
||||||
List<ProjectEntity> results = search.project_search("TestProject");
|
List<ProjectEntity> results = search.project_search("TestProject");
|
||||||
System.out.println(results);
|
System.out.println(results);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -30,8 +30,8 @@ public class MockComponentInstance implements IComponentInstance {
|
|||||||
private Point leftTopCorner = new Point(0, 0);
|
private Point leftTopCorner = new Point(0, 0);
|
||||||
private String name = "something";
|
private String name = "something";
|
||||||
|
|
||||||
public MockComponentInstance(String testField, Capacitance c, Resistance r,
|
public MockComponentInstance(String testField, Capacitance c, Resistance r, Size s,
|
||||||
Size s, Color color, Point leftTopCorner) {
|
Color color, Point leftTopCorner) {
|
||||||
super();
|
super();
|
||||||
this.testField = testField;
|
this.testField = testField;
|
||||||
this.c = c;
|
this.c = c;
|
||||||
@@ -113,16 +113,14 @@ public class MockComponentInstance implements IComponentInstance {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState) {
|
public void draw(Graphics2D g2d, ComponentState componentState) {
|
||||||
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color
|
g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker());
|
||||||
: color.darker());
|
|
||||||
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
|
g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MockComponentInstance clone() throws CloneNotSupportedException {
|
public MockComponentInstance clone() throws CloneNotSupportedException {
|
||||||
MockComponentInstance newInstance = new MockComponentInstance(
|
MockComponentInstance newInstance = new MockComponentInstance(testField, c.clone(), r
|
||||||
testField, c.clone(), r.clone(), s.clone(), color,
|
.clone(), s.clone(), color, (Point) leftTopCorner.clone());
|
||||||
(Point) leftTopCorner.clone());
|
|
||||||
return newInstance;
|
return newInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -15,16 +15,15 @@ public class ClassProcessorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractProperties() {
|
public void testExtractProperties() {
|
||||||
List<PropertyWrapper> properties = ComponentProcessor.getInstance()
|
List<PropertyWrapper> properties = ComponentProcessor.getInstance().extractProperties(
|
||||||
.extractProperties(MockComponentInstance.class);
|
MockComponentInstance.class);
|
||||||
assertNotNull(properties);
|
assertNotNull(properties);
|
||||||
assertEquals(4, properties.size());
|
assertEquals(4, properties.size());
|
||||||
};
|
};
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExtractControlPoints() {
|
public void testExtractControlPoints() {
|
||||||
List<ControlPointWrapper> controlPoints = ComponentProcessor
|
List<ControlPointWrapper> controlPoints = ComponentProcessor.getInstance()
|
||||||
.getInstance()
|
|
||||||
.extractControlPoints(MockComponentInstance.class);
|
.extractControlPoints(MockComponentInstance.class);
|
||||||
assertNotNull(controlPoints);
|
assertNotNull(controlPoints);
|
||||||
assertEquals(1, controlPoints.size());
|
assertEquals(1, controlPoints.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user