Author: EvaV Date: 2010-02-23 13:24:42 +0100 (Tue, 23 Feb 2010) New Revision: 1824 Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/DesignArea.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/LayoutDesigner.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/MenuBar.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/PopupMenu.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPane.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPaneCloseTabButton.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/propertiesManager/DocumentTypes.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/Marshaller.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/SaveLayoutOnServer.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/ServerSideContext.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/CloseLayout.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/MovingObject.java trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/Position.java Log: oprava - neslo spustit, ulozit, popupmenu Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/DesignArea.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/DesignArea.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/DesignArea.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -180,7 +180,6 @@ this.layout = layout; this.designArea = this; - designArea.paintAllPositions(); this.arePositionToPaste = false; this.isInDesignMode = false; @@ -204,6 +203,9 @@ MouseListener popupListener = popupMenu.new PopupListener(popupMenu); addMouseListener(popupListener); + + designArea.paintAllPositions(); + // adds key listener addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { @@ -1089,8 +1091,6 @@ */ public void paintAllPositions() { // paints positions - if (isNotMoving) { - designArea.removeAll(); Vector<Position> positions = layout.getLayoutPositions() @@ -1101,7 +1101,6 @@ Position actualPosition = positions.get(i); objects.add(actualPosition.paint(designArea)); } - } } /** Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/LayoutDesigner.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/LayoutDesigner.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/LayoutDesigner.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -4,6 +4,8 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -13,6 +15,7 @@ import javax.swing.border.LineBorder; import javax.swing.JDialog; import javax.swing.JApplet; +import javax.swing.Timer; import com.elvys.applet.dialog.ResolutionChoiceDialog; @@ -30,7 +33,7 @@ * LayoutDesigner is main applet class. Initializes individual components and * displays applet. */ -public class LayoutDesigner extends JApplet { +public class LayoutDesigner extends JApplet implements ActionListener { private static final long serialVersionUID = 5212730162755861066L; @@ -84,6 +87,8 @@ /** user error message - localization is not supported */ private final static String WARNING = "Warning"; /** warning dialog title in case properties file isn't loaded */ + private Timer timer; + /** timer for locking */ public static LayoutDesigner getInstance() { return new LayoutDesigner(); @@ -163,6 +168,11 @@ supportedAspectRatios = ServerSideContext.getInstance() .getSupportedResolutions(); + try { + ServerSideContext.getInstance().getLayout(instance, tabbedPane); + } catch (Exception e) { + e.printStackTrace(); + } // gets layout layoutToOpen = ServerSideContext.getInstance().getLayout(); @@ -238,6 +248,8 @@ private void initComponents() { instance = this; + timer = new Timer(60000, this); + timer.start(); // initializes sizes of components componentSizes = new ComponentSizes(); @@ -397,6 +409,22 @@ } } + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == timer) { + Layout layout = ServerSideContext.getInstance().getLayout(); + if (layout != null) { + try { + ServerSideContext.getInstance().lockLayout(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + } + + } + /** * Gets categories panel height * @return the categoriesPanelHeight Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/MenuBar.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/MenuBar.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/MenuBar.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -318,7 +318,7 @@ private void closeActualTab() { CloseLayout closeDesignArea = new CloseLayout(tabbedPane, properties); - closeDesignArea.closeActualLayout(tabbedPane.getActualDesignArea(), + closeDesignArea.closeActualLayout(tabbedPane.getActualTab(), rootPane); Layout layout = ServerSideContext.getInstance().getLayout(); if (layout != null) { Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/PopupMenu.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/PopupMenu.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/PopupMenu.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -3,6 +3,7 @@ * PopupMenu.java * @author Eva Viktorinova */ +import java.awt.Component; import java.awt.Graphics; import java.awt.event.*; import java.util.Properties; @@ -12,6 +13,7 @@ import com.elvys.applet.dialog.WarningDialog; import com.elvys.applet.structures.AbsoluteCoordinates; import com.elvys.applet.structures.Layout; +import com.elvys.applet.structures.MovingObject; import com.elvys.applet.structures.Position; import com.elvys.applet.structures.Positions; @@ -40,20 +42,29 @@ } public void mousePressed(MouseEvent e) { - designArea.paintAllPositions(); + //designArea.paintAllPositions(); maybeShowPopup(e); } public void mouseReleased(MouseEvent e) { - designArea.paintAllPositions(); + //designArea.paintAllPositions(); maybeShowPopup(e); } private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { - popupMenu.show(e.getComponent(), e.getX(), e.getY()); - popupMenu.topX = e.getX(); - popupMenu.topY = e.getY(); + Component comp = e.getComponent(); + int topX = e.getX(); + int topY = e.getY(); + /*if(comp.getClass().equals("MovingObject")) { + MovingObject object = (MovingObject)comp; + comp = (Component) object.getDesignArea(); + topX = topX + object.getPosition().getMonitor().getTopX(); + topY = topY + object.getPosition().getMonitor().getTopY(); + }*/ + popupMenu.show(comp, topX, topY); + popupMenu.topX = topX; + popupMenu.topY = topY; } } } @@ -68,7 +79,7 @@ this.setFocusable(false); this.designArea = _designArea; this.properties = properties; - designArea.paintAllPositions(); + //designArea.paintAllPositions(); // initializes paste menu item menuItemPaste = new JMenuItem(properties.getProperty("popupMenu.paste")); Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPane.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPane.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPane.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -188,10 +188,10 @@ * @return actual design area */ public DesignArea getActualDesignArea() { - if (this.getComponentCount() == 0) { + if (getActualTab() == null) { return null; } - return ((Tab) this.getSelectedComponent()).getDesignArea(); + return getActualTab().getDesignArea(); } /** @@ -233,7 +233,7 @@ this.getPropertiesManager().actualizePositionsList(); this.getMenuBar().actualize(); - designArea.paintAllPositions(); + //designArea.paintAllPositions(); int layoutCount = getTabCount(); // setSelectedIndex(0); Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPaneCloseTabButton.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPaneCloseTabButton.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/components/TabbedPaneCloseTabButton.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -101,7 +101,7 @@ CloseLayout closeDesignArea = new CloseLayout(tabbedPane, tabbedPane .getProperties()); - closeDesignArea.closeActualLayout(designArea, tabbedPane.getRootPane()); + closeDesignArea.closeActualLayout(tabbedPane.getActualTab(), tabbedPane.getRootPane()); Layout layout = ServerSideContext.getInstance().getLayout(); if (layout != null) { try { Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/propertiesManager/DocumentTypes.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/propertiesManager/DocumentTypes.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/propertiesManager/DocumentTypes.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -121,7 +121,7 @@ public void permitDocumentTypes() { TabbedPane tabbedPane = propertiesManager.getLayoutTabbedPane(); - DesignArea designArea = (DesignArea) tabbedPane.getSelectedComponent(); + DesignArea designArea = tabbedPane.getActualDesignArea(); Layout layout = designArea.getMyLayout(); Positions positions = layout Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/Marshaller.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/Marshaller.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/Marshaller.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -3,6 +3,7 @@ import java.io.*; import javax.xml.stream.*; +import com.elvys.applet.components.TabbedPane; import com.elvys.applet.structures.Layout; import com.elvys.applet.structures.Position; import com.elvys.applet.structures.RelativeCoordinates; @@ -25,10 +26,11 @@ * Gets string representation of xml file generated by the given layout * * @param layout the given layout + * @param tabbedPane tabbed pane * @return string representation of xml file generated by the given layout * @throws Exception */ - public String marshallLayoutToString(Layout layout) throws Exception { + public String marshallLayoutToString(Layout layout, TabbedPane tabbedPane) throws Exception { this.layout = layout; // initializes writer @@ -40,7 +42,7 @@ // writes head of xml file - writeHead(writer); + writeHead(writer, tabbedPane); // writes individual position in layout for (int i = 0; i < layout.getLayoutPositions().size(); ++i) { @@ -62,9 +64,10 @@ /** * Writes the head of xml file * @param writer xml writer + * @param tabbedPane tabbed pane * @throws XMLStreamException */ - private void writeHead(XMLStreamWriter writer) throws XMLStreamException { + private void writeHead(XMLStreamWriter writer, TabbedPane tabbedPane) throws XMLStreamException { @@ -88,8 +91,8 @@ writer.writeAttribute("name", layoutName); writer.writeStartElement("aspect-ratio"); // <aspect-ratio> - double width = layout.getScreenResolution().getElvysWidth(); - double height = layout.getScreenResolution().getElvysHeight(); + double width = layout.getScreenResolution().getElvysWidth() + tabbedPane.getLayoutDesigner().getTabPanelSizeWidth(); + double height = layout.getScreenResolution().getElvysHeight() + tabbedPane.getLayoutDesigner().getCategoriesPanelHeight(); double ratio = (double) width / (double) height; writer.writeAttribute("aspect-ratio", Double.toString(ratio)); writer.writeEndElement(); // </aspect-ratio> Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/SaveLayoutOnServer.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/SaveLayoutOnServer.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/SaveLayoutOnServer.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -81,7 +81,7 @@ if (layout.isNew()) { System.out.println("saved new layout"); layout.setName(newLayoutName); - String xml = new Marshaller().marshallLayoutToString(layout); + String xml = new Marshaller().marshallLayoutToString(layout, tabbedPane); System.out.println(xml); int layoutID = ServerSideContext.getInstance().storeLayout(xml); @@ -104,7 +104,7 @@ layout.setIsNew(true); layout.setRevision(0); String xml = new Marshaller() - .marshallLayoutToString(layout); + .marshallLayoutToString(layout, tabbedPane); int layoutID = ServerSideContext.getInstance() .storeLayout( xml); @@ -129,7 +129,7 @@ System.out.println(layout.getId()); System.out.println(layout.getRevision()); String xml = new Marshaller() - .marshallLayoutToString(layout); + .marshallLayoutToString(layout, tabbedPane); ServerSideContext.getInstance().storeLayout(xml); System.out.println(xml); designArea.setSaved(true); @@ -138,7 +138,7 @@ layout.setName(newLayoutName); layout.setIsNew(true); String xml = new Marshaller() - .marshallLayoutToString(layout); + .marshallLayoutToString(layout, tabbedPane); int layoutID = ServerSideContext.getInstance() .storeLayout( xml); Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/ServerSideContext.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/ServerSideContext.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/serverCommunication/ServerSideContext.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -104,7 +104,7 @@ instance.host = "http://"; + hostAddr + ":" + port; // for debugging: - //instance.host = "http://localhost:8080/";; + instance.host = "http://localhost:8080/";; } @@ -121,8 +121,6 @@ String companyID = applet.getParameter(PROPREF_COMPANY_ID); instance.companyID = Integer.parseInt(companyID); - // set layoutID - String layoutID = applet.getParameter(PROPREF_LAYOUT_ID); // set userID String userID = applet.getParameter(PROPREF_USER_ID); @@ -140,7 +138,7 @@ instance .setSupportedResolutions(instance.prepareSupportedResolutions()); - try { + /* try { instance.layoutID = Integer.parseInt(layoutID); instance.isLayoutLocked(); @@ -153,7 +151,35 @@ } catch (Exception e) { instance.layout = null; + }*/ + } + + /** + * Gets layoutID, companyID, userID, layout, permitted types of documents and supported resolutions + * @param applet LayoutDesigner applet + * @param tabbedPane main tabbed pane + * @throws Exception + */ + public void getLayout(Applet applet, TabbedPane tabbedPane) + throws Exception { + + // set layoutID + String layoutID = applet.getParameter(PROPREF_LAYOUT_ID); + + try { + instance.layoutID = Integer.parseInt(layoutID); + instance.isLayoutLocked(); + + if(!isLocked) { + instance.layout = instance.getLayoutToEdit(tabbedPane); } + else { + instance.layout = null; + } + + } catch (Exception e) { + instance.layout = null; + } } /** Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/CloseLayout.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/CloseLayout.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/CloseLayout.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -5,6 +5,7 @@ import com.elvys.applet.components.DesignArea; import com.elvys.applet.components.TabbedPane; +import com.elvys.applet.components.TabbedPane.Tab; import com.elvys.applet.dialog.UnsavedLayoutClosedDialog; import com.elvys.applet.serverCommunication.SaveLayoutOnServer; @@ -33,7 +34,7 @@ * @param rootPane root pane of the LayoutDesigner */ public void closeAllLayouts(JRootPane rootPane) { - int layoutCount = tabbedPane.getTabCount(); + /*int layoutCount = tabbedPane.getTabCount(); int index = 0; tabbedPane.setSelectedIndex(index); for(int i = 0; i < layoutCount; ++i) { @@ -48,6 +49,7 @@ } tabbedPane.getPropertiesManager().actualizeAll(); + */ } @@ -57,9 +59,10 @@ * @param rootPane root pane of the LayoutDesigner * @return whatever actual design area was closed */ - public boolean closeActualLayout(DesignArea designArea, JRootPane rootPane) { + public boolean closeActualLayout(Tab tab, JRootPane rootPane) { + DesignArea designArea = tab.getDesignArea(); if (designArea.isSaved()) { - tabbedPane.remove(designArea); + tabbedPane.remove(tab); tabbedPane.getPropertiesManager().actualizeAll(); } else { @@ -73,10 +76,10 @@ SaveLayoutOnServer saveLayoutOnServer = new SaveLayoutOnServer(tabbedPane); saveLayoutOnServer.saveLayout(layoutName, layoutName); - tabbedPane.remove(designArea); + tabbedPane.remove(tab); tabbedPane.getPropertiesManager().actualizeAll(); } else if (dialogResult == UnsavedLayoutClosedDialog.DialogResultOption.NO) { - tabbedPane.remove(designArea); + tabbedPane.remove(tab); tabbedPane.getPropertiesManager().actualizeAll(); } else { Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/MovingObject.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/MovingObject.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/MovingObject.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -125,8 +125,7 @@ * Makes deep copy */ public MovingObject clone() { - MovingObject clone = new MovingObject(); - clone.id = this.id; + MovingObject clone = new MovingObject(this.designArea, this.id, null); clone.monitorTopX = this.monitorTopX; clone.monitorTopY = this.monitorTopY; clone.monitorWidth = this.monitorWidth; @@ -652,8 +651,8 @@ /** * Empty constructor of class MovingObject */ - public MovingObject() { - } + //public MovingObject() { + //} /** * Constructor of the class Moving object @@ -662,30 +661,21 @@ * design area where corresponding position is designed * @param _id * id of corresponding position - * @param elvys - * elvys coordinates of corresponding position * @param monitor * monitor coordinates of corresponding position - * @param _screenResolution - * screen resolution - * @param _allTypes - * all permitted types of documents - * @param properties - * properties */ - public MovingObject(DesignArea _designArea, int _id, - AbsoluteCoordinates elvys, AbsoluteCoordinates monitor, - ScreenResolution _screenResolution, Vector<String> _allTypes, - Properties properties) { + public MovingObject(DesignArea _designArea, int _id, AbsoluteCoordinates monitor) { super(); this.instance = this; this.designArea = _designArea; - this.monitorTopX = monitor.getTopX(); - this.monitorTopY = monitor.getTopY(); - this.monitorWidth = monitor.getWidth(); - this.monitorHeight = monitor.getHeight(); + if(monitor != null ) { + this.monitorTopX = monitor.getTopX(); + this.monitorTopY = monitor.getTopY(); + this.monitorWidth = monitor.getWidth(); + this.monitorHeight = monitor.getHeight(); + } this.id = _id; @@ -995,4 +985,12 @@ return id; } + /** + * Gets the design area + * @return the designArea + */ + public DesignArea getDesignArea() { + return designArea; + } + } Modified: trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/Position.java =================================================================== --- trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/Position.java 2010-02-23 10:24:02 UTC (rev 1823) +++ trunk/layouteditor/LayoutDesigner/src/com/elvys/applet/structures/Position.java 2010-02-23 12:24:42 UTC (rev 1824) @@ -1433,14 +1433,10 @@ */ public MovingObject paint(DesignArea designArea) { - ScreenResolution screenSizes = designArea.getMyLayout() - .getScreenResolution(); AbsoluteCoordinates absol = getMonitor(); - MovingObject object = new MovingObject(designArea, getId(), elvys, - monitor, screenSizes, tabbedPane.getAllTypesOfDocument(), - tabbedPane.getProperties()); + MovingObject object = new MovingObject(designArea, getId(), monitor); object.setLocation(absol.getTopX(), absol.getTopY()); object.setSize(absol.getWidth(), absol.getHeight());