Exemplo n.º 1
0
  protected JFrame getPopupWindow() {
    if (popupWindow == null) {
      popupWindow = new JFrame(STLConstants.K1063_TOP_OUTLINE.getValue());
      Image[] images =
          new Image[] {
            UIImages.LOGO_24.getImage(),
            UIImages.LOGO_32.getImage(),
            UIImages.LOGO_64.getImage(),
            UIImages.LOGO_128.getImage()
          };
      popupWindow.setIconImages(Arrays.asList(images));
      popupWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      popupWindow.addComponentListener(
          new ComponentAdapter() {

            /*
             * (non-Javadoc)
             *
             * @see
             * java.awt.event.ComponentAdapter#componentResized(java.awt
             * .event.ComponentEvent)
             */
            @Override
            public void componentResized(ComponentEvent e) {
              popupBound = popupWindow.getBounds();
              popupState = popupWindow.getExtendedState();
            }

            /*
             * (non-Javadoc)
             *
             * @see
             * java.awt.event.ComponentAdapter#componentMoved(java.awt.event
             * .ComponentEvent)
             */
            @Override
            public void componentMoved(ComponentEvent e) {
              popupBound = popupWindow.getBounds();
              popupState = popupWindow.getExtendedState();
            }
          });
      JPanel content = (JPanel) popupWindow.getContentPane();
      content.setLayout(new BorderLayout());
      content.setBackground(UIConstants.INTEL_WHITE);
      content.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
      popupOutline = new TopologyOutlinePanel(updateService, Fit.WINDOW);
      popupOutline.setBackground(UIConstants.INTEL_WHITE);
      popupOutline.setPreferredSize(new Dimension(800, 600));
      popupOutline.setMinimumSize(new Dimension(400, 300));
      popupOutline.setToolTipText("");
      popupOutline.setGraph(graph);
      content.add(popupOutline, BorderLayout.CENTER);

      popupWindow.pack();
    }
    return popupWindow;
  }
Exemplo n.º 2
0
 public static void main(String[] args) {
   MojamComponent mc = new MojamComponent();
   guiFrame = new JFrame(GAME_TITLE);
   JPanel panel = new JPanel(new BorderLayout());
   panel.add(mc);
   guiFrame.setContentPane(panel);
   guiFrame.pack();
   guiFrame.setResizable(false);
   guiFrame.setLocationRelativeTo(null);
   guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   ArrayList<BufferedImage> icoList = new ArrayList<BufferedImage>();
   icoList.add(Art.icon32);
   icoList.add(Art.icon64);
   guiFrame.setIconImages(icoList);
   guiFrame.setVisible(true);
   Options.loadProperties();
   setFullscreen(Boolean.parseBoolean(Options.get(Options.FULLSCREEN, Options.VALUE_FALSE)));
   mc.start();
 }
Exemplo n.º 3
0
  protected void prepareFrame() {
    if (frame == null) {
      frame = new JFrame("Neptus 3D Viewer");
      frame.setSize(800, 600);
      frame.addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent arg0) {
              // this.
              // video = null;
            }
          });

      frame.setTitle("Neptus 3D Viewer");
      // frame.setIconImage(GuiUtils.getImage("images/neptus-icon.png"));
      frame.setIconImages(ConfigFetch.getIconImagesForFrames());
      // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
  }
Exemplo n.º 4
0
 public static void createAndShowGUI() {
   try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   } catch (ClassNotFoundException
       | InstantiationException
       | IllegalAccessException
       | UnsupportedLookAndFeelException ex) {
     ex.printStackTrace();
   }
   JFrame frame = new JFrame("@title@");
   frame.setIconImages(
       Arrays.asList(
           makeBufferedImage(new StarIcon(), 16, 16),
           makeBufferedImage(new StarIcon(16, 8, 5), 40, 40)));
   // frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
   // frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
   frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   frame.getContentPane().add(new MainPanel(frame));
   frame.setResizable(false);
   frame.pack();
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
 }
Exemplo n.º 5
0
  /**
   * Solves this TSPLIB instance while displaying a GUI showing the optimization progress.
   *
   * @param instance the TSPLIB instance to solve
   */
  public static void solve(TSPInstance instance) {
    TSPPanel panel = new TSPPanel(instance);
    panel.setAutoRepaint(false);

    // create other components on the display
    StringBuilder progress = new StringBuilder();
    JTextArea progressText = new JTextArea();

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(panel);
    splitPane.setBottomComponent(new JScrollPane(progressText));
    splitPane.setDividerLocation(300);
    splitPane.setResizeWeight(1.0);

    // display the panel on a window
    JFrame frame = new JFrame(instance.getName());
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(splitPane, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(500, 400);
    frame.setLocationRelativeTo(null);
    frame.setIconImages(Settings.getIconImages());
    frame.setVisible(true);

    // create the optimization problem and evolutionary algorithm
    Problem problem = new TSPProblem(instance);

    Properties properties = new Properties();
    properties.setProperty("swap.rate", "0.7");
    properties.setProperty("insertion.rate", "0.9");
    properties.setProperty("pmx.rate", "0.4");

    Algorithm algorithm =
        AlgorithmFactory.getInstance().getAlgorithm("NSGAII", properties, problem);

    int iteration = 0;

    // now run the evolutionary algorithm
    while (frame.isVisible()) {
      algorithm.step();
      iteration++;

      // clear existing tours in display
      panel.clearTours();

      // display population with light gray lines
      if (algorithm instanceof EvolutionaryAlgorithm) {
        EvolutionaryAlgorithm ea = (EvolutionaryAlgorithm) algorithm;

        for (Solution solution : ea.getPopulation()) {
          panel.displayTour(toTour(solution), lightGray);
        }
      }

      // display current optimal solutions with red line
      Tour best = toTour(algorithm.getResult().get(0));
      panel.displayTour(best, Color.RED, new BasicStroke(2.0f));
      progress.insert(0, "Iteration " + iteration + ": " + best.distance(instance) + "\n");
      progressText.setText(progress.toString());

      // repaint the TSP display
      panel.repaint();
    }
  }
Exemplo n.º 6
0
 private void setLegacyIconImages(List<Image> images) {
   if (this.wasSetIconImagesCalled) {
     return;
   }
   super.setIconImages(images);
 }
Exemplo n.º 7
0
 @Override
 public synchronized void setIconImages(List<? extends Image> icons) {
   super.setIconImages(icons);
   this.wasSetIconImagesCalled = true;
 }
Exemplo n.º 8
0
  /** Initializes the layout and the ribbon. */
  private void initRibbon() {
    this.setLayout(new RibbonFrameLayout());
    this.ribbon = new JRibbon(this);
    this.add(this.ribbon, BorderLayout.NORTH);

    // this.keyTipManager = new KeyTipManager(this);
    Toolkit.getDefaultToolkit()
        .addAWTEventListener(
            new AWTEventListener() {
              private boolean prevAltModif = false;

              @Override
              public void eventDispatched(AWTEvent event) {
                Object src = event.getSource();
                if (src instanceof Component) {
                  Component c = (Component) src;
                  if ((c == JRibbonFrame.this)
                      || (SwingUtilities.getWindowAncestor(c) == JRibbonFrame.this)) {
                    if (event instanceof KeyEvent) {
                      KeyEvent keyEvent = (KeyEvent) event;
                      // System.out.println(keyEvent.getID() + ":"
                      // + keyEvent.getKeyCode());
                      switch (keyEvent.getID()) {
                        case KeyEvent.KEY_PRESSED:
                          // if (keyEvent.getKeyCode() ==
                          // KeyEvent.VK_ESCAPE) {
                          // keyTipManager.showPreviousChain();
                          // }

                          break;
                        case KeyEvent.KEY_RELEASED:
                          boolean wasAltModif = prevAltModif;
                          prevAltModif = keyEvent.getModifiersEx() == InputEvent.ALT_DOWN_MASK;
                          if (wasAltModif && keyEvent.getKeyCode() == KeyEvent.VK_ALT) break;
                          char keyChar = keyEvent.getKeyChar();
                          if (Character.isLetter(keyChar) || Character.isDigit(keyChar)) {
                            // System.out.println("Will handle key press "
                            // + keyChar);
                            KeyTipManager.defaultManager().handleKeyPress(keyChar);
                          }
                          if ((keyEvent.getKeyCode() == KeyEvent.VK_ALT)
                              || (keyEvent.getKeyCode() == KeyEvent.VK_F10)) {
                            if (keyEvent.getModifiers() != 0 || keyEvent.getModifiersEx() != 0)
                              break;
                            boolean hadPopups =
                                !PopupPanelManager.defaultManager().getShownPath().isEmpty();
                            PopupPanelManager.defaultManager().hidePopups(null);
                            if (hadPopups || KeyTipManager.defaultManager().isShowingKeyTips()) {
                              KeyTipManager.defaultManager().hideAllKeyTips();
                            } else {
                              KeyTipManager.defaultManager().showRootKeyTipChain(JRibbonFrame.this);
                            }
                          }
                          if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) {
                            // System.out.println("In KTM");
                            KeyTipManager.defaultManager().showPreviousChain();
                          }
                          break;
                      }
                    }
                    if (event instanceof MouseEvent) {
                      MouseEvent mouseEvent = (MouseEvent) event;
                      switch (mouseEvent.getID()) {
                        case MouseEvent.MOUSE_CLICKED:
                        case MouseEvent.MOUSE_DRAGGED:
                        case MouseEvent.MOUSE_PRESSED:
                        case MouseEvent.MOUSE_RELEASED:
                          KeyTipManager.defaultManager().hideAllKeyTips();
                      }
                    }
                  }
                }
              }
            },
            AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);

    final KeyTipLayer keyTipLayer = new KeyTipLayer();
    JRootPane rootPane = this.getRootPane();
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    final LayoutManager currLM = rootPane.getLayout();
    rootPane.setLayout(
        new LayoutManager() {
          @Override
          public void addLayoutComponent(String name, Component comp) {
            currLM.addLayoutComponent(name, comp);
          }

          @Override
          public void layoutContainer(Container parent) {
            currLM.layoutContainer(parent);
            JRibbonFrame ribbonFrame = JRibbonFrame.this;
            if (ribbonFrame.getRootPane().getWindowDecorationStyle() != JRootPane.NONE)
              keyTipLayer.setBounds(ribbonFrame.getRootPane().getBounds());
            else keyTipLayer.setBounds(ribbonFrame.getRootPane().getContentPane().getBounds());
          }

          @Override
          public Dimension minimumLayoutSize(Container parent) {
            return currLM.minimumLayoutSize(parent);
          }

          @Override
          public Dimension preferredLayoutSize(Container parent) {
            return currLM.preferredLayoutSize(parent);
          }

          @Override
          public void removeLayoutComponent(Component comp) {
            currLM.removeLayoutComponent(comp);
          }
        });
    // layeredPane.setLayout(new OverlayLayout(layeredPane));
    layeredPane.add(keyTipLayer, (Integer) (JLayeredPane.DEFAULT_LAYER + 60));

    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowDeactivated(WindowEvent e) {
            // hide all key tips on window deactivation
            KeyTipManager keyTipManager = KeyTipManager.defaultManager();
            if (keyTipManager.isShowingKeyTips()) {
              keyTipManager.hideAllKeyTips();
            }
          }
        });

    KeyTipManager.defaultManager()
        .addKeyTipListener(
            new KeyTipManager.KeyTipListener() {
              @Override
              public void keyTipsHidden(KeyTipEvent event) {
                if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(false);
              }

              @Override
              public void keyTipsShown(KeyTipEvent event) {
                if (event.getSource() == JRibbonFrame.this) keyTipLayer.setVisible(true);
              }
            });

    ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    super.setIconImages(Arrays.asList(FlamingoUtilities.getBlankImage(16, 16)));
  }
Exemplo n.º 9
0
  /** Contruct a MegaMek, and display the main menu in the specified frame. */
  private void createGUI() {
    createController();

    // Set a couple of things to make the Swing GUI look more "Mac-like" on
    // Macs
    // Taken from:
    // http://www.devdaily.com/apple/mac/java-mac-native-look/Introduction.shtml
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MegaMek");

    // this should also help to make MegaMek look more system-specific
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      System.err.println("Error setting look and feel!");
      e.printStackTrace();
    }

    ToolTipManager.sharedInstance().setInitialDelay(GUIPreferences.getInstance().getTooltipDelay());
    if (GUIPreferences.getInstance().getTooltipDismissDelay() >= 0) {
      ToolTipManager.sharedInstance()
          .setDismissDelay(GUIPreferences.getInstance().getTooltipDismissDelay());
    }
    frame = new JFrame("MegaMek"); // $NON-NLS-1$
    frame.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            quit();
          }
        });
    frame.setBackground(SystemColor.menu);
    frame.setForeground(SystemColor.menuText);
    List<Image> iconList = new ArrayList<Image>();
    iconList.add(
        frame
            .getToolkit()
            .getImage(new File(Configuration.miscImagesDir(), FILENAME_ICON_16X16).toString()));
    iconList.add(
        frame
            .getToolkit()
            .getImage(new File(Configuration.miscImagesDir(), FILENAME_ICON_32X32).toString()));
    iconList.add(
        frame
            .getToolkit()
            .getImage(new File(Configuration.miscImagesDir(), FILENAME_ICON_48X48).toString()));
    iconList.add(
        frame
            .getToolkit()
            .getImage(new File(Configuration.miscImagesDir(), FILENAME_ICON_256X256).toString()));
    frame.setIconImages(iconList);
    CommonMenuBar menuBar = new CommonMenuBar();
    menuBar.addActionListener(actionListener);
    frame.setJMenuBar(menuBar);
    showMainMenu();

    // set visible on middle of screen
    frame.pack();
    frame.setLocationRelativeTo(null);
    // init the cache
    MechSummaryCache.getInstance();

    // Show the window.
    frame.setVisible(true);

    // tell the user about the readme...
    if (GUIPreferences.getInstance().getNagForReadme()) {
      ConfirmDialog confirm =
          new ConfirmDialog(
              frame,
              Messages.getString("MegaMek.welcome.title") + MegaMek.VERSION, // $NON-NLS-1$
              Messages.getString("MegaMek.welcome.message"), // $NON-NLS-1$
              true);
      confirm.setVisible(true);
      if (!confirm.getShowAgain()) {
        GUIPreferences.getInstance().setNagForReadme(false);
      }
      if (confirm.getAnswer()) {
        showHelp();
      }
    }
  }