diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar b/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar index bb264d70..ca82e050 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar and b/ diy-layout-creator --username bancika@gmail.com/DIYLC/lib/bancika-gui-framework.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ComponentSelection.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ComponentSelection.java index b375135b..551d5866 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ComponentSelection.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ComponentSelection.java @@ -10,25 +10,22 @@ import java.util.List; import com.diyfever.diylc.model.IComponentInstance; -public class ComponentSelection extends ArrayList implements - Transferable { +public class ComponentSelection extends ArrayList implements Transferable { private static final long serialVersionUID = 1L; - public static final DataFlavor listFlavor = new DataFlavor(List.class, - "Java List"); - + public static final DataFlavor listFlavor = new DataFlavor(List.class, "Java List"); + public ComponentSelection() { super(); } - + public ComponentSelection(Collection selectedComponents) { super(selectedComponents); } @Override - public Object getTransferData(DataFlavor flavor) - throws UnsupportedFlavorException, IOException { + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.equals(listFlavor)) { return this; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ControlPointWrapper.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ControlPointWrapper.java index 91738871..fa544094 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ControlPointWrapper.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/ControlPointWrapper.java @@ -17,8 +17,8 @@ public class ControlPointWrapper { private boolean sticky; private VisibilityPolicy visibilityPolicy; - public ControlPointWrapper(String name, Method getter, Method setter, - boolean editable, boolean sticky, VisibilityPolicy visibilityPolicy) { + public ControlPointWrapper(String name, Method getter, Method setter, boolean editable, + boolean sticky, VisibilityPolicy visibilityPolicy) { super(); this.name = name; this.getter = getter; @@ -28,15 +28,13 @@ public class ControlPointWrapper { this.visibilityPolicy = visibilityPolicy; } - public void readFrom(IComponentInstance component) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException { + public void readFrom(IComponentInstance component) throws IllegalArgumentException, + IllegalAccessException, InvocationTargetException { value = (Point) getter.invoke(component); } - public void writeTo(IComponentInstance component) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException { + public void writeTo(IComponentInstance component) throws IllegalArgumentException, + IllegalAccessException, InvocationTargetException { setter.invoke(component, value); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/IPlugInPort.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/IPlugInPort.java index ae7a9c7e..6ec15372 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/IPlugInPort.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/IPlugInPort.java @@ -108,8 +108,7 @@ public interface IPlugInPort { * @throws BadPositionException * in case invalid position is specified */ - void injectGUIComponent(JComponent component, int position) - throws BadPositionException; + void injectGUIComponent(JComponent component, int position) throws BadPositionException; /** * Injects a custom menu action into application's main menu. If @@ -144,8 +143,7 @@ public interface IPlugInPort { * * @param point */ - void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, - boolean altDown); + void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown); void mouseMoved(Point point); @@ -266,8 +264,7 @@ public interface IPlugInPort { * @param properties * @throws Exception */ - void applyPropertiesToSelection(List properties) - throws Exception; + void applyPropertiesToSelection(List properties) throws Exception; // void setCursorIcon(Icon icon); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/PropertyWrapper.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/PropertyWrapper.java index c40ac3d6..3c9b2267 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/PropertyWrapper.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/common/PropertyWrapper.java @@ -14,8 +14,8 @@ public class PropertyWrapper implements Cloneable { private Method getter; private boolean defaultable; - public PropertyWrapper(String name, Class type, Method getter, - Method setter, boolean defaultable) { + public PropertyWrapper(String name, Class type, Method getter, Method setter, + boolean defaultable) { super(); this.name = name; this.type = type; @@ -24,24 +24,22 @@ public class PropertyWrapper implements Cloneable { this.defaultable = defaultable; } - public void readFrom(IComponentInstance component) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException { + public void readFrom(IComponentInstance component) throws IllegalArgumentException, + IllegalAccessException, InvocationTargetException { this.value = getter.invoke(component); } -// public void readUniqueFrom(IComponentInstance component) -// throws IllegalArgumentException, IllegalAccessException, -// InvocationTargetException { -// Object newValue = getter.invoke(component); -// if (!newValue.equals(value)) { -// this.value = null; -// } -// } + // public void readUniqueFrom(IComponentInstance component) + // throws IllegalArgumentException, IllegalAccessException, + // InvocationTargetException { + // Object newValue = getter.invoke(component); + // if (!newValue.equals(value)) { + // this.value = null; + // } + // } - public void writeTo(IComponentInstance component) - throws IllegalArgumentException, IllegalAccessException, - InvocationTargetException { + public void writeTo(IComponentInstance component) throws IllegalArgumentException, + IllegalAccessException, InvocationTargetException { setter.invoke(component, value); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/DialogFactory.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/DialogFactory.java index 86bc794d..893cc975 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/DialogFactory.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/DialogFactory.java @@ -55,10 +55,8 @@ public class DialogFactory { } } - public PropertyEditorDialog createPropertyEditorDialog( - List properties) { - PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, - properties); + public PropertyEditorDialog createPropertyEditorDialog(List properties) { + PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties); return editor; } @@ -67,33 +65,28 @@ public class DialogFactory { return dialog; } - public File showOpenDialog(FileFilter fileFilter, File initialFile, - String defaultExtension, IFileChooserAccessory accessory) { + public File showOpenDialog(FileFilter fileFilter, File initialFile, String defaultExtension, + IFileChooserAccessory accessory) { JFileChooser openFileChooser = new JFileChooser(); - initializeFileChooser(openFileChooser, fileFilter, initialFile, - defaultExtension, accessory); + initializeFileChooser(openFileChooser, fileFilter, initialFile, defaultExtension, accessory); int result = openFileChooser.showOpenDialog(mainFrame); - return processFileChooserResult(result, openFileChooser, - defaultExtension); + return processFileChooserResult(result, openFileChooser, defaultExtension); } - public File showSaveDialog(FileFilter fileFilter, File initialFile, - String defaultExtension, IFileChooserAccessory accessory) { + public File showSaveDialog(FileFilter fileFilter, File initialFile, String defaultExtension, + IFileChooserAccessory accessory) { JFileChooser saveFileChooser = new OverwritePromptFileChooser(); - initializeFileChooser(saveFileChooser, fileFilter, initialFile, - defaultExtension, accessory); + initializeFileChooser(saveFileChooser, fileFilter, initialFile, defaultExtension, accessory); int result = saveFileChooser.showSaveDialog(mainFrame); - return processFileChooserResult(result, saveFileChooser, - defaultExtension); + return processFileChooserResult(result, saveFileChooser, defaultExtension); } - private void initializeFileChooser(JFileChooser fileChooser, - FileFilter fileFilter, File initialFile, String defaultExtension, - IFileChooserAccessory accessory) { + private void initializeFileChooser(JFileChooser fileChooser, FileFilter fileFilter, + File initialFile, String defaultExtension, IFileChooserAccessory accessory) { if (accessory != null) { accessory.install(fileChooser); } @@ -101,8 +94,7 @@ public class DialogFactory { fileChooser.removeChoosableFileFilter(filter); } if (fileChooser instanceof OverwritePromptFileChooser) { - ((OverwritePromptFileChooser) fileChooser).setFileFilter( - fileFilter, defaultExtension); + ((OverwritePromptFileChooser) fileChooser).setFileFilter(fileFilter, defaultExtension); } else { fileChooser.setFileFilter(fileFilter); } @@ -122,19 +114,18 @@ public class DialogFactory { if (fileChooser.getSelectedFile().getAbsolutePath().contains(".")) { return fileChooser.getSelectedFile(); } else { - return new File(fileChooser.getSelectedFile().getAbsoluteFile() - + "." + defaultExtension); + return new File(fileChooser.getSelectedFile().getAbsoluteFile() + "." + + defaultExtension); } } else { return null; } } - public AboutDialog createAboutDialog(String appName, Icon icon, - String version, String author, String url, String mail, - String htmlContent) { - AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, - author, url, mail, htmlContent); + public AboutDialog createAboutDialog(String appName, Icon icon, String version, String author, + String url, String mail, String htmlContent) { + AboutDialog dialog = new AboutDialog(mainFrame, appName, icon, version, author, url, mail, + htmlContent); return dialog; } @@ -153,10 +144,10 @@ public class DialogFactory { return dialog; } - public ProgressDialog createProgressDialog(String title, - String[] buttonCaptions, String description, boolean useProgress) { - ProgressDialog dialog = new ProgressDialog(mainFrame, title, - buttonCaptions, description, useProgress); + public ProgressDialog createProgressDialog(String title, String[] buttonCaptions, + String description, boolean useProgress) { + ProgressDialog dialog = new ProgressDialog(mainFrame, title, buttonCaptions, description, + useProgress); return dialog; } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/IView.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/IView.java index 40a9b01f..78b24d1b 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/IView.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/IView.java @@ -25,8 +25,7 @@ public interface IView { * * @see IPlugInPort#injectGUIComponent */ - void addComponent(JComponent component, int position) - throws BadPositionException; + void addComponent(JComponent component, int position) throws BadPositionException; /** * Adds a menu action. diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/MainFrame.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/MainFrame.java index 9c6ceadf..9c569bd0 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/MainFrame.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/MainFrame.java @@ -124,8 +124,7 @@ public class MainFrame extends JFrame implements IView { // IView @Override - public void addComponent(JComponent component, int position) - throws BadPositionException { + public void addComponent(JComponent component, int position) throws BadPositionException { switch (position) { case SwingConstants.TOP: topPanel.add(component); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/components/OverwritePromptFileChooser.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/components/OverwritePromptFileChooser.java index facdd018..9cbf93a7 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/components/OverwritePromptFileChooser.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/components/OverwritePromptFileChooser.java @@ -16,16 +16,13 @@ public class OverwritePromptFileChooser extends JFileChooser { if (getSelectedFile().getAbsolutePath().contains(".")) { lSelectedFile = getSelectedFile(); } else { - lSelectedFile = new File(getSelectedFile().getAbsoluteFile() + "." - + defaultExtension); + lSelectedFile = new File(getSelectedFile().getAbsoluteFile() + "." + defaultExtension); } if (lSelectedFile != null && lSelectedFile.exists()) { - int lResponse = JOptionPane.showConfirmDialog(this, lSelectedFile - .getAbsolutePath() - + " already exists.\nDo you " + "want to replace it?", - "Warning", JOptionPane.YES_NO_OPTION, - JOptionPane.WARNING_MESSAGE); + int lResponse = JOptionPane.showConfirmDialog(this, lSelectedFile.getAbsolutePath() + + " already exists.\nDo you " + "want to replace it?", "Warning", + JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (lResponse != JOptionPane.YES_OPTION) { return; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/ColorEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/ColorEditor.java index 960b3a52..03246ae3 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/ColorEditor.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/ColorEditor.java @@ -27,8 +27,8 @@ public class ColorEditor extends JLabel { @Override public void mouseClicked(MouseEvent e) { - Color newColor = JColorChooser.showDialog(ColorEditor.this, - "Choose Color", getBackground()); + Color newColor = JColorChooser.showDialog(ColorEditor.this, "Choose Color", + getBackground()); if (newColor != null) { property.setValue(newColor); setBackground(newColor); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/MeasureEditor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/MeasureEditor.java index f01624a4..6c5371bc 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/MeasureEditor.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/MeasureEditor.java @@ -35,8 +35,7 @@ public class MeasureEditor extends Container { add(valueField, BorderLayout.CENTER); try { Method method = measure.getUnit().getClass().getMethod("values"); - final JComboBox unitBox = new JComboBox((Object[]) method - .invoke(measure.getUnit())); + final JComboBox unitBox = new JComboBox((Object[]) method.invoke(measure.getUnit())); unitBox.setSelectedItem(measure.getUnit()); unitBox.addActionListener(new ActionListener() { diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/PropertyEditorDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/PropertyEditorDialog.java index 8fb411b0..041fb3c7 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/PropertyEditorDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/gui/editor/PropertyEditorDialog.java @@ -24,8 +24,7 @@ import com.diyfever.gui.ButtonDialog; public class PropertyEditorDialog extends ButtonDialog { - private static final Logger LOG = Logger - .getLogger(PropertyEditorDialog.class); + private static final Logger LOG = Logger.getLogger(PropertyEditorDialog.class); private static final long serialVersionUID = 1L; @@ -35,8 +34,7 @@ public class PropertyEditorDialog extends ButtonDialog { private Set defaultedProperties; public PropertyEditorDialog(JFrame owner, List properties) { - super(owner, "Editor", new String[] { ButtonDialog.OK, - ButtonDialog.CANCEL }); + super(owner, "Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL }); LOG.debug("Creating property editor for: " + properties); @@ -85,8 +83,7 @@ public class PropertyEditorDialog extends ButtonDialog { gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1; - editorPanel - .add(FieldEditorFactory.createFieldEditor(property), gbc); + editorPanel.add(FieldEditorFactory.createFieldEditor(property), gbc); if (property.isDefaultable()) { gbc.gridx = 2; @@ -124,8 +121,7 @@ public class PropertyEditorDialog extends ButtonDialog { } public static boolean showFor(JFrame owner, List properties) { - PropertyEditorDialog editor = new PropertyEditorDialog(owner, - properties); + PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties); editor.setVisible(true); if (OK.equals(editor.getSelectedButtonCaption())) { return true; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/images/IconLoader.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/images/IconLoader.java index cd68810f..045af755 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/images/IconLoader.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/images/IconLoader.java @@ -10,48 +10,18 @@ import javax.swing.ImageIcon; */ public enum IconLoader { - Delete("delete.png"), - Add("add.png"), - FolderOut("folder_out.png"), - Garbage("garbage.png"), - DiskBlue("disk_blue.png"), - SaveAs("save_as.png"), - Exit("exit.png"), - DocumentPlainYellow("document_plain_yellow.png"), - PhotoScenery("photo_scenery.png"), - LightBulbOn("lightbulb_on.png"), - LightBulbOff("lightbulb_off.png"), - NotebookAdd("notebook_add.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"), - ; + Delete("delete.png"), Add("add.png"), FolderOut("folder_out.png"), Garbage("garbage.png"), DiskBlue( + "disk_blue.png"), SaveAs("save_as.png"), Exit("exit.png"), DocumentPlainYellow( + "document_plain_yellow.png"), PhotoScenery("photo_scenery.png"), LightBulbOn( + "lightbulb_on.png"), LightBulbOff("lightbulb_off.png"), NotebookAdd("notebook_add.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; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/IComponentInstance.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/IComponentInstance.java index c80099c3..43bc98ab 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/IComponentInstance.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/IComponentInstance.java @@ -24,5 +24,5 @@ public interface IComponentInstance extends Serializable { */ void draw(Graphics2D g2d, ComponentState componentState); -// IComponentInstance clone() throws CloneNotSupportedException; + // IComponentInstance clone() throws CloneNotSupportedException; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/Project.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/Project.java index bc23354b..73f87f43 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/Project.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/Project.java @@ -27,8 +27,8 @@ public class Project implements Serializable { height = new Size(21d, SizeUnit.cm); } - public Project(String title, String author, String description, Size width, - Size height, List components) { + public Project(String title, String author, String description, Size width, Size height, + List components) { super(); this.title = title; this.author = author; @@ -92,10 +92,8 @@ public class Project implements Serializable { final int prime = 31; int result = 1; result = prime * result + ((author == null) ? 0 : author.hashCode()); - result = prime * result - + ((components == null) ? 0 : components.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((components == null) ? 0 : components.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((height == null) ? 0 : height.hashCode()); result = prime * result + ((title == null) ? 0 : title.hashCode()); result = prime * result + ((width == null) ? 0 : width.hashCode()); @@ -144,14 +142,15 @@ public class Project implements Serializable { return true; } -// @Override -// public Project clone() throws CloneNotSupportedException { -// List clonedComponents = new ArrayList(); -// for (IComponentInstance component : components) { -// clonedComponents.add(component.clone()); -// } -// Project project = new Project(title, author, description, -// width.clone(), height.clone(), clonedComponents); -// return project; -// } + // @Override + // public Project clone() throws CloneNotSupportedException { + // List clonedComponents = new + // ArrayList(); + // for (IComponentInstance component : components) { + // clonedComponents.add(component.clone()); + // } + // Project project = new Project(title, author, description, + // width.clone(), height.clone(), clonedComponents); + // return project; + // } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/annotations/ControlPoint.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/annotations/ControlPoint.java index 74a674d8..cff7a706 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/annotations/ControlPoint.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/annotations/ControlPoint.java @@ -38,11 +38,11 @@ public @interface ControlPoint { */ boolean sticky() default true; -// /** -// * If true, the control point is the main control point for the component. -// * There cannot be more than one control point for a single component. -// * -// * @return -// */ -// boolean main() default false; + // /** + // * If true, the control point is the main control point for the component. + // * There cannot be more than one control point for a single component. + // * + // * @return + // */ + // boolean main() default false; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/AbstractMeasure.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/AbstractMeasure.java index 7be0ae13..a4b7a2bd 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/AbstractMeasure.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/AbstractMeasure.java @@ -4,8 +4,7 @@ import java.io.Serializable; import java.text.DecimalFormat; import java.text.Format; -public class AbstractMeasure> implements - Serializable, Cloneable { +public class AbstractMeasure> implements Serializable, Cloneable { private static final long serialVersionUID = 1L; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Converter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Converter.java index f0779ad7..af59be1d 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Converter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Converter.java @@ -4,7 +4,7 @@ public class Converter { public static > AbstractMeasure convert( AbstractMeasure measure, T newUnit) { - + return null; } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Size.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Size.java index 75c9a61f..f603de94 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Size.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/model/measures/Size.java @@ -6,8 +6,7 @@ public class Size extends AbstractMeasure { private static final long serialVersionUID = 1L; - public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit() - .getScreenResolution(); + public static final int PIXELS_PER_INCH = Toolkit.getDefaultToolkit().getScreenResolution(); public Size() { super(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasGestureListener.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasGestureListener.java index 99281b9c..9020b571 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasGestureListener.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasGestureListener.java @@ -23,7 +23,7 @@ class CanvasGestureListener implements DragGestureListener { @Override public void dragGestureRecognized(DragGestureEvent dge) { presenter.dragStarted(dge.getDragOrigin()); - dge.startDrag(Cursor.getDefaultCursor(), new EmptyTransferable(), - new CanvasSourceListener(presenter)); + dge.startDrag(Cursor.getDefaultCursor(), new EmptyTransferable(), new CanvasSourceListener( + presenter)); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPanel.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPanel.java index 61cabd3e..217afa41 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPanel.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPanel.java @@ -48,9 +48,9 @@ class CanvasPanel extends JComponent implements Autoscroll { private VolatileImage bufferImage; private GraphicsConfiguration screenGraphicsConfiguration; - private static final EnumSet drawOptions = EnumSet.of( - DrawOption.GRID, DrawOption.SELECTION, DrawOption.ZOOM, - DrawOption.ANTIALIASING, DrawOption.CONTROL_POINTS); + private static final EnumSet drawOptions = EnumSet.of(DrawOption.GRID, + DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING, + DrawOption.CONTROL_POINTS); public CanvasPanel(IPlugInPort plugInPort) { super(); @@ -59,8 +59,7 @@ class CanvasPanel extends JComponent implements Autoscroll { setFocusable(true); initializeListeners(); initializeDnD(); - GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment - .getLocalGraphicsEnvironment(); + GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = graphicsEnvironment.getScreenDevices(); screenGraphicsConfiguration = devices[0].getDefaultConfiguration(); @@ -73,9 +72,8 @@ class CanvasPanel extends JComponent implements Autoscroll { private void initializeDnD() { // Initialize drag source recognizer. - DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( - this, DnDConstants.ACTION_MOVE, - new CanvasGestureListener(plugInPort)); + DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(this, + DnDConstants.ACTION_MOVE, new CanvasGestureListener(plugInPort)); // Initialize drop target. new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new CanvasTargetListener(plugInPort), true); @@ -96,8 +94,8 @@ class CanvasPanel extends JComponent implements Autoscroll { } protected void createBufferImage() { - bufferImage = screenGraphicsConfiguration - .createCompatibleVolatileImage(getWidth(), getHeight()); + bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(getWidth(), + getHeight()); bufferImage.validate(screenGraphicsConfiguration); Graphics2D g2d = (Graphics2D) bufferImage.getGraphics(); plugInPort.draw(g2d, drawOptions); @@ -157,24 +155,19 @@ class CanvasPanel extends JComponent implements Autoscroll { if (properties.isEmpty()) { } else { - PropertyEditorDialog editor = DialogFactory - .getInstance() + PropertyEditorDialog editor = DialogFactory.getInstance() .createPropertyEditorDialog(properties); editor.setVisible(true); - if (ButtonDialog.OK.equals(editor - .getSelectedButtonCaption())) { + if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { try { - plugInPort - .applyPropertiesToSelection(properties); + plugInPort.applyPropertiesToSelection(properties); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } - for (PropertyWrapper property : editor - .getDefaultedProperties()) { + for (PropertyWrapper property : editor.getDefaultedProperties()) { if (property.getValue() != null) { - plugInPort.setDefaultPropertyValue( - property.getName(), + plugInPort.setDefaultPropertyValue(property.getName(), property.getValue()); } } @@ -182,9 +175,8 @@ class CanvasPanel extends JComponent implements Autoscroll { } } } else { - plugInPort.mouseClicked(e.getPoint(), - e.isControlDown(), e.isShiftDown(), e - .isAltDown()); + plugInPort.mouseClicked(e.getPoint(), e.isControlDown(), e.isShiftDown(), e + .isAltDown()); } } } @@ -195,14 +187,13 @@ class CanvasPanel extends JComponent implements Autoscroll { @Override public void autoscroll(Point cursorLocn) { - scrollRectToVisible(new Rectangle(cursorLocn.x - 15, cursorLocn.y - 15, - 30, 30)); + scrollRectToVisible(new Rectangle(cursorLocn.x - 15, cursorLocn.y - 15, 30, 30)); } @Override public Insets getAutoscrollInsets() { Rectangle rect = getVisibleRect(); - return new Insets(rect.y - 15, rect.x - 15, rect.y + rect.height + 15, - rect.x + rect.width + 15); + return new Insets(rect.y - 15, rect.x - 15, rect.y + rect.height + 15, rect.x + rect.width + + 15); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPlugin.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPlugin.java index 2dc93bee..ea060a81 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPlugin.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasPlugin.java @@ -33,8 +33,7 @@ public class CanvasPlugin implements IPlugIn { this.plugInPort = plugInPort; canvasPanel = new CanvasPanel(plugInPort); try { - plugInPort.injectGUIComponent(getScrollPane(), - SwingConstants.CENTER); + plugInPort.injectGUIComponent(getScrollPane(), SwingConstants.CENTER); } catch (BadPositionException e) { e.printStackTrace(); } @@ -42,10 +41,9 @@ public class CanvasPlugin implements IPlugIn { private RulerScrollPane getScrollPane() { if (scrollPane == null) { - scrollPane = new RulerScrollPane(canvasPanel, - new ProjectDrawingProvider(plugInPort)); - Boolean metric = (Boolean) ConfigurationManager.getInstance() - .getConfigurationItem(METRIC_KEY); + scrollPane = new RulerScrollPane(canvasPanel, new ProjectDrawingProvider(plugInPort)); + Boolean metric = (Boolean) ConfigurationManager.getInstance().getConfigurationItem( + METRIC_KEY); if (metric == null) { metric = true; } @@ -54,8 +52,7 @@ public class CanvasPlugin implements IPlugIn { @Override public void unitsChanged(boolean isMetric) { - ConfigurationManager.getInstance().setConfigurationItem( - METRIC_KEY, isMetric); + ConfigurationManager.getInstance().setConfigurationItem(METRIC_KEY, isMetric); } }); } @@ -64,8 +61,7 @@ public class CanvasPlugin implements IPlugIn { @Override public EnumSet getSubscribedEventTypes() { - return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, - EventType.REPAINT); + return EnumSet.of(EventType.PROJECT_LOADED, EventType.ZOOM_CHANGED, EventType.REPAINT); } @Override @@ -81,8 +77,7 @@ public class CanvasPlugin implements IPlugIn { if ((Boolean) params[1]) { // Scroll to the center. Rectangle visibleRect = canvasPanel.getVisibleRect(); - visibleRect.setLocation( - (canvasPanel.getWidth() - visibleRect.width) / 2, + visibleRect.setLocation((canvasPanel.getWidth() - visibleRect.width) / 2, (canvasPanel.getHeight() - visibleRect.height) / 2); canvasPanel.scrollRectToVisible(visibleRect); canvasPanel.revalidate(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasSourceListener.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasSourceListener.java index 7aed9ebd..da6e92fa 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasSourceListener.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/CanvasSourceListener.java @@ -39,8 +39,7 @@ class CanvasSourceListener implements DragSourceListener { public void dragOver(DragSourceDragEvent dsde) { Point p = dsde.getDragSourceContext().getComponent().getMousePosition(); if (p != null) { - dsde.getDragSourceContext().getComponent().firePropertyChange( - "dragPoint", p.x, p.y); + dsde.getDragSourceContext().getComponent().firePropertyChange("dragPoint", p.x, p.y); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/EmptyTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/EmptyTransferable.java index 1c33f5f2..3f5b8e82 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/EmptyTransferable.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/EmptyTransferable.java @@ -8,8 +8,7 @@ import java.io.IOException; public class EmptyTransferable implements Transferable { @Override - public Object getTransferData(DataFlavor flavor) - throws UnsupportedFlavorException, IOException { + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { throw new UnsupportedFlavorException(flavor); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/PointTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/PointTransferable.java index 872eb878..793936e3 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/PointTransferable.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/PointTransferable.java @@ -8,8 +8,7 @@ import java.io.IOException; public class PointTransferable implements Transferable { - public static final DataFlavor pointFlavor = new DataFlavor(Point.class, - "Java Point"); + public static final DataFlavor pointFlavor = new DataFlavor(Point.class, "Java Point"); private Point startPoint; @@ -19,8 +18,7 @@ public class PointTransferable implements Transferable { } @Override - public Object getTransferData(DataFlavor flavor) - throws UnsupportedFlavorException, IOException { + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.equals(pointFlavor)) { return startPoint; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/SelectionTransferable.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/SelectionTransferable.java index 88d0927f..4328e6f0 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/SelectionTransferable.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/canvas/SelectionTransferable.java @@ -17,16 +17,14 @@ public class SelectionTransferable implements Transferable { private Point startPoint; private List selection; - public SelectionTransferable(List selection, - Point startPoint) { + public SelectionTransferable(List selection, Point startPoint) { super(); this.selection = selection; this.startPoint = startPoint; } @Override - public Object getTransferData(DataFlavor flavor) - throws UnsupportedFlavorException, IOException { + public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.equals(selectionFlavor)) { return selection; } @@ -38,8 +36,7 @@ public class SelectionTransferable implements Transferable { @Override public DataFlavor[] getTransferDataFlavors() { - return new DataFlavor[] { selectionFlavor, - PointTransferable.pointFlavor }; + return new DataFlavor[] { selectionFlavor, PointTransferable.pointFlavor }; } @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/clipboard/ClipboardManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/clipboard/ClipboardManager.java index 66e4ed99..0f682d11 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/clipboard/ClipboardManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/clipboard/ClipboardManager.java @@ -82,8 +82,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { @Override public EnumSet getSubscribedEventTypes() { - return EnumSet.of(EventType.SELECTION_CHANGED, - EventType.PROJECT_MODIFIED); + return EnumSet.of(EventType.SELECTION_CHANGED, EventType.PROJECT_MODIFIED); } @Override @@ -93,8 +92,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { refreshActions(); break; case PROJECT_MODIFIED: - undoHandler.stateChanged((Project) params[0], (Project) params[1], - (String) params[2]); + undoHandler.stateChanged((Project) params[0], (Project) params[1], (String) params[2]); break; } } @@ -104,8 +102,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { cutAction.setEnabled(enabled); copyAction.setEnabled(enabled); try { - pasteAction.setEnabled(clipboard - .isDataFlavorAvailable(ComponentSelection.listFlavor)); + pasteAction.setEnabled(clipboard.isDataFlavorAvailable(ComponentSelection.listFlavor)); } catch (Exception e) { pasteAction.setEnabled(false); } @@ -118,8 +115,8 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { public CutAction() { super(); putValue(AbstractAction.NAME, "Cut"); - putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_X, ActionEvent.CTRL_MASK)); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, + ActionEvent.CTRL_MASK)); putValue(AbstractAction.SMALL_ICON, IconLoader.Cut.getIcon()); } @@ -136,16 +133,16 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { public CopyAction() { super(); putValue(AbstractAction.NAME, "Copy"); - putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_C, ActionEvent.CTRL_MASK)); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, + ActionEvent.CTRL_MASK)); putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon()); } @Override public void actionPerformed(ActionEvent e) { LOG.info("Copy triggered"); - clipboard.setContents(cloner.deepClone(plugInPort - .getSelectedComponents()), ClipboardManager.this); + clipboard.setContents(cloner.deepClone(plugInPort.getSelectedComponents()), + ClipboardManager.this); } } @@ -156,8 +153,8 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { public PasteAction() { super(); putValue(AbstractAction.NAME, "Paste"); - putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_V, ActionEvent.CTRL_MASK)); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, + ActionEvent.CTRL_MASK)); putValue(AbstractAction.SMALL_ICON, IconLoader.Paste.getIcon()); } @@ -182,8 +179,8 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { public SelectAllAction() { super(); putValue(AbstractAction.NAME, "Select All"); - putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( - KeyEvent.VK_A, ActionEvent.CTRL_MASK)); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_A, + ActionEvent.CTRL_MASK)); putValue(AbstractAction.SMALL_ICON, IconLoader.Selection.getIcon()); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/BomDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/BomDialog.java index a2d5297d..06c300ea 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/BomDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/BomDialog.java @@ -54,9 +54,8 @@ public class BomDialog extends JDialog { private ObjectListTable getTable() { if (table == null) { try { - table = new ObjectListTable(BomEntry.class, - new String[] { "getName", "getValue", "getQuantity", - "getNotes/setNotes" }, null); + table = new ObjectListTable(BomEntry.class, new String[] { "getName", + "getValue", "getQuantity", "getNotes/setNotes" }, null); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { @@ -115,9 +114,8 @@ public class BomDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance().showSaveDialog( - FileFilterEnum.CSV.getFilter(), null, - FileFilterEnum.CSV.getExtensions()[0], null); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.CSV.getFilter(), + null, FileFilterEnum.CSV.getExtensions()[0], null); if (file != null) { try { TableExporter.getInstance().exportToCSV(getTable(), file); @@ -141,9 +139,8 @@ public class BomDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance().showSaveDialog( - FileFilterEnum.HTML.getFilter(), null, - FileFilterEnum.HTML.getExtensions()[0], null); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.HTML.getFilter(), + null, FileFilterEnum.HTML.getExtensions()[0], null); if (file != null) { try { TableExporter.getInstance().exportToHTML(getTable(), file); @@ -167,9 +164,8 @@ public class BomDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance().showSaveDialog( - FileFilterEnum.PNG.getFilter(), null, - FileFilterEnum.PNG.getExtensions()[0], null); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(), + null, FileFilterEnum.PNG.getExtensions()[0], null); if (file != null) { try { TableExporter.getInstance().exportToPNG(getTable(), file); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileFilterEnum.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileFilterEnum.java index d8108dca..83d31d47 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileFilterEnum.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileFilterEnum.java @@ -6,12 +6,9 @@ import javax.swing.filechooser.FileFilter; enum FileFilterEnum { - PNG("PNG Images (*.png)", "png"), - PDF("PDF Files (*.pdf)", "pdf"), - DIY("DIY Project Files (*.diy)", "diy"), - EXCEL("Excel Workbooks (*.xls)", "xls"), - CSV("Comma Separated Files (*.csv)", "csv"), - HTML("HTML Files (*.html)", "html"); + PNG("PNG Images (*.png)", "png"), PDF("PDF Files (*.pdf)", "pdf"), DIY( + "DIY Project Files (*.diy)", "diy"), EXCEL("Excel Workbooks (*.xls)", "xls"), CSV( + "Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)", "html"); FileFilter filter; String[] extensions; @@ -23,8 +20,7 @@ enum FileFilterEnum { @Override public boolean accept(File f) { String fileExt = f.getName(); - fileExt = fileExt.substring(fileExt.lastIndexOf('.') + 1) - .toLowerCase(); + fileExt = fileExt.substring(fileExt.lastIndexOf('.') + 1).toLowerCase(); for (String ext : extensions) { if (ext.equals(fileExt)) { return true; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileManager.java index 8e2df0d3..1c471950 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/FileManager.java @@ -59,8 +59,7 @@ public class FileManager implements IPlugIn { public NewAction() { super(); putValue(AbstractAction.NAME, "New"); - putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow - .getIcon()); + putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentPlainYellow.getIcon()); } @Override @@ -82,10 +81,8 @@ public class FileManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance() - .showOpenDialog(FileFilterEnum.DIY.getFilter(), null, - FileFilterEnum.DIY.getExtensions()[0], - new ProjectPreview()); + File file = DialogFactory.getInstance().showOpenDialog(FileFilterEnum.DIY.getFilter(), + null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview()); if (file != null) { LOG.info("Loading project from file."); FileInputStream fis; @@ -117,10 +114,8 @@ public class FileManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance() - .showSaveDialog(FileFilterEnum.DIY.getFilter(), null, - FileFilterEnum.DIY.getExtensions()[0], - new ProjectPreview()); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(), + null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview()); if (file != null) { LOG.info("Saving project to file."); FileOutputStream fos; @@ -151,10 +146,8 @@ public class FileManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance() - .showSaveDialog(FileFilterEnum.DIY.getFilter(), null, - FileFilterEnum.DIY.getExtensions()[0], - new ProjectPreview()); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.DIY.getFilter(), + null, FileFilterEnum.DIY.getExtensions()[0], new ProjectPreview()); if (file != null) { LOG.info("Saving project to file."); FileOutputStream fos; @@ -204,9 +197,8 @@ public class FileManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance().showSaveDialog( - FileFilterEnum.PDF.getFilter(), null, - FileFilterEnum.PDF.getExtensions()[0], null); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PDF.getFilter(), + null, FileFilterEnum.PDF.getExtensions()[0], null); if (file != null) { DrawingExporter.getInstance().exportPDF(drawingProvider, file); } @@ -225,9 +217,8 @@ public class FileManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - File file = DialogFactory.getInstance().showSaveDialog( - FileFilterEnum.PNG.getFilter(), null, - FileFilterEnum.PNG.getExtensions()[0], null); + File file = DialogFactory.getInstance().showSaveDialog(FileFilterEnum.PNG.getFilter(), + null, FileFilterEnum.PNG.getExtensions()[0], null); if (file != null) { DrawingExporter.getInstance().exportPNG(drawingProvider, file); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectDrawingProvider.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectDrawingProvider.java index 730a80f8..f7384127 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectDrawingProvider.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectDrawingProvider.java @@ -26,8 +26,7 @@ public class ProjectDrawingProvider implements IDrawingProvider { @Override public void draw(Graphics g) { - plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, - DrawOption.ANTIALIASING)); + plugInPort.draw((Graphics2D) g, EnumSet.of(DrawOption.ZOOM, DrawOption.ANTIALIASING)); } @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectPreview.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectPreview.java index e4a8af00..90a6f482 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectPreview.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/file/ProjectPreview.java @@ -35,8 +35,7 @@ import com.thoughtworks.xstream.io.xml.DomDriver; * * @author Branislav Stojkovic */ -public class ProjectPreview extends JPanel implements PropertyChangeListener, - IFileChooserAccessory { +public class ProjectPreview extends JPanel implements PropertyChangeListener, IFileChooserAccessory { private static final long serialVersionUID = 1L; @@ -148,8 +147,7 @@ public class ProjectPreview extends JPanel implements PropertyChangeListener, presenter.draw(g2d, EnumSet.noneOf(DrawOption.class)); g2d.setColor(Color.black); - g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - - (int) (1 / zoomRatio)); + g2d.drawRect(0, 0, d.width - (int) (1 / zoomRatio), d.height - (int) (1 / zoomRatio)); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/help/HelpManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/help/HelpManager.java index c35e408a..4e540151 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/help/HelpManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/help/HelpManager.java @@ -37,10 +37,10 @@ public class HelpManager implements IPlugIn { private AboutDialog getAboutDialog() { if (aboutDialog == null) { - aboutDialog = DialogFactory.getInstance().createAboutDialog( - "DIY Layout Creator 4", IconLoader.BlackBoard.getIcon(), - plugInPort.getCurrentVersionNumber().toString(), - "Bane Stojkovic", "diy-fever.com", "bancika@gmail.com", ""); + aboutDialog = DialogFactory.getInstance().createAboutDialog("DIY Layout Creator 4", + IconLoader.BlackBoard.getIcon(), + plugInPort.getCurrentVersionNumber().toString(), "Bane Stojkovic", + "diy-fever.com", "bancika@gmail.com", ""); } return aboutDialog; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/OnlineManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/OnlineManager.java index c91d2424..c0468994 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/OnlineManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/OnlineManager.java @@ -95,8 +95,7 @@ public class OnlineManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - LoginDialog dialog = DialogFactory.getInstance() - .createLoginDialog(); + LoginDialog dialog = DialogFactory.getInstance().createLoginDialog(); dialog.setVisible(true); } } @@ -113,8 +112,7 @@ public class OnlineManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - NewUserDialog dialog = DialogFactory.getInstance() - .createNewUserDialog(); + NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog(); dialog.setVisible(true); } } @@ -131,8 +129,7 @@ public class OnlineManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - UploadDialog dialog = DialogFactory.getInstance() - .createUploadDialog(); + UploadDialog dialog = DialogFactory.getInstance().createUploadDialog(); dialog.setVisible(true); } } @@ -149,9 +146,8 @@ public class OnlineManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - ProgressDialog dialog = DialogFactory.getInstance() - .createProgressDialog("Test", new String[] {}, "Some text", - false); + ProgressDialog dialog = DialogFactory.getInstance().createProgressDialog("Test", + new String[] {}, "Some text", false); dialog.setVisible(true); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/Test.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/Test.java index 8014e6bb..034b9b7d 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/Test.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/Test.java @@ -4,7 +4,6 @@ import org.apache.log4j.BasicConfigurator; import com.diyfever.diylc.plugins.online.presenter.LibraryPresenter; - public class Test { /** @@ -13,17 +12,17 @@ public class Test { */ public static void main(String[] args) throws Exception { BasicConfigurator.configure(); - LibraryPresenter pres = new LibraryPresenter(); -// pres.createUser("bancika", "pwd", "bancika@gmail.com"); - System.out.println(pres.fetchCategories()); - pres.login("bancika", "pwd"); - int id = pres.fetchMyProjectRows().get(0).getId(); - // InputStream stream = pres.downloadProjectContent(id); - // byte[] buf = new byte[100]; - // int len = stream.read(buf); - System.out.println(pres.downloadProjectContent(id)); - // System.out.println(pres.hashPassword("bancikabancikabancikabancikabancika")); - pres.dispose(); + LibraryPresenter pres = new LibraryPresenter(); + // pres.createUser("bancika", "pwd", "bancika@gmail.com"); + System.out.println(pres.fetchCategories()); + pres.login("bancika", "pwd"); + int id = pres.fetchMyProjectRows().get(0).getId(); + // InputStream stream = pres.downloadProjectContent(id); + // byte[] buf = new byte[100]; + // int len = stream.read(buf); + System.out.println(pres.downloadProjectContent(id)); + // System.out.println(pres.hashPassword("bancikabancikabancikabancikabancika")); + pres.dispose(); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/model/ProjectEntity.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/model/ProjectEntity.java index af5f4921..e23374f1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/model/ProjectEntity.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/model/ProjectEntity.java @@ -21,8 +21,7 @@ public class ProjectEntity implements Serializable { super(); } - public ProjectEntity(int id, String name, String description, String owner, - String category) { + public ProjectEntity(int id, String name, String description, String owner, String category) { super(); this.id = id; this.name = name; @@ -88,10 +87,8 @@ public class ProjectEntity implements Serializable { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result - + ((category == null) ? 0 : category.hashCode()); - result = prime * result - + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((category == null) ? 0 : category.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + id; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((owner == null) ? 0 : owner.hashCode()); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/presenter/LibraryPresenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/presenter/LibraryPresenter.java index 2ee41452..ec7960bd 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/presenter/LibraryPresenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/presenter/LibraryPresenter.java @@ -53,19 +53,17 @@ public class LibraryPresenter { } } - public void createUser(String userName, String password, String email) - throws SQLException, NotConnectedException, AlreadyExistsException { + public void createUser(String userName, String password, String email) throws SQLException, + NotConnectedException, AlreadyExistsException { LOG.info("Creating user: " + userName); if (dbManager.isConnected()) { - ResultSet resultSet = dbManager.getResultSet(String.format( - USER_SQL, userName)); + ResultSet resultSet = dbManager.getResultSet(String.format(USER_SQL, userName)); if (resultSet.next()) { throw new AlreadyExistsException(); } - dbManager.updateDB(String.format(CREATE_USER_SQL, userName, - hashPassword(password), email)); - resultSet = dbManager.getResultSet(String - .format(USER_SQL, userName)); + dbManager.updateDB(String.format(CREATE_USER_SQL, userName, hashPassword(password), + email)); + resultSet = dbManager.getResultSet(String.format(USER_SQL, userName)); if (resultSet.next()) { LOG.info("Logged in as \"" + userName + "\""); currentUserId = resultSet.getInt("user_id"); @@ -80,8 +78,7 @@ public class LibraryPresenter { NotConnectedException { LOG.info("Logging in as: " + userName); if (dbManager.isConnected()) { - ResultSet resultSet = dbManager.getResultSet(String.format( - USER_SQL, userName)); + ResultSet resultSet = dbManager.getResultSet(String.format(USER_SQL, userName)); if (resultSet.next()) { String dbPassword = resultSet.getString("password"); String hashPassword = hashPassword(password); @@ -99,15 +96,13 @@ public class LibraryPresenter { } } - public Map fetchCategories() throws SQLException, - NotConnectedException { + public Map fetchCategories() throws SQLException, NotConnectedException { LOG.info("Fetching categories"); if (dbManager.isConnected()) { Map categories = new HashMap(); ResultSet resultSet = dbManager.getResultSet(CATEGORY_SQL); while (resultSet.next()) { - categories.put(resultSet.getInt("category_id"), resultSet - .getString("name")); + categories.put(resultSet.getInt("category_id"), resultSet.getString("name")); } return categories; } else { @@ -116,19 +111,18 @@ public class LibraryPresenter { } } - public List fetchMyProjectRows() - throws NotLoggedInException, NotConnectedException, SQLException { + public List fetchMyProjectRows() throws NotLoggedInException, + NotConnectedException, SQLException { if (dbManager.isConnected()) { if (isLoggedIn()) { Map categories = fetchCategories(); List projects = new ArrayList(); - ResultSet resultSet = dbManager.getResultSet(String.format( - MY_PROJECTS_SQL, currentUserId)); + ResultSet resultSet = dbManager.getResultSet(String.format(MY_PROJECTS_SQL, + currentUserId)); while (resultSet.next()) { - projects.add(new ProjectEntity(resultSet - .getInt("project_id"), resultSet.getString("name"), - resultSet.getString("description"), "", categories - .get(resultSet.getInt("category_id")))); + projects.add(new ProjectEntity(resultSet.getInt("project_id"), resultSet + .getString("name"), resultSet.getString("description"), "", categories + .get(resultSet.getInt("category_id")))); } return projects; } else { @@ -141,16 +135,14 @@ public class LibraryPresenter { } } - public String downloadProjectContent(int projectId) - throws NotConnectedException, NotExistsException, SQLException { + public String downloadProjectContent(int projectId) throws NotConnectedException, + NotExistsException, SQLException { if (dbManager.isConnected()) { - ResultSet resultSet = dbManager.getResultSet(String.format( - PROJECT_SQL, projectId)); + ResultSet resultSet = dbManager.getResultSet(String.format(PROJECT_SQL, projectId)); if (resultSet.next()) { return resultSet.getString("content"); } - throw new NotExistsException("Project with id = " + projectId - + " does not exist."); + throw new NotExistsException("Project with id = " + projectId + " does not exist."); } else { LOG.error("Not connected"); throw new NotConnectedException(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/LoginDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/LoginDialog.java index a055159c..bac1fc10 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/LoginDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/LoginDialog.java @@ -82,31 +82,29 @@ public class LoginDialog extends ButtonDialog { this.password = new String(getPasswordField().getPassword()); JButton okButton = getButton(OK); - okButton.setEnabled((this.userName.length() > 0) - && (this.password.length() > 0)); + okButton.setEnabled((this.userName.length() > 0) && (this.password.length() > 0)); } private JTextField getUserNameField() { if (userNameField == null) { userNameField = new JTextField(); - userNameField.getDocument().addDocumentListener( - new DocumentListener() { + userNameField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return userNameField; } @@ -114,24 +112,23 @@ public class LoginDialog extends ButtonDialog { private JPasswordField getPasswordField() { if (passwordField == null) { passwordField = new JPasswordField(); - passwordField.getDocument().addDocumentListener( - new DocumentListener() { + passwordField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return passwordField; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/NewUserDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/NewUserDialog.java index 828fd82e..c6a1cba1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/NewUserDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/NewUserDialog.java @@ -100,8 +100,7 @@ public class NewUserDialog extends ButtonDialog { private void refreshState() { this.userName = getUserNameField().getText(); String password = new String(getPasswordField().getPassword()); - String confirmPassword = new String(getConfirmPasswordField() - .getPassword()); + String confirmPassword = new String(getConfirmPasswordField().getPassword()); if (password.equals(confirmPassword)) { this.password = password; } else { @@ -109,31 +108,30 @@ public class NewUserDialog extends ButtonDialog { } this.email = getEmailField().getText(); JButton okButton = getButton(OK); - okButton.setEnabled((this.userName.length() > 0) - && (this.password != null) && (this.password.length() > 0)); + okButton.setEnabled((this.userName.length() > 0) && (this.password != null) + && (this.password.length() > 0)); } private JTextField getUserNameField() { if (userNameField == null) { userNameField = new JTextField(); - userNameField.getDocument().addDocumentListener( - new DocumentListener() { + userNameField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return userNameField; } @@ -141,24 +139,23 @@ public class NewUserDialog extends ButtonDialog { private JPasswordField getPasswordField() { if (passwordField == null) { passwordField = new JPasswordField(); - passwordField.getDocument().addDocumentListener( - new DocumentListener() { + passwordField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return passwordField; } @@ -166,24 +163,23 @@ public class NewUserDialog extends ButtonDialog { private JPasswordField getConfirmPasswordField() { if (confirmPasswordField == null) { confirmPasswordField = new JPasswordField(); - confirmPasswordField.getDocument().addDocumentListener( - new DocumentListener() { + confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return confirmPasswordField; } @@ -191,24 +187,23 @@ public class NewUserDialog extends ButtonDialog { private JTextField getEmailField() { if (emailField == null) { emailField = new JTextField(); - emailField.getDocument().addDocumentListener( - new DocumentListener() { + emailField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return emailField; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/UploadDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/UploadDialog.java index 88ecf2c2..fea17e85 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/UploadDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/online/view/UploadDialog.java @@ -34,9 +34,7 @@ public class UploadDialog extends ButtonDialog { + "You can not use Online Library to advertise products or services.
" + BULLET + "Users that do not follow these terms may be banned from the server, with or without notice.
" - + BULLET - + "Administrator is not responsible for library contents.
" - + ""; + + BULLET + "Administrator is not responsible for library contents.
" + ""; private JPanel mainPanel; private JLabel termsLabel; @@ -98,9 +96,8 @@ public class UploadDialog extends ButtonDialog { termsLabel = new JLabel(); termsLabel.setOpaque(true); termsLabel.setBackground(UIManager.getColor("ToolTip.background")); - termsLabel.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createEtchedBorder(), BorderFactory - .createEmptyBorder(2, 2, 2, 2))); + termsLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory + .createEtchedBorder(), BorderFactory.createEmptyBorder(2, 2, 2, 2))); termsLabel.setText(TERMS_HTML); } return termsLabel; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/statusbar/StatusBar.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/statusbar/StatusBar.java index 065c7d13..e9427bc6 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/statusbar/StatusBar.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/statusbar/StatusBar.java @@ -49,8 +49,7 @@ public class StatusBar extends JPanel implements IPlugIn { private JComboBox getZoomBox() { if (zoomBox == null) { - zoomBox = new JComboBox(new Double[] { 0.25d, 0.5d, 0.75d, 1d, - 1.5d, 2d }); + zoomBox = new JComboBox(new Double[] { 0.25d, 0.5d, 0.75d, 1d, 1.5d, 2d }); zoomBox.setSelectedItem(1d); zoomBox.setFocusable(false); zoomBox.setRenderer(new PercentageListCellRenderer()); @@ -168,8 +167,7 @@ public class StatusBar extends JPanel implements IPlugIn { private void refreshStatusText() { if (componentSlot == null) { - if ((componentsUnderCursor == null) - || (componentsUnderCursor.isEmpty())) { + if ((componentsUnderCursor == null) || (componentsUnderCursor.isEmpty())) { getStatusLabel().setText(""); } else { String formattedNames = ""; @@ -178,17 +176,14 @@ public class StatusBar extends JPanel implements IPlugIn { if (n > 1) { formattedNames += ", "; } - formattedNames += ComponentProcessor.getInstance() - .extractBomName(component) + formattedNames += ComponentProcessor.getInstance().extractBomName(component) + " (" + n++ + ")"; } - getStatusLabel().setText( - "" + "Edit: " + formattedNames + ""); + getStatusLabel().setText("" + "Edit: " + formattedNames + ""); } } else { getStatusLabel().setText( - "Click on the canvas to create a new " - + componentSlot.getName() + "Click on the canvas to create a new " + componentSlot.getName() + " or press Esc to cancel"); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentButton.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentButton.java index 09e03d87..bc0e8bfd 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentButton.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentButton.java @@ -23,8 +23,7 @@ class ComponentButton extends JButton { private IPlugInPort plugInPort; private IComponentType componentType; - public ComponentButton(final IPlugInPort plugInPort, - final IComponentType componentType) { + public ComponentButton(final IPlugInPort plugInPort, final IComponentType componentType) { super(componentType.getIcon()); this.plugInPort = plugInPort; this.componentType = componentType; @@ -62,7 +61,7 @@ class ComponentButton extends JButton { DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, - new ToolboxGestureListener(plugInPort, componentType - .getComponentInstanceClass().getName())); + new ToolboxGestureListener(plugInPort, componentType.getComponentInstanceClass() + .getName())); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentTabbedPane.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentTabbedPane.java index d2f36cab..b7ab3d67 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentTabbedPane.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ComponentTabbedPane.java @@ -19,18 +19,15 @@ class ComponentTabbedPane extends JTabbedPane { public ComponentTabbedPane(IPlugInPort plugInPort) { super(); this.plugInPort = plugInPort; - Map> componentTypes = plugInPort - .getComponentTypes(); - for (Map.Entry> entry : componentTypes - .entrySet()) { + Map> componentTypes = plugInPort.getComponentTypes(); + for (Map.Entry> entry : componentTypes.entrySet()) { addTab(entry.getKey(), createComponentPanel(entry.getValue())); } } private Container createComponentPanel(List componentTypes) { Container componentPanel = new Container(); - componentPanel - .setLayout(new BoxLayout(componentPanel, BoxLayout.X_AXIS)); + componentPanel.setLayout(new BoxLayout(componentPanel, BoxLayout.X_AXIS)); for (IComponentType componentType : componentTypes) { JButton button = new ComponentButton(plugInPort, componentType); componentPanel.add(button); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolBox.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolBox.java index 0b4e0c69..b79d3d43 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolBox.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolBox.java @@ -14,8 +14,7 @@ public class ToolBox implements IPlugIn { @Override public void connect(IPlugInPort plugInPort) { try { - plugInPort.injectGUIComponent(new ComponentTabbedPane(plugInPort), - SwingConstants.TOP); + plugInPort.injectGUIComponent(new ComponentTabbedPane(plugInPort), SwingConstants.TOP); } catch (BadPositionException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolboxGestureListener.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolboxGestureListener.java index a1273d4f..6a6dd76e 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolboxGestureListener.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/plugins/toolbox/ToolboxGestureListener.java @@ -26,8 +26,7 @@ class ToolboxGestureListener implements DragGestureListener { @Override public void dragGestureRecognized(DragGestureEvent dge) { presenter.dragStarted(dge.getDragOrigin()); - dge.startDrag(Cursor.getDefaultCursor(), - new StringSelection(className), new ToolboxSourceListener( - presenter)); + dge.startDrag(Cursor.getDefaultCursor(), new StringSelection(className), + new ToolboxSourceListener(presenter)); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java index 494872de..12f6268f 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/ComponentProcessor.java @@ -20,8 +20,7 @@ import com.rits.cloning.Cloner; public class ComponentProcessor { - private static final Logger LOG = Logger - .getLogger(ComponentProcessor.class); + private static final Logger LOG = Logger.getLogger(ComponentProcessor.class); private static ComponentProcessor instance; @@ -44,8 +43,7 @@ public class ComponentProcessor { this.controlPointCache = new HashMap, List>(); } - public List extractProperties( - Class clazz) { + public List extractProperties(Class clazz) { if (propertyCache.containsKey(clazz)) { return cloner.deepClone(propertyCache.get(clazz)); } @@ -53,12 +51,10 @@ public class ComponentProcessor { for (Method method : clazz.getMethods()) { if (method.getName().startsWith("get")) { try { - Method setter = clazz.getMethod("set" - + method.getName().substring(3), method + Method setter = clazz.getMethod("set" + method.getName().substring(3), method .getReturnType()); if (method.isAnnotationPresent(EditableProperty.class)) { - EditableProperty annotation = method - .getAnnotation(EditableProperty.class); + EditableProperty annotation = method.getAnnotation(EditableProperty.class); String name; if (annotation.name().equals("")) { name = method.getName().substring(3); @@ -66,13 +62,12 @@ public class ComponentProcessor { name = annotation.name(); } PropertyWrapper property = new PropertyWrapper(name, - method.getReturnType(), method, setter, - annotation.defaultable()); + method.getReturnType(), method, setter, annotation.defaultable()); properties.add(property); } } catch (NoSuchMethodException e) { - LOG.debug("No matching setter found for \"" - + method.getName() + "\". Skipping..."); + LOG.debug("No matching setter found for \"" + method.getName() + + "\". Skipping..."); } } } @@ -81,8 +76,7 @@ public class ComponentProcessor { return cloner.deepClone(properties); } - public List extractControlPoints( - Class clazz) { + public List extractControlPoints(Class clazz) { if (controlPointCache.containsKey(clazz)) { return cloner.deepClone(controlPointCache.get(clazz)); } @@ -90,27 +84,22 @@ public class ComponentProcessor { for (Method method : clazz.getMethods()) { if (method.getName().startsWith("get")) { try { - Method setter = clazz.getMethod("set" - + method.getName().substring(3), method + Method setter = clazz.getMethod("set" + method.getName().substring(3), method .getReturnType()); if (method.isAnnotationPresent(ControlPoint.class)) { if (method.getReturnType().equals(Point.class)) { - ControlPoint annotation = method - .getAnnotation(ControlPoint.class); - ControlPointWrapper controlPoint = new ControlPointWrapper( - method.getName().substring(3), method, - setter, annotation.editable(), annotation - .sticky(), annotation - .visibilityPolicy()); + ControlPoint annotation = method.getAnnotation(ControlPoint.class); + ControlPointWrapper controlPoint = new ControlPointWrapper(method + .getName().substring(3), method, setter, annotation.editable(), + annotation.sticky(), annotation.visibilityPolicy()); controlPoints.add(controlPoint); } else { - LOG - .debug("Control point return type must be java.awt.Point."); + LOG.debug("Control point return type must be java.awt.Point."); } } } catch (NoSuchMethodException e) { - LOG.debug("No matching setter found for \"" - + method.getName() + "\". Skipping..."); + LOG.debug("No matching setter found for \"" + method.getName() + + "\". Skipping..."); } } } @@ -138,8 +127,7 @@ public class ComponentProcessor { } for (int i = 1; i < selectedComponents.size(); i++) { IComponentInstance component = selectedComponents.get(i); - List newProperties = extractProperties(component - .getClass()); + List newProperties = extractProperties(component.getClass()); for (PropertyWrapper property : newProperties) { try { property.readFrom(component); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/G2DWrapper.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/G2DWrapper.java index 3fce8e09..082199e7 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/G2DWrapper.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/G2DWrapper.java @@ -180,8 +180,7 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public void drawString(AttributedCharacterIterator iterator, float x, - float y) { + public void drawString(AttributedCharacterIterator iterator, float x, float y) { canvasGraphics.drawString(iterator, x, y); // FIXME: process map } @@ -441,8 +440,7 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public void drawArc(int x, int y, int width, int height, int startAngle, - int arcAngle) { + public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { canvasGraphics.drawArc(x, y, width, height, startAngle, arcAngle); } @@ -459,8 +457,7 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public boolean drawImage(Image img, int x, int y, Color bgcolor, - ImageObserver observer) { + public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { // FIXME: map return canvasGraphics.drawImage(img, x, y, bgcolor, observer); } @@ -469,8 +466,7 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public boolean drawImage(Image img, int x, int y, int width, int height, - ImageObserver observer) { + public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { // FIXME: map return canvasGraphics.drawImage(img, x, y, width, height, observer); } @@ -479,34 +475,30 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public boolean drawImage(Image img, int x, int y, int width, int height, - 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, + public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { // FIXME: map - return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, - observer); + 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) { + // FIXME: map + return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } /** @@ -545,8 +537,7 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public void drawRoundRect(int x, int y, int width, int height, - int arcWidth, int arcHeight) { + public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { canvasGraphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight); } @@ -554,11 +545,9 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public void fillArc(int x, int y, int width, int height, int startAngle, - int arcAngle) { + public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { canvasGraphics.fillArc(x, y, width, height, startAngle, arcAngle); - appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, - Arc2D.PIE)); + appendShape(new Arc2D.Double(x, y, width, height, startAngle, arcAngle, Arc2D.PIE)); } /** @@ -592,11 +581,9 @@ class G2DWrapper extends Graphics2D { *{@inheritDoc} **/ @Override - public void fillRoundRect(int x, int y, int width, int height, - int arcWidth, int arcHeight) { + public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { canvasGraphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight); - appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, - arcHeight)); + appendShape(new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight)); } /** diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java index 819e0502..b2225d56 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/presenter/Presenter.java @@ -55,8 +55,7 @@ public class Presenter implements IPlugInPort { private static final Logger LOG = Logger.getLogger(Presenter.class); - private static final VersionNumber CURRENT_VERSION = new VersionNumber(0, - 0, 0); + private static final VersionNumber CURRENT_VERSION = new VersionNumber(0, 0, 0); private static final String DEFAULTS_KEY = "defaults"; private static final int CONTROL_POINT_SENSITIVITY = 4; @@ -104,8 +103,7 @@ public class Presenter implements IPlugInPort { } public void installPlugin(IPlugIn plugIn) { - LOG.debug(String.format("installPlugin(%s)", plugIn.getClass() - .getSimpleName())); + LOG.debug(String.format("installPlugin(%s)", plugIn.getClass().getSimpleName())); plugIns.add(plugIn); plugIn.connect(this); messageDispatcher.registerListener(plugIn); @@ -135,10 +133,8 @@ public class Presenter implements IPlugInPort { @Override public Cursor getCursorAt(Point point) { // Scale point to remove zoom factor. - Point2D scaledPoint = new Point2D.Double(point.getX() / zoomLevel, - point.getY() / zoomLevel); - for (Map.Entry entry : componentAreaMap - .entrySet()) { + Point2D scaledPoint = new Point2D.Double(point.getX() / zoomLevel, point.getY() / zoomLevel); + for (Map.Entry entry : componentAreaMap.entrySet()) { if (entry.getValue().contains(scaledPoint)) { return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); } @@ -167,8 +163,7 @@ public class Presenter implements IPlugInPort { LOG.info("Loading project: " + project.getTitle()); this.currentProject = project; selectedComponents.clear(); - messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, - freshStart); + messageDispatcher.dispatchMessage(EventType.PROJECT_LOADED, project, freshStart); messageDispatcher.dispatchMessage(EventType.REPAINT); } @@ -177,20 +172,17 @@ public class Presenter implements IPlugInPort { if (componentTypes == null) { LOG.info("Loading component types."); componentTypes = new HashMap>(); - List> componentTypeClasses = JarScanner.getInstance() - .scanFolder("library/", IComponentType.class); + List> componentTypeClasses = JarScanner.getInstance().scanFolder("library/", + IComponentType.class); for (Class clazz : componentTypeClasses) { try { - IComponentType componentType = (IComponentType) clazz - .newInstance(); + IComponentType componentType = (IComponentType) clazz.newInstance(); List nestedList; if (componentTypes.containsKey(componentType.getCategory())) { - nestedList = componentTypes.get(componentType - .getCategory()); + nestedList = componentTypes.get(componentType.getCategory()); } else { nestedList = new ArrayList(); - componentTypes.put(componentType.getCategory(), - nestedList); + componentTypes.put(componentType.getCategory(), nestedList); } nestedList.add(componentType); } catch (InstantiationException e) { @@ -211,8 +203,9 @@ public class Presenter implements IPlugInPort { G2DWrapper g2dWrapper = new G2DWrapper(g2d); if (drawOptions.contains(DrawOption.ANTIALIASING)) { - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + g2d + .setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); } AffineTransform initialTx = g2d.getTransform(); @@ -236,15 +229,13 @@ public class Presenter implements IPlugInPort { } } - if ((drawOptions.contains(DrawOption.ZOOM)) - && (Math.abs(1.0 - zoomLevel) > 1e-4)) { + if ((drawOptions.contains(DrawOption.ZOOM)) && (Math.abs(1.0 - zoomLevel) > 1e-4)) { g2dWrapper.scale(zoomLevel, zoomLevel); } g2dWrapper.resetTx(); - List components = getCurrentProject() - .getComponents(); + List components = getCurrentProject().getComponents(); componentAreaMap.clear(); if (components != null) { for (IComponentInstance component : components) { @@ -253,14 +244,12 @@ public class Presenter implements IPlugInPort { .contains(DrawOption.SELECTION)) ? ComponentState.SELECTED : ComponentState.NORMAL; component.draw(g2dWrapper, state); - componentAreaMap.put(component, g2dWrapper - .finishedDrawingComponent()); + componentAreaMap.put(component, g2dWrapper.finishedDrawingComponent()); // Draw control points if (drawOptions.contains(DrawOption.CONTROL_POINTS)) { - List controlPoints = ComponentProcessor - .getInstance().extractControlPoints( - component.getClass()); + List controlPoints = ComponentProcessor.getInstance() + .extractControlPoints(component.getClass()); for (ControlPointWrapper controlPoint : controlPoints) { try { controlPoint.readFrom(component); @@ -273,9 +262,8 @@ public class Presenter implements IPlugInPort { // .getValue().y - 2, 5, 5); } } catch (Exception e) { - LOG - .error("Could not obtain control points for component of type " - + component.getClass().getName()); + LOG.error("Could not obtain control points for component of type " + + component.getClass().getName()); } } } @@ -285,8 +273,7 @@ public class Presenter implements IPlugInPort { g2d.setTransform(initialTx); // At the end draw selection rectangle. - if (drawOptions.contains(DrawOption.SELECTION) - && (selectionRect != null)) { + if (drawOptions.contains(DrawOption.SELECTION) && (selectionRect != null)) { g2d.setColor(Color.white); g2d.drawRect(selectionRect.x, selectionRect.y, selectionRect.width, selectionRect.height); @@ -298,8 +285,7 @@ public class Presenter implements IPlugInPort { } @Override - public void injectGUIComponent(JComponent component, int position) - throws BadPositionException { + public void injectGUIComponent(JComponent component, int position) throws BadPositionException { view.addComponent(component, position); } @@ -321,8 +307,7 @@ public class Presenter implements IPlugInPort { */ private List findComponentsAt(Point point) { List components = new ArrayList(); - for (Map.Entry entry : componentAreaMap - .entrySet()) { + for (Map.Entry entry : componentAreaMap.entrySet()) { if (entry.getValue().contains(point)) { components.add(entry.getKey()); } @@ -331,15 +316,13 @@ public class Presenter implements IPlugInPort { } @Override - public void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, - boolean altDown) { - LOG.debug(String.format("mouseClicked(%s, %s, %s, %s)", point, - ctrlDown, shiftDown, altDown)); + public void mouseClicked(Point point, boolean ctrlDown, boolean shiftDown, boolean altDown) { + LOG.debug(String + .format("mouseClicked(%s, %s, %s, %s)", point, ctrlDown, shiftDown, altDown)); Point scaledPoint = scalePoint(point); if (componentSlot != null) { try { - instantiateComponent(componentSlot.getComponentInstanceClass(), - scaledPoint); + instantiateComponent(componentSlot.getComponentInstanceClass(), scaledPoint); } catch (Exception e) { LOG.error("Error instatiating component of type: " + componentSlot.getComponentInstanceClass().getName()); @@ -366,8 +349,7 @@ public class Presenter implements IPlugInPort { selectedComponents.add(component); } } - messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, - selectedComponents); + messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); messageDispatcher.dispatchMessage(EventType.REPAINT); } } @@ -377,8 +359,8 @@ public class Presenter implements IPlugInPort { List components = new ArrayList(); Point scaledPoint = scalePoint(point); for (IComponentInstance component : currentProject.getComponents()) { - List currentPoints = ComponentProcessor - .getInstance().extractControlPoints(component.getClass()); + List currentPoints = ComponentProcessor.getInstance() + .extractControlPoints(component.getClass()); for (ControlPointWrapper controlPoint : currentPoints) { if (shouldShowControlPoint(controlPoint, component)) { try { @@ -388,17 +370,15 @@ public class Presenter implements IPlugInPort { break; } } catch (Exception e) { - LOG - .warn("Error reading control point for component of type: " - + component.getClass().getName()); + LOG.warn("Error reading control point for component of type: " + + component.getClass().getName()); } } } } if (!components.equals(componentsUnderCursor)) { componentsUnderCursor = components; - messageDispatcher.dispatchMessage( - EventType.AVAILABLE_CTRL_POINTS_CHANGED, components); + messageDispatcher.dispatchMessage(EventType.AVAILABLE_CTRL_POINTS_CHANGED, components); } } @@ -426,16 +406,14 @@ public class Presenter implements IPlugInPort { List components = findComponentsAt(scaledPoint); if (components.isEmpty()) { selectedComponents.clear(); - messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, - selectedComponents); + messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); messageDispatcher.dispatchMessage(EventType.REPAINT); } else { IComponentInstance component = components.get(0); if (!selectedComponents.contains(component)) { selectedComponents.clear(); selectedComponents.add(component); - messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, - selectedComponents); + messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); messageDispatcher.dispatchMessage(EventType.REPAINT); } } @@ -445,8 +423,7 @@ public class Presenter implements IPlugInPort { public boolean dragOver(Point point) { if (selectedComponents.isEmpty()) { this.selectionRect = Utils.createRectangle(point, dragStartPoint); - messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED, - selectionRect); + messageDispatcher.dispatchMessage(EventType.SELECTION_RECT_CHANGED, selectionRect); messageDispatcher.dispatchMessage(EventType.REPAINT); } return true; @@ -462,23 +439,20 @@ public class Presenter implements IPlugInPort { // If there's no selection finalize selectionRect and see which // components intersect with it. if (point != null) { - this.selectionRect = Utils.createRectangle(point, - dragStartPoint); + this.selectionRect = Utils.createRectangle(point, dragStartPoint); } selectedComponents.clear(); for (IComponentInstance component : currentProject.getComponents()) { Area area = componentAreaMap.get(component); if ((area != null) && area.intersects(selectionRect.x / zoomLevel, - selectionRect.y / zoomLevel, - selectionRect.width / zoomLevel, + selectionRect.y / zoomLevel, selectionRect.width / zoomLevel, selectionRect.height / zoomLevel)) { selectedComponents.add(component); } } selectionRect = null; - messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, - selectedComponents); + messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED, selectedComponents); } else { Project oldProject = cloner.deepClone(currentProject); @@ -486,9 +460,8 @@ public class Presenter implements IPlugInPort { int dx = (int) ((point.x - dragStartPoint.x) / zoomLevel); int dy = (int) ((point.y - dragStartPoint.y) / zoomLevel); for (IComponentInstance component : selectedComponents) { - List controlPoints = ComponentProcessor - .getInstance().extractControlPoints( - component.getClass()); + List controlPoints = ComponentProcessor.getInstance() + .extractControlPoints(component.getClass()); for (ControlPointWrapper controlPoint : controlPoints) { try { controlPoint.readFrom(component); @@ -497,14 +470,13 @@ public class Presenter implements IPlugInPort { } controlPoint.writeTo(component); } catch (Exception e) { - LOG.error("Could not translate control points: " - + e.getMessage()); + LOG.error("Could not translate control points: " + e.getMessage()); } } } if (!oldProject.equals(currentProject)) { - messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, - oldProject, cloner.deepClone(currentProject), "Move"); + messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner + .deepClone(currentProject), "Move"); } } messageDispatcher.dispatchMessage(EventType.REPAINT); @@ -512,13 +484,12 @@ public class Presenter implements IPlugInPort { } @Override - public void addComponents(List components, - Point preferredPoint) { + public void addComponents(List components, Point preferredPoint) { LOG.debug(String.format("addComponents(%s)", components)); Project oldProject = cloner.deepClone(currentProject); currentProject.getComponents().addAll(components); - messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, - oldProject, cloner.deepClone(currentProject), "Add"); + messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner + .deepClone(currentProject), "Add"); messageDispatcher.dispatchMessage(EventType.REPAINT); } @@ -558,27 +529,23 @@ public class Presenter implements IPlugInPort { // componentClass.getName() + ":" + propertyName); // } public void setDefaultPropertyValue(String propertyName, Object value) { - LOG.debug(String.format("setDefaultPropertyValue(%s, %s)", - propertyName, value)); - Map defaultMap = (Map) ConfigurationManager - .getInstance().getConfigurationItem(DEFAULTS_KEY); + LOG.debug(String.format("setDefaultPropertyValue(%s, %s)", propertyName, value)); + Map defaultMap = (Map) ConfigurationManager.getInstance() + .getConfigurationItem(DEFAULTS_KEY); if (defaultMap == null) { defaultMap = new HashMap(); - ConfigurationManager.getInstance().setConfigurationItem( - DEFAULTS_KEY, defaultMap); + ConfigurationManager.getInstance().setConfigurationItem(DEFAULTS_KEY, defaultMap); } for (IComponentInstance component : selectedComponents) { String className = component.getClass().getName(); - LOG.debug("Default property value set for " + className + ":" - + propertyName); + LOG.debug("Default property value set for " + className + ":" + propertyName); defaultMap.put(className + ":" + propertyName, value); } } @SuppressWarnings("unchecked") - private void instantiateComponent( - Class componentClass, Point point) - throws Exception { + private void instantiateComponent(Class componentClass, + Point point) throws Exception { LOG.info("Instatiating component of type: " + componentClass.getName()); Project oldProject = cloner.deepClone(currentProject); @@ -589,8 +556,8 @@ public class Presenter implements IPlugInPort { currentProject.getComponents().add(component); // Extract control points. - List controlPoints = ComponentProcessor - .getInstance().extractControlPoints(componentClass); + List controlPoints = ComponentProcessor.getInstance() + .extractControlPoints(componentClass); // Translate them to the desired location. if (point != null) { for (ControlPointWrapper controlPoint : controlPoints) { @@ -601,16 +568,15 @@ public class Presenter implements IPlugInPort { } // Extract properties. - List properties = ComponentProcessor.getInstance() - .extractProperties(componentClass); + List properties = ComponentProcessor.getInstance().extractProperties( + componentClass); // Override with default values if available. for (PropertyWrapper property : properties) { Object defaultValue = null; Map defaultMap = (Map) ConfigurationManager .getInstance().getConfigurationItem(DEFAULTS_KEY); if (defaultMap != null) { - defaultValue = defaultMap.get(componentClass.getName() + ":" - + property.getName()); + defaultValue = defaultMap.get(componentClass.getName() + ":" + property.getName()); } if (defaultValue != null) { property.setValue(cloner.deepClone(defaultValue)); @@ -620,21 +586,19 @@ public class Presenter implements IPlugInPort { // Notify the listeners. if (!oldProject.equals(currentProject)) { - messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, - oldProject, cloner.deepClone(currentProject), "Create"); + messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner + .deepClone(currentProject), "Create"); } messageDispatcher.dispatchMessage(EventType.REPAINT); } @Override public List getMutualSelectionProperties() { - return ComponentProcessor.getInstance().getMutualSelectionProperties( - selectedComponents); + return ComponentProcessor.getInstance().getMutualSelectionProperties(selectedComponents); } @Override - public void applyPropertiesToSelection(List properties) - throws Exception { + public void applyPropertiesToSelection(List properties) throws Exception { LOG.debug(String.format("applyPropertiesToSelection(%s)", properties)); Project oldProject = cloner.deepClone(currentProject); try { @@ -646,8 +610,8 @@ public class Presenter implements IPlugInPort { } finally { // Notify the listeners. if (!oldProject.equals(currentProject)) { - messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, - oldProject, cloner.deepClone(currentProject), "Edit"); + messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner + .deepClone(currentProject), "Edit"); } messageDispatcher.dispatchMessage(EventType.REPAINT); } @@ -655,26 +619,22 @@ public class Presenter implements IPlugInPort { @Override public void setNewComponentSlot(IComponentType componentType) { - LOG.debug(String.format("setNewComponentSlot(%s)", - componentType == null ? null : componentType.getName())); + LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null + : componentType.getName())); this.componentSlot = componentType; selectedComponents.clear(); messageDispatcher.dispatchMessage(EventType.SELECTION_CHANGED); - messageDispatcher - .dispatchMessage(EventType.SLOT_CHANGED, componentSlot); + messageDispatcher.dispatchMessage(EventType.SLOT_CHANGED, componentSlot); } private Point scalePoint(Point point) { - return new Point((int) (point.x / zoomLevel), - (int) (point.y / zoomLevel)); + return new Point((int) (point.x / zoomLevel), (int) (point.y / zoomLevel)); } private boolean shouldShowControlPoint(ControlPointWrapper controlPoint, IComponentInstance component) { - return controlPoint.getVisibilityPolicy().equals( - VisibilityPolicy.ALWAYS) - || ((controlPoint.getVisibilityPolicy() - .equals(VisibilityPolicy.WHEN_SELECTED)) && (getSelectedComponents() + return controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.ALWAYS) + || ((controlPoint.getVisibilityPolicy().equals(VisibilityPolicy.WHEN_SELECTED)) && (getSelectedComponents() .contains(component))); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/Constants.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/Constants.java index 6458651b..da813594 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/Constants.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/Constants.java @@ -7,12 +7,10 @@ import java.awt.Toolkit; public class Constants { - public static final float GRID = Toolkit.getDefaultToolkit() - .getScreenResolution() / 10f; + public static final float GRID = Toolkit.getDefaultToolkit().getScreenResolution() / 10f; public static final Color GRID_COLOR = new Color(240, 240, 240); - public static final Stroke dashedStroke = new BasicStroke(1.0f, - BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f, - new float[] { 2.0f }, 0.0f); + public static final Stroke dashedStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, 2.0f, new float[] { 2.0f }, 0.0f); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/AbstractComponentDecorator.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/AbstractComponentDecorator.java index cbd4235e..bf333cdb 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/AbstractComponentDecorator.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/AbstractComponentDecorator.java @@ -26,600 +26,632 @@ import javax.swing.JLayeredPane; import javax.swing.RootPaneContainer; import javax.swing.SwingUtilities; -/** Provide a method for consistently augmenting the appearance of a given - * component by painting something on it after the component itself - * gets painted. If not explicitly removed via {@link #dispose}, an instance - * of this object will live as long as its target component.

- * By default, the decorator matches the location and size of the decorated - * component, but the bounds can be adjusted by overriding - * {@link #getDecorationBounds()}. The {@link #synch()} method should be called +/** + * Provide a method for consistently augmenting the appearance of a given + * component by painting something on it after the component itself gets + * painted. If not explicitly removed via {@link #dispose}, an instance of this + * object will live as long as its target component. + *

+ * By default, the decorator matches the location and size of the decorated + * component, but the bounds can be adjusted by overriding + * {@link #getDecorationBounds()}. The {@link #synch()} method should be called * whenever the bounds returned by {@link #getDecorationBounds()} would change. *

- * The decoration is clipped to the bounds set on the decoration, which does - * not necessarily need to be the same as the decorated component bounds. The + * The decoration is clipped to the bounds set on the decoration, which does not + * necessarily need to be the same as the decorated component bounds. The * decoration may extend beyond the decorated component bounds, or it may be - * reduced to a smaller region. + * reduced to a smaller region. */ // TODO: should probably do some locking on Component.getTreeLock() -// TODO: synch underlying cursor when decorator covers more than -// one component; the cursor should change if the decoration exceeds the +// TODO: synch underlying cursor when decorator covers more than +// one component; the cursor should change if the decoration exceeds the // component's bounds public abstract class AbstractComponentDecorator { - public static final Rectangle DEFAULT_BOUNDS = null; - public static final int TOP = 0; - // Disabled for now, since it doesn't work properly - 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. - */ - private Point originOffset = new Point(0, 0); - - private Painter painter; - private JComponent component; - private Container parent; - private Listener listener; - private int layerOffset; - private int position; - private Rectangle bounds; + public static final Rectangle DEFAULT_BOUNDS = null; + public static final int TOP = 0; + // Disabled for now, since it doesn't work properly + 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. + */ + private Point originOffset = new Point(0, 0); - /** Create a decorator for the given component. */ - public AbstractComponentDecorator(JComponent c) { - this(c, 1); - } + private Painter painter; + private JComponent component; + private Container parent; + private Listener listener; + private int layerOffset; + private int position; + private Rectangle bounds; - /** Create a decorator for the given component, indicating the layer - * offset from the target component. Negative values mean the decoration - * is painted before the target component is painted. - */ - public AbstractComponentDecorator(JComponent c, int layerOffset) { - this(c, layerOffset, TOP); - } + /** Create a decorator for the given component. */ + public AbstractComponentDecorator(JComponent c) { + this(c, 1); + } - /** Create a decorator with the given position within its layer. - * Use {@link #TOP} to cover other decorations, or {@link #BOTTOM} - * to be covered by other decorations.

- * WARNING: BOTTOM doesn't currently work, probably a JLayeredPane bug - * in either the code or documentation. - * @see JLayeredPane - */ - public AbstractComponentDecorator(JComponent c, int layerOffset, int position) { - component = c; - this.layerOffset = layerOffset; - this.position = position; - this.bounds = DEFAULT_BOUNDS; - parent = c.getParent(); - painter = new Painter(); - listener = new Listener(); - component.addHierarchyListener(listener); - component.addComponentListener(listener); - component.addPropertyChangeListener(listener); - attach(); - } + /** + * Create a decorator for the given component, indicating the layer offset + * from the target component. Negative values mean the decoration is painted + * before the target component is painted. + */ + public AbstractComponentDecorator(JComponent c, int layerOffset) { + this(c, layerOffset, TOP); + } - /** Set the text to be displayed when the mouse is over the decoration. - * @see JComponent#setToolTipText(String) - */ - public void setToolTipText(String text) { - painter.setToolTipText(text); - } - - /** Return the currently set default tooltip text. - * @see JComponent#setToolTipText - */ - public String getToolTipText() { - return painter.getToolTipText(); - } - - /** Provide for different tool tips depending on the actual location - * over the decoration. Note that if you only override this - * method, you must also invoke {@link #setToolTipText(String)} with - * a non-null argument. - * @see JComponent#getToolTipText(MouseEvent) - */ - public String getToolTipText(MouseEvent e) { - return getToolTipText(); - } - - /** Indicate whether any of the decoration is visible. The decoration - * may be clipped by ancestor scroll panes or by being moved outside - * if the visible region of its parent window. - */ - public boolean isVisible() { - return painter.isVisible(); - } - - /** Use this to change the visibility of the decoration. */ - public void setVisible(boolean visible) { - painter.setVisible(visible); - } + /** + * Create a decorator with the given position within its layer. Use + * {@link #TOP} to cover other decorations, or {@link #BOTTOM} to be covered + * by other decorations. + *

+ * WARNING: BOTTOM doesn't currently work, probably a JLayeredPane bug in + * either the code or documentation. + * + * @see JLayeredPane + */ + public AbstractComponentDecorator(JComponent c, int layerOffset, int position) { + component = c; + this.layerOffset = layerOffset; + this.position = position; + this.bounds = DEFAULT_BOUNDS; + parent = c.getParent(); + painter = new Painter(); + listener = new Listener(); + component.addHierarchyListener(listener); + component.addComponentListener(listener); + component.addPropertyChangeListener(listener); + attach(); + } - protected void attach() { - Window w = SwingUtilities.getWindowAncestor(component); - if (w instanceof RootPaneContainer) { - JLayeredPane lp = ((RootPaneContainer)w).getLayeredPane(); - Component layeredChild = component; - int layer = JLayeredPane.DRAG_LAYER.intValue(); - if (this instanceof BackgroundPainter) { - layer = ((BackgroundPainter)this).layer; - painter.setDecoratedLayer(layer); - } - else if (layeredChild == lp) { - // Is this the best layer to use? - painter.setDecoratedLayer(layer); - } - else { - while (layeredChild.getParent() != lp) { - layeredChild = layeredChild.getParent(); - } - int base = lp.getLayer(layeredChild); - // NOTE: JLayeredPane doesn't properly repaint an overlapping - // child when an obscured child calls repaint() if the two - // are in the same layer, so we use the next-higher layer - // instead of simply using a different position within the - // layer. - layer = base + layerOffset; - if (layerOffset < 0) { - BackgroundPainter bp = (BackgroundPainter) - lp.getClientProperty(BackgroundPainter.key(base)); - if (bp == null) { - bp = new BackgroundPainter(lp, base); - } - } - painter.setDecoratedLayer(base); - } - lp.add(painter, new Integer(layer), position); - } - else { - // Always detach when the target component's window is null - // or is not a suitable container, - // otherwise we might prevent GC of the component - Container parent = painter.getParent(); - if (parent != null) { - parent.remove(painter); - } - } - // Track size changes in any viewport parent - if (parent != null) { - parent.removeComponentListener(listener); - } - parent = component.getParent(); - if (parent != null) { - parent.addComponentListener(listener); - } - synch(); - } + /** + * Set the text to be displayed when the mouse is over the decoration. + * + * @see JComponent#setToolTipText(String) + */ + public void setToolTipText(String text) { + painter.setToolTipText(text); + } - /** Ensure the size of the decorator matches the current - * decoration bounds with appropriate clipping to viewports. - */ - protected void synch() { - Container painterParent = painter.getParent(); - if (painterParent != null) { - Rectangle decorated = getDecorationBounds(); - Rectangle clipRect = clipDecorationBounds(decorated); + /** + * Return the currently set default tooltip text. + * + * @see JComponent#setToolTipText + */ + public String getToolTipText() { + return painter.getToolTipText(); + } - Point pt = SwingUtilities.convertPoint(component, clipRect.x, clipRect.y, - painterParent); - if (clipRect.width <= 0 || clipRect.height <= 0) { - setPainterBounds(-1, -1, 0, 0); - setVisible(false); - } - else { - setPainterBounds(pt.x, pt.y, clipRect.width, clipRect.height); - setVisible(true); - } - } - painter.repaint(); - } + /** + * Provide for different tool tips depending on the actual location over the + * decoration. Note that if you only override this method, you must + * also invoke {@link #setToolTipText(String)} with a non-null argument. + * + * @see JComponent#getToolTipText(MouseEvent) + */ + public String getToolTipText(MouseEvent e) { + return getToolTipText(); + } - /** Adjust the painting offsets and size of the decoration to - * account for ancestor clipping. This might be due to scroll panes - * or having the decoration lie outside the parent layered pane. - */ - protected Rectangle clipDecorationBounds(Rectangle decorated) { - // Amount we have to translate the Graphics context - originOffset.x = decorated.x; - originOffset.y = decorated.y; - // If the the component is obscured (by a viewport or some - // other means), use the painter bounds to clip to the visible - // bounds. Doing may change the actual origin, so adjust our - // origin offset accordingly - Rectangle visible = getClippingRect(component, decorated); - Rectangle clipRect = decorated.intersection(visible); - if (decorated.x < visible.x) - originOffset.x += visible.x - decorated.x; - if (decorated.y < visible.y) - originOffset.y += visible.y - decorated.y; - return clipRect; - } - - /** Return any clipping rectangle detected above the given component, - * in the coordinate space of the given component. The given rectangle - * is desired to be visible. - */ - private Rectangle getClippingRect(Container component, Rectangle desired) { - Rectangle clip = component instanceof JComponent - ? ((JComponent)component).getVisibleRect() - : new Rectangle(0, 0, component.getWidth(), component.getHeight()); - if (desired.x >= clip.x && desired.y >= clip.y - && desired.x + desired.width <= clip.x + clip.width - && desired.y + desired.height <= clip.y + clip.height) { - // desired rect is within the current clip rect - } - else if (component.getParent() != null) { - // Only apply the clip if it is actually smaller than the - // component's visible area - if (component != painter.getParent() - && clip.x > 0 && clip.y > 0 - && clip.width < component.getWidth() - && clip.height < component.getHeight()) { - // Don't alter the original rectangle - desired = new Rectangle(desired); - // Check for clipping further up the hierarchy - desired.x += component.getX(); - desired.y += component.getY(); - clip = getClippingRect(component.getParent(), desired); - clip.x -= component.getX(); - clip.y -= component.getY(); - } - } - return clip; - } + /** + * Indicate whether any of the decoration is visible. The decoration may be + * clipped by ancestor scroll panes or by being moved outside if the visible + * region of its parent window. + */ + public boolean isVisible() { + return painter.isVisible(); + } - /** Return the bounds, relative to the decorated component, of the - * decoration. The default covers the entire component. Note that - * this method will be called from the constructor, so be careful - * when overriding and referencing derived class state. - */ - protected Rectangle getDecorationBounds() { - return bounds != DEFAULT_BOUNDS - ? bounds : new Rectangle(0, 0, component.getWidth(), component.getHeight()); - } - - /** Change the bounds of the decoration, relative to the decorated - * component. The special value {@link #DEFAULT_BOUNDS} means the bounds - * will track the component bounds. - */ - public void setDecorationBounds(Rectangle bounds) { - if (bounds == DEFAULT_BOUNDS) { - this.bounds = bounds; - } - else { - this.bounds = new Rectangle(bounds); - } - synch(); - } - - /** Change the bounds of the decoration, relative to the decorated - * component. - */ - public void setDecorationBounds(int x, int y, int w, int h) { - setDecorationBounds(new Rectangle(x, y, w, h)); - } - - protected void setPainterBounds(int x, int y, int w, int h) { - painter.setLocation(x, y); - painter.setSize(w, h); - repaint(); - } - - protected JComponent getComponent() { return component; } - protected JComponent getPainter() { return painter; } - - /** Set the cursor to appear anywhere over the decoration bounds. */ - public void setCursor(Cursor cursor) { - painter.setCursor(cursor); - } + /** Use this to change the visibility of the decoration. */ + public void setVisible(boolean visible) { + painter.setVisible(visible); + } - /** Force a refresh of the underlying component and its decoration. */ - public void repaint() { - component.repaint(); - painter.repaint(); - } - - /** Stop decorating. */ - public void dispose() { - component.removeHierarchyListener(listener); - component.removeComponentListener(listener); - component.removePropertyChangeListener(listener); - if (parent != null) { - parent.removeComponentListener(listener); - parent = null; - } - Container painterParent = painter.getParent(); - if (painterParent != null) { - Rectangle bounds = painter.getBounds(); - painterParent.remove(painter); - painterParent.repaint(bounds.x, bounds.y, bounds.width, bounds.height); - } - component.repaint(); - component = null; - } + protected void attach() { + Window w = SwingUtilities.getWindowAncestor(component); + if (w instanceof RootPaneContainer) { + JLayeredPane lp = ((RootPaneContainer) w).getLayeredPane(); + Component layeredChild = component; + int layer = JLayeredPane.DRAG_LAYER.intValue(); + if (this instanceof BackgroundPainter) { + layer = ((BackgroundPainter) this).layer; + painter.setDecoratedLayer(layer); + } else if (layeredChild == lp) { + // Is this the best layer to use? + painter.setDecoratedLayer(layer); + } else { + while (layeredChild.getParent() != lp) { + layeredChild = layeredChild.getParent(); + } + int base = lp.getLayer(layeredChild); + // NOTE: JLayeredPane doesn't properly repaint an overlapping + // child when an obscured child calls repaint() if the two + // are in the same layer, so we use the next-higher layer + // instead of simply using a different position within the + // layer. + layer = base + layerOffset; + if (layerOffset < 0) { + BackgroundPainter bp = (BackgroundPainter) lp + .getClientProperty(BackgroundPainter.key(base)); + if (bp == null) { + bp = new BackgroundPainter(lp, base); + } + } + painter.setDecoratedLayer(base); + } + lp.add(painter, new Integer(layer), position); + } else { + // Always detach when the target component's window is null + // or is not a suitable container, + // otherwise we might prevent GC of the component + Container parent = painter.getParent(); + if (parent != null) { + parent.remove(painter); + } + } + // Track size changes in any viewport parent + if (parent != null) { + parent.removeComponentListener(listener); + } + parent = component.getParent(); + if (parent != null) { + parent.addComponentListener(listener); + } + synch(); + } - /** Define the decoration's appearance. The point (0,0) represents - * the upper left corner of the decorated component. - * The default clip mask will be the extents of the decoration bounds, as - * indicated by {@link #getDecorationBounds()}, which defaults to the - * decorated component bounds. - */ - public abstract void paint(Graphics g); - - public String toString() { - return super.toString() + " on " + getComponent(); - } - - private static Field nComponents; - static { - try { - nComponents = Container.class.getDeclaredField("ncomponents"); - nComponents.setAccessible(true); - } - catch(Exception e) { - nComponents = null; - } - } - - private static boolean useSimpleBackground() { - return nComponents == null; - } + /** + * Ensure the size of the decorator matches the current decoration bounds + * with appropriate clipping to viewports. + */ + protected void synch() { + Container painterParent = painter.getParent(); + if (painterParent != null) { + Rectangle decorated = getDecorationBounds(); + Rectangle clipRect = clipDecorationBounds(decorated); - /** Used to hook into the Swing painting architecture. */ - private class Painter extends JComponent { - private int base; - private Cursor cursor; - public JComponent getComponent() { - return AbstractComponentDecorator.this.getComponent(); - } - public void setDecoratedLayer(int base) { - this.base = base; - } - public int getDecoratedLayer() { - return base; - } - public boolean isBackgroundDecoration() { - return layerOffset < 0; - } - /** Set the cursor to something else. */ - public void setCursor(Cursor cursor) { - Cursor oldCursor = getCursor(); - // Make sure the cursor actually changed, otherwise - // we get cursor flicker (notably on w32 title bars) - if (oldCursor == null && cursor != null - || oldCursor != null && !oldCursor.equals(cursor)) { - this.cursor = cursor; - super.setCursor(cursor); - } - } + Point pt = SwingUtilities + .convertPoint(component, clipRect.x, clipRect.y, painterParent); + if (clipRect.width <= 0 || clipRect.height <= 0) { + setPainterBounds(-1, -1, 0, 0); + setVisible(false); + } else { + setPainterBounds(pt.x, pt.y, clipRect.width, clipRect.height); + setVisible(true); + } + } + painter.repaint(); + } - /** Returns the cursor of the decorated component, or the last - * cursor set by {@link #setCursor}. - */ - public Cursor getCursor() { - return cursor != null ? cursor : component.getCursor(); - } + /** + * Adjust the painting offsets and size of the decoration to account for + * ancestor clipping. This might be due to scroll panes or having the + * decoration lie outside the parent layered pane. + */ + protected Rectangle clipDecorationBounds(Rectangle decorated) { + // Amount we have to translate the Graphics context + originOffset.x = decorated.x; + originOffset.y = decorated.y; + // If the the component is obscured (by a viewport or some + // other means), use the painter bounds to clip to the visible + // bounds. Doing may change the actual origin, so adjust our + // origin offset accordingly + Rectangle visible = getClippingRect(component, decorated); + Rectangle clipRect = decorated.intersection(visible); + if (decorated.x < visible.x) + originOffset.x += visible.x - decorated.x; + if (decorated.y < visible.y) + originOffset.y += visible.y - decorated.y; + return clipRect; + } - /** Delegate to the containing decorator to perform the paint. - */ - public void paint(Graphics g) { - if (!component.isShowing()) - return; - Graphics g2 = g.create(); - g2.translate(-originOffset.x, -originOffset.y); - AbstractComponentDecorator.this.paint(g2); - g2.dispose(); - /* - g = g.create(); - g.setClip(null); - g.setColor(Color.red); - g.drawRect(0, 0, getWidth()-1, getHeight()-1); - */ - } - /** Provide a decorator-specific tooltip, shown when within the - * decorator's bounds. - */ - public String getToolTipText(MouseEvent e) { - return AbstractComponentDecorator.this.getToolTipText(e); - } - public String toString() { - return "Painter for " + AbstractComponentDecorator.this; - } - } - - /** Provides a shared background painting mechanism for multiple - * decorations. 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 String key(int layer) { - return "backgroundPainter for layer " + layer; - } - private String key; - private int layer; - public BackgroundPainter(JLayeredPane p, int layer) { - super(p, 0, TOP); - this.layer = layer; - key = key(layer); - p.putClientProperty(key, this); - } - private int hideChildren(Container c) { - if (c == null) - return 0; - int value = c.getComponentCount(); - try { - nComponents.set(c, new Integer(0)); - } - catch(Exception e) { - return c.getComponentCount(); - } - return value; - } - - private void restoreChildren(Container c, int count) { - if (c != null) { - try { - nComponents.set(c, new Integer(count)); - } - catch(Exception e) { - } - } - } - - private void paintBackground(Graphics g, Component parent, JComponent jc) { - int x = jc.getX(); - int y = jc.getY(); - int w = jc.getWidth(); - int h = jc.getHeight(); - paintBackground(g.create(x, y, w, h), jc); - } - - private void paintBackground(Graphics g, JComponent jc) { - if (jc.isOpaque()) { - if (useSimpleBackground()) { - g.setColor(jc.getBackground()); - g.fillRect(0, 0, jc.getWidth(), jc.getHeight()); - } - else { - int count = hideChildren(jc); - boolean db = jc.isDoubleBuffered(); - if (db) - jc.setDoubleBuffered(false); - jc.paint(g); - if (db) - jc.setDoubleBuffered(true); - restoreChildren(jc, count); - } - } - Component[] kids = jc.getComponents(); - for (int i=0;i < kids.length;i++) { - if (kids[i] instanceof JComponent) { - paintBackground(g, jc, (JComponent)kids[i]); - } - } - } - private List findOpaque(Component root) { - List list = new ArrayList(); - if (root.isOpaque() && root instanceof JComponent) { - list.add(root); - ((JComponent)root).setOpaque(false); - } - if (root instanceof Container) { - Component[] kids = ((Container)root).getComponents(); - for (int i=0;i < kids.length;i++) { - list.addAll(findOpaque(kids[i])); - } - } - return list; - } - private List findDoubleBuffered(Component root) { - List list = new ArrayList(); - if (root.isDoubleBuffered() && root instanceof JComponent) { - list.add(root); - ((JComponent)root).setDoubleBuffered(false); - } - if (root instanceof Container) { - Component[] kids = ((Container)root).getComponents(); - for (int i=0;i < kids.length;i++) { - list.addAll(findDoubleBuffered(kids[i])); - } - } - return list; - } - private void paintForeground(Graphics g, JComponent jc) { - List opaque = findOpaque(jc); - List db = findDoubleBuffered(jc); - jc.paint(g); - for (Iterator i=opaque.iterator();i.hasNext();) { - ((JComponent)i.next()).setOpaque(true); - } - for (Iterator i=db.iterator();i.hasNext();) { - ((JComponent)i.next()).setDoubleBuffered(true); - } - } - - /** Walk the list of "background" decorators and paint them. */ - public void paint(Graphics g) { + /** + * Return any clipping rectangle detected above the given component, in the + * coordinate space of the given component. The given rectangle is desired + * to be visible. + */ + private Rectangle getClippingRect(Container component, Rectangle desired) { + Rectangle clip = component instanceof JComponent ? ((JComponent) component) + .getVisibleRect() + : new Rectangle(0, 0, component.getWidth(), component.getHeight()); + if (desired.x >= clip.x && desired.y >= clip.y + && desired.x + desired.width <= clip.x + clip.width + && desired.y + desired.height <= clip.y + clip.height) { + // desired rect is within the current clip rect + } else if (component.getParent() != null) { + // Only apply the clip if it is actually smaller than the + // component's visible area + if (component != painter.getParent() && clip.x > 0 && clip.y > 0 + && clip.width < component.getWidth() && clip.height < component.getHeight()) { + // Don't alter the original rectangle + desired = new Rectangle(desired); + // Check for clipping further up the hierarchy + desired.x += component.getX(); + desired.y += component.getY(); + clip = getClippingRect(component.getParent(), desired); + clip.x -= component.getX(); + clip.y -= component.getY(); + } + } + return clip; + } - JLayeredPane lp = (JLayeredPane)getComponent(); - Component[] kids = lp.getComponents(); - // Construct an area of the intersection of all decorators - Area area = new Area(); - List painters = new ArrayList(); - List components = new ArrayList(); - for (int i=kids.length-1;i >=0; i--) { - if (kids[i] instanceof Painter) { - Painter p = (Painter)kids[i]; - if (p.isBackgroundDecoration() - && p.getDecoratedLayer() == layer - && p.isShowing()) { - painters.add(p); - area.add(new Area(p.getBounds())); - } - } - else if (lp.getLayer(kids[i]) == layer - && kids[i] instanceof JComponent) { - components.add(kids[i]); - } - } - if (painters.size() == 0) { - dispose(); - return; - } - g.setClip(area); + /** + * Return the bounds, relative to the decorated component, of the + * decoration. The default covers the entire component. Note that this + * method will be called from the constructor, so be careful when overriding + * and referencing derived class state. + */ + protected Rectangle getDecorationBounds() { + return bounds != DEFAULT_BOUNDS ? bounds : new Rectangle(0, 0, component.getWidth(), + component.getHeight()); + } - // Paint background for that area - for (Iterator i=components.iterator();i.hasNext();) { - JComponent c = (JComponent)i.next(); - paintBackground(g, lp, c); - } - - // Paint the bg decorators - for (Iterator i=painters.iterator();i.hasNext();) { - Painter p = (Painter)i.next(); - p.paint(g.create(p.getX(), p.getY(), p.getWidth(), p.getHeight())); - } - // Paint foreground for the area - for (Iterator i=components.iterator();i.hasNext();) { - JComponent c = (JComponent)i.next(); - paintForeground(g.create(c.getX(), c.getY(), c.getWidth(), c.getHeight()), c); - } - } - public void dispose() { - getComponent().putClientProperty(key, null); - super.dispose(); - } - public String toString() { - return key + " on " + getComponent(); - } - } + /** + * Change the bounds of the decoration, relative to the decorated component. + * The special value {@link #DEFAULT_BOUNDS} means the bounds will track the + * component bounds. + */ + public void setDecorationBounds(Rectangle bounds) { + if (bounds == DEFAULT_BOUNDS) { + this.bounds = bounds; + } else { + this.bounds = new Rectangle(bounds); + } + synch(); + } - /** Tracks changes to component configuration. */ - private final class Listener extends ComponentAdapter - implements HierarchyListener, PropertyChangeListener { - public void hierarchyChanged(HierarchyEvent e) { - if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) { - attach(); - } - } - public void propertyChange(PropertyChangeEvent e) { - if (JLayeredPane.LAYER_PROPERTY.equals(e.getPropertyName())) { - attach(); - } - } - public void componentMoved(ComponentEvent e) { - // FIXME figure out why attach works and synch doesn't - // when painting a selection marquee over a decorated background - attach(); - } - public void componentResized(ComponentEvent e) { - // FIXME figure out why attach works and synch doesn't - // when painting a selection marquee over a decorated background - attach(); - } - public void componentHidden(ComponentEvent e) { - setVisible(false); - } - public void componentShown(ComponentEvent e) { - setVisible(true); - } - } + /** + * Change the bounds of the decoration, relative to the decorated component. + */ + public void setDecorationBounds(int x, int y, int w, int h) { + setDecorationBounds(new Rectangle(x, y, w, h)); + } + + protected void setPainterBounds(int x, int y, int w, int h) { + painter.setLocation(x, y); + painter.setSize(w, h); + repaint(); + } + + protected JComponent getComponent() { + return component; + } + + protected JComponent getPainter() { + return painter; + } + + /** Set the cursor to appear anywhere over the decoration bounds. */ + public void setCursor(Cursor cursor) { + painter.setCursor(cursor); + } + + /** Force a refresh of the underlying component and its decoration. */ + public void repaint() { + component.repaint(); + painter.repaint(); + } + + /** Stop decorating. */ + public void dispose() { + component.removeHierarchyListener(listener); + component.removeComponentListener(listener); + component.removePropertyChangeListener(listener); + if (parent != null) { + parent.removeComponentListener(listener); + parent = null; + } + Container painterParent = painter.getParent(); + if (painterParent != null) { + Rectangle bounds = painter.getBounds(); + painterParent.remove(painter); + painterParent.repaint(bounds.x, bounds.y, bounds.width, bounds.height); + } + component.repaint(); + component = null; + } + + /** + * Define the decoration's appearance. The point (0,0) represents the upper + * left corner of the decorated component. The default clip mask will be the + * extents of the decoration bounds, as indicated by + * {@link #getDecorationBounds()}, which defaults to the decorated component + * bounds. + */ + public abstract void paint(Graphics g); + + public String toString() { + return super.toString() + " on " + getComponent(); + } + + private static Field nComponents; + static { + try { + nComponents = Container.class.getDeclaredField("ncomponents"); + nComponents.setAccessible(true); + } catch (Exception e) { + nComponents = null; + } + } + + private static boolean useSimpleBackground() { + return nComponents == null; + } + + /** Used to hook into the Swing painting architecture. */ + private class Painter extends JComponent { + private int base; + private Cursor cursor; + + public JComponent getComponent() { + return AbstractComponentDecorator.this.getComponent(); + } + + public void setDecoratedLayer(int base) { + this.base = base; + } + + public int getDecoratedLayer() { + return base; + } + + public boolean isBackgroundDecoration() { + return layerOffset < 0; + } + + /** Set the cursor to something else. */ + public void setCursor(Cursor cursor) { + Cursor oldCursor = getCursor(); + // Make sure the cursor actually changed, otherwise + // we get cursor flicker (notably on w32 title bars) + if (oldCursor == null && cursor != null || oldCursor != null + && !oldCursor.equals(cursor)) { + this.cursor = cursor; + super.setCursor(cursor); + } + } + + /** + * Returns the cursor of the decorated component, or the last cursor set + * by {@link #setCursor}. + */ + public Cursor getCursor() { + return cursor != null ? cursor : component.getCursor(); + } + + /** + * Delegate to the containing decorator to perform the paint. + */ + public void paint(Graphics g) { + if (!component.isShowing()) + return; + Graphics g2 = g.create(); + g2.translate(-originOffset.x, -originOffset.y); + AbstractComponentDecorator.this.paint(g2); + g2.dispose(); + /* + * g = g.create(); g.setClip(null); g.setColor(Color.red); + * g.drawRect(0, 0, getWidth()-1, getHeight()-1); + */ + } + + /** + * Provide a decorator-specific tooltip, shown when within the + * decorator's bounds. + */ + public String getToolTipText(MouseEvent e) { + return AbstractComponentDecorator.this.getToolTipText(e); + } + + public String toString() { + return "Painter for " + AbstractComponentDecorator.this; + } + } + + /** + * Provides a shared background painting mechanism for multiple decorations. + * 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 String key(int layer) { + return "backgroundPainter for layer " + layer; + } + + private String key; + private int layer; + + public BackgroundPainter(JLayeredPane p, int layer) { + super(p, 0, TOP); + this.layer = layer; + key = key(layer); + p.putClientProperty(key, this); + } + + private int hideChildren(Container c) { + if (c == null) + return 0; + int value = c.getComponentCount(); + try { + nComponents.set(c, new Integer(0)); + } catch (Exception e) { + return c.getComponentCount(); + } + return value; + } + + private void restoreChildren(Container c, int count) { + if (c != null) { + try { + nComponents.set(c, new Integer(count)); + } catch (Exception e) { + } + } + } + + private void paintBackground(Graphics g, Component parent, JComponent jc) { + int x = jc.getX(); + int y = jc.getY(); + int w = jc.getWidth(); + int h = jc.getHeight(); + paintBackground(g.create(x, y, w, h), jc); + } + + private void paintBackground(Graphics g, JComponent jc) { + if (jc.isOpaque()) { + if (useSimpleBackground()) { + g.setColor(jc.getBackground()); + g.fillRect(0, 0, jc.getWidth(), jc.getHeight()); + } else { + int count = hideChildren(jc); + boolean db = jc.isDoubleBuffered(); + if (db) + jc.setDoubleBuffered(false); + jc.paint(g); + if (db) + jc.setDoubleBuffered(true); + restoreChildren(jc, count); + } + } + Component[] kids = jc.getComponents(); + for (int i = 0; i < kids.length; i++) { + if (kids[i] instanceof JComponent) { + paintBackground(g, jc, (JComponent) kids[i]); + } + } + } + + private List findOpaque(Component root) { + List list = new ArrayList(); + if (root.isOpaque() && root instanceof JComponent) { + list.add(root); + ((JComponent) root).setOpaque(false); + } + if (root instanceof Container) { + Component[] kids = ((Container) root).getComponents(); + for (int i = 0; i < kids.length; i++) { + list.addAll(findOpaque(kids[i])); + } + } + return list; + } + + private List findDoubleBuffered(Component root) { + List list = new ArrayList(); + if (root.isDoubleBuffered() && root instanceof JComponent) { + list.add(root); + ((JComponent) root).setDoubleBuffered(false); + } + if (root instanceof Container) { + Component[] kids = ((Container) root).getComponents(); + for (int i = 0; i < kids.length; i++) { + list.addAll(findDoubleBuffered(kids[i])); + } + } + return list; + } + + private void paintForeground(Graphics g, JComponent jc) { + List opaque = findOpaque(jc); + List db = findDoubleBuffered(jc); + jc.paint(g); + for (Iterator i = opaque.iterator(); i.hasNext();) { + ((JComponent) i.next()).setOpaque(true); + } + for (Iterator i = db.iterator(); i.hasNext();) { + ((JComponent) i.next()).setDoubleBuffered(true); + } + } + + /** Walk the list of "background" decorators and paint them. */ + public void paint(Graphics g) { + + JLayeredPane lp = (JLayeredPane) getComponent(); + Component[] kids = lp.getComponents(); + // Construct an area of the intersection of all decorators + Area area = new Area(); + List painters = new ArrayList(); + List components = new ArrayList(); + for (int i = kids.length - 1; i >= 0; i--) { + if (kids[i] instanceof Painter) { + Painter p = (Painter) kids[i]; + if (p.isBackgroundDecoration() && p.getDecoratedLayer() == layer + && p.isShowing()) { + painters.add(p); + area.add(new Area(p.getBounds())); + } + } else if (lp.getLayer(kids[i]) == layer && kids[i] instanceof JComponent) { + components.add(kids[i]); + } + } + if (painters.size() == 0) { + dispose(); + return; + } + g.setClip(area); + + // Paint background for that area + for (Iterator i = components.iterator(); i.hasNext();) { + JComponent c = (JComponent) i.next(); + paintBackground(g, lp, c); + } + + // Paint the bg decorators + for (Iterator i = painters.iterator(); i.hasNext();) { + Painter p = (Painter) i.next(); + p.paint(g.create(p.getX(), p.getY(), p.getWidth(), p.getHeight())); + } + // Paint foreground for the area + for (Iterator i = components.iterator(); i.hasNext();) { + JComponent c = (JComponent) i.next(); + paintForeground(g.create(c.getX(), c.getY(), c.getWidth(), c.getHeight()), c); + } + } + + public void dispose() { + getComponent().putClientProperty(key, null); + super.dispose(); + } + + public String toString() { + return key + " on " + getComponent(); + } + } + + /** Tracks changes to component configuration. */ + private final class Listener extends ComponentAdapter implements HierarchyListener, + PropertyChangeListener { + public void hierarchyChanged(HierarchyEvent e) { + if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) { + attach(); + } + } + + public void propertyChange(PropertyChangeEvent e) { + if (JLayeredPane.LAYER_PROPERTY.equals(e.getPropertyName())) { + attach(); + } + } + + public void componentMoved(ComponentEvent e) { + // FIXME figure out why attach works and synch doesn't + // when painting a selection marquee over a decorated background + attach(); + } + + public void componentResized(ComponentEvent e) { + // FIXME figure out why attach works and synch doesn't + // when painting a selection marquee over a decorated background + attach(); + } + + public void componentHidden(ComponentEvent e) { + setVisible(false); + } + + public void componentShown(ComponentEvent e) { + setVisible(true); + } + } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/GhostedDragImage.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/GhostedDragImage.java index 5c61bf31..1779bfab 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/GhostedDragImage.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/com/diyfever/diylc/utils/dnd/GhostedDragImage.java @@ -57,10 +57,10 @@ public class GhostedDragImage extends AbstractComponentDecorator { * @param imageOffset * offset of the image from the cursor */ - public GhostedDragImage(JComponent dragSource, Point screenLocation, - Icon icon, Point imageOffset) { - this(dragSource, dragSource.getRootPane().getLayeredPane(), - screenLocation, icon, imageOffset, true); + public GhostedDragImage(JComponent dragSource, Point screenLocation, Icon icon, + Point imageOffset) { + this(dragSource, dragSource.getRootPane().getLayeredPane(), screenLocation, icon, + imageOffset, true); } /** @@ -80,29 +80,26 @@ public class GhostedDragImage extends AbstractComponentDecorator { * if true, creates additional ghosts for all extant frames which * contain a {@link JLayeredPane} where the image can be painted. */ - protected GhostedDragImage(JComponent dragSource, JLayeredPane root, - Point screenLocation, Icon icon, Point imageOffset, - boolean trackFrames) { + protected GhostedDragImage(JComponent dragSource, JLayeredPane root, Point screenLocation, + Icon icon, Point imageOffset, boolean trackFrames) { super(root); this.dragSource = dragSource; this.icon = icon; this.imageOffset = imageOffset; Point loc = root.getLocationOnScreen(); - setLocation(screenLocation.x - loc.x + imageOffset.x, screenLocation.y - - loc.y + imageOffset.y); + setLocation(screenLocation.x - loc.x + imageOffset.x, screenLocation.y - loc.y + + imageOffset.y); if (trackFrames) { Window w = SwingUtilities.getWindowAncestor(root); Frame[] frames = Frame.getFrames(); // Log.debug("track " + frames.length + " other frames"); for (int i = 0; i < frames.length; i++) { Frame frame = frames[i]; - if (frame instanceof RootPaneContainer && frame.isShowing() - && frame != w) { + if (frame instanceof RootPaneContainer && frame.isShowing() && frame != w) { // Log.debug("Track " + frame); - JLayeredPane p = ((RootPaneContainer) frame) - .getLayeredPane(); - GhostedDragImage slave = new GhostedDragImage(dragSource, - p, screenLocation, icon, imageOffset, false); + JLayeredPane p = ((RootPaneContainer) frame).getLayeredPane(); + GhostedDragImage slave = new GhostedDragImage(dragSource, p, screenLocation, + icon, imageOffset, false); ghosts.add(slave); slave.move(screenLocation); } @@ -143,8 +140,7 @@ public class GhostedDragImage extends AbstractComponentDecorator { * with {@link #returnToOrigin}. */ private void setLocation(int x, int y) { - location = SwingUtilities - .convertPoint(getComponent(), x, y, dragSource); + location = SwingUtilities.convertPoint(getComponent(), x, y, dragSource); if (origin == null) origin = location; setDecorationBounds(x, y, icon.getIconWidth(), icon.getIconHeight()); @@ -176,8 +172,7 @@ public class GhostedDragImage extends AbstractComponentDecorator { public void move(Point screen) { // Log.debug("Move to " + screen); Point loc = getComponent().getLocationOnScreen(); - setLocation(screen.x - loc.x + imageOffset.x, screen.y - loc.y - + imageOffset.y); + setLocation(screen.x - loc.x + imageOffset.x, screen.y - loc.y + imageOffset.y); for (Iterator i = ghosts.iterator(); i.hasNext();) { GhostedDragImage g = (GhostedDragImage) i.next(); // Log.debug("Move on other frame"); @@ -189,8 +184,7 @@ public class GhostedDragImage extends AbstractComponentDecorator { public void paint(Graphics graphics) { Rectangle r = getDecorationBounds(); Graphics2D g = (Graphics2D) graphics.create(); - g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, - ghostAlpha)); + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ghostAlpha)); g.translate(CURSOR_SIZE, CURSOR_SIZE); icon.paintIcon(getPainter(), g, r.x, r.y); g.dispose(); @@ -208,9 +202,8 @@ public class GhostedDragImage extends AbstractComponentDecorator { int dy = (origin.y - location.y) / 2; if (dx != 0 || dy != 0) { Point loc = dragSource.getLocationOnScreen(); - Point where = new Point(loc.x + location.x + dx - - imageOffset.x, loc.y + location.y + dy - - imageOffset.y); + Point where = new Point(loc.x + location.x + dx - imageOffset.x, loc.y + + location.y + dy - imageOffset.y); move(where); } else { timer.stop(); diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/TableTest.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/TableTest.java index 6925ab11..4aee2c97 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/TableTest.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/TableTest.java @@ -24,22 +24,16 @@ public class TableTest { BasicConfigurator.configure(); List projects = new ArrayList(); - projects - .add(new ProjectEntity(1, "first", "some text", "bane", "none")); - projects.add(new ProjectEntity(2, "second", "anoter text", "bisera", - "none")); + projects.add(new ProjectEntity(1, "first", "some text", "bane", "none")); + projects.add(new ProjectEntity(2, "second", "anoter text", "bisera", "none")); - ObjectListTable t = new ObjectListTable( - ProjectEntity.class, new String[] { "getName", - "getDescription", "getCategory", "getOwner", - "action:Download" }, - new IActionProcessor() { + ObjectListTable t = new ObjectListTable(ProjectEntity.class, + new String[] { "getName", "getDescription", "getCategory", "getOwner", + "action:Download" }, new IActionProcessor() { @Override - public void actionExecuted(ProjectEntity value, - String actionColumnName) { - System.out.println("row clicked: " + actionColumnName - + " - " + value); + public void actionExecuted(ProjectEntity value, String actionColumnName) { + System.out.println("row clicked: " + actionColumnName + " - " + value); } @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/Test.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/Test.java index 0ed3d096..e7bfb49f 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/Test.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/Test.java @@ -18,20 +18,19 @@ public class Test { * @param args */ public static void main(String[] args) { -// XStream xstream = new XStream(new JettisonMappedXmlDriver()); -// xstream.setMode(XStream.NO_REFERENCES); -// -// List projects = new ArrayList(); -//// projects.add(new ProjectEntity(1, "first project", "some text", -//// "bancika", "some category")); -//// projects.add(new ProjectEntity(2, "second project", "some text", -//// "bancika", "some category")); -// System.out.println(xstream.toXML(projects)); - + // XStream xstream = new XStream(new JettisonMappedXmlDriver()); + // xstream.setMode(XStream.NO_REFERENCES); + // + // List projects = new ArrayList(); + // // projects.add(new ProjectEntity(1, "first project", "some text", + // // "bancika", "some category")); + // // projects.add(new ProjectEntity(2, "second project", "some text", + // // "bancika", "some category")); + // System.out.println(xstream.toXML(projects)); + BasicConfigurator.configure(); - ProjectSearch search = new ProxyFactory(new PhpFlatProxy()) - .createProxy(ProjectSearch.class, - "http://host07.dwhost.net/~diyfever/diylc/db/"); + ProjectSearch search = new ProxyFactory(new PhpFlatProxy()).createProxy( + ProjectSearch.class, "http://host07.dwhost.net/~diyfever/diylc/db/"); List results = search.project_search("TestProject"); System.out.println(results); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/components/MockComponentInstance.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/components/MockComponentInstance.java index 8a7b3a65..cbfea85f 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/components/MockComponentInstance.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/components/MockComponentInstance.java @@ -30,8 +30,8 @@ public class MockComponentInstance implements IComponentInstance { private Point leftTopCorner = new Point(0, 0); private String name = "something"; - public MockComponentInstance(String testField, Capacitance c, Resistance r, - Size s, Color color, Point leftTopCorner) { + public MockComponentInstance(String testField, Capacitance c, Resistance r, Size s, + Color color, Point leftTopCorner) { super(); this.testField = testField; this.c = c; @@ -113,16 +113,14 @@ public class MockComponentInstance implements IComponentInstance { @Override public void draw(Graphics2D g2d, ComponentState componentState) { - g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color - : color.darker()); + g2d.setColor(componentState.equals(ComponentState.SELECTED) ? color : color.darker()); g2d.fillRect(leftTopCorner.x, leftTopCorner.y, 200, 50); } @Override public MockComponentInstance clone() throws CloneNotSupportedException { - MockComponentInstance newInstance = new MockComponentInstance( - testField, c.clone(), r.clone(), s.clone(), color, - (Point) leftTopCorner.clone()); + MockComponentInstance newInstance = new MockComponentInstance(testField, c.clone(), r + .clone(), s.clone(), color, (Point) leftTopCorner.clone()); return newInstance; } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/presenter/ClassProcessorTest.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/presenter/ClassProcessorTest.java index b3ebb200..4fb84f21 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/presenter/ClassProcessorTest.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/test/com/diyfever/diylc/presenter/ClassProcessorTest.java @@ -15,16 +15,15 @@ public class ClassProcessorTest { @Test public void testExtractProperties() { - List properties = ComponentProcessor.getInstance() - .extractProperties(MockComponentInstance.class); + List properties = ComponentProcessor.getInstance().extractProperties( + MockComponentInstance.class); assertNotNull(properties); assertEquals(4, properties.size()); }; @Test public void testExtractControlPoints() { - List controlPoints = ComponentProcessor - .getInstance() + List controlPoints = ComponentProcessor.getInstance() .extractControlPoints(MockComponentInstance.class); assertNotNull(controlPoints); assertEquals(1, controlPoints.size());