Ignore:
Timestamp:
2013-10-26T13:45:17+02:00 (12 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/seamap/Renderer.java

    r30028 r30029  
    330330
    331331        public static void labelText(Feature feature, String str, Font font, LabelStyle style, Color fg, Color bg, Delta delta) {
    332                 if (delta == null) delta = new Delta(Handle.CC, null);
     332                if (delta == null) delta = new Delta(Handle.CC, AffineTransform.getTranslateInstance(0, 0));
    333333                if (bg == null) bg = new Color(0x00000000, true);
    334                 if (str == null) str = " ";
    335                 if (str.isEmpty()) str = " ";
     334                if ((str == null) || (str.isEmpty())) str = " ";
    336335    FontRenderContext frc = g2.getFontRenderContext();
    337     GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "M" : str);
     336    GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
    338337    Rectangle2D bounds = gv.getVisualBounds();
    339338    double width = bounds.getWidth();
    340339    double height = bounds.getHeight();
    341                 if (width < height) width = height;
    342     double dx = 0;
    343     double dy = 0;
    344                 switch (delta.h) {
    345                 case CC:
    346                         dx += width / 2.0;
    347                         dy += height / 2.0;
    348                         break;
    349                 case TR:
    350                         dx += width;
    351                         break;
    352                 case TC:
    353                         dx += width / 2.0;
    354                         break;
    355                 case LC:
    356                         dy += height / 2.0;
    357                         break;
    358                 case RC:
    359                         dx += width;
    360                         dy += height / 2.0;
    361                         break;
    362                 case BL:
    363                         dy += height;
    364                         break;
    365                 case BR:
    366                         dx += width;
    367                         dy += height;
    368                         break;
    369                 case BC:
    370                         dx += width / 2.0;
    371                         dy += height;
    372                         break;
    373                 }
    374                 width += (height * 0.8);
    375                 dx += (height * 0.4);
    376                 height *= 1.5;
    377                 dy += (height * 0.15);
    378340                Symbol label = new Symbol();
     341                double lx = 0;
     342                double ly = 0;
     343                double tx = 0;
     344                double ty = 0;
    379345                switch (style) {
    380346                case RRCT:
     347                        width += height * 1.0;
     348                        height *= 1.5;
     349            if (width < height) width = height;
     350            lx = -width / 2;
     351            ly = -height / 2;
     352            tx = lx + (height * 0.34);
     353            ty = ly + (height * 0.17);
     354                        label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
    381355                        label.add(new Instr(Prim.FILL, bg));
    382                         label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(-dx,-dy,width,height,height,height)));
     356                        label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
    383357                        label.add(new Instr(Prim.FILL, fg));
    384358                        label.add(new Instr(Prim.STRK, new BasicStroke(1 + (int)(height/10), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
    385                         label.add(new Instr(Prim.RRCT, new RoundRectangle2D.Double(-dx,-dy,width,height,height,height)));
     359                        label.add(new Instr(Prim.RRCT, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
    386360                        break;
    387361                case VCLR:
    388                         height += 20;
    389                         dy += 10;
     362                        width += height * 1.0;
     363                        height *= 2.0;
     364            if (width < height) width = height;
     365            lx = -width / 2;
     366            ly = -height / 2;
     367            tx = lx + (height * 0.27);
     368            ty = ly + (height * 0.25);
     369                        label.add(new Instr(Prim.BBOX, new Rectangle2D.Double(lx,ly,width,height)));
    390370                        label.add(new Instr(Prim.FILL, bg));
    391                         label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(-dx,-dy,width,height,height,height)));
     371                        label.add(new Instr(Prim.RSHP, new RoundRectangle2D.Double(lx,ly,width,height,height,height)));
    392372                        label.add(new Instr(Prim.FILL, fg));
    393373                        int sw = 1 + (int)(height/10);
    394                         double po = dy - (sw / 2);
     374                        double po = sw / 2;
    395375                        label.add(new Instr(Prim.STRK, new BasicStroke(sw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
    396                         Path2D.Double p = new Path2D.Double(); p.moveTo(-(height*0.2),po); p.lineTo((height*0.2),po); p.moveTo(0,po); p.lineTo(0,po-10);
    397                         p.moveTo(-(height*0.2),-po); p.lineTo((height*0.2),-po); p.moveTo(0,-po); p.lineTo(0,-po+10);
     376                        Path2D.Double p = new Path2D.Double(); p.moveTo(-height*0.2,-ly-po); p.lineTo(height*0.2,-ly-po); p.moveTo(0,-ly-po); p.lineTo(0,-ly-po-(height*0.15));
     377                        p.moveTo(-height*0.2,ly+po); p.lineTo((height*0.2),ly+po); p.moveTo(0,ly+po); p.lineTo(0,ly+po+(height*0.15));
    398378                        label.add(new Instr(Prim.PLIN, p));
    399379                        break;
    400380                }
    401                 label.add(new Instr(Prim.TEXT, new Caption(str, font, fg, delta)));
     381                label.add(new Instr(Prim.TEXT, new Caption(str, font, fg, new Delta(Handle.TL, AffineTransform.getTranslateInstance(tx, ty)))));
    402382                Point2D point = context.getPoint(feature.centre);
    403                 Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), null, null);
     383                Symbols.drawSymbol(g2, label, sScale, point.getX(), point.getY(), delta, null);
    404384        }
    405385
Note: See TracChangeset for help on using the changeset viewer.