예제 #1
2
 /**
  * This function is used to re-run the analyser, and re-create the rows corresponding the its
  * results.
  */
 private void refreshReviewTable() {
   reviewPanel.removeAll();
   rows.clear();
   GridBagLayout gbl = new GridBagLayout();
   reviewPanel.setLayout(gbl);
   GridBagConstraints gbc = new GridBagConstraints();
   gbc.fill = GridBagConstraints.HORIZONTAL;
   gbc.gridy = 0;
   try {
     Map<String, Long> sums =
         analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate());
     for (Entry<String, Long> entry : sums.entrySet()) {
       String project = entry.getKey();
       double hours = 1.0 * entry.getValue() / (1000 * 3600);
       addRow(gbl, gbc, project, hours);
     }
     for (String project : main.getProjectsTree().getTopLevelProjects())
       if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0);
     gbc.insets = new Insets(10, 0, 0, 0);
     addLeftLabel(gbl, gbc, "TOTAL");
     gbc.gridx = 1;
     gbc.weightx = 1;
     totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3));
     gbl.setConstraints(totalLabel, gbc);
     reviewPanel.add(totalLabel);
     gbc.weightx = 0;
     addRightLabel(gbl, gbc);
   } catch (IOException e) {
     e.printStackTrace();
   }
   recomputeTotal();
   pack();
 }
  public Transferable createTransferable(JComponent comp) {

    // Clear

    image = null;

    Icon icon = null;

    if (comp instanceof JLabel) {

      JLabel label = (JLabel) comp;

      icon = label.getIcon();

    } else if (comp instanceof AbstractButton) {

      AbstractButton button = (AbstractButton) comp;

      icon = button.getIcon();
    }

    if (icon instanceof ImageIcon) {

      image = ((ImageIcon) icon).getImage();

      return this;
    }

    return null;
  }
예제 #3
0
 void addTextField(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextField field = new JTextField();
   field.setText(sketch.configFile.get(key));
   field.setMaximumSize(new Dimension(Integer.MAX_VALUE, field.getPreferredSize().height));
   fields.put(key, field);
   panel.add(field);
 }
예제 #4
0
 void addTextArea(JPanel panel, String key, String label) {
   JLabel lab = new JLabel(label);
   lab.setAlignmentX(LEFT_ALIGNMENT);
   panel.add(lab);
   JTextArea field = new JTextArea();
   field.setText(sketch.configFile.get(key));
   field.setLineWrap(true);
   field.setWrapStyleWord(true);
   fields.put(key, field);
   JScrollPane scroll = new JScrollPane(field);
   scroll.setAlignmentX(0.0f);
   panel.add(scroll);
 }
 private JPanel getNumericLevels(EnumLevelList ll) {
   JPanel levelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
   levelPanel.setBackground(Color.white);
   String labelString =
       "[ "
           + ll.getMinAsString()
           + " to "
           + ll.getMaxAsString()
           + " ] Increment by "
           + ll.getIncrementAsString();
   JLabel levelLabel = new JLabel(labelString);
   levelLabel.setForeground(ARMY_GREEN);
   add(levelLabel);
   return levelPanel;
 }
 private JPanel getStringLevels(EnumLevelList ll) {
   JPanel levelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
   levelPanel.setBackground(Color.white);
   levelPanel.setForeground(Color.black);
   Iterator i = ll.getLevelIterator();
   JLabel levelLabel = null;
   EnumLevel level = null;
   while (i != null && i.hasNext()) {
     level = (EnumLevel) i.next();
     levelLabel = new JLabel(level.toString() + "  | ");
     levelLabel.setForeground(ARMY_GREEN);
     levelPanel.add(levelLabel);
     // levelPanel.add(new JSeparator(SwingConstants.HORIZONTAL));
   }
   return levelPanel;
 }
예제 #7
0
 /**
  * This function re-computes the total number of hours for the selected period. It is ran every
  * time the user edits a text field specifying the number of hours for a particular top-level
  * project. Percentage labels are also updated.
  */
 private void recomputeTotal() {
   double total = 0;
   for (Row row : rows.values()) {
     try {
       row.hours = Double.parseDouble(row.hoursTF.getText());
       total += row.hours;
       row.hoursTF.setForeground(normalColour);
     } catch (NumberFormatException e) {
       row.hoursTF.setForeground(errorColour);
       totalLabel.setText("ERROR");
       totalLabel.setForeground(errorColour);
       return;
     }
   }
   totalLabel.setText(decimalFormat.format(total));
   totalLabel.setForeground(normalColour);
   for (Row row : rows.values()) {
     String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total);
     row.percentL.setText("(" + percentS + "%)");
   }
   pack();
 }
  public boolean importData(JComponent comp, Transferable t) {

    ImageIcon icon = null;

    try {

      if (t.isDataFlavorSupported(flavors[0])) {

        image = (Image) t.getTransferData(flavors[0]);

        icon = new ImageIcon(image);
      }

      if (comp instanceof JLabel) {

        JLabel label = (JLabel) comp;

        label.setIcon(icon);

        return true;

      } else if (comp instanceof AbstractButton) {

        AbstractButton button = (AbstractButton) comp;

        button.setIcon(icon);

        return true;
      }

    } catch (UnsupportedFlavorException ignored) {
    } catch (IOException ignored) {
    }

    return false;
  }
예제 #9
0
  private MainPanel() {
    super();

    JLabel label = new JLabel(new DragHereIcon());
    label.setText("<html>Drag <b>Files</b> Here");
    label.setVerticalTextPosition(SwingConstants.BOTTOM);
    label.setHorizontalTextPosition(SwingConstants.CENTER);
    label.setForeground(Color.GRAY);
    label.setFont(new Font(Font.SERIF, Font.PLAIN, 24));

    label.setDropTarget(
        new DropTarget(label, DnDConstants.ACTION_COPY, new FileDropTargetAdapter(), true));
    // Test: label.setTransferHandler(new FileTransferHandler());

    add(label);
    setPreferredSize(new Dimension(320, 240));
  }
예제 #10
0
  public static void main(String args[]) {

    JFrame frame = new JFrame("Drag Image");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();

    final JLabel label = new JLabel();
    //    Icon icon = new ImageIcon("/home/j2ee/Desktop/war.103.gif");
    //    label.setIcon(icon);
    label.setTransferHandler(new ImageSelection());

    MouseListener mouseListener =
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            JComponent comp = (JComponent) e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, e, TransferHandler.COPY);
          }
        };
    label.addMouseListener(mouseListener);

    JScrollPane pane = new JScrollPane(label);
    contentPane.add(pane, BorderLayout.CENTER);

    JButton copy = new JButton("Copy");
    copy.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            // fire TransferHandler's built-in copy
            // action with a new actionEvent having
            // "label" as the source
            Action copyAction = TransferHandler.getCopyAction();
            copyAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) copyAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JButton clear = new JButton("Clear");
    clear.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            label.setIcon(null);
          }
        });

    JButton paste = new JButton("Paste");
    paste.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            // use TransferHandler's built-in
            // paste action
            Action pasteAction = TransferHandler.getPasteAction();
            pasteAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) pasteAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JPanel p = new JPanel();
    p.add(copy);
    p.add(clear);
    p.add(paste);
    contentPane.add(p, BorderLayout.SOUTH);

    frame.setSize(300, 300);
    frame.show();
  }
예제 #11
0
 /**
  * A helper function that obtains the total number of hours for the selected period.
  *
  * @return Total number of hours.
  * @throws InsufficientDataException Thrown if the total is zero.
  */
 private double checkTotal() throws InsufficientDataException {
   double total = Double.parseDouble(totalLabel.getText());
   if (total == 0) throw new InsufficientDataException("Cannot submit data with no logged hours.");
   return total;
 }