コード例 #1
0
ファイル: Ssys3.java プロジェクト: scyptnex/computing
  public void makeGUI() {
    frm = new JFrame();
    c = frm.getContentPane();

    btnImport = new JButton("Import");
    btnImport.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            secureImport();
          }
        });
    btnMove = new JButton("Move");
    btnMove.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            secureMove();
          }
        });
    btnDelete = new JButton("Delete");
    btnDelete.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            secureDelete();
          }
        });
    btnAnalyse = new JButton("Analyse");
    btnAnalyse.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            secureAnalysis();
          }
        });

    tblItems = new JTable(store);
    tblItems.setRowSorter(tableSorter);
    tblItems.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tblItems.setFillsViewportHeight(true);
    tblItems.getRowSorter().toggleSortOrder(Storage.COL_DATE);
    tblItems.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
              tblItems.setRowSelectionInterval(
                  e.getY() / tblItems.getRowHeight(), e.getY() / tblItems.getRowHeight());
            }
            if (e.getClickCount() > 1 || e.getButton() == MouseEvent.BUTTON3) {
              int idx = tblItems.convertRowIndexToModel(tblItems.getSelectedRow());
              secureExport(idx);
            }
          }

          public void mouseEntered(MouseEvent arg0) {}

          public void mouseExited(MouseEvent arg0) {}

          public void mousePressed(MouseEvent arg0) {}

          public void mouseReleased(MouseEvent arg0) {}
        });

    txaStatus = new JTextArea(TXA_HEIGHT, TXA_WIDTH);
    txaStatus.setEditable(false);
    txaStatus.setBorder(BorderFactory.createTitledBorder("Status"));
    txaSearch = new JTextArea(4, TXA_WIDTH);
    txaSearch.setBorder(BorderFactory.createTitledBorder("Search"));
    txaSearch.addKeyListener(
        new KeyListener() {
          public void keyPressed(KeyEvent arg0) {}

          public void keyReleased(KeyEvent arg0) {
            filterBase(txaSearch.getText());
            // EXPORT settings here, as in mass export (export everything)
            if (allowExport && txaSearch.getText().equalsIgnoreCase(CMD_EXPORT)) {
              // txaSearch.setText("");
              if (JOptionPane.showConfirmDialog(
                      frm,
                      "Do you really want to export the whole secure base?",
                      "Confirm Export",
                      JOptionPane.OK_CANCEL_OPTION)
                  == JOptionPane.OK_OPTION) {
                totalExport();
              }
            }
            // LOST X IMPORT asin look through the store for files not listed
            if (txaSearch.getText().equalsIgnoreCase(CMD_STOCKTAKE)) {
              for (int i = 0; i < storeLocs.size(); i++) {
                if (store.stockTake(i)) needsSave = true;
              }
            }
          }

          public void keyTyped(KeyEvent arg0) {}
        });

    JPanel pnlTop = new JPanel(new GridLayout(1, 4));
    JPanel pnlEast = new JPanel(new BorderLayout());
    JPanel pnlCenterEast = new JPanel(new BorderLayout());
    JScrollPane jspItems = new JScrollPane(tblItems);

    pnlTop.add(btnImport);
    pnlTop.add(btnMove);
    pnlTop.add(btnDelete);
    pnlTop.add(btnAnalyse);
    pnlCenterEast.add(txaStatus, BorderLayout.CENTER);
    pnlCenterEast.add(txaSearch, BorderLayout.NORTH);
    // pnlEast.add(pswPass, BorderLayout.NORTH);
    pnlEast.add(pnlCenterEast, BorderLayout.CENTER);
    c.setLayout(new BorderLayout());
    c.add(pnlTop, BorderLayout.NORTH);
    c.add(pnlEast, BorderLayout.EAST);
    c.add(jspItems, BorderLayout.CENTER);
    frm.setContentPane(c);
  }
コード例 #2
0
ファイル: MainFrame.java プロジェクト: gaurav/taxref
  /**
   * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup
   * memory monitor components, then starts things off.
   */
  public MainFrame() {
    setupMemoryMonitor();

    // Set up the main frame.
    mainFrame = new JFrame(basicTitle);
    mainFrame.setJMenuBar(setupMenuBar());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the JTable.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setSelectionBackground(COLOR_SELECTION_BACKGROUND);
    table.setShowGrid(true);

    // Add a blank table model so that the component renders properly on
    // startup.
    table.setModel(blankDataModel);

    // Add a list selection listener so we can tell the matchInfoPanel
    // that a new name was selected.
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (currentCSV == null) return;

                int row = table.getSelectedRow();
                int column = table.getSelectedColumn();

                columnInfoPanel.columnChanged(column);

                Object o = table.getModel().getValueAt(row, column);
                if (Name.class.isAssignableFrom(o.getClass())) {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column);
                } else {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1);
                }
              }
            });

    // Set up the left panel (table + matchInfoPanel)
    JPanel leftPanel = new JPanel();

    matchInfoPanel = new MatchInformationPanel(this);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(matchInfoPanel, BorderLayout.SOUTH);
    leftPanel.add(new JScrollPane(table));

    // Set up the right panel (columnInfoPanel)
    JPanel rightPanel = new JPanel();

    columnInfoPanel = new ColumnInformationPanel(this);

    progressBar.setStringPainted(true);

    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(columnInfoPanel);
    rightPanel.add(progressBar, BorderLayout.SOUTH);

    // Set up a JSplitPane to split the panels up.
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel);
    split.setResizeWeight(1);
    mainFrame.add(split);
    mainFrame.pack();

    // Set up a drop target so we can pick up files
    mainFrame.setDropTarget(
        new DropTarget(
            mainFrame,
            new DropTargetAdapter() {
              @Override
              public void dragEnter(DropTargetDragEvent dtde) {
                // Accept any drags.
                dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
              }

              @Override
              public void dragOver(DropTargetDragEvent dtde) {}

              @Override
              public void dropActionChanged(DropTargetDragEvent dtde) {}

              @Override
              public void dragExit(DropTargetEvent dte) {}

              @Override
              public void drop(DropTargetDropEvent dtde) {
                // Accept a drop as long as its File List.

                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                  dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

                  Transferable t = dtde.getTransferable();

                  try {
                    java.util.List<File> files =
                        (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);

                    // If we're given multiple files, pick up only the last file and load that.
                    File f = files.get(files.size() - 1);
                    loadFile(f, DarwinCSV.FILE_CSV_DELIMITED);

                  } catch (UnsupportedFlavorException ex) {
                    dtde.dropComplete(false);

                  } catch (IOException ex) {
                    dtde.dropComplete(false);
                  }
                }
              }
            }));
  }
コード例 #3
0
  public TableModelDemo() {

    try {
      // Load the JDBC driver
      Class.forName("com.mysql.jdbc.Driver");
      Class.forName("oracle.jdbc.driver.OracleDriver");
      System.out.println("Driver loaded");

      // Create a row set
      rowSet = new CachedRowSetImpl();

      // Set RowSet properties
      //      rowSet.setUrl("jdbc:mysql://localhost/javabook");
      rowSet.setUrl("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl");
      rowSet.setUsername("scott");
      rowSet.setPassword("tiger");

      rowSet.setCommand("select * from StateCapital");

      rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE);
      rowSet.execute();
      tableModel.setRowSet(rowSet);
      rowSet.addRowSetListener(tableModel);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayout(2, 2));
    panel1.add(jbtAddRow);
    panel1.add(jbtAddColumn);
    panel1.add(jbtDeleteRow);
    panel1.add(jbtDeleteColumn);

    JPanel panel2 = new JPanel();
    panel2.add(jbtSave);
    panel2.add(jbtClear);
    panel2.add(jbtRestore);

    JPanel panel3 = new JPanel();
    panel3.setLayout(new BorderLayout(5, 0));
    panel3.add(new JLabel("Selection Mode"), BorderLayout.WEST);
    panel3.add(jcboSelectionMode, BorderLayout.CENTER);

    JPanel panel4 = new JPanel();
    panel4.setLayout(new FlowLayout(FlowLayout.LEFT));
    panel4.add(jchkRowSelectionAllowed);
    panel4.add(jchkColumnSelectionAllowed);

    JPanel panel5 = new JPanel();
    panel5.setLayout(new GridLayout(2, 1));
    panel5.add(panel3);
    panel5.add(panel4);

    JPanel panel6 = new JPanel();
    panel6.setLayout(new BorderLayout());
    panel6.add(panel1, BorderLayout.SOUTH);
    panel6.add(panel2, BorderLayout.CENTER);

    add(panel5, BorderLayout.NORTH);
    add(new JScrollPane(jTable1), BorderLayout.CENTER);
    add(panel6, BorderLayout.SOUTH);

    // Initialize table selection mode
    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    jbtAddRow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              rowSet.absolute(2);
              rowSet.moveToInsertRow();
              rowSet.updateString("state", "Georia");
              rowSet.updateString("capital", "Atlanta");
              rowSet.insertRow();
              ((CachedRowSetImpl) rowSet).acceptChanges();
              rowSet.moveToCurrentRow();
            } catch (Exception ex) {
              ex.printStackTrace();
            }

            //        if (jTable1.getSelectedRow() >= 0)
            //          tableModel.insertRow(jTable1.getSelectedRow(),
            //            new java.util.Vector());
            //        else
            //          tableModel.addRow(new java.util.Vector());
          }
        });

    jbtAddColumn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            //        String name = JOptionPane.showInputDialog("New Column Name");
            //        tableModel.addColumn(name, new java.util.Vector());
          }
        });

    jbtDeleteRow.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (jTable1.getSelectedRow() >= 0) {
              try {
                rowSet.absolute(jTable1.getSelectedRow() + 1);
                rowSet.deleteRow();
                ((CachedRowSetImpl) rowSet).acceptChanges();
              } catch (Exception ex) {
                ex.printStackTrace();
              }
            }
          }
        });

    jbtDeleteColumn.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (jTable1.getSelectedColumn() >= 0) {
              TableColumnModel columnModel = jTable1.getColumnModel();
              TableColumn tableColumn = columnModel.getColumn(jTable1.getSelectedColumn());
              columnModel.removeColumn(tableColumn);
            }
          }
        });

    jbtSave.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              ObjectOutputStream out =
                  new ObjectOutputStream(new FileOutputStream("tablemodel.dat"));
              //          out.writeObject(tableModel.getDataVector());
              out.writeObject(getColumnNames());
              out.close();
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

    jbtClear.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            //        tableModel.setRowCount(0);
          }
        });

    jbtRestore.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              ObjectInputStream in = new ObjectInputStream(new FileInputStream("tablemodel.dat"));
              Vector rowData = (Vector) in.readObject();
              Vector columnNames = (Vector) in.readObject();
              //          tableModel.setDataVector(rowData, columnNames);
              in.close();
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });

    jchkRowSelectionAllowed.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            jTable1.setRowSelectionAllowed(jchkRowSelectionAllowed.isSelected());
          }
        });

    jchkColumnSelectionAllowed.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            jTable1.setColumnSelectionAllowed(jchkColumnSelectionAllowed.isSelected());
          }
        });

    jcboSelectionMode.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String selectedItem = (String) jcboSelectionMode.getSelectedItem();

            if (selectedItem.equals("SINGLE_SELECTION"))
              jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            else if (selectedItem.equals("SINGLE_INTERVAL_SELECTION"))
              jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            else if (selectedItem.equals("MULTIPLE_INTERVAL_SELECTION"))
              jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
          }
        });
  }
コード例 #4
0
 /** Constructor (create and layout page) */
 public SOAPMonitorPage(String host_name) {
   host = host_name;
   // Set up default filter (show all messages)
   filter = new SOAPMonitorFilter();
   // Use borders to help improve appearance
   etched_border = new EtchedBorder();
   // Build top portion of split (list panel)
   model = new SOAPMonitorTableModel();
   table = new JTable(model);
   table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   table.setRowSelectionInterval(0, 0);
   table.setPreferredScrollableViewportSize(new Dimension(600, 96));
   table.getSelectionModel().addListSelectionListener(this);
   scroll = new JScrollPane(table);
   remove_button = new JButton("Remove");
   remove_button.addActionListener(this);
   remove_button.setEnabled(false);
   remove_all_button = new JButton("Remove All");
   remove_all_button.addActionListener(this);
   filter_button = new JButton("Filter ...");
   filter_button.addActionListener(this);
   list_buttons = new JPanel();
   list_buttons.setLayout(new FlowLayout());
   list_buttons.add(remove_button);
   list_buttons.add(remove_all_button);
   list_buttons.add(filter_button);
   list_panel = new JPanel();
   list_panel.setLayout(new BorderLayout());
   list_panel.add(scroll, BorderLayout.CENTER);
   list_panel.add(list_buttons, BorderLayout.SOUTH);
   list_panel.setBorder(empty_border);
   // Build bottom portion of split (message details)
   details_time = new JLabel("Time: ", SwingConstants.RIGHT);
   details_target = new JLabel("Target Service: ", SwingConstants.RIGHT);
   details_status = new JLabel("Status: ", SwingConstants.RIGHT);
   details_time_value = new JLabel();
   details_target_value = new JLabel();
   details_status_value = new JLabel();
   Dimension preferred_size = details_time.getPreferredSize();
   preferred_size.width = 1;
   details_time.setPreferredSize(preferred_size);
   details_target.setPreferredSize(preferred_size);
   details_status.setPreferredSize(preferred_size);
   details_time_value.setPreferredSize(preferred_size);
   details_target_value.setPreferredSize(preferred_size);
   details_status_value.setPreferredSize(preferred_size);
   details_header = new JPanel();
   details_header_layout = new GridBagLayout();
   details_header.setLayout(details_header_layout);
   details_header_constraints = new GridBagConstraints();
   details_header_constraints.fill = GridBagConstraints.BOTH;
   details_header_constraints.weightx = 0.5;
   details_header_layout.setConstraints(details_time, details_header_constraints);
   details_header.add(details_time);
   details_header_layout.setConstraints(details_time_value, details_header_constraints);
   details_header.add(details_time_value);
   details_header_layout.setConstraints(details_target, details_header_constraints);
   details_header.add(details_target);
   details_header_constraints.weightx = 1.0;
   details_header_layout.setConstraints(details_target_value, details_header_constraints);
   details_header.add(details_target_value);
   details_header_constraints.weightx = .5;
   details_header_layout.setConstraints(details_status, details_header_constraints);
   details_header.add(details_status);
   details_header_layout.setConstraints(details_status_value, details_header_constraints);
   details_header.add(details_status_value);
   details_header.setBorder(etched_border);
   request_label = new JLabel("SOAP Request", SwingConstants.CENTER);
   request_text = new SOAPMonitorTextArea();
   request_text.setEditable(false);
   request_scroll = new JScrollPane(request_text);
   request_panel = new JPanel();
   request_panel.setLayout(new BorderLayout());
   request_panel.add(request_label, BorderLayout.NORTH);
   request_panel.add(request_scroll, BorderLayout.CENTER);
   response_label = new JLabel("SOAP Response", SwingConstants.CENTER);
   response_text = new SOAPMonitorTextArea();
   response_text.setEditable(false);
   response_scroll = new JScrollPane(response_text);
   response_panel = new JPanel();
   response_panel.setLayout(new BorderLayout());
   response_panel.add(response_label, BorderLayout.NORTH);
   response_panel.add(response_scroll, BorderLayout.CENTER);
   details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
   details_soap.setTopComponent(request_panel);
   details_soap.setRightComponent(response_panel);
   details_soap.setResizeWeight(.5);
   details_panel = new JPanel();
   layout_button = new JButton("Switch Layout");
   layout_button.addActionListener(this);
   reflow_xml = new JCheckBox("Reflow XML text");
   reflow_xml.addActionListener(this);
   details_buttons = new JPanel();
   details_buttons.setLayout(new FlowLayout());
   details_buttons.add(reflow_xml);
   details_buttons.add(layout_button);
   details_panel.setLayout(new BorderLayout());
   details_panel.add(details_header, BorderLayout.NORTH);
   details_panel.add(details_soap, BorderLayout.CENTER);
   details_panel.add(details_buttons, BorderLayout.SOUTH);
   details_panel.setBorder(empty_border);
   // Add the two parts to the age split pane
   split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
   split.setTopComponent(list_panel);
   split.setRightComponent(details_panel);
   // Build status area
   start_button = new JButton("Start");
   start_button.addActionListener(this);
   stop_button = new JButton("Stop");
   stop_button.addActionListener(this);
   status_buttons = new JPanel();
   status_buttons.setLayout(new FlowLayout());
   status_buttons.add(start_button);
   status_buttons.add(stop_button);
   status_text = new JLabel();
   status_text.setBorder(new BevelBorder(BevelBorder.LOWERED));
   status_text_panel = new JPanel();
   status_text_panel.setLayout(new BorderLayout());
   status_text_panel.add(status_text, BorderLayout.CENTER);
   status_text_panel.setBorder(empty_border);
   status_area = new JPanel();
   status_area.setLayout(new BorderLayout());
   status_area.add(status_buttons, BorderLayout.WEST);
   status_area.add(status_text_panel, BorderLayout.CENTER);
   status_area.setBorder(etched_border);
   // Add the split and status area to page
   setLayout(new BorderLayout());
   add(split, BorderLayout.CENTER);
   add(status_area, BorderLayout.SOUTH);
 }