public void componentMoved(ComponentEvent evt) {
   Component component = evt.getComponent();
   Point point = component.getLocation();
   if (point.y < 0) {
     component.setBounds(point.x, 0, component.getWidth(), component.getHeight());
   }
 }
 public void handle(MsgTimeout event) {
   logger.info("Msg timeout");
   trigger(new Stop(), client.getControl());
   trigger(new Stop(), server.getControl());
   testObj.testStatus = false;
   testObj.failAndRelease();
 }
Beispiel #3
0
 public static void hidePopups(Component comp) {
   if (comp != null) {
     label0:
     for (Component c = comp; c != null; c = c.getParent()) {
       if (!(c instanceof ZPopupGallery)) continue;
       do {
         if (currShownList.size() <= 0) continue label0;
         if (currShownList.getLast() == c) return;
         ZPopupGallery jpg = (ZPopupGallery) currShownList.removeLast();
         Popup popup = (Popup) popupGalleryHM.get(jpg);
         popup.hide();
         popupGalleryHM.remove(jpg);
       } while (true);
     }
   }
   Iterator iterator = popupGalleryHM.keySet().iterator();
   do {
     if (!iterator.hasNext()) break;
     ZPopupGallery gallery = (ZPopupGallery) iterator.next();
     ((Popup) popupGalleryHM.get(gallery)).hide();
     if (gallery.getActionListener() != null)
       gallery.getActionListener().actionPerformed(new ActionEvent(gallery, 1, "Hidden"));
   } while (true);
   popupGalleryHM.clear();
 }
 private static void drawSelection(JTree tree, Graphics g, final int width) {
   int y = 0;
   final int[] rows = tree.getSelectionRows();
   final int height = tree.getRowHeight();
   for (int row : rows) {
     final TreeCellRenderer renderer = tree.getCellRenderer();
     final Object value = tree.getPathForRow(row).getLastPathComponent();
     if (value == null) continue;
     final Component component =
         renderer.getTreeCellRendererComponent(tree, value, false, false, false, row, false);
     if (component.getFont() == null) {
       component.setFont(tree.getFont());
     }
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
 @SuppressWarnings({"HardCodedStringLiteral"})
 private Element writePanel(final JPanel panel) {
   final Component comp = panel.getComponent(0);
   if (comp instanceof Splitter) {
     final Splitter splitter = (Splitter) comp;
     final Element res = new Element("splitter");
     res.setAttribute("split-orientation", splitter.getOrientation() ? "vertical" : "horizontal");
     res.setAttribute("split-proportion", Float.toString(splitter.getProportion()));
     final Element first = new Element("split-first");
     first.addContent(writePanel((JPanel) splitter.getFirstComponent()));
     final Element second = new Element("split-second");
     second.addContent(writePanel((JPanel) splitter.getSecondComponent()));
     res.addContent(first);
     res.addContent(second);
     return res;
   } else if (comp instanceof JBTabs) {
     final Element res = new Element("leaf");
     final EditorWindow window = findWindowWith(comp);
     writeWindow(res, window);
     return res;
   } else if (comp instanceof EditorWindow.TCompForTablessMode) {
     final EditorWithProviderComposite composite =
         ((EditorWindow.TCompForTablessMode) comp).myEditor;
     final Element res = new Element("leaf");
     writeComposite(res, composite.getFile(), composite, false, composite);
     return res;
   } else {
     LOG.error(comp != null ? comp.getClass().getName() : null);
     return null;
   }
 }
Beispiel #6
0
  /*
   * Fix for BugTraq ID 4041703.
   * Set the focus to a reasonable default for an Applet.
   */
  private void setDefaultFocus() {
    Component toFocus = null;
    Container parent = getParent();

    if (parent != null) {
      if (parent instanceof Window) {
        toFocus = getMostRecentFocusOwnerForWindow((Window) parent);
        if (toFocus == parent || toFocus == null) {
          toFocus = parent.getFocusTraversalPolicy().getInitialComponent((Window) parent);
        }
      } else if (parent.isFocusCycleRoot()) {
        toFocus = parent.getFocusTraversalPolicy().getDefaultComponent(parent);
      }
    }

    if (toFocus != null) {
      if (parent instanceof EmbeddedFrame) {
        ((EmbeddedFrame) parent).synthesizeWindowActivation(true);
      }
      // EmbeddedFrame might have focus before the applet was added.
      // Thus after its activation the most recent focus owner will be
      // restored. We need the applet's initial focusabled component to
      // be focused here.
      toFocus.requestFocusInWindow();
    }
  }
 public void
     setColumnWidths() { // See
                         // "http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#custom"
   int n = getModel().getColumnCount();
   for (int j = 0; j < n; ++j) {
     TableColumn column = getColumnModel().getColumn(j);
     TableCellRenderer headerRenderer = column.getHeaderRenderer();
     if (headerRenderer == null)
       headerRenderer = getTableHeader().getDefaultRenderer(); // the new 1.3 way
     Component columnComponent =
         headerRenderer.getTableCellRendererComponent(
             this, column.getHeaderValue(), false, false, -1, j);
     Component cellComponent =
         getDefaultRenderer(getColumnClass(j))
             .getTableCellRendererComponent(this, getModel().getValueAt(0, j), false, false, 0, j);
     int wantWidth =
         Math.max(
             columnComponent.getPreferredSize().width
                 + 10, // fudge factor ... seems to always be too small otherwise (on x86 Linux)
             cellComponent.getPreferredSize().width
                 + 10 // fudge factor ... seems to always be too small otherwise (on Mac OS X)
             );
     column.setPreferredWidth(wantWidth);
   }
 }
Beispiel #8
0
  public void enableControlPanel() {
    boolean bVisible = false;

    int nmembers = buttonPane.getComponentCount();
    for (int k = 0; k < nmembers; k++) {
      Component comp = buttonPane.getComponent(k);
      if (comp != null) {
        if (comp.isVisible() || comp.isEnabled()) {
          bVisible = true;
          break;
        }
      }
    }

    if (bVisible && !buttonPane.isVisible()) {
      Dimension dim = getSize();
      Dimension dim1 = buttonPane.getPreferredSize();
      int w = dim.width;
      int h = dim.height + dim1.height;
      if (dim1.width > w) w = dim1.width;
      if (w < 300) w = 300;
      if (h < 200) h = 200;
      setSize(w, h);
    }
    buttonPane.setVisible(bVisible);
  }
  @Override
  public void mouseMoved(MouseEvent e) {
    Component source = e.getComponent();
    Point location = e.getPoint();
    direction = 0;

    if (location.x < dragInsets.left) direction += WEST;

    if (location.x > source.getWidth() - dragInsets.right - 1) direction += EAST;

    if (location.y < dragInsets.top) direction += NORTH;

    if (location.y > source.getHeight() - dragInsets.bottom - 1) direction += SOUTH;

    //  Mouse is no longer over a resizable border

    if (direction == 0) {
      source.setCursor(sourceCursor);
    } else // use the appropriate resizable cursor
    {
      int cursorType = cursors.get(direction);
      Cursor cursor = Cursor.getPredefinedCursor(cursorType);
      source.setCursor(cursor);
    }
  }
Beispiel #10
0
 /**
  * Create possibly volatile scratch image for fast painting. A scratch image can become
  * invalidated, when this happens any actions involving it are ignored, and it needs to be
  * recreated. Use isScratchImageValid() to check this.
  */
 public static Image createScratchImage(int width, int height) {
   try {
     Image img =
         (Image)
             tryMethod(
                 output_comp,
                 "createVolatileImage",
                 new Object[] {new Integer(width), new Integer(height)});
     if (img == null) {
       // no such method -> create regular image
       return output_comp.createImage(width, height);
     }
     // if (img.validate(output_comp.getGraphicsConfiguration())
     // == VolatileImage.IMAGE_INCOMPATIBLE) {
     GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice gs = ge.getDefaultScreenDevice();
     GraphicsConfiguration gc = gs.getDefaultConfiguration();
     Integer valid = (Integer) tryMethod(img, "validate", new Object[] {gc});
     // output_comp.getGraphicsConfiguration() });
     if (valid.intValue() == 2) { // I checked, IMAGE_INCOMPATIBLE=2
       // Hmm, somehow it didn't work. Create regular image.
       return output_comp.createImage(width, height);
     }
     return img;
   } catch (java.security.AccessControlException e) {
     // we're not allowed to do this (we're probably an applet)
     return output_comp.createImage(width, height);
   }
 }
 @Override
 public void handle(PortDeleteResponse event) {
   logger.info("Received PortDeleteResponse");
   trigger(new Stop(), client.getControl());
   trigger(new Stop(), server.getControl());
   testObj.pass();
 }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   final Module module = value instanceof Module ? (Module) value : null;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     if (module != null) {
       setText(
           module.getName()
               + " ("
               + FileUtil.toSystemDependentName(module.getModuleFilePath())
               + ")");
     }
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   component.setEnabled(ProcessedModulesTable.this.isEnabled());
   if (component instanceof JLabel) {
     final Icon icon = module != null ? ModuleType.get(module).getIcon() : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   return component;
 }
 @Override
 public void mouseExited(MouseEvent e) {
   if (!resizing) {
     Component source = e.getComponent();
     source.setCursor(sourceCursor);
   }
 }
  @Override
  public void mousePressed(MouseEvent e) {
    //	The mouseMoved event continually updates this variable

    if (direction == 0) return;

    //  Setup for resizing. All future dragging calculations are done based
    //  on the original bounds of the component and mouse pressed location.

    resizing = true;

    Component source = e.getComponent();
    pressed = e.getPoint();
    SwingUtilities.convertPointToScreen(pressed, source);
    bounds = source.getBounds();

    //  Making sure autoscrolls is false will allow for smoother resizing
    //  of components

    if (source instanceof JComponent) {
      JComponent jc = (JComponent) source;
      autoscrolls = jc.getAutoscrolls();
      jc.setAutoscrolls(false);
    }
  }
Beispiel #15
0
  /**
   * Paint to an offscreen graphic, e.g. a graphic for an image or svg file.
   *
   * @param g
   * @param rect
   */
  public void paintOffscreen(Graphics2D g, Rectangle rect) {

    // Get the components of the sort by X position.
    Component[] components = getComponents();
    Arrays.sort(
        components,
        new Comparator<Component>() {
          public int compare(Component component, Component component1) {
            return component.getX() - component1.getX();
          }
        });

    for (Component c : this.getComponents()) {

      if (c instanceof DataPanel) {
        Graphics2D g2d = (Graphics2D) g.create();
        Rectangle clipRect = new Rectangle(c.getBounds());
        clipRect.height = rect.height;
        g2d.setClip(clipRect);
        g2d.translate(c.getX(), 0);
        ((DataPanel) c).paintOffscreen(g2d, rect);
      }
    }
    // super.paintBorder(g);
  }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   T t = (T) value;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     setText(t != null ? getItemText(t) : "");
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   final MyTableModel model = (MyTableModel) table.getModel();
   component.setEnabled(
       ElementsChooser.this.isEnabled()
           && (myColorUnmarkedElements ? model.isElementMarked(row) : true));
   final ElementProperties properties = myElementToPropertiesMap.get(t);
   if (component instanceof JLabel) {
     final Icon icon =
         properties != null ? properties.getIcon() : t != null ? getItemIcon(t) : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(
       properties != null && properties.getColor() != null
           ? properties.getColor()
           : (isSelected ? table.getSelectionForeground() : table.getForeground()));
   return component;
 }
 private static void drawSelection(JTable table, int column, Graphics g, final int width) {
   int y = 0;
   final int[] rows = table.getSelectedRows();
   final int height = table.getRowHeight();
   for (int row : rows) {
     final TableCellRenderer renderer = table.getCellRenderer(row, column);
     final Component component =
         renderer.getTableCellRendererComponent(
             table, table.getValueAt(row, column), false, false, row, column);
     g.translate(0, y);
     component.setBounds(0, 0, width, height);
     boolean wasOpaque = false;
     if (component instanceof JComponent) {
       final JComponent j = (JComponent) component;
       if (j.isOpaque()) wasOpaque = true;
       j.setOpaque(false);
     }
     component.paint(g);
     if (wasOpaque) {
       ((JComponent) component).setOpaque(true);
     }
     y += height;
     g.translate(0, -y);
   }
 }
Beispiel #18
0
  private Insets getButtonInsets(SynthContext context, Insets insets) {
    // The following calculations are derived from gtkbutton.c
    // (GTK+ version 2.8.20), gtk_button_size_allocate() method.
    int CHILD_SPACING = 1;
    int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
    int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
    int xThickness = getXThickness();
    int yThickness = getYThickness();
    int w = focusSize + focusPad + xThickness + CHILD_SPACING;
    int h = focusSize + focusPad + yThickness + CHILD_SPACING;
    insets.left = insets.right = w;
    insets.top = insets.bottom = h;

    Component component = context.getComponent();
    if ((component instanceof JButton)
        && !(component.getParent() instanceof JToolBar)
        && ((JButton) component).isDefaultCapable()) {
      // Include the default border insets, but only for JButtons
      // that are default capable.  Note that
      // JButton.getDefaultCapable() returns true by default, but
      // GtkToolButtons are never default capable, so we skip this
      // step if the button is contained in a toolbar.
      Insets defaultInsets =
          getClassSpecificInsetsValue(context, "default-border", BUTTON_DEFAULT_BORDER_INSETS);
      insets.left += defaultInsets.left;
      insets.right += defaultInsets.right;
      insets.top += defaultInsets.top;
      insets.bottom += defaultInsets.bottom;
    }

    return insets;
  }
 @Override
 public Dimension minimumLayoutSize(Container parent) {
   Component toolbar = parent.getComponent(0);
   Dimension toolbarSize = toolbar.isVisible() ? toolbar.getMinimumSize() : new Dimension();
   Dimension contentSize = parent.getComponent(1).getMinimumSize();
   return new Dimension(
       Math.max(toolbarSize.width, contentSize.width), toolbarSize.height + contentSize.height);
 }
 /**
  * Returns the default table cell renderer.
  *
  * @param table the <code>JTable</code>
  * @param value the value to assign to the cell at <code>[row, column]</code>
  * @param isSelected true if cell is selected
  * @param hasFocus true if cell has focus
  * @param row the row of the cell to render
  * @param column the column of the cell to render
  * @return the default table cell renderer
  */
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   ReadingList list = model.getLists()[row];
   Component comp =
       super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   comp.setForeground(list.isMissing() ? Color.GRAY : table.getForeground());
   return comp;
 }
 // Implementation of TableCellRenderer interface
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   TableCellRenderer rend = super.getCellRenderer(row, column);
   Component c =
       rend.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   c.setBackground(getBack(isSelected, hasFocus, row, column));
   c.setForeground(getFore(isSelected, hasFocus, row, column));
   return c;
 }
 /**
  * Long operations need to display an hourglass.
  *
  * @param comp The <code>JComponent</code> on which to apply the hour glass cursor
  * @param on If true, we set the cursor on the hourglass
  */
 public static void setCursorOnWait(Component comp, boolean on) {
   if (on) {
     if (comp instanceof AbstractEditorPanel) ((AbstractEditorPanel) comp).showWaitCursor();
     else comp.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   } else {
     if (comp instanceof AbstractEditorPanel) ((AbstractEditorPanel) comp).hideWaitCursor();
     else comp.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   }
 }
 private static Component setLabelColors(
     final Component label, final JTable table, final boolean isSelected, final int row) {
   if (label instanceof JComponent) {
     ((JComponent) label).setOpaque(true);
   }
   label.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
   label.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
   return label;
 }
Beispiel #24
0
  private int[] getPreferredRowHeights(Component[][] table) {
    int numberOfRows = table.length;
    int rowHeights[] = new int[numberOfRows];

    // Start by letting all span = 1 rows take what they need
    int rowIndex = 0;
    for (Component[] row : table) {
      for (int i = 0; i < row.length; i++) {
        Component component = row[i];
        if (component == null) {
          continue;
        }
        GridLayoutData layoutData = getLayoutData(component);
        if (layoutData.verticalSpan == 1) {
          rowHeights[rowIndex] =
              Math.max(rowHeights[rowIndex], component.getPreferredSize().getRows());
        }
      }
      rowIndex++;
    }

    // Next, do span > 1 and enlarge if necessary
    for (int x = 0; x < numberOfColumns; x++) {
      for (int y = 0; y < numberOfRows && y < table.length; ) {
        if (x >= table[y].length) {
          y++;
          continue;
        }
        Component component = table[y][x];
        if (component == null) {
          y++;
          continue;
        }
        GridLayoutData layoutData = getLayoutData(component);
        if (layoutData.verticalSpan > 1) {
          int accumulatedHeight = 0;
          for (int i = y; i < y + layoutData.verticalSpan; i++) {
            accumulatedHeight += rowHeights[i];
          }

          int preferredHeight = component.getPreferredSize().getRows();
          if (preferredHeight > accumulatedHeight) {
            int rowOffset = 0;
            do {
              rowHeights[y + rowOffset++]++;
              accumulatedHeight++;
              if (rowOffset == layoutData.verticalSpan) {
                rowOffset = 0;
              }
            } while (preferredHeight > accumulatedHeight);
          }
        }
        y += layoutData.verticalSpan;
      }
    }
    return rowHeights;
  }
 @Override
 public void layoutContainer(Container parent) {
   int width = parent.getWidth();
   int height = parent.getHeight();
   Component toolbar = parent.getComponent(0);
   Dimension toolbarSize = toolbar.isVisible() ? toolbar.getPreferredSize() : new Dimension();
   toolbar.setBounds(0, 0, width, toolbarSize.height);
   parent.getComponent(1).setBounds(0, toolbarSize.height, width, height - toolbarSize.height);
 }
Beispiel #26
0
 @Override
 public void setBackground(Color color) {
   super.setBackground(color);
   for (Component c : this.getComponents()) {
     if (c instanceof DataPanel) {
       c.setBackground(color);
     }
   }
 }
  /**
   * This method gets the width of a cell, specified by a column and row number.
   *
   * @param row The column number.
   * @param column The row number.
   * @return The width of the cell data.
   */
  private int getCellDataWidth(int row, int column) {
    //  Inovke the renderer for the cell to calculate the preferred width

    TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
    Component c = table.prepareRenderer(cellRenderer, row, column);
    int width = c.getPreferredSize().width + table.getIntercellSpacing().width;

    return width;
  }
  public boolean processAction(final InputEvent e, ActionProcessor processor) {
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    final Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext());
    final boolean dumb = project != null && DumbService.getInstance(project).isDumb();
    List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>();
    for (final AnAction action : myContext.getActions()) {
      final Presentation presentation = myPresentationFactory.getPresentation(action);

      // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard
      final AnActionEvent actionEvent =
          processor.createEvent(
              e,
              myContext.getDataContext(),
              ActionPlaces.MAIN_MENU,
              presentation,
              ActionManager.getInstance());

      ActionUtil.performDumbAwareUpdate(action, actionEvent, true);

      if (dumb && !action.isDumbAware()) {
        if (Boolean.FALSE.equals(
            presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) {
          continue;
        }

        nonDumbAwareAction.add(actionEvent);
        continue;
      }

      if (!presentation.isEnabled()) {
        continue;
      }

      processor.onUpdatePassed(e, action, actionEvent);

      ((DataManagerImpl.MyDataContext) myContext.getDataContext())
          .setEventCount(IdeEventQueue.getInstance().getEventCount(), this);
      actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      Component component =
          PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext());
      if (component != null && !component.isShowing()) {
        return true;
      }

      processor.performAction(e, action, actionEvent);
      actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      return true;
    }

    if (!nonDumbAwareAction.isEmpty()) {
      showDumbModeWarningLaterIfNobodyConsumesEvent(
          e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()]));
    }

    return false;
  }
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   Component component =
       myDelegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   component.setEnabled(ElementsChooser.this.isEnabled());
   if (component instanceof JComponent) {
     ((JComponent) component).setBorder(null);
   }
   return component;
 }
 protected void paintEditor(Graphics g) {
   Component component = grid.getEditorComponent();
   if (component == null) {
     return;
   }
   Rectangle cellBounds = grid.getCellBounds(grid.getEditingRow(), grid.getEditingColumn());
   component.setBounds(cellBounds);
   component.validate();
   component.requestFocus();
 }