private void initView() {
    AutomatonEditorPanel<T, S> panel = getEditorPanel();
    T auto = panel.getAutomaton();

    initTable(myAlg.getConvertedGrammar(), new UndoKeeper());
    panel.setTool(createArrowTool(panel, auto));

    MagnifiableScrollPane scroll = new MagnifiableScrollPane(myTable);
    scroll.setMinimumSize(myTable.getMinimumSize());

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel, scroll);

    Dimension size = getPreferredSize(), scrollSize = myTable.getMinimumSize();
    double width = size.width + scrollSize.width;
    split.setPreferredSize(new Dimension((int) width, size.height));

    double ratio = size.width / width;
    split.setDividerLocation(ratio);
    split.setResizeWeight(ratio);

    SizeSlider slider = new SizeSlider(scroll);
    JToolBar toolbar = initToolbar();

    add(split, BorderLayout.CENTER);
    add(slider, BorderLayout.SOUTH);
    add(toolbar, BorderLayout.NORTH);

    slider.distributeMagnification();

    size =
        new Dimension(
            (int) width,
            size.height + slider.getPreferredSize().height + toolbar.getPreferredSize().height);
    setPreferredSize(size);
  }
Пример #2
0
  public SplitPaneDemo() {

    // Create the list of images and put it in a scroll pane.

    list = new JList(imageNames);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);

    JScrollPane listScrollPane = new JScrollPane(list);
    picture = new JLabel();
    picture.setFont(picture.getFont().deriveFont(Font.ITALIC));
    picture.setHorizontalAlignment(JLabel.CENTER);

    JScrollPane pictureScrollPane = new JScrollPane(picture);

    // Create a split pane with the two scroll panes in it.
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, pictureScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(150);

    // Provide minimum sizes for the two components in the split pane.
    Dimension minimumSize = new Dimension(100, 50);
    listScrollPane.setMinimumSize(minimumSize);
    pictureScrollPane.setMinimumSize(minimumSize);

    // Provide a preferred size for the split pane.
    splitPane.setPreferredSize(new Dimension(400, 200));
    updateLabel(imageNames[list.getSelectedIndex()]);
  }
Пример #3
0
 public FigurePanel() {
   setLayout(new BorderLayout());
   JPanel panel = new JPanel();
   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
   panel.add(fs);
   panel.add(bp);
   JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panel, cp);
   sp.setPreferredSize(new Dimension(500, 400));
   sp.setDividerLocation(250);
   add(BorderLayout.CENTER, sp);
 }
Пример #4
0
 /**
  * This method initializes splitPane
  *
  * @return javax.swing.JSplitPane
  */
 private JSplitPane getSplitPane() {
   if (splitPane == null) {
     splitPane = new JSplitPane();
     splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
     splitPane.setPreferredSize(new Dimension(300, 118));
     splitPane.setDividerLocation(100);
     splitPane.setBottomComponent(getPanelResultados());
     splitPane.setTopComponent(getScrollPane());
     splitPane.setOneTouchExpandable(true);
   }
   return splitPane;
 }
Пример #5
0
  public TreeIconDemo() {
    super(new GridLayout(1, 0));

    // Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);

    // Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Set the icon for leaf nodes.
    ImageIcon leafIcon = createImageIcon("images/middle.gif");
    if (leafIcon != null) {
      DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
      renderer.setLeafIcon(leafIcon);
      tree.setCellRenderer(renderer);
    } else {
      System.err.println("Leaf icon missing; using default.");
    }

    // Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    // Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(tree);

    // Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100); // XXX: ignored in some releases
    // of Swing. bug 4101306
    // workaround for bug 4101306:
    // treeView.setPreferredSize(new Dimension(100, 100));

    splitPane.setPreferredSize(new Dimension(500, 300));

    // Add the split pane to this panel.
    add(splitPane);
  }
Пример #6
0
 /**
  * Inicializa una instancia de contentSplitPane y la devuelve
  *
  * @return JSplitPane: SplitPane contentSplitPane
  */
 private JSplitPane getContentSplitPane() {
   if (contentSplitPane == null) {
     contentSplitPane =
         new JSplitPane(
             JSplitPane.HORIZONTAL_SPLIT,
             getDirectoriesTreePanelScroller(),
             getChildFilesTableScroller());
     contentSplitPane.setPreferredSize(new Dimension(700, 430));
     contentSplitPane.setSize(new Dimension(700, 430));
     contentSplitPane.setDividerSize(4);
     contentSplitPane.setContinuousLayout(true);
     contentSplitPane.setDividerLocation(350);
     contentSplitPane.setEnabled(false);
   }
   return contentSplitPane;
 }
Пример #7
0
  public TreeDemo() {
    super(new GridLayout(1, 0));

    // Create the nodes.
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("The Java Series");
    createNodes(top);

    // Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
      System.out.println("line style = " + lineStyle);
      tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    // Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(tree);

    // Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100);
    splitPane.setPreferredSize(new Dimension(500, 300));

    // Add the split pane to this panel.
    add(splitPane);
  }
  public SVGMainWindow(Main frame) {
    super(new GridLayout(1, 0));

    owner = frame;

    createTreePanel();

    initDiagramPanel();

    // Add the scroll panes to a split pane.
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(scrollTreePanel);
    splitPane.setRightComponent(diagramPanel);

    splitPane.setDividerLocation(300);
    splitPane.setPreferredSize(new Dimension(500, 300));

    // Add the split pane to this panel.
    add(splitPane);
  }
Пример #9
0
  /** Create the main JFrame */
  public Driver() {
    frame = (JFrame) this;

    setTitle("RIDVentory v2.1.2");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Creates connection to controller
    control = Controller.getInstance();

    setBounds(100, 100, 593, 370);
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] {577, 0};
    gridBagLayout.rowHeights = new int[] {332, 0};
    gridBagLayout.columnWeights = new double[] {0.0, Double.MIN_VALUE};
    gridBagLayout.rowWeights = new double[] {0.0, Double.MIN_VALUE};
    getContentPane().setLayout(gridBagLayout);

    // Create Menu
    TopMenuBar topMenu = new TopMenuBar();
    this.setJMenuBar(topMenu.createMenuBar());

    // Popup Menus

    // Category Menu
    final JPopupMenu popupCat = new JPopupMenu();
    final JMenuItem addCat = new JMenuItem("Add Category");
    final JMenuItem editCat = new JMenuItem("Edit Category");
    final JMenuItem deleteCat = new JMenuItem("Delete Category");

    popupCat.add(addCat);
    popupCat.add(editCat);
    popupCat.add(deleteCat);

    // Brand Menu
    final JPopupMenu popupBrand = new JPopupMenu();
    final JMenuItem addBrand = new JMenuItem("Add Brand");
    final JMenuItem editBrand = new JMenuItem("Edit Brand");
    final JMenuItem deleteBrand = new JMenuItem("Delete Brand");

    popupBrand.add(addBrand);
    popupBrand.add(editBrand);
    popupBrand.add(deleteBrand);

    GridBagConstraints gbc_table = new GridBagConstraints();
    gbc_table.gridwidth = 3;
    gbc_table.fill = GridBagConstraints.BOTH;
    gbc_table.insets = new Insets(0, 0, 5, 0);
    gbc_table.gridx = 0;
    gbc_table.gridy = 0;
    gbc_table.weightx = 1;
    gbc_table.weighty = 1;

    GridBagConstraints gbc_buttonPanel = new GridBagConstraints();
    gbc_buttonPanel.insets = new Insets(0, 0, 5, 5);
    gbc_buttonPanel.fill = GridBagConstraints.BOTH;
    gbc_buttonPanel.gridx = 0;
    gbc_buttonPanel.gridy = 0;
    gbc_buttonPanel.weightx = 1;
    gbc_buttonPanel.weighty = 1;

    GridBagConstraints gbc_list = new GridBagConstraints();
    gbc_list.insets = new Insets(0, 0, 5, 0);
    gbc_list.anchor = GridBagConstraints.NORTHWEST;
    gbc_list.gridx = 1;
    gbc_list.gridy = 0;
    gbc_list.weightx = 1;
    gbc_list.weighty = 1;

    GridBagConstraints gbc_topMenu = new GridBagConstraints();
    gbc_topMenu.insets = new Insets(0, 0, 5, 0);
    gbc_topMenu.anchor = GridBagConstraints.NORTHWEST;
    gbc_topMenu.gridx = 1;
    gbc_topMenu.gridy = 0;
    gbc_topMenu.weightx = 1;
    gbc_topMenu.weighty = 1;

    JSplitPane splitPane = new JSplitPane();
    splitPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    GridBagConstraints gbc_splitPane = new GridBagConstraints();
    gbc_splitPane.weighty = 1.0;
    gbc_splitPane.weightx = 1.0;
    gbc_splitPane.fill = GridBagConstraints.BOTH;
    gbc_splitPane.gridx = 0;
    gbc_splitPane.gridy = 0;
    getContentPane().add(splitPane, gbc_splitPane);

    JPanel rightPanel = new JPanel();
    splitPane.setRightComponent(rightPanel);
    GridBagLayout gbl_rightPanel = new GridBagLayout();
    gbl_rightPanel.columnWidths = new int[] {499, 0};
    gbl_rightPanel.rowHeights = new int[] {281, 0};
    gbl_rightPanel.columnWeights = new double[] {0.0, Double.MIN_VALUE};
    gbl_rightPanel.rowWeights = new double[] {0.0, Double.MIN_VALUE};
    rightPanel.setLayout(gbl_rightPanel);

    table =
        new JTable() {
          /** */
          private static final long serialVersionUID = 1L;

          public boolean isCellEditable(int rowIndex, int vColIndex) {

            if (vColIndex > 0) // ID is not editable
            return true;
            else return false;
          }
        };

    table.setFillsViewportHeight(true);
    table.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setAlignmentY(Component.BOTTOM_ALIGNMENT);

    // Load table data
    tableData = control.loadTableData();

    final TableRowSorter<DefaultTableModel> sorter =
        new TableRowSorter<DefaultTableModel>((DefaultTableModel) tableData);
    table.setModel(tableData);
    table.setRowSorter(sorter);

    // Change it so load is only called once (Store results of load call and use it for list)

    catCellEditor = new JComboBox<String>(control.loadCategories());
    brandCellEditor = new JComboBox<String>(control.loadBrands());

    // Make model editor a dropdown (Make dynamic in the future)
    categoryColumn = table.getColumnModel().getColumn(3);
    brandColumn = table.getColumnModel().getColumn(4);

    categoryColumn.setCellEditor(new DefaultCellEditor(catCellEditor));
    brandColumn.setCellEditor(new DefaultCellEditor(brandCellEditor));

    // Right main pane
    JSplitPane splitPaneMain = new JSplitPane();
    splitPaneMain.setBorder(null);
    splitPaneMain.setDividerSize(-1);
    splitPaneMain.setResizeWeight(1.0);
    splitPaneMain.setPreferredSize(new Dimension(187, 25));
    splitPaneMain.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    splitPaneMain.setOrientation(JSplitPane.VERTICAL_SPLIT);

    GridBagConstraints gbc_splitPaneMain = new GridBagConstraints();
    gbc_splitPaneMain.weighty = 1.0;
    gbc_splitPaneMain.weightx = 1.0;
    gbc_splitPaneMain.fill = GridBagConstraints.BOTH;
    gbc_splitPaneMain.gridx = 0;
    gbc_splitPaneMain.gridy = 0;

    // Add split pane to main Right split pane
    rightPanel.add(splitPaneMain, gbc_splitPaneMain);

    // Right main pane, buttons row
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(0, 2, 0, 0));

    final JButton btnInsert = new JButton("Insert");
    final JButton btnDelete = new JButton("Delete");

    buttonPanel.add(btnInsert);
    buttonPanel.add(btnDelete);

    // Set components
    splitPaneMain.setTopComponent(new JScrollPane(table));
    splitPaneMain.setBottomComponent(buttonPanel);

    JPanel leftPanel = new JPanel();
    splitPane.setLeftComponent(leftPanel);
    GridBagLayout gbl_leftPanel = new GridBagLayout();
    gbl_leftPanel.columnWidths = new int[] {71, 0};
    gbl_leftPanel.rowHeights = new int[] {34, 0};
    gbl_leftPanel.columnWeights = new double[] {0.0, Double.MIN_VALUE};
    gbl_leftPanel.rowWeights = new double[] {0.0, Double.MIN_VALUE};
    leftPanel.setLayout(gbl_leftPanel);

    // Left Split panel
    JSplitPane splitPaneLists = new JSplitPane();
    splitPaneLists.setResizeWeight(0.5);
    splitPaneLists.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    GridBagConstraints gbc_splitPaneLists = new GridBagConstraints();
    gbc_splitPaneLists.anchor = GridBagConstraints.NORTHWEST;
    gbc_splitPaneLists.gridx = 0;
    gbc_splitPaneLists.gridy = 0;
    gbc_splitPaneLists.weightx = 1;
    gbc_splitPaneLists.weighty = 1;
    gbc_splitPaneLists.fill = GridBagConstraints.BOTH;

    leftPanel.add(splitPaneLists, gbc_splitPaneLists);

    // Right list
    final JList<String> brandList = new JList<String>();
    brandList.setLayoutOrientation(JList.VERTICAL_WRAP);
    brandList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    brandList.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    brandList.setAlignmentX(Component.RIGHT_ALIGNMENT);
    brandList.setAlignmentY(Component.TOP_ALIGNMENT);
    brandList.setModel(control.loadListBrands());
    brandList.setSelectedIndex(0);

    final ListSelectionModel brandListSelectionModel =
        (ListSelectionModel) brandList.getSelectionModel();
    splitPaneLists.setRightComponent(brandList);

    // Left List
    final JList<String> categoryList = new JList<String>();
    categoryList.setLayoutOrientation(JList.VERTICAL_WRAP);
    categoryList.setVisible(true);
    categoryList.setAlignmentY(Component.TOP_ALIGNMENT);
    categoryList.setAlignmentX(Component.LEFT_ALIGNMENT);
    categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel catListSelectionModel =
        categoryList.getSelectionModel(); // Created to add listener
    categoryList.setModel(control.loadListCategories());
    categoryList.setSelectedIndex(0);

    splitPaneLists.setLeftComponent(categoryList);

    table.addMouseListener(
        new MouseAdapter() {

          public void mouseReleased(MouseEvent e) {

            if (e.isPopupTrigger()) {

              Point p = e.getPoint();

              int rowNumber = table.rowAtPoint(p);

              if (Debug.LEVEL > 1) System.out.println("Row " + rowNumber + " selected");
            }
          }
        });

    btnDelete.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent arg0) {

            int selectedRow = table.getSelectedRow();

            String name = (String) table.getModel().getValueAt(selectedRow, 1);

            if (selectedRow != -1) {
              int answer =
                  JOptionPane.showConfirmDialog(
                      frame,
                      "Are you sure you want to erase product " + name + "?\n",
                      "Are you sure?",
                      JOptionPane.YES_NO_OPTION);

              if (answer == JOptionPane.YES_OPTION) {

                if (Debug.LEVEL > 1) System.out.println("Row " + selectedRow + " Deleted");

                DefaultTableModel model = (DefaultTableModel) table.getModel();

                // Call Delete in controller

                int id = (int) model.getValueAt(selectedRow, 0);

                if (control.deleteItem(id) == -1) {
                  JOptionPane.showMessageDialog(
                      frame, "Error: Item could not be erased", "Error", JOptionPane.ERROR_MESSAGE);
                }

                if (Debug.LEVEL > 2) System.out.println("Product ID " + id);

                // Delete it from table model

                model.removeRow(selectedRow);
              }
            }
          }
        });

    btnInsert.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent arg0) {

            InsertItem dialog = new InsertItem(table.getModel());

            dialog.setVisible(true);

            btnInsert.setEnabled(false); // Disable insert button so no multiple inserts
            btnDelete.setEnabled(false);

            // Put a listener on the window to determine when it closes
            dialog.addWindowListener(
                new WindowAdapter() {
                  @Override
                  public void windowClosed(WindowEvent e) {

                    // Notify table that data has changed to rerun filter
                    // fireTableCellUpdated
                    ((DefaultTableModel) tableData).fireTableDataChanged();

                    btnInsert.setEnabled(true); // Re-Enable insert button
                    btnDelete.setEnabled(true);

                    if (Debug.LEVEL > 3) System.out.println("Insert item window closed");
                  }
                });
          }
        });

    categoryList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {

            if (e.isPopupTrigger()) {

              Point p = e.getPoint();

              int itemChosen = categoryList.locationToIndex(p);

              // Make sure an item is chosen
              if (itemChosen > 0) // Greater than 0 to skip All
              {
                // Mark item as selected
                categoryList.setSelectedIndex(itemChosen);

                // Check if Delete Menu Item is on
                if (!popupDeleteOnCat) {
                  popupCat.add(editCat);
                  popupCat.add(deleteCat); // If not on, add it
                  popupDeleteOnCat = true;
                }

              } else {
                // Check if Delete is on
                if (popupDeleteOnCat) {
                  popupCat.remove(1); // Delete edit if turned on
                  popupCat.remove(1); // Delete delete if turned on
                  popupDeleteOnCat = false;
                }
              }

              popupCat.show(frame, e.getX(), e.getY());

              if (Debug.LEVEL > 0) System.out.println("Category List Item Chosen: " + itemChosen);
            }
          }
        });

    brandList.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseReleased(MouseEvent e) {

            if (e.isPopupTrigger()) {

              Point p = e.getPoint();

              int itemChosen = brandList.locationToIndex(p);

              // Make sure an item has been chosen
              if (itemChosen > 0) // Greater than 0 because 0 is All
              {
                // Mark item as selected
                brandList.setSelectedIndex(itemChosen);

                // Check if Delete Menu Item is not on the menu
                if (!popupDeleteOnBrand) {
                  popupBrand.add(editBrand);
                  popupBrand.add(deleteBrand); // If not on, add it
                  popupDeleteOnBrand = true;
                }

              } else {
                // Check if Delete is on the menu
                if (popupDeleteOnBrand) {
                  popupBrand.remove(1); // Delete edit
                  popupBrand.remove(1); // Delete delete if turned on
                  popupDeleteOnBrand = false;
                }
              }

              popupBrand.show(frame, e.getX(), e.getY());

              if (Debug.LEVEL > 0) System.out.println("Brand List Item Chosen: " + itemChosen);
            }
          }
        });

    // Selected index listeners
    catListSelectionModel.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {

            if (!e.getValueIsAdjusting()) // Proceed if values aren't being changed
            {
              int index = categoryList.getSelectedIndex();

              if (index >= 0) // Make sure you're actually working on an item
              {
                String category = (String) categoryList.getModel().getElementAt(index);

                index = brandList.getSelectedIndex();

                String brand = (String) brandList.getModel().getElementAt(index);

                // Call filter update
                sorter.setRowFilter(control.createFilter(category, brand));

                // debug
                if (Debug.LEVEL > 0) System.out.println("Category List Index Chosen: " + index);
              }
            }
          }
        });

    // Selected index listeners
    brandListSelectionModel.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {

            if (!e.getValueIsAdjusting()) // Proceed if values aren't being changed
            {
              int indexCat = categoryList.getSelectedIndex();
              int indexBrand = brandList.getSelectedIndex();

              if (indexCat >= 0 && indexBrand >= 0) // Make sure you're actually working on an item
              {
                String category = (String) categoryList.getModel().getElementAt(indexCat);

                String brand = (String) brandList.getModel().getElementAt(indexBrand);

                // Call filter update
                sorter.setRowFilter(control.createFilter(category, brand));
              }
            }
          }
        });

    addCat.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseReleased(MouseEvent e) {

            String newCat =
                (String)
                    JOptionPane.showInputDialog(
                        frame,
                        "Enter the name of the new Category:",
                        "Add New Category",
                        JOptionPane.PLAIN_MESSAGE,
                        null,
                        null,
                        null);
            if (newCat == null) {

              return; // Don't do anything
            }

            if (newCat.isEmpty() || newCat == "") {
              JOptionPane.showMessageDialog(
                  frame,
                  "No input encountered",
                  "New category was not created",
                  JOptionPane.ERROR_MESSAGE);
              return; // Don't do anything
            }

            String result = control.addCategory(newCat);

            // Input checking needs to be added before beta 2
            if (result != null) {
              JOptionPane.showMessageDialog(
                  frame, result, "SQL Error Encountered", JOptionPane.ERROR_MESSAGE);

              return;
            }

            // Add category to list
            DefaultListModel<String> model = (DefaultListModel<String>) categoryList.getModel();

            model.addElement(newCat);
            catCellEditor.addItem(newCat);
          }
        });

    deleteCat.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseReleased(MouseEvent e) {

            int catChosenIndex = categoryList.getSelectedIndex();
            String catName = (String) categoryList.getSelectedValue();

            // System.out.println(catChosen);

            int answer =
                JOptionPane.showConfirmDialog(
                    frame,
                    "Are you sure you want to delete category " + catName + "?\n",
                    "Are you sure?",
                    JOptionPane.YES_NO_OPTION);

            if (answer == JOptionPane.YES_OPTION) {
              if (control.deleteCategory(catName) != 0) {
                JOptionPane.showMessageDialog(
                    frame,
                    "Unable to erase category (category must not be used by any items)",
                    "SQL Error Encountered",
                    JOptionPane.ERROR_MESSAGE);

                return;
              }

              DefaultListModel<String> model = (DefaultListModel<String>) categoryList.getModel();

              categoryList.clearSelection();

              model.removeElementAt(catChosenIndex);
              catCellEditor.removeItem(catName);

              categoryList.setSelectedIndex(0);
            }
          }
        });

    addBrand.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseReleased(MouseEvent e) {

            String newBrand =
                (String)
                    JOptionPane.showInputDialog(
                        frame,
                        "Enter the name of the new Brand:",
                        "Add New Category",
                        JOptionPane.PLAIN_MESSAGE,
                        null,
                        null,
                        null);
            if (newBrand == null) {

              return; // Don't do anything
            }

            if (newBrand.isEmpty() || newBrand == "") {
              JOptionPane.showMessageDialog(
                  frame,
                  "No input encountered",
                  "New category was not created",
                  JOptionPane.ERROR_MESSAGE);
              return; // Don't do anything
            }

            String result = control.addBrand(newBrand);

            // Input checking needs to be added before beta 2
            if (result != null) {
              JOptionPane.showMessageDialog(
                  frame, result, "SQL Error Encountered", JOptionPane.ERROR_MESSAGE);

              return;
            }

            // Add category to list
            DefaultListModel<String> model = (DefaultListModel<String>) brandList.getModel();

            model.addElement(newBrand);
            brandCellEditor.addItem(newBrand);
          }
        });

    deleteBrand.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseReleased(MouseEvent e) {

            int brandChosenIndex = brandList.getSelectedIndex();
            String brandName = (String) brandList.getSelectedValue();

            System.out.println(brandChosenIndex);

            int answer =
                JOptionPane.showConfirmDialog(
                    frame,
                    "Are you sure you want to delete category " + brandName + "?\n",
                    "Are you sure?",
                    JOptionPane.YES_NO_OPTION);

            if (answer == JOptionPane.YES_OPTION) {
              if (control.deleteBrand(brandName) != 0) {
                JOptionPane.showMessageDialog(
                    frame,
                    "Unable to erase category (category must not be used by any items)",
                    "SQL Error Encountered",
                    JOptionPane.ERROR_MESSAGE);

                return;
              }

              DefaultListModel<String> model = (DefaultListModel<String>) brandList.getModel();

              // brandList.clearSelection();

              model.removeElementAt(brandChosenIndex);
              brandCellEditor.removeItem(brandName); // Use name to allow flexibility in future
              brandList.setSelectedIndex(0); // Reset to all
            }
          }
        });

    // Data change listener
    tableData.addTableModelListener(
        new TableModelListener() {

          public void tableChanged(TableModelEvent e) {

            try {
              int row = e.getFirstRow();
              int column = e.getColumn();
              String columnName = tableData.getColumnName(column);
              int itemID = (int) tableData.getValueAt(row, 0);
              Object data = tableData.getValueAt(row, column);

              if (Debug.LEVEL > 0) {
                System.out.println(
                    "Cell Edited at "
                        + row
                        + " "
                        + column
                        + ": "
                        + columnName
                        + " "
                        + data
                        + " ID: "
                        + itemID);
              }
              int rowsUpdated = control.updateItem(itemID, columnName, data);

              if (rowsUpdated == 0) {
                System.out.println("Failed to update, changes reverted");

                JOptionPane.showMessageDialog(
                    frame,
                    "Edit was invalid, please verify value is correct",
                    "SQL Error Encountered",
                    JOptionPane.ERROR_MESSAGE);

                // ((RidvTableModel)tableData).undoChange();
              }

            } catch (ArrayIndexOutOfBoundsException exception) {
              // Temp fix for data insertion bypass

            }
          }
        });
  }
Пример #10
0
 /**
  * Sets the preferred size of this panel.
  *
  * @param d the preferred size of this panel.
  */
 public void setPanelSize(Dimension d) {
   splitPane.setPreferredSize(d);
 }
  public OpetatorTreeDemo() {
    super(new GridLayout(1, 0));

    DefaultMutableTreeNode top = null;

    try {
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      System.out.println(classLoader.getResource("hive-default.xml"));
      System.out.println(classLoader.getResource("hive-site.xml"));
      HiveConf hiveConf = new HiveConf(SessionState.class);
      SessionState.start(new SessionState(hiveConf));
      Context ctx = new Context(hiveConf);
      ctx.setTryCount(10);
      ctx.setCmd(CommondDemo.command3);
      ctx.setHDFSCleanup(true);
      ParseDriver pd = new ParseDriver();
      ASTNode astTree = pd.parse(CommondDemo.command3, ctx);
      astTree = ParseUtils.findRootNonNullToken(astTree);
      SemanticAnalyzer sem = (SemanticAnalyzer) SemanticAnalyzerFactory.get(hiveConf, astTree);
      sem.analyze(astTree, ctx);
      sem.validate();
      List<Operator<? extends OperatorDesc>> topOpList =
          new ArrayList<Operator<? extends OperatorDesc>>(sem.topOps.values());
      if (topOpList.size() == 1) {
        top = createNodes(topOpList.get(0));
      } else {
        top = new DefaultMutableTreeNode("root");
        for (Operator<? extends OperatorDesc> op : topOpList) {
          top.add(createNodes(op));
        }
      }
    } catch (Exception e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    // Create a tree that allows one selection at a time.
    tree = new JTree(top);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes.
    tree.addTreeSelectionListener(this);

    if (playWithLineStyle) {
      System.out.println("line style = " + lineStyle);
      tree.putClientProperty("JTree.lineStyle", lineStyle);
    }

    // Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(tree);

    // Create the HTML viewing pane.
    htmlPane = new JEditorPane();
    htmlPane.setEditable(false);
    initHelp();
    JScrollPane htmlView = new JScrollPane(htmlPane);

    // Add the scroll panes to a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(treeView);
    splitPane.setBottomComponent(htmlView);

    Dimension minimumSize = new Dimension(100, 50);
    htmlView.setMinimumSize(minimumSize);
    treeView.setMinimumSize(minimumSize);
    splitPane.setDividerLocation(100);
    splitPane.setPreferredSize(new Dimension(500, 300));

    // Add the split pane to this panel.
    add(splitPane);
  }
Пример #12
0
  private void initGUI() {
    try {
      setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      this.setTitle("Klant");
      final JPanel topPanel = new JPanel();
      topPanel.setLayout(new BorderLayout());
      getContentPane().add(topPanel, BorderLayout.NORTH);
      topPanel.setPreferredSize(new java.awt.Dimension(842, 732));

      // create the internal frames
      createCustomerInternalFrame();
      createContactsInternalFrame();
      createAddressesInternalFrame();

      // build Contacts SplitPane
      {
        jSplitPaneContacts =
            new JSplitPane(
                JSplitPane.HORIZONTAL_SPLIT,
                jInternalFrameCustomerDetails,
                jInternalFrameCustomerContacts);
        jSplitPaneContacts.setPreferredSize(new java.awt.Dimension(840, 412));
      }

      // build General SplitPane (including contacts & addresses)
      {
        jSplitPaneCustomer =
            new JSplitPane(
                JSplitPane.VERTICAL_SPLIT, jSplitPaneContacts, jInternalFrameCustomerAddresses);
        topPanel.add(jSplitPaneCustomer, BorderLayout.CENTER);
        jSplitPaneCustomer.setPreferredSize(new java.awt.Dimension(842, 675));
      }

      {
        final JPanel buttonPanel = new JPanel();

        {
          jButtonCustomerWijzig = new JButton();
          buttonPanel.add(jButtonCustomerWijzig);
          jButtonCustomerWijzig.setText("OK");
          jButtonCustomerWijzig.setPreferredSize(new java.awt.Dimension(59, 32));
          jButtonCustomerWijzig.setFocusable(false);
          jButtonCustomerWijzig.setToolTipText("Gegevens bewaren");
          jButtonCustomerWijzig.addActionListener(
              new ActionListener() {
                public void actionPerformed(final ActionEvent evt) {
                  final StringBuilder errorMessages = new StringBuilder("");
                  if (validateInput(errorMessages)) {
                    saveInput();
                    enableAddressButton();
                    enableContactButton();
                  }
                  validateAddress(errorMessages);
                  validateContact(errorMessages);
                }
              });
        }
        topPanel.add(buttonPanel, BorderLayout.SOUTH);
        buttonPanel.setPreferredSize(new java.awt.Dimension(842, 77));
        {
          message = new JTextArea();
          resetMessage();
          buttonPanel.add(message);
          message.setFont(new java.awt.Font("Calibri", 0, 12));
          message.setEditable(false);
          message.setPreferredSize(new java.awt.Dimension(983, 21));
        }
      }

      pack();
      this.setSize(1539, 756);
      this.setLocationRelativeTo(parent);
      this.setModal(true);
      this.setVisible(true);
    } catch (final Exception e) {
      e.printStackTrace();
    }
  }
Пример #13
0
  /** Display the GUI */
  private void initGUI() {
    try {
      this.setTitle(PLUGIN_NAME + " - " + PLUGIN_VERSION);
      {
        jSplitPane1 = new JSplitPane();
        getContentPane().add(jSplitPane1, BorderLayout.CENTER);
        jSplitPane1.setPreferredSize(new java.awt.Dimension(500, 500));
        jSplitPane1.setDividerLocation(200);
        jSplitPane1.setResizeWeight(0.5);
        {
          jPanelRight = new JPanel();
          GridBagLayout jPanelRightLayout = new GridBagLayout();
          jPanelRightLayout.rowWeights = new double[] {0.0, 0.0, 0.5, 0.0};
          jPanelRightLayout.rowHeights = new int[] {7, 7, 7, 7};
          jPanelRightLayout.columnWeights = new double[] {0.0, 0.5, 0.0};
          jPanelRightLayout.columnWidths = new int[] {4, 7, 7};
          jSplitPane1.add(jPanelRight, JSplitPane.RIGHT);
          jPanelRight.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
          jPanelRight.setLayout(jPanelRightLayout);
          jPanelRight.setMinimumSize(new java.awt.Dimension(1, 1));
          {
            jButtonCancel = new JButton();
            jPanelRight.add(
                jButtonCancel,
                new GridBagConstraints(
                    0,
                    3,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.NONE,
                    new Insets(0, 10, 10, 0),
                    0,
                    0));
            jButtonCancel.setText("Quit");
            jButtonCancel.addActionListener(
                new ActionListener() {
                  // Close the GUI
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    quitGui();
                  }
                });
          }
          {
            jButtonOK = new JButton();
            jPanelRight.add(
                jButtonOK,
                new GridBagConstraints(
                    2,
                    3,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.NONE,
                    new Insets(0, 0, 10, 10),
                    0,
                    0));
            jButtonOK.setText("Parse");
            jButtonOK.setEnabled(false);
            jButtonOK.addActionListener(
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    boolean valid = checkValid();
                    if (valid) {
                      addCurrentExpressionToHistory();
                      launchCalculation();
                    }
                  }
                });
          }
          {
            jScrollPane1 = new JScrollPane();
            jPanelRight.add(
                jScrollPane1,
                new GridBagConstraints(
                    0,
                    2,
                    3,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH,
                    new Insets(10, 10, 10, 10),
                    0,
                    0));
            jScrollPane1.setOpaque(false);
            jScrollPane1.setBorder(null);
            jScrollPane1.getViewport().setOpaque(false);
            jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            {
              jTextAreaInfo = new JEditorPane();
              jTextAreaInfo.setBorder(null);
              jScrollPane1.setViewportView(jTextAreaInfo);
              jTextAreaInfo.setFont(new Font("Arial", Font.PLAIN, 10));
              jTextAreaInfo.setEditable(false);
              jTextAreaInfo.setOpaque(false);
              jTextAreaInfo.setContentType("text/html");
              jTextAreaInfo.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
            }
          }
        }
        {
          jPanelLeft = new JPanel();
          GridBagLayout jPanelLeftLayout = new GridBagLayout();
          jPanelLeftLayout.rowWeights = new double[] {0.0, 0.0, 1.0, 0.0};
          jPanelLeftLayout.rowHeights = new int[] {7, 7, -33, 50};
          jPanelLeftLayout.columnWeights = new double[] {0.1};
          jPanelLeftLayout.columnWidths = new int[] {7};
          jPanelLeft.setLayout(jPanelLeftLayout);
          jSplitPane1.add(jPanelLeft, JSplitPane.LEFT);
          jPanelLeft.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
          jPanelLeft.setPreferredSize(new java.awt.Dimension(198, 470));
          {
            jLabelExpression = new JLabel();
            jPanelLeft.add(
                jLabelExpression,
                new GridBagConstraints(
                    0,
                    0,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH,
                    new Insets(10, 10, 10, 0),
                    0,
                    0));
            jLabelExpression.setText("Expression:");
            jLabelExpression.setPreferredSize(new java.awt.Dimension(196, 16));
          }
          {
            expressionField = new JComboBox(expression_history);
            expressionField.setEditable(true);
            expressionField.setBorder(new LineBorder(new java.awt.Color(252, 117, 0), 1, false));
            expressionField.setSize(12, 18);
            jPanelLeft.add(
                expressionField,
                new GridBagConstraints(
                    0,
                    1,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH,
                    new Insets(10, 10, 10, 10),
                    0,
                    0));
            expressionField.addActionListener(
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    // Two action events are fired on edit: one for editing the textfield, one for
                    // changing
                    // the combo box selection. We only catch the edition.
                    if (e.getActionCommand().equalsIgnoreCase("comboBoxEdited")) {
                      boolean valid = checkValid();
                      if (valid) {
                        addCurrentExpressionToHistory();
                        launchCalculation();
                      }
                    }
                  }
                });
          }
          {
            jScrollPaneImages = new JScrollPane();
            jPanelLeft.add(
                jScrollPaneImages,
                new GridBagConstraints(
                    0,
                    2,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH,
                    new Insets(10, 0, 10, 0),
                    0,
                    0));
            jScrollPaneImages.setPreferredSize(new java.awt.Dimension(196, 267));
            jScrollPaneImages.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            jScrollPaneImages.getVerticalScrollBar().setUnitIncrement(20);
            {
              jPanelImages = new JPanel();
              jScrollPaneImages.setViewportView(jPanelImages);
              jPanelImages.setLayout(null);
              jPanelImages.setPreferredSize(new java.awt.Dimension(190, 45));
            }
          }
          {
            jPanelLeftButtons = new JPanel();
            jPanelLeft.add(
                jPanelLeftButtons,
                new GridBagConstraints(
                    0,
                    3,
                    1,
                    1,
                    0.0,
                    0.0,
                    GridBagConstraints.CENTER,
                    GridBagConstraints.BOTH,
                    new Insets(10, 0, 10, 0),
                    0,
                    0));
            jPanelLeftButtons.setLayout(null);
            jPanelLeftButtons.setPreferredSize(new java.awt.Dimension(196, 35));
            jPanelLeftButtons.setSize(196, 35);
            {
              jButtonPlus = new JButton();
              jPanelLeftButtons.add(jButtonPlus);
              jButtonPlus.setText("+");
              jButtonPlus.setBounds(9, -2, 35, 35);
              jButtonPlus.setFont(new java.awt.Font("Times New Roman", 0, 18));
              jButtonPlus.setOpaque(true);
              jButtonPlus.addActionListener(
                  new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      addImageBox();
                    }
                  });
            }
            {
              jButtonMinus = new JButton();
              jPanelLeftButtons.add(jButtonMinus);
              jButtonMinus.setText("—");
              jButtonMinus.setBounds(46, -2, 35, 35);
              jButtonMinus.setFont(new java.awt.Font("Arial", 0, 12));
              jButtonMinus.setOpaque(true);
              jButtonMinus.addActionListener(
                  new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      removeImageBox();
                    }
                  });
            }
          }
          jPanelLeft.addComponentListener(
              new ComponentListener() {
                public void componentShown(ComponentEvent e) {}

                public void componentResized(ComponentEvent e) {
                  refreshImageBoxes();
                }

                public void componentMoved(ComponentEvent e) {}

                public void componentHidden(ComponentEvent e) {}
              });
        }
      }
      pack();
      setSize(500, 500);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }