Exemplo n.º 1
0
  // This handles the row, column, and cell selection buttons.
  public void actionPerformed(ActionEvent ie) {

    // See which button is selected.
    if (jrbRows.isSelected()) {
      // Enable row selection.
      jtabOrders.setColumnSelectionAllowed(false);
      jtabOrders.setRowSelectionAllowed(true);
    } else if (jrbColumns.isSelected()) {
      // Enable column selection.
      jtabOrders.setColumnSelectionAllowed(true);
      jtabOrders.setRowSelectionAllowed(false);
    } else {
      // Enable cell selection.
      jtabOrders.setCellSelectionEnabled(true);
    }
  }
Exemplo n.º 2
0
 private void jbInit() throws Exception {
   panel1.setLayout(borderLayout1);
   okButton.setText("OK");
   okButton.addActionListener(new MimeTypeEditor_okButton_actionAdapter(this));
   filtersTable.setRowSelectionAllowed(true);
   filtersTable.setPreferredSize(new Dimension(418, 200));
   filtersTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
   filtersTable.setCellSelectionEnabled(true);
   filtersTable.setColumnSelectionAllowed(false);
   filtersTable.setModel(m_model);
   addButton.setToolTipText(
       "Add a new " + mimeTypeEditorBuilder.getValueName() + " for a MIME type");
   addButton.setText("Add");
   addButton.addActionListener(new MimeTypeEditor_addButton_actionAdapter(this));
   cancelButton.setText("Cancel");
   cancelButton.addActionListener(new MimeTypeEditor_cancelButton_actionAdapter(this));
   deleteButton.setToolTipText("Delete the currently selected item.");
   deleteButton.setText("Delete");
   deleteButton.addActionListener(new MimeTypeEditor_deleteButton_actionAdapter(this));
   upButton.setText("Up");
   upButton.addActionListener(new MimeTypeEditor_upButton_actionAdapter(this));
   dnButton.setText("Down");
   dnButton.addActionListener(new MimeTypeEditor_dnButton_actionAdapter(this));
   panel1.setPreferredSize(new Dimension(418, 200));
   jScrollPane1.setMinimumSize(new Dimension(200, 80));
   jScrollPane1.setOpaque(true);
   buttonPanel.add(dnButton, null);
   buttonPanel.add(upButton, null);
   buttonPanel.add(addButton, null);
   buttonPanel.add(deleteButton, null);
   buttonPanel.add(okButton, null);
   buttonPanel.add(cancelButton, null);
   getContentPane().add(panel1);
   panel1.add(buttonPanel, BorderLayout.SOUTH);
   panel1.add(jScrollPane1, BorderLayout.CENTER);
   jScrollPane1.getViewport().add(filtersTable, null);
 }
  public NetworkTable(Properties display) {
    this.display = display;

    model =
        new GenericTableModel(
            new String[] {" ", "Address", "Label", "Description", "Pivot"}, "Address", 256);
    table = new ATable(model);
    TableRowSorter sorter = new TableRowSorter(model);
    sorter.toggleSortOrder(1);

    Comparator hostCompare =
        new Comparator() {
          public int compare(Object a, Object b) {
            long aa = Route.ipToLong(a + "");
            long bb = Route.ipToLong(b + "");

            if (aa > bb) {
              return 1;
            } else if (aa < bb) {
              return -1;
            } else {
              return 0;
            }
          }

          public boolean equals(Object a, Object b) {
            return (a + "").equals(b + "");
          }
        };

    sorter.setComparator(1, hostCompare);
    sorter.setComparator(4, hostCompare);

    table.setRowSorter(sorter);
    table.setColumnSelectionAllowed(false);

    table.getColumn("Address").setPreferredWidth(125);
    table.getColumn("Label").setPreferredWidth(125);
    table.getColumn("Pivot").setPreferredWidth(125);
    table.getColumn(" ").setPreferredWidth(32);
    table.getColumn(" ").setMaxWidth(32);
    table.getColumn("Description").setPreferredWidth(500);

    final TableCellRenderer parent = table.getDefaultRenderer(Object.class);
    table.setDefaultRenderer(
        Object.class,
        new TableCellRenderer() {
          public Component getTableCellRendererComponent(
              JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
            JLabel component =
                (JLabel)
                    parent.getTableCellRendererComponent(table, value, isSelected, false, row, col);

            if (col == 4 && Boolean.TRUE.equals(model.getValueAt(table, row, "Active"))) {
              component.setFont(component.getFont().deriveFont(Font.BOLD));
            } else if (col == 1 && !"".equals(model.getValueAt(table, row, "Description"))) {
              component.setFont(component.getFont().deriveFont(Font.BOLD));
            } else {
              component.setFont(component.getFont().deriveFont(Font.PLAIN));
            }

            String tip = model.getValueAt(table, row, "Tooltip") + "";

            if (tip.length() > 0) {
              component.setToolTipText(tip);
            }
            return component;
          }
        });

    table
        .getColumn(" ")
        .setCellRenderer(
            new TableCellRenderer() {
              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int col) {
                JLabel component =
                    (JLabel)
                        parent.getTableCellRendererComponent(
                            table, value, isSelected, false, row, col);
                component.setIcon(new ImageIcon((Image) model.getValueAt(table, row, "Image")));
                component.setText("");

                String tip = model.getValueAt(table, row, "Tooltip") + "";

                if (tip.length() > 0) {
                  component.setToolTipText(tip);
                }

                return component;
              }
            });

    table.addMouseListener(
        new MouseAdapter() {
          public void all(MouseEvent ev) {
            if (ev.isPopupTrigger()) {
              popup.showGraphPopup(getSelectedHosts(), ev);
              ev.consume();
            }
          }

          public void mouseClicked(MouseEvent ev) {
            all(ev);
          }

          public void mousePressed(MouseEvent ev) {
            all(ev);
          }

          public void mouseReleased(MouseEvent ev) {
            all(ev);
          }
        });

    setLayout(new BorderLayout());
    scroller = new JScrollPane(table);
    add(scroller, BorderLayout.CENTER);
  }
Exemplo n.º 4
0
  public static void main(String args[]) {
    // style that is necessary
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
    } catch (InstantiationException e) {
    } catch (IllegalAccessException e) {
    } catch (UnsupportedLookAndFeelException e) {
    }

    // Standard preparation for a frame
    fmain = new JFrame("Schedule Appointments"); // Create and name frame
    fmain.setSize(330, 375); // Set size to 400x400 pixels
    pane = fmain.getContentPane();
    pane.setLayout(null); // Apply null layout
    fmain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when X is clicked

    // controls and portions of Calendar
    lmonth = new JLabel("January");
    lyear = new JLabel("Change year:");
    cyear = new JComboBox();
    prev = new JButton("<<");
    next = new JButton(">>");
    canc = new JButton("Cancel");
    mcal =
        new DefaultTableModel() {
          public boolean isCellEditable(int rowIndex, int mColIndex) {
            return false;
          }
        };
    Cal = new JTable(mcal);
    scal = new JScrollPane(Cal);
    pcal = new JPanel(null);

    canc.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        });

    // action listeners for buttons and the like
    prev.addActionListener(new btnPrev_Action());
    next.addActionListener(new btnNext_Action());
    cyear.addActionListener(new cmbYear_Action());
    Cal.addMouseListener(new mouseCont());

    // Adding the elements to the pane
    pane.add(pcal);
    pcal.add(lmonth);
    pcal.add(cyear);
    pcal.add(prev);
    pcal.add(next);
    pcal.add(canc);
    pcal.add(scal);

    // Setting where the elements are on the pane
    pcal.setBounds(0, 0, 320, 335);
    lmonth.setBounds(160 - lmonth.getPreferredSize().width / 2, 25, 100, 25);
    canc.setBounds(10, 305, 80, 20);
    cyear.setBounds(215, 305, 100, 20);
    prev.setBounds(10, 25, 50, 25);
    next.setBounds(260, 25, 50, 25);
    scal.setBounds(10, 50, 300, 250);

    // Make frame visible
    fmain.setResizable(false);
    fmain.setVisible(true);

    // Inner workings for the day mechanism
    GregorianCalendar cal = new GregorianCalendar(); // Create calendar
    rday = cal.get(GregorianCalendar.DAY_OF_MONTH); // Get day
    rmonth = cal.get(GregorianCalendar.MONTH); // Get month
    ryear = cal.get(GregorianCalendar.YEAR); // Get year
    currentMonth = rmonth; // Match month and year
    currentYear = ryear;

    // Add days
    String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // All of the days
    for (int i = 0; i < 7; i++) {
      mcal.addColumn(days[i]);
    }

    Cal.getParent().setBackground(Cal.getBackground()); // Set background

    // No resize/reorder
    Cal.getTableHeader().setResizingAllowed(false);
    Cal.getTableHeader().setReorderingAllowed(false);

    // Single cell selection
    Cal.setColumnSelectionAllowed(true);
    Cal.setRowSelectionAllowed(true);
    Cal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    // Set row/column count
    Cal.setRowHeight(38);
    mcal.setColumnCount(7);
    mcal.setRowCount(6);

    // Placing the dates in the cells
    for (int i = ryear - 100; i <= ryear + 100; i++) {
      cyear.addItem(String.valueOf(i));
    }

    // Refresh calendar
    refreshCalendar(rmonth, ryear); // Refresh calendar
  }