コード例 #1
0
 public static void makeFace(JTable table) {
   try {
     DefaultTableCellRenderer tcr =
         new DefaultTableCellRenderer() {
           public Component getTableCellRendererComponent(
               JTable table,
               Object value,
               boolean isSelected,
               boolean hasFocus,
               int row,
               int column) {
             if (row % 2 == 0) setBackground(Color.white); // 设置奇数行底色
             else if (row % 2 == 1) setBackground(new Color(206, 231, 255)); // 设置偶数行底色
             return super.getTableCellRendererComponent(
                 table, value, isSelected, hasFocus, row, column);
           }
         };
     for (int i = 0; i < table.getColumnCount(); i++) {
       table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
コード例 #2
0
  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);
  }
  @Override
  public JComponent createComponent() {
    myPanel =
        new JPanel(new GridBagLayout()) {
          @Override
          public Dimension getPreferredSize() {
            return new Dimension(-1, 400);
          }
        };

    myExtPanel =
        new AddEditRemovePanel<NameLocationPair>(
            new ExtUrlsTableModel(),
            myPairs,
            XmlBundle.message("label.edit.external.resource.configure.external.resources")) {
          @Override
          protected NameLocationPair addItem() {
            return addExtLocation();
          }

          @Override
          protected boolean removeItem(NameLocationPair o) {
            setModified(true);
            return true;
          }

          @Override
          protected NameLocationPair editItem(NameLocationPair o) {
            return editExtLocation(o);
          }
        };
    myExtPanel.getTable().setShowColumns(true);

    myExtPanel.setRenderer(1, new PathRenderer());

    JTable table = myExtPanel.getTable();
    if (myProject != null) {
      TableColumn column = table.getColumn(table.getColumnName(2));
      column.setMaxWidth(50);
      column.setCellEditor(JBTable.createBooleanEditor());
    }

    table
        .getModel()
        .addTableModelListener(
            new TableModelListener() {
              @Override
              public void tableChanged(TableModelEvent e) {
                setModified(true);
              }
            });
    myIgnorePanel =
        new AddEditRemovePanel<String>(
            new IgnoredUrlsModel(),
            myIgnoredUrls,
            XmlBundle.message("label.edit.external.resource.configure.ignored.resources")) {
          @Override
          protected String addItem() {
            return addIgnoreLocation();
          }

          @Override
          protected boolean removeItem(String o) {
            setModified(true);
            return true;
          }

          @Override
          protected String editItem(String o) {
            return editIgnoreLocation(o);
          }
        };

    myPanel.add(
        myExtPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.NORTH,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myPanel.add(
        myIgnorePanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.NORTH,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    myExtPanel.setData(myPairs);
    myIgnorePanel.setData(myIgnoredUrls);

    myExtPanel.getEmptyText().setText(XmlBundle.message("no.external.resources"));
    myIgnorePanel.getEmptyText().setText(XmlBundle.message("no.ignored.resources"));

    return myPanel;
  }
コード例 #4
0
  public JunctionLinkDataFrame(final JunctionLink jl) {
    super(
        jl.getCurrName() + " properties",
        false, // resizable
        false, // closable
        false, // maximizable
        true); // iconifiable
    // PSRender.onHold();
    super.setBackground(back_color);
    super.addInternalFrameListener(
        new InternalFrameAdapter() {
          public void internalFrameActivated(InternalFrameEvent e) {
            reload();
            SelectedObject.setSelectedObject(jl);
          }
        });
    PSRender.moveToTop(jl.getBound(), 0.5);
    ml = jl;
    setLocation(50, 50);
    dataModelMain = new HeadTable(jl);
    tableMain = new JTable(dataModelMain);
    tableMain.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    tableMain.setPreferredScrollableViewportSize(new Dimension(500, 20));
    //        tableMain.setBackground(back_color);

    // code
    TableColumn column_code = tableMain.getColumn("Code");
    DefaultTableCellRenderer rendererCode = new DefaultTableCellRenderer();
    rendererCode.setToolTipText("Enter new code for this path");
    column_code.setCellRenderer(rendererCode);
    column_code.setCellEditor(new TextFieldEditor());
    // name
    TableColumn column_name = tableMain.getColumn("Name");
    LanguageButtonRender render_name = new LanguageButtonRender();
    render_name.setToolTipText("Path name. Press for change name");
    column_name.setCellRenderer(render_name);
    LanguageButtonEditor editor_name = new LanguageButtonEditor(new JCheckBox());
    column_name.setCellEditor(editor_name);
    // junction 1
    TableColumn column_junc_1 = tableMain.getColumn("Junction 1");
    MLButtonRenderer rendererJunc_1 = new MLButtonRenderer();
    rendererJunc_1.setToolTipText("Code of first Junction, click for open properties");
    column_junc_1.setCellRenderer(rendererJunc_1);
    MLButtonEditor editorJunc = new MLButtonEditor(new JCheckBox());
    column_junc_1.setCellEditor(editorJunc);
    // junction 2
    TableColumn column_junc_2 = tableMain.getColumn("Junction 2");
    MLButtonRenderer rendererJunc_2 = new MLButtonRenderer();
    rendererJunc_2.setToolTipText("Code of second Junction, click for open properties");
    column_junc_2.setCellRenderer(rendererJunc_2);
    column_junc_2.setCellEditor(editorJunc);
    // type
    JComboBox comboBoxType = new JComboBox();
    String roadNames[] = jl.getTypeNames();
    for (int i = 0, len = roadNames.length; i < len; i++) {
      comboBoxType.addItem(roadNames[i]);
    }
    TableColumn column_type = tableMain.getColumn("Type");
    DefaultTableCellRenderer rendererType = new DefaultTableCellRenderer();
    rendererType.setToolTipText("To change road type click for combo box");
    column_type.setCellRenderer(rendererType);
    column_type.setCellEditor(new DefaultCellEditor(comboBoxType));
    // legth
    TableColumn column_length = tableMain.getColumn("Length");
    DefaultTableCellRenderer rendererLen = new DefaultTableCellRenderer();
    rendererLen.setToolTipText("The path length in meters");
    column_length.setCellRenderer(rendererLen);

    scrollpaneMain = new JScrollPane(tableMain);
    scrollpaneMain.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollpaneMain.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    scrollpaneMain.setPreferredSize(new Dimension(500, 50));

    Container contentPane = super.getContentPane();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    contentPane.setLayout(gridbag);

    c.ipady = 0; // make this component tall
    c.weightx = 0.5;
    c.gridwidth = 4;
    c.gridx = 0;
    c.gridy = 0;
    gridbag.setConstraints(scrollpaneMain, c);
    //        scrollpaneMain.setBackground(back_color);
    //        scrollpaneMain.setForeground(back_color);
    contentPane.add(scrollpaneMain);

    TableModel dataModelPoints = new PointTableModel(jl);
    tablePoints = new JTable(dataModelPoints);
    tablePoints.setPreferredScrollableViewportSize(
        new Dimension(200, dataModelPoints.getRowCount() * tablePoints.getRowHeight()));
    ListModel lm =
        new AbstractListModel() {
          public int getSize() {
            return 1000;
          }

          public Object getElementAt(int index) {
            return "" + index;
          }
        };
    JList rowHeader = new JList(lm);
    rowHeader.setFixedCellWidth(20);

    rowHeader.setFixedCellHeight(tablePoints.getRowHeight());
    // + tablePoints.getRowMargin());

    rowHeader.setCellRenderer(new RowHeaderRenderer(tablePoints));

    scrollPanePoints = new JScrollPane(tablePoints);
    scrollPanePoints.setWheelScrollingEnabled(true);
    scrollPanePoints.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPanePoints.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    int mh;
    if (dataModelPoints.getRowCount() * tablePoints.getRowHeight() > 100) {
      mh = 100;
    } else {
      mh = dataModelPoints.getRowCount() * tablePoints.getRowHeight();
    }
    scrollPanePoints.setPreferredSize(new Dimension(200, mh));
    scrollPanePoints.setRowHeaderView(rowHeader);

    c.ipadx = 200;
    c.weightx = 0.5;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 1;
    gridbag.setConstraints(scrollPanePoints, c);
    //        scrollPanePoints.setBackground(back_color);
    contentPane.add(scrollPanePoints);

    button_ok = new JButton("Ok");
    button_ok.addActionListener(this);
    JPanel buttonPane = new JPanel(null);
    buttonPane.setPreferredSize(new Dimension(500, 100));
    button_ok.setBounds(205, 40, 90, 40);
    buttonPane.add(button_ok);
    c.ipady = 10; // make this component tall
    c.ipadx = 10;
    c.weightx = 0.5;
    c.gridwidth = 4;
    c.gridx = 2;
    c.gridy = 2;
    gridbag.setConstraints(buttonPane, c);
    buttonPane.setBackground(back_color);
    contentPane.add(buttonPane);

    super.pack();
    super.setVisible(true);

    // MapApplication.getDesktop().setSelectedFrame(this);

  }