Fixes for Network Map text box decoration
authorEriks Jenkevics <eriks@netxms.org>
Wed, 6 Dec 2017 09:58:48 +0000 (11:58 +0200)
committerEriks Jenkevics <eriks@netxms.org>
Wed, 6 Dec 2017 09:58:48 +0000 (11:58 +0200)
src/client/java/netxms-client/src/main/java/org/netxms/client/maps/elements/NetworkMapTextBox.java
src/java/netxms-eclipse/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java
webui/webapp/NetworkMaps/src/org/netxms/ui/eclipse/networkmaps/views/helpers/TextBoxFigure.java

index 196c67a..8a558c5 100644 (file)
@@ -82,6 +82,7 @@ public class NetworkMapTextBox extends NetworkMapElement
       textColor = 0;//black
       borderColor = 0;//black
       borderRequired = true;
+      fontSize = 10;
       type = MAP_ELEMENT_TEXT_BOX;
    }
    
index cd9d13f..35b3c93 100644 (file)
  */
 package org.netxms.ui.eclipse.networkmaps.views.helpers;
 
+import org.eclipse.draw2d.BorderLayout;
 import org.eclipse.draw2d.Graphics;
 import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.PositionConstants;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.draw2d.geometry.Rectangle;
@@ -31,8 +33,9 @@ import org.netxms.ui.eclipse.tools.ColorConverter;
 
 public class TextBoxFigure extends DecorationLayerAbstractFigure
 {
-   private static final int BORDER_SIZE = 7;
-   private static final int MARGIN = 7;
+   private static final int MARGIN_X = 3;
+   private static final int MARGIN_Y = 3;
+   private static final int BORDER_SIZE = 3;
    
    private Label text;
    private NetworkMapTextBox textBoxElement;
@@ -49,22 +52,22 @@ public class TextBoxFigure extends DecorationLayerAbstractFigure
       super(decoration, viewer);
       this.textBoxElement = decoration;
       this.labelProvider = labelProvider;
+      
+      setLayoutManager(new BorderLayout());
 
       text = new Label(textBoxElement.getText());
       text.setFont(new Font(Display.getCurrent(), "Verdana", textBoxElement.getFontSize(), SWT.NONE));
-      add(text);
+      text.setLabelAlignment(PositionConstants.CENTER);
       
       Dimension d = text.getPreferredSize();
-      text.setSize(d.width+MARGIN, d.height+MARGIN);
-      int border = 0;
-      if(textBoxElement.isBorderRequired())
-      {
-         text.setLocation(new Point(BORDER_SIZE, BORDER_SIZE));
-         border = BORDER_SIZE;
-      }
-      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);
+      text.setSize(d);
+      
+      Point p = text.getLocation();
+      p.translate(MARGIN_X*4, MARGIN_Y);
+      text.setLocation(p);
+      add(text);
+      setSize(d.width + MARGIN_X*8, d.height + MARGIN_Y*2);
       
-      text.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
       text.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));  
    }
    
@@ -76,18 +79,27 @@ public class TextBoxFigure extends DecorationLayerAbstractFigure
    {
       gc.setAntialias(SWT.ON);
       
+      Rectangle rect = new Rectangle(getBounds());
+      rect.x+=MARGIN_X;
+      rect.y+=MARGIN_Y;
+      rect.width -= MARGIN_X*2;
+      rect.height -= MARGIN_Y*2;
+      gc.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
+      gc.fillRoundRectangle(rect, 3, 3);
+      
       if(textBoxElement.isBorderRequired())
       {
-         Rectangle rect = new Rectangle(text.getClientArea());
+         rect = new Rectangle(getBounds());
+         rect.x++;
+         rect.y++;
+         rect.width -= MARGIN_X;
+         rect.height -= MARGIN_Y;
          
-         gc.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));
+         gc.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBorderColor())));
          gc.setLineWidth(BORDER_SIZE);
          gc.setLineStyle(SWT.LINE_SOLID);
          gc.drawRoundRectangle(rect, 8, 8);         
       }
-
-      gc.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
-      gc.fillRoundRectangle(text.getBounds(), 8, 8);
    }
 
    /* (non-Javadoc)
@@ -96,14 +108,15 @@ public class TextBoxFigure extends DecorationLayerAbstractFigure
    @Override
    public void refresh()
    {
-      //Set new label text
       text.setText(textBoxElement.getText());
       
-      //Recalculate figure size
       Dimension d = text.getPreferredSize();
-      text.setSize(d.width+MARGIN, d.height+MARGIN);
-      int border = textBoxElement.isBorderRequired() ? BORDER_SIZE : 0;
-      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);    
+      text.setSize(d);
+      
+      Point p = text.getLocation();
+      p.translate(MARGIN_X*4, MARGIN_Y);
+      text.setLocation(p);
+      setSize(d.width + MARGIN_X*8, d.height + MARGIN_Y*2);  
       
       repaint();
    }
index 331f515..251b06a 100644 (file)
  */
 package org.netxms.ui.eclipse.networkmaps.views.helpers;
 
+import org.eclipse.draw2d.BorderLayout;
 import org.eclipse.draw2d.Graphics;
 import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.PositionConstants;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.Point;
 import org.eclipse.draw2d.geometry.Rectangle;
@@ -31,8 +33,9 @@ import org.netxms.ui.eclipse.tools.ColorConverter;
 
 public class TextBoxFigure extends DecorationLayerAbstractFigure
 {
-   private static final int BORDER_SIZE = 7;
-   private static final int MARGIN = 7;
+   private static final int MARGIN_X = 3;
+   private static final int MARGIN_Y = 3;
+   private static final int BORDER_SIZE = 3;
    
    private Label text;
    private NetworkMapTextBox textBoxElement;
@@ -46,26 +49,26 @@ public class TextBoxFigure extends DecorationLayerAbstractFigure
     */
    public TextBoxFigure(NetworkMapTextBox decoration, MapLabelProvider labelProvider, ExtendedGraphViewer viewer)
    {
-      super(decoration, viewer);
-      this.textBoxElement = decoration;
-      this.labelProvider = labelProvider;
-
-      text = new Label(textBoxElement.getText());
-      text.setFont(new Font(Display.getCurrent(), "Verdana", textBoxElement.getFontSize(), SWT.NONE));
-      add(text);
-      
-      Dimension d = text.getPreferredSize();
-      text.setSize(d.width+MARGIN, d.height+MARGIN);
-      int border = 0;
-      if(textBoxElement.isBorderRequired())
-      {
-         text.setLocation(new Point(BORDER_SIZE, BORDER_SIZE));
-         border = BORDER_SIZE;
-      }
-      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);
-      
-      text.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
-      text.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));  
+         super(decoration, viewer);
+         this.textBoxElement = decoration;
+         this.labelProvider = labelProvider;
+         
+         setLayoutManager(new BorderLayout());
+       
+         text = new Label(textBoxElement.getText());
+         text.setFont(new Font(Display.getCurrent(), "Verdana", textBoxElement.getFontSize(), SWT.NONE));
+         text.setLabelAlignment(PositionConstants.CENTER);
+         
+         Dimension d = text.getPreferredSize();
+         text.setSize(d);
+         
+         Point p = text.getLocation();
+         p.translate(MARGIN_X*4, MARGIN_Y);
+         text.setLocation(p);
+         add(text);
+         setSize(d.width + MARGIN_X*8, d.height + MARGIN_Y*2);
+         
+         text.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));
    }
    
    /* (non-Javadoc)
@@ -76,18 +79,27 @@ public class TextBoxFigure extends DecorationLayerAbstractFigure
    {
       gc.setAntialias(SWT.ON);
       
+      Rectangle rect = new Rectangle(getBounds());
+      rect.x+=MARGIN_X;
+      rect.y+=MARGIN_Y;
+      rect.width -= MARGIN_X*2;
+      rect.height -= MARGIN_Y*2;
+      gc.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
+      gc.fillRoundRectangle(rect, 3, 3);
+      
       if(textBoxElement.isBorderRequired())
       {
-         Rectangle rect = new Rectangle(text.getClientArea());
+         rect = new Rectangle(getBounds());
+         rect.x++;
+         rect.y++;
+         rect.width -= MARGIN_X;
+         rect.height -= MARGIN_Y;
          
-         gc.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getTextColor())));
+         gc.setForegroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBorderColor())));
          gc.setLineWidth(BORDER_SIZE);
-         //gc.setLineStyle(SWT.LINE);
+         gc.setLineStyle(Graphics.LINE_SOLID);
          gc.drawRoundRectangle(rect, 8, 8);         
       }
-
-      gc.setBackgroundColor(labelProvider.getColors().create(ColorConverter.rgbFromInt(textBoxElement.getBackgroundColor())));
-      gc.fillRoundRectangle(text.getBounds(), 8, 8);
    }
 
    /* (non-Javadoc)
@@ -96,16 +108,16 @@ public class TextBoxFigure extends DecorationLayerAbstractFigure
    @Override
    public void refresh()
    {
-      //Set new label text
       text.setText(textBoxElement.getText());
       
-      //Recalculate figure size
       Dimension d = text.getPreferredSize();
-      text.setSize(d.width+MARGIN, d.height+MARGIN);
-      int border = textBoxElement.isBorderRequired() ? BORDER_SIZE : 0;
-      setSize(d.width + (border *2) + MARGIN, d.height + (border *2) + MARGIN);    
+      text.setSize(d);
+      
+      Point p = text.getLocation();
+      p.translate(MARGIN_X*4, MARGIN_Y);
+      text.setLocation(p);
+      setSize(d.width + MARGIN_X*8, d.height + MARGIN_Y*2);  
       
       repaint();
    }
-
 }