コード例 #1
1
  public void showItem() {

    if (!this.editorPanel.getViewer().isLanguageFunctionAvailable()) {

      return;
    }

    this.highlight =
        this.editorPanel
            .getEditor()
            .addHighlight(this.position, this.position + this.word.length(), null, true);

    final FindSynonymsActionHandler _this = this;

    QTextEditor editor = this.editorPanel.getEditor();

    Rectangle r = null;

    try {

      r = editor.modelToView(this.position);

    } catch (Exception e) {

      // BadLocationException!
      Environment.logError("Location: " + this.position + " is not valid", e);

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      return;
    }

    int y = r.y;

    // Show a panel of all the items.
    final QPopup p = this.popup;

    p.setOpaque(false);

    Synonyms syns = null;

    try {

      syns = this.projectViewer.getSynonymProvider().getSynonyms(this.word);

    } catch (Exception e) {

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      Environment.logError("Unable to lookup synonyms for: " + word, e);

      return;
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("ed"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 2));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("s"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 1));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    StringBuilder sb = new StringBuilder();

    if (syns.words.size() > 0) {

      sb.append("6px");

      for (int i = 0; i < syns.words.size(); i++) {

        if (sb.length() > 0) {

          sb.append(", ");
        }

        sb.append("p, 3px, [p,90px], 5px");
      }
      /*
                if (syns.words.size () > 0)
                {

                    sb.append (",5px");

                }
      */
    } else {

      sb.append("6px, p, 6px");
    }

    FormLayout summOnly = new FormLayout("3px, fill:380px:grow, 3px", sb.toString());
    PanelBuilder pb = new PanelBuilder(summOnly);

    CellConstraints cc = new CellConstraints();

    int ind = 2;

    Map<String, String> names = new HashMap();
    names.put(Synonyms.ADJECTIVE + "", "Adjectives");
    names.put(Synonyms.NOUN + "", "Nouns");
    names.put(Synonyms.VERB + "", "Verbs");
    names.put(Synonyms.ADVERB + "", "Adverbs");
    names.put(Synonyms.OTHER + "", "Other");

    if (syns.words.size() == 0) {

      JLabel l = new JLabel("No synonyms found.");
      l.setFont(l.getFont().deriveFont(Font.ITALIC));

      pb.add(l, cc.xy(2, 2));
    }

    // Determine what type of word we are looking for.
    for (Synonyms.Part i : syns.words) {

      JLabel l = new JLabel(names.get(i.type + ""));

      l.setFont(l.getFont().deriveFont(Font.ITALIC));
      l.setFont(l.getFont().deriveFont((float) UIUtils.getEditorFontSize(10)));
      l.setBorder(
          new CompoundBorder(
              new MatteBorder(0, 0, 1, 0, Environment.getBorderColor()),
              new EmptyBorder(0, 0, 3, 0)));

      pb.add(l, cc.xy(2, ind));

      ind += 2;

      HTMLEditorKit kit = new HTMLEditorKit();
      HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();

      JTextPane t = new JTextPane(doc);
      t.setEditorKit(kit);
      t.setEditable(false);
      t.setOpaque(false);

      StringBuilder buf =
          new StringBuilder(
              "<style>a { text-decoration: none; } a:hover { text-decoration: underline; }</style><span style='color: #000000; font-size: "
                  + ((int) UIUtils.getEditorFontSize(10) /*t.getFont ().getSize () + 2*/)
                  + "pt; font-family: "
                  + t.getFont().getFontName()
                  + ";'>");

      for (int x = 0; x < i.words.size(); x++) {

        String w = (String) i.words.get(x);

        buf.append("<a class='x' href='http://" + w + "'>" + w + "</a>");

        if (x < (i.words.size() - 1)) {

          buf.append(", ");
        }
      }

      buf.append("</span>");

      t.setText(buf.toString());

      t.addHyperlinkListener(
          new HyperlinkAdapter() {

            public void hyperlinkUpdate(HyperlinkEvent ev) {

              if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

                QTextEditor ed = _this.editorPanel.getEditor();

                ed.replaceText(
                    _this.position, _this.position + _this.word.length(), ev.getURL().getHost());

                ed.removeHighlight(_this.highlight);

                _this.popup.setVisible(false);

                _this.projectViewer.fireProjectEvent(
                    ProjectEvent.SYNONYM, ProjectEvent.REPLACE, ev.getURL().getHost());
              }
            }
          });

      // Annoying that we have to do this but it prevents the text from being too small.

      t.setSize(new Dimension(380, Short.MAX_VALUE));

      JScrollPane sp = new JScrollPane(t);

      t.setCaretPosition(0);

      sp.setOpaque(false);
      sp.getVerticalScrollBar().setValue(0);
      /*
                  sp.setPreferredSize (t.getPreferredSize ());
                  sp.setMaximumSize (new Dimension (380,
                                                    75));
      */
      sp.getViewport().setOpaque(false);
      sp.setOpaque(false);
      sp.setBorder(null);
      sp.getViewport().setBackground(Color.WHITE);
      sp.setAlignmentX(Component.LEFT_ALIGNMENT);

      pb.add(sp, cc.xy(2, ind));

      ind += 2;
    }

    JPanel pan = pb.getPanel();
    pan.setOpaque(true);
    pan.setBackground(Color.WHITE);

    this.popup.setContent(pan);

    // r.y -= this.editorPanel.getScrollPane ().getVerticalScrollBar ().getValue ();

    Point po = SwingUtilities.convertPoint(editor, r.x, r.y, this.editorPanel);

    r.x = po.x;
    r.y = po.y;

    // Subtract the insets of the editorPanel.
    Insets ins = this.editorPanel.getInsets();

    r.x -= ins.left;
    r.y -= ins.top;

    this.editorPanel.showPopupAt(this.popup, r, "above", true);
  }
コード例 #2
0
ファイル: WhatsNew.java プロジェクト: tzkiki32/quollwriter
  /*
      public String getWindowTitle ()
      {

          return "What's new in this version - " + Environment.getQuollWriterVersion ();

      }

      public String getHeaderTitle ()
      {

          return this.getWindowTitle ();

      }

      public String getHeaderIconType ()
      {

          return null;//"whatsnew";

      }
  */
  public String getFirstHelpText() {

    return String.format(
        "Welcome to version <b>%s</b>.  This window describes the various changes that have been made since the last version and lets you setup new features.  You can also see the <a href='help://version-changes/%s'>full list of changes online</a>.",
        Environment.getQuollWriterVersion().getVersion(),
        Environment.getQuollWriterVersion().getVersion().replace('.', '_'));
  }
コード例 #3
0
 // paints the player, items, and rooms
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Environment Layout = new Environment();
   Layout.drawRoom(mapX, mapY, g);
   Player PlayerSprite = new Player();
   PlayerSprite.drawPlayer(x, y, g);
   Layout.items(x, y, g, getItem);
 }
コード例 #4
0
 // creates the JFrame, and puts first room onto panel
 public static void main(String[] s) throws IOException {
   JFrame f = new JFrame();
   f.getContentPane().add(new Adventure());
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.pack();
   f.setVisible(true);
   Environment Layout = new Environment();
   wallLayout = Layout.walls(mapX, mapY);
 }
コード例 #5
0
ファイル: WhatsNew.java プロジェクト: tzkiki32/quollwriter
  public void init() {

    super.init();

    try {

      Environment.setUserProperty(
          Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME,
          new StringProperty(
              Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME,
              Environment.getQuollWriterVersion().getVersion()));

    } catch (Exception e) {

      Environment.logError("Unable to set the whats new version viewed property", e);
    }
  }
コード例 #6
0
ファイル: StackTraceTool.java プロジェクト: NathanEEvans/api
  public StackTraceTool(Environment env) {

    super(new BorderLayout());

    this.env = env;
    this.runtime = env.getExecutionManager();
    this.context = env.getContextManager();

    stackModel = new DefaultListModel(); // empty

    list = new JList(stackModel);
    list.setCellRenderer(new StackFrameRenderer());

    JScrollPane listView = new JScrollPane(list);
    add(listView);

    // Create listener.
    StackTraceToolListener listener = new StackTraceToolListener();
    context.addContextListener(listener);
    list.addListSelectionListener(listener);

    // ### remove listeners on exit!
  }
コード例 #7
0
 // takes keyboard input to move player around, and to different rooms
 public void keyTyped(KeyEvent e) {
   c = e.getKeyChar();
   repaint();
   g = this.getGraphics();
   Environment Layout = new Environment();
   if (Layout.isWall(x, y, c, wallLayout)) {
   } else {
     if (c == 'a') {
       x = x - 3;
     } else if (c == 'w') {
       y = y - 3;
     } else if (c == 's') {
       y = y + 3;
     } else if (c == 'd') {
       x = x + 3;
     } else if (c == 'e') {
       getItem = !getItem;
     }
     int yDoor = Layout.isDoor(x, y, c, 'y', wallLayout);
     int xDoor = Layout.isDoor(x, y, c, 'x', wallLayout);
     if (xDoor != 0 || yDoor != 0) {
       mapY = mapY + yDoor;
       mapX = mapX + xDoor;
       wallLayout = Layout.walls(mapX, mapY);
       Layout.drawRoom(mapX, mapY, g);
       if (xDoor == -1) {
         x = 760;
       } else if (xDoor == 1) {
         x = 40;
       } else if (yDoor == -1) {
         y = 460;
       } else if (yDoor == 1) {
         y = 40;
       }
     }
   }
 }
コード例 #8
0
  public FindSynonymsActionHandler(String word, int position, Chapter c, AbstractEditorPanel p) {

    this.word = word;
    this.position = position;
    // this.chapter = c;
    this.editorPanel = p;
    this.projectViewer = this.editorPanel.getViewer();

    final FindSynonymsActionHandler _this = this;

    // Show a panel of all the items.
    this.popup =
        new QPopup(
            "Synonyms for: " + word,
            Environment.getIcon(Constants.FIND_ICON_NAME, Constants.ICON_POPUP),
            null);

    JButton close =
        UIUtils.createButton(
            Constants.CLOSE_ICON_NAME, Constants.ICON_MENU, "Click to close", null);

    List<JButton> buts = new ArrayList();
    buts.add(close);

    this.popup.getHeader().setControls(UIUtils.createButtonBar(buts));

    close.addActionListener(
        new ActionAdapter() {

          public void actionPerformed(ActionEvent ev) {

            _this.popup.setVisible(false);

            _this.editorPanel.getEditor().removeHighlight(_this.highlight);
          }
        });

    p.addPopup(this.popup, true, true);
    /*
          this.highlight = this.editorPanel.getEditor ().addHighlight (position,
                                                                       position + word.length (),
                                                                       null,
                                                                       true);
    */
    this.popup.setOpaque(false);
    this.popup.setVisible(false);

    this.popup.setDraggable(this.editorPanel);
  }
コード例 #9
0
    /*
     * Completely erases the current state of the Simulation
     */
    public void reset() {
      e.purgeAgents();
      paint.clearHistory();
      children.clear();
      fillWithAgents();

      Agent a = new Agent();
      a.setName("My Agent");
      a.setChrome("000 000 000 000 000 000 000 011 011 011 011 011 100 101 101 101");
      children.add(a);

      cur_gen = 0;
      current_elite = null;
      prev_elite_total = 0;
      running = true;
    }
コード例 #10
0
  public BizSimMain(int numThreads, int numAgents, int numGenerations) {

    // configure our main window which will contain all the other elements
    JFrame control_window = new JFrame();
    control_window.setTitle("Control Suite");
    control_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    control_window.setSize(new Dimension(800, 480));
    // control_window.setAlwaysOnTop(true);
    control_window.setLayout(new BorderLayout());

    JPanel species_control = new JPanel();
    JLabel species_list_l = new JLabel("Species Running");
    DefaultListModel species_list = new DefaultListModel();

    // create our Environment
    Environment e = new Environment();

    // create all our threads
    for (int kittehsex = 0; kittehsex < numThreads; ++kittehsex) {

      // create some test agents
      ArrayList<Agent> agents = new ArrayList<Agent>();
      for (int i = 0; i < numAgents; ++i) {
        agents.add(new Agent());
      }

      // create our new thread and pass in some control variables
      ProcessSimulator ps = new ProcessSimulator(agents, numGenerations, kittehsex, e, this);
      Thread t = new Thread(ps);
      species.add(ps);

      // update our current species list
      species_list.addElement("Species #" + kittehsex);

      // set the thread to a high priority, and then start it
      t.setPriority(9);
      t.start();
    }

    // create a selectable list of all the different species we have
    JList species_select_list = new JList(species_list);
    species_select_list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    species_select_list.setLayoutOrientation(JList.VERTICAL);
    species_select_list.setVisibleRowCount(3);

    // start listening to all buttons
    start_stop.addActionListener(this);
    reset.addActionListener(this);
    reconfigure.addActionListener(this);

    // add mnemonics to some buttons
    start_stop.setMnemonic('s');
    reset.setMnemonic('r');
    reconfigure.setMnemonic('e');

    // create a panel for all our environment variables
    JPanel environment_controls = new JPanel();
    environment_controls.setBorder(BorderFactory.createTitledBorder("Modify Finished Good Values"));
    environment_controls.setLayout(new GridLayout(3, 4));
    environment_controls.add(new JLabel("High Rate:"));
    environment_controls.add(high_rate);
    environment_controls.add(new JLabel("High Sale:"));
    environment_controls.add(high_sale);
    environment_controls.add(new JLabel("Med Rate:"));
    environment_controls.add(med_rate);
    environment_controls.add(new JLabel("Med Sale:"));
    environment_controls.add(med_sale);
    environment_controls.add(new JLabel("Low Rate:"));
    environment_controls.add(low_rate);
    environment_controls.add(new JLabel("Low Sale:"));
    environment_controls.add(low_sale);

    // create a panel for all our simulation variables
    JPanel simulation_controls = new JPanel();
    simulation_controls.setBorder(BorderFactory.createTitledBorder("Modify Simulation Controls"));
    simulation_controls.setLayout(new GridLayout(6, 2));
    simulation_controls.add(new JLabel("Agent Count:"));
    simulation_controls.add(agent_count);
    simulation_controls.add(new JLabel("Generation Count:"));
    simulation_controls.add(generation_count);
    simulation_controls.add(new JLabel("Elite Percent"));
    simulation_controls.add(elite_percent);
    simulation_controls.add(new JLabel("Parent Percent"));
    simulation_controls.add(parent_percent);
    simulation_controls.add(new JLabel("Agent Performance"));
    simulation_controls.add(agent_performance);

    // create a panel for displaying information about the current elite
    // agent
    JPanel elite_panel = new JPanel();
    elite_panel.setBorder(BorderFactory.createTitledBorder("Current Elite Agent Performance"));
    elite_panel.setLayout(new GridLayout(2, 2));
    elite_panel.add(new JLabel("Total: "));
    elite_panel.add(cur_elite_total);
    elite_panel.add(new JLabel("Genome: "));
    JScrollPane genome_scroll = new JScrollPane(cur_elite_genome);
    elite_panel.add(genome_scroll);

    // this panel encompasses the different panels for altering and showing
    // the current state of the simulation
    JPanel field_controls = new JPanel();
    field_controls.setLayout(new GridLayout(2, 2));
    field_controls.add(environment_controls);
    field_controls.add(simulation_controls);
    field_controls.add(elite_panel);

    // set some attributes on misc. GUI stuff
    cur_elite_genome.setWrapStyleWord(true);
    cur_elite_genome.setEditable(false);
    cur_elite_genome.setLineWrap(true);

    // set the size of the button to just 3 characters
    high_rate.setColumns(3);
    high_sale.setColumns(3);
    med_rate.setColumns(3);
    med_sale.setColumns(3);
    low_rate.setColumns(3);
    low_sale.setColumns(3);

    // set the current value of our fields to the current environment value
    high_rate.setText(e.getHQRate() + "");
    high_sale.setText(e.getHQSale() + "");
    med_rate.setText(e.getMQRate() + "");
    med_sale.setText(e.getMQSale() + "");
    low_rate.setText(e.getLQRate() + "");
    low_sale.setText(e.getLQSale() + "");

    // set the default value of our fields to the current simulation values
    day_count.setText("100");
    generation_count.setText(numGenerations + "");
    elite_percent.setText(".05");
    parent_percent.setText(".8");
    agent_count.setText(numAgents + "");
    agent_performance.setText(e.getIncomeRatioThreshold() + "");

    // create a panel for all our flow control buttons
    JPanel control_flow_buttons = new JPanel();
    control_flow_buttons.setLayout(new GridLayout(1, 6));
    control_flow_buttons.add(start_stop);
    control_flow_buttons.add(reset);
    control_flow_buttons.add(reconfigure);

    // add our components to the window
    species_control.add(species_list_l);
    species_control.add(species_select_list);
    control_window.add(species_control, BorderLayout.WEST);
    control_window.add(field_controls, BorderLayout.CENTER);
    control_window.add(control_flow_buttons, BorderLayout.SOUTH);
    control_window.setLocation(620, 0);
    control_window.setVisible(true);
  }
コード例 #11
0
    public void run() {

      // keep the thread alive
      while (true) {

        // wait for a signal to re-continue processing agents
        if (!running) {
          synchronized (this) {
            try {
              wait();
            } catch (InterruptedException ie) {
              System.err.println("ERROR: wait() call failed" + ie);
            }
          }
        }

        // run for the number of generations specified
        while (cur_gen < generations && running) {

          // create our list of agents
          e.purgeAgents();
          e.addAgents(children);

          // Process 100-days
          for (int i = 0; i < day_count; i++) {
            e.simulateDay();
          }

          // record this generation
          history.addGeneration(children);

          // sort the results by money, descending
          Collections.sort(children);
          Collections.reverse(children);

          // if the elite total changed, alert the main class
          int elite_most_money = children.get(0).getMoney();
          if (elite_most_money > prev_elite_total) {

            // cache the new elite total
            prev_elite_total = elite_most_money;
            current_elite = children.get(0);

            ep.setNewElite(current_elite);
            ep.repaint();

            // fire an event to the main class
            listener.actionPerformed(
                new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "elite_total"));
          }

          // now we need to select agents for crossover, mutation,
          // and elites for elites, keep the first x%
          List<Agent> elites = children.subList(0, (int) (children.size() * elite_percent));

          // for parents to keep, simply choose the top y%
          // (including the elites)
          List<Agent> parents = children.subList(0, (int) (children.size() * parent_percent));

          // create some children, and perform mutations
          children = evo.performCrossover(parents);
          children = evo.performMutation(children);

          // add the elite agents into the pool
          children.addAll(elites);

          // System.out.println(elites.get(0) + ": " + elites.get(0).getMoney());

          // reset the elites for the next generation
          for (Agent elitea : elites) elitea.reset();

          // repopulate the next generation with new Agents
          fillWithAgents();

          cur_gen++;
        }
        running = false;
      }
    }
コード例 #12
0
  public void actionPerformed(ActionEvent e) {

    // dump ActionEvent information
    Object src = e.getSource();
    String msg = e.getActionCommand();

    if (src == start_stop) {

      // tell all threads to continue/resume operation
      for (ProcessSimulator ps : species)
        if (ps.toggleRunning())
          synchronized (ps) {
            ps.notify();
          }
      System.out.println("Started/Stopped Simulator...");
    } else if (src == reset) {
      for (ProcessSimulator ps : species) {
        if (!ps.isRunning()) {
          ps.reset();
          synchronized (ps) {
            ps.notify();
          }
        }
      }

      // clear the Elite Agent data
      cur_elite_genome.setText("");
      cur_elite_total.setText("");

      System.out.println("Simulation Reset...");
    } else if (src == reconfigure) {

      // create a new environment with the new parameters
      Environment environment = new Environment();

      // override existing values
      environment.setHQSale(Integer.parseInt(high_sale.getText()));
      environment.setHQRate(Integer.parseInt(high_rate.getText()));
      environment.setMQRate(Integer.parseInt(med_rate.getText()));
      environment.setMQSale(Integer.parseInt(med_sale.getText()));
      environment.setLQRate(Integer.parseInt(low_rate.getText()));
      environment.setLQSale(Integer.parseInt(low_sale.getText()));
      environment.setIncomeRatioThreshold(Double.parseDouble(agent_performance.getText()));

      for (ProcessSimulator ps : species) {
        if (!ps.isRunning()) {
          ps.replaceEnvironment(environment);

          // replace simulation values
          ps.setAgentCount(Integer.parseInt(agent_count.getText()));
          ps.setDayCount(Integer.parseInt(day_count.getText()));
          ps.setElitePercent(Double.parseDouble(elite_percent.getText()));
          ps.setGenerationCount(Integer.parseInt(generation_count.getText()));
          ps.setParentPercent(Double.parseDouble(parent_percent.getText()));
        }
      }
      System.out.println("Species Reconfigured...");
    } else if (msg == "elite_total") {

      // one of the threads has a new elite
      // TODO: Later, we are going to want to differentiate between the
      // TODO: different threads
      current_elite = ((ProcessSimulator) src).getCurrentElite();

      // update our GUI
      cur_elite_total.setText("$" + current_elite.getMoney());
      cur_elite_genome.setText(current_elite.toString());
    }
  }
コード例 #13
0
ファイル: WhatsNew.java プロジェクト: tzkiki32/quollwriter
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }
コード例 #14
0
ファイル: TextArea.java プロジェクト: tzkiki32/quollwriter
  public TextArea(String placeholder, int rows, int maxChars) {

    super(BoxLayout.Y_AXIS);

    this.text = UIUtils.createTextArea(rows);

    if (placeholder != null) {

      this.placeholder = Environment.replaceObjectNames(placeholder);
      this.text.setText(this.placeholder);
      this.text.setForeground(UIUtils.getHintTextColor());
    }

    this.maxChars = maxChars;

    final TextArea _this = this;

    final JLabel maxText = new JLabel("Max " + Environment.formatNumber(maxChars) + " characters");
    maxText.setForeground(UIUtils.getHintTextColor());

    this.scrollPane = UIUtils.createScrollPane((JComponent) this.text);

    this.text.addKeyListener(
        new KeyAdapter() {

          public void keyPressed(KeyEvent ev) {

            if (_this.text.getForeground() != Color.BLACK) {

              _this.text.setText("");
            }

            _this.text.setForeground(Color.BLACK);

            if (_this.maxChars <= 0) {

              return;
            }

            maxText.setForeground(UIUtils.getHintTextColor());

            int l = _this.text.getText().trim().length();

            String t = "Max " + Environment.formatNumber(_this.maxChars) + " characters";

            if (l > 0) {

              if (l > 5000) {

                t += ", over " + Environment.formatNumber(_this.maxChars) + " characters";
                maxText.setForeground(Color.RED);

              } else {

                t += ", " + Environment.formatNumber((5000 - l)) + " remaining";
              }
            }

            maxText.setText(t);
          }
        });

    this.text.addMouseListener(
        new MouseEventHandler() {

          @Override
          public void mouseEntered(MouseEvent ev) {

            if ((!_this.text.getText().equals("")) && (_this.text.getForeground() != Color.BLACK)) {

              _this.text.getCaret().setDot(0);
            }

            if (_this.isAutoGrabFocus()) {

              _this.text.grabFocus();
            }
          }

          @Override
          public void handlePress(MouseEvent ev) {

            if ((!_this.text.getText().equals("")) && (_this.text.getForeground() == Color.BLACK)) {

              return;
            }

            _this.text.setText("");
            _this.text.setForeground(Color.BLACK);
          }
        });

    this.add(this.scrollPane);

    this.add(maxText);

    if (this.maxChars <= 0) {

      maxText.setVisible(false);
    }
  }