Exemple #1
0
 public void reviewDrill(int cardNumber) {
   String[] data = (String[]) WordList.dataNew.get(cardNumber - 1);
   this.answerGroup.clearSelection();
   this.cardNumberName = convertInt(cardNumber);
   this.setTitle("Review Card: " + this.cardNumberName);
   this.cardNumberL.setText(this.cardNumberName);
   this.choice1.setText(data[0]);
   this.choice2.setText(data[1]);
   this.choice3.setText(data[2]);
   this.choice4.setText(data[3]);
   this.wordLine.setText(data[4]);
   this.correctAInd.setText(data[5]);
   this.topLine.setText(data[6]);
   this.middleLine.setText(data[7]);
   this.correctInd.setText(data[8]);
   String uAnswer = data[9];
   if (this.choice1.getText().equals(uAnswer)) {
     this.choice1.setSelected(true);
     this.choice1.setFont(Font.getFont("Tahoma 11 Bold"));
   }
   if (this.choice2.getText().equals(uAnswer)) {
     this.choice2.setSelected(true);
     this.choice2.setFont(Font.getFont("Tahoma 11 Bold"));
   }
   if (this.choice3.getText().equals(uAnswer)) {
     this.choice3.setSelected(true);
     this.choice3.setFont(Font.getFont("Tahoma 11 Bold"));
   }
   if (this.choice4.getText().equals(uAnswer)) {
     this.choice4.setSelected(true);
     this.choice4.setFont(Font.getFont("Tahoma 11 Bold"));
   }
 }
Exemple #2
0
  /**
   * Check's FontInfo alias database, if not Font.getFont(name) is returned;
   *
   * @param name
   * @return either java's default font or font from font database.
   */
  public static Font createFont(String name) {
    FontInfo info = FontInfo.getFontInfo(name);

    if (info != null) return info.createFont();

    return Font.getFont(name);
  }
Exemple #3
0
 public FontUIResource getMessageFont() {
   if (systemFont == null) {
     systemFont =
         new FontUIResource(
             Font.getFont("swing.plaf.metal.systemFont", new Font("Dialog", Font.PLAIN, 12)));
   }
   return systemFont;
 }
Exemple #4
0
 public FontUIResource getSmallFont() {
   if (smallFont == null) {
     smallFont =
         new FontUIResource(
             Font.getFont("swing.plaf.metal.smallFont", new Font("Dialog", Font.PLAIN, 10)));
   }
   return smallFont;
 }
Exemple #5
0
 public FontUIResource getControlFont() {
   if (controlFont == null) {
     controlFont =
         new FontUIResource(
             Font.getFont("swing.plaf.metal.controlFont", new Font("Dialog", Font.PLAIN, 12)));
   }
   return controlFont;
 }
Exemple #6
0
 public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
   reader.moveDown(); // into <attributes>
   Map attributes = (Map) context.convertAnother(null, Map.class);
   reader.moveUp(); // out of </attributes>
   Font font = Font.getFont(attributes);
   if (context.getRequiredType() == FontUIResource.class) {
     return new FontUIResource(font);
   } else {
     return font;
   }
 }
  /**
   * Extract a GraphicAttribute or Font from the given attributes. If attributes does not contain a
   * GraphicAttribute, Font, or Font family entry this method returns null.
   */
  private static Object getGraphicOrFont(Map attributes) {

    Object value = attributes.get(TextAttribute.CHAR_REPLACEMENT);
    if (value != null) {
      return value;
    }
    value = attributes.get(TextAttribute.FONT);
    if (value != null) {
      return value;
    }

    if (attributes.get(TextAttribute.FAMILY) != null) {
      return Font.getFont(attributes);
    } else {
      return null;
    }
  }
  @Override
  public void scaleView() {
    // Slot sizes
    skillBoxSize = (int) (((double) getScreenWidth() / 15));
    imgSize = (int) ((double) skillBoxSize * .40);
    levelUpBoxSize = (int) ((double) skillBoxSize * .60);
    plusIconSize = (int) ((double) skillBoxSize * .45);

    // Rect size
    skillRectWidth = skillCount * skillBoxSize;
    skillRectHeight = skillBoxSize;

    // Coordinates for skill box
    skillBoxStartX = (getScreenWidth() - skillRectWidth) / 2;
    skillBoxStartY = getScreenHeight() - skillRectHeight - 25;

    // Coordinates for level up boxes
    levelUpBoxLeftX = skillBoxStartX + (skillBoxSize - levelUpBoxSize) / 2;
    int skillBoxRight = skillBoxStartX + skillBoxSize;
    levelUpBoxLeftXDistanceGap =
        skillBoxRight + (skillBoxSize - levelUpBoxSize) / 2 - levelUpBoxLeftX;
    levelUpBoxRightX =
        levelUpBoxLeftX + ((skillCount - 1) * levelUpBoxLeftXDistanceGap) + levelUpBoxSize;
    levelUpBoxBottomY = skillBoxStartY;
    levelUpBoxTopY = levelUpBoxBottomY - levelUpBoxSize;

    // Font
    keyBindFontSize = getScreenWidth() / 100;
    skillLabelFontSize = keyBindFontSize;
    CDFontSize = getScreenWidth() / 50;

    skillLabelFont = new Font("Courier New", Font.PLAIN, skillLabelFontSize);

    // Setup keybind font
    keyBindFont = new Font("Courier New", Font.BOLD, keyBindFontSize);
    Map<TextAttribute, Object> attributes = new HashMap<>();
    attributes.put(TextAttribute.FAMILY, keyBindFont.getFamily());
    attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_EXTRABOLD);
    attributes.put(TextAttribute.SIZE, (int) (keyBindFont.getSize() * 1.5));
    keyBindFont = Font.getFont(attributes);

    CDFont = new Font("Courier New", Font.PLAIN, CDFontSize);
  }
public class TextArtifact extends Artifact {
  private double x1;
  private double y1;
  private String text;
  private Font font = Font.getFont(Font.SANS_SERIF);
  private int xPixelOffset = 0;
  private int yPixelOffset = 0;

  private final Point2d tempPoint = new Point2d();

  public TextArtifact(String id, String text, double x1, double y1) {
    super(id);
    setLevel(1);
    this.text = text;
    this.x1 = x1;
    this.y1 = y1;
  }

  public void setPosition(double x1, double y1) {
    this.x1 = x1;
    this.y1 = y1;
  }

  public void setPixelOffset(int pixelOffset) {
    this.xPixelOffset = pixelOffset;
    this.yPixelOffset = pixelOffset;
  }

  public void setxPixelOffset(int xPixelOffset) {
    this.xPixelOffset = xPixelOffset;
  }

  public void setyPixelOffset(int yPixelOffset) {
    this.yPixelOffset = yPixelOffset;
  }

  public String getText() {
    return text;
  }

  public void setText(String text) {
    this.text = text;
  }

  public double getX() {
    return x1;
  }

  public double getY() {
    return y1;
  }

  public void setFontSize(int size) {
    font = new Font(Font.SANS_SERIF, Font.PLAIN, size);
  }

  /** Must provide a draw method for plotter to render artifact */
  @Override
  public void draw(Graphics2DAdapter graphics) {
    graphics.setColor(color);
    graphics.setFont(font);

    tempPoint.set(x1, y1);
    graphics.drawString(text, tempPoint);
  }

  @Override
  public void drawLegend(Plotter2DAdapter graphics, Point2d origin) {
    graphics.setColor(color);
    graphics.setFont(font);

    tempPoint.set(origin.getX() - 30.0, origin.getY() + 6.0);
    graphics.drawString(graphics.getScreenFrame(), text, tempPoint);
  }

  public void save(PrintWriter printWriter) {
    printWriter.println(x1 + " " + y1 + " " + id);
  }

  public TextArtifact getCopy() {
    TextArtifact cirlceCopy = new TextArtifact(this.getID(), this.text, x1, y1);
    cirlceCopy.setColor(this.getColor());

    return cirlceCopy;
  }

  @Override
  public void drawHistory(Graphics2DAdapter graphics) {
    throw new RuntimeException("Not implemented!");
  }

  @Override
  public void takeHistorySnapshot() {
    throw new RuntimeException("Not implemented!");
  }
}
Exemple #10
0
  private void draw() {
    Renderer renderer = ui.getRenderer();
    Graphics g = renderer.getGraphics();
    int fsize = g.getFont().getSize();
    JPanel target = ui.getDrawTarget();

    g.setColor(Color.GRAY);
    g.fillRect(0, 0, target.getWidth(), target.getHeight());

    Map<CabinType, Integer> xmap =
        new HashMap<CabinType, Integer>() {
          {
            this.put(CabinType.LEFT, Floor.PIXEL_WIDTH + 10);
            this.put(CabinType.RIGHT, Floor.PIXEL_WIDTH + 10 + Cabin.PIXEL_WIDTH + 30);
          }
        };

    for (CabinType type : cabins.keySet()) {
      Integer x = xmap.get(type);
      Cabin cabin = cabins.get(type);

      int passengers = cabin.getPassengers().size();
      double cabinY = cabin.getPosition() * REAL_TO_PIXEL_RATIO,
          cabinH = (double) cabin.PIXEL_HEIGHT,
          cabinW = (double) cabin.PIXEL_WIDTH;

      g.setColor(Color.WHITE);
      g.fillRect(x, (int) cabinY, (int) cabinW, (int) cabinH);
      g.setColor(Color.BLACK);
      g.drawRect(x, (int) cabinY, (int) cabinW, (int) cabinH);
      // cabin fullness
      g.drawString(
          passengers >= cabinLimitPeople ? passengers > cabinLimitPeople ? "초과" : "만원" : "",
          (int) (x + cabinW / 2.0 - fsize),
          (int) (cabinY + cabinH / 2.0 - fsize));
      // passengers on cabin
      g.drawString(
          String.format("%d명", passengers),
          (int) (x + cabinW / 2.0 - fsize * 2.0 / 2.0),
          (int) (cabinY + cabinH / 2.0));
      // cabin weight
      g.drawString(String.format("%.0fkg", mass(cabin)), x, (int) (cabinY + cabinH / 2.0 + fsize));
      // cabin speed
      g.drawString(
          String.format("%.1fm/s", Math.abs(cabin.getVelocity())),
          x,
          (int) (cabinY + cabinH / 2.0 + fsize * 2.0));
    }

    for (Floor floor : floors.values()) {
      int passengers = floor.getPassengers().size();
      double floorY = floor.getPosition() * REAL_TO_PIXEL_RATIO;
      g.setFont(Font.getFont(Font.SANS_SERIF));
      g.setColor(Color.WHITE);
      g.fillRect(1, (int) floorY, Floor.PIXEL_WIDTH, Floor.PIXEL_HEIGHT);
      g.setColor(Color.BLACK);
      g.drawRect(1, (int) floorY, Floor.PIXEL_WIDTH, Floor.PIXEL_HEIGHT);
      g.drawString(floor.getNum() + "층", 1, (int) floorY + 15);
      g.drawString(
          Integer.toString(passengers),
          (int) (1 + (double) (Floor.PIXEL_WIDTH) / 2.0 - (double) fsize / 2.0),
          (int) (floorY + (double) Floor.PIXEL_HEIGHT / 2.0));
    }
    if (state >> 1 == CircumstanceType.FIRE.state()) {
      Floor firedFloor = (Floor) Circumstance.get(CircumstanceType.FIRE).getParameter("floor");
      if (null != firedFloor)
        g.drawString(
            "화재",
            Floor.PIXEL_WIDTH / 2 - fsize,
            (int)
                (firedFloor.getPosition() * REAL_TO_PIXEL_RATIO
                    + (double) Floor.PIXEL_HEIGHT / 2.0
                    + fsize * 2.0));
    }
    renderer.flush();
  }
/**
 * Maintains several {@link TimeSeries} with different update frequencies to satisfy three goals;
 * (1) retain data over long timespan, (2) save memory, and (3) retain accurate data for the recent
 * past.
 *
 * <p>All in all, one instance uses about 8KB space.
 *
 * @author Kohsuke Kawaguchi
 */
@ExportedBean
public class MultiStageTimeSeries implements Serializable {
  /** Name of this data series. */
  public final Localizable title;

  /** Used to render a line in the trend chart. */
  public final Color color;

  /** Updated every 10 seconds. Keep data up to 1 hour. */
  @Exported public final TimeSeries sec10;
  /** Updated every 1 min. Keep data up to 1 day. */
  @Exported public final TimeSeries min;
  /** Updated every 1 hour. Keep data up to 4 weeks. */
  @Exported public final TimeSeries hour;

  private int counter;

  private static final Font CHART_FONT =
      Font.getFont(
          MultiStageTimeSeries.class.getName() + ".chartFont",
          new Font(Font.SANS_SERIF, Font.PLAIN, 10));

  public MultiStageTimeSeries(Localizable title, Color color, float initialValue, float decay) {
    this.title = title;
    this.color = color;
    this.sec10 = new TimeSeries(initialValue, decay, 6 * 60);
    this.min = new TimeSeries(initialValue, decay, 60 * 24);
    this.hour = new TimeSeries(initialValue, decay, 28 * 24);
  }

  /**
   * @deprecated since 2009-04-05. Use {@link #MultiStageTimeSeries(Localizable, Color, float,
   *     float)}
   */
  public MultiStageTimeSeries(float initialValue, float decay) {
    this(Messages._MultiStageTimeSeries_EMPTY_STRING(), Color.WHITE, initialValue, decay);
  }

  /** Call this method every 10 sec and supply a new data point. */
  public void update(float f) {
    counter = (counter + 1) % 360; // 1hour/10sec = 60mins/10sec=3600secs/10sec = 360
    sec10.update(f);
    if (counter % 6 == 0) min.update(f);
    if (counter == 0) hour.update(f);
  }

  /** Selects a {@link TimeSeries}. */
  public TimeSeries pick(TimeScale timeScale) {
    switch (timeScale) {
      case HOUR:
        return hour;
      case MIN:
        return min;
      case SEC10:
        return sec10;
      default:
        throw new AssertionError();
    }
  }

  /** Gets the most up-to-date data point value. */
  public float getLatest(TimeScale timeScale) {
    return pick(timeScale).getLatest();
  }

  public Api getApi() {
    return new Api(this);
  }

  /** Choose which datapoint to use. */
  public enum TimeScale {
    SEC10(TimeUnit2.SECONDS.toMillis(10)),
    MIN(TimeUnit2.MINUTES.toMillis(1)),
    HOUR(TimeUnit2.HOURS.toMillis(1));

    /** Number of milliseconds (10 secs, 1 min, and 1 hour) that this constant represents. */
    public final long tick;

    TimeScale(long tick) {
      this.tick = tick;
    }

    /** Creates a new {@link DateFormat} suitable for processing this {@link TimeScale}. */
    public DateFormat createDateFormat() {
      switch (this) {
        case HOUR:
          return new SimpleDateFormat("MMM/dd HH");
        case MIN:
          return new SimpleDateFormat("HH:mm");
        case SEC10:
          return new SimpleDateFormat("HH:mm:ss");
        default:
          throw new AssertionError();
      }
    }

    /** Parses the {@link TimeScale} from the query parameter. */
    public static TimeScale parse(String type) {
      if (type == null) return TimeScale.MIN;
      return Enum.valueOf(TimeScale.class, type.toUpperCase(Locale.ENGLISH));
    }
  }

  /**
   * Represents the trend chart that consists of several {@link MultiStageTimeSeries}.
   *
   * <p>This object is renderable as HTTP response.
   */
  public static class TrendChart implements HttpResponse {
    public final TimeScale timeScale;
    public final List<MultiStageTimeSeries> series;
    public final DefaultCategoryDataset dataset;

    public TrendChart(TimeScale timeScale, MultiStageTimeSeries... series) {
      this.timeScale = timeScale;
      this.series = new ArrayList<MultiStageTimeSeries>(Arrays.asList(series));
      this.dataset = createDataset();
    }

    /**
     * Creates a {@link DefaultCategoryDataset} for rendering a graph from a set of {@link
     * MultiStageTimeSeries}.
     */
    protected DefaultCategoryDataset createDataset() {
      float[][] dataPoints = new float[series.size()][];
      for (int i = 0; i < series.size(); i++)
        dataPoints[i] = series.get(i).pick(timeScale).getHistory();

      int dataLength = dataPoints[0].length;
      for (float[] dataPoint : dataPoints) assert dataLength == dataPoint.length;

      DefaultCategoryDataset ds = new DefaultCategoryDataset();

      DateFormat format = timeScale.createDateFormat();

      Date dt = new Date(System.currentTimeMillis() - timeScale.tick * dataLength);
      for (int i = dataLength - 1; i >= 0; i--) {
        dt = new Date(dt.getTime() + timeScale.tick);
        String l = format.format(dt);
        for (int j = 0; j < dataPoints.length; j++)
          ds.addValue(dataPoints[j][i], series.get(j).title.toString(), l);
      }
      return ds;
    }

    /** Draws a chart into {@link JFreeChart}. */
    public JFreeChart createChart() {
      final JFreeChart chart =
          ChartFactory.createLineChart(
              null, // chart title
              null, // unused
              null, // range axis label
              dataset, // data
              PlotOrientation.VERTICAL, // orientation
              true, // include legend
              true, // tooltips
              false // urls
              );

      chart.setBackgroundPaint(Color.white);
      chart.getLegend().setItemFont(CHART_FONT);

      final CategoryPlot plot = chart.getCategoryPlot();
      configurePlot(plot);

      configureRangeAxis((NumberAxis) plot.getRangeAxis());

      crop(plot);

      return chart;
    }

    protected void configureRangeAxis(NumberAxis rangeAxis) {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      rangeAxis.setTickLabelFont(CHART_FONT);
      rangeAxis.setLabelFont(CHART_FONT);
    }

    protected void crop(CategoryPlot plot) {
      // crop extra space around the graph
      plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));
    }

    protected CategoryAxis configureDomainAxis(CategoryPlot plot) {
      final CategoryAxis domainAxis = new NoOverlapCategoryAxis(null);
      plot.setDomainAxis(domainAxis);
      domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
      domainAxis.setLowerMargin(0.0);
      domainAxis.setUpperMargin(0.0);
      domainAxis.setCategoryMargin(0.0);
      domainAxis.setLabelFont(CHART_FONT);
      domainAxis.setTickLabelFont(CHART_FONT);
      return domainAxis;
    }

    protected void configureRenderer(LineAndShapeRenderer renderer) {
      renderer.setBaseStroke(new BasicStroke(3));

      for (int i = 0; i < series.size(); i++) renderer.setSeriesPaint(i, series.get(i).color);
    }

    protected void configurePlot(CategoryPlot plot) {
      plot.setBackgroundPaint(Color.WHITE);
      plot.setOutlinePaint(null);
      plot.setRangeGridlinesVisible(true);
      plot.setRangeGridlinePaint(Color.black);

      configureRenderer((LineAndShapeRenderer) plot.getRenderer());
      configureDomainAxis(plot);
    }

    /** Renders this object as an image. */
    public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node)
        throws IOException, ServletException {
      ChartUtil.generateGraph(req, rsp, createChart(), 500, 400);
    }
  }

  public static TrendChart createTrendChart(TimeScale scale, MultiStageTimeSeries... data) {
    return new TrendChart(scale, data);
  }

  private static final long serialVersionUID = 1L;
}
 /** Run the task. */
 public void run() {
   final BoundedRangeModel model = progressBar.getModel();
   switch (task) {
     case -LABEL:
       {
         value = description.getText();
         return;
       }
     case +LABEL:
       {
         description.setText((String) value);
         return;
       }
     case PROGRESS:
       {
         model.setValue(((Integer) value).intValue());
         progressBar.setIndeterminate(false);
         return;
       }
     case STARTED:
       {
         model.setRangeProperties(0, 1, 0, 100, false);
         window.setVisible(true);
         break; // Need further action below.
       }
     case COMPLETE:
       {
         model.setRangeProperties(100, 1, 0, 100, false);
         window.setVisible(warningArea != null);
         cancel.setEnabled(false);
         break; // Need further action below.
       }
   }
   /*
    * Some of the tasks above requires an action on the window, which may be a JDialog or
    * a JInternalFrame. We need to determine the window type before to apply the action.
    */
   synchronized (ProgressWindow.this) {
     if (window instanceof JDialog) {
       final JDialog window = (JDialog) ProgressWindow.this.window;
       switch (task) {
         case -TITLE:
           {
             value = window.getTitle();
             return;
           }
         case +TITLE:
           {
             window.setTitle((String) value);
             return;
           }
         case STARTED:
           {
             window.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
             return;
           }
         case COMPLETE:
           {
             window.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
             return;
           }
         case DISPOSE:
           {
             window.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
             if (warningArea == null || !window.isVisible()) {
               window.dispose();
             }
             return;
           }
       }
     } else {
       final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window;
       switch (task) {
         case -TITLE:
           {
             value = window.getTitle();
             return;
           }
         case +TITLE:
           {
             window.setTitle((String) value);
             return;
           }
         case STARTED:
           {
             window.setClosable(false);
             return;
           }
         case COMPLETE:
           {
             window.setClosable(true);
             return;
           }
         case DISPOSE:
           {
             window.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
             if (warningArea == null || !window.isVisible()) {
               window.dispose();
             }
             return;
           }
       }
     }
     /*
      * Si la tâche spécifiée n'est aucune des tâches énumérées ci-haut,
      * on supposera que l'on voulait afficher un message d'avertissement.
      */
     if (warningArea == null) {
       final JTextArea warningArea = new JTextArea();
       final JScrollPane scroll = new JScrollPane(warningArea);
       final JPanel namedArea = new JPanel(new BorderLayout());
       ProgressWindow.this.warningArea = warningArea;
       warningArea.setFont(Font.getFont("Monospaced"));
       warningArea.setEditable(false);
       namedArea.setBorder(BorderFactory.createEmptyBorder(0, HMARGIN, VMARGIN, HMARGIN));
       namedArea.add(new JLabel(getString(VocabularyKeys.WARNING)), BorderLayout.NORTH);
       namedArea.add(scroll, BorderLayout.CENTER);
       content.add(namedArea, BorderLayout.CENTER);
       if (window instanceof JDialog) {
         final JDialog window = (JDialog) ProgressWindow.this.window;
         window.setResizable(true);
       } else {
         final JInternalFrame window = (JInternalFrame) ProgressWindow.this.window;
         window.setResizable(true);
       }
       window.setSize(WIDTH, HEIGHT + WARNING_HEIGHT);
       window.setVisible(true); // Seems required in order to force relayout.
     }
     final JTextArea warningArea = (JTextArea) ProgressWindow.this.warningArea;
     warningArea.append((String) value);
   }
 }