Example #1
0
 public void paintComponent(Graphics g)
 {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D)g;
   g2.setStroke(LineAttributes.getStrokes()[selectedIndex]);
   g2.drawLine(10, 10, 90, 10);
 }
Example #2
0
  /**
   * Utility used by uk.ac.sanger.artemis.components.Plot
   * @param numPlots
   * @param lines
   * @param plot
   * @return
   */
  public static LineAttributes[] configurePlots(
                                    final List<String> bamList, 
                                    final LineAttributes[] lines,
                                    final JPanel covergePanel)
  {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    final int numPlots = bamList.size();
    final LineAttributes[] thislines;
    if(lines.length < numPlots)
      thislines = init(numPlots);
    else
      thislines = lines;
    
    int gridx = 0;
    int gridy = 0;
    c.gridy = gridy++;
    c.gridx = gridx;
    // open / filled    
    panel.add(new JLabel("Plot Options:"), c);
    final JComboBox openPlot = new JComboBox(PLOT_TYPES);
    openPlot.setSelectedItem(thislines[0].plotType);
    openPlot.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        for(int i=0; i<numPlots; i++)
          thislines[i].plotType =    
            (String) openPlot.getSelectedItem();
        covergePanel.repaint();
      }
    });
    c.gridy = gridy++;
    panel.add(openPlot, c);
    
    c.gridy = gridy++;
    panel.add(new JLabel("Line Options:"), c);
    c.gridx = gridx++;
    c.gridy = gridy++;
    gridx++;
    
    final JCheckBox applyToAll = new JCheckBox("Apply colour to all");

    panel.add(new JLabel("Colour"), c);
    c.gridx = gridx++;
    panel.add(new JLabel("Line style"), c);
   
    c.gridx = gridx;
    panel.add(new JLabel("Line size"), c);
    
    for(int i=0; i<numPlots; i++)
    {
      c.gridy = gridy++;
      final int colourNumber = i;
      gridx = 0;

      c.gridx = 0;
      c.gridwidth = GridBagConstraints.REMAINDER;
      c.anchor = GridBagConstraints.NORTHWEST;
      final JLabel bamFileName = new JLabel(bamList.get(i));
      panel.add(bamFileName,c);
      
      c.gridwidth = 1;
      c.gridy = gridy++;
      final JLabel colourLabel = new JLabel("   ");
      colourLabel.setBackground(thislines[i].getLineColour());
      colourLabel.setOpaque(true);
      c.gridx = gridx++;
      panel.add(colourLabel,c);

      JButton butt = new JButton("Select");
      butt.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent _)
        {
          Color newColour = JColorChooser.showDialog(null, "Colour Chooser",
              thislines[colourNumber].getLineColour());
          
          if(applyToAll.isSelected())
          {
            for(int iplot=0; iplot<numPlots; iplot++)
              thislines[iplot].setLineColour(newColour);
          }
          else
            thislines[colourNumber].setLineColour(newColour); 
          colourLabel.setBackground(thislines[colourNumber].getLineColour());
          covergePanel.repaint();
        }
      });
      c.gridx = gridx++;
      panel.add(butt, c);
      
      // line style
      final JSlider slider = new JSlider(1, 10, 
          (int)lines[colourNumber].getStroke().getLineWidth());
      Integer index[] = new Integer[STROKES.length];
      for(int j=0; j<index.length; j++)
        index[j] = j;
      final JComboBox lineStyle = new JComboBox(index);
      lineStyle.setRenderer(new LineStyleListRenderer());
      lineStyle.setSelectedIndex(
          LineAttributes.getStyleIndex(thislines[colourNumber].getStroke()));
      lineStyle.addItemListener(new ItemListener()
      {
        public void itemStateChanged(ItemEvent e)
        {
          thislines[colourNumber].setStroke(
              STROKES[lineStyle.getSelectedIndex()]);
          setLineSize(covergePanel, slider, thislines, colourNumber);
        }
      });
      c.gridx = gridx++;
      panel.add(lineStyle, c);
      
      
      // line size
      slider.addChangeListener(new ChangeListener()
      {
        public void stateChanged(ChangeEvent e)
        {
          setLineSize(covergePanel, slider, thislines, colourNumber);
        }
      });
      c.gridx = gridx;
      panel.add(slider, c);
      
    }
    
    c.gridx = 0;
    c.gridy = gridy++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.WEST;
    panel.add(applyToAll, c);

    JScrollPane jsp = new JScrollPane(panel, 
        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    
    if(panel.getPreferredSize().height > d.height/2)
    {
      d.setSize(jsp.getPreferredSize().width, d.height/2);
      jsp.setPreferredSize(d);
    }
    
    String config_options[] = { "OK" };
    JOptionPane.showOptionDialog(null,
                                 jsp, "Configure Lines",
                                 JOptionPane.DEFAULT_OPTION,
                                 JOptionPane.QUESTION_MESSAGE,
                                 null, config_options, config_options[0]);
    return thislines;
  }