Ejemplo n.º 1
0
  public static void init(
      JToolBar comp, Thing thing, Container parent, ActionContext actionContext) {
    JComponentCreator.init(comp, thing, parent, actionContext);

    Boolean borderPainted = JavaCreator.createBoolean(thing, "borderPainted");
    if (borderPainted != null) {
      comp.setBorderPainted(borderPainted);
    }

    Boolean floatable = JavaCreator.createBoolean(thing, "floatable");
    if (floatable != null) {
      comp.setFloatable(floatable);
    }

    Insets margin = AwtCreator.createInsets(thing, "margin", actionContext);
    if (margin != null) {
      comp.setMargin(margin);
    }

    Integer orientation = null;
    String v = thing.getString("orientation");
    if ("HORIZONTAL".equals(v)) {
      orientation = JToolBar.HORIZONTAL;
    } else if ("VERTICAL".equals(v)) {
      orientation = JToolBar.VERTICAL;
    }
    if (orientation != null) {
      comp.setOrientation(orientation);
    }

    Boolean rollover = JavaCreator.createBoolean(thing, "rollover");
    if (rollover != null) {
      comp.setRollover(rollover);
    }
  }
Ejemplo n.º 2
0
 /** Builds and lays out the UI. */
 private void buildGUI() {
   setBackground(UIUtilities.BACKGROUND_COLOR);
   setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
   if (selectable) add(checkbox);
   add(label);
   JToolBar bar = new JToolBar();
   bar.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.setFloatable(false);
   bar.setRollover(true);
   bar.setBorder(null);
   bar.setOpaque(true);
   boolean b = setControlsEnabled(data != null);
   int count = 0;
   if (editButton != null) count++;
   if (unlinkButton != null) count++;
   if (downloadButton != null) count++;
   if (infoButton != null) count++;
   if (openButton != null) count++;
   if (count > 0 && data != null) {
     menuButton.setEnabled(true);
     if (model.isAcrossGroups()) menuButton.setEnabled(false);
     bar.add(menuButton);
     if (!b) bar.add(Box.createHorizontalStrut(8));
     add(bar);
   }
 }
Ejemplo n.º 3
0
 /** Builds and lays out the UI. */
 private void buildGUI() {
   setBackground(UIUtilities.BACKGROUND_COLOR);
   JToolBar bar = new JToolBar();
   bar.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.setBorder(null);
   bar.setRollover(true);
   bar.setFloatable(false);
   JButton b = new JButton(control.getAction(RendererControl.SAVE));
   UIUtilities.unifiedButtonLookAndFeel(b);
   b.setText(ManageRndSettingsAction.NAME_SAVE);
   b.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.add(b);
   /*
   b = new JButton(control.getAction(RendererControl.VIEW));
   UIUtilities.unifiedButtonLookAndFeel(b);
   b.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.add(b);
   */
   setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
   add(bar);
   add(Box.createHorizontalStrut(5));
   JPanel p = UIUtilities.buildComponentPanelRight(selectedPlane);
   p.setBackground(UIUtilities.BACKGROUND_COLOR);
   add(p);
 }
Ejemplo n.º 4
0
  /**
   * Constructs a JToolBar that can be added to a JFrame
   *
   * @return a JToolBar
   */
  private JToolBar toolBar() {
    JToolBar toolbar = new JToolBar();
    JButton button;

    button = new JButton(images.loadImage("Images/toolbar/add_child_icon.png"));
    button.setToolTipText(lang_model.getValue(41));
    button.setFocusPainted(false);
    button.setActionCommand("newchild");
    button.addActionListener(this);
    toolbar.add(button);

    button = new JButton(images.loadImage("Images/toolbar/add_employee_icon.png"));
    button.setToolTipText(lang_model.getValue(147));
    button.setFocusPainted(false);
    button.setActionCommand("newemployee");
    button.addActionListener(this);
    toolbar.add(button);

    button = new JButton(images.loadImage("Images/toolbar/XML_icon_large.png"));
    button.setToolTipText(lang_model.getValue(148));
    button.setFocusPainted(false);
    button.setActionCommand("openfile");
    button.addActionListener(this);
    toolbar.add(button);

    button = new JButton(images.loadImage("Images/toolbar/calendar_icon_large.png"));
    button.setToolTipText(lang_model.getValue(149));
    button.setFocusPainted(false);
    button.setActionCommand("viewcalendar");
    button.addActionListener(this);
    button.setEnabled(false);
    toolbar.add(button);

    button = new JButton(images.loadImage("Images/toolbar/database_icon_large.png"));
    button.setToolTipText(lang_model.getValue(150));
    button.setFocusPainted(false);
    button.setActionCommand("viewdatabase");
    button.addActionListener(this);
    toolbar.add(button);

    button = new JButton(images.loadImage("Images/toolbar/finances_icon_large.png"));
    button.setToolTipText(lang_model.getValue(151));
    button.setFocusPainted(false);
    button.setActionCommand("viewfinances");
    button.addActionListener(this);
    button.setEnabled(false);
    toolbar.add(button);

    toolbar.setRollover(true);
    toolbar.setFloatable(false);
    toolbar.setSize(f.getWidth(), 15);

    return toolbar;
  }
Ejemplo n.º 5
0
 // Right toolbar for current scan results
 private JToolBar getToolbarRight() {
   if (footerToolbarRight == null) {
     footerToolbarRight = new JToolBar();
     footerToolbarRight.setEnabled(true);
     footerToolbarRight.setFloatable(false);
     footerToolbarRight.setRollover(true);
     footerToolbarRight.setName("Footer Toolbar Right");
     footerToolbarRight.setBorder(BorderFactory.createEmptyBorder());
   }
   return footerToolbarRight;
 }
Ejemplo n.º 6
0
  public IvusFrame(World world) {
    OrbitView view = (world != null) ? new OrbitView(world) : new OrbitView();
    view.setAxesOrientation(AxesOrientation.XRIGHT_YOUT_ZDOWN);
    ViewCanvas canvas = new ViewCanvas(view);
    canvas.setView(view);

    ModeManager mm = new ModeManager();
    mm.add(canvas);
    OrbitViewMode ovm = new OrbitViewMode(mm);
    SelectDragMode sdm = new SelectDragMode(mm);

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

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('F');
    Action exitAction =
        new AbstractAction("Exit") {
          private static final long serialVersionUID = 1L;

          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        };
    JMenuItem exitItem = fileMenu.add(exitAction);
    exitItem.setMnemonic('x');

    JMenu modeMenu = new JMenu("Mode");
    modeMenu.setMnemonic('M');
    JMenuItem ovmItem = new ModeMenuItem(ovm);
    modeMenu.add(ovmItem);
    JMenuItem sdmItem = new ModeMenuItem(sdm);
    modeMenu.add(sdmItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(modeMenu);

    JToolBar toolBar = new JToolBar(SwingConstants.VERTICAL);
    toolBar.setRollover(true);
    JToggleButton ovmButton = new ModeToggleButton(ovm);
    toolBar.add(ovmButton);
    JToggleButton sdmButton = new ModeToggleButton(sdm);
    toolBar.add(sdmButton);

    ovm.setActive(true);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(new Dimension(SIZE, SIZE));
    this.add(canvas, BorderLayout.CENTER);
    this.add(toolBar, BorderLayout.WEST);
    this.setJMenuBar(menuBar);
  }
Ejemplo n.º 7
0
  private javax.swing.JToolBar getPanelToolbar() {
    if (panelToolbar == null) {

      panelToolbar = new javax.swing.JToolBar();
      panelToolbar.setLayout(new GridBagLayout());
      panelToolbar.setEnabled(true);
      panelToolbar.setFloatable(false);
      panelToolbar.setRollover(true);
      panelToolbar.setPreferredSize(new java.awt.Dimension(800, 30));
      panelToolbar.setName(prefix + ".toolbar");

      int x = 0;

      x = this.addToolBarElements(panelToolbar, Location.start, x);

      newScanButton = getNewScanButton();

      if (newScanButton != null) {
        panelToolbar.add(newScanButton, getGBC(x++, 0));
        newScanButton.setEnabled(!Mode.safe.equals(mode));
        panelToolbar.addSeparator();
        x++;
      }

      panelToolbar.add(
          new JLabel(Constant.messages.getString(prefix + ".toolbar.progress.label")),
          getGBC(x++, 0));
      panelToolbar.add(getProgressSelect(), getGBC(x++, 0));

      x = this.addToolBarElements(panelToolbar, Location.beforeButtons, x);

      panelToolbar.add(getPauseScanButton(), getGBC(x++, 0));
      panelToolbar.add(getStopScanButton(), getGBC(x++, 0));

      x = this.addToolBarElements(panelToolbar, Location.beforeProgressBar, x);

      panelToolbar.add(getProgressBar(), getGBC(x++, 0, 1.0, new Insets(0, 5, 0, 5)));

      panelToolbar.add(getClearScansButton(), getGBC(x++, 0));

      panelToolbar.add(getActiveScansNameLabel(), getGBC(x++, 0));
      panelToolbar.add(getActiveScansValueLabel(), getGBC(x++, 0));

      x = this.addToolBarElements(panelToolbar, Location.afterProgressBar, x);

      panelToolbar.add(new JLabel(), getGBC(x++, 0, 1.0, new Insets(0, 0, 0, 0))); // Spacer
      panelToolbar.add(getOptionsButton(), getGBC(x++, 0));
    }
    return panelToolbar;
  }
Ejemplo n.º 8
0
  private void setupToolBar() // {{{
      {
    toolbar.setFloatable(false);
    toolbar.setRollover(true);
    toolbar.setName("listToolbar"); // NOI18N
    toolbar.setPreferredSize(new java.awt.Dimension(100, 18));

    btnPrev.setIcon(resourceMap.getIcon("btnPrev.icon")); // NOI18N
    btnPrev.setText(resourceMap.getString("btnPrev.text")); // NOI18N
    btnPrev.setToolTipText(resourceMap.getString("btnPrev.toolTipText")); // NOI18N
    btnPrev.setFocusable(false);
    btnPrev.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btnPrev.setMargin(new java.awt.Insets(2, 2, 2, 2));
    btnPrev.setName("btnPrev"); // NOI18N
    btnPrev.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    toolbar.add(btnPrev);

    jSeparator3.setMaximumSize(new java.awt.Dimension(1000, 10));
    jSeparator3.setName("jSeparator3"); // NOI18N
    toolbar.add(jSeparator3);

    btnAddList.setAction(actionMap.get("addNewList"));
    btnAddList.setText(resourceMap.getString("btnAddList.text"));
    btnAddList.setIcon(resourceMap.getIcon("btnAddList.icon"));
    btnAddList.setToolTipText(resourceMap.getString("btnAddList.toolTipText"));
    btnAddList.setMargin(new java.awt.Insets(2, 2, 2, 2));
    toolbar.add(btnAddList);

    btnDeleteList.setAction(actionMap.get("deleteList"));
    btnDeleteList.setText(resourceMap.getString("btnDeleteList.text"));
    btnDeleteList.setIcon(resourceMap.getIcon("btnDeleteList.icon"));
    btnDeleteList.setToolTipText(resourceMap.getString("btnDeleteList.toolTipText"));
    btnDeleteList.setMargin(new java.awt.Insets(2, 2, 2, 2));
    toolbar.add(btnDeleteList);

    separatorRight.setMaximumSize(new java.awt.Dimension(1000, 10));
    separatorRight.setName("separatorRight"); // NOI18N
    toolbar.add(separatorRight);

    btnNext.setIcon(resourceMap.getIcon("btnNext.icon")); // NOI18N
    btnNext.setToolTipText(resourceMap.getString("btnNext.toolTipText")); // NOI18N
    btnNext.setFocusable(false);
    btnNext.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btnNext.setLabel(resourceMap.getString("btnNext.label")); // NOI18N
    btnNext.setMargin(new java.awt.Insets(2, 2, 2, 2));
    btnNext.setName("btnNext"); // NOI18N
    btnNext.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    toolbar.add(btnNext);
  } // }}}
  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      e.printStackTrace();
    }

    Action action = new GloballyContextSensitiveAction("selectAll", "selectAll", "selectAll");
    JMenuBar menubar = new JMenuBar();
    JMenu menu = new JMenu("Actions");
    menu.add(action);
    menubar.add(menu);

    JToolBar toolbar = new JToolBar();
    toolbar.setRollover(true);
    toolbar.setFloatable(true);
    toolbar.add(action);

    JPanel contents = new JPanel();

    String[] listData = new String[] {"item1", "item2", "item3", "item4", "item5            "};
    JList list = new JList(listData);
    contents.add(new JScrollPane(list));

    JTree tree = new JTree();
    tree.setVisibleRowCount(10);
    contents.add(new JScrollPane(tree));

    JTable table = new JTable(new DefaultTableModel(new String[] {"Name", "Type", "Modified"}, 10));
    table.setPreferredScrollableViewportSize(new Dimension(100, 5 * table.getRowHeight()));
    contents.add(new JScrollPane(table));
    contents.add(new JPanel());

    JFrame frame = new JFrame("Globally Context Sensitive Actions - [email protected]");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menubar);
    frame.getContentPane().add(contents);
    frame.getContentPane().add(toolbar, BorderLayout.NORTH);

    frame.pack();
    frame.show();
  }
Ejemplo n.º 10
0
  private void initToolbar() {
    JToolBar tbTraceFilters = new JToolBar();
    tbTraceFilters.setFloatable(false);
    tbTraceFilters.setRollover(true);

    tbTraceFilters.add(new JLabel("Min time:"));
    txtMinTime = new JTextField(4);
    tbTraceFilters.add(txtMinTime);

    JButton btnFilterByTime = new JButton(new FilterByTimeAction());
    btnFilterByTime.setFocusable(false);
    btnFilterByTime.setToolTipText("Filter by trace execution time");
    tbTraceFilters.add(btnFilterByTime);

    tbTraceFilters.addSeparator();

    btnFilterErrors = new JToggleButton(new FilterByErrorAction());
    btnFilterErrors.setFocusable(false);
    btnFilterErrors.setToolTipText("Show only traces with errors");
    tbTraceFilters.add(btnFilterErrors);

    tbTraceFilters.addSeparator();

    cmbTraceType = new JComboBox();
    cmbTraceType.addItem("*");

    cmbTraceType.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
              String item = (String) e.getItem();
              traceLabel = "*".equals(item) ? null : item;
              tbmTraces.setDataSet(dataSet, traceFilter);
            }
          }
        });

    tbTraceFilters.add(cmbTraceType);

    add(tbTraceFilters, BorderLayout.NORTH);
  }
Ejemplo n.º 11
0
  public JToolBar getToolbar() {
    JToolBar jtb = new JToolBar();
    jtb.setOpaque(false);
    jtb.setRollover(true);
    jtb.setBorder(null);
    jtb.setOpaque(false);

    gutbut[0] = new JButton();
    gutbut[0].setIcon(SystemConfig.hmSysIcons.get("neu"));
    gutbut[0].setToolTipText("Neues Gutachten erstellen");
    gutbut[0].setActionCommand("gutneu");
    gutbut[0].addActionListener(this);
    jtb.add(gutbut[0]);

    gutbut[1] = new JButton();
    gutbut[1].setIcon(SystemConfig.hmSysIcons.get("edit"));
    gutbut[1].setToolTipText("Bestehendes Gutachten ändern/editieren");
    gutbut[1].setActionCommand("gutedit");
    gutbut[1].addActionListener(this);
    jtb.add(gutbut[1]);

    gutbut[2] = new JButton();
    gutbut[2].setIcon(SystemConfig.hmSysIcons.get("delete"));
    gutbut[2].setToolTipText("Gutachten löschen");
    gutbut[2].setActionCommand("gutdelete");
    gutbut[2].addActionListener(this);
    jtb.add(gutbut[2]);

    jtb.addSeparator(new Dimension(30, 0));

    gutbut[3] = new JButton();
    gutbut[3].setIcon(SystemConfig.hmSysIcons.get("tools"));
    gutbut[3].setToolTipText("Werkzeuge für Gutachte");
    gutbut[3].setActionCommand("guttools");
    gutbut[3].addActionListener(this);
    jtb.add(gutbut[3]);
    for (int i = 0; i < 4; i++) {
      gutbut[i].setEnabled(false);
    }
    return jtb;
  }
Ejemplo n.º 12
0
  public ToolBarDemo2() {
    // super(new BorderLayout());

    // Create the toolbar.
    JToolBar toolBar = new JToolBar("Still draggable");
    addButtons(toolBar);
    toolBar.setFloatable(false);
    toolBar.setRollover(true);

    // Create the text area used for output.  Request
    // enough space for 5 rows and 30 columns.
    textArea = new JTextArea(5, 30);
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);

    // Lay out the main panel.
    // setPreferredSize(new Dimension(450, 130));
    // add(toolBar, BorderLayout.PAGE_START);
    add(toolBar);
    // add(scrollPane, BorderLayout.CENTER);
    add(scrollPane);
  }
  public CKSyntaxPaneTest() {
    JFrame f = new JFrame("Party"); // CKSytaxPaneTest.class.getName());
    final Container c = f.getContentPane();
    c.setLayout(new BorderLayout());

    // DefaultSyntaxKit.initKit();

    final JEditorPane codeEditor = new JEditorPane();
    JScrollPane scrPane = new JScrollPane(codeEditor);
    // codeEditor.setContentType("text/python");
    codeEditor.setEditorKit(new PythonSyntaxKit());
    // codeEditor.setText("public static void main(String[] args) {\n}");

    // toolbar is part of the editor kit--ausome!
    JToolBar jToolBar1 = new javax.swing.JToolBar();
    jToolBar1.setRollover(true);
    jToolBar1.setFocusable(false);

    EditorKit kit = codeEditor.getEditorKit();
    if (kit instanceof DefaultSyntaxKit) {
      DefaultSyntaxKit defaultSyntaxKit = (DefaultSyntaxKit) kit;
      defaultSyntaxKit.addToolBarActions(codeEditor, jToolBar1);
    }
    jToolBar1.validate();
    c.add(jToolBar1, BorderLayout.PAGE_START);

    c.add(scrPane, BorderLayout.CENTER);
    // c.add(codeEditor, BorderLayout.CENTER);

    // create console for output?
    JTextPane tpane = new JTextPane();
    c.add(tpane, BorderLayout.LINE_START);
    c.doLayout();

    f.setSize(800, 600);
    f.setVisible(true);
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  }
Ejemplo n.º 14
0
 private JToolBar createToolBar() {
   ActionMap actionMap = context.getActionMap(this);
   final JToolBar toolbar = new JToolBar();
   toolbar.setFloatable(false);
   toolbar.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY));
   toolbar.setRollover(true);
   toolbar.add(actionMap.get("openProject"));
   toolbar.addSeparator();
   toolbar.add(application.getAction(NewRvConnection.COMMAND));
   toolbar.addSeparator();
   toolbar.add(application.getAction(ClearLedger.COMMAND));
   toolbar.addSeparator();
   toolbar.add(application.getAction(PauseAllConnections.COMMAND));
   final Component[] components = toolbar.getComponents();
   for (int i = 0, imax = components.length; i < imax; ++i) {
     Component component = components[i];
     if (component instanceof AbstractButton) {
       ((AbstractButton) component).setBorderPainted(false);
       ((AbstractButton) component).setOpaque(false);
     }
   }
   return toolbar;
 }
Ejemplo n.º 15
0
  /**
   * Creates the menu bar
   *
   * @return Description of the Return Value
   */
  public JToolBar createToolBar() {
    // Create the tool bar
    toolBar = new JToolBar();
    toolBar.putClientProperty("jgoodies.headerStyle", "Both");
    toolBar.setRollover(true);
    toolBar.setFloatable(false);

    for (int i = 0; i < beans.length; i++) {
      Icon icon;
      JButton button;

      try {
        final JComponent bean = beans[i];
        URL iconURL = bean.getClass().getResource("images/" + bean.getName() + "Color16.gif");
        icon = new ImageIcon(iconURL);

        button = new JButton(icon);

        ActionListener actionListener =
            new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                installBean(bean);
              }
            };

        button.addActionListener(actionListener);
      } catch (Exception e) {
        System.out.println("JCalendarDemo.createToolBar(): " + e);
        button = new JButton(beans[i].getName());
      }

      button.setFocusPainted(false);
      toolBar.add(button);
    }

    return toolBar;
  }
Ejemplo n.º 16
0
  private javax.swing.JToolBar getPanelToolbar() {
    if (panelToolbar == null) {

      panelToolbar = new javax.swing.JToolBar();
      panelToolbar.setLayout(new java.awt.GridBagLayout());
      panelToolbar.setEnabled(true);
      panelToolbar.setFloatable(false);
      panelToolbar.setRollover(true);
      panelToolbar.setPreferredSize(new java.awt.Dimension(800, 30));
      panelToolbar.setFont(new java.awt.Font("Dialog", java.awt.Font.PLAIN, 12));
      panelToolbar.setName("Search Toolbar");

      GridBagConstraints gridBagConstraintsX = new GridBagConstraints();
      gridBagConstraintsX.gridx = 6;
      gridBagConstraintsX.gridy = 0;
      gridBagConstraintsX.weightx = 1.0;
      gridBagConstraintsX.weighty = 1.0;
      gridBagConstraintsX.insets = new java.awt.Insets(0, 0, 0, 0);
      gridBagConstraintsX.anchor = java.awt.GridBagConstraints.EAST;
      gridBagConstraintsX.fill = java.awt.GridBagConstraints.HORIZONTAL;

      JLabel t1 = new JLabel();
      JLabel inverseTooltip =
          new JLabel(Constant.messages.getString("search.toolbar.label.inverse"));
      inverseTooltip.setToolTipText(Constant.messages.getString("search.toolbar.tooltip.inverse"));

      panelToolbar.add(getRegExField(), newGBC(0));
      panelToolbar.add(getSearchType(), newGBC(1));
      panelToolbar.add(inverseTooltip, newGBC(2));
      panelToolbar.add(getChkInverse(), newGBC(3));
      panelToolbar.add(getBtnSearch(), newGBC(4));
      panelToolbar.add(getBtnNext(), newGBC(5));
      panelToolbar.add(getBtnPrev(), newGBC(6));
      panelToolbar.add(t1, gridBagConstraintsX);
    }
    return panelToolbar;
  }
Ejemplo n.º 17
0
  /**
   * add toolbar function
   *
   * @version 1.0
   * @author dinglinhui
   */
  private void addToolBar() {

    JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    toolBar.setBounds(0, 0, 700, 30);
    toolBar.setFloatable(true);
    this.getContentPane().add(toolBar, BorderLayout.NORTH);

    cfg = new JButton(getImageIcon(RESOURCE_IMAGES_PATH + "antenna2.png", 24, 24));
    cfg.setText("配置");
    cfg.addActionListener(this);
    toolBar.add(cfg);
    toolBar.addSeparator();

    reload = new JButton(getImageIcon(RESOURCE_IMAGES_PATH + "reload.png", 24, 24));
    reload.setText("加载");
    reload.addActionListener(this);
    reload.setEnabled(false);
    toolBar.add(reload);

    export = new JButton(getImageIcon(RESOURCE_IMAGES_PATH + "diskette.png", 24, 24));
    export.setText("导出");
    export.addActionListener(this);
    export.setEnabled(false);
    toolBar.add(export);

    toolBar.addSeparator();
    info = new JButton(getImageIcon(RESOURCE_IMAGES_PATH + "info.png", 24, 24));
    info.setText("信息");
    info.addActionListener(this);
    toolBar.add(info);

    close = new JButton(getImageIcon(RESOURCE_IMAGES_PATH + "close.png", 24, 24));
    close.setText("退出");
    close.addActionListener(this);
    toolBar.add(close);
  }
Ejemplo n.º 18
0
  @SuppressWarnings("serial")
  public static JToolBar newToolbar(boolean anchorRight) {
    JToolBar toolbar;

    if (anchorRight) {
      toolbar =
          new JToolBar() {
            @Override
            protected void addImpl(Component c, Object constraints, int index) {
              int reverseIndex;
              if (index == -1) {
                reverseIndex = 0;
              } else {
                int oldIndex = getComponentIndex(c);
                if (oldIndex >= 0 && index > oldIndex) {
                  index--;
                }

                reverseIndex = getComponentCount() - index;
              }

              super.addImpl(c, constraints, reverseIndex);
            }
          };
      toolbar.setComponentOrientation(RIGHT_TO_LEFT);
    } else {
      toolbar = new JToolBar();
    }

    toolbar.setBorder(null);
    toolbar.setBorderPainted(false);
    toolbar.setFloatable(false);
    toolbar.setRollover(true);
    toolbar.setOpaque(false);
    return toolbar;
  }
Ejemplo n.º 19
0
  private void initComponents() {
    mnuUtilities = new JMenu("Utilities");
    mnuMaintenance = new JMenu("Maintenance");
    mnuHelp = new JMenu("Help");

    mnuUtilities.setMnemonic('U');
    mnuMaintenance.setMnemonic('M');
    mnuHelp.setMnemonic('H');

    miSearch = new JMenuItem("Search");
    miSearch.setMnemonic('S');
    miObstetCalc = new JMenuItem("Obstet Calculator");
    miObstetCalc.setMnemonic('O');
    miExit = new JMenuItem("Exit");
    miExit.setMnemonic('x');

    mnuUtilities.add(miSearch);
    mnuUtilities.addSeparator();
    mnuUtilities.add(miObstetCalc);
    mnuUtilities.addSeparator();
    mnuUtilities.add(miExit);

    miBaseMalformation = new JMenuItem("Malformation");
    miBaseMalformation.setMnemonic('M');
    miBaseSindrom = new JMenuItem("Syndrome");
    miBaseSindrom.setMnemonic('y');
    miBaseTeratogen = new JMenuItem("Teratogen");
    miBaseTeratogen.setMnemonic('T');
    miBaseBiologic = new JMenuItem("Biological Agent");
    miBaseBiologic.setMnemonic('A');
    miFetalWeight = new JMenuItem("Import Fetal Weight Table");
    miFetalWeight.setMnemonic('F');
    miUserAdmin = new JMenuItem("Users Admin");
    miUserAdmin.setMnemonic('U');

    mnuMaintenance.add(miBaseMalformation);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miBaseSindrom);
    mnuMaintenance.add(miBaseTeratogen);
    mnuMaintenance.add(miBaseBiologic);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miFetalWeight);
    mnuMaintenance.addSeparator();
    mnuMaintenance.add(miUserAdmin);

    miDisclaimer = new JMenuItem("Disclaimer");
    miAbout = new JMenuItem("About");

    mnuHelp.add(miDisclaimer);
    mnuHelp.addSeparator();
    mnuHelp.add(miAbout);

    mb = new JMenuBar();
    mb.add(mnuUtilities);
    mb.add(mnuMaintenance);
    mb.add(mnuHelp);
    mb.add(Box.createGlue());
    JLabel lblUser = new JLabel();
    lblUser.setText(
        "Active User: "******" ");
    mb.add(lblUser);

    mainBar = new JToolBar();
    btnSearch = new JButton();
    btnCalc = new JButton();
    btnExit = new JButton();
    btnSearch.setIcon(new ImageIcon(getClass().getResource("/icons/search.png"))); // NOI18N
    btnSearch.setToolTipText("Search");
    btnSearch.setFocusable(false);
    btnSearch.setBorderPainted(false);
    btnCalc.setIcon(new ImageIcon(getClass().getResource("/icons/calculator.png"))); // NOI18N
    btnCalc.setToolTipText("Obstet Calculations");
    btnCalc.setFocusable(false);
    btnCalc.setBorderPainted(false);
    btnExit.setIcon(new ImageIcon(getClass().getResource("/icons/exit.png"))); // NOI18N
    btnExit.setToolTipText("Exit");
    btnExit.setFocusable(false);
    btnExit.setBorderPainted(false);

    mainBar.add(btnSearch);
    mainBar.add(btnCalc);
    mainBar.add(btnExit);
    mainBar.setFloatable(false);
    mainBar.setRollover(true);

    imgPanel = new JPanel();
    img = new ImageIcon(getClass().getResource("/Images/logo_title.png"));
    lblImage = new JLabel(img);
    imgPanel.add(lblImage);

    miSearch.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MFSearchWindow();
          }
        });
    miExit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            safeExit();
          }
        });
    miBaseMalformation.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new MalformationWindow();
          }
        });
    miBaseSindrom.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new SyndromeBaseWindow();
          }
        });
    miBaseTeratogen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new TeratogenBaseWindow();
          }
        });
    miBaseBiologic.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new BiologicAgentWindow();
          }
        });
    miUserAdmin.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new UserWindow();
          }
        });
    miDisclaimer.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DisclaimerWindow dis = new DisclaimerWindow();
            dis.btnAgree.setVisible(false);
            dis.btnDisagree.setVisible(false);
            dis.btnClose.setVisible(true);
            dis.setVisible(true);
          }
        });
    miAbout.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new AboutWindow();
          }
        });
    miFetalWeight.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              FileRandomTool rand = new FileRandomTool("TbGOWeight");
              rand.RandomCreate(null);
            } catch (Exception ex) {
              JOptionPane.showMessageDialog(
                  MainWindow.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
              ex.printStackTrace(System.err);
            }
          }
        });
    miObstetCalc.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ObstetCalculatorWindow calc = new ObstetCalculatorWindow();
            calc.setVisible(true);
          }
        });
    btnExit.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            safeExit();
          }
        });
    btnSearch.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            new MFSearchWindow();
          }
        });
    btnCalc.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            ObstetCalculatorWindow calc = new ObstetCalculatorWindow();
            calc.setVisible(true);
          }
        });
  }
Ejemplo n.º 20
0
  /**
   * Constructs a simple frame with the specified world and orientation.
   *
   * @param world the world view.
   * @param ao the axes orientation.
   */
  public RSFFrame(World world, AxesOrientation ao) {
    super(new PlotPanel());
    if (world == null) world = new World();
    if (ao == null) ao = AxesOrientation.XRIGHT_YOUT_ZDOWN;
    _world = world;
    _view = new OrbitView(_world);
    _view.setAxesOrientation(ao);
    _canvas = new ViewCanvas();
    _canvas.setView(_view);
    _canvas.setBackground(Color.WHITE);

    _points = new ArrayList<PointGroup>();
    _lines = new ArrayList<LineGroup>();

    _d = null;
    _tpx = null;
    _tpy = null;
    _ipg = null;

    _etc = null;
    _coord = null;

    ModeManager mm = new ModeManager();
    mm.add(_canvas);
    OrbitViewMode ovm = new OrbitViewMode(mm);
    SelectDragMode sdm = new SelectDragMode(mm);

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

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('F');
    Action exitAction =
        new AbstractAction("Exit") {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        };

    Action cubeAction =
        new AbstractAction("Add Cube") {
          public void actionPerformed(ActionEvent event) {
            String filename = chooseFile(".");
            if (filename != null) addRSFCube(filename);
          }
        };

    Action lineAction =
        new AbstractAction("Add Line") {
          public void actionPerformed(ActionEvent event) {
            String filename = chooseFile(".");
            if (filename != null) addRSFLine(filename);
          }
        };

    Action pointAction =
        new AbstractAction("Add Points") {
          public void actionPerformed(ActionEvent event) {
            String filename = chooseFile(".");
            if (filename != null) addRSFPoint(filename);
          }
        };

    Action loadViewAction =
        new AbstractAction("Load Viewpoint") {
          public void actionPerformed(ActionEvent event) {
            String filename = chooseFile(".");
            if (filename != null) loadView(filename);
          }
        };

    Action saveViewAction =
        new AbstractAction("Save Viewpoint") {
          public void actionPerformed(ActionEvent event) {
            JFileChooser chooser = new JFileChooser(new File("."));
            int returnVal = chooser.showSaveDialog(new JFrame());
            String filename = null;
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              filename = chooser.getSelectedFile().getPath();
              saveView(filename);
            }
          }
        };

    Action saveFrameAction =
        new AbstractAction("Save to PNG") {
          public void actionPerformed(ActionEvent event) {
            JFileChooser chooser = new JFileChooser(new File("."));
            int returnVal = chooser.showSaveDialog(new JFrame());
            String filename = null;
            if (returnVal == JFileChooser.APPROVE_OPTION) {
              filename = chooser.getSelectedFile().getPath();
              saveFrametoPNG(filename);
            }
          }
        };

    JMenuItem cubeItem = fileMenu.add(cubeAction);
    cubeItem.setMnemonic('C');

    JMenuItem lineItem = fileMenu.add(lineAction);
    lineItem.setMnemonic('L');

    JMenuItem pointItem = fileMenu.add(pointAction);
    pointItem.setMnemonic('P');

    JMenuItem saveViewItem = fileMenu.add(saveViewAction);
    saveViewItem.setMnemonic('V');

    JMenuItem loadViewItem = fileMenu.add(loadViewAction);
    loadViewItem.setMnemonic('I');

    JMenuItem saveFrameItem = fileMenu.add(saveFrameAction);
    saveFrameItem.setMnemonic('S');

    JMenuItem exitItem = fileMenu.add(exitAction);
    exitItem.setMnemonic('X');

    JMenu colorMenu = new JMenu("Color");

    Action jetAction =
        new AbstractAction("Jet") {
          public void actionPerformed(ActionEvent event) {
            _color = ColorList.JET;
            setColorMap();
          }
        };

    Action prismAction =
        new AbstractAction("Prism") {
          public void actionPerformed(ActionEvent event) {
            _color = ColorList.PRISM;
            setColorMap();
          }
        };

    Action grayAction =
        new AbstractAction("Gray") {
          public void actionPerformed(ActionEvent event) {
            _color = ColorList.GRAY;
            setColorMap();
          }
        };

    Action rwbAction =
        new AbstractAction("Red-White-Blue") {
          public void actionPerformed(ActionEvent event) {
            _color = ColorList.RWB;
            setColorMap();
          }
        };

    colorMenu.add(jetAction);
    colorMenu.add(prismAction);
    colorMenu.add(grayAction);
    colorMenu.add(rwbAction);

    JMenu clipMenu = new JMenu("% Clip");
    Action clipUp =
        new AbstractAction("Set max pclip") {
          public void actionPerformed(ActionEvent event) {
            String value =
                JOptionPane.showInputDialog(new JFrame(), "Percentile Clip Max (0-100.0):", _pmax);
            try {
              _pmax = Float.parseFloat(value);
              if (_pmax > 100.0f) _pmax = 100.0f;
              if (_pmax < _pmin) _pmax = _pmin + 1.0f;
              System.out.printf("pclip: (%f,%f) \n", _pmin, _pmax);
              _ipg.setPercentiles(_pmin, _pmax);

            } catch (Exception e) {
              System.out.println(e);
            }
          }
        };
    Action clipDown =
        new AbstractAction("Set min pclip") {
          public void actionPerformed(ActionEvent event) {
            String value =
                JOptionPane.showInputDialog(
                    new JFrame(), String.format("Percentile Clip Min (0-%f):", _pmax), _pmin);
            try {
              _pmin = Float.parseFloat(value);
              if (_pmin < 0.0f) _pmin = 0.0f;
              if (_pmin > _pmax) _pmin = _pmax - 1.0f;
              System.out.printf("pclip: (%f,%f) \n", _pmin, _pmax);
              _ipg.setPercentiles(_pmin, _pmax);

            } catch (Exception e) {
              System.out.println(e);
            }
          }
        };

    clipMenu.add(clipUp);
    clipMenu.add(clipDown);

    JMenu modeMenu = new JMenu("Mode");
    modeMenu.setMnemonic('M');
    JMenuItem ovmItem = new JMenuItem(ovm);
    modeMenu.add(ovmItem);
    JMenuItem sdmItem = new JMenuItem(sdm);
    modeMenu.add(sdmItem);

    JMenu tensorMenu = new JMenu("Tensor");

    Action tenLoadAction =
        new AbstractAction("Load Tensors") {
          public void actionPerformed(ActionEvent event) {
            String filename = chooseFile(".");
            if (filename != null) loadTensors(filename);
          }
        };

    Action tenCoordLoadAction =
        new AbstractAction("Load Tensor Coordinates") {
          public void actionPerformed(ActionEvent event) {
            String filename = chooseFile(".");
            if (filename != null) loadTensorCoords(filename);
          }
        };

    Action showTenAction =
        new AbstractAction("Show Tensors at Coordinates") {
          public void actionPerformed(ActionEvent event) {

            String filename;
            int sel;

            if (_ipg == null) {
              sel =
                  JOptionPane.showConfirmDialog(
                      null,
                      "An RSF Cube (Image) needs to be loaded. " + " Would you like to load one?",
                      "Notice",
                      JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (sel == JOptionPane.OK_OPTION) {
                filename = chooseFile(".");
                if (filename != null) addRSFCube(filename);
              } else {
                JOptionPane.showConfirmDialog(
                    null,
                    "Cannot load tensors because an RFC cube was not loaded.",
                    "Error",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
            }
            if (_coord == null) {
              sel =
                  JOptionPane.showConfirmDialog(
                      null,
                      "The tensors coordinates need to be loaded. "
                          + " Would you like to load them?",
                      "Notice",
                      JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (sel == JOptionPane.OK_OPTION) {
                filename = chooseFile(".");
                if (filename != null) loadCoord(filename);
              } else {
                JOptionPane.showConfirmDialog(
                    null,
                    "Error loading coordinates.",
                    "Error",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
            }
            if (_etc == null) {
              sel =
                  JOptionPane.showConfirmDialog(
                      null,
                      "The tensors at coordinates need to be loaded. "
                          + " Would you like to load them?",
                      "Notice",
                      JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (sel == JOptionPane.OK_OPTION) {
                filename = chooseFile(".");
                if (filename != null) loadTensorCoords(filename);
                return;
              } else {
                JOptionPane.showConfirmDialog(
                    null,
                    "Cannot show tensors because the tensors at coordinates" + " were not loaded.",
                    "Error",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
            }
            /*
            if(_d == null) {
            	sel = JOptionPane.showConfirmDialog(null,
            						"The tensors need to be loaded. "
            						+ " Would you like to load them?",
            						"Notice",
            						JOptionPane.OK_CANCEL_OPTION,
            						JOptionPane.QUESTION_MESSAGE);
            	if(sel == JOptionPane.OK_OPTION) {
            		filename = chooseFile(".");
            		if (filename != null) loadTensors(filename);
            	} else {
            		JOptionPane.showConfirmDialog(null,
            				"Cannot show tensors because the tensors were not loaded.",
            				"Error",
            				JOptionPane.DEFAULT_OPTION,
            				JOptionPane.ERROR_MESSAGE);
            		return;
            	}
            }
            if(_etg == null) {
            	sel = JOptionPane.showConfirmDialog(null,
            						"The tensor coordinates need to be loaded. "
            						+ " Would you like to load them?",
            						"Notice",
            						JOptionPane.OK_CANCEL_OPTION,
            						JOptionPane.QUESTION_MESSAGE);
            	if(sel == JOptionPane.OK_OPTION) {
            		filename = chooseFile(".");
            		if (filename != null) loadTensorCoords(filename);
            		return;
            	} else {
            		JOptionPane.showConfirmDialog(null,
            				"Cannot show tensors because the tensor coordinates"
            				+ " were not loaded.",
            				"Error",
            				JOptionPane.DEFAULT_OPTION,
            				JOptionPane.ERROR_MESSAGE);
            		return;
            	}
            }
            */
            _world.addChild(_etg);
          }
        };

    Action hideTenAction =
        new AbstractAction("Hide Tensors at Coordinates") {
          public void actionPerformed(ActionEvent event) {
            if (_etg != null) _world.removeChild(_etg);
          }
        };

    Action showTenPanAction =
        new AbstractAction("Show Tensor Panels") {
          public void actionPerformed(ActionEvent event) {

            String filename;
            int sel;
            if (_ipg == null) {
              sel =
                  JOptionPane.showConfirmDialog(
                      null,
                      "An RSF Cube (Image) needs to be loaded. " + " Would you like to load one?",
                      "Notice",
                      JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (sel == JOptionPane.OK_OPTION) {
                filename = chooseFile(".");
                if (filename != null) addRSFCube(filename);
              } else {
                JOptionPane.showConfirmDialog(
                    null,
                    "Cannot load tensors because an RFC cube was not loaded.",
                    "Error",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
            }

            if (_d == null) {
              sel =
                  JOptionPane.showConfirmDialog(
                      null,
                      "The tensors need to be loaded. " + " Would you like to load them?",
                      "Notice",
                      JOptionPane.OK_CANCEL_OPTION,
                      JOptionPane.QUESTION_MESSAGE);
              if (sel == JOptionPane.OK_OPTION) {
                filename = chooseFile(".");
                if (filename != null) loadTensors(filename);
                addRSFTensorEllipsoids();
              } else {
                JOptionPane.showConfirmDialog(
                    null,
                    "Cannot show tensors because the tensors were not loaded.",
                    "Error",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
            } else if (_tpx == null || _tpy == null) {
              addRSFTensorEllipsoids();
            } else {
              ImagePanel ipx = _ipg.getImagePanel(Axis.X);
              ImagePanel ipy = _ipg.getImagePanel(Axis.Y);
              ipx.getFrame().addChild(_tpx);
              ipy.getFrame().addChild(_tpy);
            }
          }
        };

    Action hideTenPanAction =
        new AbstractAction("Hide Tensor Panels") {
          public void actionPerformed(ActionEvent event) {
            if (_tpx != null) {
              ImagePanel ipx = _ipg.getImagePanel(Axis.X);
              ipx.getFrame().removeChild(_tpx);
            }
            if (_tpy != null) {
              ImagePanel ipy = _ipg.getImagePanel(Axis.Y);
              ipy.getFrame().removeChild(_tpy);
            }
          }
        };

    JMenuItem tensorItem0 = tensorMenu.add(tenLoadAction);
    tensorItem0.setMnemonic('L');

    JMenuItem tensorItem2 = tensorMenu.add(tenCoordLoadAction);
    tensorItem2.setMnemonic('C');

    JMenuItem tensorItem1 = tensorMenu.add(showTenPanAction);
    tensorItem1.setMnemonic('T');

    JMenuItem tensorItem5 = tensorMenu.add(hideTenPanAction);
    tensorItem5.setMnemonic('R');

    JMenuItem tensorItem4 = tensorMenu.add(showTenAction);
    tensorItem4.setMnemonic('S');

    JMenuItem tensorItem3 = tensorMenu.add(hideTenAction);
    tensorItem3.setMnemonic('H');

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(modeMenu);
    menuBar.add(tensorMenu);
    menuBar.add(colorMenu);
    menuBar.add(clipMenu);

    JToolBar toolBar = new JToolBar(SwingConstants.VERTICAL);
    toolBar.setRollover(true);
    JToggleButton ovmButton = new ModeToggleButton(ovm);
    toolBar.add(ovmButton);
    JToggleButton sdmButton = new ModeToggleButton(sdm);
    toolBar.add(sdmButton);

    _cb = new ColorBar();
    _cb.setWidthMinimum(45);
    _cb.setFont(_cb.getFont().deriveFont(18.f));
    // _ipg.addColorMapListener(_cb);

    ovm.setActive(true);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(new Dimension(SIZE, SIZE));
    this.add(_canvas, BorderLayout.CENTER);
    this.add(toolBar, BorderLayout.WEST);
    this.add(_cb, BorderLayout.EAST);
    this.setJMenuBar(menuBar);
    this.setVisible(true);
  }
Ejemplo n.º 21
0
  public void initUI() {
    // Search
    double[][] sizeSearch = new double[][] {{3, TableLayout.PREFERRED, 3, 100}, {25}};
    JPanel jpSearch = new JPanel(new TableLayout(sizeSearch));
    sbSearch = new SearchBox(CommandJPanel.this);
    JLabel jlSearch = new JLabel(IconLoader.ICON_SEARCH);
    jlSearch.setToolTipText(Messages.getString("CommandJPanel.23"));
    // Clear search text when clicking on the search icon
    jlSearch.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            sbSearch.setText("");
          }
        });
    jpSearch.add(jlSearch, "1,0");
    jpSearch.add(sbSearch, "3,0");

    // History
    JPanel jpHistory = new JPanel();
    jcbHistory = new SteppedComboBox();
    JLabel jlHistory = new JLabel(IconLoader.ICON_HISTORY);
    jlHistory.setToolTipText(Messages.getString("CommandJPanel.0"));
    // - Increase rating button
    ActionBase actionIncRate = ActionManager.getAction(JajukAction.INC_RATE);
    actionIncRate.setName(null);
    final JPopupMenu jpmIncRating = new JPopupMenu();
    for (int i = 1; i <= 10; i++) {
      final int j = i;
      JMenuItem jmi = new JMenuItem("+" + i);
      if (ConfigurationManager.getInt(CONF_INC_RATING) == i) {
        jmi.setFont(FontManager.getInstance().getFont(JajukFont.BOLD));
      }
      // Store selected value
      jmi.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              ConfigurationManager.setProperty(CONF_INC_RATING, "" + j);
            }
          });
      jpmIncRating.add(jmi);
    }
    jbIncRate =
        new DropDownButton(IconLoader.ICON_INC_RATING) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return jpmIncRating;
          }
        };
    jbIncRate.setAction(actionIncRate);
    // we use a combo box model to make sure we get good performances after
    // rebuilding the entire model like after a refresh
    jcbHistory.setModel(new DefaultComboBoxModel(History.getInstance().getHistory()));
    // None selection because if we start in stop mode, a selection of the
    // first item will not launch the track because the selected item is
    // still the same and no action event is thrown (Java >= 1.6)
    jcbHistory.setSelectedItem(null);
    int iWidth = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2);
    // size of popup
    jcbHistory.setPopupWidth(iWidth);
    // size of the combo itself, keep it! as text can be very long
    jcbHistory.setPreferredSize(new Dimension(250, 25));
    jcbHistory.setMinimumSize(new Dimension(0, 25));
    jcbHistory.setToolTipText(Messages.getString("CommandJPanel.0"));
    jcbHistory.addActionListener(CommandJPanel.this);
    JToolBar jtbIncRate = new JToolBar();
    jtbIncRate.setFloatable(false);
    jbIncRate.addToToolBar(jtbIncRate);
    double[][] sizeHistory =
        new double[][] {
          {3, TableLayout.PREFERRED, 3, TableLayout.FILL, 10, TableLayout.PREFERRED}, {25}
        };
    jpHistory.setLayout(new TableLayout(sizeHistory));
    jpHistory.add(jlHistory, "1,0");
    jpHistory.add(jcbHistory, "3,0");
    jpHistory.add(jtbIncRate, "5,0");

    // Mode toolbar
    // we need an inner toolbar to apply size properly
    JToolBar jtbModes = new JToolBar();
    jtbModes.setBorder(null);
    // make it not floatable as this behavior is managed by vldocking
    jtbModes.setFloatable(false);
    jtbModes.setRollover(true);
    jbRepeat =
        new JajukToggleButton(ActionManager.getAction(JajukAction.REPEAT_MODE_STATUS_CHANGE));
    jbRepeat.setSelected(ConfigurationManager.getBoolean(CONF_STATE_REPEAT));
    jbRandom =
        new JajukToggleButton(ActionManager.getAction(JajukAction.SHUFFLE_MODE_STATUS_CHANGED));
    jbRandom.setSelected(ConfigurationManager.getBoolean(CONF_STATE_SHUFFLE));
    jbContinue =
        new JajukToggleButton(ActionManager.getAction(JajukAction.CONTINUE_MODE_STATUS_CHANGED));
    jbContinue.setSelected(ConfigurationManager.getBoolean(CONF_STATE_CONTINUE));
    jbIntro = new JajukToggleButton(ActionManager.getAction(JajukAction.INTRO_MODE_STATUS_CHANGED));
    jbIntro.setSelected(ConfigurationManager.getBoolean(CONF_STATE_INTRO));
    jtbModes.add(jbRepeat);
    jtbModes.addSeparator();
    jtbModes.add(jbRandom);
    jtbModes.addSeparator();
    jtbModes.add(jbContinue);
    jtbModes.addSeparator();
    jtbModes.add(jbIntro);

    // Volume
    jpVolume = new JPanel();
    ActionUtil.installKeystrokes(
        jpVolume,
        ActionManager.getAction(JajukAction.DECREASE_VOLUME),
        ActionManager.getAction(JajukAction.INCREASE_VOLUME));

    jpVolume.setLayout(new BoxLayout(jpVolume, BoxLayout.X_AXIS));
    int iVolume = (int) (100 * ConfigurationManager.getFloat(CONF_VOLUME));
    if (iVolume > 100) { // can occur in some undefined cases
      iVolume = 100;
    }
    jsVolume = new JSlider(0, 100, iVolume);
    jpVolume.add(jsVolume);
    jpVolume.add(Box.createHorizontalStrut(5));
    jpVolume.add(jbMute);
    jsVolume.setToolTipText(Messages.getString("CommandJPanel.14"));
    jsVolume.addChangeListener(CommandJPanel.this);
    jsVolume.addMouseWheelListener(CommandJPanel.this);

    // Special functions toolbar
    // Ambience combo
    ambiencesCombo = new SteppedComboBox();
    iWidth = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 4);
    ambiencesCombo.setPopupWidth(iWidth);
    ambiencesCombo.setFont(FontManager.getInstance().getFont(JajukFont.BOLD_L));
    // size of the combo itself
    ambiencesCombo.setRenderer(
        new BasicComboBoxRenderer() {
          private static final long serialVersionUID = -6943363556191659895L;

          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            JLabel jl = (JLabel) value;
            setIcon(jl.getIcon());
            setText(jl.getText());
            return this;
          }
        });
    ambiencesCombo.setToolTipText(Messages.getString("DigitalDJWizard.66"));
    populateAmbiences();
    ambienceListener = new AmbienceListener();
    ambiencesCombo.addActionListener(ambienceListener);
    jtbSpecial = new JToolBar();
    jtbSpecial.setBorder(null);
    jtbSpecial.setRollover(true);
    jtbSpecial.setFloatable(false);
    ddbGlobalRandom =
        new DropDownButton(IconLoader.ICON_SHUFFLE_GLOBAL) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupGlobalRandom;
          }
        };
    ddbGlobalRandom.setAction(ActionManager.getAction(JajukAction.SHUFFLE_GLOBAL));
    popupGlobalRandom = new JPopupMenu();
    // Global shuffle
    jmiShuffleModeSong = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.20"));
    jmiShuffleModeSong.addActionListener(this);
    // album / album
    jmiShuffleModeAlbum = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.21"));
    jmiShuffleModeAlbum.addActionListener(this);
    // Shuffle album / album
    jmiShuffleModeAlbum2 = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.22"));
    jmiShuffleModeAlbum2.addActionListener(this);
    if (ConfigurationManager.getProperty(CONF_GLOBAL_RANDOM_MODE).equals(MODE_TRACK)) {
      jmiShuffleModeSong.setSelected(true);
    } else if (ConfigurationManager.getProperty(CONF_GLOBAL_RANDOM_MODE).equals(MODE_ALBUM2)) {
      jmiShuffleModeAlbum2.setSelected(true);
    } else {
      jmiShuffleModeAlbum.setSelected(true);
    }
    ButtonGroup bgGlobalRandom = new ButtonGroup();
    bgGlobalRandom.add(jmiShuffleModeSong);
    bgGlobalRandom.add(jmiShuffleModeAlbum);
    bgGlobalRandom.add(jmiShuffleModeAlbum2);
    popupGlobalRandom.add(jmiShuffleModeSong);
    popupGlobalRandom.add(jmiShuffleModeAlbum);
    popupGlobalRandom.add(jmiShuffleModeAlbum2);
    ddbGlobalRandom.setText(""); // no text visible

    jbBestof = new JajukButton(ActionManager.getAction(JajukAction.BEST_OF));

    ddbNovelties =
        new DropDownButton(IconLoader.ICON_NOVELTIES) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupNovelties;
          }
        };
    ddbNovelties.setAction(ActionManager.getAction(JajukAction.NOVELTIES));
    popupNovelties = new JPopupMenu();
    jmiNoveltiesModeSong = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.20"));
    jmiNoveltiesModeSong.addActionListener(this);
    jmiNoveltiesModeAlbum = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.22"));
    jmiNoveltiesModeAlbum.addActionListener(this);
    if (ConfigurationManager.getProperty(CONF_NOVELTIES_MODE).equals(MODE_TRACK)) {
      jmiNoveltiesModeSong.setSelected(true);
    } else {
      jmiNoveltiesModeAlbum.setSelected(true);
    }
    ButtonGroup bgNovelties = new ButtonGroup();
    bgNovelties.add(jmiNoveltiesModeSong);
    bgNovelties.add(jmiNoveltiesModeAlbum);
    popupNovelties.add(jmiNoveltiesModeSong);
    popupNovelties.add(jmiNoveltiesModeAlbum);
    ddbNovelties.setText(""); // no text visible

    jbNorm = new JajukButton(ActionManager.getAction(FINISH_ALBUM));
    popupDDJ = new JPopupMenu();
    ddbDDJ =
        new DropDownButton(IconLoader.ICON_DIGITAL_DJ) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupDDJ;
          }
        };
    ddbDDJ.setAction(ActionManager.getAction(JajukAction.DJ));
    populateDJs();
    // no text visible
    ddbDDJ.setText("");

    popupWebRadio = new XJPopupMenu(Main.getWindow());
    ddbWebRadio =
        new DropDownButton(IconLoader.ICON_WEBRADIO) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupWebRadio;
          }
        };
    ddbWebRadio.setAction(ActionManager.getAction(JajukAction.WEB_RADIO));
    populateWebRadios();
    // no text
    ddbWebRadio.setText("");

    ddbDDJ.addToToolBar(jtbSpecial);
    ddbNovelties.addToToolBar(jtbSpecial);
    ddbGlobalRandom.addToToolBar(jtbSpecial);
    jtbSpecial.add(jbBestof);
    jtbSpecial.add(jbNorm);

    // Radio tool bar
    JToolBar jtbWebRadio = new JToolBar();
    jtbWebRadio.setBorder(null);
    jtbWebRadio.setRollover(true);
    jtbWebRadio.setFloatable(false);
    ddbWebRadio.addToToolBar(jtbWebRadio);

    // Play toolbar
    JToolBar jtbPlay = new JToolBar();
    jtbPlay.setBorder(null);
    jtbPlay.setFloatable(false);
    // add some space to get generic size
    jtbPlay.setRollover(true);
    ActionUtil.installKeystrokes(
        jtbPlay, ActionManager.getAction(NEXT_ALBUM), ActionManager.getAction(PREVIOUS_ALBUM));
    jbPrevious = new JajukButton(ActionManager.getAction(PREVIOUS_TRACK));
    jbNext = new JajukButton(ActionManager.getAction(NEXT_TRACK));
    jbRew = new JPressButton(ActionManager.getAction(REWIND_TRACK));
    jbPlayPause = new JajukButton(ActionManager.getAction(PLAY_PAUSE_TRACK));
    jbStop = new JajukButton(ActionManager.getAction(STOP_TRACK));
    jbFwd = new JPressButton(ActionManager.getAction(FAST_FORWARD_TRACK));

    jtbPlay.add(jbPrevious);
    jtbPlay.add(jbRew);
    jtbPlay.add(jbPlayPause);
    jtbPlay.add(jbStop);
    jtbPlay.add(jbFwd);
    jtbPlay.add(jbNext);

    // Add items
    FormLayout layout =
        new FormLayout(
            // --columns
            "3dlu,fill:min(10dlu;p):grow(0.5), 3dlu, "
                + // ambience
                "left:p, 2dlu"
                + // smart toolbar
                ", min(0dlu;p):grow(0.04), 3dlu,"
                + // glue
                " right:p, 10dlu, "
                + // search /modes
                "fill:p, 5dlu, "
                + // history/player
                "fill:min(60dlu;p):grow(0.2),3dlu", // volume/part of
            // history
            // --rows
            "2dlu, p, 2dlu, p, 2dlu"); // rows
    PanelBuilder builder = new PanelBuilder(layout); // , new
    // FormDebugPanel() );
    CellConstraints cc = new CellConstraints();
    // Add items
    builder.add(jtbWebRadio, cc.xyw(2, 2, 3)); // grid width = 3
    builder.add(ambiencesCombo, cc.xy(2, 4));
    builder.add(jtbSpecial, cc.xy(4, 4));
    builder.add(jpSearch, cc.xyw(6, 2, 4));
    builder.add(jpHistory, cc.xyw(10, 2, 4));
    builder.add(jtbModes, cc.xy(8, 4));
    builder.add(jtbPlay, cc.xy(10, 4));
    builder.add(jpVolume, cc.xy(12, 4));
    JPanel p = builder.getPanel();
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    add(p);
    // register to player events
    ObservationManager.register(CommandJPanel.this);

    // if a track is playing, display right state
    if (FIFO.getInstance().getCurrentFile() != null) {
      // update initial state
      update(
          new Event(
              EventSubject.EVENT_PLAYER_PLAY,
              ObservationManager.getDetailsLastOccurence(EventSubject.EVENT_PLAYER_PLAY)));
      // update the history bar
      update(new Event(EventSubject.EVENT_FILE_LAUNCHED));
      // check if some track has been launched before the view has been
      // displayed
      update(new Event(EventSubject.EVENT_HEART_BEAT));
    }
    // start timer
    timer.start();
  }
Ejemplo n.º 22
0
  /*
   * (non-Javadoc)
   *
   * @see org.jajuk.ui.views.IView#populate()
   */
  public void initUI() {
    jlLanguage = new JLabel(Messages.getString("WikipediaView.1"));
    jcbLanguage = new JComboBox();
    for (String sDesc : Messages.getDescs()) {
      jcbLanguage.addItem(sDesc);
    }
    // get stored language
    jcbLanguage.setSelectedItem(
        Messages.getDescForLocal(ConfigurationManager.getProperty(CONF_WIKIPEDIA_LANGUAGE)));
    jcbLanguage.addActionListener(this);
    // Buttons
    ActionBase aCopy = ActionManager.getAction(JajukAction.COPY_TO_CLIPBOARD);
    jbCopy = new JButton(aCopy);
    jbLaunchInExternalBrowser = new JButton(ActionManager.getAction(JajukAction.LAUNCH_IN_BROWSER));
    // Remove text inside the buttons
    jbLaunchInExternalBrowser.setText(null);
    jbCopy.setText(null);
    ButtonGroup bg = new ButtonGroup();
    jbAuthorSearch = new JToggleButton(IconLoader.ICON_AUTHOR, false);
    jbAuthorSearch.setToolTipText(Messages.getString("WikipediaView.5"));
    // Select author search (default)
    jbAuthorSearch.setSelected(true);
    jbAuthorSearch.addActionListener(this);
    jbAlbumSearch = new JToggleButton(IconLoader.ICON_ALBUM, true);
    jbAlbumSearch.setToolTipText(Messages.getString("WikipediaView.6"));
    jbAlbumSearch.addActionListener(this);
    jbTrackSearch = new JToggleButton(IconLoader.ICON_TRACK, false);
    jbTrackSearch.setToolTipText(Messages.getString("WikipediaView.7"));
    jbTrackSearch.addActionListener(this);
    // Group this three mutual exclusive buttons
    bg.add(jbAuthorSearch);
    bg.add(jbAlbumSearch);
    bg.add(jbTrackSearch);

    JToolBar jtb = new JToolBar();
    jtb.setFloatable(false);
    jtb.setRollover(true);
    jtb.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    // Add items
    jtb.add(jbAuthorSearch);
    jtb.add(jbAlbumSearch);
    jtb.add(jbTrackSearch);
    jtb.addSeparator();
    jtb.add(jbCopy);
    jtb.add(jbLaunchInExternalBrowser);
    jtb.addSeparator();
    jtb.add(jcbLanguage);

    JPanel jpCommand = new JPanel();
    jpCommand.setBorder(BorderFactory.createEtchedBorder());
    jpCommand.setLayout(new FlowLayout(FlowLayout.LEFT));
    jpCommand.add(jtb);

    // global layout
    double size[][] = {{2, TableLayout.FILL, 5}, {TableLayout.PREFERRED, 5, TableLayout.FILL}};
    setLayout(new TableLayout(size));
    browser = new JajukHtmlPanel();
    add(jpCommand, "1,0");
    add(browser, "1,2");

    // Display default page at startup is none track launch
    // avoid to launch this if a track is playing
    // to avoid thread concurrency
    if (FIFO.getInstance().getCurrentFile() == null) {
      reset();
    }

    // subscriptions to events
    ObservationManager.register(WikipediaView.this);

    // force event
    update(
        new Event(
            EventSubject.EVENT_FILE_LAUNCHED,
            ObservationManager.getDetailsLastOccurence(EventSubject.EVENT_FILE_LAUNCHED)));
  }
Ejemplo n.º 23
0
  public TestPanel(Risk r, PicturePanel p) {

    myrisk = r;
    pp = p;

    setName("Testing");

    setOpaque(false);

    toolbar = new JToolBar();

    toolbar.setRollover(true);
    toolbar.setFloatable(false);

    JButton refresh = new JButton("Refresh");
    refresh.setActionCommand("refresh");
    refresh.addActionListener(this);
    toolbar.add(refresh);

    JButton allcards = new JButton("All Cards");
    allcards.setActionCommand("allcards");
    allcards.addActionListener(this);
    toolbar.add(allcards);

    toolbar.addSeparator();

    JButton flash = new JButton("Run FlashGUI with current backend");
    flash.setActionCommand("flash");
    flash.addActionListener(this);
    toolbar.add(flash);

    toolbar.addSeparator();

    JButton changeaiwait = new JButton("Change AI wait");
    changeaiwait.setActionCommand("aiwait");
    changeaiwait.addActionListener(this);
    toolbar.add(changeaiwait);

    toolbar.addSeparator();

    JButton mapServerNameChack = new JButton("Check MapServer");
    mapServerNameChack.setActionCommand("checkMapServer");
    mapServerNameChack.addActionListener(this);
    toolbar.add(mapServerNameChack);

    countriesModel =
        new AbstractTableModel() {

          private final String[] columnNames = {
            "Color/No.",
            "ID",
            "Name",
            "x",
            "y",
            "Continent",
            "Owner",
            "Armies",
            "No. Neighbours",
            "in",
            "con"
          };

          public int getColumnCount() {
            return columnNames.length;
          }

          public int getRowCount() {

            RiskGame game = myrisk.getGame();

            if (game != null) {

              Country[] countries = game.getCountries();

              if (countries != null) {

                return countries.length;
              }
            }

            return 0;
          }

          public String getColumnName(int col) {
            return columnNames[col];
          }

          public Object getValueAt(int row, int col) {

            Country country = myrisk.getGame().getCountries()[row];

            switch (col) {
              case 0:
                return new Integer(country.getColor());
              case 1:
                return country.getIdString();
              case 2:
                return country.getName();
              case 3:
                return new Integer(country.getX());
              case 4:
                return new Integer(country.getY());
              case 5:
                return country.getContinent();
              case 6:
                return country.getOwner();
              case 7:
                return new Integer(country.getArmies());
              case 8:
                {
                  List neighbours = country.getNeighbours();
                  if (neighbours == null) return null;
                  return new Integer(neighbours.size());
                }
              case 9:
                {
                  List neighbours = country.getIncomingNeighbours();
                  if (neighbours == null) return null;
                  return new Integer(neighbours.size());
                }
              case 10:
                {
                  List neighbours = country.getCrossContinentNeighbours();
                  if (neighbours == null) return null;
                  return new Integer(neighbours.size());
                }
              default:
                throw new RuntimeException();
            }
          }
        };

    continentsModel =
        new AbstractTableModel() {

          private final String[] columnNames = {
            "No.", "ID", "Name", "Army Value", "No. Countries", "Color"
          };

          public int getColumnCount() {
            return columnNames.length;
          }

          public int getRowCount() {

            RiskGame game = myrisk.getGame();

            if (game != null) {

              Continent[] continents = game.getContinents();

              if (continents != null) {

                return continents.length;
              }
            }

            return 0;
          }

          public String getColumnName(int col) {
            return columnNames[col];
          }

          public Object getValueAt(int row, int col) {

            Continent continent = myrisk.getGame().getContinents()[row];

            switch (col) {
              case 0:
                return new Integer(row + 1);
              case 1:
                return continent.getIdString();
              case 2:
                return continent.getName();
              case 3:
                return new Integer(continent.getArmyValue());
              case 4:
                return new Integer(continent.getTerritoriesContained().size());
              case 5:
                return ColorUtil.getStringForColor(continent.getColor());
              default:
                throw new RuntimeException();
            }
          }
        };

    cardsModel =
        new CardsTableModel() {
          List getCards() {
            RiskGame game = myrisk.getGame();
            if (game != null) {
              List l = game.getCards();
              return l == null ? Collections.EMPTY_LIST : l;
            }
            return Collections.EMPTY_LIST;
          }
        };

    cardsModel2 =
        new CardsTableModel() {
          List getCards() {
            RiskGame game = myrisk.getGame();
            if (game != null) {
              List l = game.getUsedCards();
              return l == null ? Collections.EMPTY_LIST : l;
            }
            return Collections.EMPTY_LIST;
          }
        };

    playersModel =
        new AbstractTableModel() {

          private final String[] columnNames = {
            "Name",
            "Color",
            "Type",
            "Extra Armies",
            "No. Cards",
            "No. Countries",
            "No. Player Eliminated",
            "Capital",
            "Mission",
            "Address",
            "autodefend",
            "autoendgo"
          };

          public int getColumnCount() {
            return columnNames.length;
          }

          public int getRowCount() {

            RiskGame game = myrisk.getGame();

            if (game != null) {

              Vector players = game.getPlayers();

              if (players != null) {

                return players.size();
              }
            }

            return 0;
          }

          public String getColumnName(int col) {
            return columnNames[col];
          }

          public Object getValueAt(int row, int col) {

            Player player = (Player) myrisk.getGame().getPlayers().elementAt(row);

            switch (col) {
              case 0:
                return player.getName();
              case 1:
                return ColorUtil.getStringForColor(player.getColor());
              case 2:
                return myrisk.getType(player.getType());
              case 3:
                return new Integer(player.getExtraArmies());
              case 4:
                return new Integer(player.getCards().size());
              case 5:
                return new Integer(player.getNoTerritoriesOwned());
              case 6:
                return new Integer(player.getPlayersEliminated().size());
              case 7:
                return player.getCapital();
              case 8:
                return player.getMission();
              case 9:
                return player.getAddress();
              case 10:
                return new Boolean(player.getAutoDefend());
              case 11:
                return new Boolean(player.getAutoEndGo());
              default:
                throw new RuntimeException();
            }
          }

          @Override
          public boolean isCellEditable(int row, int col) {
            switch (col) {
              case 0: // name
              case 2: // type
              case 9: // address
                return true;
              default:
                return false;
            }
          }

          @Override
          public void setValueAt(Object aValue, int row, int col) {
            Player player = (Player) myrisk.getGame().getPlayers().elementAt(row);

            try {
              String name = col == 0 ? String.valueOf(aValue) : player.getName();
              if (name.equals("")) {
                throw new IllegalArgumentException("no empty name");
              }
              int type = col == 2 ? myrisk.getType(String.valueOf(aValue)) : player.getType();
              if (type == -1) {
                throw new IllegalArgumentException("bad type " + aValue);
              }
              String address = col == 9 ? String.valueOf(aValue) : player.getAddress();
              if (address.equals("")) {
                throw new IllegalArgumentException("no empty address");
              }

              HashMap map = new HashMap();
              map.put("oldName", player.getName());
              map.put("newName", name);
              map.put("newType", type);
              map.put("newAddress", address);
              myrisk.parserFromNetwork("RENAME " + Url.toQueryString(RiskUtil.asHashtable(map)));
            } catch (Exception ex) {
              System.out.println("error " + ex);
            }
          }
        };

    gameInfo =
        new ObjectTableModel() {
          public Object getObject() {
            return myrisk.getGame();
          }
        };

    commands =
        new AbstractTableModel() {

          private final String[] columnNames = {"No", "Command"};

          public int getColumnCount() {
            return columnNames.length;
          }

          public int getRowCount() {
            RiskGame game = myrisk.getGame();
            if (game != null) {
              List players = game.getCommands();
              if (players != null) {
                return players.size();
              }
            }
            return 0;
          }

          public String getColumnName(int col) {
            return columnNames[col];
          }

          public Object getValueAt(int row, int col) {
            Object command = myrisk.getGame().getCommands().elementAt(row);
            switch (col) {
              case 0:
                return String.valueOf(row);
              case 1:
                return String.valueOf(command);
              default:
                throw new RuntimeException();
            }
          }
        };

    JTabbedPane views = new JTabbedPane();

    views.add("Countries", new JScrollPane(new JTable(countriesModel)));
    views.add("Continents", new JScrollPane(new JTable(continentsModel)));
    views.add("Cards", new JScrollPane(new JTable(cardsModel)));
    views.add("Spent Cards", new JScrollPane(new JTable(cardsModel2)));
    views.add("Players", new JScrollPane(new JTable(playersModel)));
    views.add("Game", new JScrollPane(new JTable(gameInfo)));

    JTable commandsTable = new JTable(commands);
    commandsTable.setCellSelectionEnabled(true);

    views.add("Commands", new JScrollPane(commandsTable));

    setLayout(new BorderLayout());
    add(views);
  }
Ejemplo n.º 24
0
  /** The only constructor of the class. It launches the main window. */
  @SuppressWarnings("unchecked")
  public MainFrame() throws Exception {
    super("StatAlign " + StatAlign.version);

    try {
      String syslook = UIManager.getSystemLookAndFeelClassName();
      if (!UIManager.getLookAndFeel().getClass().getName().equals(syslook)) {
        UIManager.setLookAndFeel(syslook);
        SwingUtilities.updateComponentTreeUI(this);
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(this, ex);
    }

    ArrayList<Class<?>> substModList = new ArrayList<Class<?>>();
    for (String model :
        Utils.classesInPackage(SubstitutionModel.class.getPackage().getName() + ".plugins")) {
      try {
        Class<?> cl = Class.forName(model);
        /* Only include non-abstract substitution models that extend SubstitutionModel */
        if (!Modifier.isAbstract(cl.getModifiers()) && SubstitutionModel.class.isAssignableFrom(cl))
          substModList.add(cl);
      } catch (Exception ex) {
      }
    }

    substModels =
        (Class<? extends SubstitutionModel>[])
            substModList.toArray(new Class<?>[substModList.size()]);
    manager = new MainManager(this);
    mcmcSettingsDlg = new McmcSettingsDlg(this);

    setMinimumSize(new Dimension(500, 250));

    ///
    /// Creates the MenuBar and the ToolBar
    ///

    toolBar = new JToolBar();
    toolBar.setFloatable(false);
    toolBar.setRollover(true);
    JMenuBar menubar = new JMenuBar();

    JMenu menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_F);
    JMenuItem item;

    String openText = "Add sequence(s)...";
    ImageIcon icon = new ImageIcon(ClassLoader.getSystemResource("icons/open.png"));
    openItem = createMenuItem(openText, true);
    openItem.setAccelerator(KeyStroke.getKeyStroke("control O"));
    openItem.setMnemonic(KeyEvent.VK_A);
    openItem.setIcon(icon);
    menu.add(openItem);

    openButton = createButton(icon, "Add sequence(s)...");
    toolBar.add(openButton);

    toolBar.addSeparator();

    JMenuItem ioPreferencesItem = createMenuItem("Preferences...", true);
    ioPreferencesItem.setAccelerator(KeyStroke.getKeyStroke("control 1"));
    ioPreferencesItem.setMnemonic(KeyEvent.VK_P);
    menu.add(ioPreferencesItem);

    menu.addSeparator();

    item = createMenuItem("Exit", true);
    item.setAccelerator(KeyStroke.getKeyStroke("alt F4"));
    item.setMnemonic(KeyEvent.VK_X);
    menu.add(item);
    menubar.add(menu);

    //		menu = new JMenu("Edit");
    //		menu.setMnemonic(KeyEvent.VK_E);
    //		item = new JMenuItem("Cut");
    //		item.addActionListener(this);
    //		item.setAccelerator(KeyStroke.getKeyStroke("control X"));
    //		menu.add(item);
    //		item = new JMenuItem("Copy");
    //		item.addActionListener(this);
    //		item.setAccelerator(KeyStroke.getKeyStroke("control C"));
    //		menu.add(item);
    //		item = new JMenuItem("Paste");
    //		item.addActionListener(this);
    //		item.setAccelerator(KeyStroke.getKeyStroke("control V"));
    //		menu.add(item);
    //		menubar.add(menu);

    menu = new JMenu("Analysis");
    menu.setMnemonic(KeyEvent.VK_M);

    //        item = createMenuItem("Settings", true);
    //        item.setAccelerator(KeyStroke.getKeyStroke("control M"));
    //        item.setMnemonic(KeyEvent.VK_S);
    //        menu.add(item);

    String runText = "Set up and run";
    icon = new ImageIcon(ClassLoader.getSystemResource("icons/play.png"));
    runItem = createMenuItem(runText, false);
    runItem.setAccelerator(KeyStroke.getKeyStroke("control ENTER"));
    runItem.setIcon(icon);
    menu.add(runItem);
    menu.addSeparator();

    runButton = createButton(icon, runText);
    runButton.setEnabled(false);
    toolBar.add(runButton);

    String pauseText = "Pause";
    icon = new ImageIcon(ClassLoader.getSystemResource("icons/pause.png"));
    pauseItem = createMenuItem("Pause", false);
    pauseItem.setIcon(icon);
    menu.add(pauseItem);

    pauseButton = createButton(icon, pauseText);
    pauseButton.setEnabled(false);
    toolBar.add(pauseButton);

    String resumeText = "Resume";
    icon = new ImageIcon(ClassLoader.getSystemResource("icons/resume.png"));
    resumeItem = createMenuItem(resumeText, false);
    resumeItem.setIcon(icon);
    menu.add(resumeItem);

    resumeButton = createButton(icon, resumeText);
    resumeButton.setEnabled(false);
    toolBar.add(resumeButton);

    String stopText = "Stop";
    icon = new ImageIcon(ClassLoader.getSystemResource("icons/stop.png"));
    stopItem = createMenuItem("Stop", false);
    stopItem.setIcon(icon);
    menu.add(stopItem);
    menubar.add(menu);

    stopButton = createButton(icon, stopText);
    stopButton.setEnabled(false);
    toolBar.add(stopButton);

    String rnaText = "RNA mode";
    rnaButton =
        createToggleButton(new ImageIcon(ClassLoader.getSystemResource("icons/rna1.png")), rnaText);
    rnaButton.setEnabled(false);
    rnaButton.setSelected(false);
    toolBar.add(rnaButton);

    //        String settingsText = "Settings";
    //        JButton settingsButton = createButton(new ImageIcon(ClassLoader.
    //        		getSystemResource("icons/settings.png")), settingsText);
    //        toolBar.add(settingsButton);

    menu = new JMenu("Model");
    menu.setMnemonic(KeyEvent.VK_L);

    modelButtons = new JMenuItem[substModels.length];
    ButtonGroup modelGroup = new ButtonGroup();
    HashMap<String, ArrayList<Class<? extends SubstitutionModel>>> substModTypes =
        new HashMap<String, ArrayList<Class<? extends SubstitutionModel>>>();
    for (Class<? extends SubstitutionModel> cl : substModels) {
      String type = SubstitutionModel.getType(cl);
      ArrayList<Class<? extends SubstitutionModel>> arr = substModTypes.get(type);
      if (arr == null)
        substModTypes.put(type, arr = new ArrayList<Class<? extends SubstitutionModel>>());
      arr.add(cl);
    }
    String[] typeArr = new String[substModTypes.keySet().size()];
    int s = 0;
    if (typeArr.length >= 2) {
      typeArr[0] = "protein"; // amino acid subst models first
      typeArr[1] = "nucleotide"; // then nucleotide models, then the rest
      s = 2;
    }
    for (String type : substModTypes.keySet()) {
      if (!type.equals("protein") && !type.equals("nucleotide")) typeArr[s++] = type;
    }
    s = 0;
    for (String type : typeArr) {
      if (s > 0) menu.addSeparator();
      for (Class<? extends SubstitutionModel> cl : substModTypes.get(type)) {
        String name = SubstitutionModel.getMenuName(cl);
        item = new JRadioButtonMenuItem(name);
        item.addActionListener(this);
        modelButtons[s++] = item;
        modelGroup.add(item);
        menu.add(item);
      }
    }
    modelGroup.clearSelection();
    menubar.add(menu);

    /*menu = new JMenu("View");
    menu.setMnemonic(KeyEvent.VK_V);
    JMenuItem zoomInItem = new JMenuItem("Zoom in");
    zoomInItem.setEnabled(false);
    zoomInItem.addActionListener(this);
    menu.add(zoomInItem);
    JMenuItem zoomOutItem = new JMenuItem("Zoom out");
    zoomOutItem.setEnabled(false);
    zoomOutItem.addActionListener(this);
    menu.add(zoomOutItem);
    JMenuItem autofitItem = new JMenuItem("Fit to frame");
    autofitItem.setEnabled(false);
    autofitItem.addActionListener(this);
    menu.add(autofitItem);

    menubar.add(menu);*/

    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    item = new JMenuItem("About...");
    item.addActionListener(this);
    menu.add(item);
    menu.addSeparator();
    item = new JMenuItem("Help for users");
    item.addActionListener(this);
    menu.add(item);
    menu.addSeparator();
    item = new JMenuItem("Html doc for developers");
    item.addActionListener(this);
    menu.add(item);
    item = new JMenuItem("Description of plugins");
    item.addActionListener(this);
    menu.add(item);

    menubar.add(menu);

    setJMenuBar(menubar);
    add(toolBar, BorderLayout.PAGE_START);

    ///
    /// Creates the main panel
    ///

    Container cp = getContentPane();
    JPanel mainPanel = new JPanel(new BorderLayout());
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    mainPanel.setMinimumSize(new Dimension(screenSize.width / 3, screenSize.height / 3));
    mainPanel.setMaximumSize(new Dimension(screenSize.width, screenSize.height));
    mainPanel.setPreferredSize(new Dimension(screenSize.width / 2, screenSize.height / 2));

    tab = new JTabbedPane();

    input = new Input(manager);
    tab.addTab(input.getTabName(), input.getIcon(), input.getJPanel(), input.getTip());
    manager.inputgui = input.inputgui;

    // Sorts the tab according to their getTabOrder()
    pluginTabs = manager.postProcMan.plugins.clone();
    Arrays.sort(
        pluginTabs,
        new Comparator<Postprocess>() {
          @Override
          public int compare(Postprocess firstTab, Postprocess secondTab) {
            return Double.compare(firstTab.getTabOrder(), secondTab.getTabOrder());
          }
        });

    tabPluginMap = new HashMap<Integer, Postprocess>();
    for (int i = 0; i < pluginTabs.length; i++) {
      Postprocess plugin = pluginTabs[i];
      if (plugin.selected && !plugin.rnaAssociated) {
        tabPluginMap.put(i + 1, plugin); // TODO: Jesus Java, horrible.
        tab.addTab(plugin.getTabName(), plugin.getIcon(), plugin.getJPanel(), plugin.getTip());
      }
    }

    tab.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane pane = (JTabbedPane) changeEvent.getSource();
            Integer i = pane.getSelectedIndex();

            // Remove the last tabs toolbar items.
            if (lastSelectedTabIndex != -1) {
              Postprocess lastPlugin = tabPluginMap.get(lastSelectedTabIndex);
              if (lastPlugin != null && lastPlugin.hasToolBar) {
                for (JComponent item : lastPlugin.getToolBarItems()) {
                  toolBar.remove(item);
                }
                toolBar.revalidate(); // TODO: optimize.
                toolBar.repaint();
              }
            }

            // Add the currents tab toolbar items.
            Postprocess plugin = tabPluginMap.get(i);
            if (plugin != null && plugin.hasToolBar) {
              for (JComponent item : plugin.getToolBarItems()) {
                toolBar.add(item);
              }
              toolBar.revalidate();
              toolBar.repaint();
            }
            lastSelectedTabIndex = i;
          }
        });

    mainPanel.add(tab, BorderLayout.CENTER);

    cp.add(mainPanel, BorderLayout.CENTER);
    JPanel statusBar = new JPanel(new BorderLayout());
    statusText = new JLabel(IDLE_STATUS_MESSAGE);
    statusBar.add(statusText, BorderLayout.CENTER);
    cp.add(statusBar, BorderLayout.SOUTH);

    //		setSize(300, 200);
    //		setLocationByPlatform(true);
    //    	setLocation(screenSize.width/4,screenSize.height/4);
    pack();
    setBounds(
        screenSize.width / 5 - 15,
        screenSize.height / 5 - 15,
        screenSize.width * 3 / 5 + 30,
        screenSize.height * 3 / 5 + 30);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
Ejemplo n.º 25
0
  private MainFrame(String title) {

    setTitle(title);
    java.net.URL imgURL;

    getContentPane().setLayout(new BorderLayout(0, 0));

    JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    toolBar.setBounds(20, 60, 154, -30);
    getContentPane().add(toolBar, BorderLayout.NORTH);

    tabPane = new JTabbedPane();
    getContentPane().add(tabPane, BorderLayout.CENTER);

    JButton btnImpExcel = new JButton("导入Excel");
    imgURL = this.getClass().getResource("/images/excel.png");
    if (imgURL != null) {
      btnImpExcel.setIcon(new ImageIcon(imgURL.getFile()));
    }
    btnImpExcel.setToolTipText("打开Excel文件,显示表单内容并存入到数据库中");
    btnImpExcel.addActionListener(new ImportExcelListener(tabPane));

    // 刷新数据列表
    JButton btnRefreshDB = new JButton("\u5237\u65B0\u6570\u636E");
    btnRefreshDB.setToolTipText("刷新数据列表");
    imgURL = this.getClass().getResource("/images/refresh.png");
    if (imgURL != null) {
      btnRefreshDB.setIcon(new ImageIcon(imgURL.getFile()));
    }
    btnRefreshDB.addActionListener(new listener.DataRefreshListener(tabPane, panelTable));

    // 查看历史记录
    JButton btnViewImpRec = new JButton("\u6587\u4EF6\u5BFC\u5165\u8BB0\u5F55");
    imgURL = this.getClass().getResource("/images/records32.png");
    if (imgURL != null) {
      btnViewImpRec.setIcon(new ImageIcon(imgURL.getFile()));
    }

    btnViewImpRec.setToolTipText("查看导入过的历史数据文件,所有导入过的文件以列表形式展示出来");
    btnViewImpRec.addActionListener(new listener.ViewImpRecListener(tabPane));

    // 统计
    JButton btnStatistics = new JButton("销售统计");
    imgURL = this.getClass().getResource("/images/piechart.png");
    if (imgURL != null) {
      btnStatistics.setIcon(new ImageIcon(imgURL.getFile()));
    }

    btnStatistics.setToolTipText("对销售数据进行统计分析");
    btnStatistics.addActionListener(new listener.StatisticsSalesRecordListener(tabPane));

    // 将定义的工具按钮添加至工具栏
    toolBar.add(btnRefreshDB); // 刷新数据
    toolBar.add(btnImpExcel); // 导入excel
    toolBar.add(btnViewImpRec); // 查看导入记录
    toolBar.add(btnStatistics);
    toolBar.addSeparator();

    tabPane.addTab("销售记录", panelTable);
    //		tabPane.addTab("销售记录",  new javax.swing.JLabel() );
    for (int i = 1; i < tabPane.getTabCount(); i++) {
      tabPane.setTabComponentAt(i, new utilities.ButtonTabComponent(tabPane));
    }

    statusBar = new controls.StatusBar();

    // 添加一个状态栏
    getContentPane().add(statusBar, BorderLayout.SOUTH);
  }