@Override
  public void mouseClicked(MouseEvent e) {
    Component theChosenOne = e.getComponent();

    System.out.println(theChosenOne.getName());

    remove(portalPanel);

    GuideChangeSettings guidance = new GuideChangeSettings(theChosenOne.getName());
    add(guidance);
  }
  /**
   * method to negotiate draganddrop when mouse is pressed
   *
   * @param e
   */
  public void mousePressed(MouseEvent e) {
    /** Set up click point and set ActivePanel */
    Point p = e.getPoint();
    System.out.println(p);
    if (!setActivePanel(p)) return;

    /** record where the initial click occurred */
    OriP = activePanel;

    /** Check whether click was over an image label */
    selectedComponent = getImageLabel(p);
    if (selectedComponent == null) return;

    /** Check whether click was over waste box */
    if (selectedComponent.getName().equals("WasteBox")) return;

    /**
     * remove selected component from active panel add it to the glass panel set the offset and
     * original position
     */
    Rectangle labelR = selectedComponent.getBounds();
    Rectangle panelR = activePanel.getBounds();
    //  if(labelR.contains(p.x - panelR.x, p.y - panelR.y))
    //  {
    activePanel.remove(selectedComponent);
    selected = true;
    glassPanel.add(selectedComponent);
    offset.x = p.x - labelR.x - panelR.x;
    offset.y = p.y - labelR.y - panelR.y;
    dragging = true;
    Original = labelR.getLocation();
    //  }
  }
Exemple #3
0
  /**
   * We generally draw lines to/from the <I>center</I> of components; this method finds the center
   * of the argument's enclosing rectangle
   *
   * @return Point at the center of <CODE>c</CODE>
   * @param c The component whose center point we wish to determine
   */
  protected Point getCenterLocation(Component c) {

    Point p1 = new Point();
    Point p2 = new Point();

    // start with the relative location...
    c.getLocation(p1);
    // get to the middle of the fractionsLabel
    Dimension d = c.getSize();
    p1.x += d.width / 2;
    p1.y += d.height / 2;

    Component parent = c.getParent();
    // System.err.println("parent=" + parent);

    while (parent != null) {
      parent.getLocation(p2);
      p1.x += p2.x;
      p1.y += p2.y;

      if (STOP.equals(parent.getName())) break;

      parent = parent.getParent();
    }
    return p1;
  }
 @Override
 public void actionPerformed(ActionEvent ev) {
   Component component = (Component) ev.getSource();
   final String componentName = component.getName();
   switch (componentName) {
     case SAVE_MENU_ITEM_NAME:
     case SAVE_AS_MENU_ITEM_NAME:
       boolean mustChooseFile = SAVE_AS_MENU_ITEM_NAME.equals(componentName);
       saveToDisk(mustChooseFile);
       break;
     case NEW_MENU_ITEM_NAME:
     case OPEN_MENU_ITEM_NAME:
       showSaveConfirmationIfNecessaryAndRun(
           "You have changes on your current document. Save before continuing?",
           componentName,
           new Runnable() {
             @Override
             public void run() {
               if (NEW_MENU_ITEM_NAME.equals(componentName)) {
                 setSpreadsheet(new Spreadsheet());
                 setCurrentFile(null);
               } else { // open
                 Path chosenFile = chooseFile(JFileChooser.OPEN_DIALOG);
                 openSpreadsheet(chosenFile);
               }
             }
           });
       break;
     case COPY_MENU_ITEM_NAME:
       Object displayValue =
           mCellDisplayValueManager.getDisplayValueOfCellAt(getSelectedCellLocation());
       if (!"".equals(displayValue)) {
         Transferable contents = new StringSelection(displayValue.toString());
         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
       }
       break;
     case COPY_FORMULA_MENU_ITEM_NAME:
       String cellContent = mSpreadsheet.getCellContentAt(getSelectedCellLocation());
       if (cellContent != null) {
         Transferable contents = new StringSelection(cellContent);
         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
       }
       break;
     case PASTE_MENU_ITEM_NAME:
       Transferable clipboard =
           Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
       CellLocation selectedLocation = getSelectedCellLocation();
       try {
         Object transferData = clipboard.getTransferData(DataFlavor.stringFlavor);
         mTableModel.setValueAt(
             transferData.toString(), selectedLocation.getRow(), selectedLocation.getColumn());
       } catch (UnsupportedFlavorException | IOException ex) {
         // we can only use the string flavor anyway, nothing we can do here
       }
       break;
   }
 }
Exemple #5
0
 /**
  * Returns the value to initialize the opacity property of the Component to. A Style should NOT
  * assume the opacity will remain this value, the developer may reset it or override it.
  *
  * @param context SynthContext identifying requestor
  * @return opaque Whether or not the JComponent is opaque.
  */
 @Override
 public boolean isOpaque(SynthContext context) {
   Region region = context.getRegion();
   if (region == Region.COMBO_BOX
       || region == Region.DESKTOP_PANE
       || region == Region.DESKTOP_ICON
       || region == Region.EDITOR_PANE
       || region == Region.FORMATTED_TEXT_FIELD
       || region == Region.INTERNAL_FRAME
       || region == Region.LIST
       || region == Region.MENU_BAR
       || region == Region.PANEL
       || region == Region.PASSWORD_FIELD
       || region == Region.POPUP_MENU
       || region == Region.PROGRESS_BAR
       || region == Region.ROOT_PANE
       || region == Region.SCROLL_PANE
       || region == Region.SPINNER
       || region == Region.SPLIT_PANE_DIVIDER
       || region == Region.TABLE
       || region == Region.TEXT_AREA
       || region == Region.TEXT_FIELD
       || region == Region.TEXT_PANE
       || region == Region.TOOL_BAR_DRAG_WINDOW
       || region == Region.TOOL_TIP
       || region == Region.TREE
       || region == Region.VIEWPORT) {
     return true;
   }
   Component c = context.getComponent();
   String name = c.getName();
   if (name == "ComboBox.renderer" || name == "ComboBox.listRenderer") {
     return true;
   }
   return false;
 }