All pastes #412521 Raw Edit

Anonymous

public text v1 · immutable
#412521 ·published 2007-03-27 19:05 UTC
rendered paste body
    public void setRelation(IRelation relation) {
        this.relation = relation;
        repaint();
    }




   public LineChart() {
        createWindow();
    }
    
    public void createWindow() {
        JFrame frame = new JFrame("Hier oben");
        frame.setMinimumSize(new Dimension(500, 300));
        frame.setLayout(new BorderLayout());
        frame.getContentPane().setBackground(super.surroundingColor);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        LineChartZeichnen zeichnung = new LineChartZeichnen(super.relation);
        zeichnung.setOpaque(false);
        
        JPanel mittelding = new JPanel();
        mittelding.setLayout(new BorderLayout());
        mittelding.setOpaque(false);
        mittelding.setBackground(super.surroundingColor);
        JLabel yAchse = new JLabel(super.captionY);
        JLabel xAchse = new JLabel(super.captionX, JLabel.CENTER);
        yAchse.setForeground(Color.blue);
        mittelding.add(yAchse, BorderLayout.NORTH);
        mittelding.add(zeichnung, BorderLayout.CENTER);
        mittelding.add(xAchse, BorderLayout.SOUTH, getWidth() / 2);
        if (super.legendeWirdAngezeigt) {
            mittelding.add(new LineChartLegende(super.relation).relationToList(), BorderLayout.EAST);

        }
        frame.getContentPane().add(mittelding, BorderLayout.CENTER);
//        frame.setAlwaysOnTop(true);
        frame.setVisible(true);
        
    }





        Chart ads = new LineChart();
        ads.setRelation(relation);
        ads.setBackgroundColor(Color.black);
        ads.setAxisColor(Color.black);
        ads.setSurroundingColor(Color.black);
        ads.setVisible(true);






    public void paintComponent(Graphics g) {
        System.out.println(super.relation.getSortedValues().size());
        super.paintComponent(g);
        ++paintcount;
        System.out.println(paintcount);
        
        if (relation != null && relation.getSortedValues().size() > 0) {
            double xMinimum = relation.getSortedValues().get(0).getX();
            double xMaximum = relation.getSortedValues().get(relation.getSortedValues().size() - 1).getX();
            double yMinimum = relation.getSortedValues().get(0).getY();
            double yMaximum = relation.getSortedValues().get(0).getY();
            for (IPoint p : relation.getSortedValues()) {
                yMinimum = Math.min(p.getY(), yMinimum);
                yMaximum = Math.max(p.getY(), yMaximum);
            }
            
            double yInterval = yMaximum - yMinimum;
            double xInterval = xMaximum - xMinimum;
            
            fillTheColors();
            String a = "" + yMinimum;
            String b = "" + yMaximum;
            int c = Math.max(a.length(), b.length()) * 7;
            g.setColor(super.backGroundColor);
            g.fillRect(c, 19, getWidth() - c - 20, getHeight() - 40);
            g.setColor(super.axisColor);
            g.drawLine(c - 1, 0, c - 1, getHeight());
            g.drawLine(c - 20, getHeight() - 20, getWidth(), getHeight() - 20);
            g.drawLine(c - 1, 0, c - 16, 15);
            g.drawLine(getWidth(), getHeight() - 20, getWidth() - 15, getHeight() - 5);
            g.drawLine(c - 6, 20, c - 1, 20);
            g.drawLine(getWidth() - 20, getHeight() - 20, getWidth() - 20, getHeight() - 14);
            g.drawString("" + xMinimum, 32, getHeight() - 5);
            g.drawString("" + xMaximum, getWidth() - 22 - ("" + xMaximum).length() * 10, getHeight() - 5);
            g.drawString("" + yMaximum, 0, 35);
            g.drawString("" + yMinimum, 0, getHeight() - 24);
            for (String n : relation.getCategories()) {
                g.setColor(farbenListe.get(n));
                int zahl = relation.getSortedValues(n).size() - 1;
                g.drawLine(c, 20 + (int) ((yMaximum - relation.getSortedValues(n).get(0).getY()) * (getHeight() - 40) / yInterval) - 1, c + (int) (relation.getSortedValues(n).get(0).getX() * (getWidth() - c - 20) / xInterval), 20 +  (int) ((yMaximum - relation.getSortedValues(n).get(0).getY()) * (getHeight() - 40) / yInterval) - 1); 
                g.drawLine(c + (int) (relation.getSortedValues(n).get(zahl).getX() * (getWidth() - 20 - c) / xInterval), 20 + (int) ((yMaximum - relation.getSortedValues(n).get(zahl).getY()) * (getHeight() - 40) / yInterval) - 1, getWidth() - 21, 20 + (int) ((yMaximum - relation.getSortedValues(n).get(zahl).getY()) * (getHeight() - 40) / yInterval) - 1); 

                
                for (int i = 1; i < relation.getSortedValues(n).size(); i++) {
                    g.drawLine(c + (int) (relation.getSortedValues(n).get(i - 1).getX() * (getWidth() - c - 20) / xInterval), 20 + (int) ((yMaximum - relation.getSortedValues(n).get(i - 1).getY()) * (getHeight() - 40) / yInterval) - 1, c + (int) (relation.getSortedValues(n).get(i).getX() * (getWidth() - 20 - c) / xInterval), 20 + (int) ((yMaximum - relation.getSortedValues(n).get(i).getY()) * (getHeight() - 40) / yInterval) - 1);
                }
            }
        } else {
            g.setColor(super.backGroundColor);
            g.fillRect(30, 19, getWidth() - 30 - 20, getHeight() - 40);
            g.setColor(super.axisColor);
            g.drawLine(29, 0, 29, getHeight());
            g.drawLine(10, getHeight() - 20, getWidth(), getHeight() - 20);
            g.drawLine(29, 0, 14, 15);
            g.drawLine(getWidth(), getHeight() - 20, getWidth() - 15, getHeight() - 5);
            g.drawLine(24, 20, 29, 20);
            g.drawLine(getWidth() - 20, getHeight() - 20, getWidth() - 20, getHeight() - 14);

        }