public TableCellRenderFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new PlanetTableModel();
    JTable table = new JTable(model);
    table.setRowSelectionAllowed(false);

    // set up renderers and editors

    table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
    table.setDefaultEditor(Color.class, new ColorTableCellEditor());

    JComboBox<Integer> moonCombo = new JComboBox<>();
    for (int i = 0; i <= 20; i++) moonCombo.addItem(i);

    TableColumnModel columnModel = table.getColumnModel();
    TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN);
    moonColumn.setCellEditor(new DefaultCellEditor(moonCombo));
    moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class));
    moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif")));

    // show table

    table.setRowHeight(100);
    add(new JScrollPane(table), BorderLayout.CENTER);
  }
示例#2
0
 public void install() {
   classTable.setModel(this);
   classTable.setDefaultRenderer(Object.class, renderer);
   classTable.setDefaultRenderer(
       Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER));
   classTable.setDefaultEditor(Object.class, editor);
   classComboBox.addItemListener(this);
   classComboBox.addPropertyChangeListener("model", this);
 }
示例#3
0
  /**
   * Add all the components for display the list of plots and which are showing the current spectra.
   */
  protected void initUI() {
    setBorder(BorderFactory.createTitledBorder("Views of current spectra:"));
    setLayout(new BorderLayout());
    setToolTipText("Select to add the current spectra to a plot, " + "deselect to remove them.");

    //  Set up the table to use a model based on the global lists
    //  of plots and spectra and to track the current spectrum
    //  when selected in list.
    table.setModel(tableModel);

    //  Hack the size of this so that it doesn't get too big for
    //  the values we know it's going to display, cell width
    //  control in JTable sucks (or I don't understand it!).
    table.setPreferredScrollableViewportSize(new Dimension(250, 0));

    //  Set the headers!
    TableColumnModel columns = table.getColumnModel();
    TableColumn column;
    column = columns.getColumn(table.convertColumnIndexToView(0));
    column.setHeaderValue("View");
    column = columns.getColumn(table.convertColumnIndexToView(1));
    column.setHeaderValue("Displayed");

    //  The table can have many rows selected.
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    //  Double click on a row raises the associated plot.
    table.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
              raiseCurrentPlot();
            }
          }
        });

    //  Use a FuzzyBooleanCellRenderer for FuzzyBoolean objects in
    //  this table. This is tristate for dealing with partial
    //  spectra/plot relations.
    table.setDefaultRenderer(FuzzyBoolean.class, new FuzzyBooleanCellRenderer());
    table.setDefaultEditor(FuzzyBoolean.class, new FuzzyBooleanCellEditor());

    //  Add components.
    scroller.getViewport().add(table, null);
    add(scroller, BorderLayout.CENTER);

    //  Set up the listSelectionListener so that we can update
    //  when the selected spectra change.
    list.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            update(e);
          }
        });
  }
示例#4
0
 /**
  * Service method to setup a column so that it will hold a button for it's values
  *
  * @param table {@link JTable} to use
  * @param column Column to setup
  * @param sample Typical button, used for size
  */
 protected void setColumnToHoldButton(JTable table, int column, JButton sample) {
   // install a button renderer & editor
   ButtonRenderer buttonRenderer = new ButtonRenderer();
   table.setDefaultRenderer(JButton.class, buttonRenderer);
   TableCellEditor buttonEditor = new ButtonEditor(new JButton());
   table.setDefaultEditor(JButton.class, buttonEditor);
   // ensure the table rows, columns have enough room for buttons
   table.setRowHeight(sample.getPreferredSize().height);
   table
       .getColumnModel()
       .getColumn(column)
       .setPreferredWidth((sample.getPreferredSize().width) + 4);
 }
示例#5
0
  /** Create the dialog. */
  public USDialog(ActionListener listener) {
    setIconImages(Simulator.makeIcons());
    setBounds(100, 100, 450, 300);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
      JComboBox typeBox = new JComboBox(new DefaultComboBoxModel(Relationship.values()));
      typeEditor = new DefaultCellEditor(typeBox);

      table =
          new JTable(new USValuesTableModel()) {
            // Overridden to return a combobox for duration type
            @Override
            public TableCellEditor getCellEditor(int row, int column) {
              int modelColumn = convertColumnIndexToModel(column);

              if (modelColumn == 0) return typeEditor;
              else return super.getCellEditor(row, column);
            }
          };
      // Make window close on second enter press
      InputMap map = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
      map.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
      table.getColumnModel().getColumn(1).setPreferredWidth(10);
      table.getColumnModel().getColumn(1).setMaxWidth(10);
      table.doLayout();
      // Make single click start editing instead of needing double
      DefaultCellEditor singleClickEditor = new DefaultCellEditor(new JTextField());
      singleClickEditor.setClickCountToStart(1);
      table.setDefaultEditor(Object.class, singleClickEditor);
      table.setCellSelectionEnabled(false);

      JScrollPane scrollPane = new JScrollPane(table);
      contentPanel.add(scrollPane);
    }
    {
      JPanel buttonPane = new JPanel();
      buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
      getContentPane().add(buttonPane, BorderLayout.SOUTH);
      {
        JButton okButton = new JButton("OK");
        okButton.setActionCommand("OK");
        okButton.addActionListener(listener);
        buttonPane.add(okButton);
        getRootPane().setDefaultButton(okButton);
      }
    }
  }
示例#6
0
 private void setTableProps() {
   setColumnWidth(0, 170, 170, 170);
   setColumnWidth(1, 220, -1, 220);
   setColumnWidth(2, 1, 170, 1);
   setColumnWidth(3, 220, -1, 220);
   JTextField field = new JTextField();
   field.setFont(new Font("DialogInput", Font.PLAIN, 12));
   TableCellEditor editor = new DefaultCellEditor(field);
   try {
     compareTable.setDefaultEditor(Class.forName("java.lang.Object"), editor);
     compareTable.setDefaultRenderer(Class.forName("java.lang.Object"), renderer);
   } catch (ClassNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#7
0
  @Override
  protected final JPanel build() {
    JPanel p = new JPanel(new GridBagLayout());
    p.add(new JLabel(tr("Key: {0}", entry.getKey())), GBC.eol().insets(0, 0, 5, 0));
    ListSettingTableModel listModel = new ListSettingTableModel();
    JTable table = new JTable(listModel);
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    table.setTableHeader(null);

    DefaultCellEditor editor = new DefaultCellEditor(new JosmTextField());
    editor.setClickCountToStart(1);
    table.setDefaultEditor(table.getColumnClass(0), editor);

    JScrollPane pane = new JScrollPane(table);
    p.add(pane, GBC.eol().insets(5, 10, 0, 0).fill());
    return p;
  }
示例#8
0
  /** Create a new component. */
  public ParameterTable() {
    super(new ParameterTableModel());
    final JTable table = this.getTable();

    this.model = (ParameterTableModel) this.getModel();

    DefaultCellEditor textEditor = new DefaultCellEditor(new JTextField());
    textEditor.setClickCountToStart(1);
    table.setDefaultEditor(String.class, textEditor);

    TableColumn nameColumn = table.getColumnModel().getColumn(this.model.getIndex(Column.NAME));
    nameColumn.setCellEditor(textEditor);
    TableColumn typeColumn = table.getColumnModel().getColumn(this.model.getIndex(Column.TYPE));
    typeColumn.setCellEditor(new DefaultCellEditor(new JComboBox<Type>(Type.values())));

    // commit editor on focus lost
    this.getTable().putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
  }
示例#9
0
  public void initTable(SchedulesTableFrame frame, JTable table) {
    this.table = table;
    // Install the button handlers
    TableColumnModel tcm = table.getColumnModel();
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton());
    tcm.getColumn(EDIT_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(EDIT_COLUMN).setCellEditor(buttonEditor);
    tcm.getColumn(DELETE_COLUMN).setCellRenderer(buttonRenderer);
    tcm.getColumn(DELETE_COLUMN).setCellEditor(buttonEditor);
    table.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    table.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());

    setPreferredWidths(frame, table);

    // set row height
    table.setRowHeight(new JComboBox<>().getPreferredSize().height);
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  }
示例#10
0
  /** Create a new, empty property sheet. */
  public PropertySheet() {
    super(new EnhancedTable());
    this.getPreferredSize();
    props = new ForClassPropertyList();

    // Add bean change event listener
    props.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            // XXX Should I fire a 'stop editing' event here?
            refresh();
          }
        });

    // Add table
    JTable table = getTable();
    MyTableModel tableModel = new MyTableModel();
    table.setModel(tableModel);
    table.setDefaultRenderer(InstancePropertyDescriptor.class, new MyCellRenderer());
    table.setDefaultEditor(InstancePropertyDescriptor.class, new MyCellEditor());
  }
示例#11
0
  private void loadView() {
    // main views
    mTableModel = new SpreadsheetTableModel();

    mTableView = new JTable(mTableModel);
    mTableView.setRowSelectionAllowed(false);
    mTableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    mTableView.setFillsViewportHeight(true);
    mTableView.setDefaultRenderer(String.class, new ColorCellRenderer(TABLE_CELL_COLOR));
    mTableView.setDefaultEditor(
        String.class, new SpreadsheetCellEditor(mTableView.getDefaultEditor(String.class)));
    mTableView.getSelectionModel().addListSelectionListener(new SpreadsheetSelectionListener());
    mTableView
        .getColumnModel()
        .getSelectionModel()
        .addListSelectionListener(new SpreadsheetSelectionListener());

    JTable rowHeaderTable = new JTable(new RowHeaderTableModel());
    rowHeaderTable.setCellSelectionEnabled(false);
    rowHeaderTable.setPreferredScrollableViewportSize(new Dimension(50, Integer.MAX_VALUE));
    rowHeaderTable.setDefaultRenderer(Object.class, new ColorCellRenderer(ROW_HEADER_COLOR));

    mFormulaTextField = new BindableTextField();
    mFormulaTextField.setEditable(false);
    mFormulaTextField.setFocusable(false);

    JScrollPane scrollView = new JScrollPane(mTableView);
    scrollView.setRowHeaderView(rowHeaderTable);

    add(mFormulaTextField, BorderLayout.BEFORE_FIRST_LINE);
    add(scrollView, BorderLayout.CENTER);

    // helpers

    mFileChooser = new SingleExtensionFileChooser();
    String extension = SpreadsheetPersistenceManager.SPREADSHEET_FILE_EXTENSION;
    mFileChooser.setFileExtension(extension, "Spreadsheets file (." + extension + ")");
  }
示例#12
0
    @Override
    public void actionPerformed(ActionEvent e) {
      int[] selectedRows = equipmentTable.getSelectedRows();
      MapToList<EquipmentFacade, EquipNode> equipMap =
          new HashMapToList<EquipmentFacade, EquipNode>();
      EquipmentSetFacade equipSet = character.getEquipmentSetRef().getReference();
      List<EquipmentFacade> equipment = new ArrayList<EquipmentFacade>();

      for (int i = 0; i < selectedRows.length; i++) {
        EquipmentFacade equipmentFacade = selectedModel.getValue(selectedRows[i]);
        for (EquipNode path : equipSet.getNodes()) {
          if (equipSet.canEquip(path, equipmentFacade)) {
            equipMap.addToListFor(equipmentFacade, path);
          }
        }
        if (equipMap.containsListFor(equipmentFacade)) {
          equipment.add(equipmentFacade);
        }
      }
      if (!equipment.isEmpty()) {
        Object[][] data = new Object[equipment.size()][3];
        for (int i = 0; i < equipment.size(); i++) {
          EquipmentFacade equipmentFacade = equipment.get(i);
          data[i][0] = equipmentFacade;
          data[i][1] = 1;
          data[i][2] = getInitialNode(equipMap, equipSet, equipmentFacade);
        }
        Object[] columns =
            new Object[] {
              LanguageBundle.getString("in_equipItem"), // $NON-NLS-1$
              LanguageBundle.getString("in_equipQuantityAbbrev"), // $NON-NLS-1$
              LanguageBundle.getString("in_equipContainer") // $NON-NLS-1$
            };
        DefaultTableModel tableModel =
            new DefaultTableModel(data, columns) {

              @Override
              public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex == 1) {
                  return Integer.class;
                }
                return Object.class;
              }

              @Override
              public boolean isCellEditable(int row, int column) {
                return column != 0;
              }
            };
        JTable table = new JTable(tableModel);
        table.setFocusable(false);
        table.setCellSelectionEnabled(false);
        table.setDefaultEditor(Object.class, new ComboEditor(equipMap));
        table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
        table.setDefaultEditor(Integer.class, new SpinnerEditor(unequippedList));
        table.setRowHeight(22);
        table.getColumnModel().getColumn(0).setPreferredWidth(140);
        table.getColumnModel().getColumn(1).setPreferredWidth(50);
        table.getColumnModel().getColumn(2).setPreferredWidth(120);
        table.setPreferredScrollableViewportSize(table.getPreferredSize());
        JTableHeader header = table.getTableHeader();
        header.setReorderingAllowed(false);
        JScrollPane pane = new JScrollPane(table);
        JPanel panel = new JPanel(new BorderLayout());
        JLabel help = new JLabel(LanguageBundle.getString("in_equipSelectQtyLoc")); // $NON-NLS-1$
        panel.add(help, BorderLayout.NORTH);
        panel.add(pane, BorderLayout.CENTER);
        int res =
            JOptionPane.showConfirmDialog(
                JOptionPane.getFrameForComponent(equipmentTable),
                panel,
                LanguageBundle.getString("in_equipEquipSel"), // $NON-NLS-1$
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);

        if (res == JOptionPane.OK_OPTION) {
          for (int i = 0; i < equipment.size(); i++) {
            EquipNode path = (EquipNode) tableModel.getValueAt(i, 2);
            equipSet.addEquipment(path, equipment.get(i), (Integer) tableModel.getValueAt(i, 1));
          }
        }
      }
    }
示例#13
0
  /** Constructor method */
  public PollTablePane(jmri.ModifiedFlag flag) {
    super();

    this.modifiedFlag = flag;

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    pollModel = new PollDataModel(modifiedFlag);

    JTable pollTable = jmri.util.JTableUtil.sortableDataModel(pollModel);

    // install a button renderer & editor
    ButtonRenderer buttonRenderer = new ButtonRenderer();
    pollTable.setDefaultRenderer(JButton.class, buttonRenderer);
    TableCellEditor buttonEditor = new ButtonEditor(new JButton());
    pollTable.setDefaultEditor(JButton.class, buttonEditor);
    pollTable.setDefaultRenderer(JComboBox.class, new jmri.jmrit.symbolicprog.ValueRenderer());
    pollTable.setDefaultEditor(JComboBox.class, new jmri.jmrit.symbolicprog.ValueEditor());

    try {
      jmri.util.com.sun.TableSorter tmodel = ((jmri.util.com.sun.TableSorter) pollTable.getModel());
      tmodel.setSortingStatus(PollDataModel.ADDRCOL, jmri.util.com.sun.TableSorter.ASCENDING);
    } catch (ClassCastException e3) {
    } // if not a sortable table model
    pollTable.setRowSelectionAllowed(false);
    pollTable.setPreferredScrollableViewportSize(new java.awt.Dimension(580, 80));

    JScrollPane scrollPane = new JScrollPane(pollTable);
    add(scrollPane);

    // status info on bottom
    JPanel p =
        new JPanel() {
          /** */
          private static final long serialVersionUID = 2303477665465877882L;

          public Dimension getMaximumSize() {
            int height = getPreferredSize().height;
            int width = super.getMaximumSize().width;
            return new Dimension(width, height);
          }
        };
    p.setLayout(new FlowLayout());

    polling = new JCheckBox(rb.getString("LabelPoll"));
    polling.setSelected(Engine.instance().getPolling());
    p.add(polling);
    polling.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkPolling();
          }
        });

    JPanel m = new JPanel();
    m.setLayout(new BoxLayout(m, BoxLayout.Y_AXIS));
    ButtonGroup g = new ButtonGroup();
    bscMode = new JRadioButton(rb.getString("LabelBscMode"));
    bscMode.setSelected(Engine.instance().getBscPollMode());
    m.add(bscMode);
    g.add(bscMode);
    bscMode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkMode();
          }
        });
    directMode = new JRadioButton(rb.getString("LabelDirectMode"));
    directMode.setSelected(Engine.instance().getDirectPollMode());
    m.add(directMode);
    g.add(directMode);
    directMode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkMode();
          }
        });
    throttleMode = new JRadioButton(rb.getString("LabelThrottleMode"));
    throttleMode.setSelected(Engine.instance().getThrottlePollMode());
    m.add(throttleMode);
    g.add(throttleMode);
    throttleMode.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            checkMode();
          }
        });
    p.add(m);

    p.add(Box.createHorizontalGlue());
    p.add(new JLabel(rb.getString("LabelDelay")));
    delay = new JTextField(5);
    delay.setText("" + Engine.instance().getPollingInterval());
    p.add(delay);
    delay.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            updateInterval();
          }
        });

    JButton b = new JButton(rb.getString("LabelSetDefault"));
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            modifiedFlag.setModifiedFlag(true);
            setDefaults();
          }
        });
    p.add(b);

    add(p);
  }
示例#14
0
  /**
   * Constructor initialises the table and a popup tool, as well as initialising the required GUI
   * elements. It adds action listeners for the three main buttons, which include basic user input
   * validation checking.
   */
  public TableAttributeEditor(JFrame MyOwner) {
    // As usual, it is insanely hard to get the swing components to display
    // and work properly.  If JTable is not displayed in a scroll pane no headers are
    // displayed, and you have to do it manually.  (If you *do* display it
    // in a scrollbar, in this instance, it screws up sizing)
    // The broken header mis-feature is only mentioned in the tutorial,
    // not in the api doco - go figure.

    super();

    owner = MyOwner;

    // final JPanel mainPanel = (JPanel)this;

    tableData = new AttributeTableModel();

    attributeTable = new JTable(tableData);
    // attributeTable.setRowHeight(20);	// This may be needed, depends on how fussy people get about
    // the bottom of letters like 'y' getting cut off when the cell is selected - bug 3013.

    popupTableTool = new SmartPopupTableTool(attributeTable, tableData, (JXplorerBrowser) owner);

    // Set the renderer for the attribute type...
    final AttributeTypeCellRenderer typeRenderer = new AttributeTypeCellRenderer();

    attributeTable.setDefaultRenderer(AttributeNameAndType.class, typeRenderer);

    // Set the renderer for the attribute value...
    final AttributeValueCellRenderer valueRenderer = new AttributeValueCellRenderer();

    attributeTable.setDefaultRenderer(AttributeValue.class, valueRenderer);

    // Set the editor for the attribute value...
    myEditor = new AttributeValueCellEditor(owner);

    attributeTable.setDefaultEditor(AttributeValue.class, myEditor);

    attributeTable.getTableHeader().setReorderingAllowed(false);

    currentDN = null;

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttonPanel.add(
        submit =
            new CBButton(
                CBIntText.get("Submit"), CBIntText.get("Submit your changes to the Directory.")));
    buttonPanel.add(
        reset =
            new CBButton(
                CBIntText.get("Reset"),
                CBIntText.get("Reset this entry i.e. cancels any changes.")));
    buttonPanel.add(
        changeClass =
            new CBButton(
                CBIntText.get("Change Classes"),
                CBIntText.get("Change the Object Class of this entry.")));
    buttonPanel.add(
        opAttrs =
            new CBButton(
                CBIntText.get("Properties"),
                CBIntText.get("View the Operational Attributes of this entry.")));

    // I don't really understand why we have to do this...
    // but without it these buttons over ride the default
    // button (Search Bar's search button), if they have
    // been clicked and the user hits the enter key?
    opAttrs.setDefaultCapable(false);
    submit.setDefaultCapable(false);
    reset.setDefaultCapable(false);
    changeClass.setDefaultCapable(false);

    setLayout(new BorderLayout(10, 10));

    tableScroller = new JScrollPane();
    attributeTable.setBackground(Color.white);
    tableScroller.setPreferredSize(new Dimension(300, 285));
    tableScroller.setViewportView(attributeTable);
    add(tableScroller, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);

    if ("true".equals(JXConfig.getProperty("lock.read.only")))
      title = CBIntText.get("Table Viewer");
    else title = CBIntText.get("Table Editor");

    setVisible(true);

    // triggers adding operational attributes of the current entry.
    opAttrs.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            displayOperationalAttributes();
          }
        });

    reset.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            myEditor.stopCellEditing();
            // tableData.reset();
            displayEntry(originalEntry, dataSource, false);
          }
        });

    submit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            doSubmit();
          }
        });

    // This allows the user to change the objectclass attribute.
    // This is pretty tricky, because it changes what attributes are available.
    changeClass.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            changeClass();
          }
        });

    attributeTable.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            if (!doPopupStuff(e)) super.mousePressed(e);
          }

          public void mouseReleased(MouseEvent e) {
            if (!doPopupStuff(e)) super.mouseReleased(e);
          }

          // TODO need to have a way to call this from a keystroke...
          public boolean doPopupStuff(MouseEvent e) {
            if (e.isPopupTrigger() == false) return false;

            int row = attributeTable.rowAtPoint(new Point(e.getX(), e.getY()));

            attributeTable.clearSelection();
            attributeTable.addRowSelectionInterval(row, row);
            attributeTable.repaint();

            popupTableTool.registerCurrentRow(
                (AttributeNameAndType) attributeTable.getValueAt(row, 0),
                (AttributeValue) attributeTable.getValueAt(row, 1),
                row,
                tableData.getRDN()); // active path also set by valueChanged
            popupTableTool.show(attributeTable, e.getX(), e.getY());
            popupTableTool.registerCellEditor(myEditor); // TE: for bug fix 3107.
            return true;
          }
        });
  }
示例#15
0
  public IllListView(FormWindow frm) {

    setBackground(Color.darkGray);
    setLayout(new BorderLayout(0, 0));

    model = new IllTableModel();

    table = new JTable(model);
    table.setDefaultEditor(Date.class, new DateColumnEditor());
    table.setDefaultEditor(Emp.class, new EmpColumnEditor());
    table
        .getColumnModel()
        .getColumn(2)
        .setCellEditor(new DefaultCellEditor(new JComboBox(Ill.getTypes())));
    table.setRowHeight(table.getRowHeight() + 5);
    add(new JScrollPane(table), BorderLayout.CENTER);

    // КНОПКИ

    JButton btnNew = new JButton("Новый");
    JButton btnEdit = new JButton("Изменить");
    JButton btnDel = new JButton("Удалить");
    JButton btnSave = new JButton("Сохранить");
    JButton btnChanges = new JButton("Изменения");
    JButton btnRefresh = new JButton("Обновить");
    JButton btnExit = new JButton("Выход");
    JPanel panelButton = new JPanel();
    panelButton.add(btnNew);
    panelButton.add(btnEdit);
    panelButton.add(btnDel);
    panelButton.add(btnSave);
    panelButton.add(btnChanges);
    panelButton.add(btnRefresh);
    panelButton.add(btnExit);
    add(panelButton, BorderLayout.SOUTH);

    btnExit.addActionListener(frm);

    btnChanges.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            model.printChanges();
          }
        });

    btnNew.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            model.addRow();
          }
        });
    btnDel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            model.removeRow(table.convertRowIndexToModel(table.getSelectedRow()));
          }
        });
    btnSave.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              model.saveChanges();
              Msg.info(IllListView.this, "Операция выполнена успешно.");
            } catch (Exception e1) {
              Msg.error(IllListView.this, "Не удалось сохранить данные!");
            }
          }
        });

    btnRefresh.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            model.refresh();
          }
        });
  }
示例#16
0
  public RosterTable(boolean editable, int selectionMode) {
    super();
    dataModel = new RosterTableModel(editable);
    sorter = new TableSorter(dataModel);
    dataTable = new JTable(sorter);
    sorter.setTableHeader(dataTable.getTableHeader());
    dataScroll = new JScrollPane(dataTable);

    // set initial sort
    TableSorter tmodel = ((TableSorter) dataTable.getModel());
    tmodel.setSortingStatus(RosterTableModel.ADDRESSCOL, TableSorter.ASCENDING);

    // Use a "Numeric, if not, Alphanumeric" comparator
    tmodel.setColumnComparator(String.class, new jmri.util.PreferNumericComparator());

    // allow reordering of the columns
    dataTable.getTableHeader().setReorderingAllowed(true);

    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    dataTable.setColumnModel(columnModel);
    dataModel.setColumnModel(columnModel);
    dataTable.createDefaultColumnsFromModel();
    dataTable.setAutoCreateColumnsFromModel(false);

    TableColumn tc = columnModel.getColumnByModelIndex(RosterTableModel.PROTOCOL);
    columnModel.setColumnVisible(tc, false);

    for (String s : Roster.instance().getAllAttributeKeys()) {
      if (!s.contains("RosterGroup")
          && !s.toLowerCase().startsWith("sys")
          && !s.toUpperCase().startsWith("VSD")) { // NOI18N
        String[] r = s.split("(?=\\p{Lu})"); // NOI18N
        StringBuilder sb = new StringBuilder();
        sb.append(r[0].trim());
        // System.out.println("'"+r[0]+",");
        for (int j = 1; j < r.length; j++) {
          // System.out.println("'"+r[j]+",");
          sb.append(" ");
          sb.append(r[j].trim());
        }
        TableColumn c = new TableColumn(dataModel.getColumnCount());
        c.setHeaderValue((sb.toString()).trim());
        dataTable.addColumn(c);
        dataModel.addColumn(c.getHeaderValue());
        columnModel.setColumnVisible(c, false);
      }
    }

    // resize columns as requested
    resetColumnWidths();

    // general GUI config
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    // install items in GUI
    add(dataScroll);

    // set Viewport preferred size from size of table
    java.awt.Dimension dataTableSize = dataTable.getPreferredSize();
    // width is right, but if table is empty, it's not high
    // enough to reserve much space.
    dataTableSize.height = Math.max(dataTableSize.height, 400);
    dataTableSize.width = Math.max(dataTableSize.width, 400);
    dataScroll.getViewport().setPreferredSize(dataTableSize);

    dataTable.setSelectionMode(selectionMode);
    MouseListener mouseHeaderListener = new tableHeaderListener();
    dataTable.getTableHeader().addMouseListener(mouseHeaderListener);

    dataTable.setDefaultEditor(Object.class, new RosterCellEditor());

    dataTable
        .getSelectionModel()
        .addListSelectionListener(
            tableSelectionListener =
                new ListSelectionListener() {
                  @Override
                  public void valueChanged(ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                      selectedRosterEntries = null; // clear cached list of selections
                      if (dataTable.getSelectedRowCount() == 1) {
                        re =
                            Roster.instance()
                                .getEntryForId(
                                    sorter
                                        .getValueAt(
                                            dataTable.getSelectedRow(), RosterTableModel.IDCOL)
                                        .toString());
                      } else if (dataTable.getSelectedRowCount() > 1) {
                        re = null;
                      } // leave last selected item visible if no selection
                    } else if (e.getFirstIndex() == -1) {
                      // A reorder of the table might of occured therefore we are going to make sure
                      // that the selected item is still in view
                      moveTableViewToSelected();
                    }
                  }
                });
  }
示例#17
0
  public ReportDialog(
      final Frame frame,
      final boolean modal,
      final Collection<Component> components,
      final String title) {
    super(frame, modal);

    final Iterator<Component> compIterator = components.iterator();
    tables = new ArrayList<JTable>();
    boolean parCoordFound = false;

    while (compIterator.hasNext()) {
      final Component comp = compIterator.next();
      if (comp instanceof JTable) {
        tables.add((JTable) comp);

        if (!parCoordFound && comp instanceof JParCoord) {
          jpc = (JParCoord) comp;
          parCoordFound = true;
        }
      }
    }

    addOptions();
    final JLabel jtitle = new JLabel(title, ICON, SwingConstants.LEFT);
    jtitle.setAlignmentX(Component.CENTER_ALIGNMENT);
    jtitle.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0));
    getUserPanel().add(jtitle);

    properties = Messages.makeProperties("io.report.defaultReport");
    properties.put("Template File", new File("."));
    // properties.put ("Save Report Here", new File("."));
    propertyEditingTable = new PropertiesTable(properties);
    propertyEditingTable.setFont(Font.decode(Messages.getString("graphic", "systemFont")));
    propertyEditingTable
        .getColumnModel()
        .getColumn(0)
        .setCellRenderer(new KeyCellValueTypeRenderer());
    propertyEditingTable.setDefaultEditor(File.class, new FileChooserTableCellEditor());

    // Disable generate report button until all fields in property value column have some entry in
    // them
    propertyEditingTable
        .getModel()
        .addTableModelListener(
            new TableModelListener() {
              @Override
              public void tableChanged(final TableModelEvent tmEvent) {
                final TableModel tModel = propertyEditingTable.getModel();
                if (tmEvent.getType() == TableModelEvent.UPDATE
                    && tmEvent.getFirstRow() != TableModelEvent.HEADER_ROW) {
                  disableOptionsIfPropertiesIncomplete(tModel);
                }
              }
            });

    final JScrollPane tableScrollPane = new JScrollPane(propertyEditingTable);
    tableScrollPane.setPreferredSize(new Dimension(tableScrollPane.getPreferredSize().width, 200));

    getUserPanel().add(tableScrollPane);

    imageTable = new JTableST();
    imageTable.setRowHeight(48);
    refreshImageTable();
    final JScrollPane imageTableScrollPane = new JScrollPane(imageTable);
    imageTableScrollPane.setPreferredSize(
        new Dimension(imageTableScrollPane.getPreferredSize().width, 200));
    getUserPanel().add(imageTableScrollPane);

    disableOptionsIfPropertiesIncomplete(propertyEditingTable.getModel());
  }
示例#18
0
  /**
   * Diese Methode baut das JPanel (also das Objekt selbst, da es von JPanel erbt) zusammen und
   * fuellt es mit Werten. Dieses fasst die bereits vom Benutzer gespeicherten, eigenen Kommandos
   * und erlaubt das Erstellen neuer oder Loeschen alter.
   *
   * <p>Es existiert nur ein einziger Listener fuer Buttons, der
   * <i>SettingsCommandButtonListener</i>. Die Auswahl-ComboBox fuer die Kommandos bekommt ihren
   * eigenen <i>ComboBoxListener</i>.
   *
   * <p>Die Tabelle erhaelt fuer die erste Spalte, welche die Namen der Betriebssysteme fasst und
   * nicht veraendert werden darf, einen eigenen Renderer <i>CustomTableRenderer</i>. Zudem bekommt
   * die gesamte Tabelle ein eigenes DefaultTableModel <i>CustomTableModel</i>.
   *
   * @see SettingsCommandButtonListener
   * @see ComboBoxListener
   * @see CustomTableRenderer
   * @see CustomTableModel
   */
  private void drawTab() {
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    Box custInfoBoxWrapper_ref = new Box(BoxLayout.X_AXIS);
    Box custInfoBox_ref = new Box(BoxLayout.Y_AXIS);
    custInfoBox_ref.setBorder(new TitledBorder("Hinweis"));
    custInfoBox_ref.add(Box.createVerticalStrut(5));
    custInfoBox_ref.add(
        new JLabel(
            "Hier können Sie eigene Kommandos mit einem Befehl für jedes Betriebssystem definieren."));
    custInfoBox_ref.add(
        new JLabel(
            "Die Kommandos können dann über das Hauptinterface ausgewählt und ausgeführt werden."));
    custInfoBox_ref.add(Box.createVerticalStrut(10));
    custInfoBox_ref.add(
        new JLabel(
            "Sie müssen nicht für jedes Betriebssystem ein Kommando definieren, für betroffene"));
    custInfoBox_ref.add(
        new JLabel("Einträge wird jedoch dann unter Umständen kein Befehl ausgeführt."));
    custInfoBox_ref.add(Box.createVerticalStrut(5));
    custInfoBoxWrapper_ref.add(custInfoBox_ref);
    custInfoBoxWrapper_ref.add(Box.createHorizontalStrut(10));
    ImageIcon commandIcon_ref =
        new ImageIcon(
            ClassLoader.getSystemResource("de/home/tinyadmin/resource/customFrameIcon.png"));
    custInfoBoxWrapper_ref.add(new JLabel(commandIcon_ref));
    custInfoBoxWrapper_ref.add(Box.createHorizontalStrut(10));
    this.add(custInfoBoxWrapper_ref);
    this.add(Box.createVerticalStrut(25));

    Box comSelBox_ref = new Box(BoxLayout.Y_AXIS);
    comSelBox_ref.setBorder(new TitledBorder("Kommandos"));
    Box comSelBoxSub1_ref = new Box(BoxLayout.X_AXIS);
    comSelBoxSub1_ref.add(new JLabel("Kommandos:"));
    cComBox_ref = new JComboBox();
    for (int i = 0; i < (setGui_ref.getGUI().getSettings())[1].length; i++) {
      cComBox_ref.addItem((setGui_ref.getGUI().getSettings())[1][i][0]);
    } // endfor
    cComBox_ref.addItemListener(new ComboBoxListener());
    cComBox_ref.setPreferredSize(new Dimension(100, 30));
    comSelBoxSub1_ref.add(Box.createHorizontalStrut(3));
    comSelBoxSub1_ref.add(cComBox_ref);
    comSelBoxSub1_ref.add(Box.createHorizontalStrut(450));
    comSelBoxSub1_ref.add(Box.createGlue());
    Box comSelBoxSub2_ref = new Box(BoxLayout.X_AXIS);
    ImageIcon custAddIcon_ref =
        new ImageIcon(ClassLoader.getSystemResource("de/home/tinyadmin/resource/addIcon.png"));
    ImageIcon custDelIcon_ref =
        new ImageIcon(ClassLoader.getSystemResource("de/home/tinyadmin/resource/deleteIcon.png"));
    JButton custAddButton_ref = new JButton("Neu", custAddIcon_ref);
    custAddButton_ref.setToolTipText("Fügt ein neues Kommando hinzu.");
    custAddButton_ref.addActionListener(new SettingsCommandButtonListener());
    JButton custDelButton_ref = new JButton("Löschen", custDelIcon_ref);
    custDelButton_ref.setToolTipText("Löscht das gewählte Kommando.");
    custDelButton_ref.addActionListener(new SettingsCommandButtonListener());
    comSelBoxSub2_ref.add(custAddButton_ref);
    comSelBoxSub2_ref.add(Box.createHorizontalStrut(5));
    comSelBoxSub2_ref.add(custDelButton_ref);
    comSelBoxSub2_ref.add(Box.createGlue());
    comSelBox_ref.add(Box.createVerticalStrut(5));
    comSelBox_ref.add(comSelBoxSub1_ref);
    comSelBox_ref.add(Box.createVerticalStrut(10));
    comSelBox_ref.add(comSelBoxSub2_ref);
    comSelBox_ref.add(Box.createVerticalStrut(5));
    this.add(comSelBox_ref);
    this.add(Box.createVerticalStrut(15));

    Box selectedItemBox_ref = new Box(BoxLayout.Y_AXIS);
    selectedItemBox_ref.setBorder(new TitledBorder("Ausgewähltes Kommando"));
    selectedItemBox_ref.add(Box.createVerticalStrut(5));
    Box nameBox_ref = new Box(BoxLayout.X_AXIS);
    nameBox_ref.add(new JLabel("Name:"));
    custNameTextF_ref = new JTextField(10);
    nameBox_ref.add(Box.createHorizontalStrut(5));
    nameBox_ref.add(custNameTextF_ref);
    nameBox_ref.add(Box.createHorizontalStrut(600));
    nameBox_ref.add(Box.createGlue());
    selectedItemBox_ref.add(nameBox_ref);
    selectedItemBox_ref.add(Box.createVerticalStrut(10));
    Box custTableBox_ref = new Box(BoxLayout.X_AXIS);
    custTable_ref = new JTable();
    custTable_ref.setPreferredScrollableViewportSize(new Dimension(600, 75));
    JScrollPane custTableScroller_ref = new JScrollPane(custTable_ref);
    custTableScroller_ref.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    custTableScroller_ref.setHorizontalScrollBarPolicy(
        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    custTableMod_ref = new CustomTableModel(getSelTabMatrix(), new String[] {"OS", "Kommando"});
    custTable_ref.setModel(custTableMod_ref);
    custTable_ref.setDefaultEditor(new Object().getClass(), new TableEditor());
    refreshCustomTableRenderers();
    custTableBox_ref.add(custTableScroller_ref);
    custTableBox_ref.add(Box.createHorizontalStrut(10));
    selectedItemBox_ref.add(custTableBox_ref);
    Box selItemBoxButtons_ref = new Box(BoxLayout.Y_AXIS);
    ImageIcon custSaveIcon_ref =
        new ImageIcon(ClassLoader.getSystemResource("de/home/tinyadmin/resource/saveIcon.png"));
    ImageIcon custResetIcon_ref =
        new ImageIcon(ClassLoader.getSystemResource("de/home/tinyadmin/resource/resetIcon.png"));
    JButton custSaveButton_ref = new JButton("Speichern", custSaveIcon_ref);
    custSaveButton_ref.setToolTipText("Speichert die Veränderungen am ausgewählten Kommando.");
    custSaveButton_ref.addActionListener(new SettingsCommandButtonListener());
    JButton custResetButton_ref = new JButton("Reset", custResetIcon_ref);
    custResetButton_ref.setToolTipText(
        "<html>Setzt das ausgewählte Kommando auf<br>Standardeinstellungen zurück.</html>");
    custResetButton_ref.addActionListener(new SettingsCommandButtonListener());
    selItemBoxButtons_ref.add(custSaveButton_ref);
    selItemBoxButtons_ref.add(Box.createHorizontalStrut(1));
    selItemBoxButtons_ref.add(custResetButton_ref);
    selItemBoxButtons_ref.add(Box.createVerticalStrut(20));
    custTableBox_ref.add(selItemBoxButtons_ref);

    this.add(selectedItemBox_ref);
    this.add(Box.createVerticalStrut(10));

    fillSelectedItemBox();
  } // endmethod drawTab
示例#19
0
  protected void createGUI() {
    setTitle(app.getPlain("Substitute") + " - " + app.getCommand("Row") + " " + (editRow + 1));
    setResizable(true);

    GeoCasCell cell = casView.getConsoleTable().getGeoCasCell(editRow);

    HashSet<GeoElement> vars = cell.getInputVE().getVariables();
    Vector<String> row;
    if (vars != null) {
      data = new Vector<Vector<String>>(vars.size() + 1);
      Iterator<GeoElement> iter = vars.iterator();
      while (iter.hasNext()) {
        row = new Vector<String>(2);
        GeoElement var = iter.next();
        String nextVar = var.getLabel();
        int i = 0;
        for (i = 0; i < data.size(); i++) {
          if (data.get(i).firstElement().compareTo(nextVar) >= 0) {
            break;
          }
        }
        if (i == data.size() || !data.get(i).firstElement().equals(nextVar)) {
          row.add(nextVar);
          row.add("");
          data.insertElementAt(row, i);
        }
      }
    } else {
      data = new Vector<Vector<String>>(1);
    }
    row = new Vector<String>(2);
    row.add("");
    row.add("");
    data.add(row);

    Vector<String> header = new Vector<String>();
    header.add(app.getPlain("OldExpression"));
    header.add(app.getPlain("NewExpression"));
    replaceTable = new JTable(data, header);
    replaceTable.setDefaultEditor(Object.class, new MathTextCellEditor());
    replaceTable.getTableHeader().setReorderingAllowed(false);
    double fontFactor = Math.max(1, app.getGUIFontSize() / DEFAULT_FONT_SIZE);
    replaceTable.setRowHeight((int) (DEFAULT_TABLE_CELL_HEIGHT * fontFactor));

    replaceTable.setPreferredScrollableViewportSize(
        new Dimension(
            (int) (DEFAULT_TABLE_WIDTH * fontFactor), (int) (DEFAULT_TABLE_HEIGHT * fontFactor)));
    scrollPane = new JScrollPane(replaceTable);

    captionPanel = new JPanel(new BorderLayout(5, 0));

    captionPanel.add(scrollPane, BorderLayout.CENTER);

    replaceTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    replaceTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              public void valueChanged(ListSelectionEvent e) {
                addRow(false);
              }
            });

    replaceTable.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyChar() != '\t') addRow(true);
          }
        });

    // buttons
    btEval = new JButton("=");
    btEval.setToolTipText(app.getCommandTooltip("Evaluate"));
    btEval.setActionCommand("Evaluate");
    btEval.addActionListener(this);

    btNumeric = new JButton("\u2248");
    btNumeric.setToolTipText(app.getCommandTooltip("Numeric"));
    btNumeric.setActionCommand("Numeric");
    btNumeric.addActionListener(this);

    btSub = new JButton(app.getPlain("\u2713"));
    btSub.setToolTipText(app.getCommandTooltip("Substitute"));
    btSub.setActionCommand("Substitute");
    btSub.addActionListener(this);

    btPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    btPanel.add(btEval);
    btPanel.add(btNumeric);
    btPanel.add(btSub);

    // Create the JOptionPane.
    optionPane = new JPanel(new BorderLayout(5, 5));

    // create object list
    optionPane.add(captionPanel, BorderLayout.CENTER);

    optionPane.add(btPanel, BorderLayout.SOUTH);
    optionPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Make this dialog display it.
    setContentPane(optionPane);
  }
示例#20
0
  public TablePanel() {
    this.tableModel = new BetTableModel();
    this.table = new JTable(tableModel);
    popup = new JPopupMenu();

    table.setDefaultEditor(BookMaker.class, new BookMakerEditor());
    table.setDefaultRenderer(BookMaker.class, new BookMakerRenderer());
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(25);

    JMenuItem removeItem = new JMenuItem("Delete bet");
    popup.add(removeItem);

    table.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {

            int row = table.rowAtPoint(e.getPoint());

            table.getSelectionModel().setSelectionInterval(row, row);

            if (e.getButton() == MouseEvent.BUTTON3) {
              popup.show(table, e.getX(), e.getY());
            }
          }
        });

    TableColumn col = null;
    int width = 0;
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
      col = table.getColumnModel().getColumn(i);
      switch (i) {
        case 0:
          width = 50;
          break;
        case 1:
          width = 114;
          break;
        case 2:
          width = 40;
          break;
        case 3:
          width = 50;
          break;
        case 4:
          width = 50;
          break;
        case 5:
          width = 40;
          break;
        case 6:
          width = 70;
          break;
        case 7:
          width = 85;
          break;
        default:
          width = 75;
          break;
      }
      col.setPreferredWidth(width);
    }

    removeItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            int row = table.getSelectedRow();

            if (betTableListener != null) {
              betTableListener.rowDeleted(row);
              tableModel.fireTableRowsDeleted(row, row);
            }
          }
        });

    table.setVisible(true);
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.setSize(1000, this.getHeight());
    add(new JScrollPane(table), BorderLayout.CENTER);
  }
示例#21
0
    @Override
    public void actionPerformed(ActionEvent e) {
      EquipmentSetFacade equipSet = character.getEquipmentSetRef().getReference();
      int[] rows = equipmentSetTable.getSelectedRows();
      List<EquipNode> paths = new ArrayList<EquipNode>();
      for (int i = 0; i < rows.length; i++) {
        EquipNode path = (EquipNode) equipmentSetTable.getValueAt(rows[i], 0);
        if (path.getNodeType() == NodeType.EQUIPMENT) {
          paths.add(path);
        }
      }
      if (!paths.isEmpty()) {
        Object[][] data = new Object[paths.size()][3];
        for (int i = 0; i < paths.size(); i++) {
          EquipNode path = paths.get(i);
          data[i][0] = path.getEquipment();
          data[i][1] = 1;
        }
        Object[] columns =
            new Object[] {
              LanguageBundle.getString("in_equipItem"), // $NON-NLS-1$
              LanguageBundle.getString("in_equipQuantityAbbrev"), // $NON-NLS-1$
            };
        DefaultTableModel tableModel =
            new DefaultTableModel(data, columns) {

              @Override
              public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex == 1) {
                  return Integer.class;
                }
                return Object.class;
              }

              @Override
              public boolean isCellEditable(int row, int column) {
                return column != 0;
              }
            };
        JTable table = new JTable(tableModel);
        table.setFocusable(false);
        table.setCellSelectionEnabled(false);
        table.setDefaultRenderer(Integer.class, new TableCellUtilities.SpinnerRenderer());
        table.setDefaultEditor(Integer.class, new SpinnerEditor(equipSet.getEquippedItems()));
        table.setRowHeight(22);
        table.getColumnModel().getColumn(0).setPreferredWidth(140);
        table.getColumnModel().getColumn(1).setPreferredWidth(50);
        table.setPreferredScrollableViewportSize(table.getPreferredSize());
        JTableHeader header = table.getTableHeader();
        header.setReorderingAllowed(false);
        JScrollPane pane = new JScrollPane(table);
        JPanel panel = new JPanel(new BorderLayout());
        JLabel help =
            new JLabel(LanguageBundle.getString("in_equipSelectUnequipQty")); // $NON-NLS-1$
        panel.add(help, BorderLayout.NORTH);
        panel.add(pane, BorderLayout.CENTER);
        int res =
            JOptionPane.showConfirmDialog(
                JOptionPane.getFrameForComponent(equipmentTable),
                panel,
                LanguageBundle.getString("in_equipUnequipSel"), // $NON-NLS-1$
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);

        if (res == JOptionPane.OK_OPTION) {
          for (int i = 0; i < paths.size(); i++) {
            equipSet.removeEquipment(paths.get(i), (Integer) tableModel.getValueAt(i, 1));
          }
        }
      }
    }
示例#22
0
  public void createUI() {
    List<String> features = features = ExtractorManager.getSupportedFeatures();
    songs = DBHandler.getInstance().getSongs(null);
    final LTableModel model = new LTableModel(features, songs);
    model.setCurrentFolder(null);
    JTable table = new JTable();
    JScrollPane scroller = new JScrollPane(table);
    scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    table.setModel(model);
    final Border eBorder = new EmptyBorder(5, 2, 5, 2);
    table.setDefaultRenderer(
        File.class,
        new TableCellRenderer() {

          @Override
          public Component getTableCellRendererComponent(
              JTable table,
              Object value,
              boolean isSelected,
              boolean hasFocus,
              int row,
              int column) {
            JLabel label;
            if (value instanceof File) {
              String name = ((File) value).getName();
              if (!Utils.stringNotNullOrEmpty(name)) {
                name = ((File) value).getAbsolutePath();
              }
              label =
                  new JLabel(
                      name,
                      Utils.getIcon(
                          ((File) value).isDirectory()
                              ? ResourceConstants.FOLDER_ICON
                              : ResourceConstants.SONG_ICON),
                      SwingConstants.LEFT);
              label.setBorder(eBorder);
              if (((File) value).isFile()) {
                int index = songs.indexOf(new Song((File) value));
                if (index < 0) {
                  // not indexed;
                  label.setForeground(Color.GRAY);
                }
              }
              return label;
            }
            label = new JLabel(value.toString());
            return label;
          }
        });

    JTextField txtField = new JTextField();
    AutoCompletionService completionService = new AutoCompletionService();
    model.setCompletionService(completionService);
    completionService.createMapFromSongList(DBHandler.getInstance().getAllSongs());
    table.setDefaultEditor(String.class, new LCellEditor(txtField, completionService, features));

    table.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
              JTable target = (JTable) e.getSource();
              int row = target.getSelectedRow();
              LTableModel lModel = (LTableModel) target.getModel();
              File file = (File) lModel.getValueAt(row, 0);
              if (file.getName().equalsIgnoreCase("..")) {
                if (lModel.getCurrentFolder() != null) {
                  lModel.setCurrentFolder(lModel.getCurrentFolder().getParentFile());
                }
              } else if (file.isDirectory()) {
                lModel.setCurrentFolder(file);
              }
            }
          }
        });
    TableColumnModel cModel = table.getColumnModel();
    cModel.getColumn(0).setMinWidth(100);

    table.setRowHeight(ROW_HEIGHT);

    JButton btnCommit =
        new JButton(
            new AbstractAction("Commit Changes") {

              @Override
              public void actionPerformed(ActionEvent arg0) {
                final List<Modification> changes = model.getChanges();
                final ProgressMonitor monitor =
                    new ProgressMonitor(
                        MetaDataEditor.this,
                        "Committing Changes",
                        "Writing the changes to the DB",
                        0,
                        changes.size());
                new Thread() {
                  @Override
                  public void run() {
                    DBHandler.getInstance().applyModifications(changes, monitor);
                    cleanChanges();
                    MetaDataEditor.this.setVisible(false);
                  }
                }.start();
              }
            });

    JButton btnCancel =
        new JButton(
            new AbstractAction("Cancel") {

              @Override
              public void actionPerformed(ActionEvent arg0) {
                disposeChanges();
                MetaDataEditor.this.setVisible(false);
              }
            });

    JLabel lblHelp =
        new JLabel(
            "<html>You can set a value to all songs in a folder by specifing the value at the folder level. By default, it will not overwrite existing values. To overwrite, tick the checkbox below</html>");
    // JLabel lblNote = new JLabel(
    // "Note: Once the value is set for all songs recursively, the value entered at the folder level
    // will disappear.");
    chkOverwrite =
        new JCheckBox(
            new AbstractAction("Overwrite existing values if required") {

              @Override
              public void actionPerformed(ActionEvent e) {
                model.setDoOverwrite(chkOverwrite.isSelected());
              }
            });

    table.setPreferredScrollableViewportSize(new Dimension(1000, 500));
    JPanel panel = new JPanel(new MigLayout("", "[grow]", "[][][grow][]"));

    JPanel controlPanel = new JPanel(new MigLayout("", "push[][]", "[]"));
    controlPanel.add(btnCommit, "flowx,push,align right");
    controlPanel.add(btnCancel, "flowx");

    panel.add(lblHelp, "span");
    // panel.add(lblNote, "span");
    panel.add(chkOverwrite, "span");
    panel.add(scroller, "span");
    panel.add(controlPanel, "span,grow");
    this.setContentPane(panel);

    this.setVisible(true);
    this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    this.pack();
  }
示例#23
0
  // ctor
  public SymbolicProgFrame() {
    super();

    // configure GUI elements
    selectFileButton.setText("Read File");
    selectFileButton.setVisible(true);
    selectFileButton.setToolTipText("Press to select & read a configuration file");

    storeFileButton.setText("Store File");
    storeFileButton.setVisible(true);
    storeFileButton.setToolTipText("Press to store the configuration file");

    variableTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
    variableTable.setDefaultRenderer(JButton.class, new ValueRenderer());
    variableTable.setDefaultEditor(JTextField.class, new ValueEditor());
    variableTable.setDefaultEditor(JButton.class, new ValueEditor());
    variableTable.setRowHeight(new JButton("X").getPreferredSize().height);
    variableScroll.setColumnHeaderView(variableTable.getTableHeader());
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    // instead of forcing the columns to fill the frame (and only fill)
    variableTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    cvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
    cvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
    cvTable.setDefaultEditor(JTextField.class, new ValueEditor());
    cvTable.setDefaultEditor(JButton.class, new ValueEditor());
    cvTable.setRowHeight(new JButton("X").getPreferredSize().height);
    cvScroll.setColumnHeaderView(cvTable.getTableHeader());
    // have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
    // instead of forcing the columns to fill the frame (and only fill)
    cvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    newCvButton.setText("Create new CV");
    newCvLabel.setText("CV number:");
    newCvNum.setText("");

    newVarButton.setText("Create new variable");
    newVarNameLabel.setText("Name:");
    newVarName.setText("");
    newVarCvLabel.setText("Cv number:");
    newVarCv.setText("");
    newVarMaskLabel.setText("Bit mask:");
    newVarMask.setText("VVVVVVVV");

    // add actions to buttons
    selectFileButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
            selectFileButtonActionPerformed(e);
          }
        });
    storeFileButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
            writeFile();
          }
        });
    newCvButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
            cvModel.addCV(newCvNum.getText(), false, false, false);
          }
        });
    newVarButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
            newVarButtonPerformed();
          }
        });

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    // general GUI config
    setTitle("Symbolic Programmer");
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

    // install items in GUI
    JPanel tPane1 = new JPanel();
    tPane1.setLayout(new BoxLayout(tPane1, BoxLayout.X_AXIS));
    tPane1.add(new JLabel("Road Name: "));
    tPane1.add(locoRoadName);
    tPane1.add(new JLabel("Number: "));
    tPane1.add(locoRoadNumber);
    tPane1.add(new JLabel("Manufacturer: "));
    tPane1.add(locoMfg);
    tPane1.add(new JLabel("Model: "));
    tPane1.add(locoModel);
    getContentPane().add(tPane1);

    JPanel tPane3 = new JPanel();
    tPane3.setLayout(new BoxLayout(tPane3, BoxLayout.X_AXIS));
    tPane3.add(selectFileButton);
    tPane3.add(Box.createHorizontalGlue());
    tPane3.add(new JLabel("Decoder Manufacturer: "));
    tPane3.add(decoderMfg);
    tPane3.add(new JLabel(" Model: "));
    tPane3.add(decoderModel);
    tPane3.add(Box.createHorizontalGlue());
    tPane3.add(storeFileButton);
    tPane3.add(Box.createHorizontalGlue());
    getContentPane().add(tPane3);

    JPanel tPane2 = new JPanel();
    tPane2.setLayout(new BoxLayout(tPane2, BoxLayout.X_AXIS));
    tPane2.add(modePane);
    tPane2.add(Box.createHorizontalGlue());
    getContentPane().add(tPane2);

    getContentPane().add(new JSeparator());

    getContentPane().add(progStatus);

    getContentPane().add(variableScroll);

    getContentPane().add(cvScroll);

    JPanel tPane4 = new JPanel();
    tPane4.setLayout(new BoxLayout(tPane4, BoxLayout.X_AXIS));
    tPane4.add(newCvButton);
    tPane4.add(newCvLabel);
    tPane4.add(newCvNum);
    tPane4.add(Box.createHorizontalGlue());
    getContentPane().add(tPane4);

    tPane4 = new JPanel();
    tPane4.setLayout(new BoxLayout(tPane4, BoxLayout.X_AXIS));
    tPane4.add(newVarButton);
    tPane4.add(newVarNameLabel);
    tPane4.add(newVarName);
    tPane4.add(newVarCvLabel);
    tPane4.add(newVarCv);
    tPane4.add(newVarMaskLabel);
    tPane4.add(newVarMask);
    tPane4.add(Box.createHorizontalGlue());
    getContentPane().add(tPane4);

    // for debugging
    pack();
  }