Ejemplo n.º 1
0
  /**
   * Uninstalls the ShadowPopupFactory and restores the original popup factory as the new shared
   * popup factory.
   *
   * @see #install()
   */
  public static void uninstall() {
    PopupFactory factory = PopupFactory.getSharedInstance();
    if (!(factory instanceof ShadowPopupFactory)) return;

    PopupFactory stored = ((ShadowPopupFactory) factory).storedFactory;
    PopupFactory.setSharedInstance(stored);
  }
Ejemplo n.º 2
0
    public void mouseMoved(MouseEvent e) {
      if (geoDisplayPopup != null) {
        geoDisplayPopup.hide();
      }

      String pointMessage = "";

      x = e.getX();
      y = e.getY();
      double minDist = -1;
      if (geoPoints == null || geoPoints.size() == 0) {
        return;
      }
      for (GeoPoint p : geoPoints) {
        double dist = p.distance(x, y);
        if (minDist > dist || minDist < 0) {
          pointMessage = p.getMessage();
          minDist = dist;
        }
      }
      if (minDist > 2.5) {
        return;
      }
      geoPanel = GeoPolygonPanel.this;
      message.setText(pointMessage);
      PopupFactory factory = PopupFactory.getSharedInstance();
      geoDisplayPopup =
          factory.getPopup(
              owner,
              message,
              (int) geoPanel.getLocationOnScreen().getX() + x,
              (int) geoPanel.getLocationOnScreen().getY() + y - 15);
      geoDisplayPopup.show();
    }
Ejemplo n.º 3
0
  /**
   * The following code is a trick! By default Swing uses lightweight and "medium" weight popups to
   * show JPopupMenu. The code below force the creation of real heavyweight menus - this increases
   * speed of popups and allows to get rid of some drawing artifacts.
   */
  private static void fixPopupWeight() {
    int popupWeight = OurPopupFactory.WEIGHT_MEDIUM;
    String property = System.getProperty("idea.popup.weight");
    if (property != null) property = property.toLowerCase(Locale.ENGLISH).trim();
    if (SystemInfo.isMacOSLeopard) {
      // force heavy weight popups under Leopard, otherwise they don't have shadow or any kind of
      // border.
      popupWeight = OurPopupFactory.WEIGHT_HEAVY;
    } else if (property == null) {
      // use defaults if popup weight isn't specified
      if (SystemInfo.isWindows) {
        popupWeight = OurPopupFactory.WEIGHT_HEAVY;
      }
    } else {
      if ("light".equals(property)) {
        popupWeight = OurPopupFactory.WEIGHT_LIGHT;
      } else if ("medium".equals(property)) {
        popupWeight = OurPopupFactory.WEIGHT_MEDIUM;
      } else if ("heavy".equals(property)) {
        popupWeight = OurPopupFactory.WEIGHT_HEAVY;
      } else {
        LOG.error("Illegal value of property \"idea.popup.weight\": " + property);
      }
    }

    PopupFactory factory = PopupFactory.getSharedInstance();
    if (!(factory instanceof OurPopupFactory)) {
      factory = new OurPopupFactory(factory);
      PopupFactory.setSharedInstance(factory);
    }
    PopupUtil.setPopupType(factory, popupWeight);
  }
Ejemplo n.º 4
0
    public void mousePressed(MouseEvent e) {
      if (e.getButton() == e.BUTTON3) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);
        int index = list.locationToIndex(e.getPoint());
        GetImageFile gif = new GetImageFile(files[index]);

        JTextArea area =
            new JTextArea(
                "File: "
                    + gif.getImageString()
                    + "\n"
                    + "Score: "
                    + nf.format(scores[index])
                    + "\n"
                    + "Pairs: "
                    + nrpairs[index]);
        area.setEditable(false);
        area.setBorder(BorderFactory.createLineBorder(Color.black));
        area.setFont(new Font("times", Font.PLAIN, 12));
        PopupFactory factory = PopupFactory.getSharedInstance();
        popup =
            factory.getPopup(
                null,
                area,
                (int) e.getComponent().getLocationOnScreen().getX() + e.getX() + 25,
                (int) e.getComponent().getLocationOnScreen().getY() + e.getY());
        popup.show();
      }
    }
Ejemplo n.º 5
0
  /**
   * Returns a <code>Popup</code> instance from the <code>PopupMenuUI</code> that has had <code>show
   * </code> invoked on it. If the current <code>popup</code> is non-null, this will invoke <code>
   * dispose</code> of it, and then <code>show</code> the new one.
   *
   * <p>This does NOT fire any events, it is up the caller to dispatch the necessary events.
   */
  private Popup getPopup() {
    Popup oldPopup = popup;

    if (oldPopup != null) {
      oldPopup.hide();
    }
    PopupFactory popupFactory = PopupFactory.getSharedInstance();

    if (isLightWeightPopupEnabled()) {
      popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
    } else {
      popupFactory.setPopupType(PopupFactory.MEDIUM_WEIGHT_POPUP);
    }

    // adjust the location of the popup
    Point p = adjustPopupLocationToFitScreen(desiredLocationX, desiredLocationY);
    desiredLocationX = p.x;
    desiredLocationY = p.y;

    Popup newPopup = getUI().getPopup(this, desiredLocationX, desiredLocationY);

    popupFactory.setPopupType(PopupFactory.LIGHT_WEIGHT_POPUP);
    newPopup.show();
    return newPopup;
  }
Ejemplo n.º 6
0
 /** Perform a search when user stop to type in the search combo for 2 sec or pressed enter */
 private void search() {
   try {
     bNeedSearch = false;
     setEnabled(false); // no typing during search
     if (sTyped.length() >= MIN_CRITERIA_LENGTH) {
       // second test to get sure user didn't
       // typed before entering this method
       TreeSet<SearchResult> tsResu = TrackManager.getInstance().search(sTyped.toString());
       // Add web radio names
       tsResu.addAll(WebRadioManager.getInstance().search(sTyped.toString()));
       if (tsResu.size() > 0) {
         DefaultListModel model = new DefaultListModel();
         alResults = new ArrayList<SearchResult>();
         alResults.addAll(tsResu);
         for (SearchResult sr : tsResu) {
           model.addElement(sr);
         }
         jlist = new JList(model);
         jlist.setLayoutOrientation(JList.VERTICAL);
         jlist.setCellRenderer(new SearchListRenderer());
         PopupFactory factory = PopupFactory.getSharedInstance();
         JScrollPane jsp = new JScrollPane(jlist);
         int width = (int) ((float) Toolkit.getDefaultToolkit().getScreenSize().getWidth() * 0.7f);
         jsp.setMinimumSize(new Dimension(width, 250));
         jsp.setPreferredSize(new Dimension(width, 250));
         jsp.setMaximumSize(new Dimension(width, 250));
         jlist.setSelectionMode(0);
         jlist.addListSelectionListener(lsl);
         jsp.setBorder(BorderFactory.createLineBorder(Color.BLACK));
         if (popup != null) {
           popup.hide();
         }
         // take upper-left point relative to the
         // textfield
         Point point = new Point(0, 0);
         // take absolute coordonates in the screen (popups works
         // only on absolute coordonates in opposition to swing
         // widgets)
         SwingUtilities.convertPointToScreen(point, this);
         popup =
             factory.getPopup(
                 this, jsp, (int) point.getX() + 500 - (width), (int) point.getY() - 250);
         popup.show();
       } else {
         if (popup != null) {
           popup.hide();
         }
       }
     }
     requestFocusInWindow();
   } catch (Exception e) {
     Log.error(e);
   } finally { // make sure to enable search box in all cases
     setEnabled(true);
   }
 }
Ejemplo n.º 7
0
      public PopupComponent getPopup(Component owner, Component content, int x, int y) {
        final PopupFactory factory = PopupFactory.getSharedInstance();

        final int oldType = PopupUtil.getPopupType(factory);
        PopupUtil.setPopupType(factory, 2);
        final Popup popup = factory.getPopup(owner, content, x, y);
        if (oldType >= 0) PopupUtil.setPopupType(factory, oldType);

        return new AwtPopupWrapper(popup);
      }
Ejemplo n.º 8
0
  /**
   * Installs the ShadowPopupFactory as the shared popup factory on non-Mac platforms. Also stores
   * the previously set factory, so that it can be restored in <code>#uninstall</code>.
   *
   * <p>In some Mac Java environments the popup factory throws a NullPointerException when we call
   * <code>#getPopup</code>.
   *
   * <p>TODO: The Mac case shows that we may have problems replacing non PopupFactory instances.
   * Therefore we should consider replacing only instances of PopupFactory.
   *
   * @see #uninstall()
   */
  public static void install() {
    if (LookUtils.IS_OS_MAC) {
      return;
    }

    PopupFactory factory = PopupFactory.getSharedInstance();
    if (factory instanceof ShadowPopupFactory) return;

    PopupFactory.setSharedInstance(new ShadowPopupFactory(factory));
  }
Ejemplo n.º 9
0
 /** Perform a search when user stop to type in the search combo for 2 sec or pressed enter */
 private void search() {
   try {
     bNeedSearch = false;
     setEnabled(false); // no typing during search
     if (sTyped.length()
         >= MIN_CRITERIA_LENGTH) { // second test to get sure user didn't typed before entering
                                   // this method
       TreeSet tsResu = FileManager.getInstance().search(sTyped.toString());
       if (tsResu.size() > 0) {
         DefaultListModel model = new DefaultListModel();
         alResults = new ArrayList();
         alResults.addAll(tsResu);
         Iterator it = tsResu.iterator();
         while (it.hasNext()) {
           model.addElement(((SearchResult) it.next()).getResu());
         }
         jlist = new JList(model);
         PopupFactory factory = PopupFactory.getSharedInstance();
         JScrollPane jsp = new JScrollPane(jlist);
         jlist.setSelectionMode(0);
         jlist.addListSelectionListener(lsl);
         jsp.setBorder(BorderFactory.createLineBorder(Color.BLACK));
         if (popup != null) {
           popup.hide();
         }
         Point point = new Point(0, 0); // take upper-left point relative to the textfield
         SwingUtilities.convertPointToScreen(
             point,
             this); // take absolute coordonates in the screen ( popups works only on absolute
                    // coordonates in oposition to swing widgets)
         popup = factory.getPopup(this, jsp, (int) point.getX(), (int) point.getY() + 25);
         popup.show();
       } else {
         if (popup != null) {
           popup.hide();
         }
       }
     }
     requestFocusInWindow();
   } catch (Exception e) {
     Log.error(e);
   } finally { // make sure to enable search box in all cases
     setEnabled(true);
   }
 }
Ejemplo n.º 10
0
  public static void showPopup(Component parent, String title, String message, int x, int y) {
    JLabel descr = new JLabel(message);
    JLabel tit = new JLabel(title);

    JPanel pn = new JPanel(new BorderLayout());
    JPanel tpn = new JPanel(new GridBagLayout());
    tpn.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY));
    CloseButton cb = new CloseButton();
    tpn.add(
        cb,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(2, 0, 5, 0),
            0,
            0));
    tpn.add(
        tit,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1.0,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 0, 2, 5),
            0,
            0));
    tpn.setOpaque(false);
    pn.add(tpn, BorderLayout.NORTH);
    pn.add(descr, BorderLayout.CENTER);
    //    pn.setFont(new Font("Dialog", Font.PLAIN, 11));
    pn.setBackground(SystemColor.info);
    pn.setForeground(SystemColor.infoText);
    pn.setOpaque(true);
    pn.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK),
            BorderFactory.createEmptyBorder(0, 5, 5, 5)));

    final Popup p = PopupFactory.getSharedInstance().getPopup(parent, pn, x, y);
    cb.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            p.hide();
          }
        });
    p.show();
  }
Ejemplo n.º 11
0
 protected void showInfoPopup(String info, int x, int y) {
   JPanel content = new JPanel();
   content.add(new JLabel(info));
   content.setBorder(BorderFactory.createLineBorder(Color.BLACK));
   Point location = getLocationOnScreen();
   location.x += x + 5;
   location.y += y + 5;
   popup = PopupFactory.getSharedInstance().getPopup(this, content, location.x, location.y);
   popup.show();
 }
 public void actionPerformed(ActionEvent e) {
   PopupFactory popupFactory = PopupFactory.getSharedInstance();
   JToolTip tip = new JToolTip();
   tip.setTipText(TextUtils.getText("docear.monitoring.reload.name"));
   final Point locationOnScreen = comp.getLocationOnScreen();
   final int height = comp.getHeight();
   Rectangle sBounds = comp.getGraphicsConfiguration().getBounds();
   final int minX = sBounds.x;
   final int maxX = sBounds.x + sBounds.width;
   final int minY = sBounds.y;
   final int maxY = sBounds.y + sBounds.height;
   int x = locationOnScreen.x;
   int y = locationOnScreen.y + height;
   final Dimension tipSize = tip.getPreferredSize();
   final int tipWidth = tipSize.width;
   if (x + tipWidth > maxX) {
     x = maxX - tipWidth;
   }
   if (x < minX) {
     x = minX;
   }
   final int tipHeight = tipSize.height;
   if (y + tipHeight > maxY) {
     if (locationOnScreen.y - tipHeight > minY) {
       y = locationOnScreen.y - tipHeight;
     } else {
       y = maxY - tipHeight;
     }
   }
   if (y < minY) {
     y = minY;
   }
   final Popup tipPopup = popupFactory.getPopup(comp, tip, x, y);
   tipPopup.show();
   showTimer.removeActionListener(this);
   hideTimer.addActionListener(new HideToolTipAction(tipPopup, tip, comp));
   hideTimer.start();
 }
Ejemplo n.º 13
0
  private void showPopup(Set<AppearancePort> portObjects) {
    dragStart = null;
    CircuitState circuitState = canvas.getCircuitState();
    if (circuitState == null) return;
    ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
    for (AppearancePort portObject : portObjects) {
      ports.add(portObject.getPin());
    }

    hideCurrentPopup();
    LayoutThumbnail layout = new LayoutThumbnail();
    layout.setCircuit(circuitState, ports);
    JViewport owner = canvasPane.getViewport();
    Point ownerLoc = owner.getLocationOnScreen();
    Dimension ownerDim = owner.getSize();
    Dimension layoutDim = layout.getPreferredSize();
    int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
    int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
    PopupFactory factory = PopupFactory.getSharedInstance();
    Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
    popup.show();
    curPopup = popup;
    curPopupTime = System.currentTimeMillis();
  }
    @Override
    public Popup getPopup(final Component owner, final Component contents, final int x, final int y)
        throws IllegalArgumentException {
      final Point point = fixPopupLocation(contents, x, y);

      final int popupType =
          UIUtil.isUnderGTKLookAndFeel() ? WEIGHT_HEAVY : PopupUtil.getPopupType(this);
      if (popupType >= 0) {
        PopupUtil.setPopupType(myDelegate, popupType);
      }

      final Popup popup = myDelegate.getPopup(owner, contents, point.x, point.y);
      fixPopupSize(popup, contents);
      return popup;
    }
Ejemplo n.º 15
0
 /**
  * show date chooser panel
  *
  * @param owner: {@link Component}
  */
 private void showPanel(Component owner) {
   if (pop != null) {
     pop.hide();
   }
   Point show = new Point(0, showDate.getHeight());
   SwingUtilities.convertPointToScreen(show, showDate);
   Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
   int x = show.x;
   int y = show.y;
   if (x < 0) {
     x = 0;
   }
   if (x > size.width - 380) {
     x = size.width - 380;
   }
   if (y < size.height - 170) {
   } else {
     y -= 188;
   }
   pop = PopupFactory.getSharedInstance().getPopup(owner, monthPanel, x, y);
   pop.show();
   isShow = true;
 }
Ejemplo n.º 16
0
  private static void initUserInterface() {
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Draw 9-patch");
    try {
      if (Platform.isWindows()) {
        UIManager.put("RootPane.setupButtonVisible", false);
        BeautyEyeLNFHelper.translucencyAtFrameInactive = false;
        BeautyEyeLNFHelper.launchBeautyEyeLNF();

        // impl a demo PopupFactory
        PopupFactory.setSharedInstance(new CoolPopupFactory());
      } else UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 17
0
 public PopupComponent getPopup(Component owner, Component content, int x, int y) {
   return new AwtPopupWrapper(PopupFactory.getSharedInstance().getPopup(owner, content, x, y));
 }
Ejemplo n.º 18
0
  /**
   * Displays a progress indicator and then invokes <code>loadDrawing</code> on a worker thread.
   * Displays the drawing panel when done successfully. Displays an error message when done
   * unsuccessfully.
   *
   * @see #loadDrawing
   */
  @Override
  public final void init() {
    // set the language of the applet
    if (getParameter("Locale") != null) {
      Locale.setDefault(new Locale(getParameter("Locale")));
    }

    final ResourceBundleUtil labels =
        ResourceBundleUtil.getBundle("org.jhotdraw.samples.svg.Labels");

    // Set look and feel
    // -----------------
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Throwable e) {
      // Do nothing.
      // If we can't set the desired look and feel, UIManager does
      // automaticaly the right thing for us.
    }

    // Set our own popup factory, because the one that comes with Mac OS X
    // creates translucent popups which is not useful for color selection
    // using pop menus.
    try {
      PopupFactory.setSharedInstance(new PopupFactory());
    } catch (Throwable e) {
      // If we can't set the popup factory, we have to use what is there.
    }

    // Display a progress indicator while we are loading the drawing
    // ----------------------------------------------------------
    Container c = getContentPane();
    final ProgressIndicator progress =
        new ProgressIndicator(getName(), labels.getString("progressInitializing"));
    c.add(progress);
    progress.revalidate();

    // Load the drawing using a worker thread
    // --------------------------------------
    new Worker<Drawing>() {

      @Override
      protected Drawing construct() throws Exception {
        Thread t =
            new Thread() {

              @Override
              public void run() {
                try {
                  drawingComponent = createDrawingComponent();
                } catch (Throwable t) {
                  t.printStackTrace();
                }
              }
            };
        t.start();
        try {
          progress.setNote(labels.getString("progressLoading"));
          Drawing drawing = loadDrawing(progress);
          progress.setNote(labels.getString("progressOpeningEditor"));
          progress.setIndeterminate(true);
          return drawing;
        } finally {
          t.join();
        }
      }

      @Override
      protected void done(Drawing result) {
        Container c = getContentPane();
        c.removeAll();
        c.setLayout(new BorderLayout());
        c.add(drawingComponent.getComponent());
        initComponents();
        if (result != null) {
          setDrawing(result);
        }
        drawingComponent.revalidate();
        ((JComponent) c).revalidate();
      }

      @Override
      protected void failed(Throwable error) {
        Drawing d = createDrawing();
        String message = (error.getMessage() == null) ? error.toString() : error.getMessage();
        SVGTextAreaFigure txt =
            new SVGTextAreaFigure(
                labels.getFormatted("messageLoadFailed", getParameter("DrawingURL"), message));
        txt.setBounds(new Point2D.Double(0, 0), new Point2D.Double(getWidth(), getHeight()));
        d.add(txt);
        done(d);
        /*
        Container c = getContentPane();
        c.setLayout(new BorderLayout());
        c.removeAll();
        Throwable error = result;
        error.printStackTrace();
        String message = (error.getMessage() == null) ? error.toString() : error.getMessage();
        MessagePanel mp = new MessagePanel(
        UIManager.getIcon("OptionPane.errorIcon"),
        labels.getFormatted("messageLoadFailed", htmlencode(getParameter("DrawingURL")), htmlencode(message)));
        c.add(mp);
        mp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
        if ("close".equals(evt.getActionCommand())) {
        close();
        }
        }
        });
        mp.revalidate();
        */
      }

      @Override
      protected void finished() {
        long end = System.currentTimeMillis();
        System.out.println("AbstractDrawingApplet startup latency:" + (end - start));
      }
    }.start();
  }