Changeset 1102 for trunk/src/org/apollo/gui/TimeAxis.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/gui/TimeAxis.java
r375 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color;4 import java.awt.Font;5 import java.awt.FontMetrics;6 import java.awt.GradientPaint;7 import java.awt.Graphics;8 import java.awt.Graphics2D;9 import java.awt.Stroke;10 import java.awt.geom.Rectangle2D;11 import java.awt.image.BufferedImage;12 3 import java.util.LinkedList; 13 4 14 5 import org.apollo.ApolloSystem; 15 import org.expeditee.gui.Browser; 6 import org.expeditee.core.Colour; 7 import org.expeditee.core.Dimension; 8 import org.expeditee.core.Fill; 9 import org.expeditee.core.Font; 10 import org.expeditee.core.GradientFill; 11 import org.expeditee.core.Point; 12 import org.expeditee.core.Stroke; 13 import org.expeditee.core.TextLayout; 14 import org.expeditee.gio.EcosystemManager; 15 import org.expeditee.gio.GraphicsManager; 16 import org.expeditee.gio.swing.SwingConversions; 16 17 17 18 /** … … 23 24 public class TimeAxis { 24 25 25 private static final long serialVersionUID = 1L; 26 27 public static final Font TIME_BAR_FONT = new Font("Arial", Font.PLAIN, 14); 26 public static final Font TIME_BAR_FONT = new Font("Arial", Font.Style.PLAIN, 14); 28 27 private static final Stroke TICK_STROKE = Strokes.SOLID_1; 29 28 30 private static final Colo r MAJOR_TICK_COLOR = Color.BLACK;31 private static final Colo r MINOR_TICK_COLOR = new Color(0.4f, 0.4f, 0.4f);29 private static final Colour MAJOR_TICK_COLOR = Colour.BLACK; 30 private static final Colour MINOR_TICK_COLOR = new Colour(0.4f, 0.4f, 0.4f); 32 31 33 32 private static final int DESIRED_MAJOR_TICK_PIXEL_SPACING = 100; … … 43 42 private long totalTrackMSLength = 0; 44 43 45 public TimeAxis() { 44 public TimeAxis() 45 { 46 46 } 47 47 … … 51 51 long timeLengthSamples, 52 52 long totalTrackMSLength, 53 int width) { 53 int width) 54 { 54 55 55 56 assert(width > 0); … … 146 147 LinkedList<Integer> majorTickLabelPositions = new LinkedList<Integer>(); 147 148 148 Graphics g = null; 149 try { 150 151 152 // Create a temp graphics for centered label positioning 153 if (Browser._theBrowser != null && Browser._theBrowser.g != null) { 154 g = Browser._theBrowser.g.create(); 155 } else { 156 g = new BufferedImage(1,1,BufferedImage.TYPE_BYTE_INDEXED).getGraphics(); 157 } 158 159 do { 160 161 majorTickPositions.add(new Integer((int)currentTickX)); 162 163 String label = createSpecificTimeLabel((long)currentTickTime, timeAggregation); 164 165 majorTickLabels.add(label); 166 167 // Center label 168 FontMetrics fm = g.getFontMetrics(TIME_BAR_FONT); 169 Rectangle2D rect = fm.getStringBounds(label, g); 170 int textWidth = (int)(rect.getWidth()); 171 172 majorTickLabelPositions.add(new Integer((int)currentTickX - (textWidth >> 1))); 173 174 currentTickX += majorTickPixelSpacing; 175 currentTickTime += timeAggregation; 176 177 } while (currentTickX < width); 178 179 180 } finally { 181 if (g != null) 182 g.dispose(); 183 } 149 do { 150 majorTickPositions.add(new Integer((int)currentTickX)); 151 152 String label = createSpecificTimeLabel((long)currentTickTime, timeAggregation); 153 154 majorTickLabels.add(label); 155 156 // Center label 157 int textWidth = EcosystemManager.getTextLayoutManager().layoutStringSimple(label, TIME_BAR_FONT).getPixelBounds(0, 0).getWidth(); 158 159 majorTickLabelPositions.add(new Integer((int)currentTickX - (textWidth >> 1))); 160 161 currentTickX += majorTickPixelSpacing; 162 currentTickTime += timeAggregation; 163 164 } while (currentTickX < width); 184 165 185 166 this.majorTickLabels = majorTickLabels.toArray(new String[0]); … … 227 208 228 209 229 public String createSpecificTimeLabel(long atTime, double timeAggregation) {230 210 public String createSpecificTimeLabel(long atTime, double timeAggregation) 211 { 231 212 Long min = null; 232 213 Long sec = null; … … 261 242 } 262 243 263 public static String createTimeLabel(Long min, Long sec, Long ms) {264 244 public static String createTimeLabel(Long min, Long sec, Long ms) 245 { 265 246 if (min == null && sec == null && ms != null) { 266 247 return ms + "ms"; … … 314 295 } 315 296 316 public void paint( Graphics g, int x, int y, int height, Color backgroundColor) {297 public void paint(int x, int y, int height, Colour backgroundColor) { 317 298 318 299 int majorTickHeight = height / 2; … … 320 301 321 302 // Draw backing 303 Fill backingFill; 322 304 if (ApolloSystem.useQualityGraphics) { 323 324 GradientPaint gp = new GradientPaint( 325 x + (width / 2), y + (int)(height * 0.5), backgroundColor, 326 x + (width / 2), y, SampledTrackGraphView.DEFAULT_BACKGROUND_HIGHTLIGHTS_COLOR); 327 ((Graphics2D)g).setPaint(gp); 328 305 backingFill = new GradientFill(backgroundColor, new Point(x + (width / 2), y + (int)(height * 0.5)), SwingConversions.fromSwingColor(SampledTrackGraphView.DEFAULT_BACKGROUND_HIGHTLIGHTS_COLOR), new Point(x + (width / 2), y)); 329 306 } else { 330 g.setColor(backgroundColor);331 } 332 333 g.fillRect(x, y, width, height);334 335 g .setFont(TIME_BAR_FONT);307 backingFill = new Fill(backgroundColor); 308 } 309 310 GraphicsManager gm = EcosystemManager.getGraphicsManager(); 311 312 gm.drawRectangle(new Point(x, y), new Dimension(width, height), 0.0, backingFill, null, null, null); 336 313 337 314 if (majorTickXPositions != null) { 338 339 ((Graphics2D)g).setStroke(TICK_STROKE);340 341 g.setColor(MAJOR_TICK_COLOR);342 315 // Draw Major ticks and labels 343 316 for (int i = 0; i < majorTickLabels.length; i++) { 344 317 345 318 // Label 346 g .drawString(319 gm.drawString( 347 320 majorTickLabels[i], 348 x + majorTickLabelXPositions[i], 349 y + height - 2); 321 new Point(x + majorTickLabelXPositions[i], y + height - 2), 322 TIME_BAR_FONT, 323 MAJOR_TICK_COLOR); 350 324 351 325 // Tick 352 g.drawLine( 353 x + majorTickXPositions[i], 326 gm.drawLine(x + majorTickXPositions[i], 354 327 y, 355 328 x + majorTickXPositions[i], 356 y + majorTickHeight );329 y + majorTickHeight, MAJOR_TICK_COLOR, TICK_STROKE); 357 330 358 331 } 359 360 g.setColor(MINOR_TICK_COLOR);361 332 362 333 // Draw minor ticks 363 334 if (minorTickXPositions != null) { 364 335 for (int tx : minorTickXPositions) { 365 g .drawLine(336 gm.drawLine( 366 337 x + tx, 367 338 y, 368 339 x + tx, 369 y + minorTickHeight );340 y + minorTickHeight, MINOR_TICK_COLOR, TICK_STROKE); 370 341 } 371 342 } … … 373 344 } else if (alternateLabel != null) { 374 345 375 g.setColor(Color.BLACK); 376 377 FontMetrics fm = g.getFontMetrics(TIME_BAR_FONT); 378 Rectangle2D rect = fm.getStringBounds(alternateLabel, g); 379 int textWidth = (int)(rect.getWidth()); 380 381 g.drawString( 382 alternateLabel, 383 x + ((width >> 1) - (textWidth >> 1)), 384 y + (height - 2)); 385 386 } 387 388 } 389 390 public int getWidth() { 346 TextLayout layout = EcosystemManager.getTextLayoutManager().layoutStringSimple(alternateLabel, TIME_BAR_FONT); 347 348 int textWidth = layout.getPixelBounds(0, 0).getWidth(); 349 gm.drawTextLayout(layout, new Point(x + ((width >> 1) - (textWidth >> 1)), y + (height - 2)), Colour.BLACK); 350 351 } 352 353 } 354 355 public int getWidth() 356 { 391 357 return width; 392 358 }
Note:
See TracChangeset
for help on using the changeset viewer.