Ignore:
Timestamp:
2011-12-08T00:27:39+01:00 (13 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed/plugs/oseam/src/oseam/seamarks/SeaMark.java

    r27155 r27189  
    11package oseam.seamarks;
    22
     3import javax.swing.*;
     4
    35import java.awt.*;
    4 import javax.swing.*;
     6import java.awt.geom.Arc2D;
     7
    58import java.util.*;
    69
     
    1215import oseam.dialogs.OSeaMAction;
    1316
    14 public class SeaMark {
     17public class SeaMark extends JPanel {
    1518
    1619        public OSeaMAction dlg = null;
     
    5154        public void setName(String str) {
    5255                name = str.trim();
     56                repaint();
    5357        }
    5458
     
    97101        public void setObject(Obj obj) {
    98102                object = obj;
     103                repaint();
    99104        }
    100105
     
    266271        public void setCategory(Cat cat) {
    267272                category = cat;
     273                repaint();
    268274        }
    269275
     
    299305        public void setShape(Shp shp) {
    300306                shape = shp;
     307                repaint();
    301308        }
    302309
     
    387394                bodyColour.clear();
    388395                bodyColour.add(col);
     396                repaint();
    389397        }
    390398
     
    392400                if (bodyColour.size() > i)
    393401                        bodyColour.set(i, col);
     402                repaint();
    394403        }
    395404
     
    420429                topmarkColour.clear();
    421430                topmarkColour.add(col);
     431                repaint();
    422432        }
    423433
     
    425435                if (topmarkColour.size() > i)
    426436                        topmarkColour.set(i, col);
     437                repaint();
    427438        }
    428439
     
    583594                                sectors.get(i)[att] = obj;
    584595                        }
     596                repaint();
    585597        }
    586598
     
    689701        public void setTopmark(Top top) {
    690702                topShape = top;
     703                repaint();
    691704        }
    692705
     
    710723        public void setRadar(Rtb type) {
    711724                RaType = type;
     725                repaint();
    712726        }
    713727
     
    720734        public void setRaconGroup(String grp) {
    721735                raconGroup = grp;
     736                repaint();
    722737        }
    723738
     
    730745        public void setRaconSequence(String seq) {
    731746                raconSequence = seq;
     747                repaint();
    732748        }
    733749
     
    740756        public void setRaconPeriod(String per) {
    741757                raconPeriod = validDecimal(per);
     758                repaint();
    742759        }
    743760
     
    750767        public void setRaconRange(String rng) {
    751768                raconRange = validDecimal(rng);
     769                repaint();
    752770        }
    753771
     
    760778        public void setRaconSector1(String sec) {
    761779                raconSector1 = validDecimal(sec);
     780                repaint();
    762781        }
    763782
     
    770789        public void setRaconSector2(String sec) {
    771790                raconSector2 = validDecimal(sec);
     791                repaint();
    772792        }
    773793
     
    796816        public void setFogSound(Fog sound) {
    797817                fogSound = sound;
     818                repaint();
    798819        }
    799820
     
    806827        public void setFogGroup(String grp) {
    807828                fogGroup = grp;
     829                repaint();
    808830        }
    809831
     
    816838        public void setFogSequence(String seq) {
    817839                fogSequence = seq;
     840                repaint();
    818841        }
    819842
     
    826849        public void setFogRange(String rng) {
    827850                fogRange = validDecimal(rng);
     851                repaint();
    828852        }
    829853
     
    836860        public void setFogPeriod(String per) {
    837861                fogPeriod = validDecimal(per);
     862                repaint();
    838863        }
    839864
     
    964989        public String height = "";
    965990
    966         public String getHeight() {
     991        public String getObjectHeight() {
    967992                return height;
    968993        }
    969994
    970         public void setHeight(String str) {
     995        public void setObjectHeight(String str) {
    971996                height = validDecimal(str);
    972997        }
     
    10871112                dlg.panelMain.panelMore.syncPanel();
    10881113                dlg.panelMain.panelMore.setVisible(false);
    1089                 paintSign();
    10901114        }
    10911115
     
    11121136        }
    11131137
    1114         private boolean paintlock = false;
    1115 
    11161138        public void parseMark(Node node) {
    1117                 paintlock = true;
    11181139                dlg.manager.showVisualMessage("");
    11191140                String str = Main.pref.get("smedplugin.IALA");
     
    12241245
    12251246                        if (keys.containsKey("seamark:" + ObjSTR.get(obj) + ":height")) {
    1226                                 setHeight(keys.get("seamark:" + ObjSTR.get(obj) + ":height"));
     1247                                setObjectHeight(keys.get("seamark:" + ObjSTR.get(obj) + ":height"));
    12271248                        }
    12281249                        if (keys.containsKey("seamark:" + ObjSTR.get(obj) + ":elevation")) {
     
    15321553                }
    15331554                if (keys.containsKey("seamark:height")) {
    1534                         setHeight(keys.get("seamark:height"));
     1555                        setObjectHeight(keys.get("seamark:height"));
    15351556                }
    15361557                if (keys.containsKey("seamark:elevation")) {
     
    15921613                dlg.panelMain.syncPanel();
    15931614
    1594                 paintlock = false;
    1595                 paintSign();
    1596         }
    1597 
    1598         public void paintSign() {
    1599 
    1600                 if (paintlock)
    1601                         return;
    1602 
    1603                 dlg.panelMain.shapeIcon.setIcon(null);
    1604                 dlg.panelMain.litLabel.setText("");
    1605                 dlg.panelMain.colLabel.setText("");
    1606                 dlg.panelMain.radarLabel.setText("");
    1607                 dlg.panelMain.fogLabel.setText("");
    1608                 dlg.panelMain.topIcon.setIcon(null);
    1609                 dlg.panelMain.fogIcon.setIcon(null);
    1610                 dlg.panelMain.radarIcon.setIcon(null);
    1611                 dlg.panelMain.lightIcon.setIcon(null);
    1612 
    1613                 String colStr;
     1615        }
     1616
     1617        public void paintComponent(Graphics g) {
     1618                super.paintComponent(g);
     1619               
     1620    Graphics2D g2 = (Graphics2D) g;
     1621
     1622    String colStr;
    16141623                String lblStr;
    16151624                String imgStr = "/images/";
     
    17321741                                                System.out.println("Missing image: " + imgStr);
    17331742                                        } else {
    1734                                                 dlg.panelMain.shapeIcon.setIcon(new ImageIcon(getClass()
    1735                                                                 .getResource(imgStr)));
    1736                                                 dlg.panelMain.colLabel.setText(lblStr);
     1743                                                g.drawImage(new ImageIcon(getClass().getResource(imgStr)).getImage(), 7, -15, null);
     1744                                                g.drawString(lblStr, 75, 110);
    17371745                                        }
    17381746                                } else {
    1739                                         dlg.panelMain.shapeIcon.setIcon(new ImageIcon(getClass().getResource(colStr)));
    1740                                 }
    1741                         } else {
    1742                                 dlg.panelMain.shapeIcon.setIcon(null);
     1747                                        g.drawImage(new ImageIcon(getClass().getResource(colStr)).getImage(), 7, -15, null);
     1748                                }
    17431749                        }
    17441750                } else if (getObject() != Obj.UNKNOWN) {
     
    18051811                                        System.out.println("Missing image: " + imgStr);
    18061812                                } else {
    1807                                         dlg.panelMain.shapeIcon.setIcon(new ImageIcon(getClass().getResource(imgStr)));
    1808                                 }
    1809                         } else {
    1810                                 dlg.panelMain.shapeIcon.setIcon(null);
     1813                                        g.drawImage(new ImageIcon(getClass().getResource(imgStr)).getImage(), 7, -15, null);
     1814                                }
    18111815                        }
    18121816                }
     
    19141918                                        return;
    19151919                                } else {
    1916                                         dlg.panelMain.topIcon.setIcon(new ImageIcon(getClass().getResource(imgStr)));
     1920                                        g.drawImage(new ImageIcon(getClass().getResource(imgStr)).getImage(), 7, -15, null);
    19171921                                }
    19181922                        } else {
    1919                                 dlg.panelMain.topIcon.setIcon(new ImageIcon(getClass().getResource(colStr)));
    1920                         }
    1921                 } else {
    1922                         dlg.panelMain.topIcon.setIcon(null);
     1923                                g.drawImage(new ImageIcon(getClass().getResource(colStr)).getImage(), 7, -15, null);
     1924                        }
     1925                }
     1926
     1927                for (int i = 1; i < sectors.size(); i++) {
     1928            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     1929            g2.setPaint(ColMAP.get(getLightAtt(Att.COL, i)));
     1930            g2.setStroke(new BasicStroke(6.0f));
     1931            if (!((String)getLightAtt(Att.BEG, i)).isEmpty() && !((String)getLightAtt(Att.END, i)).isEmpty()) {
     1932                Double a0 = 270 - Double.parseDouble((String)getLightAtt(Att.BEG, i));
     1933                Double da = 270 - Double.parseDouble((String)getLightAtt(Att.END, i)) - a0;
     1934                da -= da > 0 ? 360 : 0;
     1935                g2.draw(new Arc2D.Double(12, 15, 140, 140, a0, da, Arc2D.OPEN));
     1936            }
     1937                }
     1938    g2.setPaint(Color.BLACK);
     1939                if (getLightAtt(Att.COL, 0) != Col.UNKNOWN) {
     1940                        if (sectors.size() == 1) {
     1941                                switch ((Col) getLightAtt(Att.COL, 0)) {
     1942                                case RED:
     1943                                        g.drawImage(new ImageIcon(getClass().getResource("/images/Light_Red_120.png")).getImage(), 7, -15, null);
     1944                                        break;
     1945                                case GREEN:
     1946                                        g.drawImage(new ImageIcon(getClass().getResource("/images/Light_Green_120.png")).getImage(), 7, -15, null);
     1947                                        break;
     1948                                case WHITE:
     1949                                case YELLOW:
     1950                                        g.drawImage(new ImageIcon(getClass().getResource("/images/Light_White_120.png")).getImage(), 7, -15, null);
     1951                                        break;
     1952                                default:
     1953                                        g.drawImage(new ImageIcon(getClass().getResource("/images/Light_Magenta_120.png")).getImage(), 7, -15, null);
     1954                                }
     1955                        }
     1956                        String c = (String) dlg.mark.getLightAtt(Att.CHR, 0);
     1957                        String tmp = "";
     1958                        if (c.contains("+")) {
     1959                                int i1 = c.indexOf("+");
     1960                                tmp = c.substring(i1, c.length());
     1961                                c = c.substring(0, i1);
     1962                                if (!((String) getLightAtt(Att.GRP, 0)).isEmpty()) {
     1963                                        c += "(" + (String) getLightAtt(Att.GRP, 0) + ")";
     1964                                }
     1965                                if (tmp != null)
     1966                                        c += tmp;
     1967                        } else if (!((String) getLightAtt(Att.GRP, 0)).isEmpty())
     1968                                c += "(" + (String) getLightAtt(Att.GRP, 0) + ")";
     1969                        switch ((Col) getLightAtt(Att.COL, 0)) {
     1970                        case RED:
     1971                                c += ".R";
     1972                                break;
     1973                        case GREEN:
     1974                                c += ".G";
     1975                                break;
     1976                        case AMBER:
     1977                                c += ".Am";
     1978                                break;
     1979                        case ORANGE:
     1980                                c += ".Or";
     1981                                break;
     1982                        case BLUE:
     1983                                c += ".Bu";
     1984                                break;
     1985                        case VIOLET:
     1986                                c += ".Vi";
     1987                                break;
     1988                        }
     1989                        tmp = (String) getLightAtt(Att.MLT, 0);
     1990                        if (!tmp.isEmpty())
     1991                                c = tmp + c;
     1992                        if (dlg.mark.getLightAtt(Att.LIT, 0) != Lit.UNKNOWN) {
     1993                                switch ((Lit)dlg.mark.getLightAtt(Att.LIT, 0)) {
     1994                                case VERT:
     1995                                        c += "(Vert)";
     1996                                        break;
     1997                                case HORIZ:
     1998                                                c += "(Horiz)";
     1999                                                break;
     2000                                }
     2001                        }
     2002                        tmp = (String) getLightAtt(Att.PER, 0);
     2003                        if (!tmp.isEmpty())
     2004                                c += " " + tmp + "s";
     2005                        g.drawString(c, 100, 70);
    19232006                }
    19242007
    19252008                if (getFogSound() != Fog.NONE) {
    1926                         dlg.panelMain.fogIcon.setIcon(new ImageIcon(getClass().getResource("/images/Fog_Signal.png")));
     2009                        g.drawImage(new ImageIcon(getClass().getResource("/images/Fog_Signal.png")).getImage(), 7, -15, null);
    19272010                        String str = "";
    19282011                        if (getFogSound() != Fog.UNKNOWN)
     
    19562039                        if (!getFogPeriod().isEmpty())
    19572040                                str += getFogPeriod() + "s";
    1958                         dlg.panelMain.fogLabel.setText(str);
     2041                        g.drawString(str, 0, 70);
    19592042                }
    19602043
    19612044                if (RaType != Rtb.NONE) {
    19622045                        if (getRadar() == Rtb.REFLECTOR) {
    1963                                 dlg.panelMain.radarIcon.setIcon(new ImageIcon(getClass().getResource("/images/Radar_Reflector_355.png")));
     2046                                g.drawImage(new ImageIcon(getClass().getResource("/images/Radar_Reflector_355.png")).getImage(), 7, -15, null);
    19642047                        } else {
    1965                                 dlg.panelMain.radarIcon.setIcon(new ImageIcon(getClass().getResource("/images/Radar_Station.png")));
     2048                                g.drawImage(new ImageIcon(getClass().getResource("/images/Radar_Station.png")).getImage(), 7, -15, null);
    19662049                                String str = "";
    19672050                                if (getRadar() == Rtb.RAMARK)
     
    19752058                                if (!getRaconPeriod().isEmpty())
    19762059                                        str += getRaconPeriod() + "s";
    1977                                 dlg.panelMain.radarLabel.setText(str);
    1978                         }
    1979                 }
    1980 
    1981                 if (getLightAtt(Att.COL, 0) != Col.UNKNOWN) {
    1982                         if (sectors.size() == 1) {
    1983                                 switch ((Col) getLightAtt(Att.COL, 0)) {
    1984                                 case RED:
    1985                                         dlg.panelMain.lightIcon.setIcon(new ImageIcon(getClass().getResource("/images/Light_Red_120.png")));
    1986                                         break;
    1987                                 case GREEN:
    1988                                         dlg.panelMain.lightIcon.setIcon(new ImageIcon(getClass().getResource("/images/Light_Green_120.png")));
    1989                                         break;
    1990                                 case WHITE:
    1991                                 case YELLOW:
    1992                                         dlg.panelMain.lightIcon.setIcon(new ImageIcon(getClass().getResource("/images/Light_White_120.png")));
    1993                                         break;
    1994                                 default:
    1995                                         dlg.panelMain.lightIcon.setIcon(new ImageIcon(getClass().getResource("/images/Light_Magenta_120.png")));
    1996                                 }
    1997                         }
    1998                         String c = (String) dlg.mark.getLightAtt(Att.CHR, 0);
    1999                         String tmp = "";
    2000                         if (c.contains("+")) {
    2001                                 int i1 = c.indexOf("+");
    2002                                 tmp = c.substring(i1, c.length());
    2003                                 c = c.substring(0, i1);
    2004                                 if (!((String) getLightAtt(Att.GRP, 0)).isEmpty()) {
    2005                                         c += "(" + (String) getLightAtt(Att.GRP, 0) + ")";
    2006                                 }
    2007                                 if (tmp != null)
    2008                                         c += tmp;
    2009                         } else if (!((String) getLightAtt(Att.GRP, 0)).isEmpty())
    2010                                 c += "(" + (String) getLightAtt(Att.GRP, 0) + ")";
    2011                         switch ((Col) getLightAtt(Att.COL, 0)) {
    2012                         case RED:
    2013                                 c += ".R";
    2014                                 break;
    2015                         case GREEN:
    2016                                 c += ".G";
    2017                                 break;
    2018                         case AMBER:
    2019                                 c += ".Am";
    2020                                 break;
    2021                         case ORANGE:
    2022                                 c += ".Or";
    2023                                 break;
    2024                         case BLUE:
    2025                                 c += ".Bu";
    2026                                 break;
    2027                         case VIOLET:
    2028                                 c += ".Vi";
    2029                                 break;
    2030                         }
    2031                         tmp = (String) getLightAtt(Att.MLT, 0);
    2032                         if (!tmp.isEmpty())
    2033                                 c = tmp + c;
    2034                         if (dlg.mark.getLightAtt(Att.LIT, 0) != Lit.UNKNOWN) {
    2035                                 switch ((Lit)dlg.mark.getLightAtt(Att.LIT, 0)) {
    2036                                 case VERT:
    2037                                         c += "(Vert)";
    2038                                         break;
    2039                                 case HORIZ:
    2040                                                 c += "(Horiz)";
    2041                                                 break;
    2042                                 }
    2043                         }
    2044                         tmp = (String) getLightAtt(Att.PER, 0);
    2045                         if (!tmp.isEmpty())
    2046                                 c += " " + tmp + "s";
    2047                         dlg.panelMain.litLabel.setText(c);
    2048                 }
    2049 
    2050                 paintlock = false;
     2060                                g.drawString(str, 0, 50);
     2061                        }
     2062                }
     2063
    20512064        }
    20522065
     
    21032116                                        }
    21042117                                }
    2105                                 if (!getHeight().isEmpty()) {
    2106                                         Main.main.undoRedo.add(new ChangePropertyCommand(node, "seamark:" + objStr + ":height", getHeight()));
     2118                                if (!getObjectHeight().isEmpty()) {
     2119                                        Main.main.undoRedo.add(new ChangePropertyCommand(node, "seamark:" + objStr + ":height", getObjectHeight()));
    21072120                                }
    21082121                                if (!getElevation().isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.