示例#1
0
  /**
   * Adds the componentType buttons to the Panel of Main Window.
   *
   * @param pkg_name whose componentType buttons will be added
   * @param a needed for the addition of the ActionListener of respective buttons and calling method
   *     of Pad_Draw
   */
  public void add_componentType_buttons(package_cls pkg_name, final counts a) {
    int i;
    JLabel pkg_hdng = new JLabel(pkg_name.getName());
    panel.add(pkg_hdng);
    for (i = 0; i < pkg_name.getComponentType_list().size(); i++) {
      final componentType cmp_Types = pkg_name.getComponentType_list().get(i);
      int btnHeight, btnWidth;
      double scale = 0.5;
      btnWidth = (int) (scale * (double) cmp_Types.getWidth());
      btnHeight = (int) (scale * (double) cmp_Types.getHeight());
      ImageIcon myIcon = new ImageIcon(cmp_Types.getType_Img());

      BufferedImage bi = new BufferedImage(btnWidth, btnHeight, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = bi.createGraphics();
      g.scale(scale, scale);
      myIcon.paintIcon(null, g, 0, 0);
      g.dispose();

      JButton strctButton = new JButton(new ImageIcon(bi));
      strctButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              drawPad.add_componentType(cmp_Types, a);
              taskbar.setText("Click to add a component");
            }
          });
      panel.add(strctButton);
    }
    panel.validate(); // Updates the Panel
  }
 private void clearDeleteRecord() {
   if (deleteList != null) {
     java.util.List list = deleteList.getSelection();
     if (list.size() > 0) {
       try {
         java.util.List dbIDs = new ArrayList(list.size());
         for (Iterator it = list.iterator(); it.hasNext(); ) {
           GKInstance instance = (GKInstance) it.next();
           dbIDs.add(instance.getDBID());
         }
         fileAdaptor.clearDeleteRecord(dbIDs);
       } catch (IOException e) {
         System.err.println("SynchronizationDialog.clearDeleteRecord(): " + e);
         e.printStackTrace();
       }
       deleteList.deleteInstances(list);
       // Check if deleteList needs to be removed
       if (deleteList.getDisplayedInstances().size() == 0) {
         centerPane.remove(deleteList);
         centerPane.validate();
         centerPane.repaint();
       }
     }
   }
 }
示例#3
0
 public void updateLastCustomer() {
   if (currentCustomer != null) {
     customerStateCheckBox.setSelected(currentCustomer.getGui().isHungry());
     customerStateCheckBox.setEnabled(!currentCustomer.getGui().isHungry());
     customerInformationPanel.validate();
   }
 }
示例#4
0
文件: InGame.java 项目: eR3tbvK/1.96
  public void drawPanel() {
    try {
      // System.out.println("right before the while loop of the thread");
      // layeredPane.add(background,99);

      panel.remove(layeredPane);
      Iterator<PlayerMob> allPlayers = players.iterator();
      PlayerMob aPlayer = null;
      /*while(allPlayers.hasNext()){
      	aPlayer = (PlayerMob) allPlayers.next();
      	//System.out.println("INTHELOOP:info.getUsername ="******" myChat.getUsername ="******"for loop index catch");
      	continue;
      }*/

    } catch (NullPointerException ed) {
      System.err.println("for loop null catch");
      // startDrawingPanelThread();
    } catch (Exception ev) {
      System.err.println("for loop catch");
      ev.printStackTrace();
    }
  }
  /**
   * This function takes the given customer or waiter object and changes the information panel to
   * hold that person's info.
   *
   * @param person customer or waiter object
   */
  public void updateInfoPanel(Object person) {
    stateCB.setVisible(true);
    changeOrder.setVisible(false);
    currentPerson = person;

    if (person instanceof CustomerAgent) {
      CustomerAgent customer = (CustomerAgent) person;
      stateCB.setText("Hungry?");
      changeOrder.setVisible(true);
      // changeOrder.setText("Change Order?");
      // changeOrder.setSelected(customer.waiter.requestingChange(customer));
      // changeOrder.setEnabled(!customer.waiter.requestingChange(customer));
      stateCB.setSelected(customer.isHungry());
      stateCB.setEnabled(!customer.isHungry());
      infoLabel.setText("<html><pre>     Name: " + customer.getName() + " </pre></html>");

    } else if (person instanceof WaiterAgent) {
      WaiterAgent waiter = (WaiterAgent) person;
      // stateCB.setText("On Break?");
      // stateCB.setSelected(waiter.isOnBreak());
      // stateCB.setEnabled(true);
      requestBreak.setVisible(true);
      stateCB.setVisible(false);
      changeOrder.setVisible(false);
      infoLabel.setText("<html><pre>     Name: " + waiter.getName() + " </html>");
    }

    infoPanel.validate();
  }
  private void resetSemImEditor() {
    java.util.List<SemEstimator> semEstimators = wrapper.getMultipleResultList();

    if (semEstimators.size() == 1) {
      SemEstimator estimatedSem = semEstimators.get(0);
      SemImEditor editor = new SemImEditor(new SemImWrapper(estimatedSem.getEstimatedSem()));
      panel.removeAll();
      panel.add(editor, BorderLayout.CENTER);
      panel.revalidate();
      panel.repaint();

    } else {
      JTabbedPane tabs = new JTabbedPane();

      for (int i = 0; i < semEstimators.size(); i++) {
        SemEstimator estimatedSem = semEstimators.get(i);
        SemImEditor editor = new SemImEditor(new SemImWrapper(estimatedSem.getEstimatedSem()));
        JPanel _panel = new JPanel();
        _panel.setLayout(new BorderLayout());
        _panel.add(editor, BorderLayout.CENTER);
        tabs.addTab(estimatedSem.getDataSet().getName(), _panel);
      }

      panel.removeAll();
      panel.add(tabs);
      panel.validate();
    }
  }
示例#7
0
 private void swapContainers(Container newContainer) {
   if (newContainer != null) {
     swappableContainer.removeAll();
     swappableContainer.add(newContainer);
     swappableContainer.repaint();
     swappableContainer.validate();
   }
 }
 private void removeInstanceList(InstanceListPane listPane) {
   SectionTitlePane titlePane = (SectionTitlePane) listToTitle.get(listPane);
   centerPane.remove(titlePane);
   centerPane.remove(listPane);
   centerPane.validate();
   centerPane.repaint();
   listToTitle.remove(listPane);
 }
示例#9
0
 /**
  * updateCustomerInformationPanel() takes the given customer (or, for v3, Host) object and changes
  * the information panel to hold that person's info.
  *
  * @param temp customer (or waiter) object
  */
 public void updateCustomerInformationPanel(Customer temp) {
   customerStateCheckBox.setVisible(true);
   currentCustomer = temp;
   Customer customer = temp;
   customerStateCheckBox.setText("Hungry?");
   customerStateCheckBox.setSelected(customer.getGui().isHungry());
   customerStateCheckBox.setEnabled(!customer.getGui().isHungry());
   infoCustomerLabel.setText("<html><pre>     Name: " + customer.getName() + " </pre></html>");
   customerInformationPanel.validate();
 }
示例#10
0
 /**
  * Remove the currently display gui and insert the given one.
  *
  * @param comp The new gui.
  */
 private void addToContents(JComponent comp) {
   handlerHolder.removeAll();
   comp.setPreferredSize(new Dimension(200, 300));
   handlerHolder.add(comp, BorderLayout.CENTER);
   if (myContents != null) {
     myContents.invalidate();
     myContents.validate();
     myContents.repaint();
   }
 }
 /** Listener to handle button actions */
 public void actionPerformed(ActionEvent e) {
   // Check if the user pressed the remove button
   if (e.getSource() == remove_button) {
     int row = table.getSelectedRow();
     model.removeRow(row);
     table.clearSelection();
     table.repaint();
     valueChanged(null);
   }
   // Check if the user pressed the remove all button
   if (e.getSource() == remove_all_button) {
     model.clearAll();
     table.setRowSelectionInterval(0, 0);
     table.repaint();
     valueChanged(null);
   }
   // Check if the user pressed the filter button
   if (e.getSource() == filter_button) {
     filter.showDialog();
     if (filter.okPressed()) {
       // Update the display with new filter
       model.setFilter(filter);
       table.repaint();
     }
   }
   // Check if the user pressed the start button
   if (e.getSource() == start_button) {
     start();
   }
   // Check if the user pressed the stop button
   if (e.getSource() == stop_button) {
     stop();
   }
   // Check if the user wants to switch layout
   if (e.getSource() == layout_button) {
     details_panel.remove(details_soap);
     details_soap.removeAll();
     if (details_soap.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
       details_soap = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
     } else {
       details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
     }
     details_soap.setTopComponent(request_panel);
     details_soap.setRightComponent(response_panel);
     details_soap.setResizeWeight(.5);
     details_panel.add(details_soap, BorderLayout.CENTER);
     details_panel.validate();
     details_panel.repaint();
   }
   // Check if the user is changing the reflow option
   if (e.getSource() == reflow_xml) {
     request_text.setReflowXML(reflow_xml.isSelected());
     response_text.setReflowXML(reflow_xml.isSelected());
   }
 }
 private void updateRozkladScrollPane() {
   mainPanel.remove(rozkladScrollPane);
   setRozkladScrollPane();
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.gridx = 2;
   c.gridy = 0;
   c.gridheight = 2;
   mainPanel.add(rozkladScrollPane, c);
   mainPanel.validate();
 }
  private void showAntView(boolean treeView) {
    AntOutputView oldView = getOutputView(treeView);
    AntOutputView newView = getOutputView(!treeView);
    myCurrentView = newView;
    myMessagePanel.remove(oldView.getComponent());
    myMessagePanel.add(newView.getComponent(), BorderLayout.CENTER);
    myMessagePanel.validate();

    JComponent component = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myMessagePanel);
    component.requestFocus();
    repaint();
  }
 void checkRunned() {
   if (runned) {
     list.selectAll(); // Add all clusters to Field again
     contentpanel.resetColors(); // Reset the colors
     PointCategory.resetIndex(); // Reset the point index
     field.reset(); // Reset the field
     updateContentPanel();
     empty.removeAll();
     empty.validate();
     runned = false;
   }
 }
  void updateList() {
    if (runned) {
      empty.removeAll();
      list = new CheckBoxList(field.getClusters(), field.getNoise(), this);

      JScrollPane sp = new JScrollPane();
      sp.getViewport().add(list);
      empty.add(sp);
      sp.repaint();
      empty.validate();
    }
  }
示例#16
0
  public void setCurrentLayout(int newId) {

    if (newId >= nviews) return;

    tabbedPane.removeAll();
    tabbedToolPanel.removeAll();
    String key;
    String currValue;
    JComponent obj;
    PushpinIF pobj;
    clearPushpinComp();
    for (int i = 0; i < keys.size(); i++) {
      key = (String) keys.get(i);
      currValue = (String) tp_paneInfo[newId].get(key);
      obj = (JComponent) panes.get(key);
      pobj = null;
      if (currValue.equals("yes") && obj != null) {
        if (obj instanceof PushpinIF) {
          pobj = (PushpinIF) obj;
          pobj.setAvailable(true);
          if (!pobj.isOpen()) {
            if (!pobj.isPopup()) obj = null;
          }
        }
        if (obj != null) {
          if (key.equals("Locator")) key = getLocatorName();
          tabbedPane.addTab(key, null, obj, "");
        }
        // tabbedPane.addTab(key, null, (JComponent)panes.get(key), "");
      }
    }

    if (tabbedPane.getTabCount() < 1) {
      pinPanel.setAvailable(false);
      pinPanel.setStatus("close");
      // setVisible(false);
      return;
    }

    pinPanel.setAvailable(true);
    pinPanel.setStatus("open");
    if (tabbedPane.getTabCount() == 1) {
      tabbedToolPanel.add(tabbedPane.getComponentAt(0));
      // tabbedToolPanel.add(tabbedPane);
    } else {
      tabbedToolPanel.add(tabbedPane);
    }
    setSelectedTab(tp_selectedTab, selectedTabName);

    tabbedToolPanel.validate();
    // repaint();
  }
 private void updateKierunekComboBox() {
   mainPanel.remove(kierunkiComboBox);
   setKierunekComboBox();
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.gridx = 1;
   c.gridy = 0;
   mainPanel.add(kierunkiComboBox, c);
   mainPanel.validate();
   if (trasa != null) {
     trasa = null;
   }
 }
 private void updatePrzystankiScrollPane() {
   mainPanel.remove(przystankiScrollPane);
   setPrzystankiScrollPane();
   GridBagConstraints c = new GridBagConstraints();
   c.fill = GridBagConstraints.HORIZONTAL;
   c.gridx = 0;
   c.gridy = 1;
   c.gridwidth = 2;
   mainPanel.add(przystankiScrollPane, c);
   mainPanel.validate();
   if (przystanek != null) {
     przystanek = null;
   }
 }
示例#19
0
 private void showHideFields() {
   if (typeSelection.getSelectedItem() == MappingTypes.LITERAL) {
     if (!literalEntry.isShowing()) {
       changeableContentContainer.remove(fieldDrop);
       changeableContentContainer.add(literalEntry);
     }
   } else {
     if (!fieldSelection.isShowing()) {
       changeableContentContainer.remove(literalEntry);
       changeableContentContainer.add(fieldDrop);
     }
   }
   changeableContentContainer.validate();
   changeableContentContainer.repaint();
 }
  public void update() {
    graphicPanel.removeAll();
    graphicPanel.add(title);
    graphicPanel.add(mainMenuButton);
    graphicPanel.add(refreshButton);
    graphicPanel.add(logoutButton);
    graphicPanel.setLayout(new FlowLayout());

    JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
    separator.setPreferredSize(new Dimension(600, 10));
    graphicPanel.add(separator);

    if (page.matches("main")) {
      graphicPanel.add(reportLocationButton);
      graphicPanel.add(loadShipmentButton);
    } else if (page.matches("reportloc")) {
      locationComboBox = new JComboBox(driver.getLocation().getNeighbours().toArray());
      graphicPanel.add(locationComboBox);
      graphicPanel.add(reportButton);
    } else if (page.matches("loadShipment")) {
      shipmentList = new ArrayList<Shipment>();

      for (int i = 0; i < driverService.getAssignedShipments().size(); ++i) {
        if (driverService.canPickup(driver, driverService.getAssignedShipments().get(i))) {
          shipmentList.add(driverService.getAssignedShipments().get(i));
        }
      }

      Object[][] tableContent = new Object[shipmentList.size()][shipmentTableColumnTitles.length];
      for (int i = 0; i < shipmentList.size(); ++i) {
        tableContent[i][0] = shipmentList.get(i).getType();
        tableContent[i][1] = shipmentList.get(i).getApproximateWeight();
        tableContent[i][2] = shipmentList.get(i).getDueDate();
        tableContent[i][3] = shipmentList.get(i).getDestination();
      }

      shipmentTable = new JTable(tableContent, shipmentTableColumnTitles);
      shipmentTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      JScrollPane tablePane = new JScrollPane(shipmentTable);
      tablePane.setPreferredSize(new Dimension(550, 250));
      graphicPanel.add(tablePane);
      graphicPanel.add(pickupButton);
    }

    graphicPanel.validate();
    graphicPanel.repaint();
  }
示例#21
0
文件: InGame.java 项目: eR3tbvK/1.96
  public void chat(JPanel panel) {
    this.panel = panel;
    userInterface = new UI(player);
    userInterface.chat(panel);

    AddKeyListener keyListener = new AddKeyListener();
    keyListener.setPlayer(player);

    keyListenerLayer = new JLayeredPane();
    keyListenerLayer.add(keyListener, 10);

    panel.add(BorderLayout.CENTER, keyListenerLayer);
    keyListener.setFocusable(true);
    keyListener.requestFocusInWindow();

    panel.add(BorderLayout.CENTER, layeredPane);
    panel.add(BorderLayout.SOUTH, userInterface.getChatPanel());
    panel.validate();
    panel.repaint();

    // initialize
    networkStartup.InGameChatInitialize(userInterface.getOutgoing(), userInterface.getIncoming());

    panel.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            keyListener.setFocusable(true);
            keyListener.requestFocusInWindow();
          }
        });

    userInterface
        .getOutgoing()
        .addActionListener(
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                networkStartup.InGameChatSendButtonListener(
                    userInterface.getOutgoing(), userInterface.getIncoming());
              }
            });

    // startDrawingPanelThread();

  }
示例#22
0
  public void PlaneNew(Plane p) {
    if (ATC.debug_flag) System.out.println("p.n.1");
    UIPlane uiplane = new UIPlane();
    char id = p.getIdChar();
    uiplane.radar_label = null;
    uiplane.info_label = new Label((new Character(id)).toString());
    if (ATC.debug_flag) System.out.println("p.n.2");
    infoArea.add(uiplane.info_label);
    if (ATC.debug_flag) System.out.println("p.n.2.1");
    infoArea.validate();
    if (ATC.debug_flag) System.out.println("p.n.3");
    synchronized (this) {
      planes.put((Object) (new Character(id)), (Object) uiplane);
    }

    if (ATC.debug_flag) System.out.println("p.n.4");
    PlaneUpdate(p);
    if (ATC.debug_flag) System.out.println("p.n.5");
  }
示例#23
0
  public void PlaneUpdate(Plane p) {
    if (ATC.debug_flag) System.out.println("p.u.1");
    char id = p.getIdChar();
    UIPlane uiplane = null;
    synchronized (this) {
      uiplane = (UIPlane) (planes.get((Object) (new Character(id))));
    }
    if (ATC.debug_flag) System.out.println("p.u.1 il=" + uiplane.info_label);
    if (uiplane == null) return;
    if (ATC.debug_flag) System.out.println("p.u.2");

    if (p.takeoff_flag) {
      if (uiplane.radar_label == null) {
        if (ATC.debug_flag) System.out.println("p.u.3");
        uiplane.radar_label = new JLabel(getPlaneText(p), dirToPlaneIcon(p.dir), JLabel.CENTER);
        uiplane.radar_label.setVerticalTextPosition(JLabel.TOP);
        uiplane.radar_label.setHorizontalTextPosition(JLabel.CENTER);
        uiplane.radar_label.setIconTextGap(text_gap);
        uiplane.radar_label.setForeground(text_color);
        radarArea.add(uiplane.radar_label, new Integer(2));
        if (ATC.debug_flag) System.out.println("p.u.4");
      } else {
        if (ATC.debug_flag) System.out.println("p.u.5");
        uiplane.radar_label.setText(getPlaneText(p));
        uiplane.radar_label.setIcon(dirToPlaneIcon(p.dir));
        if (ATC.debug_flag) System.out.println("p.u.6");
      }

      uiplane.radar_label.setBounds(
          convPos(p.pos.x) - plane_width / 2,
          convPos(p.pos.y) - plane_height + icon_size / 2,
          plane_width,
          plane_height);
      if (ATC.debug_flag) System.out.println("p.u.7");
    }

    uiplane.info_label.setText(getPlaneInfoText(p));
    if (ATC.debug_flag) System.out.println("p.u.8");
    infoArea.validate();

    if (ATC.debug_flag) System.out.println("p.u.9");
  }
 private void handleMergeResult(
     GKInstance localCopy, GKInstance dbCopy, InstanceComparisonPane comparisonPane) {
   if (comparisonPane.getSaveMergeOption() == InstanceComparisonPane.OVERWRITE_FIRST) {
     // Need to refresh the selected instance
     InstanceComparer comparer = new InstanceComparer();
     try {
       int result = comparer.compare(localCopy, dbCopy);
       if (result != InstanceComparer.IS_IDENTICAL) {
         typeMap.put(localCopy, mapCompareResultToString(result));
       } else {
         typeMap.remove(localCopy);
         changedList.deleteInstance(localCopy);
       }
       changedList.repaint();
     } catch (Exception e1) {
       System.err.println("SynchronizationDialog.handleMergeResult(): " + e1);
       e1.printStackTrace();
     }
   } else if (comparisonPane.getSaveMergeOption() == InstanceComparisonPane.SAVE_AS_NEW) {
     // Need to add a new instance to the local new instance
     GKInstance newInstance = comparisonPane.getMerged();
     List newInstances = (List) syncMap.get(NEW_KEY);
     if (newInstances == null) {
       newInstances = new ArrayList();
       syncMap.put(NEW_KEY, newInstances);
     }
     newInstances.add(newInstance);
     typeMap.put(newInstance, NEW_KEY);
     if (newList == null) {
       // Get some information from changed
       newList =
           initInstanceListPane(newInstances, "Instances created locally: " + newInstances.size());
       centerPane.validate();
     } else {
       // Cannot call this method because it is used for one schema class only
       // newList.addInstance(newInstance);
       newList.setTitle("Instances created locally: " + newInstances.size());
       newList.setDisplayedInstances(newInstances);
       newList.repaint();
     }
   }
 }
  public void updateResultTableTree(MongoResult mongoResult) {
    resultTableView =
        new JsonTreeTableView(
            JsonTreeModel.buildJsonTree(mongoResult), JsonTreeTableView.COLUMNS_FOR_READING);
    resultTableView.setName("resultTreeTable");

    resultTableView.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent mouseEvent) {
            if (mouseEvent.getClickCount() == 2 && MongoResultPanel.this.isSelectedNodeId()) {
              MongoResultPanel.this.editSelectedMongoDocument();
            }
          }
        });

    buildPopupMenu();

    resultTreePanel.invalidate();
    resultTreePanel.removeAll();
    resultTreePanel.add(new JBScrollPane(resultTableView));
    resultTreePanel.validate();
  }
示例#26
0
 public void setCommands(String[] names) {
   panel.removeAll();
   panel.add(Box.createHorizontalGlue());
   for (int i = 0; i < names.length; i++) {
     JButton b = new XButton("");
     if (shownames) b.setText(names[i]);
     else b.setToolTipText(names[i]);
     b.setActionCommand(names[i]);
     b.addActionListener(this);
     b.setMargin(new InsetsUIResource(0, 6, 0, 6));
     panel.add(b);
     if (i < names.length - 1) {
       if (isHorisontal()) {
         panel.add(Box.createHorizontalStrut(9));
       } else {
         panel.add(Box.createVerticalStrut(5));
       }
     }
     buttons.put(names[i], b);
   }
   setButtonsSize();
   panel.validate();
 }
示例#27
0
  public void setFrame() {
    f = new JFrame("数据通讯参数设置");
    // 获取屏幕分辨率的工具集
    Toolkit tool = Toolkit.getDefaultToolkit();
    // 利用工具集获取屏幕的分辨率
    Dimension dim = tool.getScreenSize();
    // 获取屏幕分辨率的高度
    int height = (int) dim.getHeight();
    // 获取屏幕分辨率的宽度
    int width = (int) dim.getWidth();
    // 设置位置
    f.setLocation((width - 300) / 2, (height - 400) / 2);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    f.setContentPane(this);
    f.setSize(320, 260);
    f.setResizable(false);

    lblIP = new JLabel("主机名");
    txtIp = new JTextField(20);
    try {
      InetAddress addr = InetAddress.getLocalHost();
      txtIp.setText(addr.getHostAddress().toString());
    } catch (Exception ex) {
    }

    lblNo = new JLabel("端口号");
    cmbNo = new JComboBox();
    cmbNo.setEditable(true);
    cmbNo.addPopupMenuListener(
        new PopupMenuListener() {
          @Override
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            cmbNo.removeAllItems();
            CommPortIdentifier portId = null;
            Enumeration portList;
            portList = CommPortIdentifier.getPortIdentifiers();
            while (portList.hasMoreElements()) {
              portId = (CommPortIdentifier) portList.nextElement();
              cmbNo.addItem(portId.getName());
            }
          }

          @Override
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }

          @Override
          public void popupMenuCanceled(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }
        });

    lblName = new JLabel("工程名");
    txtProjectName = new JComboBox();
    txtProjectName.setEditable(true);
    txtProjectName.addPopupMenuListener(
        new PopupMenuListener() {
          @Override
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            txtProjectName.removeAllItems();
            Mongo m1 = null;
            try {
              m1 = new Mongo(txtIp.getText().toString(), 27017);
            } catch (UnknownHostException ex) {
              ex.printStackTrace();
            }
            for (String name : m1.getDatabaseNames()) {
              txtProjectName.addItem(name);
            }
            m1.close();
          }

          @Override
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }

          @Override
          public void popupMenuCanceled(PopupMenuEvent e) {
            // To change body of implemented methods use File | Settings | File Templates.
          }
        });

    lblBote = new JLabel("波特率");
    cmbBote = new JComboBox();
    cmbBote.addItem(9600);
    cmbBote.addItem(19200);
    cmbBote.addItem(57600);
    cmbBote.addItem(115200);

    lblLength = new JLabel("数据长度");
    cmbLength = new JComboBox();
    cmbLength.addItem(8);
    cmbLength.addItem(7);

    lblParity = new JLabel("校验");
    cmbParity = new JComboBox();
    cmbParity.addItem("None");
    cmbParity.addItem("Odd");
    cmbParity.addItem("Even");

    lblStopBit = new JLabel("停止位");
    cmbStopBit = new JComboBox();
    cmbStopBit.addItem(1);
    cmbStopBit.addItem(2);

    lblDelay = new JLabel("刷新");
    txtDelay = new JTextField(20);

    btnOk = new JButton("确定");
    btnOk.addActionListener(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            paramIp = txtIp.getText().toString();
            paramName = txtProjectName.getSelectedItem().toString();
            paramNo = cmbNo.getSelectedItem().toString();
            paramBote = Integer.parseInt(cmbBote.getSelectedItem().toString());
            parmLength = Integer.parseInt(cmbLength.getSelectedItem().toString());
            parmParity = cmbParity.getSelectedIndex();
            parmStopBit = Integer.parseInt(cmbStopBit.getSelectedItem().toString());
            parmDelay = Integer.parseInt(txtDelay.getText().toString());

            if (!paramName.equals("") && !paramNo.equals("")) {
              receiveData(
                  paramIp,
                  paramName,
                  paramNo,
                  paramBote,
                  parmLength,
                  parmParity,
                  parmStopBit,
                  parmDelay);
            } else {

            }
          }
        });
    btnCancel = new JButton("取消");
    btnCancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(9, 2));

    p1.add(lblIP);
    p1.add(txtIp);

    p1.add(lblNo);
    p1.add(cmbNo);

    p1.add(lblName);
    p1.add(txtProjectName);

    p1.add(lblBote);
    p1.add(cmbBote);

    p1.add(lblLength);
    p1.add(cmbLength);

    p1.add(lblParity);
    p1.add(cmbParity);

    p1.add(lblStopBit);
    p1.add(cmbStopBit);

    p1.add(lblDelay);
    p1.add(txtDelay);
    txtDelay.setText("500");

    p1.add(btnOk);
    p1.add(btnCancel);

    p1.validate();

    f.add(p1);
    f.validate();
  }
示例#28
0
  protected void buildErrorPanel() {
    errorPanel = new JPanel();
    GroupLayout layout = new GroupLayout(errorPanel);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    errorPanel.setLayout(layout);
    //    errorPanel.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK));
    errorMessage = new JTextPane();
    errorMessage.setEditable(false);
    errorMessage.setContentType("text/html");
    errorMessage.setText(
        "<html><body>Could not connect to the Processing server.<br>"
            + "Contributions cannot be installed or updated without an Internet connection.<br>"
            + "Please verify your network connection again, then try connecting again.</body></html>");
    errorMessage.setFont(Toolkit.getSansFont(14, Font.PLAIN));
    errorMessage.setMaximumSize(new Dimension(550, 50));
    errorMessage.setOpaque(false);

    StyledDocument doc = errorMessage.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
    doc.setParagraphAttributes(0, doc.getLength(), center, false);

    closeButton = new JButton("X");
    closeButton.setContentAreaFilled(false);
    closeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            contribDialog.makeAndShowTab(false, false);
          }
        });
    tryAgainButton = new JButton("Try Again");
    tryAgainButton.setFont(Toolkit.getSansFont(14, Font.PLAIN));
    tryAgainButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            contribDialog.makeAndShowTab(false, true);
            contribDialog.downloadAndUpdateContributionListing(editor.getBase());
          }
        });
    layout.setHorizontalGroup(
        layout
            .createSequentialGroup()
            .addPreferredGap(
                LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
            .addGroup(
                layout
                    .createParallelGroup(GroupLayout.Alignment.CENTER)
                    .addComponent(errorMessage)
                    .addComponent(
                        tryAgainButton,
                        StatusPanel.BUTTON_WIDTH,
                        StatusPanel.BUTTON_WIDTH,
                        StatusPanel.BUTTON_WIDTH))
            .addPreferredGap(
                LayoutStyle.ComponentPlacement.RELATED, GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
            .addComponent(closeButton));
    layout.setVerticalGroup(
        layout
            .createSequentialGroup()
            .addGroup(
                layout.createParallelGroup().addComponent(errorMessage).addComponent(closeButton))
            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(tryAgainButton));
    errorPanel.setBackground(Color.PINK);
    errorPanel.validate();
  }
示例#29
0
  // *********************************************CONSTRUCTOR METHOD
  public EPoverty() throws IOException {
    UIManager.put("Button.select", Color.BLACK);

    // ******************************************CREATE MAIN PANEL
    setTitle("|||E-Poverty || V-0.1 (SKELETON)|||");
    setSize(500, 275);
    setLocation(500, 200);
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    mainPanel = new JPanel();
    setContentPane(mainPanel);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
    // ******************************************END OF CREATING MAIN PANEL

    /* CREATE THE TOP AND BOTTOM PANELS, ADDING BACKGROUND IMAGES
     *
     * BackgroundPanel is an extension to JPanel that makes it easy to
     * paint images as a background on the panel, or add a gradient
     * fill as the background (this is what you currently see on the
     * back of all the tabs.  The constructors can be seen in the
     * BackgroundPanel.java class if you need or want to use them.
     */
    BackgroundPanel topPanel = new BackgroundPanel(background);
    Dimension top = new Dimension(500, 125);
    topPanel.setPreferredSize(top);
    GradientPaint paintTop = new GradientPaint(0, 0, Color.DARK_GRAY, 100, 100, Color.BLACK);
    topPanel.setPaint(paintTop);

    BackgroundPanel bottomPanel = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);
    Dimension bottom = new Dimension(500, 75);
    bottomPanel.setPreferredSize(bottom);
    GradientPaint paintBottom = new GradientPaint(50, 200, Color.WHITE, 100, 50, Color.BLACK);
    bottomPanel.setPaint(paintBottom);

    // *******************************************ADD PANELS TO THE MAIN
    mainPanel.add(topPanel);
    mainPanel.add(bottomPanel);

    // ******************************************ADD COMPONENTS TO THE BOTTOM PANEL
    bottomPanel.setLayout(new GridBagLayout());
    GridBagConstraints gBC = new GridBagConstraints();
    gBC.fill = GridBagConstraints.HORIZONTAL;

    // *****************************************FIRST ROW (BLANK)
    JLabel blank = new JLabel("");
    gBC.weightx = 1;
    gBC.weighty = 1;
    gBC.gridx = 0;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 2;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 3;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 4;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 5;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    // *****************************************SECOND ROW (LOGIN)
    blank = new JLabel("LOGIN");
    gBC.gridx = 1;
    gBC.gridy = 1;
    gBC.gridheight = 2;
    gBC.gridwidth = 2;
    blank.setForeground(Color.WHITE);
    blank.setFont(new Font("Serif", Font.PLAIN, 16));
    bottomPanel.add(blank, gBC);
    blank.setHorizontalTextPosition(SwingConstants.RIGHT);

    login_TF = new JTextField("*****@*****.**");
    gBC.gridx = 3;
    gBC.gridy = 1;
    login_TF.setEditable(true);
    login_TF.setBackground(Color.WHITE);
    login_TF.setFont(new Font("Serif", Font.PLAIN, 16));
    login_TF.setForeground(Color.LIGHT_GRAY);
    bottomPanel.add(login_TF, gBC);
    login_TF.requestFocusInWindow();

    // ******************************************THIRD ROW (PASSWORD)
    blank = new JLabel("PASSWORD");
    gBC.gridx = 1;
    gBC.gridy = 3;
    blank.setForeground(Color.WHITE);
    blank.setFont(new Font("Serif", Font.PLAIN, 16));
    blank.setHorizontalTextPosition(JLabel.RIGHT);
    bottomPanel.add(blank, gBC);

    password_TF = new JPasswordField("password");
    gBC.gridx = 3;
    gBC.gridy = 3;
    password_TF.setEditable(true);
    password_TF.setForeground(Color.WHITE);
    password_TF.setFont(new Font("Serif", Font.PLAIN, 16));
    bottomPanel.add(password_TF, gBC);

    // *****************************************FOURTH ROW (BLANK)
    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 3;
    gBC.gridheight = 1;
    bottomPanel.add(blank, gBC);

    // *****************************************FIFTH ROW (BUTTONS)
    JButton login_BTN = new JButton("");
    gBC.gridx = 3;
    gBC.gridy = 5;
    gBC.gridwidth = 1;
    login_BTN.setIcon(new ImageIcon(login));
    login_BTN.setMargin(new Insets(0, 0, 0, 0));
    login_BTN.setBackground(Color.LIGHT_GRAY);
    login_BTN.setRolloverEnabled(false);
    login_BTN.setFocusPainted(false);
    login_BTN.setContentAreaFilled(false);
    bottomPanel.add(login_BTN, gBC);

    JButton settings_BTN = new JButton("Settings");
    gBC.gridx = 5;
    gBC.gridy = 5;
    gBC.gridheight = 3;
    settings_BTN.setIcon(new ImageIcon(settings));
    settings_BTN.setMargin(new Insets(0, 0, 0, 0));
    settings_BTN.setHorizontalAlignment(SwingConstants.RIGHT);
    settings_BTN.setVerticalTextPosition(SwingConstants.CENTER);
    settings_BTN.setHorizontalTextPosition(SwingConstants.LEFT);
    settings_BTN.setBackground(Color.LIGHT_GRAY);
    settings_BTN.setBorderPainted(false);
    settings_BTN.setRolloverEnabled(false);
    settings_BTN.setFocusPainted(false);
    settings_BTN.setContentAreaFilled(false);
    bottomPanel.add(settings_BTN, gBC);

    // *****************************************SIXTH ROW (BLANK)
    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 5;
    bottomPanel.add(blank, gBC);

    // This makes sure all components are painted on the screen correctly
    mainPanel.validate();

    // ADD AN ACTION LISTENER TO THE BUTTON THAT WILL CHECK THE LOGIN INFO AND LOG INTO THE DATABASE
    login_BTN.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String passwordHash = "";
            // Hash the password for comparison
            try {
              passwordHash = SimpleSHA1.SHA1(password_TF.getText());
            } catch (NoSuchAlgorithmException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedEncodingException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }

            String checkAdminSQL =
                "SELECT p.password FROM persons AS p, admins AS a "
                    + "WHERE p.personId = a.personId "
                    + "AND p.emailAddress = \""
                    + login_TF.getText()
                    + "\" ";

            try {
              // *********************************CHECK LOGIN AND PASSWORD
              new DBconnection(url, driver, dbLogin, dbPassword);
              conn = DBconnection.getConnection();
              PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(checkAdminSQL);
              ResultSet rs = (ResultSet) stmt.executeQuery();

              // IF THERE IS NO NEXT RECORD, E-MAIL IS NOT THAT OF AN ADMIN
              if (!rs.next()) {
                new Warnings("You do not have login rights.");
              } else {
                String dbPass = rs.getObject(1).toString();

                // CHECK VALUE OF RETURNED PASSWORD TO VALUE ENTERED
                if (dbPass.equals(passwordHash)) {
                  try {
                    new EPovertyMain();
                    EPovertyMain.updateStatus("Logged in");
                    dispose();

                  } catch (IOException ex) {
                    Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
                  }
                } else {
                  new Warnings("Incorrect Password.");
                }
              }

              rs.close();
              stmt.close();
              DBconnection.closeConnection();

            } catch (ClassNotFoundException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }); // END OF LOGIN BUTTON LISTENER

    settings_BTN.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              new Settings();
            } catch (ClassNotFoundException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }); // END OF SETTINGS BUTTON LISTENER
  }
示例#30
0
  @Override
  public void actionPerformed(ActionEvent actionEvent) {
    Object obj = actionEvent.getSource();

    if (obj == btFindPat) {

      testpanel.removeAll();
      validate();
      repaint();
      if (taDictionary.getText().isEmpty()) {
        JOptionPane.showMessageDialog(
            frame, "Please load words so they appear in Text Area before Finding Path. ");

      } else if ((tfSourc.getText().isEmpty()) || (tfSourc_6.getText().isEmpty())) {
        JOptionPane.showMessageDialog(
            frame, "Please enter Source and Destination words before Finding Path. ");
      } else if (testpanel.getComponents().length != 0) {
        JOptionPane.showMessageDialog(frame, "Please clear results before continuing.");
      } else {
        wordLadder.findPath(
            tfSourc.getText(), tfSourc_6.getText(), Integer.parseInt(tfWordSize.getText()));
        lblFindPat.setText(
            "Time to find Path: " + String.valueOf(wordLadder.getTimeForPath()) + " milliseconds");
        lblCos.setText("Cost of Path: " + String.valueOf(wordLadder.g.getCost()));
        results = wordLadder.getResults();
        Collections.reverse(results);
        int x = 10;
        int y = 20;

        for (String s : results) {
          x += 20;
          y += 20;
          JLabel _lbl = new JLabel(s);
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);

          if (results.indexOf(s) == 0) {
            _lbl.setForeground(new Color(-14646771));
          } else if (results.indexOf(s) == (results.size() - 1)) {
            _lbl.setForeground(new Color(-8254711));
          } else {
            _lbl.setForeground(new Color(-16777216));
          }
          testpanel.add(_lbl);
          testpanel.repaint();
        }
        if (wordLadder.g.getCost() == 0) {
          // if (wordLadder.g.getGraphError() != null){
          JLabel _lbl = new JLabel(wordLadder.g.getGraphError());
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);
          testpanel.add(_lbl);
          testpanel.repaint();
          // }

        }
      }
      /*if (taDictionary.getText().isEmpty()){
      wordLadder = new WordLadder(tfFilePat.getText(), tfSourc.getText(), tfSourc_6.getText());
       }else if (!taDictionary.getText().isEmpty()){
          ArrayList<String> taList = new ArrayList<String>();
          StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
          while (stringTokenizer.hasMoreTokens()) {
              String token = stringTokenizer.nextToken();
              taList.add(token);
          }
        */
      // }
    }

    if (obj == btLoadFil) {
      clearData();
      // wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      // String size = tfWordSize.getText();
      // int intSize = Integer.parseInt(size);
      // WordLadderGUI.showMessage("Loading words of" + tfWordSize.getText() + " characters from
      // file: " + tfFilePat.getText(), Color.GREEN, Color.GREEN);
      lblIndexing1.setText("Indexing...");
      System.out.println(
          "Loading words of "
              + tfWordSize.getText()
              + " characters from file: "
              + tfFilePat.getText());
      wordLadder = new WordLadder(tfFilePat.getText(), Integer.parseInt(tfWordSize.getText()));
      // wordLadder.
      guiDictionary = new WordCollection(wordLadder.getWordList());
      WordLadderGUI.showMessage(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText(),
          Color.GREEN,
          Color.GREEN);
      System.out.println(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText());
      taDictionary.setText(guiDictionary.toString());
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }

    if (obj == btLoadTextFiel) {
      wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      String taDump = taDictionary.getText();
      System.out.println("Loading Words from Text Area");
      lblIndexing1.setText("Indexing...");
      ArrayList<String> taList = new ArrayList<String>();
      StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
      while (stringTokenizer.hasMoreTokens()) {
        String token = stringTokenizer.nextToken();
        taList.add(token);
      }
      guiDictionary = new WordCollection();
      guiDictionary.setWords(taList);
      wordLadder = new WordLadder(taList);
      WordLadderGUI.showMessage(
          "Loading " + wordLadder.getWordList().size() + " words from Text Field",
          Color.GREEN,
          Color.GREEN);
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }
    if (obj == btClear) {
      testpanel.removeAll();
      testpanel.validate();
      testpanel.repaint();
      wordLadder = null;
      lblCos.setText("Cost of Path: 0.0");
      lblCos.repaint();
      lblDictCoun.setText("Words in Dictionary = 0 words");
      lblFindPat.setText("Time to find Path: 0 milliseconds");
      tfSourc.setText("");
      tfSourc_6.setText("");
      taDictionary.setText("");
      results = null;
      lblProgres.setText("Time to Build Graph: 0 milliseconds");
    }
  }