Exemplo n.º 1
0
  /**
   * Päivittää käyttäjän syöttämät tiedot <code>DocumentTypeModel</code>ille.
   *
   * @return <code>true</code>, jos tietojen päivittäminen onnistui
   */
  public boolean updateModel() {
    int count = model.getDocumentTypeCount();
    DocumentType type;

    for (int i = 0; i < count; i++) {
      type = model.getDocumentType(i);

      if (type.getNumber() < 1) {
        SwingUtils.showErrorMessage(this, "Virheellinen numero.");
        return false;
      }

      if (type.getName().length() == 0) {
        SwingUtils.showErrorMessage(this, "Syötä tositelajin nimi ennen tallentamista.");
        return false;
      }

      if (type.getNumberStart() < 1) {
        SwingUtils.showErrorMessage(this, "Virheellinen tositenumerovälin alku.");
        return false;
      }

      if (type.getNumberEnd() < 1) {
        SwingUtils.showErrorMessage(this, "Virheellinen tositenumerovälin loppu.");
        return false;
      }
    }

    return true;
  }
Exemplo n.º 2
0
 public NodeSelectionDialog(Frame owner, NodeLibrary library, NodeLibraryManager manager) {
   super(owner, "New Node", true);
   getRootPane().putClientProperty("Window.style", "small");
   JPanel panel = new JPanel(new BorderLayout());
   this.library = library;
   this.manager = manager;
   filteredNodeListModel = new FilteredNodeListModel(library, manager);
   searchField = new JTextField();
   searchField.putClientProperty("JTextField.variant", "search");
   EscapeListener escapeListener = new EscapeListener();
   searchField.addKeyListener(escapeListener);
   ArrowKeysListener arrowKeysListener = new ArrowKeysListener();
   searchField.addKeyListener(arrowKeysListener);
   SearchFieldChangeListener searchFieldChangeListener = new SearchFieldChangeListener();
   searchField.getDocument().addDocumentListener(searchFieldChangeListener);
   nodeList = new JList(filteredNodeListModel);
   DoubleClickListener doubleClickListener = new DoubleClickListener();
   nodeList.addMouseListener(doubleClickListener);
   nodeList.addKeyListener(escapeListener);
   nodeList.addKeyListener(arrowKeysListener);
   nodeList.setSelectedIndex(0);
   nodeList.setCellRenderer(new NodeRenderer());
   JScrollPane nodeScroll =
       new JScrollPane(
           nodeList,
           JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
           JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
   nodeScroll.setBorder(null);
   panel.add(searchField, BorderLayout.NORTH);
   panel.add(nodeScroll, BorderLayout.CENTER);
   setContentPane(panel);
   setSize(500, 400);
   SwingUtils.centerOnScreen(this);
 }
Exemplo n.º 3
0
  private void createToolBar() {
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);

    toolBar.add(SwingUtils.createToolButton("close-22x22.png", "Sulje", closeListener, true));

    toolBar.add(SwingUtils.createToolButton("save-22x22.png", "Tallenna", saveListener, true));

    toolBar.addSeparator();
    toolBar.add(SwingUtils.createToolButton("list-add-22x22.png", "Lisää", addRowListener, true));

    toolBar.add(
        SwingUtils.createToolButton("list-remove-22x22.png", "Poista", removeRowListener, true));

    add(toolBar, BorderLayout.NORTH);
  }
Exemplo n.º 4
0
  private static Component createDescription(Example example, ExampleGroup group) {
    Color foreground = group.getPreferredForeground();

    WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING);
    titleLabel.setDrawShade(true);
    titleLabel.setForeground(foreground);
    if (foreground.equals(Color.WHITE)) {
      titleLabel.setShadeColor(Color.BLACK);
    }

    if (example.getDescription() == null) {
      return titleLabel;
    } else {
      WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING);
      descriptionLabel.setForeground(Color.GRAY);
      SwingUtils.changeFontSize(descriptionLabel, -1);

      WebPanel vertical =
          new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false));
      vertical.setOpaque(false);
      vertical.add(titleLabel);
      vertical.add(descriptionLabel);

      return vertical;
    }
  }
Exemplo n.º 5
0
  /** Luo ikkunan valikot. */
  private void createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu;

    menu = new JMenu("Tositelajit");
    menu.setMnemonic('T');
    menuBar.add(menu);

    int shortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    menu.add(
        SwingUtils.createMenuItem(
            "Lisää",
            "list-add-16x16.png",
            'L',
            KeyStroke.getKeyStroke('N', shortcutKeyMask),
            addRowListener));

    menu.add(
        SwingUtils.createMenuItem("Poista", "list-remove-16x16.png", 'P', null, removeRowListener));

    menu.addSeparator();
    menu.add(
        SwingUtils.createMenuItem(
            "Tallenna",
            "save-16x16.png",
            'a',
            KeyStroke.getKeyStroke('S', shortcutKeyMask),
            saveListener));

    menu.add(
        SwingUtils.createMenuItem(
            "Sulje",
            "close-16x16.png",
            'S',
            KeyStroke.getKeyStroke('W', shortcutKeyMask),
            closeListener));

    setJMenuBar(menuBar);
  }
Exemplo n.º 6
0
  @Override
  protected void paintComponent(Graphics g) {
    java.util.List<Network> networks = getNetworkParts();
    positions = new int[networks.size()];
    Graphics2D g2 = (Graphics2D) g;

    g2.setFont(SMALL_BOLD_FONT);

    g2.setPaint(addressGradientPaint);
    g2.fill(g2.getClipBounds());
    // g2.drawImage(addressGradient, 0, 0, getWidth(), 26, null);

    int x = 14;

    for (int i = 0; i < networks.size(); i++) {
      Network part = networks.get(i);
      if (i == armed) {
        g2.setColor(TEXT_ARMED_COLOR);
      } else {
        g2.setColor(TEXT_NORMAL_COLOR);
      }
      String displayName = part.getDisplayName();
      SwingUtils.drawShadowText(g2, displayName, x, 16);

      int width = (int) g2.getFontMetrics().stringWidth(displayName);
      x += width + 5;
      positions[i] = x + 10;
      g2.drawImage(addressArrow, x, 0, null);
      x += 15;
    }

    String version = Application.getInstance().getVersion();
    int versionX = getWidth() - g2.getFontMetrics().stringWidth(version) - 10;
    SwingUtils.drawShadowText(g2, version, versionX, 16);

    if (renderException != null) {
      g2.drawImage(addressExclamation, versionX - 30, 0, null);
    }
  }
Exemplo n.º 7
0
  private boolean trySave() {
    if (!updateModel()) {
      return false;
    }

    try {
      model.save();
    } catch (DataAccessException e) {
      String message = "Vientimallien tallentaminen epäonnistui";
      logger.log(Level.SEVERE, message, e);
      SwingUtils.showDataAccessErrorMessage(this, e, message);
      return false;
    }

    return true;
  }
Exemplo n.º 8
0
 /** {@inheritDoc} */
 @Override
 public int getFontSize() {
   return SwingUtils.getFontSize(this);
 }
Exemplo n.º 9
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox changeFontSize(final int change) {
   return SwingUtils.changeFontSize(this, change);
 }
Exemplo n.º 10
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setFontSize(final int fontSize) {
   return SwingUtils.setFontSize(this, fontSize);
 }
Exemplo n.º 11
0
 /** {@inheritDoc} */
 @Override
 public boolean isItalicFont() {
   return SwingUtils.isItalicFont(this);
 }
Exemplo n.º 12
0
  public static Component createGroupView(WebLookAndFeelDemo owner, ExampleGroup group) {
    // Creating group view
    Component exampleView;
    List<Example> examples = group.getGroupExamples();
    if (group.isSingleExample() && examples.size() == 1) {
      Example example = examples.get(0);
      exampleView = example.getPreview(owner);
    } else {
      final List<Component> preview = new ArrayList<Component>();

      final WebPanel groupPanel =
          new WebPanel() {
            @Override
            public void setEnabled(boolean enabled) {
              for (Component previewComponent : preview) {
                SwingUtils.setEnabledRecursively(previewComponent, enabled);
              }
              super.setEnabled(enabled);
            }
          };
      groupPanel.putClientProperty(SwingUtils.HANDLES_ENABLE_STATE, true);
      groupPanel.setOpaque(false);
      exampleView = groupPanel;

      int rowsAmount = examples.size() > 1 ? examples.size() * 2 - 1 : 1;
      double[] rows = new double[6 + rowsAmount];
      rows[0] = TableLayout.FILL;
      rows[1] = 20;
      rows[2] = TableLayout.PREFERRED;
      for (int i = 3; i < rows.length - 3; i++) {
        rows[i] = TableLayout.PREFERRED;
      }
      rows[rows.length - 3] = TableLayout.PREFERRED;
      rows[rows.length - 2] = 20;
      rows[rows.length - 1] = TableLayout.FILL;

      double[] columns = {
        20,
        1f - group.getContentPartSize(),
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        group.getContentPartSize(),
        20
      };

      TableLayout groupLayout = new TableLayout(new double[][] {columns, rows});
      groupLayout.setHGap(4);
      groupLayout.setVGap(4);
      groupPanel.setLayout(groupLayout);

      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "2,0,2," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "4,0,4," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "6,0,6," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "8,0,8," + (rows.length - 1));

      groupPanel.add(
          group.modifySeparator(createHorizontalSeparator()), "0,2," + (columns.length - 1) + ",2");
      groupPanel.add(
          group.modifySeparator(createHorizontalSeparator()),
          "0," + (rows.length - 3) + "," + (columns.length - 1) + "," + (rows.length - 3));

      int row = 3;
      for (Example example : examples) {
        // Title & description
        groupPanel.add(createDescription(example, group), "1," + row);

        // Marks
        Component mark = createMark(owner, example);
        groupPanel.add(mark, "3," + row);

        // Source code
        Component source = createSourceButton(owner, example);
        groupPanel.add(source, "5," + row);

        // More usage examples
        Component usage = createPresentationButton(example);
        groupPanel.add(usage, "7," + row);

        SwingUtils.equalizeComponentsSize(mark, source, usage);

        // Preview
        Component previewComponent = createPreview(owner, example);
        groupPanel.add(previewComponent, "9," + row);
        preview.add(previewComponent);

        // Rows separator
        if (row > 3) {
          groupPanel.add(
              group.modifySeparator(createHorizontalSeparator()),
              "0," + (row - 1) + "," + (columns.length - 1) + "," + (row - 1),
              0);
        }

        row += 2;
      }
    }

    if (group.isShowWatermark()) {
      WebImage linkImage = new WebImage(logoIcon);
      linkImage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

      TooltipManager.setTooltip(linkImage, linkIcon, "Library site", TooltipWay.trailing);

      linkImage.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
              WebUtils.browseSiteSafely(WebLookAndFeelDemo.WEBLAF_SITE);
            }
          });

      WebOverlay linkOverlay =
          new WebOverlay(exampleView, linkImage, WebOverlay.LEADING, WebOverlay.BOTTOM);
      linkOverlay.setOverlayMargin(15, 15, 15, 15);
      linkOverlay.setOpaque(false);

      exampleView = linkOverlay;
    }

    return exampleView;
  }
Exemplo n.º 13
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setFontName(final String fontName) {
   return SwingUtils.setFontName(this, fontName);
 }
  public boolean recogniseWindow(Window window) {
    if (!(window instanceof JDialog)) return false;

    return (SwingUtils.titleContains(window, "Tip of the Day"));
  }
 public void handleWindow(Window window, int eventID) {
   if (!SwingUtils.clickButton(window, "Close")) {
     Utils.logError(
         "could not dismiss Tip of the Day because we could not find one of the controls.");
   }
 }
Exemplo n.º 16
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setFontSizeAndStyle(
     final int fontSize, final boolean bold, final boolean italic) {
   return SwingUtils.setFontSizeAndStyle(this, fontSize, bold, italic);
 }
Exemplo n.º 17
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setFontSizeAndStyle(final int fontSize, final int style) {
   return SwingUtils.setFontSizeAndStyle(this, fontSize, style);
 }
Exemplo n.º 18
0
 /** {@inheritDoc} */
 @Override
 public boolean isPlainFont() {
   return SwingUtils.isPlainFont(this);
 }
Exemplo n.º 19
0
 /** {@inheritDoc} */
 @Override
 public String getFontName() {
   return SwingUtils.getFontName(this);
 }
Exemplo n.º 20
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setItalicFont() {
   return SwingUtils.setItalicFont(this);
 }
Exemplo n.º 21
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setItalicFont(final boolean apply) {
   return SwingUtils.setItalicFont(this, apply);
 }
Exemplo n.º 22
0
  @Override
  public boolean recogniseWindow(Window window) {
    if (!(window instanceof JFrame)) return false;

    return (SwingUtils.titleContains(window, "Starting application..."));
  }