public static void init(int MAX_X, int MAX_Y) { init = true; LCD.MAX_X = MAX_X; LCD.MAX_Y = MAX_Y; f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); step_y = MAX_Y / 5; step_x = MAX_X >> 1; }
@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); }
/** @author Makc */ public class MyToolsScreen extends Canvas { Vector myTools = new Vector(); int se = 0; Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL); /** constructor */ public MyToolsScreen() { setFullScreenMode(true); } /** paint */ public void paint(Graphics g) { g.setFont(MainCanvas.nameFont); g.setColor(255, 255, 255); g.fillRect(0, 0, getWidth(), getHeight()); UIPainter.paintBackground(g); int i; for (i = 0; i < myTools.size(); i++) { if (se == i) { g.setColor(0, 0, 0); g.fillRect( 0, i * MainCanvas.nameFont.getHeight(), getWidth(), MainCanvas.nameFont.getHeight()); g.setColor(255, 255, 255); g.drawString( "" + JustPaint.c.brs[((Integer) myTools.elementAt(i)).intValue()], 5, i * MainCanvas.nameFont.getHeight(), Graphics.LEFT | Graphics.TOP); } else { g.setColor(0, 0, 0); g.drawString( "" + JustPaint.c.brs[((Integer) myTools.elementAt(i)).intValue()], 5, i * MainCanvas.nameFont.getHeight(), Graphics.LEFT | Graphics.TOP); } } UIPainter.paintLeftSoft(g, "Добавить"); UIPainter.paintRightSoft(g, "Отмена"); } /** Called when a key is pressed. */ protected void keyPressed(int keyCode) { if ((keyCode == KEY_NUM2) || (keyCode == -1)) se--; if ((keyCode == KEY_NUM8) || (keyCode == -2)) se++; if (se < 0) se = myTools.size() - 1; if (se >= myTools.size()) se = 0; if ((keyCode == -5) || (keyCode == KEY_NUM5)) { JustPaint.c.brush = (((Integer) myTools.elementAt(se)).intValue()); JustPaint.display.setCurrent(JustPaint.c); } // if (keyCode==KEY_NUM0) JustPaint.display.setCurrent(JustPaint.nf); if (keyCode == -6) { JustPaint.display.setCurrent(JustPaint.nmt); } if (keyCode == -7) { JustPaint.display.setCurrent(JustPaint.mm); } if (keyCode == -8) { myTools.removeElementAt(se); if (se >= myTools.size()) se--; if (se < 0) se = 0; } repaint(); } }
public void setFont(int size) { Font font = Font.getFont(Font.FACE_SYSTEM, 0, size); g.setFont(font); }
public void paint(Graphics g) { if (init == false) init(MyCanvas.max_x, MyCanvas.max_y); g.setFont(f); g.setColor(0xffffff); g.fillRect(0, 0, MAX_X, MAX_Y); drawSpeed(g, 0, 0, (GGA.fixQuality != 0) ? BTGPS.speed4A() * 3.6 : -1); /////// 1 Time time; if (BTGPS.isOn()) { time = NMEA.time; } else { Date date = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); double dtime = 3600 * calendar.get(Calendar.HOUR_OF_DAY); dtime += 60 * calendar.get(Calendar.MINUTE); dtime += calendar.get(Calendar.SECOND); dtime *= 1000; time = new Time(dtime); } drawTime(g, 1, 0, time, true, false); // 2 time = new Time(BTGPS.moving_timeMsec()); drawTime(g, 0, 1, time, false, true); // 3 time = new Time(BTGPS.stoped_timeMsec()); drawTime(g, 0, 2, time, false, true); // 4 double odom = BTGPS.getDistance(); drawDist(g, 0, 3, odom); drawSpeed(g, 1, 1, (GGA.fixQuality != 0) ? BTGPS.averageSpeed() * 3.6 : -1); g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL)); g.setColor(0); g.drawString("Speed", 4, 0, 0); // 00 g.drawString("Time", (MAX_X >> 1) + 4, 0, 0); // 10 g.drawString("Moving Time", 4, step_y, 0); // 01 g.drawString("Stoped", 4, step_y + step_y, 0); // 02 g.drawString("Trip Odom", 4, step_y * 3, 0); // 03 g.drawString("Moving Avg", (MAX_X >> 1) + 4, step_y, 0); // 03 g.setColor(0x777777); g.fillRect((MAX_X >> 1) - 1, 0, 2, MAX_Y); for (int y = step_y - 1; y < MAX_Y - step_y; y += step_y) g.fillRect(0, y - 1, MAX_X, 2); // int x=(MAX_X>>1)+(((MAX_X>>1)-(4*24+6))>>1); // g.drawString(time.get(":"),x,y,0); // drawTime(g,1,2,BTGPS.moving_time*0.001);//BTGPS.nmea.time.msec()*0.001); // drawDigit(g, 0, 24, '8', true); // drawDigit(g, 24, 24, '8', false); // if (BTGPS.isOn()==false) // synchronized(MyCanvas.update){ // MyCanvas.update.notify(); // } }
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; }